@margoengine/rigging 0.1.0 → 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.
@@ -0,0 +1,188 @@
1
+ import { type AnatomicalRig, type Tier, type Vec3 } from './anatomy.js';
2
+ /** What an issue is. */
3
+ export type PoseIssueCode =
4
+ /** A swing past the joint's range. */
5
+ 'out-of-range'
6
+ /** A hinge (elbow, knee, finger) bent past straight the wrong way. */
7
+ | 'hinge-reversed'
8
+ /** A hinge bent sideways, across its one axis. */
9
+ | 'hinge-sideways'
10
+ /** A twist past the joint's range. */
11
+ | 'twist-out-of-range'
12
+ /** A bone longer or shorter than at rest, or scaled. */
13
+ | 'bone-stretch'
14
+ /** A joint, or a point of the skin, below the ground. */
15
+ | 'ground-penetration'
16
+ /** A joint that should bear weight held off the ground. */
17
+ | 'floating'
18
+ /** Two limb volumes through each other. */
19
+ | 'self-penetration'
20
+ /** A planted foot moving along the ground. */
21
+ | 'foot-slide'
22
+ /** A joint turning faster than any body turns, or jumping in one frame. */
23
+ | 'pop'
24
+ /** A body measure outside what people measure. */
25
+ | 'proportion'
26
+ /** The left and right of a measure differing. */
27
+ | 'asymmetry';
28
+ /** `error`: no body does this. `warning`: inside the stops but outside the clinical range or what looks right. */
29
+ export type PoseSeverity = 'error' | 'warning';
30
+ /** One thing wrong with a pose. */
31
+ export interface PoseIssue {
32
+ /** What it is. */
33
+ readonly code: PoseIssueCode;
34
+ /** How bad. */
35
+ readonly severity: PoseSeverity;
36
+ /** The table joint, region or measure, or two volumes as `a + b`. */
37
+ readonly joint: string;
38
+ /** The rig bone's name, or null. */
39
+ readonly bone: string | null;
40
+ /** The clinical motion for an angle (such as `hyperextension`), or null. */
41
+ readonly motion: string | null;
42
+ /** What was measured, in `unit`. */
43
+ readonly value: number;
44
+ /** The limit it was measured against, in `unit`. */
45
+ readonly limit: number;
46
+ /** How far past the limit, in `unit`, never negative. */
47
+ readonly excess: number;
48
+ /** `deg`, `deg/s`, `stature` (a share of the body's height), `stature/s` or `ratio`. */
49
+ readonly unit: 'deg' | 'deg/s' | 'stature' | 'stature/s' | 'ratio';
50
+ /** The range tier, for an angle. */
51
+ readonly tier: Tier | null;
52
+ /** The key of the limit's first source in the species table, or null. */
53
+ readonly source: string | null;
54
+ /** The clip time in seconds, for a clip; null for one pose. */
55
+ readonly time: number | null;
56
+ /** The frame index, for a clip; null for one pose. */
57
+ readonly frame: number | null;
58
+ /** The issue in words. */
59
+ readonly message: string;
60
+ /** Where to read what it means and how to fix it. */
61
+ readonly help: string;
62
+ }
63
+ /** Options of {@link checkPose}. */
64
+ export interface PoseCheckOptions {
65
+ /** `normal` checks the clinical range only, `structural` the stops only, `both` (default) each with its severity. */
66
+ readonly tier?: Tier | 'both';
67
+ /** Degrees by which an angle may pass its limit before it counts, for noise. Default 0.5. */
68
+ readonly tolerance?: number;
69
+ /**
70
+ * Height of the ground along the body's vertical (`body.frame.vertical`, the world's up), in the rig's space, or null
71
+ * for no ground tests. Default null.
72
+ */
73
+ readonly ground?: number | null;
74
+ /** Skin points in the rig's space (x, y, z, ...), tested against the ground as well as the joints. */
75
+ readonly points?: ArrayLike<number>;
76
+ /** Table joints that bear weight in this pose: each must be within `float` of the ground. Default none. */
77
+ readonly supports?: readonly string[];
78
+ /** Shares of stature a support may sit above the ground before it floats. Default 0.06. */
79
+ readonly float?: number;
80
+ /** Shares of stature below the ground a joint or point may sink before it counts. Default 0.002. */
81
+ readonly sink?: number;
82
+ /** Test limbs through limbs with the table's volumes. Default true. */
83
+ readonly volumes?: boolean;
84
+ /** Share of the two radii a pass must reach into before it counts as one limb through another. Default 0.7. */
85
+ readonly shrink?: number;
86
+ /** Share by which a bone's length or scale may differ from rest. Default 0.01. */
87
+ readonly stretch?: number;
88
+ }
89
+ /** Options of {@link checkClip}. */
90
+ export interface ClipCheckOptions extends PoseCheckOptions {
91
+ /** Frames per second the clip is sampled at. Default 30. */
92
+ readonly fps?: number;
93
+ /** Seconds, needed when `sample` is a function. */
94
+ readonly duration?: number;
95
+ /** Time of the first frame. Default 0. */
96
+ readonly start?: number;
97
+ /** How the body travels through the world (rig units per second), for a clip played in place. Default none. */
98
+ readonly velocity?: Vec3;
99
+ /** Degrees per second no joint reaches. Default 9,000. */
100
+ readonly maxSpeed?: number;
101
+ /** Shares of stature above its lowest a foot joint may be and still be planted. Default 0.02. */
102
+ readonly contact?: number;
103
+ /** Shares of stature per second a planted foot may move along the ground. Default 0.1. */
104
+ readonly slide?: number;
105
+ }
106
+ /** One issue over a clip: how often it happens, when, and its worst frame. */
107
+ export interface ClipIssueSummary {
108
+ readonly code: PoseIssueCode;
109
+ readonly severity: PoseSeverity;
110
+ readonly joint: string;
111
+ readonly motion: string | null;
112
+ /** Frames it happens in. */
113
+ readonly frames: number;
114
+ /** Time of the first and last of them. */
115
+ readonly first: number;
116
+ readonly last: number;
117
+ /** The frame where it is furthest past its limit. */
118
+ readonly worst: PoseIssue;
119
+ }
120
+ /** What {@link checkPose} returns. */
121
+ export interface PoseReport {
122
+ /** True when no issue is an error. */
123
+ readonly passed: boolean;
124
+ readonly errors: number;
125
+ readonly warnings: number;
126
+ /** Every issue, worst first within each code. */
127
+ readonly issues: readonly PoseIssue[];
128
+ }
129
+ /** What {@link checkClip} returns. */
130
+ export interface ClipReport extends PoseReport {
131
+ /** Frames checked. */
132
+ readonly frames: number;
133
+ readonly fps: number;
134
+ /** One row per joint, motion and code, errors first, then by how often. */
135
+ readonly summary: readonly ClipIssueSummary[];
136
+ }
137
+ /** Options of {@link checkProportions}. */
138
+ export interface ProportionCheckOptions {
139
+ /** The body's real standing height in rig units, when known (from its skin). Default: the fitted body's stature. */
140
+ readonly stature?: number;
141
+ /** Share by which a left and a right measure may differ. Default 0.05. */
142
+ readonly asymmetry?: number;
143
+ }
144
+ /** The README section that explains each issue code. */
145
+ export declare const POSE_HELP = "https://margoengine.com/llms/packages/rigging.md#pose-checks-margoengineriggingvalidate";
146
+ /**
147
+ * Checks one pose of a fitted body: each joint against its clinical range (warnings) and its stops (errors), with the
148
+ * hinge faults named apart (`hinge-reversed`, `hinge-sideways`), bones stretched from rest, joints or skin points below
149
+ * `ground`, weight-bearing `supports` off it, and limbs through limbs. Nothing is changed.
150
+ * @example
151
+ * const report = checkPose(body, pose, { ground: 0 });
152
+ * for (const issue of report.issues) console.log(issue.severity, issue.message);
153
+ * @param pose A local pose, 10 numbers per bone (translation, rotation xyzw, scale).
154
+ * @throws TypeError for a body not made by `fitAnatomy` or a pose of the wrong length.
155
+ */
156
+ export declare function checkPose(body: AnatomicalRig, pose: ArrayLike<number>, options?: PoseCheckOptions): PoseReport;
157
+ /**
158
+ * Checks every frame of a clip, as {@link checkPose} does, and across frames: joints that turn faster than any body or
159
+ * jump in one frame (`pop`), and planted feet that slide (`foot-slide`). `sample` is either the frames (local poses,
160
+ * one buffer may be reused) or a function that writes the pose at a time into `out`. The summary has one row per joint,
161
+ * motion and code with how many frames it lasts and its worst frame: the report for a capture or a retargeted take.
162
+ * @example
163
+ * const clip = checkClip(body, (time, out) => out.set(sampleMyClip(time)), { duration: 2.4, fps: 30, ground: 0 });
164
+ * console.log(formatPoseReport(clip));
165
+ * @throws TypeError for a pose of the wrong length or a function sampler without a duration.
166
+ */
167
+ export declare function checkClip(body: AnatomicalRig, sample: Iterable<ArrayLike<number>> | ((time: number, out: Float64Array) => void), options?: ClipCheckOptions): ClipReport;
168
+ /**
169
+ * Checks a fitted body's build on its neutral pose (standing, arms down) against the species' measured proportions
170
+ * that the table says how to read from joint centres (heights of the shoulder, elbow, wrist and knee, the length of
171
+ * each long bone, the trunk), and the left side against the right. An arm too long or a knee too high is an error.
172
+ * @example
173
+ * for (const issue of checkProportions(body)) console.log(issue.message);
174
+ * @throws TypeError for a body not made by `fitAnatomy`.
175
+ */
176
+ export declare function checkProportions(body: AnatomicalRig, options?: ProportionCheckOptions): PoseIssue[];
177
+ /** A report as lines of text: a header, then the clip summary or each issue. */
178
+ export declare function formatPoseReport(report: PoseReport | ClipReport): string;
179
+ /**
180
+ * {@link checkPose} that throws when any issue is an error, for a test.
181
+ * @throws MargoError `failed` with the report as `error.report`.
182
+ */
183
+ export declare function assertPose(body: AnatomicalRig, pose: ArrayLike<number>, options?: PoseCheckOptions): PoseReport;
184
+ /**
185
+ * {@link checkClip} that throws when any issue is an error, for a test of a capture or a retargeted take.
186
+ * @throws MargoError `failed` with the report as `error.report`.
187
+ */
188
+ export declare function assertClip(body: AnatomicalRig, sample: Iterable<ArrayLike<number>> | ((time: number, out: Float64Array) => void), options?: ClipCheckOptions): ClipReport;
@@ -0,0 +1,440 @@
1
+ import { r as e, s as t } from "./rig-BawZ5OLb.js";
2
+ import { n, t as r } from "./body-volumes-DTym0RVY.js";
3
+ import { clampPose as i, readJointAngles as a } from "./anatomy.js";
4
+ import { n as o } from "./errors-D8rc8kzg.js";
5
+ //#region src/validate.ts
6
+ var s = "https://margoengine.com/llms/packages/rigging.md#pose-checks-margoengineriggingvalidate", c = /* @__PURE__ */ new WeakMap();
7
+ function l(t) {
8
+ let n = c.get(t);
9
+ if (n) return n;
10
+ if (!t || !t.species || !Array.isArray(t.joints) || !(t.rest instanceof Float64Array)) throw TypeError(`The pose checker needs an AnatomicalRig made by fitAnatomy(rig, { species }); see ${s}`);
11
+ let i = t.species, a = e(t.parents, "Pose checker"), o = /* @__PURE__ */ new Map(), l = new Map(i.joints.map((e) => [e.id, e]));
12
+ for (let e of t.joints) o.set(e.id, e.spec);
13
+ for (let e of t.regions) o.set(e.id, t.joints[e.joints[0]].spec);
14
+ let u = t.stature > 0 ? t.stature : 1, d = (e) => {
15
+ let n = t.index.get(e);
16
+ return n === void 0 ? void 0 : t.joints[n].bone;
17
+ }, f = t.joints.filter((e) => e.limited && t.parents[e.bone] >= 0).map((e) => {
18
+ let n = e.bone * 10;
19
+ return {
20
+ bone: e.bone,
21
+ joint: e.id,
22
+ length: Math.hypot(t.rest[n], t.rest[n + 1], t.rest[n + 2]),
23
+ scale: [
24
+ t.rest[n + 7],
25
+ t.rest[n + 8],
26
+ t.rest[n + 9]
27
+ ]
28
+ };
29
+ }).filter((e) => e.length > 1e-4 * u), { volumes: p, pairs: m } = r(t), h = /* @__PURE__ */ new Set(), g = [];
30
+ for (let e of i.feet ?? []) {
31
+ let t = d(e);
32
+ t !== void 0 && !h.has(t) && l.has(e) && (h.add(t), g.push({
33
+ id: e,
34
+ bone: t
35
+ }));
36
+ }
37
+ return n = {
38
+ order: a,
39
+ specs: o,
40
+ bones: f,
41
+ volumes: p,
42
+ pairs: m,
43
+ feet: g,
44
+ up: [...t.frame.vertical],
45
+ stature: u
46
+ }, c.set(t, n), n;
47
+ }
48
+ var u = (e, t) => t >= 0 ? e.names[t] ?? null : null;
49
+ function d(e, t = null, n = null) {
50
+ return {
51
+ ...e,
52
+ excess: e.excess ?? Math.abs(e.value - e.limit),
53
+ time: t,
54
+ frame: n,
55
+ help: s
56
+ };
57
+ }
58
+ var f = (e, t = 1) => e.toFixed(t);
59
+ function p(e, t, n, r) {
60
+ let o = r.tier === "normal" ? ["normal"] : r.tier === "structural" ? ["structural"] : ["structural", "normal"], s = r.tolerance ?? .5, c = [], l = /* @__PURE__ */ new Set();
61
+ for (let r of o) {
62
+ let a = [];
63
+ i(e, Float64Array.from(n), {
64
+ tier: r,
65
+ issues: a,
66
+ force: !0
67
+ });
68
+ for (let n of a) {
69
+ let i = Math.abs(n.value - n.limit), a = `${n.joint}|${n.motion}`;
70
+ if (i <= s || l.has(a)) continue;
71
+ l.add(a);
72
+ let o = t.specs.get(n.joint), p = o?.dofs?.findIndex((e) => e.positive === n.motion || e.negative === n.motion) ?? -1, m = o?.kind === "hinge" && !e.regions.some((e) => e.id === n.joint), h = p === 2 ? "twist-out-of-range" : m && p === 1 ? "hinge-sideways" : m && p === 0 && n.motion === o.dofs[0].negative ? "hinge-reversed" : "out-of-range", g = r === "structural" ? "error" : "warning", _ = h === "hinge-reversed" ? `bent ${f(-n.value)} deg past straight` : `${n.motion} ${f(n.value)} deg`;
73
+ c.push(d({
74
+ code: h,
75
+ severity: g,
76
+ joint: n.joint,
77
+ bone: u(e, n.bone),
78
+ motion: n.motion,
79
+ value: n.value,
80
+ limit: n.limit,
81
+ unit: "deg",
82
+ tier: r,
83
+ source: n.source,
84
+ message: `${n.joint} ${_}, ${f(i)} past its ${r === "structural" ? "stop" : "clinical range"} of ${f(n.limit)}${n.source ? ` (${n.source})` : ""}`
85
+ }));
86
+ }
87
+ }
88
+ if (r.tier !== "structural") {
89
+ let t = a(e, n);
90
+ e.joints.forEach((n, r) => {
91
+ let i = n.spec, a = t[r * 3];
92
+ n.kind === "hinge" && i.neutral === "straight" && n.normal[0] > -10 && a < -s && !l.has(`${n.id}|${i.dofs[0].negative}`) && c.push(d({
93
+ code: "hinge-reversed",
94
+ severity: "warning",
95
+ joint: n.id,
96
+ bone: u(e, n.bone),
97
+ motion: i.dofs[0].negative,
98
+ value: a,
99
+ limit: 0,
100
+ unit: "deg",
101
+ tier: "normal",
102
+ source: null,
103
+ message: `${n.id} bent ${f(-a)} deg past straight: inside its clinical range of ${f(n.normal[0])}, but it looks locked back`
104
+ }));
105
+ });
106
+ }
107
+ return c;
108
+ }
109
+ var m = (e, t) => e[0] * t[0] + e[1] * t[1] + e[2] * t[2], h = (e, t) => [
110
+ e[0] - t[0],
111
+ e[1] - t[1],
112
+ e[2] - t[2]
113
+ ], g = (e, t) => [
114
+ e[0] + t[0],
115
+ e[1] + t[1],
116
+ e[2] + t[2]
117
+ ], _ = (e, t) => [
118
+ e[0] * t,
119
+ e[1] * t,
120
+ e[2] * t
121
+ ], v = (e, t) => [
122
+ e[t * 3],
123
+ e[t * 3 + 1],
124
+ e[t * 3 + 2]
125
+ ];
126
+ function y(e, t, r, i, a) {
127
+ let o = [], c = t.stature, l = a.stretch ?? .01;
128
+ for (let n of t.bones) {
129
+ let t = n.bone * 10, i = Math.hypot(r[t], r[t + 1], r[t + 2]), a = i / n.length - 1, s = [
130
+ 0,
131
+ 1,
132
+ 2
133
+ ].reduce((e, i) => Math.max(e, Math.abs(r[t + 7 + i] / (n.scale[i] || 1) - 1)), 0);
134
+ Math.abs(a) > l && o.push(d({
135
+ code: "bone-stretch",
136
+ severity: "error",
137
+ joint: n.joint,
138
+ bone: u(e, n.bone),
139
+ motion: null,
140
+ value: i / c,
141
+ limit: n.length / c,
142
+ unit: "stature",
143
+ tier: null,
144
+ source: null,
145
+ message: `${n.joint}: the bone is ${f(Math.abs(a) * 100)} percent ${a > 0 ? "longer" : "shorter"} than at rest`
146
+ })), s > l && o.push(d({
147
+ code: "bone-stretch",
148
+ severity: "error",
149
+ joint: n.joint,
150
+ bone: u(e, n.bone),
151
+ motion: "scale",
152
+ value: 1 + s,
153
+ limit: 1,
154
+ unit: "ratio",
155
+ tier: null,
156
+ source: null,
157
+ message: `${n.joint}: the bone is scaled ${f(s * 100)} percent from rest`
158
+ }));
159
+ }
160
+ let p = a.ground;
161
+ if (p != null) {
162
+ let n = (a.sink ?? .002) * c, r = t.up, l = -1, h = n;
163
+ for (let t of e.joints) {
164
+ let e = m(v(i, t.bone), r) - p;
165
+ -e > h && (h = -e, l = t.bone);
166
+ }
167
+ if (l >= 0) {
168
+ let t = e.joints.find((e) => e.bone === l);
169
+ o.push(d({
170
+ code: "ground-penetration",
171
+ severity: "error",
172
+ joint: t.id,
173
+ bone: u(e, l),
174
+ motion: null,
175
+ value: -h / c,
176
+ limit: 0,
177
+ unit: "stature",
178
+ tier: null,
179
+ source: null,
180
+ message: `${t.id}: the joint is ${f(h / c * 100)} percent of stature below the ground`
181
+ }));
182
+ }
183
+ let g = a.points;
184
+ if (g && g.length >= 3) {
185
+ let e = n, t = -1;
186
+ for (let n = 0; n + 2 < g.length; n += 3) {
187
+ let i = g[n] * r[0] + g[n + 1] * r[1] + g[n + 2] * r[2] - p;
188
+ -i > e && (e = -i, t = n / 3);
189
+ }
190
+ t >= 0 && o.push(d({
191
+ code: "ground-penetration",
192
+ severity: "error",
193
+ joint: `point ${t}`,
194
+ bone: null,
195
+ motion: null,
196
+ value: -e / c,
197
+ limit: 0,
198
+ unit: "stature",
199
+ tier: null,
200
+ source: null,
201
+ message: `skin point ${t} is ${f(e / c * 100)} percent of stature below the ground`
202
+ }));
203
+ }
204
+ let _ = (a.float ?? .06) * c;
205
+ for (let t of a.supports ?? []) {
206
+ let n = e.index.get(t);
207
+ if (n === void 0) throw RangeError(`checkPose: support "${t}" is not a joint of this body; see ${s}`);
208
+ let a = e.joints[n].bone, l = m(v(i, a), r) - p;
209
+ l > _ && o.push(d({
210
+ code: "floating",
211
+ severity: "error",
212
+ joint: t,
213
+ bone: u(e, a),
214
+ motion: null,
215
+ value: l / c,
216
+ limit: _ / c,
217
+ unit: "stature",
218
+ tier: null,
219
+ source: null,
220
+ message: `${t} bears weight but is ${f(l / c * 100)} percent of stature above the ground`
221
+ }));
222
+ }
223
+ }
224
+ if (a.volumes !== !1 && t.pairs.length) {
225
+ let e = a.shrink ?? .7;
226
+ for (let [r, a] of t.pairs) {
227
+ let s = t.volumes.get(r), l = t.volumes.get(a), [u, p, m] = n(v(i, s.near), v(i, s.far), v(i, l.near), v(i, l.far)), h = e * (s.r0 + (s.r1 - s.r0) * u + l.r0 + (l.r1 - l.r0) * p), g = Math.sqrt(m);
228
+ g < h && o.push(d({
229
+ code: "self-penetration",
230
+ severity: "error",
231
+ joint: `${r} + ${a}`,
232
+ bone: null,
233
+ motion: null,
234
+ value: g / c,
235
+ limit: h / c,
236
+ unit: "stature",
237
+ tier: null,
238
+ source: "ansur2",
239
+ message: `${r} passes through ${a}: their axes are ${f(g / c * 100)} percent of stature apart, ${f((h - g) / c * 100)} inside their girth`
240
+ }));
241
+ }
242
+ }
243
+ return o;
244
+ }
245
+ var b = {
246
+ error: 0,
247
+ warning: 1
248
+ }, x = (e) => e.sort((e, t) => b[e.severity] - b[t.severity] || t.excess - e.excess), S = (e) => {
249
+ let t = e.filter((e) => e.severity === "error").length;
250
+ return {
251
+ passed: t === 0,
252
+ errors: t,
253
+ warnings: e.length - t,
254
+ issues: e
255
+ };
256
+ };
257
+ function C(e, t, n) {
258
+ if (!t || typeof t.length != "number" || t.length !== e.names.length * 10) throw TypeError(`${n} needs a local pose with 10 numbers per bone; see ${s}`);
259
+ }
260
+ function w(e, n, r = {}) {
261
+ let i = l(e);
262
+ C(e, n, "checkPose");
263
+ let { position: a } = t(e.parents, n, i.order);
264
+ return S(x([...p(e, i, n, r), ...y(e, i, n, a, r)]));
265
+ }
266
+ function T(e, n, r = {}) {
267
+ let i = l(e), a = r.fps ?? 30, o = r.start ?? 0, c = i.stature;
268
+ if (!(a > 0)) throw RangeError(`checkClip fps must be above 0; see ${s}`);
269
+ let x;
270
+ if (typeof n == "function") {
271
+ let t = r.duration;
272
+ if (!(typeof t == "number" && t >= 0)) throw TypeError(`checkClip needs options.duration when sample is a function; see ${s}`);
273
+ let i = Math.floor(t * a + 1e-9) + 1, c = Float64Array.from(e.rest);
274
+ x = { *[Symbol.iterator]() {
275
+ for (let e = 0; e < i; e++) n(o + e / a, c), yield c;
276
+ } };
277
+ } else x = n;
278
+ let w = [], T = e.joints.filter((e) => e.limited), E = [], D = [], O = i.feet.map(() => []), k = r.velocity ?? [
279
+ 0,
280
+ 0,
281
+ 0
282
+ ], A = new Float64Array(T.length * 4), j = 0;
283
+ for (let n of x) {
284
+ C(e, n, "checkClip");
285
+ let s = o + j / a, { position: c } = t(e.parents, n, i.order), l = (e) => w.push({
286
+ ...e,
287
+ time: s,
288
+ frame: j
289
+ });
290
+ for (let t of p(e, i, n, r)) l(t);
291
+ for (let t of y(e, i, n, c, r)) l(t);
292
+ let u = new Float64Array(T.length);
293
+ T.forEach((e, t) => {
294
+ let r = e.bone * 10;
295
+ if (j) {
296
+ let e = Math.abs(n[r + 3] * A[t * 4] + n[r + 4] * A[t * 4 + 1] + n[r + 5] * A[t * 4 + 2] + n[r + 6] * A[t * 4 + 3]);
297
+ u[t] = 2 * Math.acos(Math.min(1, e)) * 180 / Math.PI * a;
298
+ }
299
+ for (let e = 0; e < 4; e++) A[t * 4 + e] = n[r + 3 + e];
300
+ }), E.push(u), D.push(Float64Array.from(A)), i.feet.forEach((e, t) => O[t].push(g(v(c, e.bone), _(k, j / a)))), j++;
301
+ }
302
+ let M = r.maxSpeed ?? 9e3, N = (e, t, n) => {
303
+ let r = D[e], i = D[t], o = Math.abs(r[n * 4] * i[n * 4] + r[n * 4 + 1] * i[n * 4 + 1] + r[n * 4 + 2] * i[n * 4 + 2] + r[n * 4 + 3] * i[n * 4 + 3]);
304
+ return 2 * Math.acos(Math.min(1, o)) * 180 / Math.PI * a;
305
+ };
306
+ for (let t = 1; t < j; t++) T.forEach((n, r) => {
307
+ let i = E[t][r], s = t > 1 ? E[t - 1][r] : 0, c = t + 1 < j ? E[t + 1][r] : 0, l = i > 1e3 && i > 4 * Math.max(s, c), p = t + 1 < j && i > 1e3 && c > 1e3 && 4 * N(t - 1, t + 1, r) < Math.min(i, c);
308
+ i <= M && !l && !p || (p && i <= M && (E[t + 1][r] = 0), w.push(d({
309
+ code: "pop",
310
+ severity: "error",
311
+ joint: n.id,
312
+ bone: u(e, n.bone),
313
+ motion: null,
314
+ value: i,
315
+ limit: i > M ? M : l ? 4 * Math.max(s, c) : 4 * N(t - 1, t + 1, r),
316
+ unit: "deg/s",
317
+ tier: null,
318
+ source: null,
319
+ message: i > M ? `${n.id} turns ${f(i, 0)} deg/s, faster than any body (${f(M, 0)}, Fleisig et al. 2017)` : l ? `${n.id} jumps ${f(i / a)} deg in one frame, ${f(i / Math.max(s, c, 1e-9))} times its neighbouring frames` : `${n.id} leaves its path by ${f(i / a)} deg for one frame and comes back`
320
+ }, o + t / a, t)));
321
+ });
322
+ let P = (r.contact ?? .02) * c, F = (r.slide ?? .1) * c, I = i.up;
323
+ i.feet.forEach((t, n) => {
324
+ let r = O[n], i = r.map((e) => m(e, I)), s = Math.min(...i);
325
+ for (let n = 1; n + 1 < j; n++) {
326
+ if (i[n - 1] > s + P || i[n] > s + P || i[n + 1] > s + P) continue;
327
+ let l = h(r[n + 1], r[n - 1]), p = h(l, _(I, m(l, I))), g = Math.hypot(...p) * a / 2;
328
+ g <= F || w.push(d({
329
+ code: "foot-slide",
330
+ severity: "error",
331
+ joint: t.id,
332
+ bone: u(e, t.bone),
333
+ motion: null,
334
+ value: g / c,
335
+ limit: F / c,
336
+ unit: "stature/s",
337
+ tier: null,
338
+ source: null,
339
+ message: `${t.id} is planted but slides ${f(g / c * 100)} percent of stature per second`
340
+ }, o + n / a, n));
341
+ }
342
+ });
343
+ let L = /* @__PURE__ */ new Map();
344
+ for (let e of w) {
345
+ let t = `${e.code}|${e.joint}|${e.motion}`, n = L.get(t);
346
+ n ? L.set(t, {
347
+ ...n,
348
+ severity: e.severity === "error" ? "error" : n.severity,
349
+ frames: n.frames + 1,
350
+ first: Math.min(n.first, e.time),
351
+ last: Math.max(n.last, e.time),
352
+ worst: b[e.severity] < b[n.worst.severity] || e.severity === n.worst.severity && e.excess > n.worst.excess ? e : n.worst
353
+ }) : L.set(t, {
354
+ code: e.code,
355
+ severity: e.severity,
356
+ joint: e.joint,
357
+ motion: e.motion,
358
+ frames: 1,
359
+ first: e.time,
360
+ last: e.time,
361
+ worst: e
362
+ });
363
+ }
364
+ let R = [...L.values()].sort((e, t) => b[e.severity] - b[t.severity] || t.frames - e.frames || t.worst.excess - e.worst.excess);
365
+ return w.sort((e, t) => e.frame - t.frame || b[e.severity] - b[t.severity] || t.excess - e.excess), {
366
+ ...S(w),
367
+ frames: j,
368
+ fps: a,
369
+ summary: R
370
+ };
371
+ }
372
+ function E(e, n = {}) {
373
+ let r = l(e), i = n.stature ?? r.stature, a = n.asymmetry ?? .05, { position: o } = t(e.parents, e.neutral, r.order), c = new Map(e.species.joints.map((e) => [e.id, e])), u = [];
374
+ if (!(i > 0)) throw RangeError(`checkProportions needs a stature above 0; see ${s}`);
375
+ let p = (t, n, a, s) => {
376
+ let c = e.index.get(t), l = e.index.get(n);
377
+ if (c === void 0 || l === void 0) return null;
378
+ let u = e.joints[c].bone, d = e.joints[l].bone;
379
+ if (u === d) return null;
380
+ let f = h(v(o, d), v(o, u));
381
+ return (a === "length" ? Math.hypot(...f) : m(f, r.up)) / i + s;
382
+ }, g = (e) => c.get(e)?.mirror ?? e;
383
+ for (let t of e.species.proportions) {
384
+ let e = t.measure;
385
+ if (!e) continue;
386
+ let n = [[t.id, p(e.from, e.to, e.along, e.offset ?? 0)]], r = [g(e.from), g(e.to)];
387
+ (r[0] !== e.from || r[1] !== e.to) && n.push([`${t.id} (mirror)`, p(r[0], r[1], e.along, e.offset ?? 0)]);
388
+ for (let [r, i] of n) {
389
+ if (i === null) continue;
390
+ let [n, a] = e.band;
391
+ if (i >= n && i <= a) continue;
392
+ let o = i < n ? n : a;
393
+ u.push(d({
394
+ code: "proportion",
395
+ severity: "error",
396
+ joint: r,
397
+ bone: null,
398
+ motion: null,
399
+ value: i,
400
+ limit: o,
401
+ unit: "stature",
402
+ tier: null,
403
+ source: t.rows[0]?.source ?? null,
404
+ message: `${r} (${t.what}) is ${f(i, 3)} of stature, ${i < n ? "under" : "over"} ${f(o, 3)}; people measure ${f(t.share, 3)}`
405
+ }));
406
+ }
407
+ let [i, o] = n.map((e) => e[1]);
408
+ i !== null && o != null && Math.abs(i - o) > a * t.share && u.push(d({
409
+ code: "asymmetry",
410
+ severity: "warning",
411
+ joint: t.id,
412
+ bone: null,
413
+ motion: null,
414
+ value: Math.abs(i - o) / t.share,
415
+ limit: a,
416
+ unit: "ratio",
417
+ tier: null,
418
+ source: null,
419
+ message: `${t.id}: the two sides differ by ${f(Math.abs(i - o) / t.share * 100)} percent`
420
+ }));
421
+ }
422
+ return x(u);
423
+ }
424
+ function D(e) {
425
+ let t = "summary" in e, n = `${e.passed ? "passed" : "FAILED"}: ${e.errors} errors, ${e.warnings} warnings${t ? ` over ${e.frames} frames at ${e.fps} fps` : ""}`;
426
+ return t ? [n, ...e.summary.map((e) => `${e.severity.padEnd(7)} ${e.code.padEnd(18)} ${e.joint}${e.motion ? ` ${e.motion}` : ""}: ${e.frames} frames, ${f(e.first, 2)} to ${f(e.last, 2)} s; worst at ${f(e.worst.time, 2)} s: ${e.worst.message}`)].join("\n") : [n, ...e.issues.map((e) => `${e.severity.padEnd(7)} ${e.code.padEnd(18)} ${e.message}`)].join("\n");
427
+ }
428
+ var O = (e, t) => Object.assign(o("failed", `${e} failed the pose checks\n${D(t)}\nSee ${s}`), { report: t });
429
+ function k(e, t, n) {
430
+ let r = w(e, t, n);
431
+ if (!r.passed) throw O("The pose", r);
432
+ return r;
433
+ }
434
+ function A(e, t, n) {
435
+ let r = T(e, t, n);
436
+ if (!r.passed) throw O("The clip", r);
437
+ return r;
438
+ }
439
+ //#endregion
440
+ export { s as POSE_HELP, A as assertClip, k as assertPose, T as checkClip, w as checkPose, E as checkProportions, D as formatPoseReport };
@@ -1,6 +1,6 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
- const u=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
3
+ const u=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
4
  import { rotationBetween as e } from "./ik.js";
5
5
  import { i as t, r as n, t as r } from "./errors-D8rc8kzg.js";
6
6
  import { conjugateQuaternion as i, interpolateQuaternions as a, multiplyQuaternions as o, normalizeQuaternion as s, rotateByQuaternion as c, splitTRS as l } from "@margoengine/math/quat";
@@ -242,7 +242,7 @@ function S(e, n = {}) {
242
242
  }, j = () => {
243
243
  E || (E = !0, O?.(), O = void 0, D?.(), D = void 0, !e.disposed && !f.disposed && (a.forEach((t, n) => e.nodes[t.target].setQuaternion(w[n])), m.tick(!1)));
244
244
  };
245
- return n.animator ? D = n.animator.addSolver(A) : (p.use({coreRequirement:/*@__PURE__*/__margoCoreRequirement("0.1.0",import.meta.url),
245
+ return n.animator ? D = n.animator.addSolver(A) : (p.use({coreRequirement:/*@__PURE__*/__margoCoreRequirement("1.0.0",import.meta.url),
246
246
  name: T,
247
247
  setup() {},
248
248
  onPreUpdate: A,
package/dist/vrm.d.ts CHANGED
@@ -278,7 +278,11 @@ export interface VRMHandle {
278
278
  readonly gaze: VRMGaze | null;
279
279
  /** Explicit gaze angles in degrees, for motion capture or VRMA; null (default) follows lookAtTarget. */
280
280
  lookAtGaze: VRMGaze | null;
281
- /** What this model cannot show: MToon-only colour binds, by expression. Empty for most avatars. */
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
+ */
282
286
  readonly unsupported: readonly string[];
283
287
  /** Add a pose producer, evaluated before gaze, expressions and springs, in registration order. Returns its removal. */
284
288
  addPoseSource(update: (delta: number) => void): () => void;
@@ -291,8 +295,9 @@ export interface VRMHandle {
291
295
  /**
292
296
  * Brings an avatar to life on a model: expressions, gaze and spring bones run every frame in the order the
293
297
  * specification recommends, after any clip. Pass the model's `Animation` (`@margoengine/animation`), which plays the
294
- * morph targets, and `options.animator` when an Animator poses the model. Colours bound to MToon-only fields are listed
295
- * in `unsupported`: the model draws MToon materials by their glTF fallback.
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.
296
301
  * @throws RangeError when the avatar does not fit the model.
297
302
  */
298
303
  export declare function addVRM(animation: Animator['animation'], avatar: VRMAvatar, options?: AddVRMOptions): VRMHandle;
package/dist/vrm.js CHANGED
@@ -1,4 +1,4 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
3
 
4
4
  import { SpringBones as e, springAccess as t } from "./springs.js";
@@ -510,7 +510,7 @@ function L(n, r, i = {}) {
510
510
  }, Y = `vrm:${m[b].id}`, X;
511
511
  if (f) X = f.addSolver(J);
512
512
  else {
513
- let e = {coreRequirement:/*@__PURE__*/__margoCoreRequirement("0.1.0",import.meta.url),
513
+ let e = {coreRequirement:/*@__PURE__*/__margoCoreRequirement("1.0.0",import.meta.url),
514
514
  name: Y,
515
515
  setup() {},
516
516
  onPreUpdate: J,