@khr3/core 0.1.5 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -114
- package/dist/BundleSceneHost-DUqqPtJF.js +1036 -0
- package/dist/BundleSceneHost-DUqqPtJF.js.map +1 -0
- package/dist/KhrCollider.d.ts +1 -1
- package/dist/KhrVehicle.d.ts +5 -7
- package/dist/PhysicsWorld.d.ts +2 -2
- package/dist/assemblyPlan.d.ts +2 -0
- package/dist/curves.d.ts +11 -32
- package/dist/curves.js +141 -139
- package/dist/curves.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1639 -1240
- package/dist/index.js.map +1 -0
- package/dist/jointDynamics.d.ts +1 -1
- package/dist/khrBundleFinalize.d.ts +14 -0
- package/dist/khrConfigTypes.d.ts +62 -0
- package/dist/khrExportEncoders.d.ts +8 -0
- package/dist/khrExporter.d.ts +2 -1
- package/dist/khrExtras.d.ts +3 -3
- package/dist/khrGlb.d.ts +23 -0
- package/dist/khrJointParser.d.ts +3 -0
- package/dist/khrLoader.d.ts +2 -1
- package/dist/khrParsers.d.ts +5 -9
- package/dist/khrPlugin.d.ts +2 -3
- package/dist/khrPluginHelpers.d.ts +4 -0
- package/dist/khrRotorDecoders.d.ts +4 -0
- package/dist/khrShapeParser.d.ts +8 -0
- package/dist/khrTypes.d.ts +11 -103
- package/dist/khrVehicleChassis.d.ts +9 -17
- package/dist/khrVehicleJointHelpers.d.ts +24 -0
- package/dist/khrVehicleJoints.d.ts +18 -0
- package/dist/khrVehicleRotors.d.ts +22 -0
- package/dist/khrVehicleSlots.d.ts +19 -15
- package/dist/khrVehicleTypes.d.ts +52 -0
- package/dist/pacejka.d.ts +1 -1
- package/dist/physicsEcs.d.ts +2 -7
- package/dist/useKhrGlb.d.ts +2 -2
- package/dist/vehicle.d.ts +2 -2
- package/dist/vehicle.js +757 -451
- package/dist/vehicle.js.map +1 -0
- package/dist/wheelLoads.d.ts +4 -7
- package/docs/api-reference.md +209 -0
- package/package.json +8 -7
- package/dist/BundleSceneHost-CE3HPB8a.js +0 -556
package/README.md
CHANGED
|
@@ -2,126 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
`KHR_physics_rigid_bodies` + `KHR_implicit_shapes` runtime loader, binary `.glb` exporter, `@react-three/rapier` multi-body assembly synchronizer, and `@pinkaphant/ecctrl` vehicle rig + monotone Pacejka curve presets for React Three Fiber.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
All `@khr3/*` packages are **strictly `koota`-free** reusable building blocks; `Kolmo` owns the ECS, world generation, character body, and universal GLB intake gate:
|
|
8
|
-
|
|
9
|
-
| Package | Role | `koota`? |
|
|
10
|
-
| --- | --- | --- |
|
|
11
|
-
| **`@khr3/core`** *(this package)* | `.glb` KHR physics loader/exporter, `<PhysicsWorld>`, `<KhrAssembly>`, `<KhrVehicle>`, `@khr3/core/curves` | No |
|
|
12
|
-
| `@khr3/assets` | Cloudflare R2 `.glb` vault Worker/client + binary `inspectGlbBuffer` / `normalizeGlbBuffer` | No |
|
|
13
|
-
| `@khr3/c12` | Exact architectural grid ($\mathbb{Z}[1/2, \sqrt{3}]$, `yaw12`), `3 m` socket snapping, `planSettlement` | No |
|
|
14
|
-
| `@khr3/vehicles` | Multi-domain R2 vehicle catalog, multi-body `planCar` (`SEDAN_4DOOR`, `COUPE_2DOOR`), `@khr3/vehicles/paper-shell` | No |
|
|
15
|
-
| `@khr3/launchers` | Moving-part launcher planner (`planLauncher`), rail/hand sockets, ammo catalog, `stepLauncher` | No |
|
|
16
|
-
| `Kolmo` | Game engine & studio (`koota` ECS, `src/world/` roads & terrain, `src/body/`, Universal 2-Step GLB & USD Gate) | **Yes** |
|
|
17
|
-
|
|
18
|
-
## Install
|
|
19
|
-
|
|
20
|
-
```sh
|
|
21
|
-
npm install @khr3/core @pinkaphant/ecctrl @dimforge/rapier3d-compat @react-three/fiber @react-three/rapier react react-dom three
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
### Peer Dependencies
|
|
25
|
-
|
|
26
|
-
| Package | Version | Required By |
|
|
27
|
-
| --- | --- | --- |
|
|
28
|
-
| `@dimforge/rapier3d-compat` | `0.19.2` | `@khr3/core`, `@khr3/core/vehicle` |
|
|
29
|
-
| `@pinkaphant/ecctrl` | `2.0.4-beta.2` | Optional (`@khr3/core/vehicle` only) |
|
|
30
|
-
| `@react-three/fiber` | `^9.0.0` | `@khr3/core`, `@khr3/core/vehicle` |
|
|
31
|
-
| `@react-three/rapier` | `^2.2.0` | `@khr3/core`, `@khr3/core/vehicle` |
|
|
32
|
-
| `react` | `^19.0.0` | `@khr3/core`, `@khr3/core/vehicle` |
|
|
33
|
-
| `react-dom` | `^19.0.0` | Optional (browser DOM apps) |
|
|
34
|
-
| `three` | `>=0.159.0` | `@khr3/core`, `@khr3/core/vehicle` |
|
|
5
|
+
- Full API & configuration reference: [docs/api-reference.md](./docs/api-reference.md)
|
|
6
|
+
- Runnable example: [example/App.tsx](./example/App.tsx) & [example/headless.ts](./example/headless.ts)
|
|
35
7
|
|
|
36
8
|
## Subpath Exports
|
|
37
9
|
|
|
38
|
-
`@khr3/core` ships strictly three ESM subpaths (`"sideEffects": false`, NodeNext `.d.ts` declarations):
|
|
39
|
-
|
|
40
10
|
| Subpath | Exports |
|
|
41
11
|
| --- | --- |
|
|
42
12
|
| `@khr3/core` | `PhysicsWorld`, `createKhrGltfPlugin`, `useKhrGlb`, `loadKhrGlb`, `cloneKhrBundle`, `disposeKhrBundle`, `claimBundleMount`, `releaseBundleMount`, `exportKhrGlb`, `patchGlbJsonChunk`, `KhrCollider`, `KhrAssembly`, `JointRegistryContext`, `assertUnitScale`, `assertIdentityWorldScale`, `assertSceneIdentityWorldScale`, `KhrValidationError`, KHR & rotor tag types |
|
|
43
|
-
| `@khr3/core/vehicle` | `KhrVehicle`, `solveWheelLoads`, `
|
|
13
|
+
| `@khr3/core/vehicle` | `KhrVehicle`, `solveWheelLoads`, `KhrPropellerConfig`, `KhrVehicleJointsHandle`, `KhrVehicleProps`, `KhrWheelConfig`, `SolvedWheel` |
|
|
44
14
|
| `@khr3/core/curves` | `compilePacejkaCurve`, `tireGripForSurface`, `engineHorsepowerForPeakTorque`, `TIRE_ARCHETYPES`, `TIRE_SLIP_CURVES`, `ENGINE_TORQUE_CURVES`, `STEER_SPEED_CURVES`, `TireArchetypePreset`, `CurveData`, `CurvePoint` |
|
|
45
15
|
|
|
46
|
-
## Quick Start
|
|
47
|
-
|
|
48
|
-
```tsx
|
|
49
|
-
import { useRef } from "react";
|
|
50
|
-
import { Canvas } from "@react-three/fiber";
|
|
51
|
-
import type { EcctrlVehicleHandle } from "@pinkaphant/ecctrl/vehicle";
|
|
52
|
-
import { KhrAssembly, PhysicsWorld, loadKhrGlb, type KhrAssemblyHandle } from "@khr3/core";
|
|
53
|
-
import { KhrVehicle } from "@khr3/core/vehicle";
|
|
54
|
-
import { ENGINE_TORQUE_CURVES, TIRE_ARCHETYPES, tireGripForSurface } from "@khr3/core/curves";
|
|
55
|
-
|
|
56
|
-
const roadBundle = await loadKhrGlb(await fetch("/assets/city/R_Straight_6x6.glb").then((r) => r.arrayBuffer()));
|
|
57
|
-
const doorBundle = await loadKhrGlb(await fetch("/assets/city/door_hinged_single_900x2100.glb").then((r) => r.arrayBuffer()));
|
|
58
|
-
const carBundle = await loadKhrGlb(await fetch("/assets/cars/kolmogorov_hatchback.glb").then((r) => r.arrayBuffer()));
|
|
59
|
-
|
|
60
|
-
export function Scene() {
|
|
61
|
-
const doorRef = useRef<KhrAssemblyHandle>(null);
|
|
62
|
-
const vehicleRef = useRef<EcctrlVehicleHandle>(null);
|
|
63
|
-
const tire = TIRE_ARCHETYPES.streetDrift90s;
|
|
64
|
-
|
|
65
|
-
return (
|
|
66
|
-
<Canvas>
|
|
67
|
-
<PhysicsWorld>
|
|
68
|
-
<KhrAssembly bundle={roadBundle} fixedRoot />
|
|
69
|
-
<KhrAssembly ref={doorRef} bundle={doorBundle} position={[3.6, 0.1, 0]} fixedRoot />
|
|
70
|
-
<KhrVehicle
|
|
71
|
-
ref={vehicleRef}
|
|
72
|
-
bundle={carBundle}
|
|
73
|
-
position={[0, 0.15, 0]}
|
|
74
|
-
carConfig={{
|
|
75
|
-
engineTorqueCurveData: ENGINE_TORQUE_CURVES.naScreamer,
|
|
76
|
-
transmissionMode: "auto",
|
|
77
|
-
gearRatios: [3.2, 2.1, 1.45, 1.0],
|
|
78
|
-
shiftUpRPM: 5800,
|
|
79
|
-
shiftDownRPM: 2600, // < 5800 * (1.0 / 1.45) = 4000 (hysteresis invariant)
|
|
80
|
-
}}
|
|
81
|
-
wheelConfig={{
|
|
82
|
-
tireGripFactor: tireGripForSurface(tire.muPeakLng, 0.8),
|
|
83
|
-
lngSlipRatioCurveData: tire.lng,
|
|
84
|
-
latSlipRatioCurveData: tire.lat,
|
|
85
|
-
latFrictionEllipseScale: tire.latFrictionEllipseScale,
|
|
86
|
-
}}
|
|
87
|
-
frontWheelConfig={{ driveTorqueWeight: 0.35 }}
|
|
88
|
-
rearWheelConfig={{ driveTorqueWeight: 0.65 }}
|
|
89
|
-
/>
|
|
90
|
-
</PhysicsWorld>
|
|
91
|
-
</Canvas>
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
## Loading Assets
|
|
97
|
-
|
|
98
|
-
```tsx
|
|
99
|
-
import { Suspense } from "react";
|
|
100
|
-
import { KhrAssembly, useKhrGlb, disposeKhrBundle } from "@khr3/core";
|
|
101
|
-
|
|
102
|
-
function Door() {
|
|
103
|
-
const bundle = useKhrGlb("/assets/city/door_hinged_single_900x2100.glb"); // Suspense + cache, clones per call site
|
|
104
|
-
return <KhrAssembly bundle={bundle} />;
|
|
105
|
-
}
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
- `useKhrGlb(url)` suspends, caches by URL, and returns a per-instance clone; `createKhrGltfPlugin()` registers the same decoder on any `GLTFLoader`; `loadKhrGlb(bytes)` is the headless/buffer path.
|
|
109
|
-
- Call `disposeKhrBundle(template)` once when an asset is retired.
|
|
110
|
-
- `<PhysicsWorld>` steps Rapier directly in `useFrame` with clamped `maxDelta` and `timeScale`; `@pinkaphant/ecctrl` is an optional peer required only by `@khr3/core/vehicle` (`@khr3/core/curves` is zero-dependency TypeScript math).
|
|
111
|
-
- Peer range for `three` is `>=0.159.0`.
|
|
112
|
-
|
|
113
|
-
## Core Architecture & Invariants
|
|
114
|
-
|
|
115
|
-
1. **Bundle Ownership & Zero-Reparse Cloning (`cloneKhrBundle`)**: `loadKhrGlb(source)` constructs live `THREE.Object3D` nodes (`bundle.scene`, `w.object`, `p.object`). Mount each `KhrAssetBundle` in at most **one** `<KhrAssembly>` or `<KhrVehicle>` at a time; parse once with `loadKhrGlb(bytes)` and call `cloneKhrBundle(template)` per tiled road, prop, or vehicle instance (cloning only the lightweight `Object3D` hierarchy while sharing GPU `BufferGeometry`/`Material` buffers and Rapier `Float32Array` collider vertices). Sequential `mount -> unmount -> remount` of a single bundle is safe, and swapping the `bundle` prop cleanly remounts Rapier bodies and joints via `key={bundle.scene.uuid}`.
|
|
116
|
-
2. **CoM-Aligned Vehicle RigidBody (`body.translation() === body.worldCom()`)**: `<KhrVehicle>` offsets the underlying `<EcctrlVehicle>` Rapier `RigidBody` spawn to `position + R(spawnQuat) * chassisCom` and shifts local chassis colliders, `bundle.scene`, `children`, `<ShapeCastWheel>`, and `<ThrustPropeller>` mounts by `-chassisCom`. World-space visual and collider poses at `position` remain unchanged while `EcctrlVehicle` wheel lever arms (`rayOrigin - body.translation()`) act directly about the true center of mass, preserving authored CG height and parallel-axis inertia without artificial rollover or pitch coupling.
|
|
117
|
-
3. **glTF & Rapier Safety**:
|
|
118
|
-
- `exportKhrGlb` emits `KHR_physics_rigid_bodies` and `KHR_implicit_shapes` strictly in `extensionsUsed` (never `extensionsRequired`).
|
|
119
|
-
- `KhrCollider` sets `density: 0` (exact mass/CoM/inertia are applied once via `setAdditionalMassProperties`) and omits `collisionGroups` whenever `undefined` so Rapier WASM never coerces `undefined` to `0x00000000`.
|
|
120
|
-
4. **5 `@pinkaphant/ecctrl` v2 Curve & Grip Invariants**:
|
|
121
|
-
- **Surface Grip Averaging**: `ShapeCastWheel` computes $\mu_{\text{eff}} = \frac{1}{2}(\mu_{\text{ground}} + \text{tireGripFactor})$. Use `tireGripForSurface(muPeak, muGround)` (`2 * muPeak - muGround`).
|
|
122
|
-
- **Peak Torque Scaling**: `EcctrlVehicle` computes $T_{\max} = \frac{\text{engineHorsepower} \times 7022}{\text{engineMaxRPM}}$. Use `engineHorsepowerForPeakTorque(peakTorqueNm, engineMaxRPM)`.
|
|
123
|
-
- **Slip Domains**: `lngSlipRatioCurveData` maps $x = \frac{|\omega R - v_x|}{\max(|v_x|, 10^{-4})} \in [0, 1]$; `latSlipRatioCurveData` maps slip angle linearly as $x = \frac{\operatorname{atan2}(|v_y|, |v_x|)}{\pi/2} \in [0, 1]$.
|
|
124
|
-
- **Monotone Hermite Tangents**: `CurvePoint` `r_in`/`r_out` are **radian angles** (`slope = Math.tan(r)`). `compilePacejkaCurve` enforces Fritsch–Carlson clamping so `bakeCurveLUT` stays strictly in $[0, 1]$ with zero Hermite overshoot.
|
|
125
|
-
- **Shift Hysteresis & Gear-Relative Steer Curve**: Auto transmission requires `shiftDownRPM < shiftUpRPM * min(g[i+1] / g[i])` to prevent shift oscillation; `steerAngleCurveData` evaluates at `v_fwd / (maxWheelAngVel * R)` relative to the **active gear's** redline wheel speed.
|
|
126
|
-
|
|
127
16
|
See [docs/api-reference.md](./docs/api-reference.md) for the complete API, `.glb` KHR + `extras` schema, custom gravity, transmission, and curve reference.
|