Animators and coilhead animations

This commit is contained in:
2026-11-21 21:54:02 -03:00
parent 69ad4b80d0
commit 0c711b8163
21 changed files with 960 additions and 34 deletions
+6 -1
View File
@@ -10,6 +10,11 @@ import type { BoneOffsets, Vec3 } from "./model_math.ts";
// a keyframe this close to the time is the one it's on, in seconds
const ON_KEYFRAME = 1 / 1200;
// a bone nothing has moved
export function rest_offsets(): BoneOffsets {
return { rotation: [0, 0, 0], position: [0, 0, 0], scale: [1, 1, 1] };
}
// adds what clip does seconds into it to each bone's offsets, scaled by weight: rotation and position times weight,
// scale weight of the way from 1. a clip that loops wraps around its length, one that doesn't stays on its last frame
export function sample_clip(clip: ClipJson, seconds: number, offsets: Map<string, BoneOffsets>, weight = 1) {
@@ -17,7 +22,7 @@ export function sample_clip(clip: ClipJson, seconds: number, offsets: Map<string
for (const [bone, channels] of Object.entries(clip.bones)) {
let offset = offsets.get(bone);
if (!offset) {
offset = { rotation: [0, 0, 0], position: [0, 0, 0], scale: [1, 1, 1] };
offset = rest_offsets();
offsets.set(bone, offset);
}
for (const channel of ["rotation", "position"] as const) {