Tramway SDK
animation.h
Go to the documentation of this file.
1// TRAMWAY DRIFT AND DUNGEON EXPLORATION SIMULATOR 2022
2// All rights reserved.
3
4#ifndef TRAM_SDK_COMPONENTS_ARMATURECOMPONENT_H
5#define TRAM_SDK_COMPONENTS_ARMATURECOMPONENT_H
6
7#include <framework/core.h>
9#include <render/render.h>
10#include <render/model.h>
11
12namespace tram {
14public:
15 void Init();
16 void Start();
17 void SetModel(Render::Model* model) { this->model = model; }
18 void SetModel(name_t model) { this->model = Render::Model::Find(model); }
19 Render::Model* GetModel() { return model.get(); }
20 Render::Pose* GetPose() { return pose; }
21
22 void SetKeyframe(name_t bone_name, const Render::Keyframe& keyframe);
24
25 void Play(name_t animation_name, uint32_t repeats, float weight, float speed, bool interpolate = true, bool pause_on_last_frame = false);
26 bool IsPlaying(name_t animation_name);
27 void Stop(name_t animation_name);
28 void Pause(name_t animation_name);
29 void Continue(name_t animation_name);
30
31 void SetWeight(name_t animation_name, float weight);
32 void SetSpeed(name_t animation_name, float speed);
33 void SetRepeats(name_t animation_name, uint32_t repeats);
34
35 void FadeIn(name_t animation_name, float length);
36 void FadeOut(name_t animation_name, float length);
37
38 void SetPause(name_t animation_name, bool pause);
39 void SetFade(name_t animation_name, bool fade_in, float fade_length);
40 void SetFrame(name_t animation_name, float frame);
41
42 void Refresh();
43 void EventHandler(Event &event) { return; }
44 static void Update();
45protected:
46 static const size_t ANIM_COUNT = 8;
48 uint32_t repeats;
49 float weight;
50 float speed;
51 float frame;
55 bool fade_in;
57 bool pause;
61 };
62
63 void FindKeyframePointers(size_t animation_index);
64
66
67 Render::Pose* pose = nullptr;
69
71
72 const Render::Bone* armature_bones = nullptr;
73 size_t armature_bone_count = 0;
74 int32_t armature_bone_parents[Render::BONE_COUNT] = {-1};
75
78
81 template <typename> friend class Pool;
82};
83
84}
85
86#endif // TRAM_SDK_COMPONENTS_ARMATURECOMPONENT_H
Definition: animation.h:13
ResourceProxy< Render::Model > model
Definition: animation.h:68
Render::Pose * GetPose()
Definition: animation.h:20
Render::Model * GetModel()
Definition: animation.h:19
bool IsPlaying(name_t animation_name)
Returns true if an animation is playing.
Definition: animation.cpp:233
void Stop(name_t animation_name)
Stops an animation if its playing.
Definition: animation.cpp:147
void SetFade(name_t animation_name, bool fade_in, float fade_length)
Fades in or fades out an animation.
Definition: animation.cpp:252
void FindKeyframePointers(size_t animation_index)
Extracts pointers to keyframes from animation data.
Definition: animation.cpp:119
AnimationPlaybackInfo anim_info[ANIM_COUNT]
Definition: animation.h:77
void SetKeyframe(name_t bone_name, const Render::Keyframe &keyframe)
Sets procedural animation keyframe.
Definition: animation.cpp:54
void SetWeight(name_t animation_name, float weight)
Sets the weight of an animation.
Definition: animation.cpp:203
static void Update()
Updates all of the armatures.
Definition: animation.cpp:266
void Start()
Definition: animation.cpp:34
void SetPause(name_t animation_name, bool pause)
Sets animation's pause state.
Definition: animation.cpp:168
void Pause(name_t animation_name)
Pauses an animation.
Definition: animation.cpp:180
void SetOnAnimationFinishCallback(void(*callback)(AnimationComponent *, name_t))
Definition: animation.h:23
void SetModel(Render::Model *model)
Definition: animation.h:17
Render::Pose * pose
Definition: animation.h:67
name_t anim_playing[ANIM_COUNT]
Definition: animation.h:74
void SetFrame(name_t animation_name, float frame)
Sets an animation to a specific frame.
Definition: animation.cpp:273
void FadeIn(name_t animation_name, float length)
Fades in an animation.
Definition: animation.cpp:193
void SetRepeats(name_t animation_name, uint32_t repeats)
Sets the repeats of an animation.
Definition: animation.cpp:223
void(* anim_finish_callback)(AnimationComponent *, name_t)
Definition: animation.h:70
~AnimationComponent()
Definition: animation.cpp:24
void SetSpeed(name_t animation_name, float speed)
Sets the speed of an animation.
Definition: animation.cpp:213
void Continue(name_t animation_name)
Continues an animation.
Definition: animation.cpp:187
void Init()
Definition: animation.cpp:10
void EventHandler(Event &event)
Definition: animation.h:43
void SetModel(name_t model)
Definition: animation.h:18
static const size_t ANIM_COUNT
Definition: animation.h:46
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.
Definition: animation.cpp:76
void FadeOut(name_t animation_name, float length)
Fades out an animation.
Definition: animation.cpp:198
AnimationComponent()
Definition: animation.h:79
Render::Keyframe base_pose[Render::BONE_COUNT]
Definition: animation.h:65
void Refresh()
Updates an armature.
Definition: animation.cpp:284
Definition: entitycomponent.h:18
Definition: pool.h:14
Definition: model.h:28
static Model * Find(name_t name)
Definition: model.cpp:32
Definition: resource.h:47
std::pair< name_t, uint64_t > NameCount
Definition: animation.h:17
const size_t BONE_COUNT
Definition: animation.h:18
Definition: api.h:9
UID name_t
Definition: uid.h:40
bool fade_out
Definition: animation.h:56
float fade_speed
Definition: animation.h:52
bool fade_in
Definition: animation.h:55
bool pause_on_last_frame
Definition: animation.h:58
float speed
Definition: animation.h:50
bool interpolate
Definition: animation.h:54
bool pause
Definition: animation.h:57
Render::NameCount * keyframe_headers[Render::BONE_COUNT]
Definition: animation.h:60
uint32_t repeats
Definition: animation.h:48
float weight
Definition: animation.h:49
Render::NameCount * animation_header
Definition: animation.h:59
float frame
Definition: animation.h:51
float fade_ammount
Definition: animation.h:53
Definition: event.h:24
Definition: animation.h:20
Definition: animation.h:28
Definition: animation.h:36
Definition: uid.h:11