Skip to main content

Animation

Struct Animation 

Source
pub struct Animation {
Show 15 fields pub asset_id: AssetId, pub target: Option<SkinnedMeshHandle>, pub source: String, pub animation_index: u32, pub animation_name: String, pub sample_rate: f32, pub duration: f32, pub looping: bool, pub weight: f32, pub fade_in_secs: f32, pub root_motion: bool, pub root_motion_y: bool, pub root_track: Vec<RootKey>, pub tracks: Vec<AnimationTrack>, pub morph_track: Vec<MorphKey>,
}
Expand description

A skeletal animation clip that animates one SkinnedMesh.

The clip plays every frame, sampling each track and deforming the target mesh’s skeleton. Joints with no track hold their bind pose.

Several Animation assets may target the same SkinnedMesh; they are then blended into one pose, weighted by each clip’s weight (a normalised weighted average). A single clip plays at full strength regardless of its weight.

File import. A clip may be authored entirely by hand (tracks filled out, source left empty) or imported from the same glTF (.glb / .gltf) or .fbx file that backs the target SkinnedMesh. Set source to the file path and the build imports duration + tracks from it. animation_index picks one clip when the file contains several (default 0); animation_name names it for matching against the file’s clip names: when set it takes precedence over the index. FBX curves are baked at sample_rate keys per second. Channels whose target node is not a joint of the file’s first skinned node are dropped. The same file should back the target SkinnedMesh so the joint indices agree.

Animation {
    duration: 2.0,
    ..Default::default()
};

Fields§

§asset_id: AssetId

Asset identity; injected via inject_name. Not part of args.

§target: Option<SkinnedMeshHandle>

The SkinnedMesh asset this clip animates.

§source: String

Optional path to a .glb, .gltf, or .fbx file. When set, the build imports duration + tracks from it; inline-authored clips leave this empty.

§animation_index: u32

Index of the animation to import when source is set and the file contains several. Ignored when animation_name is non-empty.

§animation_name: String

Name of the animation to import. When set, the matching clip in the source file is looked up by name; takes precedence over animation_index.

§sample_rate: f32

Keys per second baked from sources whose curves need resampling at import (FBX). glTF keyframes pass through untouched. Default 30.

§duration: f32

Clip length in seconds. Overridden by glTF import.

§looping: bool

When true, playback wraps after duration.

§weight: f32

Blend weight used when several clips target the same SkinnedMesh. Ignored when this is the only clip on its target.

§fade_in_secs: f32

When non-zero, the clip’s contribution ramps from 0 to its declared weight over this many seconds after the world starts. Zero (the default) plays the clip at full weight from the first frame.

§root_motion: bool

When true, the build strips the root joint’s travel out of the pose and bakes it into root_track: the pose stays anchored in place and the runtime moves the character by the curve’s frame-to-frame delta instead (the SkinnedMesh capsule is the usual consumer). X and Z travel is always stripped; Y only with root_motion_y.

§root_motion_y: bool

Also strip the root joint’s vertical travel into root_track. Leave false (the default) so jumps and crouches stay authored in the pose.

§root_track: Vec<RootKey>

The displacement curve baked out of the root joint by the build when root_motion is set. Filled by the build; not usually authored by hand.

§tracks: Vec<AnimationTrack>

Per-joint keyframe channels.

§morph_track: Vec<MorphKey>

Morph-target weight keys for the target mesh, in time order. Each key holds one weight per morph target of the SkinnedMesh. Filled by the glTF import; empty when the clip animates no morph targets.

Implementations§

Source§

impl Animation

Source

pub fn to_clip(&self) -> AnimationClip

Convert this asset into the runtime AnimationClip consumed by the skinning math.

Trait Implementations§

Source§

impl Clone for Animation

Source§

fn clone(&self) -> Animation

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Component for Animation

Source§

const NAME: &'static str = "Animation"

The registry name a world authors this component under.
Source§

fn inject_name(&mut self, id: AssetId)

Called after construction to inject the asset’s identity from the blob def. Only meaningful for components that look themselves up by id at runtime. The default implementation does nothing.
Source§

fn from_baked(bytes: &[u8]) -> Result<Self, CnResult>

Reconstruct this component from a blob record, whose bytes are the serialized runtime component (cook already ran the asset -> component translation). The default rejects: runtime-only components are never stored in a blob, so only loadable types provide an implementation.
Source§

fn inject_locator(&mut self, _locator: PayloadLocator)

Called after construction to inject the payload locator from the blob def. Only meaningful for components with a compiled payload. The default implementation does nothing (correct for most components).
Source§

impl ComponentSlot for Animation

Source§

const DISCRIMINANT: u8

The component type’s stable id, used as its ComponentId.
Source§

fn slot(s: &ComponentStorage) -> &Column<Self>

Borrow this type’s column out of the storage.
Source§

fn slot_mut(s: &mut ComponentStorage) -> &mut Column<Self>

Mutably borrow this type’s column out of the storage.
Source§

impl Debug for Animation

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Animation

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Animation

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<Animation> for ComponentAsset

Source§

fn from(c: Animation) -> Self

Converts to this type from the input type.
Source§

impl RuntimeComponent for Animation

Source§

impl Serialize for Animation

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = !

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more