@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
@@ -0,0 +1,42 @@
1
+ import { type RigJoint } from './rig.js';
2
+ import { type WeightMesh } from './mesh.js';
3
+ import { WeightMap } from './weight-map.js';
4
+ /** Options for {@link voxelWeights}. */
5
+ export interface VoxelWeightsOptions {
6
+ /** Voxels along the mesh's longest side, 8 to 512 (default 96). Finer parts apart need more. */
7
+ resolution?: number;
8
+ /** Joints that move no vertices (indices or names), such as a root at the feet. Default none. */
9
+ skip?: readonly (number | string)[];
10
+ /** Falloff power: larger keeps vertices closer to their nearest bone (default 4). */
11
+ falloff?: number;
12
+ /** Blend from distance (0) to distance squared (1) in the falloff (default 0.75). */
13
+ curve?: number;
14
+ /** Most bones per vertex before renormalising, 1 or more (default 4). */
15
+ influences?: number;
16
+ /** Closes gaps up to this many voxels before filling; parts closer than twice this fuse (default 0). */
17
+ closing?: number;
18
+ /** Welding tolerance as a fraction of the mesh's size (default 1e-6: coincident vertices). */
19
+ weld?: number;
20
+ /** Cancels the solve between bones; the promise rejects with the signal's reason. */
21
+ signal?: AbortSignal;
22
+ }
23
+ /** What {@link voxelWeights} found, beside the weights. */
24
+ export interface VoxelWeightsResult {
25
+ /** Weights over the input vertices. */
26
+ readonly weights: WeightMap;
27
+ /** Grid size. */
28
+ readonly grid: readonly [number, number, number];
29
+ /** Solid voxels. */
30
+ readonly voxels: number;
31
+ /** Vertices no bone reached through the solid: they took the straight-line nearest bones. */
32
+ readonly unreached: number;
33
+ }
34
+ /**
35
+ * Skin weights for a mesh that bone heat cannot solve: holes, doubled or flipped faces, non-manifold edges, several
36
+ * parts, intersecting shells. Geodesic voxel binding (Dionne and de Lasa 2013): voxelizes the mesh and bones, measures
37
+ * each bone's distance through the solid, and gives each vertex the falloff of its nearest bones. Resolves to the
38
+ * weights with what the grid held. Joints and vertices share one space. A part no bone reaches, such as a loose
39
+ * accessory, takes the same falloff from straight-line distances and is counted in `unreached`.
40
+ * @throws TypeError or RangeError for invalid input.
41
+ */
42
+ export declare function voxelWeights(mesh: WeightMesh, joints: readonly RigJoint[], options?: VoxelWeightsOptions): Promise<VoxelWeightsResult>;
@@ -0,0 +1 @@
1
+ export { t as voxelWeights } from "./voxel-weights-48ok-Dax.js";
@@ -0,0 +1,36 @@
1
+ import type { RigJoint } from './rig.js';
2
+ import type { Welded } from './mesh.js';
3
+ /** Axis directions of the six a voxel inside an open mesh must find surface on. */
4
+ export declare const INSIDE_VOTES = 4;
5
+ export declare const OUTSIDE = 0;
6
+ export declare const SHELL = 1;
7
+ export declare const SOLID = 2;
8
+ /** The grid over a mesh, one voxel of margin all round so the outside is connected. */
9
+ export interface Grid {
10
+ readonly nx: number;
11
+ readonly ny: number;
12
+ readonly nz: number;
13
+ readonly cell: number;
14
+ readonly origin: readonly [number, number, number];
15
+ readonly state: Uint8Array;
16
+ }
17
+ export declare function makeGrid(welded: Welded, joints: readonly RigJoint[], resolution: number): Grid;
18
+ /** Marks every voxel a triangle passes through, by walking the triangle at under one voxel's spacing. */
19
+ export declare function markTriangles(grid: Grid, welded: Welded): void;
20
+ /** Dilates the shell `size` voxels, floods the outside, then erodes the dilation back: gaps close, parts keep their size. */
21
+ export declare function fill(grid: Grid, closing: number): void;
22
+ /** How many of the six axis directions find surface or solid from each voxel. */
23
+ export declare function votes(grid: Grid): Uint8Array;
24
+ /** A binary heap of voxels by distance, with lazy deletion. */
25
+ export declare class Heap {
26
+ private keys;
27
+ private items;
28
+ size: number;
29
+ push(key: number, item: number): void;
30
+ /** Removes the least; its item and key are left in `item` and `key`. */
31
+ item: number;
32
+ key: number;
33
+ pop(): void;
34
+ }
35
+ /** The 26 neighbours of a voxel: offset and length in voxels. */
36
+ export declare const NEIGHBOURS: readonly (readonly [number, number, number, number])[];
@@ -0,0 +1,60 @@
1
+ // @ts-ignore optional peer: its types apply when it is installed
2
+ import type { PBRModel } from '@margoengine/gltf/pbr-model';
3
+ // @ts-ignore optional peer: its types apply when it is installed
4
+ import type { Animator } from '@margoengine/animator';
5
+ declare const axes: {
6
+ readonly X: readonly [1, 0, 0];
7
+ readonly Y: readonly [0, 1, 0];
8
+ readonly Z: readonly [0, 0, 1];
9
+ readonly PositiveX: readonly [1, 0, 0];
10
+ readonly NegativeX: readonly [-1, 0, 0];
11
+ readonly PositiveY: readonly [0, 1, 0];
12
+ readonly NegativeY: readonly [0, -1, 0];
13
+ readonly PositiveZ: readonly [0, 0, 1];
14
+ readonly NegativeZ: readonly [0, 0, -1];
15
+ };
16
+ /** A normalized constraint. Only weight is mutable, from zero through one. */
17
+ export interface VRMNodeConstraint {
18
+ readonly target: number;
19
+ readonly source: number;
20
+ readonly kind: 'rotation' | 'roll' | 'aim';
21
+ readonly axis?: keyof typeof axes;
22
+ weight: number;
23
+ }
24
+ /** The glTF node data this optional entry reads, without taking ownership. */
25
+ export interface VRMConstraintDocument {
26
+ nodes?: readonly {
27
+ children?: readonly number[];
28
+ rotation?: readonly number[];
29
+ matrix?: readonly number[];
30
+ extensions?: Record<string, unknown>;
31
+ }[];
32
+ }
33
+ /** Rest and current transforms for a stateless constraint evaluation. World fields are needed only by aim. */
34
+ export interface VRMConstraintFrame {
35
+ sourceRest: ArrayLike<number>;
36
+ destinationRest: ArrayLike<number>;
37
+ sourceRotation: ArrayLike<number>;
38
+ parentWorldRotation?: ArrayLike<number>;
39
+ sourceWorldPosition?: ArrayLike<number>;
40
+ destinationWorldPosition?: ArrayLike<number>;
41
+ }
42
+ /** Read independent VRMC_node_constraint 1.0 records, validating references, hierarchy and constraint dependencies. */
43
+ export declare function readVRMConstraints(document: VRMConstraintDocument): readonly VRMNodeConstraint[];
44
+ /** Evaluate the standard rest-relative rotation, swing-free roll or shortest world-space aim, without mutating inputs. */
45
+ export declare function evaluateVRMConstraint(constraint: Pick<VRMNodeConstraint, 'kind' | 'axis' | 'weight'>, frame: VRMConstraintFrame): [number, number, number, number];
46
+ /** Attach after this model's Animator; omit to run as a scene pre-update plugin. */
47
+ export interface VRMConstraintsOptions {
48
+ animator?: Animator;
49
+ }
50
+ /** Borrowed model controller. Weights are live; disposal restores the captured pre-attachment target rotations. */
51
+ export interface VRMConstraintsHandle {
52
+ readonly constraints: readonly VRMNodeConstraint[];
53
+ readonly disposed: boolean;
54
+ update(): void;
55
+ dispose(): void;
56
+ [Symbol.dispose](): void;
57
+ }
58
+ /** Install the authored constraints in dependency order, after animation and before skin matrices are uploaded. */
59
+ export declare function addVRMConstraints(model: PBRModel, options?: VRMConstraintsOptions): VRMConstraintsHandle;
60
+ export {};
@@ -0,0 +1,261 @@
1
+ // @margo/core-built 1.0.0
2
+ import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
+ const u=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
+ import { rotationBetween as e } from "./ik.js";
5
+ import { i as t, r as n, t as r } from "./errors-D8rc8kzg.js";
6
+ import { conjugateQuaternion as i, interpolateQuaternions as a, multiplyQuaternions as o, normalizeQuaternion as s, rotateByQuaternion as c, splitTRS as l } from "@margoengine/math/quat";
7
+ import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
8
+ //#region src/vrm-constraints.ts
9
+ var d = [
10
+ 0,
11
+ 0,
12
+ 0,
13
+ 1
14
+ ], f = {
15
+ X: [
16
+ 1,
17
+ 0,
18
+ 0
19
+ ],
20
+ Y: [
21
+ 0,
22
+ 1,
23
+ 0
24
+ ],
25
+ Z: [
26
+ 0,
27
+ 0,
28
+ 1
29
+ ],
30
+ PositiveX: [
31
+ 1,
32
+ 0,
33
+ 0
34
+ ],
35
+ NegativeX: [
36
+ -1,
37
+ 0,
38
+ 0
39
+ ],
40
+ PositiveY: [
41
+ 0,
42
+ 1,
43
+ 0
44
+ ],
45
+ NegativeY: [
46
+ 0,
47
+ -1,
48
+ 0
49
+ ],
50
+ PositiveZ: [
51
+ 0,
52
+ 0,
53
+ 1
54
+ ],
55
+ NegativeZ: [
56
+ 0,
57
+ 0,
58
+ -1
59
+ ]
60
+ }, p = (e) => !!e && typeof e == "object" && !Array.isArray(e);
61
+ function m(e, t) {
62
+ if (!e || e.length !== t || Array.from(e).some((e) => !Number.isFinite(e))) throw n("VRM constraint transforms need finite vectors of the declared length", "transform");
63
+ return Array.from(e);
64
+ }
65
+ function h(e) {
66
+ let t = m(e, 4);
67
+ if (!t.some((e) => e !== 0)) throw n("VRM constraint quaternion must be nonzero", "transform");
68
+ return s(t);
69
+ }
70
+ function g(e) {
71
+ if (!Number.isFinite(e) || e < 0 || e > 1) throw n("VRM constraint weight must be finite from zero through one", "transform");
72
+ }
73
+ function _(e) {
74
+ if (!e) throw t("VRM constraint needs a rotation, roll or aim record", "transform");
75
+ if (g(e.weight), ![
76
+ "rotation",
77
+ "roll",
78
+ "aim"
79
+ ].includes(e.kind) || e.kind === "roll" && ![
80
+ "X",
81
+ "Y",
82
+ "Z"
83
+ ].includes(e.axis ?? "") || e.kind === "aim" && ![
84
+ "PositiveX",
85
+ "NegativeX",
86
+ "PositiveY",
87
+ "NegativeY",
88
+ "PositiveZ",
89
+ "NegativeZ"
90
+ ].includes(e.axis ?? "")) throw t("VRM constraint needs rotation, roll with X/Y/Z, or aim with a signed axis", "transform");
91
+ }
92
+ function v(e) {
93
+ if (!p(e) || e.nodes !== void 0 && !Array.isArray(e.nodes)) throw t("VRM constraints need a parsed glTF document with a nodes array", "transform");
94
+ let r = e.nodes ?? [], i = [];
95
+ return r.forEach((e, a) => {
96
+ if (!p(e) || e.children !== void 0 && !Array.isArray(e.children)) throw t("VRM constraints need object nodes with child-index arrays", "transform");
97
+ if (e.extensions !== void 0 && !p(e.extensions)) throw t("VRM node extensions must be an object; pass parsed extension records", "transform");
98
+ let o = p(e.extensions) ? e.extensions.VRMC_node_constraint : void 0;
99
+ if (o === void 0) return;
100
+ if (!p(o) || o.specVersion !== "1.0" || !p(o.constraint)) throw t("VRM node constraint needs specVersion 1.0 and one constraint object", "transform");
101
+ let s = Object.entries(o.constraint).filter(([e]) => [
102
+ "rotation",
103
+ "roll",
104
+ "aim"
105
+ ].includes(e));
106
+ if (s.length !== 1 || !p(s[0][1])) throw t("VRM node constraint must contain exactly one roll, aim or rotation", "transform");
107
+ let [c, l] = s[0], u = l.source, d = l.weight === void 0 ? 1 : l.weight;
108
+ if (!Number.isSafeInteger(u) || u < 0 || u >= r.length || u === a) throw n("VRM constraint source must name another existing node", "transform");
109
+ let f = {
110
+ target: a,
111
+ source: u,
112
+ kind: c,
113
+ weight: d,
114
+ axis: c === "roll" ? l.rollAxis : l.aimAxis
115
+ };
116
+ _(f);
117
+ for (let e of [
118
+ "target",
119
+ "source",
120
+ "kind",
121
+ "axis"
122
+ ]) Object.defineProperty(f, e, {
123
+ writable: !1,
124
+ configurable: !1
125
+ });
126
+ i.push(f);
127
+ }), y(e, i), Object.freeze(i);
128
+ }
129
+ function y(e, t) {
130
+ let i = e.nodes ?? [], a = new Int32Array(i.length).fill(-1);
131
+ for (let e = 0; e < i.length; e++) for (let t of i[e].children ?? []) {
132
+ if (!Number.isSafeInteger(t) || t < 0 || t >= i.length || t === e || a[t] !== -1) throw n("VRM constraint hierarchy must be a forest of existing nodes with one parent each", "transform");
133
+ a[t] = e;
134
+ }
135
+ let o = (e) => {
136
+ let t = [], n = /* @__PURE__ */ new Set();
137
+ for (let i = e; i !== -1; i = a[i]) {
138
+ if (n.has(i)) throw r("state", "VRM node hierarchy contains a cycle; remove the circular parent", "hierarchy");
139
+ n.add(i), t.push(i);
140
+ }
141
+ return t;
142
+ }, s = new Uint8Array(i.length);
143
+ for (let e = 0; e < i.length; e++) {
144
+ let t = [], n = e;
145
+ for (; n !== -1 && s[n] === 0;) s[n] = 1, t.push(n), n = a[n];
146
+ if (n !== -1 && s[n] === 1) throw r("state", "VRM node hierarchy contains a cycle; remove the circular parent", "hierarchy");
147
+ for (let e of t) s[e] = 2;
148
+ }
149
+ let c = new Map(t.map((e, t) => [e.target, t])), l = t.map((e) => {
150
+ let t = e.kind === "aim" ? [...o(e.source), ...o(a[e.target])] : [e.source];
151
+ return [...new Set(t.filter((e) => c.has(e)).map((e) => c.get(e)))];
152
+ }), u = [], d = new Uint8Array(t.length);
153
+ for (let e = 0; e < t.length; e++) {
154
+ let t = [{
155
+ node: e,
156
+ next: 0
157
+ }];
158
+ for (; t.length;) {
159
+ let e = t[t.length - 1];
160
+ if (d[e.node] === 2) {
161
+ t.pop();
162
+ continue;
163
+ }
164
+ d[e.node] = 1;
165
+ let n = l[e.node][e.next++];
166
+ if (n !== void 0) {
167
+ if (d[n] === 1) throw r("state", "VRM constraints contain a circular dependency; remove the cycle", "hierarchy");
168
+ d[n] !== 2 && t.push({
169
+ node: n,
170
+ next: 0
171
+ });
172
+ } else d[e.node] = 2, u.push(e.node), t.pop();
173
+ }
174
+ }
175
+ return u;
176
+ }
177
+ function b(n, r) {
178
+ if (_(n), !r) throw t("VRM constraint evaluation needs rest and current transforms", "transform");
179
+ let l = h(r.destinationRest), u = h(r.sourceRest), p = h(r.sourceRotation), g;
180
+ if (n.kind === "aim") {
181
+ let t = h(r.parentWorldRotation ?? d), a = c(f[n.axis], o(t, l)), s = m(r.sourceWorldPosition, 3), u = m(r.destinationWorldPosition, 3), p = s.map((e, t) => e - u[t]);
182
+ g = Math.hypot(...p) === 0 ? l : o(o(o(i(t), e(a, p)), t), l);
183
+ } else {
184
+ let e = o(i(u), p);
185
+ if (n.kind === "rotation") g = o(l, e);
186
+ else {
187
+ let t = s(o(o(i(l), u), o(e, o(i(u), l)))), r = f[n.axis], a = t[0] * r[0] + t[1] * r[1] + t[2] * r[2], c = [
188
+ r[0] * a,
189
+ r[1] * a,
190
+ r[2] * a,
191
+ t[3]
192
+ ];
193
+ g = o(l, Math.hypot(...c) === 0 ? d : s(c));
194
+ }
195
+ }
196
+ return a(l, s(g), n.weight, 1 - 2 ** -52);
197
+ }
198
+ var x = 0;
199
+ function S(e, n = {}) {
200
+ if (!e || e.disposed) throw r("disposed", "VRM constraints need a live PBRModel; load it again");
201
+ if (n.animator && n.animator.animation.model !== e) throw t("VRM constraints and Animator must belong to the same model", "transform");
202
+ let i = e.asset.doc, a = v(i), c = y(i, a), f = u(e.root.engine), p = f.sceneOf(e), m = f.store;
203
+ if (!p) throw r("state", "VRM constraints need a registered model; load it into a scene first");
204
+ let _ = (e) => {
205
+ e.syncRotation();
206
+ let t = m.transforms, n = e.id;
207
+ return h([
208
+ t.qx[n],
209
+ t.qy[n],
210
+ t.qz[n],
211
+ t.qw[n]
212
+ ]);
213
+ }, S = (e) => {
214
+ let t = [
215
+ 0,
216
+ 0,
217
+ 0,
218
+ 1
219
+ ];
220
+ for (let n = e; n; n = f.meshes.get(m.parents[n.id])) t = o(_(n), t);
221
+ return s(t);
222
+ }, C = (i.nodes ?? []).map((e) => {
223
+ if (!e.matrix) return h(e.rotation ?? d);
224
+ let n = l(e.matrix);
225
+ if (!n.ok) throw t("VRM constraint rest matrix must have nonsingular TRS; remove shear or zero scale", "transform");
226
+ return n.rotation;
227
+ }), w = a.map((t) => _(e.nodes[t.target])), T = "vrm-constraints:" + x++, E = !1, D, O, k = (t, r) => n.animator ? n.animator.writeNodeRotation(e.nodes[t], r) : e.nodes[t].setQuaternion(r), A = () => {
228
+ if (E || e.disposed) throw r("disposed", "VRM constraints are disposed; attach a new controller");
229
+ for (let e of a) g(e.weight);
230
+ m.tick(!1);
231
+ for (let t of c) {
232
+ let n = a[t], r = e.nodes[n.source], i = e.nodes[n.target], o = f.meshes.get(m.parents[i.id]), s = b(n, {
233
+ sourceRest: C[n.source],
234
+ destinationRest: C[n.target],
235
+ sourceRotation: _(r),
236
+ parentWorldRotation: S(o),
237
+ sourceWorldPosition: r.matrix.subarray(12, 15),
238
+ destinationWorldPosition: i.matrix.subarray(12, 15)
239
+ });
240
+ k(n.target, s), m.tick(!1);
241
+ }
242
+ }, j = () => {
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
+ };
245
+ return n.animator ? D = n.animator.addSolver(A) : (p.use({coreRequirement:/*@__PURE__*/__margoCoreRequirement("1.0.0",import.meta.url),
246
+ name: T,
247
+ setup() {},
248
+ onPreUpdate: A,
249
+ dispose: j
250
+ }), D = () => f.removePlugin(T, p)), O = e.onDispose(j), {
251
+ constraints: a,
252
+ get disposed() {
253
+ return E;
254
+ },
255
+ update: A,
256
+ dispose: j,
257
+ [Symbol.dispose]: j
258
+ };
259
+ }
260
+ //#endregion
261
+ export { S as addVRMConstraints, b as evaluateVRMConstraint, v as readVRMConstraints };
@@ -0,0 +1,115 @@
1
+ // @ts-ignore optional peer: its types apply when it is installed
2
+ import type { EngineKernel } from '@margoengine/core';
3
+ // @ts-ignore optional peer: its types apply when it is installed
4
+ import type { Camera } from '@margoengine/core/extension';
5
+ // @ts-ignore optional peer: its types apply when it is installed
6
+ import type { GLTFLoadOptions, PBRModel } from '@margoengine/gltf/pbr';
7
+ import { FIRST_PERSON_ONLY_LAYER, THIRD_PERSON_ONLY_LAYER } from './shared/layers.js';
8
+ export { FIRST_PERSON_ONLY_LAYER, THIRD_PERSON_ONLY_LAYER };
9
+ /** Which cameras draw a mesh (`firstPerson.meshAnnotations[].type`). */
10
+ export type VRMFirstPersonType = 'auto' | 'both' | 'thirdPersonOnly' | 'firstPersonOnly';
11
+ /** What a Draco decoder returns for one primitive; @margoengine/decoders' `DracoDecoder` matches it. */
12
+ export interface VRMDracoGeometry {
13
+ vertexCount: number;
14
+ positions?: ArrayLike<number>;
15
+ normals?: ArrayLike<number>;
16
+ uvs?: ArrayLike<number>;
17
+ colors?: ArrayLike<number>;
18
+ indices?: ArrayLike<number>;
19
+ attributes?: Record<string, {
20
+ array: ArrayLike<number>;
21
+ }>;
22
+ }
23
+ /** Options of {@link splitVRMFirstPerson}. */
24
+ export interface SplitVRMFirstPersonOptions {
25
+ /**
26
+ * Skin weight a vertex must exceed on the head or a bone below it to belong to the head. Default 0: any weight, as
27
+ * the specification describes. Raise it to keep collar triangles with a stray head weight in first person.
28
+ */
29
+ threshold?: number;
30
+ /** Cancels the split, also while a Draco decoder runs. */
31
+ signal?: AbortSignal;
32
+ /**
33
+ * Decoder for KHR_draco_mesh_compression primitives the split has to read. Default: a `DracoDecoder` from
34
+ * @margoengine/decoders, made for this call and disposed after it. The caller keeps ownership of one passed here.
35
+ */
36
+ draco?: {
37
+ decode(data: Uint8Array, options: {
38
+ attributeIds: Record<string, number>;
39
+ componentTypes: Record<string, number>;
40
+ signal?: AbortSignal;
41
+ }): Promise<VRMDracoGeometry>;
42
+ };
43
+ }
44
+ /**
45
+ * Resolves every `auto` mesh annotation of a VRM 1.0 file (a missing annotation, or no `firstPerson`, also means
46
+ * `auto`), as VRMC_vrm 1.0 firstPerson.md describes. A skinned mesh whose every point, line or triangle has a vertex
47
+ * with weight on the head bone or a bone below it becomes `thirdPersonOnly`; one with none becomes `both`; a mixed one
48
+ * keeps the rest (`both`) and gives the head part to a new child node (`thirdPersonOnly`, the same skin, appended after
49
+ * every existing node so no index moves). Each part holds compact copies of the vertices it uses, morph targets
50
+ * included, so skinning works on the original vertex count plus the seam. An unskinned `auto` mesh is
51
+ * `thirdPersonOnly` when its node is the head or below it, else `both`. Expression binds and animation weight channels
52
+ * of a split node get a twin for the child. The result has no `auto` left, so a second split returns its input; a file
53
+ * with no `auto` comes back as it was, byte for byte.
54
+ * @throws MargoError `failed` for a file whose geometry breaks glTF 2.0, `unsupported` for an external buffer; what
55
+ * {@link readVRM} throws for a file that is not VRM 1.0; the signal's reason when aborted.
56
+ */
57
+ export declare function splitVRMFirstPerson(glb: Uint8Array, options?: SplitVRMFirstPersonOptions): Promise<Uint8Array>;
58
+ /** Options of {@link loadVRM}: gltf/pbr's load options and the split's threshold. */
59
+ export interface LoadVRMOptions extends GLTFLoadOptions {
60
+ /** See {@link SplitVRMFirstPersonOptions.threshold}. Default 0. */
61
+ threshold?: number;
62
+ }
63
+ /**
64
+ * Loads a VRM 1.0 URL or bytes as a PBRModel after {@link splitVRMFirstPerson}, so {@link addVRMFirstPerson} finds no
65
+ * `auto` mesh. Downloads at most `maxDownloadBytes` (default 64 MiB); `signal` cancels the download, the split and
66
+ * the load. For a VRM 0.x file, convert it with `convertVRM0Bytes` from @margoengine/rigging/vrm0 first.
67
+ * @throws what {@link splitVRMFirstPerson} and gltf/pbr's `parseGLTFAsync` throw; RangeError past the download budget.
68
+ */
69
+ export declare function loadVRM(engine: EngineKernel, source: string | URL | Uint8Array, options?: LoadVRMOptions): Promise<PBRModel>;
70
+ /** Options of {@link addVRMFirstPerson}. */
71
+ export interface VRMFirstPersonOptions {
72
+ /** Layer (0 to 31) of `firstPersonOnly` meshes. Default {@link FIRST_PERSON_ONLY_LAYER}, 29. */
73
+ firstPersonOnlyLayer?: number;
74
+ /** Layer (0 to 31) of `thirdPersonOnly` meshes. Default {@link THIRD_PERSON_ONLY_LAYER}, 30. */
75
+ thirdPersonOnlyLayer?: number;
76
+ /** Cameras that see through the avatar's eyes: each draws `firstPersonLayers`. Default none. */
77
+ firstPersonCameras?: readonly Camera[];
78
+ /**
79
+ * Cameras that see the avatar from outside: each draws `thirdPersonLayers`, but only when the file has a
80
+ * `firstPersonOnly` mesh (otherwise every layer already is right). Default the engine's camera.
81
+ */
82
+ thirdPersonCameras?: readonly Camera[];
83
+ }
84
+ /** What {@link addVRMFirstPerson} returns. `dispose()` or `using` puts every mask back as it was. */
85
+ export interface VRMFirstPerson extends Disposable {
86
+ /** Layer of `firstPersonOnly` meshes. */
87
+ readonly firstPersonOnlyLayer: number;
88
+ /** Layer of `thirdPersonOnly` meshes. */
89
+ readonly thirdPersonOnlyLayer: number;
90
+ /** Mask for a view through the eyes: every layer but `thirdPersonOnlyLayer`. */
91
+ readonly firstPersonLayers: number;
92
+ /** Mask for a view from outside, a mirror or a probe: every layer but `firstPersonOnlyLayer`. */
93
+ readonly thirdPersonLayers: number;
94
+ /** Each mesh node's resolved type, as in the file. */
95
+ readonly meshAnnotations: readonly {
96
+ node: number;
97
+ type: Exclude<VRMFirstPersonType, 'auto'>;
98
+ }[];
99
+ /**
100
+ * World position of the eyes: `lookAt.offsetFromHeadBone` (the specification gives no default; [0, 0, 0] as `vrmGaze` uses) through the head bone's world
101
+ * matrix as the engine last computed it. Put the first-person camera here.
102
+ */
103
+ viewpoint(out?: [number, number, number]): [number, number, number];
104
+ dispose(): void;
105
+ }
106
+ /**
107
+ * Applies the first-person annotations of a loaded VRM 1.0 model through render layers: `thirdPersonOnly` nodes get
108
+ * only `thirdPersonOnlyLayer`, `firstPersonOnly` nodes only `firstPersonOnlyLayer`, `both` keep their mask, and the
109
+ * given cameras get the matching view masks. Give any other view the handle's masks: a view, mirror or probe with no
110
+ * mask draws every layer, `firstPersonOnly` meshes included. Shadows are not filtered: the avatar casts its whole
111
+ * shadow in every view. Setting a mask replaces a layer the caller had set on that node, until `dispose()`.
112
+ * @throws MargoError `state` when a mesh node is still `auto` (load the file with {@link loadVRM}); what
113
+ * {@link readVRM} throws for a model that is not VRM 1.0; RangeError for a layer outside 0 to 31 or two equal layers.
114
+ */
115
+ export declare function addVRMFirstPerson(model: PBRModel, options?: VRMFirstPersonOptions): VRMFirstPerson;