pub struct Animator { /* private fields */ }Expand description
Reusable local-pose player. Crossfades keep the outgoing clip moving. An interrupted crossfade snapshots the current base blend before layers, so reapplying aim/recoil cannot bake the same layer into the source twice. If the fade has not advanced yet, retargeting keeps the original outgoing clip moving. Events come only from the incoming clip, avoiding duplicate footstep/weapon events during transitions. Layers are visual and do not emit extra events. No frame, play/seek/transition or layer operation allocates after construction.
Implementations§
Source§impl Animator
impl Animator
pub fn new( bank: &AnimationBank, clip: usize, ) -> Result<Animator, AnimationError>
pub fn pose(&self) -> &[Transform]
pub fn base_pose(&self) -> &[Transform]
pub fn clip(&self) -> usize
pub fn timeline(&self) -> &Timeline
pub fn transitioning(&self) -> bool
pub fn set_paused(&mut self, paused: bool)
pub fn set_speed(&mut self, speed: f32) -> Result<(), AnimationError>
Sourcepub fn play(&mut self, clip: usize) -> Result<(), AnimationError>
pub fn play(&mut self, clip: usize) -> Result<(), AnimationError>
Restart the requested clip and cancel any transition. For per-frame state selection use transition(), which keeps an already selected clip running.
Sourcepub fn transition(
&mut self,
clip: usize,
seconds: f32,
) -> Result<(), AnimationError>
pub fn transition( &mut self, clip: usize, seconds: f32, ) -> Result<(), AnimationError>
Select a clip with a fade lasting seconds in 0..=60. Positive durations
leave the current pose/layers intact until the next advance. Retargeting a
progressing fade uses the unlayered base as a frozen source; retargeting
before any fade progress preserves its original moving source.
Selecting the incoming clip again with a positive duration is a no-op.
Zero duration completes an existing fade immediately at the current
playback time, clearing layers without restarting the clock or replaying
start events. With no fade, selecting the current clip remains a no-op.
Selecting a different clip with zero duration instead calls Self::play.
Invalid clip indices or durations leave all state unchanged.
use ferravex_play::{animation::*, scene::Transform};
let clip = AnimationClip::new(1, 1., LoopMode::Repeat, vec![], vec![])?;
let bank = AnimationBank::new(vec![Transform::default()], vec![clip.clone(), clip])?;
let mut player = Animator::new(&bank, 0)?;
let mut events = EventBuffer::<8>::default();
player.transition(1, 0.5)?;
player.advance(0.125, &mut events)?;
assert!(player.transitioning());
player.transition(1, 0.)?;
assert!(!player.transitioning());
assert_eq!(player.timeline().time(), 0.125);pub fn seek(&mut self, time: f32) -> Result<(), AnimationError>
pub fn advance<const N: usize>( &mut self, dt: f32, events: &mut EventBuffer<N>, ) -> Result<(), AnimationError>
Sourcepub fn apply_layer(
&mut self,
clip: usize,
time: f32,
weight: f32,
mask: Option<&JointMask>,
mode: LayerMode,
) -> Result<(), AnimationError>
pub fn apply_layer( &mut self, clip: usize, time: f32, weight: f32, mask: Option<&JointMask>, mode: LayerMode, ) -> Result<(), AnimationError>
Apply one visual layer until the next advance/play/seek or immediate transition. Repeat to stack masked overrides or additive recoil/aim over the current base pose. Invalid clips, times, weights, mask lengths or overflowing additive results leave the visible pose, base pose and playback/transition state unchanged. Zero effective weight preserves the joint exactly. No allocation occurs.
use ferravex_play::{animation::*, scene::Transform};
let clip = AnimationClip::new(2, 1., LoopMode::Clamp, vec![], vec![])?;
let bank = AnimationBank::new(vec![Transform::default(); 2], vec![clip])?;
let mut player = Animator::new(&bank, 0)?;
let mask = JointMask::new(vec![1.])?; // wrong skeleton size
let previous = player.pose().to_vec();
assert_eq!(player.apply_layer(0, 0., 1., Some(&mask), LayerMode::Additive),
Err(AnimationError::JointCount));
assert_eq!(player.pose(), previous);