@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.
- package/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +1443 -2
- package/dist/anatomy-data-ansur2.d.ts +63 -0
- package/dist/anatomy-data-cdc.d.ts +16 -0
- package/dist/anatomy-data-deleva.d.ts +86 -0
- package/dist/anatomy-human.d.ts +67 -0
- package/dist/anatomy-human.js +2229 -0
- package/dist/anatomy.d.ts +638 -0
- package/dist/anatomy.js +1112 -0
- package/dist/autorig.d.ts +50 -0
- package/dist/autorig.js +663 -0
- package/dist/bar-grip.d.ts +7 -0
- package/dist/body-volumes-DTym0RVY.js +56 -0
- package/dist/body-volumes.d.ts +19 -0
- package/dist/checks.d.ts +50 -0
- package/dist/contact.d.ts +186 -0
- package/dist/contact.js +746 -0
- package/dist/correctives.d.ts +92 -0
- package/dist/correctives.js +162 -0
- package/dist/coupling.d.ts +57 -0
- package/dist/coupling.js +330 -0
- package/dist/errors-D8rc8kzg.js +7 -0
- package/dist/face.d.ts +93 -0
- package/dist/face.js +144 -0
- package/dist/hands.d.ts +209 -0
- package/dist/hands.js +510 -0
- package/dist/heat.d.ts +38 -0
- package/dist/hinged-contact.d.ts +7 -0
- package/dist/hulls.d.ts +54 -0
- package/dist/hulls.js +134 -0
- package/dist/ik.d.ts +162 -0
- package/dist/ik.js +561 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +390 -0
- package/dist/joint-limits.d.ts +44 -0
- package/dist/joint-limits.js +74 -0
- package/dist/limb-collision.d.ts +99 -0
- package/dist/loading-CZaYr1N7.js +67 -0
- package/dist/mesh-CyvLHNp0.js +142 -0
- package/dist/mesh.d.ts +47 -0
- package/dist/mtoon-data.d.ts +118 -0
- package/dist/mtoon-legacy.d.ts +17 -0
- package/dist/mtoon-shader.d.ts +4 -0
- package/dist/mtoon.d.ts +84 -0
- package/dist/mtoon.js +990 -0
- package/dist/paint.d.ts +82 -0
- package/dist/pose-tracking.d.ts +117 -0
- package/dist/pose-tracking.js +488 -0
- package/dist/retarget.d.ts +78 -0
- package/dist/retarget.js +375 -0
- package/dist/rig-BawZ5OLb.js +127 -0
- package/dist/rig.d.ts +65 -0
- package/dist/shared/gltf.d.ts +257 -0
- package/dist/shared/layers.d.ts +16 -0
- package/dist/springs.d.ts +180 -0
- package/dist/springs.js +458 -0
- package/dist/strand-springs.d.ts +46 -0
- package/dist/strand-springs.js +168 -0
- package/dist/swim.d.ts +55 -0
- package/dist/swim.js +167 -0
- package/dist/transfer.d.ts +41 -0
- package/dist/transfer.js +136 -0
- package/dist/validate.d.ts +188 -0
- package/dist/validate.js +440 -0
- package/dist/voxel-weights-48ok-Dax.js +255 -0
- package/dist/voxel-weights.d.ts +42 -0
- package/dist/voxel-weights.js +1 -0
- package/dist/voxels.d.ts +36 -0
- package/dist/vrm-constraints.d.ts +60 -0
- package/dist/vrm-constraints.js +261 -0
- package/dist/vrm-first-person.d.ts +115 -0
- package/dist/vrm-first-person.js +618 -0
- package/dist/vrm-presets-CU4V4yq6.js +47 -0
- package/dist/vrm-presets.d.ts +1 -0
- package/dist/vrm.d.ts +303 -0
- package/dist/vrm.js +574 -0
- package/dist/vrm0.d.ts +134 -0
- package/dist/vrm0.js +377 -0
- package/dist/vrma.d.ts +90 -0
- package/dist/vrma.js +315 -0
- package/dist/weight-map-D8cAONQQ.js +92 -0
- package/dist/weight-map.d.ts +58 -0
- package/package.json +189 -4
|
@@ -0,0 +1,638 @@
|
|
|
1
|
+
// @ts-ignore optional peer: its types apply when it is installed
|
|
2
|
+
import type { Animator } from '@margoengine/animator';
|
|
3
|
+
import type { PoseJointLimit } from './joint-limits.js';
|
|
4
|
+
import { type RigJoint, type RigPose } from './rig.js';
|
|
5
|
+
/** Three numbers: a direction or an axis. */
|
|
6
|
+
export type Vec3 = readonly [number, number, number];
|
|
7
|
+
/** A rotation, [x, y, z, w]. */
|
|
8
|
+
export type Quat = readonly [number, number, number, number];
|
|
9
|
+
/**
|
|
10
|
+
* How a number in a table was checked: `dataset` (read from a measured dataset held in a data file of this
|
|
11
|
+
* repository), `print` (checked in the printed source), `online` (checked on a readable page this number names) or
|
|
12
|
+
* `recalled` (from memory, to be confirmed before anyone relies on it).
|
|
13
|
+
*/
|
|
14
|
+
export type Provenance = 'dataset' | 'print' | 'online' | 'recalled';
|
|
15
|
+
/** `normal` is the clinical range, where a validator warns; `structural` is the stop no pose may pass. */
|
|
16
|
+
export type Tier = 'normal' | 'structural';
|
|
17
|
+
/** The anatomical kind of a joint. A `free` joint carries a segment and has no limit. */
|
|
18
|
+
export type JointKind = 'free' | 'hinge' | 'ball' | 'saddle' | 'condyloid' | 'pivot' | 'glide';
|
|
19
|
+
/** Which side of the body a joint is on. */
|
|
20
|
+
export type Side = 'left' | 'right' | 'centre';
|
|
21
|
+
/** One entry of a table's list of sources. */
|
|
22
|
+
export interface SourceEntry {
|
|
23
|
+
/** The full citation. */
|
|
24
|
+
readonly cite: string;
|
|
25
|
+
/** Where to read it. */
|
|
26
|
+
readonly url?: string;
|
|
27
|
+
}
|
|
28
|
+
/** One number as its source gives it. */
|
|
29
|
+
export interface SourceRow {
|
|
30
|
+
/** Key into {@link SpeciesTable.sources}. */
|
|
31
|
+
readonly source: string;
|
|
32
|
+
/** The number, in degrees unless `what` says otherwise. */
|
|
33
|
+
readonly value: number;
|
|
34
|
+
/** What the source calls it, with the group it was measured on. */
|
|
35
|
+
readonly what: string;
|
|
36
|
+
/** How the number was checked. */
|
|
37
|
+
readonly provenance: Provenance;
|
|
38
|
+
/** The page it was read on, when that is not the source itself. */
|
|
39
|
+
readonly via?: string;
|
|
40
|
+
/** The data file that holds it, for `dataset` rows. */
|
|
41
|
+
readonly file?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* One end of a range, as degrees away from neutral in that direction. Unless `rule` says otherwise, `normal` is the
|
|
45
|
+
* first row's value and `structural` is the largest row rounded up to 5 degrees plus `allowance`, at most 180.
|
|
46
|
+
*/
|
|
47
|
+
export interface Bound {
|
|
48
|
+
/** Clinical range, degrees. */
|
|
49
|
+
readonly normal: number;
|
|
50
|
+
/** The stop, degrees. */
|
|
51
|
+
readonly structural: number;
|
|
52
|
+
/** Degrees added past the largest source value to reach the stop: tissue give and the spread between people. */
|
|
53
|
+
readonly allowance: number;
|
|
54
|
+
/** The source values. Empty for a direction the joint's kind does not allow. */
|
|
55
|
+
readonly rows: readonly SourceRow[];
|
|
56
|
+
/** How the two numbers come from the rows, when not by the default above. */
|
|
57
|
+
readonly rule?: string;
|
|
58
|
+
}
|
|
59
|
+
/** A range that opens with another motion of the same joint: a knee twists only when it is bent. */
|
|
60
|
+
export interface Gate {
|
|
61
|
+
/** The motion that opens it: 0 for the first swing, 1 for the second, 2 for the twist. */
|
|
62
|
+
readonly by: 0 | 1 | 2;
|
|
63
|
+
/** Degrees of that motion at which the range is still shut. */
|
|
64
|
+
readonly from: number;
|
|
65
|
+
/** Degrees of that motion at which the range is fully open. */
|
|
66
|
+
readonly to: number;
|
|
67
|
+
/** Degrees each way that stay free when shut. */
|
|
68
|
+
readonly floor: number;
|
|
69
|
+
}
|
|
70
|
+
/** One motion of a joint. */
|
|
71
|
+
export interface DofSpec {
|
|
72
|
+
/**
|
|
73
|
+
* The axis in the body frame (x left, y up, z forward) at the neutral pose; a right-hand turn about it is the
|
|
74
|
+
* `positive` motion. The first two axes are across the joint's long axis and across each other; the third is along it.
|
|
75
|
+
*/
|
|
76
|
+
readonly axis: Vec3;
|
|
77
|
+
/** Clinical name of the positive direction, such as `flexion`. */
|
|
78
|
+
readonly positive: string;
|
|
79
|
+
/** Clinical name of the negative direction, such as `extension`. */
|
|
80
|
+
readonly negative: string;
|
|
81
|
+
/** Range in the positive direction. */
|
|
82
|
+
readonly max: Bound;
|
|
83
|
+
/** Range in the negative direction. */
|
|
84
|
+
readonly min: Bound;
|
|
85
|
+
/** Makes the range depend on another motion of the joint. */
|
|
86
|
+
readonly gate?: Gate;
|
|
87
|
+
/** Twist only: turn past the range moves into the joint above it, which twists with it (a hand on a forearm). */
|
|
88
|
+
readonly spill?: boolean;
|
|
89
|
+
}
|
|
90
|
+
/** One joint of a species. */
|
|
91
|
+
export interface JointSpec {
|
|
92
|
+
/** Its name in the species' standard (H-Anim for humans). */
|
|
93
|
+
readonly id: string;
|
|
94
|
+
/** The joint above it in the body, null for the root. */
|
|
95
|
+
readonly parent: string | null;
|
|
96
|
+
/** The joint whose segment its angles are measured against, when that is not `parent`. */
|
|
97
|
+
readonly reference?: string;
|
|
98
|
+
/** The segment it carries. */
|
|
99
|
+
readonly segment: string;
|
|
100
|
+
/** Its kind. */
|
|
101
|
+
readonly kind: JointKind;
|
|
102
|
+
/** Its side. */
|
|
103
|
+
readonly side: Side;
|
|
104
|
+
/** The same joint on the other side. */
|
|
105
|
+
readonly mirror?: string;
|
|
106
|
+
/**
|
|
107
|
+
* What counts as zero: `body` (the segment points along `long` in the reference segment's frame: an arm hanging
|
|
108
|
+
* down), `straight` (the segment continues the line into the joint: a straight elbow) or `rest` (the rig's rest pose).
|
|
109
|
+
*/
|
|
110
|
+
readonly neutral: 'body' | 'straight' | 'rest';
|
|
111
|
+
/** Direction of its segment at neutral, in the body frame. */
|
|
112
|
+
readonly long: Vec3;
|
|
113
|
+
/** Joints whose position marks the far end of its segment, first found wins. */
|
|
114
|
+
readonly distal?: readonly string[];
|
|
115
|
+
/** Two joints that lie across its segment, to read the segment's roll (the knuckles of a hand). */
|
|
116
|
+
readonly across?: {
|
|
117
|
+
readonly pairs: readonly (readonly [string, string])[];
|
|
118
|
+
readonly neutral: Vec3;
|
|
119
|
+
};
|
|
120
|
+
/** Its three motions: two swings and the twist. Left out for a free joint. */
|
|
121
|
+
readonly dofs?: readonly [DofSpec, DofSpec, DofSpec];
|
|
122
|
+
/** The region it belongs to. */
|
|
123
|
+
readonly region?: string;
|
|
124
|
+
/**
|
|
125
|
+
* For a joint whose zero is the rest pose, how its segment rides on a limb below it (a collarbone on the arm): the
|
|
126
|
+
* segment's measured elevation and retraction in degrees against the limb's lift from the body's down, as rows of
|
|
127
|
+
* [lift, elevation, retraction], the first at the side. A rest that holds the limb raised takes its zero back toward
|
|
128
|
+
* the direction at the side (see `fitAnatomy`).
|
|
129
|
+
*/
|
|
130
|
+
readonly rhythm?: {
|
|
131
|
+
/** The limb's near and far joints. */
|
|
132
|
+
readonly from: string;
|
|
133
|
+
readonly to: string;
|
|
134
|
+
readonly curve: readonly (readonly [number, number, number])[];
|
|
135
|
+
readonly rows: readonly SourceRow[];
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* A run of joints along one chain, proximal first. A rig bone stands for every joint of the run nearest to it, and
|
|
140
|
+
* their ranges add up. In a `shared` region (a spine) the whole run's range is one budget: each bone may use any part
|
|
141
|
+
* of it, and the far end of the run stays within it.
|
|
142
|
+
*/
|
|
143
|
+
export interface RegionSpec {
|
|
144
|
+
/** Its name. */
|
|
145
|
+
readonly id: string;
|
|
146
|
+
/** Its joints, proximal first. */
|
|
147
|
+
readonly joints: readonly string[];
|
|
148
|
+
/** Whether the range is one budget for the run. */
|
|
149
|
+
readonly shared: boolean;
|
|
150
|
+
}
|
|
151
|
+
/** How to read a body's frame from its joints. */
|
|
152
|
+
export interface FrameSpec {
|
|
153
|
+
/** Left and right joints whose line gives the body's left, first pair found wins. */
|
|
154
|
+
readonly pairs: readonly (readonly [string, string])[];
|
|
155
|
+
/** Joints above the first pair, to read up; first found wins. */
|
|
156
|
+
readonly top: readonly string[];
|
|
157
|
+
/** Joints below the first pair, read when no top joint is mapped. */
|
|
158
|
+
readonly bottom: readonly string[];
|
|
159
|
+
/** Pairs that point forward (ankle to toe). When they disagree with the left and right names, the rig is mirrored. */
|
|
160
|
+
readonly ahead: readonly (readonly [string, string])[];
|
|
161
|
+
/** A fixed up direction, for a body whose spine is not upright. */
|
|
162
|
+
readonly up?: Vec3;
|
|
163
|
+
}
|
|
164
|
+
/** A proportion of the species, as a share of its stature. */
|
|
165
|
+
export interface ProportionNorm {
|
|
166
|
+
/** Its name. */
|
|
167
|
+
readonly id: string;
|
|
168
|
+
/** What is measured. */
|
|
169
|
+
readonly what: string;
|
|
170
|
+
/** Mean share of stature. */
|
|
171
|
+
readonly share: number;
|
|
172
|
+
/** Shares by sex, where the source gives them. */
|
|
173
|
+
readonly female?: number;
|
|
174
|
+
/** Shares by sex, where the source gives them. */
|
|
175
|
+
readonly male?: number;
|
|
176
|
+
/** Standard deviation as a share of mean stature, where the source gives one. */
|
|
177
|
+
readonly spread?: number;
|
|
178
|
+
/** The source values. */
|
|
179
|
+
readonly rows: readonly SourceRow[];
|
|
180
|
+
/** How a pose checker measures it on a fitted rig, when it can be read from joint centres. */
|
|
181
|
+
readonly measure?: ProportionMeasure;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* How a proportion is read on a fitted rig at neutral: the distance between two joint centres (`length`), or how far the
|
|
185
|
+
* second lies above the first along the body's vertical (`up`), plus `offset` shares of stature (a joint's own height above the
|
|
186
|
+
* ground). A joint centre is not the skin landmark a survey measured, so `band` is wider than the spread between people.
|
|
187
|
+
*/
|
|
188
|
+
export interface ProportionMeasure {
|
|
189
|
+
/** The first joint. */
|
|
190
|
+
readonly from: string;
|
|
191
|
+
/** The second joint. */
|
|
192
|
+
readonly to: string;
|
|
193
|
+
/** What is measured between them. */
|
|
194
|
+
readonly along: 'length' | 'up';
|
|
195
|
+
/** Shares of stature added to the measure. Default 0. */
|
|
196
|
+
readonly offset?: number;
|
|
197
|
+
/** [low, high] shares of stature a rig may measure. */
|
|
198
|
+
readonly band: readonly [number, number];
|
|
199
|
+
/** How the band was set. */
|
|
200
|
+
readonly rule: string;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* A volume of the body a pose checker keeps apart from others: a capsule along a segment from one joint centre to the
|
|
204
|
+
* next, tapered from one radius to the other. It is the body's girth, so two volumes that overlap are limbs through
|
|
205
|
+
* each other.
|
|
206
|
+
*/
|
|
207
|
+
export interface VolumeSpec {
|
|
208
|
+
/** Its name. */
|
|
209
|
+
readonly id: string;
|
|
210
|
+
/** The joint at its near end. */
|
|
211
|
+
readonly from: string;
|
|
212
|
+
/** Joints that can mark its far end, first mapped wins. */
|
|
213
|
+
readonly to: readonly string[];
|
|
214
|
+
/** Radius at each end as a share of stature: from the mean girth, circumference over 2 pi. */
|
|
215
|
+
readonly radius: readonly [number, number];
|
|
216
|
+
/** The source values. */
|
|
217
|
+
readonly rows: readonly SourceRow[];
|
|
218
|
+
}
|
|
219
|
+
/** A body segment's share of the body's mass and where its centre of mass sits. */
|
|
220
|
+
export interface SegmentNorm {
|
|
221
|
+
/** Its name. */
|
|
222
|
+
readonly id: string;
|
|
223
|
+
/** The joint or joints that carry it: one per side for a limb segment, whose numbers are for one limb. */
|
|
224
|
+
readonly joints: readonly string[];
|
|
225
|
+
/** Mean share of body mass, 0 to 1. */
|
|
226
|
+
readonly mass: number;
|
|
227
|
+
/** Mean centre of mass, 0 to 1 of the way from the near landmark to the far one. */
|
|
228
|
+
readonly centre: number;
|
|
229
|
+
/** [female, male] shares of body mass. */
|
|
230
|
+
readonly massBySex?: readonly [number, number];
|
|
231
|
+
/** [female, male] centres of mass. */
|
|
232
|
+
readonly centreBySex?: readonly [number, number];
|
|
233
|
+
/** The landmarks the centre is measured between. */
|
|
234
|
+
readonly landmarks: readonly [string, string];
|
|
235
|
+
/** The source values. */
|
|
236
|
+
readonly rows: readonly SourceRow[];
|
|
237
|
+
}
|
|
238
|
+
/** A motion that two or more joints share: data for the coupling solver, with its sources. */
|
|
239
|
+
export interface CouplingHook {
|
|
240
|
+
/** Its name. */
|
|
241
|
+
readonly id: string;
|
|
242
|
+
/** What kind of rule it is. */
|
|
243
|
+
readonly kind: string;
|
|
244
|
+
/** The joints it ties together, the driver first. */
|
|
245
|
+
readonly joints: readonly string[];
|
|
246
|
+
/** The rule in words. */
|
|
247
|
+
readonly note: string;
|
|
248
|
+
/** Its numbers. */
|
|
249
|
+
readonly values: Readonly<Record<string, number>>;
|
|
250
|
+
/** The source values. */
|
|
251
|
+
readonly rows: readonly SourceRow[];
|
|
252
|
+
}
|
|
253
|
+
/** What a naming finds in a rig. */
|
|
254
|
+
export interface JointNaming {
|
|
255
|
+
/** The naming convention that matched. */
|
|
256
|
+
readonly preset: string;
|
|
257
|
+
/** Joint id to bone index. */
|
|
258
|
+
readonly joints: ReadonlyMap<string, number>;
|
|
259
|
+
}
|
|
260
|
+
/** A species: its joints, parents first, and everything measured about it. */
|
|
261
|
+
export interface SpeciesTable {
|
|
262
|
+
/** Its name, such as `human`. */
|
|
263
|
+
readonly id: string;
|
|
264
|
+
/** The naming standard its joint ids follow. */
|
|
265
|
+
readonly standard: string;
|
|
266
|
+
/** The joints, parents first; the first is the root. */
|
|
267
|
+
readonly joints: readonly JointSpec[];
|
|
268
|
+
/** The regions. */
|
|
269
|
+
readonly regions: readonly RegionSpec[];
|
|
270
|
+
/** How to read the body frame. */
|
|
271
|
+
readonly frame: FrameSpec;
|
|
272
|
+
/** Distances along up that give the stature: the first whose two joints are mapped wins. */
|
|
273
|
+
readonly stature: readonly {
|
|
274
|
+
readonly from: string;
|
|
275
|
+
readonly to: string;
|
|
276
|
+
readonly share: number;
|
|
277
|
+
}[];
|
|
278
|
+
/** Proportions. */
|
|
279
|
+
readonly proportions: readonly ProportionNorm[];
|
|
280
|
+
/** Segment masses. */
|
|
281
|
+
readonly segments: readonly SegmentNorm[];
|
|
282
|
+
/** Coupled motions. */
|
|
283
|
+
readonly couplings: readonly CouplingHook[];
|
|
284
|
+
/** The body's volumes, for a pose checker's limb-through-limb test. */
|
|
285
|
+
readonly volumes?: readonly VolumeSpec[];
|
|
286
|
+
/** Pairs of volume ids that must not overlap. */
|
|
287
|
+
readonly apart?: readonly (readonly [string, string])[];
|
|
288
|
+
/** Joints that carry the body's weight when it stands (ankles, toes), for a pose checker's foot tests. */
|
|
289
|
+
readonly feet?: readonly string[];
|
|
290
|
+
/** Every source a row names. */
|
|
291
|
+
readonly sources: Readonly<Record<string, SourceEntry>>;
|
|
292
|
+
/** Finds the joints among bone names, under one named convention or the one that fits best. */
|
|
293
|
+
readonly naming?: (names: readonly string[], preset?: string) => JointNaming | null;
|
|
294
|
+
/** Names the rest pose from the rest angles, such as `T`, `A` or `arms-down`. */
|
|
295
|
+
readonly describeRest?: (rest: Readonly<Record<string, JointAngles>>) => string;
|
|
296
|
+
}
|
|
297
|
+
/** A joint's angles in degrees: the two swings and the twist, named by the joint's own motions. */
|
|
298
|
+
export interface JointAngles {
|
|
299
|
+
/** The first swing: flexion for most joints. */
|
|
300
|
+
flexion: number;
|
|
301
|
+
/** The second swing: abduction for most joints. */
|
|
302
|
+
abduction: number;
|
|
303
|
+
/** The twist about the segment's long axis. */
|
|
304
|
+
rotation: number;
|
|
305
|
+
}
|
|
306
|
+
/** One joint of a table as it sits on a rig. */
|
|
307
|
+
export interface AnatomicalJoint {
|
|
308
|
+
/** The table joint the bone is mapped to. */
|
|
309
|
+
readonly id: string;
|
|
310
|
+
/** Its table entry. */
|
|
311
|
+
readonly spec: JointSpec;
|
|
312
|
+
/** The bone that turns at this joint. */
|
|
313
|
+
readonly bone: number;
|
|
314
|
+
/** The bone its angles are measured against, -1 for none. */
|
|
315
|
+
readonly reference: number;
|
|
316
|
+
/** Every table joint this bone stands for, itself included. */
|
|
317
|
+
readonly covers: readonly string[];
|
|
318
|
+
/** Its side once the facing is known: a mirrored rig swaps left and right. */
|
|
319
|
+
readonly side: Side;
|
|
320
|
+
/** Its kind. */
|
|
321
|
+
readonly kind: JointKind;
|
|
322
|
+
/** Its region, or null. */
|
|
323
|
+
readonly region: string | null;
|
|
324
|
+
/** Whether it has a range: false for a free joint. */
|
|
325
|
+
readonly limited: boolean;
|
|
326
|
+
/** The segment's long axis at neutral, in the reference segment's anatomical frame. */
|
|
327
|
+
readonly long: Vec3;
|
|
328
|
+
/** The three motion axes in that frame; a right-hand turn about each is the positive motion. */
|
|
329
|
+
readonly axes: readonly [Vec3, Vec3, Vec3];
|
|
330
|
+
/** The same three axes in the bone's own local frame. */
|
|
331
|
+
readonly boneAxes: readonly [Vec3, Vec3, Vec3];
|
|
332
|
+
/** The anatomical frame as a rotation in the bone's own local frame. */
|
|
333
|
+
readonly frame: Quat;
|
|
334
|
+
/** The reference segment's anatomical frame in the reference bone's local frame. */
|
|
335
|
+
readonly referenceFrame: Quat;
|
|
336
|
+
/** The bone's local rotation at anatomical zero, with the bones between it and its reference at rest. */
|
|
337
|
+
readonly neutral: Quat;
|
|
338
|
+
/** Its angles in the rest pose. */
|
|
339
|
+
readonly rest: JointAngles;
|
|
340
|
+
/** Clinical range: [min, max] of the first swing, the second swing and the twist, degrees. */
|
|
341
|
+
readonly normal: readonly number[];
|
|
342
|
+
/** The stops, in the same layout. */
|
|
343
|
+
readonly structural: readonly number[];
|
|
344
|
+
}
|
|
345
|
+
/** A shared region as it sits on a rig. */
|
|
346
|
+
export interface AnatomicalRegion {
|
|
347
|
+
/** Its name. */
|
|
348
|
+
readonly id: string;
|
|
349
|
+
/** Indices into {@link AnatomicalRig.joints}, proximal first. */
|
|
350
|
+
readonly joints: readonly number[];
|
|
351
|
+
/** The clinical range of the whole run. */
|
|
352
|
+
readonly normal: readonly number[];
|
|
353
|
+
/** The stops of the whole run. */
|
|
354
|
+
readonly structural: readonly number[];
|
|
355
|
+
}
|
|
356
|
+
/** A rig with its anatomy: what {@link fitAnatomy} returns and every other function here reads. */
|
|
357
|
+
export interface AnatomicalRig {
|
|
358
|
+
/** The species table. */
|
|
359
|
+
readonly species: SpeciesTable;
|
|
360
|
+
/** Bone names. */
|
|
361
|
+
readonly names: readonly string[];
|
|
362
|
+
/** Parent bone per bone, -1 at the top. */
|
|
363
|
+
readonly parents: readonly number[];
|
|
364
|
+
/** The rest pose, 10 numbers per bone: translation, rotation xyzw, scale. */
|
|
365
|
+
readonly rest: Float64Array;
|
|
366
|
+
/** The same pose with every fitted joint at anatomical zero. */
|
|
367
|
+
readonly neutral: Float64Array;
|
|
368
|
+
/**
|
|
369
|
+
* The body frame in the rig's rest space: `left`, `up` and `forward` are the trunk's (a stoop leans `up` forward with
|
|
370
|
+
* it), which every anatomical angle is read against; `vertical` is the world's up, which heights and the ground are
|
|
371
|
+
* measured along (see {@link FitOptions.vertical}).
|
|
372
|
+
*/
|
|
373
|
+
readonly frame: {
|
|
374
|
+
readonly origin: Vec3;
|
|
375
|
+
readonly left: Vec3;
|
|
376
|
+
readonly up: Vec3;
|
|
377
|
+
readonly forward: Vec3;
|
|
378
|
+
readonly vertical: Vec3;
|
|
379
|
+
};
|
|
380
|
+
/** True when the left and right names disagree with the way the feet point; the feet win. */
|
|
381
|
+
readonly mirrored: boolean;
|
|
382
|
+
/** Standing height in the rig's units, 0 when no measure was mapped. */
|
|
383
|
+
readonly stature: number;
|
|
384
|
+
/** The rest pose as the species names it. */
|
|
385
|
+
readonly restPose: string;
|
|
386
|
+
/** The naming convention that matched, null when only `map` was used. */
|
|
387
|
+
readonly preset: string | null;
|
|
388
|
+
/** Whether limits apply. Pass `limits: false` to {@link fitAnatomy} to turn them off. */
|
|
389
|
+
readonly limits: boolean;
|
|
390
|
+
/** The fitted joints, parents first. */
|
|
391
|
+
readonly joints: readonly AnatomicalJoint[];
|
|
392
|
+
/** The shared regions that have a bone. */
|
|
393
|
+
readonly regions: readonly AnatomicalRegion[];
|
|
394
|
+
/** Table joint id to its index in `joints`, for every joint a bone stands for. */
|
|
395
|
+
readonly index: ReadonlyMap<string, number>;
|
|
396
|
+
}
|
|
397
|
+
/** Options of {@link fitAnatomy}. */
|
|
398
|
+
export interface FitOptions {
|
|
399
|
+
/** The species table, such as `human` from `@margoengine/rigging/anatomy/human`. */
|
|
400
|
+
readonly species: SpeciesTable;
|
|
401
|
+
/** A naming convention of the species to use. Default: the one that matches the most bones. */
|
|
402
|
+
readonly preset?: string;
|
|
403
|
+
/** Joint id to bone name or index, over what the naming found; null drops a joint. */
|
|
404
|
+
readonly map?: Readonly<Record<string, string | number | null>>;
|
|
405
|
+
/** False turns the limits off by name: {@link clampPose} and {@link addAnatomyLimits} then leave poses alone. Default true. */
|
|
406
|
+
readonly limits?: boolean;
|
|
407
|
+
/**
|
|
408
|
+
* The world's up in the rig's rest space, which the stature, heights and ground tests are measured along. Default:
|
|
409
|
+
* the rig's axis nearest the trunk's up (within 30 degrees) when the rest feet stand level on it, each weight-bearing
|
|
410
|
+
* joint at the height of its mirror and below the hips; otherwise the trunk's up, or the species' fixed up.
|
|
411
|
+
*/
|
|
412
|
+
readonly vertical?: Vec3;
|
|
413
|
+
/** The way the body faces in the rig's rest space, when the rig has no feet to read it from. */
|
|
414
|
+
readonly forward?: Vec3;
|
|
415
|
+
/**
|
|
416
|
+
* Degrees of roll about its own length that a segment has in the rest pose, by joint id, added to what the landmarks
|
|
417
|
+
* show. A straight arm with no knuckle bones cannot show how it is rolled, so its elbow is taken to bend the way an
|
|
418
|
+
* unrolled arm does; a reader that knows better (from a capture file's own axes, or from the motion) passes it here.
|
|
419
|
+
*/
|
|
420
|
+
readonly roll?: Readonly<Record<string, number>>;
|
|
421
|
+
/**
|
|
422
|
+
* For a joint whose zero is the rest pose and that rides on a limb (a collarbone on the arm), the degrees of
|
|
423
|
+
* elevation and retraction its segment drops from the rest pose when the limb hangs at the side, by joint id, as the
|
|
424
|
+
* rig's own motion shows it ({@link rhythmDrops}). A rest that holds the limb raised takes its zero back by this
|
|
425
|
+
* much, never past what the joint's rhythm gives between the rest limb's lift and the side. A rig bone often does not
|
|
426
|
+
* lie along the bone it stands for (a Character Creator clavicle bone aims at the shoulder joint's centre, below the
|
|
427
|
+
* collarbone), so its rest direction alone cannot show whether the rest holds it raised.
|
|
428
|
+
*/
|
|
429
|
+
readonly drop?: Readonly<Record<string, readonly [number, number]>>;
|
|
430
|
+
}
|
|
431
|
+
/** One motion that {@link clampPose} brought back into range. */
|
|
432
|
+
export interface ClampIssue {
|
|
433
|
+
/** The joint, or the region for a shared budget. */
|
|
434
|
+
readonly joint: string;
|
|
435
|
+
/** The bone that was turned, -1 for a region. */
|
|
436
|
+
readonly bone: number;
|
|
437
|
+
/** The clinical name of the motion that was out of range. */
|
|
438
|
+
readonly motion: string;
|
|
439
|
+
/** Degrees it had. */
|
|
440
|
+
readonly value: number;
|
|
441
|
+
/** Degrees it was brought to. */
|
|
442
|
+
readonly limit: number;
|
|
443
|
+
/** The tier that was applied. */
|
|
444
|
+
readonly tier: Tier;
|
|
445
|
+
/** The source of the limit's first row, or null. */
|
|
446
|
+
readonly source: string | null;
|
|
447
|
+
}
|
|
448
|
+
/** Options of {@link clampPose}. */
|
|
449
|
+
export interface ClampOptions {
|
|
450
|
+
/** Which range to hold. Default `structural`. */
|
|
451
|
+
readonly tier?: Tier;
|
|
452
|
+
/** An array that receives one entry per motion brought back. */
|
|
453
|
+
readonly issues?: ClampIssue[];
|
|
454
|
+
/** Clamp even when the body was fitted with `limits: false`. */
|
|
455
|
+
readonly force?: boolean;
|
|
456
|
+
}
|
|
457
|
+
/** A joint limit in the shape `@margoengine/ragdoll` profiles take, relative to the rest pose. */
|
|
458
|
+
export interface RagdollJointLimit {
|
|
459
|
+
/** The bone. */
|
|
460
|
+
readonly bone: number;
|
|
461
|
+
/** The bone's name. */
|
|
462
|
+
readonly name: string;
|
|
463
|
+
/** A hinge about `axis` in the bone's local frame, or a cone about the rest direction. Radians. */
|
|
464
|
+
readonly joint: {
|
|
465
|
+
type: 'hinge';
|
|
466
|
+
axis: [number, number, number];
|
|
467
|
+
limits: [number, number];
|
|
468
|
+
} | {
|
|
469
|
+
type: 'cone';
|
|
470
|
+
swing: number;
|
|
471
|
+
twist: [number, number];
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
/** A joint limit in the shape `@margoengine/kinematics-constraints` `JointLimitSet` takes, relative to neutral. */
|
|
475
|
+
export type KinematicsJointLimit = {
|
|
476
|
+
type: 'hinge';
|
|
477
|
+
axis: [number, number, number];
|
|
478
|
+
min: number;
|
|
479
|
+
max: number;
|
|
480
|
+
} | {
|
|
481
|
+
type: 'cone';
|
|
482
|
+
axis: [number, number, number];
|
|
483
|
+
angle: number;
|
|
484
|
+
twist: [number, number];
|
|
485
|
+
};
|
|
486
|
+
/**
|
|
487
|
+
* A {@link Bound} from its source rows: `normal` is the first row's value and `structural` the largest row rounded up
|
|
488
|
+
* to 5 degrees plus `allowance`, at most 180. With no rows both are `allowance` past zero: a direction the joint does
|
|
489
|
+
* not move in, with what a solver may leave there.
|
|
490
|
+
*/
|
|
491
|
+
export declare function bound(allowance: number, ...rows: SourceRow[]): Bound;
|
|
492
|
+
/**
|
|
493
|
+
* The joint on the other side of the body: ids renamed by `rename`, directions reflected across the middle plane and
|
|
494
|
+
* turning axes reflected as axes of rotation, so that the same motion names keep the same anatomical meaning.
|
|
495
|
+
*/
|
|
496
|
+
export declare function mirrorJoint(spec: JointSpec, rename: (id: string) => string): JointSpec;
|
|
497
|
+
/**
|
|
498
|
+
* Checks a species table and returns it frozen: joints parents first with unique ids, every id another entry names
|
|
499
|
+
* present, unit axes at right angles, ranges that hold zero with the stop outside the clinical range, every number's
|
|
500
|
+
* source listed, and regions whose joints share their axes so their ranges can add up.
|
|
501
|
+
* @throws TypeError for a malformed table, RangeError naming the joint and what to fix.
|
|
502
|
+
*/
|
|
503
|
+
export declare function defineSpecies<T extends SpeciesTable>(table: T): T;
|
|
504
|
+
/**
|
|
505
|
+
* Fits a species table to a rig. Finds each table joint's bone (by the species' naming conventions, by `map`, or both),
|
|
506
|
+
* reads the body's frame, stature and rest pose from the joint positions, and gives every joint its anatomical axes
|
|
507
|
+
* and ranges. A rig bone that stands for several joints of a region (one spine bone for five vertebrae) gets their
|
|
508
|
+
* summed range. Limits are on unless `limits: false`. A joint whose zero is a direction in the body (shoulder, hip,
|
|
509
|
+
* thumb base) needs the joint at the far end of its segment mapped too: without it nothing shows where the segment
|
|
510
|
+
* points at rest, and the joint is left unlimited rather than guessed.
|
|
511
|
+
* @example
|
|
512
|
+
* import { fitAnatomy, jointAngles } from '@margoengine/rigging/anatomy';
|
|
513
|
+
* import { human } from '@margoengine/rigging/anatomy/human';
|
|
514
|
+
*
|
|
515
|
+
* const body = fitAnatomy(rig, { species: human });
|
|
516
|
+
* console.log(body.restPose, jointAngles(body).l_elbow.flexion);
|
|
517
|
+
* @param rig `{ names, parents, rest }` (as `retargetRig` makes it) or an array of `{ name, parent, position }`.
|
|
518
|
+
* @param options The species, and optionally a naming convention, a joint map, `limits: false` or the facing.
|
|
519
|
+
* @throws TypeError for a malformed rig or no species; RangeError when the root, or a left and right joint, cannot be
|
|
520
|
+
* found, when two joints claim one bone, or when `map` or `roll` names an unknown joint or bone.
|
|
521
|
+
*/
|
|
522
|
+
export declare function fitAnatomy(rig: RigPose | readonly RigJoint[], options: FitOptions): AnatomicalRig;
|
|
523
|
+
/**
|
|
524
|
+
* The angles of every limited joint in a pose, as a flat array for a solver that runs each frame: three numbers per
|
|
525
|
+
* entry of `body.joints` (first swing, second swing, twist; degrees; zeros for a free joint). Allocates nothing when
|
|
526
|
+
* `out` is passed.
|
|
527
|
+
* @throws TypeError for a pose or `out` of the wrong length.
|
|
528
|
+
*/
|
|
529
|
+
export declare function readJointAngles(body: AnatomicalRig, pose?: ArrayLike<number>, out?: Float64Array): Float64Array;
|
|
530
|
+
/**
|
|
531
|
+
* The clinical angles of every limited joint in a pose, in degrees, keyed by joint id. `flexion` and `abduction` are the
|
|
532
|
+
* two parts of the swing away from neutral and `rotation` is the twist about the segment; each joint names them in its
|
|
533
|
+
* own terms in `body.joints[i].spec.dofs` (a wrist's second swing is radial deviation). The same body reads the same
|
|
534
|
+
* angles whatever its rest pose or bone axes.
|
|
535
|
+
* @example
|
|
536
|
+
* const { l_knee } = jointAngles(body, pose);
|
|
537
|
+
* if (l_knee.flexion < 0) console.log('the left knee is past straight by', -l_knee.flexion, 'degrees');
|
|
538
|
+
* @param pose A local pose, 10 numbers per bone. Default: the rest pose.
|
|
539
|
+
* @throws TypeError for a pose of the wrong length or a body not made by {@link fitAnatomy}.
|
|
540
|
+
*/
|
|
541
|
+
export declare function jointAngles(body: AnatomicalRig, pose?: ArrayLike<number>): Record<string, JointAngles>;
|
|
542
|
+
/**
|
|
543
|
+
* How each straight limb is rolled, read from motion. A hinge turns about one axis, so over a clip its swing lies along
|
|
544
|
+
* one line; where that line leaves the flexion axis the fit took, the segment above the hinge is rolled by that angle in
|
|
545
|
+
* the rest pose. A straight arm with no knuckle bones shows no roll in its joint positions, and motion capture
|
|
546
|
+
* skeletons are often rolled (the CMU skeleton's upper arms by about 20 degrees). Returns degrees by the id of the joint
|
|
547
|
+
* above each hinge whose swing reached 30 degrees somewhere in the poses: pass them as `roll` and fit again.
|
|
548
|
+
* @example
|
|
549
|
+
* const first = fitAnatomy(rig, { species: human });
|
|
550
|
+
* const body = fitAnatomy(rig, { species: human, roll: hingeRolls(first, frames) });
|
|
551
|
+
* @param poses Local poses of the motion, 10 numbers per bone each; one buffer may be reused between steps.
|
|
552
|
+
* @throws TypeError for a pose of the wrong length.
|
|
553
|
+
*/
|
|
554
|
+
export declare function hingeRolls(body: AnatomicalRig, poses: Iterable<ArrayLike<number>>): Record<string, number>;
|
|
555
|
+
/**
|
|
556
|
+
* How far each joint with a rhythm (a collarbone on its arm) drops from the rest pose when its limb hangs, read from
|
|
557
|
+
* motion: over the poses whose limb hangs within the rhythm's first measured step of the side (30 degrees for the
|
|
558
|
+
* human collarbone), the median elevation and retraction the joint loses from rest, less what the rhythm still gives
|
|
559
|
+
* for that small lift. Returns [elevation, retraction] in degrees by joint id, for the joints with such poses: pass
|
|
560
|
+
* them as `drop` and fit again, so a rest that holds the arm raised (an A pose) takes the collarbone's zero back to the
|
|
561
|
+
* side as far as the motion and the rhythm agree.
|
|
562
|
+
* @example
|
|
563
|
+
* const first = fitAnatomy(rig, { species: human });
|
|
564
|
+
* const body = fitAnatomy(rig, { species: human, drop: rhythmDrops(first, frames) });
|
|
565
|
+
* @param poses Local poses of the motion, 10 numbers per bone each; one buffer may be reused between steps.
|
|
566
|
+
* @throws TypeError for a pose of the wrong length.
|
|
567
|
+
*/
|
|
568
|
+
export declare function rhythmDrops(body: AnatomicalRig, poses: Iterable<ArrayLike<number>>): Record<string, [number, number]>;
|
|
569
|
+
/**
|
|
570
|
+
* The angles of each shared region's far end against its reference: the head against the chest, the chest against the
|
|
571
|
+
* pelvis. This is what a clinical table of the neck or trunk measures, whatever number of bones the rig spends on it.
|
|
572
|
+
* @throws TypeError for a pose of the wrong length.
|
|
573
|
+
*/
|
|
574
|
+
export declare function regionAngles(body: AnatomicalRig, pose?: ArrayLike<number>): Record<string, JointAngles>;
|
|
575
|
+
/**
|
|
576
|
+
* The pose that has the given angles: the inverse of {@link jointAngles}. Joints left out keep the base pose, and so do
|
|
577
|
+
* the motions left out of a joint.
|
|
578
|
+
* @example
|
|
579
|
+
* const pose = poseFromAngles(body, { r_elbow: { flexion: 90 }, r_shoulder: { abduction: 45 } });
|
|
580
|
+
* @param angles Degrees per joint id.
|
|
581
|
+
* @param base The pose to start from. Default: the rest pose.
|
|
582
|
+
* @returns A new local pose, 10 numbers per bone.
|
|
583
|
+
* @throws RangeError for an id that is not a limited joint of the body; TypeError for a base of the wrong length.
|
|
584
|
+
*/
|
|
585
|
+
export declare function poseFromAngles(body: AnatomicalRig, angles: Readonly<Record<string, Partial<JointAngles>>>, base?: ArrayLike<number>): Float64Array;
|
|
586
|
+
/**
|
|
587
|
+
* Brings a pose inside the body's ranges, in place: each joint's swing back inside its reach, its twist back inside its
|
|
588
|
+
* range, a hinge back to its stop, and each shared region (neck, trunk) back inside its budget by easing every bone of
|
|
589
|
+
* the run. A hand's twist past its wrist moves into the forearm, which leaves the hand where it was. The default tier
|
|
590
|
+
* is `structural`: the stops no body passes. A pose already inside is not touched.
|
|
591
|
+
* @example
|
|
592
|
+
* const issues = [];
|
|
593
|
+
* if (clampPose(body, pose, { issues })) console.warn(issues.map((issue) => `${issue.joint} ${issue.motion} ${issue.value.toFixed(1)}`));
|
|
594
|
+
* @param pose A local pose, 10 numbers per bone, edited in place.
|
|
595
|
+
* @returns How many motions were brought back; 0 when the body was fitted with `limits: false`.
|
|
596
|
+
* @throws TypeError for a pose that is not a Float64Array of the right length.
|
|
597
|
+
*/
|
|
598
|
+
export declare function clampPose(body: AnatomicalRig, pose: Float64Array, options?: ClampOptions): number;
|
|
599
|
+
/**
|
|
600
|
+
* The body's limits as `PoseJointLimit`s for `PoseJointLimits` and `addPoseJointLimits` in
|
|
601
|
+
* `@margoengine/rigging/joint-limits`. A hinge (elbow, knee, finger joint) is exact, with its twist. A joint that
|
|
602
|
+
* reaches further one way than the other is given the nearest cone those limits can hold: about the middle of its
|
|
603
|
+
* reach, as wide as the wider half. {@link clampPose} holds the exact reach.
|
|
604
|
+
* @param tier Which range. Default `structural`.
|
|
605
|
+
*/
|
|
606
|
+
export declare function poseLimits(body: AnatomicalRig, tier?: Tier): PoseJointLimit[];
|
|
607
|
+
/**
|
|
608
|
+
* The limits of a chain of bones, in the chain's order, for an IK solver: one `PoseJointLimit` per bone (the rotation
|
|
609
|
+
* the limit is measured from, and the limit), or null for a bone with no joint.
|
|
610
|
+
* @param chain Bone indices or names.
|
|
611
|
+
* @throws RangeError for a bone the rig does not have.
|
|
612
|
+
*/
|
|
613
|
+
export declare function ikLimits(body: AnatomicalRig, chain: readonly (number | string)[], tier?: Tier): (PoseJointLimit | null)[];
|
|
614
|
+
/**
|
|
615
|
+
* The body's limits for a ragdoll, relative to the rest pose the ragdoll is built in: a hinge about its anatomical axis
|
|
616
|
+
* (so a knee folds back and an elbow forward whatever the rest pose), and for every other joint a cone about its rest
|
|
617
|
+
* direction wide enough to hold its reach, with its twist range.
|
|
618
|
+
*/
|
|
619
|
+
export declare function ragdollJoints(body: AnatomicalRig, tier?: Tier): RagdollJointLimit[];
|
|
620
|
+
/**
|
|
621
|
+
* The body's limits for `JointLimitSet` in `@margoengine/kinematics-constraints`, one per bone asked for (null for a
|
|
622
|
+
* bone with no joint), measured from the anatomical neutral: pass it rotations taken relative to `body.neutral`.
|
|
623
|
+
* @param bones Bone indices or names. Default: every fitted joint's bone, in `body.joints` order.
|
|
624
|
+
* @throws RangeError for a bone the rig does not have.
|
|
625
|
+
*/
|
|
626
|
+
export declare function kinematicsLimits(body: AnatomicalRig, bones?: readonly (number | string)[], tier?: Tier): (KinematicsJointLimit | null)[];
|
|
627
|
+
/**
|
|
628
|
+
* Holds an Animator's pose inside the body's ranges every frame, after the pose and the solvers added before it. The
|
|
629
|
+
* body must be fitted to the Animator's own model, bone for bone. Returns the remover.
|
|
630
|
+
* @example
|
|
631
|
+
* const stop = addAnatomyLimits(animator, body);
|
|
632
|
+
* @param options `tier` (default `structural`) and `onClamp`, called with what was brought back on a frame that needed it.
|
|
633
|
+
* @throws RangeError when the body and the Animator's model differ in bone count.
|
|
634
|
+
*/
|
|
635
|
+
export declare function addAnatomyLimits(animator: Animator, body: AnatomicalRig, options?: {
|
|
636
|
+
tier?: Tier;
|
|
637
|
+
onClamp?: (issues: readonly ClampIssue[]) => void;
|
|
638
|
+
}): () => void;
|