@aura3d/animation 1.3.3 → 1.4.1

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.
Files changed (46) hide show
  1. package/package.json +36 -3
  2. package/src/AnimationAction.ts +0 -166
  3. package/src/AnimationClip.ts +0 -63
  4. package/src/AnimationClipEvents.ts +0 -501
  5. package/src/AnimationClipRegistry.ts +0 -404
  6. package/src/AnimationController.ts +0 -1017
  7. package/src/AnimationEvents.ts +0 -34
  8. package/src/AnimationLayer.ts +0 -73
  9. package/src/AnimationMixer.ts +0 -402
  10. package/src/AnimationStateGraph.ts +0 -105
  11. package/src/AnimationStateMachine.ts +0 -265
  12. package/src/AnimationTrack.ts +0 -176
  13. package/src/BlendTree.ts +0 -89
  14. package/src/Bone.ts +0 -40
  15. package/src/CrowdAnimation.ts +0 -25
  16. package/src/ECSAnimationBridge.ts +0 -30
  17. package/src/FighterAnimationAdapter.ts +0 -124
  18. package/src/FootIk.ts +0 -251
  19. package/src/HumanoidBoneInference.ts +0 -323
  20. package/src/HumanoidRetargeting.ts +0 -700
  21. package/src/IK.ts +0 -117
  22. package/src/Inertialization.ts +0 -269
  23. package/src/Keyframe.ts +0 -159
  24. package/src/LocomotionController.ts +0 -155
  25. package/src/LocomotionKit.ts +0 -89
  26. package/src/MotionMatchingFixtures.ts +0 -254
  27. package/src/MotionQuality.ts +0 -182
  28. package/src/RigQuality.ts +0 -101
  29. package/src/RootMotion.ts +0 -124
  30. package/src/SceneAnimationBridge.ts +0 -80
  31. package/src/SecondaryAnimationFixtures.ts +0 -210
  32. package/src/Skeleton.ts +0 -78
  33. package/src/Skinning.ts +0 -18
  34. package/src/SpringBones.ts +0 -243
  35. package/src/browser-index.ts +0 -66
  36. package/src/index.ts +0 -66
  37. package/src/library/performanceStateGraph.ts +0 -173
  38. package/src/library/standardHumanoidClips.ts +0 -659
  39. package/src/threejs-compatibility/AnimationAction.ts +0 -27
  40. package/src/threejs-compatibility/AnimationClip.ts +0 -16
  41. package/src/threejs-compatibility/AnimationDiagnostics.ts +0 -42
  42. package/src/threejs-compatibility/AnimationMixer.ts +0 -24
  43. package/src/threejs-compatibility/MorphTargetMixer.ts +0 -16
  44. package/src/threejs-compatibility/Skeleton.ts +0 -9
  45. package/src/threejs-compatibility/SkinnedMesh.ts +0 -12
  46. package/src/threejs-compatibility/index.ts +0 -11
@@ -1,323 +0,0 @@
1
- import {
2
- HUMANOID_BONES,
3
- REQUIRED_HUMANOID_BONES,
4
- type HumanoidBoneBinding,
5
- type HumanoidBoneName,
6
- type HumanoidRigDefinition
7
- } from "./HumanoidRetargeting.js";
8
-
9
- /**
10
- * Options for {@link inferHumanoidRig}. All optional — sensible defaults match the
11
- * conventions found across the free GLB/glTF catalog (Mixamo, Sketchfab/Blender, UE-ish).
12
- */
13
- export interface InferHumanoidRigOptions {
14
- /** Id assigned to the produced {@link HumanoidRigDefinition}. Defaults to `"inferred-humanoid"`. */
15
- readonly id?: string;
16
- /** Human-readable rig name copied onto the definition. */
17
- readonly name?: string;
18
- /**
19
- * Extra alias entries merged on top of the built-in table. Use this for one-off rigs whose
20
- * node names don't follow any common convention. Keys are {@link HumanoidBoneName}s; values are
21
- * additional name fragments (compared case-insensitively after normalization).
22
- */
23
- readonly extraAliases?: Partial<Record<HumanoidBoneName, readonly string[]>>;
24
- /** Forwarded onto the resulting rig definition. */
25
- readonly units?: HumanoidRigDefinition["units"];
26
- /** Forwarded onto the resulting rig definition. */
27
- readonly facingAxis?: HumanoidRigDefinition["facingAxis"];
28
- /** Forwarded onto the resulting rig definition. */
29
- readonly scale?: number;
30
- }
31
-
32
- /**
33
- * Detail about a single resolved (or unresolved) humanoid slot — exposed via
34
- * {@link HumanoidRigInference.matches} so callers can debug ambiguous skeletons.
35
- */
36
- export interface HumanoidBoneMatch {
37
- readonly bone: HumanoidBoneName;
38
- /** Resolved source node name, when one was found. */
39
- readonly node?: string;
40
- /** Score of the winning candidate (higher is a more confident match). */
41
- readonly score: number;
42
- /** Every node name that the alias table considered a plausible candidate for this slot. */
43
- readonly candidates: readonly string[];
44
- }
45
-
46
- export interface HumanoidRigInference {
47
- readonly rig: HumanoidRigDefinition;
48
- readonly matches: readonly HumanoidBoneMatch[];
49
- /** Required bones (see {@link REQUIRED_HUMANOID_BONES}) that could not be mapped. */
50
- readonly missingRequired: readonly HumanoidBoneName[];
51
- }
52
-
53
- type Side = "left" | "right" | null;
54
-
55
- /**
56
- * Per-logical-group "core" tokens. These are matched against normalized node names. Side-bearing
57
- * groups omit the side here — sidedness is detected separately (`L_`, `Left`, `_l`, `.R`, etc.) so
58
- * a single table serves both sides. Keys are *logical groups* (`shoulder`, `upperArm`, …), not
59
- * {@link HumanoidBoneName}s; the side-resolved slots are derived below in {@link SLOT_SPECS}.
60
- */
61
- const ALIAS_BY_KEY: Record<string, readonly string[]> = {
62
- hips: ["hips", "hip", "pelvis", "root", "cog", "bip01pelvis"],
63
- spine: ["spine", "spine0", "spine00", "spine1", "spine01", "abdomen", "lowerback", "torso"],
64
- chest: ["chest", "spine2", "spine02", "spine3", "ribcage", "upperback"],
65
- upperChest: ["upperchest", "spine3", "spine03", "spine4", "upperchestspine"],
66
- neck: ["neck", "neck0", "neck01", "neck1"],
67
- head: ["head"],
68
- shoulder: ["shoulder", "clavicle", "collar", "scapula"],
69
- upperArm: ["upperarm", "armupper", "arm", "uparm", "shoulderarm", "humerus", "armupper01"],
70
- lowerArm: ["lowerarm", "armlower", "forearm", "loarm", "elbow", "ulna", "armlower01"],
71
- hand: ["hand", "wrist", "palm"],
72
- upperLeg: ["upperleg", "legupper", "thigh", "upleg", "legupper01", "femur"],
73
- lowerLeg: ["lowerleg", "leglower", "calf", "shin", "leg", "loleg", "knee", "leglower01", "tibia"],
74
- foot: ["foot", "ankle"],
75
- toes: ["toe", "toes", "toebase", "ball"]
76
- };
77
-
78
- /** Logical (side-stripped) classification for each humanoid slot. */
79
- interface SlotSpec {
80
- readonly bone: HumanoidBoneName;
81
- readonly aliasKey: string;
82
- readonly side: Side;
83
- /** Bones that are required for a usable rig (used to compute `missingRequired`). */
84
- readonly required: boolean;
85
- }
86
-
87
- const REQUIRED_SET = new Set<HumanoidBoneName>(REQUIRED_HUMANOID_BONES);
88
-
89
- const SLOT_SPECS: readonly SlotSpec[] = ([
90
- { bone: "hips", aliasKey: "hips", side: null },
91
- { bone: "spine", aliasKey: "spine", side: null },
92
- { bone: "chest", aliasKey: "chest", side: null },
93
- { bone: "upperChest", aliasKey: "upperChest", side: null },
94
- { bone: "neck", aliasKey: "neck", side: null },
95
- { bone: "head", aliasKey: "head", side: null },
96
- { bone: "leftShoulder", aliasKey: "shoulder", side: "left" },
97
- { bone: "leftUpperArm", aliasKey: "upperArm", side: "left" },
98
- { bone: "leftLowerArm", aliasKey: "lowerArm", side: "left" },
99
- { bone: "leftHand", aliasKey: "hand", side: "left" },
100
- { bone: "rightShoulder", aliasKey: "shoulder", side: "right" },
101
- { bone: "rightUpperArm", aliasKey: "upperArm", side: "right" },
102
- { bone: "rightLowerArm", aliasKey: "lowerArm", side: "right" },
103
- { bone: "rightHand", aliasKey: "hand", side: "right" },
104
- { bone: "leftUpperLeg", aliasKey: "upperLeg", side: "left" },
105
- { bone: "leftLowerLeg", aliasKey: "lowerLeg", side: "left" },
106
- { bone: "leftFoot", aliasKey: "foot", side: "left" },
107
- { bone: "leftToes", aliasKey: "toes", side: "left" },
108
- { bone: "rightUpperLeg", aliasKey: "upperLeg", side: "right" },
109
- { bone: "rightLowerLeg", aliasKey: "lowerLeg", side: "right" },
110
- { bone: "rightFoot", aliasKey: "foot", side: "right" },
111
- { bone: "rightToes", aliasKey: "toes", side: "right" }
112
- ] as ReadonlyArray<{ bone: HumanoidBoneName; aliasKey: string; side: Side }>).map(
113
- (spec): SlotSpec => ({ ...spec, required: REQUIRED_SET.has(spec.bone) })
114
- );
115
-
116
- interface NormalizedNode {
117
- readonly raw: string;
118
- /** Lowercased, namespace-stripped (`mixamorig:`), separator-collapsed. */
119
- readonly canon: string;
120
- /** Side detected from prefixes/suffixes/tokens. */
121
- readonly side: Side;
122
- }
123
-
124
- const NAMESPACE_RE = /^(?:mixamorig\d*:|mixamorig\d*|bip\d*\s*|biped\s*|armature[|:_]?)/i;
125
-
126
- function stripNamespace(name: string): string {
127
- let out = name;
128
- // Blender/glTF skinned hierarchies often prefix `Armature|` or `Armature/`.
129
- out = out.replace(/^armature[|/]/i, "");
130
- out = out.replace(NAMESPACE_RE, "");
131
- return out;
132
- }
133
-
134
- /** Collapse to alphanumerics only, lowercased — `L_Arm_Upper.01` -> `larmupper01`. */
135
- function canonicalize(name: string): string {
136
- return name.toLowerCase().replace(/[^a-z0-9]/g, "");
137
- }
138
-
139
- function detectSide(raw: string): Side {
140
- const lower = raw.toLowerCase();
141
- // Explicit word boundaries first (left/right) — these are unambiguous.
142
- if (/(^|[^a-z])left([^a-z]|$)|leftarm|leftleg|lefthand|leftfoot|leftshoulder|leftupleg/.test(lower)) return "left";
143
- if (/(^|[^a-z])right([^a-z]|$)|rightarm|rightleg|righthand|rightfoot|rightshoulder|rightupleg/.test(lower)) return "right";
144
- // Side prefixes: L_, R_, l., r. and suffixes: _l, _r, .l, .r, _L, name ends in L/R
145
- if (/(^|[^a-z])l[_.\- ]/.test(lower) || /[_.\- ]l($|[^a-z])/.test(lower)) return "left";
146
- if (/(^|[^a-z])r[_.\- ]/.test(lower) || /[_.\- ]r($|[^a-z])/.test(lower)) return "right";
147
- // Leading single side letter directly glued to a part: "LShoulder", "RArm", "L_Leg".
148
- if (/^l(?=[a-z0-9])/.test(lower) && !/^le(?!ft)/.test(lower) && !/^lo/.test(lower) && !/^la(?!rm)/.test(lower)) {
149
- // crude: only treat leading "l" as side when followed by a known limb-ish token.
150
- if (/^l(shoulder|arm|upperarm|lowerarm|forearm|hand|wrist|leg|upperleg|lowerleg|thigh|calf|shin|foot|ankle|toe|clav|coll)/.test(lower)) {
151
- return "left";
152
- }
153
- }
154
- if (/^r(?=[a-z0-9])/.test(lower)) {
155
- if (/^r(shoulder|arm|upperarm|lowerarm|forearm|hand|wrist|leg|upperleg|lowerleg|thigh|calf|shin|foot|ankle|toe|clav|coll)/.test(lower)) {
156
- return "right";
157
- }
158
- }
159
- return null;
160
- }
161
-
162
- function normalizeNode(raw: string): NormalizedNode {
163
- const stripped = stripNamespace(raw);
164
- return {
165
- raw,
166
- canon: canonicalize(stripped),
167
- side: detectSide(stripped) ?? detectSide(raw)
168
- };
169
- }
170
-
171
- /**
172
- * Score how well `node` fits `aliasKey`. Returns 0 for no match. Higher = better.
173
- * The score rewards: exact-token equality, longer alias fragments (more specific), and earlier
174
- * occurrence in the name. This lets `spine2`/`chest` win the chest slot over a generic `spine`.
175
- */
176
- function scoreCandidate(node: NormalizedNode, aliasKey: string, aliases: readonly string[]): number {
177
- let best = 0;
178
- for (const alias of aliases) {
179
- const a = canonicalize(alias);
180
- if (a.length === 0) continue;
181
- const idx = node.canon.indexOf(a);
182
- if (idx < 0) continue;
183
- // Base: specificity by alias length.
184
- let score = 10 + a.length * 2;
185
- // Exact match (whole canon equals alias) is the strongest signal.
186
- if (node.canon === a) score += 40;
187
- // Side bones: a side-stripped exact-ish match where the remainder is only side tokens.
188
- const remainder = node.canon.replace(a, "");
189
- if (remainder.length <= 2) score += 15;
190
- // Prefer matches that appear toward the end (the "leaf" semantic token) for limb parts,
191
- // but prefer earlier for spine/hips where the root token leads.
192
- score += Math.max(0, 6 - idx);
193
- if (score > best) best = score;
194
- }
195
- // De-emphasize generic "spine" matching when the name clearly carries a chest/upperchest digit.
196
- if (aliasKey === "spine" && /(spine[2-9]|spine0[2-9])/.test(node.canon)) {
197
- best = Math.max(0, best - 12);
198
- }
199
- return best;
200
- }
201
-
202
- /**
203
- * Infer a {@link HumanoidRigDefinition} from a flat list of skeleton node names.
204
- *
205
- * Strategy: each humanoid slot has a side-agnostic alias table plus an L/R/Left/Right side tag.
206
- * For every slot we score all candidate nodes (filtered by detected side when the slot is sided),
207
- * pick the highest-scoring one, and forbid reusing a node across slots. Conventions covered:
208
- * Mixamo (`mixamorig:Hips`/`LeftArm`), Sketchfab/Blender (`Hip_00`, `Spine1..3`, `L_Shoulder`,
209
- * `L_Arm_Upper_01`, `L_Leg_Upper_01`, `L_Hand`, `L_Foot`), and UE-ish (`pelvis`, `upperarm_l`,
210
- * `thigh_r`, `calf_l`).
211
- *
212
- * Each produced {@link HumanoidBoneBinding} carries `name` (the resolved node) and `aliases`
213
- * (the other plausible candidates for that slot), wiring the previously-unread `aliases` field.
214
- */
215
- export function inferHumanoidRigDetailed(
216
- nodeNames: readonly string[],
217
- options: InferHumanoidRigOptions = {}
218
- ): HumanoidRigInference {
219
- const nodes = nodeNames.map(normalizeNode);
220
- const used = new Set<string>();
221
- const bones: Partial<Record<HumanoidBoneName, HumanoidBoneBinding>> = {};
222
- const matches: HumanoidBoneMatch[] = [];
223
-
224
- // Process required + more-specific slots first so generic "spine"/"leg" don't steal nodes that a
225
- // more specific slot (chest/upperChest/lowerLeg) wants. We sort by a static priority.
226
- const ordered = [...SLOT_SPECS].sort((a, b) => slotPriority(a.bone) - slotPriority(b.bone));
227
-
228
- for (const spec of ordered) {
229
- const aliasList = mergeAliases(spec, options.extraAliases);
230
- const candidates: { node: NormalizedNode; score: number }[] = [];
231
-
232
- for (const node of nodes) {
233
- if (used.has(node.raw)) continue;
234
- if (spec.side && node.side && node.side !== spec.side) continue;
235
- // For sided slots, skip nodes with no detectable side only if a sided alternative exists.
236
- const score = scoreCandidate(node, spec.aliasKey, aliasList);
237
- if (score <= 0) continue;
238
- // Penalize sided slot matching a side-less node (ambiguous).
239
- const adjusted = spec.side && !node.side ? score - 8 : score;
240
- if (adjusted <= 0) continue;
241
- candidates.push({ node, score: adjusted });
242
- }
243
-
244
- candidates.sort((a, b) => b.score - a.score);
245
- const winner = candidates[0];
246
- const candidateNames = candidates.map((c) => c.node.raw);
247
-
248
- if (winner) {
249
- used.add(winner.node.raw);
250
- bones[spec.bone] = {
251
- name: winner.node.raw,
252
- aliases: candidateNames.slice(1)
253
- };
254
- matches.push({ bone: spec.bone, node: winner.node.raw, score: winner.score, candidates: candidateNames });
255
- } else {
256
- matches.push({ bone: spec.bone, score: 0, candidates: [] });
257
- }
258
- }
259
-
260
- const missingRequired = REQUIRED_HUMANOID_BONES.filter((bone) => !bones[bone]);
261
-
262
- const rig: HumanoidRigDefinition = {
263
- id: options.id ?? "inferred-humanoid",
264
- ...(options.name !== undefined ? { name: options.name } : {}),
265
- bones,
266
- ...(options.scale !== undefined ? { scale: options.scale } : {}),
267
- ...(options.units !== undefined ? { units: options.units } : {}),
268
- ...(options.facingAxis !== undefined ? { facingAxis: options.facingAxis } : {}),
269
- metadata: { inferred: true, inferredFromNodeCount: nodeNames.length }
270
- };
271
-
272
- return { rig, matches, missingRequired };
273
- }
274
-
275
- /** Convenience wrapper returning just the rig definition. */
276
- export function inferHumanoidRig(
277
- nodeNames: readonly string[],
278
- options: InferHumanoidRigOptions = {}
279
- ): HumanoidRigDefinition {
280
- return inferHumanoidRigDetailed(nodeNames, options).rig;
281
- }
282
-
283
- function mergeAliases(spec: SlotSpec, extra?: Partial<Record<HumanoidBoneName, readonly string[]>>): readonly string[] {
284
- const base = ALIAS_BY_KEY[spec.aliasKey] ?? [];
285
- const extraForBone = extra?.[spec.bone] ?? [];
286
- return extraForBone.length > 0 ? [...extraForBone, ...base] : base;
287
- }
288
-
289
- /**
290
- * Lower number = resolved earlier. More-specific slots resolve first so they claim their nodes
291
- * before generic siblings (e.g. `chest` before `spine`, `lowerLeg` before `upperLeg` before the
292
- * generic `leg` token shared by both).
293
- */
294
- function slotPriority(bone: HumanoidBoneName): number {
295
- const table: Partial<Record<HumanoidBoneName, number>> = {
296
- hips: 0,
297
- head: 1,
298
- upperChest: 2,
299
- chest: 3,
300
- neck: 4,
301
- leftHand: 5,
302
- rightHand: 5,
303
- leftFoot: 6,
304
- rightFoot: 6,
305
- leftToes: 7,
306
- rightToes: 7,
307
- leftShoulder: 8,
308
- rightShoulder: 8,
309
- leftLowerArm: 9,
310
- rightLowerArm: 9,
311
- leftUpperArm: 10,
312
- rightUpperArm: 10,
313
- leftLowerLeg: 11,
314
- rightLowerLeg: 11,
315
- leftUpperLeg: 12,
316
- rightUpperLeg: 12,
317
- spine: 13
318
- };
319
- return table[bone] ?? 20;
320
- }
321
-
322
- /** Re-exported for callers wanting to enumerate which slots inference targets. */
323
- export const INFERABLE_HUMANOID_BONES: readonly HumanoidBoneName[] = HUMANOID_BONES;