class AnimationClip

Inherits: Resource

Contains animation curves for translation/rotation/scale of scene objects/skeleton bones, as well as curves for generic property animation.

Public

Methods

~AnimationClip

virtual ~AnimationClip() noexcept = default

GetCurves

SPtr<AnimationCurves> GetCurves() const

SetCurves

void SetCurves(const AnimationCurves &curves)

A set of all curves stored in the animation.

Returned value will not be updated if the animation clip curves are added or removed, as it is a copy of clip's internal values.

GetEvents

const Vector<AnimationEvent> &GetEvents() const

SetEvents

void SetEvents(const Vector<AnimationEvent> &events)

A set of all events to be triggered as the animation is playing.

GetRootMotion

SPtr<RootMotion> GetRootMotion() const

Returns a set of curves containing motion of the root bone.

This allows the user to evaluate the root bone animation curves manually, instead of through the normal animation process. This property is only available if animation clip was imported with root motion import enabled.

HasRootMotion

bool HasRootMotion() const

Checks if animation clip has root motion curves separate from the normal animation curves.

GetBoneMapping

void GetBoneMapping(const Skeleton &skeleton, AnimationCurveMapping *outMapping) const

Maps skeleton bone names to animation curve names, and returns a set of indices that can be easily used for locating an animation curve based on the bone index.

skeleton
Skeleton to create the mapping for.
outMapping
Pre-allocated array that will receive output animation clip indices. The array must be large enough to store an index for every bone in the . Bones that have no related animation curves will be assigned value -1.

GetCurveMapping

void GetCurveMapping(const String &name, AnimationCurveMapping &outMapping) const

Attempts to find translation/rotation/scale curves with the specified name and fills the mapping structure with their indices, which can then be used for quick lookup.

name
Name of the curves to look up.
outMapping
Triple containing the translation/rotation/scale indices of the found curves. Indices will be -1 for curves that haven't been found.

GetMorphMapping

void GetMorphMapping(const String &name, u32 &outFrameIndex, u32 &outWeightIndex) const

Attempts to find a generic curve with the specified name and fills output with found index, which can then be used for quick lookup.

name
Name of the curve to look up.
outFrameIndex
Index of the curve animating the morph shape frames, or -1 if not found.
outWeightIndex
Index of the curve animating the channel weight, or -1 if not found.

IsAdditive

bool IsAdditive() const

Checks are the curves contained within the clip additive.

Additive clips are intended to be added on top of other clips.

GetLength

float GetLength() const

Returns the length of the animation clip, in seconds.

GetSampleRate

u32 GetSampleRate() const

SetSampleRate

void SetSampleRate(u32 sampleRate)

Number of samples per second the animation clip curves were sampled at.

This value is not used by the animation clip or curves directly since unevenly spaced keyframes are supported. But it can be of value when determining the original sample rate of an imported animation or similar.

GetVersion

u64 GetVersion() const

Returns a version that can be used for detecting modifications on the clip by external systems.

Whenever the clip is modified the version is increased by one.

staticCreate

static HAnimationClip Create(bool isAdditive = false)

Creates an animation clip with no curves.

After creation make sure to register some animation curves before using it.

staticCreate

static HAnimationClip Create(const SPtr<AnimationCurves> &curves, bool isAdditive = false, u32 sampleRate = 1, const SPtr<RootMotion> &rootMotion = nullptr)

Creates an animation clip with specified curves.

curves
Curves to initialize the animation with.
isAdditive
Determines does the clip contain additive curve data. This will change the behaviour how is the clip blended with other animations.
sampleRate
If animation uses evenly spaced keyframes, number of samples per second. Not relevant if keyframes are unevenly spaced.
rootMotion
Optional set of curves that can be used for animating the root bone. Not used by the animation system directly but is instead provided to the user for manual evaluation.

staticGetRttiStatic

static RTTIType *GetRttiStatic()

GetRtti

RTTIType *GetRtti() const override

Returns an interface you can use to access class' Run Time Type Information.

staticCreateEmpty

static SPtr<AnimationClip> CreateEmpty()

Creates an AnimationClip with no data.

You must populate its data manually followed by a call to Initialize().

Internal

Methods

staticCreatePtrInternal

static SPtr<AnimationClip> CreatePtrInternal(const SPtr<AnimationCurves> &curves, bool isAdditive = false, u32 sampleRate = 1, const SPtr<RootMotion> &rootMotion = nullptr)

Creates a new AnimationClip without initializing it.

Use create() for normal use.

Protected

Constructors

AnimationClip

AnimationClip()

AnimationClip

AnimationClip(const SPtr<AnimationCurves> &curves, bool isAdditive, u32 sampleRate, const SPtr<RootMotion> &rootMotion)

Methods

Initialize

void Initialize() override

Initializes all the internal data of this object.

Must be called right after construction for new objects, or after deserialization for deserialized objects. If requested, render proxy is created and queued for initialization on the render thread.

BuildNameMapping

void BuildNameMapping()

Creates a name -> curve index mapping for quicker curve lookup by name.

CalculateLength

void CalculateLength()

Calculate the length of the clip based on assigned curves.

Fields

mVersion

u64 mVersion

mCurves

SPtr<AnimationCurves> mCurves

Contains all the animation curves in the clip.

It's important this field is immutable so it may be used on other threads. This means any modifications to the field will require a brand new data structure to be generated and all existing data copied (plus the modification).

mRootMotion

SPtr<RootMotion> mRootMotion

A set of curves containing motion of the root bone.

If this is non-empty it should be true that mCurves does not contain animation curves for the root bone. Root motion will not be evaluated through normal animation process but is instead provided for the user for manual evaluation.

mNameMapping

UnorderedMap<String, std::array<u32, (int)CurveType::Count>> mNameMapping

Contains a map from curve name to curve index.

Indices are stored as specified in CurveType enum.

mEvents

Vector<AnimationEvent> mEvents

mIsAdditive

bool mIsAdditive

mLength

float mLength

mSampleRate

u32 mSampleRate