@margoengine/rigging 0.0.0-stage → 1.0.0

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 (84) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +4 -0
  3. package/README.md +1443 -2
  4. package/dist/anatomy-data-ansur2.d.ts +63 -0
  5. package/dist/anatomy-data-cdc.d.ts +16 -0
  6. package/dist/anatomy-data-deleva.d.ts +86 -0
  7. package/dist/anatomy-human.d.ts +67 -0
  8. package/dist/anatomy-human.js +2229 -0
  9. package/dist/anatomy.d.ts +638 -0
  10. package/dist/anatomy.js +1112 -0
  11. package/dist/autorig.d.ts +50 -0
  12. package/dist/autorig.js +663 -0
  13. package/dist/bar-grip.d.ts +7 -0
  14. package/dist/body-volumes-DTym0RVY.js +56 -0
  15. package/dist/body-volumes.d.ts +19 -0
  16. package/dist/checks.d.ts +50 -0
  17. package/dist/contact.d.ts +186 -0
  18. package/dist/contact.js +746 -0
  19. package/dist/correctives.d.ts +92 -0
  20. package/dist/correctives.js +162 -0
  21. package/dist/coupling.d.ts +57 -0
  22. package/dist/coupling.js +330 -0
  23. package/dist/errors-D8rc8kzg.js +7 -0
  24. package/dist/face.d.ts +93 -0
  25. package/dist/face.js +144 -0
  26. package/dist/hands.d.ts +209 -0
  27. package/dist/hands.js +510 -0
  28. package/dist/heat.d.ts +38 -0
  29. package/dist/hinged-contact.d.ts +7 -0
  30. package/dist/hulls.d.ts +54 -0
  31. package/dist/hulls.js +134 -0
  32. package/dist/ik.d.ts +162 -0
  33. package/dist/ik.js +561 -0
  34. package/dist/index.d.ts +6 -0
  35. package/dist/index.js +390 -0
  36. package/dist/joint-limits.d.ts +44 -0
  37. package/dist/joint-limits.js +74 -0
  38. package/dist/limb-collision.d.ts +99 -0
  39. package/dist/loading-CZaYr1N7.js +67 -0
  40. package/dist/mesh-CyvLHNp0.js +142 -0
  41. package/dist/mesh.d.ts +47 -0
  42. package/dist/mtoon-data.d.ts +118 -0
  43. package/dist/mtoon-legacy.d.ts +17 -0
  44. package/dist/mtoon-shader.d.ts +4 -0
  45. package/dist/mtoon.d.ts +84 -0
  46. package/dist/mtoon.js +990 -0
  47. package/dist/paint.d.ts +82 -0
  48. package/dist/pose-tracking.d.ts +117 -0
  49. package/dist/pose-tracking.js +488 -0
  50. package/dist/retarget.d.ts +78 -0
  51. package/dist/retarget.js +375 -0
  52. package/dist/rig-BawZ5OLb.js +127 -0
  53. package/dist/rig.d.ts +65 -0
  54. package/dist/shared/gltf.d.ts +257 -0
  55. package/dist/shared/layers.d.ts +16 -0
  56. package/dist/springs.d.ts +180 -0
  57. package/dist/springs.js +458 -0
  58. package/dist/strand-springs.d.ts +46 -0
  59. package/dist/strand-springs.js +168 -0
  60. package/dist/swim.d.ts +55 -0
  61. package/dist/swim.js +167 -0
  62. package/dist/transfer.d.ts +41 -0
  63. package/dist/transfer.js +136 -0
  64. package/dist/validate.d.ts +188 -0
  65. package/dist/validate.js +440 -0
  66. package/dist/voxel-weights-48ok-Dax.js +255 -0
  67. package/dist/voxel-weights.d.ts +42 -0
  68. package/dist/voxel-weights.js +1 -0
  69. package/dist/voxels.d.ts +36 -0
  70. package/dist/vrm-constraints.d.ts +60 -0
  71. package/dist/vrm-constraints.js +261 -0
  72. package/dist/vrm-first-person.d.ts +115 -0
  73. package/dist/vrm-first-person.js +618 -0
  74. package/dist/vrm-presets-CU4V4yq6.js +47 -0
  75. package/dist/vrm-presets.d.ts +1 -0
  76. package/dist/vrm.d.ts +303 -0
  77. package/dist/vrm.js +574 -0
  78. package/dist/vrm0.d.ts +134 -0
  79. package/dist/vrm0.js +377 -0
  80. package/dist/vrma.d.ts +90 -0
  81. package/dist/vrma.js +315 -0
  82. package/dist/weight-map-D8cAONQQ.js +92 -0
  83. package/dist/weight-map.d.ts +58 -0
  84. package/package.json +189 -4
package/dist/face.d.ts ADDED
@@ -0,0 +1,93 @@
1
+ // @ts-ignore optional peer: its types apply when it is installed
2
+ import type { Animator } from '@margoengine/animator';
3
+ import type { VRMHandle } from './vrm.js';
4
+ /** The 52 face shapes, in the order of Apple's documentation. Left and right are the face's own. */
5
+ export declare const FACE_SHAPES: readonly ['eyeBlinkLeft', 'eyeLookDownLeft', 'eyeLookInLeft', 'eyeLookOutLeft', 'eyeLookUpLeft', 'eyeSquintLeft', 'eyeWideLeft', 'eyeBlinkRight', 'eyeLookDownRight', 'eyeLookInRight', 'eyeLookOutRight', 'eyeLookUpRight', 'eyeSquintRight', 'eyeWideRight', 'jawForward', 'jawLeft', 'jawRight', 'jawOpen', 'mouthClose', 'mouthFunnel', 'mouthPucker', 'mouthLeft', 'mouthRight', 'mouthSmileLeft', 'mouthSmileRight', 'mouthFrownLeft', 'mouthFrownRight', 'mouthDimpleLeft', 'mouthDimpleRight', 'mouthStretchLeft', 'mouthStretchRight', 'mouthRollLower', 'mouthRollUpper', 'mouthShrugLower', 'mouthShrugUpper', 'mouthPressLeft', 'mouthPressRight', 'mouthLowerDownLeft', 'mouthLowerDownRight', 'mouthUpperUpLeft', 'mouthUpperUpRight', 'browDownLeft', 'browDownRight', 'browInnerUp', 'browOuterUpLeft', 'browOuterUpRight', 'cheekPuff', 'cheekSquintLeft', 'cheekSquintRight', 'noseSneerLeft', 'noseSneerRight', 'tongueOut'];
6
+ /** One of the {@link FACE_SHAPES}. */
7
+ export type FaceShape = (typeof FACE_SHAPES)[number];
8
+ /**
9
+ * One tracker frame: a record of shape names to values, or a list of `{ categoryName, score }` as MediaPipe's
10
+ * `faceBlendshapes[0].categories` gives. Names need not match exactly (see {@link faceShapeOf}); others are ignored.
11
+ */
12
+ export type FaceFrame = Readonly<Record<string, number>> | readonly {
13
+ categoryName: string;
14
+ score: number;
15
+ }[];
16
+ /** Options of {@link FaceMapper}. */
17
+ export interface FaceMapperOptions {
18
+ /** Time constant of the smoothing, seconds; 0 follows the tracker exactly (default 0.05). */
19
+ smoothing?: number;
20
+ /** Multiplies values before they clamp to 0 to 1: one number for all, or per shape, the rest at 1 (default 1). */
21
+ gain?: number | Partial<Record<FaceShape, number>>;
22
+ /** Swaps left and right, for a tracker fed by a mirrored camera (default false). */
23
+ mirror?: boolean;
24
+ }
25
+ /**
26
+ * The face shape a name stands for, or null. Ignores case, separators and anything before the shape, so
27
+ * `EyeBlinkLeft`, `eye_blink_left`, `eyeBlink_L` and `blendShape1.ARKit_eyeBlinkLeft` all read as `eyeBlinkLeft`.
28
+ */
29
+ export declare function faceShapeOf(name: string): FaceShape | null;
30
+ /**
31
+ * A tracker's frames as smoothed shape values, plain data with no engine: {@link addFace} runs one on a model. Settings
32
+ * can be changed between frames.
33
+ */
34
+ export declare class FaceMapper {
35
+ /** The 52 current values, in {@link FACE_SHAPES} order. */
36
+ readonly values: Float32Array<ArrayBuffer>;
37
+ /** Seconds; see {@link FaceMapperOptions.smoothing}. */
38
+ smoothing: number;
39
+ /** See {@link FaceMapperOptions.gain}. */
40
+ gain: number | Partial<Record<FaceShape, number>>;
41
+ /** See {@link FaceMapperOptions.mirror}. */
42
+ mirror: boolean;
43
+ private readonly target;
44
+ constructor(options?: FaceMapperOptions);
45
+ private check;
46
+ private take;
47
+ /** Takes a tracker's latest frame; shapes it leaves out hold their value. Pass null when tracking is lost: all go to 0. */
48
+ push(frame: FaceFrame | null): this;
49
+ /** Moves `values` toward the last frame by `delta` seconds, the same at any frame rate. */
50
+ update(delta: number): this;
51
+ /** The current value of `shape`. */
52
+ get(shape: FaceShape): number;
53
+ /** Back to neutral at once. */
54
+ reset(): this;
55
+ }
56
+ /**
57
+ * VRM 1.0 preset expressions from the 52 values. Blinks are split so `blink` holds what both eyes share and
58
+ * `blinkLeft`, `blinkRight` the rest; the look presets are the two eyes' mean. The tracker has no reading for `relaxed`,
59
+ * so it stays out. `get` is a {@link FaceMapper}'s `get`, bound.
60
+ */
61
+ export declare function vrmFaceExpressions(get: (shape: FaceShape) => number): Record<string, number>;
62
+ /** Options of {@link addFace}. */
63
+ export interface AddFaceOptions extends FaceMapperOptions {
64
+ /** Run inside this `Animator`, after its pose; with none, run as an engine plugin. */
65
+ animator?: Animator;
66
+ /** Drive this avatar's expressions rather than morph targets by name. */
67
+ vrm?: VRMHandle;
68
+ /** Morph target names for shapes the names alone do not find: `{ jawOpen: 'Mouth_Open', eyeBlinkLeft: ['A', 'B'] }`. */
69
+ map?: Partial<Record<FaceShape, string | readonly string[]>>;
70
+ }
71
+ /** A running {@link addFace}. */
72
+ export interface FaceHandle {
73
+ readonly mapper: FaceMapper;
74
+ /** Shapes that drive something on this model. Empty with `vrm`, which goes through expressions. */
75
+ readonly matched: readonly FaceShape[];
76
+ /** Shapes with nothing to drive. */
77
+ readonly missing: readonly FaceShape[];
78
+ /** Takes the tracker's latest frame; see {@link FaceMapper.push}. */
79
+ push(frame: FaceFrame | null): void;
80
+ /** Runs one frame by hand; the Animator or the engine does this each frame by itself. */
81
+ update(delta: number): void;
82
+ /** Puts the face back to neutral and stops. */
83
+ dispose(): void;
84
+ [Symbol.dispose](): void;
85
+ }
86
+ /**
87
+ * Drives a character's face from a tracker: call `push` with each tracker frame, at the tracker's own rate. Morph
88
+ * targets are found on every mesh of the model by the names in `extras.targetNames`, so head, teeth and lashes move
89
+ * together; pass `map` for other names, or `vrm` for an avatar. A driven morph target belongs to this: a clip's track
90
+ * on it is overwritten.
91
+ * @throws MargoError (code `state`) when nothing on the model matches or the model already has a live face; RangeError for bad settings.
92
+ */
93
+ export declare function addFace(animation: Animator['animation'], options?: AddFaceOptions): FaceHandle;
package/dist/face.js ADDED
@@ -0,0 +1,144 @@
1
+ // @margo/core-built 1.0.0
2
+ import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
+
4
+ import { MargoError as e } from "@margoengine/math/errors";
5
+ //#region src/face.ts
6
+ var t = /* @__PURE__ */ "eyeBlinkLeft.eyeLookDownLeft.eyeLookInLeft.eyeLookOutLeft.eyeLookUpLeft.eyeSquintLeft.eyeWideLeft.eyeBlinkRight.eyeLookDownRight.eyeLookInRight.eyeLookOutRight.eyeLookUpRight.eyeSquintRight.eyeWideRight.jawForward.jawLeft.jawRight.jawOpen.mouthClose.mouthFunnel.mouthPucker.mouthLeft.mouthRight.mouthSmileLeft.mouthSmileRight.mouthFrownLeft.mouthFrownRight.mouthDimpleLeft.mouthDimpleRight.mouthStretchLeft.mouthStretchRight.mouthRollLower.mouthRollUpper.mouthShrugLower.mouthShrugUpper.mouthPressLeft.mouthPressRight.mouthLowerDownLeft.mouthLowerDownRight.mouthUpperUpLeft.mouthUpperUpRight.browDownLeft.browDownRight.browInnerUp.browOuterUpLeft.browOuterUpRight.cheekPuff.cheekSquintLeft.cheekSquintRight.noseSneerLeft.noseSneerRight.tongueOut".split("."), n = new Map(t.map((e, t) => [e, t])), r = (e) => e.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(), i = t.flatMap((e) => {
7
+ let t = r(e), n = t.replace(/left$/, "l").replace(/right$/, "r");
8
+ return n === t ? [[t, e]] : [[t, e], [n, e]];
9
+ }).sort((e, t) => t[0].length - e[0].length);
10
+ function a(e) {
11
+ if (n.has(e)) return e;
12
+ let t = r(e);
13
+ for (let [e, n] of i) if (t.endsWith(e)) return n;
14
+ return null;
15
+ }
16
+ function o(e) {
17
+ return e.endsWith("Left") ? `${e.slice(0, -4)}Right` : e.endsWith("Right") ? `${e.slice(0, -5)}Left` : e;
18
+ }
19
+ var s = t.map((e) => n.get(o(e))), c = (e) => e < 0 ? 0 : e > 1 ? 1 : e, l = class {
20
+ constructor(e = {}) {
21
+ this.values = new Float32Array(t.length), this.target = new Float32Array(t.length), this.smoothing = e.smoothing ?? .05, this.gain = e.gain ?? 1, this.mirror = e.mirror ?? !1, this.check();
22
+ }
23
+ check() {
24
+ let { smoothing: e, gain: t } = this;
25
+ if (!(e >= 0 && e < Infinity)) throw RangeError("Face smoothing must be 0 or more seconds");
26
+ if (typeof t == "number") {
27
+ if (!(t >= 0 && t < Infinity)) throw RangeError("Face gain must be finite and 0 or more");
28
+ } else if (typeof t != "object" || !t) throw TypeError("Face gain must be a number or a record");
29
+ else for (let [e, r] of Object.entries(t)) {
30
+ if (!n.has(e)) throw RangeError(`Face gain names ${e}; use a name from FACE_SHAPES`);
31
+ if (!(r >= 0 && r < Infinity)) throw RangeError(`Face gain of ${e} must be finite and 0 or more`);
32
+ }
33
+ }
34
+ take(e, t) {
35
+ let r = a(e);
36
+ if (r === null) return;
37
+ if (!Number.isFinite(t)) throw RangeError(`Face value of ${e} must be finite`);
38
+ let i = typeof this.gain == "number" ? this.gain : this.gain[r] ?? 1, o = n.get(r);
39
+ this.target[this.mirror ? s[o] : o] = c(t * i);
40
+ }
41
+ push(e) {
42
+ if (this.check(), e === null) this.target.fill(0);
43
+ else if (Array.isArray(e)) for (let t of e) this.take(t.categoryName, t.score);
44
+ else if (typeof e == "object") for (let [t, n] of Object.entries(e)) this.take(t, n);
45
+ else throw TypeError("A face frame must be a record, a list of {categoryName, score}, or null");
46
+ return this;
47
+ }
48
+ update(e) {
49
+ if (!(e >= 0 && e < Infinity)) throw RangeError("Face update delta must be 0 or more seconds");
50
+ this.check();
51
+ let t = this.smoothing === 0 ? 1 : 1 - Math.exp(-e / this.smoothing);
52
+ for (let e = 0; e < this.values.length; e++) this.values[e] += (this.target[e] - this.values[e]) * t;
53
+ return this;
54
+ }
55
+ get(e) {
56
+ let t = n.get(e);
57
+ if (t === void 0) throw RangeError(`Unknown face shape ${e}; use a name from FACE_SHAPES`);
58
+ return this.values[t];
59
+ }
60
+ reset() {
61
+ return this.values.fill(0), this.target.fill(0), this;
62
+ }
63
+ };
64
+ function u(e) {
65
+ let t = (t, n) => (e(t) + e(n)) / 2, n = e("eyeBlinkLeft"), r = e("eyeBlinkRight"), i = Math.min(n, r);
66
+ return {
67
+ blink: i,
68
+ blinkLeft: n - i,
69
+ blinkRight: r - i,
70
+ lookUp: t("eyeLookUpLeft", "eyeLookUpRight"),
71
+ lookDown: t("eyeLookDownLeft", "eyeLookDownRight"),
72
+ lookLeft: t("eyeLookOutLeft", "eyeLookInRight"),
73
+ lookRight: t("eyeLookInLeft", "eyeLookOutRight"),
74
+ aa: e("jawOpen"),
75
+ ih: t("mouthLowerDownLeft", "mouthLowerDownRight"),
76
+ ou: e("mouthPucker"),
77
+ ee: t("mouthStretchLeft", "mouthStretchRight"),
78
+ oh: e("mouthFunnel"),
79
+ happy: t("mouthSmileLeft", "mouthSmileRight"),
80
+ sad: t("mouthFrownLeft", "mouthFrownRight"),
81
+ angry: t("browDownLeft", "browDownRight"),
82
+ surprised: t("eyeWideLeft", "eyeWideRight")
83
+ };
84
+ }
85
+ var d = /* @__PURE__ */ new WeakSet();
86
+ function f(r, i = {}) {
87
+ let o = new l(i), s = r.model, c = s.root.engine, { animator: f, vrm: p, map: m = {} } = i;
88
+ for (let e of Object.keys(m)) if (!n.has(e)) throw RangeError(`Face map names ${e}; use a name from FACE_SHAPES`);
89
+ let h = /* @__PURE__ */ new Map();
90
+ for (let [e, t] of Object.entries(m)) for (let n of typeof t == "string" ? [t] : t) h.set(n, e);
91
+ let g = [], _ = /* @__PURE__ */ new Set();
92
+ if (!p) for (let { nodeIndex: e, targetNames: t } of s.primitives) t.forEach((t, r) => {
93
+ let i = h.get(t) ?? a(t), o = `${e}:${r}`;
94
+ i === null || _.has(o) || (_.add(o), g.push({
95
+ node: e,
96
+ target: r,
97
+ shape: n.get(i)
98
+ }));
99
+ });
100
+ if (!p && !g.length) throw new e("state", "This model has no morph target named like a face shape; pass map, or vrm for an avatar");
101
+ let v = new Set(g.map((e) => e.shape)), y = p ? [] : t.filter((e, t) => v.has(t)), b = p ? [] : t.filter((e, t) => !v.has(t)), x = (e) => o.get(e), S = () => {
102
+ if (p) for (let [e, t] of Object.entries(u(x))) p.expressions.set(e, t);
103
+ else for (let { node: e, target: t, shape: n } of g) r.setMorph(e, t, o.values[n]);
104
+ }, C = (e) => {
105
+ o.update(e), S();
106
+ };
107
+ if (d.has(s)) throw new e("state", "This model already has a face from addFace; dispose that face before adding another");
108
+ let w = `face:${s.root.id}`, T;
109
+ if (f) T = f.addSolver(C);
110
+ else {
111
+ let e = {coreRequirement:/*@__PURE__*/__margoCoreRequirement("1.0.0",import.meta.url),
112
+ name: w,
113
+ setup() {},
114
+ onPreUpdate: C,
115
+ dispose: () => {
116
+ T && (T = () => {}, O());
117
+ }
118
+ };
119
+ c.use(e), T = () => {
120
+ let t = c.sceneOf(e);
121
+ t?.plugins.get(w) === e && t.removePlugin(w);
122
+ };
123
+ }
124
+ d.add(s);
125
+ let E = () => {
126
+ let e = T;
127
+ T = null, e && d.delete(s), e?.(), D?.(), D = null;
128
+ }, D = s.onDispose(E), O = () => {
129
+ T && (E(), o.reset(), S());
130
+ };
131
+ return {
132
+ mapper: o,
133
+ matched: y,
134
+ missing: b,
135
+ push: (e) => {
136
+ o.push(e);
137
+ },
138
+ update: C,
139
+ dispose: O,
140
+ [Symbol.dispose]: O
141
+ };
142
+ }
143
+ //#endregion
144
+ export { t as FACE_SHAPES, l as FaceMapper, f as addFace, a as faceShapeOf, u as vrmFaceExpressions };
@@ -0,0 +1,209 @@
1
+ /// <reference lib="esnext.disposable" preserve="true" />
2
+ // @ts-ignore optional peer: its types apply when it is installed
3
+ import type { Animator } from '@margoengine/animator';
4
+ import { type HumanoidBone, type SkeletonPreset } from './retarget.js';
5
+ /** The five digits, thumb first. */
6
+ export declare const FINGERS: readonly ['thumb', 'index', 'middle', 'ring', 'little'];
7
+ /** One of {@link FINGERS}. */
8
+ export type FingerName = (typeof FINGERS)[number];
9
+ /** A hand. */
10
+ export type HandSide = 'left' | 'right';
11
+ /**
12
+ * Joint flexion in degrees, per digit: base, middle and tip joints (for the thumb its metacarpal, proximal and distal
13
+ * bones), toward the palm from the rig's rest pose; and `spread` in degrees, away from the middle finger (negative
14
+ * draws a finger in). A digit left out keeps its rest pose.
15
+ */
16
+ export interface HandPoseTable {
17
+ readonly flex: Partial<Record<FingerName, readonly [number, number, number]>>;
18
+ readonly spread?: Partial<Record<FingerName, number>>;
19
+ }
20
+ /** A hand pose: a named one from this module, a power grip of a bar's diameter, or a table of your own. */
21
+ export type HandPose = {
22
+ readonly name: 'relaxed' | 'fist' | 'flat' | 'point' | 'pinch';
23
+ } | {
24
+ readonly name: 'grip';
25
+ readonly diameter: number;
26
+ } | {
27
+ readonly name: 'table';
28
+ readonly table: HandPoseTable;
29
+ };
30
+ /** The rest posture of an idle hand: fingers a little curled, more toward the little finger. */
31
+ export declare const relaxed: () => HandPose;
32
+ /** A closed fist, thumb over the middle phalanges. */
33
+ export declare const fist: () => HandPose;
34
+ /** Straight fingers held together, as in a salute or a pushing palm. */
35
+ export declare const flat: () => HandPose;
36
+ /** The index straight, the other fingers curled under the thumb. */
37
+ export declare const point: () => HandPose;
38
+ /** Thumb and index brought together to hold something small; the other fingers relaxed. */
39
+ export declare const pinch: () => HandPose;
40
+ /**
41
+ * A power grip of a bar of `diameter` metres (Feix et al. 2016, medium wrap): each finger closes joint by joint until it
42
+ * meets the bar, the bar lying across the palm at the knuckles. Default 0.035 (a tool handle or a wing upright).
43
+ * @throws RangeError unless `diameter` is from 0.005 to 0.12 metres.
44
+ */
45
+ export declare function grip(diameter?: number): HandPose;
46
+ /** A pose of your own from a {@link HandPoseTable}. */
47
+ export declare function handPose(table: HandPoseTable): HandPose;
48
+ /** What {@link gripFinger} returns: the joint angles and where the bar lies, in the finger's flexion plane. */
49
+ export interface FingerGrip {
50
+ /** Base, middle and tip joint flexion, degrees. */
51
+ readonly flex: readonly [number, number, number];
52
+ /** The bar's centre: `along` the rest finger from the base joint and `depth` toward the palm side, metres. */
53
+ readonly along: number;
54
+ readonly depth: number;
55
+ /** Joint centres in the plane, base joint at [0, 0], the rest finger along +x, the palm side toward -y; 4 points. */
56
+ readonly points: readonly (readonly [number, number])[];
57
+ /** How far the fingertip's skin is from the bar's surface, metres (negative inside it). */
58
+ readonly tipGap: number;
59
+ /** The deepest a finger's skin goes into the bar, metres (0 when nothing does). */
60
+ readonly depthIn: number;
61
+ }
62
+ /** Options of {@link gripFinger}. */
63
+ export interface FingerGripOptions {
64
+ /** Half the finger's thickness, from a bone's centre line to the skin, metres. Default 0.18 of the first length. */
65
+ thickness?: number;
66
+ /** From the base joint's centre to the palm's skin, metres. Default 0.25 of the first length. */
67
+ palm?: number;
68
+ }
69
+ /**
70
+ * One finger's power grip in its flexion plane (Rijpkema and Girard 1991): with the bar against the palm, the base joint
71
+ * closes until a segment meets it, then the middle joint with the tip joint following at 2/3, then the tip joint alone,
72
+ * each within its range (95, 110 and 80 degrees). The bar lies as deep in the palm as it can with the fingertip on it.
73
+ * @param lengths the three phalanges, base to tip, metres.
74
+ * @param diameter the bar's, metres.
75
+ */
76
+ export declare function gripFinger(lengths: readonly [number, number, number], diameter: number, options?: FingerGripOptions): FingerGrip;
77
+ /** A rig as {@link measureHands} reads it: names, parents and the local rest pose, 10 numbers per bone. */
78
+ export interface HandRig {
79
+ readonly names: readonly string[];
80
+ readonly parents: readonly number[];
81
+ /** Translation xyz, rotation quaternion xyzw, scale xyz per bone. */
82
+ readonly rest: ArrayLike<number>;
83
+ }
84
+ /** One digit of a measured hand. */
85
+ export interface MeasuredFinger {
86
+ /** Bone indices, base to tip. */
87
+ readonly bones: readonly [number, number, number];
88
+ /** Phalanx lengths, metres in the rig's space; the last is estimated (3/4 of the middle one) when the rig has no tip bone. */
89
+ readonly lengths: readonly [number, number, number];
90
+ /** Per bone, the local axis a positive turn about which curls the digit toward the palm. */
91
+ readonly curl: readonly (readonly [number, number, number])[];
92
+ /** The local axis of the base bone a positive turn about which spreads it away from the middle finger; null for the middle finger. */
93
+ readonly spread: readonly [number, number, number] | null;
94
+ }
95
+ /** A hand found on a rig by {@link measureHands}. */
96
+ export interface MeasuredHand {
97
+ readonly side: HandSide;
98
+ /** The hand (wrist) bone. */
99
+ readonly hand: number;
100
+ /** The digits it has. */
101
+ readonly fingers: Partial<Record<FingerName, MeasuredFinger>>;
102
+ /** Unit palm normal in the rig's space at rest, out of the palm. */
103
+ readonly palm: readonly [number, number, number];
104
+ /** Local rest rotation per finger bone. */
105
+ readonly rest: ReadonlyMap<number, readonly number[]>;
106
+ /** World rest frames of the bones (position, rotation), the rig's space. */
107
+ readonly world: (bone: number) => {
108
+ position: readonly number[];
109
+ rotation: readonly number[];
110
+ };
111
+ }
112
+ /**
113
+ * Finds the hands of `rig` and measures them: finger bones through the retarget preset (`preset`, default the one
114
+ * {@link detectSkeleton} finds), phalanx lengths, palm normal, and each joint's curl and spread axes from the rest pose,
115
+ * so a pose turns the fingers the same on any rig. `map` (humanoid bone to bone index, such as a VRM's humanoid
116
+ * section gives) replaces the preset for rigs whose names follow none. A hand without index, middle and little (or ring)
117
+ * fingers is left out.
118
+ * @throws TypeError for a malformed rig; RangeError when no preset matches.
119
+ */
120
+ export declare function measureHands(rig: HandRig, preset?: SkeletonPreset, map?: ReadonlyMap<HumanoidBone, number>): Partial<Record<HandSide, MeasuredHand>>;
121
+ /** The flexion table `pose` gives on `hand` (a grip is solved for its fingers' lengths). */
122
+ export declare function poseTable(pose: HandPose, hand: MeasuredHand): HandPoseTable;
123
+ /**
124
+ * The local rotations of `hand`'s finger bones for `table`: each bone's rest rotation turned by its flexion about its
125
+ * curl axis, and the base bones first by their spread. Returns bone index to quaternion [x, y, z, w].
126
+ */
127
+ export declare function handRotations(hand: MeasuredHand, table: HandPoseTable): Map<number, number[]>;
128
+ /** How far a local rotation is turned from its rest rotation, degrees. */
129
+ export declare function turnFromRest(rotation: ArrayLike<number>, rest: ArrayLike<number>): number;
130
+ /** A clip as {@link fingerTurn} reads it: `animation.clips[n]` fits. */
131
+ export interface FingerClip {
132
+ readonly tracks: readonly {
133
+ readonly node: number;
134
+ readonly path: string;
135
+ readonly values: ArrayLike<number>;
136
+ }[];
137
+ }
138
+ /**
139
+ * The mean turn of `hand`'s 15 finger joints from rest over `clip`'s keys, degrees: a joint the clip does not key holds
140
+ * its rest pose and counts 0. Mixamo's body clips measure 10 to 15 (near-flat boards), a keyed grip about 60.
141
+ */
142
+ export declare function fingerTurn(clip: FingerClip, hand: MeasuredHand): number;
143
+ /** A key of a hand's layer: from `time` (seconds on the layer's clock) the hand blends to `pose` over `blend` seconds. */
144
+ export interface HandKey {
145
+ readonly time: number;
146
+ /** The pose, or null to give the hand back to the clip (and the automatic rest posture). */
147
+ readonly pose: HandPose | null;
148
+ /** Seconds to reach it, 0 or more. Default 0.25. */
149
+ readonly blend?: number;
150
+ /** How much of the pose wins over the clip, 0 to 1. Default 1. */
151
+ readonly weight?: number;
152
+ }
153
+ /** One hand's layer of {@link addHands}. */
154
+ export interface HandLayer {
155
+ /** The measured hand, or undefined when the rig has none on this side. */
156
+ readonly hand: MeasuredHand | undefined;
157
+ /** The keys, sorted by time; edit them through {@link HandLayer.set} or replace the array. */
158
+ keys: HandKey[];
159
+ /** Blends to `pose` from the layer's current time (null gives the hand back to the clip). Returns the layer. */
160
+ set(pose: HandPose | null, options?: {
161
+ blend?: number;
162
+ weight?: number;
163
+ }): this;
164
+ }
165
+ /** Options of {@link addHands}. */
166
+ export interface HandsOptions {
167
+ /** Left hand's pose from the start, or null to leave it to the clip. Default null. */
168
+ left?: HandPose | null;
169
+ /** Right hand's pose from the start, or null to leave it to the clip. Default null. */
170
+ right?: HandPose | null;
171
+ /**
172
+ * Blends the rest posture into clips whose finger joints turn less than `threshold` degrees on average (flat boards,
173
+ * or no finger tracks at all), so no hand is ever a flat board. Default true.
174
+ */
175
+ auto?: boolean;
176
+ /** Mean finger turn, degrees, below which a clip counts as flat. Default 15. */
177
+ threshold?: number;
178
+ /** The pose `auto` blends in. Default {@link relaxed}(). */
179
+ rest?: HandPose;
180
+ /** The rig's naming preset. Default the one `detectSkeleton` finds. */
181
+ preset?: SkeletonPreset;
182
+ /** Humanoid bone to glTF node index, for a rig no preset names (a VRM's humanoid section). Default none. */
183
+ bones?: ReadonlyMap<HumanoidBone, number>;
184
+ }
185
+ /** A running {@link addHands}. */
186
+ export interface Hands {
187
+ readonly left: HandLayer;
188
+ readonly right: HandLayer;
189
+ /**
190
+ * Seconds on the layers' clock: advances with the Animator's time, and setting it seeks. A hand's pose is a pure
191
+ * function of it and the Animator's state, so a seek gives what playing gives.
192
+ */
193
+ time: number;
194
+ /** The clips `auto` blends the rest posture into, by name, per hand. */
195
+ readonly flat: Readonly<Record<HandSide, readonly string[]>>;
196
+ dispose(): void;
197
+ [Symbol.dispose](): void;
198
+ }
199
+ /**
200
+ * Hand poses on `animator` (`@margoengine/animator`): one layer per hand, keyed over time, over the clip's finger tracks,
201
+ * and by default the rest posture blended into every clip whose fingers are near flat. Runs on the finished pose, before
202
+ * foot IK and the solvers. A rig whose bone names no preset knows, given no `bones` map, gets empty layers. Returns the
203
+ * handle; dispose it to stop.
204
+ * @example
205
+ * const hands = addHands(animator, {right: grip(0.035)});
206
+ * hands.left.set(point(), {blend: 0.4});
207
+ * @throws RangeError for bad keys or options.
208
+ */
209
+ export declare function addHands(animator: Animator, options?: HandsOptions): Hands;