@margoengine/kinematics-constraints 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +440 -2
- package/dist/AvoidanceSolver.d.ts +203 -0
- package/dist/chain.d.ts +48 -0
- package/dist/chain.js +159 -0
- package/dist/errors-D5_2oB8I.js +7 -0
- package/dist/hull-RrgFbmB9.js +325 -0
- package/dist/hull.d.ts +62 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +300 -0
- package/dist/joint-limits.d.ts +34 -0
- package/dist/joint-limits.js +104 -0
- package/dist/multi-goal-math.d.ts +12 -0
- package/dist/multi-goal.d.ts +147 -0
- package/dist/multi-goal.js +313 -0
- package/dist/sdf.d.ts +121 -0
- package/dist/sdf.js +202 -0
- package/dist/shared/validate-vector.d.ts +2 -0
- package/dist/swept.d.ts +67 -0
- package/dist/swept.js +185 -0
- package/dist/types.d.ts +36 -0
- package/dist/validate-vector-7JTvvTtJ.js +15 -0
- package/dist/volumes-CpBBobtO.js +219 -0
- package/dist/volumes.d.ts +58 -0
- package/package.json +77 -4
package/dist/swept.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { ConvexHullVolume } from './hull.js';
|
|
2
|
+
import type { ConstraintVolume, Vec3View } from './types.js';
|
|
3
|
+
/** Settings of every swept check. */
|
|
4
|
+
export interface SweepOptions {
|
|
5
|
+
/** Gap the motion must keep from every collider, in scene units. Default 0: only a true contact stops it. */
|
|
6
|
+
minClearance?: number;
|
|
7
|
+
/** A gap this close to `minClearance` counts as reached; it also sets the smallest step. Default 1e-4. */
|
|
8
|
+
tolerance?: number;
|
|
9
|
+
/** Most poses tested; a motion that needs more ends `exhausted`, not clear. Default 4,096. */
|
|
10
|
+
maxSteps?: number;
|
|
11
|
+
}
|
|
12
|
+
/** Settings of {@link sweepChain}. */
|
|
13
|
+
export interface ChainSweepOptions extends SweepOptions {
|
|
14
|
+
/** Capsule radius of every link, or one per link. Required. */
|
|
15
|
+
radius: number | readonly number[];
|
|
16
|
+
/** Radius of a sphere on every joint, or one per joint, root first; 0 is none. Default 0. */
|
|
17
|
+
jointRadius?: number | readonly number[];
|
|
18
|
+
}
|
|
19
|
+
/** What a swept check found. */
|
|
20
|
+
export interface SweepResult {
|
|
21
|
+
/** The whole motion keeps the gap. False on a contact, and on `exhausted`. */
|
|
22
|
+
clear: boolean;
|
|
23
|
+
/** The step budget ran out first: nothing is known past `time`. */
|
|
24
|
+
exhausted: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Where the check stopped, from 0 to 1 along the motion: the first contact, or 1 when clear. The motion is clear up
|
|
27
|
+
* to here and no later than the true contact, so this is a safe place to stop.
|
|
28
|
+
*/
|
|
29
|
+
time: number;
|
|
30
|
+
/** Smallest gap beyond `minClearance` at any pose tested. A true gap between two poses can be smaller, never below 0. */
|
|
31
|
+
clearance: number;
|
|
32
|
+
/** Poses tested. */
|
|
33
|
+
steps: number;
|
|
34
|
+
/** Moving shape at the contact, or -1: a chain's link index, then its joints after its links; 0 for a hull. */
|
|
35
|
+
shape: number;
|
|
36
|
+
/** Index of the collider at the contact; -1 for none. */
|
|
37
|
+
collider: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Checks a chain of joints, such as the root, elbow and hand an `AvoidanceSolver` gives, moving between two poses. The
|
|
41
|
+
* root moves on a straight line and each bone turns on the shortest arc from its old direction to its new one, its
|
|
42
|
+
* length held (or eased between the two lengths), which is the motion of bones and not of loose points. `from` and
|
|
43
|
+
* `to` list the joint positions in order. A collider that stands between the ends is found, however fast the motion:
|
|
44
|
+
* the check never steps past a contact. Colliders hold still during the check.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { SphereVolume } from 'margoengine/kinematics-constraints';
|
|
49
|
+
* import { sweepChain } from 'margoengine/kinematics-constraints/swept';
|
|
50
|
+
*
|
|
51
|
+
* const post = new SphereVolume({ center: [0, 1, 0], radius: 0.1 });
|
|
52
|
+
* const hit = sweepChain(
|
|
53
|
+
* [[0, 0, 0], [0.5, 0, 0], [1, 0, 0]],
|
|
54
|
+
* [[0, 0, 0], [-0.5, 0.1, 0], [-1, 0.2, 0]],
|
|
55
|
+
* [post],
|
|
56
|
+
* { radius: 0.05, minClearance: 0.01 },
|
|
57
|
+
* );
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function sweepChain(from: readonly Vec3View[], to: readonly Vec3View[], colliders: readonly ConstraintVolume[], options: ChainSweepOptions): SweepResult;
|
|
61
|
+
/**
|
|
62
|
+
* Checks a convex hull moving from one matrix to the other, for a link hull or any solid thing: its translation moves
|
|
63
|
+
* on a straight line, its rotation on the shortest arc about the hull's own origin, and its scale eases between the
|
|
64
|
+
* two. Matrices may hold rotation, positive scale and translation. The hull ends at `to`. See {@link sweepChain} for
|
|
65
|
+
* what the check promises.
|
|
66
|
+
*/
|
|
67
|
+
export declare function sweepHull(hull: ConvexHullVolume, from: ArrayLike<number>, to: ArrayLike<number>, colliders: readonly ConstraintVolume[], options?: SweepOptions): SweepResult;
|
package/dist/swept.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { n as e, r as t } from "./errors-D5_2oB8I.js";
|
|
2
|
+
import { t as n } from "./validate-vector-7JTvvTtJ.js";
|
|
3
|
+
import { i as r, s as i, t as a } from "./hull-RrgFbmB9.js";
|
|
4
|
+
import { o } from "./volumes-CpBBobtO.js";
|
|
5
|
+
//#region ../shared/swept-advance.js
|
|
6
|
+
function s(t) {
|
|
7
|
+
let n = t?.minClearance ?? 0, r = t?.tolerance ?? 1e-4, i = t?.maxSteps ?? 4096;
|
|
8
|
+
if (!(n >= 0) || !Number.isFinite(n)) throw e("Sweep minClearance must be 0 or more", "kinematics");
|
|
9
|
+
if (!(r > 0) || !Number.isFinite(r)) throw e("Sweep tolerance must be above 0", "kinematics");
|
|
10
|
+
if (!Number.isSafeInteger(i) || i < 1) throw e("Sweep maxSteps must be a positive integer", "kinematics");
|
|
11
|
+
return {
|
|
12
|
+
minClearance: n,
|
|
13
|
+
tolerance: r,
|
|
14
|
+
maxSteps: i
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function c(t, n, r, i, a) {
|
|
18
|
+
let { count: o, speed: s } = t, c = t.pairs, l = {
|
|
19
|
+
clear: !1,
|
|
20
|
+
exhausted: !1,
|
|
21
|
+
time: 0,
|
|
22
|
+
clearance: Infinity,
|
|
23
|
+
steps: 0,
|
|
24
|
+
shape: -1,
|
|
25
|
+
collider: -1
|
|
26
|
+
}, u = 0;
|
|
27
|
+
for (;;) {
|
|
28
|
+
t.place(u), l.steps++;
|
|
29
|
+
let d = Infinity;
|
|
30
|
+
for (let a = 0; a < o; a++) {
|
|
31
|
+
let o = s[a];
|
|
32
|
+
if (o === 0 && u > 0) continue;
|
|
33
|
+
let c = Infinity;
|
|
34
|
+
for (let o = 0; o < n.length; o++) {
|
|
35
|
+
let s = t.gap(a, n[o]) - r;
|
|
36
|
+
if (Number.isNaN(s)) throw e("A collider gave no finite clearance", "kinematics");
|
|
37
|
+
if (s < l.clearance && (l.clearance = s), s <= i) return l.time = u, l.shape = a, l.collider = o, l;
|
|
38
|
+
s < c && (c = s);
|
|
39
|
+
}
|
|
40
|
+
o > 0 && c / o < d && (d = c / o);
|
|
41
|
+
}
|
|
42
|
+
if (c) for (let n = 0; n < c.length; n += 2) {
|
|
43
|
+
let a = c[n], o = c[n + 1], f = s[a] + s[o];
|
|
44
|
+
if (f === 0 && u > 0) continue;
|
|
45
|
+
let p = t.pairGap(a, o) - r;
|
|
46
|
+
if (Number.isNaN(p)) throw e("A pair of shapes gave no finite clearance", "kinematics");
|
|
47
|
+
if (p < l.clearance && (l.clearance = p), p <= i) return l.time = u, l.shape = a, l.collider = -2 - o, l;
|
|
48
|
+
f > 0 && p / f < d && (d = p / f);
|
|
49
|
+
}
|
|
50
|
+
if (l.time = u, u >= 1 || d === Infinity) return l.time = 1, l.clear = !0, l;
|
|
51
|
+
if (l.steps >= a) return l.exhausted = !0, l;
|
|
52
|
+
u = Math.min(1, u + d);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/swept.ts
|
|
57
|
+
var l = {
|
|
58
|
+
pointA: /* @__PURE__ */ new Float64Array(3),
|
|
59
|
+
pointB: /* @__PURE__ */ new Float64Array(3),
|
|
60
|
+
distance: 0,
|
|
61
|
+
parameterA: 0,
|
|
62
|
+
parameterB: 0
|
|
63
|
+
}, u = /* @__PURE__ */ new Float64Array(1);
|
|
64
|
+
function d(e, r) {
|
|
65
|
+
if (!Array.isArray(e) || e.length < 2) throw t(`${r} must list at least two joint positions`, "kinematics");
|
|
66
|
+
let a = new Float64Array(e.length * 3);
|
|
67
|
+
return e.forEach((e, t) => {
|
|
68
|
+
n(e, `${r} joint ${t}`), i(e, a, t * 3);
|
|
69
|
+
}), a;
|
|
70
|
+
}
|
|
71
|
+
function f(n, r, i) {
|
|
72
|
+
let a = new Float64Array(r);
|
|
73
|
+
if (typeof n == "number") a.fill(n);
|
|
74
|
+
else if (Array.isArray(n) && n.length === r) a.set(n);
|
|
75
|
+
else throw t(`${i} must be a number or one number each for ${r}`, "kinematics");
|
|
76
|
+
for (let t of a) if (!(t >= 0) || !Number.isFinite(t)) throw e(`${i} must be 0 or more`, "kinematics");
|
|
77
|
+
return a;
|
|
78
|
+
}
|
|
79
|
+
function p(e, t, n, r, i) {
|
|
80
|
+
let a = e[t + 3] - e[t], o = e[t + 4] - e[t + 1], s = e[t + 5] - e[t + 2], c = Math.hypot(a, o, s);
|
|
81
|
+
r[i] = c, n[i * 3] = c > 0 ? a / c : 1, n[i * 3 + 1] = c > 0 ? o / c : 0, n[i * 3 + 2] = c > 0 ? s / c : 0;
|
|
82
|
+
}
|
|
83
|
+
function m(t, n, r, i) {
|
|
84
|
+
let { minClearance: a, tolerance: m, maxSteps: h } = s(i), g = d(t, "Sweep from"), _ = d(n, "Sweep to"), v = g.length / 3, y = v - 1;
|
|
85
|
+
if (_.length !== g.length) throw e("Sweep poses must have the same joints", "kinematics");
|
|
86
|
+
let b = f(i?.radius, y, "Sweep radius"), x = f(i?.jointRadius ?? 0, v, "Sweep jointRadius"), S = new Float64Array(y * 3), C = new Float64Array(y * 3), w = new Float64Array(y), T = new Float64Array(y), E = new Float64Array(y * 3), D = new Float64Array(y), O = [];
|
|
87
|
+
for (let e = 0; e < v; e++) x[e] > 0 && O.push(e);
|
|
88
|
+
let k = new Float64Array(y + O.length), A = Math.hypot(_[0] - g[0], _[1] - g[1], _[2] - g[2]), j = new Float64Array(v);
|
|
89
|
+
j[0] = A;
|
|
90
|
+
for (let e = 0; e < y; e++) {
|
|
91
|
+
p(g, e * 3, S, w, e), p(_, e * 3, C, T, e);
|
|
92
|
+
let t = e * 3, n = S[t], r = S[t + 1], i = S[t + 2], a = C[t], o = C[t + 1], s = C[t + 2], c = r * s - i * o, l = i * a - n * s, u = n * o - r * a, d = Math.hypot(c, l, u), f = n * a + r * o + i * s;
|
|
93
|
+
if (d < 1e-12 && f < 0) {
|
|
94
|
+
let e = Math.abs(n) < .7 ? 0 : 1;
|
|
95
|
+
c = e === 0 ? 0 : -i, l = e === 0 ? -i : 0, u = e === 0 ? r : n, d = Math.hypot(c, l, u);
|
|
96
|
+
}
|
|
97
|
+
D[e] = Math.atan2(Math.hypot(n * o - r * a, r * s - i * o, i * a - n * s), f), d > 0 && (E[t] = c / d, E[t + 1] = l / d, E[t + 2] = u / d);
|
|
98
|
+
let m = Math.max(w[e], T[e]);
|
|
99
|
+
j[e + 1] = j[e] + m * D[e] + Math.abs(T[e] - w[e]), k[e] = j[e + 1];
|
|
100
|
+
}
|
|
101
|
+
O.forEach((e, t) => {
|
|
102
|
+
k[y + t] = j[e];
|
|
103
|
+
});
|
|
104
|
+
let M = new Float64Array(v * 3);
|
|
105
|
+
return c({
|
|
106
|
+
count: k.length,
|
|
107
|
+
speed: k,
|
|
108
|
+
place(e) {
|
|
109
|
+
for (let t = 0; t < 3; t++) M[t] = g[t] + (_[t] - g[t]) * e;
|
|
110
|
+
for (let t = 0; t < y; t++) {
|
|
111
|
+
let n = t * 3, r = D[t] * e, i = Math.cos(r), a = Math.sin(r), o = E[n], s = E[n + 1], c = E[n + 2], l = S[n], u = S[n + 1], d = S[n + 2], f = w[t] + (T[t] - w[t]) * e, p = l * i + (s * d - c * u) * a, m = u * i + (c * l - o * d) * a, h = d * i + (o * u - s * l) * a;
|
|
112
|
+
M[n + 3] = M[n] + p * f, M[n + 4] = M[n + 1] + m * f, M[n + 5] = M[n + 2] + h * f;
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
gap(e, t) {
|
|
116
|
+
let n = e < y, r = n ? e * 3 : O[e - y] * 3, i = M.subarray(r, r + 3), a = n ? M.subarray(r + 3, r + 6) : i;
|
|
117
|
+
return o(t, i, a, n ? b[e] : x[O[e - y]], u, l), u[0];
|
|
118
|
+
}
|
|
119
|
+
}, r, a, m, h);
|
|
120
|
+
}
|
|
121
|
+
function h(n, r) {
|
|
122
|
+
if (!n || n.length !== 16) throw t(`${r} must have 16 values`, "kinematics");
|
|
123
|
+
let i = [
|
|
124
|
+
0,
|
|
125
|
+
1,
|
|
126
|
+
2
|
|
127
|
+
].map((e) => [
|
|
128
|
+
n[e * 4],
|
|
129
|
+
n[e * 4 + 1],
|
|
130
|
+
n[e * 4 + 2]
|
|
131
|
+
]), a = Float64Array.from(i, ([e, t, n]) => Math.hypot(e, t, n));
|
|
132
|
+
if (!(a[0] > 0 && a[1] > 0 && a[2] > 0 && a.every(Number.isFinite))) throw e(`${r} must have finite, non-zero axes`, "kinematics");
|
|
133
|
+
let [o, s, c] = i.map((e, t) => e.map((e) => e / a[t])), l = Math.abs(o[0] * s[0] + o[1] * s[1] + o[2] * s[2]) + Math.abs(o[0] * c[0] + o[1] * c[1] + o[2] * c[2]) + Math.abs(s[0] * c[0] + s[1] * c[1] + s[2] * c[2]), u = o[0] * (s[1] * c[2] - s[2] * c[1]) + o[1] * (s[2] * c[0] - s[0] * c[2]) + o[2] * (s[0] * c[1] - s[1] * c[0]);
|
|
134
|
+
if (l > 1e-6 || u < 0) throw e(`${r} must be a rotation, a positive scale and a move: no shear, no mirror`, "kinematics");
|
|
135
|
+
let d = o[0] + s[1] + c[2], f = /* @__PURE__ */ new Float64Array(4);
|
|
136
|
+
if (d > 0) {
|
|
137
|
+
let e = Math.sqrt(d + 1) * 2;
|
|
138
|
+
f[3] = e / 4, f[0] = (s[2] - c[1]) / e, f[1] = (c[0] - o[2]) / e, f[2] = (o[1] - s[0]) / e;
|
|
139
|
+
} else if (o[0] >= s[1] && o[0] >= c[2]) {
|
|
140
|
+
let e = Math.sqrt(1 + o[0] - s[1] - c[2]) * 2;
|
|
141
|
+
f[3] = (s[2] - c[1]) / e, f[0] = e / 4, f[1] = (o[1] + s[0]) / e, f[2] = (c[0] + o[2]) / e;
|
|
142
|
+
} else if (s[1] >= c[2]) {
|
|
143
|
+
let e = Math.sqrt(1 + s[1] - o[0] - c[2]) * 2;
|
|
144
|
+
f[3] = (c[0] - o[2]) / e, f[0] = (o[1] + s[0]) / e, f[1] = e / 4, f[2] = (s[2] + c[1]) / e;
|
|
145
|
+
} else {
|
|
146
|
+
let e = Math.sqrt(1 + c[2] - o[0] - s[1]) * 2;
|
|
147
|
+
f[3] = (o[1] - s[0]) / e, f[0] = (c[0] + o[2]) / e, f[1] = (s[2] + c[1]) / e, f[2] = e / 4;
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
translation: Float64Array.of(n[12], n[13], n[14]),
|
|
151
|
+
rotation: f,
|
|
152
|
+
scale: a
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function g(e, n, i, o, l) {
|
|
156
|
+
if (!(e instanceof a)) throw t("sweepHull needs a ConvexHullVolume", "kinematics");
|
|
157
|
+
let { minClearance: u, tolerance: d, maxSteps: f } = s(l), p = h(n, "Sweep from"), m = h(i, "Sweep to"), g = 0;
|
|
158
|
+
for (let e = 0; e < 4; e++) g += p.rotation[e] * m.rotation[e];
|
|
159
|
+
let _ = g < 0 ? -1 : 1, v = Math.acos(Math.min(1, Math.abs(g))), y = Math.sin(v), b = 0, x = 0, S = r(e);
|
|
160
|
+
for (let e = 0; e < S.length; e += 3) {
|
|
161
|
+
let t = S[e], n = S[e + 1], r = S[e + 2];
|
|
162
|
+
b = Math.max(b, Math.hypot(t * p.scale[0], n * p.scale[1], r * p.scale[2]), Math.hypot(t * m.scale[0], n * m.scale[1], r * m.scale[2])), x = Math.max(x, Math.hypot(t * (m.scale[0] - p.scale[0]), n * (m.scale[1] - p.scale[1]), r * (m.scale[2] - p.scale[2])));
|
|
163
|
+
}
|
|
164
|
+
let C = Math.hypot(m.translation[0] - p.translation[0], m.translation[1] - p.translation[1], m.translation[2] - p.translation[2]), w = Float64Array.of(C + 2 * v * b + x), T = /* @__PURE__ */ new Float64Array(16), E = /* @__PURE__ */ new Float64Array(4), D = /* @__PURE__ */ new Float64Array(1);
|
|
165
|
+
T[15] = 1;
|
|
166
|
+
let O = c({
|
|
167
|
+
count: 1,
|
|
168
|
+
speed: w,
|
|
169
|
+
place(t) {
|
|
170
|
+
let n = y > 1e-9 ? Math.sin((1 - t) * v) / y : 1 - t, r = (y > 1e-9 ? Math.sin(t * v) / y : t) * _;
|
|
171
|
+
for (let e = 0; e < 4; e++) E[e] = p.rotation[e] * n + m.rotation[e] * r;
|
|
172
|
+
let i = Math.hypot(E[0], E[1], E[2], E[3]), a = E[0] / i, o = E[1] / i, s = E[2] / i, c = E[3] / i, l = p.scale[0] + (m.scale[0] - p.scale[0]) * t, u = p.scale[1] + (m.scale[1] - p.scale[1]) * t, d = p.scale[2] + (m.scale[2] - p.scale[2]) * t;
|
|
173
|
+
T[0] = (1 - 2 * (o * o + s * s)) * l, T[1] = 2 * (a * o + c * s) * l, T[2] = 2 * (a * s - c * o) * l, T[4] = 2 * (a * o - c * s) * u, T[5] = (1 - 2 * (a * a + s * s)) * u, T[6] = 2 * (o * s + c * a) * u, T[8] = 2 * (a * s + c * o) * d, T[9] = 2 * (o * s - c * a) * d, T[10] = (1 - 2 * (a * a + o * o)) * d;
|
|
174
|
+
for (let e = 0; e < 3; e++) T[12 + e] = p.translation[e] + (m.translation[e] - p.translation[e]) * t;
|
|
175
|
+
e.setTransform(T);
|
|
176
|
+
},
|
|
177
|
+
gap(n, r) {
|
|
178
|
+
if (!r.hullClearanceInto) throw t("sweepHull needs colliders with hullClearanceInto", "kinematics");
|
|
179
|
+
return r.hullClearanceInto(e, D), D[0];
|
|
180
|
+
}
|
|
181
|
+
}, o, u, d, f);
|
|
182
|
+
return e.setTransform(i), O;
|
|
183
|
+
}
|
|
184
|
+
//#endregion
|
|
185
|
+
export { m as sweepChain, g as sweepHull };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ConvexHullVolume } from './hull.js';
|
|
2
|
+
/** A three-component vector in the caller's common coordinate frame. */
|
|
3
|
+
export type Vec3View = readonly [number, number, number] | Float32Array | Float64Array;
|
|
4
|
+
/** Writable, caller-owned vector storage. Only vectors of length three are accepted. */
|
|
5
|
+
export type MutableVec3View = [number, number, number] | Float32Array | Float64Array;
|
|
6
|
+
/** Geometry used by the constraint solver, independent of any scene or rig. */
|
|
7
|
+
export interface ConstraintVolume {
|
|
8
|
+
/** Signed distance to the surface: negative inside, positive outside. */
|
|
9
|
+
evaluate(point: Vec3View, outSurface: MutableVec3View, outNormal: MutableVec3View): number;
|
|
10
|
+
/** Signed clearance between a swept segment and this volume. */
|
|
11
|
+
segmentClearance(start: Vec3View, end: Vec3View, radius: number): number;
|
|
12
|
+
/** Optional form of `evaluate` that writes the distance to `outDistance[0]`; the solver prefers it. */
|
|
13
|
+
evaluateInto?(point: Vec3View, outSurface: MutableVec3View, outNormal: MutableVec3View, outDistance: Float64Array): void;
|
|
14
|
+
/** Optional form of `segmentClearance` that writes the gap to `outDistance[0]`; the solver prefers it. */
|
|
15
|
+
segmentClearanceInto?(start: Vec3View, end: Vec3View, radius: number, outDistance: Float64Array): void;
|
|
16
|
+
/**
|
|
17
|
+
* Signed gap to a convex hull, written to `outDistance[0]`. A solver with link hulls needs this on every collider;
|
|
18
|
+
* spheres, capsules and hulls have it.
|
|
19
|
+
*/
|
|
20
|
+
hullClearanceInto?(hull: ConvexHullVolume, outDistance: Float64Array): void;
|
|
21
|
+
}
|
|
22
|
+
/** Fixed-arity norm; avoids variadic builtin boxing while retaining tiny/large ranges. */
|
|
23
|
+
export declare function length3(x: number, y: number, z: number): number;
|
|
24
|
+
/** The slow path of length3, for squared lengths too small or too large for a double. */
|
|
25
|
+
export declare function scaledLength3(x: number, y: number, z: number): number;
|
|
26
|
+
export declare function validateNonNegative(value: number, name?: string): void;
|
|
27
|
+
export declare function validatePositive(value: number, name?: string): void;
|
|
28
|
+
/** Copies a three-component vector to `into` at element `at`. */
|
|
29
|
+
export declare function readVector(from: Vec3View, into: Float64Array, at: number): void;
|
|
30
|
+
/** Copies three elements of `from` at element `at` to a vector. */
|
|
31
|
+
export declare function writeVector(out: MutableVec3View, from: Float64Array, at: number): void;
|
|
32
|
+
export { validateVector } from './shared/validate-vector.js';
|
|
33
|
+
export declare function validateOutputVector(value: MutableVec3View, name?: string): void;
|
|
34
|
+
/** Reject impossible simultaneous outputs, including overlapping typed-array views. */
|
|
35
|
+
export declare function validateDistinctOutputs(a: MutableVec3View, b: MutableVec3View): void;
|
|
36
|
+
export declare function validateOutputValues(out: MutableVec3View, x: number, y: number, z: number): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region ../shared/validate-vector.js
|
|
2
|
+
var e = 1e100, t = /* @__PURE__ */ new Float64Array(3);
|
|
3
|
+
function n(n, r = "vector") {
|
|
4
|
+
if (n instanceof Float64Array && n.length === 3) t[0] = n[0], t[1] = n[1], t[2] = n[2];
|
|
5
|
+
else if (n instanceof Float32Array && n.length === 3) t[0] = n[0], t[1] = n[1], t[2] = n[2];
|
|
6
|
+
else if (Array.isArray(n) && n.length === 3) {
|
|
7
|
+
let e = n[0], i = n[1], a = n[2];
|
|
8
|
+
if (typeof e != "number" || typeof i != "number" || typeof a != "number") throw RangeError(`${r} must be finite with magnitude at most 1e100`);
|
|
9
|
+
t[0] = e, t[1] = i, t[2] = a;
|
|
10
|
+
} else throw TypeError(`${r} must have three components`);
|
|
11
|
+
let i = t[0], a = t[1], o = t[2];
|
|
12
|
+
if (!(i <= e && i >= -1e100 && a <= e && a >= -1e100) || !(o <= e && o >= -1e100)) throw RangeError(`${r} must be finite with magnitude at most 1e100`);
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { n as t };
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { r as e } from "./errors-D5_2oB8I.js";
|
|
2
|
+
import { t } from "./validate-vector-7JTvvTtJ.js";
|
|
3
|
+
import { d as n, f as r, l as i, m as a, u as o } from "./hull-RrgFbmB9.js";
|
|
4
|
+
//#region src/volumes.ts
|
|
5
|
+
function s(e, t, n) {
|
|
6
|
+
return Math.max(t, Math.min(n, e));
|
|
7
|
+
}
|
|
8
|
+
function c(e, t, n, r) {
|
|
9
|
+
let i = Math.max(Math.abs(e), Math.abs(t), Math.abs(n));
|
|
10
|
+
if (i === 0) return 0;
|
|
11
|
+
let a = e / i, o = t / i, s = n / i;
|
|
12
|
+
return l(i, Math.sqrt(a * a + o * o + s * s), r);
|
|
13
|
+
}
|
|
14
|
+
function l(e, t, n) {
|
|
15
|
+
return e < 2 ** -1022 ? e * n * t : e * t * n;
|
|
16
|
+
}
|
|
17
|
+
function u() {
|
|
18
|
+
return {
|
|
19
|
+
pointA: [
|
|
20
|
+
0,
|
|
21
|
+
0,
|
|
22
|
+
0
|
|
23
|
+
],
|
|
24
|
+
pointB: [
|
|
25
|
+
0,
|
|
26
|
+
0,
|
|
27
|
+
0
|
|
28
|
+
],
|
|
29
|
+
distance: 0,
|
|
30
|
+
parameterA: 0,
|
|
31
|
+
parameterB: 0
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function d(e, n, a, o, s) {
|
|
35
|
+
t(e, "segment start"), t(n, "segment end"), t(a, "segment start"), t(o, "segment end");
|
|
36
|
+
let c = s ?? u();
|
|
37
|
+
r(c.pointA), r(c.pointB), i(c.pointA, c.pointB);
|
|
38
|
+
let l = e[0], d = e[1], f = e[2], p = n[0], m = n[1], h = n[2], g = a[0], _ = a[1], v = a[2], y = o[0], b = o[1], x = o[2], S = p - l, C = m - d, w = h - f, T = y - g, E = b - _, D = x - v, O = l - g, k = d - _, A = f - v, j = Math.max(Math.abs(S), Math.abs(C), Math.abs(w), Math.abs(T), Math.abs(E), Math.abs(D), Math.abs(O), Math.abs(k), Math.abs(A));
|
|
39
|
+
j > 0 && (S /= j, C /= j, w /= j, T /= j, E /= j, D /= j, O /= j, k /= j, A /= j);
|
|
40
|
+
let M = S, N = C, P = w, F = T, I = E, L = D, R = S * S + C * C + w * w, z = T * T + E * E + D * D, B = Math.sqrt(R), V = Math.sqrt(z);
|
|
41
|
+
if (!(R >= 1e-300 && R < Infinity)) {
|
|
42
|
+
let e = Math.max(Math.abs(S), Math.abs(C), Math.abs(w));
|
|
43
|
+
B = e === 0 ? 0 : e * Math.sqrt(S / e * (S / e) + C / e * (C / e) + w / e * (w / e));
|
|
44
|
+
}
|
|
45
|
+
if (!(z >= 1e-300 && z < Infinity)) {
|
|
46
|
+
let e = Math.max(Math.abs(T), Math.abs(E), Math.abs(D));
|
|
47
|
+
V = e === 0 ? 0 : e * Math.sqrt(T / e * (T / e) + E / e * (E / e) + D / e * (D / e));
|
|
48
|
+
}
|
|
49
|
+
let H = Math.max(Math.abs(S), Math.abs(C), Math.abs(w)), U = Math.max(Math.abs(T), Math.abs(E), Math.abs(D));
|
|
50
|
+
if (H > 0) {
|
|
51
|
+
S /= H, C /= H, w /= H;
|
|
52
|
+
let e = Math.sqrt(S * S + C * C + w * w);
|
|
53
|
+
S /= e, C /= e, w /= e;
|
|
54
|
+
}
|
|
55
|
+
if (U > 0) {
|
|
56
|
+
T /= U, E /= U, D /= U;
|
|
57
|
+
let e = Math.sqrt(T * T + E * E + D * D);
|
|
58
|
+
T /= e, E /= e, D /= e;
|
|
59
|
+
}
|
|
60
|
+
let W = 0, G = 0, K = S * O + C * k + w * A, q = T * O + E * k + D * A;
|
|
61
|
+
if (B === 0) V > 0 && (G = Math.max(0, Math.min(V, q)));
|
|
62
|
+
else if (V === 0) W = Math.max(0, Math.min(B, -K));
|
|
63
|
+
else {
|
|
64
|
+
let e = Math.max(-1, Math.min(1, S * T + C * E + w * D)), t = C * D - w * E, n = w * T - S * D, r = S * E - C * T, i = Math.max(Math.abs(t), Math.abs(n), Math.abs(r));
|
|
65
|
+
if (i > 0) {
|
|
66
|
+
let e = t / i, a = n / i, o = r / i, s = Math.sqrt(e * e + a * a + o * o), c = Math.max(Math.abs(O), Math.abs(k), Math.abs(A));
|
|
67
|
+
if (c > 0) {
|
|
68
|
+
let e = O / c, a = k / c, o = A / c, l = a * D - o * E, u = o * T - e * D, d = e * E - a * T, f = l * (t / i / s) + u * (n / i / s) + d * (r / i / s);
|
|
69
|
+
W = f === 0 ? 0 : Math.max(0, Math.min(B, -(f / s) * (c / i)));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
G = e * W + q, G < 0 ? (G = 0, W = Math.max(0, Math.min(B, -K))) : G > V && (G = V, W = Math.max(0, Math.min(B, e * V - K)));
|
|
73
|
+
}
|
|
74
|
+
let J = B > 0 ? W / B : 0, Y = V > 0 ? G / V : 0, X = J > .5 ? p + (l - p) * (1 - J) : l + (p - l) * J, Z = J > .5 ? m + (d - m) * (1 - J) : d + (m - d) * J, Q = J > .5 ? h + (f - h) * (1 - J) : f + (h - f) * J, ee = Y > .5 ? y + (g - y) * (1 - Y) : g + (y - g) * Y, te = Y > .5 ? b + (_ - b) * (1 - Y) : _ + (b - _) * Y, ne = Y > .5 ? x + (v - x) * (1 - Y) : v + (x - v) * Y;
|
|
75
|
+
if (!Number.isFinite(X) || !Number.isFinite(Z) || !Number.isFinite(Q) || !Number.isFinite(ee) || !Number.isFinite(te) || !Number.isFinite(ne) || c.pointA instanceof Float32Array && (Math.abs(X) > 34028234663852886e22 || Math.abs(Z) > 34028234663852886e22 || Math.abs(Q) > 34028234663852886e22) || c.pointB instanceof Float32Array && (Math.abs(ee) > 34028234663852886e22 || Math.abs(te) > 34028234663852886e22 || Math.abs(ne) > 34028234663852886e22)) throw RangeError("Result exceeds output precision; scale the scene down or move it nearer the origin");
|
|
76
|
+
c.pointA[0] = X, c.pointA[1] = Z, c.pointA[2] = Q, c.pointB[0] = ee, c.pointB[1] = te, c.pointB[2] = ne;
|
|
77
|
+
let re = O + M * J - F * Y, ie = k + N * J - I * Y, ae = A + P * J - L * Y, $ = Math.max(Math.abs(re), Math.abs(ie), Math.abs(ae)), oe = 0;
|
|
78
|
+
if ($ > 0) {
|
|
79
|
+
let e = re / $, t = ie / $, n = ae / $, r = Math.sqrt(e * e + t * t + n * n);
|
|
80
|
+
oe = $ < 2 ** -1022 ? $ * j * r : $ * r * j;
|
|
81
|
+
}
|
|
82
|
+
return c.distance = oe, c.parameterA = J, c.parameterB = Y, c;
|
|
83
|
+
}
|
|
84
|
+
function f(e, n, a) {
|
|
85
|
+
t(e, "query point"), r(n, "surface output"), r(a, "normal output"), i(n, a);
|
|
86
|
+
}
|
|
87
|
+
function p(e, t, r, i, a, o, s, c, l) {
|
|
88
|
+
let u = r + o * l, d = i + s * l, f = a + c * l;
|
|
89
|
+
n(e, u, d, f), e[0] = u, e[1] = d, e[2] = f, t[0] = o, t[1] = s, t[2] = c;
|
|
90
|
+
}
|
|
91
|
+
var m = /* @__PURE__ */ new Float64Array(6);
|
|
92
|
+
function h(e, t) {
|
|
93
|
+
let n = m[0], r = m[1], i = m[2];
|
|
94
|
+
if (!Number.isFinite(n) || !Number.isFinite(r) || !Number.isFinite(i) || e instanceof Float32Array && (Math.abs(n) > 34028234663852886e22 || Math.abs(r) > 34028234663852886e22 || Math.abs(i) > 34028234663852886e22)) throw RangeError("Result exceeds output precision; scale the scene down or move it nearer the origin");
|
|
95
|
+
a(e, m, 0), a(t, m, 3);
|
|
96
|
+
}
|
|
97
|
+
var g = /* @__PURE__ */ new Float64Array(1);
|
|
98
|
+
function _(e, n, r, i, a) {
|
|
99
|
+
t(e.center, "sphere center"), o(e.radius, "sphere radius"), f(n, r, i);
|
|
100
|
+
let s = e.center[0], c = e.center[1], l = e.center[2], u = e.radius, d = n[0] - s, m = n[1] - c, h = n[2] - l, g = Math.max(Math.abs(d), Math.abs(m), Math.abs(h)), _ = 0;
|
|
101
|
+
if (g > 0) {
|
|
102
|
+
d /= g, m /= g, h /= g;
|
|
103
|
+
let e = Math.sqrt(d * d + m * m + h * h);
|
|
104
|
+
_ = g * e, d /= e, m /= e, h /= e;
|
|
105
|
+
} else d = 1, m = 0, h = 0;
|
|
106
|
+
p(r, i, s, c, l, d, m, h, u), a[0] = _ - u;
|
|
107
|
+
}
|
|
108
|
+
function v(e, n, r, i, a) {
|
|
109
|
+
t(e.start, "capsule start"), t(e.end, "capsule end"), e.radius >= 0 && e.radius <= 1e100 || o(e.radius, "capsule radius"), f(n, r, i);
|
|
110
|
+
let s = n[0], c = n[1], l = n[2], u = e.start[0], d = e.start[1], p = e.start[2], g = e.radius, _ = e.end[0] - u, v = e.end[1] - d, y = e.end[2] - p, b = s - u, x = c - d, S = l - p, C = Math.max(Math.abs(_), Math.abs(v), Math.abs(y)), w = C > 0 ? _ / C : 0, T = C > 0 ? v / C : 0, E = C > 0 ? y / C : 0, D = Math.sqrt(w * w + T * T + E * E), O = C * D;
|
|
111
|
+
D > 0 && (w /= D, T /= D, E /= D);
|
|
112
|
+
let k = Math.max(C, Math.abs(b), Math.abs(x), Math.abs(S)), A = k > 0 ? b / k : 0, j = k > 0 ? x / k : 0, M = k > 0 ? S / k : 0, N = k > 0 ? C / k * D : 0, P = N > 0 ? Math.max(0, Math.min(1, (A * w + j * T + M * E) / N)) : 0, F = e.end[0], I = e.end[1], L = e.end[2], R = P > .5 ? F + (u - F) * (1 - P) : u + (F - u) * P, z = P > .5 ? I + (d - I) * (1 - P) : d + (I - d) * P, B = P > .5 ? L + (p - L) * (1 - P) : p + (L - p) * P, V = A - (k > 0 ? _ / k : 0) * P, H = j - (k > 0 ? v / k : 0) * P, U = M - (k > 0 ? y / k : 0) * P, W = Math.max(Math.abs(V), Math.abs(H), Math.abs(U));
|
|
113
|
+
W > 0 && (V /= W, H /= W, U /= W);
|
|
114
|
+
let G = Math.sqrt(V * V + H * H + U * U), K = W < 2 ** -1022 ? W * k * G : W * G * k, q = 2 ** -52 * 8 * Math.max(O, Math.abs(s), Math.abs(c), Math.abs(l), Math.abs(R), Math.abs(z), Math.abs(B));
|
|
115
|
+
if (G > 0 && (K > q || O === 0)) V /= G, H /= G, U /= G;
|
|
116
|
+
else if (O > 0) {
|
|
117
|
+
Math.abs(w) <= Math.abs(T) && Math.abs(w) <= Math.abs(E) ? (V = 0, H = E, U = -T) : Math.abs(T) <= Math.abs(E) ? (V = -E, H = 0, U = w) : (V = T, H = -w, U = 0);
|
|
118
|
+
let e = Math.sqrt(V * V + H * H + U * U);
|
|
119
|
+
V /= e, H /= e, U /= e;
|
|
120
|
+
} else V = 1, H = 0, U = 0;
|
|
121
|
+
m[0] = R + V * g, m[1] = z + H * g, m[2] = B + U * g, m[3] = V, m[4] = H, m[5] = U, h(r, i), a[0] = K - g;
|
|
122
|
+
}
|
|
123
|
+
function y(e, n, r, i, a) {
|
|
124
|
+
t(e.center, "sphere center"), o(e.radius, "sphere radius"), t(n, "segment start"), t(r, "segment end"), o(i, "segment radius");
|
|
125
|
+
let l = r[0] - n[0], u = r[1] - n[1], d = r[2] - n[2], f = e.center[0] - n[0], p = e.center[1] - n[1], m = e.center[2] - n[2], h = Math.max(Math.abs(l), Math.abs(u), Math.abs(d), Math.abs(f), Math.abs(p), Math.abs(m)), g = 0;
|
|
126
|
+
if (h > 0) {
|
|
127
|
+
let e = l / h, t = u / h, n = d / h, r = f / h, i = p / h, a = m / h, o = Math.max(Math.abs(e), Math.abs(t), Math.abs(n)), _ = 0;
|
|
128
|
+
if (o > 0) {
|
|
129
|
+
let c = e / o, l = t / o, u = n / o;
|
|
130
|
+
_ = s((r * c + i * l + a * u) / o / (c * c + l * l + u * u), 0, 1);
|
|
131
|
+
}
|
|
132
|
+
g = c(r - e * _, i - t * _, a - n * _, h);
|
|
133
|
+
}
|
|
134
|
+
a[0] = g - e.radius - i;
|
|
135
|
+
}
|
|
136
|
+
var b = "A volume with an overridden segmentClearance must override hullClearanceInto for link hulls", x = class {
|
|
137
|
+
constructor(e) {
|
|
138
|
+
this.center = [
|
|
139
|
+
0,
|
|
140
|
+
0,
|
|
141
|
+
0
|
|
142
|
+
], this.radius = 0, this.set(e.center, e.radius);
|
|
143
|
+
}
|
|
144
|
+
set(e, n = this.radius) {
|
|
145
|
+
t(e, "sphere center"), o(n, "sphere radius");
|
|
146
|
+
let r = e[0], i = e[1], a = e[2];
|
|
147
|
+
return this.center[0] = r, this.center[1] = i, this.center[2] = a, this.radius = n, this;
|
|
148
|
+
}
|
|
149
|
+
evaluate(e, t, n) {
|
|
150
|
+
return _(this, e, t, n, g), g[0];
|
|
151
|
+
}
|
|
152
|
+
segmentClearance(e, t, n) {
|
|
153
|
+
return y(this, e, t, n, g), g[0];
|
|
154
|
+
}
|
|
155
|
+
hullClearanceInto(t, n) {
|
|
156
|
+
if (this.segmentClearance !== D) throw e(b, "kinematics");
|
|
157
|
+
o(this.radius, "sphere radius"), t.segmentClearanceInto(this.center, this.center, this.radius, n);
|
|
158
|
+
}
|
|
159
|
+
}, S = class {
|
|
160
|
+
constructor(e) {
|
|
161
|
+
this.start = [
|
|
162
|
+
0,
|
|
163
|
+
0,
|
|
164
|
+
0
|
|
165
|
+
], this.end = [
|
|
166
|
+
0,
|
|
167
|
+
0,
|
|
168
|
+
0
|
|
169
|
+
], this.radius = 0, this.segmentResult = u(), this.set(e.start, e.end, e.radius);
|
|
170
|
+
}
|
|
171
|
+
set(e, n, r = this.radius) {
|
|
172
|
+
t(e, "capsule start"), t(n, "capsule end"), o(r, "capsule radius");
|
|
173
|
+
let i = e[0], a = e[1], s = e[2], c = n[0], l = n[1], u = n[2];
|
|
174
|
+
return this.start[0] = i, this.start[1] = a, this.start[2] = s, this.end[0] = c, this.end[1] = l, this.end[2] = u, this.radius = r, this;
|
|
175
|
+
}
|
|
176
|
+
evaluate(e, t, n) {
|
|
177
|
+
return v(this, e, t, n, g), g[0];
|
|
178
|
+
}
|
|
179
|
+
segmentClearance(e, t, n) {
|
|
180
|
+
return o(this.radius, "capsule radius"), o(n, "segment radius"), d(e, t, this.start, this.end, this.segmentResult).distance - this.radius - n;
|
|
181
|
+
}
|
|
182
|
+
hullClearanceInto(t, n) {
|
|
183
|
+
if (this.segmentClearance !== O) throw e(b, "kinematics");
|
|
184
|
+
o(this.radius, "capsule radius"), t.segmentClearanceInto(this.start, this.end, this.radius, n);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
function C(e) {
|
|
188
|
+
return e.prototype.evaluate;
|
|
189
|
+
}
|
|
190
|
+
var w = /* @__PURE__ */ C(x), T = /* @__PURE__ */ C(S);
|
|
191
|
+
function E(e) {
|
|
192
|
+
return e.prototype.segmentClearance;
|
|
193
|
+
}
|
|
194
|
+
var D = /* @__PURE__ */ E(x), O = /* @__PURE__ */ E(S);
|
|
195
|
+
function k(e, t, n, r, i) {
|
|
196
|
+
let a = e.evaluate;
|
|
197
|
+
if (e instanceof S && a === T) v(e, t, n, r, i);
|
|
198
|
+
else if (e instanceof x && a === w) _(e, t, n, r, i);
|
|
199
|
+
else if (e.evaluateInto) e.evaluateInto(t, n, r, i);
|
|
200
|
+
else {
|
|
201
|
+
let o = a.call(e, t, n, r);
|
|
202
|
+
i[0] = Number.isFinite(o) ? o : NaN;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function A(e, t, n, r, i, a) {
|
|
206
|
+
let s = e.segmentClearance;
|
|
207
|
+
if (e instanceof S && s === O) e.radius >= 0 && e.radius <= 1e100 || o(e.radius, "capsule radius"), r >= 0 && r <= 1e100 || o(r, "segment radius"), i[0] = d(t, n, e.start, e.end, a).distance - e.radius - r;
|
|
208
|
+
else if (e instanceof x && s === D) y(e, t, n, r, i);
|
|
209
|
+
else if (e.segmentClearanceInto) e.segmentClearanceInto(t, n, r, i);
|
|
210
|
+
else {
|
|
211
|
+
let a = s.call(e, t, n, r);
|
|
212
|
+
i[0] = Number.isFinite(a) ? a : NaN;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
function j(e, n, r, i) {
|
|
216
|
+
return t(e, "segment start"), t(n, "segment end"), o(r, "segment radius"), i.segmentClearance(e, n, r);
|
|
217
|
+
}
|
|
218
|
+
//#endregion
|
|
219
|
+
export { j as a, k as i, x as n, A as o, d as r, S as t };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ConvexHullVolume } from './hull.js';
|
|
2
|
+
import type { ConstraintVolume, MutableVec3View, Vec3View } from './types.js';
|
|
3
|
+
/** Closest points between two segments, their distance and the parameter of each point along its segment. */
|
|
4
|
+
export interface SegmentDistanceResult {
|
|
5
|
+
pointA: MutableVec3View;
|
|
6
|
+
pointB: MutableVec3View;
|
|
7
|
+
distance: number;
|
|
8
|
+
parameterA: number;
|
|
9
|
+
parameterB: number;
|
|
10
|
+
}
|
|
11
|
+
/** A sphere collider: its centre and radius in scene units. */
|
|
12
|
+
export interface SphereVolumeOptions {
|
|
13
|
+
center: Vec3View;
|
|
14
|
+
radius: number;
|
|
15
|
+
}
|
|
16
|
+
/** A capsule collider: the two end points of its axis and its radius in scene units. */
|
|
17
|
+
export interface CapsuleVolumeOptions {
|
|
18
|
+
start: Vec3View;
|
|
19
|
+
end: Vec3View;
|
|
20
|
+
radius: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Closest points on two closed line segments. Supply `out` to reuse storage.
|
|
24
|
+
* Inputs may alias output points; the two output points must be distinct.
|
|
25
|
+
*/
|
|
26
|
+
export declare function closestPointsBetweenSegments(a: Vec3View, b: Vec3View, c: Vec3View, d: Vec3View, out?: SegmentDistanceResult): SegmentDistanceResult;
|
|
27
|
+
/** A sphere in a caller-selected coordinate frame. */
|
|
28
|
+
export declare class SphereVolume implements ConstraintVolume {
|
|
29
|
+
readonly center: [number, number, number];
|
|
30
|
+
radius: number;
|
|
31
|
+
constructor(options: SphereVolumeOptions);
|
|
32
|
+
/** Atomically copy a moving sphere's center and radius. */
|
|
33
|
+
set(center: Vec3View, radius?: number): this;
|
|
34
|
+
evaluate(point: Vec3View, outSurface: MutableVec3View, outNormal: MutableVec3View): number;
|
|
35
|
+
segmentClearance(start: Vec3View, end: Vec3View, radius: number): number;
|
|
36
|
+
/** Signed gap to a convex hull, written to `outDistance[0]`. A subclass that changes the geometry overrides this. */
|
|
37
|
+
hullClearanceInto(hull: ConvexHullVolume, outDistance: Float64Array): void;
|
|
38
|
+
}
|
|
39
|
+
/** A segment swept by a sphere; a zero-length segment is a sphere. */
|
|
40
|
+
export declare class CapsuleVolume implements ConstraintVolume {
|
|
41
|
+
readonly start: [number, number, number];
|
|
42
|
+
readonly end: [number, number, number];
|
|
43
|
+
radius: number;
|
|
44
|
+
private readonly segmentResult;
|
|
45
|
+
constructor(options: CapsuleVolumeOptions);
|
|
46
|
+
/** Atomically copy a moving capsule, including when its endpoint inputs alias. */
|
|
47
|
+
set(start: Vec3View, end: Vec3View, radius?: number): this;
|
|
48
|
+
evaluate(point: Vec3View, outSurface: MutableVec3View, outNormal: MutableVec3View): number;
|
|
49
|
+
segmentClearance(start: Vec3View, end: Vec3View, radius: number): number;
|
|
50
|
+
/** Signed gap to a convex hull, written to `outDistance[0]`. A subclass that changes the geometry overrides this. */
|
|
51
|
+
hullClearanceInto(hull: ConvexHullVolume, outDistance: Float64Array): void;
|
|
52
|
+
}
|
|
53
|
+
/** @internal Destination passing for unchanged built-ins; custom methods retain their contract. */
|
|
54
|
+
export declare function evaluateVolumeInto(volume: ConstraintVolume, point: Vec3View, outSurface: MutableVec3View, outNormal: MutableVec3View, outDistance: Float64Array): void;
|
|
55
|
+
/** @internal Reuse both scalar and closest-point storage for built-in link checks. */
|
|
56
|
+
export declare function segmentVolumeInto(volume: ConstraintVolume, start: Vec3View, end: Vec3View, radius: number, outDistance: Float64Array, segmentResult: SegmentDistanceResult): void;
|
|
57
|
+
/** Signed clearance of a swept segment against any compatible proxy volume. */
|
|
58
|
+
export declare function measureSegmentClearance(start: Vec3View, end: Vec3View, radius: number, volume: ConstraintVolume): number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,79 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@margoengine/kinematics-constraints",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Standalone analytical capsule, sphere and convex hull constraints for IK target and arm clearance.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"margoengine",
|
|
7
|
+
"webgpu",
|
|
8
|
+
"3d",
|
|
9
|
+
"kinematics",
|
|
10
|
+
"constraints"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://margoengine.com",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/scottcampbelldata/margoengine/issues"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/scottcampbelldata/margoengine.git",
|
|
19
|
+
"directory": "packages/kinematics-constraints"
|
|
20
|
+
},
|
|
21
|
+
"license": "Apache-2.0",
|
|
22
|
+
"author": "Scott Campbell",
|
|
23
|
+
"type": "module",
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./joint-limits": {
|
|
31
|
+
"types": "./dist/joint-limits.d.ts",
|
|
32
|
+
"import": "./dist/joint-limits.js"
|
|
33
|
+
},
|
|
34
|
+
"./chain": {
|
|
35
|
+
"types": "./dist/chain.d.ts",
|
|
36
|
+
"import": "./dist/chain.js"
|
|
37
|
+
},
|
|
38
|
+
"./swept": {
|
|
39
|
+
"types": "./dist/swept.d.ts",
|
|
40
|
+
"import": "./dist/swept.js"
|
|
41
|
+
},
|
|
42
|
+
"./sdf": {
|
|
43
|
+
"types": "./dist/sdf.d.ts",
|
|
44
|
+
"import": "./dist/sdf.js"
|
|
45
|
+
},
|
|
46
|
+
"./multi-goal": {
|
|
47
|
+
"types": "./dist/multi-goal.d.ts",
|
|
48
|
+
"import": "./dist/multi-goal.js"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"files": [
|
|
52
|
+
"dist",
|
|
53
|
+
"LICENSE",
|
|
54
|
+
"NOTICE"
|
|
55
|
+
],
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"test:gpu:multi-goal": "cd ../.. && node packages/kinematics-constraints/tests/multi-goal-browser.mjs",
|
|
61
|
+
"build": "node ../../scripts/build-optional.js kinematics-constraints",
|
|
62
|
+
"test": "npm run build && node --test tests/*.test.js",
|
|
63
|
+
"test:browser": "node ../../scripts/test-kinematics-constraints-browser.js",
|
|
64
|
+
"test:limits:browser": "cd ../.. && node packages/kinematics-constraints/tests/limits-browser.mjs",
|
|
65
|
+
"prepack": "npm run build"
|
|
66
|
+
},
|
|
67
|
+
"peerDependencies": {
|
|
68
|
+
"@margoengine/bvh": "^1.0.0",
|
|
69
|
+
"@margoengine/geometry": "^1.0.0"
|
|
70
|
+
},
|
|
71
|
+
"peerDependenciesMeta": {
|
|
72
|
+
"@margoengine/bvh": {
|
|
73
|
+
"optional": true
|
|
74
|
+
},
|
|
75
|
+
"@margoengine/geometry": {
|
|
76
|
+
"optional": true
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|