@margoengine/rigging 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +969 -3
- package/dist/autorig.d.ts +50 -0
- package/dist/autorig.js +660 -0
- package/dist/bar-grip.d.ts +7 -0
- package/dist/checks.d.ts +50 -0
- package/dist/contact.d.ts +175 -0
- package/dist/contact.js +739 -0
- package/dist/correctives.d.ts +92 -0
- package/dist/correctives.js +162 -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 +109 -0
- package/dist/ik.js +358 -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 +71 -0
- package/dist/retarget.js +351 -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/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 +298 -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 +175 -6
package/dist/vrm0.js
ADDED
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { t as e } from "./errors-D8rc8kzg.js";
|
|
2
|
+
import { a as t, i as n, n as r, o as i } from "./vrm-presets-CU4V4yq6.js";
|
|
3
|
+
import { checkVRM as a } from "./vrm.js";
|
|
4
|
+
import { t as o } from "./loading-CZaYr1N7.js";
|
|
5
|
+
import { Matrix4 as s } from "@margoengine/math";
|
|
6
|
+
import { invertMatrix as c, multiplyMatrices as l } from "@margoengine/math/mat4";
|
|
7
|
+
//#region src/vrm0.ts
|
|
8
|
+
var u = (t) => e("failed", `VRM 0.x: ${t}; repair the avatar before loading`), d = (e, t = [
|
|
9
|
+
0,
|
|
10
|
+
0,
|
|
11
|
+
0
|
|
12
|
+
]) => e ? [
|
|
13
|
+
e.x ?? 0,
|
|
14
|
+
e.y ?? 0,
|
|
15
|
+
-(e.z ?? 0)
|
|
16
|
+
] : t, f = {
|
|
17
|
+
neutral: "neutral",
|
|
18
|
+
a: "aa",
|
|
19
|
+
i: "ih",
|
|
20
|
+
u: "ou",
|
|
21
|
+
e: "ee",
|
|
22
|
+
o: "oh",
|
|
23
|
+
blink: "blink",
|
|
24
|
+
joy: "happy",
|
|
25
|
+
angry: "angry",
|
|
26
|
+
sorrow: "sad",
|
|
27
|
+
fun: "relaxed",
|
|
28
|
+
lookup: "lookUp",
|
|
29
|
+
lookdown: "lookDown",
|
|
30
|
+
lookleft: "lookLeft",
|
|
31
|
+
lookright: "lookRight",
|
|
32
|
+
blink_l: "blinkLeft",
|
|
33
|
+
blink_r: "blinkRight"
|
|
34
|
+
}, p = {
|
|
35
|
+
_Color: "color",
|
|
36
|
+
_EmissionColor: "emissionColor",
|
|
37
|
+
_ShadeColor: "shadeColor",
|
|
38
|
+
_RimColor: "rimColor",
|
|
39
|
+
_OutlineColor: "outlineColor"
|
|
40
|
+
};
|
|
41
|
+
function m(e) {
|
|
42
|
+
return e instanceof Uint8Array ? r(new TextDecoder().decode(i(e)[0].data)) : e;
|
|
43
|
+
}
|
|
44
|
+
function h(e) {
|
|
45
|
+
let t = structuredClone(m(e)), n = t?.extensions?.VRM;
|
|
46
|
+
if (!n || typeof n != "object" || Array.isArray(n)) throw u("no VRM extension");
|
|
47
|
+
if (t.extensions?.VRMC_vrm) throw u("both VRM and VRMC_vrm are present; choose one version");
|
|
48
|
+
if (n.specVersion && !/^0\./.test(n.specVersion)) throw u(`unsupported version ${n.specVersion}`);
|
|
49
|
+
let r = t.nodes ??= [], i = r.length, o = new Int32Array(i).fill(-1), h = [], v = (e) => {
|
|
50
|
+
if (!Number.isInteger(e) || e < 0 || e >= i) throw u(`node ${e} does not exist`);
|
|
51
|
+
};
|
|
52
|
+
r.forEach((e, t) => e.children?.forEach((e) => {
|
|
53
|
+
if (v(e), o[e] !== -1) throw u(`node ${e} has multiple parents`);
|
|
54
|
+
o[e] = t;
|
|
55
|
+
}));
|
|
56
|
+
let y = Array.from(o).flatMap((e, t) => e === -1 ? [t] : []), b = 0;
|
|
57
|
+
for (; y.length;) {
|
|
58
|
+
let e = y.pop();
|
|
59
|
+
b++;
|
|
60
|
+
for (let t of r[e].children ?? []) y.push(t);
|
|
61
|
+
}
|
|
62
|
+
if (b !== i) throw u("node hierarchy has a cycle");
|
|
63
|
+
let x = {};
|
|
64
|
+
for (let { bone: e, node: t } of n.humanoid?.humanBones ?? []) {
|
|
65
|
+
v(t);
|
|
66
|
+
let n = e.replace(/ThumbProximal$/, "ThumbMetacarpal").replace(/ThumbIntermediate$/, "ThumbProximal");
|
|
67
|
+
if (x[n]) throw u(`duplicate humanoid bone ${n}`);
|
|
68
|
+
x[n] = { node: t };
|
|
69
|
+
}
|
|
70
|
+
let S = n.meta ?? {}, C = {
|
|
71
|
+
specVersion: "1.0",
|
|
72
|
+
meta: {
|
|
73
|
+
name: S.title || "Untitled VRM 0.x",
|
|
74
|
+
authors: [S.author || "Unknown"],
|
|
75
|
+
version: S.version,
|
|
76
|
+
licenseUrl: S.otherLicenseUrl || g(S.licenseName),
|
|
77
|
+
contactInformation: S.contactInformation,
|
|
78
|
+
references: S.reference ? [S.reference] : [],
|
|
79
|
+
avatarPermission: {
|
|
80
|
+
OnlyAuthor: "onlyAuthor",
|
|
81
|
+
ExplicitlyLicensedPerson: "onlySeparatelyLicensedPerson",
|
|
82
|
+
Everyone: "everyone"
|
|
83
|
+
}[S.allowedUserName ?? ""] ?? "onlyAuthor",
|
|
84
|
+
allowExcessivelyViolentUsage: S.violentUssageName === "Allow",
|
|
85
|
+
allowExcessivelySexualUsage: S.sexualUssageName === "Allow",
|
|
86
|
+
commercialUsage: S.commercialUssageName === "Allow" ? "corporation" : "personalNonProfit",
|
|
87
|
+
allowPoliticalOrReligiousUsage: !1,
|
|
88
|
+
allowAntisocialOrHateUsage: !1,
|
|
89
|
+
otherLicenseUrl: S.otherPermissionUrl
|
|
90
|
+
},
|
|
91
|
+
humanoid: { humanBones: x },
|
|
92
|
+
expressions: {
|
|
93
|
+
preset: {},
|
|
94
|
+
custom: {}
|
|
95
|
+
},
|
|
96
|
+
extras: { vrm0: structuredClone(n) }
|
|
97
|
+
}, w = t.textures;
|
|
98
|
+
S.texture !== void 0 && (C.meta.thumbnailImage = w?.[S.texture]?.source), h.push("Original VRM 0.x licence remains authoritative; meta is a runtime projection, not a new licence.");
|
|
99
|
+
let T = (e) => {
|
|
100
|
+
if (!Number.isInteger(e) || !t.meshes?.[e]) throw u(`mesh ${e} does not exist`);
|
|
101
|
+
return r.flatMap((t, n) => t.mesh === e ? [n] : []);
|
|
102
|
+
}, E = t.materials ?? [];
|
|
103
|
+
for (let [e, t] of (n.blendShapeMaster?.blendShapeGroups ?? []).entries()) {
|
|
104
|
+
let n = f[(t.presetName ?? "").toLowerCase()], r = n ?? t.name ?? `expression${e}`, i = n ? C.expressions.preset : C.expressions.custom;
|
|
105
|
+
if (r in i || !n && Object.values(f).includes(r)) throw u(`expression name ${r} is not unique`);
|
|
106
|
+
let a = {
|
|
107
|
+
isBinary: t.isBinary ?? !1,
|
|
108
|
+
morphTargetBinds: [],
|
|
109
|
+
materialColorBinds: [],
|
|
110
|
+
textureTransformBinds: []
|
|
111
|
+
};
|
|
112
|
+
for (let e of t.binds ?? []) {
|
|
113
|
+
if (!Number.isFinite(e.weight) || e.weight < 0 || e.weight > 100) throw u("morph weights must be 0 to 100");
|
|
114
|
+
for (let t of T(e.mesh)) a.morphTargetBinds.push({
|
|
115
|
+
node: t,
|
|
116
|
+
index: e.index,
|
|
117
|
+
weight: e.weight / 100
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
for (let e of t.materialValues ?? []) {
|
|
121
|
+
let t = E.flatMap((t, n) => t.name === e.materialName ? [n] : []);
|
|
122
|
+
if (!t.length) throw u(`expression ${r} names missing material ${e.materialName}`);
|
|
123
|
+
let n = e.targetValue;
|
|
124
|
+
if (!Array.isArray(n) || n.some((e) => !Number.isFinite(e))) throw u(`invalid material bind ${r}`);
|
|
125
|
+
for (let i of t) if (p[e.propertyName]) {
|
|
126
|
+
if (n.length < 3) throw u(`colour bind ${r} needs RGB`);
|
|
127
|
+
a.materialColorBinds.push({
|
|
128
|
+
material: i,
|
|
129
|
+
type: p[e.propertyName],
|
|
130
|
+
targetValue: [
|
|
131
|
+
n[0],
|
|
132
|
+
n[1],
|
|
133
|
+
n[2],
|
|
134
|
+
n[3] ?? 1
|
|
135
|
+
]
|
|
136
|
+
});
|
|
137
|
+
} else if (e.propertyName === "_MainTex" || e.propertyName === "_MainTex_ST") {
|
|
138
|
+
if (n.length !== 4) throw u(`texture bind ${r} needs scale and offset`);
|
|
139
|
+
a.textureTransformBinds.push({
|
|
140
|
+
material: i,
|
|
141
|
+
scale: [n[0], n[1]],
|
|
142
|
+
offset: [n[2], 1 - n[1] - n[3]]
|
|
143
|
+
});
|
|
144
|
+
} else h.push(`Expression ${r}: legacy material property ${e.propertyName} retained in extras.vrm0.`);
|
|
145
|
+
}
|
|
146
|
+
i[r] = a;
|
|
147
|
+
}
|
|
148
|
+
let D = n.firstPerson;
|
|
149
|
+
if (D) {
|
|
150
|
+
C.firstPerson = { meshAnnotations: (D.meshAnnotations ?? []).flatMap((e) => T(e.mesh).map((t) => ({
|
|
151
|
+
node: t,
|
|
152
|
+
type: {
|
|
153
|
+
Auto: "auto",
|
|
154
|
+
Both: "both",
|
|
155
|
+
FirstPersonOnly: "firstPersonOnly",
|
|
156
|
+
ThirdPersonOnly: "thirdPersonOnly"
|
|
157
|
+
}[e.firstPersonFlag ?? "Auto"] ?? "auto"
|
|
158
|
+
}))) };
|
|
159
|
+
let e = d(D.firstPersonBoneOffset), t = x.head?.node, n = D.firstPersonBone;
|
|
160
|
+
if (t !== void 0 && n !== void 0 && n !== -1 && n !== t) {
|
|
161
|
+
v(n);
|
|
162
|
+
let i = (e) => {
|
|
163
|
+
let t = [];
|
|
164
|
+
for (let n = e; n !== -1; n = o[n]) t.push(n);
|
|
165
|
+
let n = new s().elements;
|
|
166
|
+
for (let e of t.reverse()) {
|
|
167
|
+
let t = r[e].translation ?? [
|
|
168
|
+
0,
|
|
169
|
+
0,
|
|
170
|
+
0
|
|
171
|
+
], i = r[e].rotation ?? [
|
|
172
|
+
0,
|
|
173
|
+
0,
|
|
174
|
+
0,
|
|
175
|
+
1
|
|
176
|
+
], a = r[e].scale ?? [
|
|
177
|
+
1,
|
|
178
|
+
1,
|
|
179
|
+
1
|
|
180
|
+
], o = r[e].matrix ?? new s().compose({
|
|
181
|
+
x: t[0],
|
|
182
|
+
y: t[1],
|
|
183
|
+
z: t[2]
|
|
184
|
+
}, {
|
|
185
|
+
x: i[0],
|
|
186
|
+
y: i[1],
|
|
187
|
+
z: i[2],
|
|
188
|
+
w: i[3]
|
|
189
|
+
}, {
|
|
190
|
+
x: a[0],
|
|
191
|
+
y: a[1],
|
|
192
|
+
z: a[2]
|
|
193
|
+
}).elements;
|
|
194
|
+
n = l(n, o);
|
|
195
|
+
}
|
|
196
|
+
return n;
|
|
197
|
+
}, a = c(i(t));
|
|
198
|
+
if (!a) throw u("head transform cannot be inverted");
|
|
199
|
+
let d = l(a, i(n)), f = (t) => d[t] * e[0] + d[t + 4] * e[1] + d[t + 8] * e[2] + d[t + 12];
|
|
200
|
+
e = [
|
|
201
|
+
f(0),
|
|
202
|
+
f(1),
|
|
203
|
+
f(2)
|
|
204
|
+
];
|
|
205
|
+
}
|
|
206
|
+
C.lookAt = {
|
|
207
|
+
type: D.lookAtTypeName === "BlendShape" ? "expression" : "bone",
|
|
208
|
+
offsetFromHeadBone: e
|
|
209
|
+
};
|
|
210
|
+
for (let e of [
|
|
211
|
+
"HorizontalInner",
|
|
212
|
+
"HorizontalOuter",
|
|
213
|
+
"VerticalUp",
|
|
214
|
+
"VerticalDown"
|
|
215
|
+
]) {
|
|
216
|
+
let t = D[`lookAt${e}`];
|
|
217
|
+
C.lookAt[`rangeMap${e}`] = {
|
|
218
|
+
inputMaxValue: t?.xRange ?? 90,
|
|
219
|
+
outputScale: t?.yRange ?? (C.lookAt.type === "bone" ? 10 : 1)
|
|
220
|
+
}, t?.curve && h.push(`lookAt${e}: curve retained in extras.vrm0; 1.0 uses a linear range.`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
_(n, t, o, v);
|
|
224
|
+
let O = t.extensions?.VRMC_springBone;
|
|
225
|
+
O && (C.springBone = O);
|
|
226
|
+
let k = Array.from(o).flatMap((e, t) => e === -1 ? [t] : []), A = /* @__PURE__ */ new Map();
|
|
227
|
+
for (let e of k) A.set(e, r.length), r.push({
|
|
228
|
+
name: "VRM 0.x forward",
|
|
229
|
+
rotation: [
|
|
230
|
+
0,
|
|
231
|
+
1,
|
|
232
|
+
0,
|
|
233
|
+
0
|
|
234
|
+
],
|
|
235
|
+
children: [e]
|
|
236
|
+
});
|
|
237
|
+
let j = t.scenes;
|
|
238
|
+
if (j) for (let e of j) e.nodes = (e.nodes ?? []).map((e) => {
|
|
239
|
+
let t = A.get(e);
|
|
240
|
+
if (t === void 0) throw u(`scene node ${e} is not a root`);
|
|
241
|
+
return t;
|
|
242
|
+
});
|
|
243
|
+
else t.scenes = [{ nodes: [...A.values()] }], t.scene = 0;
|
|
244
|
+
let { springBone: M, ...N } = C;
|
|
245
|
+
t.extensions = {
|
|
246
|
+
...t.extensions,
|
|
247
|
+
VRMC_vrm: N
|
|
248
|
+
}, delete t.extensions.VRM, t.extensionsUsed = [.../* @__PURE__ */ new Set([
|
|
249
|
+
...(t.extensionsUsed ?? []).filter((e) => e !== "VRM"),
|
|
250
|
+
"VRMC_vrm",
|
|
251
|
+
...O ? ["VRMC_springBone"] : []
|
|
252
|
+
])], Array.isArray(t.extensionsRequired) && (t.extensionsRequired = t.extensionsRequired.filter((e) => e !== "VRM"));
|
|
253
|
+
let P = a(C, t);
|
|
254
|
+
if (P.length) throw u(P.join("; "));
|
|
255
|
+
return {
|
|
256
|
+
document: t,
|
|
257
|
+
avatar: C,
|
|
258
|
+
legacy: structuredClone(n),
|
|
259
|
+
differences: h
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
function g(e) {
|
|
263
|
+
let t = {
|
|
264
|
+
CC0: "publicdomain/zero/1.0/",
|
|
265
|
+
CC_BY: "licenses/by/4.0/",
|
|
266
|
+
CC_BY_NC: "licenses/by-nc/4.0/",
|
|
267
|
+
CC_BY_SA: "licenses/by-sa/4.0/",
|
|
268
|
+
CC_BY_NC_SA: "licenses/by-nc-sa/4.0/",
|
|
269
|
+
CC_BY_ND: "licenses/by-nd/4.0/",
|
|
270
|
+
CC_BY_NC_ND: "licenses/by-nc-nd/4.0/"
|
|
271
|
+
};
|
|
272
|
+
return t[e ?? ""] ? `https://creativecommons.org/${t[e]}` : "https://vrm.dev/en/vrm0/";
|
|
273
|
+
}
|
|
274
|
+
function _(e, t, n, r) {
|
|
275
|
+
let i = e.secondaryAnimation;
|
|
276
|
+
if (!i) return;
|
|
277
|
+
let a = t.nodes, o = {
|
|
278
|
+
specVersion: "1.0",
|
|
279
|
+
colliders: [],
|
|
280
|
+
colliderGroups: [],
|
|
281
|
+
springs: []
|
|
282
|
+
};
|
|
283
|
+
for (let e of i.colliderGroups ?? []) {
|
|
284
|
+
r(e.node);
|
|
285
|
+
let t = [];
|
|
286
|
+
for (let n of e.colliders ?? []) t.push(o.colliders.length), o.colliders.push({
|
|
287
|
+
node: e.node,
|
|
288
|
+
shape: { sphere: {
|
|
289
|
+
offset: d(n.offset),
|
|
290
|
+
radius: n.radius ?? 0
|
|
291
|
+
} }
|
|
292
|
+
});
|
|
293
|
+
o.colliderGroups.push({ colliders: t });
|
|
294
|
+
}
|
|
295
|
+
let s = /* @__PURE__ */ new Set();
|
|
296
|
+
for (let e of i.boneGroups ?? []) {
|
|
297
|
+
let t = d(e.gravityDir, [
|
|
298
|
+
0,
|
|
299
|
+
-1,
|
|
300
|
+
0
|
|
301
|
+
]), n = [
|
|
302
|
+
-t[0],
|
|
303
|
+
t[1],
|
|
304
|
+
-t[2]
|
|
305
|
+
], i = {
|
|
306
|
+
hitRadius: e.hitRadius ?? 0,
|
|
307
|
+
stiffness: e.stiffiness ?? 1,
|
|
308
|
+
gravityPower: e.gravityPower ?? 0,
|
|
309
|
+
gravityDir: n,
|
|
310
|
+
dragForce: e.dragForce ?? .4
|
|
311
|
+
}, c = e.colliderGroups ?? [];
|
|
312
|
+
for (let e of c) if (!Number.isInteger(e) || !o.colliderGroups[e]) throw u(`collider group ${e} does not exist`);
|
|
313
|
+
let l;
|
|
314
|
+
e.center !== void 0 && e.center !== -1 && (r(e.center), l = e.center);
|
|
315
|
+
let f = (t) => {
|
|
316
|
+
let n = [t];
|
|
317
|
+
for (; n.length;) {
|
|
318
|
+
let t = n.pop();
|
|
319
|
+
if (s.has(t)) throw u(`spring node ${t} belongs to multiple bone roots`);
|
|
320
|
+
s.add(t);
|
|
321
|
+
let r = (a[t].children ?? []).slice(), d = a[t].translation ?? [
|
|
322
|
+
0,
|
|
323
|
+
0,
|
|
324
|
+
0
|
|
325
|
+
], f = Math.hypot(...d), p = r.length ? a[r[0]].translation ?? [
|
|
326
|
+
0,
|
|
327
|
+
0,
|
|
328
|
+
0
|
|
329
|
+
] : f > 0 ? d.map((e) => e * .07 / f) : [
|
|
330
|
+
0,
|
|
331
|
+
.07,
|
|
332
|
+
0
|
|
333
|
+
], m = a.length;
|
|
334
|
+
a.push({
|
|
335
|
+
name: "VRM 0.x spring tail",
|
|
336
|
+
translation: p.slice()
|
|
337
|
+
}), a[t].children = [...r, m], o.springs.push({
|
|
338
|
+
name: e.comment,
|
|
339
|
+
joints: [{
|
|
340
|
+
node: t,
|
|
341
|
+
...i
|
|
342
|
+
}, {
|
|
343
|
+
node: m,
|
|
344
|
+
...i
|
|
345
|
+
}],
|
|
346
|
+
center: l,
|
|
347
|
+
colliderGroups: c.slice()
|
|
348
|
+
}), n.push(...r.slice().reverse());
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
for (let t of e.bones ?? []) r(t), f(t);
|
|
352
|
+
}
|
|
353
|
+
(t.extensions ??= {}).VRMC_springBone = o;
|
|
354
|
+
}
|
|
355
|
+
function v(e) {
|
|
356
|
+
let r = i(e), { document: a } = h(e), o = new TextEncoder().encode(JSON.stringify(a)), s = o.length + 3 & -4, c = r.slice(1), l = 20 + s + c.reduce((e, t) => e + 8 + t.data.length, 0), u = new Uint8Array(l), d = new DataView(u.buffer);
|
|
357
|
+
d.setUint32(0, t, !0), d.setUint32(4, 2, !0), d.setUint32(8, l, !0), d.setUint32(12, s, !0), d.setUint32(16, n, !0), u.set(o, 20), u.fill(32, 20 + o.length, 20 + s);
|
|
358
|
+
let f = 20 + s;
|
|
359
|
+
for (let e of c) d.setUint32(f, e.data.length, !0), d.setUint32(f + 4, e.type, !0), u.set(e.data, f + 8), f += 8 + e.data.length;
|
|
360
|
+
return u;
|
|
361
|
+
}
|
|
362
|
+
async function y(e, t, n = {}) {
|
|
363
|
+
n.signal?.throwIfAborted();
|
|
364
|
+
let r = n.fetch ?? globalThis.fetch, i = n.maxDownloadBytes ?? 67108864;
|
|
365
|
+
if (!Number.isSafeInteger(i) || i <= 0) throw u("maxDownloadBytes must be a positive safe integer");
|
|
366
|
+
let a = t instanceof Uint8Array ? t : await o(await r(t, { signal: n.signal }), {
|
|
367
|
+
maxBytes: i,
|
|
368
|
+
signal: n.signal,
|
|
369
|
+
label: "VRM 0.x"
|
|
370
|
+
});
|
|
371
|
+
if (a.byteLength > i) throw u("download exceeds maxDownloadBytes");
|
|
372
|
+
let s = v(a), { parseGLTFAsync: c } = await import("@margoengine/gltf/pbr");
|
|
373
|
+
return n.signal?.throwIfAborted(), c(e, s, n);
|
|
374
|
+
}
|
|
375
|
+
var b = (e) => h(e).avatar;
|
|
376
|
+
//#endregion
|
|
377
|
+
export { h as convertVRM0, v as convertVRM0Bytes, y as loadVRM0, b as readVRM0 };
|
package/dist/vrma.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// @ts-ignore optional peer: its types apply when it is installed
|
|
2
|
+
import { type Interpolation } from '@margoengine/animation/sampling';
|
|
3
|
+
// @ts-ignore optional peer: its types apply when it is installed
|
|
4
|
+
import type { RetargetRig } from '@margoengine/animation/skeleton-utils';
|
|
5
|
+
// @ts-ignore optional peer: its types apply when it is installed
|
|
6
|
+
import type { Animation } from '@margoengine/animation';
|
|
7
|
+
// @ts-ignore optional peer: its types apply when it is installed
|
|
8
|
+
import type { GLTFDocument } from '@margoengine/gltf/asset';
|
|
9
|
+
import { type HumanoidBone } from './retarget.js';
|
|
10
|
+
import type { VRMAvatar, VRMHandle, VRMGaze } from './vrm.js';
|
|
11
|
+
/** VRMC_vrm_animation metadata, retained with extension fields and licensing extras. */
|
|
12
|
+
export interface VRMAExtension {
|
|
13
|
+
specVersion: '1.0';
|
|
14
|
+
humanoid?: {
|
|
15
|
+
humanBones: Partial<Record<HumanoidBone, {
|
|
16
|
+
node: number;
|
|
17
|
+
}>>;
|
|
18
|
+
};
|
|
19
|
+
expressions?: {
|
|
20
|
+
preset?: Record<string, {
|
|
21
|
+
node: number;
|
|
22
|
+
}>;
|
|
23
|
+
custom?: Record<string, {
|
|
24
|
+
node: number;
|
|
25
|
+
}>;
|
|
26
|
+
};
|
|
27
|
+
lookAt?: {
|
|
28
|
+
node?: number;
|
|
29
|
+
offsetFromHeadBone?: readonly number[];
|
|
30
|
+
};
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
}
|
|
33
|
+
/** One checked glTF animation channel, using seconds and quaternion XYZW. */
|
|
34
|
+
export interface VRMATrack {
|
|
35
|
+
readonly node: number;
|
|
36
|
+
readonly path: 'rotation' | 'translation';
|
|
37
|
+
readonly times: Float32Array;
|
|
38
|
+
readonly values: Float32Array;
|
|
39
|
+
readonly interpolation: Interpolation;
|
|
40
|
+
}
|
|
41
|
+
/** A file may carry several clips; playback defaults to the first. */
|
|
42
|
+
export interface VRMAClip {
|
|
43
|
+
readonly name: string;
|
|
44
|
+
readonly duration: number;
|
|
45
|
+
readonly tracks: readonly VRMATrack[];
|
|
46
|
+
}
|
|
47
|
+
/** Decoded VRMA data, independent of a renderer or avatar. */
|
|
48
|
+
export interface VRMA {
|
|
49
|
+
readonly document: GLTFDocument;
|
|
50
|
+
readonly extension: VRMAExtension;
|
|
51
|
+
readonly rig: RetargetRig;
|
|
52
|
+
readonly clips: readonly VRMAClip[];
|
|
53
|
+
}
|
|
54
|
+
/** Loading limits and cancellation. Defaults: 64 MiB total and global fetch. */
|
|
55
|
+
export interface VRMALoadOptions {
|
|
56
|
+
signal?: AbortSignal;
|
|
57
|
+
maxDownloadBytes?: number;
|
|
58
|
+
fetch?: typeof globalThis.fetch;
|
|
59
|
+
/** External buffers for a parsed document or bytes, indexed as in glTF. */
|
|
60
|
+
buffers?: Array<ArrayBuffer | ArrayBufferView>;
|
|
61
|
+
}
|
|
62
|
+
/** Parse bytes or glTF JSON and supplied buffers. Sparse/interleaved accessors use the checked glTF asset reader. */
|
|
63
|
+
export declare function readVRMA(source: Uint8Array | GLTFDocument, options?: VRMALoadOptions): Promise<VRMA>;
|
|
64
|
+
/** Fetch a .vrma/JSON glTF and its external buffers, with a single total byte budget and AbortSignal. */
|
|
65
|
+
export declare function loadVRMA(url: string | URL, options?: VRMALoadOptions): Promise<VRMA>;
|
|
66
|
+
/** Explicit playback controls. Defaults: clip 0, looping, speed 1, automatic scene updates. */
|
|
67
|
+
export interface VRMAPlayerOptions {
|
|
68
|
+
clip?: string | number;
|
|
69
|
+
loop?: boolean;
|
|
70
|
+
speed?: number;
|
|
71
|
+
hipScale?: number;
|
|
72
|
+
vrm?: VRMHandle;
|
|
73
|
+
autoUpdate?: boolean;
|
|
74
|
+
}
|
|
75
|
+
/** A bound humanoid animation player. Dispose restores the transforms and expression values it owns. */
|
|
76
|
+
export interface VRMAPlayer {
|
|
77
|
+
readonly clip: VRMAClip;
|
|
78
|
+
readonly time: number;
|
|
79
|
+
playing: boolean;
|
|
80
|
+
speed: number;
|
|
81
|
+
loop: boolean;
|
|
82
|
+
seek(time: number): void;
|
|
83
|
+
update(delta: number): void;
|
|
84
|
+
dispose(): void;
|
|
85
|
+
[Symbol.dispose](): void;
|
|
86
|
+
}
|
|
87
|
+
/** Convert a glTF XYZW gaze quaternion to extrinsic ZXY yaw and pitch, in VRM degrees. */
|
|
88
|
+
export declare function vrmaGaze(q: ArrayLike<number>): VRMGaze;
|
|
89
|
+
/** Bind VRMA to a VRM model. Full rest world frames absorb arbitrary axes and missing optional bones. */
|
|
90
|
+
export declare function playVRMA(data: VRMA, animation: Animation, avatar: VRMAvatar, options?: VRMAPlayerOptions): Promise<VRMAPlayer>;
|