@khr3/core 0.1.5 → 0.2.0
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 +3 -114
- package/dist/BundleSceneHost-DUqqPtJF.js +1036 -0
- package/dist/BundleSceneHost-DUqqPtJF.js.map +1 -0
- package/dist/KhrCollider.d.ts +1 -1
- package/dist/KhrVehicle.d.ts +5 -7
- package/dist/PhysicsWorld.d.ts +2 -2
- package/dist/assemblyPlan.d.ts +2 -0
- package/dist/curves.d.ts +11 -32
- package/dist/curves.js +141 -139
- package/dist/curves.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1639 -1240
- package/dist/index.js.map +1 -0
- package/dist/jointDynamics.d.ts +1 -1
- package/dist/khrBundleFinalize.d.ts +14 -0
- package/dist/khrConfigTypes.d.ts +62 -0
- package/dist/khrExportEncoders.d.ts +8 -0
- package/dist/khrExporter.d.ts +2 -1
- package/dist/khrExtras.d.ts +3 -3
- package/dist/khrGlb.d.ts +23 -0
- package/dist/khrJointParser.d.ts +3 -0
- package/dist/khrLoader.d.ts +2 -1
- package/dist/khrParsers.d.ts +5 -9
- package/dist/khrPlugin.d.ts +2 -3
- package/dist/khrPluginHelpers.d.ts +4 -0
- package/dist/khrRotorDecoders.d.ts +4 -0
- package/dist/khrShapeParser.d.ts +8 -0
- package/dist/khrTypes.d.ts +11 -103
- package/dist/khrVehicleChassis.d.ts +9 -17
- package/dist/khrVehicleJointHelpers.d.ts +24 -0
- package/dist/khrVehicleJoints.d.ts +18 -0
- package/dist/khrVehicleRotors.d.ts +22 -0
- package/dist/khrVehicleSlots.d.ts +19 -15
- package/dist/khrVehicleTypes.d.ts +52 -0
- package/dist/pacejka.d.ts +1 -1
- package/dist/physicsEcs.d.ts +2 -7
- package/dist/useKhrGlb.d.ts +2 -2
- package/dist/vehicle.d.ts +2 -2
- package/dist/vehicle.js +757 -451
- package/dist/vehicle.js.map +1 -0
- package/dist/wheelLoads.d.ts +4 -7
- package/docs/api-reference.md +209 -0
- package/package.json +8 -7
- package/dist/BundleSceneHost-CE3HPB8a.js +0 -556
|
@@ -1,556 +0,0 @@
|
|
|
1
|
-
import { createContext as e, useCallback as t, useEffect as n, useLayoutEffect as r, useRef as i } from "react";
|
|
2
|
-
import { BallCollider as a, CapsuleCollider as o, ConvexHullCollider as s, CuboidCollider as c, CylinderCollider as l, TrimeshCollider as u } from "@react-three/rapier";
|
|
3
|
-
import * as d from "three";
|
|
4
|
-
import { jsx as f } from "react/jsx-runtime";
|
|
5
|
-
// src/khrMassProps.ts
|
|
6
|
-
var p = new d.Vector3(), m = new d.Quaternion(), h = new d.Quaternion(), g = new d.Vector3(), _ = new d.Vector3(1, 1, 1), v = new d.Matrix4(), y = new d.Matrix4(), b = new d.Vector3();
|
|
7
|
-
function x(e, t = new d.Matrix4()) {
|
|
8
|
-
return p.fromArray(e.localPosition), m.fromArray(e.localQuaternion), t.compose(p, m, _);
|
|
9
|
-
}
|
|
10
|
-
function S(e, t, n, r, i, a) {
|
|
11
|
-
let o = [
|
|
12
|
-
[
|
|
13
|
-
e,
|
|
14
|
-
r,
|
|
15
|
-
i
|
|
16
|
-
],
|
|
17
|
-
[
|
|
18
|
-
r,
|
|
19
|
-
t,
|
|
20
|
-
a
|
|
21
|
-
],
|
|
22
|
-
[
|
|
23
|
-
i,
|
|
24
|
-
a,
|
|
25
|
-
n
|
|
26
|
-
]
|
|
27
|
-
], s = [
|
|
28
|
-
[
|
|
29
|
-
1,
|
|
30
|
-
0,
|
|
31
|
-
0
|
|
32
|
-
],
|
|
33
|
-
[
|
|
34
|
-
0,
|
|
35
|
-
1,
|
|
36
|
-
0
|
|
37
|
-
],
|
|
38
|
-
[
|
|
39
|
-
0,
|
|
40
|
-
0,
|
|
41
|
-
1
|
|
42
|
-
]
|
|
43
|
-
];
|
|
44
|
-
for (let e = 0; e < 32; e++) {
|
|
45
|
-
let e = Math.max(o[0][0] + o[1][1] + o[2][2], 0), t = 0, n = 1, r = Math.abs(o[0][1]);
|
|
46
|
-
if (Math.abs(o[0][2]) > r && (t = 0, n = 2, r = Math.abs(o[0][2])), Math.abs(o[1][2]) > r && (t = 1, n = 2, r = Math.abs(o[1][2])), r <= 1e-12 * e) break;
|
|
47
|
-
let i = o[t][n], a = o[t][t], c = o[n][n], l = (c - a) / (2 * i), u = l >= 0 ? 1 / (l + Math.sqrt(1 + l * l)) : -1 / (-l + Math.sqrt(1 + l * l)), d = 1 / Math.sqrt(1 + u * u), f = u * d, p = 3 - t - n;
|
|
48
|
-
o[t][t] = d * d * a - 2 * f * d * i + f * f * c, o[n][n] = f * f * a + 2 * f * d * i + d * d * c, o[t][n] = o[n][t] = 0;
|
|
49
|
-
let m = o[p][t], h = o[p][n];
|
|
50
|
-
o[p][t] = o[t][p] = d * m - f * h, o[p][n] = o[n][p] = f * m + d * h;
|
|
51
|
-
for (let e = 0; e < 3; e++) {
|
|
52
|
-
let r = s[e][t], i = s[e][n];
|
|
53
|
-
s[e][t] = d * r - f * i, s[e][n] = f * r + d * i;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return s[0][0] * (s[1][1] * s[2][2] - s[1][2] * s[2][1]) - s[0][1] * (s[1][0] * s[2][2] - s[1][2] * s[2][0]) + s[0][2] * (s[1][0] * s[2][1] - s[1][1] * s[2][0]) < 0 && (s[0][2] = -s[0][2], s[1][2] = -s[1][2], s[2][2] = -s[2][2]), v.set(s[0][0], s[0][1], s[0][2], 0, s[1][0], s[1][1], s[1][2], 0, s[2][0], s[2][1], s[2][2], 0, 0, 0, 0, 1), m.setFromRotationMatrix(v).normalize(), {
|
|
57
|
-
inertia: [
|
|
58
|
-
o[0][0],
|
|
59
|
-
o[1][1],
|
|
60
|
-
o[2][2]
|
|
61
|
-
],
|
|
62
|
-
inertiaFrame: [
|
|
63
|
-
m.x,
|
|
64
|
-
m.y,
|
|
65
|
-
m.z,
|
|
66
|
-
m.w
|
|
67
|
-
]
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
function C(e, t) {
|
|
71
|
-
t ? (v.multiplyMatrices(t, x(e, y)).decompose(p, m, g), m.normalize()) : (p.fromArray(e.localPosition), m.fromArray(e.localQuaternion).normalize());
|
|
72
|
-
}
|
|
73
|
-
function w(e, t) {
|
|
74
|
-
let n = e.filter((e) => !e.isKinematic && e.mass > 0);
|
|
75
|
-
if (n.length === 0) return null;
|
|
76
|
-
let r = 0, i = 0, a = 0, o = 0;
|
|
77
|
-
for (let e of n) C(e, t), b.fromArray(e.centerOfMass).applyQuaternion(m), r += e.mass, i += (p.x + b.x) * e.mass, a += (p.y + b.y) * e.mass, o += (p.z + b.z) * e.mass;
|
|
78
|
-
if (!(r > 0)) return null;
|
|
79
|
-
let s = [
|
|
80
|
-
i / r,
|
|
81
|
-
a / r,
|
|
82
|
-
o / r
|
|
83
|
-
], c = 0, l = 0, u = 0, d = 0, f = 0, g = 0, _ = v.elements;
|
|
84
|
-
for (let e of n) {
|
|
85
|
-
C(e, t), b.fromArray(e.centerOfMass).applyQuaternion(m);
|
|
86
|
-
let n = p.x + b.x - s[0], r = p.y + b.y - s[1], i = p.z + b.z - s[2];
|
|
87
|
-
v.makeRotationFromQuaternion(m.multiply(h.fromArray(e.inertiaOrientation)));
|
|
88
|
-
let [a, o, y] = e.inertiaDiagonal;
|
|
89
|
-
c += _[0] * _[0] * a + _[4] * _[4] * o + _[8] * _[8] * y + e.mass * (r * r + i * i), l += _[1] * _[1] * a + _[5] * _[5] * o + _[9] * _[9] * y + e.mass * (n * n + i * i), u += _[2] * _[2] * a + _[6] * _[6] * o + _[10] * _[10] * y + e.mass * (n * n + r * r), d += _[0] * _[1] * a + _[4] * _[5] * o + _[8] * _[9] * y - e.mass * n * r, f += _[0] * _[2] * a + _[4] * _[6] * o + _[8] * _[10] * y - e.mass * n * i, g += _[1] * _[2] * a + _[5] * _[6] * o + _[9] * _[10] * y - e.mass * r * i;
|
|
90
|
-
}
|
|
91
|
-
if (n.length === 1) {
|
|
92
|
-
let e = n[0];
|
|
93
|
-
return C(e, t), m.multiply(h.fromArray(e.inertiaOrientation)).normalize(), {
|
|
94
|
-
mass: r,
|
|
95
|
-
com: s,
|
|
96
|
-
inertia: [
|
|
97
|
-
e.inertiaDiagonal[0],
|
|
98
|
-
e.inertiaDiagonal[1],
|
|
99
|
-
e.inertiaDiagonal[2]
|
|
100
|
-
],
|
|
101
|
-
inertiaFrame: [
|
|
102
|
-
m.x,
|
|
103
|
-
m.y,
|
|
104
|
-
m.z,
|
|
105
|
-
m.w
|
|
106
|
-
]
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
let y = Math.max(c + l + u, 0);
|
|
110
|
-
if (Math.max(Math.abs(d), Math.abs(f), Math.abs(g)) <= 1e-12 * y) return {
|
|
111
|
-
mass: r,
|
|
112
|
-
com: s,
|
|
113
|
-
inertia: [
|
|
114
|
-
c,
|
|
115
|
-
l,
|
|
116
|
-
u
|
|
117
|
-
],
|
|
118
|
-
inertiaFrame: [
|
|
119
|
-
0,
|
|
120
|
-
0,
|
|
121
|
-
0,
|
|
122
|
-
1
|
|
123
|
-
]
|
|
124
|
-
};
|
|
125
|
-
let { inertia: x, inertiaFrame: w } = S(c, l, u, d, f, g);
|
|
126
|
-
return {
|
|
127
|
-
mass: r,
|
|
128
|
-
com: s,
|
|
129
|
-
inertia: x,
|
|
130
|
-
inertiaFrame: w
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
// src/khrTypes.ts
|
|
134
|
-
var T = class extends Error {
|
|
135
|
-
constructor(e) {
|
|
136
|
-
super(e), this.name = "KhrValidationError";
|
|
137
|
-
}
|
|
138
|
-
}, E = e(null), D = e(null), O = e(!0), k = e(null), A = 1e-4;
|
|
139
|
-
function j(e) {
|
|
140
|
-
return typeof e == "number" && Number.isFinite(e) && Math.abs(e - 1) <= 1e-9;
|
|
141
|
-
}
|
|
142
|
-
function M(e, t) {
|
|
143
|
-
if (e === void 0) return;
|
|
144
|
-
let n = !1;
|
|
145
|
-
if (typeof e == "number") n = j(e);
|
|
146
|
-
else if (Array.isArray(e)) n = e.length === 3 && e.every(j);
|
|
147
|
-
else if (typeof e == "object" && e && "x" in e && "y" in e && "z" in e) {
|
|
148
|
-
let t = e;
|
|
149
|
-
n = j(t.x) && j(t.y) && j(t.z);
|
|
150
|
-
}
|
|
151
|
-
if (!n) throw new T(`${t}: scale must be 1 (got ${typeof e == "number" && !Number.isFinite(e) ? String(e) : JSON.stringify(e)}); bake scale into the .glb at import`);
|
|
152
|
-
}
|
|
153
|
-
function N(e, t) {
|
|
154
|
-
if (!Array.isArray(e) || e.length !== 3 || !e.every((e) => typeof e == "number" && Number.isFinite(e))) throw new T(`Invalid ${t}: expected finite 3-tuple`);
|
|
155
|
-
return [
|
|
156
|
-
e[0],
|
|
157
|
-
e[1],
|
|
158
|
-
e[2]
|
|
159
|
-
];
|
|
160
|
-
}
|
|
161
|
-
function P(e, t) {
|
|
162
|
-
if (!Array.isArray(e) || e.length !== 4 || !e.every((e) => typeof e == "number" && Number.isFinite(e))) throw new T(`Invalid ${t}: expected finite 4-tuple`);
|
|
163
|
-
let n = Math.hypot(e[0], e[1], e[2], e[3]);
|
|
164
|
-
if (!(n > 1e-6)) throw new T(`Invalid ${t}: zero-norm quaternion`);
|
|
165
|
-
return [
|
|
166
|
-
e[0] / n,
|
|
167
|
-
e[1] / n,
|
|
168
|
-
e[2] / n,
|
|
169
|
-
e[3] / n
|
|
170
|
-
];
|
|
171
|
-
}
|
|
172
|
-
function F(e, t) {
|
|
173
|
-
let n = e.getWorldScale(new d.Vector3());
|
|
174
|
-
if (!Number.isFinite(n.x) || !Number.isFinite(n.y) || !Number.isFinite(n.z) || Math.abs(n.x - 1) > A || Math.abs(n.y - 1) > A || Math.abs(n.z - 1) > A) throw new T(`Non-identity world scale [${n.x.toFixed(4)}, ${n.y.toFixed(4)}, ${n.z.toFixed(4)}] on "${t}"; bake scale=[1,1,1]`);
|
|
175
|
-
let r = e.scale;
|
|
176
|
-
if (!Number.isFinite(r.x) || !Number.isFinite(r.y) || !Number.isFinite(r.z) || Math.abs(r.x - 1) > A || Math.abs(r.y - 1) > A || Math.abs(r.z - 1) > A) throw new T(`Non-identity local scale [${r.x.toFixed(4)}, ${r.y.toFixed(4)}, ${r.z.toFixed(4)}] on "${t}"; bake scale=[1,1,1]`);
|
|
177
|
-
}
|
|
178
|
-
function I(e) {
|
|
179
|
-
e.traverse((t) => {
|
|
180
|
-
F(t, t.name || (t === e ? "gltf.scene" : "unnamed_node"));
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
function L(e, t) {
|
|
184
|
-
let n = e.getWorldPosition(new d.Vector3()), r = e.getWorldQuaternion(new d.Quaternion()).invert(), i = t.getWorldPosition(new d.Vector3()).sub(n).applyQuaternion(r), a = r.multiply(t.getWorldQuaternion(new d.Quaternion()));
|
|
185
|
-
return {
|
|
186
|
-
localPosition: [
|
|
187
|
-
i.x,
|
|
188
|
-
i.y,
|
|
189
|
-
i.z
|
|
190
|
-
],
|
|
191
|
-
localQuaternion: [
|
|
192
|
-
a.x,
|
|
193
|
-
a.y,
|
|
194
|
-
a.z,
|
|
195
|
-
a.w
|
|
196
|
-
]
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
function ee(e, t, n) {
|
|
200
|
-
F(e, t);
|
|
201
|
-
let r = e.matrixWorld.clone().invert(), i = new d.Matrix4(), a = new d.Vector3(), o = [], s = [];
|
|
202
|
-
if (e.traverse((e) => {
|
|
203
|
-
let n = e;
|
|
204
|
-
if (!n.isMesh || !n.geometry) return;
|
|
205
|
-
F(n, n.name || t);
|
|
206
|
-
let c = n.geometry.getAttribute("position");
|
|
207
|
-
if (!c || c.count === 0) return;
|
|
208
|
-
i.multiplyMatrices(r, n.matrixWorld);
|
|
209
|
-
let l = o.length / 3;
|
|
210
|
-
for (let e = 0; e < c.count; e++) {
|
|
211
|
-
if (a.fromBufferAttribute(c, e).applyMatrix4(i), !Number.isFinite(a.x) || !Number.isFinite(a.y) || !Number.isFinite(a.z)) throw new T(`Non-finite vertex in collider mesh "${t}"`);
|
|
212
|
-
o.push(a.x, a.y, a.z);
|
|
213
|
-
}
|
|
214
|
-
let u = n.geometry.getIndex();
|
|
215
|
-
if (u) for (let e = 0; e < u.count; e++) s.push(l + u.getX(e));
|
|
216
|
-
else for (let e = 0; e < c.count; e++) s.push(l + e);
|
|
217
|
-
}), o.length < 9) throw new T(`Collider node "${t}" has fewer than 3 vertices`);
|
|
218
|
-
if (n) return {
|
|
219
|
-
type: "convexHull",
|
|
220
|
-
vertices: new Float32Array(o),
|
|
221
|
-
meshNodeName: t
|
|
222
|
-
};
|
|
223
|
-
if (s.length < 3) throw new T(`Trimesh node "${t}" has fewer than 3 indices`);
|
|
224
|
-
return {
|
|
225
|
-
type: "trimesh",
|
|
226
|
-
vertices: new Float32Array(o),
|
|
227
|
-
indices: new Uint32Array(s),
|
|
228
|
-
meshNodeName: t
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
function R(e) {
|
|
232
|
-
if (e.type === "box") {
|
|
233
|
-
let [t, n, r] = e.size;
|
|
234
|
-
return {
|
|
235
|
-
volume: t * n * r,
|
|
236
|
-
centroid: new d.Vector3(),
|
|
237
|
-
unitInertia: [
|
|
238
|
-
(n * n + r * r) / 12,
|
|
239
|
-
(t * t + r * r) / 12,
|
|
240
|
-
(t * t + n * n) / 12
|
|
241
|
-
]
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
if (e.type === "sphere") {
|
|
245
|
-
let t = e.radius, n = .4 * t * t;
|
|
246
|
-
return {
|
|
247
|
-
volume: 4 / 3 * Math.PI * t * t * t,
|
|
248
|
-
centroid: new d.Vector3(),
|
|
249
|
-
unitInertia: [
|
|
250
|
-
n,
|
|
251
|
-
n,
|
|
252
|
-
n
|
|
253
|
-
]
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
if (e.type === "convexHull" || e.type === "trimesh") {
|
|
257
|
-
let t = new d.Box3(), n = new d.Vector3(), r = e.vertices;
|
|
258
|
-
for (let e = 0; e < r.length; e += 3) t.expandByPoint(n.set(r[e], r[e + 1], r[e + 2]));
|
|
259
|
-
let i = t.getSize(new d.Vector3());
|
|
260
|
-
return {
|
|
261
|
-
volume: i.x * i.y * i.z,
|
|
262
|
-
centroid: t.getCenter(new d.Vector3()),
|
|
263
|
-
unitInertia: [
|
|
264
|
-
(i.y * i.y + i.z * i.z) / 12,
|
|
265
|
-
(i.x * i.x + i.z * i.z) / 12,
|
|
266
|
-
(i.x * i.x + i.y * i.y) / 12
|
|
267
|
-
]
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
let t = e.radiusTop, n = e.height;
|
|
271
|
-
if (e.type === "capsule") {
|
|
272
|
-
let e = Math.PI * t * t * n, r = e + 4 / 3 * Math.PI * t * t * t, i = e / r, a = 1 - i, o = .5 * i * t * t + .4 * a * t * t, s = i * (n * n / 12 + .25 * t * t) + a * (.4 * t * t + .25 * n * n + .375 * n * t);
|
|
273
|
-
return {
|
|
274
|
-
volume: r,
|
|
275
|
-
centroid: new d.Vector3(),
|
|
276
|
-
unitInertia: [
|
|
277
|
-
s,
|
|
278
|
-
o,
|
|
279
|
-
s
|
|
280
|
-
]
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
let r = (3 * t * t + n * n) / 12;
|
|
284
|
-
return {
|
|
285
|
-
volume: Math.PI * t * t * n,
|
|
286
|
-
centroid: new d.Vector3(),
|
|
287
|
-
unitInertia: [
|
|
288
|
-
r,
|
|
289
|
-
.5 * t * t,
|
|
290
|
-
r
|
|
291
|
-
]
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
function z(e, t, n, r, i) {
|
|
295
|
-
if (e.length === 0) throw new T(`Dynamic node "${i}" is missing motion.inertiaDiagonal and has no colliders`);
|
|
296
|
-
let a = e.map((e) => R(e.shape)), o = 0;
|
|
297
|
-
for (let e of a) o += e.volume;
|
|
298
|
-
let s = new d.Quaternion().fromArray(r).invert(), c = new d.Vector3().fromArray(n), l = new d.Quaternion(), u = new d.Quaternion(), f = new d.Vector3(), p = new d.Matrix4(), m = p.elements, h = 0, g = 0, _ = 0;
|
|
299
|
-
for (let n = 0; n < e.length; n++) {
|
|
300
|
-
let r = e[n], i = a[n], v = o > 0 ? t * (i.volume / o) : t / e.length;
|
|
301
|
-
l.fromArray(r.localQuaternion), f.copy(i.centroid).applyQuaternion(l).add(new d.Vector3().fromArray(r.localPosition)).sub(c).applyQuaternion(s), u.copy(s).multiply(l), p.makeRotationFromQuaternion(u);
|
|
302
|
-
let [y, b, x] = i.unitInertia, S = m[0] * m[0] * y + m[4] * m[4] * b + m[8] * m[8] * x, C = m[1] * m[1] * y + m[5] * m[5] * b + m[9] * m[9] * x, w = m[2] * m[2] * y + m[6] * m[6] * b + m[10] * m[10] * x;
|
|
303
|
-
h += v * (S + f.y * f.y + f.z * f.z), g += v * (C + f.x * f.x + f.z * f.z), _ += v * (w + f.x * f.x + f.y * f.y);
|
|
304
|
-
}
|
|
305
|
-
if (!Number.isFinite(h) || !Number.isFinite(g) || !Number.isFinite(_) || h <= 0 || g <= 0 || _ <= 0) throw new T(`Dynamic node "${i}" has degenerate collider geometry; cannot compute positive motion.inertiaDiagonal`);
|
|
306
|
-
return [
|
|
307
|
-
h,
|
|
308
|
-
g,
|
|
309
|
-
_
|
|
310
|
-
];
|
|
311
|
-
}
|
|
312
|
-
function B(e) {
|
|
313
|
-
let t = 0, n = 0, r = 0, i = 0, a = new d.Quaternion(), o = new d.Vector3();
|
|
314
|
-
for (let s of e) s.isKinematic || (t += s.mass, o.fromArray(s.centerOfMass).applyQuaternion(a.fromArray(s.localQuaternion)), n += (s.localPosition[0] + o.x) * s.mass, r += (s.localPosition[1] + o.y) * s.mass, i += (s.localPosition[2] + o.z) * s.mass);
|
|
315
|
-
return {
|
|
316
|
-
totalDynamicMass: t,
|
|
317
|
-
centerOfMass: t > 0 ? [
|
|
318
|
-
n / t,
|
|
319
|
-
r / t,
|
|
320
|
-
i / t
|
|
321
|
-
] : [
|
|
322
|
-
0,
|
|
323
|
-
0,
|
|
324
|
-
0
|
|
325
|
-
]
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
// src/khrClone.ts
|
|
329
|
-
var V = /* @__PURE__ */ new WeakSet(), H = /* @__PURE__ */ new WeakSet(), U = /* @__PURE__ */ new WeakSet();
|
|
330
|
-
function W(e, t) {
|
|
331
|
-
if (U.has(e.scene)) throw new T(`${t}: KhrAssetBundle "${e.scene.name || e.scene.uuid}" has already been disposed`);
|
|
332
|
-
if (V.has(e.scene)) throw new T(`${t}: KhrAssetBundle "${e.scene.name || e.scene.uuid}" is already mounted; call cloneKhrBundle(template) per concurrent instance`);
|
|
333
|
-
V.add(e.scene);
|
|
334
|
-
}
|
|
335
|
-
function G(e) {
|
|
336
|
-
V.delete(e.scene);
|
|
337
|
-
}
|
|
338
|
-
function K(e, t, n) {
|
|
339
|
-
if (t === e) return n;
|
|
340
|
-
let r = [], i = t;
|
|
341
|
-
for (; i && i !== e;) {
|
|
342
|
-
let e = i.parent;
|
|
343
|
-
if (!e) throw new T(`cloneKhrBundle: body node "${t.name}" is detached from bundle.scene`);
|
|
344
|
-
let n = e.children.indexOf(i);
|
|
345
|
-
if (n < 0) throw new T(`cloneKhrBundle: child index missing for "${t.name}"`);
|
|
346
|
-
r.push(n), i = e;
|
|
347
|
-
}
|
|
348
|
-
let a = n;
|
|
349
|
-
for (let e = r.length - 1; e >= 0; e--) a = a.children[r[e]];
|
|
350
|
-
return a;
|
|
351
|
-
}
|
|
352
|
-
function q(e) {
|
|
353
|
-
if (e) return {
|
|
354
|
-
...e,
|
|
355
|
-
points: e.points.map((e) => ({ ...e }))
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
function J(e) {
|
|
359
|
-
if (e) return {
|
|
360
|
-
...e,
|
|
361
|
-
...e.gearRatios ? { gearRatios: [...e.gearRatios] } : {},
|
|
362
|
-
...e.engineTorqueCurveData ? { engineTorqueCurveData: q(e.engineTorqueCurveData) } : {},
|
|
363
|
-
...e.steerAngleCurveData ? { steerAngleCurveData: q(e.steerAngleCurveData) } : {}
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
function Y(e) {
|
|
367
|
-
if (U.has(e.scene)) throw new T(`cloneKhrBundle: cannot clone disposed KhrAssetBundle "${e.scene.name || e.scene.uuid}"`);
|
|
368
|
-
let t = e.scene.clone(!0);
|
|
369
|
-
return H.add(t), {
|
|
370
|
-
scene: t,
|
|
371
|
-
bodies: e.bodies.map((n) => {
|
|
372
|
-
let r = n.joint ? n.joint.drives.map((e) => ({ ...e })) : [];
|
|
373
|
-
return {
|
|
374
|
-
...n,
|
|
375
|
-
centerOfMass: [...n.centerOfMass],
|
|
376
|
-
inertiaDiagonal: [...n.inertiaDiagonal],
|
|
377
|
-
inertiaOrientation: [...n.inertiaOrientation],
|
|
378
|
-
...n.linearVelocity ? { linearVelocity: [...n.linearVelocity] } : {},
|
|
379
|
-
...n.angularVelocity ? { angularVelocity: [...n.angularVelocity] } : {},
|
|
380
|
-
localPosition: [...n.localPosition],
|
|
381
|
-
localQuaternion: [...n.localQuaternion],
|
|
382
|
-
colliders: n.colliders.map((e) => ({
|
|
383
|
-
...e,
|
|
384
|
-
shape: e.shape.type === "box" ? {
|
|
385
|
-
...e.shape,
|
|
386
|
-
size: [...e.shape.size]
|
|
387
|
-
} : { ...e.shape },
|
|
388
|
-
localPosition: [...e.localPosition],
|
|
389
|
-
localQuaternion: [...e.localQuaternion]
|
|
390
|
-
})),
|
|
391
|
-
joint: n.joint ? {
|
|
392
|
-
...n.joint,
|
|
393
|
-
axis: [...n.joint.axis],
|
|
394
|
-
limits: n.joint.limits ? [...n.joint.limits] : null,
|
|
395
|
-
drive: r[0] ?? (n.joint.drive ? { ...n.joint.drive } : null),
|
|
396
|
-
drives: r,
|
|
397
|
-
anchor1: [...n.joint.anchor1],
|
|
398
|
-
anchor2: [...n.joint.anchor2]
|
|
399
|
-
} : null,
|
|
400
|
-
object: K(e.scene, n.object, t)
|
|
401
|
-
};
|
|
402
|
-
}),
|
|
403
|
-
wheels: e.wheels.map((n) => ({
|
|
404
|
-
...n,
|
|
405
|
-
object: K(e.scene, n.object, t),
|
|
406
|
-
position: [...n.position],
|
|
407
|
-
...n.quaternion ? { quaternion: [...n.quaternion] } : {},
|
|
408
|
-
...n.lngSlipRatioCurveData ? { lngSlipRatioCurveData: q(n.lngSlipRatioCurveData) } : {},
|
|
409
|
-
...n.latSlipRatioCurveData ? { latSlipRatioCurveData: q(n.latSlipRatioCurveData) } : {}
|
|
410
|
-
})),
|
|
411
|
-
propellers: e.propellers.map((n) => ({
|
|
412
|
-
...n,
|
|
413
|
-
object: K(e.scene, n.object, t),
|
|
414
|
-
position: [...n.position],
|
|
415
|
-
...n.quaternion ? { quaternion: [...n.quaternion] } : {}
|
|
416
|
-
})),
|
|
417
|
-
sockets: Object.fromEntries(Object.entries(e.sockets).map(([e, t]) => [e, [...t]])),
|
|
418
|
-
totalDynamicMass: e.totalDynamicMass,
|
|
419
|
-
centerOfMass: [...e.centerOfMass],
|
|
420
|
-
...e.tune ? { tune: J(e.tune) } : {},
|
|
421
|
-
...e.droneTune ? { droneTune: { ...e.droneTune } } : {}
|
|
422
|
-
};
|
|
423
|
-
}
|
|
424
|
-
function X(e) {
|
|
425
|
-
if (V.delete(e.scene), H.has(e.scene) || U.has(e.scene)) {
|
|
426
|
-
U.add(e.scene);
|
|
427
|
-
return;
|
|
428
|
-
}
|
|
429
|
-
U.add(e.scene);
|
|
430
|
-
let t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), i = (e) => {
|
|
431
|
-
e.traverse((e) => {
|
|
432
|
-
let i = e;
|
|
433
|
-
i.geometry && !t.has(i.geometry) && (t.add(i.geometry), i.geometry.dispose());
|
|
434
|
-
let a = Array.isArray(i.material) ? i.material : i.material ? [i.material] : [];
|
|
435
|
-
for (let e of a) if (!n.has(e)) {
|
|
436
|
-
n.add(e);
|
|
437
|
-
for (let t of Object.values(e)) if (t && typeof t == "object" && "isTexture" in t && t.isTexture) {
|
|
438
|
-
let e = t;
|
|
439
|
-
r.has(e) || (r.add(e), e.dispose());
|
|
440
|
-
}
|
|
441
|
-
e.dispose();
|
|
442
|
-
}
|
|
443
|
-
});
|
|
444
|
-
};
|
|
445
|
-
i(e.scene);
|
|
446
|
-
for (let t of e.wheels) i(t.object);
|
|
447
|
-
for (let t of e.propellers) i(t.object);
|
|
448
|
-
}
|
|
449
|
-
// src/KhrCollider.tsx
|
|
450
|
-
function Z({ c: e, position: r, quaternion: d, massProperties: p, ref: m }) {
|
|
451
|
-
let h = i(null), g = t((e) => {
|
|
452
|
-
h.current = e, typeof m == "function" ? m(e) : m && (m.current = e);
|
|
453
|
-
}, [m]);
|
|
454
|
-
n(() => {
|
|
455
|
-
let e = h.current;
|
|
456
|
-
e && e.parent()?.recomputeMassPropertiesFromColliders();
|
|
457
|
-
}, [e, p]);
|
|
458
|
-
let _ = {
|
|
459
|
-
ref: g,
|
|
460
|
-
position: r ?? e.localPosition,
|
|
461
|
-
quaternion: d ?? e.localQuaternion,
|
|
462
|
-
...p ? { massProperties: p } : { density: 0 },
|
|
463
|
-
...e.friction === void 0 ? {} : { friction: e.friction },
|
|
464
|
-
...e.restitution === void 0 ? {} : { restitution: e.restitution },
|
|
465
|
-
...e.collisionGroups === void 0 ? {} : { collisionGroups: e.collisionGroups }
|
|
466
|
-
}, { shape: v } = e;
|
|
467
|
-
if (v.type === "box") {
|
|
468
|
-
let [e, t, n] = v.size;
|
|
469
|
-
return /* @__PURE__ */ f(c, {
|
|
470
|
-
args: [
|
|
471
|
-
e * .5,
|
|
472
|
-
t * .5,
|
|
473
|
-
n * .5
|
|
474
|
-
],
|
|
475
|
-
..._
|
|
476
|
-
});
|
|
477
|
-
}
|
|
478
|
-
return v.type === "sphere" ? /* @__PURE__ */ f(a, {
|
|
479
|
-
args: [v.radius],
|
|
480
|
-
..._
|
|
481
|
-
}) : v.type === "cylinder" ? /* @__PURE__ */ f(l, {
|
|
482
|
-
args: [v.height * .5, v.radiusTop],
|
|
483
|
-
..._
|
|
484
|
-
}) : v.type === "capsule" ? /* @__PURE__ */ f(o, {
|
|
485
|
-
args: [v.height * .5, v.radiusTop],
|
|
486
|
-
..._
|
|
487
|
-
}) : v.type === "convexHull" ? /* @__PURE__ */ f(s, {
|
|
488
|
-
args: [v.vertices],
|
|
489
|
-
..._
|
|
490
|
-
}) : /* @__PURE__ */ f(u, {
|
|
491
|
-
args: [v.vertices, v.indices],
|
|
492
|
-
..._
|
|
493
|
-
});
|
|
494
|
-
}
|
|
495
|
-
// src/BundleSceneHost.tsx
|
|
496
|
-
function Q(e) {
|
|
497
|
-
let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
|
|
498
|
-
for (let r of e) {
|
|
499
|
-
let e = r.parent, i = /* @__PURE__ */ new Map(), a = -1;
|
|
500
|
-
if (e) {
|
|
501
|
-
let n = t.get(e);
|
|
502
|
-
n || (n = /* @__PURE__ */ new Map(), e.children.forEach((e, t) => n.set(e, t)), t.set(e, n)), i = n, a = i.get(r) ?? e.children.indexOf(r);
|
|
503
|
-
}
|
|
504
|
-
n.set(r, {
|
|
505
|
-
origParent: e,
|
|
506
|
-
origIndex: a,
|
|
507
|
-
origOrder: i,
|
|
508
|
-
origPos: r.position.clone(),
|
|
509
|
-
origQuat: r.quaternion.clone(),
|
|
510
|
-
origScale: r.scale.clone()
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
return n;
|
|
514
|
-
}
|
|
515
|
-
function $(e, t) {
|
|
516
|
-
e.position.copy(t.origPos), e.quaternion.copy(t.origQuat), e.scale.copy(t.origScale);
|
|
517
|
-
let { origParent: n, origIndex: r, origOrder: i } = t;
|
|
518
|
-
if (n) {
|
|
519
|
-
n.add(e);
|
|
520
|
-
let t = n.children.indexOf(e);
|
|
521
|
-
t >= 0 && n.children.splice(t, 1);
|
|
522
|
-
let a = n.children.length;
|
|
523
|
-
if (i.size > 0) {
|
|
524
|
-
for (let e = 0; e < n.children.length; e++) if ((i.get(n.children[e]) ?? Infinity) > r) {
|
|
525
|
-
a = e;
|
|
526
|
-
break;
|
|
527
|
-
}
|
|
528
|
-
} else r >= 0 && (a = Math.min(r, n.children.length));
|
|
529
|
-
n.children.splice(a, 0, e);
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
function te({ bundle: e, owner: t }) {
|
|
533
|
-
let n = i(null);
|
|
534
|
-
return r(() => {
|
|
535
|
-
let r = n.current;
|
|
536
|
-
if (r) return W(e, t), r.add(e.scene), () => {
|
|
537
|
-
e.scene.parent === r && r.remove(e.scene), G(e);
|
|
538
|
-
};
|
|
539
|
-
}, [e, t]), /* @__PURE__ */ f("group", { ref: n });
|
|
540
|
-
}
|
|
541
|
-
function ne({ object: e, position: t, quaternion: n, origin: a }) {
|
|
542
|
-
let o = i(null);
|
|
543
|
-
return r(() => {
|
|
544
|
-
let t = o.current;
|
|
545
|
-
if (!t) return;
|
|
546
|
-
let n = a ?? Q([e]).get(e);
|
|
547
|
-
return n.origParent && n.origParent.remove(e), e.position.set(0, 0, 0), e.quaternion.set(0, 0, 0, 1), e.scale.set(1, 1, 1), t.add(e), () => {
|
|
548
|
-
e.parent === t && t.remove(e), $(e, n);
|
|
549
|
-
};
|
|
550
|
-
}, [e, a]), /* @__PURE__ */ f("group", {
|
|
551
|
-
ref: o,
|
|
552
|
-
position: t,
|
|
553
|
-
quaternion: n
|
|
554
|
-
});
|
|
555
|
-
}
|
|
556
|
-
export { T as C, k as S, w as T, N as _, Z as a, O as b, X as c, I as d, M as f, ee as g, L as h, $ as i, G as l, z as m, ne as n, W as o, B as p, Q as r, Y as s, te as t, F as u, P as v, x as w, D as x, E as y };
|