Foundation
Loading...
Searching...
No Matches
Animation.hpp
Go to the documentation of this file.
1#pragma once
2#include <Core/Container.hpp>
3#include <Math/Math.hpp>
4#include "Mesh.hpp"
5
6using namespace Foundation;
7using namespace Core;
8using namespace Math;
9
30struct FJoint
31{
32 int32_t parent{-1}; // parent joint index (< this joint's index), or -1 for a root
33 float3 restTranslation{0, 0, 0}; // rest-pose local TRS (used when a channel is absent)
34 quat restRotation{0, 0, 0, 1};
35 float3 restScale{1, 1, 1};
36 mat4 inverseBind{1.0f}; // bind space -> joint space; identity for pure articulation
37};
38
43{
45 explicit FSkeleton(Allocator* alloc = GLOBAL_ALLOC) : joints(alloc) {}
46 [[nodiscard]] uint32_t Count() const { return static_cast<uint32_t>(joints.size()); }
47};
48
50enum class FAnimPath : uint8_t
51{
54 Scale,
55};
56
58enum class FAnimInterp : uint8_t
59{
60 Step,
61 Linear,
63};
64
81
88{
90 float duration{0.0f};
91 int32_t skeleton{-1};
92 explicit FAnimationClip(Allocator* alloc = GLOBAL_ALLOC) : channels(alloc) {}
93};
94
101struct FPose
102{
107 explicit FPose(Allocator* alloc = GLOBAL_ALLOC)
108 : translations(alloc), rotations(alloc), scales(alloc), globals(alloc)
109 {
110 }
111 void Resize(uint32_t jointCount);
112};
113
115[[nodiscard]] mat4 JointLocalMatrix(float3 const& t, quat const& r, float3 const& s);
116
118void ResetToRest(FSkeleton const& skel, FPose& pose);
119
125void SampleClip(FAnimationClip const& clip, float t, FPose& pose);
126
128void ComputeGlobals(FSkeleton const& skel, FPose& pose);
129
136void SampleTrack(Span<const float> times, Span<const float> values, uint32_t comps, FAnimInterp interp, float t,
137 Span<float> out);
138
143void ComputeSkinningMatrices(FSkeleton const& skel, FPose const& pose, Span<mat4> outPalette);
144
154 Span<FQVertex> out);
155
#define GLOBAL_ALLOC
Definition Allocator.hpp:225
FAnimInterp
Keyframe interpolation mode (mirrors glTF sampler interpolation).
Definition Animation.hpp:59
FAnimPath
Which local TRS component an animation channel drives.
Definition Animation.hpp:51
void SampleClip(FAnimationClip const &clip, float t, FPose &pose)
Samples a clip at time t, overwriting the seeded local TRS for every channel's joint.
Definition Animation.cpp:110
void RecomputeNormals(Span< FVertex > verts, Span< const uint32_t > indices)
Recomputes smooth per-vertex normals from positions over an indexed triangle list.
Definition Animation.cpp:226
void ResetToRest(FSkeleton const &skel, FPose &pose)
Seeds a pose's local TRS from the skeleton rest pose (call before SampleClip).
Definition Animation.cpp:99
void SkinVertices(Span< const FVertex > bind, Span< const FSkinBinding > binding, Span< const mat4 > palette, Span< FQVertex > out)
Linear-blend skins bind-pose vertices by the palette, packing results for the dynamic ring.
Definition Animation.cpp:190
void SampleTrack(Span< const float > times, Span< const float > values, uint32_t comps, FAnimInterp interp, float t, Span< float > out)
Samples a generic keyframed track of comps-wide values at time t into out.
Definition Animation.cpp:140
void ComputeSkinningMatrices(FSkeleton const &skel, FPose const &pose, Span< mat4 > outPalette)
Builds the skinning palette globals[j] * inverseBind[j] into outPalette.
Definition Animation.cpp:182
mat4 JointLocalMatrix(float3 const &t, quat const &r, float3 const &s)
Composes a joint's local TRS into a matrix (T * R * S).
Definition Animation.cpp:86
void ComputeGlobals(FSkeleton const &skel, FPose &pose)
Walks the hierarchy, composing local TRS into world matrices in FPose::globals.
Definition Animation.cpp:126
General Purpose Allocator (GPA) interface.
Definition Allocator.hpp:24
std::vector< T, StlAllocator< T > > Vector
std::vector with explicit Foundation::Core::StlAllocator constructor
Definition Container.hpp:130
std::span< T > Span
Alias for std::span
Definition Container.hpp:60
vec3 float3
Definition Math.hpp:26
Definition Allocator.hpp:5
A single animated component of a single joint: sorted keyframe times + packed values.
Definition Animation.hpp:73
Vector< float > times
Definition Animation.hpp:77
FAnimPath path
Definition Animation.hpp:75
FAnimChannel(Allocator *alloc=GLOBAL_ALLOC)
Definition Animation.hpp:79
uint32_t joint
Definition Animation.hpp:74
FAnimInterp interp
Definition Animation.hpp:76
Vector< float > values
Definition Animation.hpp:78
A clip: a set of channels plus its total duration (seconds).
Definition Animation.hpp:88
int32_t skeleton
Definition Animation.hpp:91
FAnimationClip(Allocator *alloc=GLOBAL_ALLOC)
Definition Animation.hpp:92
float duration
Definition Animation.hpp:90
Vector< FAnimChannel > channels
Definition Animation.hpp:89
One node of a transform hierarchy (a skeleton joint or an articulation node).
Definition Animation.hpp:31
int32_t parent
Definition Animation.hpp:32
float3 restTranslation
Definition Animation.hpp:33
float3 restScale
Definition Animation.hpp:35
quat restRotation
Definition Animation.hpp:34
mat4 inverseBind
Definition Animation.hpp:36
Reusable per-instance evaluation scratch for one skeleton (allocate once, reuse per frame).
Definition Animation.hpp:102
Vector< mat4 > globals
Definition Animation.hpp:106
FPose(Allocator *alloc=GLOBAL_ALLOC)
Definition Animation.hpp:107
Vector< quat > rotations
Definition Animation.hpp:104
Vector< float3 > scales
Definition Animation.hpp:105
Vector< float3 > translations
Definition Animation.hpp:103
void Resize(uint32_t jointCount)
Definition Animation.cpp:91
A flat skeleton: the only hierarchy the animation layer retains, owned by the asset.
Definition Animation.hpp:43
FSkeleton(Allocator *alloc=GLOBAL_ALLOC)
Definition Animation.hpp:45
Vector< FJoint > joints
Definition Animation.hpp:44
uint32_t Count() const
Definition Animation.hpp:46