Tramway SDK
animation.h
Go to the documentation of this file.
1// Tramway Drifting and Dungeon Exploration Simulator SDK Runtime
2
3#ifndef TRAM_SDK_ARMATURE_H
4#define TRAM_SDK_ARMATURE_H
5
6#include <unordered_map>
7
8#include <framework/core.h>
9#include <framework/uid.h>
10#include <framework/resource.h>
11
12#include <framework/math.h>
13
14namespace tram::Render {
15
16typedef std::pair<name_t, uint64_t> NameCount; // animation header
17const size_t BONE_COUNT = 30; // bone count in a pose
18
19struct Bone {
21 int32_t parent = -1;
22 vec3 head = {0.0f, 0.0f, 0.0f};
23 vec3 tail = {1.0f, 1.0f, 1.0f};
24 float roll = 0.0f;
25};
26
27struct Keyframe {
28 float frame = 0.0f;
29 vec3 location = {0.0f, 0.0f, 0.0f};
30 quat rotation = {1.0f, 0.0f, 0.0f, 0.0f};
31 vec3 scale = {1.0f, 1.0f, 1.0f};
32 char padding[4]; // for emscripten ??
33};
34
35struct Pose {
37};
38
43};
44
45class Animation : public Resource {
46public:
48
50 uint32_t GetKeyframeCount(name_t bone);
51
52 inline KeyframeHeader* GetHeader(uint32_t index) { return &headers[index]; }
53 inline uint32_t GetHeaderCount() { return header_count; }
54
55 void LoadFromDisk();
57
58 void Unload();
59
60 static Animation* Find(name_t name);
61 static void LoadAll();
62private:
63 Keyframe* keyframes = nullptr;
64
65 KeyframeHeader* headers = nullptr;
66 uint32_t header_count = 0;
67};
68
69}
70
71#endif // TRAM_SDK_ARMATURE_H
Skeletal animation for a 3D model.
Definition: animation.h:45
void LoadFromMemory()
Definition: animation.h:56
uint32_t GetKeyframeCount(name_t bone)
Definition: animation.cpp:170
uint32_t GetHeaderCount()
Definition: animation.h:53
KeyframeHeader * GetHeader(uint32_t index)
Definition: animation.h:52
void LoadFromDisk()
Definition: animation.cpp:91
static Animation * Find(name_t name)
Definition: animation.cpp:180
void Unload()
Definition: animation.cpp:156
Animation(name_t name)
Definition: animation.h:47
Keyframe * GetKeyframes(name_t bone)
Definition: animation.cpp:160
Definition: resource.h:11
name_t name
Definition: resource.h:37
High-level Render system API.
Definition: gui.h:8
std::pair< name_t, uint64_t > NameCount
Definition: animation.h:16
const size_t BONE_COUNT
Definition: animation.h:17
glm::vec3 vec3
Definition: math.h:11
glm::quat quat
Definition: math.h:12
glm::mat4 mat4
Definition: math.h:14
Bone for a 3D models skeleton.
Definition: animation.h:19
float roll
Rotation of the bone.
Definition: animation.h:24
int32_t parent
Parent index of the bone.
Definition: animation.h:21
name_t name
Unique identifier for the bone.
Definition: animation.h:20
vec3 head
Origin of the bone.
Definition: animation.h:22
vec3 tail
Direction of the bone.
Definition: animation.h:23
Definition: animation.h:39
uint32_t keyframe_offset
Definition: animation.h:41
uint32_t keyframe_count
Definition: animation.h:42
name_t bone
Definition: animation.h:40
Keyframe for a skeletal animation.
Definition: animation.h:27
float frame
Used only when keyframes are used in the context of an animation.
Definition: animation.h:28
char padding[4]
Definition: animation.h:32
vec3 location
Definition: animation.h:29
vec3 scale
Definition: animation.h:31
quat rotation
Definition: animation.h:30
Definition: animation.h:35
mat4 pose[BONE_COUNT]
Definition: animation.h:36
Interned string type.
Definition: uid.h:10