@khr3/core 0.2.6 → 0.2.8

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.
Files changed (44) hide show
  1. package/AGENTS.md +12 -0
  2. package/CLAUDE.md +8 -0
  3. package/README.md +171 -9
  4. package/dist/KhrAssembly.d.ts +1 -1
  5. package/dist/KhrCollider.d.ts +5 -1
  6. package/dist/curves-Cf8okB-M.js +542 -0
  7. package/dist/curves-Cf8okB-M.js.map +1 -0
  8. package/dist/curves.js +1 -542
  9. package/dist/index.d.ts +3 -2
  10. package/dist/index.js +4 -1544
  11. package/dist/index.js.map +1 -1
  12. package/dist/jointDynamics.d.ts +7 -0
  13. package/dist/khrClone.d.ts +3 -3
  14. package/dist/khrInertia-DgCUCDTx.js +247 -0
  15. package/dist/khrInertia-DgCUCDTx.js.map +1 -0
  16. package/dist/khrVehicleJointHelpers.d.ts +16 -0
  17. package/dist/khrVehicleJoints.d.ts +2 -1
  18. package/dist/khrVehicleSlots.d.ts +2 -2
  19. package/dist/{physicsEcs-dBq4psbC.js → physicsEcs-C00N5zCh.js} +27 -251
  20. package/dist/physicsEcs-C00N5zCh.js.map +1 -0
  21. package/dist/sand3d/sand3dAssemblyHelpers.d.ts +30 -0
  22. package/dist/sand3d/sand3dCavityOps.d.ts +15 -0
  23. package/dist/sand3d/sand3dCompiler.d.ts +121 -0
  24. package/dist/sand3d/sand3dEvaluator.d.ts +80 -0
  25. package/dist/sand3d/sand3dFramesAndEdits.d.ts +30 -0
  26. package/dist/sand3d/sand3dHullAndSweep.d.ts +27 -0
  27. package/dist/sand3d/sand3dParser.d.ts +6 -0
  28. package/dist/sand3d/sand3dPrimitives.d.ts +50 -0
  29. package/dist/sand3d/sand3dProfiles.d.ts +32 -0
  30. package/dist/sand3d/sand3dRecipes.d.ts +5 -0
  31. package/dist/sand3d/sand3dShellOp.d.ts +8 -0
  32. package/dist/sand3d/sand3dSolids.d.ts +32 -0
  33. package/dist/sand3d/sand3dTokenizer.d.ts +8 -0
  34. package/dist/sand3d/sand3dTypes.d.ts +157 -0
  35. package/dist/sand3d-DQ8-OMlo.js +5045 -0
  36. package/dist/sand3d-DQ8-OMlo.js.map +1 -0
  37. package/dist/sand3d.d.ts +23 -0
  38. package/dist/sand3d.js +1 -0
  39. package/dist/vehicle.js +97 -8
  40. package/dist/vehicle.js.map +1 -1
  41. package/docs/api-reference.md +333 -163
  42. package/package.json +10 -4
  43. package/dist/curves.js.map +0 -1
  44. package/dist/physicsEcs-dBq4psbC.js.map +0 -1
@@ -1,250 +1,8 @@
1
+ import { u as KhrValidationError } from "./khrInertia-DgCUCDTx.js";
1
2
  import { createContext, useCallback, useEffect, useLayoutEffect, useRef } from "react";
2
3
  import { BallCollider, CapsuleCollider, CoefficientCombineRule, ConvexHullCollider, CuboidCollider, CylinderCollider, TrimeshCollider } from "@react-three/rapier";
3
4
  import { jsx } from "react/jsx-runtime";
4
5
  import * as THREE from "three";
5
- // src/khrConfigTypes.ts
6
- var KhrValidationError = class extends Error {
7
- constructor(message) {
8
- super(message);
9
- this.name = "KhrValidationError";
10
- }
11
- };
12
- // src/khrInertia.ts
13
- var SCALE_EPS = 1e-4;
14
- function isUnitScalar(v) {
15
- return typeof v === "number" && Number.isFinite(v) && Math.abs(v - 1) <= 1e-9;
16
- }
17
- function assertUnitScale(scale, owner) {
18
- if (scale === void 0) return;
19
- let ok = false;
20
- if (typeof scale === "number") ok = isUnitScalar(scale);
21
- else if (Array.isArray(scale)) ok = scale.length === 3 && scale.every(isUnitScalar);
22
- else if (typeof scale === "object" && scale && "x" in scale && "y" in scale && "z" in scale) {
23
- const v = scale;
24
- ok = isUnitScalar(v.x) && isUnitScalar(v.y) && isUnitScalar(v.z);
25
- }
26
- if (!ok) throw new KhrValidationError(`${owner}: scale must be 1 (got ${typeof scale === "number" && !Number.isFinite(scale) ? String(scale) : JSON.stringify(scale)}); bake scale into the .glb at import`);
27
- }
28
- function readFiniteVec3(val, fieldLabel) {
29
- if (!Array.isArray(val) || val.length !== 3 || !val.every((n) => typeof n === "number" && Number.isFinite(n))) throw new KhrValidationError(`Invalid ${fieldLabel}: expected finite 3-tuple`);
30
- return [
31
- val[0],
32
- val[1],
33
- val[2]
34
- ];
35
- }
36
- function readUnitQuat(val, fieldLabel) {
37
- if (!Array.isArray(val) || val.length !== 4 || !val.every((n) => typeof n === "number" && Number.isFinite(n))) throw new KhrValidationError(`Invalid ${fieldLabel}: expected finite 4-tuple`);
38
- const norm = Math.hypot(val[0], val[1], val[2], val[3]);
39
- if (!(norm > 1e-6)) throw new KhrValidationError(`Invalid ${fieldLabel}: zero-norm quaternion`);
40
- return [
41
- val[0] / norm,
42
- val[1] / norm,
43
- val[2] / norm,
44
- val[3] / norm
45
- ];
46
- }
47
- function assertIdentityWorldScale(obj, nodeName) {
48
- const ws = obj.getWorldScale(new THREE.Vector3());
49
- if (!Number.isFinite(ws.x) || !Number.isFinite(ws.y) || !Number.isFinite(ws.z) || Math.abs(ws.x - 1) > SCALE_EPS || Math.abs(ws.y - 1) > SCALE_EPS || Math.abs(ws.z - 1) > SCALE_EPS) throw new KhrValidationError(`Non-identity world scale [${ws.x.toFixed(4)}, ${ws.y.toFixed(4)}, ${ws.z.toFixed(4)}] on "${nodeName}"; bake scale=[1,1,1]`);
50
- const ls = obj.scale;
51
- if (!Number.isFinite(ls.x) || !Number.isFinite(ls.y) || !Number.isFinite(ls.z) || Math.abs(ls.x - 1) > SCALE_EPS || Math.abs(ls.y - 1) > SCALE_EPS || Math.abs(ls.z - 1) > SCALE_EPS) throw new KhrValidationError(`Non-identity local scale [${ls.x.toFixed(4)}, ${ls.y.toFixed(4)}, ${ls.z.toFixed(4)}] on "${nodeName}"; bake scale=[1,1,1]`);
52
- }
53
- function assertSceneIdentityWorldScale(root) {
54
- root.traverse((child) => {
55
- assertIdentityWorldScale(child, child.name || (child === root ? "gltf.scene" : "unnamed_node"));
56
- });
57
- }
58
- function computeRelativePose(ownerObj, childObj) {
59
- const ownerPos = ownerObj.getWorldPosition(new THREE.Vector3());
60
- const ownerInvQuat = ownerObj.getWorldQuaternion(new THREE.Quaternion()).invert();
61
- const pos = childObj.getWorldPosition(new THREE.Vector3()).sub(ownerPos).applyQuaternion(ownerInvQuat);
62
- const quat = ownerInvQuat.multiply(childObj.getWorldQuaternion(new THREE.Quaternion()));
63
- return {
64
- localPosition: [
65
- pos.x,
66
- pos.y,
67
- pos.z
68
- ],
69
- localQuaternion: [
70
- quat.x,
71
- quat.y,
72
- quat.z,
73
- quat.w
74
- ]
75
- };
76
- }
77
- function extractMeshColliderShape(targetObj, meshNodeName, convexHull) {
78
- assertIdentityWorldScale(targetObj, meshNodeName);
79
- const invOwner = targetObj.matrixWorld.clone().invert();
80
- const rel = new THREE.Matrix4();
81
- const v = new THREE.Vector3();
82
- const verts = [];
83
- const indices = [];
84
- targetObj.traverse((child) => {
85
- const mesh = child;
86
- if (!mesh.isMesh || !mesh.geometry) return;
87
- assertIdentityWorldScale(mesh, mesh.name || meshNodeName);
88
- const posAttr = mesh.geometry.getAttribute("position");
89
- if (!posAttr || posAttr.count === 0) return;
90
- rel.multiplyMatrices(invOwner, mesh.matrixWorld);
91
- const base = verts.length / 3;
92
- for (let i = 0; i < posAttr.count; i++) {
93
- v.fromBufferAttribute(posAttr, i).applyMatrix4(rel);
94
- if (!Number.isFinite(v.x) || !Number.isFinite(v.y) || !Number.isFinite(v.z)) throw new KhrValidationError(`Non-finite vertex in collider mesh "${meshNodeName}"`);
95
- verts.push(v.x, v.y, v.z);
96
- }
97
- const idx = mesh.geometry.getIndex();
98
- if (idx) for (let i = 0; i < idx.count; i++) indices.push(base + idx.getX(i));
99
- else for (let i = 0; i < posAttr.count; i++) indices.push(base + i);
100
- });
101
- if (verts.length < 9) throw new KhrValidationError(`Collider node "${meshNodeName}" has fewer than 3 vertices`);
102
- if (convexHull) return {
103
- type: "convexHull",
104
- vertices: new Float32Array(verts),
105
- meshNodeName
106
- };
107
- if (indices.length < 3) throw new KhrValidationError(`Trimesh node "${meshNodeName}" has fewer than 3 indices`);
108
- return {
109
- type: "trimesh",
110
- vertices: new Float32Array(verts),
111
- indices: new Uint32Array(indices),
112
- meshNodeName
113
- };
114
- }
115
- function unitInertiaForShape(shape) {
116
- if (shape.type === "box") {
117
- const [x, y, z] = shape.size;
118
- return {
119
- volume: x * y * z,
120
- centroid: new THREE.Vector3(),
121
- unitInertia: [
122
- (y * y + z * z) / 12,
123
- (x * x + z * z) / 12,
124
- (x * x + y * y) / 12
125
- ]
126
- };
127
- }
128
- if (shape.type === "sphere") {
129
- const r = shape.radius;
130
- const i = .4 * r * r;
131
- return {
132
- volume: 4 / 3 * Math.PI * r * r * r,
133
- centroid: new THREE.Vector3(),
134
- unitInertia: [
135
- i,
136
- i,
137
- i
138
- ]
139
- };
140
- }
141
- if (shape.type === "convexHull" || shape.type === "trimesh") {
142
- const box = new THREE.Box3();
143
- const pt = new THREE.Vector3();
144
- const verts = shape.vertices;
145
- for (let i = 0; i < verts.length; i += 3) box.expandByPoint(pt.set(verts[i], verts[i + 1], verts[i + 2]));
146
- const s = box.getSize(new THREE.Vector3());
147
- return {
148
- volume: s.x * s.y * s.z,
149
- centroid: box.getCenter(new THREE.Vector3()),
150
- unitInertia: [
151
- (s.y * s.y + s.z * s.z) / 12,
152
- (s.x * s.x + s.z * s.z) / 12,
153
- (s.x * s.x + s.y * s.y) / 12
154
- ]
155
- };
156
- }
157
- const r = shape.radiusTop;
158
- const h = shape.height;
159
- if (shape.type === "capsule") {
160
- const cylVol = Math.PI * r * r * h;
161
- const totVol = cylVol + 4 / 3 * Math.PI * r * r * r;
162
- const fc = cylVol / totVol;
163
- const fh = 1 - fc;
164
- const iy = .5 * fc * r * r + .4 * fh * r * r;
165
- const ix = fc * (h * h / 12 + .25 * r * r) + fh * (.4 * r * r + .25 * h * h + .375 * h * r);
166
- return {
167
- volume: totVol,
168
- centroid: new THREE.Vector3(),
169
- unitInertia: [
170
- ix,
171
- iy,
172
- ix
173
- ]
174
- };
175
- }
176
- const ix = (3 * r * r + h * h) / 12;
177
- return {
178
- volume: Math.PI * r * r * h,
179
- centroid: new THREE.Vector3(),
180
- unitInertia: [
181
- ix,
182
- .5 * r * r,
183
- ix
184
- ]
185
- };
186
- }
187
- function computeBodyInertia(colliders, mass, centerOfMass, inertiaOrientation, nodeName) {
188
- if (colliders.length === 0) throw new KhrValidationError(`Dynamic node "${nodeName}" is missing motion.inertiaDiagonal and has no colliders`);
189
- const shapes = colliders.map((c) => unitInertiaForShape(c.shape));
190
- let totalVol = 0;
191
- for (const s of shapes) totalVol += s.volume;
192
- const invFrame = new THREE.Quaternion().fromArray(inertiaOrientation).invert();
193
- const com = new THREE.Vector3().fromArray(centerOfMass);
194
- const colQuat = new THREE.Quaternion();
195
- const relQuat = new THREE.Quaternion();
196
- const offset = new THREE.Vector3();
197
- const rotMat = new THREE.Matrix4();
198
- const m = rotMat.elements;
199
- let ix = 0, iy = 0, iz = 0;
200
- for (let i = 0; i < colliders.length; i++) {
201
- const col = colliders[i];
202
- const shp = shapes[i];
203
- const mShare = totalVol > 0 ? mass * (shp.volume / totalVol) : mass / colliders.length;
204
- colQuat.fromArray(col.localQuaternion);
205
- offset.copy(shp.centroid).applyQuaternion(colQuat).add(new THREE.Vector3().fromArray(col.localPosition)).sub(com).applyQuaternion(invFrame);
206
- relQuat.copy(invFrame).multiply(colQuat);
207
- rotMat.makeRotationFromQuaternion(relQuat);
208
- const [u0, u1, u2] = shp.unitInertia;
209
- const rx = m[0] * m[0] * u0 + m[4] * m[4] * u1 + m[8] * m[8] * u2;
210
- const ry = m[1] * m[1] * u0 + m[5] * m[5] * u1 + m[9] * m[9] * u2;
211
- const rz = m[2] * m[2] * u0 + m[6] * m[6] * u1 + m[10] * m[10] * u2;
212
- ix += mShare * (rx + offset.y * offset.y + offset.z * offset.z);
213
- iy += mShare * (ry + offset.x * offset.x + offset.z * offset.z);
214
- iz += mShare * (rz + offset.x * offset.x + offset.y * offset.y);
215
- }
216
- if (!Number.isFinite(ix) || !Number.isFinite(iy) || !Number.isFinite(iz) || ix <= 0 || iy <= 0 || iz <= 0) throw new KhrValidationError(`Dynamic node "${nodeName}" has degenerate collider geometry; cannot compute positive motion.inertiaDiagonal`);
217
- return [
218
- ix,
219
- iy,
220
- iz
221
- ];
222
- }
223
- function computeAssemblyMassAndCom(bodies) {
224
- let totalDynamicMass = 0, mx = 0, my = 0, mz = 0;
225
- const q = new THREE.Quaternion();
226
- const c = new THREE.Vector3();
227
- for (const b of bodies) {
228
- if (b.isKinematic) continue;
229
- totalDynamicMass += b.mass;
230
- c.fromArray(b.centerOfMass).applyQuaternion(q.fromArray(b.localQuaternion));
231
- mx += (b.localPosition[0] + c.x) * b.mass;
232
- my += (b.localPosition[1] + c.y) * b.mass;
233
- mz += (b.localPosition[2] + c.z) * b.mass;
234
- }
235
- return {
236
- totalDynamicMass,
237
- centerOfMass: totalDynamicMass > 0 ? [
238
- mx / totalDynamicMass,
239
- my / totalDynamicMass,
240
- mz / totalDynamicMass
241
- ] : [
242
- 0,
243
- 0,
244
- 0
245
- ]
246
- };
247
- }
248
6
  // src/khrClone.ts
249
7
  var mountedScenes = /* @__PURE__ */ new WeakSet();
250
8
  var clonedScenes = /* @__PURE__ */ new WeakSet();
@@ -298,8 +56,8 @@ function cloneCarTune(tune) {
298
56
  };
299
57
  }
300
58
  /**
301
- * Clones a parsed `KhrAssetBundle` in O(nodes) without re-parsing `.glb` bytes or duplicating
302
- * GPU `BufferGeometry` / `Material` buffers or Rapier `Float32Array` collider vertices.
59
+ * Clones a parsed `KhrAssetBundle` in O(nodes) while sharing parsed `.glb` buffers,
60
+ * GPU `BufferGeometry` / `Material` buffers, and Rapier `Float32Array` collider vertices.
303
61
  */
304
62
  function cloneKhrBundle(bundle) {
305
63
  if (disposedScenes.has(bundle.scene)) throw new KhrValidationError(`cloneKhrBundle: cannot clone disposed KhrAssetBundle "${bundle.scene.name || bundle.scene.uuid}"`);
@@ -368,7 +126,7 @@ function cloneKhrBundle(bundle) {
368
126
  }
369
127
  }
370
128
  /**
371
- * Releases mount ownership on clones without destroying shared template GPU resources.
129
+ * Releases clone mount ownership while keeping shared template GPU resources intact.
372
130
  * When called on a root template bundle, disposes unique GPU geometries, materials, and textures once.
373
131
  */
374
132
  function disposeKhrBundle(bundle) {
@@ -413,7 +171,7 @@ var COMBINE_RULES = {
413
171
  maximum: CoefficientCombineRule.Max,
414
172
  multiply: CoefficientCombineRule.Multiply
415
173
  };
416
- function KhrCollider({ c, position, quaternion, massProperties, ref }) {
174
+ function KhrCollider({ c, position, quaternion, massProperties, collisionGroups, solverGroups, ref }) {
417
175
  const innerRef = useRef(null);
418
176
  const setRef = useCallback((node) => {
419
177
  innerRef.current = node;
@@ -423,6 +181,8 @@ function KhrCollider({ c, position, quaternion, massProperties, ref }) {
423
181
  useEffect(() => {
424
182
  innerRef.current?.parent()?.recomputeMassPropertiesFromColliders();
425
183
  }, [c, massProperties]);
184
+ const effCollisionGroups = c.collisionGroups ?? collisionGroups;
185
+ const effSolverGroups = c.collisionGroups === void 0 ? solverGroups : void 0;
426
186
  const common = {
427
187
  ref: setRef,
428
188
  position: position ?? c.localPosition,
@@ -432,7 +192,8 @@ function KhrCollider({ c, position, quaternion, massProperties, ref }) {
432
192
  ...c.restitution === void 0 ? {} : { restitution: c.restitution },
433
193
  ...c.frictionCombine === void 0 ? {} : { frictionCombineRule: COMBINE_RULES[c.frictionCombine] },
434
194
  ...c.restitutionCombine === void 0 ? {} : { restitutionCombineRule: COMBINE_RULES[c.restitutionCombine] },
435
- ...c.collisionGroups === void 0 ? {} : { collisionGroups: c.collisionGroups }
195
+ ...effCollisionGroups === void 0 ? {} : { collisionGroups: effCollisionGroups },
196
+ ...effSolverGroups === void 0 ? {} : { solverGroups: effSolverGroups }
436
197
  };
437
198
  const { shape } = c;
438
199
  if (shape.type === "box") {
@@ -980,7 +741,6 @@ function MountSubtreeSlot({ object, position, quaternion, origin }) {
980
741
  quaternion
981
742
  });
982
743
  }
983
- // src/jointDynamics.ts
984
744
  var _q1 = new THREE.Quaternion();
985
745
  var _q2 = new THREE.Quaternion();
986
746
  var _qRel = new THREE.Quaternion();
@@ -1115,6 +875,22 @@ function buildJointRuntime(params) {
1115
875
  rt.detached = true;
1116
876
  rt.unlatched = true;
1117
877
  rt.positionTarget = null;
878
+ const ud = childBody.userData;
879
+ if (ud?.ecctrl) childBody.userData = {
880
+ ...ud,
881
+ ecctrl: {
882
+ ...ud.ecctrl,
883
+ excludeVehicleRay: false
884
+ }
885
+ };
886
+ for (let i = 0; i < childBody.numColliders(); i++) {
887
+ const col = childBody.collider(i);
888
+ const cg = col.collisionGroups();
889
+ if (cg === 196605 || cg === 1073790975) {
890
+ col.setCollisionGroups(4294967295);
891
+ col.setSolverGroups(4294967295);
892
+ }
893
+ }
1118
894
  if (childBody.isDynamic()) childBody.wakeUp();
1119
895
  return "detached";
1120
896
  }
@@ -1133,6 +909,6 @@ function buildJointRuntime(params) {
1133
909
  // src/physicsEcs.ts
1134
910
  /** Retained as an optional context export for compatibility; Rapier steps ImpulseJoints natively. */
1135
911
  var JointRegistryContext = createContext(null);
1136
- export { computeRelativePose as C, KhrValidationError as D, readUnitQuat as E, computeBodyInertia as S, readFiniteVec3 as T, releaseBundleMount as _, MountSubtreeSlot as a, assertUnitScale as b, planAssembly as c, computeLumpedMassProps as d, KhrCollider as f, registerMountedSubtree as g, disposeKhrBundle as h, BundleSceneHost as i, toColliderMass as l, cloneKhrBundle as m, buildJointRuntime as n, captureSubtreeOrigins as o, claimBundleMount as p, createRapierImpulseJoint as r, restoreSubtreeOrigin as s, JointRegistryContext as t, bodyPoseMatrix as u, assertIdentityWorldScale as v, extractMeshColliderShape as w, computeAssemblyMassAndCom as x, assertSceneIdentityWorldScale as y };
912
+ export { releaseBundleMount as _, MountSubtreeSlot as a, planAssembly as c, computeLumpedMassProps as d, KhrCollider as f, registerMountedSubtree as g, disposeKhrBundle as h, BundleSceneHost as i, toColliderMass as l, cloneKhrBundle as m, buildJointRuntime as n, captureSubtreeOrigins as o, claimBundleMount as p, createRapierImpulseJoint as r, restoreSubtreeOrigin as s, JointRegistryContext as t, bodyPoseMatrix as u };
1137
913
 
1138
- //# sourceMappingURL=physicsEcs-dBq4psbC.js.map
914
+ //# sourceMappingURL=physicsEcs-C00N5zCh.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"physicsEcs-C00N5zCh.js","names":[],"sources":["../src/khrClone.ts","../src/KhrCollider.tsx","../src/khrMassProps.ts","../src/assemblyPlan.ts","../src/BundleSceneHost.tsx","../src/jointDynamics.ts","../src/physicsEcs.ts"],"sourcesContent":["import * as THREE from \"three\";\nimport { type KhrAssetBundle, type KhrCarConfig, type KhrCurveData, KhrValidationError } from \"./khrTypes.js\";\n\nconst mountedScenes = new WeakSet<THREE.Object3D>();\nconst clonedScenes = new WeakSet<THREE.Object3D>();\nconst disposedScenes = new WeakSet<THREE.Object3D>();\nconst activeSubtreeRestorers: Array<() => () => void> = [];\n\nexport function registerMountedSubtree(restoreForClone: () => () => void): () => void {\n activeSubtreeRestorers.push(restoreForClone);\n return () => {\n const idx = activeSubtreeRestorers.indexOf(restoreForClone);\n if (idx >= 0)\n activeSubtreeRestorers.splice(idx, 1);\n };\n}\n\nexport function claimBundleMount(bundle: KhrAssetBundle, ownerComponent: string): void {\n if (disposedScenes.has(bundle.scene)) {\n throw new KhrValidationError(`${ownerComponent}: KhrAssetBundle \"${bundle.scene.name || bundle.scene.uuid}\" has already been disposed`);\n }\n if (mountedScenes.has(bundle.scene)) {\n throw new KhrValidationError(`${ownerComponent}: KhrAssetBundle \"${bundle.scene.name || bundle.scene.uuid}\" is already mounted; call cloneKhrBundle(template) per concurrent instance`);\n }\n mountedScenes.add(bundle.scene);\n}\n\nexport function releaseBundleMount(bundle: KhrAssetBundle): void {\n mountedScenes.delete(bundle.scene);\n}\n\nfunction remapNode(srcRoot: THREE.Object3D, node: THREE.Object3D, dstRoot: THREE.Object3D): THREE.Object3D {\n if (node === srcRoot)\n return dstRoot;\n const path: number[] = [];\n let cur: THREE.Object3D | null = node;\n while (cur && cur !== srcRoot) {\n const parent: THREE.Object3D | null = cur.parent;\n if (!parent)\n throw new KhrValidationError(`cloneKhrBundle: body node \"${node.name}\" is detached from bundle.scene`);\n const idx = parent.children.indexOf(cur);\n if (idx < 0)\n throw new KhrValidationError(`cloneKhrBundle: child index missing for \"${node.name}\"`);\n path.push(idx);\n cur = parent;\n }\n let out = dstRoot;\n for (let i = path.length - 1; i >= 0; i--)\n out = out.children[path[i]];\n return out;\n}\n\nfunction cloneCurve(curve?: KhrCurveData): KhrCurveData | undefined {\n if (!curve)\n return undefined;\n return {\n ...curve,\n points: curve.points.map((pt) => ({ ...pt })),\n };\n}\n\nfunction cloneCarTune(tune?: Partial<KhrCarConfig>): Partial<KhrCarConfig> | undefined {\n if (!tune)\n return undefined;\n return {\n ...tune,\n ...(tune.gearRatios ? { gearRatios: [...tune.gearRatios] } : {}),\n ...(tune.engineTorqueCurveData ? { engineTorqueCurveData: cloneCurve(tune.engineTorqueCurveData) } : {}),\n ...(tune.steerAngleCurveData ? { steerAngleCurveData: cloneCurve(tune.steerAngleCurveData) } : {}),\n };\n}\n\n/**\n * Clones a parsed `KhrAssetBundle` in O(nodes) while sharing parsed `.glb` buffers,\n * GPU `BufferGeometry` / `Material` buffers, and Rapier `Float32Array` collider vertices.\n */\nexport function cloneKhrBundle(bundle: KhrAssetBundle): KhrAssetBundle {\n if (disposedScenes.has(bundle.scene)) {\n throw new KhrValidationError(`cloneKhrBundle: cannot clone disposed KhrAssetBundle \"${bundle.scene.name || bundle.scene.uuid}\"`);\n }\n const reattach: Array<() => void> = [];\n for (let i = activeSubtreeRestorers.length - 1; i >= 0; i--) {\n reattach.push(activeSubtreeRestorers[i]());\n }\n try {\n const scene = bundle.scene.clone(true);\n clonedScenes.add(scene);\n return {\n scene,\n bodies: bundle.bodies.map((b) => {\n const drives = b.joint ? b.joint.drives.map((d) => ({ ...d })) : [];\n return {\n ...b,\n centerOfMass: [...b.centerOfMass],\n inertiaDiagonal: [...b.inertiaDiagonal],\n inertiaOrientation: [...b.inertiaOrientation],\n ...(b.linearVelocity ? { linearVelocity: [...b.linearVelocity] } : {}),\n ...(b.angularVelocity ? { angularVelocity: [...b.angularVelocity] } : {}),\n localPosition: [...b.localPosition],\n localQuaternion: [...b.localQuaternion],\n colliders: b.colliders.map((c) => ({\n ...c,\n shape: c.shape.type === \"box\" ? { ...c.shape, size: [...c.shape.size] } : { ...c.shape },\n localPosition: [...c.localPosition],\n localQuaternion: [...c.localQuaternion],\n })),\n joint: b.joint\n ? {\n ...b.joint,\n axis: [...b.joint.axis],\n limits: b.joint.limits ? [...b.joint.limits] : null,\n drive: drives[0] ?? (b.joint.drive ? { ...b.joint.drive } : null),\n drives,\n anchor1: [...b.joint.anchor1],\n anchor2: [...b.joint.anchor2],\n }\n : null,\n ...(b.breakaway ? { breakaway: { ...b.breakaway } } : {}),\n object: remapNode(bundle.scene, b.object, scene),\n };\n }),\n wheels: bundle.wheels.map((w) => ({\n ...w,\n object: remapNode(bundle.scene, w.object, scene),\n position: [...w.position],\n ...(w.quaternion ? { quaternion: [...w.quaternion] } : {}),\n ...(w.lngSlipRatioCurveData ? { lngSlipRatioCurveData: cloneCurve(w.lngSlipRatioCurveData) } : {}),\n ...(w.latSlipRatioCurveData ? { latSlipRatioCurveData: cloneCurve(w.latSlipRatioCurveData) } : {}),\n })),\n propellers: bundle.propellers.map((p) => ({\n ...p,\n object: remapNode(bundle.scene, p.object, scene),\n position: [...p.position],\n ...(p.quaternion ? { quaternion: [...p.quaternion] } : {}),\n })),\n sockets: Object.fromEntries(Object.entries(bundle.sockets).map(([k, v]) => [k, [...v]])),\n totalDynamicMass: bundle.totalDynamicMass,\n centerOfMass: [...bundle.centerOfMass],\n ...(bundle.tune ? { tune: cloneCarTune(bundle.tune) } : {}),\n ...(bundle.droneTune ? { droneTune: { ...bundle.droneTune } } : {}),\n };\n }\n finally {\n for (let i = reattach.length - 1; i >= 0; i--)\n reattach[i]();\n }\n}\n\n/**\n * Releases clone mount ownership while keeping shared template GPU resources intact.\n * When called on a root template bundle, disposes unique GPU geometries, materials, and textures once.\n */\nexport function disposeKhrBundle(bundle: KhrAssetBundle): void {\n mountedScenes.delete(bundle.scene);\n if (clonedScenes.has(bundle.scene) || disposedScenes.has(bundle.scene)) {\n disposedScenes.add(bundle.scene);\n return;\n }\n disposedScenes.add(bundle.scene);\n const geos = new Set<THREE.BufferGeometry>();\n const mats = new Set<THREE.Material>();\n const texs = new Set<THREE.Texture>();\n const disposeTree = (obj: THREE.Object3D): void => {\n obj.traverse((child) => {\n const mesh = child as THREE.Mesh;\n if (mesh.geometry && !geos.has(mesh.geometry)) {\n geos.add(mesh.geometry);\n mesh.geometry.dispose();\n }\n const matList = Array.isArray(mesh.material) ? mesh.material : mesh.material ? [mesh.material] : [];\n for (const mat of matList) {\n if (!mats.has(mat)) {\n mats.add(mat);\n for (const val of Object.values(mat)) {\n if (val && typeof val === \"object\" && \"isTexture\" in val && (val as THREE.Texture).isTexture) {\n const tex = val as THREE.Texture;\n if (!texs.has(tex)) {\n texs.add(tex);\n tex.dispose();\n }\n }\n }\n mat.dispose();\n }\n }\n });\n };\n disposeTree(bundle.scene);\n for (const w of bundle.wheels)\n disposeTree(w.object);\n for (const p of bundle.propellers)\n disposeTree(p.object);\n}\n","import React, { useCallback, useEffect, useRef } from \"react\";\nimport {\n BallCollider,\n CapsuleCollider,\n CoefficientCombineRule,\n ConvexHullCollider,\n CuboidCollider,\n CylinderCollider,\n TrimeshCollider,\n type RapierCollider,\n} from \"@react-three/rapier\";\nimport type { ColliderMass } from \"./assemblyPlan.js\";\nimport type { KhrColliderSpec, KhrCombineMode } from \"./khrTypes.js\";\n\nconst COMBINE_RULES: Record<KhrCombineMode, CoefficientCombineRule> = {\n average: CoefficientCombineRule.Average,\n minimum: CoefficientCombineRule.Min,\n maximum: CoefficientCombineRule.Max,\n multiply: CoefficientCombineRule.Multiply,\n};\n\nexport interface KhrColliderProps {\n c: KhrColliderSpec;\n /** Pose override in the parent RigidBody frame; defaults to the authored KHR collider offset. */\n position?: [number, number, number];\n quaternion?: [number, number, number, number];\n /** Authored body mass carried declaratively by this collider (`density: 0` when omitted). */\n massProperties?: ColliderMass;\n /** Fallback Rapier collision groups when `c.collisionGroups` is omitted. */\n collisionGroups?: number;\n /** Fallback Rapier solver groups when `c.collisionGroups` is omitted. */\n solverGroups?: number;\n ref?: React.Ref<RapierCollider>;\n}\n\nexport function KhrCollider({ c, position, quaternion, massProperties, collisionGroups, solverGroups, ref }: KhrColliderProps): React.JSX.Element {\n const innerRef = useRef<RapierCollider | null>(null);\n const setRef = useCallback((node: RapierCollider | null) => {\n innerRef.current = node;\n if (typeof ref === \"function\")\n ref(node);\n else if (ref)\n (ref as React.MutableRefObject<RapierCollider | null>).current = node;\n }, [ref]);\n // Rapier WASM only auto-flushes dirty collider mass flags inside world.step(); flush once after\n // @react-three/rapier's AnyCollider useEffect so body.mass() is already exact before step 0.\n useEffect(() => {\n innerRef.current?.parent()?.recomputeMassPropertiesFromColliders();\n }, [c, massProperties]);\n const effCollisionGroups = c.collisionGroups ?? collisionGroups;\n const effSolverGroups = c.collisionGroups === undefined ? solverGroups : undefined;\n const common = {\n ref: setRef,\n position: position ?? c.localPosition,\n quaternion: quaternion ?? c.localQuaternion,\n ...(massProperties ? { massProperties } : { density: 0 }),\n ...(c.friction === undefined ? {} : { friction: c.friction }),\n ...(c.restitution === undefined ? {} : { restitution: c.restitution }),\n ...(c.frictionCombine === undefined ? {} : { frictionCombineRule: COMBINE_RULES[c.frictionCombine] }),\n ...(c.restitutionCombine === undefined ? {} : { restitutionCombineRule: COMBINE_RULES[c.restitutionCombine] }),\n ...(effCollisionGroups === undefined ? {} : { collisionGroups: effCollisionGroups }),\n ...(effSolverGroups === undefined ? {} : { solverGroups: effSolverGroups }),\n };\n const { shape } = c;\n if (shape.type === \"box\") {\n const [sx, sy, sz] = shape.size;\n return <CuboidCollider args={[sx * 0.5, sy * 0.5, sz * 0.5]} {...common} />;\n }\n if (shape.type === \"sphere\")\n return <BallCollider args={[shape.radius]} {...common} />;\n if (shape.type === \"cylinder\")\n return <CylinderCollider args={[shape.height * 0.5, shape.radiusTop]} {...common} />;\n if (shape.type === \"capsule\")\n return <CapsuleCollider args={[shape.height * 0.5, shape.radiusTop]} {...common} />;\n if (shape.type === \"convexHull\")\n return <ConvexHullCollider args={[shape.vertices]} {...common} />;\n return <TrimeshCollider args={[shape.vertices, shape.indices]} {...common} />;\n}\n","import * as THREE from \"three\";\nimport type { KhrBodySpec } from \"./khrTypes.js\";\n\nexport type Vec3Tuple = [number, number, number];\nexport type QuatTuple = [number, number, number, number];\n\nexport interface LumpedMassProps {\n mass: number;\n com: Vec3Tuple;\n inertia: Vec3Tuple;\n inertiaFrame: QuatTuple;\n}\n\nconst _pos = new THREE.Vector3();\nconst _quat = new THREE.Quaternion();\nconst _qExtra = new THREE.Quaternion();\nconst _comVec = new THREE.Vector3();\nconst _one = new THREE.Vector3(1, 1, 1);\nconst _mat = new THREE.Matrix4();\nconst _tmpMat = new THREE.Matrix4();\nconst _rCom = new THREE.Vector3();\n\nexport function bodyPoseMatrix(body: KhrBodySpec, target = new THREE.Matrix4()): THREE.Matrix4 {\n _pos.fromArray(body.localPosition);\n _quat.fromArray(body.localQuaternion);\n return target.compose(_pos, _quat, _one);\n}\n\nexport function jacobiPrincipalInertia(\n ixx: number,\n iyy: number,\n izz: number,\n ixy: number,\n ixz: number,\n iyz: number,\n): { inertia: Vec3Tuple; inertiaFrame: QuatTuple } {\n const a: [Vec3Tuple, Vec3Tuple, Vec3Tuple] = [\n [ixx, ixy, ixz],\n [ixy, iyy, iyz],\n [ixz, iyz, izz],\n ];\n const v: [Vec3Tuple, Vec3Tuple, Vec3Tuple] = [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n ];\n for (let iter = 0; iter < 32; iter++) {\n const tr = Math.max(a[0][0] + a[1][1] + a[2][2], 0);\n let p = 0, q = 1, maxOff = Math.abs(a[0][1]);\n if (Math.abs(a[0][2]) > maxOff) {\n p = 0;\n q = 2;\n maxOff = Math.abs(a[0][2]);\n }\n if (Math.abs(a[1][2]) > maxOff) {\n p = 1;\n q = 2;\n maxOff = Math.abs(a[1][2]);\n }\n if (maxOff <= 1e-12 * tr)\n break;\n const apq = a[p][q], app = a[p][p], aqq = a[q][q];\n const tau = (aqq - app) / (2 * apq);\n const t = tau >= 0 ? 1 / (tau + Math.sqrt(1 + tau * tau)) : -1 / (-tau + Math.sqrt(1 + tau * tau));\n const c = 1 / Math.sqrt(1 + t * t), s = t * c;\n const r = 3 - p - q;\n a[p][p] = c * c * app - 2 * s * c * apq + s * s * aqq;\n a[q][q] = s * s * app + 2 * s * c * apq + c * c * aqq;\n a[p][q] = a[q][p] = 0;\n const arp = a[r][p], arq = a[r][q];\n a[r][p] = a[p][r] = c * arp - s * arq;\n a[r][q] = a[q][r] = s * arp + c * arq;\n for (let i = 0; i < 3; i++) {\n const vip = v[i][p], viq = v[i][q];\n v[i][p] = c * vip - s * viq;\n v[i][q] = s * vip + c * viq;\n }\n }\n const det = v[0][0] * (v[1][1] * v[2][2] - v[1][2] * v[2][1])\n - v[0][1] * (v[1][0] * v[2][2] - v[1][2] * v[2][0])\n + v[0][2] * (v[1][0] * v[2][1] - v[1][1] * v[2][0]);\n if (det < 0) {\n v[0][2] = -v[0][2];\n v[1][2] = -v[1][2];\n v[2][2] = -v[2][2];\n }\n _mat.set(\n v[0][0], v[0][1], v[0][2], 0,\n v[1][0], v[1][1], v[1][2], 0,\n v[2][0], v[2][1], v[2][2], 0,\n 0, 0, 0, 1,\n );\n _quat.setFromRotationMatrix(_mat).normalize();\n return {\n inertia: [a[0][0], a[1][1], a[2][2]],\n inertiaFrame: [_quat.x, _quat.y, _quat.z, _quat.w],\n };\n}\n\nfunction resolvePose(body: KhrBodySpec, invFrame?: THREE.Matrix4): void {\n if (invFrame) {\n _mat.multiplyMatrices(invFrame, bodyPoseMatrix(body, _tmpMat)).decompose(_pos, _quat, _comVec);\n _quat.normalize();\n }\n else {\n _pos.fromArray(body.localPosition);\n _quat.fromArray(body.localQuaternion).normalize();\n }\n}\n\nexport function computeLumpedMassProps(bodies: readonly KhrBodySpec[], invFrame?: THREE.Matrix4): LumpedMassProps | null {\n const dyn = bodies.filter((b) => !b.isKinematic && b.mass > 0);\n if (dyn.length === 0)\n return null;\n let totalMass = 0, mx = 0, my = 0, mz = 0;\n for (const b of dyn) {\n resolvePose(b, invFrame);\n _rCom.fromArray(b.centerOfMass).applyQuaternion(_quat);\n totalMass += b.mass;\n mx += (_pos.x + _rCom.x) * b.mass;\n my += (_pos.y + _rCom.y) * b.mass;\n mz += (_pos.z + _rCom.z) * b.mass;\n }\n if (!(totalMass > 0))\n return null;\n const com: Vec3Tuple = [mx / totalMass, my / totalMass, mz / totalMass];\n let ixx = 0, iyy = 0, izz = 0, ixy = 0, ixz = 0, iyz = 0;\n const m = _mat.elements;\n for (const b of dyn) {\n resolvePose(b, invFrame);\n _rCom.fromArray(b.centerOfMass).applyQuaternion(_quat);\n const dx = _pos.x + _rCom.x - com[0];\n const dy = _pos.y + _rCom.y - com[1];\n const dz = _pos.z + _rCom.z - com[2];\n _mat.makeRotationFromQuaternion(_quat.multiply(_qExtra.fromArray(b.inertiaOrientation)));\n const [d0, d1, d2] = b.inertiaDiagonal;\n ixx += m[0] * m[0] * d0 + m[4] * m[4] * d1 + m[8] * m[8] * d2 + b.mass * (dy * dy + dz * dz);\n iyy += m[1] * m[1] * d0 + m[5] * m[5] * d1 + m[9] * m[9] * d2 + b.mass * (dx * dx + dz * dz);\n izz += m[2] * m[2] * d0 + m[6] * m[6] * d1 + m[10] * m[10] * d2 + b.mass * (dx * dx + dy * dy);\n ixy += m[0] * m[1] * d0 + m[4] * m[5] * d1 + m[8] * m[9] * d2 - b.mass * dx * dy;\n ixz += m[0] * m[2] * d0 + m[4] * m[6] * d1 + m[8] * m[10] * d2 - b.mass * dx * dz;\n iyz += m[1] * m[2] * d0 + m[5] * m[6] * d1 + m[9] * m[10] * d2 - b.mass * dy * dz;\n }\n if (dyn.length === 1) {\n const b = dyn[0];\n resolvePose(b, invFrame);\n _quat.multiply(_qExtra.fromArray(b.inertiaOrientation)).normalize();\n return {\n mass: totalMass,\n com,\n inertia: [b.inertiaDiagonal[0], b.inertiaDiagonal[1], b.inertiaDiagonal[2]],\n inertiaFrame: [_quat.x, _quat.y, _quat.z, _quat.w],\n };\n }\n const diagSum = Math.max(ixx + iyy + izz, 0);\n if (Math.max(Math.abs(ixy), Math.abs(ixz), Math.abs(iyz)) <= 1e-12 * diagSum) {\n return {\n mass: totalMass,\n com,\n inertia: [ixx, iyy, izz],\n inertiaFrame: [0, 0, 0, 1],\n };\n }\n const { inertia, inertiaFrame } = jacobiPrincipalInertia(ixx, iyy, izz, ixy, ixz, iyz);\n return { mass: totalMass, com, inertia, inertiaFrame };\n}\n","import * as THREE from \"three\";\nimport { bodyPoseMatrix, computeLumpedMassProps, type LumpedMassProps } from \"./khrMassProps.js\";\nimport { type KhrAssetBundle, type KhrBodySpec, type KhrColliderSpec, type KhrJointSpec, KhrValidationError } from \"./khrTypes.js\";\n\ntype Vec3 = [number, number, number];\ntype Quat = [number, number, number, number];\n\nexport interface ColliderMass {\n mass: number;\n centerOfMass: { x: number; y: number; z: number };\n principalAngularInertia: { x: number; y: number; z: number };\n angularInertiaLocalFrame: { x: number; y: number; z: number; w: number };\n}\n\nexport interface PlannedCollider {\n spec: KhrColliderSpec;\n local: THREE.Matrix4;\n position: Vec3;\n quaternion: Quat;\n massProperties?: ColliderMass;\n}\n\nexport interface PartPlan {\n spec: KhrBodySpec;\n joint: KhrJointSpec;\n parent: PartPlan | null;\n restRelParentPos: Vec3;\n restRelParentQuat: Quat;\n restRelRootPos: Vec3;\n restRelRootQuat: Quat;\n axisParent: Vec3;\n axisChild: Vec3;\n inertia: number;\n partMass?: ColliderMass;\n colliders: PlannedCollider[];\n}\n\nexport interface RootPlan {\n spec: KhrBodySpec;\n sceneInRootPos: Vec3;\n sceneInRootQuat: Quat;\n mountNode: THREE.Object3D;\n mountInRoot: THREE.Matrix4;\n mountPosition: Vec3;\n mountQuaternion: Quat;\n rootMass?: ColliderMass;\n colliders: PlannedCollider[];\n parts: PartPlan[];\n}\n\nfunction matrixToRoot(node: THREE.Object3D, sceneRoot: THREE.Object3D): THREE.Matrix4 {\n const out = new THREE.Matrix4();\n for (let cur: THREE.Object3D | null = node; cur && cur !== sceneRoot; cur = cur.parent) {\n if (!cur.parent)\n throw new KhrValidationError(`Node \"${node.name}\" is detached from bundle.scene`);\n cur.updateMatrix();\n out.premultiply(cur.matrix);\n }\n return out;\n}\n\nfunction lowestCommonAncestor(nodes: readonly THREE.Object3D[], sceneRoot: THREE.Object3D): THREE.Object3D {\n const chain = (n: THREE.Object3D): THREE.Object3D[] => {\n const list: THREE.Object3D[] = [];\n for (let cur: THREE.Object3D | null = n; cur; cur = cur.parent) {\n list.push(cur);\n if (cur === sceneRoot) break;\n }\n return list;\n };\n let shared = new Set(chain(nodes[0]));\n for (let i = 1; i < nodes.length; i++) {\n const setI = new Set(chain(nodes[i]));\n shared = new Set([...shared].filter((x) => setI.has(x)));\n }\n return chain(nodes[0]).find((c) => shared.has(c)) ?? sceneRoot;\n}\n\nexport function toColliderMass(lumped: LumpedMassProps, colMat?: THREE.Matrix4, colQuat?: THREE.Quaternion): ColliderMass {\n const com = new THREE.Vector3().fromArray(lumped.com);\n const frame = new THREE.Quaternion().fromArray(lumped.inertiaFrame);\n if (colMat && colQuat) {\n com.applyMatrix4(colMat.clone().invert());\n frame.premultiply(colQuat.clone().invert()).normalize();\n }\n return {\n mass: lumped.mass,\n centerOfMass: { x: com.x, y: com.y, z: com.z },\n principalAngularInertia: { x: lumped.inertia[0], y: lumped.inertia[1], z: lumped.inertia[2] },\n angularInertiaLocalFrame: { x: frame.x, y: frame.y, z: frame.z, w: frame.w },\n };\n}\n\nfunction planOwnColliders(body: KhrBodySpec, lumped: LumpedMassProps | null, frameQuat?: THREE.Quaternion): PlannedCollider[] {\n const one = new THREE.Vector3(1, 1, 1);\n const frameMat = frameQuat ? new THREE.Matrix4().makeRotationFromQuaternion(frameQuat) : null;\n const pos = new THREE.Vector3(), quat = new THREE.Quaternion(), scl = new THREE.Vector3();\n return body.colliders.map((spec, idx) => {\n const colQuat = new THREE.Quaternion().fromArray(spec.localQuaternion);\n const local = new THREE.Matrix4().compose(new THREE.Vector3().fromArray(spec.localPosition), colQuat, one);\n if (frameMat)\n local.premultiply(frameMat);\n local.decompose(pos, quat, scl);\n quat.normalize();\n const planned: PlannedCollider = {\n spec,\n local,\n position: [pos.x, pos.y, pos.z],\n quaternion: [quat.x, quat.y, quat.z, quat.w],\n };\n if (idx === 0 && lumped)\n planned.massProperties = toColliderMass(lumped, local, quat);\n return planned;\n });\n}\n\nfunction isSceneDescendant(node: THREE.Object3D, ancestor: THREE.Object3D): boolean {\n for (let cur: THREE.Object3D | null = node; cur; cur = cur.parent) {\n if (cur === ancestor)\n return true;\n }\n return false;\n}\n\nfunction approxPartInertia(b: KhrBodySpec, axisChild: Vec3): number {\n if (b.joint?.kind === \"fixed\")\n return 0;\n if (b.joint?.kind === \"prismatic\")\n return b.mass;\n const ax = new THREE.Vector3().fromArray(axisChild).normalize();\n const qInv = new THREE.Quaternion().fromArray(b.inertiaOrientation).invert();\n const axLocal = ax.clone().applyQuaternion(qInv);\n const [d0, d1, d2] = b.inertiaDiagonal;\n const com = new THREE.Vector3().fromArray(b.centerOfMass);\n const along = com.dot(ax);\n return d0 * axLocal.x * axLocal.x + d1 * axLocal.y * axLocal.y + d2 * axLocal.z * axLocal.z + b.mass * (com.lengthSq() - along * along);\n}\n\n/** Plans independent Rapier bodies for roots and jointed dynamic children connected by Rapier ImpulseJoints. */\nexport function planAssembly(bundle: KhrAssetBundle): RootPlan[] {\n const byName = new Map(bundle.bodies.map((b) => [b.nodeName, b]));\n const findRoot = (b: KhrBodySpec, seen = new Set<string>()): KhrBodySpec => {\n if (!b.joint)\n return b;\n if (seen.has(b.nodeName))\n throw new KhrValidationError(`Joint cycle through \"${b.nodeName}\"`);\n seen.add(b.nodeName);\n const parent = byName.get(b.joint.connectedNodeName);\n if (!parent) {\n throw new KhrValidationError(`Joint on \"${b.nodeName}\" targets \"${b.joint.connectedNodeName}\", which is not a KHR body`);\n }\n return findRoot(parent, seen);\n };\n\n const plans = bundle.bodies\n .filter((b) => !b.joint)\n .map((root): RootPlan => {\n const rootMat = bodyPoseMatrix(root);\n const invRoot = rootMat.clone().invert();\n const descendants = bundle.bodies.filter((b) => b.joint && findRoot(b) === root);\n const depthOf = (b: KhrBodySpec): number => b.joint ? 1 + depthOf(byName.get(b.joint.connectedNodeName)!) : 0;\n descendants.sort((a, b) => depthOf(a) - depthOf(b));\n\n const partByName = new Map<string, PartPlan>();\n const parts: PartPlan[] = descendants.map((b) => {\n const joint = b.joint!;\n const parent = partByName.get(joint.connectedNodeName) ?? null;\n if (parent && !isSceneDescendant(b.object, parent.spec.object)) {\n throw new KhrValidationError(`Jointed node \"${b.nodeName}\" must be a scene-graph descendant of its jointed parent \"${joint.connectedNodeName}\"`);\n }\n const parentSpec = parent ? parent.spec : root;\n const relParentMat = bodyPoseMatrix(parentSpec).clone().invert().multiply(bodyPoseMatrix(b));\n const relRootMat = invRoot.clone().multiply(bodyPoseMatrix(b));\n const rpPos = new THREE.Vector3(), rpQuat = new THREE.Quaternion(), rpScl = new THREE.Vector3();\n relParentMat.decompose(rpPos, rpQuat, rpScl);\n rpQuat.normalize();\n const rrPos = new THREE.Vector3(), rrQuat = new THREE.Quaternion();\n relRootMat.decompose(rrPos, rrQuat, rpScl);\n rrQuat.normalize();\n\n const axChildVec = new THREE.Vector3().fromArray(joint.axis).normalize();\n const axParentVec = axChildVec.clone().applyQuaternion(rrQuat).normalize();\n const axisChild: Vec3 = [axChildVec.x, axChildVec.y, axChildVec.z];\n const axisParent: Vec3 = [axParentVec.x, axParentVec.y, axParentVec.z];\n const anchorParent: Vec3 = parent\n ? [rrPos.x - parent.restRelRootPos[0], rrPos.y - parent.restRelRootPos[1], rrPos.z - parent.restRelRootPos[2]]\n : [rpPos.x, rpPos.y, rpPos.z];\n\n const bodyAlignInv = new THREE.Matrix4().compose(new THREE.Vector3().fromArray(b.localPosition), new THREE.Quaternion().fromArray(root.localQuaternion), new THREE.Vector3(1, 1, 1)).invert();\n const ownLumped = b.isKinematic ? null : computeLumpedMassProps([b], bodyAlignInv);\n const colliders = planOwnColliders(b, ownLumped, rrQuat);\n const partMass = ownLumped && colliders.length === 0 ? toColliderMass(ownLumped) : undefined;\n\n const plan: PartPlan = {\n spec: b,\n joint,\n parent,\n restRelParentPos: anchorParent,\n restRelParentQuat: [rrQuat.x, rrQuat.y, rrQuat.z, rrQuat.w],\n restRelRootPos: [rrPos.x, rrPos.y, rrPos.z],\n restRelRootQuat: [rrQuat.x, rrQuat.y, rrQuat.z, rrQuat.w],\n axisParent,\n axisChild,\n inertia: approxPartInertia(b, axisChild),\n ...(partMass ? { partMass } : {}),\n colliders,\n };\n partByName.set(b.nodeName, plan);\n return plan;\n });\n\n const rootLumped = root.isKinematic ? null : computeLumpedMassProps([root], invRoot);\n const colliders = planOwnColliders(root, rootLumped);\n const rootMass = rootLumped && colliders.length === 0 ? toColliderMass(rootLumped) : undefined;\n const mountNode = lowestCommonAncestor([root.object, ...descendants.map((d) => d.object)], bundle.scene);\n const mountInRoot = invRoot.clone().multiply(matrixToRoot(mountNode, bundle.scene));\n\n const scenePos = new THREE.Vector3(), sceneQuat = new THREE.Quaternion(), sceneScl = new THREE.Vector3();\n invRoot.decompose(scenePos, sceneQuat, sceneScl);\n sceneQuat.normalize();\n const mountPos = new THREE.Vector3(), mountQuat = new THREE.Quaternion();\n mountInRoot.decompose(mountPos, mountQuat, sceneScl);\n mountQuat.normalize();\n\n return {\n spec: root,\n sceneInRootPos: [scenePos.x, scenePos.y, scenePos.z],\n sceneInRootQuat: [sceneQuat.x, sceneQuat.y, sceneQuat.z, sceneQuat.w],\n mountNode,\n mountInRoot,\n mountPosition: [mountPos.x, mountPos.y, mountPos.z],\n mountQuaternion: [mountQuat.x, mountQuat.y, mountQuat.z, mountQuat.w],\n ...(rootMass ? { rootMass } : {}),\n colliders,\n parts,\n };\n });\n\n for (const a of plans) {\n for (const b of plans) {\n if (a !== b && isSceneDescendant(b.mountNode, a.mountNode)) {\n throw new KhrValidationError(`Root bodies \"${a.spec.nodeName}\" and \"${b.spec.nodeName}\" share scene subtree \"${a.mountNode.name}\"; split them into separate glTF branches`);\n }\n }\n }\n return plans;\n}\n","import React, { useLayoutEffect, useRef } from \"react\";\nimport * as THREE from \"three\";\nimport { claimBundleMount, registerMountedSubtree, releaseBundleMount } from \"./khrClone.js\";\nimport type { KhrAssetBundle } from \"./khrTypes.js\";\n\nexport interface SubtreeOrigin {\n origParent: THREE.Object3D | null;\n origIndex: number;\n origOrder: Map<THREE.Object3D, number>;\n origPos: THREE.Vector3;\n origQuat: THREE.Quaternion;\n origScale: THREE.Vector3;\n}\n\nexport function captureSubtreeOrigins(objects: readonly THREE.Object3D[]): Map<THREE.Object3D, SubtreeOrigin> {\n const parentOrders = new Map<THREE.Object3D, Map<THREE.Object3D, number>>();\n const origins = new Map<THREE.Object3D, SubtreeOrigin>();\n for (const obj of objects) {\n const origParent = obj.parent;\n let origOrder = new Map<THREE.Object3D, number>();\n let origIndex = -1;\n if (origParent) {\n let order = parentOrders.get(origParent);\n if (!order) {\n order = new Map<THREE.Object3D, number>();\n origParent.children.forEach((child, idx) => order!.set(child, idx));\n parentOrders.set(origParent, order);\n }\n origOrder = order;\n origIndex = order.get(obj) ?? origParent.children.indexOf(obj);\n }\n origins.set(obj, {\n origParent,\n origIndex,\n origOrder,\n origPos: obj.position.clone(),\n origQuat: obj.quaternion.clone(),\n origScale: obj.scale.clone(),\n });\n }\n return origins;\n}\n\nexport function restoreSubtreeOrigin(object: THREE.Object3D, snap: SubtreeOrigin): void {\n object.position.copy(snap.origPos);\n object.quaternion.copy(snap.origQuat);\n object.scale.copy(snap.origScale);\n const { origParent, origIndex, origOrder } = snap;\n if (origParent) {\n origParent.add(object);\n const curIdx = origParent.children.indexOf(object);\n if (curIdx >= 0)\n origParent.children.splice(curIdx, 1);\n let insertAt = origParent.children.length;\n if (origOrder.size > 0) {\n for (let i = 0; i < origParent.children.length; i++) {\n if ((origOrder.get(origParent.children[i]) ?? Infinity) > origIndex) {\n insertAt = i;\n break;\n }\n }\n }\n else if (origIndex >= 0) {\n insertAt = Math.min(origIndex, origParent.children.length);\n }\n origParent.children.splice(insertAt, 0, object);\n }\n}\n\nexport function BundleSceneHost({ bundle, owner }: { bundle: KhrAssetBundle; owner: string }): React.JSX.Element {\n const hostRef = useRef<THREE.Group | null>(null);\n useLayoutEffect(() => {\n const host = hostRef.current;\n if (!host)\n return;\n claimBundleMount(bundle, owner);\n host.add(bundle.scene);\n return () => {\n if (bundle.scene.parent === host)\n host.remove(bundle.scene);\n releaseBundleMount(bundle);\n };\n }, [bundle, owner]);\n return <group ref={hostRef} />;\n}\n\nexport function MountSubtreeSlot({\n object,\n position,\n quaternion,\n origin,\n}: {\n object: THREE.Object3D;\n position: [number, number, number];\n quaternion: [number, number, number, number];\n origin?: SubtreeOrigin;\n}): React.JSX.Element {\n const slotRef = useRef<THREE.Group | null>(null);\n useLayoutEffect(() => {\n const slot = slotRef.current;\n if (!slot)\n return;\n const snap = origin ?? captureSubtreeOrigins([object]).get(object)!;\n if (snap.origParent)\n snap.origParent.remove(object);\n object.position.set(0, 0, 0);\n object.quaternion.set(0, 0, 0, 1);\n object.scale.set(1, 1, 1);\n slot.add(object);\n const untrack = registerMountedSubtree(() => {\n const p = object.position.clone(), q = object.quaternion.clone(), s = object.scale.clone();\n if (object.parent === slot)\n slot.remove(object);\n restoreSubtreeOrigin(object, snap);\n return () => {\n if (snap.origParent)\n snap.origParent.remove(object);\n object.position.copy(p);\n object.quaternion.copy(q);\n object.scale.copy(s);\n slot.add(object);\n };\n });\n return () => {\n untrack();\n if (object.parent === slot)\n slot.remove(object);\n restoreSubtreeOrigin(object, snap);\n };\n }, [object, origin]);\n return <group ref={slotRef} position={position} quaternion={quaternion} />;\n}\n","import * as THREE from \"three\";\nimport type RAPIER from \"@dimforge/rapier3d-compat\";\nimport { type KhrBreakawaySpec, type KhrJointDriveSpec, type KhrJointSpec, KhrValidationError } from \"./khrTypes.js\";\nimport type { JointRuntime } from \"./physicsEcs.js\";\n\n/**\n * Rapier interaction group bitmask for attached vehicle articulated panels:\n * member of group 14 (`0x4000`), collides with all groups except 14 (`0xbfff`),\n * preventing adjacent hinged panels (e.g. `door_fl` <-> `door_rl` / `hood`) from\n * fighting across joints while colliding normally with world geometry and projectiles.\n */\nexport const VEHICLE_PANEL_INTERACTION_GROUPS = 0x0002fffd;\n\nconst _q1 = new THREE.Quaternion();\nconst _q2 = new THREE.Quaternion();\nconst _qRel = new THREE.Quaternion();\nconst _restInv = new THREE.Quaternion();\nconst _deltaPos = new THREE.Vector3();\nconst _axWorld = new THREE.Vector3();\n\nexport function createRapierImpulseJoint(\n rapier: typeof RAPIER,\n world: RAPIER.World,\n parentBody: RAPIER.RigidBody,\n childBody: RAPIER.RigidBody,\n joint: KhrJointSpec,\n anchorParent: readonly [number, number, number],\n anchorChild: readonly [number, number, number],\n axisParent: readonly [number, number, number],\n axisChild: readonly [number, number, number],\n restFrameRelQuat: readonly [number, number, number, number],\n): RAPIER.ImpulseJoint {\n const a1 = { x: anchorParent[0], y: anchorParent[1], z: anchorParent[2] };\n const a2 = { x: anchorChild[0], y: anchorChild[1], z: anchorChild[2] };\n const qRel = _qRel.set(restFrameRelQuat[0], restFrameRelQuat[1], restFrameRelQuat[2], restFrameRelQuat[3]).normalize();\n const axFromChild = _axWorld.set(axisChild[0], axisChild[1], axisChild[2]).applyQuaternion(qRel);\n const ax = (axFromChild.lengthSq() > 1e-12 ? axFromChild : _axWorld.set(axisParent[0], axisParent[1], axisParent[2])).normalize();\n let data: RAPIER.JointData;\n if (joint.kind === \"fixed\") {\n const pr = parentBody.rotation();\n const cr = childBody.rotation();\n const bodyRel = _q1.set(pr.x, pr.y, pr.z, pr.w).invert().multiply(_q2.set(cr.x, cr.y, cr.z, cr.w)).normalize();\n const useBodyRel = Math.abs(bodyRel.x) + Math.abs(bodyRel.y) + Math.abs(bodyRel.z) <= 1e-6 && Math.abs(Math.abs(bodyRel.w) - 1) <= 1e-6;\n const f1 = useBodyRel\n ? { x: bodyRel.x, y: bodyRel.y, z: bodyRel.z, w: bodyRel.w }\n : { x: qRel.x, y: qRel.y, z: qRel.z, w: qRel.w };\n data = rapier.JointData.fixed(\n a1,\n f1,\n a2,\n { x: 0, y: 0, z: 0, w: 1 },\n );\n }\n else if (joint.kind === \"revolute\") {\n data = rapier.JointData.revolute(a1, a2, { x: ax.x, y: ax.y, z: ax.z });\n if (joint.limits) {\n data.limitsEnabled = true;\n data.limits = [joint.limits[0], joint.limits[1]];\n }\n }\n else {\n data = rapier.JointData.prismatic(a1, a2, { x: ax.x, y: ax.y, z: ax.z });\n if (joint.limits) {\n data.limitsEnabled = true;\n data.limits = [joint.limits[0], joint.limits[1]];\n }\n }\n const imp = world.createImpulseJoint(data, parentBody, childBody, true);\n imp.setContactsEnabled(Boolean(joint.enableCollision));\n configureJointDrive(rapier, imp, joint.kind, joint.drive, joint.drive?.positionTarget ?? null);\n return imp;\n}\n\nexport function configureJointDrive(\n rapier: typeof RAPIER,\n imp: RAPIER.ImpulseJoint,\n kind: KhrJointSpec[\"kind\"],\n drive: KhrJointDriveSpec | null,\n targetPos: number | null,\n): void {\n if (kind === \"fixed\" || !drive)\n return;\n const unit = imp as RAPIER.UnitImpulseJoint & { setMotorMaxForce?: (maxForce: number) => void };\n unit.configureMotorModel(\n drive.mode === \"force\" ? rapier.MotorModel.ForceBased : rapier.MotorModel.AccelerationBased,\n );\n const effTargetPos = targetPos ?? drive.positionTarget ?? (drive.stiffness !== undefined && drive.stiffness > 0 ? 0 : null);\n if (effTargetPos !== null && drive.stiffness !== undefined) {\n if (drive.velocityTarget !== undefined) {\n unit.configureMotor(effTargetPos, drive.velocityTarget, drive.stiffness, drive.damping ?? 0);\n }\n else {\n unit.configureMotorPosition(effTargetPos, drive.stiffness, drive.damping ?? 0);\n }\n }\n else if (drive.velocityTarget !== undefined) {\n unit.configureMotorVelocity(drive.velocityTarget, drive.damping ?? 0);\n }\n if (drive.maxForce !== undefined) {\n unit.setMotorMaxForce?.(drive.maxForce);\n }\n}\n\nexport function measureJointCoordinate(\n parentBody: RAPIER.RigidBody | null,\n childBody: RAPIER.RigidBody | null,\n kind: KhrJointSpec[\"kind\"],\n axisParent: readonly [number, number, number],\n anchorParent: readonly [number, number, number],\n restRelQuat: readonly [number, number, number, number],\n): number {\n if (!parentBody || !childBody || kind === \"fixed\")\n return 0;\n const pr = parentBody.rotation();\n const cr = childBody.rotation();\n _q1.set(pr.x, pr.y, pr.z, pr.w);\n _q2.set(cr.x, cr.y, cr.z, cr.w);\n if (kind === \"prismatic\") {\n const pt = parentBody.translation();\n const ct = childBody.translation();\n _deltaPos.set(anchorParent[0], anchorParent[1], anchorParent[2]).applyQuaternion(_q1);\n _deltaPos.set(ct.x - (pt.x + _deltaPos.x), ct.y - (pt.y + _deltaPos.y), ct.z - (pt.z + _deltaPos.z));\n _axWorld.set(axisParent[0], axisParent[1], axisParent[2]).applyQuaternion(_q1).normalize();\n return _deltaPos.dot(_axWorld);\n }\n _restInv.set(restRelQuat[0], restRelQuat[1], restRelQuat[2], restRelQuat[3]).invert();\n _qRel.copy(_q1).invert().multiply(_q2).premultiply(_restInv).normalize();\n if (_qRel.w < 0)\n _qRel.set(-_qRel.x, -_qRel.y, -_qRel.z, -_qRel.w);\n const sinHalf = _qRel.x * axisParent[0] + _qRel.y * axisParent[1] + _qRel.z * axisParent[2];\n return 2 * Math.atan2(sinHalf, _qRel.w);\n}\n\nexport function buildJointRuntime(params: {\n rapier: typeof RAPIER;\n world?: RAPIER.World;\n nodeName: string;\n role: string | null;\n kind: KhrJointSpec[\"kind\"];\n object: THREE.Object3D;\n axisParent: readonly [number, number, number];\n anchorParent: readonly [number, number, number];\n restRelQuat: readonly [number, number, number, number];\n limits: [number, number] | null;\n drive: KhrJointDriveSpec | null;\n breakaway?: KhrBreakawaySpec;\n rapierJoint: RAPIER.ImpulseJoint;\n parentBody: RAPIER.RigidBody;\n childBody: RAPIER.RigidBody;\n}): JointRuntime {\n const { rapier, world, nodeName, role, kind, object, axisParent, anchorParent, restRelQuat, limits, drive, breakaway, rapierJoint, parentBody, childBody } = params;\n const rt: JointRuntime = {\n nodeName,\n role,\n kind,\n object,\n axis: new THREE.Vector3(axisParent[0], axisParent[1], axisParent[2]).normalize(),\n limits,\n drive,\n positionTarget: drive?.positionTarget ?? null,\n velocityTarget: drive?.velocityTarget ?? 0,\n rapierJoint,\n parentBody,\n childBody,\n unlatched: false,\n detached: false,\n getCoordinate: () => measureJointCoordinate(rt.parentBody, rt.childBody, kind, axisParent, anchorParent, restRelQuat),\n applyTarget: (target: number) => {\n if (rt.detached || !rt.rapierJoint)\n return;\n if (!drive || drive.stiffness === undefined) {\n throw new KhrValidationError(`Joint \"${nodeName}\" has no authored drive stiffness; cannot set a position target`);\n }\n rt.unlatched = false;\n rt.positionTarget = target;\n configureJointDrive(rapier, rt.rapierJoint, kind, drive, target);\n if (parentBody.isDynamic())\n parentBody.wakeUp();\n if (childBody.isDynamic())\n childBody.wakeUp();\n },\n applyImpactImpulse: (impulseNs: number) => {\n if (rt.detached || !breakaway || !(impulseNs > 0))\n return rt.detached ? \"detached\" : rt.unlatched ? \"unlatched\" : \"intact\";\n if (impulseNs >= breakaway.breakImpulseNs) {\n if (world && rt.rapierJoint && world.getImpulseJoint(rt.rapierJoint.handle)) {\n world.removeImpulseJoint(rt.rapierJoint, true);\n }\n rt.rapierJoint = null;\n rt.detached = true;\n rt.unlatched = true;\n rt.positionTarget = null;\n const ud = childBody.userData as { ecctrl?: Record<string, unknown> } | undefined;\n if (ud?.ecctrl) {\n childBody.userData = { ...ud, ecctrl: { ...ud.ecctrl, excludeVehicleRay: false } };\n }\n for (let i = 0; i < childBody.numColliders(); i++) {\n const col = childBody.collider(i);\n const cg = col.collisionGroups();\n if (cg === VEHICLE_PANEL_INTERACTION_GROUPS || cg === 0x4000bfff) {\n col.setCollisionGroups(0xffffffff);\n col.setSolverGroups(0xffffffff);\n }\n }\n if (childBody.isDynamic())\n childBody.wakeUp();\n return \"detached\";\n }\n if (breakaway.latchImpulseNs !== undefined && impulseNs >= breakaway.latchImpulseNs && !rt.unlatched) {\n rt.unlatched = true;\n rt.positionTarget = null;\n if (kind !== \"fixed\" && rt.rapierJoint) {\n const unit = rt.rapierJoint as RAPIER.UnitImpulseJoint;\n unit.configureMotorPosition(0, 0, Math.min(drive?.damping ?? 1, 1.5));\n }\n if (childBody.isDynamic())\n childBody.wakeUp();\n return \"unlatched\";\n }\n return rt.unlatched ? \"unlatched\" : \"intact\";\n },\n };\n return rt;\n}\n","import { createContext } from \"react\";\nimport type * as THREE from \"three\";\nimport type RAPIER from \"@dimforge/rapier3d-compat\";\nimport type { KhrJointDriveSpec, KhrJointSpec } from \"./khrTypes.js\";\n\nexport interface JointRuntime {\n nodeName: string;\n role: string | null;\n kind: KhrJointSpec[\"kind\"];\n object: THREE.Object3D;\n axis: THREE.Vector3;\n limits: [number, number] | null;\n drive: KhrJointDriveSpec | null;\n positionTarget: number | null;\n velocityTarget: number;\n rapierJoint: RAPIER.ImpulseJoint | null;\n parentBody: RAPIER.RigidBody | null;\n childBody: RAPIER.RigidBody | null;\n unlatched: boolean;\n detached: boolean;\n getCoordinate: () => number;\n applyTarget: (target: number) => void;\n applyImpactImpulse: (impulseNs: number) => \"intact\" | \"unlatched\" | \"detached\";\n}\n\nexport type JointRegistry = Set<JointRuntime>;\n\n/** Retained as an optional context export for compatibility; Rapier steps ImpulseJoints natively. */\nexport const JointRegistryContext = createContext<JointRegistry | null>(null);\n"],"mappings":";;;;;;AAGA,IAAM,gCAAgB,IAAI,QAAwB;AAClD,IAAM,+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sand3dAssembly, Sand3dJointDef, Sand3dNodeItem, Sand3dPartOpts, Sand3dPartSpec, Sand3dSocketDef, Sand3dSolid, Sand3dThrusterDef, Sand3dUnits, Sand3dWheelDef, Vec3 } from "./sand3dTypes.js";
4
+ export declare const r4: (v: number) => number;
5
+ export declare const scaleV3: (v: Vec3 | undefined, s: number) => Vec3;
6
+ export declare function makeSand3dMaterial(name: string, shade: string | number | undefined, rough?: number, metal?: number, opacity?: number): THREE.MeshStandardMaterial;
7
+ export declare function part(name: string, solid: Sand3dSolid, opts?: Sand3dPartOpts): Sand3dPartSpec;
8
+ type JointOptsLike = Partial<Sand3dJointDef> & {
9
+ range?: [number, number] | null;
10
+ };
11
+ export declare function joint(kindOrSpec: "revolute" | "prismatic" | "fixed" | (Omit<Sand3dJointDef, "kind" | "jointKind"> & {
12
+ kind?: "revolute" | "prismatic" | "fixed";
13
+ jointKind?: "revolute" | "prismatic" | "fixed";
14
+ range?: [number, number] | null;
15
+ }), parentOrOpts?: string | JointOptsLike, childArg?: string, optsArg?: JointOptsLike): Sand3dJointDef;
16
+ export declare function wheel(name: string, opts: Omit<Sand3dWheelDef, "kind" | "name">): Sand3dWheelDef;
17
+ export declare function thruster(name: string, opts: Omit<Sand3dThrusterDef, "kind" | "name">): Sand3dThrusterDef;
18
+ export declare function socket(name: string, position: Vec3, opts?: Omit<Sand3dSocketDef, "kind" | "name" | "position">): Sand3dSocketDef;
19
+ export declare function assembly(name: string, itemsOrConfig: readonly Sand3dNodeItem[] | Partial<Omit<Sand3dAssembly, "kind" | "name">>, opts?: {
20
+ units?: Sand3dUnits;
21
+ carTune?: Partial<KhrCarConfig>;
22
+ droneTune?: Partial<KhrDroneConfig>;
23
+ extras?: Record<string, unknown>;
24
+ }): Sand3dAssembly;
25
+ export declare function exportTarget(target: Sand3dAssembly | Sand3dPartSpec | Sand3dSolid, opts?: {
26
+ name?: string;
27
+ units?: Sand3dUnits;
28
+ }): Sand3dAssembly;
29
+ export declare function appendRotorsAndSockets(asm: Sand3dAssembly, s: number, totalBodyMass: number, primaryBodyName: string, nodeMap: Map<string, THREE.Object3D>, worldOriginByPart: Map<string, Vec3>, scene: THREE.Group, specs: KhrExportNodeSpec[]): void;
30
+ export {};
@@ -0,0 +1,15 @@
1
+ import { resolveFaceFrame, shell } from "./sand3dShellOp.js";
2
+ import type { Sand3dFaceSelector, Sand3dProfile, Sand3dSolid, Vec2 } from "./sand3dTypes.js";
3
+ export { resolveFaceFrame, shell };
4
+ /** Carves cylindrical through-bores or blind bores with re-triangulated planar cap rings. */
5
+ export declare function hole(solid: Sand3dSolid, diameter: number, opts?: {
6
+ depth?: number;
7
+ on?: readonly Vec2[] | Vec2;
8
+ face?: Sand3dFaceSelector;
9
+ segments?: number;
10
+ }): Sand3dSolid;
11
+ /** Carves recessed or through polygonal cavities with re-triangulated walls and floor caps. */
12
+ export declare function pocket(solid: Sand3dSolid, profile: Sand3dProfile, depth: number, opts?: {
13
+ on?: readonly Vec2[] | Vec2;
14
+ face?: Sand3dFaceSelector;
15
+ }): Sand3dSolid;