@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/vrm.d.ts ADDED
@@ -0,0 +1,303 @@
1
+ import type { Vec3 } from '@margoengine/math';
2
+ // @ts-ignore optional peer: its types apply when it is installed
3
+ import type { Animator } from '@margoengine/animator';
4
+ import type { HumanoidBone } from './retarget.js';
5
+ import { SpringBones, type SpringBonesOptions } from './springs.js';
6
+ /** The expressions the specification names. */
7
+ export type VRMPresetExpression = 'happy' | 'angry' | 'sad' | 'relaxed' | 'surprised' | 'aa' | 'ih' | 'ou' | 'ee' | 'oh' | 'blink' | 'blinkLeft' | 'blinkRight' | 'lookUp' | 'lookDown' | 'lookLeft' | 'lookRight' | 'neutral';
8
+ /** How an expression holds back lip sync, blinking or gaze: not at all, fully, or in step with its own value. */
9
+ export type VRMOverride = 'none' | 'block' | 'blend';
10
+ /** One expression, with the specification's field names. */
11
+ export interface VRMExpression {
12
+ /** Values above 0.5 count as 1, the rest as 0. */
13
+ isBinary?: boolean;
14
+ /** Morph targets: `node` (with a mesh), target `index`, `weight` at full value. */
15
+ morphTargetBinds?: {
16
+ node: number;
17
+ index: number;
18
+ weight: number;
19
+ }[];
20
+ /** Material colours: `material`, `type`, `targetValue` at full value. */
21
+ materialColorBinds?: {
22
+ material: number;
23
+ type: 'color' | 'emissionColor' | 'shadeColor' | 'matcapColor' | 'rimColor' | 'outlineColor';
24
+ targetValue: [number, number, number, number];
25
+ }[];
26
+ /** Texture moves: `material`, `scale` and `offset` at full value. */
27
+ textureTransformBinds?: {
28
+ material: number;
29
+ scale?: [number, number];
30
+ offset?: [number, number];
31
+ }[];
32
+ overrideBlink?: VRMOverride;
33
+ overrideLookAt?: VRMOverride;
34
+ overrideMouth?: VRMOverride;
35
+ [field: string]: unknown;
36
+ }
37
+ /** A gaze range: gaze up to `inputMaxValue` degrees maps onto 0 to `outputScale`. */
38
+ export interface VRMRangeMap {
39
+ inputMaxValue: number;
40
+ outputScale: number;
41
+ }
42
+ /** `VRMC_vrm.lookAt`. */
43
+ export interface VRMLookAtData {
44
+ /** `bone` turns the eye bones, `expression` drives lookUp, lookDown, lookLeft and lookRight. */
45
+ type: 'bone' | 'expression';
46
+ /** LookAt space's origin in the head bone's space (between the eyes). */
47
+ offsetFromHeadBone?: Vec3;
48
+ rangeMapHorizontalInner?: VRMRangeMap;
49
+ rangeMapHorizontalOuter?: VRMRangeMap;
50
+ rangeMapVerticalDown?: VRMRangeMap;
51
+ rangeMapVerticalUp?: VRMRangeMap;
52
+ [field: string]: unknown;
53
+ }
54
+ /** `VRMC_vrm.meta`: who made the model and what may be done with it. */
55
+ export interface VRMMeta {
56
+ name: string;
57
+ authors: string[];
58
+ licenseUrl: string;
59
+ version?: string;
60
+ [field: string]: unknown;
61
+ }
62
+ /** `VRMC_springBone`, as in the file. */
63
+ export interface VRMSpringBoneData {
64
+ specVersion?: string;
65
+ colliders?: {
66
+ node: number;
67
+ shape: {
68
+ sphere?: {
69
+ offset?: Vec3;
70
+ radius?: number;
71
+ };
72
+ capsule?: {
73
+ offset?: Vec3;
74
+ radius?: number;
75
+ tail?: Vec3;
76
+ };
77
+ };
78
+ }[];
79
+ colliderGroups?: {
80
+ name?: string;
81
+ colliders: number[];
82
+ }[];
83
+ springs?: {
84
+ name?: string;
85
+ joints: {
86
+ node: number;
87
+ hitRadius?: number;
88
+ stiffness?: number;
89
+ gravityPower?: number;
90
+ gravityDir?: Vec3;
91
+ dragForce?: number;
92
+ }[];
93
+ colliderGroups?: number[];
94
+ center?: number;
95
+ }[];
96
+ [field: string]: unknown;
97
+ }
98
+ /** A VRM 1.0 avatar: `VRMC_vrm` as in the file, with `VRMC_springBone` beside it when the file has one. */
99
+ export interface VRMAvatar {
100
+ specVersion: string;
101
+ meta: VRMMeta;
102
+ humanoid: {
103
+ humanBones: Partial<Record<HumanoidBone, {
104
+ node: number;
105
+ }>>;
106
+ [field: string]: unknown;
107
+ };
108
+ expressions?: {
109
+ preset?: Partial<Record<VRMPresetExpression, VRMExpression>>;
110
+ custom?: Record<string, VRMExpression>;
111
+ [field: string]: unknown;
112
+ };
113
+ lookAt?: VRMLookAtData;
114
+ firstPerson?: {
115
+ meshAnnotations?: {
116
+ node: number;
117
+ type: 'auto' | 'both' | 'thirdPersonOnly' | 'firstPersonOnly';
118
+ }[];
119
+ [field: string]: unknown;
120
+ };
121
+ /** `VRMC_springBone`. */
122
+ springBone?: VRMSpringBoneData;
123
+ [field: string]: unknown;
124
+ }
125
+ /** The parts of a glTF document this entry reads. */
126
+ export interface VRMDocument {
127
+ extensions?: Record<string, unknown>;
128
+ extensionsUsed?: string[];
129
+ nodes?: {
130
+ children?: number[];
131
+ mesh?: number;
132
+ scale?: readonly number[];
133
+ rotation?: readonly number[];
134
+ matrix?: readonly number[];
135
+ }[];
136
+ meshes?: {
137
+ primitives: {
138
+ targets?: unknown[];
139
+ }[];
140
+ }[];
141
+ materials?: unknown[];
142
+ [field: string]: unknown;
143
+ }
144
+ /** Humanoid bones a VRM must have. */
145
+ export declare const VRM_REQUIRED_BONES: readonly HumanoidBone[];
146
+ /**
147
+ * Reads the VRM 1.0 avatar of a `.vrm` file's bytes, or of a glTF document (`model.asset.doc`). The result is a copy,
148
+ * so editing it does not touch the document.
149
+ * @throws TypeError for something that is not a VRM, MargoError `unsupported` for VRM 0.x.
150
+ */
151
+ export declare function readVRM(source: Uint8Array | VRMDocument): VRMAvatar;
152
+ /**
153
+ * Every way `avatar` breaks the specification against `doc`: required fields and bones, bone order, scales, binds that
154
+ * point at nothing, spring chains that are not ancestor lines. Empty when it is valid. {@link writeVRM} refuses any.
155
+ */
156
+ export declare function checkVRM(avatar: VRMAvatar, doc: VRMDocument): string[];
157
+ /**
158
+ * Writes `avatar` into a GLB: `VRMC_vrm` and `VRMC_springBone` replace what the file had, and everything else, other
159
+ * extensions, the BIN chunk and later chunks, stays as it was, byte for byte. Turns any rigged GLB into a `.vrm`.
160
+ * @throws TypeError for bytes that are not a GLB, RangeError naming what {@link checkVRM} found.
161
+ */
162
+ export declare function writeVRM(glb: Uint8Array, avatar: VRMAvatar): Uint8Array;
163
+ /** Fields of a new avatar. */
164
+ export interface CreateVRMOptions {
165
+ /** Model name. */
166
+ name: string;
167
+ /** At least one author. */
168
+ authors: string[];
169
+ /** Humanoid bone to glTF node index; `humanoidBones` from `margoengine/rigging/retarget` makes it from node names. */
170
+ bones: ReadonlyMap<HumanoidBone, number> | Partial<Record<HumanoidBone, number>>;
171
+ /** Licence page. Default the VRM Public License 1.0. */
172
+ licenseUrl?: string;
173
+ expressions?: VRMAvatar['expressions'];
174
+ lookAt?: VRMLookAtData;
175
+ /** Spring bones, as in the file. */
176
+ springBone?: VRMSpringBoneData;
177
+ }
178
+ /** A new avatar for {@link writeVRM}, from the fields a VRM must have. The other `meta` fields take their defaults. */
179
+ export declare function createVRM(options: CreateVRMOptions): VRMAvatar;
180
+ /**
181
+ * The spring bones of `avatar` as {@link addSpringBones} options: joints and centers are glTF node indices, as in the
182
+ * file. Null when it has none. A spring of one joint moves nothing and is left out, as the specification has it.
183
+ */
184
+ export declare function vrmSprings(avatar: VRMAvatar): SpringBonesOptions | null;
185
+ /** Extra expressions that lip sync, blink or gaze overrides hold back, as the specification suggests for custom ones. */
186
+ export interface VRMExpressionsOptions {
187
+ mouth?: readonly string[];
188
+ blink?: readonly string[];
189
+ lookAt?: readonly string[];
190
+ }
191
+ /** The morph, colour and texture values the expressions come to. */
192
+ export interface VRMExpressionOutput {
193
+ /** Every morph target any expression binds: node, target index and weight. */
194
+ readonly morphs: readonly {
195
+ node: number;
196
+ index: number;
197
+ weight: number;
198
+ }[];
199
+ /** Per bound colour: material, type, and each expression's share with its target, to add to the base value. */
200
+ readonly colors: readonly {
201
+ material: number;
202
+ type: string;
203
+ parts: readonly {
204
+ value: number;
205
+ target: readonly number[];
206
+ }[];
207
+ }[];
208
+ /** Per bound material: each expression's share with its scale and offset. */
209
+ readonly transforms: readonly {
210
+ material: number;
211
+ parts: readonly {
212
+ value: number;
213
+ scale: readonly number[];
214
+ offset: readonly number[];
215
+ }[];
216
+ }[];
217
+ }
218
+ /**
219
+ * An avatar's expressions as plain data: set values, read what they come to under the specification's override rules.
220
+ * {@link addVRM} applies them to a model.
221
+ */
222
+ export declare class VRMExpressions {
223
+ /** Expression names, presets and custom ones. */
224
+ readonly names: readonly string[];
225
+ private readonly list;
226
+ private readonly values;
227
+ private readonly kinds;
228
+ /** @param options custom expressions that overrides also hold back. */
229
+ constructor(avatar: VRMAvatar, options?: VRMExpressionsOptions);
230
+ /**
231
+ * Sets an expression's value, clamped to 0 to 1. A preset the avatar lacks is ignored, as every preset is optional.
232
+ * @throws RangeError for a non-finite value or an unknown custom name.
233
+ */
234
+ set(name: VRMPresetExpression | (string & {}), value: number): this;
235
+ /** The value last set, 0 if none. */
236
+ get(name: string): number;
237
+ /** What each expression comes to after `isBinary` and the overrides, by name. */
238
+ resolve(): Map<string, number>;
239
+ /** The morph weights, colours and texture moves of the current values, by the specification's accumulation. */
240
+ evaluate(): VRMExpressionOutput;
241
+ }
242
+ /** Gaze as the specification's yaw and pitch, in degrees: yaw above 0 is the model's left, pitch above 0 is down. */
243
+ export interface VRMGaze {
244
+ readonly yaw: number;
245
+ readonly pitch: number;
246
+ }
247
+ /**
248
+ * Yaw and pitch to `target` from LookAt space: the head's world matrix, moved by `offsetFromHeadBone`, and turned back
249
+ * by `headRest`, the head's rest rotation in model space, so that +Z is the model's forward.
250
+ */
251
+ export declare function vrmGaze(lookAt: VRMLookAtData, head: ArrayLike<number>, headRest: readonly number[], target: Vec3): VRMGaze;
252
+ /** Each eye's turn in degrees for a gaze, through the range maps. For `lookAt.type` `bone`. */
253
+ export declare function vrmEyeAngles(lookAt: VRMLookAtData, gaze: VRMGaze): {
254
+ left: VRMGaze;
255
+ right: VRMGaze;
256
+ };
257
+ /** Weights of the four look expressions for a gaze, through the range maps. For `lookAt.type` `expression`. */
258
+ export declare function vrmLookWeights(lookAt: VRMLookAtData, gaze: VRMGaze): Record<string, number>;
259
+ /** Options of {@link addVRM}. */
260
+ export interface AddVRMOptions extends VRMExpressionsOptions {
261
+ /**
262
+ * The Animator playing clips on this model. Default none, for an avatar that stands still or is posed by hand: the
263
+ * avatar then runs by itself as an engine plugin.
264
+ */
265
+ animator?: Animator;
266
+ /** Run spring bones. Default true. */
267
+ springs?: boolean;
268
+ }
269
+ /** A running {@link addVRM}. */
270
+ export interface VRMHandle {
271
+ readonly avatar: VRMAvatar;
272
+ readonly expressions: VRMExpressions;
273
+ /** Spring bones, or null for an avatar with none. */
274
+ readonly springs: SpringBones | null;
275
+ /** World point the eyes follow; null looks ahead. Needs `lookAt` on the avatar. */
276
+ lookAtTarget: Vec3 | null;
277
+ /** Gaze of the last update, or null when not looking at anything. */
278
+ readonly gaze: VRMGaze | null;
279
+ /** Explicit gaze angles in degrees, for motion capture or VRMA; null (default) follows lookAtTarget. */
280
+ lookAtGaze: VRMGaze | null;
281
+ /**
282
+ * Colour binds this handle does not drive, by expression: the MToon-only `shadeColor`, `rimColor`, `matcapColor`
283
+ * and `outlineColor`. `MToon.attach(model, { expressions })` drives them; without it they are not shown. Empty for
284
+ * most avatars.
285
+ */
286
+ readonly unsupported: readonly string[];
287
+ /** Add a pose producer, evaluated before gaze, expressions and springs, in registration order. Returns its removal. */
288
+ addPoseSource(update: (delta: number) => void): () => void;
289
+ /** Runs one frame by hand; the Animator or the engine does this each frame by itself. */
290
+ update(delta: number): void;
291
+ /** Puts expressions and eyes back to neutral and stops. */
292
+ dispose(): void;
293
+ [Symbol.dispose](): void;
294
+ }
295
+ /**
296
+ * Brings an avatar to life on a model: expressions, gaze and spring bones run every frame in the order the
297
+ * specification recommends, after any clip. Pass the model's `Animation` (`@margoengine/animation`), which plays the
298
+ * morph targets, and `options.animator` when an Animator poses the model. Colour binds to MToon-only fields are listed
299
+ * in `unsupported`; pass `handle.expressions` to `MToon.attach` (`@margoengine/rigging/mtoon`) to draw them. Without
300
+ * MToon the model draws MToon materials by their glTF fallback, with no toon shading, outlines or those binds.
301
+ * @throws RangeError when the avatar does not fit the model.
302
+ */
303
+ export declare function addVRM(animation: Animator['animation'], avatar: VRMAvatar, options?: AddVRMOptions): VRMHandle;