euv_core/game/engine3d/animation/struct.rs
1use super::*;
2
3/// Single timestamped 3D transform keyframe inside an `AnimationClip3D`.
4#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
5pub struct Keyframe3D {
6 /// Keyframe time offset in seconds.
7 #[get(type(copy))]
8 pub(crate) time_secs: f32,
9 /// Local joint or node transform at `time_secs`.
10 #[get(type(copy))]
11 pub(crate) transform: Transform3D,
12}
13
14/// Named bone joint inside a hierarchical `SkeletonRig3D`.
15#[derive(Clone, Data, Debug, PartialEq)]
16pub struct SkeletonJoint3D {
17 /// Human-readable joint identifier (e.g., `"root"`, `"spine"`, `"turret"`).
18 pub(crate) name: String,
19 /// Optional parent joint index (`None` for root bone).
20 #[get(skip)]
21 pub(crate) parent: Option<usize>,
22 /// Bind-pose local transform relative to parent.
23 #[get(type(copy))]
24 pub(crate) rest_transform: Transform3D,
25}
26
27/// Per-joint keyframe track animating one joint index over time.
28#[derive(Clone, Data, Debug, PartialEq)]
29pub struct JointTrack3D {
30 /// Target joint index inside `SkeletonRig3D::joints`.
31 #[get(type(copy))]
32 pub(crate) joint_index: usize,
33 /// Chronologically sorted keyframes.
34 pub(crate) keyframes: Vec<Keyframe3D>,
35}
36
37/// Reusable skeletal/transform animation clip with duration and looping control.
38#[derive(Clone, Data, Debug, PartialEq)]
39pub struct AnimationClip3D {
40 /// Clip name.
41 pub(crate) name: String,
42 /// Total clip duration in seconds.
43 #[get(type(copy))]
44 pub(crate) duration_secs: f32,
45 /// Whether playback wraps seamlessly at `duration_secs`.
46 #[get(type(copy))]
47 pub(crate) looping: bool,
48 /// Per-joint keyframe tracks.
49 pub(crate) tracks: Vec<JointTrack3D>,
50}
51
52/// Per-vertex 4-bone linear-blend skeletal skinning weights.
53#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
54pub struct SkinWeight3D {
55 /// Four influencing joint indices into `SkeletonRig3D::joints`.
56 #[get(type(copy))]
57 pub(crate) joint_indices: [u16; 4],
58 /// Normalized blend weights corresponding to `joint_indices`.
59 #[get(type(copy))]
60 pub(crate) weights: [f32; 4],
61}
62
63/// Hierarchical 3D skeletal rig evaluating forward kinematics across bone chains.
64#[derive(Clone, Data, Debug, Default, PartialEq)]
65pub struct SkeletonRig3D {
66 /// Ordered joint hierarchy (parents precede children).
67 pub(crate) joints: Vec<SkeletonJoint3D>,
68}
69
70/// Real Blender/glTF 2.0 armature skin binding scene-graph joints and inverse bind matrices for LBS and DQS deformation.
71#[derive(Clone, Data, Debug, Default, PartialEq)]
72pub struct Skin3D {
73 /// Human-readable armature or skin label.
74 pub(crate) name: String,
75 /// Ordered joint node indices into `SceneGraph3D::nodes`.
76 pub(crate) joints: Vec<u32>,
77 /// Optional skeleton root node index inside `SceneGraph3D::nodes`.
78 #[get(type(copy))]
79 pub(crate) skeleton_root: Option<u32>,
80 /// Column-major inverse bind matrices aligned 1:1 with `joints`.
81 pub(crate) inverse_bind_matrices: Vec<Mat4>,
82 /// Active deformation mode (`LinearBlend` or `DualQuaternion`).
83 #[get(type(copy))]
84 pub(crate) skinning_mode: SkinningMode,
85}
86
87/// Reusable pre-allocated skinning and shape-key scratch arena guaranteeing zero steady-state heap allocations per frame.
88#[derive(Clone, Data, Debug, Default, PartialEq)]
89pub struct SkinPaletteScratch3D {
90 /// Reusable bone palette matrices `inv(M_mesh_world) * M_joint_world[j] * M_inv_bind[j]`.
91 pub(crate) skin_matrices: Vec<Mat4>,
92 /// Reusable exact cofactor 3x3 normal bases aligned 1:1 with `skin_matrices`.
93 pub(crate) skin_normal_matrices: Vec<[Vec3; 3]>,
94 /// Reusable rigid dual quaternions aligned 1:1 with `skin_matrices` for volume-preserving DQS.
95 pub(crate) skin_dual_quats: Vec<DualQuat>,
96 /// Reusable post-morph intermediate vertex buffer (applied before skinning).
97 pub(crate) morphed_vertices: Vec<Vertex3D>,
98 /// Reusable final deformed vertex buffer output by LBS or DQS skinning.
99 pub(crate) skinned_vertices: Vec<Vertex3D>,
100}
101
102/// Single Non-Linear Animation (NLA) playback layer supporting override/additive blending, joint bitmasks, and smooth crossfades.
103#[derive(Clone, Copy, Data, Debug, PartialEq)]
104pub struct NlaLayer3D {
105 /// Index into `AnimationMixer3D::clips`.
106 #[get(type(copy))]
107 pub(crate) clip_index: usize,
108 /// Active layer blend weight in `[0.0, 1.0]`.
109 #[get(type(copy))]
110 pub(crate) weight: f32,
111 /// Layer composition operator (`Override` or `Additive`).
112 #[get(type(copy))]
113 pub(crate) blend_mode: NlaBlendMode,
114 /// Playback wrap mode (`Loop`, `Clamp`, or `PingPong`).
115 #[get(type(copy))]
116 pub(crate) repeat_mode: NlaRepeatMode,
117 /// Current local playback time in seconds.
118 #[get(type(copy))]
119 pub(crate) time_secs: f32,
120 /// Playback speed multiplier (`1.0` = real time).
121 #[get(type(copy))]
122 pub(crate) time_scale: f32,
123 /// Elapsed seconds inside an active weight crossfade ramp.
124 #[get(type(copy))]
125 pub(crate) fade_elapsed_secs: f32,
126 /// Total duration of an active weight crossfade ramp (`0.0` = inactive).
127 #[get(type(copy))]
128 pub(crate) fade_duration_secs: f32,
129 /// Starting weight captured when crossfade began.
130 #[get(type(copy))]
131 pub(crate) fade_start_weight: f32,
132 /// Target weight approached at end of crossfade.
133 #[get(type(copy))]
134 pub(crate) fade_target_weight: f32,
135 /// 64-bit node/joint eligibility bitmask (`u64::MAX` enables all nodes).
136 #[get(type(copy))]
137 pub(crate) joint_mask: u64,
138 /// Whether this layer is active during mixer evaluation.
139 #[get(type(copy))]
140 pub(crate) enabled: bool,
141}
142
143/// Pre-allocated Structure-of-Arrays scratch workspace used by `AnimationMixer3D` for zero-allocation NLA evaluation.
144#[derive(Clone, Data, Debug, Default, PartialEq)]
145pub struct AnimationPoseScratch3D {
146 /// Accumulated local node translations.
147 pub(crate) node_translations: Vec<Vec3>,
148 /// Accumulated local node unit quaternions.
149 pub(crate) node_rotations: Vec<Quat>,
150 /// Accumulated local node non-uniform scales.
151 pub(crate) node_scales: Vec<Vec3>,
152 /// Flags marking nodes whose translation was modified this tick.
153 pub(crate) node_touched_translation: Vec<bool>,
154 /// Flags marking nodes whose rotation was modified this tick.
155 pub(crate) node_touched_rotation: Vec<bool>,
156 /// Flags marking nodes whose scale was modified this tick.
157 pub(crate) node_touched_scale: Vec<bool>,
158 /// Accumulated flat morph weights mirroring `SceneGraph3D::morph_weights`.
159 pub(crate) morph_weights: Vec<f32>,
160 /// Flags marking morph weight entries modified this tick.
161 pub(crate) morph_touched: Vec<bool>,
162 /// Temporary scalar sample buffer reused across all channel evaluations.
163 pub(crate) sampler_values: Vec<f32>,
164}
165
166/// Multi-layer glTF 2.0 & Blender NLA animation mixer supporting STEP/LINEAR/CUBICSPLINE channels, morph weights, and zero-allocation ticking.
167#[derive(Clone, Data, Debug, Default, PartialEq)]
168pub struct AnimationMixer3D {
169 /// Registered animation clips (Blender Actions / glTF animations).
170 pub(crate) clips: Vec<ImportedAnimationClip3D>,
171 /// Active NLA playback layers evaluated from index `0` upward.
172 pub(crate) layers: Vec<NlaLayer3D>,
173 /// Reusable pose accumulation scratch workspace.
174 pub(crate) pose_scratch: AnimationPoseScratch3D,
175 /// Captured bind/rest local translations for additive blending and reset.
176 pub(crate) rest_translations: Vec<Vec3>,
177 /// Captured bind/rest local rotations for additive blending and reset.
178 pub(crate) rest_rotations: Vec<Quat>,
179 /// Captured bind/rest local scales for additive blending and reset.
180 pub(crate) rest_scales: Vec<Vec3>,
181 /// Captured bind/rest morph weights for additive blending and reset.
182 pub(crate) rest_morph_weights: Vec<f32>,
183}