@jdultra/threedtiles 14.0.21 → 14.0.22
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/dist/assets/physicsHelper.worker-Cr8S3sZk.js +37 -0
- package/dist/assets/physicsRapier.worker-jgQ9dgLt.js +393 -0
- package/dist/threedtiles.cjs.js +17 -447
- package/dist/threedtiles.cjs.js.map +1 -1
- package/dist/threedtiles.es.js +2237 -2687
- package/dist/threedtiles.es.js.map +1 -1
- package/dist/threedtiles.umd.js +20 -450
- package/dist/threedtiles.umd.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
function u(n, e = null, t = []) {
|
|
2
|
+
n != null && postMessage({ replyTo: n, result: e }, t);
|
|
3
|
+
}
|
|
4
|
+
function a(n, e) {
|
|
5
|
+
n != null && postMessage({ replyTo: n, error: e && (e.message || String(e)) || String(e) });
|
|
6
|
+
}
|
|
7
|
+
function f(n, e) {
|
|
8
|
+
if (!(n instanceof Float32Array))
|
|
9
|
+
throw new Error("positions must be a Float32Array");
|
|
10
|
+
const t = n.length;
|
|
11
|
+
if (t % 3 !== 0)
|
|
12
|
+
throw new Error("positions length must be a multiple of 3");
|
|
13
|
+
const s = e && +e[0] || 1, r = e && +e[1] || 1, o = e && +e[2] || 1;
|
|
14
|
+
if (s !== 1 || r !== 1 || o !== 1)
|
|
15
|
+
for (let l = 0; l < t; l += 3)
|
|
16
|
+
n[l + 0] *= s, n[l + 1] *= r, n[l + 2] *= o;
|
|
17
|
+
return { hullVertices: n, hullIndices: null };
|
|
18
|
+
}
|
|
19
|
+
self.addEventListener("message", (n) => {
|
|
20
|
+
const e = n.data || {}, t = typeof e._envId < "u" ? e._envId : typeof e.replyTo < "u" ? e.replyTo : e.id;
|
|
21
|
+
try {
|
|
22
|
+
switch (e.type) {
|
|
23
|
+
case "computeConvexHull": {
|
|
24
|
+
const s = e.positions instanceof Float32Array ? e.positions : new Float32Array(e.positions?.buffer || e.positions), r = e.localScale || e.scale || e.local?.s || [1, 1, 1], { hullVertices: o, hullIndices: i } = f(s, r), c = [];
|
|
25
|
+
o?.buffer && c.push(o.buffer), i?.buffer, u(t, { vertices: o, indices: i }, c);
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
default: {
|
|
29
|
+
u(t, { ok: !1, reason: "unknown message type" });
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
} catch (s) {
|
|
34
|
+
a(t, s);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=physicsHelper.worker-Cr8S3sZk.js.map
|
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
let l = null, p = null, A = null;
|
|
2
|
+
const x = /* @__PURE__ */ new Map(), B = /* @__PURE__ */ new Map(), C = /* @__PURE__ */ new Map(), M = /* @__PURE__ */ new Map();
|
|
3
|
+
let I = "vector", D = { x: 0, y: -9.81, z: 0 }, W = { x: 0, y: 0, z: 0 }, q = 9.81, E = 0, R = 1 / 60;
|
|
4
|
+
function F(t, e = null) {
|
|
5
|
+
t != null && postMessage({ replyTo: t, result: e });
|
|
6
|
+
}
|
|
7
|
+
function U(t, e) {
|
|
8
|
+
t != null && postMessage({ replyTo: t, error: e && (e.message || e) || "error" });
|
|
9
|
+
}
|
|
10
|
+
function L(t, e, o) {
|
|
11
|
+
return Math.max(e, Math.min(o, t));
|
|
12
|
+
}
|
|
13
|
+
function w(t) {
|
|
14
|
+
return { x: +t[0], y: +t[1], z: +t[2] };
|
|
15
|
+
}
|
|
16
|
+
function z(t) {
|
|
17
|
+
return { x: +t[0], y: +t[1], z: +t[2], w: +t[3] };
|
|
18
|
+
}
|
|
19
|
+
function P(t, e) {
|
|
20
|
+
return { x: t.x - e.x, y: t.y - e.y, z: t.z - e.z };
|
|
21
|
+
}
|
|
22
|
+
function j(t, e) {
|
|
23
|
+
return { x: t.x * e, y: t.y * e, z: t.z * e };
|
|
24
|
+
}
|
|
25
|
+
function O(t) {
|
|
26
|
+
return Math.hypot(t.x, t.y, t.z);
|
|
27
|
+
}
|
|
28
|
+
function $(t) {
|
|
29
|
+
const e = O(t) || 1;
|
|
30
|
+
return { x: t.x / e, y: t.y / e, z: t.z / e };
|
|
31
|
+
}
|
|
32
|
+
async function v() {
|
|
33
|
+
if (A) {
|
|
34
|
+
await A;
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
A = (async () => {
|
|
38
|
+
if (!l) {
|
|
39
|
+
postMessage({ type: "debug", msg: "importing rapier module" });
|
|
40
|
+
const t = await import("./rapier-CaKmQPsS.js"), o = { locateFile: (r) => {
|
|
41
|
+
try {
|
|
42
|
+
return new URL(r, import.meta.url).href;
|
|
43
|
+
} catch {
|
|
44
|
+
return r;
|
|
45
|
+
}
|
|
46
|
+
} }, n = t?.default ?? t;
|
|
47
|
+
postMessage({
|
|
48
|
+
type: "debug",
|
|
49
|
+
msg: "rapier module import result",
|
|
50
|
+
hasDefault: !!t?.default,
|
|
51
|
+
hasInitFunction: typeof n?.init == "function",
|
|
52
|
+
isFactoryFunction: typeof n == "function"
|
|
53
|
+
});
|
|
54
|
+
try {
|
|
55
|
+
if (typeof n == "function") {
|
|
56
|
+
postMessage({ type: "debug", msg: "rapier: calling module factory function" });
|
|
57
|
+
const r = n(o);
|
|
58
|
+
l = r && typeof r.then == "function" ? await r : r || n, postMessage({ type: "debug", msg: "rapier factory resolved", hasWorld: !!l?.World });
|
|
59
|
+
} else if (typeof n?.init == "function")
|
|
60
|
+
postMessage({ type: "debug", msg: "rapier: calling init()" }), await n.init(o), l = n, postMessage({ type: "debug", msg: "rapier.init completed", hasWorld: !!l?.World });
|
|
61
|
+
else if (n)
|
|
62
|
+
l = n, postMessage({ type: "debug", msg: "rapier: using imported module as-is", hasWorld: !!l?.World });
|
|
63
|
+
else
|
|
64
|
+
throw new Error("Imported Rapier module is empty/invalid");
|
|
65
|
+
} catch (r) {
|
|
66
|
+
throw postMessage({ type: "error", msg: "rapier init failed", error: r && (r.message || String(r)) || String(r) }), r;
|
|
67
|
+
}
|
|
68
|
+
if (!l) throw new Error("Failed to import Rapier module");
|
|
69
|
+
}
|
|
70
|
+
if (!p) {
|
|
71
|
+
const t = I === "vector" ? D : { x: 0, y: 0, z: 0 };
|
|
72
|
+
try {
|
|
73
|
+
typeof l.World == "function" ? p = new l.World(t) : typeof l.World?.new == "function" ? p = l.World.new(t) : typeof l?.World == "object" && typeof l.World.create == "function" ? p = l.World.create(t) : typeof l == "function" ? p = l(t) : p = l.World ? l.World(t) : null, postMessage({ type: "debug", msg: "rapier world created" });
|
|
74
|
+
} catch (e) {
|
|
75
|
+
throw postMessage({ type: "error", msg: "failed to construct rapier World", error: e && (e.message || String(e)) || String(e) }), new Error("Failed to construct Rapier World: " + (e && e.message ? e.message : String(e)));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
})();
|
|
79
|
+
try {
|
|
80
|
+
await A;
|
|
81
|
+
} finally {
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function S(t) {
|
|
85
|
+
I = "vector", D = { x: +t[0], y: +t[1], z: +t[2] }, p && (p.gravity = D);
|
|
86
|
+
}
|
|
87
|
+
function T(t, e) {
|
|
88
|
+
I = "geocentric", W = { x: +t[0], y: +t[1], z: +t[2] }, q = +e, p && (p.gravity = { x: 0, y: 0, z: 0 });
|
|
89
|
+
}
|
|
90
|
+
function H(t) {
|
|
91
|
+
const e = $(P(W, t));
|
|
92
|
+
return j(e, q);
|
|
93
|
+
}
|
|
94
|
+
function V(t, e, o) {
|
|
95
|
+
try {
|
|
96
|
+
if (typeof p.createRigidBody != "function")
|
|
97
|
+
throw postMessage({ type: "error", msg: "world.createRigidBody is not a function", value: typeof p.createRigidBody }), new Error("world.createRigidBody is not a function");
|
|
98
|
+
postMessage({ type: "debug", msg: "createBody: about to call world.createRigidBody", id: e, descType: typeof t, descCtor: t && t.constructor ? t.constructor.name : null });
|
|
99
|
+
const n = p.createRigidBody(t);
|
|
100
|
+
return o?.v && typeof n.setLinvel == "function" && n.setLinvel(w(o.v), !1), o?.w && typeof n.setAngvel == "function" && n.setAngvel(w(o.w), !1), x.set(e, n), B.set(e, { type: o.type, mass: o.mass }), n;
|
|
101
|
+
} catch (n) {
|
|
102
|
+
throw postMessage({ type: "error", msg: "createBody failed", error: n && (n.message || String(n)) || String(n), id: e, descType: typeof t }), n;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function G(t) {
|
|
106
|
+
const e = x.get(t);
|
|
107
|
+
if (e) {
|
|
108
|
+
for (const [o, n] of Array.from(M.entries()))
|
|
109
|
+
if (n === t) {
|
|
110
|
+
const r = C.get(o);
|
|
111
|
+
r && p.removeCollider(r, !0), C.delete(o), M.delete(o);
|
|
112
|
+
}
|
|
113
|
+
p.removeRigidBody(e);
|
|
114
|
+
}
|
|
115
|
+
x.delete(t), B.delete(t);
|
|
116
|
+
}
|
|
117
|
+
function N({ id: t, positions: e, indices: o, bodyId: n, local: r }) {
|
|
118
|
+
if (!(e instanceof Float32Array))
|
|
119
|
+
throw new Error("attachCollider: positions must be Float32Array");
|
|
120
|
+
if (e.length % 3 !== 0)
|
|
121
|
+
throw new Error("attachCollider: positions length must be a multiple of 3");
|
|
122
|
+
const d = new Float32Array(e), h = r && r.s && +r.s[0] || 1, m = r && r.s && +r.s[1] || 1, k = r && r.s && +r.s[2] || 1;
|
|
123
|
+
for (let i = 0, c = d.length; i < c; i += 3)
|
|
124
|
+
d[i + 0] *= h, d[i + 1] *= m, d[i + 2] *= k;
|
|
125
|
+
let s = null;
|
|
126
|
+
if (o) {
|
|
127
|
+
const i = o instanceof Uint32Array ? o : new Uint32Array(o.buffer || o);
|
|
128
|
+
s = new Uint32Array(i);
|
|
129
|
+
const c = d.length / 3;
|
|
130
|
+
for (let u = 0; u < s.length; ++u) {
|
|
131
|
+
const b = s[u];
|
|
132
|
+
if (!Number.isFinite(b) || b < 0 || b >= c)
|
|
133
|
+
throw new Error(`attachCollider: index out of range or invalid at ${u}: ${b} (vertCount=${c})`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
for (let i = 0; i < d.length; ++i) {
|
|
137
|
+
const c = d[i];
|
|
138
|
+
if (!Number.isFinite(c)) throw new Error(`attachCollider: invalid position value at ${i}: ${c}`);
|
|
139
|
+
}
|
|
140
|
+
const a = l.ColliderDesc.trimesh(d, s);
|
|
141
|
+
r?.p && a.setTranslation(+r.p[0], +r.p[1], +r.p[2]), r?.q && a.setRotation(z(r.q));
|
|
142
|
+
const y = x.get(n);
|
|
143
|
+
if (!y) throw new Error(`attachCollider: body not found: ${n}`);
|
|
144
|
+
const f = p.createCollider(a, y);
|
|
145
|
+
C.set(t, f), M.set(t, n);
|
|
146
|
+
}
|
|
147
|
+
function _(t) {
|
|
148
|
+
const e = C.get(t);
|
|
149
|
+
e && p.removeCollider(e, !0), C.delete(t), M.delete(t);
|
|
150
|
+
}
|
|
151
|
+
function K(t) {
|
|
152
|
+
if (!t || typeof t != "object") throw new Error("attachShapeCollider: missing shape");
|
|
153
|
+
const e = String(t.kind || "").toLowerCase(), o = t.params || {};
|
|
154
|
+
switch (e) {
|
|
155
|
+
case "ball": {
|
|
156
|
+
const n = +o.radius;
|
|
157
|
+
return l.ColliderDesc.ball(n);
|
|
158
|
+
}
|
|
159
|
+
case "cuboid":
|
|
160
|
+
case "box": {
|
|
161
|
+
const n = +o.hx, r = +o.hy, d = +o.hz;
|
|
162
|
+
return l.ColliderDesc.cuboid(n, r, d);
|
|
163
|
+
}
|
|
164
|
+
case "roundcuboid":
|
|
165
|
+
case "round_cuboid":
|
|
166
|
+
case "round-cuboid": {
|
|
167
|
+
const n = +o.hx, r = +o.hy, d = +o.hz, h = +o.radius || 0;
|
|
168
|
+
return l.ColliderDesc.roundCuboid(n, r, d, h);
|
|
169
|
+
}
|
|
170
|
+
case "capsule": {
|
|
171
|
+
const n = +o.halfHeight, r = +o.radius;
|
|
172
|
+
return l.ColliderDesc.capsule(n, r);
|
|
173
|
+
}
|
|
174
|
+
case "cone": {
|
|
175
|
+
const n = +o.halfHeight, r = +o.radius;
|
|
176
|
+
return l.ColliderDesc.cone(n, r);
|
|
177
|
+
}
|
|
178
|
+
case "cylinder": {
|
|
179
|
+
const n = +o.halfHeight, r = +o.radius;
|
|
180
|
+
return l.ColliderDesc.cylinder(n, r);
|
|
181
|
+
}
|
|
182
|
+
case "segment": {
|
|
183
|
+
const n = o.a || o.p1, r = o.b || o.p2;
|
|
184
|
+
if (!n || !r) throw new Error("segment requires a and b (or p1,p2)");
|
|
185
|
+
return l.ColliderDesc.segment(w(n), w(r));
|
|
186
|
+
}
|
|
187
|
+
case "triangle": {
|
|
188
|
+
const n = o.a, r = o.b, d = o.c;
|
|
189
|
+
if (!n || !r || !d) throw new Error("triangle requires a, b, c");
|
|
190
|
+
return l.ColliderDesc.triangle(w(n), w(r), w(d));
|
|
191
|
+
}
|
|
192
|
+
case "polyline": {
|
|
193
|
+
const n = o.vertices instanceof Float32Array ? o.vertices : new Float32Array(o.vertices);
|
|
194
|
+
let r = null;
|
|
195
|
+
return o.indices && (r = o.indices instanceof Uint32Array ? o.indices : new Uint32Array(o.indices)), l.ColliderDesc.polyline(n, r);
|
|
196
|
+
}
|
|
197
|
+
case "convexhull":
|
|
198
|
+
case "convex_hull":
|
|
199
|
+
case "convex-hull": {
|
|
200
|
+
const n = o.vertices instanceof Float32Array ? o.vertices : new Float32Array(o.vertices), r = l.ColliderDesc.convexHull(n);
|
|
201
|
+
if (!r) throw new Error("convexHull: invalid or insufficient points");
|
|
202
|
+
return r;
|
|
203
|
+
}
|
|
204
|
+
case "heightfield": {
|
|
205
|
+
const n = +o.rows, r = +o.cols, d = o.heights instanceof Float32Array ? o.heights : new Float32Array(o.heights), h = o.scale || { x: 1, y: 1, z: 1 };
|
|
206
|
+
return l.ColliderDesc.heightfield(n, r, d, h);
|
|
207
|
+
}
|
|
208
|
+
default:
|
|
209
|
+
throw new Error(`Unknown primitive collider kind: ${t.kind}`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function J(t) {
|
|
213
|
+
if (I === "geocentric")
|
|
214
|
+
for (const [e, o] of x.entries()) {
|
|
215
|
+
if (!o || o.isFixed()) continue;
|
|
216
|
+
const n = Math.max(1e-6, B.get(e)?.mass ?? 1), r = o.translation(), d = H(r), h = { x: d.x * n, y: d.y * n, z: d.z * n };
|
|
217
|
+
o.applyForce(h, !0);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
function Q(t) {
|
|
221
|
+
p.timestep = t, J(), p.step(), E += t * 1e3;
|
|
222
|
+
const e = {};
|
|
223
|
+
for (const [o, n] of x.entries()) {
|
|
224
|
+
const r = n.translation(), d = n.rotation();
|
|
225
|
+
e[o] = { p: [r.x, r.y, r.z], q: [d.x, d.y, d.z, d.w] };
|
|
226
|
+
}
|
|
227
|
+
postMessage({ type: "state", state: { timeMs: E, bodies: e } });
|
|
228
|
+
}
|
|
229
|
+
function X(t, e, o = 1e6) {
|
|
230
|
+
const n = w(t), r = w(e), d = new l.Ray(n, r), h = p.castRay(d, o, !0);
|
|
231
|
+
if (!h) return { hits: [] };
|
|
232
|
+
const m = h.toi, k = d.pointAt(m), s = h.normal;
|
|
233
|
+
let a = null;
|
|
234
|
+
for (const [i, c] of C.entries())
|
|
235
|
+
if (c.handle === h.collider.handle) {
|
|
236
|
+
a = i;
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
let y = null;
|
|
240
|
+
const f = h.collider.parent()?.handle;
|
|
241
|
+
if (f != null) {
|
|
242
|
+
for (const [i, c] of x.entries())
|
|
243
|
+
if (c.handle === f) {
|
|
244
|
+
y = i;
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return {
|
|
249
|
+
hits: [{
|
|
250
|
+
toi: m,
|
|
251
|
+
point: [k.x, k.y, k.z],
|
|
252
|
+
normal: [s.x, s.y, s.z],
|
|
253
|
+
colliderId: a,
|
|
254
|
+
bodyId: y
|
|
255
|
+
}]
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
async function Y(t) {
|
|
259
|
+
const e = t.data || {}, { id: o, type: n, _envId: r, replyTo: d } = e, h = typeof r < "u" ? r : typeof d < "u" ? d : o, m = (s) => F(h, s), k = (s) => U(h, s);
|
|
260
|
+
try {
|
|
261
|
+
switch (n) {
|
|
262
|
+
case "init": {
|
|
263
|
+
R = typeof e.fixedDt == "number" ? e.fixedDt : R;
|
|
264
|
+
const s = e.gravity || {};
|
|
265
|
+
(s.mode || "vector").toLowerCase() === "geocentric" ? T(s.planetCenter || [0, 0, 0], typeof s.intensity == "number" ? s.intensity : 9.81) : S(s.vector || [0, -9.81, 0]), await v(), m({ ok: !0 });
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
case "addObject": {
|
|
269
|
+
let u = function(g) {
|
|
270
|
+
return typeof g == "number" && isFinite(g);
|
|
271
|
+
};
|
|
272
|
+
await v();
|
|
273
|
+
const s = e.id, a = e.body || {}, y = (a.type || "dynamic").toLowerCase(), f = typeof a.mass == "number" ? a.mass : 1, i = w(a.p || [0, 0, 0]), c = z(a.q || [0, 0, 0, 1]);
|
|
274
|
+
if ((!u(i.x) || !u(i.y) || !u(i.z)) && (postMessage({ type: "debug", msg: "addObject: invalid translation detected, resetting to 0", bodyId: s, p: i }), i.x = u(i.x) ? i.x : 0, i.y = u(i.y) ? i.y : 0, i.z = u(i.z) ? i.z : 0), ![c.x, c.y, c.z, c.w].every(u))
|
|
275
|
+
postMessage({ type: "debug", msg: "addObject: invalid rotation detected, using identity quat", bodyId: s, q: c }), c.x = 0, c.y = 0, c.z = 0, c.w = 1;
|
|
276
|
+
else {
|
|
277
|
+
const g = Math.hypot(c.x, c.y, c.z, c.w) || 1;
|
|
278
|
+
c.x /= g, c.y /= g, c.z /= g, c.w /= g;
|
|
279
|
+
}
|
|
280
|
+
let b;
|
|
281
|
+
y === "fixed" ? b = l.RigidBodyDesc.fixed() : y === "kinematic" ? b = l.RigidBodyDesc.kinematicPositionBased() : b = l.RigidBodyDesc.dynamic().setAdditionalMass(f);
|
|
282
|
+
try {
|
|
283
|
+
b.setTranslation(i.x, i.y, i.z);
|
|
284
|
+
} catch (g) {
|
|
285
|
+
throw postMessage({ type: "error", msg: "desc.setTranslation failed", error: g && (g.message || String(g)) || String(g), bodyId: s, p: i }), g;
|
|
286
|
+
}
|
|
287
|
+
try {
|
|
288
|
+
b.setRotation(c);
|
|
289
|
+
} catch (g) {
|
|
290
|
+
throw postMessage({ type: "error", msg: "desc.setRotation failed", error: g && (g.message || String(g)) || String(g), bodyId: s, q: c }), g;
|
|
291
|
+
}
|
|
292
|
+
postMessage({ type: "debug", msg: "addObject: creating body", bodyId: s, typeStr: y, mass: f, p: i, q: c }), V(b, s, { type: y, mass: f, v: a.v, w: a.w }), m({ ok: !0 });
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
case "removeObject": {
|
|
296
|
+
await v(), G(e.id), m({ ok: !0 });
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
// addCollider removed: colliders are created during attachCollider
|
|
300
|
+
// disposeCollider removed
|
|
301
|
+
case "attachCollider":
|
|
302
|
+
case "attachTrimeshCollider": {
|
|
303
|
+
await v();
|
|
304
|
+
const s = e.bodyId, a = e.id || e.colliderId, y = e.positions, f = e.indices || null, i = e.local || {};
|
|
305
|
+
if (!y) {
|
|
306
|
+
F(o, { ok: !1, reason: "missing positions" });
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
const c = y instanceof Float32Array ? y : new Float32Array(y.buffer || y);
|
|
310
|
+
let u = f;
|
|
311
|
+
u && !(u instanceof Uint32Array) && (u = new Uint32Array(u.buffer || u)), N({
|
|
312
|
+
id: a,
|
|
313
|
+
positions: c,
|
|
314
|
+
indices: u || null,
|
|
315
|
+
bodyId: s,
|
|
316
|
+
local: i
|
|
317
|
+
}), m({ ok: !0, colliderId: a });
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
case "attachShapeCollider": {
|
|
321
|
+
await v();
|
|
322
|
+
const s = e.bodyId, a = e.id || e.colliderId, y = e.shape, f = e.local || {}, i = K(y);
|
|
323
|
+
f?.p && i.setTranslation(+f.p[0], +f.p[1], +f.p[2]), f?.q && i.setRotation(z(f.q));
|
|
324
|
+
const c = x.get(s);
|
|
325
|
+
if (!c) {
|
|
326
|
+
F(o, { ok: !1, reason: "unknown body" });
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
const u = p.createCollider(i, c);
|
|
330
|
+
C.set(a, u), M.set(a, s), m({ ok: !0, colliderId: a });
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
333
|
+
case "detachCollider": {
|
|
334
|
+
await v();
|
|
335
|
+
const s = e.colliderId || e.id;
|
|
336
|
+
_(s), m({ ok: !0 });
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
case "applyForce": {
|
|
340
|
+
await v();
|
|
341
|
+
const s = e.id, a = x.get(s);
|
|
342
|
+
if (!a) {
|
|
343
|
+
F(o, { ok: !1, reason: "unknown body" });
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
const y = !!e.impulse, f = w(e.force || [0, 0, 0]), i = e.wake !== !1;
|
|
347
|
+
y ? e.point && typeof a.applyImpulseAtPoint == "function" ? a.applyImpulseAtPoint(f, w(e.point), i) : a.applyImpulse(f, i) : e.point && typeof a.applyForceAtPoint == "function" ? a.applyForceAtPoint(f, w(e.point), i) : a.applyForce(f, i), m({ ok: !0 });
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
case "setPose": {
|
|
351
|
+
await v();
|
|
352
|
+
const s = e.id, a = x.get(s);
|
|
353
|
+
if (!a) {
|
|
354
|
+
m({ ok: !1, reason: "unknown body" });
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
const y = e.p, f = e.q, i = e.wake !== !1;
|
|
358
|
+
try {
|
|
359
|
+
typeof a.isKinematic == "function" && a.isKinematic() ? (y && a.setNextKinematicTranslation(w(y)), f && a.setNextKinematicRotation(z(f))) : (y && typeof a.setTranslation == "function" && a.setTranslation(w(y), !0), f && typeof a.setRotation == "function" && a.setRotation(z(f), !0)), i && typeof a.wakeUp == "function" && a.wakeUp(), m({ ok: !0 });
|
|
360
|
+
} catch (c) {
|
|
361
|
+
k(c);
|
|
362
|
+
}
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
case "setGravity": {
|
|
366
|
+
await v();
|
|
367
|
+
const s = e.gravity || {};
|
|
368
|
+
(s.mode || "vector").toLowerCase() === "geocentric" ? T(s.planetCenter || [0, 0, 0], typeof s.intensity == "number" ? s.intensity : 9.81) : S(s.vector || [0, -9.81, 0]), m({ ok: !0 });
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
case "step": {
|
|
372
|
+
await v();
|
|
373
|
+
const s = typeof e.dt == "number" ? L(e.dt, 1 / 600, 1 / 10) : R;
|
|
374
|
+
Q(s), m({ ok: !0, dtUsed: s });
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
case "raycast": {
|
|
378
|
+
await v();
|
|
379
|
+
const s = X(e.origin || [0, 0, 0], e.direction || [0, -1, 0], typeof e.maxToi == "number" ? e.maxToi : 1e6);
|
|
380
|
+
m(s);
|
|
381
|
+
break;
|
|
382
|
+
}
|
|
383
|
+
default: {
|
|
384
|
+
m({ ok: !1, reason: "unknown message type" });
|
|
385
|
+
break;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
} catch (s) {
|
|
389
|
+
k(s);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
self.addEventListener("message", Y);
|
|
393
|
+
//# sourceMappingURL=physicsRapier.worker-jgQ9dgLt.js.map
|