@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/README.md +2 -2
- package/dist/{BundleSceneHost-BXLH_LrO.js → BundleSceneHost-CE3HPB8a.js} +203 -75
- package/dist/KhrVehicle.d.ts +5 -7
- 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 +966 -888
- 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 +7 -31
- package/dist/physicsEcs.d.ts +7 -2
- package/dist/vehicle.d.ts +1 -1
- package/dist/vehicle.js +298 -652
- package/dist/wheelLoads.d.ts +1 -9
- package/package.json +5 -7
- package/dist/khrVehicleSettle.d.ts +0 -33
package/dist/index.js
CHANGED
|
@@ -1,70 +1,127 @@
|
|
|
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 } 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
|
|
11
|
-
function
|
|
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
|
-
|
|
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
|
+
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
|
|
21
|
-
if (
|
|
22
|
-
let
|
|
23
|
-
if (
|
|
24
|
-
let
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
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 de = 1e-7;
|
|
53
|
+
function fe(e, t) {
|
|
35
54
|
if (e.stamp === t) return;
|
|
36
|
-
e.parent && e.parent.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) >
|
|
39
|
-
e.dirtyStamp = t, r && (e.lastWrittenQ = e.q), e.kind === "revolute" ? (
|
|
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 && (
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
let
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
|
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:
|
|
67
|
-
let
|
|
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__ */
|
|
77
|
-
value:
|
|
78
|
-
children: /* @__PURE__ */
|
|
79
|
-
value:
|
|
80
|
-
children: /* @__PURE__ */
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
|
97
|
-
function
|
|
98
|
-
if (
|
|
99
|
-
let
|
|
100
|
-
if (
|
|
101
|
-
if (
|
|
102
|
-
let
|
|
103
|
-
if (
|
|
104
|
-
if (20 +
|
|
105
|
-
return
|
|
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
|
|
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
|
|
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,
|
|
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
|
|
139
|
-
let
|
|
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
|
-
|
|
213
|
+
o = JSON.parse(new TextDecoder().decode(new Uint8Array(r, 20, i)));
|
|
142
214
|
} catch {
|
|
143
|
-
throw new
|
|
215
|
+
throw new e("Malformed GLB JSON chunk");
|
|
144
216
|
}
|
|
145
|
-
|
|
146
|
-
let
|
|
147
|
-
return
|
|
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
|
|
151
|
-
function
|
|
152
|
-
|
|
222
|
+
var we = /* @__PURE__ */ new WeakMap();
|
|
223
|
+
function Te(e, t) {
|
|
224
|
+
we.set(e, t);
|
|
153
225
|
}
|
|
154
|
-
function
|
|
155
|
-
let i =
|
|
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
|
|
179
|
-
function
|
|
180
|
-
return e.updateWorldMatrix(!0, !1), e.getWorldQuaternion(
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
|
188
|
-
function
|
|
189
|
-
let
|
|
190
|
-
if (
|
|
191
|
-
if (!
|
|
192
|
-
return
|
|
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
|
|
196
|
-
let
|
|
197
|
-
if (
|
|
198
|
-
if (typeof
|
|
199
|
-
return
|
|
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
|
|
203
|
-
if (
|
|
204
|
-
if (!
|
|
205
|
-
for (let
|
|
206
|
-
if (
|
|
207
|
-
return
|
|
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
|
|
211
|
-
if (
|
|
212
|
-
let
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
],
|
|
217
|
-
if (
|
|
218
|
-
let e = typeof
|
|
219
|
-
|
|
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
|
|
222
|
-
if (
|
|
223
|
-
if (!Array.isArray(
|
|
224
|
-
|
|
225
|
-
for (let
|
|
226
|
-
if (!
|
|
227
|
-
|
|
228
|
-
let
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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
|
-
|
|
305
|
+
i[t.role] = r, l.push([t.role, r]);
|
|
234
306
|
}
|
|
235
307
|
}
|
|
236
308
|
return {
|
|
237
|
-
nodeName:
|
|
238
|
-
extras:
|
|
239
|
-
worldPosition:
|
|
240
|
-
...
|
|
309
|
+
nodeName: n,
|
|
310
|
+
extras: r,
|
|
311
|
+
worldPosition: s,
|
|
312
|
+
...l ? { contactDots: l } : {}
|
|
241
313
|
};
|
|
242
314
|
}
|
|
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
|
|
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:
|
|
262
|
-
object:
|
|
333
|
+
nodeName: n,
|
|
334
|
+
object: t,
|
|
263
335
|
position: [
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
336
|
+
g.x,
|
|
337
|
+
g.y,
|
|
338
|
+
g.z
|
|
267
339
|
],
|
|
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:
|
|
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
|
|
293
|
-
if (
|
|
294
|
-
if (!
|
|
295
|
-
let
|
|
296
|
-
if (
|
|
297
|
-
if (!
|
|
298
|
-
|
|
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
|
|
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:
|
|
303
|
-
object:
|
|
374
|
+
nodeName: n,
|
|
375
|
+
object: t,
|
|
304
376
|
position: [
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
377
|
+
s.x,
|
|
378
|
+
s.y,
|
|
379
|
+
s.z
|
|
308
380
|
],
|
|
309
|
-
quaternion:
|
|
310
|
-
maxThrust:
|
|
311
|
-
torqueRatio:
|
|
312
|
-
invertThrust:
|
|
313
|
-
invertTorque:
|
|
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
|
|
318
|
-
function J(
|
|
319
|
-
if (
|
|
320
|
-
if (typeof
|
|
321
|
-
return
|
|
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
|
|
325
|
-
if (!
|
|
326
|
-
let
|
|
327
|
-
if (
|
|
328
|
-
let
|
|
329
|
-
if (!Array.isArray(
|
|
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
|
-
|
|
334
|
-
|
|
335
|
-
|
|
405
|
+
r[0],
|
|
406
|
+
r[1],
|
|
407
|
+
r[2]
|
|
336
408
|
]
|
|
337
409
|
};
|
|
338
410
|
}
|
|
339
|
-
if (
|
|
340
|
-
let
|
|
341
|
-
if (!q(
|
|
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:
|
|
416
|
+
radius: r
|
|
345
417
|
};
|
|
346
418
|
}
|
|
347
|
-
if ((
|
|
348
|
-
let
|
|
349
|
-
if (!q(
|
|
350
|
-
if (!q(
|
|
351
|
-
if (!q(
|
|
352
|
-
if (Math.abs(
|
|
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:
|
|
355
|
-
height:
|
|
356
|
-
radiusTop:
|
|
357
|
-
radiusBottom:
|
|
426
|
+
type: r,
|
|
427
|
+
height: i.height,
|
|
428
|
+
radiusTop: i.radiusTop,
|
|
429
|
+
radiusBottom: i.radiusBottom
|
|
358
430
|
};
|
|
359
431
|
}
|
|
360
|
-
throw new
|
|
432
|
+
throw new e(`KHR_implicit_shapes[${n}] unsupported shape type "${r}"`);
|
|
361
433
|
}
|
|
362
|
-
function
|
|
363
|
-
if (
|
|
364
|
-
if (typeof
|
|
365
|
-
let
|
|
366
|
-
if (!
|
|
367
|
-
let
|
|
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
|
-
...
|
|
370
|
-
...
|
|
441
|
+
...a !== void 0 || o !== void 0 ? { friction: a ?? o } : {},
|
|
442
|
+
...s === void 0 ? {} : { restitution: s }
|
|
371
443
|
};
|
|
372
444
|
}
|
|
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
|
-
|
|
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 (!
|
|
381
|
-
|
|
452
|
+
if (!Re(t.mass)) throw new e(`Kinematic node "${i}" has invalid motion.mass`);
|
|
453
|
+
o = t.mass;
|
|
382
454
|
}
|
|
383
|
-
let
|
|
455
|
+
let s = t.centerOfMass === void 0 ? [
|
|
384
456
|
0,
|
|
385
457
|
0,
|
|
386
458
|
0
|
|
387
|
-
] :
|
|
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
|
-
] :
|
|
464
|
+
] : b(t.inertiaOrientation, `${i}.motion.inertiaOrientation`), l = [
|
|
393
465
|
0,
|
|
394
466
|
0,
|
|
395
467
|
0
|
|
396
|
-
],
|
|
397
|
-
if (
|
|
398
|
-
let
|
|
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:
|
|
401
|
-
mass:
|
|
402
|
-
centerOfMass:
|
|
403
|
-
inertiaDiagonal:
|
|
404
|
-
inertiaOrientation:
|
|
405
|
-
hasExplicitInertia:
|
|
406
|
-
...
|
|
407
|
-
...
|
|
408
|
-
...
|
|
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
|
|
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
|
-
|
|
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
|
|
498
|
+
return i;
|
|
427
499
|
};
|
|
428
|
-
return
|
|
429
|
-
if (!
|
|
430
|
-
if (
|
|
431
|
-
let
|
|
432
|
-
return (
|
|
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
|
|
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
|
|
449
|
-
return
|
|
450
|
-
let
|
|
451
|
-
if (!
|
|
452
|
-
if (
|
|
453
|
-
if (
|
|
454
|
-
if (
|
|
455
|
-
let
|
|
456
|
-
if (
|
|
457
|
-
let
|
|
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
|
-
...
|
|
460
|
-
mode:
|
|
461
|
-
axis:
|
|
462
|
-
...
|
|
463
|
-
...
|
|
464
|
-
...
|
|
465
|
-
...
|
|
466
|
-
...
|
|
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
|
|
471
|
-
let
|
|
472
|
-
if (!
|
|
473
|
-
if (
|
|
474
|
-
if (
|
|
475
|
-
let
|
|
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
|
-
],
|
|
551
|
+
], p = [
|
|
480
552
|
"unlimited",
|
|
481
553
|
"unlimited",
|
|
482
554
|
"unlimited"
|
|
483
|
-
],
|
|
555
|
+
], m = [
|
|
484
556
|
void 0,
|
|
485
557
|
void 0,
|
|
486
558
|
void 0
|
|
487
|
-
],
|
|
559
|
+
], h = [
|
|
488
560
|
void 0,
|
|
489
561
|
void 0,
|
|
490
562
|
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
|
-
...
|
|
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
|
|
508
|
-
if (!
|
|
509
|
-
|
|
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
|
|
583
|
+
let _ = [
|
|
512
584
|
0,
|
|
513
585
|
1,
|
|
514
586
|
2
|
|
515
|
-
].filter((e) =>
|
|
587
|
+
].filter((e) => f[e] !== "locked"), v = [
|
|
516
588
|
0,
|
|
517
589
|
1,
|
|
518
590
|
2
|
|
519
|
-
].filter((e) =>
|
|
591
|
+
].filter((e) => p[e] !== "locked"), y, b = [
|
|
520
592
|
0,
|
|
521
593
|
1,
|
|
522
594
|
0
|
|
523
595
|
], x = null, S;
|
|
524
|
-
if (
|
|
525
|
-
else if (
|
|
526
|
-
y = "revolute", b =
|
|
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
|
|
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());
|
|
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:
|
|
537
|
-
nodeName:
|
|
538
|
-
connectedNodeName:
|
|
608
|
+
index: n,
|
|
609
|
+
nodeName: r,
|
|
610
|
+
connectedNodeName: c,
|
|
539
611
|
kind: y,
|
|
540
612
|
axis: b,
|
|
541
613
|
limits: x,
|
|
542
|
-
enableCollision:
|
|
543
|
-
role:
|
|
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(
|
|
563
|
-
if (
|
|
564
|
-
if (!Array.isArray(
|
|
565
|
-
return
|
|
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
|
|
639
|
+
function Ke() {
|
|
568
640
|
return (e) => ({
|
|
569
641
|
name: "khr3_headless_texture",
|
|
570
642
|
loadTexture(t) {
|
|
571
|
-
let n = new
|
|
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
|
|
577
|
-
let
|
|
578
|
-
for (let
|
|
579
|
-
let
|
|
580
|
-
if (!Y(
|
|
581
|
-
let
|
|
582
|
-
if (
|
|
583
|
-
if (!Array.isArray(
|
|
584
|
-
for (let
|
|
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
|
|
588
|
-
if (Array.isArray(
|
|
589
|
-
let
|
|
590
|
-
if (!Y(
|
|
591
|
-
if (
|
|
592
|
-
|
|
593
|
-
if (typeof
|
|
594
|
-
return
|
|
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
|
|
597
|
-
for (;
|
|
598
|
-
let e =
|
|
599
|
-
if (
|
|
600
|
-
|
|
601
|
-
let
|
|
602
|
-
if (
|
|
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 <
|
|
605
|
-
let
|
|
606
|
-
for (let
|
|
607
|
-
let
|
|
608
|
-
if (
|
|
609
|
-
if (
|
|
610
|
-
let
|
|
611
|
-
throw new
|
|
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
|
|
614
|
-
let
|
|
615
|
-
throw new
|
|
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
|
-
|
|
689
|
+
i[a] = t;
|
|
618
690
|
}
|
|
619
691
|
}
|
|
620
|
-
let
|
|
621
|
-
let r =
|
|
622
|
-
if (
|
|
623
|
-
for (
|
|
624
|
-
|
|
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
|
-
|
|
698
|
+
l[e] = i;
|
|
627
699
|
};
|
|
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
|
|
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
|
|
715
|
+
for (let e = 0; e < a.length; e++) r(a[e], t.scene.children[e]);
|
|
644
716
|
}
|
|
645
717
|
return {
|
|
646
|
-
parentIdx:
|
|
647
|
-
nodeNames:
|
|
648
|
-
resolveObj: (
|
|
649
|
-
if (
|
|
650
|
-
let r =
|
|
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 =
|
|
653
|
-
return
|
|
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
|
|
658
|
-
if (!Y(
|
|
659
|
-
let
|
|
660
|
-
if (!Y(
|
|
661
|
-
if (
|
|
662
|
-
if (typeof
|
|
663
|
-
return
|
|
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 (
|
|
666
|
-
if (typeof
|
|
667
|
-
if (
|
|
668
|
-
let
|
|
669
|
-
if (!
|
|
670
|
-
return
|
|
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
|
|
744
|
+
throw new e(`Node "${n}" collider.geometry must specify shape or node`);
|
|
673
745
|
}
|
|
674
746
|
// 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) =>
|
|
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 =
|
|
760
|
+
let t = v(e);
|
|
689
761
|
if (!t) continue;
|
|
690
762
|
let r = Y(m[e].extras) ? m[e].extras : {};
|
|
691
|
-
y.push(
|
|
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 = [],
|
|
694
|
-
for (let 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
|
-
},
|
|
697
|
-
for (let t = e; t !== -1; 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
|
|
704
|
-
let
|
|
705
|
-
if (!
|
|
706
|
-
let
|
|
707
|
-
if (
|
|
708
|
-
if (
|
|
709
|
-
|
|
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 (
|
|
713
|
-
let
|
|
714
|
-
if (
|
|
715
|
-
if (!Y(
|
|
716
|
-
if (
|
|
717
|
-
if (
|
|
718
|
-
if (
|
|
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 (
|
|
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
|
-
|
|
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
|
|
737
|
-
nodeName:
|
|
738
|
-
...
|
|
808
|
+
let h = o.getWorldPosition(new N.Vector3()), y = o.getWorldQuaternion(new N.Quaternion()), b = {
|
|
809
|
+
nodeName: a,
|
|
810
|
+
...u,
|
|
739
811
|
localPosition: [
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
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:
|
|
752
|
-
object:
|
|
753
|
-
role:
|
|
823
|
+
joint: f,
|
|
824
|
+
object: o,
|
|
825
|
+
role: d
|
|
754
826
|
};
|
|
755
827
|
x.push(b), S.push({
|
|
756
|
-
nodeName:
|
|
757
|
-
extras:
|
|
758
|
-
}), C.set(
|
|
828
|
+
nodeName: a,
|
|
829
|
+
extras: s
|
|
830
|
+
}), C.set(r, b);
|
|
759
831
|
}
|
|
760
|
-
for (let
|
|
761
|
-
if (
|
|
762
|
-
let
|
|
763
|
-
if (
|
|
764
|
-
let
|
|
765
|
-
if (!
|
|
766
|
-
let
|
|
767
|
-
if (!
|
|
768
|
-
let
|
|
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
|
-
} :
|
|
781
|
-
if (
|
|
782
|
-
if (typeof
|
|
783
|
-
|
|
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
|
-
|
|
786
|
-
shape:
|
|
787
|
-
localPosition:
|
|
788
|
-
localQuaternion:
|
|
789
|
-
...
|
|
790
|
-
...
|
|
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 =
|
|
794
|
-
let { totalDynamicMass:
|
|
795
|
-
if (
|
|
796
|
-
if (!Y(
|
|
797
|
-
for (let [
|
|
798
|
-
let
|
|
799
|
-
b[
|
|
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
|
|
803
|
-
return
|
|
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:
|
|
878
|
+
ikSockets: k
|
|
807
879
|
}), {
|
|
808
880
|
scene: t.scene,
|
|
809
881
|
bodies: x,
|
|
810
882
|
wheels: T,
|
|
811
|
-
propellers:
|
|
883
|
+
propellers: ee,
|
|
812
884
|
sockets: b,
|
|
813
|
-
totalDynamicMass:
|
|
814
|
-
centerOfMass:
|
|
815
|
-
tune:
|
|
816
|
-
droneTune:
|
|
885
|
+
totalDynamicMass: O,
|
|
886
|
+
centerOfMass: te,
|
|
887
|
+
tune: j,
|
|
888
|
+
droneTune: M
|
|
817
889
|
};
|
|
818
890
|
}
|
|
819
|
-
function
|
|
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
|
|
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[
|
|
900
|
+
return t.userData[Ye] = Xe(t, e), null;
|
|
829
901
|
}
|
|
830
902
|
});
|
|
831
903
|
}
|
|
832
904
|
// src/khrLoader.ts
|
|
833
|
-
var
|
|
834
|
-
function
|
|
835
|
-
let e = new
|
|
836
|
-
return typeof document > "u" && typeof createImageBitmap > "u" && e.register(
|
|
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
|
|
839
|
-
let
|
|
840
|
-
new Uint8Array(
|
|
841
|
-
let
|
|
842
|
-
|
|
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
|
|
845
|
-
|
|
846
|
-
}).catch((
|
|
847
|
-
throw e
|
|
848
|
-
})).userData[
|
|
849
|
-
if (!
|
|
850
|
-
return
|
|
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
|
-
|
|
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(
|
|
858
|
-
if (
|
|
859
|
-
if (typeof
|
|
860
|
-
return
|
|
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
|
|
864
|
-
if (
|
|
865
|
-
if (!Array.isArray(
|
|
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:
|
|
940
|
+
box: { size: t.size }
|
|
869
941
|
};
|
|
870
942
|
}
|
|
871
|
-
if (
|
|
872
|
-
if (!Z(
|
|
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:
|
|
947
|
+
sphere: { radius: t.radius }
|
|
876
948
|
};
|
|
877
949
|
}
|
|
878
|
-
if (!Z(
|
|
879
|
-
if (Math.abs(
|
|
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:
|
|
882
|
-
[
|
|
883
|
-
height:
|
|
884
|
-
radiusTop:
|
|
885
|
-
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
|
|
890
|
-
if (!Array.isArray(
|
|
891
|
-
let
|
|
892
|
-
if (Math.hypot(
|
|
893
|
-
return
|
|
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
|
|
896
|
-
if (!
|
|
897
|
-
if (
|
|
898
|
-
if (
|
|
899
|
-
if (
|
|
900
|
-
let
|
|
901
|
-
if (
|
|
902
|
-
let
|
|
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:
|
|
905
|
-
mode:
|
|
906
|
-
axis:
|
|
907
|
-
...
|
|
908
|
-
...
|
|
909
|
-
...
|
|
910
|
-
...
|
|
911
|
-
...
|
|
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
|
|
915
|
-
if (
|
|
916
|
-
if (
|
|
917
|
-
if (
|
|
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
|
|
1008
|
+
let r = nt(t.axis, t.kind, n), i = [
|
|
937
1009
|
0,
|
|
938
1010
|
1,
|
|
939
1011
|
2
|
|
940
|
-
].filter((e) => e !==
|
|
941
|
-
if (
|
|
942
|
-
let
|
|
943
|
-
[
|
|
944
|
-
...
|
|
945
|
-
min:
|
|
946
|
-
max:
|
|
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
|
-
...
|
|
949
|
-
...
|
|
950
|
-
}] : [],
|
|
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:
|
|
1033
|
+
angularAxes: i,
|
|
962
1034
|
min: 0,
|
|
963
1035
|
max: 0
|
|
964
1036
|
},
|
|
965
|
-
...
|
|
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:
|
|
1049
|
+
linearAxes: i,
|
|
978
1050
|
min: 0,
|
|
979
1051
|
max: 0
|
|
980
1052
|
},
|
|
981
|
-
...
|
|
982
|
-
] },
|
|
983
|
-
return
|
|
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
|
|
986
|
-
let
|
|
987
|
-
if (!
|
|
988
|
-
if (
|
|
989
|
-
if (t.gravityFactor !== void 0 && (typeof t.gravityFactor != "number" || !Number.isFinite(t.gravityFactor))) throw new
|
|
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:
|
|
1063
|
+
isKinematic: i,
|
|
992
1064
|
...t.mass === void 0 ? {} : { mass: t.mass },
|
|
993
|
-
...t.centerOfMass ? { centerOfMass:
|
|
1065
|
+
...t.centerOfMass ? { centerOfMass: r(t.centerOfMass, `${n}.motion.centerOfMass`) } : {},
|
|
994
1066
|
...t.inertiaDiagonal ? { inertiaDiagonal: t.inertiaDiagonal } : {},
|
|
995
|
-
...t.inertiaOrientation ? { inertiaOrientation:
|
|
996
|
-
...t.linearVelocity ? { linearVelocity:
|
|
997
|
-
...t.angularVelocity ? { 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
|
|
1002
|
-
|
|
1003
|
-
let
|
|
1004
|
-
return
|
|
1005
|
-
|
|
1006
|
-
}), (
|
|
1007
|
-
let
|
|
1008
|
-
|
|
1009
|
-
e.name &&
|
|
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
|
|
1012
|
-
let
|
|
1013
|
-
if (
|
|
1014
|
-
return
|
|
1015
|
-
},
|
|
1016
|
-
for (let
|
|
1017
|
-
let
|
|
1018
|
-
|
|
1019
|
-
...
|
|
1020
|
-
...
|
|
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
|
|
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:
|
|
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
|
|
1036
|
-
let
|
|
1037
|
-
if ((
|
|
1038
|
-
...
|
|
1039
|
-
staticFriction:
|
|
1040
|
-
dynamicFriction:
|
|
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
|
-
...
|
|
1043
|
-
})),
|
|
1044
|
-
if (
|
|
1045
|
-
if (!Array.isArray(
|
|
1046
|
-
|
|
1047
|
-
collisionSystems:
|
|
1048
|
-
...
|
|
1049
|
-
...
|
|
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
|
-
|
|
1124
|
+
r.collider = n;
|
|
1053
1125
|
}
|
|
1054
|
-
if (
|
|
1055
|
-
|
|
1056
|
-
let
|
|
1057
|
-
|
|
1058
|
-
joint:
|
|
1059
|
-
connectedNode:
|
|
1060
|
-
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(
|
|
1064
|
-
...
|
|
1065
|
-
KHR_physics_rigid_bodies:
|
|
1135
|
+
Object.keys(r).length > 0 && (n.extensions = {
|
|
1136
|
+
...n.extensions,
|
|
1137
|
+
KHR_physics_rigid_bodies: r
|
|
1066
1138
|
});
|
|
1067
1139
|
}
|
|
1068
|
-
if (
|
|
1069
|
-
let
|
|
1070
|
-
|
|
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
|
-
...
|
|
1144
|
+
...r
|
|
1145
|
+
} : t.extras = {
|
|
1146
|
+
...t.extras,
|
|
1147
|
+
...r
|
|
1076
1148
|
};
|
|
1077
1149
|
}
|
|
1078
|
-
let
|
|
1079
|
-
|
|
1080
|
-
...
|
|
1081
|
-
...
|
|
1082
|
-
...
|
|
1083
|
-
}),
|
|
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
|
-
|
|
1088
|
-
|
|
1089
|
-
let n =
|
|
1090
|
-
|
|
1091
|
-
|
|
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
|
|
1165
|
+
return r;
|
|
1095
1166
|
}
|
|
1096
|
-
function
|
|
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
|
|
1110
|
-
|
|
1111
|
-
return
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
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
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1210
|
+
o.x,
|
|
1211
|
+
o.y,
|
|
1212
|
+
o.z
|
|
1121
1213
|
],
|
|
1122
1214
|
quaternion: [
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1215
|
+
s.x,
|
|
1216
|
+
s.y,
|
|
1217
|
+
s.z,
|
|
1218
|
+
s.w
|
|
1127
1219
|
]
|
|
1128
1220
|
};
|
|
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;
|
|
1221
|
+
return r === 0 && n && (l.massProperties = lt(n, a, i)), l;
|
|
1152
1222
|
});
|
|
1153
1223
|
}
|
|
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
|
-
|
|
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
|
|
1177
|
-
}),
|
|
1178
|
-
|
|
1179
|
-
let
|
|
1180
|
-
return
|
|
1181
|
-
spec:
|
|
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
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1257
|
+
g.x,
|
|
1258
|
+
g.y,
|
|
1259
|
+
g.z
|
|
1186
1260
|
],
|
|
1187
1261
|
sceneInRootQuat: [
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1262
|
+
_.x,
|
|
1263
|
+
_.y,
|
|
1264
|
+
_.z,
|
|
1265
|
+
_.w
|
|
1192
1266
|
],
|
|
1193
|
-
mountNode:
|
|
1194
|
-
mountInRoot:
|
|
1267
|
+
mountNode: m,
|
|
1268
|
+
mountInRoot: h,
|
|
1195
1269
|
mountPosition: [
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1270
|
+
y.x,
|
|
1271
|
+
y.y,
|
|
1272
|
+
y.z
|
|
1199
1273
|
],
|
|
1200
1274
|
mountQuaternion: [
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1275
|
+
b.x,
|
|
1276
|
+
b.y,
|
|
1277
|
+
b.z,
|
|
1278
|
+
b.w
|
|
1205
1279
|
],
|
|
1206
|
-
|
|
1207
|
-
|
|
1280
|
+
...p ? { rootMass: p } : {},
|
|
1281
|
+
colliders: f,
|
|
1282
|
+
parts: u
|
|
1208
1283
|
};
|
|
1209
1284
|
});
|
|
1210
|
-
for (let
|
|
1211
|
-
return
|
|
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
|
|
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
|
|
1219
|
-
let u =
|
|
1220
|
-
|
|
1221
|
-
let t =
|
|
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:
|
|
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
|
|
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 ?
|
|
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
|
-
|
|
1328
|
+
n.set(o.nodeName, o), u?.add(o);
|
|
1251
1329
|
}
|
|
1252
|
-
return c(p.nodeName,
|
|
1330
|
+
return c(p.nodeName, n), () => {
|
|
1253
1331
|
c(p.nodeName, null);
|
|
1254
|
-
for (let e of
|
|
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
|
-
|
|
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__ */
|
|
1343
|
+
return /* @__PURE__ */ F(j, {
|
|
1266
1344
|
...o,
|
|
1267
1345
|
ref: d,
|
|
1268
1346
|
type: m,
|
|
1269
|
-
position:
|
|
1270
|
-
quaternion:
|
|
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,
|
|
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${
|
|
1283
|
-
e.parts.map((e,
|
|
1284
|
-
ref: f[
|
|
1285
|
-
c:
|
|
1286
|
-
position:
|
|
1287
|
-
quaternion:
|
|
1288
|
-
massProperties:
|
|
1289
|
-
}, `${e.spec.nodeName}:${
|
|
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
|
|
1295
|
-
function
|
|
1372
|
+
var ht = 0;
|
|
1373
|
+
function gt({ ref: t, bundle: n, position: r = [
|
|
1296
1374
|
0,
|
|
1297
1375
|
0,
|
|
1298
1376
|
0
|
|
1299
|
-
], rotation:
|
|
1300
|
-
|
|
1301
|
-
let m =
|
|
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
|
-
], [
|
|
1383
|
+
], [E, te, k, A] = a ?? [
|
|
1306
1384
|
NaN,
|
|
1307
1385
|
NaN,
|
|
1308
1386
|
NaN,
|
|
1309
1387
|
NaN
|
|
1310
|
-
],
|
|
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
|
-
|
|
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));
|
|
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
|
-
|
|
1335
|
-
|
|
1412
|
+
h,
|
|
1413
|
+
j,
|
|
1336
1414
|
y,
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
]),
|
|
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
|
|
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
|
-
}, [
|
|
1347
|
-
t ?
|
|
1348
|
-
}, []),
|
|
1349
|
-
t ?
|
|
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 (
|
|
1352
|
-
let
|
|
1353
|
-
if (!
|
|
1354
|
-
|
|
1355
|
-
let
|
|
1356
|
-
|
|
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 =
|
|
1361
|
-
return t ?
|
|
1438
|
+
let t = R.get(e);
|
|
1439
|
+
return t ? I.current.get(t)?.current ?? null : null;
|
|
1362
1440
|
},
|
|
1363
|
-
setJointTarget: (
|
|
1364
|
-
let r =
|
|
1365
|
-
r &&
|
|
1441
|
+
setJointTarget: (e, n) => {
|
|
1442
|
+
let r = L.current.get(R.get(e) ?? "")?.get(e);
|
|
1443
|
+
r && t(r, n);
|
|
1366
1444
|
},
|
|
1367
|
-
setRoleTarget: (
|
|
1368
|
-
for (let r of
|
|
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
|
-
}, [
|
|
1372
|
-
let e =
|
|
1373
|
-
return /* @__PURE__ */
|
|
1449
|
+
}, [R]), h.length === 1) {
|
|
1450
|
+
let e = h[0];
|
|
1451
|
+
return /* @__PURE__ */ P("group", {
|
|
1374
1452
|
...f,
|
|
1375
|
-
children: /* @__PURE__ */
|
|
1453
|
+
children: /* @__PURE__ */ P(mt, {
|
|
1376
1454
|
plan: e,
|
|
1377
1455
|
assemblyId: m,
|
|
1378
|
-
position:
|
|
1379
|
-
quaternion:
|
|
1380
|
-
fixedRoot:
|
|
1381
|
-
rigidBodyProps:
|
|
1382
|
-
onBody:
|
|
1383
|
-
onJoints:
|
|
1384
|
-
children: /* @__PURE__ */
|
|
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__ */
|
|
1388
|
-
bundle:
|
|
1465
|
+
children: [/* @__PURE__ */ P(v, {
|
|
1466
|
+
bundle: n,
|
|
1389
1467
|
owner: "KhrAssembly"
|
|
1390
1468
|
}), d]
|
|
1391
1469
|
})
|
|
1392
|
-
}, `${
|
|
1470
|
+
}, `${n.scene.uuid}:${e.spec.nodeName}`)
|
|
1393
1471
|
});
|
|
1394
1472
|
}
|
|
1395
|
-
return /* @__PURE__ */
|
|
1473
|
+
return /* @__PURE__ */ F("group", {
|
|
1396
1474
|
...f,
|
|
1397
|
-
children: [/* @__PURE__ */
|
|
1398
|
-
position:
|
|
1399
|
-
quaternion:
|
|
1400
|
-
children: [/* @__PURE__ */
|
|
1401
|
-
bundle:
|
|
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
|
-
}),
|
|
1482
|
+
}), h.map((e, t) => /* @__PURE__ */ P(mt, {
|
|
1405
1483
|
plan: e,
|
|
1406
1484
|
assemblyId: m,
|
|
1407
|
-
position:
|
|
1408
|
-
quaternion:
|
|
1409
|
-
fixedRoot:
|
|
1410
|
-
rigidBodyProps:
|
|
1411
|
-
onBody:
|
|
1412
|
-
onJoints:
|
|
1413
|
-
children: /* @__PURE__ */
|
|
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
|
-
}, `${
|
|
1497
|
+
}, `${n.scene.uuid}:${e.spec.nodeName}`))]
|
|
1420
1498
|
});
|
|
1421
1499
|
}
|
|
1422
1500
|
// src/useKhrGlb.ts
|
|
1423
|
-
var
|
|
1501
|
+
var _t = class extends I {
|
|
1424
1502
|
static khrLoaderScope = Symbol("KhrGLTFLoader");
|
|
1425
|
-
},
|
|
1426
|
-
function
|
|
1427
|
-
|
|
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
|
|
1507
|
+
function Ct(e) {
|
|
1430
1508
|
return !!(e?.extendLoader || e?.cacheKey !== void 0);
|
|
1431
1509
|
}
|
|
1432
|
-
function
|
|
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
|
|
1436
|
-
let n =
|
|
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
|
|
1518
|
+
let a = new I(), o = t.extendLoader, s = {
|
|
1441
1519
|
loader: a,
|
|
1442
1520
|
registerExtensions: (t) => {
|
|
1443
|
-
if (
|
|
1444
|
-
o(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
|
|
1456
|
-
let
|
|
1457
|
-
if (!
|
|
1458
|
-
return
|
|
1459
|
-
let e =
|
|
1460
|
-
return (
|
|
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
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1540
|
+
c,
|
|
1541
|
+
r,
|
|
1542
|
+
i
|
|
1465
1543
|
]);
|
|
1466
1544
|
}
|
|
1467
|
-
|
|
1468
|
-
let n =
|
|
1469
|
-
|
|
1470
|
-
},
|
|
1471
|
-
if (
|
|
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 =
|
|
1475
|
-
i && (
|
|
1476
|
-
} else if (
|
|
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())
|
|
1557
|
+
for (let n of t.values()) k.clear(n.loader, e);
|
|
1480
1558
|
$.delete(e);
|
|
1481
1559
|
}
|
|
1482
1560
|
}
|
|
1483
1561
|
};
|
|
1484
|
-
export {
|
|
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 };
|