class Animation

Handles animation playback.

Takes one or multiple animation clips as input and evaluates them every animation update tick depending on set properties. The evaluated data is used by the render thread for skeletal animation, by the main thread for updating attached scene objects and bones (if skeleton is attached), or the data is made available for manual queries in the case of generic animation.

Public

Constructors

Animation

Animation(const HSceneObject &parent)

Methods

SetDefaultClip

void SetDefaultClip(const HAnimationClip &clip)

Determines the default clip to play as soon as the component is enabled.

If more control over playing clips is needed use the Play(), Blend*(), CrossFade() methods to queue clips for playback manually, and SetState() method to modify their states individually.

GetDefaultClip

HAnimationClip GetDefaultClip() const

SetWrapMode

void SetWrapMode(AnimationWrapMode wrapMode)

Determines the wrap mode for all active animations.

Wrap mode determines what happens when animation reaches the first or last frame.

GetWrapMode

AnimationWrapMode GetWrapMode() const

SetSpeed

void SetSpeed(float speed)

Determines the speed for all animations.

The default value is 1.0f. Use negative values to play-back in reverse.

GetSpeed

float GetSpeed() const

Play

void Play(const HAnimationClip &clip)

Plays the specified animation clip.

BlendAdditive

void BlendAdditive(const HAnimationClip &clip, float weight, float fadeLength = 0.F, u32 layer = 0)

Plays the specified animation clip on top of the animation currently playing in the main layer.

Multiple such clips can be playing at once, as long as you ensure each is given its own layer. Each animation can also have a weight that determines how much it influences the main animation.

clip
Clip to additively blend. Must contain additive animation curves.
weight
Determines how much of an effect will the blended animation have on the final output. In range [0, 1].
fadeLength
Applies the blend over a specified time period, increasing the weight as the time passes. Set to zero to blend immediately. In seconds.
layer
Layer to play the clip in. Multiple additive clips can be playing at once in separate layers and each layer has its own weight.

Blend1D

void Blend1D(const Blend1DInfo &info, float alpha)

Blend multiple animation clips between each other using linear interpolation.

Unlike normal animations these animations are not advanced with the progress of time, and is instead expected the user manually changes the

parameter.

info
Information about the clips to blend. Clip positions must be sorted from lowest to highest.
alpha
Parameter that controls the blending. Range depends on the positions of the provided animation clips.

Blend2D

void Blend2D(const Blend2DInfo &info, const Vector2 &alpha)

Blend four animation clips between each other using bilinear interpolation.

Unlike normal animations these animations are not advanced with the progress of time, and is instead expected the user manually changes the

parameter.

info
Information about the clips to blend.
alpha
Parameter that controls the blending, in range [(0, 0), (1, 1)]. alpha = (0, 0) means top left animation has full influence, alpha = (1, 0) means top right animation has full influence, alpha = (0, 1) means bottom left animation has full influence, alpha = (1, 1) means bottom right animation has full influence.

CrossFade

void CrossFade(const HAnimationClip &clip, float fadeLength)

Fades the specified animation clip in, while fading other playing animation out, over the specified time period.

clip
Clip to fade in.
fadeLength
Determines the time period over which the fade occurs. In seconds.

Sample

void Sample(const HAnimationClip &clip, float time)

Samples an animation clip at the specified time, displaying only that particular frame without further playback.

clip
Animation clip to sample.
time
Time to sample the clip at.

Stop

void Stop(u32 layer)

Stops playing all animations on the provided layer.

Specify ~0u to stop animation on the main layer (non-additive animations).

StopAll

void StopAll()

Stops playing all animations.

IsPlaying

bool IsPlaying() const

Checks if any animation clips are currently playing.

GetState

bool GetState(const HAnimationClip &clip, AnimationClipState &outState)

Retrieves detailed information about a currently playing animation clip.

clip
Clip to retrieve the information for.
outState
Animation clip state containing the requested information. Only valid if the method returns true.

Returns: True if the state was found (animation clip is playing), false otherwise.

SetState

void SetState(const HAnimationClip &clip, AnimationClipState state)

Changes the state of a playing animation clip.

If animation clip is not currently playing the playback is started for the clip.

clip
Clip to change the state for.
state
New state of the animation (e.g. changing the time for seeking).

SetMorphChannelWeight

void SetMorphChannelWeight(const String &name, float weight)

Changes a weight of a single morph channel, determining how much of it to apply on top of the base mesh.

name
Name of the morph channel to modify. This depends on the mesh the animation is currently animating.
weight
Weight that determines how much of the channel to apply to the mesh, in range [0, 1].

SetCustomBounds

void SetCustomBounds(const AABox &bounds)

Determines bounds that will be used for animation and mesh culling.

Only relevant if SetUseCustomBounds() is set to true.

GetCustomBounds

const AABox &GetCustomBounds() const

SetUseCustomBounds

void SetUseCustomBounds(bool enable)

Determines should animation bounds be used for visibility determination (culling).

If false the bounds of the mesh attached to the relevant Renderable component will be used instead.

GetUseCustomBounds

bool GetUseCustomBounds() const

SetEnableCull

void SetEnableCull(bool enable)

Enables or disables culling of the animation when out of view.

Culled animation will not be evaluated.

GetEnableCull

bool GetEnableCull() const

Checks whether the animation will be evaluated when it is out of view.

GetClipCount

u32 GetClipCount() const

Returns the total number of animation clips influencing this animation.

GetClip

HAnimationClip GetClip(u32 index) const

Returns one of the animation clips influencing this animation.

index
Sequential index of the animation clip to retrieve.

Returns: Animation clip at the specified index, or null if the index is out of range.

staticGetRttiStatic

static RTTIType *GetRttiStatic()

GetRtti

RTTIType *GetRtti() const override

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

Fields

OnEventTriggered

Event<void (const HAnimationClip &, const String &)> OnEventTriggered

Triggered whenever an animation event is reached.

Internal

Methods

GetAnimationId

u64 GetAnimationId() const

Returns the unique ID for this animation object.

SetSkeleton

void SetSkeleton(const SPtr<Skeleton> &skeleton)

Changes the skeleton which will the translation/rotation/scale animation values manipulate.

If no skeleton is set the animation will only evaluate the generic curves, and the root translation/rotation/scale curves.

SetMorphShapes

void SetMorphShapes(const SPtr<MorphShapes> &morphShapes)

Sets morph shapes that can be used for per-vertex blending animation.

After they're set call setMorphShapeWeight() to apply morph shapes.

SetMask

void SetMask(const SkeletonMask &mask)

Sets a mask that allows certain bones from the skeleton to be disabled.

Caller must ensure that the mask matches the skeleton assigned to the animation.

AddBone

void AddBone(const HBone &bone)

Registers a new bone component, creating a new transform mapping from the bone name to the scene object the component is attached to.

RemoveBone

void RemoveBone(const HBone &bone)

Unregisters a bone component, removing the bone -> scene object mapping.

NotifyBoneNameChanged

void NotifyBoneNameChanged(const HBone &bone)

Called whenever the bone name the Bone component points to changes.

GetAnimatesRoot

bool GetAnimatesRoot() const

Checks if any currently set animation clips perform animation of the root bone.

RegisterRenderable

void RegisterRenderable(const HRenderable &renderable)

Registers a Renderable component with the animation, should be called whenever a Renderable component is added to the same scene object as this component.

UnregisterRenderable

void UnregisterRenderable()

Removes renderable from the animation component.

Should be called when a Renderable component is removed from this scene object.

UpdateBounds

void UpdateBounds(bool updateRenderable = true)

Re-applies the bounds to the internal animation object, and the relevant renderable object if one exists.

GetCullingBounds

AABox GetCullingBounds() const

Returns bounds used for culling the animation.

RefreshClipMappingsInternal

void RefreshClipMappingsInternal()

Rebuilds internal curve -> property mapping about the currently playing animation clip.

This mapping allows the animation component to know which property to assign which values from an animation curve. This should be called whenever playback for a new clip starts, or when clip curves change.

GetGenericCurveValueInternal

bool GetGenericCurveValueInternal(u32 curveIndex, float &outValue)

Retrieves an evaluated value for a generic curve with the specified index.

curveIndex
The curve index referencing a set of curves from the first playing animation clip. Generic curves from all other clips are ignored.
outValue
Value of the generic curve. Only valid if the method return true.

Returns: True if the value was retrieved successfully. The method might fail if animation update didn't yet have a chance to execute and values are not yet available, or if the animation clip changed since the last frame (the last problem can be avoided by ensuring to read the curve values before changing the clip).

TogglePreviewModeInternal

bool TogglePreviewModeInternal(bool enabled)

Preview mode allows certain operations on the component to be allowed (like basic animation playback), even when the component is not actively running.

This is intended for use primarily by the animation editor. Preview mode ends automatically when the component is enabled (i.e. starts running normally), or when explicitly disabled. Returns true if the preview mode was enabled (which could fail if the component is currently running). When previewing, you can only run the animation using Sample() or directly by setting state, all other playback commands will be ignored.

Fields

ScriptRebuildFloatPropertiesInternal

std::function<void (const HAnimationClip &)> ScriptRebuildFloatPropertiesInternal

Triggered when the list of properties animated via generic animation curves needs to be recreated (script only).

ScriptUpdateFloatPropertiesInternal

std::function<void ()> ScriptUpdateFloatPropertiesInternal

Triggered when generic animation curves values need be applied to the properties they effect (script only).

ScriptOnEventTriggeredInternal

std::function<void (const HAnimationClip &, const String &)> ScriptOnEventTriggeredInternal

Triggers a callback in script code when animation event is triggered (script only).

Protected

Constructors

Animation

Animation()

Methods

OnDestroyed

void OnDestroyed() override

Called once just before the component is destroyed.

Called regardless of the state the component is in.

Update

void Update() override

Called once per frame.

Only called if the component is in Running state.

OnDisabled

void OnDisabled() override

Called every time a component is placed into the Stopped state.

This includes component destruction if component wasn't already in Stopped state during destruction. When called during destruction it is called before OnDestroyed.

OnEnabled

void OnEnabled() override

Called every time a component leaves the Stopped state, if the component is enabled.

This includes component creation if requirements for leaving the Stopped state are met. When called during creation it is called after OnBeginPlay.

OnTransformChanged

void OnTransformChanged(TransformChangedFlags flags) override

Called when the component's parent scene object has changed.

Not called if the component is in Stopped state. Also only called if necessary notify flags are set via SetNotifyFlagsInternal().

CreateAnimationProxy

void CreateAnimationProxy(bool previewMode)

Creates the internal animation proxy and registers it with the animation scene.

Animation without a proxy cannot be played.

DestroyAnimationProxy

void DestroyAnimationProxy()

Destroys the internal animation proxy.

Animation without a proxy cannot be played.

IsAnimationProxyValid

bool IsAnimationProxyValid() const

Returns true if the animation proxy is created and registered with the animation scene.

If false, animation cannot play.

NotifyAnimationEventTriggered

void NotifyAnimationEventTriggered(const HAnimationClip &clip, const String &name)

Callback triggered whenever an animation event is triggered.

RebuildBoneMappings

void RebuildBoneMappings()

Finds any scene objects that are mapped to bone transforms.

Such object's transforms will be affected by skeleton bone animation.

RebuildGenericMappings

void RebuildGenericMappings()

Finds any curves that affect a transform of a specific scene object, and ensures that animation properly updates those transforms.

This does not include curves referencing bones.

FindChildBones

Vector<HBone> FindChildBones()

Searches child scene objects for Bone components and returns any found ones.

TriggerEvents

void TriggerEvents(float timeDelta)

Triggers any events between the last frame and current one.

timeDelta
Time elapsed since the last call to this method.

UpdateAnimationProxy

void UpdateAnimationProxy(float timeDelta)

Updates the animation proxy object based on the currently set skeleton, playing clips and dirty flags.

timeDelta
Seconds passed since the last call to this method.

UpdateFromProxy

void UpdateFromProxy()

Applies any outputs stored in the animation proxy (as written by the animation thread), and uses them to update the animation state on the main thread.

Caller must ensure that the animation thread has finished with the animation proxy.

GetOrCreateClipInfo

AnimationClipInfo *GetOrCreateClipInfo(const HAnimationClip &clip, u32 layer, bool stopExisting = true)

Registers a new animation in the specified layer, or returns an existing animation clip info if the animation is already registered.

If is true any existing animations in the layer will be stopped. Layout will be marked as dirty if any changes were made.

GetListenerResources

void GetListenerResources(Vector<HResource> &resources) override

Retrieves all the resources that the class depends on.

NotifyResourceLoaded

void NotifyResourceLoaded(const HResource &resource) override

Called when a resource has been fully loaded.

NotifyResourceChanged

void NotifyResourceChanged(const HResource &resource) override

Called when the internal resource the resource handle is pointing to changes.

Fields

mAnimationId

u64 mAnimationId

mDirty

AnimDirtyState mDirty

mAnimatedRenderable

HRenderable mAnimatedRenderable

mDefaultClip

HAnimationClip mDefaultClip

mPrimaryPlayingClip

HAnimationClip mPrimaryPlayingClip

mWrapMode

mSpeed

float mSpeed

mEnableCull

bool mEnableCull

mUseCustomBounds

bool mUseCustomBounds

mPreviewMode

bool mPreviewMode

mCustomBounds

AABox mCustomBounds

mCullingBounds

AABox mCullingBounds

mSkeleton

SPtr<Skeleton> mSkeleton

mSkeletonMask

SkeletonMask mSkeletonMask

mMorphShapes

SPtr<MorphShapes> mMorphShapes

mMorphChannelWeights

Vector<float> mMorphChannelWeights

mClipInfos

Vector<AnimationClipInfo> mClipInfos

mMappedSceneObjectInfos

Vector<SceneObjectMappingInfo> mMappedSceneObjectInfos

mMappedSceneObjectsById

UnorderedMap<UUID, SceneObjectMappingCurveInfo> mMappedSceneObjectsById

mGenericCurveOutputs

Vector<float> mGenericCurveOutputs

mGenericCurveValuesValid

bool mGenericCurveValuesValid

mSampleStep

mAnimationProxy

SPtr<AnimationProxy> mAnimationProxy