From 6fde17649f7404e79a17d4d8f96662d03011aca1 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Thu, 30 Oct 2025 20:08:53 -0700 Subject: Move animation module outside of scene/ --- include/gfx/animation.h | 139 +++++++++++++++++++++++++++++++++++++++++ include/gfx/scene.h | 1 - include/gfx/scene/animation.h | 140 ------------------------------------------ 3 files changed, 139 insertions(+), 141 deletions(-) create mode 100644 include/gfx/animation.h delete mode 100644 include/gfx/scene/animation.h (limited to 'include') diff --git a/include/gfx/animation.h b/include/gfx/animation.h new file mode 100644 index 0000000..b55e575 --- /dev/null +++ b/include/gfx/animation.h @@ -0,0 +1,139 @@ +#pragma once + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +typedef struct Buffer Buffer; + +typedef struct Anima Anima; +typedef struct Joint Joint; +typedef struct Skeleton Skeleton; + +/// Index type used to store relative indices into arrays. +typedef uint16_t joint_idx; + +/// Index value denoting no index. +static const joint_idx INDEX_NONE = (joint_idx)-1; + +typedef struct Box { + vec3 vertices[8]; +} Box; + +/// Joint descriptor. +typedef struct JointDesc { + joint_idx parent; /// Parent Joint; index into Anima's joints. + mat4 inv_bind_matrix; /// Transforms the mesh into the joint's local space. + aabb3 box; /// Bounding box. +} JointDesc; + +/// Skeleton descriptor. +typedef struct SkeletonDesc { + size_t num_joints; + joint_idx joints[GFX_MAX_NUM_JOINTS]; /// Indices into Anima's joints array. +} SkeletonDesc; + +/// Animation interpolation mode. +typedef enum AnimationInterpolation { + StepInterpolation, + LinearInterpolation, + CubicSplineInterpolation +} AnimationInterpolation; + +/// The kind of transformation applied by a Channel. +typedef enum ChannelType { + RotationChannel, + ScaleChannel, + TranslationChannel, + WeightsChannel +} ChannelType; + +/// Animation keyframe descriptor. +/// +/// The arrays should have as many entries as 'num_joints' in the SkeletonDesc. +typedef struct KeyframeDesc { + R time; // Start time in [0, end animation time] + union { + vec3 translation; + quat rotation; + }; +} KeyframeDesc; + +/// Animation channel descriptor. +typedef struct ChannelDesc { + joint_idx target; /// Index into Anima's joints array. + ChannelType type; + AnimationInterpolation interpolation; + size_t num_keyframes; + KeyframeDesc keyframes[GFX_MAX_NUM_KEYFRAMES]; +} ChannelDesc; + +/// Animation descriptor. +typedef struct AnimationDesc { + // TODO: Store a name hash for faster comparisons. + sstring name; // Animation name. Required for playback. + size_t num_channels; // Number of channels. + ChannelDesc channels[GFX_MAX_NUM_CHANNELS]; +} AnimationDesc; + +/// Anima object descriptor. +/// +/// The last joint of the joints array at index 'num_joints - 1' must be the +/// root of all skeletons; specifically, the root of all joints that otherwise +/// would have no parent (a skeleton need not have its own root and can be a set +/// of disjoint node hierarchies). +typedef struct AnimaDesc { + size_t num_skeletons; + size_t num_animations; + size_t num_joints; + SkeletonDesc skeletons[GFX_MAX_NUM_SKELETONS]; + AnimationDesc animations[GFX_MAX_NUM_ANIMATIONS]; + JointDesc joints[GFX_MAX_NUM_JOINTS]; +} AnimaDesc; + +/// Animation play settings. +typedef struct AnimationPlaySettings { + const char* name; // Animation name. + bool loop; // Whether to loop the animation or just play once. + // TODO: Add animation speed. +} AnimationPlaySettings; + +/// Create an anima object. +Anima* gfx_make_anima(const AnimaDesc*); + +/// Destroy the anima. +void gfx_destroy_anima(Anima**); + +/// Play an animation (sets the current animation). +bool gfx_play_animation(Anima*, const AnimationPlaySettings*); + +/// Update the current animation. +void gfx_update_animation(Anima*, R t); + +/// Stop the current animation. +void gfx_stop_animation(Anima*); + +/// Return the anima's ith skeleton. +const Skeleton* gfx_get_anima_skeleton(const Anima* anima, size_t i); + +/// Return the number of joints in the skeleton. +size_t gfx_get_skeleton_num_joints(const Skeleton*); + +/// Return true if the skeleton's ith joint has a bounding box. +/// +/// IK joints that do not directly transform vertices have no bounding box. +bool gfx_joint_has_box(const Anima*, const Skeleton*, size_t joint); + +/// Return the bounding box of the skeleton's ith joint. +/// +/// IK joints that do not directly transform vertices have no box. +Box gfx_get_joint_box(const Anima*, const Skeleton*, size_t joint); diff --git a/include/gfx/scene.h b/include/gfx/scene.h index e9a6a89..3098221 100644 --- a/include/gfx/scene.h +++ b/include/gfx/scene.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include diff --git a/include/gfx/scene/animation.h b/include/gfx/scene/animation.h deleted file mode 100644 index 11d8984..0000000 --- a/include/gfx/scene/animation.h +++ /dev/null @@ -1,140 +0,0 @@ -// TODO: Move outside of scene/ -#pragma once - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -typedef struct Buffer Buffer; - -typedef struct Anima Anima; -typedef struct Joint Joint; -typedef struct Skeleton Skeleton; - -/// Index type used to store relative indices into arrays. -typedef uint16_t joint_idx; - -/// Index value denoting no index. -static const joint_idx INDEX_NONE = (joint_idx)-1; - -typedef struct Box { - vec3 vertices[8]; -} Box; - -/// Joint descriptor. -typedef struct JointDesc { - joint_idx parent; /// Parent Joint; index into Anima's joints. - mat4 inv_bind_matrix; /// Transforms the mesh into the joint's local space. - aabb3 box; /// Bounding box. -} JointDesc; - -/// Skeleton descriptor. -typedef struct SkeletonDesc { - size_t num_joints; - joint_idx joints[GFX_MAX_NUM_JOINTS]; /// Indices into Anima's joints array. -} SkeletonDesc; - -/// Animation interpolation mode. -typedef enum AnimationInterpolation { - StepInterpolation, - LinearInterpolation, - CubicSplineInterpolation -} AnimationInterpolation; - -/// The kind of transformation applied by a Channel. -typedef enum ChannelType { - RotationChannel, - ScaleChannel, - TranslationChannel, - WeightsChannel -} ChannelType; - -/// Animation keyframe descriptor. -/// -/// The arrays should have as many entries as 'num_joints' in the SkeletonDesc. -typedef struct KeyframeDesc { - R time; // Start time in [0, end animation time] - union { - vec3 translation; - quat rotation; - }; -} KeyframeDesc; - -/// Animation channel descriptor. -typedef struct ChannelDesc { - joint_idx target; /// Index into Anima's joints array. - ChannelType type; - AnimationInterpolation interpolation; - size_t num_keyframes; - KeyframeDesc keyframes[GFX_MAX_NUM_KEYFRAMES]; -} ChannelDesc; - -/// Animation descriptor. -typedef struct AnimationDesc { - // TODO: Store a name hash for faster comparisons. - sstring name; // Animation name. Required for playback. - size_t num_channels; // Number of channels. - ChannelDesc channels[GFX_MAX_NUM_CHANNELS]; -} AnimationDesc; - -/// Anima object descriptor. -/// -/// The last joint of the joints array at index 'num_joints - 1' must be the -/// root of all skeletons; specifically, the root of all joints that otherwise -/// would have no parent (a skeleton need not have its own root and can be a set -/// of disjoint node hierarchies). -typedef struct AnimaDesc { - size_t num_skeletons; - size_t num_animations; - size_t num_joints; - SkeletonDesc skeletons[GFX_MAX_NUM_SKELETONS]; - AnimationDesc animations[GFX_MAX_NUM_ANIMATIONS]; - JointDesc joints[GFX_MAX_NUM_JOINTS]; -} AnimaDesc; - -/// Animation play settings. -typedef struct AnimationPlaySettings { - const char* name; // Animation name. - bool loop; // Whether to loop the animation or just play once. - // TODO: Add animation speed. -} AnimationPlaySettings; - -/// Create an anima object. -Anima* gfx_make_anima(const AnimaDesc*); - -/// Destroy the anima. -void gfx_destroy_anima(Anima**); - -/// Play an animation (sets the current animation). -bool gfx_play_animation(Anima*, const AnimationPlaySettings*); - -/// Update the current animation. -void gfx_update_animation(Anima*, R t); - -/// Stop the current animation. -void gfx_stop_animation(Anima*); - -/// Return the anima's ith skeleton. -const Skeleton* gfx_get_anima_skeleton(const Anima* anima, size_t i); - -/// Return the number of joints in the skeleton. -size_t gfx_get_skeleton_num_joints(const Skeleton*); - -/// Return true if the skeleton's ith joint has a bounding box. -/// -/// IK joints that do not directly transform vertices have no bounding box. -bool gfx_joint_has_box(const Anima*, const Skeleton*, size_t joint); - -/// Return the bounding box of the skeleton's ith joint. -/// -/// IK joints that do not directly transform vertices have no box. -Box gfx_get_joint_box(const Anima*, const Skeleton*, size_t joint); -- cgit v1.2.3