@khr3/core 0.1.3 → 0.1.4
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/README.md +2 -2
- package/dist/KhrVehicle.d.ts +1 -1
- package/dist/index.js +252 -287
- package/dist/khrTypes.d.ts +0 -6
- package/dist/khrVehicleSlots.d.ts +7 -3
- package/dist/vehicle.js +140 -122
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
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
|
-
import { useCallback as w, useContext as T, useImperativeHandle as ee, useLayoutEffect as
|
|
3
|
-
import { useFrame as
|
|
4
|
-
import { Physics as
|
|
5
|
-
import * as
|
|
6
|
-
import { jsx as
|
|
7
|
-
import { GLTFLoader as
|
|
8
|
-
import { GLTFExporter as
|
|
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
|
+
import { useFrame as j, useLoader as M } from "@react-three/fiber";
|
|
4
|
+
import { Physics as N, RigidBody as te, useRapier as P } from "@react-three/rapier";
|
|
5
|
+
import * as F from "three";
|
|
6
|
+
import { jsx as I, jsxs as L } from "react/jsx-runtime";
|
|
7
|
+
import { GLTFLoader as R } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
8
|
+
import { GLTFExporter as ne } from "three/examples/jsm/exporters/GLTFExporter.js";
|
|
9
9
|
// src/jointDynamics.ts
|
|
10
|
-
var
|
|
11
|
-
function
|
|
10
|
+
var z = new F.Vector3(), B = new F.Vector3(), re = new F.Vector3(), ie = new F.Quaternion(), ae = new F.Quaternion(), oe = new F.Matrix4(), se = new F.Matrix4(), ce = new F.Matrix4(), le = new F.Matrix4(), V = new F.Vector3(), H = new F.Quaternion(), ue = new F.Vector3();
|
|
11
|
+
function de(e, t, n = []) {
|
|
12
12
|
if (t.kind === "fixed") return 0;
|
|
13
13
|
let r = n.length > 0 ? [e, ...n] : [e];
|
|
14
14
|
if (t.kind === "prismatic") {
|
|
@@ -16,19 +16,19 @@ function le(e, t, n = []) {
|
|
|
16
16
|
for (let n of r) n.isKinematic && n !== e || (t += n.mass);
|
|
17
17
|
return t;
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
z.fromArray(t.axis).normalize(), n.length > 0 && x(e, oe).invert();
|
|
20
20
|
let i = 0;
|
|
21
21
|
for (let t of r) {
|
|
22
22
|
if (t !== e && t.isKinematic) continue;
|
|
23
|
-
t === e ? (V.set(0, 0, 0), H.identity()) : (
|
|
24
|
-
let [n, r, a] = t.inertiaDiagonal, o = n *
|
|
25
|
-
|
|
26
|
-
let s =
|
|
27
|
-
i += o + t.mass * (
|
|
23
|
+
t === e ? (V.set(0, 0, 0), H.identity()) : (se.multiplyMatrices(oe, x(t, le)).decompose(V, H, ue), H.normalize()), ae.copy(H).multiply(ie.fromArray(t.inertiaOrientation)).invert(), B.copy(z).applyQuaternion(ae);
|
|
24
|
+
let [n, r, a] = t.inertiaDiagonal, o = n * B.x * B.x + r * B.y * B.y + a * B.z * B.z;
|
|
25
|
+
re.fromArray(t.centerOfMass).applyQuaternion(H).add(V);
|
|
26
|
+
let s = re.dot(z);
|
|
27
|
+
i += o + t.mass * (re.lengthSq() - s * s);
|
|
28
28
|
}
|
|
29
29
|
return i;
|
|
30
30
|
}
|
|
31
|
-
function
|
|
31
|
+
function fe(t, n) {
|
|
32
32
|
if (t.kind === "fixed" || !(n > 0)) return;
|
|
33
33
|
let r = t.drive, i = r?.mode === "force", a = t.limits !== null && t.limitStiffness !== null;
|
|
34
34
|
if ((i || a) && !(t.inertia > 0)) throw new e(`Joint "${t.nodeName}" requires positive effective inertia (got ${t.inertia})`);
|
|
@@ -49,79 +49,46 @@ function ue(t, n) {
|
|
|
49
49
|
}
|
|
50
50
|
t.v = p, t.q += p * n, t.limits && t.limitStiffness === null && (t.q < t.limits[0] ? (t.q = t.limits[0], t.v < 0 && (t.v = 0)) : t.q > t.limits[1] && (t.q = t.limits[1], t.v > 0 && (t.v = 0)));
|
|
51
51
|
}
|
|
52
|
-
var
|
|
53
|
-
function
|
|
52
|
+
var pe = 1e-7;
|
|
53
|
+
function me(e, t) {
|
|
54
54
|
if (e.stamp === t) return;
|
|
55
|
-
e.parent && e.parent.stamp !== t &&
|
|
55
|
+
e.parent && e.parent.stamp !== t && me(e.parent, t), e.stamp = t;
|
|
56
56
|
let n = e.parent !== null && e.parent.dirtyStamp === t, r = e.colliders.every((e) => e.ref.current !== null);
|
|
57
|
-
if (e.lastWrittenQ === void 0 || Math.abs(e.q - e.lastWrittenQ) >
|
|
58
|
-
e.dirtyStamp = t, r && (e.lastWrittenQ = e.q), e.kind === "revolute" ? (
|
|
57
|
+
if (e.lastWrittenQ === void 0 || Math.abs(e.q - e.lastWrittenQ) > pe || n) {
|
|
58
|
+
e.dirtyStamp = t, r && (e.lastWrittenQ = e.q), e.kind === "revolute" ? (ie.setFromAxisAngle(e.axis, e.q), e.object.quaternion.copy(e.restQuaternion).multiply(ie), e.object.position.copy(e.restPosition), ce.makeRotationFromQuaternion(ie)) : e.kind === "prismatic" ? (z.copy(e.axis).multiplyScalar(e.q), e.object.quaternion.copy(e.restQuaternion), e.object.position.copy(z).applyQuaternion(e.restQuaternion).add(e.restPosition), ce.makeTranslation(z.x, z.y, z.z)) : ce.identity(), e.parent ? e.current.multiplyMatrices(e.parent.current, e.restRelParent) : e.current.copy(e.restRelParent), e.current.multiply(ce);
|
|
59
59
|
for (let t of e.colliders) {
|
|
60
60
|
let n = t.ref.current;
|
|
61
|
-
n && (
|
|
61
|
+
n && (le.multiplyMatrices(e.current, t.local).decompose(V, H, ue), n.setTranslationWrtParent(V), n.setRotationWrtParent(H));
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
// src/PhysicsWorld.tsx
|
|
66
|
-
var
|
|
67
|
-
function
|
|
68
|
-
let { world:
|
|
69
|
-
return
|
|
70
|
-
let
|
|
71
|
-
if (!(
|
|
72
|
-
|
|
73
|
-
let e =
|
|
74
|
-
e
|
|
75
|
-
|
|
76
|
-
let n = t.linvel(), r = t.angvel();
|
|
77
|
-
e.push({
|
|
78
|
-
rb: t,
|
|
79
|
-
lx: n.x,
|
|
80
|
-
ly: n.y,
|
|
81
|
-
lz: n.z,
|
|
82
|
-
ax: r.x,
|
|
83
|
-
ay: r.y,
|
|
84
|
-
az: r.z,
|
|
85
|
-
sleeping: t.isSleeping()
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
} else if (a.current.length = 0, i.current = f, o.timestep = f, r.size > 0) {
|
|
89
|
-
let e = ++s.current;
|
|
90
|
-
for (let e of r) ue(e, f);
|
|
91
|
-
for (let t of r) fe(t, e);
|
|
66
|
+
var he = (e) => typeof e == "number" ? e : e.current;
|
|
67
|
+
function ge({ paused: e, timeScale: t, maxDelta: n, joints: r, dtRef: i, activeRef: a, setActiveState: o }) {
|
|
68
|
+
let { world: s } = P(), c = k(0);
|
|
69
|
+
return j((l, u) => {
|
|
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
|
+
if (p !== a.current && (a.current = p, o(p)), !(m > 0)) i.current = 0;
|
|
72
|
+
else if (i.current = m, s.timestep = m, r.size > 0) {
|
|
73
|
+
let e = ++c.current;
|
|
74
|
+
for (let e of r) fe(e, m);
|
|
75
|
+
for (let t of r) me(t, e);
|
|
92
76
|
}
|
|
93
77
|
}), null;
|
|
94
78
|
}
|
|
95
|
-
function
|
|
96
|
-
let { step:
|
|
97
|
-
return
|
|
98
|
-
let
|
|
99
|
-
|
|
100
|
-
n(r);
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
let i = t.current;
|
|
104
|
-
for (let e = 0; e < i.length; e++) {
|
|
105
|
-
let t = i[e];
|
|
106
|
-
t.rb.setLinvel({
|
|
107
|
-
x: t.lx,
|
|
108
|
-
y: t.ly,
|
|
109
|
-
z: t.lz
|
|
110
|
-
}, !1), t.rb.setAngvel({
|
|
111
|
-
x: t.ax,
|
|
112
|
-
y: t.ay,
|
|
113
|
-
z: t.az
|
|
114
|
-
}, !1), t.sleeping && !t.rb.isSleeping() && t.rb.sleep();
|
|
115
|
-
}
|
|
116
|
-
i.length = 0;
|
|
79
|
+
function _e({ dtRef: e }) {
|
|
80
|
+
let { step: t } = P();
|
|
81
|
+
return j(() => {
|
|
82
|
+
let n = e.current;
|
|
83
|
+
n > 0 && t(n);
|
|
117
84
|
}), null;
|
|
118
85
|
}
|
|
119
|
-
function
|
|
86
|
+
function ve({ paused: e = !1, timeScale: n = 1, maxDelta: r = 1 / 30, gravity: i = [
|
|
120
87
|
0,
|
|
121
88
|
-9.81,
|
|
122
89
|
0
|
|
123
90
|
], children: o, ...s }) {
|
|
124
|
-
let c =
|
|
91
|
+
let c = O(() => /* @__PURE__ */ new Set(), []), l = k(0), u = !e && (typeof n != "number" || n > 0) && (typeof r != "number" || r > 0), [d, f] = A(u), p = k(u), m = u && d, h = O(() => [
|
|
125
92
|
i[0],
|
|
126
93
|
i[1],
|
|
127
94
|
i[2]
|
|
@@ -129,34 +96,32 @@ function ge({ paused: e = !1, timeScale: n = 1, maxDelta: r = 1 / 30, gravity: i
|
|
|
129
96
|
i[0],
|
|
130
97
|
i[1],
|
|
131
98
|
i[2]
|
|
132
|
-
])
|
|
133
|
-
return /* @__PURE__ */
|
|
99
|
+
]);
|
|
100
|
+
return /* @__PURE__ */ I(C.Provider, {
|
|
134
101
|
value: c,
|
|
135
|
-
children: /* @__PURE__ */
|
|
136
|
-
value:
|
|
137
|
-
children: /* @__PURE__ */
|
|
138
|
-
value:
|
|
139
|
-
children: /* @__PURE__ */
|
|
102
|
+
children: /* @__PURE__ */ I(S.Provider, {
|
|
103
|
+
value: h,
|
|
104
|
+
children: /* @__PURE__ */ I(a.Provider, {
|
|
105
|
+
value: m,
|
|
106
|
+
children: /* @__PURE__ */ I(t.Provider, {
|
|
140
107
|
value: l,
|
|
141
|
-
children: /* @__PURE__ */
|
|
108
|
+
children: /* @__PURE__ */ L(N, {
|
|
142
109
|
...s,
|
|
143
110
|
paused: !0,
|
|
144
111
|
timeStep: "vary",
|
|
145
112
|
gravity: i,
|
|
146
113
|
children: [
|
|
147
|
-
/* @__PURE__ */
|
|
114
|
+
/* @__PURE__ */ I(ge, {
|
|
148
115
|
paused: e,
|
|
149
116
|
timeScale: n,
|
|
150
117
|
maxDelta: r,
|
|
151
118
|
joints: c,
|
|
152
119
|
dtRef: l,
|
|
153
|
-
|
|
120
|
+
activeRef: p,
|
|
121
|
+
setActiveState: f
|
|
154
122
|
}),
|
|
155
123
|
o,
|
|
156
|
-
/* @__PURE__ */
|
|
157
|
-
dtRef: l,
|
|
158
|
-
frozenRef: u
|
|
159
|
-
})
|
|
124
|
+
/* @__PURE__ */ I(_e, { dtRef: l })
|
|
160
125
|
]
|
|
161
126
|
})
|
|
162
127
|
})
|
|
@@ -165,8 +130,8 @@ function ge({ paused: e = !1, timeScale: n = 1, maxDelta: r = 1 / 30, gravity: i
|
|
|
165
130
|
});
|
|
166
131
|
}
|
|
167
132
|
// src/khrGlb.ts
|
|
168
|
-
var
|
|
169
|
-
function
|
|
133
|
+
var ye = 1179937895, be = 1313821514, xe = 5130562;
|
|
134
|
+
function Se(t) {
|
|
170
135
|
if (t.byteLength < 20) throw new e("GLB buffer shorter than 20-byte header");
|
|
171
136
|
let n = new DataView(t);
|
|
172
137
|
if (n.getUint32(0, !0) !== 1179937895) throw new e("Invalid GLB magic");
|
|
@@ -176,7 +141,7 @@ function be(t) {
|
|
|
176
141
|
if (20 + r > t.byteLength) throw new e("Truncated GLB JSON chunk");
|
|
177
142
|
return r;
|
|
178
143
|
}
|
|
179
|
-
function
|
|
144
|
+
function Ce() {
|
|
180
145
|
if (globalThis.FileReader !== void 0) return;
|
|
181
146
|
class e {
|
|
182
147
|
result = null;
|
|
@@ -203,28 +168,28 @@ function xe() {
|
|
|
203
168
|
}
|
|
204
169
|
globalThis.FileReader = e;
|
|
205
170
|
}
|
|
206
|
-
function
|
|
171
|
+
function we(e) {
|
|
207
172
|
let t = new TextEncoder().encode(JSON.stringify(e)), n = t.byteLength + 3 & -4, r = 20 + n, i = new ArrayBuffer(r), a = new DataView(i), o = new Uint8Array(i);
|
|
208
|
-
return a.setUint32(0,
|
|
173
|
+
return a.setUint32(0, ye, !0), a.setUint32(4, 2, !0), a.setUint32(8, r, !0), a.setUint32(12, n, !0), a.setUint32(16, be, !0), o.set(t, 20), o.fill(32, 20 + t.byteLength, 20 + n), i;
|
|
209
174
|
}
|
|
210
|
-
function
|
|
211
|
-
let r = t instanceof ArrayBuffer ? t : t.buffer.slice(t.byteOffset, t.byteOffset + t.byteLength), i =
|
|
175
|
+
function Te(t, n) {
|
|
176
|
+
let r = t instanceof ArrayBuffer ? t : t.buffer.slice(t.byteOffset, t.byteOffset + t.byteLength), i = Se(r), a = new DataView(r), o;
|
|
212
177
|
try {
|
|
213
178
|
o = JSON.parse(new TextDecoder().decode(new Uint8Array(r, 20, i)));
|
|
214
179
|
} catch {
|
|
215
180
|
throw new e("Malformed GLB JSON chunk");
|
|
216
181
|
}
|
|
217
182
|
n(o);
|
|
218
|
-
let s = new TextEncoder().encode(JSON.stringify(o)), c = s.byteLength + 3 & -4, l = 20 + i, u = l + 8 <= r.byteLength, d = u ? Math.min(a.getUint32(l, !0), r.byteLength - (l + 8)) : 0, f = u ? a.getUint32(l + 4, !0) :
|
|
219
|
-
return _.setUint32(0,
|
|
183
|
+
let s = new TextEncoder().encode(JSON.stringify(o)), c = s.byteLength + 3 & -4, l = 20 + i, u = l + 8 <= r.byteLength, d = u ? Math.min(a.getUint32(l, !0), r.byteLength - (l + 8)) : 0, f = u ? a.getUint32(l + 4, !0) : xe, p = u ? new Uint8Array(r, l + 8, d) : /* @__PURE__ */ new Uint8Array(), m = p.byteLength + 3 & -4, h = 20 + c + (u ? 8 + m : 0), g = new ArrayBuffer(h), _ = new DataView(g), v = new Uint8Array(g);
|
|
184
|
+
return _.setUint32(0, ye, !0), _.setUint32(4, 2, !0), _.setUint32(8, h, !0), _.setUint32(12, c, !0), _.setUint32(16, be, !0), v.set(s, 20), v.fill(32, 20 + s.byteLength, 20 + c), u && (_.setUint32(20 + c, m, !0), _.setUint32(24 + c, f, !0), v.set(p, 28 + c)), g;
|
|
220
185
|
}
|
|
221
186
|
// src/khrExtras.ts
|
|
222
|
-
var
|
|
223
|
-
function
|
|
224
|
-
|
|
187
|
+
var Ee = /* @__PURE__ */ new WeakMap();
|
|
188
|
+
function De(e, t) {
|
|
189
|
+
Ee.set(e, t);
|
|
225
190
|
}
|
|
226
|
-
function
|
|
227
|
-
let i =
|
|
191
|
+
function Oe(e, t, n, r) {
|
|
192
|
+
let i = Ee.get(t.scene);
|
|
228
193
|
if (i) {
|
|
229
194
|
if (n) for (let t = 0; t < e.bodies.length; t++) {
|
|
230
195
|
let r = i.bodies[t], a = e.bodies[t];
|
|
@@ -247,9 +212,9 @@ function Ee(e, t, n, r) {
|
|
|
247
212
|
}
|
|
248
213
|
}
|
|
249
214
|
}
|
|
250
|
-
var
|
|
251
|
-
function
|
|
252
|
-
return e.updateWorldMatrix(!0, !1), e.getWorldQuaternion(U), t && (t.updateWorldMatrix(!0, !1), U.premultiply(t.getWorldQuaternion(
|
|
215
|
+
var ke = new F.Vector3(), U = new F.Quaternion(), Ae = new F.Quaternion();
|
|
216
|
+
function je(e, t) {
|
|
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(), [
|
|
253
218
|
U.x || 0,
|
|
254
219
|
U.y || 0,
|
|
255
220
|
U.z || 0,
|
|
@@ -264,14 +229,14 @@ function K(t, n, r, i = !1) {
|
|
|
264
229
|
return a;
|
|
265
230
|
}
|
|
266
231
|
}
|
|
267
|
-
function
|
|
232
|
+
function Me(t, n, r, i) {
|
|
268
233
|
let a = t[n];
|
|
269
234
|
if (a !== void 0) {
|
|
270
235
|
if (typeof a != "boolean") throw new e(`${r} "${i}" has non-boolean ${r}.${n}`);
|
|
271
236
|
return a;
|
|
272
237
|
}
|
|
273
238
|
}
|
|
274
|
-
function
|
|
239
|
+
function Ne(t, n, r) {
|
|
275
240
|
if (t !== void 0) {
|
|
276
241
|
if (!W(t) || !Array.isArray(t.points) || t.points.length === 0) throw new e(`ecctrlWheel "${r}" has invalid ecctrlWheel.${n}`);
|
|
277
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}`);
|
|
@@ -279,9 +244,9 @@ function je(t, n, r) {
|
|
|
279
244
|
return t;
|
|
280
245
|
}
|
|
281
246
|
}
|
|
282
|
-
function
|
|
247
|
+
function Pe(t, n, r, i, a) {
|
|
283
248
|
if (r.socketId !== void 0 && (typeof r.socketId != "string" || r.socketId.length === 0)) throw new e(`Node "${n}" has invalid extras.socketId`);
|
|
284
|
-
let o = t.getWorldPosition(new
|
|
249
|
+
let o = t.getWorldPosition(new F.Vector3()), s = [
|
|
285
250
|
o.x,
|
|
286
251
|
o.y,
|
|
287
252
|
o.z
|
|
@@ -296,11 +261,11 @@ function Me(t, n, r, i, a) {
|
|
|
296
261
|
t.getWorldQuaternion(U), l = [];
|
|
297
262
|
for (let t of r.contactDots) {
|
|
298
263
|
if (!W(t) || typeof t.role != "string" || t.role.length === 0 || !Array.isArray(t.pos) || t.pos.length !== 3 || !t.pos.every(G)) throw new e(`Node "${n}" has invalid entry in extras.contactDots`);
|
|
299
|
-
|
|
264
|
+
ke.set(t.pos[0], t.pos[1], t.pos[2]).applyQuaternion(U).add(o);
|
|
300
265
|
let r = [
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
266
|
+
ke.x,
|
|
267
|
+
ke.y,
|
|
268
|
+
ke.z
|
|
304
269
|
];
|
|
305
270
|
i[t.role] = r, l.push([t.role, r]);
|
|
306
271
|
}
|
|
@@ -312,7 +277,7 @@ function Me(t, n, r, i, a) {
|
|
|
312
277
|
...l ? { contactDots: l } : {}
|
|
313
278
|
};
|
|
314
279
|
}
|
|
315
|
-
function
|
|
280
|
+
function Fe(t, n, r, i) {
|
|
316
281
|
if (y(t, n), !W(r)) throw new e(`ecctrlWheel "${n}" must be an object`);
|
|
317
282
|
let a = (t) => {
|
|
318
283
|
let i = r[t];
|
|
@@ -328,7 +293,7 @@ function Ne(t, n, r, i) {
|
|
|
328
293
|
return i;
|
|
329
294
|
}, c = a("radius"), l = a("width"), u = o("travel"), d = o("sag");
|
|
330
295
|
if (d > u) throw new e(`ecctrlWheel "${n}" has invalid ecctrlWheel.sag (${d}) > ecctrlWheel.travel (${u})`);
|
|
331
|
-
let f = s("steer"), p = s("drive"), m = s("brake"), h = new
|
|
296
|
+
let f = s("steer"), p = s("drive"), m = s("brake"), h = new F.Box3().setFromObject(t), g = h.isEmpty() ? t.getWorldPosition(new F.Vector3()) : h.getCenter(new F.Vector3());
|
|
332
297
|
return {
|
|
333
298
|
nodeName: n,
|
|
334
299
|
object: t,
|
|
@@ -337,13 +302,13 @@ function Ne(t, n, r, i) {
|
|
|
337
302
|
g.y,
|
|
338
303
|
g.z
|
|
339
304
|
],
|
|
340
|
-
quaternion:
|
|
305
|
+
quaternion: je(t, i),
|
|
341
306
|
radius: c,
|
|
342
307
|
width: l,
|
|
343
308
|
steer: f,
|
|
344
|
-
steerInvert:
|
|
309
|
+
steerInvert: Me(r, "steerInvert", "ecctrlWheel", n),
|
|
345
310
|
drive: p,
|
|
346
|
-
driveInvert:
|
|
311
|
+
driveInvert: Me(r, "driveInvert", "ecctrlWheel", n),
|
|
347
312
|
brake: m,
|
|
348
313
|
travel: u,
|
|
349
314
|
sag: d,
|
|
@@ -357,11 +322,11 @@ function Ne(t, n, r, i) {
|
|
|
357
322
|
latFrictionEllipseScale: K(r, "latFrictionEllipseScale", n),
|
|
358
323
|
relaxLngRate: K(r, "relaxLngRate", n),
|
|
359
324
|
relaxLatRate: K(r, "relaxLatRate", n),
|
|
360
|
-
lngSlipRatioCurveData:
|
|
361
|
-
latSlipRatioCurveData:
|
|
325
|
+
lngSlipRatioCurveData: Ne(r.lngSlipRatioCurveData, "lngSlipRatioCurveData", n),
|
|
326
|
+
latSlipRatioCurveData: Ne(r.latSlipRatioCurveData, "latSlipRatioCurveData", n)
|
|
362
327
|
};
|
|
363
328
|
}
|
|
364
|
-
function
|
|
329
|
+
function Ie(t, n, r, i) {
|
|
365
330
|
if (y(t, n), !W(r)) throw new e(`ecctrlPropeller "${n}" must be an object`);
|
|
366
331
|
if (!G(r.maxThrust) || r.maxThrust <= 0) throw new e(`ecctrlPropeller "${n}" is missing positive finite ecctrlPropeller.maxThrust`);
|
|
367
332
|
let a;
|
|
@@ -369,7 +334,7 @@ function Pe(t, n, r, i) {
|
|
|
369
334
|
if (!G(r.torqueRatio)) throw new e(`ecctrlPropeller "${n}" has invalid ecctrlPropeller.torqueRatio`);
|
|
370
335
|
a = r.torqueRatio;
|
|
371
336
|
}
|
|
372
|
-
let o = new
|
|
337
|
+
let o = new F.Box3().setFromObject(t), s = o.isEmpty() ? t.getWorldPosition(new F.Vector3()) : o.getCenter(new F.Vector3());
|
|
373
338
|
return {
|
|
374
339
|
nodeName: n,
|
|
375
340
|
object: t,
|
|
@@ -378,23 +343,23 @@ function Pe(t, n, r, i) {
|
|
|
378
343
|
s.y,
|
|
379
344
|
s.z
|
|
380
345
|
],
|
|
381
|
-
quaternion:
|
|
346
|
+
quaternion: je(t, i),
|
|
382
347
|
maxThrust: r.maxThrust,
|
|
383
348
|
torqueRatio: a,
|
|
384
|
-
invertThrust:
|
|
385
|
-
invertTorque:
|
|
349
|
+
invertThrust: Me(r, "invertThrust", "ecctrlPropeller", n),
|
|
350
|
+
invertTorque: Me(r, "invertTorque", "ecctrlPropeller", n)
|
|
386
351
|
};
|
|
387
352
|
}
|
|
388
353
|
// src/khrParsers.ts
|
|
389
|
-
var
|
|
354
|
+
var Le = /* @__PURE__ */ new Map([["default", 0]]), Re = 1, ze = (e) => typeof e == "object" && !!e && !Array.isArray(e), q = (e) => typeof e == "number" && Number.isFinite(e) && e > 0, Be = (e) => typeof e == "number" && Number.isFinite(e) && e >= 0;
|
|
390
355
|
function J(t, n, r = !1) {
|
|
391
356
|
if (t !== void 0) {
|
|
392
357
|
if (typeof t != "number" || !Number.isFinite(t) || r && t < 0) throw new e(`Invalid ${n}`);
|
|
393
358
|
return t;
|
|
394
359
|
}
|
|
395
360
|
}
|
|
396
|
-
function
|
|
397
|
-
if (!
|
|
361
|
+
function Ve(t, n) {
|
|
362
|
+
if (!ze(t)) throw new e(`KHR_implicit_shapes[${n}] must be an object`);
|
|
398
363
|
let r = t.type;
|
|
399
364
|
if (r === "box" && t.box && typeof t.box == "object") {
|
|
400
365
|
let r = t.box.size;
|
|
@@ -431,25 +396,25 @@ function ze(t, n) {
|
|
|
431
396
|
}
|
|
432
397
|
throw new e(`KHR_implicit_shapes[${n}] unsupported shape type "${r}"`);
|
|
433
398
|
}
|
|
434
|
-
function
|
|
399
|
+
function He(t, n, r) {
|
|
435
400
|
if (n === void 0) return {};
|
|
436
401
|
if (typeof n != "number" || !Number.isInteger(n) || n < 0 || n >= t.length) throw new e(`Node "${r}" references out-of-bounds physicsMaterial ${String(n)}`);
|
|
437
402
|
let i = t[n];
|
|
438
|
-
if (!
|
|
403
|
+
if (!ze(i)) throw new e(`Invalid physicsMaterials[${n}] on "${r}"`);
|
|
439
404
|
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);
|
|
440
405
|
return {
|
|
441
406
|
...a !== void 0 || o !== void 0 ? { friction: a ?? o } : {},
|
|
442
407
|
...s === void 0 ? {} : { restitution: s }
|
|
443
408
|
};
|
|
444
409
|
}
|
|
445
|
-
function
|
|
410
|
+
function Ue(t, n, i) {
|
|
446
411
|
if (t.isKinematic !== void 0 && typeof t.isKinematic != "boolean") throw new e(`Node "${i}" has non-boolean motion.isKinematic`);
|
|
447
412
|
let a = !n || !!t.isKinematic, o = 0;
|
|
448
413
|
if (!a) {
|
|
449
414
|
if (!q(t.mass)) throw new e(`Dynamic node "${i}" is missing positive finite motion.mass`);
|
|
450
415
|
o = t.mass;
|
|
451
416
|
} else if (t.mass !== void 0) {
|
|
452
|
-
if (!
|
|
417
|
+
if (!Be(t.mass)) throw new e(`Kinematic node "${i}" has invalid motion.mass`);
|
|
453
418
|
o = t.mass;
|
|
454
419
|
}
|
|
455
420
|
let s = t.centerOfMass === void 0 ? [
|
|
@@ -480,13 +445,13 @@ function Ve(t, n, i) {
|
|
|
480
445
|
...p === void 0 ? {} : { gravityFactor: p }
|
|
481
446
|
};
|
|
482
447
|
}
|
|
483
|
-
function
|
|
448
|
+
function We(t) {
|
|
484
449
|
let n = (t) => {
|
|
485
|
-
let n =
|
|
450
|
+
let n = Le.get(t);
|
|
486
451
|
if (n !== void 0) return n;
|
|
487
|
-
if (
|
|
488
|
-
let r =
|
|
489
|
-
return
|
|
452
|
+
if (Re > 15) throw new e(`Exceeded Rapier 16-group limit for collisionSystem "${t}"`);
|
|
453
|
+
let r = Re++;
|
|
454
|
+
return Le.set(t, r), r;
|
|
490
455
|
}, r = (t, r) => {
|
|
491
456
|
if (t === void 0) return 0;
|
|
492
457
|
if (!Array.isArray(t)) throw new e(`collisionFilter.${r} must be an array`);
|
|
@@ -504,7 +469,7 @@ function He(t) {
|
|
|
504
469
|
return (i & 65535) << 16 | a & 65535;
|
|
505
470
|
});
|
|
506
471
|
}
|
|
507
|
-
var
|
|
472
|
+
var Ge = (e) => e === 0 ? [
|
|
508
473
|
1,
|
|
509
474
|
0,
|
|
510
475
|
0
|
|
@@ -517,7 +482,7 @@ var Ue = (e) => e === 0 ? [
|
|
|
517
482
|
0,
|
|
518
483
|
1
|
|
519
484
|
];
|
|
520
|
-
function
|
|
485
|
+
function Ke(t, n, r) {
|
|
521
486
|
return t.map((t, i) => {
|
|
522
487
|
let a = `physicsJoints[${n}].drives[${i}] on "${r}"`;
|
|
523
488
|
if (!t || typeof t != "object" || Array.isArray(t)) throw new e(`${a} must be an object`);
|
|
@@ -539,9 +504,9 @@ function We(t, n, r) {
|
|
|
539
504
|
};
|
|
540
505
|
});
|
|
541
506
|
}
|
|
542
|
-
function
|
|
507
|
+
function qe(t, n, r, i, a, o, s, c = i.name) {
|
|
543
508
|
let l = t[n];
|
|
544
|
-
if (!
|
|
509
|
+
if (!ze(l)) throw new e(`physicsJoints[${n}] out of bounds for "${r}"`);
|
|
545
510
|
if (l.limits !== void 0 && !Array.isArray(l.limits)) throw new e(`physicsJoints[${n}].limits on "${r}" must be an array`);
|
|
546
511
|
if (l.drives !== void 0 && !Array.isArray(l.drives)) throw new e(`physicsJoints[${n}].drives on "${r}" must be an array`);
|
|
547
512
|
let u = l.limits ?? [], d = l.drives ?? [], f = [
|
|
@@ -577,7 +542,7 @@ function Ge(t, n, r, i, a, o, s, c = i.name) {
|
|
|
577
542
|
});
|
|
578
543
|
};
|
|
579
544
|
for (let t of u) {
|
|
580
|
-
if (!
|
|
545
|
+
if (!ze(t)) throw new e(`physicsJoints[${n}].limits entry on "${r}" must be an object`);
|
|
581
546
|
g(t.linearAxes, t, f, m), g(t.angularAxes, t, p, h);
|
|
582
547
|
}
|
|
583
548
|
let _ = [
|
|
@@ -595,15 +560,15 @@ function Ge(t, n, r, i, a, o, s, c = i.name) {
|
|
|
595
560
|
], x = null, S;
|
|
596
561
|
if (_.length === 0 && v.length === 0) y = "fixed";
|
|
597
562
|
else if (_.length === 0 && v.length === 1) {
|
|
598
|
-
y = "revolute", b =
|
|
563
|
+
y = "revolute", b = Ge(v[0]);
|
|
599
564
|
let e = p[v[0]];
|
|
600
565
|
x = Array.isArray(e) ? e : null, S = h[v[0]];
|
|
601
566
|
} else if (v.length === 0 && _.length === 1) {
|
|
602
|
-
y = "prismatic", b =
|
|
567
|
+
y = "prismatic", b = Ge(_[0]);
|
|
603
568
|
let e = f[_[0]];
|
|
604
569
|
x = Array.isArray(e) ? e : null, S = m[_[0]];
|
|
605
570
|
} else throw new e(`physicsJoints[${n}] unsupported DOF (${_.length} lin, ${v.length} ang) on "${r}"`);
|
|
606
|
-
let C =
|
|
571
|
+
let C = Ke(d, n, r), w = a.getWorldPosition(new F.Vector3()).sub(i.getWorldPosition(new F.Vector3())).applyQuaternion(i.getWorldQuaternion(new F.Quaternion()).invert());
|
|
607
572
|
return {
|
|
608
573
|
index: n,
|
|
609
574
|
nodeName: r,
|
|
@@ -636,16 +601,16 @@ function X(t, n) {
|
|
|
636
601
|
if (!Array.isArray(t)) throw new e(`${n} must be an array`);
|
|
637
602
|
return t;
|
|
638
603
|
}
|
|
639
|
-
function
|
|
604
|
+
function Je() {
|
|
640
605
|
return (e) => ({
|
|
641
606
|
name: "khr3_headless_texture",
|
|
642
607
|
loadTexture(t) {
|
|
643
|
-
let n = new
|
|
608
|
+
let n = new F.Texture();
|
|
644
609
|
return n.flipY = !1, e.associations.set(n, { textures: t }), Promise.resolve(n);
|
|
645
610
|
}
|
|
646
611
|
});
|
|
647
612
|
}
|
|
648
|
-
function
|
|
613
|
+
function Ye(t, n, r = t.parser?.json) {
|
|
649
614
|
let i = new Int32Array(n.length).fill(-1);
|
|
650
615
|
for (let t = 0; t < n.length; t++) {
|
|
651
616
|
let r = n[t];
|
|
@@ -721,12 +686,12 @@ function qe(t, n, r = t.parser?.json) {
|
|
|
721
686
|
if (e < 0 || e >= n.length || !o.has(e)) return;
|
|
722
687
|
let r = d.get(e);
|
|
723
688
|
if (r) return r;
|
|
724
|
-
let i = l[e], a =
|
|
689
|
+
let i = l[e], a = F.PropertyBinding.sanitizeNodeName(i);
|
|
725
690
|
return f.get(i) ?? f.get(a) ?? t.scene.getObjectByName(i);
|
|
726
691
|
}
|
|
727
692
|
};
|
|
728
693
|
}
|
|
729
|
-
function
|
|
694
|
+
function Xe(t, n, r, i, a) {
|
|
730
695
|
if (!Y(t)) throw new e(`Node "${n}" has invalid collider (expected object)`);
|
|
731
696
|
let o = t.geometry;
|
|
732
697
|
if (!Y(o)) throw new e(`Node "${n}" is missing collider.geometry object`);
|
|
@@ -744,8 +709,8 @@ function Je(t, n, r, i, a) {
|
|
|
744
709
|
throw new e(`Node "${n}" collider.geometry must specify shape or node`);
|
|
745
710
|
}
|
|
746
711
|
// src/khrPlugin.ts
|
|
747
|
-
var
|
|
748
|
-
function
|
|
712
|
+
var Ze = "khrBundle";
|
|
713
|
+
function Qe(t, n) {
|
|
749
714
|
if (!t.scene) throw new e("GLTF asset has no active scene");
|
|
750
715
|
t.scene.updateMatrixWorld(!0), s(t.scene);
|
|
751
716
|
let i = t.parser?.json;
|
|
@@ -755,14 +720,14 @@ function Xe(t, n) {
|
|
|
755
720
|
if (a !== void 0 && !Y(a)) throw new e("KHR_physics_rigid_bodies extension must be an object");
|
|
756
721
|
let o = i.extensions?.KHR_implicit_shapes;
|
|
757
722
|
if (o !== void 0 && !Y(o)) throw new e("KHR_implicit_shapes extension must be an object");
|
|
758
|
-
let c = X(o?.shapes, "KHR_implicit_shapes.shapes").map((e, t) =>
|
|
723
|
+
let c = X(o?.shapes, "KHR_implicit_shapes.shapes").map((e, t) => Ve(e, t)), l = X(a?.physicsMaterials, "KHR_physics_rigid_bodies.physicsMaterials"), d = We(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 } = Ye(t, m, i), y = [], b = {};
|
|
759
724
|
for (let e = 0; e < m.length; e++) {
|
|
760
725
|
let t = v(e);
|
|
761
726
|
if (!t) continue;
|
|
762
727
|
let r = Y(m[e].extras) ? m[e].extras : {};
|
|
763
|
-
y.push(
|
|
728
|
+
y.push(Pe(t, _[e], r, b, n?.isSocketNode));
|
|
764
729
|
}
|
|
765
|
-
let x = [], S = [], C = /* @__PURE__ */ new Map(), w = /* @__PURE__ */ new Set(), T = [],
|
|
730
|
+
let x = [], S = [], C = /* @__PURE__ */ new Map(), w = /* @__PURE__ */ new Set(), T = [], E = [], ee = (e) => {
|
|
766
731
|
for (let t = g[e]; t !== -1; t = g[t]) if (m[t].extensions?.KHR_physics_rigid_bodies?.motion) return t;
|
|
767
732
|
return -1;
|
|
768
733
|
}, D = (e) => {
|
|
@@ -778,7 +743,7 @@ function Xe(t, n) {
|
|
|
778
743
|
let s = Y(i.extras) ? i.extras : {};
|
|
779
744
|
if (s.ecctrlWheel !== void 0 || s.ecctrlPropeller !== void 0) {
|
|
780
745
|
if (g[r] !== -1 && D(g[r])) throw new e(`Nested rotor "${a}" inside detached rotor is unsupported`);
|
|
781
|
-
s.ecctrlWheel === void 0 ?
|
|
746
|
+
s.ecctrlWheel === void 0 ? E.push(Ie(o, a, s.ecctrlPropeller, t.scene)) : T.push(Fe(o, a, s.ecctrlWheel, t.scene));
|
|
782
747
|
continue;
|
|
783
748
|
}
|
|
784
749
|
if (D(r)) continue;
|
|
@@ -786,12 +751,12 @@ function Xe(t, n) {
|
|
|
786
751
|
if (c === void 0) continue;
|
|
787
752
|
if (!Y(c)) throw new e(`Node "${a}" has invalid KHR_physics_rigid_bodies`);
|
|
788
753
|
if (c.motion === void 0 && c.collider === void 0 && c.joint === void 0) continue;
|
|
789
|
-
if (c.motion === void 0 &&
|
|
754
|
+
if (c.motion === void 0 && ee(r) !== -1) {
|
|
790
755
|
if (c.joint !== void 0) throw new e(`Node "${a}" has joint without motion`);
|
|
791
756
|
continue;
|
|
792
757
|
}
|
|
793
758
|
if (c.motion !== void 0 && !Y(c.motion)) throw new e(`Node "${a}" has invalid motion`);
|
|
794
|
-
let { hasExplicitInertia: l, ...u } =
|
|
759
|
+
let { hasExplicitInertia: l, ...u } = Ue(c.motion ?? {}, c.motion !== void 0, a);
|
|
795
760
|
l && w.add(r);
|
|
796
761
|
let d = n?.extractRole?.(a, s) ?? (typeof s.role == "string" ? s.role : null), f = null;
|
|
797
762
|
if (c.joint !== void 0) {
|
|
@@ -803,9 +768,9 @@ function Xe(t, n) {
|
|
|
803
768
|
let n = t.connectedNode, r = _[n] ?? `node_${n}`, i = v(n);
|
|
804
769
|
if (!i) throw new e(`Joint on "${a}" targets missing connectedNode "${r}"`);
|
|
805
770
|
if (D(n)) throw new e(`Joint on "${a}" cannot target detached rotor "${r}"`);
|
|
806
|
-
f =
|
|
771
|
+
f = qe(p, t.joint, a, i, o, !!t.enableCollision, d, r);
|
|
807
772
|
}
|
|
808
|
-
let h = o.getWorldPosition(new
|
|
773
|
+
let h = o.getWorldPosition(new F.Vector3()), y = o.getWorldQuaternion(new F.Quaternion()), b = {
|
|
809
774
|
nodeName: a,
|
|
810
775
|
...u,
|
|
811
776
|
localPosition: [
|
|
@@ -835,9 +800,9 @@ function Xe(t, n) {
|
|
|
835
800
|
if (n === void 0) continue;
|
|
836
801
|
let r = v(t);
|
|
837
802
|
if (!r) continue;
|
|
838
|
-
let i = C.has(t) ? t :
|
|
803
|
+
let i = C.has(t) ? t : ee(t), a = C.get(i);
|
|
839
804
|
if (!a) continue;
|
|
840
|
-
let o =
|
|
805
|
+
let o = Xe(n, _[t], c, _, v), s = n, f = i === t ? {
|
|
841
806
|
localPosition: [
|
|
842
807
|
0,
|
|
843
808
|
0,
|
|
@@ -849,7 +814,7 @@ function Xe(t, n) {
|
|
|
849
814
|
0,
|
|
850
815
|
1
|
|
851
816
|
]
|
|
852
|
-
} : u(a.object, r), p =
|
|
817
|
+
} : u(a.object, r), p = He(l, s.physicsMaterial, _[t]), h;
|
|
853
818
|
if (s.collisionFilter !== void 0) {
|
|
854
819
|
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)}`);
|
|
855
820
|
h = d[s.collisionFilter];
|
|
@@ -863,61 +828,61 @@ function Xe(t, n) {
|
|
|
863
828
|
});
|
|
864
829
|
}
|
|
865
830
|
for (let [e, t] of C) w.has(e) || t.isKinematic || (t.inertiaDiagonal = f(t.colliders, t.mass, t.centerOfMass, t.inertiaOrientation, t.nodeName));
|
|
866
|
-
let { totalDynamicMass: O, centerOfMass:
|
|
867
|
-
if (
|
|
868
|
-
if (!Y(
|
|
869
|
-
for (let [e, t] of Object.entries(
|
|
831
|
+
let { totalDynamicMass: O, centerOfMass: k } = h(x), A = [], j = i.scenes?.[i.scene ?? 0]?.extras ?? i.extras;
|
|
832
|
+
if (j?.ikSockets !== void 0) {
|
|
833
|
+
if (!Y(j.ikSockets)) throw new e("scene.extras.ikSockets must be an object");
|
|
834
|
+
for (let [e, t] of Object.entries(j.ikSockets)) {
|
|
870
835
|
let n = r(t, `scene.extras.ikSockets.${e}`);
|
|
871
|
-
b[e] = n,
|
|
836
|
+
b[e] = n, A.push([e, n]);
|
|
872
837
|
}
|
|
873
838
|
}
|
|
874
|
-
let
|
|
875
|
-
return
|
|
839
|
+
let M = Y(j?.tune) ? j.tune : void 0, N = Y(j?.droneTune) ? j.droneTune : void 0;
|
|
840
|
+
return De(t.scene, {
|
|
876
841
|
nodes: y,
|
|
877
842
|
bodies: S,
|
|
878
|
-
ikSockets:
|
|
843
|
+
ikSockets: A
|
|
879
844
|
}), {
|
|
880
845
|
scene: t.scene,
|
|
881
846
|
bodies: x,
|
|
882
847
|
wheels: T,
|
|
883
|
-
propellers:
|
|
848
|
+
propellers: E,
|
|
884
849
|
sockets: b,
|
|
885
850
|
totalDynamicMass: O,
|
|
886
|
-
centerOfMass:
|
|
887
|
-
tune:
|
|
888
|
-
droneTune:
|
|
851
|
+
centerOfMass: k,
|
|
852
|
+
tune: M,
|
|
853
|
+
droneTune: N
|
|
889
854
|
};
|
|
890
855
|
}
|
|
891
|
-
function
|
|
856
|
+
function $e(e) {
|
|
892
857
|
let t = typeof document > "u" && typeof createImageBitmap > "u";
|
|
893
858
|
return (n) => ({
|
|
894
859
|
name: "KHR_physics_rigid_bodies",
|
|
895
860
|
...t ? { loadTexture(e) {
|
|
896
|
-
let t = new
|
|
861
|
+
let t = new F.Texture();
|
|
897
862
|
return t.flipY = !1, n.associations.set(t, { textures: e }), Promise.resolve(t);
|
|
898
863
|
} } : {},
|
|
899
864
|
afterRoot(t) {
|
|
900
|
-
return t.userData[
|
|
865
|
+
return t.userData[Ze] = Qe(t, e), null;
|
|
901
866
|
}
|
|
902
867
|
});
|
|
903
868
|
}
|
|
904
869
|
// src/khrLoader.ts
|
|
905
|
-
var
|
|
906
|
-
function
|
|
907
|
-
let e = new
|
|
908
|
-
return typeof document > "u" && typeof createImageBitmap > "u" && e.register(
|
|
870
|
+
var et = Je();
|
|
871
|
+
function tt() {
|
|
872
|
+
let e = new R();
|
|
873
|
+
return typeof document > "u" && typeof createImageBitmap > "u" && e.register(et), e;
|
|
909
874
|
}
|
|
910
|
-
async function
|
|
875
|
+
async function nt(t, n) {
|
|
911
876
|
let r = t instanceof Uint8Array ? t : new Uint8Array(t), i = new ArrayBuffer(r.byteLength);
|
|
912
|
-
new Uint8Array(i).set(r),
|
|
913
|
-
let a = n?.loader ??
|
|
877
|
+
new Uint8Array(i).set(r), Se(i);
|
|
878
|
+
let a = n?.loader ?? tt(), o = $e(n);
|
|
914
879
|
a.register(o);
|
|
915
880
|
try {
|
|
916
881
|
let t = (t) => t instanceof e ? t : new e(t instanceof Error ? t.message : "Failed to parse GLB"), n = (await new Promise((e, n) => {
|
|
917
882
|
a.parse(i, "", e, (e) => n(t(e)));
|
|
918
883
|
}).catch((e) => {
|
|
919
884
|
throw t(e);
|
|
920
|
-
})).userData[
|
|
885
|
+
})).userData[Ze];
|
|
921
886
|
if (!n) throw new e("Missing parsed KHR bundle on GLTF userData");
|
|
922
887
|
return n;
|
|
923
888
|
} finally {
|
|
@@ -932,7 +897,7 @@ function Q(t, n, r = !1) {
|
|
|
932
897
|
return t;
|
|
933
898
|
}
|
|
934
899
|
}
|
|
935
|
-
function
|
|
900
|
+
function rt(t, n) {
|
|
936
901
|
if (t.type === "box") {
|
|
937
902
|
if (!Array.isArray(t.size) || t.size.length !== 3 || !t.size.every(Z)) throw new e(`exportKhrGlb: invalid box.size on "${n}"`);
|
|
938
903
|
return {
|
|
@@ -958,13 +923,13 @@ function tt(t, n) {
|
|
|
958
923
|
}
|
|
959
924
|
};
|
|
960
925
|
}
|
|
961
|
-
function
|
|
926
|
+
function it(t, n, r) {
|
|
962
927
|
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`);
|
|
963
928
|
let i = Math.abs(t[0]), a = Math.abs(t[1]), o = Math.abs(t[2]);
|
|
964
929
|
if (Math.hypot(i, a, o) <= 1e-8) throw new e(`exportKhrGlb: ${n} joint on "${r}" requires non-zero axis`);
|
|
965
930
|
return i >= a && i >= o ? 0 : a >= o ? 1 : 2;
|
|
966
931
|
}
|
|
967
|
-
function
|
|
932
|
+
function at(t, n, r, i) {
|
|
968
933
|
if (!t || typeof t != "object" || Array.isArray(t)) throw new e(`exportKhrGlb: joint drive on "${i}" must be an object`);
|
|
969
934
|
if (t.mode !== "force" && t.mode !== "acceleration") throw new e(`exportKhrGlb: joint drive on "${i}" requires drive.mode ("force" | "acceleration")`);
|
|
970
935
|
if (t.type !== void 0 && t.type !== "linear" && t.type !== "angular") throw new e(`exportKhrGlb: joint drive on "${i}" has invalid drive.type`);
|
|
@@ -983,7 +948,7 @@ function rt(t, n, r, i) {
|
|
|
983
948
|
...l === void 0 ? {} : { maxForce: l }
|
|
984
949
|
};
|
|
985
950
|
}
|
|
986
|
-
function
|
|
951
|
+
function ot(t, n) {
|
|
987
952
|
if (t.kind !== "fixed" && t.kind !== "revolute" && t.kind !== "prismatic") throw new e(`exportKhrGlb: invalid joint.kind "${String(t.kind)}" on "${n}"`);
|
|
988
953
|
if (t.kind === "fixed") {
|
|
989
954
|
if (t.drive || t.drives && t.drives.length > 0) throw new e(`exportKhrGlb: fixed joint on "${n}" cannot define drives`);
|
|
@@ -1005,7 +970,7 @@ function it(t, n) {
|
|
|
1005
970
|
max: 0
|
|
1006
971
|
}] };
|
|
1007
972
|
}
|
|
1008
|
-
let r =
|
|
973
|
+
let r = it(t.axis, t.kind, n), i = [
|
|
1009
974
|
0,
|
|
1010
975
|
1,
|
|
1011
976
|
2
|
|
@@ -1052,9 +1017,9 @@ function it(t, n) {
|
|
|
1052
1017
|
},
|
|
1053
1018
|
...c
|
|
1054
1019
|
] }, u = t.drives ?? (t.drive ? [t.drive] : []);
|
|
1055
|
-
return u.length > 0 && (l.drives = u.map((e) =>
|
|
1020
|
+
return u.length > 0 && (l.drives = u.map((e) => at(e, t.kind === "revolute" ? "angular" : "linear", r, n))), l;
|
|
1056
1021
|
}
|
|
1057
|
-
function
|
|
1022
|
+
function st(t, n) {
|
|
1058
1023
|
let i = !!t.isKinematic;
|
|
1059
1024
|
if (!i && !Z(t.mass)) throw new e(`exportKhrGlb: dynamic node "${n}" requires positive finite motion.mass`);
|
|
1060
1025
|
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}"`);
|
|
@@ -1070,11 +1035,11 @@ function at(t, n) {
|
|
|
1070
1035
|
...t.gravityFactor === void 0 ? {} : { gravityFactor: t.gravityFactor }
|
|
1071
1036
|
};
|
|
1072
1037
|
}
|
|
1073
|
-
async function
|
|
1074
|
-
|
|
1075
|
-
let i = new
|
|
1076
|
-
return
|
|
1077
|
-
i.parse(t, (t) => e(t instanceof ArrayBuffer ? t :
|
|
1038
|
+
async function ct(t, n, r) {
|
|
1039
|
+
Ce(), t.updateMatrixWorld(!0);
|
|
1040
|
+
let i = new ne();
|
|
1041
|
+
return Te(await new Promise((e, n) => {
|
|
1042
|
+
i.parse(t, (t) => e(t instanceof ArrayBuffer ? t : we(t)), n, { binary: !0 });
|
|
1078
1043
|
}), (t) => {
|
|
1079
1044
|
let i = t.nodes ?? [], a = /* @__PURE__ */ new Map();
|
|
1080
1045
|
i.forEach((e, t) => {
|
|
@@ -1092,11 +1057,11 @@ async function ot(t, n, r) {
|
|
|
1092
1057
|
...t.extras
|
|
1093
1058
|
});
|
|
1094
1059
|
let r = {};
|
|
1095
|
-
if (t.motion && (f = !0, r.motion =
|
|
1060
|
+
if (t.motion && (f = !0, r.motion = st(t.motion, t.nodeName)), t.collider) {
|
|
1096
1061
|
f = !0;
|
|
1097
1062
|
let n = {};
|
|
1098
1063
|
if (t.collider.shape) {
|
|
1099
|
-
let e =
|
|
1064
|
+
let e = rt(t.collider.shape, t.nodeName), r = JSON.stringify(e), i = c.get(r);
|
|
1100
1065
|
i === void 0 && (i = s.length, s.push(e), c.set(r, i)), n.geometry = { shape: i };
|
|
1101
1066
|
} else if (t.collider.meshNodeName) {
|
|
1102
1067
|
if (typeof t.collider.convexHull != "boolean") throw new e(`exportKhrGlb: mesh collider on "${t.nodeName}" requires explicit boolean convexHull`);
|
|
@@ -1126,7 +1091,7 @@ async function ot(t, n, r) {
|
|
|
1126
1091
|
if (t.joint) {
|
|
1127
1092
|
f = !0;
|
|
1128
1093
|
let e = o(t.joint.connectedNodeName);
|
|
1129
|
-
d.push(
|
|
1094
|
+
d.push(ot(t.joint, t.nodeName)), r.joint = {
|
|
1130
1095
|
joint: d.length - 1,
|
|
1131
1096
|
connectedNode: e,
|
|
1132
1097
|
enableCollision: !!t.joint.enableCollision
|
|
@@ -1156,15 +1121,15 @@ async function ot(t, n, r) {
|
|
|
1156
1121
|
});
|
|
1157
1122
|
}
|
|
1158
1123
|
// src/assemblyPlan.ts
|
|
1159
|
-
function
|
|
1160
|
-
let r = new
|
|
1124
|
+
function lt(t, n) {
|
|
1125
|
+
let r = new F.Matrix4();
|
|
1161
1126
|
for (let i = t; i && i !== n; i = i.parent) {
|
|
1162
1127
|
if (!i.parent) throw new e(`Node "${t.name}" is detached from bundle.scene`);
|
|
1163
1128
|
i.updateMatrix(), r.premultiply(i.matrix);
|
|
1164
1129
|
}
|
|
1165
1130
|
return r;
|
|
1166
1131
|
}
|
|
1167
|
-
function
|
|
1132
|
+
function ut(e, t) {
|
|
1168
1133
|
let n = (e) => {
|
|
1169
1134
|
let n = [];
|
|
1170
1135
|
for (let r = e; r && (n.push(r), r !== t); r = r.parent);
|
|
@@ -1177,8 +1142,8 @@ function ct(e, t) {
|
|
|
1177
1142
|
for (let t of n(e[0])) if (r.has(t)) return t;
|
|
1178
1143
|
return t;
|
|
1179
1144
|
}
|
|
1180
|
-
function
|
|
1181
|
-
let r = new
|
|
1145
|
+
function dt(e, t, n) {
|
|
1146
|
+
let r = new F.Vector3().fromArray(e.com), i = new F.Quaternion().fromArray(e.inertiaFrame);
|
|
1182
1147
|
return t && n && (r.applyMatrix4(t.clone().invert()), i.premultiply(n.clone().invert()).normalize()), {
|
|
1183
1148
|
mass: e.mass,
|
|
1184
1149
|
centerOfMass: {
|
|
@@ -1199,10 +1164,10 @@ function lt(e, t, n) {
|
|
|
1199
1164
|
}
|
|
1200
1165
|
};
|
|
1201
1166
|
}
|
|
1202
|
-
function
|
|
1167
|
+
function ft(e, t, n) {
|
|
1203
1168
|
return e.colliders.map((e, r) => {
|
|
1204
|
-
let i = new
|
|
1205
|
-
new
|
|
1169
|
+
let i = new F.Quaternion().fromArray(e.localQuaternion), a = new F.Matrix4().compose(new F.Vector3().fromArray(e.localPosition), i, new F.Vector3(1, 1, 1)), o = new F.Vector3(), s = new F.Quaternion(), c = new F.Vector3();
|
|
1170
|
+
new F.Matrix4().multiplyMatrices(t, a).decompose(o, s, c);
|
|
1206
1171
|
let l = {
|
|
1207
1172
|
spec: e,
|
|
1208
1173
|
local: a,
|
|
@@ -1218,14 +1183,14 @@ function ut(e, t, n) {
|
|
|
1218
1183
|
s.w
|
|
1219
1184
|
]
|
|
1220
1185
|
};
|
|
1221
|
-
return r === 0 && n && (l.massProperties =
|
|
1186
|
+
return r === 0 && n && (l.massProperties = dt(n, a, i)), l;
|
|
1222
1187
|
});
|
|
1223
1188
|
}
|
|
1224
|
-
function
|
|
1189
|
+
function pt(e, t, n) {
|
|
1225
1190
|
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;
|
|
1226
1191
|
return !1;
|
|
1227
1192
|
}
|
|
1228
|
-
function
|
|
1193
|
+
function mt(t) {
|
|
1229
1194
|
let r = new Map(t.bodies.map((e) => [e.nodeName, e])), i = (t, n = /* @__PURE__ */ new Set()) => {
|
|
1230
1195
|
if (!t.joint) return t;
|
|
1231
1196
|
if (n.has(t.nodeName)) throw new e(`Joint cycle through "${t.nodeName}"`);
|
|
@@ -1238,19 +1203,19 @@ function ft(t) {
|
|
|
1238
1203
|
s.sort((e, t) => c(e) - c(t));
|
|
1239
1204
|
let l = /* @__PURE__ */ new Map(), u = s.map((t) => {
|
|
1240
1205
|
let n = t.joint, i = l.get(n.connectedNodeName) ?? null;
|
|
1241
|
-
if (i && !
|
|
1206
|
+
if (i && !ht(t.object, i.spec.object)) throw new e(`Jointed node "${t.nodeName}" must be a scene-graph descendant of its jointed parent "${n.connectedNodeName}"`);
|
|
1242
1207
|
let a = o.clone().multiply(x(t)), c = {
|
|
1243
1208
|
spec: t,
|
|
1244
1209
|
joint: n,
|
|
1245
1210
|
parent: i,
|
|
1246
1211
|
restRelParent: i ? x(i.spec).invert().multiply(x(t)) : a,
|
|
1247
|
-
inertia:
|
|
1248
|
-
colliders:
|
|
1212
|
+
inertia: de(t, n, s.filter((e) => e !== t && pt(e, t.nodeName, r))),
|
|
1213
|
+
colliders: ft(t, a, null)
|
|
1249
1214
|
};
|
|
1250
1215
|
return l.set(t.nodeName, c), c;
|
|
1251
|
-
}), d = a.isKinematic ? null : n([a, ...s], o), f =
|
|
1216
|
+
}), d = a.isKinematic ? null : n([a, ...s], o), f = ft(a, new F.Matrix4(), d), p = d && f.length === 0 ? dt(d) : void 0, m = ut([a.object, ...s.map((e) => e.object)], t.scene), h = o.clone().multiply(lt(m, t.scene)), g = new F.Vector3(), _ = new F.Quaternion(), v = new F.Vector3();
|
|
1252
1217
|
o.decompose(g, _, v), _.normalize();
|
|
1253
|
-
let y = new
|
|
1218
|
+
let y = new F.Vector3(), b = new F.Quaternion(), S = new F.Vector3();
|
|
1254
1219
|
return h.decompose(y, b, S), b.normalize(), {
|
|
1255
1220
|
spec: a,
|
|
1256
1221
|
sceneInRootPos: [
|
|
@@ -1282,20 +1247,20 @@ function ft(t) {
|
|
|
1282
1247
|
parts: u
|
|
1283
1248
|
};
|
|
1284
1249
|
});
|
|
1285
|
-
for (let t of a) for (let n of a) if (t !== n &&
|
|
1250
|
+
for (let t of a) for (let n of a) if (t !== n && ht(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`);
|
|
1286
1251
|
return a;
|
|
1287
1252
|
}
|
|
1288
|
-
function
|
|
1253
|
+
function ht(e, t) {
|
|
1289
1254
|
for (let n = e; n; n = n.parent) if (n === t) return !0;
|
|
1290
1255
|
return !1;
|
|
1291
1256
|
}
|
|
1292
1257
|
// src/AssemblyRootBody.tsx
|
|
1293
|
-
function
|
|
1294
|
-
let u = T(C), d =
|
|
1258
|
+
function gt({ plan: e, assemblyId: t, position: n, quaternion: r, fixedRoot: a, rigidBodyProps: o, onBody: s, onJoints: c, children: l }) {
|
|
1259
|
+
let u = T(C), d = k(null), f = O(() => e.parts.map((e) => e.colliders.map(() => ({ current: null }))), [e]), p = e.spec;
|
|
1295
1260
|
E(() => (s(p.nodeName, d), () => s(p.nodeName, null)), [p, s]), E(() => {
|
|
1296
1261
|
let t = d.current, n = e.rootMass;
|
|
1297
1262
|
t && n && (t.setAdditionalMassProperties(n.mass, n.centerOfMass, n.principalAngularInertia, n.angularInertiaLocalFrame, !0), t.recomputeMassPropertiesFromColliders());
|
|
1298
|
-
}, [e.rootMass]),
|
|
1263
|
+
}, [e.rootMass]), D(() => {
|
|
1299
1264
|
let n = /* @__PURE__ */ new Map();
|
|
1300
1265
|
for (let r = 0; r < e.parts.length; r++) {
|
|
1301
1266
|
let i = e.parts[r], a = i.joint.drive, o = {
|
|
@@ -1304,7 +1269,7 @@ function mt({ plan: e, assemblyId: t, position: n, quaternion: r, fixedRoot: a,
|
|
|
1304
1269
|
role: i.joint.role,
|
|
1305
1270
|
kind: i.joint.kind,
|
|
1306
1271
|
object: i.spec.object,
|
|
1307
|
-
axis: new
|
|
1272
|
+
axis: new F.Vector3().fromArray(i.joint.axis).normalize(),
|
|
1308
1273
|
restPosition: i.spec.object.position.clone(),
|
|
1309
1274
|
restQuaternion: i.spec.object.quaternion.clone(),
|
|
1310
1275
|
q: 0,
|
|
@@ -1340,7 +1305,7 @@ function mt({ plan: e, assemblyId: t, position: n, quaternion: r, fixedRoot: a,
|
|
|
1340
1305
|
c
|
|
1341
1306
|
]);
|
|
1342
1307
|
let m = p.isKinematic ? a ? "fixed" : "kinematicPosition" : "dynamic";
|
|
1343
|
-
return /* @__PURE__ */
|
|
1308
|
+
return /* @__PURE__ */ L(te, {
|
|
1344
1309
|
...o,
|
|
1345
1310
|
ref: d,
|
|
1346
1311
|
type: m,
|
|
@@ -1352,13 +1317,13 @@ function mt({ plan: e, assemblyId: t, position: n, quaternion: r, fixedRoot: a,
|
|
|
1352
1317
|
...p.gravityFactor === void 0 ? {} : { gravityScale: p.gravityFactor },
|
|
1353
1318
|
children: [
|
|
1354
1319
|
l,
|
|
1355
|
-
e.colliders.map((e, t) => /* @__PURE__ */
|
|
1320
|
+
e.colliders.map((e, t) => /* @__PURE__ */ I(i, {
|
|
1356
1321
|
c: e.spec,
|
|
1357
1322
|
position: e.position,
|
|
1358
1323
|
quaternion: e.quaternion,
|
|
1359
1324
|
massProperties: e.massProperties
|
|
1360
1325
|
}, `r${t}`)),
|
|
1361
|
-
e.parts.map((e, t) => e.colliders.map((n, r) => /* @__PURE__ */
|
|
1326
|
+
e.parts.map((e, t) => e.colliders.map((n, r) => /* @__PURE__ */ I(i, {
|
|
1362
1327
|
ref: f[t][r],
|
|
1363
1328
|
c: n.spec,
|
|
1364
1329
|
position: n.position,
|
|
@@ -1369,32 +1334,32 @@ function mt({ plan: e, assemblyId: t, position: n, quaternion: r, fixedRoot: a,
|
|
|
1369
1334
|
});
|
|
1370
1335
|
}
|
|
1371
1336
|
// src/KhrAssembly.tsx
|
|
1372
|
-
var
|
|
1373
|
-
function
|
|
1337
|
+
var _t = 0;
|
|
1338
|
+
function vt({ ref: t, bundle: n, position: r = [
|
|
1374
1339
|
0,
|
|
1375
1340
|
0,
|
|
1376
1341
|
0
|
|
1377
1342
|
], rotation: i, quaternion: a, scale: o, fixedRoot: l = !1, rigidBodyProps: u, children: d, ...f }) {
|
|
1378
1343
|
c(o, "KhrAssembly"), n.scene.updateMatrixWorld(!0), s(n.scene);
|
|
1379
|
-
let m =
|
|
1344
|
+
let m = O(() => _t++, []), h = O(() => mt(n), [n]), _ = O(() => h.length > 1 ? g(h.map((e) => e.mountNode)) : null, [h]), [y, b, x] = r, [S, C, T] = i ?? [
|
|
1380
1345
|
0,
|
|
1381
1346
|
0,
|
|
1382
1347
|
0
|
|
1383
|
-
], [E,
|
|
1348
|
+
], [E, D, A, j] = a ?? [
|
|
1384
1349
|
NaN,
|
|
1385
1350
|
NaN,
|
|
1386
1351
|
NaN,
|
|
1387
1352
|
NaN
|
|
1388
|
-
],
|
|
1353
|
+
], M = O(() => a ? new F.Quaternion(E, D, A, j) : new F.Quaternion().setFromEuler(new F.Euler(S, C, T)), [
|
|
1389
1354
|
E,
|
|
1390
|
-
|
|
1391
|
-
k,
|
|
1355
|
+
D,
|
|
1392
1356
|
A,
|
|
1357
|
+
j,
|
|
1393
1358
|
S,
|
|
1394
1359
|
C,
|
|
1395
1360
|
T
|
|
1396
|
-
]),
|
|
1397
|
-
let t = new
|
|
1361
|
+
]), N = O(() => h.map((e) => {
|
|
1362
|
+
let t = new F.Vector3().fromArray(e.spec.localPosition).applyQuaternion(M).add(new F.Vector3(y, b, x)), n = M.clone().multiply(new F.Quaternion().fromArray(e.spec.localQuaternion));
|
|
1398
1363
|
return {
|
|
1399
1364
|
position: [
|
|
1400
1365
|
t.x,
|
|
@@ -1410,59 +1375,59 @@ function gt({ ref: t, bundle: n, position: r = [
|
|
|
1410
1375
|
};
|
|
1411
1376
|
}), [
|
|
1412
1377
|
h,
|
|
1413
|
-
|
|
1378
|
+
M,
|
|
1414
1379
|
y,
|
|
1415
1380
|
b,
|
|
1416
1381
|
x
|
|
1417
|
-
]),
|
|
1382
|
+
]), te = k(/* @__PURE__ */ new Map()), P = k(/* @__PURE__ */ new Map()), R = O(() => {
|
|
1418
1383
|
let e = /* @__PURE__ */ new Map();
|
|
1419
1384
|
for (let t of h) {
|
|
1420
1385
|
e.set(t.spec.nodeName, t.spec.nodeName);
|
|
1421
1386
|
for (let n of t.parts) e.set(n.spec.nodeName, t.spec.nodeName);
|
|
1422
1387
|
}
|
|
1423
1388
|
return e;
|
|
1424
|
-
}, [h]),
|
|
1425
|
-
t ?
|
|
1426
|
-
}, []),
|
|
1427
|
-
t ?
|
|
1389
|
+
}, [h]), ne = w((e, t) => {
|
|
1390
|
+
t ? te.current.set(e, t) : te.current.delete(e);
|
|
1391
|
+
}, []), z = w((e, t) => {
|
|
1392
|
+
t ? P.current.set(e, t) : P.current.delete(e);
|
|
1428
1393
|
}, []);
|
|
1429
1394
|
if (ee(t, () => {
|
|
1430
1395
|
let t = (t, n) => {
|
|
1431
1396
|
if (!t.drive || t.drive.stiffness === void 0) throw new e(`Joint "${t.nodeName}" has no authored drive stiffness; cannot set a position target`);
|
|
1432
1397
|
t.positionTarget = n;
|
|
1433
|
-
let r =
|
|
1398
|
+
let r = te.current.get(R.get(t.nodeName))?.current;
|
|
1434
1399
|
r && r.isDynamic() && r.wakeUp();
|
|
1435
1400
|
};
|
|
1436
1401
|
return {
|
|
1437
1402
|
getBody: (e) => {
|
|
1438
1403
|
let t = R.get(e);
|
|
1439
|
-
return t ?
|
|
1404
|
+
return t ? te.current.get(t)?.current ?? null : null;
|
|
1440
1405
|
},
|
|
1441
1406
|
setJointTarget: (e, n) => {
|
|
1442
|
-
let r =
|
|
1407
|
+
let r = P.current.get(R.get(e) ?? "")?.get(e);
|
|
1443
1408
|
r && t(r, n);
|
|
1444
1409
|
},
|
|
1445
1410
|
setRoleTarget: (e, n) => {
|
|
1446
|
-
for (let r of
|
|
1411
|
+
for (let r of P.current.values()) for (let i of r.values()) i.role === e && t(i, n);
|
|
1447
1412
|
}
|
|
1448
1413
|
};
|
|
1449
1414
|
}, [R]), h.length === 1) {
|
|
1450
1415
|
let e = h[0];
|
|
1451
|
-
return /* @__PURE__ */
|
|
1416
|
+
return /* @__PURE__ */ I("group", {
|
|
1452
1417
|
...f,
|
|
1453
|
-
children: /* @__PURE__ */
|
|
1418
|
+
children: /* @__PURE__ */ I(gt, {
|
|
1454
1419
|
plan: e,
|
|
1455
1420
|
assemblyId: m,
|
|
1456
|
-
position:
|
|
1457
|
-
quaternion:
|
|
1421
|
+
position: N[0].position,
|
|
1422
|
+
quaternion: N[0].quaternion,
|
|
1458
1423
|
fixedRoot: l,
|
|
1459
1424
|
rigidBodyProps: u,
|
|
1460
|
-
onBody:
|
|
1461
|
-
onJoints:
|
|
1462
|
-
children: /* @__PURE__ */
|
|
1425
|
+
onBody: ne,
|
|
1426
|
+
onJoints: z,
|
|
1427
|
+
children: /* @__PURE__ */ L("group", {
|
|
1463
1428
|
position: e.sceneInRootPos,
|
|
1464
1429
|
quaternion: e.sceneInRootQuat,
|
|
1465
|
-
children: [/* @__PURE__ */
|
|
1430
|
+
children: [/* @__PURE__ */ I(v, {
|
|
1466
1431
|
bundle: n,
|
|
1467
1432
|
owner: "KhrAssembly"
|
|
1468
1433
|
}), d]
|
|
@@ -1470,25 +1435,25 @@ function gt({ ref: t, bundle: n, position: r = [
|
|
|
1470
1435
|
}, `${n.scene.uuid}:${e.spec.nodeName}`)
|
|
1471
1436
|
});
|
|
1472
1437
|
}
|
|
1473
|
-
return /* @__PURE__ */
|
|
1438
|
+
return /* @__PURE__ */ L("group", {
|
|
1474
1439
|
...f,
|
|
1475
|
-
children: [/* @__PURE__ */
|
|
1440
|
+
children: [/* @__PURE__ */ L("group", {
|
|
1476
1441
|
position: r,
|
|
1477
|
-
quaternion:
|
|
1478
|
-
children: [/* @__PURE__ */
|
|
1442
|
+
quaternion: M,
|
|
1443
|
+
children: [/* @__PURE__ */ I(v, {
|
|
1479
1444
|
bundle: n,
|
|
1480
1445
|
owner: "KhrAssembly"
|
|
1481
1446
|
}), d]
|
|
1482
|
-
}), h.map((e, t) => /* @__PURE__ */
|
|
1447
|
+
}), h.map((e, t) => /* @__PURE__ */ I(gt, {
|
|
1483
1448
|
plan: e,
|
|
1484
1449
|
assemblyId: m,
|
|
1485
|
-
position:
|
|
1486
|
-
quaternion:
|
|
1450
|
+
position: N[t].position,
|
|
1451
|
+
quaternion: N[t].quaternion,
|
|
1487
1452
|
fixedRoot: l,
|
|
1488
1453
|
rigidBodyProps: u,
|
|
1489
|
-
onBody:
|
|
1490
|
-
onJoints:
|
|
1491
|
-
children: /* @__PURE__ */
|
|
1454
|
+
onBody: ne,
|
|
1455
|
+
onJoints: z,
|
|
1456
|
+
children: /* @__PURE__ */ I(p, {
|
|
1492
1457
|
object: e.mountNode,
|
|
1493
1458
|
position: e.mountPosition,
|
|
1494
1459
|
quaternion: e.mountQuaternion,
|
|
@@ -1498,28 +1463,28 @@ function gt({ ref: t, bundle: n, position: r = [
|
|
|
1498
1463
|
});
|
|
1499
1464
|
}
|
|
1500
1465
|
// src/useKhrGlb.ts
|
|
1501
|
-
var
|
|
1466
|
+
var yt = class extends R {
|
|
1502
1467
|
static khrLoaderScope = Symbol("KhrGLTFLoader");
|
|
1503
|
-
},
|
|
1504
|
-
function
|
|
1505
|
-
|
|
1468
|
+
}, bt = Je(), xt = $e(), St = /* @__PURE__ */ new WeakSet(), Ct = /* @__PURE__ */ new WeakSet(), $ = /* @__PURE__ */ new Map();
|
|
1469
|
+
function wt(e) {
|
|
1470
|
+
St.has(e) || (St.add(e), typeof document > "u" && typeof createImageBitmap > "u" && e.register(bt), e.register(xt));
|
|
1506
1471
|
}
|
|
1507
|
-
function
|
|
1472
|
+
function Tt(e) {
|
|
1508
1473
|
return !!(e?.extendLoader || e?.cacheKey !== void 0);
|
|
1509
1474
|
}
|
|
1510
|
-
function
|
|
1475
|
+
function Et(e) {
|
|
1511
1476
|
return e.cacheKey === void 0 ? `src:${Function.prototype.toString.call(e.extendLoader)}` : `key:${e.cacheKey}`;
|
|
1512
1477
|
}
|
|
1513
|
-
function
|
|
1514
|
-
let n =
|
|
1478
|
+
function Dt(e, t) {
|
|
1479
|
+
let n = Et(t), r = $.get(e);
|
|
1515
1480
|
r || (r = /* @__PURE__ */ new Map(), $.set(e, r));
|
|
1516
1481
|
let i = r.get(n);
|
|
1517
1482
|
if (!i) {
|
|
1518
|
-
let a = new
|
|
1483
|
+
let a = new R(), o = t.extendLoader, s = {
|
|
1519
1484
|
loader: a,
|
|
1520
1485
|
registerExtensions: (t) => {
|
|
1521
|
-
if (
|
|
1522
|
-
o(t),
|
|
1486
|
+
if (wt(t), o && !Ct.has(t)) try {
|
|
1487
|
+
o(t), Ct.add(t);
|
|
1523
1488
|
} catch (t) {
|
|
1524
1489
|
let r = $.get(e);
|
|
1525
1490
|
throw r?.get(n) === s && (r.delete(n), r.size === 0 && $.delete(e)), t;
|
|
@@ -1530,33 +1495,33 @@ function Tt(e, t) {
|
|
|
1530
1495
|
}
|
|
1531
1496
|
return i;
|
|
1532
1497
|
}
|
|
1533
|
-
function
|
|
1534
|
-
let r = n?.extractRole, i = n?.isSocketNode, a =
|
|
1535
|
-
if (!c) throw new e(`useKhrGlb: missing "${
|
|
1536
|
-
return
|
|
1498
|
+
function Ot(t, n) {
|
|
1499
|
+
let r = n?.extractRole, i = n?.isSocketNode, a = Tt(n) ? Dt(t, n) : null, o = a ? a.loader : yt, s = a ? a.registerExtensions : wt, c = M(o, t, s).userData[Ze];
|
|
1500
|
+
if (!c) throw new e(`useKhrGlb: missing "${Ze}" on loaded GLTF for "${t}"`);
|
|
1501
|
+
return O(() => {
|
|
1537
1502
|
let e = _(c);
|
|
1538
|
-
return (r || i) &&
|
|
1503
|
+
return (r || i) && Oe(e, c, r, i), e;
|
|
1539
1504
|
}, [
|
|
1540
1505
|
c,
|
|
1541
1506
|
r,
|
|
1542
1507
|
i
|
|
1543
1508
|
]);
|
|
1544
1509
|
}
|
|
1545
|
-
|
|
1546
|
-
let n =
|
|
1547
|
-
|
|
1548
|
-
},
|
|
1549
|
-
if (
|
|
1510
|
+
Ot.preload = (e, t) => {
|
|
1511
|
+
let n = Tt(t) ? Dt(e, t) : null, r = n ? n.loader : yt, i = n ? n.registerExtensions : wt;
|
|
1512
|
+
M.preload(r, e, i);
|
|
1513
|
+
}, Ot.clear = (e, t) => {
|
|
1514
|
+
if (Tt(t)) {
|
|
1550
1515
|
let n = $.get(e);
|
|
1551
1516
|
if (!n) return;
|
|
1552
|
-
let r =
|
|
1553
|
-
i && (
|
|
1554
|
-
} else if (
|
|
1517
|
+
let r = Et(t), i = n.get(r);
|
|
1518
|
+
i && (M.clear(i.loader, e), n.delete(r), n.size === 0 && $.delete(e));
|
|
1519
|
+
} else if (M.clear(yt, e), t === void 0) {
|
|
1555
1520
|
let t = $.get(e);
|
|
1556
1521
|
if (t) {
|
|
1557
|
-
for (let n of t.values())
|
|
1522
|
+
for (let n of t.values()) M.clear(n.loader, e);
|
|
1558
1523
|
$.delete(e);
|
|
1559
1524
|
}
|
|
1560
1525
|
}
|
|
1561
1526
|
};
|
|
1562
|
-
export { C as JointRegistryContext,
|
|
1527
|
+
export { C as JointRegistryContext, vt 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, $e as createKhrGltfPlugin, o as disposeKhrBundle, ct as exportKhrGlb, nt as loadKhrGlb, Te as patchGlbJsonChunk, d as releaseBundleMount, Ot as useKhrGlb };
|