@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.
- package/LICENSE +201 -201
- package/NOTICE +4 -4
- package/README.md +1444 -969
- package/dist/anatomy-data-ansur2.d.ts +63 -0
- package/dist/anatomy-data-cdc.d.ts +16 -0
- package/dist/anatomy-data-deleva.d.ts +86 -0
- package/dist/anatomy-human.d.ts +67 -0
- package/dist/anatomy-human.js +2229 -0
- package/dist/anatomy.d.ts +638 -0
- package/dist/anatomy.js +1112 -0
- package/dist/autorig.js +137 -134
- package/dist/body-volumes-DTym0RVY.js +56 -0
- package/dist/body-volumes.d.ts +19 -0
- package/dist/contact.d.ts +12 -1
- package/dist/contact.js +197 -190
- package/dist/coupling.d.ts +57 -0
- package/dist/coupling.js +330 -0
- package/dist/face.js +2 -2
- package/dist/ik.d.ts +55 -2
- package/dist/ik.js +369 -166
- package/dist/mtoon.js +4 -4
- package/dist/pose-tracking.js +2 -2
- package/dist/retarget.d.ts +9 -2
- package/dist/retarget.js +53 -29
- package/dist/shared/gltf.d.ts +257 -257
- package/dist/shared/layers.d.ts +16 -16
- package/dist/validate.d.ts +188 -0
- package/dist/validate.js +440 -0
- package/dist/vrm-constraints.js +3 -3
- package/dist/vrm.d.ts +8 -3
- package/dist/vrm.js +2 -2
- package/dist/vrma.js +2 -2
- package/package.json +191 -175
package/dist/autorig.js
CHANGED
|
@@ -27,7 +27,7 @@ var u = .09, d = 14, f = .03, p = .423, m = .755, h = .5, g = .085, _ = .9994, v
|
|
|
27
27
|
0,
|
|
28
28
|
e[2]
|
|
29
29
|
]);
|
|
30
|
-
function
|
|
30
|
+
function O(e, t) {
|
|
31
31
|
let { nx: n, ny: r } = e, i = new Int32Array(t.length), a = [], s = 0, c = 0, l = 0;
|
|
32
32
|
for (let e = 0; e < t.length; e++) {
|
|
33
33
|
if (!t[e] || i[e]) continue;
|
|
@@ -45,7 +45,7 @@ function ee(e, t) {
|
|
|
45
45
|
for (let e = 0; e < t.length; e++) i[e] !== s && (t[e] = 0);
|
|
46
46
|
return c;
|
|
47
47
|
}
|
|
48
|
-
function
|
|
48
|
+
function ee(e, t) {
|
|
49
49
|
let { nx: n, ny: r, nz: i } = e, a = new Float32Array(t.length);
|
|
50
50
|
for (let e = 0; e < t.length; e++) a[e] = t[e] ? 1e9 : 0;
|
|
51
51
|
let s = (e) => {
|
|
@@ -63,7 +63,7 @@ function te(e, t) {
|
|
|
63
63
|
};
|
|
64
64
|
return s(!0), s(!1), a;
|
|
65
65
|
}
|
|
66
|
-
function
|
|
66
|
+
function k(e, t, n) {
|
|
67
67
|
let { grid: r, mask: a } = e, { nx: s, ny: c } = r, l = o.map(([e, t, n, r]) => [e + s * (t + c * n), r]), u = new Float64Array(a.length).fill(Infinity), d = new Int32Array(a.length).fill(-1), f = new i();
|
|
68
68
|
for (u[t] = 0, f.push(0, t); f.size;) {
|
|
69
69
|
f.pop();
|
|
@@ -80,12 +80,12 @@ function O(e, t, n) {
|
|
|
80
80
|
from: d
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
-
function
|
|
83
|
+
function A(e, t) {
|
|
84
84
|
let n = [];
|
|
85
85
|
for (let r = t; r !== -1; r = e[r]) n.push(r);
|
|
86
86
|
return n.reverse();
|
|
87
87
|
}
|
|
88
|
-
function
|
|
88
|
+
function j(e, t) {
|
|
89
89
|
let { nx: n, ny: r } = e.grid, i = t.map((e) => [
|
|
90
90
|
e % n,
|
|
91
91
|
(e / n | 0) % r,
|
|
@@ -106,7 +106,7 @@ function A(e, t) {
|
|
|
106
106
|
depth: t.map((t) => e.depth[t])
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
|
-
function
|
|
109
|
+
function M(e, t) {
|
|
110
110
|
let { points: n, along: r } = e;
|
|
111
111
|
if (t <= 0) return n[0];
|
|
112
112
|
let i = 1;
|
|
@@ -114,21 +114,21 @@ function j(e, t) {
|
|
|
114
114
|
let a = r[i] - r[i - 1];
|
|
115
115
|
return S(n[i - 1], n[i], a > 0 ? Math.min(1, (t - r[i - 1]) / a) : 0);
|
|
116
116
|
}
|
|
117
|
-
function
|
|
117
|
+
function N(e, t) {
|
|
118
118
|
let n = 0;
|
|
119
119
|
for (; n < e.length && n < t.length && e[n] === t[n];) n++;
|
|
120
120
|
return n - 1;
|
|
121
121
|
}
|
|
122
|
-
var
|
|
123
|
-
function
|
|
122
|
+
var P = (e) => new l("failed", `autoRig found no humanoid here; ${e}`);
|
|
123
|
+
function te(e, t) {
|
|
124
124
|
let { grid: n, mask: r } = e, { nx: i, ny: a } = n, o = Infinity, s = -Infinity;
|
|
125
125
|
for (let e = 0; e < r.length; e++) {
|
|
126
126
|
if (!r[e]) continue;
|
|
127
127
|
let t = (e / i | 0) % a;
|
|
128
128
|
t < o && (o = t), t > s && (s = t);
|
|
129
129
|
}
|
|
130
|
-
let c = s - o + 1, l =
|
|
131
|
-
if (l.length < 2 || l[1].length < .1 * l[0].length) throw
|
|
130
|
+
let c = s - o + 1, l = F(e, o, c);
|
|
131
|
+
if (l.length < 2 || l[1].length < .1 * l[0].length) throw P("stand it upright on two separate feet, or pass up.");
|
|
132
132
|
let u = (e) => {
|
|
133
133
|
let t = [
|
|
134
134
|
0,
|
|
@@ -150,21 +150,21 @@ function ne(e, t) {
|
|
|
150
150
|
feet: m > 0 ? [l[0], l[1]] : [l[1], l[0]]
|
|
151
151
|
};
|
|
152
152
|
}
|
|
153
|
-
function
|
|
153
|
+
function ne(e, t) {
|
|
154
154
|
let { depth: n, mask: r } = e, i = 0;
|
|
155
155
|
for (let e = 0; e < r.length; e++) n[e] > n[i] && (i = e);
|
|
156
|
-
let a =
|
|
156
|
+
let a = k(e, i).distance, o = [], s = u * t;
|
|
157
157
|
for (; o.length < d;) {
|
|
158
158
|
let t = -1, n = s;
|
|
159
159
|
for (let e = 0; e < a.length; e++) a[e] > n && a[e] < Infinity && (n = a[e], t = e);
|
|
160
160
|
if (t < 0) break;
|
|
161
161
|
o.push(t);
|
|
162
|
-
let r =
|
|
162
|
+
let r = k(e, t).distance;
|
|
163
163
|
for (let e = 0; e < a.length; e++) r[e] < a[e] && (a[e] = r[e]);
|
|
164
164
|
}
|
|
165
165
|
return o;
|
|
166
166
|
}
|
|
167
|
-
function
|
|
167
|
+
function F(e, t, n) {
|
|
168
168
|
let { grid: r, mask: i } = e, { nx: a, ny: s } = r, c = t + Math.max(1, f * n), l = new Uint8Array(i.length), u = [], d = (e) => i[e] === 1 && (e / a | 0) % s <= c;
|
|
169
169
|
for (let e = 0; e < i.length; e++) {
|
|
170
170
|
if (!d(e) || l[e]) continue;
|
|
@@ -181,7 +181,7 @@ function P(e, t, n) {
|
|
|
181
181
|
}
|
|
182
182
|
return u.sort((e, t) => t.length - e.length);
|
|
183
183
|
}
|
|
184
|
-
function
|
|
184
|
+
function I(e, t, n) {
|
|
185
185
|
let { nx: r, ny: i } = e.grid, a = t[0], o = Infinity;
|
|
186
186
|
for (let e of t) {
|
|
187
187
|
let t = w(b([
|
|
@@ -193,7 +193,7 @@ function F(e, t, n) {
|
|
|
193
193
|
}
|
|
194
194
|
return a;
|
|
195
195
|
}
|
|
196
|
-
function
|
|
196
|
+
function L(e, t, n, r) {
|
|
197
197
|
let { grid: i, mask: a } = e, { nx: s, ny: c } = i, l = Math.round(t[0]) + s * (Math.round(t[1]) + c * Math.round(t[2])), u = /* @__PURE__ */ new Set(), d = [], f = [
|
|
198
198
|
0,
|
|
199
199
|
0,
|
|
@@ -232,7 +232,7 @@ function I(e, t, n, r) {
|
|
|
232
232
|
middle: f.map((e) => e / p)
|
|
233
233
|
};
|
|
234
234
|
}
|
|
235
|
-
function
|
|
235
|
+
function re(e, t, n, r) {
|
|
236
236
|
let { grid: i, mask: a } = e, { nx: o, ny: s } = i, c = (e, t) => {
|
|
237
237
|
for (let n of e.points) if (n[1] <= t) return n;
|
|
238
238
|
return e.points[e.points.length - 1];
|
|
@@ -246,15 +246,15 @@ function ie(e, t, n, r) {
|
|
|
246
246
|
}
|
|
247
247
|
return r;
|
|
248
248
|
}
|
|
249
|
-
var
|
|
249
|
+
var R = [
|
|
250
250
|
0,
|
|
251
251
|
1,
|
|
252
252
|
0
|
|
253
|
-
],
|
|
254
|
-
function
|
|
253
|
+
], ie = 1.7, ae = 3.2, z = .07, oe = 4.5, B = .48, se = 1.5;
|
|
254
|
+
function V(e, t, n) {
|
|
255
255
|
let r = t.points.length, i = [], a = [];
|
|
256
256
|
for (let o = 0; o < r; o++) {
|
|
257
|
-
let s = E(b(t.points[Math.min(r - 1, o + 3)], t.points[Math.max(0, o - 3)])), c =
|
|
257
|
+
let s = E(b(t.points[Math.min(r - 1, o + 3)], t.points[Math.max(0, o - 3)])), c = L(e, t.points[o], s, n);
|
|
258
258
|
i.push(c.area), a.push(c.area ? c.middle : t.points[o]);
|
|
259
259
|
}
|
|
260
260
|
let o = [0];
|
|
@@ -268,16 +268,16 @@ function z(e, t, n) {
|
|
|
268
268
|
area: i
|
|
269
269
|
};
|
|
270
270
|
}
|
|
271
|
-
function
|
|
271
|
+
function H(e, t, n) {
|
|
272
272
|
let { grid: r } = e, { nx: i, ny: a } = r, { height: o, sole: s, side: c, centre: l } = t, u = (e) => [
|
|
273
273
|
e % i,
|
|
274
274
|
(e / i | 0) % a,
|
|
275
275
|
e / (i * a) | 0
|
|
276
|
-
], d = (e) => C(b(e, l), c), f =
|
|
276
|
+
], d = (e) => C(b(e, l), c), f = ne(e, o), _ = f.reduce((e, t) => {
|
|
277
277
|
let n = (e) => u(e)[1] - 1.5 * Math.abs(d(u(e)));
|
|
278
278
|
return n(t) > n(e) ? t : e;
|
|
279
279
|
}, f[0]);
|
|
280
|
-
if (_ === void 0) throw
|
|
280
|
+
if (_ === void 0) throw P("the solid has no tips; raise resolution.");
|
|
281
281
|
let v = (e) => {
|
|
282
282
|
let t = [
|
|
283
283
|
0,
|
|
@@ -289,94 +289,97 @@ function B(e, t, n) {
|
|
|
289
289
|
voxels: e,
|
|
290
290
|
middle: t.map((t) => t / e.length)
|
|
291
291
|
};
|
|
292
|
-
}, y = v(t.feet[0]), D = v(t.feet[1]),
|
|
293
|
-
for (let t = 0; t <
|
|
292
|
+
}, y = v(t.feet[0]), D = v(t.feet[1]), O = I(e, y.voxels, y.middle), ee = I(e, D.voxels, D.middle), te = .022 * o, F = new Float32Array(e.depth.length);
|
|
293
|
+
for (let t = 0; t < F.length; t++) {
|
|
294
294
|
let n = e.depth[t];
|
|
295
|
-
n > 0 && (
|
|
295
|
+
n > 0 && (F[t] = 1 + te / n * (te / n) * 4);
|
|
296
296
|
}
|
|
297
|
-
let
|
|
298
|
-
if (
|
|
299
|
-
let
|
|
300
|
-
for (let e of
|
|
297
|
+
let H = k(e, _, F).from, U = A(H, O), W = A(H, ee);
|
|
298
|
+
if (U.length < 2 || W.length < 2) throw P("join the parts of the figure, or raise closing.");
|
|
299
|
+
let G = N(U, W), K = re(e, j(e, U.slice(G)), j(e, W.slice(G)), s), de = f.filter((e) => e !== _ && u(e)[1] > K - .1 * o), fe = (e) => x(e, c, -2 * d(e)), pe = -1, me = -1, he = Infinity;
|
|
300
|
+
for (let e of de) for (let t of de) {
|
|
301
301
|
if (d(u(e)) >= 0 || d(u(t)) <= 0) continue;
|
|
302
|
-
let n = w(b(
|
|
303
|
-
n <
|
|
302
|
+
let n = w(b(fe(u(e)), u(t))) - .25 * (d(u(t)) - d(u(e)));
|
|
303
|
+
n < he && (he = n, pe = e, me = t);
|
|
304
304
|
}
|
|
305
|
-
if (
|
|
306
|
-
let
|
|
307
|
-
if (
|
|
308
|
-
let
|
|
309
|
-
let r =
|
|
310
|
-
for (let e = 0; e + 1 <
|
|
311
|
-
|
|
305
|
+
if (pe < 0) throw P("hold the arms away from the body, in a T or A pose.");
|
|
306
|
+
let ge = A(H, pe), _e = A(H, me);
|
|
307
|
+
if (ge.length < 2 || _e.length < 2) throw P("join the parts of the figure, or raise closing.");
|
|
308
|
+
let q = .3 * o, ve = V(e, j(e, U.slice(G)), q).line, ye = V(e, j(e, W.slice(G)), q).line, be = (t, n) => {
|
|
309
|
+
let r = N(t, n), i = V(e, j(e, t.slice(r).reverse()), q), a = Math.sign(d(i.line.points[0])), s = i.line.points.findIndex((e) => d(e) * a < z * o), l = i.line, u = i.area, f = s > 1 ? l.along[s] : l.along[l.along.length - 1], h = u.filter((e, t) => l.along[t] > f * .3 && l.along[t] < f * .65).sort((e, t) => e - t), g = h[h.length >> 1] ?? 1, _ = f;
|
|
310
|
+
for (let e = 0; e + 1 < u.length; e++) if (l.along[e] > f * .5 && u[e] > ie * g && u[e + 1] > ie * g) {
|
|
311
|
+
_ = Math.min(_, l.along[e]);
|
|
312
312
|
break;
|
|
313
313
|
}
|
|
314
|
-
let
|
|
315
|
-
for (let t =
|
|
316
|
-
let t = x(
|
|
317
|
-
if (d(t) * a <
|
|
314
|
+
let v = M(l, _ * .5), y = E(b(M(l, _ * .72), v)), S = Math.sqrt(g / Math.PI), w = 0, T = !1;
|
|
315
|
+
for (let t = f - _ * .5; w < t; w += 1) {
|
|
316
|
+
let t = x(v, y, w), n = L(e, t, y, q);
|
|
317
|
+
if (d(t) * a < z * o || t[1] < K) break;
|
|
318
318
|
if (!n.area) {
|
|
319
319
|
let n = 1;
|
|
320
|
-
for (; n < 2 *
|
|
321
|
-
if (n < 2 *
|
|
322
|
-
|
|
320
|
+
for (; n < 2 * S && !L(e, x(t, y, n), y, q).area;) n++;
|
|
321
|
+
if (n < 2 * S) continue;
|
|
322
|
+
w -= S, T = !0;
|
|
323
323
|
break;
|
|
324
324
|
}
|
|
325
|
-
if (
|
|
325
|
+
if (w > _ * .15 && n.area > ae * g) break;
|
|
326
326
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
327
|
+
if (!T) {
|
|
328
|
+
let e = -a * C(y, c), t = d(x(v, y, w)) * a - (z * o + S), n = se * S;
|
|
329
|
+
w += e > 0 ? Math.min(n, Math.max(0, t / e)) : n;
|
|
330
|
+
}
|
|
331
|
+
let D = x(v, y, w);
|
|
332
|
+
_ = _ * .5 + w;
|
|
333
|
+
let O = ue(l, u, _ * (.245 - .08), _ * .325);
|
|
331
334
|
return {
|
|
332
|
-
upper:
|
|
333
|
-
lower:
|
|
334
|
-
hand:
|
|
335
|
-
end:
|
|
335
|
+
upper: D,
|
|
336
|
+
lower: M(l, O + (_ - O) * (1 - p / m)),
|
|
337
|
+
hand: M(l, O),
|
|
338
|
+
end: l.points[0]
|
|
336
339
|
};
|
|
337
|
-
},
|
|
338
|
-
for (let t =
|
|
339
|
-
let n =
|
|
340
|
-
n > 0 && n <
|
|
340
|
+
}, xe = be(ge, U), Se = be(_e, W), J = (xe.upper[1] + Se.upper[1]) / 2, Y = le(e, S(ce(ve, K), ce(ye, K), .5), K, u(_), q), Ce = u(_)[1], we = L(e, Y(J), R, q).area, X = J + (Ce - J) * .2, Te = we * .7;
|
|
341
|
+
for (let t = J + .02 * o; t < J + (Ce - J) * .6; t++) {
|
|
342
|
+
let n = L(e, Y(t), R, q).area;
|
|
343
|
+
n > 0 && n < Te && (Te = n, X = t);
|
|
341
344
|
}
|
|
342
|
-
let
|
|
345
|
+
let Ee = o / Math.max(1, Ce - X) > oe && K - s < B * .95 * o ? s + B * o : K, Z = Ee + .05 * o, De = (e) => {
|
|
343
346
|
let t = (t) => {
|
|
344
|
-
let n =
|
|
347
|
+
let n = ce(e, Math.min(t, K - .02 * o));
|
|
345
348
|
return [
|
|
346
349
|
n[0],
|
|
347
350
|
t,
|
|
348
351
|
n[2]
|
|
349
352
|
];
|
|
350
|
-
}, n = t(
|
|
353
|
+
}, n = t(Ee - .04 * o), r = [
|
|
351
354
|
n[0],
|
|
352
|
-
|
|
355
|
+
Z,
|
|
353
356
|
n[2]
|
|
354
|
-
], i = s + g * (
|
|
357
|
+
], i = s + g * (Z - s), a = t(i);
|
|
355
358
|
return {
|
|
356
359
|
upper: r,
|
|
357
|
-
knee: t(i + (
|
|
360
|
+
knee: t(i + (Z - i) * h),
|
|
358
361
|
ankle: a
|
|
359
362
|
};
|
|
360
|
-
},
|
|
361
|
-
arm:
|
|
362
|
-
leg:
|
|
363
|
-
},
|
|
364
|
-
arm:
|
|
365
|
-
leg:
|
|
366
|
-
},
|
|
363
|
+
}, Q = {
|
|
364
|
+
arm: xe,
|
|
365
|
+
leg: De(ve)
|
|
366
|
+
}, $ = {
|
|
367
|
+
arm: Se,
|
|
368
|
+
leg: De(ye)
|
|
369
|
+
}, Oe = T(c, R), ke = (e, t) => {
|
|
367
370
|
let n = -Infinity, r = Infinity;
|
|
368
371
|
for (let i of e.voxels) {
|
|
369
|
-
let e = C(b(u(i), t),
|
|
372
|
+
let e = C(b(u(i), t), Oe);
|
|
370
373
|
e > n && (n = e), e < r && (r = e);
|
|
371
374
|
}
|
|
372
375
|
return n + r;
|
|
373
|
-
},
|
|
374
|
-
-
|
|
376
|
+
}, Ae = (ke(y, Q.leg.ankle) + ke(D, $.leg.ankle)) / 2, je = !!n || Math.abs(Ae) > .01 * o, Me = n ?? (Ae >= 0 ? Oe : [
|
|
377
|
+
-Oe[0],
|
|
375
378
|
0,
|
|
376
|
-
-
|
|
379
|
+
-Oe[2]
|
|
377
380
|
]), Ne = (e, t) => {
|
|
378
381
|
let n = e.voxels[0];
|
|
379
|
-
for (let t of e.voxels) C(u(t),
|
|
382
|
+
for (let t of e.voxels) C(u(t), Me) > C(u(n), Me) && (n = t);
|
|
380
383
|
let r = u(n);
|
|
381
384
|
return {
|
|
382
385
|
toes: S([
|
|
@@ -387,10 +390,10 @@ function B(e, t, n) {
|
|
|
387
390
|
end: r
|
|
388
391
|
};
|
|
389
392
|
}, Pe = [
|
|
390
|
-
(
|
|
391
|
-
|
|
392
|
-
(
|
|
393
|
-
], Fe = (e) => Pe[1] + (
|
|
393
|
+
(Q.leg.upper[0] + $.leg.upper[0]) / 2,
|
|
394
|
+
Z + .02 * o,
|
|
395
|
+
(Q.leg.upper[2] + $.leg.upper[2]) / 2
|
|
396
|
+
], Fe = (e) => Pe[1] + (J - Pe[1]) * e, Ie = Y(X + .012 * o), Le = Y(J + (X - J) * .45), Re = C(T(R, Me), c) > 0 ? 1 : -1, ze = Re > 0 ? $ : Q, Be = Re > 0 ? Q : $, Ve = Re > 0 ? D : y, He = Re > 0 ? y : D, Ue = (e) => S(Y(J), e, .28), We = Ne(Ve, ze.leg.ankle), Ge = Ne(He, Be.leg.ankle), Ke = [
|
|
394
397
|
[
|
|
395
398
|
"hips",
|
|
396
399
|
null,
|
|
@@ -399,17 +402,17 @@ function B(e, t, n) {
|
|
|
399
402
|
[
|
|
400
403
|
"spine",
|
|
401
404
|
"hips",
|
|
402
|
-
|
|
405
|
+
Y(Fe(.25))
|
|
403
406
|
],
|
|
404
407
|
[
|
|
405
408
|
"chest",
|
|
406
409
|
"spine",
|
|
407
|
-
|
|
410
|
+
Y(Fe(.55))
|
|
408
411
|
],
|
|
409
412
|
[
|
|
410
413
|
"upperChest",
|
|
411
414
|
"chest",
|
|
412
|
-
|
|
415
|
+
Y(Fe(.8))
|
|
413
416
|
],
|
|
414
417
|
[
|
|
415
418
|
"neck",
|
|
@@ -478,15 +481,15 @@ function B(e, t, n) {
|
|
|
478
481
|
]);
|
|
479
482
|
return {
|
|
480
483
|
named: Ke,
|
|
481
|
-
forward:
|
|
482
|
-
facingFound:
|
|
484
|
+
forward: Me,
|
|
485
|
+
facingFound: je
|
|
483
486
|
};
|
|
484
487
|
}
|
|
485
|
-
function
|
|
488
|
+
function ce(e, t) {
|
|
486
489
|
for (let n of e.points) if (n[1] <= t) return n;
|
|
487
490
|
return e.points[e.points.length - 1];
|
|
488
491
|
}
|
|
489
|
-
function
|
|
492
|
+
function le(e, t, n, r, i) {
|
|
490
493
|
let { grid: a, mask: o, depth: s } = e, { nx: c, ny: l } = a, u = /* @__PURE__ */ new Map(), d = t;
|
|
491
494
|
for (let e = Math.round(n); e <= r[1]; e++) {
|
|
492
495
|
let t = Math.round(d[0]), n = Math.round(d[2]), r = Math.ceil(i), f = 0, p = 0, m = 0;
|
|
@@ -516,13 +519,13 @@ function de(e, t, n, r, i) {
|
|
|
516
519
|
];
|
|
517
520
|
};
|
|
518
521
|
}
|
|
519
|
-
function
|
|
522
|
+
function ue(e, t, n, r) {
|
|
520
523
|
let i = Infinity, a = (n + r) / 2;
|
|
521
524
|
return e.along.forEach((e, o) => {
|
|
522
525
|
e >= n && e <= r && t[o] > 0 && t[o] < i && (i = t[o], a = e);
|
|
523
526
|
}), a;
|
|
524
527
|
}
|
|
525
|
-
function
|
|
528
|
+
function U(e, t, n) {
|
|
526
529
|
let r = new Map(e.map((e) => [e[0], e])), i = r.get("hips")[2], a = C(i, t), o = (e) => x(e, t, 2 * (a - C(e, t))), s = e.filter((e) => e[0].startsWith("left"));
|
|
527
530
|
if (!(Math.max(...s.map((e) => w(b(o(e[2]), r.get(`right${e[0].slice(4)}`)[2])))) > .08 * n)) {
|
|
528
531
|
for (let e of s) {
|
|
@@ -542,7 +545,7 @@ function V(e, t, n) {
|
|
|
542
545
|
}
|
|
543
546
|
}
|
|
544
547
|
}
|
|
545
|
-
async function
|
|
548
|
+
async function W(i, o = {}) {
|
|
546
549
|
let { resolution: l = 128, up: u = [
|
|
547
550
|
0,
|
|
548
551
|
1,
|
|
@@ -561,7 +564,7 @@ async function H(i, o = {}) {
|
|
|
561
564
|
if (!(Math.sqrt(Math.max(0, e * e - t * t)) > 1e-6 * e)) throw RangeError("autoRig forward must not be parallel to up; give the direction the figure faces");
|
|
562
565
|
}
|
|
563
566
|
m?.throwIfAborted();
|
|
564
|
-
let
|
|
567
|
+
let k = Math.abs(S[1]) < .9 ? [
|
|
565
568
|
0,
|
|
566
569
|
1,
|
|
567
570
|
0
|
|
@@ -569,61 +572,61 @@ async function H(i, o = {}) {
|
|
|
569
572
|
0,
|
|
570
573
|
0,
|
|
571
574
|
1
|
|
572
|
-
],
|
|
573
|
-
C(e,
|
|
575
|
+
], A = t(i, o.weld), j = E(T(S, k)), M = T(j, S), N = (e) => [
|
|
576
|
+
C(e, j),
|
|
574
577
|
C(e, S),
|
|
575
|
-
C(e,
|
|
576
|
-
],
|
|
578
|
+
C(e, M)
|
|
579
|
+
], P = (e) => x(x(x([
|
|
577
580
|
0,
|
|
578
581
|
0,
|
|
579
582
|
0
|
|
580
|
-
],
|
|
581
|
-
let e = new Float64Array(
|
|
582
|
-
for (let t = 0; t < e.length; t += 3) e.set(
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
583
|
+
], j, e[0]), S, e[1]), M, e[2]), ne = () => {
|
|
584
|
+
let e = new Float64Array(A.positions.length);
|
|
585
|
+
for (let t = 0; t < e.length; t += 3) e.set(N([
|
|
586
|
+
A.positions[t],
|
|
587
|
+
A.positions[t + 1],
|
|
588
|
+
A.positions[t + 2]
|
|
586
589
|
]), t);
|
|
587
590
|
let t = {
|
|
588
|
-
...
|
|
591
|
+
...A,
|
|
589
592
|
positions: e
|
|
590
593
|
}, i = n(t, [], l);
|
|
591
594
|
a(i, t), r(i, d);
|
|
592
595
|
let o = s(i), c = new Uint8Array(i.state.length);
|
|
593
596
|
for (let e = 0; e < c.length; e++) c[e] = +(i.state[e] !== 0 || o[e] === 6);
|
|
594
|
-
let u =
|
|
597
|
+
let u = O(i, c), f = {
|
|
595
598
|
grid: i,
|
|
596
599
|
mask: c,
|
|
597
|
-
depth:
|
|
600
|
+
depth: ee(i, c),
|
|
598
601
|
count: u
|
|
599
|
-
}, p = g && D(
|
|
602
|
+
}, p = g && D(N(g));
|
|
600
603
|
return {
|
|
601
604
|
grid: i,
|
|
602
605
|
solid: f,
|
|
603
|
-
body:
|
|
606
|
+
body: te(f, p ? T([
|
|
604
607
|
0,
|
|
605
608
|
1,
|
|
606
609
|
0
|
|
607
610
|
], p) : void 0)
|
|
608
611
|
};
|
|
609
|
-
}, { grid:
|
|
610
|
-
m?.throwIfAborted(), Math.abs(
|
|
611
|
-
let
|
|
612
|
-
f &&
|
|
613
|
-
let
|
|
612
|
+
}, { grid: F, solid: I, body: L } = ne();
|
|
613
|
+
m?.throwIfAborted(), Math.abs(L.side[0]) < _ && (j = E(P(D(L.side))), M = T(j, S), {grid: F, solid: I, body: L} = ne(), m?.throwIfAborted());
|
|
614
|
+
let re = I.count, { named: R, forward: ie, facingFound: ae } = H(I, L, g ? D(N(g)) : null);
|
|
615
|
+
f && U(R, L.side, L.height);
|
|
616
|
+
let z = (e) => P(x(F.origin, x(e, [
|
|
614
617
|
.5,
|
|
615
618
|
.5,
|
|
616
619
|
.5
|
|
617
|
-
]),
|
|
620
|
+
]), F.cell)), oe = new Map(R.map((e, t) => [e[0], t])), B = R.map(([e, t, n]) => ({
|
|
618
621
|
name: e,
|
|
619
|
-
parent: t === null ? -1 :
|
|
620
|
-
position:
|
|
622
|
+
parent: t === null ? -1 : oe.get(t),
|
|
623
|
+
position: z(n)
|
|
621
624
|
}));
|
|
622
|
-
e(
|
|
623
|
-
let
|
|
624
|
-
|
|
625
|
-
let n = e.parent < 0 ? e.position : b(e.position,
|
|
626
|
-
|
|
625
|
+
e(B);
|
|
626
|
+
let se = new Float64Array(B.length * 10);
|
|
627
|
+
B.forEach((e, t) => {
|
|
628
|
+
let n = e.parent < 0 ? e.position : b(e.position, B[e.parent].position);
|
|
629
|
+
se.set([
|
|
627
630
|
n[0],
|
|
628
631
|
n[1],
|
|
629
632
|
n[2],
|
|
@@ -636,25 +639,25 @@ async function H(i, o = {}) {
|
|
|
636
639
|
1
|
|
637
640
|
], t * 10);
|
|
638
641
|
});
|
|
639
|
-
let
|
|
640
|
-
return p === "voxel" && (
|
|
642
|
+
let V = null;
|
|
643
|
+
return p === "voxel" && (V = (await c(i, B, {
|
|
641
644
|
resolution: l,
|
|
642
645
|
closing: d,
|
|
643
646
|
weld: o.weld,
|
|
644
647
|
signal: m
|
|
645
648
|
})).weights), {
|
|
646
|
-
joints:
|
|
647
|
-
humanoid: Object.fromEntries(
|
|
649
|
+
joints: B,
|
|
650
|
+
humanoid: Object.fromEntries(oe),
|
|
648
651
|
pose: {
|
|
649
|
-
names:
|
|
650
|
-
parents:
|
|
651
|
-
rest:
|
|
652
|
+
names: B.map((e) => e.name),
|
|
653
|
+
parents: B.map((e) => e.parent),
|
|
654
|
+
rest: se
|
|
652
655
|
},
|
|
653
|
-
weights:
|
|
654
|
-
forward: E(
|
|
655
|
-
facingFound:
|
|
656
|
-
voxels:
|
|
656
|
+
weights: V,
|
|
657
|
+
forward: E(P(ie)),
|
|
658
|
+
facingFound: ae,
|
|
659
|
+
voxels: re
|
|
657
660
|
};
|
|
658
661
|
}
|
|
659
662
|
//#endregion
|
|
660
|
-
export {
|
|
663
|
+
export { W as autoRig };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
//#region src/body-volumes.ts
|
|
2
|
+
var e = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
function t(t) {
|
|
4
|
+
let n = e.get(t);
|
|
5
|
+
if (n) return n;
|
|
6
|
+
let r = t.species, i = t.stature > 0 ? t.stature : 1, a = (e) => {
|
|
7
|
+
let n = t.index.get(e);
|
|
8
|
+
return n === void 0 ? void 0 : t.joints[n].bone;
|
|
9
|
+
}, o = /* @__PURE__ */ new Map();
|
|
10
|
+
for (let e of r.volumes ?? []) {
|
|
11
|
+
let t = a(e.from), n = e.to.map(a).find((e) => e !== void 0 && e !== t);
|
|
12
|
+
t !== void 0 && n !== void 0 && o.set(e.id, {
|
|
13
|
+
near: t,
|
|
14
|
+
far: n,
|
|
15
|
+
r0: e.radius[0] * i,
|
|
16
|
+
r1: e.radius[1] * i
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return n = {
|
|
20
|
+
volumes: o,
|
|
21
|
+
pairs: (r.apart ?? []).filter(([e, t]) => {
|
|
22
|
+
let n = o.get(e), r = o.get(t);
|
|
23
|
+
return n && r && n.near !== r.near && n.near !== r.far && n.far !== r.near && n.far !== r.far;
|
|
24
|
+
})
|
|
25
|
+
}, e.set(t, n), n;
|
|
26
|
+
}
|
|
27
|
+
var n = (e, t) => [
|
|
28
|
+
e[0] - t[0],
|
|
29
|
+
e[1] - t[1],
|
|
30
|
+
e[2] - t[2]
|
|
31
|
+
], r = (e, t) => e[0] * t[0] + e[1] * t[1] + e[2] * t[2];
|
|
32
|
+
function i(e, t, i, a) {
|
|
33
|
+
let o = n(t, e), s = n(a, i), c = n(e, i), l = r(o, o), u = r(s, s), d = r(s, c), f = (e) => e < 0 ? 0 : e > 1 ? 1 : e, p, m;
|
|
34
|
+
if (l <= 1e-12 && u <= 1e-12) p = 0, m = 0;
|
|
35
|
+
else if (l <= 1e-12) p = 0, m = f(d / u);
|
|
36
|
+
else {
|
|
37
|
+
let e = r(o, c);
|
|
38
|
+
if (u <= 1e-12) m = 0, p = f(-e / l);
|
|
39
|
+
else {
|
|
40
|
+
let t = r(o, s), n = l * u - t * t;
|
|
41
|
+
p = n > 1e-12 ? f((t * d - e * u) / n) : 0, m = (t * p + d) / u, m < 0 ? (m = 0, p = f(-e / l)) : m > 1 && (m = 1, p = f((t - e) / l));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
let h = e[0] + o[0] * p - (i[0] + s[0] * m), g = e[1] + o[1] * p - (i[1] + s[1] * m), _ = e[2] + o[2] * p - (i[2] + s[2] * m);
|
|
45
|
+
return [
|
|
46
|
+
p,
|
|
47
|
+
m,
|
|
48
|
+
h * h + g * g + _ * _
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
function a(e, t, n, r, a, o, s) {
|
|
52
|
+
let [c, l, u] = i(e, t, r, a), d = s * (n.r0 + (n.r1 - n.r0) * c + o.r0 + (o.r1 - o.r0) * l), f = Math.sqrt(u);
|
|
53
|
+
return f < d ? d - f : 0;
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
export { i as n, a as r, t };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AnatomicalRig } from './anatomy.js';
|
|
2
|
+
/** A capsule on the rig: the bones at its two ends and its radius at each, in rig units. */
|
|
3
|
+
export interface BodyVolume {
|
|
4
|
+
readonly near: number;
|
|
5
|
+
readonly far: number;
|
|
6
|
+
readonly r0: number;
|
|
7
|
+
readonly r1: number;
|
|
8
|
+
}
|
|
9
|
+
/** The capsules of a fitted body by id, and the pairs of them that must stay apart. */
|
|
10
|
+
export interface BodyVolumes {
|
|
11
|
+
readonly volumes: Map<string, BodyVolume>;
|
|
12
|
+
readonly pairs: readonly (readonly [string, string])[];
|
|
13
|
+
}
|
|
14
|
+
/** The body's volumes and the pairs that stay apart; pairs that share an end bone meet at a joint and are left out. */
|
|
15
|
+
export declare function bodyVolumes(body: AnatomicalRig): BodyVolumes;
|
|
16
|
+
/** Closest points of segments p0-p1 and q0-q1: [s, t, squared distance] (Ericson 2005, 5.1.9). */
|
|
17
|
+
export declare function closestSegments(p0: ArrayLike<number>, p1: ArrayLike<number>, q0: ArrayLike<number>, q1: ArrayLike<number>): [number, number, number];
|
|
18
|
+
/** How far two capsules reach into each other past `shrink` of their radii, in rig units; 0 when apart. */
|
|
19
|
+
export declare function overlapDepth(a0: ArrayLike<number>, a1: ArrayLike<number>, va: BodyVolume, b0: ArrayLike<number>, b1: ArrayLike<number>, vb: BodyVolume, shrink: number): number;
|
package/dist/contact.d.ts
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import type { Animator } from '@margoengine/animator';
|
|
3
3
|
// @ts-ignore optional peer: its types apply when it is installed
|
|
4
4
|
import { type CCDJointLimit } from '@margoengine/animator/ccd';
|
|
5
|
+
// @ts-ignore optional peer: its types apply when it is installed
|
|
6
|
+
import { type Anatomy } from '@margoengine/animator/ik';
|
|
5
7
|
import type { Vec3 } from '@margoengine/math';
|
|
6
8
|
import { type HandRig, type HandSide } from './hands.js';
|
|
7
9
|
import type { IKPose } from './ik.js';
|
|
@@ -30,8 +32,17 @@ export interface ContactIKOptions {
|
|
|
30
32
|
readonly anchor: Vec3;
|
|
31
33
|
/** Blend toward the contact, default 1. Zero preserves the input pose exactly. */
|
|
32
34
|
readonly weight?: number;
|
|
33
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Anatomical limits for the joints to constrain. Default: the ranges of the pose's fitted body (`body`, `pose.body`
|
|
37
|
+
* or `setAnatomy(pose, body)`) for every joint of the chain, each measured from its anatomical zero. A list given
|
|
38
|
+
* here is used as it is, and joints not in it are free.
|
|
39
|
+
*/
|
|
34
40
|
readonly limits?: readonly ContactJointLimit[];
|
|
41
|
+
/**
|
|
42
|
+
* The fitted body whose joint ranges the chain takes when `limits` is not given. Default: the pose's body. Null
|
|
43
|
+
* leaves the body out, so with no `limits` every joint is free.
|
|
44
|
+
*/
|
|
45
|
+
readonly body?: Anatomy | null;
|
|
35
46
|
/** Point on the desired elbow or knee bend side in skeleton space. */
|
|
36
47
|
readonly pole?: Vec3 | null;
|
|
37
48
|
/** Maximum CCD sweeps, from 1 to 1,024. Default 64. */
|