@margoengine/kinematics-constraints 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +441 -3
- 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 +79 -6
package/dist/index.js
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { n as e, r as t, t as n } from "./errors-D5_2oB8I.js";
|
|
2
|
+
import { t as r } from "./validate-vector-7JTvvTtJ.js";
|
|
3
|
+
import { c as i, o as a, p as o, s, t as c, u as l } from "./hull-RrgFbmB9.js";
|
|
4
|
+
import { a as u, i as d, n as f, o as p, r as m, t as h } from "./volumes-CpBBobtO.js";
|
|
5
|
+
//#region src/AvoidanceSolver.ts
|
|
6
|
+
var g = /* @__PURE__ */ function(e) {
|
|
7
|
+
return e[e.Success = 0] = "Success", e[e.SwivelRateLimitExceeded = 1] = "SwivelRateLimitExceeded", e[e.SingularDeadZone = 2] = "SingularDeadZone", e[e.ObstacleOccluded = 3] = "ObstacleOccluded", e;
|
|
8
|
+
}({}), _ = Object.freeze({});
|
|
9
|
+
function v(e, t, n) {
|
|
10
|
+
if (!Number.isSafeInteger(e) || e < 0 || e > t) throw RangeError(n);
|
|
11
|
+
}
|
|
12
|
+
function y(n) {
|
|
13
|
+
if (!n) return null;
|
|
14
|
+
let i = n.hull;
|
|
15
|
+
if (!i || typeof i.setTransform != "function") throw t("A link hull must be a ConvexHullVolume", "kinematics");
|
|
16
|
+
let o = n.origin ?? [
|
|
17
|
+
0,
|
|
18
|
+
0,
|
|
19
|
+
0
|
|
20
|
+
], s = n.axis ?? [
|
|
21
|
+
0,
|
|
22
|
+
1,
|
|
23
|
+
0
|
|
24
|
+
], c = n.hinge ?? [
|
|
25
|
+
1,
|
|
26
|
+
0,
|
|
27
|
+
0
|
|
28
|
+
];
|
|
29
|
+
r(o, "link hull origin"), r(s, "link hull axis"), r(c, "link hull hinge");
|
|
30
|
+
let l = a(s[0], s[1], s[2]), u = s[0] / l, d = s[1] / l, f = s[2] / l, p = c[0] * u + c[1] * d + c[2] * f, m = c[0] - u * p, h = c[1] - d * p, g = c[2] - f * p, _ = a(m, h, g);
|
|
31
|
+
if (!(l > 0) || !(_ > 1e-9 * a(c[0], c[1], c[2]))) throw e("A link hull axis and hinge must be non-zero and not parallel", "kinematics");
|
|
32
|
+
let v = m / _, y = h / _, b = g / _;
|
|
33
|
+
return {
|
|
34
|
+
hull: i,
|
|
35
|
+
basis: new Float64Array([
|
|
36
|
+
u,
|
|
37
|
+
d,
|
|
38
|
+
f,
|
|
39
|
+
v,
|
|
40
|
+
y,
|
|
41
|
+
b,
|
|
42
|
+
d * b - f * y,
|
|
43
|
+
f * v - u * b,
|
|
44
|
+
u * y - d * v,
|
|
45
|
+
o[0],
|
|
46
|
+
o[1],
|
|
47
|
+
o[2]
|
|
48
|
+
])
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
var b = class {
|
|
52
|
+
constructor(e = [], n = {}) {
|
|
53
|
+
this.linkMatrix = /* @__PURE__ */ new Float64Array(16), this.linkFrame = /* @__PURE__ */ new Float64Array(3), this.measured = /* @__PURE__ */ new Float64Array(1), this.surface = /* @__PURE__ */ new Float64Array(3), this.normal = /* @__PURE__ */ new Float64Array(3), this.distance = /* @__PURE__ */ new Float64Array(1), this.poseDistance = /* @__PURE__ */ new Float64Array(1), this.solveInputs = /* @__PURE__ */ new Float64Array(3), this.poleArguments = {
|
|
54
|
+
accepted: void 0,
|
|
55
|
+
center: void 0,
|
|
56
|
+
candidate: void 0,
|
|
57
|
+
best: void 0,
|
|
58
|
+
bounded: void 0
|
|
59
|
+
}, this.segmentResult = {
|
|
60
|
+
pointA: /* @__PURE__ */ new Float64Array(3),
|
|
61
|
+
pointB: /* @__PURE__ */ new Float64Array(3),
|
|
62
|
+
distance: 0,
|
|
63
|
+
parameterA: 0,
|
|
64
|
+
parameterB: 0
|
|
65
|
+
}, this.point = /* @__PURE__ */ new Float64Array(3), this.previousTarget = /* @__PURE__ */ new Float32Array(3), this.candidate = /* @__PURE__ */ new Float32Array(3), this.filterElbow = /* @__PURE__ */ new Float32Array(3), this.callbackRoot = /* @__PURE__ */ new Float64Array(3), this.callbackTarget = /* @__PURE__ */ new Float32Array(3), this.bestElbow = /* @__PURE__ */ new Float32Array(3), this.boundedElbow = /* @__PURE__ */ new Float32Array(3), this.trim = /* @__PURE__ */ new Float64Array(3), this.root = /* @__PURE__ */ new Float64Array(3), this.hand = /* @__PURE__ */ new Float64Array(3), this.raw = /* @__PURE__ */ new Float64Array(3), this.target = /* @__PURE__ */ new Float32Array(3), this.outputTarget = /* @__PURE__ */ new Float32Array(3), this.hasTarget = !1, this.hasPole = !1, this.previousPole = 0, this.busy = !1, this.targetClearance = Infinity, this.targetIterations = 0, this.singular = !1, this.bestAngle = 0, this.bestClearance = -Infinity, this.searchIterations = 0, this.rotationX = 0, this.rotationY = 0, this.rotationZ = 0, this.radialX = 0, this.radialY = 0, this.radialZ = 0, this.crossX = 0, this.crossY = 0, this.crossZ = 0, this.poleResult = {
|
|
66
|
+
resolved: !1,
|
|
67
|
+
elbow: /* @__PURE__ */ new Float32Array(3),
|
|
68
|
+
pole: /* @__PURE__ */ new Float32Array(3),
|
|
69
|
+
poleAngleOffset: 0,
|
|
70
|
+
clearance: -Infinity,
|
|
71
|
+
iterations: 0
|
|
72
|
+
}, this.targetResult = {
|
|
73
|
+
resolved: !1,
|
|
74
|
+
clearance: -Infinity,
|
|
75
|
+
maxPenetration: Infinity,
|
|
76
|
+
iterations: 0
|
|
77
|
+
}, this.result = {
|
|
78
|
+
status: 3,
|
|
79
|
+
resolved: !1,
|
|
80
|
+
targetResolved: !1,
|
|
81
|
+
target: this.outputTarget,
|
|
82
|
+
elbow: /* @__PURE__ */ new Float32Array(3),
|
|
83
|
+
poleAngle: 0,
|
|
84
|
+
poleAngleOffset: 0,
|
|
85
|
+
clearance: -Infinity,
|
|
86
|
+
maxPenetration: Infinity,
|
|
87
|
+
iterations: 0
|
|
88
|
+
}, this.rotateElbow = (e, t, n, r) => {
|
|
89
|
+
let i = Math.cos(n), a = Math.sin(n);
|
|
90
|
+
r[0] = this.rotationX + this.radialX * i + this.crossX * a, r[1] = this.rotationY + this.radialY * i + this.crossY * a, r[2] = this.rotationZ + this.radialZ * i + this.crossZ * a;
|
|
91
|
+
};
|
|
92
|
+
let r = Array.isArray(e) ? n : e;
|
|
93
|
+
if (this.volumes = Array.from(Array.isArray(e) ? e : r.colliders ?? []), this.minClearance = r.minClearance ?? .025, this.complianceMargin = r.complianceMargin ?? .08, this.targetRadius = r.targetRadius ?? 0, this.damping = r.damping ?? 0, this.maxIterations = r.maxIterations ?? 32, this.tolerance = r.tolerance ?? 1e-6, this.rootExclusion = r.rootExclusion ?? 0, this.upperArmRadius = r.upperArmRadius, l(this.minClearance, "minClearance"), l(this.complianceMargin, "complianceMargin"), l(this.targetRadius, "targetRadius"), l(this.damping, "damping"), l(this.rootExclusion, "rootExclusion"), o(this.tolerance, "tolerance"), this.upperArmRadius !== void 0 && this.upperArmRadius !== null && l(this.upperArmRadius, "upperArmRadius"), v(this.maxIterations, 256, "maxIterations must be 1..256"), this.maxIterations === 0) throw RangeError("maxIterations must be 1..256");
|
|
94
|
+
if (this.upperHull = y(r.links?.[0]), this.forearmHull = y(r.links?.[1]), this.upperHull && (r.upperArmRadius !== void 0 || this.rootExclusion > 0)) throw t("An upper link hull replaces upperArmRadius and rootExclusion; pass one or the other", "kinematics");
|
|
95
|
+
for (let e = 0; e < this.volumes.length; e++) this.checkVolume(this.volumes[e]);
|
|
96
|
+
}
|
|
97
|
+
checkVolume(e) {
|
|
98
|
+
if (!e || typeof e.evaluate != "function" || typeof e.segmentClearance != "function") throw TypeError("Volumes require evaluate and exact segmentClearance methods");
|
|
99
|
+
if (this.upperHull || this.forearmHull) {
|
|
100
|
+
if (typeof e.hullClearanceInto != "function") throw t("A collider of a solver with link hulls needs a hullClearanceInto method", "kinematics");
|
|
101
|
+
if (e === this.upperHull?.hull || e === this.forearmHull?.hull) throw t("A link hull cannot also be a collider; pass a separate ConvexHullVolume", "kinematics");
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
addVolume(e) {
|
|
105
|
+
if (this.busy) throw n("state", "Solver is not reentrant; do not call the solver from inside its own callback");
|
|
106
|
+
this.checkVolume(e), this.volumes.push(e);
|
|
107
|
+
}
|
|
108
|
+
reset() {
|
|
109
|
+
if (this.busy) throw n("state", "Solver is not reentrant; do not call the solver from inside its own callback");
|
|
110
|
+
this.hasTarget = this.hasPole = !1, this.previousPole = 0, this.poleArguments.accepted = void 0;
|
|
111
|
+
}
|
|
112
|
+
enter() {
|
|
113
|
+
if (this.busy) throw n("state", "Solver is not reentrant; do not call the solver from inside its own callback");
|
|
114
|
+
this.busy = !0;
|
|
115
|
+
}
|
|
116
|
+
copyInput(e, t) {
|
|
117
|
+
r(e), s(e, t, 0);
|
|
118
|
+
let n = 34028235677973366e22;
|
|
119
|
+
if (!(t[0] < n && t[0] > -34028235677973366e22) || !(t[1] < n && t[1] > -34028235677973366e22) || !(t[2] < n && t[2] > -34028235677973366e22)) throw RangeError("Position exceeds Float32 output range; move the target closer to the origin");
|
|
120
|
+
}
|
|
121
|
+
evaluateInto(e, t) {
|
|
122
|
+
if (this.distance[0] = NaN, d(e, t, this.surface, this.normal, this.distance), !Number.isFinite(this.distance[0])) throw RangeError("Non-finite volume distance; check the collider for NaN or infinite values");
|
|
123
|
+
r(this.surface), r(this.normal);
|
|
124
|
+
let n = this.normal[0], i = this.normal[1], a = this.normal[2];
|
|
125
|
+
if (Math.abs(Math.sqrt(n * n + i * i + a * a) - 1) > 1e-6) throw RangeError("Volume normal must be unit length");
|
|
126
|
+
}
|
|
127
|
+
updateTargetClearance(e) {
|
|
128
|
+
let t = Infinity;
|
|
129
|
+
for (let n = 0; n < this.volumes.length; n++) {
|
|
130
|
+
this.evaluateInto(this.volumes[n], e);
|
|
131
|
+
let r = this.distance[0] - this.minClearance - this.targetRadius;
|
|
132
|
+
r < t && (t = r);
|
|
133
|
+
}
|
|
134
|
+
this.targetClearance = t;
|
|
135
|
+
}
|
|
136
|
+
measure(e, t) {
|
|
137
|
+
let n = e[0] - t[0], r = e[1] - t[1], a = e[2] - t[2], o = n * n + r * r + a * a;
|
|
138
|
+
o >= 1e-300 && o < Infinity ? this.measured[0] = Math.sqrt(o) : this.measured[0] = i(n, r, a);
|
|
139
|
+
}
|
|
140
|
+
clampReach() {
|
|
141
|
+
let e = this.solveInputs[0], t = this.solveInputs[1], n = this.point[0] - this.root[0], r = this.point[1] - this.root[1], i = this.point[2] - this.root[2], a = n === 0 && r === 0 && i === 0;
|
|
142
|
+
a && (n = this.hand[0] - this.root[0], r = this.hand[1] - this.root[1], i = this.hand[2] - this.root[2], n === 0 && r === 0 && i === 0 && (n = 1, r = i = 0));
|
|
143
|
+
let o = n * n + r * r + i * i, s;
|
|
144
|
+
if (o >= 1e-300 && o < Infinity) s = Math.sqrt(o);
|
|
145
|
+
else {
|
|
146
|
+
let e = Math.max(Math.abs(n), Math.abs(r), Math.abs(i)), t = n / e, a = r / e, o = i / e;
|
|
147
|
+
s = e * Math.sqrt(t * t + a * a + o * o);
|
|
148
|
+
}
|
|
149
|
+
let c = a ? 0 : s;
|
|
150
|
+
if (c >= e && c <= t) return;
|
|
151
|
+
this.singular = !0;
|
|
152
|
+
let l = Math.max(t, Math.abs(this.root[0]), Math.abs(this.root[1]), Math.abs(this.root[2])), u = Math.min((t - e) * .25, l * 2 ** -22), d = c < e ? e + u : t - u;
|
|
153
|
+
this.point[0] = this.root[0] + n / s * d, this.point[1] = this.root[1] + r / s * d, this.point[2] = this.root[2] + i / s * d;
|
|
154
|
+
}
|
|
155
|
+
project(e, t, n) {
|
|
156
|
+
let i = this.solveInputs[0], a = this.solveInputs[1], o = this.damping === 0 ? 1 : -Math.expm1(-t / this.damping);
|
|
157
|
+
for (let t = 0; t < 3; t++) this.point[t] = o === 1 ? this.raw[t] : o > .5 ? this.raw[t] + (e[t] - this.raw[t]) * (1 - o) : e[t] + (this.raw[t] - e[t]) * o;
|
|
158
|
+
for (let e = 0; e < this.volumes.length; e++) {
|
|
159
|
+
this.evaluateInto(this.volumes[e], this.point);
|
|
160
|
+
let t = this.distance[0] - this.targetRadius - this.minClearance;
|
|
161
|
+
if (t < this.complianceMargin) {
|
|
162
|
+
let e = this.targetRadius + this.minClearance + Math.sqrt(this.complianceMargin * Math.max(0, t));
|
|
163
|
+
for (let t = 0; t < 3; t++) this.point[t] = this.surface[t] + this.normal[t] * e;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
this.targetIterations = 0;
|
|
167
|
+
for (let e = 0; e < this.maxIterations; e++) {
|
|
168
|
+
for (let e = 0; e < this.volumes.length; e++) if (this.evaluateInto(this.volumes[e], this.point), this.distance[0] - this.targetRadius - this.minClearance < 0) {
|
|
169
|
+
let e = this.targetRadius + this.minClearance + this.tolerance * .25;
|
|
170
|
+
for (let t = 0; t < 3; t++) this.point[t] = this.surface[t] + this.normal[t] * e;
|
|
171
|
+
}
|
|
172
|
+
n && this.clampReach();
|
|
173
|
+
for (let e = 0; e < 3; e++) this.target[e] = this.point[e];
|
|
174
|
+
r(this.target), this.updateTargetClearance(this.target), this.targetIterations = e + 1, this.measure(this.target, this.root);
|
|
175
|
+
let t = this.measured[0];
|
|
176
|
+
if (this.targetClearance >= -this.tolerance && (!n || t >= i && t <= a)) break;
|
|
177
|
+
for (let e = 0; e < 3; e++) this.point[e] = this.target[e];
|
|
178
|
+
}
|
|
179
|
+
let s = this.targetResult;
|
|
180
|
+
if (s.clearance = this.targetClearance, s.resolved = this.targetClearance >= -this.tolerance, n) {
|
|
181
|
+
this.measure(this.target, this.root);
|
|
182
|
+
let e = this.measured[0];
|
|
183
|
+
s.resolved &&= e >= i && e <= a;
|
|
184
|
+
}
|
|
185
|
+
s.maxPenetration = Math.max(0, -s.clearance), s.iterations = this.targetIterations;
|
|
186
|
+
}
|
|
187
|
+
resolveTarget(e, t) {
|
|
188
|
+
this.enter(), this.targetResult.resolved = !1;
|
|
189
|
+
try {
|
|
190
|
+
return o(t, "dt"), this.copyInput(e, this.raw), this.project(this.hasTarget ? this.previousTarget : this.raw, t, !1), this.targetResult.resolved && (this.previousTarget.set(this.target), this.hasTarget = !0), this.outputTarget.set(this.target), this.outputTarget;
|
|
191
|
+
} finally {
|
|
192
|
+
this.busy = !1;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
segmentInto(e, t, n, r) {
|
|
196
|
+
this.distance[0] = NaN, p(e, t, n, r, this.distance, this.segmentResult);
|
|
197
|
+
}
|
|
198
|
+
bendNormal(e, t, n) {
|
|
199
|
+
let r = t[0] - e[0], i = t[1] - e[1], a = t[2] - e[2], o = n[0] - t[0], s = n[1] - t[1], c = n[2] - t[2], l = i * c - a * s, u = a * o - r * c, d = r * s - i * o, f = l * l + u * u + d * d;
|
|
200
|
+
if (f < 1e-300) {
|
|
201
|
+
let e = Math.abs(r) <= Math.abs(i) && Math.abs(r) <= Math.abs(a);
|
|
202
|
+
l = e ? 0 : -a, u = e ? -a : 0, d = e ? i : r, f = l * l + u * u + d * d, f < 1e-300 && (l = 1, u = d = 0, f = 1);
|
|
203
|
+
}
|
|
204
|
+
let p = Math.sqrt(f);
|
|
205
|
+
this.linkFrame[0] = l / p, this.linkFrame[1] = u / p, this.linkFrame[2] = d / p;
|
|
206
|
+
}
|
|
207
|
+
linkGapInto(e, t, n) {
|
|
208
|
+
let r = n[0] - t[0], i = n[1] - t[1], a = n[2] - t[2];
|
|
209
|
+
this.measure(n, t);
|
|
210
|
+
let o = this.measured[0], s = o > 0 ? r / o : 1, c = o > 0 ? i / o : 0, l = o > 0 ? a / o : 0, u = this.linkFrame[0], d = this.linkFrame[1], f = this.linkFrame[2], p = c * f - l * d, m = l * u - s * f, h = s * d - c * u, g = e.basis, _ = this.linkMatrix;
|
|
211
|
+
for (let e = 0; e < 3; e++) {
|
|
212
|
+
let t = g[e], n = g[e + 3], r = g[e + 6];
|
|
213
|
+
_[e * 4] = s * t + u * n + p * r, _[e * 4 + 1] = c * t + d * n + m * r, _[e * 4 + 2] = l * t + f * n + h * r;
|
|
214
|
+
}
|
|
215
|
+
_[12] = t[0] - (_[0] * g[9] + _[4] * g[10] + _[8] * g[11]), _[13] = t[1] - (_[1] * g[9] + _[5] * g[10] + _[9] * g[11]), _[14] = t[2] - (_[2] * g[9] + _[6] * g[10] + _[10] * g[11]), _[15] = 1, e.hull.setTransform(_);
|
|
216
|
+
}
|
|
217
|
+
poseClearanceInto(e, t, n, r, i, a) {
|
|
218
|
+
let o = Infinity, s = this.upperHull, c = this.forearmHull, l = s ? 0 : this.upperArmRadius === void 0 ? r : this.upperArmRadius, u = Math.min(1, this.rootExclusion / a);
|
|
219
|
+
for (let n = 0; n < 3; n++) this.trim[n] = e[n] + (t[n] - e[n]) * u;
|
|
220
|
+
(s || c) && this.bendNormal(e, t, n), s && this.linkGapInto(s, e, t), c && this.linkGapInto(c, t, n);
|
|
221
|
+
for (let e = 0; e < this.volumes.length; e++) {
|
|
222
|
+
let a = this.volumes[e];
|
|
223
|
+
this.evaluateInto(a, t);
|
|
224
|
+
let u = this.distance[0] - r;
|
|
225
|
+
c ? a.hullClearanceInto(c.hull, this.distance) : this.segmentInto(a, t, n, i);
|
|
226
|
+
let d = this.distance[0], f = Infinity;
|
|
227
|
+
if (s ? (a.hullClearanceInto(s.hull, this.distance), f = this.distance[0]) : l !== null && (this.segmentInto(a, this.trim, t, l), f = this.distance[0]), !Number.isFinite(d) || l !== null && !Number.isFinite(f)) throw RangeError("Non-finite segment clearance; check the collider for NaN or infinite values");
|
|
228
|
+
o = Math.min(o, u - this.minClearance, d - this.minClearance, f - this.minClearance);
|
|
229
|
+
}
|
|
230
|
+
this.poseDistance[0] = o;
|
|
231
|
+
}
|
|
232
|
+
testPoseInto(e, t, n, i, a, o) {
|
|
233
|
+
this.poleArguments.candidate = e, this.candidate.fill(NaN), this.callbackRoot.set(this.root), this.callbackTarget.set(this.target), o(this.callbackRoot, this.callbackTarget, e, this.candidate), r(this.candidate, "IK elbow"), this.measure(this.candidate, this.root);
|
|
234
|
+
let s = this.measured[0];
|
|
235
|
+
this.measure(this.candidate, this.target);
|
|
236
|
+
let c = this.measured[0], l = Math.min(this.tolerance * 4, Math.min(t, n) * 1e-5);
|
|
237
|
+
this.poseDistance[0] = -Infinity, !(Math.abs(s - t) > l || Math.abs(c - n) > l) && (this.poseFilter && (this.callbackRoot.set(this.root), this.callbackTarget.set(this.target), this.filterElbow.set(this.candidate), !this.poseFilter(this.callbackRoot, this.filterElbow, this.callbackTarget, e)) || this.poseClearanceInto(this.root, this.candidate, this.target, i, a, t));
|
|
238
|
+
}
|
|
239
|
+
search(e, t, n, r, i, a) {
|
|
240
|
+
let o = this.poleArguments.center, s = this.solveInputs[2];
|
|
241
|
+
if (this.bestAngle = o, this.testPoseInto(o, t, n, r, i, a), this.bestClearance = this.poseDistance[0], this.poleArguments.best = this.poleArguments.candidate, this.bestElbow.set(this.candidate), this.searchIterations = 1, this.bestClearance >= -this.tolerance) return;
|
|
242
|
+
let c = Math.ceil(e / 2);
|
|
243
|
+
for (let l = 1; l <= e; l++) {
|
|
244
|
+
let e = o + (l % 2 == 1 ? 1 : -1) * Math.ceil(l / 2) / c * s, u = this.poleArguments.candidate, d = e === u && (e !== 0 || 1 / e == 1 / u);
|
|
245
|
+
this.testPoseInto(d ? u : e, t, n, r, i, a);
|
|
246
|
+
let f = this.poseDistance[0];
|
|
247
|
+
if (this.searchIterations++, f > this.bestClearance && (this.bestClearance = f, this.bestAngle = e, this.bestElbow.set(this.candidate), this.poleArguments.best = this.poleArguments.candidate), f >= -this.tolerance) return;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
solve(e, n, r, i, a, s, c, u, d, f = _) {
|
|
251
|
+
this.enter();
|
|
252
|
+
let p = this.result;
|
|
253
|
+
p.resolved = p.targetResolved = !1, p.status = 3;
|
|
254
|
+
try {
|
|
255
|
+
if (this.copyInput(e, this.root), this.copyInput(n, this.hand), this.copyInput(r, this.raw), o(i, "upperArmLen"), o(a, "forearmLen"), l(s, "elbowRadius"), l(c, "forearmRadius"), o(u, "dt"), typeof d != "function") throw TypeError("An elbow evaluator is required; pass an evaluator to the constructor or use the two-bone solver");
|
|
256
|
+
let m = f.swivelSpeedLimit ?? Math.PI * 2;
|
|
257
|
+
if (f.acceptPose !== void 0 && typeof f.acceptPose != "function") throw t("Supply a function for acceptPose to test each candidate", "kinematics");
|
|
258
|
+
this.poseFilter = f.acceptPose;
|
|
259
|
+
let h = f.foldMargin ?? 1e-5, g = f.reachMargin ?? 1e-5, _ = f.searchBudget ?? 32;
|
|
260
|
+
l(m, "swivelSpeedLimit"), o(h, "foldMargin"), o(g, "reachMargin"), v(_, 256, "searchBudget must be 0..256");
|
|
261
|
+
let y = Math.abs(i - a) + h, b = i + a - g;
|
|
262
|
+
if (y >= b || !Number.isFinite(Math.fround(b))) throw RangeError("Singularity margins leave no operational reach; lower reachMargin or foldMargin");
|
|
263
|
+
this.singular = !1, this.measure(this.raw, this.root);
|
|
264
|
+
let x = this.measured[0];
|
|
265
|
+
(x < y || x > b) && (this.singular = !0), this.solveInputs[0] = y, this.solveInputs[1] = b, this.project(this.hand, u, !0);
|
|
266
|
+
let S = this.hasPole ? this.previousPole : 0, C = this.hasPole ? Math.min(Math.PI, m * u) : Math.PI;
|
|
267
|
+
this.poleArguments.center = this.hasPole ? this.poleArguments.accepted : 0, this.solveInputs[2] = C, this.search(_, i, a, s, c, d), this.boundedElbow.set(this.bestElbow), this.poleArguments.bounded = this.poleArguments.best;
|
|
268
|
+
let w = this.bestAngle, T = this.bestClearance !== -Infinity, E = this.targetIterations + this.searchIterations, D = 3;
|
|
269
|
+
this.updateTargetClearance(this.target), this.measure(this.target, this.root);
|
|
270
|
+
let O = this.measured[0], k = this.targetClearance >= -this.tolerance && O >= y && O <= b;
|
|
271
|
+
k && this.bestClearance >= -this.tolerance ? D = this.singular ? 2 : 0 : k && this.hasPole && C < Math.PI && (this.solveInputs[2] = Math.PI, this.search(_, i, a, s, c, d), E += this.searchIterations, this.bestClearance >= -this.tolerance && (Math.abs(this.bestAngle - S) <= C ? (w = this.bestAngle, T = !0, this.boundedElbow.set(this.bestElbow), this.poleArguments.bounded = this.poleArguments.best, D = this.singular ? 2 : 0) : D = 1)), this.updateTargetClearance(this.target), this.poseDistance[0] = -Infinity, T && this.poseClearanceInto(this.root, this.boundedElbow, this.target, s, c, i);
|
|
272
|
+
let A = this.poseDistance[0];
|
|
273
|
+
return p.targetResolved = this.targetClearance >= -this.tolerance && O >= y && O <= b, (!p.targetResolved || A < -this.tolerance) && (D === 0 || D === 2) && (D = 3), D === 0 && this.hasPole && Math.abs(w - this.previousPole) > m * u && (D = 1), p.target.set(this.target), p.elbow.set(this.boundedElbow), p.poleAngle = p.poleAngleOffset = w, p.iterations = E, p.clearance = Math.min(this.targetClearance, A), p.maxPenetration = Math.max(0, -p.clearance), p.status = D, p.resolved = p.status === 0, p.resolved && (this.previousPole = p.poleAngle, this.hasPole = !0, this.poleArguments.accepted = this.poleArguments.bounded, this.previousTarget.set(p.target), this.hasTarget = !0), p;
|
|
274
|
+
} finally {
|
|
275
|
+
this.poseFilter = void 0, this.busy = !1;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
calculatePoleClearance(e, t, n, r) {
|
|
279
|
+
this.enter();
|
|
280
|
+
let i = this.poleResult;
|
|
281
|
+
i.resolved = !1;
|
|
282
|
+
try {
|
|
283
|
+
this.copyInput(e, this.root), this.copyInput(n, this.hand), this.copyInput(t, this.raw), l(r, "radius"), this.target.set(this.hand);
|
|
284
|
+
let s = a(this.raw[0] - this.root[0], this.raw[1] - this.root[1], this.raw[2] - this.root[2]), c = a(this.raw[0] - this.hand[0], this.raw[1] - this.hand[1], this.raw[2] - this.hand[2]);
|
|
285
|
+
o(s, "upper length"), o(c, "lower length");
|
|
286
|
+
let u = this.hand[0] - this.root[0], d = this.hand[1] - this.root[1], f = this.hand[2] - this.root[2], p = a(u, d, f);
|
|
287
|
+
if (p === 0) {
|
|
288
|
+
let e = this.raw[0] - this.root[0], t = this.raw[1] - this.root[1], n = this.raw[2] - this.root[2];
|
|
289
|
+
Math.abs(e) < Math.abs(t) ? (u = 0, d = -n, f = t) : (u = -n, d = 0, f = e), p = a(u, d, f), p === 0 && (u = 0, d = 1, f = 0, p = 1);
|
|
290
|
+
}
|
|
291
|
+
u /= p, d /= p, f /= p;
|
|
292
|
+
let m = this.raw[0] - this.root[0], h = this.raw[1] - this.root[1], g = this.raw[2] - this.root[2], _ = m * u + h * d + g * f;
|
|
293
|
+
return this.rotationX = this.root[0] + _ * u, this.rotationY = this.root[1] + _ * d, this.rotationZ = this.root[2] + _ * f, this.radialX = m - _ * u, this.radialY = h - _ * d, this.radialZ = g - _ * f, this.crossX = d * this.radialZ - f * this.radialY, this.crossY = f * this.radialX - u * this.radialZ, this.crossZ = u * this.radialY - d * this.radialX, this.poleArguments.center = 0, this.solveInputs[2] = Math.PI, this.search(64, s, c, r, r, this.rotateElbow), i.elbow.set(this.bestElbow), i.pole.set(this.bestElbow), i.poleAngleOffset = this.bestAngle, i.clearance = this.bestClearance, i.iterations = this.searchIterations, i.resolved = this.bestClearance >= -this.tolerance, i;
|
|
294
|
+
} finally {
|
|
295
|
+
this.busy = !1;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
//#endregion
|
|
300
|
+
export { b as AvoidanceSolver, h as CapsuleVolume, c as ConvexHullVolume, g as SolveStatus, f as SphereVolume, m as closestPointsBetweenSegments, u as measureSegmentClearance };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { PosePredicate } from './AvoidanceSolver.js';
|
|
2
|
+
import type { Vec3View } from './types.js';
|
|
3
|
+
/** Local rotation bounds, relative to the joint's rest frame; angles are radians. */
|
|
4
|
+
export type JointLimit = {
|
|
5
|
+
type: 'euler';
|
|
6
|
+
min: Vec3View;
|
|
7
|
+
max: Vec3View;
|
|
8
|
+
} | {
|
|
9
|
+
type: 'hinge';
|
|
10
|
+
axis: Vec3View;
|
|
11
|
+
min?: number;
|
|
12
|
+
max?: number;
|
|
13
|
+
} | {
|
|
14
|
+
type: 'cone';
|
|
15
|
+
axis?: Vec3View;
|
|
16
|
+
angle: number;
|
|
17
|
+
twist?: readonly [number, number];
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Compiled Euler XYZ, hinge and cone/swing-twist bounds. Checks, rather than clamps, complete candidate rotations.
|
|
21
|
+
* Quaternions are local [x,y,z,w] in the rest frame. Null bounds allow that joint to rotate freely.
|
|
22
|
+
*/
|
|
23
|
+
export declare class JointLimitSet {
|
|
24
|
+
private readonly limits;
|
|
25
|
+
private readonly tolerance;
|
|
26
|
+
/** Copies bounds. Angular tolerance defaults to 1e-7 radians; it must be finite and nonnegative. */
|
|
27
|
+
constructor(limits: readonly (JointLimit | null)[], tolerance?: number);
|
|
28
|
+
/** Rejects missing, nonfinite, zero or out-of-bound rotations, without modifying any rotation or limit. */
|
|
29
|
+
accepts(rotations: readonly ArrayLike<number>[]): boolean;
|
|
30
|
+
}
|
|
31
|
+
/** Reads each candidate's local, rest-relative joint rotations, in the same order as its limit set. */
|
|
32
|
+
export type CandidateRotations = (root: Vec3View, elbow: Vec3View, target: Vec3View, poleAngle: number) => readonly ArrayLike<number>[];
|
|
33
|
+
/** Builds SolveOptions.acceptPose; the regular obstacle search continues past clear but illegal candidates. */
|
|
34
|
+
export declare function jointLimitPredicate(limits: JointLimitSet, rotations: CandidateRotations): PosePredicate;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { n as e } from "./errors-D5_2oB8I.js";
|
|
2
|
+
//#region src/joint-limits.ts
|
|
3
|
+
var t = Math.PI;
|
|
4
|
+
function n(t) {
|
|
5
|
+
if (t.length !== 3 || !Array.from(t).every(Number.isFinite)) throw e("Supply a finite three-component limit axis", "kinematics");
|
|
6
|
+
let n = Math.hypot(t[0], t[1], t[2]);
|
|
7
|
+
if (!(n > 0 && Number.isFinite(n))) throw e("Supply a nonzero finite limit axis", "kinematics");
|
|
8
|
+
return Array.from(t, (e) => e / n);
|
|
9
|
+
}
|
|
10
|
+
function r(n, r) {
|
|
11
|
+
if (n.length !== r.length || n.some((e, n) => !Number.isFinite(e) || !Number.isFinite(r[n]) || e < -t || r[n] > t || e > r[n])) throw e("Supply ordered finite joint bounds within -pi..pi", "kinematics");
|
|
12
|
+
}
|
|
13
|
+
var i = class {
|
|
14
|
+
constructor(i, a = 1e-7) {
|
|
15
|
+
if (!(a >= 0 && Number.isFinite(a))) throw e("Supply a finite nonnegative limit tolerance", "kinematics");
|
|
16
|
+
this.tolerance = a, this.limits = i.map((i) => {
|
|
17
|
+
if (i === null) return null;
|
|
18
|
+
if (i.type === "euler") {
|
|
19
|
+
let t = Array.from(i.min), n = Array.from(i.max);
|
|
20
|
+
if (t.length !== 3 || n.length !== 3) throw e("Supply three Euler bounds per joint", "kinematics");
|
|
21
|
+
return r(t, n), {
|
|
22
|
+
type: i.type,
|
|
23
|
+
axis: [],
|
|
24
|
+
min: t,
|
|
25
|
+
max: n,
|
|
26
|
+
angle: 0
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
if (i.type !== "hinge" && i.type !== "cone") throw e("Choose an Euler, hinge or cone joint limit", "kinematics");
|
|
30
|
+
let a = n(i.axis ?? [
|
|
31
|
+
0,
|
|
32
|
+
1,
|
|
33
|
+
0
|
|
34
|
+
]), o = [i.type === "hinge" ? i.min ?? -t : i.twist?.[0] ?? -t], s = [i.type === "hinge" ? i.max ?? t : i.twist?.[1] ?? t];
|
|
35
|
+
r(o, s);
|
|
36
|
+
let c = i.type === "cone" ? i.angle : 0;
|
|
37
|
+
if (!(c >= 0 && c <= t)) throw e("Supply a cone angle from zero to pi", "kinematics");
|
|
38
|
+
return {
|
|
39
|
+
type: i.type,
|
|
40
|
+
axis: a,
|
|
41
|
+
min: o,
|
|
42
|
+
max: s,
|
|
43
|
+
angle: c
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
accepts(e) {
|
|
48
|
+
if (e.length !== this.limits.length) return !1;
|
|
49
|
+
let n = this.tolerance;
|
|
50
|
+
for (let r = 0; r < this.limits.length; r++) {
|
|
51
|
+
let i = e[r];
|
|
52
|
+
if (!i || i.length !== 4 || !Array.from(i).every(Number.isFinite)) return !1;
|
|
53
|
+
let a = Math.hypot(i[0], i[1], i[2], i[3]);
|
|
54
|
+
if (!(a > 0 && Number.isFinite(a))) return !1;
|
|
55
|
+
let o = i[0] / a, s = i[1] / a, c = i[2] / a, l = i[3] / a, u = this.limits[r];
|
|
56
|
+
if (!u) continue;
|
|
57
|
+
let { axis: d, min: f, max: p } = u;
|
|
58
|
+
if (u.type === "euler") {
|
|
59
|
+
let e = Math.max(-1, Math.min(1, 2 * (o * c + s * l))), r = Math.asin(e), i, a;
|
|
60
|
+
if (Math.abs(e) < 1 - 1e-12) i = Math.atan2(2 * (o * l - s * c), 1 - 2 * (o * o + s * s)), a = Math.atan2(2 * (c * l - o * s), 1 - 2 * (s * s + c * c));
|
|
61
|
+
else {
|
|
62
|
+
let i = Math.atan2(2 * (o * l + s * c), 1 - 2 * (o * o + c * c));
|
|
63
|
+
if (r < f[1] - n || r > p[1] + n) return !1;
|
|
64
|
+
let a = f[0] + (e > 0 ? f[2] : -p[2]), u = p[0] + (e > 0 ? p[2] : -f[2]);
|
|
65
|
+
if (![
|
|
66
|
+
-2 * t,
|
|
67
|
+
0,
|
|
68
|
+
2 * t
|
|
69
|
+
].some((e) => i + e >= a - n && i + e <= u + n)) return !1;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
let u = [
|
|
73
|
+
i,
|
|
74
|
+
r,
|
|
75
|
+
a
|
|
76
|
+
], d = (e) => Math.atan2(Math.sin(e), Math.cos(e));
|
|
77
|
+
if (![u, [
|
|
78
|
+
d(i + t),
|
|
79
|
+
d(t - r),
|
|
80
|
+
d(a + t)
|
|
81
|
+
]].some((e) => e.every((e, r) => [
|
|
82
|
+
-2 * t,
|
|
83
|
+
0,
|
|
84
|
+
2 * t
|
|
85
|
+
].some((t) => e + t >= f[r] - n && e + t <= p[r] + n)))) return !1;
|
|
86
|
+
} else {
|
|
87
|
+
let e = o * d[0] + s * d[1] + c * d[2];
|
|
88
|
+
if (2 * Math.acos(Math.min(1, Math.hypot(e, l))) > u.angle + n) return !1;
|
|
89
|
+
if (Math.hypot(e, l) < 1e-12) {
|
|
90
|
+
if (f[0] > -t || p[0] < t) return !1;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
let r = 2 * Math.atan2(e, l), i = Math.atan2(Math.sin(r), Math.cos(r)), a = Math.abs(Math.abs(i) - t) <= n;
|
|
94
|
+
if (!(i >= f[0] - n && i <= p[0] + n) && !(a && -i >= f[0] - n && -i <= p[0] + n)) return !1;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return !0;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
function a(e, t) {
|
|
101
|
+
return (n, r, i, a) => e.accepts(t(n, r, i, a));
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
104
|
+
export { i as JointLimitSet, a as jointLimitPredicate };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type V3 = [number, number, number];
|
|
2
|
+
export type Q4 = [number, number, number, number];
|
|
3
|
+
export interface Pose {
|
|
4
|
+
position: V3;
|
|
5
|
+
rotation: Q4;
|
|
6
|
+
}
|
|
7
|
+
export declare const identity: () => Pose;
|
|
8
|
+
export declare function multiply(a: Q4, b: Q4): Q4;
|
|
9
|
+
export declare function rotate(q: Q4, p: V3): V3;
|
|
10
|
+
export declare function compose(a: Pose, b: Pose): Pose;
|
|
11
|
+
export declare function angularError(current: Q4, target: Q4): V3;
|
|
12
|
+
export declare function dampedStep(jac: Float64Array[], error: number[], damping: number, blocked: Set<number>): number[];
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/** Joint-local displacement in metres or axis direction. */
|
|
2
|
+
export type IKVector = readonly [number, number, number];
|
|
3
|
+
/** Quaternion in x, y, z, w order; finite nonzero inputs are normalized. */
|
|
4
|
+
export type IKQuaternion = readonly [number, number, number, number];
|
|
5
|
+
/** One scalar degree of freedom. Compose joints for spherical or floating joints. */
|
|
6
|
+
export interface IKJoint {
|
|
7
|
+
/** Joint kind. Fixed joints supply link transforms without a variable. */
|
|
8
|
+
type: 'fixed' | 'revolute' | 'prismatic';
|
|
9
|
+
/** Parent index, in any input order. Omitted or -1 means the world. */
|
|
10
|
+
parent?: number;
|
|
11
|
+
/** Rest offset in the parent frame. Default [0,0,0]. */
|
|
12
|
+
position?: IKVector;
|
|
13
|
+
/** Rest orientation in the parent frame. Default identity. */
|
|
14
|
+
rotation?: IKQuaternion;
|
|
15
|
+
/** Motion axis in the rest joint frame. Default +Z; normalized on input. */
|
|
16
|
+
axis?: IKVector;
|
|
17
|
+
/** Initial angle in radians or translation in metres. Default 0. */
|
|
18
|
+
value?: number;
|
|
19
|
+
/** Hard lower bound. Default -Infinity. */
|
|
20
|
+
min?: number;
|
|
21
|
+
/** Hard upper bound. Default Infinity. Equal bounds lock the joint. */
|
|
22
|
+
max?: number;
|
|
23
|
+
}
|
|
24
|
+
/** An attachment frame on a joint, or on the world when joint is -1. */
|
|
25
|
+
export interface IKFrame {
|
|
26
|
+
/** Index into the constructor's joints, or -1 for the world. */
|
|
27
|
+
joint: number;
|
|
28
|
+
/** Attachment position in joint coordinates. Default origin. */
|
|
29
|
+
position?: IKVector;
|
|
30
|
+
/** Attachment orientation in joint coordinates. Default identity. */
|
|
31
|
+
rotation?: IKQuaternion;
|
|
32
|
+
}
|
|
33
|
+
/** Position and orientation channels shared by goals and loop closures. */
|
|
34
|
+
export interface IKChannels {
|
|
35
|
+
/** Position objective weight, >=0. Default 1; 0 disables this channel. */
|
|
36
|
+
positionWeight?: number;
|
|
37
|
+
/** Orientation objective weight, >=0. Default 1; 0 disables this channel. */
|
|
38
|
+
orientationWeight?: number;
|
|
39
|
+
/** Active world position axes. Default [true,true,true]. */
|
|
40
|
+
positionAxes?: readonly [boolean, boolean, boolean];
|
|
41
|
+
/** Active world rotation-vector axes. Default [true,true,true]. */
|
|
42
|
+
orientationAxes?: readonly [boolean, boolean, boolean];
|
|
43
|
+
}
|
|
44
|
+
/** One world-space effector goal; all supplied goals are solved together. */
|
|
45
|
+
export interface IKGoal extends IKChannels {
|
|
46
|
+
/** Attachment to constrain. */
|
|
47
|
+
frame: IKFrame;
|
|
48
|
+
/** World position target; omitted means no position goal. */
|
|
49
|
+
position?: IKVector;
|
|
50
|
+
/** World orientation target; omitted means no orientation goal. */
|
|
51
|
+
rotation?: IKQuaternion;
|
|
52
|
+
}
|
|
53
|
+
/** Closes a cut in a kinematic tree by matching two attachment frames. */
|
|
54
|
+
export interface IKLoop extends IKChannels {
|
|
55
|
+
/** First attachment. */
|
|
56
|
+
a: IKFrame;
|
|
57
|
+
/** Second attachment, possibly on another tree or the world. */
|
|
58
|
+
b: IKFrame;
|
|
59
|
+
/** Match position. Default true. */
|
|
60
|
+
position?: boolean;
|
|
61
|
+
/** Match orientation. Default false (a point closure). */
|
|
62
|
+
orientation?: boolean;
|
|
63
|
+
}
|
|
64
|
+
/** Bounded local nonlinear solver settings. */
|
|
65
|
+
export interface MultiGoalIKOptions {
|
|
66
|
+
/** Maximum iterations per seed, 1..4096. Default 128. */
|
|
67
|
+
iterations?: number;
|
|
68
|
+
/** Deterministic seeds, including the initial pose, 1..64. Default 4. */
|
|
69
|
+
candidates?: number;
|
|
70
|
+
/** Unweighted active position tolerance in metres. Default 1e-5. */
|
|
71
|
+
positionTolerance?: number;
|
|
72
|
+
/** Unweighted active orientation tolerance in radians. Default 1e-5. */
|
|
73
|
+
orientationTolerance?: number;
|
|
74
|
+
/** Positive initial DLS damping, 1e-6..1e3. Default 0.01. */
|
|
75
|
+
damping?: number;
|
|
76
|
+
/** Maximum absolute scalar change per step (radians/metres). Default 0.25. */
|
|
77
|
+
maxStep?: number;
|
|
78
|
+
}
|
|
79
|
+
/** Owned world transform of a joint or attachment. */
|
|
80
|
+
export interface IKPose {
|
|
81
|
+
/** World position in metres. */
|
|
82
|
+
position: [number, number, number];
|
|
83
|
+
/** World orientation in x,y,z,w order. */
|
|
84
|
+
rotation: [number, number, number, number];
|
|
85
|
+
}
|
|
86
|
+
/** Solve request. Inputs are copied and never modified. */
|
|
87
|
+
export interface MultiGoalIKRequest {
|
|
88
|
+
/** World goals. Default none; loops can be solved alone. */
|
|
89
|
+
goals?: readonly IKGoal[];
|
|
90
|
+
/** Explicit cuts that close loops. Default none. */
|
|
91
|
+
loops?: readonly IKLoop[];
|
|
92
|
+
/** Starting scalars, one per joint including fixed joints. Default constructor values. */
|
|
93
|
+
values?: readonly number[];
|
|
94
|
+
/** Optional cancellation, checked before work and every iteration. */
|
|
95
|
+
signal?: AbortSignal;
|
|
96
|
+
}
|
|
97
|
+
/** One constraint's physical errors, after masks and before weights. */
|
|
98
|
+
export interface IKError {
|
|
99
|
+
/** Active positional distance in metres, zero when disabled. */
|
|
100
|
+
position: number;
|
|
101
|
+
/** Active rotation-vector norm in radians, zero when disabled. */
|
|
102
|
+
orientation: number;
|
|
103
|
+
}
|
|
104
|
+
/** Best bounded pose, including explicit nonconvergence diagnostics. */
|
|
105
|
+
export interface MultiGoalIKResult {
|
|
106
|
+
/** True only when every active goal and loop is within both physical tolerances. */
|
|
107
|
+
resolved: boolean;
|
|
108
|
+
/** Converged, stationary after all seeds, or iteration budget exhausted. */
|
|
109
|
+
status: 'converged' | 'stalled' | 'iteration-limit';
|
|
110
|
+
/** One angle/translation per input joint; fixed joints have zero. */
|
|
111
|
+
values: number[];
|
|
112
|
+
/** Joint transforms in the original input order. */
|
|
113
|
+
poses: IKPose[];
|
|
114
|
+
/** Goal errors in request order. */
|
|
115
|
+
goals: IKError[];
|
|
116
|
+
/** Loop closure errors in request order. */
|
|
117
|
+
loops: IKError[];
|
|
118
|
+
/** Sum of weighted squared residuals. */
|
|
119
|
+
objective: number;
|
|
120
|
+
/** Total linearizations across all candidates. */
|
|
121
|
+
iterations: number;
|
|
122
|
+
/** Seeds attempted. */
|
|
123
|
+
candidates: number;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Simultaneous weighted DLS for trees joined by explicit position/orientation closures.
|
|
127
|
+
* Scalar joints compose into arbitrary translational/rotational DOFs; outputs remain caller-owned.
|
|
128
|
+
* This bounded local search reports failure rather than claiming infeasibility or accepting an open loop.
|
|
129
|
+
*/
|
|
130
|
+
export declare class MultiGoalIKSolver {
|
|
131
|
+
private readonly joints;
|
|
132
|
+
private readonly order;
|
|
133
|
+
private readonly variables;
|
|
134
|
+
private readonly options;
|
|
135
|
+
/** Copies topology, rest transforms, bounds and settings; rejects cyclic parent graphs. */
|
|
136
|
+
constructor(joints: readonly IKJoint[], options?: MultiGoalIKOptions);
|
|
137
|
+
private values;
|
|
138
|
+
private frame;
|
|
139
|
+
private forward;
|
|
140
|
+
/** Computes owned world transforms, without solving or mutating the configured pose. */
|
|
141
|
+
evaluate(values?: readonly number[], frame?: IKFrame): IKPose[];
|
|
142
|
+
private attachment;
|
|
143
|
+
private constraints;
|
|
144
|
+
private residual;
|
|
145
|
+
/** Solves all goals and cuts simultaneously. Failure returns the best bounded pose with resolved=false. */
|
|
146
|
+
solve(request?: MultiGoalIKRequest): MultiGoalIKResult;
|
|
147
|
+
}
|