@pinkaphant/kolmo 0.5.1 → 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 +94 -441
  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 +10 -6
  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 +17 -6
  22. package/dist/toolgun/index.d.ts +2 -2
  23. package/dist/toolgun/index.js +1 -1
  24. package/dist/toolgun/store.d.ts +25 -75
  25. package/dist/{toolgun-BfcCIAQx.js → toolgun-COu_5SxS.js} +391 -673
  26. package/dist/toolgun-COu_5SxS.js.map +1 -0
  27. package/dist/traits-Dp1ey_4w.js +267 -0
  28. package/dist/traits-Dp1ey_4w.js.map +1 -0
  29. package/dist/vite/index.js +1 -0
  30. package/dist/vite/index.js.map +1 -1
  31. package/dist/water/index.d.ts +71 -0
  32. package/dist/water/index.js +442 -0
  33. package/dist/water/index.js.map +1 -0
  34. package/dist/{surface-DUol_5ml.js → world-BDhBihjW.js} +442 -57
  35. package/dist/world-BDhBihjW.js.map +1 -0
  36. package/docs/api-reference.md +201 -0
  37. package/package.json +25 -8
  38. package/dist/physics-ZDFXaCli.js +0 -475
  39. package/dist/physics-ZDFXaCli.js.map +0 -1
  40. package/dist/surface-DUol_5ml.js.map +0 -1
  41. package/dist/toolgun-BfcCIAQx.js.map +0 -1
package/README.md CHANGED
@@ -1,29 +1,107 @@
1
1
  # `@pinkaphant/kolmo`
2
2
 
3
- Thin React Three Fiber + Rapier WASM game layer over the pmndrs + KHR + C12 stack:
3
+ Thin, composable React Three Fiber + Rapier WASM + `@pinkaphant/ecctrl` + `@khr3/core` + `@khr3/c12` + Koota ECA game layer.
4
4
 
5
- - **`@pinkaphant/ecctrl`**: Direct `Ecctrl` (`Ref<EcctrlHandle>`) and `EcctrlVehicle` (`Ref<EcctrlVehicleHandle>`), `ShapeCastWheel`, `ThrustPropeller`, `Joystick`, `VirtualButton`, `EcctrlCameraControls`, `useCustomGravity`, and `zustand` stores.
6
- - **Koota ECA**: Zero-allocation SoA traits (`ActorTrait`, `VehicleTrait`, `TransformTrait`, `VelocityTrait`, `VehicleTelemetryTrait`) via `unpackEntity` + `getStore`, `PilotLink` exclusive relation, and `kolmoActions(world)`.
7
- - **`@khr3/core` & `@khr3/c12`**: `KHR_physics_rigid_bodies` + `KHR_implicit_shapes` + `OMI_vehicle_wheel` `.glb` assemblies/vehicles (`<Vehicle>`, `<Prop>`, `<Surface>`) and exact $\mathbb{Z}[1/2, \sqrt{3}]$ C12 lattice tools.
8
- - **`<Toolgun />` (`@pinkaphant/kolmo/toolgun`)**: Handheld physics/building toolgun with real Rapier WASM raycasts (`castRayAndGetNormal`), two-shot Fixed Weld & Revolute Hinge `ImpulseJoint`s, direct `@khr3/core` `JointRuntime` rigging/breakaway, KHR `.glb` spawning, exact `@khr3/c12` 30° `yaw12` socket building, and diegetic `256×192` LCD screen.
5
+ - **Full API Reference**: [`docs/api-reference.md`](./docs/api-reference.md)
6
+ - **SI Right-Handed Frame**: `1.0 unit === 1.0 m`, `+Y` up, `+Z` forward, baked `[1, 1, 1]` scale.
7
+ - **React 19 `<StrictMode>` Safe**: Every Rapier `RigidBody` and `ImpulseJoint` pointer is verified against the live `RAPIER.World` before mutation.
9
8
 
10
- ## Usage
9
+ ## Installation & Vite Config
10
+
11
+ ```bash
12
+ npm install @pinkaphant/kolmo @khr3/core @khr3/c12 @khr3/roads @pinkaphant/ecctrl \
13
+ three @react-three/fiber @react-three/drei @react-three/rapier @dimforge/rapier3d-compat \
14
+ koota maath zustand
15
+ ```
16
+
17
+ Always pass `KOLMO_SINGLETON_DEDUPE` in `vite.config.ts` so React, R3F, Rapier WASM, Koota, and Zustand share singletons:
18
+
19
+ ```ts
20
+ import { defineConfig } from "vite";
21
+ import react from "@vitejs/plugin-react";
22
+ import { KOLMO_SINGLETON_DEDUPE } from "@pinkaphant/kolmo/vite";
23
+
24
+ export default defineConfig({
25
+ plugins: [react()],
26
+ resolve: { dedupe: KOLMO_SINGLETON_DEDUPE },
27
+ });
28
+ ```
29
+
30
+ ## Quick Start (R2 Vault + `@khr3/roads` + `<Terrain>` + `<Vehicle>` + `<Actor>`)
11
31
 
12
32
  ```tsx
13
- import { useRef } from "react";
14
- import { Game, Surface, Actor, Vehicle, Toolgun, Hud, type EcctrlHandle } from "@pinkaphant/kolmo";
33
+ import { useMemo, useRef } from "react";
34
+ import {
35
+ Game,
36
+ Terrain,
37
+ Water,
38
+ Actor,
39
+ Vehicle,
40
+ Prop,
41
+ Toolgun,
42
+ Hud,
43
+ type EcctrlHandle,
44
+ } from "@pinkaphant/kolmo";
45
+ import { growRoad, makeTerrain, sampleRapierHeightfield, frontage } from "@khr3/roads";
15
46
 
16
- export function App() {
47
+ const VAULT = "https://khr3.optimuspi.workers.dev/assets";
48
+
49
+ export default function App() {
17
50
  const actorRef = useRef<EcctrlHandle>(null);
18
51
 
52
+ const { heights, startPos, lotPos } = useMemo(() => {
53
+ const road = growRoad(42, {
54
+ length: 600,
55
+ halfWidth: 4.5,
56
+ controlSpacing: 35,
57
+ maxTurn: 0.28,
58
+ maxGrade: 0.06,
59
+ hilliness: 18,
60
+ start: [0, 0, -140],
61
+ });
62
+ const land = makeTerrain(42, road, {
63
+ amplitude: 12,
64
+ noise: { wavelength: 140, octaves: 4, gain: 0.5, lacunarity: 2 },
65
+ maxSlope: 0.55,
66
+ minShoulder: 6,
67
+ verge: 2,
68
+ });
69
+ const heights = sampleRapierHeightfield(land, [-160, 0, -160], 320, 128);
70
+ const s0 = road.at(25).pos;
71
+ const lot = frontage(road, { spacing: 24, setback: 3 })[0];
72
+ return {
73
+ heights,
74
+ startPos: [s0[0], s0[1] + 1.5, s0[2]] as [number, number, number],
75
+ lotPos: lot ? ([lot.front[0], lot.groundY, lot.front[2]] as [number, number, number]) : ([10, 0, 20] as [number, number, number]),
76
+ };
77
+ }, []);
78
+
19
79
  return (
20
- <Game skybox="day">
21
- <Surface size={200} />
22
- <Actor ref={actorRef} position={[0, 1.4, 0]} />
23
- <Vehicle src="/assets/coupe.glb" position={[4, 0.8, 4]} />
24
- <Toolgun />
80
+ <Game skybox="day" debug={false}>
81
+ <Terrain heights={heights} segments={128} size={[320, 320]} />
82
+ <Water levelY={-3.5} size={[120, 120]} />
83
+
84
+ <Vehicle id="r34" src={`${VAULT}/cars/nissan_skyline_r34.glb`} position={startPos} />
85
+ <Vehicle id="arwing" src={`${VAULT}/cars/starfox_rocket.glb`} position={[startPos[0] + 5, startPos[1] + 0.5, startPos[2]]} />
86
+ <Prop src={`${VAULT}/city/door_hinged_single_900x2100.glb`} position={lotPos} fixed />
87
+
88
+ <Actor ref={actorRef} position={[startPos[0] - 3.2, startPos[1] + 0.8, startPos[2]]} />
89
+ <Toolgun
90
+ actorRef={actorRef}
91
+ defaultArmedAsset={{ id: "supra", name: "Supra A80", src: `${VAULT}/cars/toyota_supra_a80.glb`, kind: "vehicle" }}
92
+ />
25
93
  <Hud />
26
94
  </Game>
27
95
  );
28
96
  }
29
97
  ```
98
+
99
+ ## Subpath Entrypoints
100
+
101
+ - `@pinkaphant/kolmo` — `Game`, `Canvas`, `World`, `Physics`, `Hud`, `Actor`, `Vehicle`, `Prop`, `Surface`, `Terrain`, `Water`, `Toolgun`, plus Koota, `@pinkaphant/ecctrl`, `@khr3/core`, and `@khr3/c12` re-exports
102
+ - `@pinkaphant/kolmo/terrain` — `KolmoTerrain`, `KolmoTerrainField`, `createRollingBasinHeightFn`, `exportTerrainKhrGlb`
103
+ - `@pinkaphant/kolmo/water` — `KolmoWater`, `KolmoWaterField`, `stepWaterHydrodynamics`, `sphericalCapVolume`
104
+ - `@pinkaphant/kolmo/physics` — `KolmoPhysics`, `evaluateNBodyGravity`, `createNBodyGravityField`, `computeCircularOrbitSpeed`
105
+ - `@pinkaphant/kolmo/replay` — `FixedStepAccumulator`, `InputTapeRecorder`, `InputTapePlayer`, `KootaTrajectoryTape`
106
+ - `@pinkaphant/kolmo/toolgun` — `KolmoToolgun`, `useToolgunStore`, `DEFAULT_VAULT_C12_URLS`, `castToolgunRay`, `createWeldImpulseJoint`, `createHingeImpulseJoint`
107
+ - `@pinkaphant/kolmo/vite` — `KOLMO_SINGLETON_DEDUPE`
@@ -10,4 +10,4 @@ export interface KolmoActorProps extends Omit<EcctrlProps, "ref"> {
10
10
  readonly getInput?: KolmoInputGetter;
11
11
  readonly bundle?: KhrAssetBundle | null;
12
12
  }
13
- export declare function KolmoActor({ ref, cameraRef, cameraProps, getInput, bundle, enable, enableCustomGravity, position, rotation, userData, children, ...ecctrlRest }: KolmoActorProps): React.JSX.Element | null;
13
+ export declare function KolmoActor({ ref, cameraRef, cameraProps, getInput, bundle, enable, enableToggleRun, enableCustomGravity, position, rotation, userData, children, ...ecctrlRest }: KolmoActorProps): React.JSX.Element | null;
@@ -6,3 +6,6 @@ export * from "./surface.js";
6
6
  export * from "./world.js";
7
7
  export * from "./gltfLoader.js";
8
8
  export * from "../physics/index.js";
9
+ export * from "../terrain/index.js";
10
+ export * from "../water/index.js";
11
+ export * from "../replay/index.js";