@khr3/core 0.1.4 → 0.1.5
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/KhrVehicle.d.ts +5 -3
- package/dist/curves.d.ts +32 -11
- package/dist/curves.js +54 -28
- package/dist/index.js +150 -140
- package/dist/khrTypes.d.ts +4 -0
- package/dist/khrVehicleChassis.d.ts +9 -2
- package/dist/pacejka.d.ts +1 -1
- package/dist/vehicle.d.ts +1 -1
- package/dist/vehicle.js +131 -100
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { C as e, S as t, T as n, _ as r, a as i, b as a, c as o, d as s, f as c, g as l, h as u, l as d, m as f, n as p, o as m, p as h, r as g, s as _, t as v, u as y, v as b, w as x, x as S, y as C } from "./BundleSceneHost-CE3HPB8a.js";
|
|
2
2
|
import { useCallback as w, useContext as T, useEffect as E, useImperativeHandle as ee, useLayoutEffect as D, useMemo as O, useRef as k, useState as A } from "react";
|
|
3
3
|
import { useFrame as j, useLoader as M } from "@react-three/fiber";
|
|
4
|
-
import { Physics as N, RigidBody as
|
|
5
|
-
import * as
|
|
6
|
-
import { jsx as
|
|
4
|
+
import { Physics as N, RigidBody as P, useRapier as F } from "@react-three/rapier";
|
|
5
|
+
import * as I from "three";
|
|
6
|
+
import { jsx as L, jsxs as te } from "react/jsx-runtime";
|
|
7
7
|
import { GLTFLoader as R } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
8
8
|
import { GLTFExporter as ne } from "three/examples/jsm/exporters/GLTFExporter.js";
|
|
9
9
|
// src/jointDynamics.ts
|
|
10
|
-
var z = new
|
|
10
|
+
var z = new I.Vector3(), B = new I.Vector3(), re = new I.Vector3(), ie = new I.Quaternion(), ae = new I.Quaternion(), oe = new I.Matrix4(), se = new I.Matrix4(), ce = new I.Matrix4(), le = new I.Matrix4(), V = new I.Vector3(), H = new I.Quaternion(), ue = new I.Vector3();
|
|
11
11
|
function de(e, t, n = []) {
|
|
12
12
|
if (t.kind === "fixed") return 0;
|
|
13
13
|
let r = n.length > 0 ? [e, ...n] : [e];
|
|
@@ -65,7 +65,7 @@ function me(e, t) {
|
|
|
65
65
|
// src/PhysicsWorld.tsx
|
|
66
66
|
var he = (e) => typeof e == "number" ? e : e.current;
|
|
67
67
|
function ge({ paused: e, timeScale: t, maxDelta: n, joints: r, dtRef: i, activeRef: a, setActiveState: o }) {
|
|
68
|
-
let { world: s } =
|
|
68
|
+
let { world: s } = F(), c = k(0);
|
|
69
69
|
return j((l, u) => {
|
|
70
70
|
let d = he(t), f = Math.max(0, he(n)), p = !e && d > 0 && f > 0 && u > 0, m = p ? Math.min(Math.min(u, f) * d, .5) : 0;
|
|
71
71
|
if (p !== a.current && (a.current = p, o(p)), !(m > 0)) i.current = 0;
|
|
@@ -77,7 +77,7 @@ function ge({ paused: e, timeScale: t, maxDelta: n, joints: r, dtRef: i, activeR
|
|
|
77
77
|
}), null;
|
|
78
78
|
}
|
|
79
79
|
function _e({ dtRef: e }) {
|
|
80
|
-
let { step: t } =
|
|
80
|
+
let { step: t } = F();
|
|
81
81
|
return j(() => {
|
|
82
82
|
let n = e.current;
|
|
83
83
|
n > 0 && t(n);
|
|
@@ -97,21 +97,21 @@ function ve({ paused: e = !1, timeScale: n = 1, maxDelta: r = 1 / 30, gravity: i
|
|
|
97
97
|
i[1],
|
|
98
98
|
i[2]
|
|
99
99
|
]);
|
|
100
|
-
return /* @__PURE__ */
|
|
100
|
+
return /* @__PURE__ */ L(C.Provider, {
|
|
101
101
|
value: c,
|
|
102
|
-
children: /* @__PURE__ */
|
|
102
|
+
children: /* @__PURE__ */ L(S.Provider, {
|
|
103
103
|
value: h,
|
|
104
|
-
children: /* @__PURE__ */
|
|
104
|
+
children: /* @__PURE__ */ L(a.Provider, {
|
|
105
105
|
value: m,
|
|
106
|
-
children: /* @__PURE__ */
|
|
106
|
+
children: /* @__PURE__ */ L(t.Provider, {
|
|
107
107
|
value: l,
|
|
108
|
-
children: /* @__PURE__ */
|
|
108
|
+
children: /* @__PURE__ */ te(N, {
|
|
109
109
|
...s,
|
|
110
110
|
paused: !0,
|
|
111
111
|
timeStep: "vary",
|
|
112
112
|
gravity: i,
|
|
113
113
|
children: [
|
|
114
|
-
/* @__PURE__ */
|
|
114
|
+
/* @__PURE__ */ L(ge, {
|
|
115
115
|
paused: e,
|
|
116
116
|
timeScale: n,
|
|
117
117
|
maxDelta: r,
|
|
@@ -121,7 +121,7 @@ function ve({ paused: e = !1, timeScale: n = 1, maxDelta: r = 1 / 30, gravity: i
|
|
|
121
121
|
setActiveState: f
|
|
122
122
|
}),
|
|
123
123
|
o,
|
|
124
|
-
/* @__PURE__ */
|
|
124
|
+
/* @__PURE__ */ L(_e, { dtRef: l })
|
|
125
125
|
]
|
|
126
126
|
})
|
|
127
127
|
})
|
|
@@ -212,7 +212,7 @@ function Oe(e, t, n, r) {
|
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
|
-
var ke = new
|
|
215
|
+
var ke = new I.Vector3(), U = new I.Quaternion(), Ae = new I.Quaternion();
|
|
216
216
|
function je(e, t) {
|
|
217
217
|
return e.updateWorldMatrix(!0, !1), e.getWorldQuaternion(U), t && (t.updateWorldMatrix(!0, !1), U.premultiply(t.getWorldQuaternion(Ae).invert())), U.lengthSq() > 0 ? U.normalize() : U.identity(), [
|
|
218
218
|
U.x || 0,
|
|
@@ -238,15 +238,21 @@ function Me(t, n, r, i) {
|
|
|
238
238
|
}
|
|
239
239
|
function Ne(t, n, r) {
|
|
240
240
|
if (t !== void 0) {
|
|
241
|
-
if (!W(t) || !Array.isArray(t.points) || t.points.length
|
|
241
|
+
if (!W(t) || !Array.isArray(t.points) || t.points.length < 2) throw new e(`ecctrlWheel "${r}" has invalid ecctrlWheel.${n}`);
|
|
242
242
|
for (let i of t.points) if (!W(i) || !G(i.x) || !G(i.y)) throw new e(`ecctrlWheel "${r}" has invalid point in ecctrlWheel.${n}`);
|
|
243
243
|
if (t.samples !== void 0 && (!G(t.samples) || t.samples <= 0)) throw new e(`ecctrlWheel "${r}" has invalid samples in ecctrlWheel.${n}`);
|
|
244
244
|
return t;
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
|
-
function Pe(t, n
|
|
247
|
+
function Pe(t, n) {
|
|
248
|
+
if (t !== void 0) {
|
|
249
|
+
if (t === "shapeCast" || t === "rayCast") return t;
|
|
250
|
+
throw new e(`ecctrlWheel "${n}" has invalid ecctrlWheel.groundDetection`);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
function Fe(t, n, r, i, a) {
|
|
248
254
|
if (r.socketId !== void 0 && (typeof r.socketId != "string" || r.socketId.length === 0)) throw new e(`Node "${n}" has invalid extras.socketId`);
|
|
249
|
-
let o = t.getWorldPosition(new
|
|
255
|
+
let o = t.getWorldPosition(new I.Vector3()), s = [
|
|
250
256
|
o.x,
|
|
251
257
|
o.y,
|
|
252
258
|
o.z
|
|
@@ -277,7 +283,7 @@ function Pe(t, n, r, i, a) {
|
|
|
277
283
|
...l ? { contactDots: l } : {}
|
|
278
284
|
};
|
|
279
285
|
}
|
|
280
|
-
function
|
|
286
|
+
function Ie(t, n, r, i) {
|
|
281
287
|
if (y(t, n), !W(r)) throw new e(`ecctrlWheel "${n}" must be an object`);
|
|
282
288
|
let a = (t) => {
|
|
283
289
|
let i = r[t];
|
|
@@ -293,7 +299,7 @@ function Fe(t, n, r, i) {
|
|
|
293
299
|
return i;
|
|
294
300
|
}, c = a("radius"), l = a("width"), u = o("travel"), d = o("sag");
|
|
295
301
|
if (d > u) throw new e(`ecctrlWheel "${n}" has invalid ecctrlWheel.sag (${d}) > ecctrlWheel.travel (${u})`);
|
|
296
|
-
let f = s("steer"), p = s("drive"), m = s("brake"), h = new
|
|
302
|
+
let f = s("steer"), p = s("drive"), m = s("brake"), h = new I.Box3().setFromObject(t), g = h.isEmpty() ? t.getWorldPosition(new I.Vector3()) : h.getCenter(new I.Vector3());
|
|
297
303
|
return {
|
|
298
304
|
nodeName: n,
|
|
299
305
|
object: t,
|
|
@@ -317,16 +323,20 @@ function Fe(t, n, r, i) {
|
|
|
317
323
|
maxBrakeTorque: K(r, "maxBrakeTorque", n),
|
|
318
324
|
rollingResistanceCoef: K(r, "rollingResistanceCoef", n),
|
|
319
325
|
wheelDensity: K(r, "wheelDensity", n, !0),
|
|
326
|
+
groundDetection: Pe(r.groundDetection, n),
|
|
320
327
|
driveTorqueWeight: K(r, "driveTorqueWeight", n),
|
|
321
328
|
tireGripFactor: K(r, "tireGripFactor", n),
|
|
329
|
+
lngFrictionEllipseScale: K(r, "lngFrictionEllipseScale", n),
|
|
322
330
|
latFrictionEllipseScale: K(r, "latFrictionEllipseScale", n),
|
|
323
331
|
relaxLngRate: K(r, "relaxLngRate", n),
|
|
324
332
|
relaxLatRate: K(r, "relaxLatRate", n),
|
|
333
|
+
minLngRelaxCoeff: K(r, "minLngRelaxCoeff", n),
|
|
334
|
+
minLatRelaxCoeff: K(r, "minLatRelaxCoeff", n),
|
|
325
335
|
lngSlipRatioCurveData: Ne(r.lngSlipRatioCurveData, "lngSlipRatioCurveData", n),
|
|
326
336
|
latSlipRatioCurveData: Ne(r.latSlipRatioCurveData, "latSlipRatioCurveData", n)
|
|
327
337
|
};
|
|
328
338
|
}
|
|
329
|
-
function
|
|
339
|
+
function Le(t, n, r, i) {
|
|
330
340
|
if (y(t, n), !W(r)) throw new e(`ecctrlPropeller "${n}" must be an object`);
|
|
331
341
|
if (!G(r.maxThrust) || r.maxThrust <= 0) throw new e(`ecctrlPropeller "${n}" is missing positive finite ecctrlPropeller.maxThrust`);
|
|
332
342
|
let a;
|
|
@@ -334,7 +344,7 @@ function Ie(t, n, r, i) {
|
|
|
334
344
|
if (!G(r.torqueRatio)) throw new e(`ecctrlPropeller "${n}" has invalid ecctrlPropeller.torqueRatio`);
|
|
335
345
|
a = r.torqueRatio;
|
|
336
346
|
}
|
|
337
|
-
let o = new
|
|
347
|
+
let o = new I.Box3().setFromObject(t), s = o.isEmpty() ? t.getWorldPosition(new I.Vector3()) : o.getCenter(new I.Vector3());
|
|
338
348
|
return {
|
|
339
349
|
nodeName: n,
|
|
340
350
|
object: t,
|
|
@@ -351,15 +361,15 @@ function Ie(t, n, r, i) {
|
|
|
351
361
|
};
|
|
352
362
|
}
|
|
353
363
|
// src/khrParsers.ts
|
|
354
|
-
var
|
|
364
|
+
var Re = /* @__PURE__ */ new Map([["default", 0]]), ze = 1, Be = (e) => typeof e == "object" && !!e && !Array.isArray(e), q = (e) => typeof e == "number" && Number.isFinite(e) && e > 0, Ve = (e) => typeof e == "number" && Number.isFinite(e) && e >= 0;
|
|
355
365
|
function J(t, n, r = !1) {
|
|
356
366
|
if (t !== void 0) {
|
|
357
367
|
if (typeof t != "number" || !Number.isFinite(t) || r && t < 0) throw new e(`Invalid ${n}`);
|
|
358
368
|
return t;
|
|
359
369
|
}
|
|
360
370
|
}
|
|
361
|
-
function
|
|
362
|
-
if (!
|
|
371
|
+
function He(t, n) {
|
|
372
|
+
if (!Be(t)) throw new e(`KHR_implicit_shapes[${n}] must be an object`);
|
|
363
373
|
let r = t.type;
|
|
364
374
|
if (r === "box" && t.box && typeof t.box == "object") {
|
|
365
375
|
let r = t.box.size;
|
|
@@ -396,25 +406,25 @@ function Ve(t, n) {
|
|
|
396
406
|
}
|
|
397
407
|
throw new e(`KHR_implicit_shapes[${n}] unsupported shape type "${r}"`);
|
|
398
408
|
}
|
|
399
|
-
function
|
|
409
|
+
function Ue(t, n, r) {
|
|
400
410
|
if (n === void 0) return {};
|
|
401
411
|
if (typeof n != "number" || !Number.isInteger(n) || n < 0 || n >= t.length) throw new e(`Node "${r}" references out-of-bounds physicsMaterial ${String(n)}`);
|
|
402
412
|
let i = t[n];
|
|
403
|
-
if (!
|
|
413
|
+
if (!Be(i)) throw new e(`Invalid physicsMaterials[${n}] on "${r}"`);
|
|
404
414
|
let a = J(i.dynamicFriction, `physicsMaterials[${n}].dynamicFriction`, !0), o = J(i.staticFriction, `physicsMaterials[${n}].staticFriction`, !0), s = J(i.restitution, `physicsMaterials[${n}].restitution`, !0);
|
|
405
415
|
return {
|
|
406
416
|
...a !== void 0 || o !== void 0 ? { friction: a ?? o } : {},
|
|
407
417
|
...s === void 0 ? {} : { restitution: s }
|
|
408
418
|
};
|
|
409
419
|
}
|
|
410
|
-
function
|
|
420
|
+
function We(t, n, i) {
|
|
411
421
|
if (t.isKinematic !== void 0 && typeof t.isKinematic != "boolean") throw new e(`Node "${i}" has non-boolean motion.isKinematic`);
|
|
412
422
|
let a = !n || !!t.isKinematic, o = 0;
|
|
413
423
|
if (!a) {
|
|
414
424
|
if (!q(t.mass)) throw new e(`Dynamic node "${i}" is missing positive finite motion.mass`);
|
|
415
425
|
o = t.mass;
|
|
416
426
|
} else if (t.mass !== void 0) {
|
|
417
|
-
if (!
|
|
427
|
+
if (!Ve(t.mass)) throw new e(`Kinematic node "${i}" has invalid motion.mass`);
|
|
418
428
|
o = t.mass;
|
|
419
429
|
}
|
|
420
430
|
let s = t.centerOfMass === void 0 ? [
|
|
@@ -445,13 +455,13 @@ function Ue(t, n, i) {
|
|
|
445
455
|
...p === void 0 ? {} : { gravityFactor: p }
|
|
446
456
|
};
|
|
447
457
|
}
|
|
448
|
-
function
|
|
458
|
+
function Ge(t) {
|
|
449
459
|
let n = (t) => {
|
|
450
|
-
let n =
|
|
460
|
+
let n = Re.get(t);
|
|
451
461
|
if (n !== void 0) return n;
|
|
452
|
-
if (
|
|
453
|
-
let r =
|
|
454
|
-
return
|
|
462
|
+
if (ze > 15) throw new e(`Exceeded Rapier 16-group limit for collisionSystem "${t}"`);
|
|
463
|
+
let r = ze++;
|
|
464
|
+
return Re.set(t, r), r;
|
|
455
465
|
}, r = (t, r) => {
|
|
456
466
|
if (t === void 0) return 0;
|
|
457
467
|
if (!Array.isArray(t)) throw new e(`collisionFilter.${r} must be an array`);
|
|
@@ -469,7 +479,7 @@ function We(t) {
|
|
|
469
479
|
return (i & 65535) << 16 | a & 65535;
|
|
470
480
|
});
|
|
471
481
|
}
|
|
472
|
-
var
|
|
482
|
+
var Ke = (e) => e === 0 ? [
|
|
473
483
|
1,
|
|
474
484
|
0,
|
|
475
485
|
0
|
|
@@ -482,7 +492,7 @@ var Ge = (e) => e === 0 ? [
|
|
|
482
492
|
0,
|
|
483
493
|
1
|
|
484
494
|
];
|
|
485
|
-
function
|
|
495
|
+
function qe(t, n, r) {
|
|
486
496
|
return t.map((t, i) => {
|
|
487
497
|
let a = `physicsJoints[${n}].drives[${i}] on "${r}"`;
|
|
488
498
|
if (!t || typeof t != "object" || Array.isArray(t)) throw new e(`${a} must be an object`);
|
|
@@ -504,9 +514,9 @@ function Ke(t, n, r) {
|
|
|
504
514
|
};
|
|
505
515
|
});
|
|
506
516
|
}
|
|
507
|
-
function
|
|
517
|
+
function Je(t, n, r, i, a, o, s, c = i.name) {
|
|
508
518
|
let l = t[n];
|
|
509
|
-
if (!
|
|
519
|
+
if (!Be(l)) throw new e(`physicsJoints[${n}] out of bounds for "${r}"`);
|
|
510
520
|
if (l.limits !== void 0 && !Array.isArray(l.limits)) throw new e(`physicsJoints[${n}].limits on "${r}" must be an array`);
|
|
511
521
|
if (l.drives !== void 0 && !Array.isArray(l.drives)) throw new e(`physicsJoints[${n}].drives on "${r}" must be an array`);
|
|
512
522
|
let u = l.limits ?? [], d = l.drives ?? [], f = [
|
|
@@ -542,7 +552,7 @@ function qe(t, n, r, i, a, o, s, c = i.name) {
|
|
|
542
552
|
});
|
|
543
553
|
};
|
|
544
554
|
for (let t of u) {
|
|
545
|
-
if (!
|
|
555
|
+
if (!Be(t)) throw new e(`physicsJoints[${n}].limits entry on "${r}" must be an object`);
|
|
546
556
|
g(t.linearAxes, t, f, m), g(t.angularAxes, t, p, h);
|
|
547
557
|
}
|
|
548
558
|
let _ = [
|
|
@@ -560,15 +570,15 @@ function qe(t, n, r, i, a, o, s, c = i.name) {
|
|
|
560
570
|
], x = null, S;
|
|
561
571
|
if (_.length === 0 && v.length === 0) y = "fixed";
|
|
562
572
|
else if (_.length === 0 && v.length === 1) {
|
|
563
|
-
y = "revolute", b =
|
|
573
|
+
y = "revolute", b = Ke(v[0]);
|
|
564
574
|
let e = p[v[0]];
|
|
565
575
|
x = Array.isArray(e) ? e : null, S = h[v[0]];
|
|
566
576
|
} else if (v.length === 0 && _.length === 1) {
|
|
567
|
-
y = "prismatic", b =
|
|
577
|
+
y = "prismatic", b = Ke(_[0]);
|
|
568
578
|
let e = f[_[0]];
|
|
569
579
|
x = Array.isArray(e) ? e : null, S = m[_[0]];
|
|
570
580
|
} else throw new e(`physicsJoints[${n}] unsupported DOF (${_.length} lin, ${v.length} ang) on "${r}"`);
|
|
571
|
-
let C =
|
|
581
|
+
let C = qe(d, n, r), w = a.getWorldPosition(new I.Vector3()).sub(i.getWorldPosition(new I.Vector3())).applyQuaternion(i.getWorldQuaternion(new I.Quaternion()).invert());
|
|
572
582
|
return {
|
|
573
583
|
index: n,
|
|
574
584
|
nodeName: r,
|
|
@@ -601,16 +611,16 @@ function X(t, n) {
|
|
|
601
611
|
if (!Array.isArray(t)) throw new e(`${n} must be an array`);
|
|
602
612
|
return t;
|
|
603
613
|
}
|
|
604
|
-
function
|
|
614
|
+
function Ye() {
|
|
605
615
|
return (e) => ({
|
|
606
616
|
name: "khr3_headless_texture",
|
|
607
617
|
loadTexture(t) {
|
|
608
|
-
let n = new
|
|
618
|
+
let n = new I.Texture();
|
|
609
619
|
return n.flipY = !1, e.associations.set(n, { textures: t }), Promise.resolve(n);
|
|
610
620
|
}
|
|
611
621
|
});
|
|
612
622
|
}
|
|
613
|
-
function
|
|
623
|
+
function Xe(t, n, r = t.parser?.json) {
|
|
614
624
|
let i = new Int32Array(n.length).fill(-1);
|
|
615
625
|
for (let t = 0; t < n.length; t++) {
|
|
616
626
|
let r = n[t];
|
|
@@ -686,12 +696,12 @@ function Ye(t, n, r = t.parser?.json) {
|
|
|
686
696
|
if (e < 0 || e >= n.length || !o.has(e)) return;
|
|
687
697
|
let r = d.get(e);
|
|
688
698
|
if (r) return r;
|
|
689
|
-
let i = l[e], a =
|
|
699
|
+
let i = l[e], a = I.PropertyBinding.sanitizeNodeName(i);
|
|
690
700
|
return f.get(i) ?? f.get(a) ?? t.scene.getObjectByName(i);
|
|
691
701
|
}
|
|
692
702
|
};
|
|
693
703
|
}
|
|
694
|
-
function
|
|
704
|
+
function Ze(t, n, r, i, a) {
|
|
695
705
|
if (!Y(t)) throw new e(`Node "${n}" has invalid collider (expected object)`);
|
|
696
706
|
let o = t.geometry;
|
|
697
707
|
if (!Y(o)) throw new e(`Node "${n}" is missing collider.geometry object`);
|
|
@@ -709,8 +719,8 @@ function Xe(t, n, r, i, a) {
|
|
|
709
719
|
throw new e(`Node "${n}" collider.geometry must specify shape or node`);
|
|
710
720
|
}
|
|
711
721
|
// src/khrPlugin.ts
|
|
712
|
-
var
|
|
713
|
-
function
|
|
722
|
+
var Qe = "khrBundle";
|
|
723
|
+
function $e(t, n) {
|
|
714
724
|
if (!t.scene) throw new e("GLTF asset has no active scene");
|
|
715
725
|
t.scene.updateMatrixWorld(!0), s(t.scene);
|
|
716
726
|
let i = t.parser?.json;
|
|
@@ -720,12 +730,12 @@ function Qe(t, n) {
|
|
|
720
730
|
if (a !== void 0 && !Y(a)) throw new e("KHR_physics_rigid_bodies extension must be an object");
|
|
721
731
|
let o = i.extensions?.KHR_implicit_shapes;
|
|
722
732
|
if (o !== void 0 && !Y(o)) throw new e("KHR_implicit_shapes extension must be an object");
|
|
723
|
-
let c = X(o?.shapes, "KHR_implicit_shapes.shapes").map((e, t) =>
|
|
733
|
+
let c = X(o?.shapes, "KHR_implicit_shapes.shapes").map((e, t) => He(e, t)), l = X(a?.physicsMaterials, "KHR_physics_rigid_bodies.physicsMaterials"), d = Ge(X(a?.collisionFilters, "KHR_physics_rigid_bodies.collisionFilters")), p = X(a?.physicsJoints, "KHR_physics_rigid_bodies.physicsJoints"), m = X(i.nodes, "glTF nodes"), { parentIdx: g, nodeNames: _, resolveObj: v } = Xe(t, m, i), y = [], b = {};
|
|
724
734
|
for (let e = 0; e < m.length; e++) {
|
|
725
735
|
let t = v(e);
|
|
726
736
|
if (!t) continue;
|
|
727
737
|
let r = Y(m[e].extras) ? m[e].extras : {};
|
|
728
|
-
y.push(
|
|
738
|
+
y.push(Fe(t, _[e], r, b, n?.isSocketNode));
|
|
729
739
|
}
|
|
730
740
|
let x = [], S = [], C = /* @__PURE__ */ new Map(), w = /* @__PURE__ */ new Set(), T = [], E = [], ee = (e) => {
|
|
731
741
|
for (let t = g[e]; t !== -1; t = g[t]) if (m[t].extensions?.KHR_physics_rigid_bodies?.motion) return t;
|
|
@@ -743,7 +753,7 @@ function Qe(t, n) {
|
|
|
743
753
|
let s = Y(i.extras) ? i.extras : {};
|
|
744
754
|
if (s.ecctrlWheel !== void 0 || s.ecctrlPropeller !== void 0) {
|
|
745
755
|
if (g[r] !== -1 && D(g[r])) throw new e(`Nested rotor "${a}" inside detached rotor is unsupported`);
|
|
746
|
-
s.ecctrlWheel === void 0 ? E.push(
|
|
756
|
+
s.ecctrlWheel === void 0 ? E.push(Le(o, a, s.ecctrlPropeller, t.scene)) : T.push(Ie(o, a, s.ecctrlWheel, t.scene));
|
|
747
757
|
continue;
|
|
748
758
|
}
|
|
749
759
|
if (D(r)) continue;
|
|
@@ -756,7 +766,7 @@ function Qe(t, n) {
|
|
|
756
766
|
continue;
|
|
757
767
|
}
|
|
758
768
|
if (c.motion !== void 0 && !Y(c.motion)) throw new e(`Node "${a}" has invalid motion`);
|
|
759
|
-
let { hasExplicitInertia: l, ...u } =
|
|
769
|
+
let { hasExplicitInertia: l, ...u } = We(c.motion ?? {}, c.motion !== void 0, a);
|
|
760
770
|
l && w.add(r);
|
|
761
771
|
let d = n?.extractRole?.(a, s) ?? (typeof s.role == "string" ? s.role : null), f = null;
|
|
762
772
|
if (c.joint !== void 0) {
|
|
@@ -768,9 +778,9 @@ function Qe(t, n) {
|
|
|
768
778
|
let n = t.connectedNode, r = _[n] ?? `node_${n}`, i = v(n);
|
|
769
779
|
if (!i) throw new e(`Joint on "${a}" targets missing connectedNode "${r}"`);
|
|
770
780
|
if (D(n)) throw new e(`Joint on "${a}" cannot target detached rotor "${r}"`);
|
|
771
|
-
f =
|
|
781
|
+
f = Je(p, t.joint, a, i, o, !!t.enableCollision, d, r);
|
|
772
782
|
}
|
|
773
|
-
let h = o.getWorldPosition(new
|
|
783
|
+
let h = o.getWorldPosition(new I.Vector3()), y = o.getWorldQuaternion(new I.Quaternion()), b = {
|
|
774
784
|
nodeName: a,
|
|
775
785
|
...u,
|
|
776
786
|
localPosition: [
|
|
@@ -802,7 +812,7 @@ function Qe(t, n) {
|
|
|
802
812
|
if (!r) continue;
|
|
803
813
|
let i = C.has(t) ? t : ee(t), a = C.get(i);
|
|
804
814
|
if (!a) continue;
|
|
805
|
-
let o =
|
|
815
|
+
let o = Ze(n, _[t], c, _, v), s = n, f = i === t ? {
|
|
806
816
|
localPosition: [
|
|
807
817
|
0,
|
|
808
818
|
0,
|
|
@@ -814,7 +824,7 @@ function Qe(t, n) {
|
|
|
814
824
|
0,
|
|
815
825
|
1
|
|
816
826
|
]
|
|
817
|
-
} : u(a.object, r), p =
|
|
827
|
+
} : u(a.object, r), p = Ue(l, s.physicsMaterial, _[t]), h;
|
|
818
828
|
if (s.collisionFilter !== void 0) {
|
|
819
829
|
if (typeof s.collisionFilter != "number" || !Number.isInteger(s.collisionFilter) || s.collisionFilter < 0 || s.collisionFilter >= d.length) throw new e(`Node "${_[t]}" references out-of-bounds collisionFilter ${String(s.collisionFilter)}`);
|
|
820
830
|
h = d[s.collisionFilter];
|
|
@@ -853,36 +863,36 @@ function Qe(t, n) {
|
|
|
853
863
|
droneTune: N
|
|
854
864
|
};
|
|
855
865
|
}
|
|
856
|
-
function
|
|
866
|
+
function et(e) {
|
|
857
867
|
let t = typeof document > "u" && typeof createImageBitmap > "u";
|
|
858
868
|
return (n) => ({
|
|
859
869
|
name: "KHR_physics_rigid_bodies",
|
|
860
870
|
...t ? { loadTexture(e) {
|
|
861
|
-
let t = new
|
|
871
|
+
let t = new I.Texture();
|
|
862
872
|
return t.flipY = !1, n.associations.set(t, { textures: e }), Promise.resolve(t);
|
|
863
873
|
} } : {},
|
|
864
874
|
afterRoot(t) {
|
|
865
|
-
return t.userData[
|
|
875
|
+
return t.userData[Qe] = $e(t, e), null;
|
|
866
876
|
}
|
|
867
877
|
});
|
|
868
878
|
}
|
|
869
879
|
// src/khrLoader.ts
|
|
870
|
-
var
|
|
871
|
-
function
|
|
880
|
+
var tt = Ye();
|
|
881
|
+
function nt() {
|
|
872
882
|
let e = new R();
|
|
873
|
-
return typeof document > "u" && typeof createImageBitmap > "u" && e.register(
|
|
883
|
+
return typeof document > "u" && typeof createImageBitmap > "u" && e.register(tt), e;
|
|
874
884
|
}
|
|
875
|
-
async function
|
|
885
|
+
async function rt(t, n) {
|
|
876
886
|
let r = t instanceof Uint8Array ? t : new Uint8Array(t), i = new ArrayBuffer(r.byteLength);
|
|
877
887
|
new Uint8Array(i).set(r), Se(i);
|
|
878
|
-
let a = n?.loader ??
|
|
888
|
+
let a = n?.loader ?? nt(), o = et(n);
|
|
879
889
|
a.register(o);
|
|
880
890
|
try {
|
|
881
891
|
let t = (t) => t instanceof e ? t : new e(t instanceof Error ? t.message : "Failed to parse GLB"), n = (await new Promise((e, n) => {
|
|
882
892
|
a.parse(i, "", e, (e) => n(t(e)));
|
|
883
893
|
}).catch((e) => {
|
|
884
894
|
throw t(e);
|
|
885
|
-
})).userData[
|
|
895
|
+
})).userData[Qe];
|
|
886
896
|
if (!n) throw new e("Missing parsed KHR bundle on GLTF userData");
|
|
887
897
|
return n;
|
|
888
898
|
} finally {
|
|
@@ -897,7 +907,7 @@ function Q(t, n, r = !1) {
|
|
|
897
907
|
return t;
|
|
898
908
|
}
|
|
899
909
|
}
|
|
900
|
-
function
|
|
910
|
+
function it(t, n) {
|
|
901
911
|
if (t.type === "box") {
|
|
902
912
|
if (!Array.isArray(t.size) || t.size.length !== 3 || !t.size.every(Z)) throw new e(`exportKhrGlb: invalid box.size on "${n}"`);
|
|
903
913
|
return {
|
|
@@ -923,13 +933,13 @@ function rt(t, n) {
|
|
|
923
933
|
}
|
|
924
934
|
};
|
|
925
935
|
}
|
|
926
|
-
function
|
|
936
|
+
function at(t, n, r) {
|
|
927
937
|
if (!Array.isArray(t) || t.length !== 3 || !t.every((e) => typeof e == "number" && Number.isFinite(e))) throw new e(`exportKhrGlb: ${n} joint on "${r}" requires a finite axis`);
|
|
928
938
|
let i = Math.abs(t[0]), a = Math.abs(t[1]), o = Math.abs(t[2]);
|
|
929
939
|
if (Math.hypot(i, a, o) <= 1e-8) throw new e(`exportKhrGlb: ${n} joint on "${r}" requires non-zero axis`);
|
|
930
940
|
return i >= a && i >= o ? 0 : a >= o ? 1 : 2;
|
|
931
941
|
}
|
|
932
|
-
function
|
|
942
|
+
function ot(t, n, r, i) {
|
|
933
943
|
if (!t || typeof t != "object" || Array.isArray(t)) throw new e(`exportKhrGlb: joint drive on "${i}" must be an object`);
|
|
934
944
|
if (t.mode !== "force" && t.mode !== "acceleration") throw new e(`exportKhrGlb: joint drive on "${i}" requires drive.mode ("force" | "acceleration")`);
|
|
935
945
|
if (t.type !== void 0 && t.type !== "linear" && t.type !== "angular") throw new e(`exportKhrGlb: joint drive on "${i}" has invalid drive.type`);
|
|
@@ -948,7 +958,7 @@ function at(t, n, r, i) {
|
|
|
948
958
|
...l === void 0 ? {} : { maxForce: l }
|
|
949
959
|
};
|
|
950
960
|
}
|
|
951
|
-
function
|
|
961
|
+
function st(t, n) {
|
|
952
962
|
if (t.kind !== "fixed" && t.kind !== "revolute" && t.kind !== "prismatic") throw new e(`exportKhrGlb: invalid joint.kind "${String(t.kind)}" on "${n}"`);
|
|
953
963
|
if (t.kind === "fixed") {
|
|
954
964
|
if (t.drive || t.drives && t.drives.length > 0) throw new e(`exportKhrGlb: fixed joint on "${n}" cannot define drives`);
|
|
@@ -970,7 +980,7 @@ function ot(t, n) {
|
|
|
970
980
|
max: 0
|
|
971
981
|
}] };
|
|
972
982
|
}
|
|
973
|
-
let r =
|
|
983
|
+
let r = at(t.axis, t.kind, n), i = [
|
|
974
984
|
0,
|
|
975
985
|
1,
|
|
976
986
|
2
|
|
@@ -1017,9 +1027,9 @@ function ot(t, n) {
|
|
|
1017
1027
|
},
|
|
1018
1028
|
...c
|
|
1019
1029
|
] }, u = t.drives ?? (t.drive ? [t.drive] : []);
|
|
1020
|
-
return u.length > 0 && (l.drives = u.map((e) =>
|
|
1030
|
+
return u.length > 0 && (l.drives = u.map((e) => ot(e, t.kind === "revolute" ? "angular" : "linear", r, n))), l;
|
|
1021
1031
|
}
|
|
1022
|
-
function
|
|
1032
|
+
function ct(t, n) {
|
|
1023
1033
|
let i = !!t.isKinematic;
|
|
1024
1034
|
if (!i && !Z(t.mass)) throw new e(`exportKhrGlb: dynamic node "${n}" requires positive finite motion.mass`);
|
|
1025
1035
|
if (i && t.mass !== void 0 && Q(t.mass, `kinematic motion.mass on "${n}"`, !0), t.inertiaDiagonal && r(t.inertiaDiagonal, `${n}.motion.inertiaDiagonal`).some((e) => i ? e < 0 : e <= 0)) throw new e(`exportKhrGlb: invalid motion.inertiaDiagonal on "${n}"`);
|
|
@@ -1035,7 +1045,7 @@ function st(t, n) {
|
|
|
1035
1045
|
...t.gravityFactor === void 0 ? {} : { gravityFactor: t.gravityFactor }
|
|
1036
1046
|
};
|
|
1037
1047
|
}
|
|
1038
|
-
async function
|
|
1048
|
+
async function lt(t, n, r) {
|
|
1039
1049
|
Ce(), t.updateMatrixWorld(!0);
|
|
1040
1050
|
let i = new ne();
|
|
1041
1051
|
return Te(await new Promise((e, n) => {
|
|
@@ -1057,11 +1067,11 @@ async function ct(t, n, r) {
|
|
|
1057
1067
|
...t.extras
|
|
1058
1068
|
});
|
|
1059
1069
|
let r = {};
|
|
1060
|
-
if (t.motion && (f = !0, r.motion =
|
|
1070
|
+
if (t.motion && (f = !0, r.motion = ct(t.motion, t.nodeName)), t.collider) {
|
|
1061
1071
|
f = !0;
|
|
1062
1072
|
let n = {};
|
|
1063
1073
|
if (t.collider.shape) {
|
|
1064
|
-
let e =
|
|
1074
|
+
let e = it(t.collider.shape, t.nodeName), r = JSON.stringify(e), i = c.get(r);
|
|
1065
1075
|
i === void 0 && (i = s.length, s.push(e), c.set(r, i)), n.geometry = { shape: i };
|
|
1066
1076
|
} else if (t.collider.meshNodeName) {
|
|
1067
1077
|
if (typeof t.collider.convexHull != "boolean") throw new e(`exportKhrGlb: mesh collider on "${t.nodeName}" requires explicit boolean convexHull`);
|
|
@@ -1091,7 +1101,7 @@ async function ct(t, n, r) {
|
|
|
1091
1101
|
if (t.joint) {
|
|
1092
1102
|
f = !0;
|
|
1093
1103
|
let e = o(t.joint.connectedNodeName);
|
|
1094
|
-
d.push(
|
|
1104
|
+
d.push(st(t.joint, t.nodeName)), r.joint = {
|
|
1095
1105
|
joint: d.length - 1,
|
|
1096
1106
|
connectedNode: e,
|
|
1097
1107
|
enableCollision: !!t.joint.enableCollision
|
|
@@ -1121,15 +1131,15 @@ async function ct(t, n, r) {
|
|
|
1121
1131
|
});
|
|
1122
1132
|
}
|
|
1123
1133
|
// src/assemblyPlan.ts
|
|
1124
|
-
function
|
|
1125
|
-
let r = new
|
|
1134
|
+
function ut(t, n) {
|
|
1135
|
+
let r = new I.Matrix4();
|
|
1126
1136
|
for (let i = t; i && i !== n; i = i.parent) {
|
|
1127
1137
|
if (!i.parent) throw new e(`Node "${t.name}" is detached from bundle.scene`);
|
|
1128
1138
|
i.updateMatrix(), r.premultiply(i.matrix);
|
|
1129
1139
|
}
|
|
1130
1140
|
return r;
|
|
1131
1141
|
}
|
|
1132
|
-
function
|
|
1142
|
+
function dt(e, t) {
|
|
1133
1143
|
let n = (e) => {
|
|
1134
1144
|
let n = [];
|
|
1135
1145
|
for (let r = e; r && (n.push(r), r !== t); r = r.parent);
|
|
@@ -1142,8 +1152,8 @@ function ut(e, t) {
|
|
|
1142
1152
|
for (let t of n(e[0])) if (r.has(t)) return t;
|
|
1143
1153
|
return t;
|
|
1144
1154
|
}
|
|
1145
|
-
function
|
|
1146
|
-
let r = new
|
|
1155
|
+
function ft(e, t, n) {
|
|
1156
|
+
let r = new I.Vector3().fromArray(e.com), i = new I.Quaternion().fromArray(e.inertiaFrame);
|
|
1147
1157
|
return t && n && (r.applyMatrix4(t.clone().invert()), i.premultiply(n.clone().invert()).normalize()), {
|
|
1148
1158
|
mass: e.mass,
|
|
1149
1159
|
centerOfMass: {
|
|
@@ -1164,10 +1174,10 @@ function dt(e, t, n) {
|
|
|
1164
1174
|
}
|
|
1165
1175
|
};
|
|
1166
1176
|
}
|
|
1167
|
-
function
|
|
1177
|
+
function pt(e, t, n) {
|
|
1168
1178
|
return e.colliders.map((e, r) => {
|
|
1169
|
-
let i = new
|
|
1170
|
-
new
|
|
1179
|
+
let i = new I.Quaternion().fromArray(e.localQuaternion), a = new I.Matrix4().compose(new I.Vector3().fromArray(e.localPosition), i, new I.Vector3(1, 1, 1)), o = new I.Vector3(), s = new I.Quaternion(), c = new I.Vector3();
|
|
1180
|
+
new I.Matrix4().multiplyMatrices(t, a).decompose(o, s, c);
|
|
1171
1181
|
let l = {
|
|
1172
1182
|
spec: e,
|
|
1173
1183
|
local: a,
|
|
@@ -1183,14 +1193,14 @@ function ft(e, t, n) {
|
|
|
1183
1193
|
s.w
|
|
1184
1194
|
]
|
|
1185
1195
|
};
|
|
1186
|
-
return r === 0 && n && (l.massProperties =
|
|
1196
|
+
return r === 0 && n && (l.massProperties = ft(n, a, i)), l;
|
|
1187
1197
|
});
|
|
1188
1198
|
}
|
|
1189
|
-
function
|
|
1199
|
+
function mt(e, t, n) {
|
|
1190
1200
|
for (let r = e.joint ? n.get(e.joint.connectedNodeName) : void 0; r; r = r.joint ? n.get(r.joint.connectedNodeName) : void 0) if (r.nodeName === t) return !0;
|
|
1191
1201
|
return !1;
|
|
1192
1202
|
}
|
|
1193
|
-
function
|
|
1203
|
+
function ht(t) {
|
|
1194
1204
|
let r = new Map(t.bodies.map((e) => [e.nodeName, e])), i = (t, n = /* @__PURE__ */ new Set()) => {
|
|
1195
1205
|
if (!t.joint) return t;
|
|
1196
1206
|
if (n.has(t.nodeName)) throw new e(`Joint cycle through "${t.nodeName}"`);
|
|
@@ -1203,19 +1213,19 @@ function mt(t) {
|
|
|
1203
1213
|
s.sort((e, t) => c(e) - c(t));
|
|
1204
1214
|
let l = /* @__PURE__ */ new Map(), u = s.map((t) => {
|
|
1205
1215
|
let n = t.joint, i = l.get(n.connectedNodeName) ?? null;
|
|
1206
|
-
if (i && !
|
|
1216
|
+
if (i && !gt(t.object, i.spec.object)) throw new e(`Jointed node "${t.nodeName}" must be a scene-graph descendant of its jointed parent "${n.connectedNodeName}"`);
|
|
1207
1217
|
let a = o.clone().multiply(x(t)), c = {
|
|
1208
1218
|
spec: t,
|
|
1209
1219
|
joint: n,
|
|
1210
1220
|
parent: i,
|
|
1211
1221
|
restRelParent: i ? x(i.spec).invert().multiply(x(t)) : a,
|
|
1212
|
-
inertia: de(t, n, s.filter((e) => e !== t &&
|
|
1213
|
-
colliders:
|
|
1222
|
+
inertia: de(t, n, s.filter((e) => e !== t && mt(e, t.nodeName, r))),
|
|
1223
|
+
colliders: pt(t, a, null)
|
|
1214
1224
|
};
|
|
1215
1225
|
return l.set(t.nodeName, c), c;
|
|
1216
|
-
}), d = a.isKinematic ? null : n([a, ...s], o), f =
|
|
1226
|
+
}), d = a.isKinematic ? null : n([a, ...s], o), f = pt(a, new I.Matrix4(), d), p = d && f.length === 0 ? ft(d) : void 0, m = dt([a.object, ...s.map((e) => e.object)], t.scene), h = o.clone().multiply(ut(m, t.scene)), g = new I.Vector3(), _ = new I.Quaternion(), v = new I.Vector3();
|
|
1217
1227
|
o.decompose(g, _, v), _.normalize();
|
|
1218
|
-
let y = new
|
|
1228
|
+
let y = new I.Vector3(), b = new I.Quaternion(), S = new I.Vector3();
|
|
1219
1229
|
return h.decompose(y, b, S), b.normalize(), {
|
|
1220
1230
|
spec: a,
|
|
1221
1231
|
sceneInRootPos: [
|
|
@@ -1247,15 +1257,15 @@ function mt(t) {
|
|
|
1247
1257
|
parts: u
|
|
1248
1258
|
};
|
|
1249
1259
|
});
|
|
1250
|
-
for (let t of a) for (let n of a) if (t !== n &&
|
|
1260
|
+
for (let t of a) for (let n of a) if (t !== n && gt(n.mountNode, t.mountNode)) throw new e(`Root bodies "${t.spec.nodeName}" and "${n.spec.nodeName}" share scene subtree "${t.mountNode.name}"; split them into separate glTF branches`);
|
|
1251
1261
|
return a;
|
|
1252
1262
|
}
|
|
1253
|
-
function
|
|
1263
|
+
function gt(e, t) {
|
|
1254
1264
|
for (let n = e; n; n = n.parent) if (n === t) return !0;
|
|
1255
1265
|
return !1;
|
|
1256
1266
|
}
|
|
1257
1267
|
// src/AssemblyRootBody.tsx
|
|
1258
|
-
function
|
|
1268
|
+
function _t({ plan: e, assemblyId: t, position: n, quaternion: r, fixedRoot: a, rigidBodyProps: o, onBody: s, onJoints: c, children: l }) {
|
|
1259
1269
|
let u = T(C), d = k(null), f = O(() => e.parts.map((e) => e.colliders.map(() => ({ current: null }))), [e]), p = e.spec;
|
|
1260
1270
|
E(() => (s(p.nodeName, d), () => s(p.nodeName, null)), [p, s]), E(() => {
|
|
1261
1271
|
let t = d.current, n = e.rootMass;
|
|
@@ -1269,7 +1279,7 @@ function gt({ plan: e, assemblyId: t, position: n, quaternion: r, fixedRoot: a,
|
|
|
1269
1279
|
role: i.joint.role,
|
|
1270
1280
|
kind: i.joint.kind,
|
|
1271
1281
|
object: i.spec.object,
|
|
1272
|
-
axis: new
|
|
1282
|
+
axis: new I.Vector3().fromArray(i.joint.axis).normalize(),
|
|
1273
1283
|
restPosition: i.spec.object.position.clone(),
|
|
1274
1284
|
restQuaternion: i.spec.object.quaternion.clone(),
|
|
1275
1285
|
q: 0,
|
|
@@ -1305,7 +1315,7 @@ function gt({ plan: e, assemblyId: t, position: n, quaternion: r, fixedRoot: a,
|
|
|
1305
1315
|
c
|
|
1306
1316
|
]);
|
|
1307
1317
|
let m = p.isKinematic ? a ? "fixed" : "kinematicPosition" : "dynamic";
|
|
1308
|
-
return /* @__PURE__ */
|
|
1318
|
+
return /* @__PURE__ */ te(P, {
|
|
1309
1319
|
...o,
|
|
1310
1320
|
ref: d,
|
|
1311
1321
|
type: m,
|
|
@@ -1317,13 +1327,13 @@ function gt({ plan: e, assemblyId: t, position: n, quaternion: r, fixedRoot: a,
|
|
|
1317
1327
|
...p.gravityFactor === void 0 ? {} : { gravityScale: p.gravityFactor },
|
|
1318
1328
|
children: [
|
|
1319
1329
|
l,
|
|
1320
|
-
e.colliders.map((e, t) => /* @__PURE__ */
|
|
1330
|
+
e.colliders.map((e, t) => /* @__PURE__ */ L(i, {
|
|
1321
1331
|
c: e.spec,
|
|
1322
1332
|
position: e.position,
|
|
1323
1333
|
quaternion: e.quaternion,
|
|
1324
1334
|
massProperties: e.massProperties
|
|
1325
1335
|
}, `r${t}`)),
|
|
1326
|
-
e.parts.map((e, t) => e.colliders.map((n, r) => /* @__PURE__ */
|
|
1336
|
+
e.parts.map((e, t) => e.colliders.map((n, r) => /* @__PURE__ */ L(i, {
|
|
1327
1337
|
ref: f[t][r],
|
|
1328
1338
|
c: n.spec,
|
|
1329
1339
|
position: n.position,
|
|
@@ -1334,14 +1344,14 @@ function gt({ plan: e, assemblyId: t, position: n, quaternion: r, fixedRoot: a,
|
|
|
1334
1344
|
});
|
|
1335
1345
|
}
|
|
1336
1346
|
// src/KhrAssembly.tsx
|
|
1337
|
-
var
|
|
1338
|
-
function
|
|
1347
|
+
var vt = 0;
|
|
1348
|
+
function yt({ ref: t, bundle: n, position: r = [
|
|
1339
1349
|
0,
|
|
1340
1350
|
0,
|
|
1341
1351
|
0
|
|
1342
1352
|
], rotation: i, quaternion: a, scale: o, fixedRoot: l = !1, rigidBodyProps: u, children: d, ...f }) {
|
|
1343
1353
|
c(o, "KhrAssembly"), n.scene.updateMatrixWorld(!0), s(n.scene);
|
|
1344
|
-
let m = O(() =>
|
|
1354
|
+
let m = O(() => vt++, []), h = O(() => ht(n), [n]), _ = O(() => h.length > 1 ? g(h.map((e) => e.mountNode)) : null, [h]), [y, b, x] = r, [S, C, T] = i ?? [
|
|
1345
1355
|
0,
|
|
1346
1356
|
0,
|
|
1347
1357
|
0
|
|
@@ -1350,7 +1360,7 @@ function vt({ ref: t, bundle: n, position: r = [
|
|
|
1350
1360
|
NaN,
|
|
1351
1361
|
NaN,
|
|
1352
1362
|
NaN
|
|
1353
|
-
], M = O(() => a ? new
|
|
1363
|
+
], M = O(() => a ? new I.Quaternion(E, D, A, j) : new I.Quaternion().setFromEuler(new I.Euler(S, C, T)), [
|
|
1354
1364
|
E,
|
|
1355
1365
|
D,
|
|
1356
1366
|
A,
|
|
@@ -1359,7 +1369,7 @@ function vt({ ref: t, bundle: n, position: r = [
|
|
|
1359
1369
|
C,
|
|
1360
1370
|
T
|
|
1361
1371
|
]), N = O(() => h.map((e) => {
|
|
1362
|
-
let t = new
|
|
1372
|
+
let t = new I.Vector3().fromArray(e.spec.localPosition).applyQuaternion(M).add(new I.Vector3(y, b, x)), n = M.clone().multiply(new I.Quaternion().fromArray(e.spec.localQuaternion));
|
|
1363
1373
|
return {
|
|
1364
1374
|
position: [
|
|
1365
1375
|
t.x,
|
|
@@ -1379,7 +1389,7 @@ function vt({ ref: t, bundle: n, position: r = [
|
|
|
1379
1389
|
y,
|
|
1380
1390
|
b,
|
|
1381
1391
|
x
|
|
1382
|
-
]),
|
|
1392
|
+
]), P = k(/* @__PURE__ */ new Map()), F = k(/* @__PURE__ */ new Map()), R = O(() => {
|
|
1383
1393
|
let e = /* @__PURE__ */ new Map();
|
|
1384
1394
|
for (let t of h) {
|
|
1385
1395
|
e.set(t.spec.nodeName, t.spec.nodeName);
|
|
@@ -1387,35 +1397,35 @@ function vt({ ref: t, bundle: n, position: r = [
|
|
|
1387
1397
|
}
|
|
1388
1398
|
return e;
|
|
1389
1399
|
}, [h]), ne = w((e, t) => {
|
|
1390
|
-
t ? te.current.set(e, t) : te.current.delete(e);
|
|
1391
|
-
}, []), z = w((e, t) => {
|
|
1392
1400
|
t ? P.current.set(e, t) : P.current.delete(e);
|
|
1401
|
+
}, []), z = w((e, t) => {
|
|
1402
|
+
t ? F.current.set(e, t) : F.current.delete(e);
|
|
1393
1403
|
}, []);
|
|
1394
1404
|
if (ee(t, () => {
|
|
1395
1405
|
let t = (t, n) => {
|
|
1396
1406
|
if (!t.drive || t.drive.stiffness === void 0) throw new e(`Joint "${t.nodeName}" has no authored drive stiffness; cannot set a position target`);
|
|
1397
1407
|
t.positionTarget = n;
|
|
1398
|
-
let r =
|
|
1408
|
+
let r = P.current.get(R.get(t.nodeName))?.current;
|
|
1399
1409
|
r && r.isDynamic() && r.wakeUp();
|
|
1400
1410
|
};
|
|
1401
1411
|
return {
|
|
1402
1412
|
getBody: (e) => {
|
|
1403
1413
|
let t = R.get(e);
|
|
1404
|
-
return t ?
|
|
1414
|
+
return t ? P.current.get(t)?.current ?? null : null;
|
|
1405
1415
|
},
|
|
1406
1416
|
setJointTarget: (e, n) => {
|
|
1407
|
-
let r =
|
|
1417
|
+
let r = F.current.get(R.get(e) ?? "")?.get(e);
|
|
1408
1418
|
r && t(r, n);
|
|
1409
1419
|
},
|
|
1410
1420
|
setRoleTarget: (e, n) => {
|
|
1411
|
-
for (let r of
|
|
1421
|
+
for (let r of F.current.values()) for (let i of r.values()) i.role === e && t(i, n);
|
|
1412
1422
|
}
|
|
1413
1423
|
};
|
|
1414
1424
|
}, [R]), h.length === 1) {
|
|
1415
1425
|
let e = h[0];
|
|
1416
|
-
return /* @__PURE__ */
|
|
1426
|
+
return /* @__PURE__ */ L("group", {
|
|
1417
1427
|
...f,
|
|
1418
|
-
children: /* @__PURE__ */
|
|
1428
|
+
children: /* @__PURE__ */ L(_t, {
|
|
1419
1429
|
plan: e,
|
|
1420
1430
|
assemblyId: m,
|
|
1421
1431
|
position: N[0].position,
|
|
@@ -1424,10 +1434,10 @@ function vt({ ref: t, bundle: n, position: r = [
|
|
|
1424
1434
|
rigidBodyProps: u,
|
|
1425
1435
|
onBody: ne,
|
|
1426
1436
|
onJoints: z,
|
|
1427
|
-
children: /* @__PURE__ */
|
|
1437
|
+
children: /* @__PURE__ */ te("group", {
|
|
1428
1438
|
position: e.sceneInRootPos,
|
|
1429
1439
|
quaternion: e.sceneInRootQuat,
|
|
1430
|
-
children: [/* @__PURE__ */
|
|
1440
|
+
children: [/* @__PURE__ */ L(v, {
|
|
1431
1441
|
bundle: n,
|
|
1432
1442
|
owner: "KhrAssembly"
|
|
1433
1443
|
}), d]
|
|
@@ -1435,16 +1445,16 @@ function vt({ ref: t, bundle: n, position: r = [
|
|
|
1435
1445
|
}, `${n.scene.uuid}:${e.spec.nodeName}`)
|
|
1436
1446
|
});
|
|
1437
1447
|
}
|
|
1438
|
-
return /* @__PURE__ */
|
|
1448
|
+
return /* @__PURE__ */ te("group", {
|
|
1439
1449
|
...f,
|
|
1440
|
-
children: [/* @__PURE__ */
|
|
1450
|
+
children: [/* @__PURE__ */ te("group", {
|
|
1441
1451
|
position: r,
|
|
1442
1452
|
quaternion: M,
|
|
1443
|
-
children: [/* @__PURE__ */
|
|
1453
|
+
children: [/* @__PURE__ */ L(v, {
|
|
1444
1454
|
bundle: n,
|
|
1445
1455
|
owner: "KhrAssembly"
|
|
1446
1456
|
}), d]
|
|
1447
|
-
}), h.map((e, t) => /* @__PURE__ */
|
|
1457
|
+
}), h.map((e, t) => /* @__PURE__ */ L(_t, {
|
|
1448
1458
|
plan: e,
|
|
1449
1459
|
assemblyId: m,
|
|
1450
1460
|
position: N[t].position,
|
|
@@ -1453,7 +1463,7 @@ function vt({ ref: t, bundle: n, position: r = [
|
|
|
1453
1463
|
rigidBodyProps: u,
|
|
1454
1464
|
onBody: ne,
|
|
1455
1465
|
onJoints: z,
|
|
1456
|
-
children: /* @__PURE__ */
|
|
1466
|
+
children: /* @__PURE__ */ L(p, {
|
|
1457
1467
|
object: e.mountNode,
|
|
1458
1468
|
position: e.mountPosition,
|
|
1459
1469
|
quaternion: e.mountQuaternion,
|
|
@@ -1463,28 +1473,28 @@ function vt({ ref: t, bundle: n, position: r = [
|
|
|
1463
1473
|
});
|
|
1464
1474
|
}
|
|
1465
1475
|
// src/useKhrGlb.ts
|
|
1466
|
-
var
|
|
1476
|
+
var bt = class extends R {
|
|
1467
1477
|
static khrLoaderScope = Symbol("KhrGLTFLoader");
|
|
1468
|
-
},
|
|
1469
|
-
function wt(e) {
|
|
1470
|
-
St.has(e) || (St.add(e), typeof document > "u" && typeof createImageBitmap > "u" && e.register(bt), e.register(xt));
|
|
1471
|
-
}
|
|
1478
|
+
}, xt = Ye(), St = et(), Ct = /* @__PURE__ */ new WeakSet(), wt = /* @__PURE__ */ new WeakSet(), $ = /* @__PURE__ */ new Map();
|
|
1472
1479
|
function Tt(e) {
|
|
1473
|
-
|
|
1480
|
+
Ct.has(e) || (Ct.add(e), typeof document > "u" && typeof createImageBitmap > "u" && e.register(xt), e.register(St));
|
|
1474
1481
|
}
|
|
1475
1482
|
function Et(e) {
|
|
1483
|
+
return !!(e?.extendLoader || e?.cacheKey !== void 0);
|
|
1484
|
+
}
|
|
1485
|
+
function Dt(e) {
|
|
1476
1486
|
return e.cacheKey === void 0 ? `src:${Function.prototype.toString.call(e.extendLoader)}` : `key:${e.cacheKey}`;
|
|
1477
1487
|
}
|
|
1478
|
-
function
|
|
1479
|
-
let n =
|
|
1488
|
+
function Ot(e, t) {
|
|
1489
|
+
let n = Dt(t), r = $.get(e);
|
|
1480
1490
|
r || (r = /* @__PURE__ */ new Map(), $.set(e, r));
|
|
1481
1491
|
let i = r.get(n);
|
|
1482
1492
|
if (!i) {
|
|
1483
1493
|
let a = new R(), o = t.extendLoader, s = {
|
|
1484
1494
|
loader: a,
|
|
1485
1495
|
registerExtensions: (t) => {
|
|
1486
|
-
if (
|
|
1487
|
-
o(t),
|
|
1496
|
+
if (Tt(t), o && !wt.has(t)) try {
|
|
1497
|
+
o(t), wt.add(t);
|
|
1488
1498
|
} catch (t) {
|
|
1489
1499
|
let r = $.get(e);
|
|
1490
1500
|
throw r?.get(n) === s && (r.delete(n), r.size === 0 && $.delete(e)), t;
|
|
@@ -1495,9 +1505,9 @@ function Dt(e, t) {
|
|
|
1495
1505
|
}
|
|
1496
1506
|
return i;
|
|
1497
1507
|
}
|
|
1498
|
-
function
|
|
1499
|
-
let r = n?.extractRole, i = n?.isSocketNode, a =
|
|
1500
|
-
if (!c) throw new e(`useKhrGlb: missing "${
|
|
1508
|
+
function kt(t, n) {
|
|
1509
|
+
let r = n?.extractRole, i = n?.isSocketNode, a = Et(n) ? Ot(t, n) : null, o = a ? a.loader : bt, s = a ? a.registerExtensions : Tt, c = M(o, t, s).userData[Qe];
|
|
1510
|
+
if (!c) throw new e(`useKhrGlb: missing "${Qe}" on loaded GLTF for "${t}"`);
|
|
1501
1511
|
return O(() => {
|
|
1502
1512
|
let e = _(c);
|
|
1503
1513
|
return (r || i) && Oe(e, c, r, i), e;
|
|
@@ -1507,16 +1517,16 @@ function Ot(t, n) {
|
|
|
1507
1517
|
i
|
|
1508
1518
|
]);
|
|
1509
1519
|
}
|
|
1510
|
-
|
|
1511
|
-
let n =
|
|
1520
|
+
kt.preload = (e, t) => {
|
|
1521
|
+
let n = Et(t) ? Ot(e, t) : null, r = n ? n.loader : bt, i = n ? n.registerExtensions : Tt;
|
|
1512
1522
|
M.preload(r, e, i);
|
|
1513
|
-
},
|
|
1514
|
-
if (
|
|
1523
|
+
}, kt.clear = (e, t) => {
|
|
1524
|
+
if (Et(t)) {
|
|
1515
1525
|
let n = $.get(e);
|
|
1516
1526
|
if (!n) return;
|
|
1517
|
-
let r =
|
|
1527
|
+
let r = Dt(t), i = n.get(r);
|
|
1518
1528
|
i && (M.clear(i.loader, e), n.delete(r), n.size === 0 && $.delete(e));
|
|
1519
|
-
} else if (M.clear(
|
|
1529
|
+
} else if (M.clear(bt, e), t === void 0) {
|
|
1520
1530
|
let t = $.get(e);
|
|
1521
1531
|
if (t) {
|
|
1522
1532
|
for (let n of t.values()) M.clear(n.loader, e);
|
|
@@ -1524,4 +1534,4 @@ Ot.preload = (e, t) => {
|
|
|
1524
1534
|
}
|
|
1525
1535
|
}
|
|
1526
1536
|
};
|
|
1527
|
-
export { C as JointRegistryContext,
|
|
1537
|
+
export { C as JointRegistryContext, yt as KhrAssembly, i as KhrCollider, e as KhrValidationError, ve as PhysicsWorld, y as assertIdentityWorldScale, s as assertSceneIdentityWorldScale, c as assertUnitScale, m as claimBundleMount, _ as cloneKhrBundle, et as createKhrGltfPlugin, o as disposeKhrBundle, lt as exportKhrGlb, rt as loadKhrGlb, Te as patchGlbJsonChunk, d as releaseBundleMount, kt as useKhrGlb };
|