@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/contact.js
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
import { r as e, s as t } from "./rig-BawZ5OLb.js";
|
|
2
2
|
import { FINGERS as n, grip as r, handRotations as i, measureHands as a, poseTable as o, relaxed as s } from "./hands.js";
|
|
3
3
|
import { axisAngleToQuaternion as c, conjugateQuaternion as l, interpolateQuaternions as u, multiplyQuaternions as d, normalizeQuaternion as f, rotateByQuaternion as p, rotationToQuaternion as m } from "@margoengine/math/quat";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { anatomyOf as h, ccdLimit as g, jointOf as _ } from "@margoengine/animator/ik";
|
|
5
|
+
import { CCDSolver as v } from "@margoengine/animator/ccd";
|
|
6
|
+
import { add as y, cross as b, dot as x, length as S, normalize as C, scale as w, sub as T } from "@margoengine/math/vec3";
|
|
6
7
|
//#region src/bar-grip.ts
|
|
7
|
-
function
|
|
8
|
-
let
|
|
9
|
-
if (
|
|
10
|
-
let
|
|
8
|
+
function E(e, t, r, i, a, o, s, m) {
|
|
9
|
+
let h = t.world(t.hand), g = C(b(r, i));
|
|
10
|
+
if (S(g) < .99) return;
|
|
11
|
+
let _ = b(i, g), E = (e, t) => p(T(D(e).position, D(t).position), l(D(t).rotation)), D = (e) => t.world(e), O = t.fingers.index?.bones[0];
|
|
11
12
|
if (O === void 0) return;
|
|
12
|
-
let k =
|
|
13
|
+
let k = x(p(T(D(O).position, h.position), l(h.rotation)), g), A = o / 2, j = y(a, w(i, A));
|
|
13
14
|
for (let r of n) {
|
|
14
15
|
let n = t.fingers[r];
|
|
15
|
-
if (!n || n.curl.some((e) =>
|
|
16
|
-
let [a, o,
|
|
17
|
-
if (e.parents[a] !== t.hand || e.parents[o] !== a || e.parents[
|
|
18
|
-
let
|
|
16
|
+
if (!n || n.curl.some((e) => S(e) < .9)) continue;
|
|
17
|
+
let [a, o, h] = n.bones;
|
|
18
|
+
if (e.parents[a] !== t.hand || e.parents[o] !== a || e.parents[h] !== o) continue;
|
|
19
|
+
let b = r === "thumb", O = e.parents.findIndex((e) => e === h), M = O < 0 ? p(T(D(h).position, D(o).position), l(D(h).rotation)) : E(O, h), N = w(C(M), n.lengths[2]), P = [
|
|
19
20
|
E(a, t.hand),
|
|
20
21
|
E(o, a),
|
|
21
|
-
E(
|
|
22
|
+
E(h, o)
|
|
22
23
|
];
|
|
23
|
-
if (
|
|
24
|
-
let F = new
|
|
24
|
+
if (S(N) < 1e-6 || P.slice(1).some((e) => S(e) < 1e-6)) continue;
|
|
25
|
+
let F = new v(P, N), I = n.lengths[1] * (b ? .23 : .28), L = /* @__PURE__ */ new Float64Array(12), R = /* @__PURE__ */ new Float64Array(12);
|
|
25
26
|
for (let [e, r] of n.bones.entries()) {
|
|
26
27
|
let n = f(t.rest.get(r) ?? [
|
|
27
28
|
0,
|
|
@@ -31,9 +32,9 @@ function C(e, t, r, i, a, o, s, m) {
|
|
|
31
32
|
]);
|
|
32
33
|
F.rest.set(n, e * 4), L.set(m.get(r) ?? n, e * 4), R.set(s.get(r) ?? n, e * 4);
|
|
33
34
|
}
|
|
34
|
-
F.setLimit(0,
|
|
35
|
+
F.setLimit(0, b ? {
|
|
35
36
|
type: "cone",
|
|
36
|
-
axis:
|
|
37
|
+
axis: C(P[1]),
|
|
37
38
|
angle: 1.12,
|
|
38
39
|
twist: [-.58, .58]
|
|
39
40
|
} : {
|
|
@@ -46,7 +47,7 @@ function C(e, t, r, i, a, o, s, m) {
|
|
|
46
47
|
type: "hinge",
|
|
47
48
|
axis: n.curl[1],
|
|
48
49
|
min: -.15,
|
|
49
|
-
max:
|
|
50
|
+
max: b ? 1.16 : 1.97
|
|
50
51
|
}, B = {
|
|
51
52
|
type: "hinge",
|
|
52
53
|
axis: n.curl[2],
|
|
@@ -55,8 +56,8 @@ function C(e, t, r, i, a, o, s, m) {
|
|
|
55
56
|
};
|
|
56
57
|
F.setLimit(1, z), F.setLimit(2, B), F.tolerance = Math.max(5e-5, I * .018), F.iterations = 28;
|
|
57
58
|
let V = (e) => {
|
|
58
|
-
let t =
|
|
59
|
-
return [
|
|
59
|
+
let t = T(F.positions.subarray(e, e + 3), j);
|
|
60
|
+
return [x(t, _), x(t, i)];
|
|
60
61
|
}, H = () => {
|
|
61
62
|
let e = 0;
|
|
62
63
|
for (let t = 0; t < 3; t++) {
|
|
@@ -64,9 +65,9 @@ function C(e, t, r, i, a, o, s, m) {
|
|
|
64
65
|
e = Math.max(e, A + I - Math.hypot(n[0] + i * s, n[1] + a * s));
|
|
65
66
|
}
|
|
66
67
|
return e;
|
|
67
|
-
}, U =
|
|
68
|
-
let a =
|
|
69
|
-
return F.rotations.set(n), F.solve(
|
|
68
|
+
}, U = x(P[0], g), W = b ? k * .7 + U * .3 : U, G = w(g, W - x(j, g)), K = y(j, G), q = (e, t, n, r = 0) => {
|
|
69
|
+
let a = y(w(_, Math.sin(e) * (b ? -1 : 1)), w(i, -Math.cos(e)));
|
|
70
|
+
return F.rotations.set(n), F.solve(y(y(K, w(g, r)), w(a, A + I + t))), F.rotations.slice();
|
|
70
71
|
}, J = (e, t) => {
|
|
71
72
|
let r = 0;
|
|
72
73
|
for (let n of [
|
|
@@ -86,13 +87,13 @@ function C(e, t, r, i, a, o, s, m) {
|
|
|
86
87
|
F.update(), r = Math.max(r, H());
|
|
87
88
|
}
|
|
88
89
|
let i = V(9), a = 0;
|
|
89
|
-
if (
|
|
90
|
-
let i = r * 4, o = d(l(e.subarray(i, i + 4)), t.subarray(i, i + 4)), s = 2 * Math.atan2(
|
|
90
|
+
if (b) for (let r of [1, 2]) {
|
|
91
|
+
let i = r * 4, o = d(l(e.subarray(i, i + 4)), t.subarray(i, i + 4)), s = 2 * Math.atan2(x(o.slice(0, 3), n.curl[r]), o[3]);
|
|
91
92
|
a += I * 16 * Math.max(0, .16 - Math.atan2(Math.sin(s), Math.cos(s)));
|
|
92
93
|
}
|
|
93
|
-
return Math.abs(Math.hypot(...i) - A - I) + 16 * r + a + Math.max(0,
|
|
94
|
+
return Math.abs(Math.hypot(...i) - A - I) + 16 * r + a + Math.max(0, b ? i[0] : -i[0]);
|
|
94
95
|
}, Y = L.slice(), X = R, Z = J(R, L);
|
|
95
|
-
for (let e of
|
|
96
|
+
for (let e of b ? [
|
|
96
97
|
.4,
|
|
97
98
|
.68,
|
|
98
99
|
.95,
|
|
@@ -121,7 +122,7 @@ function C(e, t, r, i, a, o, s, m) {
|
|
|
121
122
|
a + 1e-6 < Z && (Z = a, Y = t, X = i);
|
|
122
123
|
}
|
|
123
124
|
}
|
|
124
|
-
if (
|
|
125
|
+
if (b) for (let e of [
|
|
125
126
|
.4,
|
|
126
127
|
.68,
|
|
127
128
|
.95,
|
|
@@ -174,58 +175,58 @@ function C(e, t, r, i, a, o, s, m) {
|
|
|
174
175
|
}
|
|
175
176
|
//#endregion
|
|
176
177
|
//#region src/hinged-contact.ts
|
|
177
|
-
function
|
|
178
|
+
function D(e, t) {
|
|
178
179
|
return m([
|
|
179
180
|
...e,
|
|
180
|
-
...
|
|
181
|
+
...b(t, e),
|
|
181
182
|
...t
|
|
182
183
|
]);
|
|
183
184
|
}
|
|
184
|
-
function
|
|
185
|
+
function O(e, t, n, r, i) {
|
|
185
186
|
let a = e.joints - 1, o = a - 1, s = a - 2, u = (t) => [
|
|
186
187
|
e.positions[t * 3],
|
|
187
188
|
e.positions[t * 3 + 1],
|
|
188
189
|
e.positions[t * 3 + 2]
|
|
189
|
-
], f = (t) => e.worldRotations.slice(t * 4, t * 4 + 4), m = (t) => e.rest.subarray(t * 4, t * 4 + 4), h = (t) =>
|
|
190
|
-
if (Math.abs(
|
|
191
|
-
let k = Math.atan2(
|
|
190
|
+
], f = (t) => e.worldRotations.slice(t * 4, t * 4 + 4), m = (t) => e.rest.subarray(t * 4, t * 4 + 4), h = (t) => C(e.offsets.subarray(t * 3, t * 3 + 3)), g = h(o), _ = h(a), v = C(i.axis), E = p(v, m(o)), O = p(_, m(o));
|
|
191
|
+
if (Math.abs(x(E, g)) > 1e-5 || Math.abs(x(E, O)) > 1e-5 || i.twist && x(C(i.twist.axis), _) < .99999) throw RangeError("Hinged contact needs a bend axis perpendicular to both links and forearm roll along the last link");
|
|
192
|
+
let k = Math.atan2(x(E, b(g, O)), x(g, O)), A = Math.max(1e-5, k + (i.min ?? -Math.PI)), j = Math.min(Math.PI - 1e-5, k + (i.max ?? Math.PI));
|
|
192
193
|
if (j < A) throw RangeError("Hinged contact needs a flexion range that intersects the positive bend branch");
|
|
193
194
|
e.projectRotations(), e.update();
|
|
194
|
-
let M = u(s), N = u(o), P = u(a), F =
|
|
195
|
+
let M = u(s), N = u(o), P = u(a), F = S(T(N, M)), I = S(T(P, N)), L = T(t, M), R = S(L), z = R < 1e-8 ? C(T(P, M)) : w(L, 1 / R);
|
|
195
196
|
if (F < 1e-8 || I < 1e-8) throw RangeError("Hinged contact needs two links with nonzero lengths");
|
|
196
|
-
let B =
|
|
197
|
-
if (
|
|
198
|
-
let H = (e) => Math.sqrt(Math.max(0, F * F + I * I + 2 * F * I * Math.cos(e))), U = Math.max(H(j), Math.min(H(A), R)), W =
|
|
197
|
+
let B = C(T(r, M)), V = b(B, z);
|
|
198
|
+
if (S(V) < 1e-6) throw RangeError("Choose a hinged contact pole off the shoulder-to-target line to define a bend plane");
|
|
199
|
+
let H = (e) => Math.sqrt(Math.max(0, F * F + I * I + 2 * F * I * Math.cos(e))), U = Math.max(H(j), Math.min(H(A), R)), W = C(V), G = (F * F - I * I + U * U) / (2 * U), K = Math.sqrt(Math.max(0, F * F - G * G)), q = C(y(w(z, G), w(b(z, W), K))), J = (U * U - F * F - I * I) / (2 * F * I), Y = Math.acos(Math.max(-1, Math.min(1, J))), X = d(D(q, W), l(D(g, E))), Z = s === 0 ? e.parentRotation : f(s - 1), Q = d(m(o), c(v, Y - k)), ee = d(X, Q), te = 0;
|
|
199
200
|
if (i.twist) {
|
|
200
|
-
let e = d(l(ee), d(n, l(m(a)))), t = 2 * Math.atan2(
|
|
201
|
-
|
|
201
|
+
let e = d(l(ee), d(n, l(m(a)))), t = 2 * Math.atan2(x(e.slice(0, 3), _), e[3]), r = Math.atan2(Math.sin(t), Math.cos(t));
|
|
202
|
+
te = Math.max(i.twist.range[0], Math.min(i.twist.range[1], r));
|
|
202
203
|
}
|
|
203
|
-
let
|
|
204
|
-
e.rotations.set(d(l(Z), X), s * 4), e.rotations.set(
|
|
204
|
+
let $ = d(Q, c(_, te)), ne = d(X, $);
|
|
205
|
+
e.rotations.set(d(l(Z), X), s * 4), e.rotations.set($, o * 4), e.rotations.set(d(l(ne), n), a * 4), e.projectRotations(), e.update();
|
|
205
206
|
}
|
|
206
207
|
//#endregion
|
|
207
208
|
//#region src/limb-collision.ts
|
|
208
|
-
var
|
|
209
|
+
var k = [
|
|
209
210
|
0,
|
|
210
211
|
0,
|
|
211
212
|
0
|
|
212
|
-
],
|
|
213
|
+
], A = (e, t) => [
|
|
213
214
|
e[t],
|
|
214
215
|
e[t + 1],
|
|
215
216
|
e[t + 2]
|
|
216
217
|
];
|
|
217
|
-
function
|
|
218
|
+
function j(e) {
|
|
218
219
|
return e?.length === 3 && Number.isFinite(e[0]) && Number.isFinite(e[1]) && Number.isFinite(e[2]);
|
|
219
220
|
}
|
|
220
|
-
function
|
|
221
|
-
let r =
|
|
221
|
+
function M(e, t, n) {
|
|
222
|
+
let r = x(e, t) + S(e) * n;
|
|
222
223
|
if (!Number.isFinite(r)) throw RangeError("Give the direction limit finite vectors at scene scale");
|
|
223
224
|
return r;
|
|
224
225
|
}
|
|
225
|
-
function
|
|
226
|
-
let i =
|
|
227
|
-
if (Math.abs(
|
|
228
|
-
let c =
|
|
226
|
+
function N(e, t, n, r) {
|
|
227
|
+
let i = A(e, n), a = A(t, n), o = A(e, n + 3), s = A(t, n + 3);
|
|
228
|
+
if (Math.abs(S(o) - 1) > 1e-9 || Math.abs(S(s) - 1) > 1e-9) throw RangeError("Direction samples need unit body axes");
|
|
229
|
+
let c = C(o), l = C(s), u = b(c, l), d = S(u), f = x(c, l), p = Math.atan2(d, f), m = b(C(u), c), h = T(a, i), g = (1 + r) * S(h) + p * Math.max(S(i), S(a));
|
|
229
230
|
if (!Number.isFinite(g)) throw RangeError("Give the direction sweep finite motion at scene scale");
|
|
230
231
|
return {
|
|
231
232
|
start: i,
|
|
@@ -238,22 +239,22 @@ function A(e, t, n, r) {
|
|
|
238
239
|
opposed: d <= 1e-12 && f < 0
|
|
239
240
|
};
|
|
240
241
|
}
|
|
241
|
-
function
|
|
242
|
+
function P(e, t) {
|
|
242
243
|
let n = e.arc * t;
|
|
243
|
-
return
|
|
244
|
+
return M(y(e.start, w(e.delta, t)), y(w(e.axis, Math.cos(n)), w(e.tangent, Math.sin(n))), e.allowance);
|
|
244
245
|
}
|
|
245
|
-
function
|
|
246
|
-
return
|
|
246
|
+
function F(e, t, n) {
|
|
247
|
+
return S(T(e, w(t, Math.max(0, Math.min(n, x(e, t))))));
|
|
247
248
|
}
|
|
248
|
-
function
|
|
249
|
-
let i =
|
|
249
|
+
function I(e, t, n, r) {
|
|
250
|
+
let i = T(t, e), a = T(r, n), o = T(n, e), s = C(i), c = C(a), l = S(i), u = S(a), d = Math.min(F(w(o, -1), c, u), F(T(i, o), c, u), F(o, s, l), F(T(r, e), s, l)), f = b(s, c), p = x(f, f);
|
|
250
251
|
if (p > 0) {
|
|
251
|
-
let e =
|
|
252
|
-
e >= 0 && e <= l && t >= 0 && t <= u && (d = Math.min(d, Math.abs(
|
|
252
|
+
let e = x(b(o, c), f) / p, t = x(b(o, s), f) / p;
|
|
253
|
+
e >= 0 && e <= l && t >= 0 && t <= u && (d = Math.min(d, Math.abs(x(o, f)) / Math.sqrt(p)));
|
|
253
254
|
}
|
|
254
255
|
return d;
|
|
255
256
|
}
|
|
256
|
-
function
|
|
257
|
+
function L(e, t, n, r) {
|
|
257
258
|
let { position: i, linear: a } = e, o = t * 9;
|
|
258
259
|
return [
|
|
259
260
|
a[o] * n[0] + a[o + 3] * n[1] + a[o + 6] * n[2] + (r ? i[t * 3] : 0),
|
|
@@ -261,19 +262,19 @@ function P(e, t, n, r) {
|
|
|
261
262
|
a[o + 2] * n[0] + a[o + 5] * n[1] + a[o + 8] * n[2] + (r ? i[t * 3 + 2] : 0)
|
|
262
263
|
];
|
|
263
264
|
}
|
|
264
|
-
var
|
|
265
|
+
var R = class {
|
|
265
266
|
constructor(t, n, r, i = []) {
|
|
266
267
|
if (this.axes = [], this.posed = !1, this.clearance = (e) => {
|
|
267
268
|
this.packLimb(e, this.candidate);
|
|
268
269
|
let t = this.measure(this.body, this.candidate);
|
|
269
270
|
return this.limits.forEach(({ start: n, end: r, maxBackwards: i }, a) => {
|
|
270
|
-
let o =
|
|
271
|
-
t = Math.min(t,
|
|
271
|
+
let o = T(A(e, r * 3), A(e, n * 3));
|
|
272
|
+
t = Math.min(t, M(o, this.axes[a], Math.sin(i)));
|
|
272
273
|
}), t;
|
|
273
274
|
}, !t.length || t.length > 65536 || t.some((e) => !Number.isInteger(e) || e < -1 || e >= t.length)) throw RangeError("Limb collision needs 1–65,536 joints with valid parent indices or -1");
|
|
274
275
|
let a = (e) => Number.isInteger(e) && e >= 0 && e < t.length, o = (e) => Number.isInteger(e) && e >= 0 && e < 65536, s = (e) => {
|
|
275
|
-
let t = e.offset ??
|
|
276
|
-
if (!a(e.joint) || !
|
|
276
|
+
let t = e.offset ?? k;
|
|
277
|
+
if (!a(e.joint) || !j(t)) throw RangeError("Body collision landmarks need a valid bone and a finite local XYZ offset");
|
|
277
278
|
return {
|
|
278
279
|
joint: e.joint,
|
|
279
280
|
offset: [...t]
|
|
@@ -296,12 +297,12 @@ var F = class {
|
|
|
296
297
|
range: [...r]
|
|
297
298
|
};
|
|
298
299
|
}), this.limits = i.map(({ start: e, end: t, reference: n, forward: r, maxBackwards: i = .75 }) => {
|
|
299
|
-
if (!(o(e) && o(t) && e !== t && a(n) &&
|
|
300
|
+
if (!(o(e) && o(t) && e !== t && a(n) && j(r) && S(r) > 0 && i >= 0 && i <= Math.PI / 2)) throw RangeError("Direction limits need distinct valid slots, a reference bone, a forward axis and an angle from 0 to π/2");
|
|
300
301
|
return {
|
|
301
302
|
start: e,
|
|
302
303
|
end: t,
|
|
303
304
|
reference: n,
|
|
304
|
-
forward:
|
|
305
|
+
forward: C(r),
|
|
305
306
|
maxBackwards: i
|
|
306
307
|
};
|
|
307
308
|
}), this.slots = [...this.links, ...this.limits].reduce((e, { start: t, end: n }) => Math.max(e, t, n), 0) + 1, this.body = new Float64Array(this.volumes.length * 6), this.candidate = new Float64Array(this.links.length * 6);
|
|
@@ -309,15 +310,15 @@ var F = class {
|
|
|
309
310
|
setBodyPose(e) {
|
|
310
311
|
if (e.length !== this.parents.length * 10) throw RangeError("A collision pose needs ten local transform components per joint");
|
|
311
312
|
for (let t = 0; t < e.length; t++) if (!Number.isFinite(e[t])) throw RangeError("Give the collision rig finite translation, quaternion and scale values");
|
|
312
|
-
let n = t(this.parents, e, this.order), r = new Float64Array(this.body.length), i = (e) =>
|
|
313
|
+
let n = t(this.parents, e, this.order), r = new Float64Array(this.body.length), i = (e) => L(n, e.joint, e.offset ?? k, !0);
|
|
313
314
|
this.volumes.forEach(({ start: e, end: t }, n) => {
|
|
314
315
|
let a = i(e), o = t ? i(t) : a;
|
|
315
|
-
if (!
|
|
316
|
+
if (!j(a) || !j(o)) throw RangeError("Collision body landmarks overflowed; use finite transforms at scene scale");
|
|
316
317
|
r.set(a, n * 6), r.set(o, n * 6 + 3);
|
|
317
318
|
});
|
|
318
319
|
let a = this.limits.map(({ reference: e, forward: t }) => {
|
|
319
|
-
let r =
|
|
320
|
-
if (
|
|
320
|
+
let r = C(L(n, e, t, !1));
|
|
321
|
+
if (S(r) < .9) throw RangeError("A collision direction needs a non-degenerate reference frame");
|
|
321
322
|
return r;
|
|
322
323
|
});
|
|
323
324
|
this.body.set(r), this.axes = a, this.posed = !0;
|
|
@@ -331,8 +332,8 @@ var F = class {
|
|
|
331
332
|
if (!this.limits.length) return t;
|
|
332
333
|
let n = new Float64Array(this.limits.length * 6);
|
|
333
334
|
return this.limits.forEach(({ start: t, end: r }, i) => {
|
|
334
|
-
let a =
|
|
335
|
-
if (!
|
|
335
|
+
let a = T(A(e, r * 3), A(e, t * 3));
|
|
336
|
+
if (!j(a)) throw RangeError("Give the direction sample finite joint displacements at scene scale");
|
|
336
337
|
n.set(a, i * 6), n.set(this.axes[i], i * 6 + 3);
|
|
337
338
|
}), {
|
|
338
339
|
...t,
|
|
@@ -345,9 +346,9 @@ var F = class {
|
|
|
345
346
|
let i = e.directions, a = t.directions;
|
|
346
347
|
if (!!i != !!a) throw RangeError("Pass direction data in both sweep snapshots, or two legacy snapshots");
|
|
347
348
|
for (let e of [i, a]) if (e && (e.length !== this.limits.length * 6 || !e.every(Number.isFinite))) throw RangeError("Sweep direction samples must match the rig layout and contain finite vectors");
|
|
348
|
-
let o = i && a ? this.limits.map(({ maxBackwards: e }, t) =>
|
|
349
|
+
let o = i && a ? this.limits.map(({ maxBackwards: e }, t) => N(i, a, t * 6, Math.sin(e))) : [], s = o.some((e) => e.opposed), c = e.body.slice(), l = e.limb.slice(), u = t.body.map((t, n) => t - e.body[n]), d = t.limb.map((t, n) => t - e.limb[n]), f = A(u, 0), p = (e) => {
|
|
349
350
|
let t = 0;
|
|
350
|
-
for (let n = 0; n < e.length; n += 3) t = Math.max(t,
|
|
351
|
+
for (let n = 0; n < e.length; n += 3) t = Math.max(t, S(T(A(e, n), f)));
|
|
351
352
|
return t;
|
|
352
353
|
}, m = p(u) + p(d);
|
|
353
354
|
if (!Number.isFinite(m)) throw RangeError("Give the collision sweep finite motion at scene scale");
|
|
@@ -355,7 +356,7 @@ var F = class {
|
|
|
355
356
|
for (let t = 0; t < r; t++) {
|
|
356
357
|
let t = this.measure(c, l), r = t, i = m > 0 ? (t - n * .5) / m : Infinity;
|
|
357
358
|
for (let e of o) {
|
|
358
|
-
let t =
|
|
359
|
+
let t = P(e, h);
|
|
359
360
|
r = Math.min(r, t), e.speed > 0 && (i = Math.min(i, (t - n * .5) / e.speed));
|
|
360
361
|
}
|
|
361
362
|
if (g = Math.min(g, r), r <= n) return {
|
|
@@ -399,9 +400,9 @@ var F = class {
|
|
|
399
400
|
measure(e, t) {
|
|
400
401
|
let n = Infinity;
|
|
401
402
|
return this.links.forEach(({ radius: r }, i) => {
|
|
402
|
-
let a =
|
|
403
|
+
let a = A(t, i * 6), o = A(t, i * 6 + 3);
|
|
403
404
|
this.volumes.forEach((t, i) => {
|
|
404
|
-
let s =
|
|
405
|
+
let s = I(a, o, A(e, i * 6), A(e, i * 6 + 3)) - r - t.radius;
|
|
405
406
|
if (!Number.isFinite(s)) throw RangeError("Collision distance overflowed; use finite positions at scene scale");
|
|
406
407
|
n = Math.min(n, s);
|
|
407
408
|
});
|
|
@@ -410,35 +411,35 @@ var F = class {
|
|
|
410
411
|
};
|
|
411
412
|
//#endregion
|
|
412
413
|
//#region src/contact.ts
|
|
413
|
-
function
|
|
414
|
+
function z(e, t) {
|
|
414
415
|
if (!(e?.length === 4 && e.every(Number.isFinite) && Math.hypot(...e) > 0)) throw RangeError(`Contact IK ${t} needs a finite, nonzero quaternion`);
|
|
415
416
|
return f(e);
|
|
416
417
|
}
|
|
417
|
-
function
|
|
418
|
-
let { parents: i, local: a } = n, { joints: o, point: s, anchor: c, rotation: l, pole: d,
|
|
418
|
+
function B(n, r) {
|
|
419
|
+
let { parents: i, local: a } = n, { joints: o, point: s, anchor: c, rotation: l, pole: d, clearance: f } = r, { weight: m = 1, iterations: b = 64, tolerance: x = 1e-4, angleTolerance: S = .02 } = r;
|
|
419
420
|
if (!Array.isArray(i) || !(a instanceof Float64Array) || a.length !== i.length * 10) throw TypeError("Contact IK needs a pose with parents and 10 local values per joint");
|
|
420
421
|
if (!Array.isArray(o) || o.length < 2 || o.length > 256) throw TypeError("Contact IK needs a chain of 2 to 256 joints");
|
|
421
422
|
if (!o.every((e, t) => Number.isInteger(e) && e >= 0 && e < i.length && (t === 0 || i[e] === o[t - 1]))) throw RangeError("Contact IK joints must form a parent-child chain");
|
|
422
423
|
if (i.some((e) => !Number.isInteger(e) || e < -1 || e >= i.length)) throw RangeError("Contact IK parents must be valid joint indices or -1");
|
|
423
424
|
if (!(s?.length === 3 && c?.length === 3 && [...s, ...c].every(Number.isFinite))) throw RangeError("Contact IK point and anchor need three finite coordinates each");
|
|
424
|
-
if (!(
|
|
425
|
-
let C = e(i, "Contact IK"),
|
|
426
|
-
c[0] * a[
|
|
427
|
-
c[1] * a[
|
|
428
|
-
c[2] * a[
|
|
429
|
-
],
|
|
430
|
-
for (let e = i[
|
|
425
|
+
if (!(m >= 0 && m <= 1 && x > 0 && Number.isFinite(x) && S > 0 && S <= Math.PI && Number.isInteger(b) && b >= 1 && b <= 1024)) throw RangeError("Contact IK weight, tolerance or iteration count is out of range; use the supported ranges");
|
|
426
|
+
let C = e(i, "Contact IK"), E = o.at(-1), D = E * 10, k = z(l, "rotation"), A = i[o[0]], j = [
|
|
427
|
+
c[0] * a[D + 7],
|
|
428
|
+
c[1] * a[D + 8],
|
|
429
|
+
c[2] * a[D + 9]
|
|
430
|
+
], M = 1, N = 1;
|
|
431
|
+
for (let e = i[E]; e >= 0; e = i[e]) {
|
|
431
432
|
let t = e * 10, n = a[t + 7];
|
|
432
433
|
if (!(n > 0 && Number.isFinite(n) && a[t + 8] === n && a[t + 9] === n)) throw RangeError("Contact IK needs uniform positive ancestor scales; apply scale to the mesh before rigging");
|
|
433
|
-
|
|
434
|
+
M *= n;
|
|
434
435
|
}
|
|
435
|
-
for (let e =
|
|
436
|
-
if (!(Number.isFinite(
|
|
437
|
-
let
|
|
438
|
-
if (
|
|
439
|
-
let e =
|
|
440
|
-
if (!
|
|
441
|
-
let t =
|
|
436
|
+
for (let e = A; e >= 0; e = i[e]) N *= a[e * 10 + 7];
|
|
437
|
+
if (!(Number.isFinite(M) && M > 0 && j.every(Number.isFinite) && a.subarray(D + 7, D + 10).every((e) => e > 0 && Number.isFinite(e)))) throw RangeError("Contact IK needs finite positive scales");
|
|
438
|
+
let P = w(j, M), F = t(i, a, C), I = F.rotation.subarray(E * 4, E * 4 + 4), L = y(F.position.subarray(E * 3, E * 3 + 3), p(P, I)), R = () => U(L, I, s, k, x, S), B = () => V(f, o.flatMap((e) => Array.from(F.position.subarray(e * 3, e * 3 + 3))), o.flatMap((e) => Array.from(F.rotation.subarray(e * 4, e * 4 + 4))));
|
|
439
|
+
if (m === 0) {
|
|
440
|
+
let e = R();
|
|
441
|
+
if (!f) return e;
|
|
442
|
+
let t = B();
|
|
442
443
|
return {
|
|
443
444
|
...e,
|
|
444
445
|
locked: e.locked && t >= 0,
|
|
@@ -446,7 +447,7 @@ function L(n, r) {
|
|
|
446
447
|
clearance: t
|
|
447
448
|
};
|
|
448
449
|
}
|
|
449
|
-
let
|
|
450
|
+
let W = new v(o.map((e) => {
|
|
450
451
|
let t = e * 10;
|
|
451
452
|
return [
|
|
452
453
|
a[t],
|
|
@@ -454,60 +455,66 @@ function L(n, r) {
|
|
|
454
455
|
a[t + 2]
|
|
455
456
|
];
|
|
456
457
|
}));
|
|
457
|
-
|
|
458
|
+
W.iterations = b, W.tolerance = x, W.angleTolerance = S, A >= 0 && (W.parentPosition.set(F.position.subarray(A * 3, A * 3 + 3)), W.parentRotation.set(F.rotation.subarray(A * 4, A * 4 + 4)), W.parentScale[0] = N), o.forEach((e, t) => {
|
|
458
459
|
let n = e * 10;
|
|
459
|
-
|
|
460
|
+
W.rotations.set(a.subarray(n + 3, n + 7), t * 4), e !== E && (W.scales[t] = a[n + 7]);
|
|
460
461
|
});
|
|
461
|
-
let
|
|
462
|
-
|
|
462
|
+
let G = r.body === null ? null : r.body ?? n.body ?? h(n), K = r.limits ?? (G?.limits ? o.flatMap((e) => {
|
|
463
|
+
let t = _(G, e);
|
|
464
|
+
return t ? [{
|
|
465
|
+
joint: e,
|
|
466
|
+
...g(t)
|
|
467
|
+
}] : [];
|
|
468
|
+
}) : []), q = /* @__PURE__ */ new Set();
|
|
469
|
+
for (let { joint: e, neutral: t, limit: n } of K) {
|
|
463
470
|
let r = o.indexOf(e);
|
|
464
|
-
if (r < 0 ||
|
|
465
|
-
|
|
471
|
+
if (r < 0 || q.has(e)) throw RangeError("Contact IK limits must name distinct joints in the chain");
|
|
472
|
+
q.add(e), W.rest.set(z(t, "neutral rotation"), r * 4), W.setLimit(r, n);
|
|
466
473
|
}
|
|
467
|
-
let
|
|
474
|
+
let J = u(I, k, m, .9995), Y = y(L, w(T(s, L), m)), X = T(Y, p(P, J)), Z;
|
|
468
475
|
if (r.reach === "hinged") {
|
|
469
|
-
let e =
|
|
476
|
+
let e = K.find(({ joint: e }) => e === o[o.length - 2])?.limit;
|
|
470
477
|
if (o.length < 3 || !d || e?.type !== "hinge") throw RangeError("Hinged contact requires three joints or more, an explicit pole and a penultimate hinge limit");
|
|
471
|
-
if (
|
|
472
|
-
...
|
|
478
|
+
if (O(W, X, J, d, e), f && (Z = V(f, W.positions.subarray(0, W.joints * 3), W.worldRotations), Z < 0)) return {
|
|
479
|
+
...R(),
|
|
473
480
|
locked: !1,
|
|
474
481
|
blocked: !0,
|
|
475
|
-
clearance:
|
|
482
|
+
clearance: B()
|
|
476
483
|
};
|
|
477
|
-
} else if (
|
|
484
|
+
} else if (f) {
|
|
478
485
|
let e = o[o.length - 2] * 3;
|
|
479
|
-
if (
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
],
|
|
484
|
-
...
|
|
486
|
+
if (Z = H(W, X, J, d ?? [
|
|
487
|
+
F.position[e],
|
|
488
|
+
F.position[e + 1],
|
|
489
|
+
F.position[e + 2]
|
|
490
|
+
], f), Z === void 0) return {
|
|
491
|
+
...R(),
|
|
485
492
|
locked: !1,
|
|
486
493
|
blocked: !0,
|
|
487
|
-
clearance:
|
|
494
|
+
clearance: B()
|
|
488
495
|
};
|
|
489
|
-
} else
|
|
490
|
-
let
|
|
491
|
-
o.forEach((e, t) => a.set(
|
|
492
|
-
let
|
|
493
|
-
return
|
|
494
|
-
|
|
496
|
+
} else W.solve(X, J, d);
|
|
497
|
+
let Q = o.length - 1, ee = W.worldRotations.subarray(Q * 4, Q * 4 + 4), te = y(W.positions.subarray(Q * 3, Q * 3 + 3), p(P, ee));
|
|
498
|
+
o.forEach((e, t) => a.set(W.rotations.subarray(t * 4, t * 4 + 4), e * 10 + 3));
|
|
499
|
+
let $ = U(te, ee, s, k, x, S);
|
|
500
|
+
return Z === void 0 ? $ : {
|
|
501
|
+
...$,
|
|
495
502
|
blocked: !1,
|
|
496
|
-
clearance:
|
|
503
|
+
clearance: Z
|
|
497
504
|
};
|
|
498
505
|
}
|
|
499
|
-
function
|
|
506
|
+
function V(e, t, n) {
|
|
500
507
|
let r = e(t, n);
|
|
501
508
|
if (!Number.isFinite(r) && r !== Infinity) throw RangeError("Contact clearance must return a signed distance, or positive infinity when no obstacle applies");
|
|
502
509
|
return r;
|
|
503
510
|
}
|
|
504
|
-
function
|
|
505
|
-
let a = e.positions.subarray(0, e.joints * 3), o = e.solve(t, n, r), s =
|
|
511
|
+
function H(e, t, n, r, i) {
|
|
512
|
+
let a = e.positions.subarray(0, e.joints * 3), o = e.solve(t, n, r), s = V(i, a, e.worldRotations);
|
|
506
513
|
if (s >= 0 && o.reached) return s;
|
|
507
|
-
let u = Math.max(0, e.joints - 3), f = a.slice(u * 3, u * 3 + 3), m =
|
|
508
|
-
if (
|
|
509
|
-
let h = e.rotations.slice(),
|
|
510
|
-
|
|
514
|
+
let u = Math.max(0, e.joints - 3), f = a.slice(u * 3, u * 3 + 3), m = C(T(t, f));
|
|
515
|
+
if (S(m) < .9) return s >= 0 ? s : void 0;
|
|
516
|
+
let h = e.rotations.slice(), g = (e.joints - 1) * 4, _ = u * 4, v = h.subarray(_, _ + 4), x = u === 0 ? e.parentRotation : e.worldRotations.slice(_ - 4, _), w = l(x), E = e.worldRotations.slice(g - 4, g), D = e.worldRotations.slice(g, g + 4), O = T(r, f);
|
|
517
|
+
S(b(m, O)) < 1e-6 && (O = b(m, Math.abs(m[1]) < .9 ? [
|
|
511
518
|
0,
|
|
512
519
|
1,
|
|
513
520
|
0
|
|
@@ -536,22 +543,22 @@ function z(e, t, n, r, i) {
|
|
|
536
543
|
]) {
|
|
537
544
|
let o = c(m, r);
|
|
538
545
|
e.rotations.set(h);
|
|
539
|
-
let s = d(
|
|
540
|
-
e.rotations.set(d(s,
|
|
541
|
-
let u = e.solve(t, n,
|
|
542
|
-
if (
|
|
543
|
-
if (u.reached) return
|
|
544
|
-
let
|
|
545
|
-
(!A ||
|
|
546
|
-
distance:
|
|
547
|
-
gap:
|
|
546
|
+
let s = d(w, d(o, x));
|
|
547
|
+
e.rotations.set(d(s, v), _), e.rotations.set(d(l(d(o, E)), D), g);
|
|
548
|
+
let u = e.solve(t, n, y(f, p(O, o))), b = V(i, a, e.worldRotations);
|
|
549
|
+
if (b < 0) continue;
|
|
550
|
+
if (u.reached) return b;
|
|
551
|
+
let S = k(u.distance, u.angle);
|
|
552
|
+
(!A || S < A.distance) && (A = {
|
|
553
|
+
distance: S,
|
|
554
|
+
gap: b,
|
|
548
555
|
pose: e.rotations.slice()
|
|
549
556
|
});
|
|
550
557
|
}
|
|
551
558
|
if (A) return e.rotations.set(A.pose), e.update(), A.gap;
|
|
552
559
|
}
|
|
553
|
-
function
|
|
554
|
-
let o =
|
|
560
|
+
function U(e, t, n, r, i, a) {
|
|
561
|
+
let o = S(T(e, n)), s = t[0] * r[0] + t[1] * r[1] + t[2] * r[2] + t[3] * r[3], c = 2 * Math.acos(Math.min(1, Math.abs(s)));
|
|
555
562
|
return {
|
|
556
563
|
locked: o <= i && c <= a,
|
|
557
564
|
distance: o,
|
|
@@ -559,39 +566,39 @@ function B(e, t, n, r, i, a) {
|
|
|
559
566
|
point: e
|
|
560
567
|
};
|
|
561
568
|
}
|
|
562
|
-
function
|
|
563
|
-
let n =
|
|
564
|
-
if (
|
|
569
|
+
function W(e, t) {
|
|
570
|
+
let n = C(t), r = C(T(e, w(n, x(e, n))));
|
|
571
|
+
if (S(n) < .9 || S(r) < .9 || S(b(C(e), n)) < 1e-5) throw RangeError("Palm orientation needs a nonzero normal and a finger direction across that normal");
|
|
565
572
|
return f(m([
|
|
566
573
|
...r,
|
|
567
574
|
...n,
|
|
568
|
-
...
|
|
575
|
+
...b(r, n)
|
|
569
576
|
]));
|
|
570
577
|
}
|
|
571
|
-
function
|
|
578
|
+
function G(e, t) {
|
|
572
579
|
if (e?.length !== 3 || !e.every(Number.isFinite)) throw RangeError(`${t} needs three finite coordinates`);
|
|
573
580
|
}
|
|
574
|
-
function
|
|
581
|
+
function K(e, t) {
|
|
575
582
|
let n = t * 10 + 3;
|
|
576
|
-
return
|
|
583
|
+
return z([
|
|
577
584
|
e.rest[n],
|
|
578
585
|
e.rest[n + 1],
|
|
579
586
|
e.rest[n + 2],
|
|
580
587
|
e.rest[n + 3]
|
|
581
588
|
], "local rest rotation");
|
|
582
589
|
}
|
|
583
|
-
function
|
|
590
|
+
function q(e, t, n, r) {
|
|
584
591
|
let { joint: i, flexDirection: a, min: o = -.035, max: s = 2.55, roll: c = [-1.25, 1.25] } = r, u = n.indexOf(i);
|
|
585
592
|
if (u <= 0 || u >= n.length - 1) throw RangeError("Elbow calibration needs an intermediate joint of the arm chain");
|
|
586
|
-
|
|
587
|
-
let d = t.world(i), f =
|
|
588
|
-
if (
|
|
593
|
+
G(a, "Elbow flexion direction");
|
|
594
|
+
let d = t.world(i), f = C(T(t.world(t.hand).position, d.position)), m = b(f, C(a)), h = l(d.rotation);
|
|
595
|
+
if (S(m) < 1e-5) throw RangeError("Elbow flexion needs a direction across the forearm");
|
|
589
596
|
return {
|
|
590
597
|
joint: i,
|
|
591
|
-
neutral:
|
|
598
|
+
neutral: K(e, i),
|
|
592
599
|
limit: {
|
|
593
600
|
type: "hinge",
|
|
594
|
-
axis: p(
|
|
601
|
+
axis: p(C(m), h),
|
|
595
602
|
min: o,
|
|
596
603
|
max: s,
|
|
597
604
|
twist: c === !1 ? void 0 : {
|
|
@@ -601,64 +608,64 @@ function W(e, t, n, r) {
|
|
|
601
608
|
}
|
|
602
609
|
};
|
|
603
610
|
}
|
|
604
|
-
var
|
|
611
|
+
var J = class {
|
|
605
612
|
constructor(n, r) {
|
|
606
613
|
this.rig = n;
|
|
607
|
-
let { side: c, preset: u, bones: d, joints: f, limits: m = [], anchor: h, elbow:
|
|
614
|
+
let { side: c, preset: u, bones: d, joints: f, limits: m = [], anchor: h, elbow: g } = r;
|
|
608
615
|
if (c !== "left" && c !== "right") throw RangeError("Choose left or right for the palm calibration");
|
|
609
616
|
if (n.parents.some((e) => !Number.isInteger(e) || e < -1 || e >= n.parents.length)) throw RangeError("Palm calibration needs parents with valid joint indices or −1");
|
|
610
|
-
let
|
|
611
|
-
if (!
|
|
612
|
-
if (!Array.isArray(f) || f.length < 2 || f.length > 256 || f.at(-1) !==
|
|
613
|
-
let E =
|
|
614
|
-
this.inversePalm = l(
|
|
615
|
-
let j = t(n.parents, n.rest,
|
|
617
|
+
let _ = e(n.parents, "Palm calibration"), v = a(n, u, d)[c], b = v?.fingers.middle?.bones[0];
|
|
618
|
+
if (!v || b === void 0) throw RangeError("Palm calibration needs an index, middle and outer finger mapped on the requested hand");
|
|
619
|
+
if (!Array.isArray(f) || f.length < 2 || f.length > 256 || f.at(-1) !== v.hand || !f.every((e, t) => Number.isInteger(e) && e >= 0 && e < n.parents.length && (!t || n.parents[e] === f[t - 1]))) throw RangeError("Palm calibration needs a consecutive 2–256 joint arm ending at the mapped wrist");
|
|
620
|
+
let E = v.world(v.hand), D = l(z(E.rotation, "wrist rest rotation")), O = p(T(v.world(b).position, E.position), D), k = p(v.palm, D), A = w(k, S(O) * .085);
|
|
621
|
+
this.inversePalm = l(W(O, k));
|
|
622
|
+
let j = t(n.parents, n.rest, _).linear, M = v.hand * 9, N = [
|
|
616
623
|
0,
|
|
617
624
|
1,
|
|
618
625
|
2
|
|
619
626
|
].map((e) => {
|
|
620
627
|
let t = M + e * 3;
|
|
621
628
|
return Math.hypot(j[t], j[t + 1], j[t + 2]);
|
|
622
|
-
}), P =
|
|
623
|
-
this.anchor = h ? [...h] : B,
|
|
624
|
-
let { flexion:
|
|
629
|
+
}), P = S(O), F = C(O), I = v.fingers.thumb, L = I ? x(p(T(v.world(I.bones[0]).position, E.position), D), F) : 0, R = Math.min(P * .88, Math.max(P * .56, L + .9 * (I?.lengths[1] ?? 0))), B = y(w(F, R), A).map((e, t) => e / N[t]);
|
|
630
|
+
this.anchor = h ? [...h] : B, G(this.anchor, "Palm anchor"), this.gripForward = C(O), this.gripNormal = C(k), this.gripAnchor = this.anchor.map((e, t) => e * N[t]);
|
|
631
|
+
let { flexion: V = 1.12, extension: H = 1, deviation: U = .46 } = r.wrist || {};
|
|
625
632
|
if (![
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
633
|
+
V,
|
|
634
|
+
H,
|
|
635
|
+
U
|
|
629
636
|
].every((e) => e >= 0 && e <= Math.PI / 2)) throw RangeError("Palm wrist ranges need angles from zero to π/2 radians");
|
|
630
637
|
this.wrist = r.wrist === !1 ? null : {
|
|
631
|
-
flexion:
|
|
632
|
-
extension:
|
|
633
|
-
deviation:
|
|
634
|
-
}, this.hand =
|
|
638
|
+
flexion: V,
|
|
639
|
+
extension: H,
|
|
640
|
+
deviation: U
|
|
641
|
+
}, this.hand = v, this.arm = [...f];
|
|
635
642
|
let J = [...m];
|
|
636
|
-
if (
|
|
637
|
-
joint:
|
|
638
|
-
neutral:
|
|
643
|
+
if (g && !J.some(({ joint: e }) => e === g.joint) && J.push(q(n, v, f, g)), J.some(({ joint: e }) => e === v.hand) || J.push({
|
|
644
|
+
joint: v.hand,
|
|
645
|
+
neutral: K(n, v.hand),
|
|
639
646
|
limit: {
|
|
640
647
|
type: "cone",
|
|
641
|
-
axis:
|
|
648
|
+
axis: C(O),
|
|
642
649
|
angle: 1.15,
|
|
643
650
|
twist: [-.22, .22]
|
|
644
651
|
}
|
|
645
652
|
}), this.limits = J, this.tolerance = r.tolerance ?? .003, this.angleTolerance = r.angleTolerance ?? Math.PI / 36, !(this.tolerance > 0 && Number.isFinite(this.tolerance) && this.angleTolerance > 0 && this.angleTolerance <= Math.PI)) throw RangeError("Palm tolerances need a finite positive distance and an angle between zero and π");
|
|
646
|
-
this.open = i(
|
|
647
|
-
for (let [e, t] of
|
|
653
|
+
this.open = i(v, o(s(), v));
|
|
654
|
+
for (let [e, t] of v.rest) this.open.has(e) || this.open.set(e, [...t]);
|
|
648
655
|
this.joints = [...this.arm, ...this.open.keys()];
|
|
649
656
|
}
|
|
650
657
|
solve(e, t) {
|
|
651
658
|
let { point: n, normal: a, towardsFingers: s, diameter: c, close: l = 1, weight: p = 1, elbowPole: m, clearance: h } = t;
|
|
652
|
-
if (
|
|
659
|
+
if (G(a, "Surface normal"), G(s, "Direction toward fingers"), m && G(m, "Elbow pole"), !(l >= 0 && l <= 1 && p >= 0 && p <= 1)) throw RangeError("Hand closure and reach weight must be from zero to one");
|
|
653
660
|
if (this.gripPose?.diameter !== c) {
|
|
654
661
|
let e = i(this.hand, o(r(c), this.hand)), t = new Map(this.open);
|
|
655
|
-
|
|
662
|
+
E(this.rig, this.hand, this.gripForward, this.gripNormal, this.gripAnchor, c, t, e), this.gripPose = {
|
|
656
663
|
diameter: c,
|
|
657
664
|
approach: t,
|
|
658
665
|
closed: e
|
|
659
666
|
};
|
|
660
667
|
}
|
|
661
|
-
let g = f(d(
|
|
668
|
+
let g = f(d(W(s, w(a, -1)), this.inversePalm)), _ = this.wrist, v = _ ? (e, t) => Math.min(this.wristGap(e, t, _), h?.(e, t) ?? Infinity) : h, y = B({
|
|
662
669
|
parents: this.rig.parents,
|
|
663
670
|
local: e
|
|
664
671
|
}, {
|
|
@@ -673,19 +680,19 @@ var G = class {
|
|
|
673
680
|
clearance: v,
|
|
674
681
|
tolerance: this.tolerance * .05,
|
|
675
682
|
angleTolerance: this.angleTolerance * .05
|
|
676
|
-
}), b = y.blocked ? Infinity : Math.max(y.distance / this.tolerance, y.angle / this.angleTolerance),
|
|
683
|
+
}), b = y.blocked ? Infinity : Math.max(y.distance / this.tolerance, y.angle / this.angleTolerance), x = Math.max(0, 1 - b), S = p === 0 ? 0 : l * x * x * (3 - 2 * x);
|
|
677
684
|
if (p > 0) for (let [t, n] of this.gripPose.approach) {
|
|
678
|
-
let r = u(n, this.gripPose.closed.get(t) ?? n,
|
|
685
|
+
let r = u(n, this.gripPose.closed.get(t) ?? n, S, .9995);
|
|
679
686
|
e.set(r, t * 10 + 3);
|
|
680
687
|
}
|
|
681
688
|
return {
|
|
682
689
|
...y,
|
|
683
690
|
locked: b <= 1,
|
|
684
|
-
gripWeight:
|
|
691
|
+
gripWeight: S
|
|
685
692
|
};
|
|
686
693
|
}
|
|
687
694
|
wristGap(e, t, n) {
|
|
688
|
-
let r = this.arm.length - 1, i = r * 3, a = r * 4, o =
|
|
695
|
+
let r = this.arm.length - 1, i = r * 3, a = r * 4, o = T([
|
|
689
696
|
e[i],
|
|
690
697
|
e[i + 1],
|
|
691
698
|
e[i + 2]
|
|
@@ -693,23 +700,23 @@ var G = class {
|
|
|
693
700
|
e[i - 3],
|
|
694
701
|
e[i - 2],
|
|
695
702
|
e[i - 1]
|
|
696
|
-
]), s =
|
|
703
|
+
]), s = S(o);
|
|
697
704
|
if (s < 1e-6) return Infinity;
|
|
698
705
|
let c = [
|
|
699
706
|
-t[a],
|
|
700
707
|
-t[a + 1],
|
|
701
708
|
-t[a + 2],
|
|
702
709
|
t[a + 3]
|
|
703
|
-
], l = p(o, c), u = b(
|
|
704
|
-
return s * Math.min(n.flexion - g, n.extension + g, n.deviation -
|
|
710
|
+
], l = p(o, c), u = C(b(this.gripForward, this.gripNormal)), d = b(this.gripNormal, u), f = x(l, d), m = x(l, this.gripNormal), h = x(l, u), g = -Math.atan2(m, f), _ = Math.atan2(Math.abs(h), Math.hypot(f, m));
|
|
711
|
+
return s * Math.min(n.flexion - g, n.extension + g, n.deviation - _);
|
|
705
712
|
}
|
|
706
713
|
};
|
|
707
|
-
function
|
|
714
|
+
function Y(e, t, n, r) {
|
|
708
715
|
let i = e.animation.model, a = i.nodes, o = i.root.engine.store, s = new Map(a.map((e, t) => [e.id, t])), c = a.map((e) => s.get(o.parents[e.id]) ?? -1), l = new Float64Array(a.length * 10);
|
|
709
716
|
a.forEach((t, n) => {
|
|
710
717
|
l.set(e.restPosition(n), n * 10), l.set(e.restRotation(n), n * 10 + 3), l.set(e.restScale(n), n * 10 + 7);
|
|
711
718
|
});
|
|
712
|
-
let u = new
|
|
719
|
+
let u = new J({
|
|
713
720
|
names: a.map((e) => e.name ?? ""),
|
|
714
721
|
parents: c,
|
|
715
722
|
rest: l
|
|
@@ -736,4 +743,4 @@ function K(e, t, n, r) {
|
|
|
736
743
|
});
|
|
737
744
|
}
|
|
738
745
|
//#endregion
|
|
739
|
-
export {
|
|
746
|
+
export { R as LimbCollisionRig, J as PalmContactRig, Y as addPalmContact, B as solveContactIK };
|