@margoengine/rigging 0.0.0-stage → 0.1.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 (71) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +4 -0
  3. package/README.md +969 -3
  4. package/dist/autorig.d.ts +50 -0
  5. package/dist/autorig.js +660 -0
  6. package/dist/bar-grip.d.ts +7 -0
  7. package/dist/checks.d.ts +50 -0
  8. package/dist/contact.d.ts +175 -0
  9. package/dist/contact.js +739 -0
  10. package/dist/correctives.d.ts +92 -0
  11. package/dist/correctives.js +162 -0
  12. package/dist/errors-D8rc8kzg.js +7 -0
  13. package/dist/face.d.ts +93 -0
  14. package/dist/face.js +144 -0
  15. package/dist/hands.d.ts +209 -0
  16. package/dist/hands.js +510 -0
  17. package/dist/heat.d.ts +38 -0
  18. package/dist/hinged-contact.d.ts +7 -0
  19. package/dist/hulls.d.ts +54 -0
  20. package/dist/hulls.js +134 -0
  21. package/dist/ik.d.ts +109 -0
  22. package/dist/ik.js +358 -0
  23. package/dist/index.d.ts +6 -0
  24. package/dist/index.js +390 -0
  25. package/dist/joint-limits.d.ts +44 -0
  26. package/dist/joint-limits.js +74 -0
  27. package/dist/limb-collision.d.ts +99 -0
  28. package/dist/loading-CZaYr1N7.js +67 -0
  29. package/dist/mesh-CyvLHNp0.js +142 -0
  30. package/dist/mesh.d.ts +47 -0
  31. package/dist/mtoon-data.d.ts +118 -0
  32. package/dist/mtoon-legacy.d.ts +17 -0
  33. package/dist/mtoon-shader.d.ts +4 -0
  34. package/dist/mtoon.d.ts +84 -0
  35. package/dist/mtoon.js +990 -0
  36. package/dist/paint.d.ts +82 -0
  37. package/dist/pose-tracking.d.ts +117 -0
  38. package/dist/pose-tracking.js +488 -0
  39. package/dist/retarget.d.ts +71 -0
  40. package/dist/retarget.js +351 -0
  41. package/dist/rig-BawZ5OLb.js +127 -0
  42. package/dist/rig.d.ts +65 -0
  43. package/dist/shared/gltf.d.ts +257 -0
  44. package/dist/shared/layers.d.ts +16 -0
  45. package/dist/springs.d.ts +180 -0
  46. package/dist/springs.js +458 -0
  47. package/dist/strand-springs.d.ts +46 -0
  48. package/dist/strand-springs.js +168 -0
  49. package/dist/swim.d.ts +55 -0
  50. package/dist/swim.js +167 -0
  51. package/dist/transfer.d.ts +41 -0
  52. package/dist/transfer.js +136 -0
  53. package/dist/voxel-weights-48ok-Dax.js +255 -0
  54. package/dist/voxel-weights.d.ts +42 -0
  55. package/dist/voxel-weights.js +1 -0
  56. package/dist/voxels.d.ts +36 -0
  57. package/dist/vrm-constraints.d.ts +60 -0
  58. package/dist/vrm-constraints.js +261 -0
  59. package/dist/vrm-first-person.d.ts +115 -0
  60. package/dist/vrm-first-person.js +618 -0
  61. package/dist/vrm-presets-CU4V4yq6.js +47 -0
  62. package/dist/vrm-presets.d.ts +1 -0
  63. package/dist/vrm.d.ts +298 -0
  64. package/dist/vrm.js +574 -0
  65. package/dist/vrm0.d.ts +134 -0
  66. package/dist/vrm0.js +377 -0
  67. package/dist/vrma.d.ts +90 -0
  68. package/dist/vrma.js +315 -0
  69. package/dist/weight-map-D8cAONQQ.js +92 -0
  70. package/dist/weight-map.d.ts +58 -0
  71. package/package.json +175 -6
@@ -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;