aboutsummaryrefslogtreecommitdiff
path: root/src/scene/animation_impl.h
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2025-06-27 10:18:39 -0700
committer3gg <3gg@shellblade.net>2025-06-27 10:18:39 -0700
commitbd57f345ed9dbed1d81683e48199626de2ea9044 (patch)
tree4221f2f2a7ad2244d2e93052bd68187ec91b8ea9 /src/scene/animation_impl.h
parent9a82ce0083437a4f9f58108b2c23b957d2249ad8 (diff)
Restructure projectHEADmain
Diffstat (limited to 'src/scene/animation_impl.h')
-rw-r--r--src/scene/animation_impl.h98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/scene/animation_impl.h b/src/scene/animation_impl.h
new file mode 100644
index 0000000..4408158
--- /dev/null
+++ b/src/scene/animation_impl.h
@@ -0,0 +1,98 @@
1#pragma once
2
3#include <gfx/scene/animation.h>
4#include <gfx/sizes.h>
5
6#include "types.h"
7
8#include <cstring.h>
9#include <math/defs.h>
10#include <math/mat4.h>
11#include <math/quat.h>
12#include <math/vec3.h>
13
14#include <stddef.h>
15#include <stdint.h>
16
17typedef struct Buffer Buffer;
18
19// Currently ignoring scale in skinning and animation.
20//
21// TODO: Simultaneous animation of disjoint animations.
22
23/// Skeleton joint.
24/// Joints are mutable and store the transform and joint matrices that result
25/// from animation, aside from the inverse bind matrix.
26typedef struct Joint {
27 joint_idx child; /// First child Joint; index into Anima's joints.
28 joint_idx next; /// Next sibling Joint; index into Anima's joints.
29 mat4 transform; /// Local transform relative to parent.
30 mat4 inv_bind_matrix; /// Transforms the mesh into the joint's local space.
31 mat4 joint_matrix; /// inv(global) * global joint transform * inv(bind).
32 aabb3 box; /// Bounding box of vertices affected by joint.
33} Joint;
34
35/// Animation skeleton.
36typedef struct Skeleton {
37 skeleton_idx next;
38 size_t num_joints;
39 joint_idx joints[GFX_MAX_NUM_JOINTS]; /// Indices into Anima's joints array.
40} Skeleton;
41
42/// A keyframe of animation.
43typedef struct Keyframe {
44 R time; /// Start time in [0, end animation time]
45 union {
46 vec3 translation;
47 quat rotation;
48 };
49} Keyframe;
50
51/// Animation channel.
52typedef struct Channel {
53 joint_idx target; /// Index into Anima's joints array.
54 ChannelType type;
55 AnimationInterpolation interpolation;
56 size_t num_keyframes;
57 Keyframe keyframes[GFX_MAX_NUM_KEYFRAMES];
58} Channel;
59
60/// A skeletal animation.
61typedef struct Animation {
62 animation_idx next;
63 sstring name;
64 R duration;
65 size_t num_channels;
66 Channel channels[GFX_MAX_NUM_CHANNELS];
67} Animation;
68
69/// Animation state.
70///
71/// This represents the current state of an animation.
72typedef struct AnimationState {
73 R start_time; // Time when the current animation started playing. -1 means the
74 // animation playback has not yet been initialized.
75 animation_idx animation; // Current animation. 0 = no animation.
76 bool loop;
77} AnimationState;
78
79/// Animation object.
80///
81/// This is the top-level animation object that encapsulates everything
82/// necessary for animation.
83///
84/// For lack of a better name, this is called an Anima. It is short and the
85/// Latin root of animation.
86///
87/// The last joint of the joints array at index 'num_joints - 1' is the root of
88/// all skeletons; specifically, the root of all joints that otherwise would
89/// have no parent (a skeleton need not have its own root and can be a set of
90/// disjoint node hierarchies).
91typedef struct Anima {
92 node_idx parent; /// Parent SceneNode.
93 skeleton_idx skeleton; /// Index of first skeleton.
94 animation_idx animation; /// Index of first animation.
95 AnimationState state; /// Current animation state.
96 size_t num_joints; /// Number of actual joints in the array.
97 Joint joints[GFX_MAX_NUM_JOINTS]; /// Shared by all skeletons.
98} Anima;