Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
mnd::AnimationComponent Class Referenceabstract

Drives transform animation on a hierarchy of GameObjects. More...

#include <AnimationComponent.h>

+ Inheritance diagram for mnd::AnimationComponent:
+ Collaboration diagram for mnd::AnimationComponent:

Public Member Functions

void Update (float deltaTime) override
 Advance playback time and write interpolated transforms to bound objects.
 
void SetClip (AnimationClip *clip)
 Set the active clip directly (bypasses the name registry).
 
void RegisterClip (const std::string &name, const std::shared_ptr< AnimationClip > &clip)
 Register a named clip so it can be started via Play().
 
void RegisterSkeletalClip (const std::string &name, const std::shared_ptr< SkeletalAnimationClip > &clip)
 Register a skeletal clip (per-bone TRS tracks) — used by SkinnedMeshComponent.
 
void SetSkeleton (const std::shared_ptr< Skeleton > &skeleton)
 Bind a skeleton to the component so skeletal clips can be evaluated.
 
const std::shared_ptr< Skeleton > & GetSkeleton () const
 Read-only handle to the bound skeleton (may be null for non-skeletal anims).
 
void Stop ()
 Halt playback. Pose freezes at the current frame.
 
bool IsPlaying ()
 
const std::vector< glm::mat4 > & GetPalette () const
 Read-only access to the bone palette computed at the last Update().
 
void Play (const std::string &name, bool loop=true)
 Start playing a registered clip by name.
 
std::vector< std::string > GetClipNames () const
 List every clip name registered on this component (node + skeletal).
 
virtual void LoadProperties (const nlohmann::json &json)
 
virtual void Init ()
 
virtual size_t GetTypeId () const =0
 
GameObjectGetOwner ()
 

Static Public Member Functions

template<typename T >
static size_t StaticTypeId ()
 

Protected Attributes

GameObjectm_owner = nullptr
 

Detailed Description

Drives transform animation on a hierarchy of GameObjects.

Attach to the root of a GLTF-loaded hierarchy. Register the clips loaded from the file (this is done automatically by GameObject::LoadGLTF), then call Play() to start playback.

Definition at line 100 of file AnimationComponent.h.

Member Function Documentation

◆ GetClipNames()

std::vector< std::string > mnd::AnimationComponent::GetClipNames ( ) const

List every clip name registered on this component (node + skeletal).

Names are deduplicated and returned sorted. Useful for editor UIs that want to enumerate available animations without poking at the maps.

Definition at line 12 of file AnimationComponent.cpp.

◆ GetOwner()

GameObject * mnd::Component::GetOwner ( )
inherited

◆ GetPalette()

const std::vector< glm::mat4 > & mnd::AnimationComponent::GetPalette ( ) const
inline

Read-only access to the bone palette computed at the last Update().

Empty until a skeletal clip is registered and Play() has been called. SkinnedMeshComponent reads this to upload uBones[] each frame.

Definition at line 143 of file AnimationComponent.h.

Referenced by mnd::SkinnedMeshComponent::Update().

◆ GetSkeleton()

const std::shared_ptr< Skeleton > & mnd::AnimationComponent::GetSkeleton ( ) const
inline

Read-only handle to the bound skeleton (may be null for non-skeletal anims).

Definition at line 130 of file AnimationComponent.h.

◆ GetTypeId()

virtual size_t mnd::Component::GetTypeId ( ) const
pure virtualinherited

◆ Init()

void mnd::Component::Init ( )
virtualinherited

Reimplemented in mnd::PhysicsComponent, and mnd::PlayerControllerComponent.

Definition at line 10 of file Component.cpp.

Referenced by mnd::GameObject::AddComponent().

◆ IsPlaying()

bool mnd::AnimationComponent::IsPlaying ( )

Definition at line 272 of file AnimationComponent.cpp.

◆ LoadProperties()

void mnd::Component::LoadProperties ( const nlohmann::json &  json)
virtualinherited

◆ Play()

void mnd::AnimationComponent::Play ( const std::string &  name,
bool  loop = true 
)

Start playing a registered clip by name.

Resolves target GameObjects by name (BuildBindings) and resets m_time to 0. Calling Play() while already playing restarts from the beginning.

Parameters
nameLoop key registered via RegisterClip.
looptrue to loop indefinitely; false to play once and stop.

Definition at line 110 of file AnimationComponent.cpp.

References mnd::ResetPoseToBind(), and SetClip().

◆ RegisterClip()

void mnd::AnimationComponent::RegisterClip ( const std::string &  name,
const std::shared_ptr< AnimationClip > &  clip 
)

Register a named clip so it can be started via Play().

Parameters
nameLookup key (typically the GLTF animation name).
clipShared AnimationClip loaded from GLTF.

Definition at line 94 of file AnimationComponent.cpp.

Referenced by mnd::ModelImporter::Import().

◆ RegisterSkeletalClip()

void mnd::AnimationComponent::RegisterSkeletalClip ( const std::string &  name,
const std::shared_ptr< SkeletalAnimationClip > &  clip 
)

Register a skeletal clip (per-bone TRS tracks) — used by SkinnedMeshComponent.

Definition at line 99 of file AnimationComponent.cpp.

Referenced by mnd::ModelImporter::Import().

◆ SetClip()

void mnd::AnimationComponent::SetClip ( AnimationClip clip)

Set the active clip directly (bypasses the name registry).

Parameters
clipRaw pointer to the clip to play; not owned.

Definition at line 88 of file AnimationComponent.cpp.

Referenced by Play().

◆ SetSkeleton()

void mnd::AnimationComponent::SetSkeleton ( const std::shared_ptr< Skeleton > &  skeleton)

Bind a skeleton to the component so skeletal clips can be evaluated.

Definition at line 105 of file AnimationComponent.cpp.

Referenced by mnd::ModelImporter::Import().

◆ StaticTypeId()

template<typename T >
static size_t mnd::Component::StaticTypeId ( )
inlinestaticinherited

Definition at line 50 of file Component.h.

◆ Stop()

void mnd::AnimationComponent::Stop ( )
inline

Halt playback. Pose freezes at the current frame.

Definition at line 133 of file AnimationComponent.h.

◆ Update()

void mnd::AnimationComponent::Update ( float  deltaTime)
overridevirtual

Advance playback time and write interpolated transforms to bound objects.

Parameters
deltaTimeSeconds since the previous frame.

Implements mnd::Component.

Definition at line 24 of file AnimationComponent.cpp.

References mnd::ComputePalette(), mnd::SkeletalAnimationClip::duration, mnd::AnimationClip::duration, mnd::EvaluatePose(), mnd::Pose::finalPalette, and mnd::AnimationClip::tracks.

Member Data Documentation

◆ m_owner


The documentation for this class was generated from the following files: