Struct Animator

Source
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

Source

pub fn new( bank: &AnimationBank, clip: usize, ) -> Result<Animator, AnimationError>

Source

pub fn pose(&self) -> &[Transform]

Source

pub fn base_pose(&self) -> &[Transform]

Source

pub fn clip(&self) -> usize

Source

pub fn timeline(&self) -> &Timeline

Source

pub fn transitioning(&self) -> bool

Source

pub fn set_paused(&mut self, paused: bool)

Source

pub fn set_speed(&mut self, speed: f32) -> Result<(), AnimationError>

Source

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.

Source

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);
Source

pub fn seek(&mut self, time: f32) -> Result<(), AnimationError>

Source

pub fn advance<const N: usize>( &mut self, dt: f32, events: &mut EventBuffer<N>, ) -> Result<(), AnimationError>

Source

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);

Trait Implementations§

Source§

impl Clone for Animator

Source§

fn clone(&self) -> Animator

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Animator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.