ugly-game 0.15.16 → 0.15.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/anim/animBlend.d.ts +24 -0
- package/dist/anim/animBlend.js +156 -0
- package/dist/anim/animCook.d.ts +78 -0
- package/dist/anim/animCook.js +233 -0
- package/dist/anim/animEval.d.ts +47 -0
- package/dist/anim/animEval.js +203 -0
- package/dist/anim/animFootPlant.d.ts +220 -0
- package/dist/anim/animFootPlant.js +311 -0
- package/dist/anim/animGlb.d.ts +98 -0
- package/dist/anim/animGlb.js +216 -0
- package/dist/anim/animHandIk.d.ts +56 -0
- package/dist/anim/animHandIk.js +67 -0
- package/dist/anim/animHold.d.ts +32 -0
- package/dist/anim/animHold.js +82 -0
- package/dist/anim/animIR.d.ts +95 -0
- package/dist/anim/animIR.js +167 -0
- package/dist/anim/animIk.d.ts +79 -0
- package/dist/anim/animIk.js +189 -0
- package/dist/anim/animLocomotion.d.ts +243 -0
- package/dist/anim/animLocomotion.js +525 -0
- package/dist/anim/animLookAt.d.ts +74 -0
- package/dist/anim/animLookAt.js +128 -0
- package/dist/anim/animMask.d.ts +25 -0
- package/dist/anim/animMask.js +82 -0
- package/dist/anim/animMirror.d.ts +45 -0
- package/dist/anim/animMirror.js +110 -0
- package/dist/anim/animMotion.d.ts +288 -0
- package/dist/anim/animMotion.js +619 -0
- package/dist/anim/animOracle.d.ts +66 -0
- package/dist/anim/animOracle.js +121 -0
- package/dist/anim/animQuality.d.ts +95 -0
- package/dist/anim/animQuality.js +428 -0
- package/dist/anim/animRef.d.ts +71 -0
- package/dist/anim/animRef.js +243 -0
- package/dist/anim/animSample.d.ts +4 -0
- package/dist/anim/animSample.js +57 -0
- package/dist/anim/animSockets.d.ts +141 -0
- package/dist/anim/animSockets.js +258 -0
- package/dist/anim/animThresholds.d.ts +29 -0
- package/dist/anim/animThresholds.js +197 -0
- package/dist/anim/animTypes.d.ts +122 -0
- package/dist/anim/animTypes.js +69 -0
- package/dist/anim/animUgm.d.ts +75 -0
- package/dist/anim/animUgm.js +352 -0
- package/dist/gpuShadow.d.ts +136 -7
- package/dist/gpuShadow.js +442 -124
- package/package.json +12 -11
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { BoneMask, JointTRS } from './animTypes';
|
|
2
|
+
export type Quat = [number, number, number, number];
|
|
3
|
+
export declare function quatMul(a: Quat | readonly number[], b: Quat | readonly number[]): Quat;
|
|
4
|
+
export declare function quatConj(q: Quat | readonly number[]): Quat;
|
|
5
|
+
/** Blend one joint. Exact passthrough at the endpoints — see the header. */
|
|
6
|
+
export declare function blendTRS(a: JointTRS, b: JointTRS, t: number,
|
|
7
|
+
/** Override the shortest-arc choice — see `layerPose` for why a crossfade
|
|
8
|
+
* must not re-decide it every frame. */
|
|
9
|
+
sign?: 1 | -1,
|
|
10
|
+
/** Fade the rotation blend out near 180° — see `nlerp`'s `damp`. */
|
|
11
|
+
damp?: boolean): JointTRS;
|
|
12
|
+
/** Blend two full poses by a single scalar — the crossfade slot's operation. */
|
|
13
|
+
export declare function blendLocals(a: readonly JointTRS[], b: readonly JointTRS[], t: number,
|
|
14
|
+
/** Frozen per-joint shortest-arc signs — see `animEval.layerPose`. */
|
|
15
|
+
signs?: Int8Array | null): JointTRS[];
|
|
16
|
+
/** Blend `overlay` onto `base` per bone, at `mask[j] * weight`.
|
|
17
|
+
* Bones whose effective weight is 0 are returned BIT-IDENTICAL to `base`. */
|
|
18
|
+
export declare function blendLocalsMasked(base: readonly JointTRS[], overlay: readonly JointTRS[], mask: BoneMask | null, weight: number): JointTRS[];
|
|
19
|
+
/** Apply an additive layer: `base ⊗ (ref⁻¹ ⊗ add)^w` on rotation, and the
|
|
20
|
+
* weighted difference on translation/scale.
|
|
21
|
+
*
|
|
22
|
+
* ⚠️ At w=0 this returns `base` verbatim — the additive-neutrality gate asserts
|
|
23
|
+
* that a disabled additive layer changes literally nothing. */
|
|
24
|
+
export declare function additiveLocals(base: readonly JointTRS[], add: readonly JointTRS[], ref: readonly JointTRS[], mask: BoneMask | null, weight: number): JointTRS[];
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { cloneTRS } from './animTypes';
|
|
2
|
+
export function quatMul(a, b) {
|
|
3
|
+
const [ax, ay, az, aw] = a;
|
|
4
|
+
const [bx, by, bz, bw] = b;
|
|
5
|
+
return [
|
|
6
|
+
aw * bx + ax * bw + ay * bz - az * by,
|
|
7
|
+
aw * by - ax * bz + ay * bw + az * bx,
|
|
8
|
+
aw * bz + ax * by - ay * bx + az * bw,
|
|
9
|
+
aw * bw - ax * bx - ay * by - az * bz,
|
|
10
|
+
];
|
|
11
|
+
}
|
|
12
|
+
export function quatConj(q) {
|
|
13
|
+
return [-q[0], -q[1], -q[2], q[3]];
|
|
14
|
+
}
|
|
15
|
+
/** Normalized lerp with the antipodal sign fix. Cheaper than slerp and
|
|
16
|
+
* indistinguishable at the blend durations we use (≤400 ms). */
|
|
17
|
+
/**
|
|
18
|
+
* How close to antipodal a pair has to be before the blend fades out — see
|
|
19
|
+
* `nlerp`'s `damp`.
|
|
20
|
+
*
|
|
21
|
+
* 0.15 is ~81° of quaternion angle, which is 162° of ROTATION: a pair that far
|
|
22
|
+
* apart has no meaningful midpoint, and everything a locomotion blend actually
|
|
23
|
+
* mixes sits above 0.9.
|
|
24
|
+
*/
|
|
25
|
+
const ANTIPODAL_DEAD_ZONE = 0.15;
|
|
26
|
+
function nlerp(a, b, t, forced,
|
|
27
|
+
/**
|
|
28
|
+
* Fade the blend out as the pair approaches 180° apart.
|
|
29
|
+
*
|
|
30
|
+
* ⚠️ THE FIX FOR A SIGN FLIP THAT CANNOT BE FROZEN. `layerPose` freezes the
|
|
31
|
+
* arc for a CROSSFADE because a fade has a start; a layer's blend against the
|
|
32
|
+
* stack below it does not — its weight ramps for as long as it likes and its
|
|
33
|
+
* clip can change underneath at any weight. Freezing there was tried and
|
|
34
|
+
* measured: it moved the flip from the crossing to the moment the freeze was
|
|
35
|
+
* re-decided, and the sweep went from two events at 0.4 and 0.9 m to five at
|
|
36
|
+
* 1.0 m. It is the wrong tool.
|
|
37
|
+
*
|
|
38
|
+
* What makes the crossing continuous instead is noticing that the blend has
|
|
39
|
+
* no meaning near it. At dot = 0 the two rotations are 180° apart and every
|
|
40
|
+
* midpoint is as good as every other, so the flip is a choice between two
|
|
41
|
+
* equally arbitrary answers — and both are far from where the joint was. So
|
|
42
|
+
* the overlay's weight is taken to zero as the pair approaches that, the base
|
|
43
|
+
* is held through it, and the sign flips where its effect is nil. The blend
|
|
44
|
+
* comes back the moment the pair is a pair again.
|
|
45
|
+
*/
|
|
46
|
+
damp) {
|
|
47
|
+
// `noUncheckedIndexedAccess` is on; quaternions are always length 4 here, and
|
|
48
|
+
// the repo's convention for numeric hot paths is the assertion (see
|
|
49
|
+
// shared/cloth/topology.ts).
|
|
50
|
+
const ax = a[0], ay = a[1], az = a[2], aw = a[3];
|
|
51
|
+
const bx = b[0], by = b[1], bz = b[2], bw = b[3];
|
|
52
|
+
const dot = ax * bx + ay * by + az * bz + aw * bw;
|
|
53
|
+
const sign = forced ?? (dot < 0 ? -1 : 1);
|
|
54
|
+
const k = damp === true ? t * Math.min(1, Math.abs(dot) / ANTIPODAL_DEAD_ZONE) : t;
|
|
55
|
+
const x = ax + (bx * sign - ax) * k;
|
|
56
|
+
const y = ay + (by * sign - ay) * k;
|
|
57
|
+
const z = az + (bz * sign - az) * k;
|
|
58
|
+
const w = aw + (bw * sign - aw) * k;
|
|
59
|
+
const len = Math.hypot(x, y, z, w) || 1;
|
|
60
|
+
return [x / len, y / len, z / len, w / len];
|
|
61
|
+
}
|
|
62
|
+
/** Scale a rotation by `t` — the quaternion "power" for additive layers, done
|
|
63
|
+
* as nlerp from identity so it shares the antipodal fix. */
|
|
64
|
+
function quatScale(q, t) {
|
|
65
|
+
return nlerp([0, 0, 0, 1], q, t);
|
|
66
|
+
}
|
|
67
|
+
/** Blend one joint. Exact passthrough at the endpoints — see the header. */
|
|
68
|
+
export function blendTRS(a, b, t,
|
|
69
|
+
/** Override the shortest-arc choice — see `layerPose` for why a crossfade
|
|
70
|
+
* must not re-decide it every frame. */
|
|
71
|
+
sign,
|
|
72
|
+
/** Fade the rotation blend out near 180° — see `nlerp`'s `damp`. */
|
|
73
|
+
damp) {
|
|
74
|
+
if (t <= 0)
|
|
75
|
+
return cloneTRS(a);
|
|
76
|
+
if (t >= 1)
|
|
77
|
+
return cloneTRS(b);
|
|
78
|
+
return {
|
|
79
|
+
t: [
|
|
80
|
+
a.t[0] + (b.t[0] - a.t[0]) * t,
|
|
81
|
+
a.t[1] + (b.t[1] - a.t[1]) * t,
|
|
82
|
+
a.t[2] + (b.t[2] - a.t[2]) * t,
|
|
83
|
+
],
|
|
84
|
+
q: nlerp(a.q, b.q, t, sign, damp),
|
|
85
|
+
s: [
|
|
86
|
+
a.s[0] + (b.s[0] - a.s[0]) * t,
|
|
87
|
+
a.s[1] + (b.s[1] - a.s[1]) * t,
|
|
88
|
+
a.s[2] + (b.s[2] - a.s[2]) * t,
|
|
89
|
+
],
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/** Blend two full poses by a single scalar — the crossfade slot's operation. */
|
|
93
|
+
export function blendLocals(a, b, t,
|
|
94
|
+
/** Frozen per-joint shortest-arc signs — see `animEval.layerPose`. */
|
|
95
|
+
signs) {
|
|
96
|
+
const n = Math.min(a.length, b.length);
|
|
97
|
+
const out = new Array(n);
|
|
98
|
+
// ⚠️ NOT DAMPED, and the M0 gate is why: `blend-pop` asserts a smooth
|
|
99
|
+
// crossfade at every fixed pose separation INCLUDING 180°, which is exactly
|
|
100
|
+
// the case the damping suppresses. A crossfade's arc is already frozen, so it
|
|
101
|
+
// cannot flip; damping would only remove motion the gate requires.
|
|
102
|
+
for (let j = 0; j < n; j++)
|
|
103
|
+
out[j] = blendTRS(a[j], b[j], t, signs ? (signs[j] < 0 ? -1 : 1) : undefined);
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
/** Blend `overlay` onto `base` per bone, at `mask[j] * weight`.
|
|
107
|
+
* Bones whose effective weight is 0 are returned BIT-IDENTICAL to `base`. */
|
|
108
|
+
export function blendLocalsMasked(base, overlay, mask, weight) {
|
|
109
|
+
const n = base.length;
|
|
110
|
+
const out = new Array(n);
|
|
111
|
+
for (let j = 0; j < n; j++) {
|
|
112
|
+
const w = (mask === null ? 1 : mask[j]) * weight;
|
|
113
|
+
if (w <= 0 || j >= overlay.length) {
|
|
114
|
+
out[j] = cloneTRS(base[j]);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
// ⚠️ DAMPED, because this blend's sign is chosen fresh every frame and
|
|
118
|
+
// there is no fade boundary to freeze it at. See `nlerp`'s `damp`.
|
|
119
|
+
out[j] = blendTRS(base[j], overlay[j], w, undefined, true);
|
|
120
|
+
}
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
123
|
+
/** Apply an additive layer: `base ⊗ (ref⁻¹ ⊗ add)^w` on rotation, and the
|
|
124
|
+
* weighted difference on translation/scale.
|
|
125
|
+
*
|
|
126
|
+
* ⚠️ At w=0 this returns `base` verbatim — the additive-neutrality gate asserts
|
|
127
|
+
* that a disabled additive layer changes literally nothing. */
|
|
128
|
+
export function additiveLocals(base, add, ref, mask, weight) {
|
|
129
|
+
const n = base.length;
|
|
130
|
+
const out = new Array(n);
|
|
131
|
+
for (let j = 0; j < n; j++) {
|
|
132
|
+
const w = (mask === null ? 1 : mask[j]) * weight;
|
|
133
|
+
if (w <= 0 || j >= add.length || j >= ref.length) {
|
|
134
|
+
out[j] = cloneTRS(base[j]);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
const b = base[j];
|
|
138
|
+
const a = add[j];
|
|
139
|
+
const r = ref[j];
|
|
140
|
+
const delta = quatMul(quatConj(r.q), a.q);
|
|
141
|
+
out[j] = {
|
|
142
|
+
t: [
|
|
143
|
+
b.t[0] + (a.t[0] - r.t[0]) * w,
|
|
144
|
+
b.t[1] + (a.t[1] - r.t[1]) * w,
|
|
145
|
+
b.t[2] + (a.t[2] - r.t[2]) * w,
|
|
146
|
+
],
|
|
147
|
+
q: quatMul(b.q, quatScale(delta, w)),
|
|
148
|
+
s: [
|
|
149
|
+
b.s[0] * (1 + (a.s[0] / (r.s[0] || 1) - 1) * w),
|
|
150
|
+
b.s[1] * (1 + (a.s[1] / (r.s[1] || 1) - 1) * w),
|
|
151
|
+
b.s[2] * (1 + (a.s[2] / (r.s[2] || 1) - 1) * w),
|
|
152
|
+
],
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
return out;
|
|
156
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { type MotionLimits } from './animMotion';
|
|
2
|
+
/**
|
|
3
|
+
* Why this rig cannot be used, or null if it can.
|
|
4
|
+
*
|
|
5
|
+
* ⚠️ A SPECIFIC MESSAGE, NEVER A SILENT MANGLE. The spec's wording: *"this rig
|
|
6
|
+
* has 24 bones named `Bip01_*`; we need a Mixamo-compatible skeleton."* On a
|
|
7
|
+
* page a user can reach, a silently bind-posed character reads as "the site is
|
|
8
|
+
* broken" — and the one thing that turns that into a five-minute fix is naming
|
|
9
|
+
* what was actually found.
|
|
10
|
+
*/
|
|
11
|
+
export declare function rejectRig(boneNames: readonly string[]): string | null;
|
|
12
|
+
/** Everything the cook measures. Every field here is a property of the CLIP. */
|
|
13
|
+
export interface CookedClip {
|
|
14
|
+
id: string;
|
|
15
|
+
/** The clip's own internal name, which need not equal the catalogue id. */
|
|
16
|
+
sourceName: string;
|
|
17
|
+
durationS: number;
|
|
18
|
+
boneCount: number;
|
|
19
|
+
rotationTracks: number;
|
|
20
|
+
/** Rotation tracks naming a bone the file's own skeleton does not carry. */
|
|
21
|
+
orphanTracks: number;
|
|
22
|
+
strideSpeedMps: number;
|
|
23
|
+
strideDirDeg: number;
|
|
24
|
+
facingOffsetDeg: number;
|
|
25
|
+
cycleSeconds: number;
|
|
26
|
+
supportFraction: number;
|
|
27
|
+
stanceRatio: number;
|
|
28
|
+
hipExcursionM: number;
|
|
29
|
+
contacts: number;
|
|
30
|
+
/**
|
|
31
|
+
* How far the last pose is from the first, degrees, worst joint.
|
|
32
|
+
*
|
|
33
|
+
* ⚠️ THE LOOP TEST THAT DOES NOT ASSUME A LOOP. A clip whose ends differ by
|
|
34
|
+
* 40° at the shoulder will pop once per cycle however confidently its metadata
|
|
35
|
+
* says `loop: true`, and a clip whose ends match is loopable whatever the flag
|
|
36
|
+
* says. Measuring the seam is what lets the flag be checked instead of trusted.
|
|
37
|
+
*/
|
|
38
|
+
loopSeamDeg: number;
|
|
39
|
+
/** Measured: the root actually travels. Compared against the declared flag. */
|
|
40
|
+
rootMotion: boolean;
|
|
41
|
+
}
|
|
42
|
+
export type CookOutcome = {
|
|
43
|
+
ok: true;
|
|
44
|
+
clip: CookedClip;
|
|
45
|
+
} | {
|
|
46
|
+
ok: false;
|
|
47
|
+
id: string;
|
|
48
|
+
reason: string;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Measure one GLB. Pure: bytes in, findings out, no I/O and no globals.
|
|
52
|
+
*
|
|
53
|
+
* `id` is the catalogue's, carried through untouched so the caller can join.
|
|
54
|
+
*/
|
|
55
|
+
export declare function cookGlb(id: string, bytes: ArrayBuffer, limits?: MotionLimits): CookOutcome;
|
|
56
|
+
/** What the catalogue declares, for the fields a measurement can check. */
|
|
57
|
+
export interface DeclaredClip {
|
|
58
|
+
id: string;
|
|
59
|
+
loop: boolean;
|
|
60
|
+
rootMotion: boolean;
|
|
61
|
+
}
|
|
62
|
+
export interface Disagreement {
|
|
63
|
+
id: string;
|
|
64
|
+
field: 'loop' | 'rootMotion';
|
|
65
|
+
declared: boolean;
|
|
66
|
+
measured: boolean;
|
|
67
|
+
/** The number behind the measurement, so the reader can judge it. */
|
|
68
|
+
evidence: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Where a hand-curated flag and a measurement disagree.
|
|
72
|
+
*
|
|
73
|
+
* ⚠️ REPORTED, NOT RESOLVED, and the spec is emphatic. Overwriting the flag
|
|
74
|
+
* destroys a curator's judgement; overwriting the measurement destroys the only
|
|
75
|
+
* evidence. Both are findings about ONE of the two, and which one is wrong is
|
|
76
|
+
* not a decision arithmetic gets to make.
|
|
77
|
+
*/
|
|
78
|
+
export declare function disagreements(cooked: CookedClip, declared: DeclaredClip, loopSeamToleranceDeg?: number): Disagreement[];
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
2
|
+
// THE COOK — a clip measured once, offline, instead of on every page load.
|
|
3
|
+
//
|
|
4
|
+
// ⚠️ INGESTION IS A BATCH RUN PRODUCING A COMMITTED MANIFEST, not a per-page-load
|
|
5
|
+
// conversion. §3's M1 says so outright, and the reason is visible in the bench
|
|
6
|
+
// today: the lab re-measures thirty-odd clips every time anyone opens it, which
|
|
7
|
+
// is both slow and — because measurement depends on how many samples a stride
|
|
8
|
+
// happens to get — not perfectly reproducible between loads.
|
|
9
|
+
//
|
|
10
|
+
// ⚠️ ONLY THE MEASURED FIELDS ARE COMPUTED. `name`, `category`, `style` and the
|
|
11
|
+
// dance group are hand-curated upstream and are carried through VERBATIM; where
|
|
12
|
+
// a measurement disagrees with the catalogue's `loop` or `rootMotion` flag, the
|
|
13
|
+
// disagreement is REPORTED, never silently resolved. A hand flag and a
|
|
14
|
+
// measurement disagreeing is a finding about one of them, and overwriting either
|
|
15
|
+
// destroys the finding.
|
|
16
|
+
//
|
|
17
|
+
// ⚠️ WHAT IS NOT COOKABLE: the retarget. A clip is baked against the character's
|
|
18
|
+
// OWN derived bind pose — `deriveCharRig` rebuilds it per body — so the baked
|
|
19
|
+
// result is a property of (clip, character) and cannot be precomputed for a
|
|
20
|
+
// character that does not exist yet. What IS a property of the clip alone is
|
|
21
|
+
// everything below, and that is exactly what this produces.
|
|
22
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
23
|
+
import { parseGlbClips } from './animGlb';
|
|
24
|
+
import { refRig } from './animRef';
|
|
25
|
+
import { measureClip, DEFAULT_MOTION_LIMITS, } from './animMotion';
|
|
26
|
+
import { quatAngleDeg } from './animUgm';
|
|
27
|
+
/** The bones a Mixamo-compatible rig must carry for any of this to mean anything. */
|
|
28
|
+
const REQUIRED_BONES = [
|
|
29
|
+
'Hips',
|
|
30
|
+
'Spine',
|
|
31
|
+
'Head',
|
|
32
|
+
'LeftArm',
|
|
33
|
+
'RightArm',
|
|
34
|
+
'LeftUpLeg',
|
|
35
|
+
'LeftLeg',
|
|
36
|
+
'LeftFoot',
|
|
37
|
+
'RightUpLeg',
|
|
38
|
+
'RightLeg',
|
|
39
|
+
'RightFoot',
|
|
40
|
+
];
|
|
41
|
+
/**
|
|
42
|
+
* Why this rig cannot be used, or null if it can.
|
|
43
|
+
*
|
|
44
|
+
* ⚠️ A SPECIFIC MESSAGE, NEVER A SILENT MANGLE. The spec's wording: *"this rig
|
|
45
|
+
* has 24 bones named `Bip01_*`; we need a Mixamo-compatible skeleton."* On a
|
|
46
|
+
* page a user can reach, a silently bind-posed character reads as "the site is
|
|
47
|
+
* broken" — and the one thing that turns that into a five-minute fix is naming
|
|
48
|
+
* what was actually found.
|
|
49
|
+
*/
|
|
50
|
+
export function rejectRig(boneNames) {
|
|
51
|
+
if (boneNames.length === 0)
|
|
52
|
+
return 'no skeleton at all: the file has no bone nodes';
|
|
53
|
+
const have = new Set(boneNames);
|
|
54
|
+
const missing = REQUIRED_BONES.filter((b) => !have.has(b));
|
|
55
|
+
if (missing.length === 0)
|
|
56
|
+
return null;
|
|
57
|
+
// Name the shape that IS there, so the reader can tell a foreign rig from a
|
|
58
|
+
// prefix-stripping bug — the two look identical from a missing-bone list.
|
|
59
|
+
const sample = boneNames.slice(0, 3).join(', ');
|
|
60
|
+
return (`this rig has ${boneNames.length} bones (${sample}${boneNames.length > 3 ? ', …' : ''}) ` +
|
|
61
|
+
`and is missing ${missing.length} we need (${missing.slice(0, 4).join(', ')}` +
|
|
62
|
+
`${missing.length > 4 ? ', …' : ''}); we need a Mixamo-compatible skeleton`);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The worst per-joint difference between the clip's first and last frames.
|
|
66
|
+
*
|
|
67
|
+
* ⚠️ SAMPLED FROM THE TRACKS, NOT FROM A POSE EVALUATION. A seam is a property
|
|
68
|
+
* of the authored keys; running it through FK would fold in the rig and answer a
|
|
69
|
+
* different question.
|
|
70
|
+
*/
|
|
71
|
+
function loopSeam(tracks) {
|
|
72
|
+
let worst = 0;
|
|
73
|
+
for (const t of tracks.values()) {
|
|
74
|
+
const n = t.times.length;
|
|
75
|
+
if (n < 2)
|
|
76
|
+
continue;
|
|
77
|
+
worst = Math.max(worst, quatAngleDeg(t.values, 0, t.values, (n - 1) * 4));
|
|
78
|
+
}
|
|
79
|
+
return worst;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Does the root actually GO somewhere.
|
|
83
|
+
*
|
|
84
|
+
* ⚠️ NET DISPLACEMENT, NOT RANGE, AND THE THRESHOLD IS A STRIDE NOT A NUDGE.
|
|
85
|
+
* The first version asked whether the hips' horizontal RANGE exceeded 5 cm, and
|
|
86
|
+
* reported 99 of 165 clips as travelling — because an idle shifting its weight
|
|
87
|
+
* moves its hips 13.6 cm side to side while going nowhere. What separates a walk
|
|
88
|
+
* from a sway is not how far the hips wander but whether they END UP anywhere:
|
|
89
|
+
* `m_walk_01` nets 3.2 m, `m_idle_var_01` nets about zero.
|
|
90
|
+
*
|
|
91
|
+
* ⚠️ WHICH MISSES A CLIP THAT WALKS IN A CIRCLE, and that is a real limitation
|
|
92
|
+
* rather than an oversight — such a clip travels and nets zero. The corpus has
|
|
93
|
+
* none, the disagreement report would surface one as a `rootMotion` conflict,
|
|
94
|
+
* and a path-length test instead would fold idle sway back in. Stated so the
|
|
95
|
+
* next person knows which way it fails.
|
|
96
|
+
*/
|
|
97
|
+
function hasRootMotion(data, anim, thresholdM = 0.3) {
|
|
98
|
+
const tr = data.animations[anim]?.translations.get('Hips');
|
|
99
|
+
if (!tr || tr.values.length < 6)
|
|
100
|
+
return false;
|
|
101
|
+
const n = tr.values.length;
|
|
102
|
+
// Horizontal only: every clip's hips move VERTICALLY — that is breathing and
|
|
103
|
+
// stride bob, not travel — so including Y reports the whole corpus as moving.
|
|
104
|
+
return (Math.hypot(tr.values[n - 3] - tr.values[0], tr.values[n - 1] - tr.values[2]) > thresholdM);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Measure one GLB. Pure: bytes in, findings out, no I/O and no globals.
|
|
108
|
+
*
|
|
109
|
+
* `id` is the catalogue's, carried through untouched so the caller can join.
|
|
110
|
+
*/
|
|
111
|
+
export function cookGlb(id, bytes, limits = DEFAULT_MOTION_LIMITS) {
|
|
112
|
+
let data;
|
|
113
|
+
try {
|
|
114
|
+
data = parseGlbClips(bytes);
|
|
115
|
+
}
|
|
116
|
+
catch (e) {
|
|
117
|
+
return {
|
|
118
|
+
ok: false,
|
|
119
|
+
id,
|
|
120
|
+
reason: `unreadable container: ${e.message}`,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const boneNames = [...data.bind.parent.keys()];
|
|
124
|
+
const bad = rejectRig(boneNames);
|
|
125
|
+
if (bad !== null)
|
|
126
|
+
return { ok: false, id, reason: bad };
|
|
127
|
+
const anim = data.animations[0];
|
|
128
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- runtime guard; ugly-game lacks noUncheckedIndexedAccess so the type cannot see why this is here
|
|
129
|
+
if (!anim)
|
|
130
|
+
return {
|
|
131
|
+
ok: false,
|
|
132
|
+
id,
|
|
133
|
+
reason: 'the file carries a skeleton but no animation',
|
|
134
|
+
};
|
|
135
|
+
if (anim.rotations.size === 0)
|
|
136
|
+
return {
|
|
137
|
+
ok: false,
|
|
138
|
+
id,
|
|
139
|
+
reason: 'the animation has no rotation tracks — bind pose only',
|
|
140
|
+
};
|
|
141
|
+
if (!(anim.duration > 0))
|
|
142
|
+
return { ok: false, id, reason: `duration is ${anim.duration}s` };
|
|
143
|
+
/**
|
|
144
|
+
* ⚠️ DUPLICATE KEY TIMES ARE A STEP DISCONTINUITY, AND THEY ARE REAL. Two
|
|
145
|
+
* rotations at the same instant is not something a sampler can represent: the
|
|
146
|
+
* pose jumps between them in zero time, which is precisely what
|
|
147
|
+
* `continuityScan` exists to refuse, and every time-indexed lookup downstream
|
|
148
|
+
* becomes ambiguous about which of the two it found.
|
|
149
|
+
*
|
|
150
|
+
* Measured: `m_dance_74` carries a duplicate at t=2.8333 in all 52 of its
|
|
151
|
+
* tracks. Caught first as "round trip drifts 17.3°" — the symptom, three
|
|
152
|
+
* layers from the cause — which is why the check is here, at the container,
|
|
153
|
+
* rather than left to whatever trips over it.
|
|
154
|
+
*/
|
|
155
|
+
for (const [bone, t] of anim.rotations) {
|
|
156
|
+
for (let i = 1; i < t.times.length; i++) {
|
|
157
|
+
if (t.times[i] > t.times[i - 1])
|
|
158
|
+
continue;
|
|
159
|
+
const same = t.times[i] === t.times[i - 1];
|
|
160
|
+
const kind = same ? 'duplicate' : 'out-of-order';
|
|
161
|
+
return {
|
|
162
|
+
ok: false,
|
|
163
|
+
id,
|
|
164
|
+
reason: `${kind} key time ${t.times[i].toFixed(4)}s at index ${i} of the ${bone} track ` +
|
|
165
|
+
`— two rotations at one instant is a step discontinuity, not an animation`,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const rig = refRig(data.bind);
|
|
170
|
+
const known = new Set(rig.names);
|
|
171
|
+
let orphans = 0;
|
|
172
|
+
const tracks = new Map();
|
|
173
|
+
for (const [bone, t] of anim.rotations) {
|
|
174
|
+
if (!known.has(bone)) {
|
|
175
|
+
orphans++;
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
tracks.set(bone, { times: t.times, values: t.values });
|
|
179
|
+
}
|
|
180
|
+
const m = measureClip(rig, tracks, anim.duration, limits, anim.translations);
|
|
181
|
+
return {
|
|
182
|
+
ok: true,
|
|
183
|
+
clip: {
|
|
184
|
+
id,
|
|
185
|
+
sourceName: anim.name,
|
|
186
|
+
durationS: anim.duration,
|
|
187
|
+
boneCount: rig.names.length,
|
|
188
|
+
rotationTracks: tracks.size,
|
|
189
|
+
orphanTracks: orphans,
|
|
190
|
+
strideSpeedMps: m.strideSpeed,
|
|
191
|
+
strideDirDeg: m.strideDirDeg,
|
|
192
|
+
facingOffsetDeg: m.facingOffsetDeg,
|
|
193
|
+
cycleSeconds: m.cycleSeconds,
|
|
194
|
+
supportFraction: m.supportFraction,
|
|
195
|
+
stanceRatio: m.stanceRatio,
|
|
196
|
+
hipExcursionM: m.hipHigh - m.hipLow,
|
|
197
|
+
contacts: m.contacts.length,
|
|
198
|
+
loopSeamDeg: loopSeam(tracks),
|
|
199
|
+
rootMotion: hasRootMotion(data, 0),
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Where a hand-curated flag and a measurement disagree.
|
|
205
|
+
*
|
|
206
|
+
* ⚠️ REPORTED, NOT RESOLVED, and the spec is emphatic. Overwriting the flag
|
|
207
|
+
* destroys a curator's judgement; overwriting the measurement destroys the only
|
|
208
|
+
* evidence. Both are findings about ONE of the two, and which one is wrong is
|
|
209
|
+
* not a decision arithmetic gets to make.
|
|
210
|
+
*/
|
|
211
|
+
export function disagreements(cooked, declared, loopSeamToleranceDeg = 15) {
|
|
212
|
+
const out = [];
|
|
213
|
+
const loops = cooked.loopSeamDeg <= loopSeamToleranceDeg;
|
|
214
|
+
if (loops !== declared.loop)
|
|
215
|
+
out.push({
|
|
216
|
+
id: cooked.id,
|
|
217
|
+
field: 'loop',
|
|
218
|
+
declared: declared.loop,
|
|
219
|
+
measured: loops,
|
|
220
|
+
evidence: `worst joint differs by ${cooked.loopSeamDeg.toFixed(1)}° between the first and last frames`,
|
|
221
|
+
});
|
|
222
|
+
if (cooked.rootMotion !== declared.rootMotion)
|
|
223
|
+
out.push({
|
|
224
|
+
id: cooked.id,
|
|
225
|
+
field: 'rootMotion',
|
|
226
|
+
declared: declared.rootMotion,
|
|
227
|
+
measured: cooked.rootMotion,
|
|
228
|
+
evidence: cooked.rootMotion
|
|
229
|
+
? 'the hips translate horizontally by more than 5 cm'
|
|
230
|
+
: 'the hips do not translate horizontally',
|
|
231
|
+
});
|
|
232
|
+
return out;
|
|
233
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { AnimLayer, JointTRS, LayerBlendMode, LayerSlot, RigInfo } from './animTypes';
|
|
2
|
+
import { type BoneHolds } from './animHold';
|
|
3
|
+
export declare function makeLayer(name: string, mode: LayerBlendMode): AnimLayer;
|
|
4
|
+
/** Start `slot` on `layer`, crossfading from whatever is playing over
|
|
5
|
+
* `blendMs`. A blendMs of 0 is an immediate cut. */
|
|
6
|
+
export declare function startClip(layer: AnimLayer, slot: LayerSlot, blendMs: number): void;
|
|
7
|
+
/** Accumulate `dtMs` into the layer's clip clocks and its crossfade. */
|
|
8
|
+
export declare function advanceLayer(layer: AnimLayer, dtMs: number): void;
|
|
9
|
+
/** Evaluate the whole stack to per-joint local transforms. */
|
|
10
|
+
export declare function evalLayerLocals(rig: RigInfo, layers: readonly AnimLayer[]): JointTRS[];
|
|
11
|
+
/** The bone palette the skinning kernel consumes: `J × 16`, column-major.
|
|
12
|
+
*
|
|
13
|
+
* ⚠️ `forwardKinematics` consumes column-major MATRICES, not TRS records, so
|
|
14
|
+
* the locals are composed first.
|
|
15
|
+
*
|
|
16
|
+
* Note: `charClip.ts` has to widen `composeTRS`'s return by hand because
|
|
17
|
+
* ugly-game's `Mat4` does not resolve for it. Here it resolves cleanly — the
|
|
18
|
+
* type-aware linter rejects an assertion as unnecessary — so none is used. */
|
|
19
|
+
export declare function evalPalette(rig: RigInfo, layers: readonly AnimLayer[], holds?: BoneHolds | null): Float32Array;
|
|
20
|
+
export interface LayerStat {
|
|
21
|
+
name: string;
|
|
22
|
+
mode: LayerBlendMode;
|
|
23
|
+
weight: number;
|
|
24
|
+
clip: string | null;
|
|
25
|
+
previousClip: string | null;
|
|
26
|
+
blendT: number;
|
|
27
|
+
time: number;
|
|
28
|
+
/** How many bones this layer is NOT allowed to move (mask weight exactly 0). */
|
|
29
|
+
maskedBones: number;
|
|
30
|
+
}
|
|
31
|
+
export interface EvalStats {
|
|
32
|
+
layers: LayerStat[];
|
|
33
|
+
boneCount: number;
|
|
34
|
+
/** Joints whose own animation is switched off this frame — advanced mode's
|
|
35
|
+
* bisection instrument. Empty is the normal state and the only state the
|
|
36
|
+
* gates run in; a non-empty list means the stage is DELIBERATELY not
|
|
37
|
+
* showing the clip, and the IR says so rather than leaving a reader to
|
|
38
|
+
* wonder why the arm is straight. */
|
|
39
|
+
heldBones: string[];
|
|
40
|
+
}
|
|
41
|
+
/** Evaluate AND record what ran. The readouts come from HERE, never from a
|
|
42
|
+
* debug hook recomputing them — a hook that recomputes certifies its own copy
|
|
43
|
+
* of the logic (the `__charLab.drawnTris` bug). */
|
|
44
|
+
export declare function evalWithStats(rig: RigInfo, layers: readonly AnimLayer[], holds?: BoneHolds | null): {
|
|
45
|
+
palette: Float32Array;
|
|
46
|
+
stats: EvalStats;
|
|
47
|
+
};
|