@threenative/core 0.3.4 → 0.3.5

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 (176) hide show
  1. package/capabilities.json +1505 -79
  2. package/dist/{audio-7i3Xl0l3.d.ts → audio-DIJE5HTr.d.ts} +43 -3
  3. package/dist/{canvas-layer-DDmC_VVF.d.ts → canvas-layer-C1-5CviZ.d.ts} +5 -1
  4. package/dist/{game-CljaDv4D.d.ts → game-Bj8G1wmD.d.ts} +102 -11
  5. package/dist/hot.d.ts +4 -4
  6. package/dist/index.d.ts +712 -118
  7. package/dist/index.js +12423 -4955
  8. package/dist/{gpu-readback-CqJEfWNQ.d.ts → model-lod-BDAUYgsS.d.ts} +80 -5
  9. package/dist/playtest.d.ts +6 -10
  10. package/dist/playtest.js +47 -24
  11. package/dist/react-css.d.ts +62 -0
  12. package/dist/react-css.js +591 -0
  13. package/dist/react.d.ts +2 -2
  14. package/dist/{renderer-CfsS2hxi.d.ts → renderer-9yEo9hPa.d.ts} +489 -22
  15. package/dist/terrain-jobs-worker.d.ts +2 -0
  16. package/dist/terrain-jobs-worker.js +130 -0
  17. package/dist/ui-layer.js +59 -8
  18. package/dist/world.d.ts +766 -73
  19. package/dist/world.js +9307 -3543
  20. package/gpl/recipes/export_world.py +18 -1
  21. package/mcp/blender-server.mjs +7 -4
  22. package/mcp/blender.mjs +3 -4
  23. package/mcp/engine-server.mjs +2 -2
  24. package/mcp/servers.mjs +4 -4
  25. package/package.json +15 -9
  26. package/patches/three@0.185.1-prd269-upgrade.patch +22418 -0
  27. package/patches/three@0.185.1.patch +6594 -700
  28. package/scripts/apply-three-patch.mjs +62 -4
  29. package/src/animation-blend.ts +264 -0
  30. package/src/animation-composition.ts +362 -0
  31. package/src/animation-layers.ts +260 -0
  32. package/src/animation-root-motion.ts +283 -0
  33. package/src/animation.ts +896 -0
  34. package/src/assets.ts +1303 -0
  35. package/src/atmosphere/index.ts +335 -0
  36. package/src/atmosphere/luts.ts +298 -0
  37. package/src/atmosphere/params.ts +323 -0
  38. package/src/audio.ts +912 -0
  39. package/src/billboard.ts +124 -0
  40. package/src/bone-lengths.ts +157 -0
  41. package/src/camera-shake.ts +116 -0
  42. package/src/canvas-layer.ts +47 -0
  43. package/src/clip-audit.ts +401 -0
  44. package/src/clustered-batch.ts +492 -0
  45. package/src/clustered-mesh.ts +638 -0
  46. package/src/compute-driven.ts +176 -0
  47. package/src/compute-timing.ts +318 -0
  48. package/src/config.ts +593 -0
  49. package/src/debug.ts +82 -0
  50. package/src/engine-render-hook.ts +25 -0
  51. package/src/entities.ts +79 -0
  52. package/src/entity-snapshot.ts +53 -0
  53. package/src/flight.ts +683 -0
  54. package/src/fluid-field.ts +748 -0
  55. package/src/fluid-particles.ts +1253 -0
  56. package/src/frame-budget.ts +1368 -0
  57. package/src/game.ts +2390 -0
  58. package/src/geometry-capture.ts +1098 -0
  59. package/src/gpu-class.ts +160 -0
  60. package/src/gpu-frame-observation.ts +424 -0
  61. package/src/gpu-readback.ts +143 -0
  62. package/src/gpu-scene-bvh.ts +464 -0
  63. package/src/grounding.ts +100 -0
  64. package/src/hot.ts +161 -0
  65. package/src/import-meta.d.ts +13 -0
  66. package/src/index.ts +1536 -0
  67. package/src/input.ts +690 -0
  68. package/src/instanced-batch-lod.ts +283 -0
  69. package/src/instanced-batch.ts +274 -0
  70. package/src/interpolation.ts +129 -0
  71. package/src/launch-diagnostics.ts +161 -0
  72. package/src/loop.ts +564 -0
  73. package/src/matrix-world.ts +245 -0
  74. package/src/merge-parts.ts +812 -0
  75. package/src/model-lod.ts +1315 -0
  76. package/src/net-protocol.ts +333 -0
  77. package/src/net-session.ts +477 -0
  78. package/src/net.ts +80 -0
  79. package/src/ocean/fft.ts +72 -0
  80. package/src/ocean/spectral.ts +728 -0
  81. package/src/particle-significance.ts +102 -0
  82. package/src/particles.ts +648 -0
  83. package/src/path-follow.ts +175 -0
  84. package/src/picking.ts +250 -0
  85. package/src/pipeline-census.ts +1566 -0
  86. package/src/platform.ts +210 -0
  87. package/src/playtest.ts +839 -0
  88. package/src/pointer-events.ts +411 -0
  89. package/src/pose-measure.ts +435 -0
  90. package/src/profiling/FrameCounters.ts +231 -0
  91. package/src/profiling/Spans.ts +548 -0
  92. package/src/profiling/opacity-convention.ts +21 -0
  93. package/src/profiling/render-list-validate.ts +175 -0
  94. package/src/profiling/render-trap-audit.ts +84 -0
  95. package/src/profiling/scene-warning.ts +190 -0
  96. package/src/profiling/span-probes.ts +191 -0
  97. package/src/profiling/unlit-foliage-warning.ts +149 -0
  98. package/src/projection-apply.ts +1529 -0
  99. package/src/projection-marker.ts +142 -0
  100. package/src/projection-plan.ts +1258 -0
  101. package/src/projection-skinned.ts +419 -0
  102. package/src/projection-stability.ts +409 -0
  103. package/src/projection-uniform.ts +328 -0
  104. package/src/random.ts +41 -0
  105. package/src/react-css.ts +604 -0
  106. package/src/react-glyphs.ts +114 -0
  107. package/src/react-host.ts +576 -0
  108. package/src/react-layout.ts +265 -0
  109. package/src/react.ts +60 -0
  110. package/src/render/alpha-antialiasing.ts +159 -0
  111. package/src/render/batched-velocity.ts +126 -0
  112. package/src/render/chain.ts +1021 -0
  113. package/src/render/daylight.ts +189 -0
  114. package/src/render/depth-pyramid.ts +596 -0
  115. package/src/render/foliage-alpha.ts +166 -0
  116. package/src/render/material-key.ts +60 -0
  117. package/src/render/mesh-pool.ts +144 -0
  118. package/src/render/probe-volume.ts +1668 -0
  119. package/src/render/resolution-subrect.ts +253 -0
  120. package/src/render/velocity.ts +442 -0
  121. package/src/render/virtual-shadow-pages.ts +827 -0
  122. package/src/render/virtual-shadow-partial.ts +174 -0
  123. package/src/render/virtual-shadow.ts +3330 -0
  124. package/src/render/world-impostor-surface.ts +722 -0
  125. package/src/render/world-impostor.ts +558 -0
  126. package/src/render-camera-cull.ts +441 -0
  127. package/src/render-pass-budget.ts +501 -0
  128. package/src/renderProjection.ts +758 -0
  129. package/src/renderer-config.ts +127 -0
  130. package/src/renderer.ts +1847 -0
  131. package/src/replay-protocol.ts +85 -0
  132. package/src/replay.ts +205 -0
  133. package/src/resolution-scaler.ts +819 -0
  134. package/src/rig-preparation.ts +271 -0
  135. package/src/ripple-field.ts +432 -0
  136. package/src/scale.ts +109 -0
  137. package/src/scene.ts +239 -0
  138. package/src/schedule.ts +155 -0
  139. package/src/skeletal-mesh.ts +61 -0
  140. package/src/skeleton.ts +100 -0
  141. package/src/snow-field.ts +744 -0
  142. package/src/softbody-topology.ts +269 -0
  143. package/src/softbody.ts +516 -0
  144. package/src/sprite-animator.ts +222 -0
  145. package/src/startup-readiness.ts +386 -0
  146. package/src/state.ts +66 -0
  147. package/src/static-transform.ts +274 -0
  148. package/src/storage-buffer.ts +253 -0
  149. package/src/streaming.ts +308 -0
  150. package/src/target-fps.ts +92 -0
  151. package/src/terrain-jobs-worker.ts +17 -0
  152. package/src/terrain-jobs.ts +353 -0
  153. package/src/textures.ts +39 -0
  154. package/src/tracers.ts +237 -0
  155. package/src/ui-bridge.ts +368 -0
  156. package/src/ui-hit-regions.ts +380 -0
  157. package/src/ui-layer.ts +83 -0
  158. package/src/ui-state.ts +220 -0
  159. package/src/version.ts +2 -0
  160. package/src/viewport.ts +253 -0
  161. package/src/warmup.ts +1357 -0
  162. package/src/water-surface.ts +384 -0
  163. package/src/wave-field.ts +524 -0
  164. package/src/world-capabilities.ts +131 -0
  165. package/src/world-cell-proxy.ts +392 -0
  166. package/src/world-cells.ts +10564 -0
  167. package/src/world-gpu-scene.ts +3354 -0
  168. package/src/world-heightmap.ts +82 -0
  169. package/src/world-package.ts +469 -0
  170. package/src/world-passes.ts +582 -0
  171. package/src/world-region.ts +17 -0
  172. package/src/world-terrain-splat.ts +564 -0
  173. package/src/world-tiles.ts +3826 -0
  174. package/src/world-topology.ts +370 -0
  175. package/src/world-validate.ts +48 -0
  176. package/src/world.ts +805 -0
@@ -0,0 +1,401 @@
1
+ import {
2
+ type AnimationClip,
3
+ AnimationMixer,
4
+ type Bone,
5
+ MathUtils,
6
+ type Object3D,
7
+ PropertyBinding,
8
+ Quaternion,
9
+ type SkinnedMesh,
10
+ type Vector3,
11
+ getConsoleFunction,
12
+ setConsoleFunction,
13
+ } from "three";
14
+ import { bonesIn } from "./skeleton.js";
15
+
16
+ /** One track of a clip, and whether it resolves to a real property on a root. */
17
+ export interface IClipTrackBinding {
18
+ readonly track: string;
19
+ /** The node the track names, or `null` when nothing under the root carries that name. */
20
+ readonly node: string | null;
21
+ readonly bound: boolean;
22
+ /** Three.js's own reason the track binds nothing. `null` when it binds. */
23
+ readonly reason: string | null;
24
+ }
25
+
26
+ export interface IClipBindingReport {
27
+ readonly clip: string;
28
+ readonly tracks: number;
29
+ readonly bound: number;
30
+ /** Every track that drives nothing, in clip order. */
31
+ readonly unbound: readonly IClipTrackBinding[];
32
+ }
33
+
34
+ export interface IClipCoverageReport {
35
+ readonly clip: string;
36
+ readonly bones: number;
37
+ readonly driven: readonly string[];
38
+ /** Bones no bound track touches. They hold whatever the previous clip left them in. */
39
+ readonly undriven: readonly string[];
40
+ }
41
+
42
+ export interface IClipPoseSubject {
43
+ readonly root: Object3D;
44
+ readonly clip: AnimationClip;
45
+ }
46
+
47
+ export interface IClipPoseErrorOptions {
48
+ /** Measured bone name to reference bone name. Defaults to the names the two rigs share. */
49
+ readonly bones?: Readonly<Record<string, string>>;
50
+ /** Poses compared across the clip. Defaults to 8. */
51
+ readonly samples?: number;
52
+ }
53
+
54
+ export interface IBonePoseError {
55
+ readonly bone: string;
56
+ readonly reference: string;
57
+ readonly meanDegrees: number;
58
+ readonly maxDegrees: number;
59
+ readonly maxAtSeconds: number;
60
+ }
61
+
62
+ export interface IClipPoseErrorReport {
63
+ readonly clip: string;
64
+ readonly referenceClip: string;
65
+ readonly samples: number;
66
+ readonly meanDegrees: number;
67
+ readonly maxDegrees: number;
68
+ /** Every compared bone, worst mean first. */
69
+ readonly bones: readonly IBonePoseError[];
70
+ }
71
+
72
+ interface IResolvedTrack {
73
+ readonly binding: IClipTrackBinding;
74
+ readonly node: Object3D | null;
75
+ }
76
+
77
+ interface IPropertyBindingWithTarget extends PropertyBinding {
78
+ readonly targetObject?: unknown;
79
+ }
80
+
81
+ function label(object: Object3D): string {
82
+ return object.name || object.type;
83
+ }
84
+
85
+ /**
86
+ * Bind one track the way `AnimationMixer` does and capture the reason it fails.
87
+ *
88
+ * `PropertyBinding.bind()` reports every bail-out through Three.js's console hook and binds
89
+ * nothing after it, so a captured message is exactly "this track drives nothing" — with Three.js's
90
+ * own wording. Reading it through `setConsoleFunction` keeps the diagnostic out of the page
91
+ * console, where it would fail a scenario's `noConsoleErrors` before anyone read it.
92
+ */
93
+ function bindTrack(root: Object3D, path: string): IResolvedTrack {
94
+ let nodeName: string;
95
+ try {
96
+ nodeName = PropertyBinding.parseTrackName(path).nodeName;
97
+ } catch (cause) {
98
+ const reason = cause instanceof Error ? cause.message : String(cause);
99
+ return { binding: { track: path, node: null, bound: false, reason }, node: null };
100
+ }
101
+
102
+ const previous = getConsoleFunction();
103
+ let failure: string | null = null;
104
+ setConsoleFunction((type, message) => {
105
+ if (failure === null && type !== "log") failure = message;
106
+ });
107
+ const propertyBinding = new PropertyBinding(root, path);
108
+ try {
109
+ propertyBinding.bind();
110
+ } finally {
111
+ setConsoleFunction(previous);
112
+ }
113
+
114
+ const reportedNode = PropertyBinding.findNode(root, nodeName) as Object3D | null;
115
+ const bound = failure === null;
116
+ const target = (propertyBinding as IPropertyBindingWithTarget).targetObject;
117
+ const resolvedNode =
118
+ bound &&
119
+ target !== null &&
120
+ typeof target === "object" &&
121
+ (target as { isObject3D?: unknown }).isObject3D === true
122
+ ? (target as Object3D)
123
+ : null;
124
+ return {
125
+ binding: {
126
+ track: path,
127
+ node: bound || reportedNode !== null ? nodeName : null,
128
+ bound,
129
+ reason: failure,
130
+ },
131
+ node: resolvedNode,
132
+ };
133
+ }
134
+
135
+ function resolveTracks(root: Object3D, clip: AnimationClip, caller: string): IResolvedTrack[] {
136
+ if (clip.tracks.length === 0) {
137
+ throw new Error(`${caller}: clip '${clip.name}' has no tracks, so it animates nothing.`);
138
+ }
139
+ return clip.tracks.map((track) => bindTrack(root, track.name));
140
+ }
141
+
142
+ /**
143
+ * Report which of a clip's tracks resolve to a real property on `root`.
144
+ *
145
+ * A retarget that writes the wrong glTF target path produces tracks named `<bone>.undefined`:
146
+ * they load without error, bind nothing, and the character plays its bind pose.
147
+ */
148
+ export function clipTrackBindings(root: Object3D, clip: AnimationClip): IClipBindingReport {
149
+ const resolved = resolveTracks(root, clip, "clipTrackBindings");
150
+ const unbound = resolved.filter(({ binding }) => !binding.bound).map(({ binding }) => binding);
151
+ return {
152
+ clip: clip.name,
153
+ tracks: resolved.length,
154
+ bound: resolved.length - unbound.length,
155
+ unbound,
156
+ };
157
+ }
158
+
159
+ /**
160
+ * Report which bones of `root` a clip does not drive.
161
+ *
162
+ * An undriven bone keeps whatever the previous clip left it in, so a rig whose clips cover 22 of
163
+ * 65 bones carries the last walk cycle's hand shape into every pose that follows.
164
+ */
165
+ export function clipBoneCoverage(root: Object3D, clip: AnimationClip): IClipCoverageReport {
166
+ const bones = bonesIn(root);
167
+ if (bones.length === 0) {
168
+ throw new Error(`clipBoneCoverage: '${label(root)}' has no bones.`);
169
+ }
170
+ const driven = new Set<Object3D>();
171
+ for (const { node } of resolveTracks(root, clip, "clipBoneCoverage")) {
172
+ if (node !== null) driven.add(node);
173
+ }
174
+ const drivenNames: string[] = [];
175
+ const undrivenNames: string[] = [];
176
+ for (const bone of bones) (driven.has(bone) ? drivenNames : undrivenNames).push(bone.name);
177
+ return {
178
+ clip: clip.name,
179
+ bones: bones.length,
180
+ driven: drivenNames,
181
+ undriven: undrivenNames,
182
+ };
183
+ }
184
+
185
+ interface ITransformSnapshot {
186
+ readonly object: Object3D;
187
+ readonly position: Vector3;
188
+ readonly quaternion: Quaternion;
189
+ readonly scale: Vector3;
190
+ }
191
+
192
+ function snapshotTransforms(root: Object3D): ITransformSnapshot[] {
193
+ const snapshot: ITransformSnapshot[] = [];
194
+ root.traverse((object) => {
195
+ snapshot.push({
196
+ object,
197
+ position: object.position.clone(),
198
+ quaternion: object.quaternion.clone(),
199
+ scale: object.scale.clone(),
200
+ });
201
+ });
202
+ return snapshot;
203
+ }
204
+
205
+ function restoreTransforms(root: Object3D, snapshot: readonly ITransformSnapshot[]): void {
206
+ for (const entry of snapshot) {
207
+ entry.object.position.copy(entry.position);
208
+ entry.object.quaternion.copy(entry.quaternion);
209
+ entry.object.scale.copy(entry.scale);
210
+ }
211
+ root.updateMatrixWorld(true);
212
+ }
213
+
214
+ /** A bone on each rig, its rest rotation on each rig, and the error accumulated so far. */
215
+ interface IPairState {
216
+ readonly bone: string;
217
+ readonly reference: string;
218
+ readonly subjectBone: Bone;
219
+ readonly referenceBone: Bone;
220
+ readonly subjectRest: Quaternion;
221
+ readonly referenceRest: Quaternion;
222
+ sum: number;
223
+ max: number;
224
+ at: number;
225
+ }
226
+
227
+ /** Return every skeleton under `root` to its bind pose, so rest rotations are read, not assumed. */
228
+ function toBindPose(root: Object3D): void {
229
+ root.traverse((object) => {
230
+ const skinned = object as SkinnedMesh;
231
+ if (skinned.isSkinnedMesh === true) skinned.skeleton.pose();
232
+ });
233
+ root.updateMatrixWorld(true);
234
+ }
235
+
236
+ function boneByName(root: Object3D, name: string, side: string): Bone {
237
+ const bone = bonesIn(root).find((candidate) => candidate.name === name);
238
+ if (bone === undefined) {
239
+ throw new Error(`clipPoseError: the ${side} rig '${label(root)}' has no bone named '${name}'.`);
240
+ }
241
+ return bone;
242
+ }
243
+
244
+ function boneNamePairs(
245
+ subject: Object3D,
246
+ reference: Object3D,
247
+ requested: Readonly<Record<string, string>> | undefined,
248
+ ): readonly (readonly [string, string])[] {
249
+ if (requested !== undefined) {
250
+ const pairs = Object.entries(requested);
251
+ if (pairs.length === 0) throw new Error("clipPoseError: bones must name at least one pair.");
252
+ return pairs;
253
+ }
254
+ const referenceNames = new Set(bonesIn(reference).map((bone) => bone.name));
255
+ const shared = bonesIn(subject)
256
+ .map((bone) => bone.name)
257
+ .filter((name) => referenceNames.has(name))
258
+ .map((name) => [name, name] as const);
259
+ if (shared.length === 0) {
260
+ throw new Error(
261
+ "clipPoseError: the two rigs share no bone names. Pass bones to map one rig onto the other.",
262
+ );
263
+ }
264
+ return shared;
265
+ }
266
+
267
+ function duration(subject: IClipPoseSubject, side: string): number {
268
+ const seconds = subject.clip.duration;
269
+ if (!Number.isFinite(seconds) || seconds <= 0) {
270
+ throw new Error(`clipPoseError: the ${side} clip '${subject.clip.name}' has no duration.`);
271
+ }
272
+ return seconds;
273
+ }
274
+
275
+ function isSameOrAncestor(ancestor: Object3D, object: Object3D): boolean {
276
+ let current: Object3D | null = object;
277
+ while (current !== null) {
278
+ if (current === ancestor) return true;
279
+ current = current.parent;
280
+ }
281
+ return false;
282
+ }
283
+
284
+ function assertDisjointRoots(subject: Object3D, reference: Object3D): void {
285
+ if (isSameOrAncestor(subject, reference) || isSameOrAncestor(reference, subject)) {
286
+ throw new Error(
287
+ `clipPoseError: subject and reference roots overlap ('${label(subject)}' and '${label(reference)}'); pass two disjoint roots.`,
288
+ );
289
+ }
290
+ }
291
+
292
+ /**
293
+ * Score how far a clip's pose is from the same pose on a reference rig, in degrees.
294
+ *
295
+ * Each bone is compared as its world rotation *relative to its own rig's bind pose*, as a whole
296
+ * quaternion. The delta makes the two rigs' bind conventions cancel, so rigs whose arms sit 90
297
+ * degrees apart at rest still score zero when the retarget is right; the whole quaternion makes
298
+ * twist count, which a bone-direction check cannot see — a forearm rolled about its own axis
299
+ * points exactly where it should while the skin between elbow and wrist tears into a smear.
300
+ *
301
+ * Both rigs are driven and then restored to the transforms they arrived with.
302
+ */
303
+ export function clipPoseError(
304
+ subject: IClipPoseSubject,
305
+ reference: IClipPoseSubject,
306
+ options: IClipPoseErrorOptions = {},
307
+ ): IClipPoseErrorReport {
308
+ const samples = options.samples ?? 8;
309
+ if (!Number.isInteger(samples) || samples < 1) {
310
+ throw new Error(`clipPoseError: samples must be a positive integer, received ${samples}.`);
311
+ }
312
+ assertDisjointRoots(subject.root, reference.root);
313
+ const names = boneNamePairs(subject.root, reference.root, options.bones);
314
+ const subjectSeconds = duration(subject, "measured");
315
+ const referenceSeconds = duration(reference, "reference");
316
+ const pairs: IPairState[] = names.map(([bone, referenceBone]) => ({
317
+ bone,
318
+ reference: referenceBone,
319
+ subjectBone: boneByName(subject.root, bone, "measured"),
320
+ referenceBone: boneByName(reference.root, referenceBone, "reference"),
321
+ subjectRest: new Quaternion(),
322
+ referenceRest: new Quaternion(),
323
+ sum: 0,
324
+ max: 0,
325
+ at: 0,
326
+ }));
327
+
328
+ const subjectSnapshot = snapshotTransforms(subject.root);
329
+ const referenceSnapshot = snapshotTransforms(reference.root);
330
+ const subjectMixer = new AnimationMixer(subject.root);
331
+ const referenceMixer = new AnimationMixer(reference.root);
332
+ try {
333
+ toBindPose(subject.root);
334
+ toBindPose(reference.root);
335
+ for (const pair of pairs) {
336
+ pair.subjectBone.getWorldQuaternion(pair.subjectRest);
337
+ pair.referenceBone.getWorldQuaternion(pair.referenceRest);
338
+ }
339
+ subjectMixer.clipAction(subject.clip).play();
340
+ referenceMixer.clipAction(reference.clip).play();
341
+
342
+ const measured = new Quaternion();
343
+ const expected = new Quaternion();
344
+ const world = new Quaternion();
345
+ let elapsedSubject = 0;
346
+ let elapsedReference = 0;
347
+ for (let sample = 0; sample < samples; sample += 1) {
348
+ const phase = (sample + 0.5) / samples;
349
+ const subjectTime = subjectSeconds * phase;
350
+ const referenceTime = referenceSeconds * phase;
351
+ subjectMixer.update(subjectTime - elapsedSubject);
352
+ referenceMixer.update(referenceTime - elapsedReference);
353
+ elapsedSubject = subjectTime;
354
+ elapsedReference = referenceTime;
355
+ subject.root.updateMatrixWorld(true);
356
+ reference.root.updateMatrixWorld(true);
357
+
358
+ for (const pair of pairs) {
359
+ deltaFromRest(pair.subjectBone, pair.subjectRest, world, measured);
360
+ deltaFromRest(pair.referenceBone, pair.referenceRest, world, expected);
361
+ const degrees =
362
+ 2 * Math.acos(Math.min(1, Math.abs(measured.dot(expected)))) * MathUtils.RAD2DEG;
363
+ pair.sum += degrees;
364
+ if (degrees > pair.max) {
365
+ pair.max = degrees;
366
+ pair.at = subjectTime;
367
+ }
368
+ }
369
+ }
370
+ } finally {
371
+ subjectMixer.stopAllAction();
372
+ referenceMixer.stopAllAction();
373
+ subjectMixer.uncacheRoot(subject.root);
374
+ referenceMixer.uncacheRoot(reference.root);
375
+ restoreTransforms(subject.root, subjectSnapshot);
376
+ restoreTransforms(reference.root, referenceSnapshot);
377
+ }
378
+
379
+ const bones: IBonePoseError[] = pairs
380
+ .map((pair) => ({
381
+ bone: pair.bone,
382
+ reference: pair.reference,
383
+ meanDegrees: pair.sum / samples,
384
+ maxDegrees: pair.max,
385
+ maxAtSeconds: pair.at,
386
+ }))
387
+ .sort((left, right) => right.meanDegrees - left.meanDegrees);
388
+ return {
389
+ clip: subject.clip.name,
390
+ referenceClip: reference.clip.name,
391
+ samples,
392
+ meanDegrees: bones.reduce((sum, bone) => sum + bone.meanDegrees, 0) / bones.length,
393
+ maxDegrees: bones.reduce((most, bone) => Math.max(most, bone.maxDegrees), 0),
394
+ bones,
395
+ };
396
+ }
397
+
398
+ function deltaFromRest(bone: Bone, rest: Quaternion, world: Quaternion, out: Quaternion): void {
399
+ bone.getWorldQuaternion(world);
400
+ out.copy(rest).invert().premultiply(world);
401
+ }