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