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§
Sourcefn blend(
&mut self,
graph_node: NodeIndex,
) -> Result<(), AnimationEvaluationError>
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:
-
Pop the top element of the stack. Call its value vₘ and its weight wₘ. If the stack was empty, return success.
-
If the blend register is empty, set the blend register value to vₘ and the blend register weight to wₘ; then, return success.
-
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ₙ. -
Return success.
Sourcefn add(&mut self, graph_node: NodeIndex) -> Result<(), AnimationEvaluationError>
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:
-
Pop the top element of the stack. Call its value vₘ and its weight wₘ. If the stack was empty, return success.
-
If the blend register is empty, set the blend register value to vₘ and the blend register weight to wₘ; then, return success.
-
If the blend register is nonempty, call its current value vₙ. Then, set the value of the blend register to vₙ + vₘwₘ.
-
Return success.
Sourcefn push_blend_register(
&mut self,
weight: f32,
graph_node: NodeIndex,
) -> Result<(), AnimationEvaluationError>
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.
Sourcefn commit(
&mut self,
entity: EntityMutExcept<'_, '_, (AnimationTarget, AnimationPlayer, AnimationGraphHandle)>,
) -> Result<(), AnimationEvaluationError>
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
impl dyn AnimationCurveEvaluator
Sourcepub fn is<__T>(&self) -> boolwhere
__T: AnimationCurveEvaluator,
pub fn is<__T>(&self) -> boolwhere
__T: AnimationCurveEvaluator,
Returns true if the trait object wraps an object of type __T.
Sourcepub fn downcast<__T>(
self: Box<dyn AnimationCurveEvaluator>,
) -> Result<Box<__T>, Box<dyn AnimationCurveEvaluator>>where
__T: AnimationCurveEvaluator,
pub fn downcast<__T>(
self: Box<dyn AnimationCurveEvaluator>,
) -> Result<Box<__T>, Box<dyn AnimationCurveEvaluator>>where
__T: 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.
Sourcepub fn downcast_rc<__T>(
self: Rc<dyn AnimationCurveEvaluator>,
) -> Result<Rc<__T>, Rc<dyn AnimationCurveEvaluator>>where
__T: AnimationCurveEvaluator,
pub fn downcast_rc<__T>(
self: Rc<dyn AnimationCurveEvaluator>,
) -> Result<Rc<__T>, Rc<dyn AnimationCurveEvaluator>>where
__T: 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.
Sourcepub fn downcast_ref<__T>(&self) -> Option<&__T>where
__T: AnimationCurveEvaluator,
pub fn downcast_ref<__T>(&self) -> Option<&__T>where
__T: AnimationCurveEvaluator,
Returns a reference to the object within the trait object if it is of type __T, or
None if it isn’t.
Sourcepub fn downcast_mut<__T>(&mut self) -> Option<&mut __T>where
__T: AnimationCurveEvaluator,
pub fn downcast_mut<__T>(&mut self) -> Option<&mut __T>where
__T: AnimationCurveEvaluator,
Returns a mutable reference to the object within the trait object if it is of type
__T, or None if it isn’t.