AnimationCurveEvaluator

Trait AnimationCurveEvaluator 

Source
pub trait AnimationCurveEvaluator:
    Downcast
    + Send
    + Sync
    + 'static {
    // Required methods
    fn blend(
        &mut self,
        graph_node: NodeIndex,
    ) -> Result<(), AnimationEvaluationError>;
    fn add(
        &mut self,
        graph_node: NodeIndex,
    ) -> Result<(), AnimationEvaluationError>;
    fn push_blend_register(
        &mut self,
        weight: f32,
        graph_node: NodeIndex,
    ) -> Result<(), AnimationEvaluationError>;
    fn commit(
        &mut self,
        entity: EntityMutExcept<'_, '_, (AnimationTarget, AnimationPlayer, AnimationGraphHandle)>,
    ) -> Result<(), AnimationEvaluationError>;
}
Expand description

A low-level trait for use in VariableCurve that provides fine control over how animations are evaluated.

You can implement this trait when the generic AnimatableCurveEvaluator isn’t sufficiently-expressive for your needs. For example, MorphWeights implements this trait instead of using AnimatableCurveEvaluator because it needs to animate arbitrarily many weights at once, which can’t be done with Animatable as that works on fixed-size values only.

If you implement this trait, you should also implement AnimationCurve on your curve type, as that trait allows creating instances of this one.

Implementations of AnimatableCurveEvaluator should maintain a stack of (value, weight, node index) triples, as well as a blend register, which is either a (value, weight) pair or empty. Value here refers to an instance of the value being animated: for example, Vec3 in the case of translation keyframes. The stack stores intermediate values generated while evaluating the AnimationGraph, while the blend register stores the result of a blend operation.

Required Methods§

Source

fn blend( &mut self, graph_node: NodeIndex, ) -> Result<(), AnimationEvaluationError>

Blends the top element of the stack with the blend register.

The semantics of this method are as follows:

  1. Pop the top element of the stack. Call its value vₘ and its weight wₘ. If the stack was empty, return success.

  2. If the blend register is empty, set the blend register value to vₘ and the blend register weight to wₘ; then, return success.

  3. If the blend register is nonempty, call its current value vₙ and its current weight wₙ. Then, set the value of the blend register to interpolate(vₙ, vₘ, wₘ / (wₘ + wₙ)), and set the weight of the blend register to wₘ + wₙ.

  4. Return success.

Source

fn add(&mut self, graph_node: NodeIndex) -> Result<(), AnimationEvaluationError>

Additively blends the top element of the stack with the blend register.

The semantics of this method are as follows:

  1. Pop the top element of the stack. Call its value vₘ and its weight wₘ. If the stack was empty, return success.

  2. If the blend register is empty, set the blend register value to vₘ and the blend register weight to wₘ; then, return success.

  3. If the blend register is nonempty, call its current value vₙ. Then, set the value of the blend register to vₙ + vₘwₘ.

  4. Return success.

Source

fn push_blend_register( &mut self, weight: f32, graph_node: NodeIndex, ) -> Result<(), AnimationEvaluationError>

Pushes the current value of the blend register onto the stack.

If the blend register is empty, this method does nothing successfully. Otherwise, this method pushes the current value of the blend register onto the stack, alongside the weight and graph node supplied to this function. The weight present in the blend register is discarded; only the weight parameter to this function is pushed onto the stack. The blend register is emptied after this process.

Source

fn commit( &mut self, entity: EntityMutExcept<'_, '_, (AnimationTarget, AnimationPlayer, AnimationGraphHandle)>, ) -> Result<(), AnimationEvaluationError>

Pops the top value off the stack and writes it into the appropriate component.

If the stack is empty, this method does nothing successfully. Otherwise, it pops the top value off the stack, fetches the associated component from either the transform or entity values as appropriate, and updates the appropriate property with the value popped from the stack. The weight and node index associated with the popped stack element are discarded. After doing this, the stack is emptied.

The property on the component must be overwritten with the value from the stack, not blended with it.

Implementations§

Source§

impl dyn AnimationCurveEvaluator

Source

pub fn is<__T>(&self) -> bool

Returns true if the trait object wraps an object of type __T.

Source

pub fn downcast<__T>( self: Box<dyn AnimationCurveEvaluator>, ) -> Result<Box<__T>, Box<dyn AnimationCurveEvaluator>>

Returns a boxed object from a boxed trait object if the underlying object is of type __T. Returns the original boxed trait if it isn’t.

Source

pub fn downcast_rc<__T>( self: Rc<dyn AnimationCurveEvaluator>, ) -> Result<Rc<__T>, Rc<dyn AnimationCurveEvaluator>>

Returns an Rc-ed object from an Rc-ed trait object if the underlying object is of type __T. Returns the original Rc-ed trait if it isn’t.

Source

pub fn downcast_ref<__T>(&self) -> Option<&__T>

Returns a reference to the object within the trait object if it is of type __T, or None if it isn’t.

Source

pub fn downcast_mut<__T>(&mut self) -> Option<&mut __T>

Returns a mutable reference to the object within the trait object if it is of type __T, or None if it isn’t.

Implementors§