Tramway SDK
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
tram::AnimationComponent Class Reference

Plays back Animations. More...

#include <components/animation.h>

Inheritance diagram for tram::AnimationComponent:
tram::EntityComponent

Classes

struct  AnimationPlaybackInfo
 

Public Member Functions

void Start ()
 
void SetModel (Render::Model *model)
 
void SetModel (name_t model)
 
Render::ModelGetModel ()
 
Render::PoseGetPose ()
 
void SetKeyframe (name_t bone_name, const Render::Keyframe &keyframe)
 Sets procedural animation keyframe. More...
 
void SetOnAnimationFinishCallback (void(*callback)(AnimationComponent *, name_t))
 
void Play (name_t animation_name, uint32_t repeats, float weight, float speed, bool interpolate=true, bool pause_on_last_frame=false)
 Plays an animation. More...
 
bool IsPlaying (name_t animation_name)
 Returns true if an animation is playing. More...
 
void Stop (name_t animation_name)
 Stops an animation if its playing. More...
 
void Pause (name_t animation_name)
 Pauses an animation. More...
 
void Continue (name_t animation_name)
 Continues an animation. More...
 
void SetWeight (name_t animation_name, float weight)
 Sets the weight of an animation. More...
 
void SetSpeed (name_t animation_name, float speed)
 Sets the speed of an animation. More...
 
void SetRepeats (name_t animation_name, uint32_t repeats)
 Sets the repeats of an animation. More...
 
void FadeIn (name_t animation_name, float length)
 Fades in an animation. More...
 
void FadeOut (name_t animation_name, float length)
 Fades out an animation. More...
 
void SetPause (name_t animation_name, bool pause)
 Sets animation's pause state. More...
 
void SetFade (name_t animation_name, bool fade_in, float fade_length)
 Fades in or fades out an animation. More...
 
void SetFrame (name_t animation_name, float frame)
 Sets an animation to a specific frame. More...
 
void Reparent (name_t bone_name, name_t new_parent)
 Reparents a bone. More...
 
void Refresh ()
 Updates an armature. More...
 
void EventHandler (Event &event)
 
- Public Member Functions inherited from tram::EntityComponent
 EntityComponent ()=default
 
virtual ~EntityComponent ()=default
 
virtual void Init ()
 Initializes an entity component. More...
 
bool IsReady ()
 Returns the component's readiness. More...
 
bool IsInit ()
 Returns the component's init status. More...
 
EntityGetParent ()
 
void SetParent (Entity *parent)
 

Static Public Member Functions

static bool IsDebugInfoDraw ()
 Checks whether the debug text is drawn. More...
 
static void SetDebugInfoDraw (bool draw)
 Sets the drawing of debug info. More...
 
static void Update ()
 Updates all of the armatures. More...
 

Protected Member Functions

void FindKeyframePointers (Render::Animation *animation, size_t animation_index)
 Extracts pointers to keyframes from animation data. More...
 
 AnimationComponent ()
 
 ~AnimationComponent ()
 
- Protected Member Functions inherited from tram::EntityComponent
void ResourceReady ()
 Notifies the component of a streamed-in resource. More...
 

Protected Attributes

Render::Keyframe base_pose [Render::BONE_COUNT]
 
Render::Posepose = nullptr
 
ResourceProxy< Render::Modelmodel
 
void(* anim_finish_callback )(AnimationComponent *, name_t) = nullptr
 
const Render::Bonearmature_bones = nullptr
 
size_t armature_bone_count = 0
 
int32_t armature_bone_parents [Render::BONE_COUNT] = {-1}
 
name_t anim_playing [ANIM_COUNT]
 
AnimationPlaybackInfo anim_info [ANIM_COUNT]
 
- Protected Attributes inherited from tram::EntityComponent
size_t resources_waiting = 0
 
bool is_ready = false
 
bool is_init = false
 
Entityparent = nullptr
 

Static Protected Attributes

static const size_t ANIM_COUNT = 8
 

Friends

template<typename >
class Pool
 

Detailed Description

Plays back Animations.

See also
https://racenis.github.io/tram-sdk/documentation/components/animation.html

Constructor & Destructor Documentation

◆ AnimationComponent()

tram::AnimationComponent::AnimationComponent ( )
protected

◆ ~AnimationComponent()

tram::AnimationComponent::~AnimationComponent ( )
protected

Member Function Documentation

◆ Continue()

void tram::AnimationComponent::Continue ( name_t  animation_name)

Continues an animation.

If an animation is paused, it will continue playback. Otherwise this method will do nothing.

◆ EventHandler()

void tram::AnimationComponent::EventHandler ( Event event)
inlinevirtual

Implements tram::EntityComponent.

◆ FadeIn()

void tram::AnimationComponent::FadeIn ( name_t  animation_name,
float  speed 
)

Fades in an animation.

Before fading in an animation, it must be started with Play().

◆ FadeOut()

void tram::AnimationComponent::FadeOut ( name_t  animation_name,
float  length 
)

Fades out an animation.

◆ FindKeyframePointers()

void tram::AnimationComponent::FindKeyframePointers ( Render::Animation animation,
size_t  animation_index 
)
protected

Extracts pointers to keyframes from animation data.

◆ GetModel()

Render::Model * tram::AnimationComponent::GetModel ( )
inline

◆ GetPose()

Render::Pose * tram::AnimationComponent::GetPose ( )
inline

◆ IsDebugInfoDraw()

bool tram::AnimationComponent::IsDebugInfoDraw ( )
static

Checks whether the debug text is drawn.

Check SetDebugInfoDraw() for more info.

◆ IsPlaying()

bool tram::AnimationComponent::IsPlaying ( name_t  animation_name)

Returns true if an animation is playing.

◆ Pause()

void tram::AnimationComponent::Pause ( name_t  animation_name)

Pauses an animation.

If the animation is being played, it will be paused. Otherwise this method will do nothing. Use Continue() method to continue playing the animation.

◆ Play()

void tram::AnimationComponent::Play ( name_t  animation_name,
uint32_t  repeats,
float  weight,
float  speed,
bool  interpolate = true,
bool  pause_on_last_frame = false 
)

Plays an animation.

Animation must be already loaded before playing.

Note
Will not play an animation if there are no empty animation slots.
Parameters
animation_nameName of the animation to be played.
repeatsHow many times the animation will be looped before stopping.
weightWeight of the animation. Set to 1.0 for normal weight. Should be in range from 0.0 to 1.0, if set outside of range, then the animation might look really weird.
speedSpeed of the animation. Value of 1.0 will play the animation at regular speed, 0.5 will play it half speed, 2.0 double speed.
interpolateIf set to true, then animation will be interpolated, if set to false, then it will use only the latest keyframe.
pause_on_lastIf set to true, then the animation will pause on the last keyframe.

◆ Refresh()

void tram::AnimationComponent::Refresh ( )

Updates an armature.

Pushes animations forward and regenerates matrices.

◆ Reparent()

void tram::AnimationComponent::Reparent ( name_t  bone_name,
name_t  new_parent 
)

Reparents a bone.

Make sure to not create cycles in the bone hierarchy.

Parameters
bone_nameName of the bone for which a new parent will be set.
new_parentName of the bone which will be the new parent. Can be set to "none" to clear the bone's parent.

◆ SetDebugInfoDraw()

void tram::AnimationComponent::SetDebugInfoDraw ( bool  draw)
static

Sets the drawing of debug info.

If set to true, each frame some debug text will be drawn for each animation component. This is useful for debugging.

◆ SetFade()

void tram::AnimationComponent::SetFade ( name_t  animation_name,
bool  fade_in,
float  fade_length 
)

Fades in or fades out an animation.

This will gradually increase or decrease the weight of an animation until it is fully faded in or faded out. The animation must already be started with Play() for it to be faded, otherwise this method will do nothing. If an animation is fully faded out, it will automatically be stopped.

Parameters
animation_nameName of the animation to be faded.
fade_inSet to true, if animation is to be faded in, false if faded out.
fade_lengthHow long, in seconds, will it take for the animation to finish fading in/out.

◆ SetFrame()

void tram::AnimationComponent::SetFrame ( name_t  animation_name,
float  frame 
)

Sets an animation to a specific frame.

If the animation is not already started with Play(), then this method will do nothing.

◆ SetKeyframe()

void tram::AnimationComponent::SetKeyframe ( name_t  bone_name,
const Render::Keyframe keyframe 
)

Sets procedural animation keyframe.

◆ SetModel() [1/2]

void tram::AnimationComponent::SetModel ( name_t  model)
inline

◆ SetModel() [2/2]

void tram::AnimationComponent::SetModel ( Render::Model model)
inline

◆ SetOnAnimationFinishCallback()

void tram::AnimationComponent::SetOnAnimationFinishCallback ( void(*)(AnimationComponent *, name_t callback)
inline

◆ SetPause()

void tram::AnimationComponent::SetPause ( name_t  animation_name,
bool  pause 
)

Sets animation's pause state.

This will do nothing, if the animation is not playing. Pausing an already paused or continuing an already playing animation will do nothing.

Parameters
animation_nameName of the animation to pause.
pauseSet to true to pause the animation, set to false to continue.

◆ SetRepeats()

void tram::AnimationComponent::SetRepeats ( name_t  animation_name,
uint32_t  repeats 
)

Sets the repeats of an animation.

◆ SetSpeed()

void tram::AnimationComponent::SetSpeed ( name_t  animation_name,
float  speed 
)

Sets the speed of an animation.

◆ SetWeight()

void tram::AnimationComponent::SetWeight ( name_t  animation_name,
float  weight 
)

Sets the weight of an animation.

◆ Start()

void tram::AnimationComponent::Start ( )
virtual

Implements tram::EntityComponent.

◆ Stop()

void tram::AnimationComponent::Stop ( name_t  animation_name)

Stops an animation if its playing.

Will do nothing if the animation is not playing.

◆ Update()

void tram::AnimationComponent::Update ( )
static

Updates all of the armatures.

This static function calls the Refresh() method on all of the ArmatureComponents.

Friends And Related Function Documentation

◆ Pool

template<typename >
friend class Pool
friend

Member Data Documentation

◆ ANIM_COUNT

const size_t tram::AnimationComponent::ANIM_COUNT = 8
staticprotected

◆ anim_finish_callback

void(* tram::AnimationComponent::anim_finish_callback) (AnimationComponent *, name_t) = nullptr
protected

◆ anim_info

AnimationPlaybackInfo tram::AnimationComponent::anim_info[ANIM_COUNT]
protected

◆ anim_playing

name_t tram::AnimationComponent::anim_playing[ANIM_COUNT]
protected

◆ armature_bone_count

size_t tram::AnimationComponent::armature_bone_count = 0
protected

◆ armature_bone_parents

int32_t tram::AnimationComponent::armature_bone_parents[Render::BONE_COUNT] = {-1}
protected

◆ armature_bones

const Render::Bone* tram::AnimationComponent::armature_bones = nullptr
protected

◆ base_pose

Render::Keyframe tram::AnimationComponent::base_pose[Render::BONE_COUNT]
protected

◆ model

ResourceProxy<Render::Model> tram::AnimationComponent::model
protected

◆ pose

Render::Pose* tram::AnimationComponent::pose = nullptr
protected

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