@pinkaphant/kolmo 0.5.2 → 0.5.3

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 (41) hide show
  1. package/README.md +92 -14
  2. package/dist/engine/actor.d.ts +1 -1
  3. package/dist/engine/index.d.ts +3 -0
  4. package/dist/engine/index.js +44 -34
  5. package/dist/engine/index.js.map +1 -1
  6. package/dist/engine/surface.d.ts +5 -6
  7. package/dist/engine/traits.d.ts +27 -0
  8. package/dist/engine/world.d.ts +5 -3
  9. package/dist/index.d.ts +2 -2
  10. package/dist/index.js +9 -5
  11. package/dist/physics/index.d.ts +2 -1
  12. package/dist/physics/index.js +3 -1
  13. package/dist/physics-KYWAXctg.js +233 -0
  14. package/dist/physics-KYWAXctg.js.map +1 -0
  15. package/dist/replay/index.d.ts +84 -0
  16. package/dist/replay/index.js +380 -0
  17. package/dist/replay/index.js.map +1 -0
  18. package/dist/terrain/index.d.ts +119 -0
  19. package/dist/terrain/index.js +495 -0
  20. package/dist/terrain/index.js.map +1 -0
  21. package/dist/toolgun/Toolgun.d.ts +11 -4
  22. package/dist/toolgun/index.d.ts +2 -2
  23. package/dist/toolgun/index.js +1 -1
  24. package/dist/{toolgun-CFCNO00q.js → toolgun-COu_5SxS.js} +202 -542
  25. package/dist/toolgun-COu_5SxS.js.map +1 -0
  26. package/dist/traits-Dp1ey_4w.js +267 -0
  27. package/dist/traits-Dp1ey_4w.js.map +1 -0
  28. package/dist/vite/index.js +1 -0
  29. package/dist/vite/index.js.map +1 -1
  30. package/dist/water/index.d.ts +71 -0
  31. package/dist/water/index.js +442 -0
  32. package/dist/water/index.js.map +1 -0
  33. package/dist/{world-BljtS6Fb.js → world-BDhBihjW.js} +114 -139
  34. package/dist/world-BDhBihjW.js.map +1 -0
  35. package/docs/api-reference.md +201 -0
  36. package/package.json +23 -6
  37. package/dist/physics-CA1abDCY.js +0 -476
  38. package/dist/physics-CA1abDCY.js.map +0 -1
  39. package/dist/toolgun/c12Outlets.d.ts +0 -36
  40. package/dist/toolgun-CFCNO00q.js.map +0 -1
  41. package/dist/world-BljtS6Fb.js.map +0 -1
@@ -0,0 +1,201 @@
1
+ # `@pinkaphant/kolmo` API Reference
2
+
3
+ `@pinkaphant/kolmo` is a thin React Three Fiber (`@react-three/fiber`) + Rapier WASM (`@react-three/rapier`) game layer composing:
4
+
5
+ - **`@pinkaphant/ecctrl`** (`Ecctrl` character capsule + `EcctrlCameraControls` + `EcctrlVehicle` / `ShapeCastWheel` / `ThrustPropeller` + `Joystick` / `VirtualButton` + `useCustomGravity`)
6
+ - **`@khr3/core`** (`KHR_physics_rigid_bodies` + `KHR_implicit_shapes` + `OMI_vehicle_wheel` + `KOLMO_emitter` `.glb` loader, exporter, articulated `KhrAssembly`, `KhrVehicle`, and `KhrHeightfield`)
7
+ - **`@khr3/c12`** (exact $\mathbb{Z}[1/2, \sqrt{3}]$ 12-direction modular building lattice & socket snapping)
8
+ - **`@khr3/roads`** (seeded spline roads, slope-bounded terrain, and frontage lots)
9
+ - **`koota`** (zero-allocation Structure-of-Arrays ECS world, traits, exclusive `PilotLink` relation, and actions)
10
+
11
+ ---
12
+
13
+ ## 1. Vite Configuration (`@pinkaphant/kolmo/vite`)
14
+
15
+ Always pass `KOLMO_SINGLETON_DEDUPE` to `resolve.dedupe` so React contexts, Three.js `Object3D` prototypes, Rapier WASM worlds, Koota worlds, and Zustand stores are never duplicated across chunks:
16
+
17
+ ```ts
18
+ import { defineConfig } from "vite";
19
+ import react from "@vitejs/plugin-react";
20
+ import { KOLMO_SINGLETON_DEDUPE } from "@pinkaphant/kolmo/vite";
21
+
22
+ export default defineConfig({
23
+ plugins: [react()],
24
+ resolve: {
25
+ dedupe: KOLMO_SINGLETON_DEDUPE,
26
+ },
27
+ });
28
+ ```
29
+
30
+ ---
31
+
32
+ ## 2. Shell, World & Physics (`@pinkaphant/kolmo`)
33
+
34
+ ### `<Game>` (`KolmoGame`)
35
+
36
+ Full-viewport game container mounting `<KolmoCanvas>`, `<KolmoWorld>`, Koota `<WorldProvider>`, and an overlay portal target for `<Hud>`.
37
+
38
+ | Prop | Type | Default | Description |
39
+ | --- | --- | --- | --- |
40
+ | `gravity` | `KolmoGravitySpec` | `"planar"` | `"planar"` (`[0, -9.81, 0]`), `"zero"`, `[gx, gy, gz]`, `{ kind: "point", center, surfaceG, radius, inverseSquare? }`, `{ kind: "nbody", attractors }`, or `(pos, out) => THREE.Vector3`. |
41
+ | `skybox` | `"day" \| "night" \| "none"` | `"day"` | Sky clear color and atmospheric fog. |
42
+ | `lighting` | `"default" \| "none"` | `"default"` | Hemisphere + shadow-casting sun directional light (`RoomEnvironment` IBL controlled via `roomEnv`). |
43
+ | `fogExp2` | `[color: string, density: number] \| null` | `undefined` | Optional exponential squared fog override. |
44
+ | `paused` | `boolean` | `false` | Freezes physics stepping while preserving rendering. |
45
+ | `timeScale` | `number \| RefObject<number>` | `1` | Real-time simulation speed multiplier (supports bullet-time). |
46
+ | `maxDelta` | `number \| RefObject<number>` | `1 / 30` | Upper clamp on variable frame `dt`. |
47
+ | `debug` | `boolean` | `false` | Renders Rapier WASM collider wireframes (`physicsDebug` alias also accepted). |
48
+ | `dpr` | `number \| [number, number]` | `[1, 1.5]` | Canvas device pixel ratio. |
49
+ | `roomEnv` | `boolean \| number` | `0.65` | `RoomEnvironment` PMREM IBL intensity (`false` to disable). |
50
+ | `kootaWorld` | `KootaWorld` | `kolmoWorld` | Custom Koota `World` instance. |
51
+
52
+ > **Composing Inside Your Own `<Canvas>`**: Render `<World>` (`KolmoWorld`) inside any `<Canvas>` (or `<Physics>` / `KolmoPhysics` if managing your own lights and `<KeyboardControls>`). `<Hud>` works both inside `<Canvas>` (portals out automatically) and outside `<Canvas>`.
53
+
54
+ ---
55
+
56
+ ## 3. Terrain (`<Terrain>` / `@pinkaphant/kolmo/terrain`)
57
+
58
+ `<Terrain>` (`KolmoTerrain`) supports **two modes** with zero `BoxGeometry` placeholders and exact Rapier WASM `HeightFieldFlags.FIX_INTERNAL_EDGES` parity:
59
+
60
+ ### Mode A: Pre-Sampled Height Grid (e.g. `@khr3/roads`)
61
+
62
+ ```tsx
63
+ import { Terrain } from "@pinkaphant/kolmo";
64
+ import { growRoad, makeTerrain, sampleRapierHeightfield } from "@khr3/roads";
65
+
66
+ const road = growRoad(7, { length: 1200, halfWidth: 4, controlSpacing: 40, maxTurn: 0.3, maxGrade: 0.08, hilliness: 24 });
67
+ const land = makeTerrain(7, road, {
68
+ amplitude: 16,
69
+ noise: { wavelength: 160, octaves: 4, gain: 0.5, lacunarity: 2 },
70
+ maxSlope: 0.55,
71
+ minShoulder: 6,
72
+ verge: 1.5,
73
+ });
74
+
75
+ // Sample centered at [0, 0, 0] over [-200, +200] x [-200, +200] in Rapier column-major order:
76
+ const heights = sampleRapierHeightfield(land, [-200, 0, -200], 400, 128);
77
+
78
+ <Terrain heights={heights} segments={128} size={[400, 400]} position={[0, 0, 0]} color="#49644d" />
79
+ ```
80
+
81
+ *(If you have a row-major height array such as `@khr3/roads` `sampleHeightfield`, pass `layout="row-major"` and `<Terrain>` transposes it automatically.)*
82
+
83
+ ### Mode B: Multi-Chunk Sculptable & `.glb`-Exportable Heightfield
84
+
85
+ ```tsx
86
+ const terrainRef = useRef<KolmoTerrainHandle>(null);
87
+
88
+ <Terrain
89
+ ref={terrainRef}
90
+ chunksX={4}
91
+ chunksZ={4}
92
+ cellsPerChunk={24}
93
+ cellSizeM={1.5}
94
+ heightFn={(x, z) => 3 * Math.sin(x * 0.04) * Math.cos(z * 0.04)}
95
+ />
96
+ ```
97
+
98
+ - `terrainRef.current.applyBrush({ x, z, radius, strength, mode: "add" | "flatten" | "smooth" })` updates dirty chunk meshes and Rapier colliders in real time with $C^1$ cross-chunk normals.
99
+ - `await terrainRef.current.exportGlb()` exports a Khronos `KHR_physics_rigid_bodies` `.glb` binary with static trimesh colliders.
100
+
101
+ ---
102
+
103
+ ## 4. Actors, Vehicles, Props & Surfaces
104
+
105
+ ### `<Actor>` (`KolmoActor`)
106
+
107
+ Wraps `@pinkaphant/ecctrl`'s `<Ecctrl>` (`enableToggleRun={false}` by default so `[Shift]` sprints while held) + `<EcctrlCameraControls>` + Koota `ActorTrait`, and handles `[F]` vehicle boarding/exiting (`<React.StrictMode>` safe via `getLiveActorBody`):
108
+
109
+ ```tsx
110
+ <Actor
111
+ ref={actorRef}
112
+ position={[0, 2, 8]}
113
+ bundle={optionalCharacterBundle}
114
+ maxWalkVel={3.8}
115
+ maxRunVel={7.8}
116
+ jumpVel={5.8}
117
+ />
118
+ ```
119
+
120
+ ### `<Vehicle>` (`KolmoVehicle`)
121
+
122
+ Loads a `.glb` (`src` or `bundle`) via `@khr3/core`'s `<KhrVehicle>`, resolves `seat` / `exit` sockets (`KOLMO_emitter` `socket: "seat" | "exit"`, `IK_Seat`, or `Seat_L`), drives ground cars, aircraft/rockets (`propellers`), or hybrid vehicles (`[G]` mode toggle), and streams `TransformTrait`, `VelocityTrait`, and `VehicleTelemetryTrait` (`rpm`, `gear`, `throttle`, `boost`, `slip`) into Koota:
123
+
124
+ ```tsx
125
+ <Vehicle
126
+ id="skyline"
127
+ src="https://khr3.optimuspi.workers.dev/assets/cars/nissan_skyline_r34.glb"
128
+ position={[0, 1.6, 0]}
129
+ piloted={false}
130
+ interactRadius={4.2}
131
+ />
132
+ ```
133
+
134
+ - Pass `driver={(veh, dt, state) => { ... }}` for AI traffic / autonomous control.
135
+ - Read `bundle.emitters` (`KhrEmitterSpec[]`) for authored exhaust plumes, brake flares, and headlights (`KOLMO_emitter`).
136
+
137
+ ### `<Prop>` (`KolmoProp`) & `<Surface>` (`KolmoSurface`)
138
+
139
+ - `<Prop src={...} position={[x, y, z]} fixed={false} />`: Mounts a dynamic or `fixed` KHR `.glb` assembly (`KhrAssembly`), registers `PropTrait` in Koota, and toggles articulated doors/hinges on click.
140
+ - `<Surface src={...} position={[x, y, z]} />`: Mounts a static KHR `.glb` ground/road/building assembly (`fixedRoot={true}`).
141
+
142
+ ---
143
+
144
+ ## 5. Water Hydrodynamics (`<Water>` / `@pinkaphant/kolmo/water`)
145
+
146
+ Exact spherical-cap and 8-octant Archimedes submerged-volume buoyancy, hydrostatic roll/pitch righting torque, and exponentially stable linear/quadratic drag over dynamic Rapier bodies:
147
+
148
+ ```tsx
149
+ <Water levelY={-1.2} originXZ={[0, 0]} size={[80, 80]} segments={[48, 48]} densityKgM3={1000} />
150
+ ```
151
+
152
+ ---
153
+
154
+ ## 6. Toolgun (`<Toolgun>` / `@pinkaphant/kolmo/toolgun`)
155
+
156
+ 6-mode physics & C12 construction toolgun (`spawn`, `weld`, `hinge`, `rig`, `build`, `delete`):
157
+
158
+ - **Zero Primitive Fallbacks**: Viewmodel renders only when a `.glb` `src` or `bundle` is supplied (LCD canvas quad mounts automatically when `screen_rect` or `lcd_screen` exists on the `.glb`). Spawning/building requires an actual Rapier raycast surface hit (`NO SURFACE HIT` on sky miss).
159
+ - **Default R2 Vault C12 Pieces (`DEFAULT_VAULT_C12_URLS`)**: Out of the box, `build` mode loads real KHR `.glb` C12 architectural pieces (`FoundationSquare`, `FoundationTriangle`, `Wall`, `Doorway`, `Floor`, `FloorTriangle`, `Roof`, `RoofTriangle`, `Stairs`, `Street`, `DoorLeaf`) from the R2 vault, overridable via `c12Bundles` or `c12Urls`.
160
+ - **Shortcuts (when on foot)**: `[1–6]` or `[Q]` mode, `[R]` rotate +30° (`yaw12`), `[` / `]` cycle C12 piece, `[Z]` undo, `LMB` fire, `RMB` / `Tab` zoom.
161
+
162
+ ---
163
+
164
+ ## 7. Koota ECS Queries, Actions & Replay
165
+
166
+ ```tsx
167
+ import {
168
+ useQuery,
169
+ useActiveKolmoWorld,
170
+ useKolmoGame,
171
+ kolmoActions,
172
+ VehicleTrait,
173
+ VehicleTelemetryTrait,
174
+ PropTrait,
175
+ TransformTrait,
176
+ VelocityTrait,
177
+ } from "@pinkaphant/kolmo";
178
+
179
+ function CustomTelemetry() {
180
+ const { mode, activeVehicleId, nearVehicleId, boardVehicle, exitVehicle, resetVehicle } = useKolmoGame();
181
+ const vehicles = useQuery(VehicleTrait, VelocityTrait, VehicleTelemetryTrait);
182
+ // ...
183
+ }
184
+ ```
185
+
186
+ ### Deterministic Replay (`@pinkaphant/kolmo/replay`)
187
+
188
+ - `FixedStepAccumulator(tickHz)`: Fixed-dt substepper with `alpha` interpolation factor.
189
+ - `InputTapeRecorder` / `InputTapePlayer`: 6-byte/tick binary `KRPL` input recording & playback (`<Actor getInput={player.readTick} />`).
190
+ - `KootaTrajectoryTape`: Zero-allocation `KTAP` SoA state capture (`tape.captureWorld(world)`) and quaternion-slerp timeline scrubbing (`tape.scrubWorld(world, timeSec)`).
191
+
192
+ ---
193
+
194
+ ## 8. Live Cloudflare R2 Asset Vault (`https://khr3.optimuspi.workers.dev/assets`)
195
+
196
+ Full catalog index: `https://khr3.optimuspi.workers.dev/assets/manifest.json`
197
+
198
+ - **Vehicles (`cars/`)**:
199
+ - `cars/nissan_skyline_r34.glb`, `cars/toyota_supra_a80.glb`, `cars/nissan_silvia_s15.glb`, `cars/lexus_is300.glb`, `cars/kolmogorov_hatchback.glb`, `cars/crotch_rocket.glb`, `cars/starfox_rocket.glb`
200
+ - **C12 Architecture & Props (`city/`)**:
201
+ - `city/foundation_square_3x3.glb`, `city/foundation_triangle_3m.glb`, `city/wall_solid_3x3x200mm.glb`, `city/wall_clapboard_doorframe_3x3.glb`, `city/door_hinged_single_900x2100.glb`, `city/floor_square_3x3.glb`, `city/floor_triangle_3m.glb`, `city/roof_flat_3x3.glb`, `city/roof_triangle_3m.glb`, `city/stairs_3x3.glb`, `city/R_Straight_6x6.glb`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pinkaphant/kolmo",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "description": "Thin React Three Fiber + Rapier WASM + @pinkaphant/ecctrl + @khr3/core + @khr3/c12 + Koota ECA game layer",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -20,6 +20,18 @@
20
20
  "types": "./dist/physics/index.d.ts",
21
21
  "import": "./dist/physics/index.js"
22
22
  },
23
+ "./terrain": {
24
+ "types": "./dist/terrain/index.d.ts",
25
+ "import": "./dist/terrain/index.js"
26
+ },
27
+ "./water": {
28
+ "types": "./dist/water/index.d.ts",
29
+ "import": "./dist/water/index.js"
30
+ },
31
+ "./replay": {
32
+ "types": "./dist/replay/index.d.ts",
33
+ "import": "./dist/replay/index.js"
34
+ },
23
35
  "./toolgun": {
24
36
  "types": "./dist/toolgun/index.d.ts",
25
37
  "import": "./dist/toolgun/index.js"
@@ -32,6 +44,7 @@
32
44
  },
33
45
  "files": [
34
46
  "dist",
47
+ "docs",
35
48
  "LICENSE",
36
49
  "README.md"
37
50
  ],
@@ -47,21 +60,25 @@
47
60
  "pack:dry": "npm pack --dry-run"
48
61
  },
49
62
  "peerDependencies": {
50
- "@dimforge/rapier3d-compat": "0.19.2",
63
+ "@dimforge/rapier3d-compat": "^0.19.2",
51
64
  "@khr3/c12": ">=0.3.12",
52
- "@khr3/core": ">=0.2.12",
53
- "@pinkaphant/ecctrl": "2.0.4-beta.5",
65
+ "@khr3/core": ">=0.2.13",
66
+ "@pinkaphant/ecctrl": ">=2.0.4-beta.5",
54
67
  "@react-three/drei": "^10.0.0",
55
68
  "@react-three/fiber": "^9.0.0",
56
69
  "@react-three/rapier": "^2.2.0",
70
+ "@types/three": ">=0.159.0",
57
71
  "koota": "^0.6.6",
58
72
  "maath": "^0.10.8",
59
73
  "react": "^19.0.0",
60
74
  "react-dom": "^19.0.0",
61
- "three": "0.184.0",
75
+ "three": ">=0.159.0",
62
76
  "zustand": "^5.0.0"
63
77
  },
64
78
  "peerDependenciesMeta": {
79
+ "@types/three": {
80
+ "optional": true
81
+ },
65
82
  "react-dom": {
66
83
  "optional": true
67
84
  }
@@ -69,7 +86,7 @@
69
86
  "devDependencies": {
70
87
  "@dimforge/rapier3d-compat": "0.19.2",
71
88
  "@khr3/c12": "^0.3.12",
72
- "@khr3/core": "^0.2.12",
89
+ "@khr3/core": "^0.2.13",
73
90
  "@pinkaphant/ecctrl": "2.0.4-beta.5",
74
91
  "@react-three/drei": "^10.7.7",
75
92
  "@react-three/fiber": "^9.6.1",