@khr3/core 0.1.1 → 0.1.3

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/index.js CHANGED
@@ -1,70 +1,127 @@
1
- import { _ as e, a as t, b as n, c as r, d as i, f as a, g as o, h as s, l as c, m as l, n as u, o as d, p as f, r as p, s as m, t as h, u as g, v as _, x as v, y } from "./BundleSceneHost-BXLH_LrO.js";
2
- import { useCallback as b, useContext as x, useImperativeHandle as S, useLayoutEffect as C, useMemo as w, useRef as T } from "react";
3
- import { useFrame as E, useLoader as D } from "@react-three/fiber";
4
- import { Physics as O, RigidBody as k, useRapier as A } from "@react-three/rapier";
5
- import * as j from "three";
6
- import { jsx as M, jsxs as N } from "react/jsx-runtime";
7
- import { GLTFLoader as P } from "three/examples/jsm/loaders/GLTFLoader.js";
8
- import { GLTFExporter as F } from "three/examples/jsm/exporters/GLTFExporter.js";
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 E, useMemo as D, useRef as O } from "react";
3
+ import { useFrame as te, useLoader as k } from "@react-three/fiber";
4
+ import { Physics as A, RigidBody as j, useRapier as M } from "@react-three/rapier";
5
+ import * as N from "three";
6
+ import { jsx as P, jsxs as F } from "react/jsx-runtime";
7
+ import { GLTFLoader as I } from "three/examples/jsm/loaders/GLTFLoader.js";
8
+ import { GLTFExporter as L } from "three/examples/jsm/exporters/GLTFExporter.js";
9
9
  // src/jointDynamics.ts
10
- var I = new j.Vector3(), L = new j.Vector3(), R = new j.Quaternion(), z = new j.Matrix4(), B = new j.Matrix4(), ee = new j.Vector3(), te = new j.Quaternion(), ne = new j.Vector3();
11
- function re(e, t) {
10
+ var R = new N.Vector3(), z = new N.Vector3(), B = new N.Vector3(), ne = new N.Quaternion(), re = new N.Quaternion(), ie = new N.Matrix4(), ae = new N.Matrix4(), oe = new N.Matrix4(), se = new N.Matrix4(), V = new N.Vector3(), H = new N.Quaternion(), ce = new N.Vector3();
11
+ function le(e, t, n = []) {
12
12
  if (t.kind === "fixed") return 0;
13
- if (t.kind === "prismatic") return e.mass;
14
- I.fromArray(t.axis).normalize(), R.fromArray(e.inertiaOrientation).invert();
15
- let n = I.clone().applyQuaternion(R), [r, i, a] = e.inertiaDiagonal, o = r * n.x * n.x + i * n.y * n.y + a * n.z * n.z;
16
- L.fromArray(e.centerOfMass);
17
- let s = L.dot(I);
18
- return o + e.mass * (L.lengthSq() - s * s);
13
+ let r = n.length > 0 ? [e, ...n] : [e];
14
+ if (t.kind === "prismatic") {
15
+ let t = 0;
16
+ for (let n of r) n.isKinematic && n !== e || (t += n.mass);
17
+ return t;
18
+ }
19
+ R.fromArray(t.axis).normalize(), n.length > 0 && x(e, ie).invert();
20
+ let i = 0;
21
+ for (let t of r) {
22
+ if (t !== e && t.isKinematic) continue;
23
+ t === e ? (V.set(0, 0, 0), H.identity()) : (ae.multiplyMatrices(ie, x(t, se)).decompose(V, H, ce), H.normalize()), re.copy(H).multiply(ne.fromArray(t.inertiaOrientation)).invert(), z.copy(R).applyQuaternion(re);
24
+ let [n, r, a] = t.inertiaDiagonal, o = n * z.x * z.x + r * z.y * z.y + a * z.z * z.z;
25
+ B.fromArray(t.centerOfMass).applyQuaternion(H).add(V);
26
+ let s = B.dot(R);
27
+ i += o + t.mass * (B.lengthSq() - s * s);
28
+ }
29
+ return i;
19
30
  }
20
- function ie(e, t) {
21
- if (e.kind === "fixed" || t <= 0) return;
22
- let n = e.drive, r = n?.mode === "force";
23
- if (r && !(e.inertia > 0)) throw new v(`Joint "${e.nodeName}" has force-mode drive but non-positive effective inertia ${e.inertia}`);
24
- let i = r ? 1 / e.inertia : 1, a = e.positionTarget !== null && n?.stiffness !== void 0 ? n.stiffness * i : 0, o = n?.damping === void 0 ? 0 : n.damping * i, s = 0, c = 0, l = 0;
25
- e.limits && e.limitStiffness !== null && (e.q < e.limits[0] ? l = e.limits[0] : e.q > e.limits[1] && (l = e.limits[1]), (e.q < e.limits[0] || e.q > e.limits[1]) && (s = e.limitStiffness * (r ? i : 1), c = e.limitDamping * (r ? i : 1)));
26
- let u = e.positionTarget ?? 0, d = (e.v + t * (a * (u - e.q) + o * e.velocityTarget + s * (l - e.q))) / (1 + t * (o + c) + t * t * (a + s));
27
- if (r && n?.maxForce !== void 0) {
28
- let r = n.maxForce / e.inertia, i = (d - e.v) / t;
29
- Math.abs(i) > r && (d = e.v + Math.sign(i) * r * t);
31
+ function ue(t, n) {
32
+ if (t.kind === "fixed" || !(n > 0)) return;
33
+ let r = t.drive, i = r?.mode === "force", a = t.limits !== null && t.limitStiffness !== null;
34
+ if ((i || a) && !(t.inertia > 0)) throw new e(`Joint "${t.nodeName}" requires positive effective inertia (got ${t.inertia})`);
35
+ let o = i ? 1 / t.inertia : 1, s = t.positionTarget !== null && r?.stiffness !== void 0 ? r.stiffness * o : 0, c = r?.damping === void 0 ? 0 : r.damping * o, l = 0, u = 0, d = 0;
36
+ if (t.limits && t.limitStiffness !== null && (t.q < t.limits[0] || t.q > t.limits[1])) {
37
+ d = t.q < t.limits[0] ? t.limits[0] : t.limits[1];
38
+ let e = 1 / t.inertia;
39
+ l = t.limitStiffness * e, u = t.limitDamping * e;
40
+ }
41
+ let f = t.positionTarget ?? 0, p = (t.v + n * (s * (f - t.q) + c * t.velocityTarget + l * (d - t.q))) / (1 + n * (c + u) + n * n * (s + l));
42
+ if (r?.maxForce !== void 0) {
43
+ if (!(r.maxForce >= 0)) throw new e(`Joint "${t.nodeName}" has negative drive.maxForce ${r.maxForce}`);
44
+ let a = i ? r.maxForce / t.inertia : r.maxForce, o = s * (f - (t.q + n * p)) + c * (t.velocityTarget - p);
45
+ if (Math.abs(o) > a) {
46
+ let e = Math.sign(o) * a;
47
+ p = (t.v + n * (e + l * (d - t.q))) / (1 + n * u + n * n * l);
48
+ }
30
49
  }
31
- e.v = d, e.q += d * t, e.limits && (e.q < e.limits[0] ? (e.q = e.limits[0], e.v < 0 && (e.v = 0)) : e.q > e.limits[1] && (e.q = e.limits[1], e.v > 0 && (e.v = 0)));
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)));
32
51
  }
33
- var ae = 1e-7;
34
- function oe(e, t) {
52
+ var de = 1e-7;
53
+ function fe(e, t) {
35
54
  if (e.stamp === t) return;
36
- e.parent && e.parent.stamp !== t && oe(e.parent, t), e.stamp = t;
55
+ e.parent && e.parent.stamp !== t && fe(e.parent, t), e.stamp = t;
37
56
  let n = e.parent !== null && e.parent.dirtyStamp === t, r = e.colliders.every((e) => e.ref.current !== null);
38
- if (e.lastWrittenQ === void 0 || Math.abs(e.q - e.lastWrittenQ) > ae || n) {
39
- e.dirtyStamp = t, r && (e.lastWrittenQ = e.q), e.kind === "revolute" ? (R.setFromAxisAngle(e.axis, e.q), e.object.quaternion.copy(e.restQuaternion).multiply(R), e.object.position.copy(e.restPosition), z.makeRotationFromQuaternion(R)) : e.kind === "prismatic" ? (I.copy(e.axis).multiplyScalar(e.q), e.object.quaternion.copy(e.restQuaternion), e.object.position.copy(I).applyQuaternion(e.restQuaternion).add(e.restPosition), z.makeTranslation(I.x, I.y, I.z)) : z.identity(), e.parent ? e.current.multiplyMatrices(e.parent.current, e.restRelParent) : e.current.copy(e.restRelParent), e.current.multiply(z);
57
+ if (e.lastWrittenQ === void 0 || Math.abs(e.q - e.lastWrittenQ) > de || n) {
58
+ e.dirtyStamp = t, r && (e.lastWrittenQ = e.q), e.kind === "revolute" ? (ne.setFromAxisAngle(e.axis, e.q), e.object.quaternion.copy(e.restQuaternion).multiply(ne), e.object.position.copy(e.restPosition), oe.makeRotationFromQuaternion(ne)) : e.kind === "prismatic" ? (R.copy(e.axis).multiplyScalar(e.q), e.object.quaternion.copy(e.restQuaternion), e.object.position.copy(R).applyQuaternion(e.restQuaternion).add(e.restPosition), oe.makeTranslation(R.x, R.y, R.z)) : oe.identity(), e.parent ? e.current.multiplyMatrices(e.parent.current, e.restRelParent) : e.current.copy(e.restRelParent), e.current.multiply(oe);
40
59
  for (let t of e.colliders) {
41
60
  let n = t.ref.current;
42
- n && (B.multiplyMatrices(e.current, t.local).decompose(ee, te, ne), n.setTranslationWrtParent(ee), n.setRotationWrtParent(te));
61
+ n && (se.multiplyMatrices(e.current, t.local).decompose(V, H, ce), n.setTranslationWrtParent(V), n.setRotationWrtParent(H));
43
62
  }
44
63
  }
45
64
  }
46
65
  // src/PhysicsWorld.tsx
47
- function se({ paused: e, timeScale: t, maxDelta: n, joints: r }) {
48
- let { step: i, world: a } = A(), o = T(0);
49
- return E((s, c) => {
50
- if (e || !(t > 0)) return;
51
- let l = Math.min(Math.max(c, 0), Math.max(0, n)) * t;
52
- if (l > 0) {
53
- if (r.size > 0) {
54
- let e = ++o.current;
55
- for (let e of r) ie(e, l);
56
- for (let t of r) oe(t, e);
57
- }
58
- a.timestep = l, i(l);
66
+ var pe = (e) => typeof e == "number" ? e : e.current;
67
+ function me({ paused: e, timeScale: t, maxDelta: n, joints: r, dtRef: i, frozenRef: a }) {
68
+ let { world: o } = M(), s = O(0);
69
+ return te((c, l) => {
70
+ let u = pe(t), d = Math.max(0, pe(n)), f = !e && u > 0 && d > 0 && l > 0 ? Math.min(Math.min(l, d) * u, .5) : 0;
71
+ if (!(f > 0)) {
72
+ i.current = 0, o.timestep > 0 || (o.timestep = 1 / 60);
73
+ let e = a.current;
74
+ e.length = 0, o.bodies.forEach((t) => {
75
+ if (!t.isDynamic()) return;
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);
59
92
  }
60
93
  }), null;
61
94
  }
62
- function ce({ paused: e = !1, timeScale: t = 1, maxDelta: r = 1 / 30, gravity: i = [
95
+ function he({ dtRef: e, frozenRef: t }) {
96
+ let { step: n } = M();
97
+ return te(() => {
98
+ let r = e.current;
99
+ if (r > 0) {
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;
117
+ }), null;
118
+ }
119
+ function ge({ paused: e = !1, timeScale: n = 1, maxDelta: r = 1 / 30, gravity: i = [
63
120
  0,
64
121
  -9.81,
65
122
  0
66
- ], children: a, ...o }) {
67
- let s = w(() => /* @__PURE__ */ new Set(), []), c = w(() => [
123
+ ], children: o, ...s }) {
124
+ let c = D(() => /* @__PURE__ */ new Set(), []), l = O(0), u = O([]), d = D(() => [
68
125
  i[0],
69
126
  i[1],
70
127
  i[2]
@@ -72,39 +129,54 @@ function ce({ paused: e = !1, timeScale: t = 1, maxDelta: r = 1 / 30, gravity: i
72
129
  i[0],
73
130
  i[1],
74
131
  i[2]
75
- ]);
76
- return /* @__PURE__ */ M(y.Provider, {
77
- value: s,
78
- children: /* @__PURE__ */ M(n.Provider, {
79
- value: c,
80
- children: /* @__PURE__ */ N(O, {
81
- ...o,
82
- paused: !0,
83
- timeStep: "vary",
84
- gravity: i,
85
- children: [/* @__PURE__ */ M(se, {
86
- paused: e,
87
- timeScale: t,
88
- maxDelta: r,
89
- joints: s
90
- }), a]
132
+ ]), f = !e && (typeof n != "number" || n > 0) && (typeof r != "number" || r > 0);
133
+ return /* @__PURE__ */ P(C.Provider, {
134
+ value: c,
135
+ children: /* @__PURE__ */ P(S.Provider, {
136
+ value: d,
137
+ children: /* @__PURE__ */ P(a.Provider, {
138
+ value: f,
139
+ children: /* @__PURE__ */ P(t.Provider, {
140
+ value: l,
141
+ children: /* @__PURE__ */ F(A, {
142
+ ...s,
143
+ paused: !0,
144
+ timeStep: "vary",
145
+ gravity: i,
146
+ children: [
147
+ /* @__PURE__ */ P(me, {
148
+ paused: e,
149
+ timeScale: n,
150
+ maxDelta: r,
151
+ joints: c,
152
+ dtRef: l,
153
+ frozenRef: u
154
+ }),
155
+ o,
156
+ /* @__PURE__ */ P(he, {
157
+ dtRef: l,
158
+ frozenRef: u
159
+ })
160
+ ]
161
+ })
162
+ })
91
163
  })
92
164
  })
93
165
  });
94
166
  }
95
167
  // src/khrGlb.ts
96
- var le = 1179937895, ue = 1313821514, de = 5130562;
97
- function fe(e) {
98
- if (e.byteLength < 20) throw new v("GLB buffer shorter than 20-byte header");
99
- let t = new DataView(e);
100
- if (t.getUint32(0, !0) !== 1179937895) throw new v("Invalid GLB magic");
101
- if (t.getUint32(4, !0) !== 2) throw new v("Unsupported glTF version");
102
- let n = t.getUint32(12, !0);
103
- if (t.getUint32(16, !0) !== 1313821514) throw new v("Missing GLB JSON chunk");
104
- if (20 + n > e.byteLength) throw new v("Truncated GLB JSON chunk");
105
- return n;
168
+ var _e = 1179937895, ve = 1313821514, ye = 5130562;
169
+ function be(t) {
170
+ if (t.byteLength < 20) throw new e("GLB buffer shorter than 20-byte header");
171
+ let n = new DataView(t);
172
+ if (n.getUint32(0, !0) !== 1179937895) throw new e("Invalid GLB magic");
173
+ if (n.getUint32(4, !0) !== 2) throw new e("Unsupported glTF version");
174
+ let r = n.getUint32(12, !0);
175
+ if (n.getUint32(16, !0) !== 1313821514) throw new e("Missing GLB JSON chunk");
176
+ if (20 + r > t.byteLength) throw new e("Truncated GLB JSON chunk");
177
+ return r;
106
178
  }
107
- function pe() {
179
+ function xe() {
108
180
  if (globalThis.FileReader !== void 0) return;
109
181
  class e {
110
182
  result = null;
@@ -131,28 +203,28 @@ function pe() {
131
203
  }
132
204
  globalThis.FileReader = e;
133
205
  }
134
- function me(e) {
206
+ function Se(e) {
135
207
  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);
136
- return a.setUint32(0, le, !0), a.setUint32(4, 2, !0), a.setUint32(8, r, !0), a.setUint32(12, n, !0), a.setUint32(16, ue, !0), o.set(t, 20), o.fill(32, 20 + t.byteLength, 20 + n), i;
208
+ return a.setUint32(0, _e, !0), a.setUint32(4, 2, !0), a.setUint32(8, r, !0), a.setUint32(12, n, !0), a.setUint32(16, ve, !0), o.set(t, 20), o.fill(32, 20 + t.byteLength, 20 + n), i;
137
209
  }
138
- function he(e, t) {
139
- let n = e instanceof ArrayBuffer ? e : e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength), r = fe(n), i = new DataView(n), a;
210
+ function Ce(t, n) {
211
+ let r = t instanceof ArrayBuffer ? t : t.buffer.slice(t.byteOffset, t.byteOffset + t.byteLength), i = be(r), a = new DataView(r), o;
140
212
  try {
141
- a = JSON.parse(new TextDecoder().decode(new Uint8Array(n, 20, r)));
213
+ o = JSON.parse(new TextDecoder().decode(new Uint8Array(r, 20, i)));
142
214
  } catch {
143
- throw new v("Malformed GLB JSON chunk");
215
+ throw new e("Malformed GLB JSON chunk");
144
216
  }
145
- t(a);
146
- let o = new TextEncoder().encode(JSON.stringify(a)), s = o.byteLength + 3 & -4, c = 20 + r, l = c + 8 <= n.byteLength, u = l ? Math.min(i.getUint32(c, !0), n.byteLength - (c + 8)) : 0, d = l ? i.getUint32(c + 4, !0) : de, f = l ? new Uint8Array(n, c + 8, u) : /* @__PURE__ */ new Uint8Array(), p = f.byteLength + 3 & -4, m = 20 + s + (l ? 8 + p : 0), h = new ArrayBuffer(m), g = new DataView(h), _ = new Uint8Array(h);
147
- return g.setUint32(0, le, !0), g.setUint32(4, 2, !0), g.setUint32(8, m, !0), g.setUint32(12, s, !0), g.setUint32(16, ue, !0), _.set(o, 20), _.fill(32, 20 + o.byteLength, 20 + s), l && (g.setUint32(20 + s, p, !0), g.setUint32(24 + s, d, !0), _.set(f, 28 + s)), h;
217
+ 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) : ye, 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);
219
+ return _.setUint32(0, _e, !0), _.setUint32(4, 2, !0), _.setUint32(8, h, !0), _.setUint32(12, c, !0), _.setUint32(16, ve, !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;
148
220
  }
149
221
  // src/khrExtras.ts
150
- var ge = /* @__PURE__ */ new WeakMap();
151
- function _e(e, t) {
152
- ge.set(e, t);
222
+ var we = /* @__PURE__ */ new WeakMap();
223
+ function Te(e, t) {
224
+ we.set(e, t);
153
225
  }
154
- function ve(e, t, n, r) {
155
- let i = ge.get(t.scene);
226
+ function Ee(e, t, n, r) {
227
+ let i = we.get(t.scene);
156
228
  if (i) {
157
229
  if (n) for (let t = 0; t < e.bodies.length; t++) {
158
230
  let r = i.bodies[t], a = e.bodies[t];
@@ -175,264 +247,264 @@ function ve(e, t, n, r) {
175
247
  }
176
248
  }
177
249
  }
178
- var V = new j.Vector3(), H = new j.Quaternion(), ye = new j.Quaternion();
179
- function be(e, t) {
180
- return e.updateWorldMatrix(!0, !1), e.getWorldQuaternion(H), t && (t.updateWorldMatrix(!0, !1), H.premultiply(t.getWorldQuaternion(ye).invert())), H.lengthSq() > 0 ? H.normalize() : H.identity(), [
181
- H.x || 0,
182
- H.y || 0,
183
- H.z || 0,
184
- H.w || 0
250
+ var De = new N.Vector3(), U = new N.Quaternion(), Oe = new N.Quaternion();
251
+ function ke(e, t) {
252
+ return e.updateWorldMatrix(!0, !1), e.getWorldQuaternion(U), t && (t.updateWorldMatrix(!0, !1), U.premultiply(t.getWorldQuaternion(Oe).invert())), U.lengthSq() > 0 ? U.normalize() : U.identity(), [
253
+ U.x || 0,
254
+ U.y || 0,
255
+ U.z || 0,
256
+ U.w || 0
185
257
  ];
186
258
  }
187
- var U = (e) => typeof e == "object" && !!e && !Array.isArray(e), W = (e) => typeof e == "number" && Number.isFinite(e);
188
- function G(e, t, n, r = !1) {
189
- let i = e[t];
190
- if (i !== void 0) {
191
- if (!W(i) || (r ? i <= 0 : i < 0)) throw new v(`ecctrlWheel "${n}" has invalid ${t}: ecctrlWheel.${t}`);
192
- return i;
259
+ var W = (e) => typeof e == "object" && !!e && !Array.isArray(e), G = (e) => typeof e == "number" && Number.isFinite(e);
260
+ function K(t, n, r, i = !1) {
261
+ let a = t[n];
262
+ if (a !== void 0) {
263
+ if (!G(a) || (i ? a <= 0 : a < 0)) throw new e(`ecctrlWheel "${r}" has invalid ${n}: ecctrlWheel.${n}`);
264
+ return a;
193
265
  }
194
266
  }
195
- function K(e, t, n, r) {
196
- let i = e[t];
197
- if (i !== void 0) {
198
- if (typeof i != "boolean") throw new v(`${n} "${r}" has non-boolean ${n}.${t}`);
199
- return i;
267
+ function Ae(t, n, r, i) {
268
+ let a = t[n];
269
+ if (a !== void 0) {
270
+ if (typeof a != "boolean") throw new e(`${r} "${i}" has non-boolean ${r}.${n}`);
271
+ return a;
200
272
  }
201
273
  }
202
- function xe(e, t, n) {
203
- if (e !== void 0) {
204
- if (!U(e) || !Array.isArray(e.points) || e.points.length === 0) throw new v(`ecctrlWheel "${n}" has invalid ecctrlWheel.${t}`);
205
- for (let r of e.points) if (!U(r) || !W(r.x) || !W(r.y)) throw new v(`ecctrlWheel "${n}" has invalid point in ecctrlWheel.${t}`);
206
- if (e.samples !== void 0 && (!W(e.samples) || e.samples <= 0)) throw new v(`ecctrlWheel "${n}" has invalid samples in ecctrlWheel.${t}`);
207
- return e;
274
+ function je(t, n, r) {
275
+ if (t !== void 0) {
276
+ if (!W(t) || !Array.isArray(t.points) || t.points.length === 0) throw new e(`ecctrlWheel "${r}" has invalid ecctrlWheel.${n}`);
277
+ 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}`);
278
+ if (t.samples !== void 0 && (!G(t.samples) || t.samples <= 0)) throw new e(`ecctrlWheel "${r}" has invalid samples in ecctrlWheel.${n}`);
279
+ return t;
208
280
  }
209
281
  }
210
- function Se(e, t, n, r, i) {
211
- if (n.socketId !== void 0 && (typeof n.socketId != "string" || n.socketId.length === 0)) throw new v(`Node "${t}" has invalid extras.socketId`);
212
- let a = e.getWorldPosition(new j.Vector3()), o = [
213
- a.x,
214
- a.y,
215
- a.z
216
- ], s = i?.(t, n);
217
- if (s || n.isIkAnchor === !0 || typeof n.socketId == "string") {
218
- let e = typeof s == "string" && s.length > 0 ? s : n.socketId ?? t;
219
- r[e] = [...o];
282
+ function Me(t, n, r, i, a) {
283
+ 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 N.Vector3()), s = [
285
+ o.x,
286
+ o.y,
287
+ o.z
288
+ ], c = a?.(n, r);
289
+ if (c || r.isIkAnchor === !0 || typeof r.socketId == "string") {
290
+ let e = typeof c == "string" && c.length > 0 ? c : r.socketId ?? n;
291
+ i[e] = [...s];
220
292
  }
221
- let c;
222
- if (n.contactDots !== void 0) {
223
- if (!Array.isArray(n.contactDots)) throw new v(`Node "${t}" has invalid extras.contactDots (expected array)`);
224
- e.getWorldQuaternion(H), c = [];
225
- for (let e of n.contactDots) {
226
- if (!U(e) || typeof e.role != "string" || e.role.length === 0 || !Array.isArray(e.pos) || e.pos.length !== 3 || !e.pos.every(W)) throw new v(`Node "${t}" has invalid entry in extras.contactDots`);
227
- V.set(e.pos[0], e.pos[1], e.pos[2]).applyQuaternion(H).add(a);
228
- let n = [
229
- V.x,
230
- V.y,
231
- V.z
293
+ let l;
294
+ if (r.contactDots !== void 0) {
295
+ if (!Array.isArray(r.contactDots)) throw new e(`Node "${n}" has invalid extras.contactDots (expected array)`);
296
+ t.getWorldQuaternion(U), l = [];
297
+ for (let t of r.contactDots) {
298
+ 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
+ De.set(t.pos[0], t.pos[1], t.pos[2]).applyQuaternion(U).add(o);
300
+ let r = [
301
+ De.x,
302
+ De.y,
303
+ De.z
232
304
  ];
233
- r[e.role] = n, c.push([e.role, n]);
305
+ i[t.role] = r, l.push([t.role, r]);
234
306
  }
235
307
  }
236
308
  return {
237
- nodeName: t,
238
- extras: n,
239
- worldPosition: o,
240
- ...c ? { contactDots: c } : {}
309
+ nodeName: n,
310
+ extras: r,
311
+ worldPosition: s,
312
+ ...l ? { contactDots: l } : {}
241
313
  };
242
314
  }
243
- function Ce(e, t, n, r) {
244
- if (g(e, t), !U(n)) throw new v(`ecctrlWheel "${t}" must be an object`);
245
- let i = (e) => {
246
- let r = n[e];
247
- if (!W(r) || r <= 0) throw new v(`ecctrlWheel "${t}" is missing valid ecctrlWheel.${e}`);
248
- return r;
249
- }, a = (e) => {
250
- let r = n[e];
251
- if (!W(r) || r < 0) throw new v(`ecctrlWheel "${t}" is missing valid ecctrlWheel.${e}`);
252
- return r;
253
- }, o = (e) => {
254
- let r = n[e];
255
- if (typeof r != "boolean") throw new v(`ecctrlWheel "${t}" is missing boolean ecctrlWheel.${e}`);
256
- return r;
257
- }, s = i("radius"), c = i("width"), l = a("travel"), u = a("sag");
258
- if (u > l) throw new v(`ecctrlWheel "${t}" has invalid ecctrlWheel.sag (${u}) > ecctrlWheel.travel (${l})`);
259
- let d = o("steer"), f = o("drive"), p = o("brake"), m = new j.Box3().setFromObject(e), h = m.isEmpty() ? e.getWorldPosition(new j.Vector3()) : m.getCenter(new j.Vector3());
315
+ function Ne(t, n, r, i) {
316
+ if (y(t, n), !W(r)) throw new e(`ecctrlWheel "${n}" must be an object`);
317
+ let a = (t) => {
318
+ let i = r[t];
319
+ if (!G(i) || i <= 0) throw new e(`ecctrlWheel "${n}" is missing valid ecctrlWheel.${t}`);
320
+ return i;
321
+ }, o = (t) => {
322
+ let i = r[t];
323
+ if (!G(i) || i < 0) throw new e(`ecctrlWheel "${n}" is missing valid ecctrlWheel.${t}`);
324
+ return i;
325
+ }, s = (t) => {
326
+ let i = r[t];
327
+ if (typeof i != "boolean") throw new e(`ecctrlWheel "${n}" is missing boolean ecctrlWheel.${t}`);
328
+ return i;
329
+ }, c = a("radius"), l = a("width"), u = o("travel"), d = o("sag");
330
+ 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 N.Box3().setFromObject(t), g = h.isEmpty() ? t.getWorldPosition(new N.Vector3()) : h.getCenter(new N.Vector3());
260
332
  return {
261
- nodeName: t,
262
- object: e,
333
+ nodeName: n,
334
+ object: t,
263
335
  position: [
264
- h.x,
265
- h.y,
266
- h.z
336
+ g.x,
337
+ g.y,
338
+ g.z
267
339
  ],
268
- quaternion: be(e, r),
269
- radius: s,
270
- width: c,
271
- steer: d,
272
- steerInvert: K(n, "steerInvert", "ecctrlWheel", t),
273
- drive: f,
274
- driveInvert: K(n, "driveInvert", "ecctrlWheel", t),
275
- brake: p,
276
- travel: l,
277
- sag: u,
278
- springK: G(n, "springK", t),
279
- dampingC: G(n, "dampingC", t),
280
- maxBrakeTorque: G(n, "maxBrakeTorque", t),
281
- rollingResistanceCoef: G(n, "rollingResistanceCoef", t),
282
- wheelDensity: G(n, "wheelDensity", t, !0),
283
- driveTorqueWeight: G(n, "driveTorqueWeight", t),
284
- tireGripFactor: G(n, "tireGripFactor", t),
285
- latFrictionEllipseScale: G(n, "latFrictionEllipseScale", t),
286
- relaxLngRate: G(n, "relaxLngRate", t),
287
- relaxLatRate: G(n, "relaxLatRate", t),
288
- lngSlipRatioCurveData: xe(n.lngSlipRatioCurveData, "lngSlipRatioCurveData", t),
289
- latSlipRatioCurveData: xe(n.latSlipRatioCurveData, "latSlipRatioCurveData", t)
340
+ quaternion: ke(t, i),
341
+ radius: c,
342
+ width: l,
343
+ steer: f,
344
+ steerInvert: Ae(r, "steerInvert", "ecctrlWheel", n),
345
+ drive: p,
346
+ driveInvert: Ae(r, "driveInvert", "ecctrlWheel", n),
347
+ brake: m,
348
+ travel: u,
349
+ sag: d,
350
+ springK: K(r, "springK", n),
351
+ dampingC: K(r, "dampingC", n),
352
+ maxBrakeTorque: K(r, "maxBrakeTorque", n),
353
+ rollingResistanceCoef: K(r, "rollingResistanceCoef", n),
354
+ wheelDensity: K(r, "wheelDensity", n, !0),
355
+ driveTorqueWeight: K(r, "driveTorqueWeight", n),
356
+ tireGripFactor: K(r, "tireGripFactor", n),
357
+ latFrictionEllipseScale: K(r, "latFrictionEllipseScale", n),
358
+ relaxLngRate: K(r, "relaxLngRate", n),
359
+ relaxLatRate: K(r, "relaxLatRate", n),
360
+ lngSlipRatioCurveData: je(r.lngSlipRatioCurveData, "lngSlipRatioCurveData", n),
361
+ latSlipRatioCurveData: je(r.latSlipRatioCurveData, "latSlipRatioCurveData", n)
290
362
  };
291
363
  }
292
- function we(e, t, n, r) {
293
- if (g(e, t), !U(n)) throw new v(`ecctrlPropeller "${t}" must be an object`);
294
- if (!W(n.maxThrust) || n.maxThrust <= 0) throw new v(`ecctrlPropeller "${t}" is missing positive finite ecctrlPropeller.maxThrust`);
295
- let i;
296
- if (n.torqueRatio !== void 0) {
297
- if (!W(n.torqueRatio)) throw new v(`ecctrlPropeller "${t}" has invalid ecctrlPropeller.torqueRatio`);
298
- i = n.torqueRatio;
364
+ function Pe(t, n, r, i) {
365
+ if (y(t, n), !W(r)) throw new e(`ecctrlPropeller "${n}" must be an object`);
366
+ if (!G(r.maxThrust) || r.maxThrust <= 0) throw new e(`ecctrlPropeller "${n}" is missing positive finite ecctrlPropeller.maxThrust`);
367
+ let a;
368
+ if (r.torqueRatio !== void 0) {
369
+ if (!G(r.torqueRatio)) throw new e(`ecctrlPropeller "${n}" has invalid ecctrlPropeller.torqueRatio`);
370
+ a = r.torqueRatio;
299
371
  }
300
- let a = new j.Box3().setFromObject(e), o = a.isEmpty() ? e.getWorldPosition(new j.Vector3()) : a.getCenter(new j.Vector3());
372
+ let o = new N.Box3().setFromObject(t), s = o.isEmpty() ? t.getWorldPosition(new N.Vector3()) : o.getCenter(new N.Vector3());
301
373
  return {
302
- nodeName: t,
303
- object: e,
374
+ nodeName: n,
375
+ object: t,
304
376
  position: [
305
- o.x,
306
- o.y,
307
- o.z
377
+ s.x,
378
+ s.y,
379
+ s.z
308
380
  ],
309
- quaternion: be(e, r),
310
- maxThrust: n.maxThrust,
311
- torqueRatio: i,
312
- invertThrust: K(n, "invertThrust", "ecctrlPropeller", t),
313
- invertTorque: K(n, "invertTorque", "ecctrlPropeller", t)
381
+ quaternion: ke(t, i),
382
+ maxThrust: r.maxThrust,
383
+ torqueRatio: a,
384
+ invertThrust: Ae(r, "invertThrust", "ecctrlPropeller", n),
385
+ invertTorque: Ae(r, "invertTorque", "ecctrlPropeller", n)
314
386
  };
315
387
  }
316
388
  // src/khrParsers.ts
317
- var Te = /* @__PURE__ */ new Map([["default", 0]]), Ee = 1, De = (e) => typeof e == "object" && !!e && !Array.isArray(e), q = (e) => typeof e == "number" && Number.isFinite(e) && e > 0, Oe = (e) => typeof e == "number" && Number.isFinite(e) && e >= 0;
318
- function J(e, t, n = !1) {
319
- if (e !== void 0) {
320
- if (typeof e != "number" || !Number.isFinite(e) || n && e < 0) throw new v(`Invalid ${t}`);
321
- return e;
389
+ var Fe = /* @__PURE__ */ new Map([["default", 0]]), Ie = 1, Le = (e) => typeof e == "object" && !!e && !Array.isArray(e), q = (e) => typeof e == "number" && Number.isFinite(e) && e > 0, Re = (e) => typeof e == "number" && Number.isFinite(e) && e >= 0;
390
+ function J(t, n, r = !1) {
391
+ if (t !== void 0) {
392
+ if (typeof t != "number" || !Number.isFinite(t) || r && t < 0) throw new e(`Invalid ${n}`);
393
+ return t;
322
394
  }
323
395
  }
324
- function ke(e, t) {
325
- if (!De(e)) throw new v(`KHR_implicit_shapes[${t}] must be an object`);
326
- let n = e.type;
327
- if (n === "box" && e.box && typeof e.box == "object") {
328
- let n = e.box.size;
329
- if (!Array.isArray(n) || n.length !== 3 || !n.every(q)) throw new v(`KHR_implicit_shapes[${t}] invalid box.size`);
396
+ function ze(t, n) {
397
+ if (!Le(t)) throw new e(`KHR_implicit_shapes[${n}] must be an object`);
398
+ let r = t.type;
399
+ if (r === "box" && t.box && typeof t.box == "object") {
400
+ let r = t.box.size;
401
+ if (!Array.isArray(r) || r.length !== 3 || !r.every(q)) throw new e(`KHR_implicit_shapes[${n}] invalid box.size`);
330
402
  return {
331
403
  type: "box",
332
404
  size: [
333
- n[0],
334
- n[1],
335
- n[2]
405
+ r[0],
406
+ r[1],
407
+ r[2]
336
408
  ]
337
409
  };
338
410
  }
339
- if (n === "sphere" && e.sphere && typeof e.sphere == "object") {
340
- let n = e.sphere.radius;
341
- if (!q(n)) throw new v(`KHR_implicit_shapes[${t}] invalid sphere.radius`);
411
+ if (r === "sphere" && t.sphere && typeof t.sphere == "object") {
412
+ let r = t.sphere.radius;
413
+ if (!q(r)) throw new e(`KHR_implicit_shapes[${n}] invalid sphere.radius`);
342
414
  return {
343
415
  type: "sphere",
344
- radius: n
416
+ radius: r
345
417
  };
346
418
  }
347
- if ((n === "cylinder" || n === "capsule") && e[n] && typeof e[n] == "object") {
348
- let r = e[n];
349
- if (!q(r.height)) throw new v(`KHR_implicit_shapes[${t}] invalid ${n}.height`);
350
- if (!q(r.radiusTop)) throw new v(`KHR_implicit_shapes[${t}] invalid ${n}.radiusTop`);
351
- if (!q(r.radiusBottom)) throw new v(`KHR_implicit_shapes[${t}] invalid ${n}.radiusBottom`);
352
- if (Math.abs(r.radiusTop - r.radiusBottom) > 1e-6) throw new v(`KHR_implicit_shapes[${t}] tapered ${n} (${r.radiusTop} !== ${r.radiusBottom}) is unsupported`);
419
+ if ((r === "cylinder" || r === "capsule") && t[r] && typeof t[r] == "object") {
420
+ let i = t[r];
421
+ if (!q(i.height)) throw new e(`KHR_implicit_shapes[${n}] invalid ${r}.height`);
422
+ if (!q(i.radiusTop)) throw new e(`KHR_implicit_shapes[${n}] invalid ${r}.radiusTop`);
423
+ if (!q(i.radiusBottom)) throw new e(`KHR_implicit_shapes[${n}] invalid ${r}.radiusBottom`);
424
+ if (Math.abs(i.radiusTop - i.radiusBottom) > 1e-6) throw new e(`KHR_implicit_shapes[${n}] tapered ${r} (${i.radiusTop} !== ${i.radiusBottom}) is unsupported`);
353
425
  return {
354
- type: n,
355
- height: r.height,
356
- radiusTop: r.radiusTop,
357
- radiusBottom: r.radiusBottom
426
+ type: r,
427
+ height: i.height,
428
+ radiusTop: i.radiusTop,
429
+ radiusBottom: i.radiusBottom
358
430
  };
359
431
  }
360
- throw new v(`KHR_implicit_shapes[${t}] unsupported shape type "${n}"`);
432
+ throw new e(`KHR_implicit_shapes[${n}] unsupported shape type "${r}"`);
361
433
  }
362
- function Ae(e, t, n) {
363
- if (t === void 0) return {};
364
- if (typeof t != "number" || !Number.isInteger(t) || t < 0 || t >= e.length) throw new v(`Node "${n}" references out-of-bounds physicsMaterial ${String(t)}`);
365
- let r = e[t];
366
- if (!De(r)) throw new v(`Invalid physicsMaterials[${t}] on "${n}"`);
367
- let i = J(r.dynamicFriction, `physicsMaterials[${t}].dynamicFriction`, !0), a = J(r.staticFriction, `physicsMaterials[${t}].staticFriction`, !0), o = J(r.restitution, `physicsMaterials[${t}].restitution`, !0);
434
+ function Be(t, n, r) {
435
+ if (n === void 0) return {};
436
+ 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
+ let i = t[n];
438
+ if (!Le(i)) throw new e(`Invalid physicsMaterials[${n}] on "${r}"`);
439
+ 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);
368
440
  return {
369
- ...i !== void 0 || a !== void 0 ? { friction: i ?? a } : {},
370
- ...o === void 0 ? {} : { restitution: o }
441
+ ...a !== void 0 || o !== void 0 ? { friction: a ?? o } : {},
442
+ ...s === void 0 ? {} : { restitution: s }
371
443
  };
372
444
  }
373
- function je(t, n, r) {
374
- if (t.isKinematic !== void 0 && typeof t.isKinematic != "boolean") throw new v(`Node "${r}" has non-boolean motion.isKinematic`);
375
- let i = !n || !!t.isKinematic, a = 0;
376
- if (!i) {
377
- if (!q(t.mass)) throw new v(`Dynamic node "${r}" is missing positive finite motion.mass`);
378
- a = t.mass;
445
+ function Ve(t, n, i) {
446
+ if (t.isKinematic !== void 0 && typeof t.isKinematic != "boolean") throw new e(`Node "${i}" has non-boolean motion.isKinematic`);
447
+ let a = !n || !!t.isKinematic, o = 0;
448
+ if (!a) {
449
+ if (!q(t.mass)) throw new e(`Dynamic node "${i}" is missing positive finite motion.mass`);
450
+ o = t.mass;
379
451
  } else if (t.mass !== void 0) {
380
- if (!Oe(t.mass)) throw new v(`Kinematic node "${r}" has invalid motion.mass`);
381
- a = t.mass;
452
+ if (!Re(t.mass)) throw new e(`Kinematic node "${i}" has invalid motion.mass`);
453
+ o = t.mass;
382
454
  }
383
- let o = t.centerOfMass === void 0 ? [
455
+ let s = t.centerOfMass === void 0 ? [
384
456
  0,
385
457
  0,
386
458
  0
387
- ] : e(t.centerOfMass, `${r}.motion.centerOfMass`), s = t.inertiaOrientation === void 0 ? [
459
+ ] : r(t.centerOfMass, `${i}.motion.centerOfMass`), c = t.inertiaOrientation === void 0 ? [
388
460
  0,
389
461
  0,
390
462
  0,
391
463
  1
392
- ] : _(t.inertiaOrientation, `${r}.motion.inertiaOrientation`), c = [
464
+ ] : b(t.inertiaOrientation, `${i}.motion.inertiaOrientation`), l = [
393
465
  0,
394
466
  0,
395
467
  0
396
- ], l = t.inertiaDiagonal !== void 0;
397
- if (l && (c = e(t.inertiaDiagonal, `${r}.motion.inertiaDiagonal`), c.some((e) => i ? e < 0 : e <= 0))) throw new v(`Node "${r}" has invalid motion.inertiaDiagonal`);
398
- let u = t.linearVelocity === void 0 ? void 0 : e(t.linearVelocity, `${r}.motion.linearVelocity`), d = t.angularVelocity === void 0 ? void 0 : e(t.angularVelocity, `${r}.motion.angularVelocity`), f = J(t.gravityFactor, `${r}.motion.gravityFactor`);
468
+ ], u = t.inertiaDiagonal !== void 0;
469
+ if (u && (l = r(t.inertiaDiagonal, `${i}.motion.inertiaDiagonal`), l.some((e) => a ? e < 0 : e <= 0))) throw new e(`Node "${i}" has invalid motion.inertiaDiagonal`);
470
+ let d = t.linearVelocity === void 0 ? void 0 : r(t.linearVelocity, `${i}.motion.linearVelocity`), f = t.angularVelocity === void 0 ? void 0 : r(t.angularVelocity, `${i}.motion.angularVelocity`), p = J(t.gravityFactor, `${i}.motion.gravityFactor`);
399
471
  return {
400
- isKinematic: i,
401
- mass: a,
402
- centerOfMass: o,
403
- inertiaDiagonal: c,
404
- inertiaOrientation: s,
405
- hasExplicitInertia: l,
406
- ...u ? { linearVelocity: u } : {},
407
- ...d ? { angularVelocity: d } : {},
408
- ...f === void 0 ? {} : { gravityFactor: f }
472
+ isKinematic: a,
473
+ mass: o,
474
+ centerOfMass: s,
475
+ inertiaDiagonal: l,
476
+ inertiaOrientation: c,
477
+ hasExplicitInertia: u,
478
+ ...d ? { linearVelocity: d } : {},
479
+ ...f ? { angularVelocity: f } : {},
480
+ ...p === void 0 ? {} : { gravityFactor: p }
409
481
  };
410
482
  }
411
- function Me(e) {
412
- let t = (e) => {
413
- let t = Te.get(e);
414
- if (t !== void 0) return t;
415
- if (Ee > 15) throw new v(`Exceeded Rapier 16-group limit for collisionSystem "${e}"`);
416
- let n = Ee++;
417
- return Te.set(e, n), n;
418
- }, n = (e, n) => {
419
- if (e === void 0) return 0;
420
- if (!Array.isArray(e)) throw new v(`collisionFilter.${n} must be an array`);
421
- let r = 0;
422
- for (let i of e) {
423
- if (typeof i != "string" || i.length === 0) throw new v(`collisionFilter.${n} has invalid system`);
424
- r |= 1 << t(i);
483
+ function He(t) {
484
+ let n = (t) => {
485
+ let n = Fe.get(t);
486
+ if (n !== void 0) return n;
487
+ if (Ie > 15) throw new e(`Exceeded Rapier 16-group limit for collisionSystem "${t}"`);
488
+ let r = Ie++;
489
+ return Fe.set(t, r), r;
490
+ }, r = (t, r) => {
491
+ if (t === void 0) return 0;
492
+ if (!Array.isArray(t)) throw new e(`collisionFilter.${r} must be an array`);
493
+ let i = 0;
494
+ for (let a of t) {
495
+ if (typeof a != "string" || a.length === 0) throw new e(`collisionFilter.${r} has invalid system`);
496
+ i |= 1 << n(a);
425
497
  }
426
- return r;
498
+ return i;
427
499
  };
428
- return e.map((e, t) => {
429
- if (!e || typeof e != "object" || Array.isArray(e)) throw new v(`collisionFilters[${t}] must be an object`);
430
- if (e.collideWithSystems !== void 0 && e.notCollideWithSystems !== void 0) throw new v(`collisionFilters[${t}] cannot specify both collideWithSystems and notCollideWithSystems`);
431
- let r = n(e.collisionSystems, "collisionSystems"), i = e.collideWithSystems === void 0 ? 65535 & ~n(e.notCollideWithSystems, "notCollideWithSystems") : n(e.collideWithSystems, "collideWithSystems");
432
- return (r & 65535) << 16 | i & 65535;
500
+ return t.map((t, n) => {
501
+ if (!t || typeof t != "object" || Array.isArray(t)) throw new e(`collisionFilters[${n}] must be an object`);
502
+ if (t.collideWithSystems !== void 0 && t.notCollideWithSystems !== void 0) throw new e(`collisionFilters[${n}] cannot specify both collideWithSystems and notCollideWithSystems`);
503
+ let i = r(t.collisionSystems, "collisionSystems"), a = t.collideWithSystems === void 0 ? 65535 & ~r(t.notCollideWithSystems, "notCollideWithSystems") : r(t.collideWithSystems, "collideWithSystems");
504
+ return (i & 65535) << 16 | a & 65535;
433
505
  });
434
506
  }
435
- var Ne = (e) => e === 0 ? [
507
+ var Ue = (e) => e === 0 ? [
436
508
  1,
437
509
  0,
438
510
  0
@@ -445,102 +517,102 @@ var Ne = (e) => e === 0 ? [
445
517
  0,
446
518
  1
447
519
  ];
448
- function Pe(e, t, n) {
449
- return e.map((e, r) => {
450
- let i = `physicsJoints[${t}].drives[${r}] on "${n}"`;
451
- if (!e || typeof e != "object" || Array.isArray(e)) throw new v(`${i} must be an object`);
452
- if (e.mode !== "force" && e.mode !== "acceleration") throw new v(`${i} missing valid drive.mode`);
453
- if (e.axis !== 0 && e.axis !== 1 && e.axis !== 2) throw new v(`${i} missing valid drive.axis (0|1|2)`);
454
- if (e.type !== void 0 && e.type !== "linear" && e.type !== "angular") throw new v(`${i} invalid drive.type`);
455
- let a = J(e.positionTarget, `${i} drive.positionTarget`), o = J(e.velocityTarget, `${i} drive.velocityTarget`);
456
- if (a === void 0 && o === void 0) throw new v(`${i} requires finite drive.positionTarget or drive.velocityTarget`);
457
- let s = J(e.stiffness, `${i} drive.stiffness`, !0), c = J(e.damping, `${i} drive.damping`, !0), l = J(e.maxForce, `${i} drive.maxForce`, !0);
520
+ function We(t, n, r) {
521
+ return t.map((t, i) => {
522
+ let a = `physicsJoints[${n}].drives[${i}] on "${r}"`;
523
+ if (!t || typeof t != "object" || Array.isArray(t)) throw new e(`${a} must be an object`);
524
+ if (t.mode !== "force" && t.mode !== "acceleration") throw new e(`${a} missing valid drive.mode`);
525
+ if (t.axis !== 0 && t.axis !== 1 && t.axis !== 2) throw new e(`${a} missing valid drive.axis (0|1|2)`);
526
+ if (t.type !== void 0 && t.type !== "linear" && t.type !== "angular") throw new e(`${a} invalid drive.type`);
527
+ let o = J(t.positionTarget, `${a} drive.positionTarget`), s = J(t.velocityTarget, `${a} drive.velocityTarget`);
528
+ if (o === void 0 && s === void 0) throw new e(`${a} requires finite drive.positionTarget or drive.velocityTarget`);
529
+ let c = J(t.stiffness, `${a} drive.stiffness`, !0), l = J(t.damping, `${a} drive.damping`, !0), u = J(t.maxForce, `${a} drive.maxForce`, !0);
458
530
  return {
459
- ...e.type ? { type: e.type } : {},
460
- mode: e.mode,
461
- axis: e.axis,
462
- ...a === void 0 ? {} : { positionTarget: a },
463
- ...o === void 0 ? {} : { velocityTarget: o },
464
- ...s === void 0 ? {} : { stiffness: s },
465
- ...c === void 0 ? {} : { damping: c },
466
- ...l === void 0 ? {} : { maxForce: l }
531
+ ...t.type ? { type: t.type } : {},
532
+ mode: t.mode,
533
+ axis: t.axis,
534
+ ...o === void 0 ? {} : { positionTarget: o },
535
+ ...s === void 0 ? {} : { velocityTarget: s },
536
+ ...c === void 0 ? {} : { stiffness: c },
537
+ ...l === void 0 ? {} : { damping: l },
538
+ ...u === void 0 ? {} : { maxForce: u }
467
539
  };
468
540
  });
469
541
  }
470
- function Fe(e, t, n, r, i, a, o, s = r.name) {
471
- let c = e[t];
472
- if (!De(c)) throw new v(`physicsJoints[${t}] out of bounds for "${n}"`);
473
- if (c.limits !== void 0 && !Array.isArray(c.limits)) throw new v(`physicsJoints[${t}].limits on "${n}" must be an array`);
474
- if (c.drives !== void 0 && !Array.isArray(c.drives)) throw new v(`physicsJoints[${t}].drives on "${n}" must be an array`);
475
- let l = c.limits ?? [], u = c.drives ?? [], d = [
542
+ function Ge(t, n, r, i, a, o, s, c = i.name) {
543
+ let l = t[n];
544
+ if (!Le(l)) throw new e(`physicsJoints[${n}] out of bounds for "${r}"`);
545
+ if (l.limits !== void 0 && !Array.isArray(l.limits)) throw new e(`physicsJoints[${n}].limits on "${r}" must be an array`);
546
+ if (l.drives !== void 0 && !Array.isArray(l.drives)) throw new e(`physicsJoints[${n}].drives on "${r}" must be an array`);
547
+ let u = l.limits ?? [], d = l.drives ?? [], f = [
476
548
  "unlimited",
477
549
  "unlimited",
478
550
  "unlimited"
479
- ], f = [
551
+ ], p = [
480
552
  "unlimited",
481
553
  "unlimited",
482
554
  "unlimited"
483
- ], p = [
555
+ ], m = [
484
556
  void 0,
485
557
  void 0,
486
558
  void 0
487
- ], m = [
559
+ ], h = [
488
560
  void 0,
489
561
  void 0,
490
562
  void 0
491
- ], h = (e, r, i, a) => {
492
- if (e === void 0) return;
493
- if (!Array.isArray(e)) throw new v(`physicsJoints[${t}].limits axes on "${n}" must be an array`);
494
- let o = e.map((e) => {
495
- if (e !== 0 && e !== 1 && e !== 2) throw new v(`physicsJoints[${t}].limits invalid axis ${String(e)} on "${n}"`);
496
- return e;
497
- }), s = J(r.min, `physicsJoints[${t}] limit.min on "${n}"`), c = J(r.max, `physicsJoints[${t}] limit.max on "${n}"`);
498
- if ((r.min !== void 0 || r.max !== void 0) && (s === void 0 || c === void 0)) throw new v(`physicsJoints[${t}].limits on "${n}" must specify both min and max`);
499
- if (s !== void 0 && c !== void 0 && s > c) throw new v(`physicsJoints[${t}] limit.min > limit.max on "${n}"`);
500
- let l = J(r.stiffness, `physicsJoints[${t}] limit.stiffness on "${n}"`, !0), u = J(r.damping, `physicsJoints[${t}] limit.damping on "${n}"`, !0), d = s !== void 0 && c !== void 0 && c - s <= 1e-6;
501
- if (!d && o.length > 1) throw new v(`physicsJoints[${t}] coupled multi-axis limit on "${n}" is unsupported`);
502
- for (let e of o) i[e] = d ? "locked" : s !== void 0 && c !== void 0 ? [s, c] : "unlimited", d || l === void 0 && u === void 0 || (a[e] = {
503
- ...l === void 0 ? {} : { stiffness: l },
504
- ...u === void 0 ? {} : { damping: u }
563
+ ], g = (t, i, a, o) => {
564
+ if (t === void 0) return;
565
+ if (!Array.isArray(t)) throw new e(`physicsJoints[${n}].limits axes on "${r}" must be an array`);
566
+ let s = t.map((t) => {
567
+ if (t !== 0 && t !== 1 && t !== 2) throw new e(`physicsJoints[${n}].limits invalid axis ${String(t)} on "${r}"`);
568
+ return t;
569
+ }), c = J(i.min, `physicsJoints[${n}] limit.min on "${r}"`), l = J(i.max, `physicsJoints[${n}] limit.max on "${r}"`);
570
+ if ((i.min !== void 0 || i.max !== void 0) && (c === void 0 || l === void 0)) throw new e(`physicsJoints[${n}].limits on "${r}" must specify both min and max`);
571
+ if (c !== void 0 && l !== void 0 && c > l) throw new e(`physicsJoints[${n}] limit.min > limit.max on "${r}"`);
572
+ let u = J(i.stiffness, `physicsJoints[${n}] limit.stiffness on "${r}"`, !0), d = J(i.damping, `physicsJoints[${n}] limit.damping on "${r}"`, !0), f = c !== void 0 && l !== void 0 && l - c <= 1e-6;
573
+ if (!f && s.length > 1) throw new e(`physicsJoints[${n}] coupled multi-axis limit on "${r}" is unsupported`);
574
+ for (let e of s) a[e] = f ? "locked" : c !== void 0 && l !== void 0 ? [c, l] : "unlimited", f || u === void 0 && d === void 0 || (o[e] = {
575
+ ...u === void 0 ? {} : { stiffness: u },
576
+ ...d === void 0 ? {} : { damping: d }
505
577
  });
506
578
  };
507
- for (let e of l) {
508
- if (!De(e)) throw new v(`physicsJoints[${t}].limits entry on "${n}" must be an object`);
509
- h(e.linearAxes, e, d, p), h(e.angularAxes, e, f, m);
579
+ for (let t of u) {
580
+ if (!Le(t)) throw new e(`physicsJoints[${n}].limits entry on "${r}" must be an object`);
581
+ g(t.linearAxes, t, f, m), g(t.angularAxes, t, p, h);
510
582
  }
511
- let g = [
583
+ let _ = [
512
584
  0,
513
585
  1,
514
586
  2
515
- ].filter((e) => d[e] !== "locked"), _ = [
587
+ ].filter((e) => f[e] !== "locked"), v = [
516
588
  0,
517
589
  1,
518
590
  2
519
- ].filter((e) => f[e] !== "locked"), y, b = [
591
+ ].filter((e) => p[e] !== "locked"), y, b = [
520
592
  0,
521
593
  1,
522
594
  0
523
595
  ], x = null, S;
524
- if (g.length === 0 && _.length === 0) y = "fixed";
525
- else if (g.length === 0 && _.length === 1) {
526
- y = "revolute", b = Ne(_[0]);
596
+ if (_.length === 0 && v.length === 0) y = "fixed";
597
+ else if (_.length === 0 && v.length === 1) {
598
+ y = "revolute", b = Ue(v[0]);
599
+ let e = p[v[0]];
600
+ x = Array.isArray(e) ? e : null, S = h[v[0]];
601
+ } else if (v.length === 0 && _.length === 1) {
602
+ y = "prismatic", b = Ue(_[0]);
527
603
  let e = f[_[0]];
528
604
  x = Array.isArray(e) ? e : null, S = m[_[0]];
529
- } else if (_.length === 0 && g.length === 1) {
530
- y = "prismatic", b = Ne(g[0]);
531
- let e = d[g[0]];
532
- x = Array.isArray(e) ? e : null, S = p[g[0]];
533
- } else throw new v(`physicsJoints[${t}] unsupported DOF (${g.length} lin, ${_.length} ang) on "${n}"`);
534
- let C = Pe(u, t, n), w = i.getWorldPosition(new j.Vector3()).sub(r.getWorldPosition(new j.Vector3())).applyQuaternion(r.getWorldQuaternion(new j.Quaternion()).invert());
605
+ } else throw new e(`physicsJoints[${n}] unsupported DOF (${_.length} lin, ${v.length} ang) on "${r}"`);
606
+ let C = We(d, n, r), w = a.getWorldPosition(new N.Vector3()).sub(i.getWorldPosition(new N.Vector3())).applyQuaternion(i.getWorldQuaternion(new N.Quaternion()).invert());
535
607
  return {
536
- index: t,
537
- nodeName: n,
538
- connectedNodeName: s,
608
+ index: n,
609
+ nodeName: r,
610
+ connectedNodeName: c,
539
611
  kind: y,
540
612
  axis: b,
541
613
  limits: x,
542
- enableCollision: a,
543
- role: o,
614
+ enableCollision: o,
615
+ role: s,
544
616
  ...S?.stiffness === void 0 ? {} : { limitStiffness: S.stiffness },
545
617
  ...S?.damping === void 0 ? {} : { limitDamping: S.damping },
546
618
  drive: C[0] ?? null,
@@ -559,187 +631,187 @@ function Fe(e, t, n, r, i, a, o, s = r.name) {
559
631
  }
560
632
  // src/khrPluginHelpers.ts
561
633
  var Y = (e) => typeof e == "object" && !!e && !Array.isArray(e);
562
- function X(e, t) {
563
- if (e === void 0) return [];
564
- if (!Array.isArray(e)) throw new v(`${t} must be an array`);
565
- return e;
634
+ function X(t, n) {
635
+ if (t === void 0) return [];
636
+ if (!Array.isArray(t)) throw new e(`${n} must be an array`);
637
+ return t;
566
638
  }
567
- function Ie() {
639
+ function Ke() {
568
640
  return (e) => ({
569
641
  name: "khr3_headless_texture",
570
642
  loadTexture(t) {
571
- let n = new j.Texture();
643
+ let n = new N.Texture();
572
644
  return n.flipY = !1, e.associations.set(n, { textures: t }), Promise.resolve(n);
573
645
  }
574
646
  });
575
647
  }
576
- function Le(e, t, n = e.parser?.json) {
577
- let r = new Int32Array(t.length).fill(-1);
578
- for (let e = 0; e < t.length; e++) {
579
- let n = t[e];
580
- if (!Y(n)) throw new v(`GLTF node[${e}] must be an object`);
581
- let r = typeof n.name == "string" && n.name.length > 0 ? n.name : e;
582
- if (n.children !== void 0) {
583
- if (!Array.isArray(n.children)) throw new v(`GLTF node "${r}" children must be an array`);
584
- for (let e of n.children) if (typeof e != "number" || !Number.isInteger(e) || e < 0 || e >= t.length) throw new v(`GLTF node "${r}" has out-of-bounds child index ${String(e)}`);
648
+ function qe(t, n, r = t.parser?.json) {
649
+ let i = new Int32Array(n.length).fill(-1);
650
+ for (let t = 0; t < n.length; t++) {
651
+ let r = n[t];
652
+ if (!Y(r)) throw new e(`GLTF node[${t}] must be an object`);
653
+ let i = typeof r.name == "string" && r.name.length > 0 ? r.name : t;
654
+ if (r.children !== void 0) {
655
+ if (!Array.isArray(r.children)) throw new e(`GLTF node "${i}" children must be an array`);
656
+ for (let t of r.children) if (typeof t != "number" || !Number.isInteger(t) || t < 0 || t >= n.length) throw new e(`GLTF node "${i}" has out-of-bounds child index ${String(t)}`);
585
657
  }
586
658
  }
587
- let i, a = /* @__PURE__ */ new Set();
588
- if (Array.isArray(n?.scenes)) {
589
- let e = n.scene ?? 0, r = n.scenes[e];
590
- if (!Y(r)) throw new v(`GLTF scene[${e}] must be an object`);
591
- if (r.nodes !== void 0 && !Array.isArray(r.nodes)) throw new v(`GLTF scene[${e}].nodes must be an array`);
592
- i = (r.nodes ?? []).map((n, r) => {
593
- if (typeof n != "number" || !Number.isInteger(n) || n < 0 || n >= t.length) throw new v(`GLTF scene[${e}].nodes[${r}] has invalid node index ${String(n)}`);
594
- return n;
659
+ let a, o = /* @__PURE__ */ new Set();
660
+ if (Array.isArray(r?.scenes)) {
661
+ let t = r.scene ?? 0, i = r.scenes[t];
662
+ if (!Y(i)) throw new e(`GLTF scene[${t}] must be an object`);
663
+ if (i.nodes !== void 0 && !Array.isArray(i.nodes)) throw new e(`GLTF scene[${t}].nodes must be an array`);
664
+ a = (i.nodes ?? []).map((r, i) => {
665
+ if (typeof r != "number" || !Number.isInteger(r) || r < 0 || r >= n.length) throw new e(`GLTF scene[${t}].nodes[${i}] has invalid node index ${String(r)}`);
666
+ return r;
595
667
  });
596
- let o = [...i];
597
- for (; o.length > 0;) {
598
- let e = o.pop();
599
- if (a.has(e)) continue;
600
- a.add(e);
601
- let n = t[e].children;
602
- if (n) for (let e of n) o.push(e);
668
+ let s = [...a];
669
+ for (; s.length > 0;) {
670
+ let e = s.pop();
671
+ if (o.has(e)) continue;
672
+ o.add(e);
673
+ let t = n[e].children;
674
+ if (t) for (let e of t) s.push(e);
603
675
  }
604
- } else for (let e = 0; e < t.length; e++) a.add(e);
605
- let o = i ? new Set(i) : void 0;
606
- for (let e of a) {
607
- let n = t[e].children;
608
- if (n) for (let i of n) {
609
- if (r[i] !== -1 || o?.has(i)) {
610
- let e = typeof t[i].name == "string" && t[i].name.length > 0 ? t[i].name : i;
611
- throw new v(`GLTF node "${e}" has multiple parents in active scene`);
676
+ } else for (let e = 0; e < n.length; e++) o.add(e);
677
+ let s = a ? new Set(a) : void 0;
678
+ for (let t of o) {
679
+ let r = n[t].children;
680
+ if (r) for (let a of r) {
681
+ if (i[a] !== -1 || s?.has(a)) {
682
+ let t = typeof n[a].name == "string" && n[a].name.length > 0 ? n[a].name : a;
683
+ throw new e(`GLTF node "${t}" has multiple parents in active scene`);
612
684
  }
613
- for (let n = e; n !== -1; n = r[n]) if (n === i) {
614
- let e = typeof t[i].name == "string" && t[i].name.length > 0 ? t[i].name : i;
615
- throw new v(`GLTF node "${e}" has cyclic parent in active scene`);
685
+ for (let r = t; r !== -1; r = i[r]) if (r === a) {
686
+ let t = typeof n[a].name == "string" && n[a].name.length > 0 ? n[a].name : a;
687
+ throw new e(`GLTF node "${t}" has cyclic parent in active scene`);
616
688
  }
617
- r[i] = e;
689
+ i[a] = t;
618
690
  }
619
691
  }
620
- let s = /* @__PURE__ */ new Set(), c = Array(t.length), l = (e, n) => {
621
- let r = t[e].name, i = typeof r == "string" && r.length > 0 ? r : `node_${e}`;
622
- if (n) {
623
- for (s.has(i) && (i = `${i}_${e}`); s.has(i);) i = `${i}_`;
624
- s.add(i);
692
+ let c = /* @__PURE__ */ new Set(), l = Array(n.length), u = (e, t) => {
693
+ let r = n[e].name, i = typeof r == "string" && r.length > 0 ? r : `node_${e}`;
694
+ if (t) {
695
+ for (c.has(i) && (i = `${i}_${e}`); c.has(i);) i = `${i}_`;
696
+ c.add(i);
625
697
  }
626
- c[e] = i;
698
+ l[e] = i;
627
699
  };
628
- for (let e = 0; e < t.length; e++) a.has(e) && l(e, !0);
629
- for (let e = 0; e < t.length; e++) a.has(e) || l(e, !1);
630
- let u = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map();
631
- if (e.scene.traverse((t) => {
632
- let n = e.parser?.associations?.get(t)?.nodes;
633
- typeof n == "number" && a.has(n) && !u.has(n) && u.set(n, t), t.name && !d.has(t.name) && d.set(t.name, t);
634
- }), i && e.scene.children.length === i.length) {
635
- let n = /* @__PURE__ */ new Set(), r = (e, i) => {
636
- if (n.has(e)) return;
637
- n.add(e), u.has(e) || u.set(e, i);
638
- let a = t[e].children;
700
+ for (let e = 0; e < n.length; e++) o.has(e) && u(e, !0);
701
+ for (let e = 0; e < n.length; e++) o.has(e) || u(e, !1);
702
+ let d = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map();
703
+ if (t.scene.traverse((e) => {
704
+ let n = t.parser?.associations?.get(e)?.nodes;
705
+ typeof n == "number" && o.has(n) && !d.has(n) && d.set(n, e), e.name && !f.has(e.name) && f.set(e.name, e);
706
+ }), a && t.scene.children.length === a.length) {
707
+ let e = /* @__PURE__ */ new Set(), r = (t, i) => {
708
+ if (e.has(t)) return;
709
+ e.add(t), d.has(t) || d.set(t, i);
710
+ let a = n[t].children;
639
711
  if (!a || a.length === 0) return;
640
712
  let o = i.children.length - a.length;
641
713
  if (!(o < 0)) for (let e = 0; e < a.length; e++) r(a[e], i.children[o + e]);
642
714
  };
643
- for (let t = 0; t < i.length; t++) r(i[t], e.scene.children[t]);
715
+ for (let e = 0; e < a.length; e++) r(a[e], t.scene.children[e]);
644
716
  }
645
717
  return {
646
- parentIdx: r,
647
- nodeNames: c,
648
- resolveObj: (n) => {
649
- if (n < 0 || n >= t.length || !a.has(n)) return;
650
- let r = u.get(n);
718
+ parentIdx: i,
719
+ nodeNames: l,
720
+ resolveObj: (e) => {
721
+ if (e < 0 || e >= n.length || !o.has(e)) return;
722
+ let r = d.get(e);
651
723
  if (r) return r;
652
- let i = c[n], o = j.PropertyBinding.sanitizeNodeName(i);
653
- return d.get(i) ?? d.get(o) ?? e.scene.getObjectByName(i);
724
+ let i = l[e], a = N.PropertyBinding.sanitizeNodeName(i);
725
+ return f.get(i) ?? f.get(a) ?? t.scene.getObjectByName(i);
654
726
  }
655
727
  };
656
728
  }
657
- function Re(e, t, n, r, i) {
658
- if (!Y(e)) throw new v(`Node "${t}" has invalid collider (expected object)`);
659
- let a = e.geometry;
660
- if (!Y(a)) throw new v(`Node "${t}" is missing collider.geometry object`);
661
- if (a.shape !== void 0) {
662
- if (typeof a.shape != "number" || !Number.isInteger(a.shape) || a.shape < 0 || a.shape >= n.length) throw new v(`Node "${t}" references missing collider.geometry.shape ${String(a.shape)}`);
663
- return n[a.shape];
729
+ function Je(t, n, r, i, a) {
730
+ if (!Y(t)) throw new e(`Node "${n}" has invalid collider (expected object)`);
731
+ let o = t.geometry;
732
+ if (!Y(o)) throw new e(`Node "${n}" is missing collider.geometry object`);
733
+ if (o.shape !== void 0) {
734
+ if (typeof o.shape != "number" || !Number.isInteger(o.shape) || o.shape < 0 || o.shape >= r.length) throw new e(`Node "${n}" references missing collider.geometry.shape ${String(o.shape)}`);
735
+ return r[o.shape];
664
736
  }
665
- if (a.node !== void 0) {
666
- if (typeof a.node != "number" || !Number.isInteger(a.node)) throw new v(`Node "${t}" has invalid collider.geometry.node`);
667
- if (a.convexHull !== void 0 && typeof a.convexHull != "boolean") throw new v(`Node "${t}" has non-boolean collider.geometry.convexHull`);
668
- let e = i(a.node), n = r[a.node] ?? `node_${a.node}`;
669
- if (!e) throw new v(`Node "${t}" references missing mesh node "${n}"`);
670
- return o(e, n, !!a.convexHull);
737
+ if (o.node !== void 0) {
738
+ if (typeof o.node != "number" || !Number.isInteger(o.node)) throw new e(`Node "${n}" has invalid collider.geometry.node`);
739
+ if (o.convexHull !== void 0 && typeof o.convexHull != "boolean") throw new e(`Node "${n}" has non-boolean collider.geometry.convexHull`);
740
+ let t = a(o.node), r = i[o.node] ?? `node_${o.node}`;
741
+ if (!t) throw new e(`Node "${n}" references missing mesh node "${r}"`);
742
+ return l(t, r, !!o.convexHull);
671
743
  }
672
- throw new v(`Node "${t}" collider.geometry must specify shape or node`);
744
+ throw new e(`Node "${n}" collider.geometry must specify shape or node`);
673
745
  }
674
746
  // src/khrPlugin.ts
675
- var ze = "khrBundle";
676
- function Be(t, n) {
677
- if (!t.scene) throw new v("GLTF asset has no active scene");
678
- t.scene.updateMatrixWorld(!0), i(t.scene);
679
- let r = t.parser?.json;
680
- if (!r) throw new v("GLTFParser is missing parsed JSON");
681
- if (r.extensions !== void 0 && !Y(r.extensions)) throw new v("glTF extensions must be an object");
682
- let a = r.extensions?.KHR_physics_rigid_bodies;
683
- if (a !== void 0 && !Y(a)) throw new v("KHR_physics_rigid_bodies extension must be an object");
684
- let o = r.extensions?.KHR_implicit_shapes;
685
- if (o !== void 0 && !Y(o)) throw new v("KHR_implicit_shapes extension must be an object");
686
- let c = X(o?.shapes, "KHR_implicit_shapes.shapes").map((e, t) => ke(e, t)), u = X(a?.physicsMaterials, "KHR_physics_rigid_bodies.physicsMaterials"), d = Me(X(a?.collisionFilters, "KHR_physics_rigid_bodies.collisionFilters")), p = X(a?.physicsJoints, "KHR_physics_rigid_bodies.physicsJoints"), m = X(r.nodes, "glTF nodes"), { parentIdx: h, nodeNames: g, resolveObj: _ } = Le(t, m, r), y = [], b = {};
747
+ var Ye = "khrBundle";
748
+ function Xe(t, n) {
749
+ if (!t.scene) throw new e("GLTF asset has no active scene");
750
+ t.scene.updateMatrixWorld(!0), s(t.scene);
751
+ let i = t.parser?.json;
752
+ if (!i) throw new e("GLTFParser is missing parsed JSON");
753
+ if (i.extensions !== void 0 && !Y(i.extensions)) throw new e("glTF extensions must be an object");
754
+ let a = i.extensions?.KHR_physics_rigid_bodies;
755
+ if (a !== void 0 && !Y(a)) throw new e("KHR_physics_rigid_bodies extension must be an object");
756
+ let o = i.extensions?.KHR_implicit_shapes;
757
+ 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) => ze(e, t)), l = X(a?.physicsMaterials, "KHR_physics_rigid_bodies.physicsMaterials"), d = He(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 } = qe(t, m, i), y = [], b = {};
687
759
  for (let e = 0; e < m.length; e++) {
688
- let t = _(e);
760
+ let t = v(e);
689
761
  if (!t) continue;
690
762
  let r = Y(m[e].extras) ? m[e].extras : {};
691
- y.push(Se(t, g[e], r, b, n?.isSocketNode));
763
+ y.push(Me(t, _[e], r, b, n?.isSocketNode));
692
764
  }
693
- let x = [], S = [], C = /* @__PURE__ */ new Map(), w = /* @__PURE__ */ new Set(), T = [], E = [], D = (e) => {
694
- for (let t = h[e]; t !== -1; t = h[t]) if (m[t].extensions?.KHR_physics_rigid_bodies?.motion) return t;
765
+ let x = [], S = [], C = /* @__PURE__ */ new Map(), w = /* @__PURE__ */ new Set(), T = [], ee = [], E = (e) => {
766
+ for (let t = g[e]; t !== -1; t = g[t]) if (m[t].extensions?.KHR_physics_rigid_bodies?.motion) return t;
695
767
  return -1;
696
- }, O = (e) => {
697
- for (let t = e; t !== -1; t = h[t]) {
768
+ }, D = (e) => {
769
+ for (let t = e; t !== -1; t = g[t]) {
698
770
  let e = m[t].extras;
699
771
  if (Y(e) && (e.ecctrlWheel !== void 0 || e.ecctrlPropeller !== void 0)) return !0;
700
772
  }
701
773
  return !1;
702
774
  };
703
- for (let e = 0; e < m.length; e++) {
704
- let r = m[e], i = g[e], a = _(e);
705
- if (!a) continue;
706
- let o = Y(r.extras) ? r.extras : {};
707
- if (o.ecctrlWheel !== void 0 || o.ecctrlPropeller !== void 0) {
708
- if (h[e] !== -1 && O(h[e])) throw new v(`Nested rotor "${i}" inside detached rotor is unsupported`);
709
- o.ecctrlWheel === void 0 ? E.push(we(a, i, o.ecctrlPropeller, t.scene)) : T.push(Ce(a, i, o.ecctrlWheel, t.scene));
775
+ for (let r = 0; r < m.length; r++) {
776
+ let i = m[r], a = _[r], o = v(r);
777
+ if (!o) continue;
778
+ let s = Y(i.extras) ? i.extras : {};
779
+ if (s.ecctrlWheel !== void 0 || s.ecctrlPropeller !== void 0) {
780
+ if (g[r] !== -1 && D(g[r])) throw new e(`Nested rotor "${a}" inside detached rotor is unsupported`);
781
+ s.ecctrlWheel === void 0 ? ee.push(Pe(o, a, s.ecctrlPropeller, t.scene)) : T.push(Ne(o, a, s.ecctrlWheel, t.scene));
710
782
  continue;
711
783
  }
712
- if (O(e)) continue;
713
- let s = r.extensions?.KHR_physics_rigid_bodies;
714
- if (s === void 0) continue;
715
- if (!Y(s)) throw new v(`Node "${i}" has invalid KHR_physics_rigid_bodies`);
716
- if (s.motion === void 0 && s.collider === void 0 && s.joint === void 0) continue;
717
- if (s.motion === void 0 && D(e) !== -1) {
718
- if (s.joint !== void 0) throw new v(`Node "${i}" has joint without motion`);
784
+ if (D(r)) continue;
785
+ let c = i.extensions?.KHR_physics_rigid_bodies;
786
+ if (c === void 0) continue;
787
+ if (!Y(c)) throw new e(`Node "${a}" has invalid KHR_physics_rigid_bodies`);
788
+ if (c.motion === void 0 && c.collider === void 0 && c.joint === void 0) continue;
789
+ if (c.motion === void 0 && E(r) !== -1) {
790
+ if (c.joint !== void 0) throw new e(`Node "${a}" has joint without motion`);
719
791
  continue;
720
792
  }
721
- if (s.motion !== void 0 && !Y(s.motion)) throw new v(`Node "${i}" has invalid motion`);
722
- let { hasExplicitInertia: c, ...l } = je(s.motion ?? {}, s.motion !== void 0, i);
723
- c && w.add(e);
724
- let u = n?.extractRole?.(i, o) ?? (typeof o.role == "string" ? o.role : null), d = null;
725
- if (s.joint !== void 0) {
726
- if (!Y(s.joint)) throw new v(`Node "${i}" has invalid joint`);
727
- let e = s.joint;
728
- if (typeof e.joint != "number" || !Number.isInteger(e.joint)) throw new v(`Joint on "${i}" is missing numeric joint index`);
729
- if (typeof e.connectedNode != "number" || !Number.isInteger(e.connectedNode)) throw new v(`Joint on "${i}" is missing numeric connectedNode index`);
730
- if (e.enableCollision !== void 0 && typeof e.enableCollision != "boolean") throw new v(`Joint on "${i}" has non-boolean enableCollision`);
731
- let t = e.connectedNode, n = g[t] ?? `node_${t}`, r = _(t);
732
- if (!r) throw new v(`Joint on "${i}" targets missing connectedNode "${n}"`);
733
- if (O(t)) throw new v(`Joint on "${i}" cannot target detached rotor "${n}"`);
734
- d = Fe(p, e.joint, i, r, a, !!e.enableCollision, u, n);
793
+ if (c.motion !== void 0 && !Y(c.motion)) throw new e(`Node "${a}" has invalid motion`);
794
+ let { hasExplicitInertia: l, ...u } = Ve(c.motion ?? {}, c.motion !== void 0, a);
795
+ l && w.add(r);
796
+ let d = n?.extractRole?.(a, s) ?? (typeof s.role == "string" ? s.role : null), f = null;
797
+ if (c.joint !== void 0) {
798
+ if (!Y(c.joint)) throw new e(`Node "${a}" has invalid joint`);
799
+ let t = c.joint;
800
+ if (typeof t.joint != "number" || !Number.isInteger(t.joint)) throw new e(`Joint on "${a}" is missing numeric joint index`);
801
+ if (typeof t.connectedNode != "number" || !Number.isInteger(t.connectedNode)) throw new e(`Joint on "${a}" is missing numeric connectedNode index`);
802
+ if (t.enableCollision !== void 0 && typeof t.enableCollision != "boolean") throw new e(`Joint on "${a}" has non-boolean enableCollision`);
803
+ let n = t.connectedNode, r = _[n] ?? `node_${n}`, i = v(n);
804
+ if (!i) throw new e(`Joint on "${a}" targets missing connectedNode "${r}"`);
805
+ if (D(n)) throw new e(`Joint on "${a}" cannot target detached rotor "${r}"`);
806
+ f = Ge(p, t.joint, a, i, o, !!t.enableCollision, d, r);
735
807
  }
736
- let f = a.getWorldPosition(new j.Vector3()), y = a.getWorldQuaternion(new j.Quaternion()), b = {
737
- nodeName: i,
738
- ...l,
808
+ let h = o.getWorldPosition(new N.Vector3()), y = o.getWorldQuaternion(new N.Quaternion()), b = {
809
+ nodeName: a,
810
+ ...u,
739
811
  localPosition: [
740
- f.x,
741
- f.y,
742
- f.z
812
+ h.x,
813
+ h.y,
814
+ h.z
743
815
  ],
744
816
  localQuaternion: [
745
817
  y.x,
@@ -748,24 +820,24 @@ function Be(t, n) {
748
820
  y.w
749
821
  ],
750
822
  colliders: [],
751
- joint: d,
752
- object: a,
753
- role: u
823
+ joint: f,
824
+ object: o,
825
+ role: d
754
826
  };
755
827
  x.push(b), S.push({
756
- nodeName: i,
757
- extras: o
758
- }), C.set(e, b);
828
+ nodeName: a,
829
+ extras: s
830
+ }), C.set(r, b);
759
831
  }
760
- for (let e = 0; e < m.length; e++) {
761
- if (O(e)) continue;
762
- let t = m[e].extensions?.KHR_physics_rigid_bodies?.collider;
763
- if (t === void 0) continue;
764
- let n = _(e);
765
- if (!n) continue;
766
- let r = C.has(e) ? e : D(e), i = C.get(r);
767
- if (!i) continue;
768
- let a = Re(t, g[e], c, g, _), o = t, l = r === e ? {
832
+ for (let t = 0; t < m.length; t++) {
833
+ if (D(t)) continue;
834
+ let n = m[t].extensions?.KHR_physics_rigid_bodies?.collider;
835
+ if (n === void 0) continue;
836
+ let r = v(t);
837
+ if (!r) continue;
838
+ let i = C.has(t) ? t : E(t), a = C.get(i);
839
+ if (!a) continue;
840
+ let o = Je(n, _[t], c, _, v), s = n, f = i === t ? {
769
841
  localPosition: [
770
842
  0,
771
843
  0,
@@ -777,144 +849,144 @@ function Be(t, n) {
777
849
  0,
778
850
  1
779
851
  ]
780
- } : s(i.object, n), f = Ae(u, o.physicsMaterial, g[e]), p;
781
- if (o.collisionFilter !== void 0) {
782
- if (typeof o.collisionFilter != "number" || !Number.isInteger(o.collisionFilter) || o.collisionFilter < 0 || o.collisionFilter >= d.length) throw new v(`Node "${g[e]}" references out-of-bounds collisionFilter ${String(o.collisionFilter)}`);
783
- p = d[o.collisionFilter];
852
+ } : u(a.object, r), p = Be(l, s.physicsMaterial, _[t]), h;
853
+ if (s.collisionFilter !== void 0) {
854
+ 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
+ h = d[s.collisionFilter];
784
856
  }
785
- i.colliders.push({
786
- shape: a,
787
- localPosition: l.localPosition,
788
- localQuaternion: l.localQuaternion,
789
- ...f,
790
- ...p === void 0 ? {} : { collisionGroups: p }
857
+ a.colliders.push({
858
+ shape: o,
859
+ localPosition: f.localPosition,
860
+ localQuaternion: f.localQuaternion,
861
+ ...p,
862
+ ...h === void 0 ? {} : { collisionGroups: h }
791
863
  });
792
864
  }
793
- for (let [e, t] of C) w.has(e) || t.isKinematic || (t.inertiaDiagonal = l(t.colliders, t.mass, t.centerOfMass, t.inertiaOrientation, t.nodeName));
794
- let { totalDynamicMass: k, centerOfMass: A } = f(x), M = [], N = r.scenes?.[r.scene ?? 0]?.extras ?? r.extras;
795
- if (N?.ikSockets !== void 0) {
796
- if (!Y(N.ikSockets)) throw new v("scene.extras.ikSockets must be an object");
797
- for (let [t, n] of Object.entries(N.ikSockets)) {
798
- let r = e(n, `scene.extras.ikSockets.${t}`);
799
- b[t] = r, M.push([t, r]);
865
+ 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: te } = h(x), k = [], A = i.scenes?.[i.scene ?? 0]?.extras ?? i.extras;
867
+ if (A?.ikSockets !== void 0) {
868
+ if (!Y(A.ikSockets)) throw new e("scene.extras.ikSockets must be an object");
869
+ for (let [e, t] of Object.entries(A.ikSockets)) {
870
+ let n = r(t, `scene.extras.ikSockets.${e}`);
871
+ b[e] = n, k.push([e, n]);
800
872
  }
801
873
  }
802
- let P = Y(N?.tune) ? N.tune : void 0, F = Y(N?.droneTune) ? N.droneTune : void 0;
803
- return _e(t.scene, {
874
+ let j = Y(A?.tune) ? A.tune : void 0, M = Y(A?.droneTune) ? A.droneTune : void 0;
875
+ return Te(t.scene, {
804
876
  nodes: y,
805
877
  bodies: S,
806
- ikSockets: M
878
+ ikSockets: k
807
879
  }), {
808
880
  scene: t.scene,
809
881
  bodies: x,
810
882
  wheels: T,
811
- propellers: E,
883
+ propellers: ee,
812
884
  sockets: b,
813
- totalDynamicMass: k,
814
- centerOfMass: A,
815
- tune: P,
816
- droneTune: F
885
+ totalDynamicMass: O,
886
+ centerOfMass: te,
887
+ tune: j,
888
+ droneTune: M
817
889
  };
818
890
  }
819
- function Ve(e) {
891
+ function Ze(e) {
820
892
  let t = typeof document > "u" && typeof createImageBitmap > "u";
821
893
  return (n) => ({
822
894
  name: "KHR_physics_rigid_bodies",
823
895
  ...t ? { loadTexture(e) {
824
- let t = new j.Texture();
896
+ let t = new N.Texture();
825
897
  return t.flipY = !1, n.associations.set(t, { textures: e }), Promise.resolve(t);
826
898
  } } : {},
827
899
  afterRoot(t) {
828
- return t.userData[ze] = Be(t, e), null;
900
+ return t.userData[Ye] = Xe(t, e), null;
829
901
  }
830
902
  });
831
903
  }
832
904
  // src/khrLoader.ts
833
- var He = Ie();
834
- function Ue() {
835
- let e = new P();
836
- return typeof document > "u" && typeof createImageBitmap > "u" && e.register(He), e;
905
+ var Qe = Ke();
906
+ function $e() {
907
+ let e = new I();
908
+ return typeof document > "u" && typeof createImageBitmap > "u" && e.register(Qe), e;
837
909
  }
838
- async function We(e, t) {
839
- let n = e instanceof Uint8Array ? e : new Uint8Array(e), r = new ArrayBuffer(n.byteLength);
840
- new Uint8Array(r).set(n), fe(r);
841
- let i = t?.loader ?? Ue(), a = Ve(t);
842
- i.register(a);
910
+ async function et(t, n) {
911
+ let r = t instanceof Uint8Array ? t : new Uint8Array(t), i = new ArrayBuffer(r.byteLength);
912
+ new Uint8Array(i).set(r), be(i);
913
+ let a = n?.loader ?? $e(), o = Ze(n);
914
+ a.register(o);
843
915
  try {
844
- let e = (e) => e instanceof v ? e : new v(e instanceof Error ? e.message : "Failed to parse GLB"), t = (await new Promise((t, n) => {
845
- i.parse(r, "", t, (t) => n(e(t)));
846
- }).catch((t) => {
847
- throw e(t);
848
- })).userData[ze];
849
- if (!t) throw new v("Missing parsed KHR bundle on GLTF userData");
850
- return t;
916
+ 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
+ a.parse(i, "", e, (e) => n(t(e)));
918
+ }).catch((e) => {
919
+ throw t(e);
920
+ })).userData[Ye];
921
+ if (!n) throw new e("Missing parsed KHR bundle on GLTF userData");
922
+ return n;
851
923
  } finally {
852
- i.unregister(a);
924
+ a.unregister(o);
853
925
  }
854
926
  }
855
927
  // src/khrExporter.ts
856
928
  var Z = (e) => typeof e == "number" && Number.isFinite(e) && e > 0;
857
- function Q(e, t, n = !1) {
858
- if (e !== void 0) {
859
- if (typeof e != "number" || !Number.isFinite(e) || n && e < 0) throw new v(`exportKhrGlb: ${t} must be finite${n ? " >= 0" : ""}`);
860
- return e;
929
+ function Q(t, n, r = !1) {
930
+ if (t !== void 0) {
931
+ if (typeof t != "number" || !Number.isFinite(t) || r && t < 0) throw new e(`exportKhrGlb: ${n} must be finite${r ? " >= 0" : ""}`);
932
+ return t;
861
933
  }
862
934
  }
863
- function Ge(e, t) {
864
- if (e.type === "box") {
865
- if (!Array.isArray(e.size) || e.size.length !== 3 || !e.size.every(Z)) throw new v(`exportKhrGlb: invalid box.size on "${t}"`);
935
+ function tt(t, n) {
936
+ if (t.type === "box") {
937
+ if (!Array.isArray(t.size) || t.size.length !== 3 || !t.size.every(Z)) throw new e(`exportKhrGlb: invalid box.size on "${n}"`);
866
938
  return {
867
939
  type: "box",
868
- box: { size: e.size }
940
+ box: { size: t.size }
869
941
  };
870
942
  }
871
- if (e.type === "sphere") {
872
- if (!Z(e.radius)) throw new v(`exportKhrGlb: invalid sphere.radius on "${t}"`);
943
+ if (t.type === "sphere") {
944
+ if (!Z(t.radius)) throw new e(`exportKhrGlb: invalid sphere.radius on "${n}"`);
873
945
  return {
874
946
  type: "sphere",
875
- sphere: { radius: e.radius }
947
+ sphere: { radius: t.radius }
876
948
  };
877
949
  }
878
- if (!Z(e.height) || !Z(e.radiusTop) || !Z(e.radiusBottom)) throw new v(`exportKhrGlb: invalid ${e.type} dimensions on "${t}"`);
879
- if (Math.abs(e.radiusTop - e.radiusBottom) > 1e-6) throw new v(`exportKhrGlb: tapered ${e.type} (${e.radiusTop} !== ${e.radiusBottom}) on "${t}" is unsupported`);
950
+ if (!Z(t.height) || !Z(t.radiusTop) || !Z(t.radiusBottom)) throw new e(`exportKhrGlb: invalid ${t.type} dimensions on "${n}"`);
951
+ if (Math.abs(t.radiusTop - t.radiusBottom) > 1e-6) throw new e(`exportKhrGlb: tapered ${t.type} (${t.radiusTop} !== ${t.radiusBottom}) on "${n}" is unsupported`);
880
952
  return {
881
- type: e.type,
882
- [e.type]: {
883
- height: e.height,
884
- radiusTop: e.radiusTop,
885
- radiusBottom: e.radiusBottom
953
+ type: t.type,
954
+ [t.type]: {
955
+ height: t.height,
956
+ radiusTop: t.radiusTop,
957
+ radiusBottom: t.radiusBottom
886
958
  }
887
959
  };
888
960
  }
889
- function Ke(e, t, n) {
890
- if (!Array.isArray(e) || e.length !== 3 || !e.every((e) => typeof e == "number" && Number.isFinite(e))) throw new v(`exportKhrGlb: ${t} joint on "${n}" requires a finite axis`);
891
- let r = Math.abs(e[0]), i = Math.abs(e[1]), a = Math.abs(e[2]);
892
- if (Math.hypot(r, i, a) <= 1e-8) throw new v(`exportKhrGlb: ${t} joint on "${n}" requires non-zero axis`);
893
- return r >= i && r >= a ? 0 : i >= a ? 1 : 2;
961
+ function nt(t, n, r) {
962
+ 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
+ let i = Math.abs(t[0]), a = Math.abs(t[1]), o = Math.abs(t[2]);
964
+ if (Math.hypot(i, a, o) <= 1e-8) throw new e(`exportKhrGlb: ${n} joint on "${r}" requires non-zero axis`);
965
+ return i >= a && i >= o ? 0 : a >= o ? 1 : 2;
894
966
  }
895
- function qe(e, t, n, r) {
896
- if (!e || typeof e != "object" || Array.isArray(e)) throw new v(`exportKhrGlb: joint drive on "${r}" must be an object`);
897
- if (e.mode !== "force" && e.mode !== "acceleration") throw new v(`exportKhrGlb: joint drive on "${r}" requires drive.mode ("force" | "acceleration")`);
898
- if (e.type !== void 0 && e.type !== "linear" && e.type !== "angular") throw new v(`exportKhrGlb: joint drive on "${r}" has invalid drive.type`);
899
- if (e.axis !== void 0 && e.axis !== 0 && e.axis !== 1 && e.axis !== 2) throw new v(`exportKhrGlb: joint drive on "${r}" has invalid drive.axis`);
900
- let i = Q(e.positionTarget, `joint drive.positionTarget on "${r}"`), a = Q(e.velocityTarget, `joint drive.velocityTarget on "${r}"`);
901
- if (i === void 0 && a === void 0) throw new v(`exportKhrGlb: joint drive on "${r}" requires finite positionTarget or velocityTarget`);
902
- let o = Q(e.stiffness, `joint drive.stiffness on "${r}"`, !0), s = Q(e.damping, `joint drive.damping on "${r}"`, !0), c = Q(e.maxForce, `joint drive.maxForce on "${r}"`, !0);
967
+ function rt(t, n, r, i) {
968
+ if (!t || typeof t != "object" || Array.isArray(t)) throw new e(`exportKhrGlb: joint drive on "${i}" must be an object`);
969
+ if (t.mode !== "force" && t.mode !== "acceleration") throw new e(`exportKhrGlb: joint drive on "${i}" requires drive.mode ("force" | "acceleration")`);
970
+ if (t.type !== void 0 && t.type !== "linear" && t.type !== "angular") throw new e(`exportKhrGlb: joint drive on "${i}" has invalid drive.type`);
971
+ if (t.axis !== void 0 && t.axis !== 0 && t.axis !== 1 && t.axis !== 2) throw new e(`exportKhrGlb: joint drive on "${i}" has invalid drive.axis`);
972
+ let a = Q(t.positionTarget, `joint drive.positionTarget on "${i}"`), o = Q(t.velocityTarget, `joint drive.velocityTarget on "${i}"`);
973
+ if (a === void 0 && o === void 0) throw new e(`exportKhrGlb: joint drive on "${i}" requires finite positionTarget or velocityTarget`);
974
+ let s = Q(t.stiffness, `joint drive.stiffness on "${i}"`, !0), c = Q(t.damping, `joint drive.damping on "${i}"`, !0), l = Q(t.maxForce, `joint drive.maxForce on "${i}"`, !0);
903
975
  return {
904
- type: e.type ?? t,
905
- mode: e.mode,
906
- axis: e.axis ?? n,
907
- ...i === void 0 ? {} : { positionTarget: i },
908
- ...a === void 0 ? {} : { velocityTarget: a },
909
- ...o === void 0 ? {} : { stiffness: o },
910
- ...s === void 0 ? {} : { damping: s },
911
- ...c === void 0 ? {} : { maxForce: c }
976
+ type: t.type ?? n,
977
+ mode: t.mode,
978
+ axis: t.axis ?? r,
979
+ ...a === void 0 ? {} : { positionTarget: a },
980
+ ...o === void 0 ? {} : { velocityTarget: o },
981
+ ...s === void 0 ? {} : { stiffness: s },
982
+ ...c === void 0 ? {} : { damping: c },
983
+ ...l === void 0 ? {} : { maxForce: l }
912
984
  };
913
985
  }
914
- function Je(e, t) {
915
- if (e.kind !== "fixed" && e.kind !== "revolute" && e.kind !== "prismatic") throw new v(`exportKhrGlb: invalid joint.kind "${String(e.kind)}" on "${t}"`);
916
- if (e.kind === "fixed") {
917
- if (e.drive || e.drives && e.drives.length > 0) throw new v(`exportKhrGlb: fixed joint on "${t}" cannot define drives`);
986
+ function it(t, n) {
987
+ if (t.kind !== "fixed" && t.kind !== "revolute" && t.kind !== "prismatic") throw new e(`exportKhrGlb: invalid joint.kind "${String(t.kind)}" on "${n}"`);
988
+ if (t.kind === "fixed") {
989
+ if (t.drive || t.drives && t.drives.length > 0) throw new e(`exportKhrGlb: fixed joint on "${n}" cannot define drives`);
918
990
  return { limits: [{
919
991
  linearAxes: [
920
992
  0,
@@ -933,21 +1005,21 @@ function Je(e, t) {
933
1005
  max: 0
934
1006
  }] };
935
1007
  }
936
- let n = Ke(e.axis, e.kind, t), r = [
1008
+ let r = nt(t.axis, t.kind, n), i = [
937
1009
  0,
938
1010
  1,
939
1011
  2
940
- ].filter((e) => e !== n);
941
- if (e.limits && (!Number.isFinite(e.limits[0]) || !Number.isFinite(e.limits[1]) || e.limits[0] > e.limits[1])) throw new v(`exportKhrGlb: joint on "${t}" has invalid joint.limits`);
942
- let i = Q(e.limitStiffness, `joint.limitStiffness on "${t}"`, !0), a = Q(e.limitDamping, `joint.limitDamping on "${t}"`, !0), o = e.kind === "revolute" ? "angularAxes" : "linearAxes", s = e.limits || i !== void 0 || a !== void 0 ? [{
943
- [o]: [n],
944
- ...e.limits ? {
945
- min: e.limits[0],
946
- max: e.limits[1]
1012
+ ].filter((e) => e !== r);
1013
+ if (t.limits && (!Number.isFinite(t.limits[0]) || !Number.isFinite(t.limits[1]) || t.limits[0] > t.limits[1])) throw new e(`exportKhrGlb: joint on "${n}" has invalid joint.limits`);
1014
+ let a = Q(t.limitStiffness, `joint.limitStiffness on "${n}"`, !0), o = Q(t.limitDamping, `joint.limitDamping on "${n}"`, !0), s = t.kind === "revolute" ? "angularAxes" : "linearAxes", c = t.limits || a !== void 0 || o !== void 0 ? [{
1015
+ [s]: [r],
1016
+ ...t.limits ? {
1017
+ min: t.limits[0],
1018
+ max: t.limits[1]
947
1019
  } : {},
948
- ...i === void 0 ? {} : { stiffness: i },
949
- ...a === void 0 ? {} : { damping: a }
950
- }] : [], c = { limits: e.kind === "revolute" ? [
1020
+ ...a === void 0 ? {} : { stiffness: a },
1021
+ ...o === void 0 ? {} : { damping: o }
1022
+ }] : [], l = { limits: t.kind === "revolute" ? [
951
1023
  {
952
1024
  linearAxes: [
953
1025
  0,
@@ -958,11 +1030,11 @@ function Je(e, t) {
958
1030
  max: 0
959
1031
  },
960
1032
  {
961
- angularAxes: r,
1033
+ angularAxes: i,
962
1034
  min: 0,
963
1035
  max: 0
964
1036
  },
965
- ...s
1037
+ ...c
966
1038
  ] : [
967
1039
  {
968
1040
  angularAxes: [
@@ -974,126 +1046,125 @@ function Je(e, t) {
974
1046
  max: 0
975
1047
  },
976
1048
  {
977
- linearAxes: r,
1049
+ linearAxes: i,
978
1050
  min: 0,
979
1051
  max: 0
980
1052
  },
981
- ...s
982
- ] }, l = e.drives ?? (e.drive ? [e.drive] : []);
983
- return l.length > 0 && (c.drives = l.map((r) => qe(r, e.kind === "revolute" ? "angular" : "linear", n, t))), c;
1053
+ ...c
1054
+ ] }, u = t.drives ?? (t.drive ? [t.drive] : []);
1055
+ return u.length > 0 && (l.drives = u.map((e) => rt(e, t.kind === "revolute" ? "angular" : "linear", r, n))), l;
984
1056
  }
985
- function Ye(t, n) {
986
- let r = !!t.isKinematic;
987
- if (!r && !Z(t.mass)) throw new v(`exportKhrGlb: dynamic node "${n}" requires positive finite motion.mass`);
988
- if (r && t.mass !== void 0 && Q(t.mass, `kinematic motion.mass on "${n}"`, !0), t.inertiaDiagonal && e(t.inertiaDiagonal, `${n}.motion.inertiaDiagonal`).some((e) => r ? e < 0 : e <= 0)) throw new v(`exportKhrGlb: invalid motion.inertiaDiagonal on "${n}"`);
989
- if (t.gravityFactor !== void 0 && (typeof t.gravityFactor != "number" || !Number.isFinite(t.gravityFactor))) throw new v(`exportKhrGlb: invalid motion.gravityFactor on "${n}"`);
1057
+ function at(t, n) {
1058
+ let i = !!t.isKinematic;
1059
+ if (!i && !Z(t.mass)) throw new e(`exportKhrGlb: dynamic node "${n}" requires positive finite motion.mass`);
1060
+ 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}"`);
1061
+ if (t.gravityFactor !== void 0 && (typeof t.gravityFactor != "number" || !Number.isFinite(t.gravityFactor))) throw new e(`exportKhrGlb: invalid motion.gravityFactor on "${n}"`);
990
1062
  return {
991
- isKinematic: r,
1063
+ isKinematic: i,
992
1064
  ...t.mass === void 0 ? {} : { mass: t.mass },
993
- ...t.centerOfMass ? { centerOfMass: e(t.centerOfMass, `${n}.motion.centerOfMass`) } : {},
1065
+ ...t.centerOfMass ? { centerOfMass: r(t.centerOfMass, `${n}.motion.centerOfMass`) } : {},
994
1066
  ...t.inertiaDiagonal ? { inertiaDiagonal: t.inertiaDiagonal } : {},
995
- ...t.inertiaOrientation ? { inertiaOrientation: _(t.inertiaOrientation, `${n}.motion.inertiaOrientation`) } : {},
996
- ...t.linearVelocity ? { linearVelocity: e(t.linearVelocity, `${n}.motion.linearVelocity`) } : {},
997
- ...t.angularVelocity ? { angularVelocity: e(t.angularVelocity, `${n}.motion.angularVelocity`) } : {},
1067
+ ...t.inertiaOrientation ? { inertiaOrientation: b(t.inertiaOrientation, `${n}.motion.inertiaOrientation`) } : {},
1068
+ ...t.linearVelocity ? { linearVelocity: r(t.linearVelocity, `${n}.motion.linearVelocity`) } : {},
1069
+ ...t.angularVelocity ? { angularVelocity: r(t.angularVelocity, `${n}.motion.angularVelocity`) } : {},
998
1070
  ...t.gravityFactor === void 0 ? {} : { gravityFactor: t.gravityFactor }
999
1071
  };
1000
1072
  }
1001
- async function Xe(e, t, n) {
1002
- pe(), e.updateMatrixWorld(!0);
1003
- let r = new F();
1004
- return he(await new Promise((t, n) => {
1005
- r.parse(e, (e) => t(e instanceof ArrayBuffer ? e : me(e)), n, { binary: !0 });
1006
- }), (e) => {
1007
- let r = e.nodes ?? [], i = /* @__PURE__ */ new Map();
1008
- r.forEach((e, t) => {
1009
- e.name && i.set(e.name, t);
1073
+ async function ot(t, n, r) {
1074
+ xe(), t.updateMatrixWorld(!0);
1075
+ let i = new L();
1076
+ return Ce(await new Promise((e, n) => {
1077
+ i.parse(t, (t) => e(t instanceof ArrayBuffer ? t : Se(t)), n, { binary: !0 });
1078
+ }), (t) => {
1079
+ let i = t.nodes ?? [], a = /* @__PURE__ */ new Map();
1080
+ i.forEach((e, t) => {
1081
+ e.name && a.set(e.name, t);
1010
1082
  });
1011
- let a = (e) => {
1012
- let t = i.get(e);
1013
- if (t === void 0) throw new v(`exportKhrGlb: missing scene node "${e}"`);
1014
- return t;
1015
- }, o = [], s = /* @__PURE__ */ new Map(), c = [], l = [], u = [], d = !1;
1016
- for (let e of t) {
1017
- let t = r[a(e.nodeName)];
1018
- e.extras && (t.extras = {
1019
- ...t.extras,
1020
- ...e.extras
1083
+ let o = (t) => {
1084
+ let n = a.get(t);
1085
+ if (n === void 0) throw new e(`exportKhrGlb: missing scene node "${t}"`);
1086
+ return n;
1087
+ }, s = [], c = /* @__PURE__ */ new Map(), l = [], u = [], d = [], f = !1;
1088
+ for (let t of n) {
1089
+ let n = i[o(t.nodeName)];
1090
+ t.extras && (n.extras = {
1091
+ ...n.extras,
1092
+ ...t.extras
1021
1093
  });
1022
- let n = {};
1023
- if (e.motion && (d = !0, n.motion = Ye(e.motion, e.nodeName)), e.collider) {
1024
- d = !0;
1025
- let t = {};
1026
- if (e.collider.shape) {
1027
- let n = Ge(e.collider.shape, e.nodeName), r = JSON.stringify(n), i = s.get(r);
1028
- i === void 0 && (i = o.length, o.push(n), s.set(r, i)), t.geometry = { shape: i };
1029
- } else if (e.collider.meshNodeName) {
1030
- if (typeof e.collider.convexHull != "boolean") throw new v(`exportKhrGlb: mesh collider on "${e.nodeName}" requires explicit boolean convexHull`);
1031
- t.geometry = {
1032
- node: a(e.collider.meshNodeName),
1033
- convexHull: e.collider.convexHull
1094
+ let r = {};
1095
+ if (t.motion && (f = !0, r.motion = at(t.motion, t.nodeName)), t.collider) {
1096
+ f = !0;
1097
+ let n = {};
1098
+ if (t.collider.shape) {
1099
+ let e = tt(t.collider.shape, t.nodeName), r = JSON.stringify(e), i = c.get(r);
1100
+ i === void 0 && (i = s.length, s.push(e), c.set(r, i)), n.geometry = { shape: i };
1101
+ } else if (t.collider.meshNodeName) {
1102
+ if (typeof t.collider.convexHull != "boolean") throw new e(`exportKhrGlb: mesh collider on "${t.nodeName}" requires explicit boolean convexHull`);
1103
+ n.geometry = {
1104
+ node: o(t.collider.meshNodeName),
1105
+ convexHull: t.collider.convexHull
1034
1106
  };
1035
- } else throw new v(`exportKhrGlb: collider on "${e.nodeName}" requires shape or meshNodeName`);
1036
- let r = Q(e.collider.friction, `collider.friction on "${e.nodeName}"`, !0), i = Q(e.collider.restitution, `collider.restitution on "${e.nodeName}"`, !0);
1037
- if ((r !== void 0 || i !== void 0) && (t.physicsMaterial = c.length, c.push({
1038
- ...r === void 0 ? {} : {
1039
- staticFriction: r,
1040
- dynamicFriction: r
1107
+ } else throw new e(`exportKhrGlb: collider on "${t.nodeName}" requires shape or meshNodeName`);
1108
+ let i = Q(t.collider.friction, `collider.friction on "${t.nodeName}"`, !0), a = Q(t.collider.restitution, `collider.restitution on "${t.nodeName}"`, !0);
1109
+ if ((i !== void 0 || a !== void 0) && (n.physicsMaterial = l.length, l.push({
1110
+ ...i === void 0 ? {} : {
1111
+ staticFriction: i,
1112
+ dynamicFriction: i
1041
1113
  },
1042
- ...i === void 0 ? {} : { restitution: i }
1043
- })), e.collider.collideWithSystems !== void 0 && e.collider.notCollideWithSystems !== void 0) throw new v(`exportKhrGlb: collider on "${e.nodeName}" cannot specify both collideWithSystems and notCollideWithSystems`);
1044
- if (e.collider.collisionSystems !== void 0 || e.collider.collideWithSystems !== void 0 || e.collider.notCollideWithSystems !== void 0) {
1045
- if (!Array.isArray(e.collider.collisionSystems) || e.collider.collisionSystems.length === 0) throw new v(`exportKhrGlb: collision filter on "${e.nodeName}" requires non-empty collisionSystems`);
1046
- t.collisionFilter = l.length, l.push({
1047
- collisionSystems: e.collider.collisionSystems,
1048
- ...e.collider.collideWithSystems ? { collideWithSystems: e.collider.collideWithSystems } : {},
1049
- ...e.collider.notCollideWithSystems ? { notCollideWithSystems: e.collider.notCollideWithSystems } : {}
1114
+ ...a === void 0 ? {} : { restitution: a }
1115
+ })), t.collider.collideWithSystems !== void 0 && t.collider.notCollideWithSystems !== void 0) throw new e(`exportKhrGlb: collider on "${t.nodeName}" cannot specify both collideWithSystems and notCollideWithSystems`);
1116
+ if (t.collider.collisionSystems !== void 0 || t.collider.collideWithSystems !== void 0 || t.collider.notCollideWithSystems !== void 0) {
1117
+ if (!Array.isArray(t.collider.collisionSystems) || t.collider.collisionSystems.length === 0) throw new e(`exportKhrGlb: collision filter on "${t.nodeName}" requires non-empty collisionSystems`);
1118
+ n.collisionFilter = u.length, u.push({
1119
+ collisionSystems: t.collider.collisionSystems,
1120
+ ...t.collider.collideWithSystems ? { collideWithSystems: t.collider.collideWithSystems } : {},
1121
+ ...t.collider.notCollideWithSystems ? { notCollideWithSystems: t.collider.notCollideWithSystems } : {}
1050
1122
  });
1051
1123
  }
1052
- n.collider = t;
1124
+ r.collider = n;
1053
1125
  }
1054
- if (e.joint) {
1055
- d = !0;
1056
- let t = a(e.joint.connectedNodeName);
1057
- u.push(Je(e.joint, e.nodeName)), n.joint = {
1058
- joint: u.length - 1,
1059
- connectedNode: t,
1060
- enableCollision: !!e.joint.enableCollision
1126
+ if (t.joint) {
1127
+ f = !0;
1128
+ let e = o(t.joint.connectedNodeName);
1129
+ d.push(it(t.joint, t.nodeName)), r.joint = {
1130
+ joint: d.length - 1,
1131
+ connectedNode: e,
1132
+ enableCollision: !!t.joint.enableCollision
1061
1133
  };
1062
1134
  }
1063
- Object.keys(n).length > 0 && (t.extensions = {
1064
- ...t.extensions,
1065
- KHR_physics_rigid_bodies: n
1135
+ Object.keys(r).length > 0 && (n.extensions = {
1136
+ ...n.extensions,
1137
+ KHR_physics_rigid_bodies: r
1066
1138
  });
1067
1139
  }
1068
- if (n) {
1069
- let t = e.scenes?.[e.scene ?? 0];
1070
- t ? t.extras = {
1071
- ...t.extras,
1072
- ...n
1073
- } : e.extras = {
1140
+ if (r) {
1141
+ let e = t.scenes?.[t.scene ?? 0];
1142
+ e ? e.extras = {
1074
1143
  ...e.extras,
1075
- ...n
1144
+ ...r
1145
+ } : t.extras = {
1146
+ ...t.extras,
1147
+ ...r
1076
1148
  };
1077
1149
  }
1078
- let f = new Set(e.extensionsUsed ?? []);
1079
- e.extensions ??= {}, o.length > 0 && (f.add("KHR_implicit_shapes"), e.extensions.KHR_implicit_shapes = { shapes: o }), d && (f.add("KHR_physics_rigid_bodies"), e.extensions.KHR_physics_rigid_bodies = {
1080
- ...c.length > 0 ? { physicsMaterials: c } : {},
1081
- ...l.length > 0 ? { collisionFilters: l } : {},
1082
- ...u.length > 0 ? { physicsJoints: u } : {}
1083
- }), f.size > 0 && (e.extensionsUsed = [...f]);
1150
+ let p = new Set(t.extensionsUsed ?? []);
1151
+ t.extensions ??= {}, s.length > 0 && (p.add("KHR_implicit_shapes"), t.extensions.KHR_implicit_shapes = { shapes: s }), f && (p.add("KHR_physics_rigid_bodies"), t.extensions.KHR_physics_rigid_bodies = {
1152
+ ...l.length > 0 ? { physicsMaterials: l } : {},
1153
+ ...u.length > 0 ? { collisionFilters: u } : {},
1154
+ ...d.length > 0 ? { physicsJoints: d } : {}
1155
+ }), p.size > 0 && (t.extensionsUsed = [...p]);
1084
1156
  });
1085
1157
  }
1086
1158
  // src/assemblyPlan.ts
1087
- var Ze = (e) => new j.Matrix4().compose(new j.Vector3().fromArray(e.localPosition), new j.Quaternion().fromArray(e.localQuaternion), new j.Vector3(1, 1, 1));
1088
- function Qe(e, t) {
1089
- let n = new j.Matrix4();
1090
- for (let r = e; r && r !== t; r = r.parent) {
1091
- if (!r.parent) throw new v(`Node "${e.name}" is detached from bundle.scene`);
1092
- r.updateMatrix(), n.premultiply(r.matrix);
1159
+ function st(t, n) {
1160
+ let r = new N.Matrix4();
1161
+ for (let i = t; i && i !== n; i = i.parent) {
1162
+ if (!i.parent) throw new e(`Node "${t.name}" is detached from bundle.scene`);
1163
+ i.updateMatrix(), r.premultiply(i.matrix);
1093
1164
  }
1094
- return n;
1165
+ return r;
1095
1166
  }
1096
- function $e(e, t) {
1167
+ function ct(e, t) {
1097
1168
  let n = (e) => {
1098
1169
  let n = [];
1099
1170
  for (let r = e; r && (n.push(r), r !== t); r = r.parent);
@@ -1106,127 +1177,134 @@ function $e(e, t) {
1106
1177
  for (let t of n(e[0])) if (r.has(t)) return t;
1107
1178
  return t;
1108
1179
  }
1109
- function et(e, t, n) {
1110
- if (n && e.mass > 0 && e.colliders.length === 0) throw new v(`Dynamic body "${e.nodeName}" has mass ${e.mass} but no colliders to carry it`);
1111
- return e.colliders.map((r, i) => {
1112
- let a = new j.Quaternion().fromArray(r.localQuaternion), o = new j.Matrix4().compose(new j.Vector3().fromArray(r.localPosition), a, new j.Vector3(1, 1, 1)), s = new j.Vector3(), c = new j.Quaternion(), l = new j.Vector3();
1113
- new j.Matrix4().multiplyMatrices(t, o).decompose(s, c, l);
1114
- let u = {
1115
- spec: r,
1116
- local: o,
1180
+ function lt(e, t, n) {
1181
+ let r = new N.Vector3().fromArray(e.com), i = new N.Quaternion().fromArray(e.inertiaFrame);
1182
+ return t && n && (r.applyMatrix4(t.clone().invert()), i.premultiply(n.clone().invert()).normalize()), {
1183
+ mass: e.mass,
1184
+ centerOfMass: {
1185
+ x: r.x,
1186
+ y: r.y,
1187
+ z: r.z
1188
+ },
1189
+ principalAngularInertia: {
1190
+ x: e.inertia[0],
1191
+ y: e.inertia[1],
1192
+ z: e.inertia[2]
1193
+ },
1194
+ angularInertiaLocalFrame: {
1195
+ x: i.x,
1196
+ y: i.y,
1197
+ z: i.z,
1198
+ w: i.w
1199
+ }
1200
+ };
1201
+ }
1202
+ function ut(e, t, n) {
1203
+ return e.colliders.map((e, r) => {
1204
+ let i = new N.Quaternion().fromArray(e.localQuaternion), a = new N.Matrix4().compose(new N.Vector3().fromArray(e.localPosition), i, new N.Vector3(1, 1, 1)), o = new N.Vector3(), s = new N.Quaternion(), c = new N.Vector3();
1205
+ new N.Matrix4().multiplyMatrices(t, a).decompose(o, s, c);
1206
+ let l = {
1207
+ spec: e,
1208
+ local: a,
1117
1209
  position: [
1118
- s.x,
1119
- s.y,
1120
- s.z
1210
+ o.x,
1211
+ o.y,
1212
+ o.z
1121
1213
  ],
1122
1214
  quaternion: [
1123
- c.x,
1124
- c.y,
1125
- c.z,
1126
- c.w
1215
+ s.x,
1216
+ s.y,
1217
+ s.z,
1218
+ s.w
1127
1219
  ]
1128
1220
  };
1129
- if (i === 0 && n) {
1130
- let t = o.clone().invert(), n = new j.Vector3().fromArray(e.centerOfMass).applyMatrix4(t), r = a.clone().invert().multiply(new j.Quaternion().fromArray(e.inertiaOrientation)), [i, s, c] = e.inertiaDiagonal;
1131
- u.massProperties = {
1132
- mass: e.mass,
1133
- centerOfMass: {
1134
- x: n.x,
1135
- y: n.y,
1136
- z: n.z
1137
- },
1138
- principalAngularInertia: {
1139
- x: i,
1140
- y: s,
1141
- z: c
1142
- },
1143
- angularInertiaLocalFrame: {
1144
- x: r.x,
1145
- y: r.y,
1146
- z: r.z,
1147
- w: r.w
1148
- }
1149
- };
1150
- }
1151
- return u;
1221
+ return r === 0 && n && (l.massProperties = lt(n, a, i)), l;
1152
1222
  });
1153
1223
  }
1154
- function tt(e) {
1155
- let t = new Map(e.bodies.map((e) => [e.nodeName, e])), n = (e, r = /* @__PURE__ */ new Set()) => {
1156
- if (!e.joint) return e;
1157
- if (r.has(e.nodeName)) throw new v(`Joint cycle through "${e.nodeName}"`);
1158
- r.add(e.nodeName);
1159
- let i = t.get(e.joint.connectedNodeName);
1160
- if (!i) throw new v(`Joint on "${e.nodeName}" targets "${e.joint.connectedNodeName}", which is not a KHR body`);
1161
- return n(i, r);
1162
- }, r = e.bodies.filter((e) => !e.joint).map((r) => {
1163
- let i = Ze(r).clone().invert(), a = e.bodies.filter((e) => e.joint && n(e) === r), o = (e) => e.joint ? 1 + o(t.get(e.joint.connectedNodeName)) : 0;
1164
- a.sort((e, t) => o(e) - o(t));
1165
- let s = /* @__PURE__ */ new Map(), c = a.map((e) => {
1166
- let t = e.joint, n = s.get(t.connectedNodeName) ?? null;
1167
- if (n && !nt(e.object, n.spec.object)) throw new v(`Jointed node "${e.nodeName}" must be a scene-graph descendant of its jointed parent "${t.connectedNodeName}"`);
1168
- let r = i.clone().multiply(Ze(e)), a = {
1169
- spec: e,
1170
- joint: t,
1171
- parent: n,
1172
- restRelParent: n ? Ze(n.spec).invert().multiply(Ze(e)) : r,
1173
- inertia: re(e, t),
1174
- colliders: et(e, r, !0)
1224
+ function dt(e, t, n) {
1225
+ 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
+ return !1;
1227
+ }
1228
+ function ft(t) {
1229
+ let r = new Map(t.bodies.map((e) => [e.nodeName, e])), i = (t, n = /* @__PURE__ */ new Set()) => {
1230
+ if (!t.joint) return t;
1231
+ if (n.has(t.nodeName)) throw new e(`Joint cycle through "${t.nodeName}"`);
1232
+ n.add(t.nodeName);
1233
+ let a = r.get(t.joint.connectedNodeName);
1234
+ if (!a) throw new e(`Joint on "${t.nodeName}" targets "${t.joint.connectedNodeName}", which is not a KHR body`);
1235
+ return i(a, n);
1236
+ }, a = t.bodies.filter((e) => !e.joint).map((a) => {
1237
+ let o = x(a).clone().invert(), s = t.bodies.filter((e) => e.joint && i(e) === a), c = (e) => e.joint ? 1 + c(r.get(e.joint.connectedNodeName)) : 0;
1238
+ s.sort((e, t) => c(e) - c(t));
1239
+ let l = /* @__PURE__ */ new Map(), u = s.map((t) => {
1240
+ let n = t.joint, i = l.get(n.connectedNodeName) ?? null;
1241
+ if (i && !pt(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
+ let a = o.clone().multiply(x(t)), c = {
1243
+ spec: t,
1244
+ joint: n,
1245
+ parent: i,
1246
+ restRelParent: i ? x(i.spec).invert().multiply(x(t)) : a,
1247
+ inertia: le(t, n, s.filter((e) => e !== t && dt(e, t.nodeName, r))),
1248
+ colliders: ut(t, a, null)
1175
1249
  };
1176
- return s.set(e.nodeName, a), a;
1177
- }), l = $e([r.object, ...a.map((e) => e.object)], e.scene), u = i.clone().multiply(Qe(l, e.scene)), d = new j.Vector3(), f = new j.Quaternion(), p = new j.Vector3();
1178
- i.decompose(d, f, p), f.normalize();
1179
- let m = new j.Vector3(), h = new j.Quaternion(), g = new j.Vector3();
1180
- return u.decompose(m, h, g), h.normalize(), {
1181
- spec: r,
1250
+ return l.set(t.nodeName, c), c;
1251
+ }), d = a.isKinematic ? null : n([a, ...s], o), f = ut(a, new N.Matrix4(), d), p = d && f.length === 0 ? lt(d) : void 0, m = ct([a.object, ...s.map((e) => e.object)], t.scene), h = o.clone().multiply(st(m, t.scene)), g = new N.Vector3(), _ = new N.Quaternion(), v = new N.Vector3();
1252
+ o.decompose(g, _, v), _.normalize();
1253
+ let y = new N.Vector3(), b = new N.Quaternion(), S = new N.Vector3();
1254
+ return h.decompose(y, b, S), b.normalize(), {
1255
+ spec: a,
1182
1256
  sceneInRootPos: [
1183
- d.x,
1184
- d.y,
1185
- d.z
1257
+ g.x,
1258
+ g.y,
1259
+ g.z
1186
1260
  ],
1187
1261
  sceneInRootQuat: [
1188
- f.x,
1189
- f.y,
1190
- f.z,
1191
- f.w
1262
+ _.x,
1263
+ _.y,
1264
+ _.z,
1265
+ _.w
1192
1266
  ],
1193
- mountNode: l,
1194
- mountInRoot: u,
1267
+ mountNode: m,
1268
+ mountInRoot: h,
1195
1269
  mountPosition: [
1196
- m.x,
1197
- m.y,
1198
- m.z
1270
+ y.x,
1271
+ y.y,
1272
+ y.z
1199
1273
  ],
1200
1274
  mountQuaternion: [
1201
- h.x,
1202
- h.y,
1203
- h.z,
1204
- h.w
1275
+ b.x,
1276
+ b.y,
1277
+ b.z,
1278
+ b.w
1205
1279
  ],
1206
- colliders: et(r, new j.Matrix4(), !r.isKinematic),
1207
- parts: c
1280
+ ...p ? { rootMass: p } : {},
1281
+ colliders: f,
1282
+ parts: u
1208
1283
  };
1209
1284
  });
1210
- for (let e of r) for (let t of r) if (e !== t && nt(t.mountNode, e.mountNode)) throw new v(`Root bodies "${e.spec.nodeName}" and "${t.spec.nodeName}" share scene subtree "${e.mountNode.name}"; split them into separate glTF branches`);
1211
- return r;
1285
+ for (let t of a) for (let n of a) if (t !== n && pt(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
+ return a;
1212
1287
  }
1213
- function nt(e, t) {
1288
+ function pt(e, t) {
1214
1289
  for (let n = e; n; n = n.parent) if (n === t) return !0;
1215
1290
  return !1;
1216
1291
  }
1217
1292
  // src/AssemblyRootBody.tsx
1218
- function rt({ plan: e, assemblyId: n, position: r, quaternion: i, fixedRoot: a, rigidBodyProps: o, onBody: s, onJoints: c, children: l }) {
1219
- let u = x(y), d = T(null), f = w(() => e.parts.map((e) => e.colliders.map(() => ({ current: null }))), [e]), p = e.spec;
1220
- C(() => (s(p.nodeName, d), () => s(p.nodeName, null)), [p, s]), C(() => {
1221
- let t = /* @__PURE__ */ new Map();
1293
+ function mt({ plan: e, assemblyId: t, position: n, quaternion: r, fixedRoot: a, rigidBodyProps: o, onBody: s, onJoints: c, children: l }) {
1294
+ let u = T(C), d = O(null), f = D(() => e.parts.map((e) => e.colliders.map(() => ({ current: null }))), [e]), p = e.spec;
1295
+ E(() => (s(p.nodeName, d), () => s(p.nodeName, null)), [p, s]), E(() => {
1296
+ let t = d.current, n = e.rootMass;
1297
+ t && n && (t.setAdditionalMassProperties(n.mass, n.centerOfMass, n.principalAngularInertia, n.angularInertiaLocalFrame, !0), t.recomputeMassPropertiesFromColliders());
1298
+ }, [e.rootMass]), E(() => {
1299
+ let n = /* @__PURE__ */ new Map();
1222
1300
  for (let r = 0; r < e.parts.length; r++) {
1223
1301
  let i = e.parts[r], a = i.joint.drive, o = {
1224
- assemblyId: n,
1302
+ assemblyId: t,
1225
1303
  nodeName: i.spec.nodeName,
1226
1304
  role: i.joint.role,
1227
1305
  kind: i.joint.kind,
1228
1306
  object: i.spec.object,
1229
- axis: new j.Vector3().fromArray(i.joint.axis).normalize(),
1307
+ axis: new N.Vector3().fromArray(i.joint.axis).normalize(),
1230
1308
  restPosition: i.spec.object.position.clone(),
1231
1309
  restQuaternion: i.spec.object.quaternion.clone(),
1232
1310
  q: 0,
@@ -1238,7 +1316,7 @@ function rt({ plan: e, assemblyId: n, position: r, quaternion: i, fixedRoot: a,
1238
1316
  limitStiffness: i.joint.limitStiffness ?? null,
1239
1317
  limitDamping: i.joint.limitDamping ?? 0,
1240
1318
  inertia: i.inertia,
1241
- parent: i.parent ? t.get(i.parent.spec.nodeName) : null,
1319
+ parent: i.parent ? n.get(i.parent.spec.nodeName) : null,
1242
1320
  restRelParent: i.restRelParent,
1243
1321
  current: i.restRelParent.clone(),
1244
1322
  stamp: -1,
@@ -1247,76 +1325,76 @@ function rt({ plan: e, assemblyId: n, position: r, quaternion: i, fixedRoot: a,
1247
1325
  local: e.local
1248
1326
  }))
1249
1327
  };
1250
- t.set(o.nodeName, o), u?.add(o);
1328
+ n.set(o.nodeName, o), u?.add(o);
1251
1329
  }
1252
- return c(p.nodeName, t), () => {
1330
+ return c(p.nodeName, n), () => {
1253
1331
  c(p.nodeName, null);
1254
- for (let e of t.values()) u?.delete(e), e.object.position.copy(e.restPosition), e.object.quaternion.copy(e.restQuaternion);
1332
+ for (let e of n.values()) u?.delete(e), e.object.position.copy(e.restPosition), e.object.quaternion.copy(e.restQuaternion);
1255
1333
  };
1256
1334
  }, [
1257
1335
  e,
1258
1336
  u,
1259
- n,
1337
+ t,
1260
1338
  f,
1261
1339
  p,
1262
1340
  c
1263
1341
  ]);
1264
1342
  let m = p.isKinematic ? a ? "fixed" : "kinematicPosition" : "dynamic";
1265
- return /* @__PURE__ */ N(k, {
1343
+ return /* @__PURE__ */ F(j, {
1266
1344
  ...o,
1267
1345
  ref: d,
1268
1346
  type: m,
1269
- position: r,
1270
- quaternion: i,
1347
+ position: n,
1348
+ quaternion: r,
1271
1349
  colliders: !1,
1272
1350
  ...p.linearVelocity ? { linearVelocity: p.linearVelocity } : {},
1273
1351
  ...p.angularVelocity ? { angularVelocity: p.angularVelocity } : {},
1274
1352
  ...p.gravityFactor === void 0 ? {} : { gravityScale: p.gravityFactor },
1275
1353
  children: [
1276
1354
  l,
1277
- e.colliders.map((e, n) => /* @__PURE__ */ M(t, {
1355
+ e.colliders.map((e, t) => /* @__PURE__ */ P(i, {
1278
1356
  c: e.spec,
1279
1357
  position: e.position,
1280
1358
  quaternion: e.quaternion,
1281
1359
  massProperties: e.massProperties
1282
- }, `r${n}`)),
1283
- e.parts.map((e, n) => e.colliders.map((r, i) => /* @__PURE__ */ M(t, {
1284
- ref: f[n][i],
1285
- c: r.spec,
1286
- position: r.position,
1287
- quaternion: r.quaternion,
1288
- massProperties: r.massProperties
1289
- }, `${e.spec.nodeName}:${i}`)))
1360
+ }, `r${t}`)),
1361
+ e.parts.map((e, t) => e.colliders.map((n, r) => /* @__PURE__ */ P(i, {
1362
+ ref: f[t][r],
1363
+ c: n.spec,
1364
+ position: n.position,
1365
+ quaternion: n.quaternion,
1366
+ massProperties: n.massProperties
1367
+ }, `${e.spec.nodeName}:${r}`)))
1290
1368
  ]
1291
1369
  });
1292
1370
  }
1293
1371
  // src/KhrAssembly.tsx
1294
- var it = 0;
1295
- function at({ ref: e, bundle: t, position: n = [
1372
+ var ht = 0;
1373
+ function gt({ ref: t, bundle: n, position: r = [
1296
1374
  0,
1297
1375
  0,
1298
1376
  0
1299
- ], rotation: r, quaternion: o, scale: s, fixedRoot: c = !1, rigidBodyProps: l, children: d, ...f }) {
1300
- a(s, "KhrAssembly"), t.scene.updateMatrixWorld(!0), i(t.scene);
1301
- let m = w(() => it++, []), g = w(() => tt(t), [t]), _ = w(() => g.length > 1 ? p(g.map((e) => e.mountNode)) : null, [g]), [y, x, C] = n, [E, D, O] = r ?? [
1377
+ ], rotation: i, quaternion: a, scale: o, fixedRoot: l = !1, rigidBodyProps: u, children: d, ...f }) {
1378
+ c(o, "KhrAssembly"), n.scene.updateMatrixWorld(!0), s(n.scene);
1379
+ let m = D(() => ht++, []), h = D(() => ft(n), [n]), _ = D(() => h.length > 1 ? g(h.map((e) => e.mountNode)) : null, [h]), [y, b, x] = r, [S, C, T] = i ?? [
1302
1380
  0,
1303
1381
  0,
1304
1382
  0
1305
- ], [k, A, P, F] = o ?? [
1383
+ ], [E, te, k, A] = a ?? [
1306
1384
  NaN,
1307
1385
  NaN,
1308
1386
  NaN,
1309
1387
  NaN
1310
- ], I = w(() => o ? new j.Quaternion(k, A, P, F) : new j.Quaternion().setFromEuler(new j.Euler(E, D, O)), [
1388
+ ], j = D(() => a ? new N.Quaternion(E, te, k, A) : new N.Quaternion().setFromEuler(new N.Euler(S, C, T)), [
1389
+ E,
1390
+ te,
1311
1391
  k,
1312
1392
  A,
1313
- P,
1314
- F,
1315
- E,
1316
- D,
1317
- O
1318
- ]), L = w(() => g.map((e) => {
1319
- let t = new j.Vector3().fromArray(e.spec.localPosition).applyQuaternion(I).add(new j.Vector3(y, x, C)), n = I.clone().multiply(new j.Quaternion().fromArray(e.spec.localQuaternion));
1393
+ S,
1394
+ C,
1395
+ T
1396
+ ]), M = D(() => h.map((e) => {
1397
+ let t = new N.Vector3().fromArray(e.spec.localPosition).applyQuaternion(j).add(new N.Vector3(y, b, x)), n = j.clone().multiply(new N.Quaternion().fromArray(e.spec.localQuaternion));
1320
1398
  return {
1321
1399
  position: [
1322
1400
  t.x,
@@ -1331,117 +1409,117 @@ function at({ ref: e, bundle: t, position: n = [
1331
1409
  ]
1332
1410
  };
1333
1411
  }), [
1334
- g,
1335
- I,
1412
+ h,
1413
+ j,
1336
1414
  y,
1337
- x,
1338
- C
1339
- ]), R = T(/* @__PURE__ */ new Map()), z = T(/* @__PURE__ */ new Map()), B = w(() => {
1415
+ b,
1416
+ x
1417
+ ]), I = O(/* @__PURE__ */ new Map()), L = O(/* @__PURE__ */ new Map()), R = D(() => {
1340
1418
  let e = /* @__PURE__ */ new Map();
1341
- for (let t of g) {
1419
+ for (let t of h) {
1342
1420
  e.set(t.spec.nodeName, t.spec.nodeName);
1343
1421
  for (let n of t.parts) e.set(n.spec.nodeName, t.spec.nodeName);
1344
1422
  }
1345
1423
  return e;
1346
- }, [g]), ee = b((e, t) => {
1347
- t ? R.current.set(e, t) : R.current.delete(e);
1348
- }, []), te = b((e, t) => {
1349
- t ? z.current.set(e, t) : z.current.delete(e);
1424
+ }, [h]), z = w((e, t) => {
1425
+ t ? I.current.set(e, t) : I.current.delete(e);
1426
+ }, []), B = w((e, t) => {
1427
+ t ? L.current.set(e, t) : L.current.delete(e);
1350
1428
  }, []);
1351
- if (S(e, () => {
1352
- let e = (e, t) => {
1353
- if (!e.drive || e.drive.stiffness === void 0) throw new v(`Joint "${e.nodeName}" has no authored drive stiffness; cannot set a position target`);
1354
- e.positionTarget = t;
1355
- let n = R.current.get(B.get(e.nodeName))?.current;
1356
- n && n.isDynamic() && n.wakeUp();
1429
+ if (ee(t, () => {
1430
+ let t = (t, n) => {
1431
+ 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
+ t.positionTarget = n;
1433
+ let r = I.current.get(R.get(t.nodeName))?.current;
1434
+ r && r.isDynamic() && r.wakeUp();
1357
1435
  };
1358
1436
  return {
1359
1437
  getBody: (e) => {
1360
- let t = B.get(e);
1361
- return t ? R.current.get(t)?.current ?? null : null;
1438
+ let t = R.get(e);
1439
+ return t ? I.current.get(t)?.current ?? null : null;
1362
1440
  },
1363
- setJointTarget: (t, n) => {
1364
- let r = z.current.get(B.get(t) ?? "")?.get(t);
1365
- r && e(r, n);
1441
+ setJointTarget: (e, n) => {
1442
+ let r = L.current.get(R.get(e) ?? "")?.get(e);
1443
+ r && t(r, n);
1366
1444
  },
1367
- setRoleTarget: (t, n) => {
1368
- for (let r of z.current.values()) for (let i of r.values()) i.role === t && e(i, n);
1445
+ setRoleTarget: (e, n) => {
1446
+ for (let r of L.current.values()) for (let i of r.values()) i.role === e && t(i, n);
1369
1447
  }
1370
1448
  };
1371
- }, [B]), g.length === 1) {
1372
- let e = g[0];
1373
- return /* @__PURE__ */ M("group", {
1449
+ }, [R]), h.length === 1) {
1450
+ let e = h[0];
1451
+ return /* @__PURE__ */ P("group", {
1374
1452
  ...f,
1375
- children: /* @__PURE__ */ M(rt, {
1453
+ children: /* @__PURE__ */ P(mt, {
1376
1454
  plan: e,
1377
1455
  assemblyId: m,
1378
- position: L[0].position,
1379
- quaternion: L[0].quaternion,
1380
- fixedRoot: c,
1381
- rigidBodyProps: l,
1382
- onBody: ee,
1383
- onJoints: te,
1384
- children: /* @__PURE__ */ N("group", {
1456
+ position: M[0].position,
1457
+ quaternion: M[0].quaternion,
1458
+ fixedRoot: l,
1459
+ rigidBodyProps: u,
1460
+ onBody: z,
1461
+ onJoints: B,
1462
+ children: /* @__PURE__ */ F("group", {
1385
1463
  position: e.sceneInRootPos,
1386
1464
  quaternion: e.sceneInRootQuat,
1387
- children: [/* @__PURE__ */ M(h, {
1388
- bundle: t,
1465
+ children: [/* @__PURE__ */ P(v, {
1466
+ bundle: n,
1389
1467
  owner: "KhrAssembly"
1390
1468
  }), d]
1391
1469
  })
1392
- }, `${t.scene.uuid}:${e.spec.nodeName}`)
1470
+ }, `${n.scene.uuid}:${e.spec.nodeName}`)
1393
1471
  });
1394
1472
  }
1395
- return /* @__PURE__ */ N("group", {
1473
+ return /* @__PURE__ */ F("group", {
1396
1474
  ...f,
1397
- children: [/* @__PURE__ */ N("group", {
1398
- position: n,
1399
- quaternion: I,
1400
- children: [/* @__PURE__ */ M(h, {
1401
- bundle: t,
1475
+ children: [/* @__PURE__ */ F("group", {
1476
+ position: r,
1477
+ quaternion: j,
1478
+ children: [/* @__PURE__ */ P(v, {
1479
+ bundle: n,
1402
1480
  owner: "KhrAssembly"
1403
1481
  }), d]
1404
- }), g.map((e, n) => /* @__PURE__ */ M(rt, {
1482
+ }), h.map((e, t) => /* @__PURE__ */ P(mt, {
1405
1483
  plan: e,
1406
1484
  assemblyId: m,
1407
- position: L[n].position,
1408
- quaternion: L[n].quaternion,
1409
- fixedRoot: c,
1410
- rigidBodyProps: l,
1411
- onBody: ee,
1412
- onJoints: te,
1413
- children: /* @__PURE__ */ M(u, {
1485
+ position: M[t].position,
1486
+ quaternion: M[t].quaternion,
1487
+ fixedRoot: l,
1488
+ rigidBodyProps: u,
1489
+ onBody: z,
1490
+ onJoints: B,
1491
+ children: /* @__PURE__ */ P(p, {
1414
1492
  object: e.mountNode,
1415
1493
  position: e.mountPosition,
1416
1494
  quaternion: e.mountQuaternion,
1417
1495
  origin: _.get(e.mountNode)
1418
1496
  })
1419
- }, `${t.scene.uuid}:${e.spec.nodeName}`))]
1497
+ }, `${n.scene.uuid}:${e.spec.nodeName}`))]
1420
1498
  });
1421
1499
  }
1422
1500
  // src/useKhrGlb.ts
1423
- var ot = class extends P {
1501
+ var _t = class extends I {
1424
1502
  static khrLoaderScope = Symbol("KhrGLTFLoader");
1425
- }, st = Ie(), ct = Ve(), lt = /* @__PURE__ */ new WeakSet(), ut = /* @__PURE__ */ new WeakSet(), $ = /* @__PURE__ */ new Map();
1426
- function dt(e) {
1427
- lt.has(e) || (lt.add(e), typeof document > "u" && typeof createImageBitmap > "u" && e.register(st), e.register(ct));
1503
+ }, vt = Ke(), yt = Ze(), bt = /* @__PURE__ */ new WeakSet(), xt = /* @__PURE__ */ new WeakSet(), $ = /* @__PURE__ */ new Map();
1504
+ function St(e) {
1505
+ bt.has(e) || (bt.add(e), typeof document > "u" && typeof createImageBitmap > "u" && e.register(vt), e.register(yt));
1428
1506
  }
1429
- function ft(e) {
1507
+ function Ct(e) {
1430
1508
  return !!(e?.extendLoader || e?.cacheKey !== void 0);
1431
1509
  }
1432
- function pt(e) {
1510
+ function wt(e) {
1433
1511
  return e.cacheKey === void 0 ? `src:${Function.prototype.toString.call(e.extendLoader)}` : `key:${e.cacheKey}`;
1434
1512
  }
1435
- function mt(e, t) {
1436
- let n = pt(t), r = $.get(e);
1513
+ function Tt(e, t) {
1514
+ let n = wt(t), r = $.get(e);
1437
1515
  r || (r = /* @__PURE__ */ new Map(), $.set(e, r));
1438
1516
  let i = r.get(n);
1439
1517
  if (!i) {
1440
- let a = new P(), o = t.extendLoader, s = {
1518
+ let a = new I(), o = t.extendLoader, s = {
1441
1519
  loader: a,
1442
1520
  registerExtensions: (t) => {
1443
- if (dt(t), o && !ut.has(t)) try {
1444
- o(t), ut.add(t);
1521
+ if (St(t), o && !xt.has(t)) try {
1522
+ o(t), xt.add(t);
1445
1523
  } catch (t) {
1446
1524
  let r = $.get(e);
1447
1525
  throw r?.get(n) === s && (r.delete(n), r.size === 0 && $.delete(e)), t;
@@ -1452,33 +1530,33 @@ function mt(e, t) {
1452
1530
  }
1453
1531
  return i;
1454
1532
  }
1455
- function ht(e, t) {
1456
- let n = t?.extractRole, r = t?.isSocketNode, i = ft(t) ? mt(e, t) : null, a = i ? i.loader : ot, o = i ? i.registerExtensions : dt, s = D(a, e, o).userData[ze];
1457
- if (!s) throw new v(`useKhrGlb: missing "${ze}" on loaded GLTF for "${e}"`);
1458
- return w(() => {
1459
- let e = m(s);
1460
- return (n || r) && ve(e, s, n, r), e;
1533
+ function Et(t, n) {
1534
+ let r = n?.extractRole, i = n?.isSocketNode, a = Ct(n) ? Tt(t, n) : null, o = a ? a.loader : _t, s = a ? a.registerExtensions : St, c = k(o, t, s).userData[Ye];
1535
+ if (!c) throw new e(`useKhrGlb: missing "${Ye}" on loaded GLTF for "${t}"`);
1536
+ return D(() => {
1537
+ let e = _(c);
1538
+ return (r || i) && Ee(e, c, r, i), e;
1461
1539
  }, [
1462
- s,
1463
- n,
1464
- r
1540
+ c,
1541
+ r,
1542
+ i
1465
1543
  ]);
1466
1544
  }
1467
- ht.preload = (e, t) => {
1468
- let n = ft(t) ? mt(e, t) : null, r = n ? n.loader : ot, i = n ? n.registerExtensions : dt;
1469
- D.preload(r, e, i);
1470
- }, ht.clear = (e, t) => {
1471
- if (ft(t)) {
1545
+ Et.preload = (e, t) => {
1546
+ let n = Ct(t) ? Tt(e, t) : null, r = n ? n.loader : _t, i = n ? n.registerExtensions : St;
1547
+ k.preload(r, e, i);
1548
+ }, Et.clear = (e, t) => {
1549
+ if (Ct(t)) {
1472
1550
  let n = $.get(e);
1473
1551
  if (!n) return;
1474
- let r = pt(t), i = n.get(r);
1475
- i && (D.clear(i.loader, e), n.delete(r), n.size === 0 && $.delete(e));
1476
- } else if (D.clear(ot, e), t === void 0) {
1552
+ let r = wt(t), i = n.get(r);
1553
+ i && (k.clear(i.loader, e), n.delete(r), n.size === 0 && $.delete(e));
1554
+ } else if (k.clear(_t, e), t === void 0) {
1477
1555
  let t = $.get(e);
1478
1556
  if (t) {
1479
- for (let n of t.values()) D.clear(n.loader, e);
1557
+ for (let n of t.values()) k.clear(n.loader, e);
1480
1558
  $.delete(e);
1481
1559
  }
1482
1560
  }
1483
1561
  };
1484
- export { y as JointRegistryContext, at as KhrAssembly, t as KhrCollider, v as KhrValidationError, ce as PhysicsWorld, g as assertIdentityWorldScale, i as assertSceneIdentityWorldScale, a as assertUnitScale, d as claimBundleMount, m as cloneKhrBundle, Ve as createKhrGltfPlugin, r as disposeKhrBundle, Xe as exportKhrGlb, We as loadKhrGlb, he as patchGlbJsonChunk, c as releaseBundleMount, ht as useKhrGlb };
1562
+ export { C as JointRegistryContext, gt as KhrAssembly, i as KhrCollider, e as KhrValidationError, ge as PhysicsWorld, y as assertIdentityWorldScale, s as assertSceneIdentityWorldScale, c as assertUnitScale, m as claimBundleMount, _ as cloneKhrBundle, Ze as createKhrGltfPlugin, o as disposeKhrBundle, ot as exportKhrGlb, et as loadKhrGlb, Ce as patchGlbJsonChunk, d as releaseBundleMount, Et as useKhrGlb };