@margoengine/ragdoll 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 +381 -3
- package/dist/balance.d.ts +195 -0
- package/dist/balance.js +468 -0
- package/dist/getup.d.ts +86 -0
- package/dist/getup.js +135 -0
- package/dist/hulls.d.ts +71 -0
- package/dist/hulls.js +173 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +741 -0
- package/dist/limits-CCe6Pdej.js +55 -0
- package/dist/limits.d.ts +12 -0
- package/dist/powered.d.ts +145 -0
- package/dist/powered.js +245 -0
- package/dist/profile.d.ts +62 -0
- package/dist/profile.js +267 -0
- package/dist/ragdoll.d.ts +276 -0
- package/package.json +82 -6
package/dist/index.js
ADDED
|
@@ -0,0 +1,741 @@
|
|
|
1
|
+
// @margo/core-built 0.1.0
|
|
2
|
+
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
|
+
|
|
4
|
+
import { MargoError as e } from "@margoengine/math/errors";
|
|
5
|
+
import { conjugateQuaternion as t, normalizeQuaternion as n, rotateByQuaternion as r, rotationToQuaternion as i } from "@margoengine/math/quat";
|
|
6
|
+
//#region ../shared/scene-scope.js
|
|
7
|
+
var a = 0, o = (e, t) => {
|
|
8
|
+
let n = t + a++;
|
|
9
|
+
for (; e.plugins?.has(n);) n += ":";
|
|
10
|
+
return n;
|
|
11
|
+
};
|
|
12
|
+
function s(e, t) {
|
|
13
|
+
return {
|
|
14
|
+
scene: t,
|
|
15
|
+
run(n) {
|
|
16
|
+
if (!t) return n();
|
|
17
|
+
let r, i = {coreRequirement:/*@__PURE__*/__margoCoreRequirement("0.1.0",import.meta.url),
|
|
18
|
+
name: o(e, "scene-scope:"),
|
|
19
|
+
setup() {
|
|
20
|
+
r = n();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
return t.use(i), t.removePlugin(i.name), r;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/ragdoll.ts
|
|
29
|
+
var c = 2e-6, l = [
|
|
30
|
+
0,
|
|
31
|
+
0,
|
|
32
|
+
0,
|
|
33
|
+
1
|
|
34
|
+
], u = {
|
|
35
|
+
type: "cone",
|
|
36
|
+
swing: Math.PI / 4,
|
|
37
|
+
twist: [-Math.PI / 6, Math.PI / 6]
|
|
38
|
+
}, d = (e) => e[0] * (e[5] * e[10] - e[6] * e[9]) - e[4] * (e[1] * e[10] - e[2] * e[9]) + e[8] * (e[1] * e[6] - e[2] * e[5]), f = (e, t) => n(i(e, t, Math.hypot(e[0], e[1], e[2]), Math.hypot(e[4], e[5], e[6]), Math.hypot(e[8], e[9], e[10])), t), p = (e, t, n, r = 0) => {
|
|
39
|
+
let i = e[0], a = e[1], o = e[2], s = e[3], c = t[0], l = t[1], u = t[2], d = t[3];
|
|
40
|
+
return n[r] = s * c + i * d + a * u - o * l, n[r + 1] = s * l - i * u + a * d + o * c, n[r + 2] = s * u + i * l - a * c + o * d, n[r + 3] = s * d - i * c - a * l - o * u, n;
|
|
41
|
+
};
|
|
42
|
+
function m(e, t, r) {
|
|
43
|
+
let i = e[0] * t[0] + e[1] * t[1] + e[2] * t[2];
|
|
44
|
+
if (i < -.999999) {
|
|
45
|
+
let t = 0, n = -e[2], i = e[1];
|
|
46
|
+
Math.hypot(n, i) < 1e-6 && (t = e[2], n = 0, i = -e[0]), r[0] = t, r[1] = n, r[2] = i, r[3] = 0;
|
|
47
|
+
} else r[0] = e[1] * t[2] - e[2] * t[1], r[1] = e[2] * t[0] - e[0] * t[2], r[2] = e[0] * t[1] - e[1] * t[0], r[3] = 1 + i;
|
|
48
|
+
return n(r, r);
|
|
49
|
+
}
|
|
50
|
+
function h(e, t, n, r, i, a, o) {
|
|
51
|
+
let s = e[t] * n[r] + e[t + 1] * n[r + 1] + e[t + 2] * n[r + 2] + e[t + 3] * n[r + 3], c = 1;
|
|
52
|
+
s < 0 && (c = -1, s = -s);
|
|
53
|
+
let l = 1 - i, u = i * c;
|
|
54
|
+
if (s < .9995) {
|
|
55
|
+
let e = Math.acos(s), t = Math.sin(e);
|
|
56
|
+
l = Math.sin((1 - i) * e) / t, u = Math.sin(i * e) / t * c;
|
|
57
|
+
}
|
|
58
|
+
let d = 0;
|
|
59
|
+
for (let i = 0; i < 4; i++) {
|
|
60
|
+
let s = e[t + i] * l + n[r + i] * u;
|
|
61
|
+
a[o + i] = s, d += s * s;
|
|
62
|
+
}
|
|
63
|
+
d = Math.sqrt(d);
|
|
64
|
+
for (let e = 0; e < 4; e++) a[o + e] /= d;
|
|
65
|
+
}
|
|
66
|
+
function g(e) {
|
|
67
|
+
let t = e.store.parents, n = /* @__PURE__ */ new Map();
|
|
68
|
+
for (let r of e.meshes.values()) {
|
|
69
|
+
let e = t[r.id];
|
|
70
|
+
if (e === -1) continue;
|
|
71
|
+
let i = n.get(e);
|
|
72
|
+
i || n.set(e, i = []), i.push(r);
|
|
73
|
+
}
|
|
74
|
+
return n;
|
|
75
|
+
}
|
|
76
|
+
function _(e, t, n, r, i) {
|
|
77
|
+
let a = n, o = r, s = v(e);
|
|
78
|
+
if (s) {
|
|
79
|
+
let e = Infinity, n = -Infinity, r = 0, i = s.length / 3, c = [
|
|
80
|
+
0,
|
|
81
|
+
1,
|
|
82
|
+
2
|
|
83
|
+
].map((e) => {
|
|
84
|
+
let t = 0;
|
|
85
|
+
for (let n = e; n < s.length; n += 3) t += s[n];
|
|
86
|
+
return t / i;
|
|
87
|
+
});
|
|
88
|
+
for (let i = 0; i < s.length; i += 3) {
|
|
89
|
+
let a = s[i] - c[0], o = s[i + 1] - c[1], l = s[i + 2] - c[2], u = a * t[0] + o * t[1] + l * t[2];
|
|
90
|
+
e = Math.min(e, u), n = Math.max(n, u), r += a * a + o * o + l * l - u * u;
|
|
91
|
+
}
|
|
92
|
+
a = n - e, o = Math.sqrt(r / i);
|
|
93
|
+
}
|
|
94
|
+
return [2 / (i * o * o), 12 / (i * (3 * o * o + a * a))];
|
|
95
|
+
}
|
|
96
|
+
function v(e) {
|
|
97
|
+
if (e.type === "hull") return e.points;
|
|
98
|
+
if (e.type === "capsule") return null;
|
|
99
|
+
let t = /* @__PURE__ */ new Float64Array(24);
|
|
100
|
+
for (let n = 0; n < 8; n++) {
|
|
101
|
+
let i = r([
|
|
102
|
+
0,
|
|
103
|
+
1,
|
|
104
|
+
2
|
|
105
|
+
].map((t) => e.halfExtents[t] * (n >> t & 1 ? 1 : -1)), e.rotation);
|
|
106
|
+
for (let r = 0; r < 3; r++) t[n * 3 + r] = i[r] + e.center[r];
|
|
107
|
+
}
|
|
108
|
+
return t;
|
|
109
|
+
}
|
|
110
|
+
function y(e) {
|
|
111
|
+
let t = (e) => Array.prototype.every.call(e, Number.isFinite);
|
|
112
|
+
if (e?.type === "capsule") return e;
|
|
113
|
+
if (e?.type === "hull") {
|
|
114
|
+
if (!e.points || e.points.length < 12 || e.points.length % 3 || !t(e.points)) throw RangeError("A ragdoll hull needs at least four finite xyz points; pass points that span a volume.");
|
|
115
|
+
return e;
|
|
116
|
+
}
|
|
117
|
+
if (e?.type === "box") {
|
|
118
|
+
if (!(e.halfExtents?.length === 3 && t(e.halfExtents) && e.halfExtents.every((e) => e > 0)) || !(e.center?.length === 3 && t(e.center)) || !(e.rotation?.length === 4 && t(e.rotation)) || Math.abs(Math.hypot(...e.rotation) - 1) > .001) throw RangeError("A ragdoll box needs positive halfExtents, a finite center and a unit rotation; pass {center, halfExtents, rotation}.");
|
|
119
|
+
return e;
|
|
120
|
+
}
|
|
121
|
+
throw RangeError("A ragdoll shape must be of type 'capsule', 'hull' or 'box'.");
|
|
122
|
+
}
|
|
123
|
+
var b = (e, t, n) => {
|
|
124
|
+
if (typeof e != "number" || !(e > 0) || e === Infinity) throw RangeError(`Ragdoll ${t} must be a positive finite number; ${n}`);
|
|
125
|
+
return e;
|
|
126
|
+
}, x = class n {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
|
|
127
|
+
constructor(e, n) {
|
|
128
|
+
if (this.physics = e, this.unsubscribe = [], this.loose = 0, this.stepped = 0, this.disposed = !1, this.q = /* @__PURE__ */ new Float64Array(4), this.r = /* @__PURE__ */ new Float64Array(4), this.s = /* @__PURE__ */ new Float64Array(4), this.v = /* @__PURE__ */ new Float64Array(3), this.w = /* @__PURE__ */ new Float64Array(3), this.c = /* @__PURE__ */ new Float64Array(3), this.pose = /* @__PURE__ */ new Float64Array(7), this.turnBy = /* @__PURE__ */ new Float64Array(4), this.turned = /* @__PURE__ */ new Float64Array(4), this.omega = /* @__PURE__ */ new Float64Array(), typeof e?.addBody != "function" || e.isDisposed) throw TypeError("A ragdoll needs a live Physics world: new Ragdoll(physics, {root: hips}).");
|
|
129
|
+
if (!n || n.root === void 0 == (n.bones === void 0)) throw TypeError("Ragdoll options need exactly one of root (the hips node) or bones (a list of nodes).");
|
|
130
|
+
let i = n.minLength ?? .05, a = n.thickness ?? .2, o = n.density ?? 1e3;
|
|
131
|
+
if (!(i >= 0) || i === Infinity) throw RangeError("Ragdoll minLength must be a finite number of at least 0; pass metres, e.g. 0.05.");
|
|
132
|
+
if (b(a, "thickness", "pass a fraction of the bone length, e.g. 0.2."), b(o, "density", "pass kilograms per cubic metre, e.g. 1000."), this.stiffness = n.limitStiffness ?? .2, !(this.stiffness >= 0 && this.stiffness <= 1)) throw RangeError("Ragdoll limitStiffness must be from 0 to 1; pass the share of the error removed per step.");
|
|
133
|
+
let s = this.boneList(n, i), c = s[0].node.engine;
|
|
134
|
+
this.engine = c, this.name = "ragdoll:" + s[0].node.id;
|
|
135
|
+
let l = c.store, m = l.parents, h = /* @__PURE__ */ new Map();
|
|
136
|
+
s.forEach((e, t) => {
|
|
137
|
+
if (e.node.engine !== c) throw TypeError("Ragdoll bones must all belong to one engine; pass nodes of one skeleton.");
|
|
138
|
+
if (h.has(e.node.id)) throw TypeError("Ragdoll bones must be distinct; list each node once.");
|
|
139
|
+
h.set(e.node.id, t);
|
|
140
|
+
});
|
|
141
|
+
let v = s.map((e) => {
|
|
142
|
+
let t = m[e.node.id];
|
|
143
|
+
return t !== -1 && h.has(t) ? h.get(t) : -1;
|
|
144
|
+
});
|
|
145
|
+
if (v.filter((e) => e === -1).length !== 1) throw TypeError("Ragdoll bones must form one tree; list every node between the root bone and each other bone (each bone's parent node is a bone).");
|
|
146
|
+
let x = [], S = (e) => {
|
|
147
|
+
x.push(e), s.forEach((t, n) => v[n] === e && S(n));
|
|
148
|
+
};
|
|
149
|
+
S(v.indexOf(-1)), l.tick(!1);
|
|
150
|
+
let C = g(c), w = (e, t) => {
|
|
151
|
+
let n = e.matrix;
|
|
152
|
+
if (!(d(n) > 0)) throw RangeError("Ragdoll bones need positive world scales; remove zero or mirrored bone scales.");
|
|
153
|
+
return t[0] = n[12], t[1] = n[13], t[2] = n[14], t.set(f(n, this.q), 3), t;
|
|
154
|
+
}, T = [], E = [], D = /* @__PURE__ */ new Map(), O = n.collisionGroups ?? 2147516415;
|
|
155
|
+
if (!Number.isInteger(O) || O < 0 || O > 4294967295) throw RangeError("Ragdoll collisionGroups must be a packed 32-bit integer; build it with collisionGroups().");
|
|
156
|
+
this.settings = {
|
|
157
|
+
collisionGroups: O,
|
|
158
|
+
friction: n.friction ?? .6,
|
|
159
|
+
linearDamping: n.linearDamping ?? .05,
|
|
160
|
+
angularDamping: n.angularDamping ?? .8,
|
|
161
|
+
limitStiffness: this.stiffness
|
|
162
|
+
};
|
|
163
|
+
try {
|
|
164
|
+
for (let i of x) {
|
|
165
|
+
let c = s[i], l = c.node, d = w(l, /* @__PURE__ */ new Float64Array(7)), f = [
|
|
166
|
+
d[0],
|
|
167
|
+
d[1],
|
|
168
|
+
d[2]
|
|
169
|
+
], m = [
|
|
170
|
+
d[3],
|
|
171
|
+
d[4],
|
|
172
|
+
d[5],
|
|
173
|
+
d[6]
|
|
174
|
+
], h = t(m), g = (C.get(l.id) ?? []).map((e) => [
|
|
175
|
+
e.matrix[12],
|
|
176
|
+
e.matrix[13],
|
|
177
|
+
e.matrix[14]
|
|
178
|
+
]), x = [
|
|
179
|
+
0,
|
|
180
|
+
1,
|
|
181
|
+
0
|
|
182
|
+
], S = 0, O = 0;
|
|
183
|
+
if (g.length) {
|
|
184
|
+
let e = [
|
|
185
|
+
0,
|
|
186
|
+
1,
|
|
187
|
+
2
|
|
188
|
+
].map((e) => g.reduce((t, n) => t + n[e], 0) / g.length - f[e]), t = e, n = Math.hypot(e[0], e[1], e[2]);
|
|
189
|
+
if (n < .001) for (let e of g) {
|
|
190
|
+
let r = [
|
|
191
|
+
e[0] - f[0],
|
|
192
|
+
e[1] - f[1],
|
|
193
|
+
e[2] - f[2]
|
|
194
|
+
], i = Math.hypot(r[0], r[1], r[2]);
|
|
195
|
+
i > n && (n = i, t = r);
|
|
196
|
+
}
|
|
197
|
+
if (n > 1e-6) {
|
|
198
|
+
x = r(t.map((e) => e / n), h), S = n;
|
|
199
|
+
for (let e of g) {
|
|
200
|
+
let r = [
|
|
201
|
+
e[0] - f[0],
|
|
202
|
+
e[1] - f[1],
|
|
203
|
+
e[2] - f[2]
|
|
204
|
+
], i = (r[0] * t[0] + r[1] * t[1] + r[2] * t[2]) / n;
|
|
205
|
+
O = Math.max(O, Math.hypot(r[0] - t[0] / n * i, r[1] - t[1] / n * i, r[2] - t[2] / n * i));
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
let k = c.length === void 0 ? S : b(c.length, "bone length", "pass metres, or leave it out for a bone with children.");
|
|
210
|
+
if (!(k > 0)) throw TypeError(`Ragdoll bone "${l.name || l.id}" has no children to measure; give it a length in metres.`);
|
|
211
|
+
let A = c.radius === void 0 ? Math.max(k * a, O / 2) : b(c.radius, "bone radius", "pass metres, or leave it out for thickness times the length."), j = Math.PI * A * A * (2 * Math.max(k / 2 - A, .001) + 4 / 3 * A), M = c.mass === void 0 ? j * o : b(c.mass, "bone mass", "pass kilograms, or leave it out for the capsule volume times density."), N = Float64Array.from(x), P = y(c.shape ?? { type: "capsule" }), F = e.addBody(null, {
|
|
212
|
+
type: n.active ? "dynamic" : "kinematicPosition",
|
|
213
|
+
position: f,
|
|
214
|
+
rotation: m,
|
|
215
|
+
linearDamping: this.settings.linearDamping,
|
|
216
|
+
angularDamping: this.settings.angularDamping,
|
|
217
|
+
userData: {
|
|
218
|
+
ragdoll: this,
|
|
219
|
+
node: l
|
|
220
|
+
},
|
|
221
|
+
colliders: this.collider(P, N, k, A, M)
|
|
222
|
+
});
|
|
223
|
+
E.push(F);
|
|
224
|
+
let I = v[i] === -1 ? -1 : D.get(v[i]), L = new Float64Array([
|
|
225
|
+
0,
|
|
226
|
+
0,
|
|
227
|
+
0,
|
|
228
|
+
1
|
|
229
|
+
]), R = null, z = null, B = null;
|
|
230
|
+
if (I !== -1) {
|
|
231
|
+
let e = T[I], i = t(e.world.subarray(3, 7)), a = r([
|
|
232
|
+
f[0] - e.world[0],
|
|
233
|
+
f[1] - e.world[1],
|
|
234
|
+
f[2] - e.world[2]
|
|
235
|
+
], i);
|
|
236
|
+
p(i, m, L);
|
|
237
|
+
let o = c.joint ?? n.joint ?? u;
|
|
238
|
+
({joint: R, cone: z, spec: B} = this.join(e.body, F, o, a, L));
|
|
239
|
+
}
|
|
240
|
+
let V = {
|
|
241
|
+
node: l,
|
|
242
|
+
body: F,
|
|
243
|
+
joint: R,
|
|
244
|
+
parent: I,
|
|
245
|
+
length: k,
|
|
246
|
+
radius: A,
|
|
247
|
+
mass: M,
|
|
248
|
+
shape: P,
|
|
249
|
+
axis: N,
|
|
250
|
+
rest: L,
|
|
251
|
+
bind: new Float64Array([
|
|
252
|
+
0,
|
|
253
|
+
0,
|
|
254
|
+
0,
|
|
255
|
+
1
|
|
256
|
+
]),
|
|
257
|
+
spec: B,
|
|
258
|
+
cone: z,
|
|
259
|
+
inertia: Float64Array.from(_(P, N, k, A, M)),
|
|
260
|
+
prev: d.slice(),
|
|
261
|
+
cur: d.slice(),
|
|
262
|
+
animated: /* @__PURE__ */ new Float64Array(7),
|
|
263
|
+
written: (/* @__PURE__ */ new Float64Array(7)).fill(NaN),
|
|
264
|
+
local: /* @__PURE__ */ new Float64Array(7),
|
|
265
|
+
world: d,
|
|
266
|
+
target: [
|
|
267
|
+
d[0],
|
|
268
|
+
d[1],
|
|
269
|
+
d[2],
|
|
270
|
+
d[3],
|
|
271
|
+
d[4],
|
|
272
|
+
d[5],
|
|
273
|
+
d[6]
|
|
274
|
+
],
|
|
275
|
+
limp: !!n.active,
|
|
276
|
+
weight: +!!n.active,
|
|
277
|
+
fade: 0,
|
|
278
|
+
fadeFrom: 0,
|
|
279
|
+
fadeAt: 0,
|
|
280
|
+
landed: !1,
|
|
281
|
+
jump: !n.active
|
|
282
|
+
};
|
|
283
|
+
this.readLocal(l, V.animated), V.local.set(V.animated), this.fit(V, T), D.set(i, T.length), T.push(V);
|
|
284
|
+
}
|
|
285
|
+
} catch (e) {
|
|
286
|
+
for (let e of T) e.joint?.remove();
|
|
287
|
+
for (let e of E) e.remove();
|
|
288
|
+
throw e;
|
|
289
|
+
}
|
|
290
|
+
this.parts = T, this.bones = T, this.omega = new Float64Array(T.length * 3), this.loose = n.active ? T.length : 0, this.unsubscribe.push(e.on("beforestep", () => this.beforeStep()), e.on("afterstep", () => this.afterStep()));
|
|
291
|
+
}
|
|
292
|
+
static attach(t, r) {__margoAssertCore(t,__margoCoreRequirement("0.1.0",import.meta.url));
|
|
293
|
+
let i = new n(t, r), a = i.engine;
|
|
294
|
+
return s(a, a.sceneOf(t)).run(() => {
|
|
295
|
+
if (a.hasPlugin(i.name)) throw i.dispose(), new e("attached", "This skeleton already has an attached ragdoll; dispose it first, or use the one you have.");
|
|
296
|
+
try {
|
|
297
|
+
a.use(i);
|
|
298
|
+
} catch (e) {
|
|
299
|
+
throw i.dispose(), e;
|
|
300
|
+
}
|
|
301
|
+
return i;
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
collider(e, t, n, r, i) {
|
|
305
|
+
let { friction: a, collisionGroups: o } = this.settings, s = {
|
|
306
|
+
mass: i,
|
|
307
|
+
friction: a,
|
|
308
|
+
collisionGroups: o
|
|
309
|
+
};
|
|
310
|
+
return e.type === "hull" ? {
|
|
311
|
+
shape: "convexHull",
|
|
312
|
+
points: e.points,
|
|
313
|
+
...s
|
|
314
|
+
} : e.type === "box" ? {
|
|
315
|
+
shape: "box",
|
|
316
|
+
halfExtents: e.halfExtents,
|
|
317
|
+
offset: e.center,
|
|
318
|
+
rotation: e.rotation,
|
|
319
|
+
...s
|
|
320
|
+
} : {
|
|
321
|
+
shape: "capsule",
|
|
322
|
+
halfHeight: Math.max(n / 2 - r, .001),
|
|
323
|
+
radius: r,
|
|
324
|
+
offset: [
|
|
325
|
+
t[0] * (n / 2),
|
|
326
|
+
t[1] * (n / 2),
|
|
327
|
+
t[2] * (n / 2)
|
|
328
|
+
],
|
|
329
|
+
rotation: [...m([
|
|
330
|
+
0,
|
|
331
|
+
1,
|
|
332
|
+
0
|
|
333
|
+
], t, /* @__PURE__ */ new Float64Array(4))],
|
|
334
|
+
...s
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
setShape(e, t) {
|
|
338
|
+
this.live();
|
|
339
|
+
let n = e && "body" in e ? e.node : e, r = this.parts.find((e) => e.node === n);
|
|
340
|
+
if (!r) throw RangeError("That node is not a bone of this ragdoll; pass a node or part of ragdoll.bones.");
|
|
341
|
+
y(t);
|
|
342
|
+
let i = [...r.body.colliders];
|
|
343
|
+
r.body.addCollider(this.collider(t, r.axis, r.length, r.radius, r.mass));
|
|
344
|
+
for (let e of i) r.body.removeCollider(e);
|
|
345
|
+
return r.shape = t, r.inertia.set(_(t, r.axis, r.length, r.radius, r.mass)), this;
|
|
346
|
+
}
|
|
347
|
+
boneList(e, t) {
|
|
348
|
+
if (e.bones !== void 0) {
|
|
349
|
+
if (!Array.isArray(e.bones) || !e.bones.length) throw TypeError("Ragdoll bones must be a non-empty array of nodes or {node} objects.");
|
|
350
|
+
return e.bones.map((e) => {
|
|
351
|
+
let t = e && "node" in e ? e : { node: e };
|
|
352
|
+
if (!t.node || typeof t.node.setQuaternion != "function" || !t.node.engine) throw TypeError("Ragdoll bones must be skeleton nodes (meshes) or {node} objects; pass model.nodes[i].");
|
|
353
|
+
return t.node.check(), t;
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
let n = e.root;
|
|
357
|
+
if (typeof n?.setQuaternion != "function" || !n.engine) throw TypeError("Ragdoll root must be a skeleton node (a mesh), e.g. the hips: model.nodes[i].");
|
|
358
|
+
n.check(), n.engine.store.tick(!1);
|
|
359
|
+
let r = g(n.engine), i = [], a = (e) => {
|
|
360
|
+
let n = r.get(e.id);
|
|
361
|
+
if (!n?.length) return;
|
|
362
|
+
let o = e.matrix;
|
|
363
|
+
if (!(Math.max(...n.map((e) => Math.hypot(e.matrix[12] - o[12], e.matrix[13] - o[13], e.matrix[14] - o[14]))) < t && i.length)) {
|
|
364
|
+
i.push({ node: e });
|
|
365
|
+
for (let e of n) a(e);
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
if (a(n), !i.length) throw TypeError("Ragdoll root has no child bones; pass the hips of a skeleton, or list bones with lengths.");
|
|
369
|
+
return i;
|
|
370
|
+
}
|
|
371
|
+
join(e, t, n, r, i) {
|
|
372
|
+
let a = this.physics, o = r;
|
|
373
|
+
if (n?.type === "free" || n?.type === "cone") {
|
|
374
|
+
let r = null;
|
|
375
|
+
if (n.type === "cone") {
|
|
376
|
+
let e = n.swing ?? Math.PI / 4, [t, i] = n.twist ?? [-Math.PI / 6, Math.PI / 6];
|
|
377
|
+
if (!(e >= 0 && e <= Math.PI) || !(t <= i && t >= -Math.PI && i <= Math.PI)) throw RangeError("Ragdoll cone limits need a swing from 0 to π and a twist [min, max] within -π to π; pass radians.");
|
|
378
|
+
r = {
|
|
379
|
+
swing: e,
|
|
380
|
+
min: t,
|
|
381
|
+
max: i
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
if (!r) return {
|
|
385
|
+
joint: a.addJoint(e, t, {
|
|
386
|
+
type: "spherical",
|
|
387
|
+
anchorA: o,
|
|
388
|
+
anchorB: [
|
|
389
|
+
0,
|
|
390
|
+
0,
|
|
391
|
+
0
|
|
392
|
+
]
|
|
393
|
+
}),
|
|
394
|
+
cone: r,
|
|
395
|
+
spec: { type: "free" }
|
|
396
|
+
};
|
|
397
|
+
let s = m([
|
|
398
|
+
1,
|
|
399
|
+
0,
|
|
400
|
+
0
|
|
401
|
+
], [
|
|
402
|
+
0,
|
|
403
|
+
1,
|
|
404
|
+
0
|
|
405
|
+
], /* @__PURE__ */ new Float64Array(4)), c = p(i, s, /* @__PURE__ */ new Float64Array(4));
|
|
406
|
+
return {
|
|
407
|
+
joint: a.addJoint(e, t, {
|
|
408
|
+
type: "cone",
|
|
409
|
+
anchorA: o,
|
|
410
|
+
anchorB: [
|
|
411
|
+
0,
|
|
412
|
+
0,
|
|
413
|
+
0
|
|
414
|
+
],
|
|
415
|
+
frameA: [
|
|
416
|
+
c[0],
|
|
417
|
+
c[1],
|
|
418
|
+
c[2],
|
|
419
|
+
c[3]
|
|
420
|
+
],
|
|
421
|
+
frameB: [
|
|
422
|
+
s[0],
|
|
423
|
+
s[1],
|
|
424
|
+
s[2],
|
|
425
|
+
s[3]
|
|
426
|
+
],
|
|
427
|
+
swing: r.swing,
|
|
428
|
+
twist: [r.min, r.max]
|
|
429
|
+
}),
|
|
430
|
+
cone: null,
|
|
431
|
+
spec: {
|
|
432
|
+
type: "cone",
|
|
433
|
+
swing: r.swing,
|
|
434
|
+
twist: [r.min, r.max]
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
if (n?.type !== "hinge") throw TypeError("Unknown ragdoll joint type; use 'cone', 'hinge' or 'free'.");
|
|
439
|
+
let s = n.axis, c = Array.isArray(s) && s.length === 3 ? Math.hypot(s[0], s[1], s[2]) : NaN;
|
|
440
|
+
if (!(c > 0) || c === Infinity) throw RangeError("Ragdoll hinge axis must be a nonzero finite [x, y, z] in the bone frame; e.g. [1, 0, 0].");
|
|
441
|
+
let [l, u] = n.limits ?? [-Math.PI * .75, 0];
|
|
442
|
+
if (!(l <= u && l >= -Math.PI && u <= Math.PI)) throw RangeError("Ragdoll hinge limits need [min, max] within -π to π; pass radians.");
|
|
443
|
+
let d = [
|
|
444
|
+
s[0] / c,
|
|
445
|
+
s[1] / c,
|
|
446
|
+
s[2] / c
|
|
447
|
+
], f = m([
|
|
448
|
+
1,
|
|
449
|
+
0,
|
|
450
|
+
0
|
|
451
|
+
], d, /* @__PURE__ */ new Float64Array(4)), h = p(i, f, /* @__PURE__ */ new Float64Array(4)), g = (e) => [
|
|
452
|
+
e[0],
|
|
453
|
+
e[1],
|
|
454
|
+
e[2],
|
|
455
|
+
e[3]
|
|
456
|
+
];
|
|
457
|
+
return {
|
|
458
|
+
joint: a.addJoint(e, t, {
|
|
459
|
+
type: "revolute",
|
|
460
|
+
frameA: g(h),
|
|
461
|
+
frameB: g(f),
|
|
462
|
+
anchorA: o,
|
|
463
|
+
anchorB: [
|
|
464
|
+
0,
|
|
465
|
+
0,
|
|
466
|
+
0
|
|
467
|
+
],
|
|
468
|
+
limits: [l, u]
|
|
469
|
+
}),
|
|
470
|
+
cone: null,
|
|
471
|
+
spec: {
|
|
472
|
+
type: "hinge",
|
|
473
|
+
axis: [
|
|
474
|
+
d[0],
|
|
475
|
+
d[1],
|
|
476
|
+
d[2]
|
|
477
|
+
],
|
|
478
|
+
limits: [l, u]
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
get active() {
|
|
483
|
+
return this.loose > 0;
|
|
484
|
+
}
|
|
485
|
+
get weight() {
|
|
486
|
+
let e = 0;
|
|
487
|
+
for (let t of this.parts) e = Math.max(e, t.weight);
|
|
488
|
+
return e;
|
|
489
|
+
}
|
|
490
|
+
set weight(e) {
|
|
491
|
+
if (!(e >= 0 && e <= 1)) throw RangeError("Ragdoll weight must be from 0 to 1.");
|
|
492
|
+
for (let t of this.parts) (t.limp || !this.loose) && (t.weight = e, t.fade = 0);
|
|
493
|
+
}
|
|
494
|
+
get rootPosition() {
|
|
495
|
+
let e = this.live().parts[0].cur;
|
|
496
|
+
return [
|
|
497
|
+
e[0],
|
|
498
|
+
e[1],
|
|
499
|
+
e[2]
|
|
500
|
+
];
|
|
501
|
+
}
|
|
502
|
+
limbBones(e) {
|
|
503
|
+
if (e === void 0) return this.parts;
|
|
504
|
+
let t = /* @__PURE__ */ new Set();
|
|
505
|
+
for (let n of Array.isArray(e) ? e : [e]) {
|
|
506
|
+
let e = n && "body" in n ? n.node : n, r = this.parts.find((t) => t.node === e);
|
|
507
|
+
if (!r) throw RangeError("That node is not a bone of this ragdoll; pass nodes or parts of ragdoll.bones.");
|
|
508
|
+
t.add(r);
|
|
509
|
+
}
|
|
510
|
+
for (let e of this.parts) e.parent !== -1 && t.has(this.parts[e.parent]) && t.add(e);
|
|
511
|
+
return [...t];
|
|
512
|
+
}
|
|
513
|
+
activate(e) {
|
|
514
|
+
this.live();
|
|
515
|
+
let n = this.physics.fixedTimestep, r = this.stepped >= 2;
|
|
516
|
+
this.engine.store.tick(!1);
|
|
517
|
+
for (let i of this.limbBones(e)) {
|
|
518
|
+
if (i.limp) continue;
|
|
519
|
+
this.fit(i, this.parts), i.limp = !0, i.weight = 1, i.fade = 0, this.loose++, i.body.setType("dynamic");
|
|
520
|
+
let { prev: e, cur: a } = i;
|
|
521
|
+
if (!r) continue;
|
|
522
|
+
if (i.body.setLinearVelocity([
|
|
523
|
+
(a[0] - e[0]) / n,
|
|
524
|
+
(a[1] - e[1]) / n,
|
|
525
|
+
(a[2] - e[2]) / n
|
|
526
|
+
]), p(a.subarray(3, 7), t(e.subarray(3, 7), this.q), this.r), this.r[3] < 0) for (let e = 0; e < 4; e++) this.r[e] = -this.r[e];
|
|
527
|
+
let o = Math.hypot(this.r[0], this.r[1], this.r[2]), s = 2 * Math.atan2(o, this.r[3]), c = o > 1e-9 ? s / o / n : 0;
|
|
528
|
+
i.body.setAngularVelocity([
|
|
529
|
+
this.r[0] * c,
|
|
530
|
+
this.r[1] * c,
|
|
531
|
+
this.r[2] * c
|
|
532
|
+
]);
|
|
533
|
+
}
|
|
534
|
+
return this;
|
|
535
|
+
}
|
|
536
|
+
deactivate(e = .3, t) {
|
|
537
|
+
if (this.live(), !(e >= 0) || e === Infinity) throw RangeError("Ragdoll blend duration must be a finite number of seconds, 0 or more.");
|
|
538
|
+
let n = this.limbBones(t);
|
|
539
|
+
if (!this.loose) return this;
|
|
540
|
+
this.physicsLocals();
|
|
541
|
+
for (let t of n) t.limp && (t.body.setType("kinematicPosition"), t.limp = !1, t.jump = !0, t.fade = e > 0 ? 1 / e : 0, t.fadeFrom = t.weight, t.fadeAt = 0, e || (t.weight = 0), this.loose--);
|
|
542
|
+
return this;
|
|
543
|
+
}
|
|
544
|
+
part(e) {
|
|
545
|
+
return this.parts.find((t) => t.node === e);
|
|
546
|
+
}
|
|
547
|
+
setup(t) {
|
|
548
|
+
if (this.disposed) throw new e("disposed", "Ragdoll is disposed; create a new Ragdoll.");
|
|
549
|
+
if (t !== this.engine) throw new e("attached", "Ragdoll belongs to its bones' engine; attach it to that engine.");
|
|
550
|
+
this.attached = t;
|
|
551
|
+
}
|
|
552
|
+
onPreUpdate(e) {
|
|
553
|
+
if (this.disposed) return;
|
|
554
|
+
if (this.physics.isDisposed || !this.parts[0].body.valid) {
|
|
555
|
+
this.dispose();
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
if (!Number.isFinite(e) || e < 0) throw RangeError("Invalid ragdoll delta; pass a finite delta of 0 or more seconds.");
|
|
559
|
+
let t = this.engine.store;
|
|
560
|
+
t.tick(!1);
|
|
561
|
+
for (let t of this.parts) if (this.track(t), !t.limp && t.fade > 0) {
|
|
562
|
+
t.fadeAt = Math.min(1, t.fadeAt + t.fade * e);
|
|
563
|
+
let n = t.fadeAt;
|
|
564
|
+
t.weight = t.fadeFrom * (1 - n * n * (3 - 2 * n)), n >= 1 && (t.weight = 0, t.fade = 0, t.landed = !0);
|
|
565
|
+
}
|
|
566
|
+
this.loose && this.physicsLocals(), this.write(), t.tick(!1);
|
|
567
|
+
for (let e of this.parts) {
|
|
568
|
+
if (e.limp) continue;
|
|
569
|
+
let t = e.node.matrix, n = e.target;
|
|
570
|
+
f(t, this.q), n[0] = t[12], n[1] = t[13], n[2] = t[14], n[3] = this.q[0], n[4] = this.q[1], n[5] = this.q[2], n[6] = this.q[3];
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
fit(e, n) {
|
|
574
|
+
let r = this.engine.store.parents[e.node.id], i = e.parent === -1 ? r === -1 ? null : this.engine.meshes.get(r) : n[e.parent].node, a = f(e.node.matrix, /* @__PURE__ */ new Float64Array(4));
|
|
575
|
+
i && p(t(f(i.matrix, this.q), this.q), a, a);
|
|
576
|
+
let o = this.readLocal(e.node, this.pose);
|
|
577
|
+
p(t(a, a), o.subarray(3, 7), e.bind), Math.hypot(e.bind[0], e.bind[1], e.bind[2]) < c && e.bind.set(l);
|
|
578
|
+
}
|
|
579
|
+
readLocal(e, t) {
|
|
580
|
+
let n = e.engine.store.transforms, r = e.id;
|
|
581
|
+
return t[0] = n.x[r], t[1] = n.y[r], t[2] = n.z[r], t[3] = n.qx[r], t[4] = n.qy[r], t[5] = n.qz[r], t[6] = n.qw[r], t;
|
|
582
|
+
}
|
|
583
|
+
track(e) {
|
|
584
|
+
let t = this.readLocal(e.node, this.pose), n = e.written;
|
|
585
|
+
for (let r = 0; r < 7; r++) if (t[r] !== n[r]) {
|
|
586
|
+
e.animated.set(t);
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
physicsLocals() {
|
|
591
|
+
let e = this.physics.alpha;
|
|
592
|
+
for (let n of this.parts) {
|
|
593
|
+
let { prev: r, cur: i, world: a, local: o } = n;
|
|
594
|
+
for (let t = 0; t < 3; t++) a[t] = r[t] + (i[t] - r[t]) * e;
|
|
595
|
+
if (h(r, 3, i, 3, e, a, 3), !n.limp) continue;
|
|
596
|
+
if (o[0] = n.animated[0], o[1] = n.animated[1], o[2] = n.animated[2], n.parent !== -1) {
|
|
597
|
+
let e = this.parts[n.parent].world;
|
|
598
|
+
t(e.subarray(3, 7), this.q), p(this.q, a.subarray(3, 7), this.r), p(this.r, n.bind, o, 3);
|
|
599
|
+
continue;
|
|
600
|
+
}
|
|
601
|
+
let s = this.engine.store.parents[n.node.id];
|
|
602
|
+
if (s === -1) {
|
|
603
|
+
o.set(a), p(a.subarray(3, 7), n.bind, o, 3);
|
|
604
|
+
continue;
|
|
605
|
+
}
|
|
606
|
+
let c = this.engine.meshes.get(s).matrix;
|
|
607
|
+
t(f(c, this.q), this.q), p(this.q, a.subarray(3, 7), this.r), p(this.r, n.bind, o, 3);
|
|
608
|
+
let l = a[0] - c[12], u = a[1] - c[13], m = a[2] - c[14], g = d(c);
|
|
609
|
+
o[0] = (l * (c[5] * c[10] - c[6] * c[9]) + u * (c[8] * c[6] - c[4] * c[10]) + m * (c[4] * c[9] - c[8] * c[5])) / g, o[1] = (l * (c[9] * c[2] - c[1] * c[10]) + u * (c[0] * c[10] - c[8] * c[2]) + m * (c[8] * c[1] - c[0] * c[9])) / g, o[2] = (l * (c[1] * c[6] - c[5] * c[2]) + u * (c[4] * c[2] - c[0] * c[6]) + m * (c[0] * c[5] - c[4] * c[1])) / g;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
write() {
|
|
613
|
+
for (let e of this.parts) {
|
|
614
|
+
let { animated: t, local: n, written: r, node: i, weight: a } = e;
|
|
615
|
+
if (!a && !e.landed) continue;
|
|
616
|
+
if (e.landed = !1, h(t, 3, n, 3, a, r, 3), e.parent === -1) for (let e = 0; e < 3; e++) r[e] = t[e] + (n[e] - t[e]) * a;
|
|
617
|
+
else for (let e = 0; e < 3; e++) r[e] = t[e];
|
|
618
|
+
i.setPosition([
|
|
619
|
+
r[0],
|
|
620
|
+
r[1],
|
|
621
|
+
r[2]
|
|
622
|
+
]), i.setQuaternion([
|
|
623
|
+
r[3],
|
|
624
|
+
r[4],
|
|
625
|
+
r[5],
|
|
626
|
+
r[6]
|
|
627
|
+
]);
|
|
628
|
+
let o = i.engine.store.transforms, s = i.id;
|
|
629
|
+
r[0] = o.x[s], r[1] = o.y[s], r[2] = o.z[s], r[3] = o.qx[s], r[4] = o.qy[s], r[5] = o.qz[s], r[6] = o.qw[s];
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
beforeStep() {
|
|
633
|
+
if (!this.disposed && this.parts[0].body.valid) {
|
|
634
|
+
for (let e of this.parts) {
|
|
635
|
+
if (e.limp) continue;
|
|
636
|
+
let t = e.target, n = [
|
|
637
|
+
t[0],
|
|
638
|
+
t[1],
|
|
639
|
+
t[2]
|
|
640
|
+
], r = [
|
|
641
|
+
t[3],
|
|
642
|
+
t[4],
|
|
643
|
+
t[5],
|
|
644
|
+
t[6]
|
|
645
|
+
];
|
|
646
|
+
e.jump && (e.jump = !1, e.body.setPosition(n), e.body.setRotation(r), e.cur.set(t)), e.body.setNextPosition(n), e.body.setNextRotation(r);
|
|
647
|
+
}
|
|
648
|
+
this.loose && this.limits();
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
limits() {
|
|
652
|
+
let e = this.parts, n = this.omega, i = this.stiffness, { q: a, r: o, s, v: c, w: l } = this, u = !1;
|
|
653
|
+
for (let t = 0; t < e.length; t++) {
|
|
654
|
+
let r = e[t].body.angularVelocity;
|
|
655
|
+
n[t * 3] = r[0], n[t * 3 + 1] = r[1], n[t * 3 + 2] = r[2];
|
|
656
|
+
}
|
|
657
|
+
for (let n = 1; n < e.length; n++) {
|
|
658
|
+
let d = e[n], f = d.cone;
|
|
659
|
+
if (!f || !d.limp) continue;
|
|
660
|
+
let m = e[d.parent], h = m.body.rotation, g = d.body.rotation;
|
|
661
|
+
if (p(h, d.rest, s), t(s, a), p(a, g, o), o[3] < 0) for (let e = 0; e < 4; e++) o[e] = -o[e];
|
|
662
|
+
let _ = d.axis, v = o[0] * _[0] + o[1] * _[1] + o[2] * _[2], y = 2 * Math.atan2(v, o[3]);
|
|
663
|
+
y > Math.PI && (y -= 2 * Math.PI);
|
|
664
|
+
let b = Math.hypot(v, o[3]);
|
|
665
|
+
b > 1e-9 ? (a[0] = -_[0] * v / b, a[1] = -_[1] * v / b, a[2] = -_[2] * v / b, a[3] = o[3] / b) : a.set([
|
|
666
|
+
0,
|
|
667
|
+
0,
|
|
668
|
+
0,
|
|
669
|
+
1
|
|
670
|
+
]), p(o, a, o);
|
|
671
|
+
let x = Math.hypot(o[0], o[1], o[2]), S = 2 * Math.atan2(x, Math.abs(o[3])), C = m.limp;
|
|
672
|
+
if (S > f.swing && x > 1e-9) {
|
|
673
|
+
let e = o[3] < 0 ? -1 : 1;
|
|
674
|
+
c[0] = o[0] / x * e, c[1] = o[1] / x * e, c[2] = o[2] / x * e, r(c, s, c), u = this.push(n, d.parent, c, C) || u, this.turn(d, c, -(S - f.swing) * i);
|
|
675
|
+
}
|
|
676
|
+
if (y > f.max || y < f.min) {
|
|
677
|
+
r(_, g, l);
|
|
678
|
+
let e = y - f.max;
|
|
679
|
+
y < f.min && (e = f.min - y, l[0] = -l[0], l[1] = -l[1], l[2] = -l[2]), u = this.push(n, d.parent, l, C) || u, this.turn(d, l, -e * i);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
if (u) for (let t = 0; t < e.length; t++) e[t].limp && e[t].body.setAngularVelocity([
|
|
683
|
+
n[t * 3],
|
|
684
|
+
n[t * 3 + 1],
|
|
685
|
+
n[t * 3 + 2]
|
|
686
|
+
]);
|
|
687
|
+
}
|
|
688
|
+
turn(e, t, n) {
|
|
689
|
+
let r = n / 2, i = Math.sin(r), a = this.turnBy;
|
|
690
|
+
a[0] = t[0] * i, a[1] = t[1] * i, a[2] = t[2] * i, a[3] = Math.cos(r);
|
|
691
|
+
let o = p(a, e.body.rotation, this.turned);
|
|
692
|
+
e.body.setRotation([
|
|
693
|
+
o[0],
|
|
694
|
+
o[1],
|
|
695
|
+
o[2],
|
|
696
|
+
o[3]
|
|
697
|
+
]);
|
|
698
|
+
}
|
|
699
|
+
push(e, t, n, r) {
|
|
700
|
+
let i = this.omega, a = e * 3, o = t * 3, s = (i[a] - i[o]) * n[0] + (i[a + 1] - i[o + 1]) * n[1] + (i[a + 2] - i[o + 2]) * n[2];
|
|
701
|
+
if (s <= 0) return !1;
|
|
702
|
+
let c = this.inverseInertia(this.parts[e], n), l = r ? this.inverseInertia(this.parts[t], n) : 0, u = c + l;
|
|
703
|
+
if (!(u > 0)) return !1;
|
|
704
|
+
let d = (0 - s) / u;
|
|
705
|
+
for (let e = 0; e < 3; e++) i[a + e] += d * c * n[e], i[o + e] -= d * l * n[e];
|
|
706
|
+
return !0;
|
|
707
|
+
}
|
|
708
|
+
inverseInertia(e, t) {
|
|
709
|
+
let n = this.c, i = e.cur.subarray(3, 7);
|
|
710
|
+
r(e.axis, i, n);
|
|
711
|
+
let a = n[0] * t[0] + n[1] * t[1] + n[2] * t[2], o = a * a;
|
|
712
|
+
return 1 / (o / e.inertia[0] + (1 - o) / e.inertia[1]);
|
|
713
|
+
}
|
|
714
|
+
afterStep() {
|
|
715
|
+
if (!this.disposed && this.parts[0].body.valid) {
|
|
716
|
+
this.stepped++;
|
|
717
|
+
for (let e of this.parts) {
|
|
718
|
+
e.prev.set(e.cur);
|
|
719
|
+
let t = e.body.position, n = e.body.rotation;
|
|
720
|
+
e.cur[0] = t[0], e.cur[1] = t[1], e.cur[2] = t[2], e.cur[3] = n[0], e.cur[4] = n[1], e.cur[5] = n[2], e.cur[6] = n[3];
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
live() {
|
|
725
|
+
if (this.disposed) throw new e("disposed", "Ragdoll is disposed; create a new Ragdoll.");
|
|
726
|
+
return this;
|
|
727
|
+
}
|
|
728
|
+
dispose() {
|
|
729
|
+
if (this.disposed) return;
|
|
730
|
+
this.disposed = !0;
|
|
731
|
+
for (let e of this.unsubscribe) e();
|
|
732
|
+
if (this.unsubscribe.length = 0, !this.physics.isDisposed) for (let e of this.parts) e.joint?.remove(), e.body.remove();
|
|
733
|
+
let e = this.attached;
|
|
734
|
+
this.attached = void 0, e?.sceneOf(this)?.removePlugin(this.name);
|
|
735
|
+
}
|
|
736
|
+
[Symbol.dispose ?? Symbol()]() {
|
|
737
|
+
this.dispose();
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
//#endregion
|
|
741
|
+
export { x as Ragdoll };
|