@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
package/dist/sand3d.d.ts DELETED
@@ -1,23 +0,0 @@
1
- import type { KhrAssetBundle } from "./khrTypes.js";
2
- import { assembly, exportTarget, joint, part, s3d, socket, thruster, wheel } from "./sand3d/sand3dCompiler.js";
3
- import { isSand3dFileName, parseSand3dSource } from "./sand3d/sand3dParser.js";
4
- import { buildSand3dRecipe, findSand3dRecipe, SAND3D_RECIPE_MAP, SAND3D_RECIPES } from "./sand3d/sand3dRecipes.js";
5
- import type { CompiledSand3dAssembly, Sand3dAssembly, Sand3dPartSpec, Sand3dRecipeId, Sand3dSolid, Sand3dUnits } from "./sand3d/sand3dTypes.js";
6
- export * from "./sand3d/sand3dTypes.js";
7
- export * from "./sand3d/sand3dProfiles.js";
8
- export * from "./sand3d/sand3dSolids.js";
9
- export * from "./sand3d/sand3dFramesAndEdits.js";
10
- export { assembly, buildSand3dRecipe, exportTarget, findSand3dRecipe, isSand3dFileName, joint, parseSand3dSource, part, s3d, SAND3D_RECIPE_MAP, SAND3D_RECIPES, socket, thruster, wheel, };
11
- export type Sand3dCompileInput = Sand3dAssembly | Sand3dPartSpec | Sand3dSolid | Sand3dRecipeId | string;
12
- /** Compiles a Sand3D assembly, solid, recipe ID, or script string into a Three.js scene and KHR specs. */
13
- export declare function compileSand3dAssembly(input: Sand3dCompileInput, opts?: {
14
- units?: Sand3dUnits;
15
- }): CompiledSand3dAssembly;
16
- /** Compiles and exports any Sand3D assembly, solid, recipe ID, or script string into binary .glb bytes. */
17
- export declare function exportSand3dGlb(input: Sand3dCompileInput, opts?: {
18
- units?: Sand3dUnits;
19
- }): Promise<Uint8Array>;
20
- /** Compiles, exports, and loads any Sand3D assembly, recipe ID, or script into a validated KhrAssetBundle. */
21
- export declare function loadSand3dBundle(input: Sand3dCompileInput, opts?: {
22
- units?: Sand3dUnits;
23
- }): Promise<KhrAssetBundle>;
package/dist/sand3d.js DELETED
@@ -1 +0,0 @@
1
- export { i as SAND3D_RECIPES, a as SAND3D_RECIPE_MAP, f as assembly, N as at, P as bend, S as box, o as buildSand3dRecipe, F as chamfer, X as circle, Z as cleanLoop2D, I as color, t as compileSand3dAssembly, C as cone, w as cylinder, T as dome, n as exportSand3dGlb, p as exportTarget, y as extrude, L as fillet, k as finalizeManifoldGeometry, s as findSand3dRecipe, R as grid, A as helix, K as hole, j as hull, c as isSand3dFileName, m as joint, r as loadSand3dBundle, b as loft, Q as ngon, z as on, l as parseSand3dSource, h as part, q as pocket, B as polar, $ as polygon, et as rect, J as resolveFaceFrame, x as revolve, V as rotate, u as s3d, d as sand3dUnitScale, Y as shell, tt as signedArea2D, nt as slot, g as socket, E as sphere, rt as star, it as subtractProfileHole, M as sweep, H as taper, _ as thruster, D as torus, U as translate, at as triangulateProfile2D, O as tube, W as twist, G as unionSolids, v as wheel } from "./sand3d-DQ8-OMlo.js";
@@ -1,383 +0,0 @@
1
- # `@khr3/core` API & Schema Reference
2
-
3
- `@khr3/core` (package overview and quick start in [README.md](../README.md)) implements `KHR_physics_rigid_bodies`, `KHR_implicit_shapes`, and `OMI_vehicle_wheel` glTF 2.0 binary `.glb` serialization and loading, multi-body Rapier `ImpulseJoint` assembly hosting (`<KhrAssembly>`), natural-origin `<KhrVehicle>` mounting over `@pinkaphant/ecctrl/vehicle`, monotone Pacejka curve compilation, and declarative `Sand3D` Code-CAD compilation (`@khr3/core/sand3d`).
4
-
5
- Four subpaths are published:
6
-
7
- - `@khr3/core` ([index.ts](../src/index.ts)) — `PhysicsWorld`, `KhrAssembly`, `KhrCollider`, `loadKhrGlb`, `createKhrGltfPlugin`, `useKhrGlb`, `exportKhrGlb`, `patchGlbJsonChunk`, `cloneKhrBundle`, `disposeKhrBundle`, `claimBundleMount`, `releaseBundleMount`, scale validators, `JointRegistryContext`, `KhrValidationError`, core `Sand3D` entrypoints, and the KHR and Sand3D TypeScript interfaces detailed below.
8
- - `@khr3/core/vehicle` ([vehicle.ts](../src/vehicle.ts)) — `KhrVehicle`, `solveWheelLoads`, `type KhrVehicleJointsHandle`, `type KhrVehicleProps`, `type KhrWheelConfig`, `type KhrPropellerConfig`, `type SolvedWheel`.
9
- - `@khr3/core/curves` ([curves.ts](../src/curves.ts)) — `compilePacejkaCurve`, `tireGripForSurface`, `engineHorsepowerForPeakTorque`, `TIRE_ARCHETYPES`, `TIRE_SLIP_CURVES`, `ENGINE_TORQUE_CURVES`, `STEER_SPEED_CURVES`, `type TireArchetypePreset`, `type CurveData`, `type CurvePoint`.
10
- - `@khr3/core/sand3d` ([sand3d.ts](../src/sand3d.ts)) — `s3d`, `SAND3D_RECIPES`, `SAND3D_RECIPE_MAP`, `findSand3dRecipe`, `buildSand3dRecipe`, `compileSand3dAssembly`, `exportSand3dGlb`, `loadSand3dBundle`, `parseSand3dSource`, `isSand3dFileName`, profile builders, solid builders, topological frames, cavity edits, and kinematic constructors.
11
-
12
- ---
13
-
14
- ## `@khr3/core`
15
-
16
- ### `<PhysicsWorld>` ([PhysicsWorld.tsx](../src/PhysicsWorld.tsx))
17
-
18
- Wraps `@react-three/rapier` `<Physics paused timeStep="vary">` with `@pinkaphant/ecctrl/time` `<TimeControl>` mounted after scene children so vehicle and joint impulses apply ahead of each `step(dt)`.
19
-
20
- | Prop | Type | Default | Description |
21
- | :--- | :--- | :--- | :--- |
22
- | `paused` | `boolean` | `false` | Holds simulation state stationary while true |
23
- | `timeScale` | `number \| RefObject<number>` | `1` | Scalar or live ref step multiplier |
24
- | `maxDelta` | `number \| RefObject<number>` | `1 / 30` | Frame delta upper bound applied ahead of `timeScale` |
25
- | `gravity` | `[number, number, number]` | `[0, -9.81, 0]` | World gravity vector forwarded to `<Physics>` |
26
- | `...physicsProps` | `Omit<PhysicsProps, ...>` | — | Additional props forwarded to `@react-three/rapier` `<Physics>` |
27
-
28
- ### `<KhrAssembly>` and `JointRegistryContext`
29
-
30
- Implemented across [KhrAssembly.tsx](../src/KhrAssembly.tsx), [AssemblyRootBody.tsx](../src/AssemblyRootBody.tsx), [BundleSceneHost.tsx](../src/BundleSceneHost.tsx), [assemblyPlan.ts](../src/assemblyPlan.ts), [jointDynamics.ts](../src/jointDynamics.ts), and [physicsEcs.ts](../src/physicsEcs.ts).
31
-
32
- Mounts a `KhrAssetBundle` into Rapier with one `<RigidBody>` per root body and an independent `<RigidBody>` per jointed child connected via a Rapier `ImpulseJoint` (`revolute`, `prismatic`, or `fixed` with motor drives and limits). `JointRegistryContext` (`Set<JointRuntime> | null`) is an opt-in registry (`null` by default, including inside `<PhysicsWorld>`); Rapier steps `ImpulseJoint` constraints natively and `KhrAssemblyHandle` / `KhrVehicleJointsHandle` (`jointsRef`) operate independently of a provider. Mounting `<JointRegistryContext.Provider value={set}>` registers active `JointRuntime` instances on mount and removes them on unmount.
33
-
34
- | Prop (`KhrAssemblyProps`) | Type | Default | Description |
35
- | :--- | :--- | :--- | :--- |
36
- | `bundle` | `KhrAssetBundle` | required | Validated KHR bundle at unit `[1, 1, 1]` world and local scale |
37
- | `position` | `[number, number, number]` | `[0, 0, 0]` | Root spawn position |
38
- | `rotation` | `[number, number, number]` | — | Root Euler rotation in radians |
39
- | `quaternion` | `[number, number, number, number]` | — | Root spawn quaternion |
40
- | `scale` | `ThreeElements["group"]["scale"]` | `1` | Enforced unit scale `1` |
41
- | `fixedRoot` | `boolean` | `false` | `false` mounts kinematic roots (`isKinematic: true`) as `"kinematicPosition"`; `true` mounts kinematic roots as `"fixed"`, while dynamic roots (`isKinematic: false`) mount as `"dynamic"` |
42
- | `rigidBodyProps` | `Omit<RigidBodyProps, ...>` | — | Props forwarded to root `<RigidBody>` |
43
- | `ref` | `React.Ref<KhrAssemblyHandle>` | — | Imperative assembly handle |
44
-
45
- ### `KhrAssemblyHandle`, `JointRuntime`, and `KhrBreakawaySpec`
46
-
47
- - `getBody(nodeName: string): RapierRigidBody | null` — retrieves the `<RigidBody>` handle for `nodeName`.
48
- - `setJointTarget(nodeName: string, target: number): void` — sets motor position target on one jointed node.
49
- - `setRoleTarget(role: string, target: number): void` — sets motor position target across jointed nodes matching `role`.
50
- - `KhrBreakawaySpec`: `{ latchImpulseNs?: number; breakImpulseNs: number }` — decoded from `node.extras.breakaway`. Contact impulses `>= latchImpulseNs` set `unlatched = true` and switch revolute and prismatic Rapier motors to `0` stiffness free-swing (`min(drive.damping ?? 1, 1.5)` damping) until `applyTarget(target)` restores `unlatched = false` and active drive stiffness; contact impulses `>= breakImpulseNs` remove the Rapier `ImpulseJoint` and set `detached = true`.
51
-
52
- Each active joint in `<KhrAssembly>` and `<KhrVehicle>` exposes the following `JointRuntime` record:
53
-
54
- | Member (`JointRuntime`) | Type | Description |
55
- | :--- | :--- | :--- |
56
- | `nodeName` / `role` | `string` / `string \| null` | Authored glTF node name and semantic role |
57
- | `kind` / `object` | `"revolute" \| "prismatic" \| "fixed"` / `THREE.Object3D` | Constraint kind and visual scene-graph node |
58
- | `axis` / `limits` | `THREE.Vector3` / `[number, number] \| null` | Normalized parent-frame joint axis and coordinate limits |
59
- | `drive` / `positionTarget` / `velocityTarget` | `KhrJointDriveSpec \| null` / `number \| null` / `number` | Authored drive spec and live motor targets |
60
- | `rapierJoint` / `parentBody` / `childBody` | `RAPIER.ImpulseJoint \| null` / `RAPIER.RigidBody \| null` / `RAPIER.RigidBody \| null` | Live Rapier constraint (`null` after breakaway) and connected rigid bodies |
61
- | `unlatched` / `detached` | `boolean` / `boolean` | Latch-release state (`>= latchImpulseNs`) and full breakaway state (`>= breakImpulseNs`) |
62
- | `getCoordinate()` | `() => number` | Measures current revolute angle (radians) or prismatic translation (meters) |
63
- | `applyTarget(target)` | `(target: number) => void` | Sets `positionTarget = target`, clears `unlatched = false`, reconfigures active drive stiffness, and wakes dynamic bodies |
64
- | `applyImpactImpulse(impulseNs)` | `(impulseNs: number) => "intact" \| "unlatched" \| "detached"` | Evaluates contact impulse against `latchImpulseNs` and `breakImpulseNs` |
65
-
66
- ### `<KhrCollider>` ([KhrCollider.tsx](../src/KhrCollider.tsx))
67
-
68
- Instantiates the Rapier collider matching a `KhrColliderSpec` (`box`, `sphere`, `cylinder`, `capsule`, `convexHull`, or `trimesh`), mapping `frictionCombine` and `restitutionCombine` onto Rapier `CoefficientCombineRule` values and flushing parent body mass properties immediately on mount.
69
-
70
- | Prop (`KhrColliderProps`) | Type | Default | Description |
71
- | :--- | :--- | :--- | :--- |
72
- | `c` | `KhrColliderSpec` | required | Decoded KHR shape, local pose, friction, restitution, and filter groups |
73
- | `position` | `[number, number, number]` | `c.localPosition` | Pose override in the parent `RigidBody` frame |
74
- | `quaternion` | `[number, number, number, number]` | `c.localQuaternion` | Orientation override in the parent `RigidBody` frame |
75
- | `massProperties` | `ColliderMass` | `{ density: 0 }` | Declarative `{ mass, centerOfMass, principalAngularInertia, angularInertiaLocalFrame }` |
76
- | `ref` | `React.Ref<RapierCollider>` | — | Imperative Rapier collider reference |
77
-
78
- ### Export, Load, and Bundle Schemas
79
-
80
- Implemented across [khrExporter.ts](../src/khrExporter.ts), [khrExportEncoders.ts](../src/khrExportEncoders.ts), [khrGlb.ts](../src/khrGlb.ts), [khrLoader.ts](../src/khrLoader.ts), [khrPlugin.ts](../src/khrPlugin.ts), [khrPluginHelpers.ts](../src/khrPluginHelpers.ts), [khrBundleFinalize.ts](../src/khrBundleFinalize.ts), [khrParsers.ts](../src/khrParsers.ts), [khrShapeParser.ts](../src/khrShapeParser.ts), [khrJointParser.ts](../src/khrJointParser.ts), [khrRotorDecoders.ts](../src/khrRotorDecoders.ts), [khrExtras.ts](../src/khrExtras.ts), [useKhrGlb.ts](../src/useKhrGlb.ts), [khrClone.ts](../src/khrClone.ts), [khrInertia.ts](../src/khrInertia.ts), [khrMassProps.ts](../src/khrMassProps.ts), [khrTypes.ts](../src/khrTypes.ts), [khrConfigTypes.ts](../src/khrConfigTypes.ts), and [khrVehicleTypes.ts](../src/khrVehicleTypes.ts).
81
-
82
- - `exportKhrGlb(root, specs, sceneExtras?): Promise<ArrayBuffer>` — serializes `root` through `GLTFExporter` and writes `KHR_implicit_shapes`, `KHR_physics_rigid_bodies`, `OMI_vehicle_wheel`, custom `extensions`, and `sceneExtras` into a 4-byte-aligned binary GLB.
83
- - `patchGlbJsonChunk(source, mutator): ArrayBuffer` — mutates a GLB JSON chunk in memory while preserving its binary buffer chunk.
84
- - `loadKhrGlb(source, options?): Promise<KhrAssetBundle>` — parses and validates a binary GLB into a `KhrAssetBundle`, cloning each node's `extensions.KOLMO_emitter` payload onto `object.userData.KOLMO_emitter` and resolving `ikSockets`, `tune`, and `droneTune` from `scene.extras` with fallback to root `gltf.extras`.
85
- - `createKhrGltfPlugin(options?)` and `useKhrGlb(url, options?)` — `GLTFLoader` plugin factory and Suspense-cached React Three Fiber hook.
86
- - `cloneKhrBundle`, `claimBundleMount`, `releaseBundleMount`, `disposeKhrBundle` — scene-graph cloning and mount ownership utilities; `disposeKhrBundle(clone)` retires clone mount ownership while preserving shared template GPU resources, whereas `disposeKhrBundle(template)` on a root `loadKhrGlb` or `loadSand3dBundle` bundle disposes unique GPU geometries, materials, and textures once.
87
- - `assertUnitScale`, `assertIdentityWorldScale`, `assertSceneIdentityWorldScale` — unit `[1, 1, 1]` scale validators throwing `KhrValidationError` on scaled transforms.
88
-
89
- `exportKhrGlb` accepts an array of `KhrExportNodeSpec` descriptors (with joint drives typed as `KhrJointDriveSpec: { type?: "linear" | "angular"; mode: "force" | "acceleration"; axis?: 0 | 1 | 2; positionTarget?: number; velocityTarget?: number; stiffness?: number; damping?: number; maxForce?: number }`):
90
-
91
- | Field (`KhrExportNodeSpec`) | Type | Description |
92
- | :--- | :--- | :--- |
93
- | `nodeName` | `string` | Unique glTF node name in `root` targeted by this specification (identifies the jointed child node when `joint` is set) |
94
- | `motion` | `{ isKinematic?, mass?, centerOfMass?, inertiaDiagonal?, inertiaOrientation?, linearVelocity?, angularVelocity?, gravityFactor? }` | Rigid-body motion record written to `KHR_physics_rigid_bodies.motion` |
95
- | `collider` | `{ shape?, meshNodeName?, convexHull?, friction?, restitution?, frictionCombine?, restitutionCombine?, collisionSystems?, collideWithSystems?, notCollideWithSystems? }` | Analytic `KHR_implicit_shapes` or mesh-referenced collider plus material and collision filter lists |
96
- | `joint` | `{ connectedNodeName: string; kind: "revolute" \| "prismatic" \| "fixed"; axis?; limits?; limitStiffness?; limitDamping?; enableCollision?; drive?; drives? }` | Constrains child `nodeName` to parent `connectedNodeName`; pivot anchors (`anchor1` in parent local space, `anchor2 = [0, 0, 0]` at the child origin) derive from `nodeName`'s local transform on `root`, `axis` is expressed in the child node's local coordinate frame, singular `drive` configures the primary joint axis, and `drives` (`KhrJointDriveSpec[]`) configures multi-axis 6-DOF drives |
97
- | `wheel` | `OmiVehicleWheelSpec` | Explicit `OMI_vehicle_wheel` descriptor (auto-synthesized from `extras.ecctrlWheel` if omitted) |
98
- | `extras` | `Record<string, unknown>` | Node metadata including `breakaway`, `isIkAnchor`, `socketId`, `contactDots` (`Array<{ role: string; pos: [number, number, number] }>` transformed into scene-space `bundle.sockets[role]`), `role`, `ecctrlWheel`, and `ecctrlPropeller` |
99
- | `extensions` | `Record<string, unknown>` | Custom node-level glTF extensions such as `KOLMO_emitter` merged into `extensionsUsed` |
100
-
101
- `loadKhrGlb`, `useKhrGlb`, `cloneKhrBundle`, and `loadSand3dBundle` return a `KhrAssetBundle` with the following fields:
102
-
103
- | Field (`KhrAssetBundle`) | Type | Description |
104
- | :--- | :--- | :--- |
105
- | `scene` | `THREE.Group` | Unit-scale root scene hierarchy (with `node.extensions.KOLMO_emitter` cloned onto `node.userData.KOLMO_emitter`) |
106
- | `bodies` | `KhrBodySpec[]` | Rigid bodies decoded from `KHR_physics_rigid_bodies`: `{ nodeName, isKinematic, mass, centerOfMass, inertiaDiagonal, inertiaOrientation, linearVelocity?, angularVelocity?, gravityFactor?, localPosition, localQuaternion, colliders, joint, breakaway?, object, role }` |
107
- | `wheels` | `EcctrlWheelTag[]` | Decoded `OMI_vehicle_wheel` and `extras.ecctrlWheel` suspension records |
108
- | `propellers` | `EcctrlPropellerTag[]` | Decoded `extras.ecctrlPropeller` thrust records |
109
- | `sockets` | `Record<string, [number, number, number]>` | Scene-space coordinates merged in order (later entries overwrite matching keys): node traversal (`isSocketNode` string return, then `extras.socketId`, then `node.name` when `extras.isIkAnchor === true` or boolean `isSocketNode` returns `true`, followed by each node's `extras.contactDots` roles), then `scene.extras.ikSockets` (with fallback to `gltf.extras.ikSockets`) |
110
- | `totalDynamicMass` | `number` | Sum of dynamic `KhrBodySpec.mass` values in kilograms |
111
- | `centerOfMass` | `[number, number, number]` | Mass-weighted composite dynamic center of mass in scene coordinates |
112
- | `tune` | `Partial<KhrCarConfig>` | Optional ground-vehicle tuning resolved from `scene.extras.tune` with fallback to `gltf.extras.tune` |
113
- | `droneTune` | `Partial<KhrDroneConfig>` | Optional flight tuning resolved from `scene.extras.droneTune` with fallback to `gltf.extras.droneTune` |
114
-
115
- ### Wheel, Propeller, and Tuning Interfaces
116
-
117
- Defined in [khrVehicleTypes.ts](../src/khrVehicleTypes.ts) and [khrConfigTypes.ts](../src/khrConfigTypes.ts):
118
-
119
- ```ts
120
- export interface KhrCurvePoint {
121
- x: number;
122
- y: number;
123
- r_in?: number;
124
- r_out?: number;
125
- w_in?: number;
126
- w_out?: number;
127
- }
128
-
129
- export interface KhrCurveData {
130
- points: KhrCurvePoint[];
131
- samples?: number;
132
- }
133
-
134
- export interface OmiVehicleWheelSpec {
135
- radius: number;
136
- width: number;
137
- maxForce?: number;
138
- steering?: boolean;
139
- propulsion?: boolean;
140
- maxSteeringAngle?: number;
141
- suspensionStiffness?: number;
142
- suspensionDampingCompression?: number;
143
- suspensionDampingRebound?: number;
144
- suspensionTravel?: number;
145
- }
146
-
147
- export interface EcctrlWheelTag {
148
- nodeName: string;
149
- object: THREE.Object3D;
150
- position: [number, number, number];
151
- quaternion?: [number, number, number, number];
152
- radius: number;
153
- width: number;
154
- steer: boolean;
155
- steerInvert?: boolean;
156
- drive: boolean;
157
- driveInvert?: boolean;
158
- brake: boolean;
159
- travel: number;
160
- sag: number;
161
- springK?: number;
162
- dampingC?: number;
163
- maxBrakeTorque?: number;
164
- maxSteeringAngle?: number;
165
- rollingResistanceCoef?: number;
166
- wheelDensity?: number;
167
- driveTorqueWeight?: number;
168
- tireGripFactor?: number;
169
- latFrictionEllipseScale?: number;
170
- relaxLngRate?: number;
171
- relaxLatRate?: number;
172
- lngSlipRatioCurveData?: KhrCurveData;
173
- latSlipRatioCurveData?: KhrCurveData;
174
- }
175
-
176
- export interface EcctrlPropellerTag {
177
- nodeName: string;
178
- object: THREE.Object3D;
179
- position: [number, number, number];
180
- quaternion?: [number, number, number, number];
181
- maxThrust: number;
182
- torqueRatio?: number;
183
- invertThrust?: boolean;
184
- invertTorque?: boolean;
185
- }
186
-
187
- export interface KhrCarConfig {
188
- controlMode?: "VELOCITY" | "POSITION";
189
- engineHorsepower?: number;
190
- engineMaxRPM?: number;
191
- gearRatios?: number[];
192
- finalDriveRatio?: number;
193
- transmissionMode?: "auto" | "manual";
194
- shiftUpRPM?: number;
195
- shiftDownRPM?: number;
196
- shiftCooldown?: number;
197
- steerRate?: number;
198
- maxSteerAngle?: number;
199
- reverseTorqueScale?: number;
200
- reverseRPMScale?: number;
201
- engineTorqueCurveData?: KhrCurveData;
202
- steerAngleCurveData?: KhrCurveData;
203
- }
204
-
205
- export interface KhrDroneConfig {
206
- controlMode?: "VELOCITY" | "POSITION";
207
- maxYawRate?: number;
208
- maxHorizSpeed?: number;
209
- maxVertSpeed?: number;
210
- maxTiltAngle?: number;
211
- airDragFactor?: number;
212
- TILT_P?: number;
213
- TILT_D?: number;
214
- YAW_POS_P?: number;
215
- YAW_VEL_P?: number;
216
- VERT_POS_P?: number;
217
- VERT_POS_D?: number;
218
- HORIZ_POS_P?: number;
219
- HORIZ_POS_D?: number;
220
- HORIZ_VEL_P?: number;
221
- VERT_VEL_P?: number;
222
- }
223
- ```
224
-
225
- ---
226
-
227
- ## `@khr3/core/vehicle`
228
-
229
- Implemented across [vehicle.ts](../src/vehicle.ts), [KhrVehicle.tsx](../src/KhrVehicle.tsx), [khrVehicleChassis.ts](../src/khrVehicleChassis.ts), [khrVehicleJointHelpers.ts](../src/khrVehicleJointHelpers.ts), [khrVehicleJoints.tsx](../src/khrVehicleJoints.tsx), [khrVehicleRotors.tsx](../src/khrVehicleRotors.tsx), [khrVehicleSlots.tsx](../src/khrVehicleSlots.tsx), and [wheelLoads.ts](../src/wheelLoads.ts).
230
-
231
- ### `<KhrVehicle>` and Rotor Mounting
232
-
233
- `<KhrVehicle>` mounts a vehicle or craft `KhrAssetBundle` inside `@pinkaphant/ecctrl/vehicle` `<EcctrlVehicle>` in a right-handed `+Z` forward, `+Y` up, `+X` left coordinate frame while preserving the scene origin `[0, 0, 0]` and supplying composite chassis `massProperties` via `<KhrCollider>`. `<KhrVehicle>` partitions `frontWheelConfig` (`mountPos[2] >= chassis.com[2]`) and `rearWheelConfig` (`mountPos[2] < chassis.com[2]`) against the composite chassis root `chassis.com[2]`, while calling `solveWheelLoads` against `bundle.totalDynamicMass` and `bundle.centerOfMass`.
234
-
235
- - **Rotor Mounting ([khrVehicleRotors.tsx](../src/khrVehicleRotors.tsx))**: `KhrVehicleRotors` instantiates `@pinkaphant/ecctrl/vehicle` `<ShapeCastWheel>` (cylinder-cast suspension actuator parameterized by `rayLength`, `rayShapeR`, `rayShapeH`, `springK`, `dampingC`, and Pacejka slip curves) and `<ThrustPropeller>` components, each wrapping `<RotorVisualSlot>` children.
236
- - **Microgravity Gating & Visual Slots ([khrVehicleSlots.tsx](../src/khrVehicleSlots.tsx))**: Exports `ZeroGWheelGate` and `ZeroGWheelPostClear` (gating `<ShapeCastWheel>` forces in microgravity or `enableCustomGravity` worlds and incrementing `wheelEpoch` upon gravity restoration), `RotorVisualSlot` (reparenting wheel and propeller `THREE.Object3D` subtrees into live rotor groups), `captureRotorOrigins`, and disabled-rotor state reset helpers (`resetAllWheelHits`, `resetDisabledWheelHits`, `resetAllPropellerOutputs`, `resetDisabledRotors`).
237
- - **Wheel Load Solver ([wheelLoads.ts](../src/wheelLoads.ts))**: `solveWheelLoads(wheels, totalMassKg, com, dampingRatio = 0.7): SolvedWheel[]` solves static-equilibrium corner masses for `N >= 1` wheels around `com` and returns `SolvedWheel` records (`{ tag, cornerMassKg, springK, dampingC, mountPos }`), where `springK = tag.springK ?? (cornerMassKg * 9.81) / Math.max(tag.sag, 1e-4)`, `dampingC = tag.dampingC ?? 2 * dampingRatio * Math.sqrt(springK * cornerMassKg)`, and `mountPos` adds local `+Y` suspension lift `[0, Math.max(0, tag.travel - tag.sag), 0]` (rotated by `tag.quaternion` when present) to `tag.position`.
238
-
239
- | Prop (`KhrVehicleProps`) | Type | Default | Description |
240
- | :--- | :--- | :--- | :--- |
241
- | `bundle` | `KhrAssetBundle` | required | Cloned or loaded KHR vehicle/craft bundle at unit `[1, 1, 1]` scale |
242
- | `position` | `EcctrlVehicleProps["position"]` | `[0, 0.5, 0]` | Chassis spawn position in world space |
243
- | `ref` | `React.Ref<EcctrlVehicleHandle>` | — | Forwarded React ref receiving the `<EcctrlVehicle>` controller handle |
244
- | `vehicleRef` | `React.RefObject<EcctrlVehicleHandle \| null>` | — | Mutable ref object synchronized alongside `ref` |
245
- | `jointsRef` | `React.Ref<KhrVehicleJointsHandle>` | — | Imperative handle for articulated doors, hoods, canopies, and breakaway parts |
246
- | `enable` | `boolean` | `true` | Enables `<EcctrlVehicle>` input, wheels, and propellers |
247
- | `enableCustomGravity` | `boolean` | `false` | Activates external gravity field mode and microgravity wheel gating |
248
- | `carConfig` | `Partial<KhrCarConfig>` | `bundle.tune` | Overrides merged over `bundle.tune` and `OMI_vehicle_wheel.maxSteeringAngle` |
249
- | `droneConfig` | `Partial<KhrDroneConfig>` | `bundle.droneTune` | Overrides merged over `bundle.droneTune` |
250
- | `wheelConfig` | `KhrWheelConfig` | — | `Partial<Omit<ShapeCastWheelProps, "ref" \| "key" \| "children">>` applied to every wheel |
251
- | `frontWheelConfig` | `KhrWheelConfig` | — | Overrides applied to wheels with `mountPos[2] >= chassis.com[2]` |
252
- | `rearWheelConfig` | `KhrWheelConfig` | — | Overrides applied to wheels with `mountPos[2] < chassis.com[2]` |
253
- | `propellerConfig` | `KhrPropellerConfig` | — | `Partial<Omit<ThrustPropellerProps, "ref" \| "key" \| "children">>` applied to every propeller |
254
- | `...ecctrlRest` | `Omit<EcctrlVehicleProps, ...>` | — | Rotation, quaternion, velocities, `gravityScale`, and `<EcctrlVehicle>` props |
255
-
256
- ### `KhrVehicleJointsHandle` ([khrVehicleJoints.tsx](../src/khrVehicleJoints.tsx))
257
-
258
- Imperative handle exposed via `<KhrVehicle jointsRef={...} />` for articulated vehicle panels and breakaway parts:
259
-
260
- | Member | Type | Description |
261
- | :--- | :--- | :--- |
262
- | `hasJoints` | `readonly boolean` | True if `bundle.bodies` includes articulated child panels |
263
- | `jointNames` | `readonly string[]` | Ordered `nodeName` list of articulated vehicle parts |
264
- | `getBody(nodeName)` | `(nodeName: string) => RapierRigidBody \| null` | Returns the child `<RigidBody>` handle for `nodeName` |
265
- | `getJointRuntime(nodeName)` | `(nodeName: string) => JointRuntime \| null` | Returns the active `JointRuntime` state for `nodeName` |
266
- | `getJointAngle(nodeName)` | `(nodeName: string) => number \| null` | Reads the current joint coordinate (radians or meters) |
267
- | `setJointTarget(nodeName, target)` | `(nodeName: string, target: number) => void` | Sets motor position target on one vehicle joint |
268
- | `setRoleTarget(role, target)` | `(role: string, target: number) => void` | Sets motor position target across vehicle joints matching `role` |
269
- | `toggleHitObject(hit)` | `(hit: THREE.Object3D \| null) => boolean` | Walks ancestors of a raycast hit mesh and toggles the enclosing driven joint between `0` and its open limit |
270
- | `toggleRolePrefix(prefix)` | `(prefix: string) => void` | Toggles driven joints whose `role` or `nodeName` starts with `prefix` (case-insensitive) |
271
- | `shiftBodies(dx, dy, dz)` | `(dx: number, dy: number, dz: number) => void` | Shifts attached dynamic panel `<RigidBody>` positions across floating-origin rebases |
272
- | `syncBodiesToParent()` | `() => void` | Synchronizes attached panel `<RigidBody>` transforms and velocities to the parent chassis after teleports or upright resets |
273
-
274
- ---
275
-
276
- ## `@khr3/core/curves`
277
-
278
- Implemented across [curves.ts](../src/curves.ts) and [pacejka.ts](../src/pacejka.ts).
279
-
280
- ### Pacejka Curve Compiler and Presets
281
-
282
- - `compilePacejkaCurve(B, C, E, samples = 100, axis = "lng"): CurveData` — evaluates the Pacejka Magic Formula `phi(u) = B * u - E * (B * u - atan(B * u))` and `yRaw(u) = sin(C * atan(phi(u)))`, normalizing by the peak over `x in [0, 1]` into an 8-knot Fritsch–Carlson monotone cubic Hermite `CurveData` (`{ points: CurvePoint[]; samples?: number }`).
283
- - `axis: "lng"` evaluates `u = x` matching `<ShapeCastWheel>` longitudinal slip ratio `|w * R - vx| / |vx|`.
284
- - `axis: "lat"` evaluates `u = sin((pi / 2) * x)` matching `<ShapeCastWheel>` normalized lateral slip angle `atan2(|vy|, |vx|) / (pi / 2)`.
285
- - Each `CurvePoint` (`{ x, y, r_in?, r_out?, w_in?, w_out? }`) encodes Fritsch–Carlson monotone slopes as clamped radian tangent angles `atan(dy / dx)` in `[-1.54, 1.54]` on `r_in` and `r_out` with unit tangent weights `1` (`w_in = 1`, `w_out = 1`).
286
- - `tireGripForSurface(muPeakLng, groundColliderFriction = 0.5): number` — scales unit-peak Pacejka curves to physical peak longitudinal friction `muPeakLng` via `2 * muPeakLng - groundColliderFriction`, matching `<ShapeCastWheel>` `(rayHitFriction + tireGripFactor) * 0.5`.
287
- - `engineHorsepowerForPeakTorque(peakTorqueNm, engineMaxRPM): number` — converts physical peak torque (`N*m`) into `carConfig.engineHorsepower` (`peakTorqueNm * engineMaxRPM / 7022`).
288
- - Exported types and presets: `type CurvePoint`, `type CurveData`, `type TireArchetypePreset`, `TIRE_ARCHETYPES` (`hypercarDry`, `streetDrift90s`, `offroad6x6At`, `gravelRally`, `wetAsphalt`, `snowIce`), `TIRE_SLIP_CURVES` (`streetRadial`, `driftProgressive`, `offroadLug`), `ENGINE_TORQUE_CURVES` (`w16QuadTurbo`, `naScreamer`, `heavyTurboDiesel`, `evDirectDrive`), and `STEER_SPEED_CURVES` (`progressiveHighway`, `driftCountersteer`, `evSingleGearGt`, `heavy6x6AntiRollover`).
289
-
290
- ---
291
-
292
- ## `@khr3/core/sand3d`
293
-
294
- Implemented across [sand3d.ts](../src/sand3d.ts), [sand3dTypes.ts](../src/sand3d/sand3dTypes.ts), [sand3dProfiles.ts](../src/sand3d/sand3dProfiles.ts), [sand3dSolids.ts](../src/sand3d/sand3dSolids.ts), [sand3dPrimitives.ts](../src/sand3d/sand3dPrimitives.ts), [sand3dHullAndSweep.ts](../src/sand3d/sand3dHullAndSweep.ts), [sand3dFramesAndEdits.ts](../src/sand3d/sand3dFramesAndEdits.ts), [sand3dCavityOps.ts](../src/sand3d/sand3dCavityOps.ts), [sand3dShellOp.ts](../src/sand3d/sand3dShellOp.ts), [sand3dCompiler.ts](../src/sand3d/sand3dCompiler.ts), [sand3dAssemblyHelpers.ts](../src/sand3d/sand3dAssemblyHelpers.ts), [sand3dTokenizer.ts](../src/sand3d/sand3dTokenizer.ts), [sand3dParser.ts](../src/sand3d/sand3dParser.ts), [sand3dEvaluator.ts](../src/sand3d/sand3dEvaluator.ts), and [sand3dRecipes.ts](../src/sand3d/sand3dRecipes.ts).
295
-
296
- ### Fluent `s3d` Namespace and Builders
297
-
298
- - **2D Profiles ([sand3dProfiles.ts](../src/sand3d/sand3dProfiles.ts))**: `rect(w, d, { r, chamfer, segments, center })`, `circle(diameter, segmentsOrOpts = 24, center = [0, 0])`, `ngon(sides, radius, startOrOpts = 0, center = [0, 0])`, `star(points, rOuter, rInner, startOrOpts = 0, center = [0, 0])`, `slot(length, width, segmentsOrOpts = 16, center = [0, 0])`, `polygon(pts, holes)`, `subtractProfileHole(profile, hole, offset = [0, 0])`, and `triangulateProfile2D(profile)` (mutual-visibility hole bridging plus ear clipping).
299
- - **Manifold 3D Solids ([sand3dSolids.ts](../src/sand3d/sand3dSolids.ts), [sand3dPrimitives.ts](../src/sand3d/sand3dPrimitives.ts), [sand3dHullAndSweep.ts](../src/sand3d/sand3dHullAndSweep.ts))**: `extrude(profile, height, opts)`, `revolve(profile, angleDeg = 360, segments = 24, opts)`, `loft(profiles, heights, opts)`, `sweep(profile, path, opts)` (Bishop parallel-transport frames), `helix(profile, { radius, pitch, turns, segmentsPerTurn, name, color })`, `box(w, h, d, opts)`, `cylinder(diameter, height, opts)`, `tube(outerDiameter, innerDiameter, height, opts)`, `cone(diameterBottom, diameterTop, height, opts)`, `sphere(diameter, opts)`, `dome(diameter, heightOrOpts, opts)`, `torus(majorDiameter, tubeDiameter, opts)`, and `hull(pointsOrSolids, opts)` (3D incremental convex hull). 2D-to-3D axis mapping: `extrude` and `loft` map 2D `[u, v]` profile coordinates onto `[X, Z]` and sweep along `+Y`, while `revolve` sweeps `[radius, y]` around `+Y`.
300
- - **Topological Frames, Deformations, and Cavity Edits ([sand3dFramesAndEdits.ts](../src/sand3d/sand3dFramesAndEdits.ts), [sand3dCavityOps.ts](../src/sand3d/sand3dCavityOps.ts), [sand3dShellOp.ts](../src/sand3d/sand3dShellOp.ts))**: `grid(nx, ny, pitchX, pitchY = pitchX, center = [0, 0])`, `polar(count, radius, startDeg = 0, spanDeg = 360)`, `at(origin, rotDeg = [0, 0, 0])`, `on(target, selector = "top", offset = [0, 0, 0])` (`"top"`, `"bottom"`, `"front"`, `"back"`, `"left"`, `"right"`, `"+X"`, `"-X"`, `"+Y"`, `"-Y"`, `"+Z"`, `"-Z"`, and corner selectors such as `"+X-Y+Z"`), `hole(solid, diameter, { depth, on, face, segments })` (through and blind cylindrical bores defaulting to `face = "top"` `+Y` with re-triangulated planar cap rings), `pocket(solid, profile, depth, { on, face })` (defaulting to `face = "top"` `+Y`), `shell(solid, thickness, { openFace })`, `chamfer(solid, distance)`, `fillet(solid, radius)`, `taper(solid, factor, axis = "Y")`, `twist(solid, angleDeg, axis = "Y")`, `bend(solid, angleDeg, axis = "X")`, `color(solid, shade, { roughness, metalness, opacity })`, `translate(solid, offset)`, `rotate(solid, rotDeg)`, and `unionSolids(solids, name = "union", shade)`.
301
- - **Low-Level Helpers and Types**: `@khr3/core/sand3d` also exports `sand3dUnitScale`, `signedArea2D`, `cleanLoop2D`, `finalizeManifoldGeometry`, `resolveFaceFrame`, `type Vec2`, `type Vec3`, `type Quat4`, `type Sand3dPartOpts`, `type Sand3dEmitterKind`, and `type Sand3dNodeItem`.
302
-
303
- ### Kinematic Assembly, Colliders, and `KOLMO_emitter`
304
-
305
- Implemented in [sand3dCompiler.ts](../src/sand3d/sand3dCompiler.ts) and [sand3dAssemblyHelpers.ts](../src/sand3d/sand3dAssemblyHelpers.ts):
306
-
307
- - `s3d.part(name, solid, opts)` — places a rigid-body part with mass, density, material color, role, breakaway thresholds, and collider selection: centered `box`, `sphere`, and `cylinder` solids emit analytic `KHR_implicit_shapes` (`{ type: "box", size }`, `{ type: "sphere", radius }`, `{ type: "cylinder", height, radiusTop, radiusBottom }`), while `"hull"` or off-center solids emit mesh-referenced `convexHull` colliders.
308
- - `s3d.joint(kind, parent, child, opts)` — authors `revolute`, `prismatic`, or `fixed` `KHR_physics_rigid_bodies` constraints with pivot `anchor`, `axis`, `limits`/`range`, `stiffness`, `damping`, `positionTarget`, `velocityTarget`, `latchImpulseNs`, and `breakImpulseNs`.
309
- - `s3d.wheel(name, opts)` — emits `OMI_vehicle_wheel` and `extras.ecctrlWheel` suspension metadata with Pacejka slip curves.
310
- - `s3d.thruster(name, opts)` and `s3d.socket(name, position, opts)` — emit `extras.ecctrlPropeller`, `socketId` / `isIkAnchor` nodes, and canonical `KOLMO_emitter` node extensions:
311
- - `kind`: `"plume" | "sparkle" | "fume" | "trail" | "flare"` (authoring `"muzzle"` normalizes to `kind: "flare"`, `drive: "fire"`, `socket: "muzzle"`).
312
- - `drive`: `"throttle" | "boost" | "brake" | "slip" | "reverse" | "turn_l" | "turn_r" | "headlight" | "fire" | "damage" | "always"` (11 supported channels).
313
- - `color`: `[r, g, b]` linear RGB tuple with components in `[0, 1]`; `size`: positive scalar defaulting to `0.34` on thrusters and `s3d.socket` emitters.
314
- - `compileSand3dAssembly(input, opts): CompiledSand3dAssembly` — returns `{ scene, specs, sceneExtras, assembly }`, scaling `"mm"` coordinates by `0.001` into unit-scale SI meter geometry.
315
- - `exportSand3dGlb(input, opts): Promise<Uint8Array>` and `loadSand3dBundle(input, opts): Promise<KhrAssetBundle>`.
316
-
317
- ### Script Parser, `.s3d.json` Manifests, and Recipes
318
-
319
- Implemented in [sand3dTokenizer.ts](../src/sand3d/sand3dTokenizer.ts), [sand3dParser.ts](../src/sand3d/sand3dParser.ts), [sand3dEvaluator.ts](../src/sand3d/sand3dEvaluator.ts), and [sand3dRecipes.ts](../src/sand3d/sand3dRecipes.ts):
320
-
321
- - `isSand3dFileName(fileName)` and `parseSand3dSource(source, opts): Sand3dAssembly` — parses `.sand3d`, `.s3d`, `.s3d.py`, `.s3d.ts`, and `.s3d.json` sources. In Python-style `.sand3d` scripts, `snake_case` keyword arguments (`mass_kg`, `density_kg_m3`, `break_impulse_ns`, `latch_impulse_ns`, `max_thrust`, `plume_color`, `open_face`, `twist_deg`) map to `camelCase` builder options (`massKg`, `densityKgM3`, `breakImpulseNs`, `latchImpulseNs`, `maxThrust`, `plumeColor`, `openFace`, `twistDeg`), and `s3d.export(...)` registers the root solid, part, or assembly. `.s3d.json` manifests accept top-level keys `name`, `units` (`"mm" | "m"`), `parts`, `joints`, `wheels`, `thrusters`, and `sockets` (plus optional `carTune`, `droneTune`, and `extras`), forwarding `centered: true` and `collider` options into `box`, `cylinder`, and `sphere` primitives so centered solids emit analytic `KHR_implicit_shapes` colliders.
322
- - `SAND3D_RECIPES` (`cnc_mounting_bracket`, `hinged_ammo_chest`, `articulated_robot_arm`, `mars_sample_buggy`, `orbital_reaction_thruster`, `cyclotomic_airlock_bulkhead`), `SAND3D_RECIPE_MAP`, `findSand3dRecipe`, and `buildSand3dRecipe`.
323
-
324
- ```python
325
- import sand3d as s3d
326
-
327
- def bracket(w=80, d=40, t=6, hole_d=6.6, pitch=50):
328
- plate = s3d.extrude(s3d.rect(w, d, r=4), t, color="#94a3b8")
329
- bored = s3d.hole(plate, hole_d, on=s3d.grid(2, 1, pitch, 0))
330
- return s3d.assembly("bracket_rig", [
331
- s3d.part("Bracket_Base", bored, mass_kg=0.45, break_impulse_ns=1200),
332
- ], units="mm")
333
-
334
- s3d.export(bracket())
335
- ```
336
-
337
- ```json
338
- {
339
- "name": "json_pedestal",
340
- "units": "mm",
341
- "parts": [
342
- {
343
- "name": "ped_root",
344
- "primitive": "cylinder",
345
- "diameter": 60,
346
- "height": 30,
347
- "centered": true,
348
- "massKg": 2.5,
349
- "color": "#38bdf8"
350
- }
351
- ],
352
- "joints": [],
353
- "wheels": [],
354
- "thrusters": [],
355
- "sockets": []
356
- }
357
- ```
358
-
359
- ---
360
-
361
- ## Test Suites
362
-
363
- ```bash
364
- npm run typecheck && npm test && npm run build && npm run example
365
- ```
366
-
367
- Verified across 15 automated test suites:
368
-
369
- - [core.test.ts](../src/core.test.ts) — End-to-end KHR export, binary load, collider inertia, and socket extraction.
370
- - [schemaFixes.test.ts](../src/schemaFixes.test.ts) — glTF schema edge cases, extension preservation, and validation error checks.
371
- - [omiWheel.test.ts](../src/omiWheel.test.ts) — `OMI_vehicle_wheel` and `extras.ecctrlWheel` synthesis and round-trips.
372
- - [headlessTexture.test.ts](../src/headlessTexture.test.ts) — Headless Node `EXT_texture_webp` stubbing across `createImageBitmap` environments.
373
- - [r3fMount.test.tsx](../src/r3fMount.test.tsx) — React Three Fiber `<PhysicsWorld>`, `<KhrAssembly>`, and `<KhrVehicle>` mounts.
374
- - [jointRegistryContext.test.tsx](../src/jointRegistryContext.test.tsx) — Opt-in `JointRegistryContext` provider registration and cleanup.
375
- - [breakaway.test.tsx](../src/breakaway.test.tsx) — Contact-impulse latch release and dynamic joint breakaway.
376
- - [hybridRotorGate.test.tsx](../src/hybridRotorGate.test.tsx) — Hybrid wheel and propeller switching.
377
- - [zeroGVehicle.test.tsx](../src/zeroGVehicle.test.tsx) — Microgravity wheel gating and thruster control.
378
- - [crossPackage.test.ts](../src/crossPackage.test.ts) — Cross-package round-trips dynamically loading optional sibling `../khr3-vehicles`, `../khr3-launchers`, and `../khr3-assets` builds when present.
379
- - [indexExports.test.ts](../src/indexExports.test.ts) — Root barrel symbol and TypeScript export assertions.
380
- - [sand3d.test.ts](../src/sand3d/sand3d.test.ts) — `Sand3D` script evaluation, bore geometry, analytic sphere/cylinder colliders, `.s3d.json` manifests, 6 recipes, and GLB round-trips.
381
- - [workbenchAssets.test.ts](../src/workbenchAssets.test.ts) — Interactive workbench `Sand3D` vehicle/assembly round-trips, gullwing breakaway thresholds, and `0.08` virtual stick deadzone checks.
382
- - [wobbleStability.test.tsx](../src/wobbleStability.test.tsx) — Articulated panel wheel-cast exclusion, sibling door filter isolation, 60 Hz / 30 Hz roll settle stability, and custom gravity panel detachment checks.
383
- - [clawfootTubRegression.test.tsx](../src/clawfootTubRegression.test.tsx) — 60 Hz / 30 Hz steep-slope stability, downhill coasting turn-in, 4-wheel brake-before-reverse uphill Y-turn, and `576 m` floating-origin articulated panel synchronization on `@pinkaphant/ecctrl@2.0.4-beta.5`.