pub struct AnimationPlayer { /* private fields */ }Expand description
A component that manages animation playback state for a skinned entity.
Attach alongside a [Handle<SkinnedMesh>]. The engine advances time each
tick via advance. Call play /
crossfade to control playback. Obtain skinning
matrices via compute_matrices from your own
skinning system, or add CpuSkinningPlugin
to have the engine do it automatically.
Cloning shares the skeleton and clip data (via Arc) but resets
per-entity playback state — useful for spawning many entities from the
same loaded skeleton.
Implementations§
Source§impl AnimationPlayer
impl AnimationPlayer
Sourcepub fn play(&mut self, name: &str)
pub fn play(&mut self, name: &str)
Switch immediately to name, restarting from the beginning. Use for
hard cuts (hit reactions, death). Warns if name wasn’t loaded.
Sourcepub fn play_once(&mut self, name: &str)
pub fn play_once(&mut self, name: &str)
Play name once to completion without looping, then hold the last
frame. Warns if name wasn’t loaded.
Sourcepub fn crossfade(&mut self, name: &str, duration: f32)
pub fn crossfade(&mut self, name: &str, duration: f32)
Blend from the current clip to name over duration seconds. Use
for smooth transitions (walk → run). Warns if name wasn’t loaded.
Sourcepub fn set_speed(&mut self, speed: f32)
pub fn set_speed(&mut self, speed: f32)
Set the playback speed multiplier. 1.0 = normal, 2.0 = double,
negative values play in reverse.
Sourcepub fn joint_count(&self) -> usize
pub fn joint_count(&self) -> usize
Number of joints in this player’s skeleton.
Sourcepub fn current_clip(&self) -> Option<&AnimationClip>
pub fn current_clip(&self) -> Option<&AnimationClip>
The currently active clip, if any.
Sourcepub fn clip_names(&self) -> impl Iterator<Item = &str>
pub fn clip_names(&self) -> impl Iterator<Item = &str>
Returns an iterator over the names of all loaded animation clips, in an unspecified order.
Sourcepub fn advance(&mut self, dt: f32)
pub fn advance(&mut self, dt: f32)
Advance time by dt seconds, handling looping and any active
crossfade. Called by advance_animations —
call it yourself only if you skip CpuSkinningPlugin.
Sourcepub fn compute_pose(&self) -> Pose
pub fn compute_pose(&self) -> Pose
Sample the current animation (including any active crossfade) into a
Pose. Use as the IK entry point — modify joints via
set_world_rotation /
set_world_position, then call
skinning_matrices. Returns the bind pose
if no clip is playing.
Sourcepub fn set_matrices(&mut self, matrices: Vec<Mat4>)
pub fn set_matrices(&mut self, matrices: Vec<Mat4>)
Override the matrices that compute_matrices
returns. Use after modifying a Pose for IK or procedural animation:
let mut pose = player.compute_pose();
pose.set_world_rotation(foot, target_rot);
player.set_matrices(pose.skinning_matrices());The override persists until clear_matrices is
called, so call this every frame while the override is active.
Sourcepub fn clear_matrices(&mut self)
pub fn clear_matrices(&mut self)
Remove the matrix override — compute_matrices
returns to sampling the current animation clip.
Sourcepub fn compute_matrices(&self) -> Vec<Mat4>
pub fn compute_matrices(&self) -> Vec<Mat4>
Sample the current animation (including any active crossfade) and
return one skinning matrix per joint, ready to upload. Returns the
matrix override if one is set via set_matrices,
or identity matrices if no clip is playing.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AnimationPlayer
impl RefUnwindSafe for AnimationPlayer
impl Send for AnimationPlayer
impl Sync for AnimationPlayer
impl Unpin for AnimationPlayer
impl UnsafeUnpin for AnimationPlayer
impl UnwindSafe for AnimationPlayer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Component for T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more