@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/vrma.js
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
// @margo/core-built 0.1.0
|
|
2
|
+
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
|
+
|
|
4
|
+
import { HUMANOID_BONES as e } from "./retarget.js";
|
|
5
|
+
import { i as t, n, o as r, r as i, s as a, t as o } from "./vrm-presets-CU4V4yq6.js";
|
|
6
|
+
import { t as s } from "./loading-CZaYr1N7.js";
|
|
7
|
+
import { MargoError as c } from "@margoengine/math/errors";
|
|
8
|
+
import { splitTRS as l } from "@margoengine/math/quat";
|
|
9
|
+
import { sampleTrack as u } from "@margoengine/animation/sampling";
|
|
10
|
+
//#region ../shared/asset-url.js
|
|
11
|
+
var d = /%2f|%5c|%00|\u0000|(^|\/)(\.|%2e){1,2}(\/|$)/i;
|
|
12
|
+
function f(e) {
|
|
13
|
+
for (let t = 0; t < 8; t++) {
|
|
14
|
+
if (d.test(e)) return !0;
|
|
15
|
+
let t = e.replace(/%[\da-f]{2}/gi, (e) => String.fromCharCode(`0x${e.slice(1)}`));
|
|
16
|
+
if (t === e) return !1;
|
|
17
|
+
e = t;
|
|
18
|
+
}
|
|
19
|
+
return !0;
|
|
20
|
+
}
|
|
21
|
+
function p(e, t) {
|
|
22
|
+
let n;
|
|
23
|
+
try {
|
|
24
|
+
n = new URL(t);
|
|
25
|
+
} catch {
|
|
26
|
+
throw TypeError(`allowedURLs entry ${String(t)} is not an absolute URL; pass a full http(s) URL`);
|
|
27
|
+
}
|
|
28
|
+
if (n.origin !== e.origin || n.protocol !== "http:" && n.protocol !== "https:" || n.search && n.search !== e.search) return !1;
|
|
29
|
+
let r = n.pathname;
|
|
30
|
+
return r.endsWith("/") ? e.pathname.startsWith(r) : e.pathname === r || e.pathname.startsWith(`${r}/`);
|
|
31
|
+
}
|
|
32
|
+
function m(e, t, n = [], r = "Asset") {
|
|
33
|
+
if (typeof e != "string" || !e || e.length > 8192) throw TypeError(`Invalid ${r} URI; pass a shorter string`);
|
|
34
|
+
let i;
|
|
35
|
+
try {
|
|
36
|
+
i = new URL(e, t);
|
|
37
|
+
} catch {
|
|
38
|
+
throw TypeError(`Invalid ${r} URI; pass a valid URL`);
|
|
39
|
+
}
|
|
40
|
+
if ((i.protocol === "http:" || i.protocol === "https:") && !f(i.pathname)) {
|
|
41
|
+
for (let e of n) if (p(i, e)) return i;
|
|
42
|
+
let e = t === void 0 ? void 0 : new URL(".", t);
|
|
43
|
+
if (e && i.origin === e.origin && i.pathname.startsWith(e.pathname)) return i;
|
|
44
|
+
}
|
|
45
|
+
throw TypeError(`${r} URI ${i.href} leaves the model's directory; add its prefix to allowedURLs to load it`);
|
|
46
|
+
}
|
|
47
|
+
function h(e, t, n = [], r = "Asset") {
|
|
48
|
+
if (!e.url) return e;
|
|
49
|
+
try {
|
|
50
|
+
m(e.url, t, n, r);
|
|
51
|
+
} catch {
|
|
52
|
+
throw e.body?.cancel().catch(() => {}), TypeError(`${r} URI redirected to ${e.url}, which leaves the model's directory; add its prefix to allowedURLs to load it`);
|
|
53
|
+
}
|
|
54
|
+
return e;
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/vrma.ts
|
|
58
|
+
var g = (e) => {
|
|
59
|
+
throw RangeError(`Invalid VRMA: ${e}; check the file against VRMC_vrm_animation 1.0`);
|
|
60
|
+
}, _ = (e) => !!e && typeof e == "object" && !Array.isArray(e), v = (e, t) => Number.isInteger(e) && e >= 0 && e < t;
|
|
61
|
+
function y(t, n) {
|
|
62
|
+
(!Array.isArray(t.nodes ?? []) || (t.nodes?.length ?? 0) > 1e5) && g("nodes must be an array with at most 100000 entries");
|
|
63
|
+
let r = t.nodes ?? [], i = r.map(() => -1), a = r.map((e, t) => `#${t}`), o = new Float64Array(r.length * 10);
|
|
64
|
+
for (let [t, i] of Object.entries(n)) (!e.includes(t) || !v(i?.node, r.length) || !a[i.node].startsWith("#")) && g(`invalid or repeated bone ${t}`), a[i.node] = t;
|
|
65
|
+
r.forEach((e, t) => {
|
|
66
|
+
_(e) || g(`node ${t}`);
|
|
67
|
+
for (let [n, r] of [
|
|
68
|
+
["translation", 3],
|
|
69
|
+
["rotation", 4],
|
|
70
|
+
["scale", 3],
|
|
71
|
+
["matrix", 16]
|
|
72
|
+
]) {
|
|
73
|
+
let i = e[n];
|
|
74
|
+
i !== void 0 && (!Array.isArray(i) || i.length !== r || !i.every(Number.isFinite)) && g(`node ${t} ${n}`);
|
|
75
|
+
}
|
|
76
|
+
e.rotation && Math.abs(Math.hypot(...e.rotation) - 1) > 1e-5 && g(`node ${t} rotation must be normalized`), e.scale?.some((e) => e <= 0) && g(`node ${t} scale must be positive`);
|
|
77
|
+
let n = e.matrix ? l(e.matrix) : null;
|
|
78
|
+
n && !n.ok && g(`node ${t} matrix is ${n.reason}`), o.set(n?.ok ? n.position : e.translation ?? [
|
|
79
|
+
0,
|
|
80
|
+
0,
|
|
81
|
+
0
|
|
82
|
+
], t * 10), o.set(n?.ok ? n.rotation : e.rotation ?? [
|
|
83
|
+
0,
|
|
84
|
+
0,
|
|
85
|
+
0,
|
|
86
|
+
1
|
|
87
|
+
], t * 10 + 3), o.set(n?.ok ? n.scale : e.scale ?? [
|
|
88
|
+
1,
|
|
89
|
+
1,
|
|
90
|
+
1
|
|
91
|
+
], t * 10 + 7), e.children !== void 0 && !Array.isArray(e.children) && g(`node ${t} children`);
|
|
92
|
+
for (let n of e.children ?? []) (!v(n, r.length) || i[n] !== -1) && g(`node ${t} child or multiple parent`), i[n] = t;
|
|
93
|
+
});
|
|
94
|
+
let s = new Uint8Array(r.length);
|
|
95
|
+
for (let e = 0; e < r.length; e++) {
|
|
96
|
+
let t = e;
|
|
97
|
+
for (; t >= 0 && s[t] === 0;) s[t] = 1, t = i[t];
|
|
98
|
+
for (t >= 0 && s[t] === 1 && g("cyclic node hierarchy"), t = e; t >= 0 && s[t] === 1;) s[t] = 2, t = i[t];
|
|
99
|
+
}
|
|
100
|
+
return o.every(Number.isFinite) || g("nonfinite rest transform"), {
|
|
101
|
+
names: a,
|
|
102
|
+
parents: i,
|
|
103
|
+
rest: o
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
async function b(e, s = {}) {
|
|
107
|
+
s.signal?.throwIfAborted();
|
|
108
|
+
let c = s.maxDownloadBytes ?? 67108864;
|
|
109
|
+
(!Number.isSafeInteger(c) || c <= 0) && g("maxDownloadBytes must be a positive integer");
|
|
110
|
+
let l, d;
|
|
111
|
+
if (e instanceof Uint8Array) {
|
|
112
|
+
if (e.byteLength > c && g("download exceeds maxDownloadBytes"), a(e)) {
|
|
113
|
+
let a = r(e);
|
|
114
|
+
l = n(new TextDecoder().decode(a.find((e) => e.type === t).data)), d = a.find((e) => e.type === i)?.data;
|
|
115
|
+
} else l = n(new TextDecoder().decode(e));
|
|
116
|
+
} else l = structuredClone(e);
|
|
117
|
+
let f = l?.extensions?.VRMC_vrm_animation;
|
|
118
|
+
(!_(f) || f.specVersion !== "1.0") && g("VRMC_vrm_animation specVersion must be 1.0");
|
|
119
|
+
let p = f.humanoid?.humanBones ?? {};
|
|
120
|
+
_(p) || g("humanoid humanBones must be an object"), (p.leftEye || p.rightEye) && g("eye bones must use lookAt");
|
|
121
|
+
let m = y(l, p), h = /* @__PURE__ */ new Map();
|
|
122
|
+
for (let [e, t] of Object.entries(p)) h.set(t.node, e);
|
|
123
|
+
for (let e of [f.expressions?.preset, f.expressions?.custom]) {
|
|
124
|
+
e !== void 0 && !_(e) && g("expressions must be objects");
|
|
125
|
+
for (let [t, n] of Object.entries(e ?? {})) (!v(n?.node, m.names.length) || h.has(n.node) || [
|
|
126
|
+
"lookUp",
|
|
127
|
+
"lookDown",
|
|
128
|
+
"lookLeft",
|
|
129
|
+
"lookRight"
|
|
130
|
+
].includes(t)) && g(`expression ${t}`), e === f.expressions?.custom && o.has(t) && g(`custom expression ${t} has a preset expression's name`), h.set(n.node, `expression:${t}`);
|
|
131
|
+
}
|
|
132
|
+
let b = f.lookAt?.node;
|
|
133
|
+
b !== void 0 && ((!v(b, m.names.length) || h.has(b)) && g("lookAt node"), h.set(b, "lookAt"));
|
|
134
|
+
let { GLTFAsset: x } = await import("@margoengine/gltf/asset");
|
|
135
|
+
s.signal?.throwIfAborted();
|
|
136
|
+
let S = new x({
|
|
137
|
+
...l,
|
|
138
|
+
extensionsRequired: l.extensionsRequired?.filter((e) => e !== "VRMC_vrm_animation")
|
|
139
|
+
}, s.buffers ?? [], d, {}, c), C = (l.animations ?? []).map((e, t) => {
|
|
140
|
+
let n = /* @__PURE__ */ new Set(), r = [];
|
|
141
|
+
for (let t of e.channels) {
|
|
142
|
+
let i = t.target?.node, a = h.get(i), o = t.target?.path;
|
|
143
|
+
if (v(i, m.names.length) || g("animation target node"), !a || a === "lookAt" && o !== "rotation" || a.startsWith("expression:") && o !== "translation" || (a !== "lookAt" && !a.startsWith("expression:") && (o === "scale" || o === "translation" && a !== "hips") && g(`forbidden ${o} track on ${a}`), o !== "rotation" && o !== "translation")) continue;
|
|
144
|
+
n.has(`${i}:${o}`) && g("duplicate animation channel"), n.add(`${i}:${o}`);
|
|
145
|
+
let s = e.samplers[t.sampler];
|
|
146
|
+
s || g("animation sampler");
|
|
147
|
+
let c = s.interpolation ?? "LINEAR", d = o === "rotation" ? 4 : 3, f = S.accessor(s.input, "SCALAR"), p = S.accessor(s.output, d === 4 ? "VEC4" : "VEC3");
|
|
148
|
+
(!f.length || f.some((e, t) => !Number.isFinite(e) || e < 0 || t > 0 && e <= f[t - 1]) || !p.every(Number.isFinite)) && g("animation times or values");
|
|
149
|
+
let _ = l.accessors[s.output], y = d === 4 && _.normalized === !0 ? {
|
|
150
|
+
5120: 127,
|
|
151
|
+
5121: 255,
|
|
152
|
+
5122: 32767,
|
|
153
|
+
5123: 65535
|
|
154
|
+
}[_.componentType] : void 0;
|
|
155
|
+
if ((l.accessors[s.input].componentType !== 5126 || _.componentType !== 5126 && !y) && g("animation accessors must be FLOAT, or normalized bytes or shorts for rotations"), d === 4) {
|
|
156
|
+
let e = c === "CUBICSPLINE" ? 12 : 4, t = c === "CUBICSPLINE" ? 4 : 0, n = y ? 1 / y : 1e-5;
|
|
157
|
+
for (let r = t; r < p.length; r += e) {
|
|
158
|
+
let e = Math.hypot(...p.subarray(r, r + 4));
|
|
159
|
+
if (Math.abs(e - 1) > n && g("rotation keys must be normalized"), y) for (let t = 0; t < 4; t++) p[r + t] /= e;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
u(f, p, d, 0, c, d === 4), r.push({
|
|
163
|
+
node: i,
|
|
164
|
+
path: o,
|
|
165
|
+
times: f.slice(),
|
|
166
|
+
values: p.slice(),
|
|
167
|
+
interpolation: c
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
name: e.name ?? `animation_${t}`,
|
|
172
|
+
duration: r.reduce((e, t) => Math.max(e, t.times[t.times.length - 1]), 0),
|
|
173
|
+
tracks: r
|
|
174
|
+
};
|
|
175
|
+
});
|
|
176
|
+
return C.length || g("file has no animations"), {
|
|
177
|
+
document: l,
|
|
178
|
+
extension: f,
|
|
179
|
+
rig: m,
|
|
180
|
+
clips: C
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
async function x(e, i = {}) {
|
|
184
|
+
let o = new URL(String(e), typeof location > "u" ? void 0 : location.href), l = m(o.href, o), u = i.maxDownloadBytes ?? 67108864;
|
|
185
|
+
(!Number.isSafeInteger(u) || u <= 0) && g("maxDownloadBytes must be a positive integer");
|
|
186
|
+
let d = 0, f = async (e) => {
|
|
187
|
+
i.signal?.throwIfAborted();
|
|
188
|
+
let t = h(await (i.fetch ?? fetch)(e, { signal: i.signal }), l);
|
|
189
|
+
if (!t.ok) throw new c("failed", `VRMA download failed: HTTP ${t.status}; check the URL and server access`);
|
|
190
|
+
let n = await s(t, {
|
|
191
|
+
maxBytes: u - d,
|
|
192
|
+
signal: i.signal,
|
|
193
|
+
label: "VRMA"
|
|
194
|
+
});
|
|
195
|
+
return d += n.byteLength, n;
|
|
196
|
+
}, p = await f(l), v = a(p) ? r(p) : null, y = n(new TextDecoder().decode(v ? v.find((e) => e.type === t).data : p));
|
|
197
|
+
(!_(y) || !Array.isArray(y.buffers ?? [])) && g("document or buffers");
|
|
198
|
+
let x = [...i.buffers ?? []];
|
|
199
|
+
for (let e = 0; e < (y.buffers?.length ?? 0); e++) {
|
|
200
|
+
let t = y.buffers[e].uri;
|
|
201
|
+
t && !t.startsWith("data:") && !x[e] && (x[e] = await f(m(t, l)));
|
|
202
|
+
}
|
|
203
|
+
return b(p, {
|
|
204
|
+
...i,
|
|
205
|
+
buffers: x
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
function S(e) {
|
|
209
|
+
let [t, n, r, i] = Array.from(e), a = Math.hypot(t, n, r, i);
|
|
210
|
+
(!(a > 0) || !Number.isFinite(a)) && g("gaze quaternion");
|
|
211
|
+
let o = t / a, s = n / a, c = r / a, l = i / a;
|
|
212
|
+
return {
|
|
213
|
+
yaw: Math.atan2(2 * (o * c + s * l), 1 - 2 * (o * o + s * s)) * 180 / Math.PI,
|
|
214
|
+
pitch: Math.asin(Math.max(-1, Math.min(1, 2 * (o * l - s * c)))) * 180 / Math.PI
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
async function C(e, t, n, r = {}) {
|
|
218
|
+
let { Retarget: i } = await import("@margoengine/animation/skeleton-utils"), a = t.model, o = y(a.asset.doc, n.humanoid.humanBones), s = typeof r.clip == "string" ? e.clips.findIndex((e) => e.name === r.clip) : r.clip ?? 0, l = e.clips[s];
|
|
219
|
+
l || g("unknown clip");
|
|
220
|
+
let d = {
|
|
221
|
+
...e.rig,
|
|
222
|
+
names: e.rig.names.map((e) => e.startsWith("#") ? `source${e}` : e)
|
|
223
|
+
}, f = Object.keys(n.humanoid.humanBones).filter((e) => d.names.includes(e)), p = f.length ? new i(d, o, { ...f.includes("hips") ? {
|
|
224
|
+
hip: "hips",
|
|
225
|
+
hipScale: r.hipScale
|
|
226
|
+
} : {} }) : null, m = d.rest.slice(), h = o.rest.slice(), _ = [/* @__PURE__ */ new Float32Array(3), /* @__PURE__ */ new Float32Array(4)], v = f.map((e) => {
|
|
227
|
+
let t = n.humanoid.humanBones[e].node, r = a.nodes[t].id, i = a.root.engine.store.transforms;
|
|
228
|
+
return {
|
|
229
|
+
node: t,
|
|
230
|
+
q: [
|
|
231
|
+
i.qx[r],
|
|
232
|
+
i.qy[r],
|
|
233
|
+
i.qz[r],
|
|
234
|
+
i.qw[r]
|
|
235
|
+
],
|
|
236
|
+
p: [
|
|
237
|
+
i.x[r],
|
|
238
|
+
i.y[r],
|
|
239
|
+
i.z[r]
|
|
240
|
+
]
|
|
241
|
+
};
|
|
242
|
+
}), b = /* @__PURE__ */ new Map();
|
|
243
|
+
for (let t of [e.extension.expressions?.preset, e.extension.expressions?.custom]) for (let [e, n] of Object.entries(t ?? {})) r.vrm?.expressions.names.includes(e) && b.set(n.node, e);
|
|
244
|
+
let x = new Map([...b.values()].map((e) => [e, r.vrm.expressions.get(e)])), C = r.vrm?.lookAtGaze ?? null, w = 0, T = !1, E = r.speed ?? 1, D = r.loop ?? !0, O = !0, k = (e) => (Number.isFinite(e) || g("speed must be finite"), e);
|
|
245
|
+
k(E);
|
|
246
|
+
let A = (t) => {
|
|
247
|
+
if (T) throw new c("disposed", "VRMA player is disposed; create a new player");
|
|
248
|
+
(!Number.isFinite(t) || t < 0) && g("time must be finite and nonnegative"), w = Math.min(l.duration, t), m.set(d.rest);
|
|
249
|
+
for (let t of l.tracks) {
|
|
250
|
+
let n = u(t.times, t.values, t.path === "rotation" ? 4 : 3, w, t.interpolation, t.path === "rotation", _[+(t.path === "rotation")]);
|
|
251
|
+
b.has(t.node) ? r.vrm.expressions.set(b.get(t.node), Math.max(0, Math.min(1, n[0]))) : t.node === e.extension.lookAt?.node ? r.vrm && (r.vrm.lookAtGaze = S(n)) : m.set(n, t.node * 10 + (t.path === "rotation" ? 3 : 0));
|
|
252
|
+
}
|
|
253
|
+
p?.pose(m, h);
|
|
254
|
+
for (let { node: e } of v) a.nodes[e].setQuaternion(Array.from(h.subarray(e * 10 + 3, e * 10 + 7))), o.names[e] === "hips" && p?.hip === e && a.nodes[e].setPosition(Array.from(h.subarray(e * 10, e * 10 + 3)));
|
|
255
|
+
}, j = (e) => {
|
|
256
|
+
if ((!Number.isFinite(e) || e < 0) && g("delta must be finite and nonnegative"), T || !O) return;
|
|
257
|
+
let t = w + e * E;
|
|
258
|
+
D && l.duration > 0 ? t = (t % l.duration + l.duration) % l.duration : (t >= l.duration || t < 0) && (t = Math.max(0, Math.min(l.duration, t)), O = !1), A(t);
|
|
259
|
+
}, M = a.root.scene, N = `vrma:${a.root.id}`, P, F, I = () => {
|
|
260
|
+
if (!T) {
|
|
261
|
+
T = !0, O = !1, P?.(), F?.();
|
|
262
|
+
for (let { node: e, q: t, p: n } of v) a.nodes[e].setQuaternion(t), o.names[e] === "hips" && a.nodes[e].setPosition(n);
|
|
263
|
+
for (let [e, t] of x) r.vrm.expressions.set(e, t);
|
|
264
|
+
r.vrm && (r.vrm.lookAtGaze = C);
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
if (r.autoUpdate !== !1) {
|
|
268
|
+
if (r.vrm) P = r.vrm.addPoseSource(j);
|
|
269
|
+
else {
|
|
270
|
+
let e = {coreRequirement:/*@__PURE__*/__margoCoreRequirement("0.1.0",import.meta.url),
|
|
271
|
+
name: N,
|
|
272
|
+
setup() {},
|
|
273
|
+
onPreUpdate: j,
|
|
274
|
+
dispose: () => {
|
|
275
|
+
P = void 0, I();
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
M.use(e), P = () => {
|
|
279
|
+
M.plugins.get(N) === e && M.removePlugin(N);
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return F = a.onDispose(() => {
|
|
284
|
+
T || (T = !0, O = !1, P?.());
|
|
285
|
+
}), A(0), {
|
|
286
|
+
clip: l,
|
|
287
|
+
get time() {
|
|
288
|
+
return w;
|
|
289
|
+
},
|
|
290
|
+
get playing() {
|
|
291
|
+
return O;
|
|
292
|
+
},
|
|
293
|
+
set playing(e) {
|
|
294
|
+
O = e;
|
|
295
|
+
},
|
|
296
|
+
get speed() {
|
|
297
|
+
return E;
|
|
298
|
+
},
|
|
299
|
+
set speed(e) {
|
|
300
|
+
E = k(e);
|
|
301
|
+
},
|
|
302
|
+
get loop() {
|
|
303
|
+
return D;
|
|
304
|
+
},
|
|
305
|
+
set loop(e) {
|
|
306
|
+
D = e;
|
|
307
|
+
},
|
|
308
|
+
seek: A,
|
|
309
|
+
update: j,
|
|
310
|
+
dispose: I,
|
|
311
|
+
[Symbol.dispose]: I
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
//#endregion
|
|
315
|
+
export { x as loadVRMA, C as playVRMA, b as readVRMA, S as vrmaGaze };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
//#region src/weight-map.ts
|
|
2
|
+
var e = class e {
|
|
3
|
+
constructor(e, t, n) {
|
|
4
|
+
if (this.vertexCount = e, this.boneCount = t, !Number.isSafeInteger(e) || e < 1) throw RangeError(`WeightMap vertexCount ${e} must be a positive integer`);
|
|
5
|
+
if (!Number.isSafeInteger(t) || t < 1 || t > 65536) throw RangeError(`WeightMap boneCount ${t} must be an integer from 1 to 65,536`);
|
|
6
|
+
if (e * t > 268435456) throw RangeError("WeightMap vertices times bones exceed 2^28; weight the mesh in parts");
|
|
7
|
+
if (this.values = new Float32Array(e * t), n !== void 0) {
|
|
8
|
+
if (n?.length !== this.values.length) throw RangeError(`WeightMap values need ${this.values.length} numbers (vertices times bones)`);
|
|
9
|
+
this.values.set(n);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
get(e, t) {
|
|
13
|
+
return this.values[this.index(e, t)];
|
|
14
|
+
}
|
|
15
|
+
set(e, t, n) {
|
|
16
|
+
if (!(n >= 0 && n < Infinity)) throw RangeError(`Weight ${n} must be finite and 0 or more`);
|
|
17
|
+
return this.values[this.index(e, t)] = n, this;
|
|
18
|
+
}
|
|
19
|
+
index(e, t) {
|
|
20
|
+
if (!Number.isInteger(e) || e < 0 || e >= this.vertexCount) throw RangeError(`Vertex ${e} is outside the ${this.vertexCount} vertices; pass 0 to ${this.vertexCount - 1}`);
|
|
21
|
+
if (!Number.isInteger(t) || t < 0 || t >= this.boneCount) throw RangeError(`Bone ${t} is outside the ${this.boneCount} bones; pass 0 to ${this.boneCount - 1}`);
|
|
22
|
+
return e * this.boneCount + t;
|
|
23
|
+
}
|
|
24
|
+
normalize({ locked: e } = {}) {
|
|
25
|
+
let r = this.boneCount, i = this.values, a = t(r, e);
|
|
26
|
+
for (let e = 0; e < i.length; e += r) n(i, e, r, a);
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
clone() {
|
|
30
|
+
return new e(this.vertexCount, this.boneCount, this.values);
|
|
31
|
+
}
|
|
32
|
+
toInfluences(e = 4) {
|
|
33
|
+
if (!Number.isInteger(e) || e < 1 || e > 16) throw RangeError("Influences per vertex must be 1 to 16");
|
|
34
|
+
let t = this.vertexCount, n = this.boneCount, r = this.values, i = new Uint16Array(t * e), a = new Float32Array(t * e), o = new Int32Array(e);
|
|
35
|
+
for (let s = 0; s < t; s++) {
|
|
36
|
+
let t = s * n, c = 0;
|
|
37
|
+
for (let i = 0; i < n; i++) {
|
|
38
|
+
let n = r[t + i];
|
|
39
|
+
if (!Number.isFinite(n)) throw RangeError(`Vertex ${s} bone ${i} weight ${n} is not finite; call normalize() or set a finite weight`);
|
|
40
|
+
if (!(n > 0)) continue;
|
|
41
|
+
let a = c < e ? c++ : e;
|
|
42
|
+
for (; a > 0 && r[t + o[a - 1]] < n;) a < e && (o[a] = o[a - 1]), a--;
|
|
43
|
+
a < e && (o[a] = i);
|
|
44
|
+
}
|
|
45
|
+
let l = 0;
|
|
46
|
+
for (let e = 0; e < c; e++) l += r[t + o[e]];
|
|
47
|
+
for (let n = 0; n < c; n++) i[s * e + n] = o[n], a[s * e + n] = r[t + o[n]] / l;
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
joints: i,
|
|
51
|
+
weights: a,
|
|
52
|
+
influences: e
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
static fromInfluences(t, n) {
|
|
56
|
+
let { joints: r, weights: i } = t ?? {}, a = t?.influences ?? 4;
|
|
57
|
+
if (!Number.isInteger(a) || a < 1 || r?.length !== i?.length || r.length % a) throw TypeError(`Influences need equal-length joints and weights, ${a} per vertex`);
|
|
58
|
+
let o = 0;
|
|
59
|
+
for (let e = 0; e < r.length; e++) r[e] > o && (o = r[e]);
|
|
60
|
+
let s = n ?? o + 1;
|
|
61
|
+
if (o >= s) throw RangeError(`Joint ${o} is outside the ${s} bones; pass boneCount`);
|
|
62
|
+
let c = new e(r.length / a, s);
|
|
63
|
+
for (let e = 0; e < r.length; e++) {
|
|
64
|
+
let t = i[e];
|
|
65
|
+
if (!(t >= 0 && t < Infinity)) throw RangeError(`Weight ${e} (${t}) must be finite and 0 or more`);
|
|
66
|
+
c.values[Math.floor(e / a) * s + r[e]] += t;
|
|
67
|
+
}
|
|
68
|
+
return c;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
function t(e, t) {
|
|
72
|
+
let n = new Uint8Array(e);
|
|
73
|
+
if (t === void 0) return n;
|
|
74
|
+
if (!Array.isArray(t)) throw TypeError("locked must be an array of bone indices");
|
|
75
|
+
for (let r of t) {
|
|
76
|
+
if (!Number.isInteger(r) || r < 0 || r >= e) throw RangeError(`Locked bone ${r} is outside the ${e} bones; pass 0 to ${e - 1}`);
|
|
77
|
+
n[r] = 1;
|
|
78
|
+
}
|
|
79
|
+
return n;
|
|
80
|
+
}
|
|
81
|
+
function n(e, t, n, r) {
|
|
82
|
+
let i = 0, a = 0;
|
|
83
|
+
for (let o = 0; o < n; o++) {
|
|
84
|
+
let n = e[t + o];
|
|
85
|
+
n > 0 && n < Infinity || (n = e[t + o] = 0), r[o] ? i += n : a += n;
|
|
86
|
+
}
|
|
87
|
+
if (!(a > 0)) return;
|
|
88
|
+
let o = Math.max(0, 1 - i) / a;
|
|
89
|
+
for (let i = 0; i < n; i++) r[i] || (e[t + i] *= o);
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
92
|
+
export { t as n, n as r, e as t };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-vertex joint indices and weights, `influences` of each per vertex: glTF's JOINTS_0 / WEIGHTS_0 at 4 (the shape of
|
|
3
|
+
* `@margoengine/exporters/skin`'s `SkinWeights` and `Skin.attach`'s arguments). Unused slots hold joint 0, weight 0.
|
|
4
|
+
*/
|
|
5
|
+
export interface VertexInfluences {
|
|
6
|
+
readonly joints: Uint16Array;
|
|
7
|
+
readonly weights: Float32Array;
|
|
8
|
+
/** Slots per vertex (default 4). */
|
|
9
|
+
readonly influences?: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Skin weights for every vertex and bone, row-major (`values[vertex * boneCount + bone]`). Solvers return one and the
|
|
13
|
+
* painter edits one; {@link WeightMap.toInfluences} gives the export form.
|
|
14
|
+
*/
|
|
15
|
+
export declare class WeightMap {
|
|
16
|
+
readonly vertexCount: number;
|
|
17
|
+
readonly boneCount: number;
|
|
18
|
+
/** `vertexCount * boneCount` weights, one row per vertex. */
|
|
19
|
+
readonly values: Float32Array;
|
|
20
|
+
/**
|
|
21
|
+
* @param vertexCount Vertices (rows), at least 1.
|
|
22
|
+
* @param boneCount Bones (columns), 1-65,536.
|
|
23
|
+
* @param values Optional initial weights (copied), `vertexCount * boneCount` of them; default all zero.
|
|
24
|
+
* @throws RangeError for counts out of range or a wrong-length `values`.
|
|
25
|
+
*/
|
|
26
|
+
constructor(vertexCount: number, boneCount: number, values?: ArrayLike<number>);
|
|
27
|
+
/** Weight of `bone` on `vertex`. */
|
|
28
|
+
get(vertex: number, bone: number): number;
|
|
29
|
+
/** Sets one weight (finite, 0 or more); call {@link normalize} after a batch of edits. */
|
|
30
|
+
set(vertex: number, bone: number, weight: number): this;
|
|
31
|
+
private index;
|
|
32
|
+
/**
|
|
33
|
+
* Scales each vertex's weights to sum to 1. Weights of `locked` bones are kept; the others share what remains (none
|
|
34
|
+
* when the locked ones already reach 1). A vertex with no unlocked weight to scale is left as it is; find those
|
|
35
|
+
* with `checkSkin`. Negative and non-finite weights become 0 first.
|
|
36
|
+
*/
|
|
37
|
+
normalize({ locked }?: {
|
|
38
|
+
locked?: readonly number[];
|
|
39
|
+
}): this;
|
|
40
|
+
/** A copy. */
|
|
41
|
+
clone(): WeightMap;
|
|
42
|
+
/**
|
|
43
|
+
* The strongest `max` weights per vertex (default 4, glTF's JOINTS_0 / WEIGHTS_0), renormalised to sum to 1, sorted
|
|
44
|
+
* strongest first; unused slots are joint 0 with weight 0. Ties keep the lower bone index. Negative weights count
|
|
45
|
+
* as 0, as in {@link normalize}.
|
|
46
|
+
* @throws RangeError for a NaN or infinite weight (glTF holds finite weights only): call normalize() or fix it.
|
|
47
|
+
*/
|
|
48
|
+
toInfluences(max?: number): VertexInfluences;
|
|
49
|
+
/**
|
|
50
|
+
* A map from per-vertex influences (glTF JOINTS_0 / WEIGHTS_0, or wider): weights listed twice for one joint add up.
|
|
51
|
+
* @param boneCount Bones in the skin; default one more than the largest joint index.
|
|
52
|
+
*/
|
|
53
|
+
static fromInfluences(influences: VertexInfluences, boneCount?: number): WeightMap;
|
|
54
|
+
}
|
|
55
|
+
/** Uint8 lock flags per bone. @throws RangeError for an out-of-range bone. */
|
|
56
|
+
export declare function lockMask(boneCount: number, locked: readonly number[] | undefined): Uint8Array;
|
|
57
|
+
/** Normalises one row in place (see WeightMap.normalize). */
|
|
58
|
+
export declare function normalizeRow(v: Float32Array, row: number, b: number, lock: Uint8Array): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,175 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@margoengine/rigging",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@margoengine/rigging",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Rigging and animation authoring: automatic skin weights, weight painting, skin checks, IK chains with poles, retarget presets, spring bones, VRM 1.0 avatars, geodesic voxel weights, corrective shapes, weight transfer, face tracking, automatic rigs from a bare mesh.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"margoengine",
|
|
7
|
+
"webgpu",
|
|
8
|
+
"3d",
|
|
9
|
+
"rigging",
|
|
10
|
+
"skinning",
|
|
11
|
+
"weights",
|
|
12
|
+
"vrm",
|
|
13
|
+
"voxel-weights",
|
|
14
|
+
"autorig",
|
|
15
|
+
"correctives",
|
|
16
|
+
"face-tracking"
|
|
17
|
+
],
|
|
18
|
+
"homepage": "https://margoengine.com",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/scottcampbelldata/margoengine/issues"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/scottcampbelldata/margoengine.git",
|
|
25
|
+
"directory": "packages/rigging"
|
|
26
|
+
},
|
|
27
|
+
"license": "Apache-2.0",
|
|
28
|
+
"author": "Scott Campbell",
|
|
29
|
+
"type": "module",
|
|
30
|
+
"sideEffects": false,
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./ik": {
|
|
37
|
+
"types": "./dist/ik.d.ts",
|
|
38
|
+
"import": "./dist/ik.js"
|
|
39
|
+
},
|
|
40
|
+
"./contact": {
|
|
41
|
+
"types": "./dist/contact.d.ts",
|
|
42
|
+
"import": "./dist/contact.js"
|
|
43
|
+
},
|
|
44
|
+
"./joint-limits": {
|
|
45
|
+
"types": "./dist/joint-limits.d.ts",
|
|
46
|
+
"import": "./dist/joint-limits.js"
|
|
47
|
+
},
|
|
48
|
+
"./swim": {
|
|
49
|
+
"types": "./dist/swim.d.ts",
|
|
50
|
+
"import": "./dist/swim.js"
|
|
51
|
+
},
|
|
52
|
+
"./retarget": {
|
|
53
|
+
"types": "./dist/retarget.d.ts",
|
|
54
|
+
"import": "./dist/retarget.js"
|
|
55
|
+
},
|
|
56
|
+
"./hulls": {
|
|
57
|
+
"types": "./dist/hulls.d.ts",
|
|
58
|
+
"import": "./dist/hulls.js"
|
|
59
|
+
},
|
|
60
|
+
"./springs": {
|
|
61
|
+
"types": "./dist/springs.d.ts",
|
|
62
|
+
"import": "./dist/springs.js"
|
|
63
|
+
},
|
|
64
|
+
"./vrm": {
|
|
65
|
+
"types": "./dist/vrm.d.ts",
|
|
66
|
+
"import": "./dist/vrm.js"
|
|
67
|
+
},
|
|
68
|
+
"./autorig": {
|
|
69
|
+
"types": "./dist/autorig.d.ts",
|
|
70
|
+
"import": "./dist/autorig.js"
|
|
71
|
+
},
|
|
72
|
+
"./voxel-weights": {
|
|
73
|
+
"types": "./dist/voxel-weights.d.ts",
|
|
74
|
+
"import": "./dist/voxel-weights.js"
|
|
75
|
+
},
|
|
76
|
+
"./correctives": {
|
|
77
|
+
"types": "./dist/correctives.d.ts",
|
|
78
|
+
"import": "./dist/correctives.js"
|
|
79
|
+
},
|
|
80
|
+
"./transfer": {
|
|
81
|
+
"types": "./dist/transfer.d.ts",
|
|
82
|
+
"import": "./dist/transfer.js"
|
|
83
|
+
},
|
|
84
|
+
"./face": {
|
|
85
|
+
"types": "./dist/face.d.ts",
|
|
86
|
+
"import": "./dist/face.js"
|
|
87
|
+
},
|
|
88
|
+
"./vrm0": {
|
|
89
|
+
"types": "./dist/vrm0.d.ts",
|
|
90
|
+
"import": "./dist/vrm0.js"
|
|
91
|
+
},
|
|
92
|
+
"./mtoon": {
|
|
93
|
+
"types": "./dist/mtoon.d.ts",
|
|
94
|
+
"import": "./dist/mtoon.js"
|
|
95
|
+
},
|
|
96
|
+
"./vrm-constraints": {
|
|
97
|
+
"types": "./dist/vrm-constraints.d.ts",
|
|
98
|
+
"import": "./dist/vrm-constraints.js"
|
|
99
|
+
},
|
|
100
|
+
"./vrma": {
|
|
101
|
+
"types": "./dist/vrma.d.ts",
|
|
102
|
+
"import": "./dist/vrma.js"
|
|
103
|
+
},
|
|
104
|
+
"./vrm-first-person": {
|
|
105
|
+
"types": "./dist/vrm-first-person.d.ts",
|
|
106
|
+
"import": "./dist/vrm-first-person.js"
|
|
107
|
+
},
|
|
108
|
+
"./pose-tracking": {
|
|
109
|
+
"types": "./dist/pose-tracking.d.ts",
|
|
110
|
+
"import": "./dist/pose-tracking.js"
|
|
111
|
+
},
|
|
112
|
+
"./hands": {
|
|
113
|
+
"types": "./dist/hands.d.ts",
|
|
114
|
+
"import": "./dist/hands.js"
|
|
115
|
+
},
|
|
116
|
+
"./strand-springs": {
|
|
117
|
+
"types": "./dist/strand-springs.d.ts",
|
|
118
|
+
"import": "./dist/strand-springs.js"
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
"files": [
|
|
122
|
+
"dist",
|
|
123
|
+
"LICENSE",
|
|
124
|
+
"NOTICE"
|
|
125
|
+
],
|
|
126
|
+
"publishConfig": {
|
|
127
|
+
"access": "public"
|
|
128
|
+
},
|
|
129
|
+
"dependencies": {
|
|
130
|
+
"@margoengine/bvh": "^0.1.0",
|
|
131
|
+
"@margoengine/geometry": "^0.1.0",
|
|
132
|
+
"@margoengine/math": "^0.1.0",
|
|
133
|
+
"@margoengine/physics": "^0.1.0"
|
|
134
|
+
},
|
|
135
|
+
"peerDependencies": {
|
|
136
|
+
"@margoengine/animator": "^0.1.0",
|
|
137
|
+
"@margoengine/core": "^0.1.0",
|
|
138
|
+
"@margoengine/kinematics-constraints": "^0.1.0",
|
|
139
|
+
"@margoengine/gltf": "^0.1.0",
|
|
140
|
+
"@margoengine/animation": "^0.1.0",
|
|
141
|
+
"@margoengine/decoders": "^0.1.0"
|
|
142
|
+
},
|
|
143
|
+
"peerDependenciesMeta": {
|
|
144
|
+
"@margoengine/animator": {
|
|
145
|
+
"optional": true
|
|
146
|
+
},
|
|
147
|
+
"@margoengine/core": {
|
|
148
|
+
"optional": true
|
|
149
|
+
},
|
|
150
|
+
"@margoengine/kinematics-constraints": {
|
|
151
|
+
"optional": true
|
|
152
|
+
},
|
|
153
|
+
"@margoengine/gltf": {
|
|
154
|
+
"optional": true
|
|
155
|
+
},
|
|
156
|
+
"@margoengine/animation": {
|
|
157
|
+
"optional": true
|
|
158
|
+
},
|
|
159
|
+
"@margoengine/decoders": {
|
|
160
|
+
"optional": true
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
"scripts": {
|
|
164
|
+
"build": "node ../../scripts/build-optional.js rigging",
|
|
165
|
+
"test": "npm run build && node --test tests/*.test.js",
|
|
166
|
+
"test:browser": "npm run build && node tests/rigging-browser.mjs",
|
|
167
|
+
"prepack": "npm run build",
|
|
168
|
+
"test:mtoon:browser": "cd ../.. && node packages/rigging/tests/mtoon-light.browser.mjs && node packages/rigging/tests/mtoon-replica.browser.mjs && node packages/rigging/tests/mtoon-matcap.browser.mjs && node packages/rigging/tests/mtoon-uv.browser.mjs && node packages/rigging/tests/mtoon-uv-animation.browser.mjs && node packages/rigging/tests/mtoon-uv-shadow.browser.mjs && node packages/rigging/tests/mtoon-expressions.browser.mjs && node packages/rigging/tests/mtoon-local-rim.browser.mjs && node packages/rigging/tests/mtoon-gbuffer.browser.mjs && node packages/rigging/tests/mtoon-outline.browser.mjs && node packages/rigging/tests/mtoon-avatar.browser.mjs && node packages/rigging/tests/mtoon-avatar.browser.mjs --vrm1",
|
|
169
|
+
"test:strand-springs:browser": "cd ../.. && node packages/rigging/tests/strand-springs.browser.mjs",
|
|
170
|
+
"test:constraints:browser": "node tests/vrm-constraints.browser.mjs",
|
|
171
|
+
"test:vrma:browser": "node tests/vrma.browser.mjs",
|
|
172
|
+
"test:pose-tracking:browser": "node tests/pose-tracking.browser.mjs",
|
|
173
|
+
"test:first-person:browser": "cd ../.. && node packages/rigging/tests/vrm-first-person.browser.mjs"
|
|
174
|
+
}
|
|
175
|
+
}
|