@khr3/core 0.2.9 → 0.2.11

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 (76) hide show
  1. package/README.md +5 -175
  2. package/dist/KhrAssembly-CKW8I_2z.js +1667 -0
  3. package/dist/KhrAssembly-CKW8I_2z.js.map +1 -0
  4. package/dist/KhrAssembly.d.ts +46 -8
  5. package/dist/KhrCollider.d.ts +21 -7
  6. package/dist/clone.d.ts +40 -0
  7. package/dist/{khrExporter.d.ts → exporter.d.ts} +2 -2
  8. package/dist/{khrGlb.d.ts → glb.d.ts} +4 -3
  9. package/dist/index.d.ts +10 -10
  10. package/dist/index.js +1548 -343
  11. package/dist/index.js.map +1 -1
  12. package/dist/{khrInertia.d.ts → inertia.d.ts} +22 -8
  13. package/dist/{jointDynamics.d.ts → joints.d.ts} +8 -7
  14. package/dist/loader.d.ts +9 -0
  15. package/dist/types.d.ts +282 -0
  16. package/dist/useKhrGlb.d.ts +6 -1
  17. package/dist/vehicle.d.ts +35 -2
  18. package/dist/vehicle.js +435 -539
  19. package/dist/vehicle.js.map +1 -1
  20. package/dist/wheelLoads.d.ts +5 -4
  21. package/package.json +6 -25
  22. package/AGENTS.md +0 -12
  23. package/CLAUDE.md +0 -8
  24. package/dist/AssemblyRootBody.d.ts +0 -16
  25. package/dist/BundleSceneHost.d.ts +0 -23
  26. package/dist/KhrVehicle.d.ts +0 -20
  27. package/dist/assemblyPlan.d.ts +0 -61
  28. package/dist/curves-Cf8okB-M.js +0 -542
  29. package/dist/curves-Cf8okB-M.js.map +0 -1
  30. package/dist/curves.d.ts +0 -378
  31. package/dist/curves.js +0 -1
  32. package/dist/khrBundleFinalize.d.ts +0 -15
  33. package/dist/khrClone.d.ts +0 -14
  34. package/dist/khrConfigTypes.d.ts +0 -62
  35. package/dist/khrExportEncoders.d.ts +0 -8
  36. package/dist/khrExtras.d.ts +0 -22
  37. package/dist/khrInertia-DgCUCDTx.js +0 -247
  38. package/dist/khrInertia-DgCUCDTx.js.map +0 -1
  39. package/dist/khrJointParser.d.ts +0 -3
  40. package/dist/khrLoader.d.ts +0 -7
  41. package/dist/khrMassProps.d.ts +0 -16
  42. package/dist/khrParsers.d.ts +0 -10
  43. package/dist/khrPlugin.d.ts +0 -8
  44. package/dist/khrPluginHelpers.d.ts +0 -26
  45. package/dist/khrRotorDecoders.d.ts +0 -4
  46. package/dist/khrShapeParser.d.ts +0 -8
  47. package/dist/khrTypes.d.ts +0 -141
  48. package/dist/khrVehicleChassis.d.ts +0 -20
  49. package/dist/khrVehicleJointHelpers.d.ts +0 -37
  50. package/dist/khrVehicleJoints.d.ts +0 -30
  51. package/dist/khrVehicleRotors.d.ts +0 -22
  52. package/dist/khrVehicleSlots.d.ts +0 -41
  53. package/dist/khrVehicleTypes.d.ts +0 -52
  54. package/dist/pacejka.d.ts +0 -22
  55. package/dist/physicsEcs-C00N5zCh.js +0 -914
  56. package/dist/physicsEcs-C00N5zCh.js.map +0 -1
  57. package/dist/physicsEcs.d.ts +0 -25
  58. package/dist/sand3d/sand3dAssemblyHelpers.d.ts +0 -30
  59. package/dist/sand3d/sand3dCavityOps.d.ts +0 -15
  60. package/dist/sand3d/sand3dCompiler.d.ts +0 -121
  61. package/dist/sand3d/sand3dEvaluator.d.ts +0 -80
  62. package/dist/sand3d/sand3dFramesAndEdits.d.ts +0 -30
  63. package/dist/sand3d/sand3dHullAndSweep.d.ts +0 -27
  64. package/dist/sand3d/sand3dParser.d.ts +0 -6
  65. package/dist/sand3d/sand3dPrimitives.d.ts +0 -50
  66. package/dist/sand3d/sand3dProfiles.d.ts +0 -32
  67. package/dist/sand3d/sand3dRecipes.d.ts +0 -5
  68. package/dist/sand3d/sand3dShellOp.d.ts +0 -8
  69. package/dist/sand3d/sand3dSolids.d.ts +0 -32
  70. package/dist/sand3d/sand3dTokenizer.d.ts +0 -8
  71. package/dist/sand3d/sand3dTypes.d.ts +0 -157
  72. package/dist/sand3d-DQ8-OMlo.js +0 -5045
  73. package/dist/sand3d-DQ8-OMlo.js.map +0 -1
  74. package/dist/sand3d.d.ts +0 -23
  75. package/dist/sand3d.js +0 -1
  76. package/docs/api-reference.md +0 -383
@@ -1,247 +0,0 @@
1
- import * as THREE from "three";
2
- // src/khrConfigTypes.ts
3
- var KhrValidationError = class extends Error {
4
- constructor(message) {
5
- super(message);
6
- this.name = "KhrValidationError";
7
- }
8
- };
9
- // src/khrInertia.ts
10
- var SCALE_EPS = 1e-4;
11
- function isUnitScalar(v) {
12
- return typeof v === "number" && Number.isFinite(v) && Math.abs(v - 1) <= 1e-9;
13
- }
14
- function assertUnitScale(scale, owner) {
15
- if (scale === void 0) return;
16
- let ok = false;
17
- if (typeof scale === "number") ok = isUnitScalar(scale);
18
- else if (Array.isArray(scale)) ok = scale.length === 3 && scale.every(isUnitScalar);
19
- else if (typeof scale === "object" && scale && "x" in scale && "y" in scale && "z" in scale) {
20
- const v = scale;
21
- ok = isUnitScalar(v.x) && isUnitScalar(v.y) && isUnitScalar(v.z);
22
- }
23
- 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`);
24
- }
25
- function readFiniteVec3(val, fieldLabel) {
26
- 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`);
27
- return [
28
- val[0],
29
- val[1],
30
- val[2]
31
- ];
32
- }
33
- function readUnitQuat(val, fieldLabel) {
34
- 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`);
35
- const norm = Math.hypot(val[0], val[1], val[2], val[3]);
36
- if (!(norm > 1e-6)) throw new KhrValidationError(`Invalid ${fieldLabel}: zero-norm quaternion`);
37
- return [
38
- val[0] / norm,
39
- val[1] / norm,
40
- val[2] / norm,
41
- val[3] / norm
42
- ];
43
- }
44
- function assertIdentityWorldScale(obj, nodeName) {
45
- const ws = obj.getWorldScale(new THREE.Vector3());
46
- 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]`);
47
- const ls = obj.scale;
48
- 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]`);
49
- }
50
- function assertSceneIdentityWorldScale(root) {
51
- root.traverse((child) => {
52
- assertIdentityWorldScale(child, child.name || (child === root ? "gltf.scene" : "unnamed_node"));
53
- });
54
- }
55
- function computeRelativePose(ownerObj, childObj) {
56
- const ownerPos = ownerObj.getWorldPosition(new THREE.Vector3());
57
- const ownerInvQuat = ownerObj.getWorldQuaternion(new THREE.Quaternion()).invert();
58
- const pos = childObj.getWorldPosition(new THREE.Vector3()).sub(ownerPos).applyQuaternion(ownerInvQuat);
59
- const quat = ownerInvQuat.multiply(childObj.getWorldQuaternion(new THREE.Quaternion()));
60
- return {
61
- localPosition: [
62
- pos.x,
63
- pos.y,
64
- pos.z
65
- ],
66
- localQuaternion: [
67
- quat.x,
68
- quat.y,
69
- quat.z,
70
- quat.w
71
- ]
72
- };
73
- }
74
- function extractMeshColliderShape(targetObj, meshNodeName, convexHull) {
75
- assertIdentityWorldScale(targetObj, meshNodeName);
76
- const invOwner = targetObj.matrixWorld.clone().invert();
77
- const rel = new THREE.Matrix4();
78
- const v = new THREE.Vector3();
79
- const verts = [];
80
- const indices = [];
81
- targetObj.traverse((child) => {
82
- const mesh = child;
83
- if (!mesh.isMesh || !mesh.geometry) return;
84
- assertIdentityWorldScale(mesh, mesh.name || meshNodeName);
85
- const posAttr = mesh.geometry.getAttribute("position");
86
- if (!posAttr || posAttr.count === 0) return;
87
- rel.multiplyMatrices(invOwner, mesh.matrixWorld);
88
- const base = verts.length / 3;
89
- for (let i = 0; i < posAttr.count; i++) {
90
- v.fromBufferAttribute(posAttr, i).applyMatrix4(rel);
91
- if (!Number.isFinite(v.x) || !Number.isFinite(v.y) || !Number.isFinite(v.z)) throw new KhrValidationError(`Non-finite vertex in collider mesh "${meshNodeName}"`);
92
- verts.push(v.x, v.y, v.z);
93
- }
94
- const idx = mesh.geometry.getIndex();
95
- if (idx) for (let i = 0; i < idx.count; i++) indices.push(base + idx.getX(i));
96
- else for (let i = 0; i < posAttr.count; i++) indices.push(base + i);
97
- });
98
- if (verts.length < 9) throw new KhrValidationError(`Collider node "${meshNodeName}" has fewer than 3 vertices`);
99
- if (convexHull) return {
100
- type: "convexHull",
101
- vertices: new Float32Array(verts),
102
- meshNodeName
103
- };
104
- if (indices.length < 3) throw new KhrValidationError(`Trimesh node "${meshNodeName}" has fewer than 3 indices`);
105
- return {
106
- type: "trimesh",
107
- vertices: new Float32Array(verts),
108
- indices: new Uint32Array(indices),
109
- meshNodeName
110
- };
111
- }
112
- function unitInertiaForShape(shape) {
113
- if (shape.type === "box") {
114
- const [x, y, z] = shape.size;
115
- return {
116
- volume: x * y * z,
117
- centroid: new THREE.Vector3(),
118
- unitInertia: [
119
- (y * y + z * z) / 12,
120
- (x * x + z * z) / 12,
121
- (x * x + y * y) / 12
122
- ]
123
- };
124
- }
125
- if (shape.type === "sphere") {
126
- const r = shape.radius;
127
- const i = .4 * r * r;
128
- return {
129
- volume: 4 / 3 * Math.PI * r * r * r,
130
- centroid: new THREE.Vector3(),
131
- unitInertia: [
132
- i,
133
- i,
134
- i
135
- ]
136
- };
137
- }
138
- if (shape.type === "convexHull" || shape.type === "trimesh") {
139
- const box = new THREE.Box3();
140
- const pt = new THREE.Vector3();
141
- const verts = shape.vertices;
142
- for (let i = 0; i < verts.length; i += 3) box.expandByPoint(pt.set(verts[i], verts[i + 1], verts[i + 2]));
143
- const s = box.getSize(new THREE.Vector3());
144
- return {
145
- volume: s.x * s.y * s.z,
146
- centroid: box.getCenter(new THREE.Vector3()),
147
- unitInertia: [
148
- (s.y * s.y + s.z * s.z) / 12,
149
- (s.x * s.x + s.z * s.z) / 12,
150
- (s.x * s.x + s.y * s.y) / 12
151
- ]
152
- };
153
- }
154
- const r = shape.radiusTop;
155
- const h = shape.height;
156
- if (shape.type === "capsule") {
157
- const cylVol = Math.PI * r * r * h;
158
- const totVol = cylVol + 4 / 3 * Math.PI * r * r * r;
159
- const fc = cylVol / totVol;
160
- const fh = 1 - fc;
161
- const iy = .5 * fc * r * r + .4 * fh * r * r;
162
- const ix = fc * (h * h / 12 + .25 * r * r) + fh * (.4 * r * r + .25 * h * h + .375 * h * r);
163
- return {
164
- volume: totVol,
165
- centroid: new THREE.Vector3(),
166
- unitInertia: [
167
- ix,
168
- iy,
169
- ix
170
- ]
171
- };
172
- }
173
- const ix = (3 * r * r + h * h) / 12;
174
- return {
175
- volume: Math.PI * r * r * h,
176
- centroid: new THREE.Vector3(),
177
- unitInertia: [
178
- ix,
179
- .5 * r * r,
180
- ix
181
- ]
182
- };
183
- }
184
- function computeBodyInertia(colliders, mass, centerOfMass, inertiaOrientation, nodeName) {
185
- if (colliders.length === 0) throw new KhrValidationError(`Dynamic node "${nodeName}" is missing motion.inertiaDiagonal and has no colliders`);
186
- const shapes = colliders.map((c) => unitInertiaForShape(c.shape));
187
- let totalVol = 0;
188
- for (const s of shapes) totalVol += s.volume;
189
- const invFrame = new THREE.Quaternion().fromArray(inertiaOrientation).invert();
190
- const com = new THREE.Vector3().fromArray(centerOfMass);
191
- const colQuat = new THREE.Quaternion();
192
- const relQuat = new THREE.Quaternion();
193
- const offset = new THREE.Vector3();
194
- const rotMat = new THREE.Matrix4();
195
- const m = rotMat.elements;
196
- let ix = 0, iy = 0, iz = 0;
197
- for (let i = 0; i < colliders.length; i++) {
198
- const col = colliders[i];
199
- const shp = shapes[i];
200
- const mShare = totalVol > 0 ? mass * (shp.volume / totalVol) : mass / colliders.length;
201
- colQuat.fromArray(col.localQuaternion);
202
- offset.copy(shp.centroid).applyQuaternion(colQuat).add(new THREE.Vector3().fromArray(col.localPosition)).sub(com).applyQuaternion(invFrame);
203
- relQuat.copy(invFrame).multiply(colQuat);
204
- rotMat.makeRotationFromQuaternion(relQuat);
205
- const [u0, u1, u2] = shp.unitInertia;
206
- const rx = m[0] * m[0] * u0 + m[4] * m[4] * u1 + m[8] * m[8] * u2;
207
- const ry = m[1] * m[1] * u0 + m[5] * m[5] * u1 + m[9] * m[9] * u2;
208
- const rz = m[2] * m[2] * u0 + m[6] * m[6] * u1 + m[10] * m[10] * u2;
209
- ix += mShare * (rx + offset.y * offset.y + offset.z * offset.z);
210
- iy += mShare * (ry + offset.x * offset.x + offset.z * offset.z);
211
- iz += mShare * (rz + offset.x * offset.x + offset.y * offset.y);
212
- }
213
- 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`);
214
- return [
215
- ix,
216
- iy,
217
- iz
218
- ];
219
- }
220
- function computeAssemblyMassAndCom(bodies) {
221
- let totalDynamicMass = 0, mx = 0, my = 0, mz = 0;
222
- const q = new THREE.Quaternion();
223
- const c = new THREE.Vector3();
224
- for (const b of bodies) {
225
- if (b.isKinematic) continue;
226
- totalDynamicMass += b.mass;
227
- c.fromArray(b.centerOfMass).applyQuaternion(q.fromArray(b.localQuaternion));
228
- mx += (b.localPosition[0] + c.x) * b.mass;
229
- my += (b.localPosition[1] + c.y) * b.mass;
230
- mz += (b.localPosition[2] + c.z) * b.mass;
231
- }
232
- return {
233
- totalDynamicMass,
234
- centerOfMass: totalDynamicMass > 0 ? [
235
- mx / totalDynamicMass,
236
- my / totalDynamicMass,
237
- mz / totalDynamicMass
238
- ] : [
239
- 0,
240
- 0,
241
- 0
242
- ]
243
- };
244
- }
245
- export { computeBodyInertia as a, readFiniteVec3 as c, computeAssemblyMassAndCom as i, readUnitQuat as l, assertSceneIdentityWorldScale as n, computeRelativePose as o, assertUnitScale as r, extractMeshColliderShape as s, assertIdentityWorldScale as t, KhrValidationError as u };
246
-
247
- //# sourceMappingURL=khrInertia-DgCUCDTx.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"khrInertia-DgCUCDTx.js","names":[],"sources":["../src/khrConfigTypes.ts","../src/khrInertia.ts"],"sourcesContent":["import type { GLTFLoader } from \"three/examples/jsm/loaders/GLTFLoader.js\";\n\nexport class KhrValidationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"KhrValidationError\";\n }\n}\n\nexport interface KhrCurvePoint {\n x: number;\n y: number;\n r_in?: number;\n r_out?: number;\n w_in?: number;\n w_out?: number;\n}\n\nexport interface KhrCurveData {\n points: KhrCurvePoint[];\n samples?: number;\n}\n\nexport interface KhrCarConfig {\n controlMode?: \"VELOCITY\" | \"POSITION\";\n engineHorsepower?: number;\n engineMaxRPM?: number;\n gearRatios?: number[];\n finalDriveRatio?: number;\n transmissionMode?: \"auto\" | \"manual\";\n shiftUpRPM?: number;\n shiftDownRPM?: number;\n shiftCooldown?: number;\n steerRate?: number;\n maxSteerAngle?: number;\n reverseTorqueScale?: number;\n reverseRPMScale?: number;\n engineTorqueCurveData?: KhrCurveData;\n steerAngleCurveData?: KhrCurveData;\n}\n\nexport interface KhrDroneConfig {\n controlMode?: \"VELOCITY\" | \"POSITION\";\n maxYawRate?: number;\n maxHorizSpeed?: number;\n maxVertSpeed?: number;\n maxTiltAngle?: number;\n airDragFactor?: number;\n TILT_P?: number;\n TILT_D?: number;\n YAW_POS_P?: number;\n YAW_VEL_P?: number;\n VERT_POS_P?: number;\n VERT_POS_D?: number;\n HORIZ_POS_P?: number;\n HORIZ_POS_D?: number;\n HORIZ_VEL_P?: number;\n VERT_VEL_P?: number;\n}\n\nexport interface KhrPluginOptions {\n extractRole?: (nodeName: string, extras: Record<string, unknown>) => string | null;\n isSocketNode?: (nodeName: string, extras: Record<string, unknown>) => boolean | string;\n}\n\nexport interface LoadKhrGlbOptions extends KhrPluginOptions {\n loader?: GLTFLoader;\n}\n\nexport interface UseKhrGlbOptions extends KhrPluginOptions {\n extendLoader?: (loader: GLTFLoader) => void;\n cacheKey?: string;\n}\n","import * as THREE from \"three\";\nimport { type KhrBodySpec, type KhrColliderShape, type KhrColliderSpec, KhrValidationError } from \"./khrTypes.js\";\n\nconst SCALE_EPS = 1e-4;\n\nfunction isUnitScalar(v: unknown): boolean {\n return typeof v === \"number\" && Number.isFinite(v) && Math.abs(v - 1) <= 1e-9;\n}\n\nexport function assertUnitScale(scale: unknown, owner: string): void {\n if (scale === undefined) return;\n let ok = false;\n if (typeof scale === \"number\") ok = isUnitScalar(scale);\n else if (Array.isArray(scale)) ok = scale.length === 3 && scale.every(isUnitScalar);\n else if (typeof scale === \"object\" && scale && \"x\" in scale && \"y\" in scale && \"z\" in scale) {\n const v = scale as { x: unknown; y: unknown; z: unknown };\n ok = isUnitScalar(v.x) && isUnitScalar(v.y) && isUnitScalar(v.z);\n }\n 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`);\n}\n\nexport function readFiniteVec3(val: unknown, fieldLabel: string): [number, number, number] {\n if (!Array.isArray(val) || val.length !== 3 || !val.every((n) => typeof n === \"number\" && Number.isFinite(n))) {\n throw new KhrValidationError(`Invalid ${fieldLabel}: expected finite 3-tuple`);\n }\n return [val[0], val[1], val[2]];\n}\n\nexport function readUnitQuat(val: unknown, fieldLabel: string): [number, number, number, number] {\n if (!Array.isArray(val) || val.length !== 4 || !val.every((n) => typeof n === \"number\" && Number.isFinite(n))) {\n throw new KhrValidationError(`Invalid ${fieldLabel}: expected finite 4-tuple`);\n }\n const norm = Math.hypot(val[0], val[1], val[2], val[3]);\n if (!(norm > 1e-6))\n throw new KhrValidationError(`Invalid ${fieldLabel}: zero-norm quaternion`);\n return [val[0] / norm, val[1] / norm, val[2] / norm, val[3] / norm];\n}\n\nexport function assertIdentityWorldScale(obj: THREE.Object3D, nodeName: string): void {\n const ws = obj.getWorldScale(new THREE.Vector3());\n if (!Number.isFinite(ws.x) || !Number.isFinite(ws.y) || !Number.isFinite(ws.z) ||\n Math.abs(ws.x - 1) > SCALE_EPS || Math.abs(ws.y - 1) > SCALE_EPS || Math.abs(ws.z - 1) > SCALE_EPS) {\n 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]`);\n }\n const ls = obj.scale;\n if (!Number.isFinite(ls.x) || !Number.isFinite(ls.y) || !Number.isFinite(ls.z) ||\n Math.abs(ls.x - 1) > SCALE_EPS || Math.abs(ls.y - 1) > SCALE_EPS || Math.abs(ls.z - 1) > SCALE_EPS) {\n 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]`);\n }\n}\n\nexport function assertSceneIdentityWorldScale(root: THREE.Object3D): void {\n root.traverse((child) => {\n assertIdentityWorldScale(child, child.name || (child === root ? \"gltf.scene\" : \"unnamed_node\"));\n });\n}\n\nexport function computeRelativePose(ownerObj: THREE.Object3D, childObj: THREE.Object3D): {\n localPosition: [number, number, number];\n localQuaternion: [number, number, number, number];\n} {\n const ownerPos = ownerObj.getWorldPosition(new THREE.Vector3());\n const ownerInvQuat = ownerObj.getWorldQuaternion(new THREE.Quaternion()).invert();\n const pos = childObj.getWorldPosition(new THREE.Vector3()).sub(ownerPos).applyQuaternion(ownerInvQuat);\n const quat = ownerInvQuat.multiply(childObj.getWorldQuaternion(new THREE.Quaternion()));\n return {\n localPosition: [pos.x, pos.y, pos.z],\n localQuaternion: [quat.x, quat.y, quat.z, quat.w],\n };\n}\n\nexport function extractMeshColliderShape(targetObj: THREE.Object3D, meshNodeName: string, convexHull: boolean): KhrColliderShape {\n assertIdentityWorldScale(targetObj, meshNodeName);\n const invOwner = targetObj.matrixWorld.clone().invert();\n const rel = new THREE.Matrix4();\n const v = new THREE.Vector3();\n const verts: number[] = [];\n const indices: number[] = [];\n targetObj.traverse((child) => {\n const mesh = child as THREE.Mesh;\n if (!mesh.isMesh || !mesh.geometry)\n return;\n assertIdentityWorldScale(mesh, mesh.name || meshNodeName);\n const posAttr = mesh.geometry.getAttribute(\"position\");\n if (!posAttr || posAttr.count === 0)\n return;\n rel.multiplyMatrices(invOwner, mesh.matrixWorld);\n const base = verts.length / 3;\n for (let i = 0; i < posAttr.count; i++) {\n v.fromBufferAttribute(posAttr, i).applyMatrix4(rel);\n if (!Number.isFinite(v.x) || !Number.isFinite(v.y) || !Number.isFinite(v.z)) {\n throw new KhrValidationError(`Non-finite vertex in collider mesh \"${meshNodeName}\"`);\n }\n verts.push(v.x, v.y, v.z);\n }\n const idx = mesh.geometry.getIndex();\n if (idx) {\n for (let i = 0; i < idx.count; i++)\n indices.push(base + idx.getX(i));\n }\n else {\n for (let i = 0; i < posAttr.count; i++)\n indices.push(base + i);\n }\n });\n if (verts.length < 9)\n throw new KhrValidationError(`Collider node \"${meshNodeName}\" has fewer than 3 vertices`);\n if (convexHull) {\n return { type: \"convexHull\", vertices: new Float32Array(verts), meshNodeName };\n }\n if (indices.length < 3)\n throw new KhrValidationError(`Trimesh node \"${meshNodeName}\" has fewer than 3 indices`);\n return { type: \"trimesh\", vertices: new Float32Array(verts), indices: new Uint32Array(indices), meshNodeName };\n}\n\nfunction unitInertiaForShape(shape: KhrColliderShape): {\n volume: number;\n centroid: THREE.Vector3;\n unitInertia: [number, number, number];\n} {\n if (shape.type === \"box\") {\n const [x, y, z] = shape.size;\n return {\n volume: x * y * z,\n centroid: new THREE.Vector3(),\n unitInertia: [(y * y + z * z) / 12, (x * x + z * z) / 12, (x * x + y * y) / 12],\n };\n }\n if (shape.type === \"sphere\") {\n const r = shape.radius;\n const i = 0.4 * r * r;\n return {\n volume: (4 / 3) * Math.PI * r * r * r,\n centroid: new THREE.Vector3(),\n unitInertia: [i, i, i],\n };\n }\n if (shape.type === \"convexHull\" || shape.type === \"trimesh\") {\n const box = new THREE.Box3();\n const pt = new THREE.Vector3();\n const verts = shape.vertices;\n for (let i = 0; i < verts.length; i += 3)\n box.expandByPoint(pt.set(verts[i], verts[i + 1], verts[i + 2]));\n const s = box.getSize(new THREE.Vector3());\n return {\n volume: s.x * s.y * s.z,\n centroid: box.getCenter(new THREE.Vector3()),\n unitInertia: [(s.y * s.y + s.z * s.z) / 12, (s.x * s.x + s.z * s.z) / 12, (s.x * s.x + s.y * s.y) / 12],\n };\n }\n const r = shape.radiusTop;\n const h = shape.height;\n if (shape.type === \"capsule\") {\n const cylVol = Math.PI * r * r * h;\n const totVol = cylVol + (4 / 3) * Math.PI * r * r * r;\n const fc = cylVol / totVol;\n const fh = 1 - fc;\n const iy = 0.5 * fc * r * r + 0.4 * fh * r * r;\n const ix = fc * ((h * h) / 12 + 0.25 * r * r) + fh * (0.4 * r * r + 0.25 * h * h + 0.375 * h * r);\n return {\n volume: totVol,\n centroid: new THREE.Vector3(),\n unitInertia: [ix, iy, ix],\n };\n }\n const ix = (3 * r * r + h * h) / 12;\n return {\n volume: Math.PI * r * r * h,\n centroid: new THREE.Vector3(),\n unitInertia: [ix, 0.5 * r * r, ix],\n };\n}\n\nexport function computeShapeInertia(shape: KhrColliderShape, mass: number): [number, number, number] {\n const [ix, iy, iz] = unitInertiaForShape(shape).unitInertia;\n return [mass * ix, mass * iy, mass * iz];\n}\n\nexport function computeBodyInertia(\n colliders: readonly KhrColliderSpec[],\n mass: number,\n centerOfMass: readonly [number, number, number],\n inertiaOrientation: readonly [number, number, number, number],\n nodeName: string,\n): [number, number, number] {\n if (colliders.length === 0) {\n throw new KhrValidationError(`Dynamic node \"${nodeName}\" is missing motion.inertiaDiagonal and has no colliders`);\n }\n const shapes = colliders.map((c) => unitInertiaForShape(c.shape));\n let totalVol = 0;\n for (const s of shapes)\n totalVol += s.volume;\n const invFrame = new THREE.Quaternion().fromArray(inertiaOrientation).invert();\n const com = new THREE.Vector3().fromArray(centerOfMass);\n const colQuat = new THREE.Quaternion();\n const relQuat = new THREE.Quaternion();\n const offset = new THREE.Vector3();\n const rotMat = new THREE.Matrix4();\n const m = rotMat.elements;\n let ix = 0, iy = 0, iz = 0;\n for (let i = 0; i < colliders.length; i++) {\n const col = colliders[i];\n const shp = shapes[i];\n const mShare = totalVol > 0 ? mass * (shp.volume / totalVol) : mass / colliders.length;\n colQuat.fromArray(col.localQuaternion);\n offset.copy(shp.centroid).applyQuaternion(colQuat).add(new THREE.Vector3().fromArray(col.localPosition)).sub(com).applyQuaternion(invFrame);\n relQuat.copy(invFrame).multiply(colQuat);\n rotMat.makeRotationFromQuaternion(relQuat);\n const [u0, u1, u2] = shp.unitInertia;\n const rx = m[0] * m[0] * u0 + m[4] * m[4] * u1 + m[8] * m[8] * u2;\n const ry = m[1] * m[1] * u0 + m[5] * m[5] * u1 + m[9] * m[9] * u2;\n const rz = m[2] * m[2] * u0 + m[6] * m[6] * u1 + m[10] * m[10] * u2;\n ix += mShare * (rx + offset.y * offset.y + offset.z * offset.z);\n iy += mShare * (ry + offset.x * offset.x + offset.z * offset.z);\n iz += mShare * (rz + offset.x * offset.x + offset.y * offset.y);\n }\n if (!Number.isFinite(ix) || !Number.isFinite(iy) || !Number.isFinite(iz) || ix <= 0 || iy <= 0 || iz <= 0) {\n throw new KhrValidationError(`Dynamic node \"${nodeName}\" has degenerate collider geometry; cannot compute positive motion.inertiaDiagonal`);\n }\n return [ix, iy, iz];\n}\n\nexport function computeAssemblyMassAndCom(bodies: readonly KhrBodySpec[]): {\n totalDynamicMass: number;\n centerOfMass: [number, number, number];\n} {\n let totalDynamicMass = 0, mx = 0, my = 0, mz = 0;\n const q = new THREE.Quaternion();\n const c = new THREE.Vector3();\n for (const b of bodies) {\n if (b.isKinematic)\n continue;\n totalDynamicMass += b.mass;\n c.fromArray(b.centerOfMass).applyQuaternion(q.fromArray(b.localQuaternion));\n mx += (b.localPosition[0] + c.x) * b.mass;\n my += (b.localPosition[1] + c.y) * b.mass;\n mz += (b.localPosition[2] + c.z) * b.mass;\n }\n return {\n totalDynamicMass,\n centerOfMass: totalDynamicMass > 0 ? [mx / totalDynamicMass, my / totalDynamicMass, mz / totalDynamicMass] : [0, 0, 0],\n };\n}\n"],"mappings":";;AAEA,IAAa,qBAAb,cAAwC,MAAM;CAC1C,YAAY,SAAiB;EACzB,MAAM,OAAO;EACb,KAAK,OAAO;CAChB;AACJ;;ACJA,IAAM,YAAY;AAElB,SAAS,aAAa,GAAqB;CACvC,OAAO,OAAO,MAAM,YAAY,OAAO,SAAS,CAAC,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK;AAC7E;AAEA,SAAgB,gBAAgB,OAAgB,OAAqB;CACjE,IAAI,UAAU,KAAA,GAAW;CACzB,IAAI,KAAK;CACT,IAAI,OAAO,UAAU,UAAU,KAAK,aAAa,KAAK;MACjD,IAAI,MAAM,QAAQ,KAAK,GAAG,KAAK,MAAM,WAAW,KAAK,MAAM,MAAM,YAAY;MAC7E,IAAI,OAAO,UAAU,YAAY,SAAS,OAAO,SAAS,OAAO,SAAS,OAAO,OAAO;EACzF,MAAM,IAAI;EACV,KAAK,aAAa,EAAE,CAAC,KAAK,aAAa,EAAE,CAAC,KAAK,aAAa,EAAE,CAAC;CACnE;CACA,IAAI,CAAC,IAAI,MAAM,IAAI,mBAAmB,GAAG,MAAM,yBAAyB,OAAO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,KAAK,MAAM,KAAK,MAAM,KAAK,MAAM,GACpG,MAAM,IAAI,mBAAmB,iBAAiB,SAAS,mFAAmF;CAE9I,OAAO;EAAC;EAAI;EAAI;CAAE;AACtB;AAEA,SAAgB,0BAA0B,QAGxC;CACE,IAAI,mBAAmB,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK;CAC/C,MAAM,IAAI,IAAI,MAAM,WAAW;CAC/B,MAAM,IAAI,IAAI,MAAM,QAAQ;CAC5B,KAAK,MAAM,KAAK,QAAQ;EACpB,IAAI,EAAE,aACF;EACJ,oBAAoB,EAAE;EACtB,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC,gBAAgB,EAAE,UAAU,EAAE,eAAe,CAAC;EAC1E,OAAO,EAAE,cAAc,KAAK,EAAE,KAAK,EAAE;EACrC,OAAO,EAAE,cAAc,KAAK,EAAE,KAAK,EAAE;EACrC,OAAO,EAAE,cAAc,KAAK,EAAE,KAAK,EAAE;CACzC;CACA,OAAO;EACH;EACA,cAAc,mBAAmB,IAAI;GAAC,KAAK;GAAkB,KAAK;GAAkB,KAAK;EAAgB,IAAI;GAAC;GAAG;GAAG;EAAC;CACzH;AACJ"}
@@ -1,3 +0,0 @@
1
- import * as THREE from "three";
2
- import { type KhrJointSpec } from "./khrTypes.js";
3
- export declare function decodeJoint(rawJoints: Array<Record<string, unknown>>, jointIdx: number, nodeName: string, connectedNode: THREE.Object3D, childNode: THREE.Object3D, enableCollision: boolean, role: string | null, connectedNodeName?: string): KhrJointSpec;
@@ -1,7 +0,0 @@
1
- import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
2
- import { KHR_BUNDLE_USERDATA_KEY, createHeadlessTexturePlugin, createKhrGltfPlugin } from "./khrPlugin.js";
3
- import { type KhrAssetBundle, type LoadKhrGlbOptions } from "./khrTypes.js";
4
- export * from "./khrTypes.js";
5
- export { KHR_BUNDLE_USERDATA_KEY, createHeadlessTexturePlugin, createKhrGltfPlugin };
6
- export declare function createDefaultGltfLoader(): GLTFLoader;
7
- export declare function loadKhrGlb(source: ArrayBuffer | Uint8Array, options?: LoadKhrGlbOptions): Promise<KhrAssetBundle>;
@@ -1,16 +0,0 @@
1
- import * as THREE from "three";
2
- import type { KhrBodySpec } from "./khrTypes.js";
3
- export type Vec3Tuple = [number, number, number];
4
- export type QuatTuple = [number, number, number, number];
5
- export interface LumpedMassProps {
6
- mass: number;
7
- com: Vec3Tuple;
8
- inertia: Vec3Tuple;
9
- inertiaFrame: QuatTuple;
10
- }
11
- export declare function bodyPoseMatrix(body: KhrBodySpec, target?: THREE.Matrix4): THREE.Matrix4;
12
- export declare function jacobiPrincipalInertia(ixx: number, iyy: number, izz: number, ixy: number, ixz: number, iyz: number): {
13
- inertia: Vec3Tuple;
14
- inertiaFrame: QuatTuple;
15
- };
16
- export declare function computeLumpedMassProps(bodies: readonly KhrBodySpec[], invFrame?: THREE.Matrix4): LumpedMassProps | null;
@@ -1,10 +0,0 @@
1
- import { assertIdentityWorldScale, assertSceneIdentityWorldScale, computeBodyInertia, computeRelativePose, computeShapeInertia, extractMeshColliderShape } from "./khrInertia.js";
2
- import { type KhrBodySpec } from "./khrTypes.js";
3
- export { GLB_BIN_CHUNK, GLB_JSON_CHUNK, GLB_MAGIC, parseGlbJson, validateGlbHeader, type RawGltfJson } from "./khrGlb.js";
4
- export { assertIdentityWorldScale, assertSceneIdentityWorldScale, computeBodyInertia, computeRelativePose, computeShapeInertia, extractMeshColliderShape };
5
- export { decodeJoint } from "./khrJointParser.js";
6
- export { decodePhysicsMaterial, decodeShape } from "./khrShapeParser.js";
7
- export declare function decodeMotion(motion: Record<string, unknown>, hasMotion: boolean, name: string): Omit<KhrBodySpec, "nodeName" | "localPosition" | "localQuaternion" | "colliders" | "joint" | "object" | "role"> & {
8
- hasExplicitInertia: boolean;
9
- };
10
- export declare function decodeCollisionGroups(rawFilters: Array<Record<string, unknown>>): number[];
@@ -1,8 +0,0 @@
1
- import type { GLTF, GLTFLoaderPlugin, GLTFParser } from "three/examples/jsm/loaders/GLTFLoader.js";
2
- import { applyKhrCustomExtractors } from "./khrExtras.js";
3
- import { createHeadlessTexturePlugin, isHeadlessTextureEnv } from "./khrPluginHelpers.js";
4
- import { type KhrAssetBundle, type KhrPluginOptions } from "./khrTypes.js";
5
- export declare const KHR_BUNDLE_USERDATA_KEY = "khrBundle";
6
- export { applyKhrCustomExtractors, createHeadlessTexturePlugin, isHeadlessTextureEnv };
7
- export declare function extractKhrBundleFromGltf(gltf: GLTF, options?: KhrPluginOptions): KhrAssetBundle;
8
- export declare function createKhrGltfPlugin(options?: KhrPluginOptions): (parser: GLTFParser) => GLTFLoaderPlugin;
@@ -1,26 +0,0 @@
1
- import * as THREE from "three";
2
- import type { GLTF, GLTFLoaderPlugin, GLTFParser } from "three/examples/jsm/loaders/GLTFLoader.js";
3
- import type { RawGltfJson } from "./khrGlb.js";
4
- import { type KhrColliderShape, type KhrImplicitShape } from "./khrTypes.js";
5
- export declare const isPlainObject: (v: unknown) => v is Record<string, unknown>;
6
- export declare function reqArr<T>(val: unknown, label: string): T[];
7
- export interface RawColliderDef {
8
- geometry?: {
9
- shape?: number;
10
- node?: number;
11
- convexHull?: boolean;
12
- };
13
- physicsMaterial?: number;
14
- collisionFilter?: number;
15
- }
16
- export declare const HEADLESS_TEXTURE_EXT_NAMES: readonly ["EXT_texture_webp", "EXT_texture_avif", "KHR_texture_basisu"];
17
- export declare function isHeadlessTextureEnv(): boolean;
18
- export declare function stubTextureInParser(parser: GLTFParser, textureIndex: number): Promise<THREE.Texture>;
19
- export declare function patchHeadlessTexturePlugins(parser: GLTFParser): void;
20
- export declare function createHeadlessTexturePlugin(): (parser: GLTFParser) => GLTFLoaderPlugin;
21
- export declare function buildNodeGraphLookup(gltf: GLTF, rawNodes: NonNullable<RawGltfJson["nodes"]>, rawGltf?: RawGltfJson | undefined): {
22
- parentIdx: Int32Array;
23
- nodeNames: string[];
24
- resolveObj: (idx: number) => THREE.Object3D | undefined;
25
- };
26
- export declare function resolveColliderShape(col: unknown, ownerName: string, shapes: readonly KhrImplicitShape[], nodeNames: readonly string[], resolveObj: (idx: number) => THREE.Object3D | undefined): KhrColliderShape;
@@ -1,4 +0,0 @@
1
- import * as THREE from "three";
2
- import { type EcctrlPropellerTag, type EcctrlWheelTag } from "./khrTypes.js";
3
- export declare function decodeWheelTag(obj: THREE.Object3D, name: string, rawWheel: unknown, scene?: THREE.Object3D, rawOmiWheel?: unknown): EcctrlWheelTag;
4
- export declare function decodePropellerTag(obj: THREE.Object3D, name: string, rawPropeller: unknown, scene?: THREE.Object3D): EcctrlPropellerTag;
@@ -1,8 +0,0 @@
1
- import { type KhrCombineMode, type KhrImplicitShape } from "./khrTypes.js";
2
- export declare function decodeShape(raw: Record<string, unknown>, idx: number): KhrImplicitShape;
3
- export declare function decodePhysicsMaterial(rawMaterials: Array<Record<string, unknown>>, idx: unknown, ownerName: string): {
4
- friction?: number;
5
- restitution?: number;
6
- frictionCombine?: KhrCombineMode;
7
- restitutionCombine?: KhrCombineMode;
8
- };
@@ -1,141 +0,0 @@
1
- import type * as THREE from "three";
2
- import type { KhrCarConfig, KhrDroneConfig } from "./khrConfigTypes.js";
3
- import type { EcctrlPropellerTag, EcctrlWheelTag, OmiVehicleWheelSpec } from "./khrVehicleTypes.js";
4
- export * from "./khrConfigTypes.js";
5
- export * from "./khrVehicleTypes.js";
6
- export type KhrCombineMode = "average" | "minimum" | "maximum" | "multiply";
7
- export type KhrImplicitShape = {
8
- type: "box";
9
- size: [number, number, number];
10
- } | {
11
- type: "sphere";
12
- radius: number;
13
- } | {
14
- type: "cylinder";
15
- height: number;
16
- radiusTop: number;
17
- radiusBottom: number;
18
- } | {
19
- type: "capsule";
20
- height: number;
21
- radiusTop: number;
22
- radiusBottom: number;
23
- };
24
- export type KhrColliderShape = KhrImplicitShape | {
25
- type: "convexHull";
26
- vertices: Float32Array;
27
- meshNodeName: string;
28
- } | {
29
- type: "trimesh";
30
- vertices: Float32Array;
31
- indices: Uint32Array;
32
- meshNodeName: string;
33
- };
34
- export interface KhrColliderSpec {
35
- shape: KhrColliderShape;
36
- localPosition: [number, number, number];
37
- localQuaternion: [number, number, number, number];
38
- friction?: number;
39
- restitution?: number;
40
- frictionCombine?: KhrCombineMode;
41
- restitutionCombine?: KhrCombineMode;
42
- collisionGroups?: number;
43
- }
44
- export interface KhrJointDriveSpec {
45
- type?: "linear" | "angular";
46
- mode: "force" | "acceleration";
47
- axis?: 0 | 1 | 2;
48
- positionTarget?: number;
49
- velocityTarget?: number;
50
- stiffness?: number;
51
- damping?: number;
52
- maxForce?: number;
53
- }
54
- export interface KhrJointSpec {
55
- index: number;
56
- nodeName: string;
57
- connectedNodeName: string;
58
- kind: "revolute" | "prismatic" | "fixed";
59
- axis: [number, number, number];
60
- limits: [number, number] | null;
61
- limitStiffness?: number;
62
- limitDamping?: number;
63
- enableCollision: boolean;
64
- drive: KhrJointDriveSpec | null;
65
- drives: KhrJointDriveSpec[];
66
- anchor1: [number, number, number];
67
- anchor2: [number, number, number];
68
- role: string | null;
69
- }
70
- export interface KhrBreakawaySpec {
71
- latchImpulseNs?: number;
72
- breakImpulseNs: number;
73
- }
74
- export interface KhrBodySpec {
75
- nodeName: string;
76
- isKinematic: boolean;
77
- mass: number;
78
- centerOfMass: [number, number, number];
79
- inertiaDiagonal: [number, number, number];
80
- inertiaOrientation: [number, number, number, number];
81
- linearVelocity?: [number, number, number];
82
- angularVelocity?: [number, number, number];
83
- gravityFactor?: number;
84
- localPosition: [number, number, number];
85
- localQuaternion: [number, number, number, number];
86
- colliders: KhrColliderSpec[];
87
- joint: KhrJointSpec | null;
88
- breakaway?: KhrBreakawaySpec;
89
- object: THREE.Object3D;
90
- role: string | null;
91
- }
92
- export interface KhrAssetBundle {
93
- scene: THREE.Group;
94
- bodies: KhrBodySpec[];
95
- wheels: EcctrlWheelTag[];
96
- propellers: EcctrlPropellerTag[];
97
- sockets: Record<string, [number, number, number]>;
98
- totalDynamicMass: number;
99
- centerOfMass: [number, number, number];
100
- tune?: Partial<KhrCarConfig>;
101
- droneTune?: Partial<KhrDroneConfig>;
102
- }
103
- export interface KhrExportNodeSpec {
104
- nodeName: string;
105
- motion?: {
106
- isKinematic?: boolean;
107
- mass?: number;
108
- centerOfMass?: [number, number, number];
109
- inertiaDiagonal?: [number, number, number];
110
- inertiaOrientation?: [number, number, number, number];
111
- linearVelocity?: [number, number, number];
112
- angularVelocity?: [number, number, number];
113
- gravityFactor?: number;
114
- };
115
- collider?: {
116
- shape?: KhrImplicitShape;
117
- meshNodeName?: string;
118
- convexHull?: boolean;
119
- friction?: number;
120
- restitution?: number;
121
- frictionCombine?: KhrCombineMode;
122
- restitutionCombine?: KhrCombineMode;
123
- collisionSystems?: string[];
124
- collideWithSystems?: string[];
125
- notCollideWithSystems?: string[];
126
- };
127
- joint?: {
128
- connectedNodeName: string;
129
- kind: "revolute" | "prismatic" | "fixed";
130
- axis?: [number, number, number];
131
- limits?: [number, number] | null;
132
- limitStiffness?: number;
133
- limitDamping?: number;
134
- enableCollision?: boolean;
135
- drive?: KhrJointDriveSpec | null;
136
- drives?: KhrJointDriveSpec[];
137
- };
138
- wheel?: OmiVehicleWheelSpec;
139
- extras?: Record<string, unknown>;
140
- extensions?: Record<string, unknown>;
141
- }
@@ -1,20 +0,0 @@
1
- import * as THREE from "three";
2
- import type { EcctrlVehicleProps } from "@pinkaphant/ecctrl/vehicle";
3
- import { type ColliderMass } from "./assemblyPlan.js";
4
- import { type LumpedMassProps, type QuatTuple, type Vec3Tuple } from "./khrMassProps.js";
5
- import { type KhrBodySpec, type KhrColliderSpec } from "./khrTypes.js";
6
- export declare function assertVehicleProps(scale: unknown, colliders: unknown): void;
7
- export declare function readPosTuple(pos: EcctrlVehicleProps["position"]): Vec3Tuple;
8
- export declare function readSpawnQuat(rotation: EcctrlVehicleProps["rotation"], quaternion: EcctrlVehicleProps["quaternion"]): QuatTuple;
9
- export interface ChassisMassSummary extends LumpedMassProps {
10
- linearVelocity?: Vec3Tuple;
11
- angularVelocity?: Vec3Tuple;
12
- gravityFactor?: number;
13
- }
14
- export declare function computeChassisMassProps(bodies: readonly KhrBodySpec[]): ChassisMassSummary;
15
- export declare function buildChassisColliders(bodies: readonly KhrBodySpec[], chassis: LumpedMassProps): Array<{
16
- key: string;
17
- spec: KhrColliderSpec;
18
- massProperties?: ColliderMass;
19
- }>;
20
- export declare function computeRotorLocalMatrix(node: THREE.Object3D, scene: THREE.Object3D, center: readonly [number, number, number], quaternion?: readonly [number, number, number, number]): THREE.Matrix4;
@@ -1,37 +0,0 @@
1
- import type RAPIER from "@dimforge/rapier3d-compat";
2
- import { type ColliderMass, type PlannedCollider } from "./assemblyPlan.js";
3
- import { type KhrBodySpec, type KhrJointSpec } from "./khrTypes.js";
4
- import type { JointRuntime } from "./physicsEcs.js";
5
- /** Membership group 1 (0x0002), filter ~0x0002 (0xfffd): collides with world/actors, never with sibling attached vehicle panels. */
6
- export declare const ATTACHED_PANEL_COLLISION_GROUPS = 196605;
7
- export declare const DETACHED_PANEL_COLLISION_GROUPS = 4294967295;
8
- type Vec3 = [number, number, number];
9
- type Quat = [number, number, number, number];
10
- export interface PlannedVehiclePart {
11
- spec: KhrBodySpec;
12
- joint: KhrJointSpec;
13
- parent: PlannedVehiclePart | null;
14
- restRelParentPos: Vec3;
15
- restRelParentQuat: Quat;
16
- restRelChassisPos: Vec3;
17
- restRelChassisQuat: Quat;
18
- axisParent: Vec3;
19
- axisChild: Vec3;
20
- partMass?: ColliderMass;
21
- colliders: PlannedCollider[];
22
- }
23
- export declare function planVehicleJointParts(bodies: readonly KhrBodySpec[]): PlannedVehiclePart[];
24
- export declare function openTargetForLimits(limits: readonly [number, number]): number;
25
- export declare function isVehicleJointOpen(rt: JointRuntime): boolean;
26
- export declare function shiftAttachedPanels(parts: readonly PlannedVehiclePart[], bodyMap: ReadonlyMap<string, RAPIER.RigidBody>, runtimeMap: ReadonlyMap<string, JointRuntime>, dx: number, dy: number, dz: number): void;
27
- export declare function syncAttachedPanelsToParent(parts: readonly PlannedVehiclePart[], bodyMap: ReadonlyMap<string, RAPIER.RigidBody>, runtimeMap: ReadonlyMap<string, JointRuntime>, parentBody: RAPIER.RigidBody | null): void;
28
- export declare function stepVehicleArticulatedPanels(params: {
29
- parts: readonly PlannedVehiclePart[];
30
- bodyMap: ReadonlyMap<string, RAPIER.RigidBody>;
31
- runtimeMap: ReadonlyMap<string, JointRuntime>;
32
- detachedCleared: WeakSet<RAPIER.RigidBody>;
33
- enableCustomGravity: boolean;
34
- timestep: number;
35
- applyGravityField?: (body: RAPIER.RigidBody, timeStep: number) => void;
36
- }): void;
37
- export {};
@@ -1,30 +0,0 @@
1
- import React from "react";
2
- import * as THREE from "three";
3
- import { type RapierRigidBody } from "@react-three/rapier";
4
- import type { EcctrlVehicleHandle } from "@pinkaphant/ecctrl/vehicle";
5
- import { type KhrBodySpec } from "./khrTypes.js";
6
- import { type JointRuntime } from "./physicsEcs.js";
7
- export interface KhrVehicleJointsHandle {
8
- readonly hasJoints: boolean;
9
- readonly jointNames: readonly string[];
10
- getBody: (nodeName: string) => RapierRigidBody | null;
11
- getJointRuntime: (nodeName: string) => JointRuntime | null;
12
- getJointAngle: (nodeName: string) => number | null;
13
- setJointTarget: (nodeName: string, target: number) => void;
14
- setRoleTarget: (role: string, target: number) => void;
15
- toggleHitObject: (hit: THREE.Object3D | null) => boolean;
16
- toggleRolePrefix: (prefix: string) => void;
17
- shiftBodies: (dx: number, dy: number, dz: number) => void;
18
- syncBodiesToParent: () => void;
19
- }
20
- export declare function KhrVehicleJoints({ bodies, vehicleRef, spawnPos, spawnQuat, enableCustomGravity, linearVelocity, angularVelocity, gravityScale, jointsRef, }: {
21
- bodies: readonly KhrBodySpec[];
22
- vehicleRef: React.RefObject<EcctrlVehicleHandle | null>;
23
- spawnPos: readonly [number, number, number];
24
- spawnQuat: readonly [number, number, number, number];
25
- enableCustomGravity?: boolean;
26
- linearVelocity?: [number, number, number];
27
- angularVelocity?: [number, number, number];
28
- gravityScale?: number;
29
- jointsRef?: React.Ref<KhrVehicleJointsHandle>;
30
- }): React.JSX.Element | null;
@@ -1,22 +0,0 @@
1
- import React from "react";
2
- import type * as THREE from "three";
3
- import { type ShapeCastWheelProps, type ThrustPropellerProps } from "@pinkaphant/ecctrl/vehicle";
4
- import type { EcctrlPropellerTag } from "./khrTypes.js";
5
- import { type RotorOrigin } from "./khrVehicleSlots.js";
6
- import type { SolvedWheel } from "./wheelLoads.js";
7
- export type KhrWheelConfig = Partial<Omit<ShapeCastWheelProps, "ref" | "key" | "children">>;
8
- export type KhrPropellerConfig = Partial<Omit<ThrustPropellerProps, "ref" | "key" | "children">>;
9
- export declare function KhrVehicleRotors({ solvedWheels, propellers, scene, comZ, rotorOrigins, enable, wheelEnable, wheelEpoch, wheelConfig, frontWheelConfig, rearWheelConfig, propellerConfig, }: {
10
- solvedWheels: readonly SolvedWheel[];
11
- propellers: readonly EcctrlPropellerTag[];
12
- scene: THREE.Group;
13
- comZ: number;
14
- rotorOrigins: ReadonlyMap<THREE.Object3D, RotorOrigin>;
15
- enable: boolean;
16
- wheelEnable: boolean;
17
- wheelEpoch?: number;
18
- wheelConfig?: KhrWheelConfig;
19
- frontWheelConfig?: KhrWheelConfig;
20
- rearWheelConfig?: KhrWheelConfig;
21
- propellerConfig?: KhrPropellerConfig;
22
- }): React.JSX.Element;