@pinkaphant/create-kolmo 0.4.2 → 0.5.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.
Files changed (78) hide show
  1. package/README.md +56 -17
  2. package/bin/create-kolmo.mjs +20 -12
  3. package/package.json +1 -1
  4. package/templates/demolition/README.md +17 -0
  5. package/templates/demolition/index.html +29 -0
  6. package/templates/demolition/package.json +39 -0
  7. package/templates/demolition/src/App.tsx +599 -0
  8. package/templates/{lonedrive → demolition}/tsconfig.json +4 -2
  9. package/templates/{lonedrive → demolition}/vite.config.ts +3 -1
  10. package/templates/dust/README.md +9 -1
  11. package/templates/dust/index.html +15 -1
  12. package/templates/dust/package.json +8 -6
  13. package/templates/dust/src/App.tsx +106 -122
  14. package/templates/dust/tsconfig.json +4 -2
  15. package/templates/evolution/README.md +15 -0
  16. package/templates/evolution/index.html +29 -0
  17. package/templates/{lonedrive → evolution}/package.json +8 -7
  18. package/templates/evolution/src/App.tsx +619 -0
  19. package/templates/evolution/src/main.tsx +10 -0
  20. package/templates/evolution/src/styles.css +237 -0
  21. package/templates/evolution/tsconfig.json +16 -0
  22. package/templates/evolution/vite.config.ts +10 -0
  23. package/templates/longline/README.md +16 -9
  24. package/templates/longline/index.html +26 -12
  25. package/templates/longline/package.json +11 -9
  26. package/templates/longline/src/App.tsx +191 -42
  27. package/templates/longline/src/highway.ts +222 -0
  28. package/templates/longline/src/main.tsx +7 -6
  29. package/templates/longline/tsconfig.json +14 -16
  30. package/templates/longline/vite.config.ts +5 -23
  31. package/templates/road/README.md +8 -4
  32. package/templates/road/index.html +15 -1
  33. package/templates/road/package.json +5 -5
  34. package/templates/road/src/App.tsx +21 -6
  35. package/templates/road/tsconfig.json +1 -0
  36. package/templates/tugline/README.md +16 -0
  37. package/templates/tugline/index.html +31 -0
  38. package/templates/tugline/package.json +41 -0
  39. package/templates/tugline/src/App.tsx +48 -0
  40. package/templates/{longline → tugline}/src/components/Boat.tsx +1 -2
  41. package/templates/{longline → tugline}/src/components/Crates.tsx +2 -2
  42. package/templates/tugline/src/components/Hud.tsx +281 -0
  43. package/templates/{longline → tugline}/src/components/Longline.tsx +2 -2
  44. package/templates/{longline → tugline}/src/components/Ocean.tsx +14 -3
  45. package/templates/{longline → tugline}/src/components/Radar.tsx +15 -14
  46. package/templates/{longline → tugline}/src/components/Referee.tsx +6 -4
  47. package/templates/{longline → tugline}/src/components/Scene.tsx +10 -9
  48. package/templates/{longline → tugline}/src/components/Sky.tsx +14 -8
  49. package/templates/{longline → tugline}/src/game/store.test.ts +2 -2
  50. package/templates/{longline → tugline}/src/game/store.ts +38 -19
  51. package/templates/tugline/src/main.tsx +13 -0
  52. package/templates/tugline/src/styles.css +495 -0
  53. package/templates/tugline/tsconfig.json +18 -0
  54. package/templates/tugline/vite.config.ts +16 -0
  55. package/templates/lonedrive/README.md +0 -11
  56. package/templates/lonedrive/index.html +0 -15
  57. package/templates/lonedrive/src/App.tsx +0 -149
  58. package/templates/longline/src/components/Hud.tsx +0 -197
  59. package/templates/longline/src/styles.css +0 -367
  60. /package/templates/{lonedrive → demolition}/src/main.tsx +0 -0
  61. /package/templates/{longline → tugline}/src/components/CameraRig.tsx +0 -0
  62. /package/templates/{longline → tugline}/src/components/ocean-material.ts +0 -0
  63. /package/templates/{longline → tugline}/src/components/round-context.ts +0 -0
  64. /package/templates/{longline → tugline}/src/game/boat-control.ts +0 -0
  65. /package/templates/{longline → tugline}/src/game/constants.ts +0 -0
  66. /package/templates/{longline → tugline}/src/game/input.test.ts +0 -0
  67. /package/templates/{longline → tugline}/src/game/input.ts +0 -0
  68. /package/templates/{longline → tugline}/src/game/logic.test.ts +0 -0
  69. /package/templates/{longline → tugline}/src/game/logic.ts +0 -0
  70. /package/templates/{longline → tugline}/src/game/physics.test.ts +0 -0
  71. /package/templates/{longline → tugline}/src/game/radar.ts +0 -0
  72. /package/templates/{longline → tugline}/src/game/registry.ts +0 -0
  73. /package/templates/{longline → tugline}/src/game/sea.ts +0 -0
  74. /package/templates/{longline → tugline}/src/game/session.ts +0 -0
  75. /package/templates/{longline → tugline}/src/game/simulation.test.ts +0 -0
  76. /package/templates/{longline → tugline}/src/game/simulation.ts +0 -0
  77. /package/templates/{longline → tugline}/src/game/test-world.ts +0 -0
  78. /package/templates/{longline → tugline}/src/sfx.ts +0 -0
@@ -1,6 +1,4 @@
1
- import { useEffect, useMemo, useRef } from "react";
2
- import * as THREE from "three";
3
- import { useFrame } from "@react-three/fiber";
1
+ import { useMemo, useRef } from "react";
4
2
  import {
5
3
  ACTOR_GROUND_CLEARANCE,
6
4
  Actor,
@@ -8,146 +6,132 @@ import {
8
6
  Hud,
9
7
  Prop,
10
8
  Radar,
9
+ RoadRibbon,
10
+ Settlement,
11
11
  Terrain,
12
12
  Toolgun,
13
13
  Vehicle,
14
+ Water,
15
+ computeSurfaceSpawnPose,
16
+ radarFootprintsFromBatches,
17
+ radarRoadFromSpline,
18
+ settlementShoulderWidth,
14
19
  type EcctrlHandle,
15
20
  } from "@pinkaphant/kolmo";
16
- import { WaveField, createWaveSpectrum } from "@pinkaphant/kolmo/water";
17
- import { usePhysicsClock } from "@pinkaphant/kolmo/water/react";
21
+ import { instanceBatches, planSettlement } from "@khr3/c12";
18
22
  import { sampleRapierHeightfield } from "@khr3/core";
23
+ import { frontage, roadFromPoints, type V3 } from "@khr3/roads";
19
24
 
20
25
  const VAULT = "https://khr3.optimuspi.workers.dev/assets";
21
- const SEA_SIZE = 576;
22
- const SEA_SEGMENTS = 96;
23
- const SUN = new THREE.Vector3(40, 60, 24).normalize();
24
26
 
25
- const SEA_VERT = /* glsl */ `
26
- uniform float uTime;
27
- uniform vec2 uOrigin;
28
- uniform float uLevel;
29
- uniform vec4 uDirKW[6];
30
- uniform vec4 uAmp[6];
31
- varying vec3 vWorld;
32
-
33
- void main() {
34
- vec2 rest = position.xz + uOrigin;
35
- vec3 p = vec3(rest.x, uLevel, rest.y);
36
- for (int i = 0; i < 6; i++) {
37
- vec4 d = uDirKW[i];
38
- vec4 w = uAmp[i];
39
- float theta = d.z * (d.x * rest.x + d.y * rest.y) - d.w * uTime + w.z;
40
- p.x += w.w * d.x * cos(theta);
41
- p.z += w.w * d.y * cos(theta);
42
- p.y += w.x * sin(theta);
43
- }
44
- vWorld = p;
45
- gl_Position = projectionMatrix * viewMatrix * vec4(p, 1.0);
46
- }
47
- `;
48
-
49
- const SEA_FRAG = /* glsl */ `
50
- uniform vec3 uSun;
51
- uniform float uLevel;
52
- uniform float uCrest;
53
- varying vec3 vWorld;
54
-
55
- void main() {
56
- vec3 n = normalize(cross(dFdx(vWorld), dFdy(vWorld)));
57
- if (n.y < 0.0) n = -n;
58
- float lift = clamp((vWorld.y - uLevel) / max(uCrest, 0.05) * 0.5 + 0.5, 0.0, 1.0);
59
- float diffuse = max(dot(n, uSun), 0.0);
60
- float heightBand = floor(lift * 4.0) / 3.0;
61
- float lightBand = floor(diffuse * 3.0) / 2.0;
62
- vec3 col = mix(vec3(0.024, 0.184, 0.302), vec3(0.082, 0.592, 0.651), clamp(heightBand * 0.65 + lightBand * 0.25, 0.0, 1.0));
63
- float foam = step(0.88, lift) * step(0.35, diffuse);
64
- col = mix(col, vec3(0.949, 0.973, 0.984), foam);
65
- gl_FragColor = vec4(col, 1.0);
66
- #include <colorspace_fragment>
67
- }
68
- `;
27
+ export default function App() {
28
+ const actorRef = useRef<EcctrlHandle>(null);
69
29
 
70
- function islandHeight(x: number, z: number): number {
71
- const r = Math.hypot(x, z);
72
- const ridge = 14 - r * 0.14 + 1.6 * Math.sin(x * 0.045) * Math.cos(z * 0.04);
73
- return Math.max(-5, ridge);
74
- }
30
+ const world = useMemo(() => {
31
+ const spurPoints: V3[] = [
32
+ [-64, 5.2, -32],
33
+ [-28, 7.6, -12],
34
+ [6, 9.2, 8],
35
+ [42, 6.4, 24],
36
+ [74, 2.2, 38],
37
+ ];
38
+ const road = roadFromPoints(spurPoints, 4.0, 2.0);
39
+ const settlement = planSettlement(road, "village", 11, { centerS: 72, setback: 2 });
40
+ const batches = instanceBatches(settlement.pieces);
41
+ const flatRadius = road.halfWidth + 2 + settlementShoulderWidth("village", 2);
75
42
 
76
- function IslandSea() {
77
- const clock = usePhysicsClock();
78
- const { geometry, material } = useMemo(() => {
79
- const field = new WaveField({
80
- level: 0,
81
- waves: createWaveSpectrum({ seed: 11, count: 6, wavelength: 20, amplitude: 0.38, steepness: 0.75 }),
82
- });
83
- const u = field.toUniforms();
84
- const geo = new THREE.PlaneGeometry(SEA_SIZE, SEA_SIZE, SEA_SEGMENTS, SEA_SEGMENTS);
85
- geo.rotateX(-Math.PI / 2);
86
- const mat = new THREE.ShaderMaterial({
87
- vertexShader: SEA_VERT,
88
- fragmentShader: SEA_FRAG,
89
- uniforms: {
90
- uTime: { value: 0 },
91
- uOrigin: { value: new THREE.Vector2(0, 0) },
92
- uLevel: { value: u.level },
93
- uDirKW: { value: u.dirKW },
94
- uAmp: { value: u.ampSteepPhase },
95
- uCrest: { value: field.maxCrest },
96
- uSun: { value: SUN },
97
- },
98
- });
99
- return { geometry: geo, material: mat };
100
- }, []);
43
+ const islandHeight = (x: number, z: number): number => {
44
+ const r = Math.hypot(x, z);
45
+ const ridge =
46
+ 12.5 -
47
+ r * 0.105 +
48
+ 1.8 * Math.sin(x * 0.042) * Math.cos(z * 0.038) +
49
+ 0.75 * Math.cos((x + z) * 0.06);
50
+ const raw = Math.max(-5.5, ridge);
101
51
 
102
- const mountsRef = useRef(0);
103
- useEffect(() => {
104
- mountsRef.current += 1;
105
- return () => {
106
- mountsRef.current -= 1;
107
- queueMicrotask(() => {
108
- if (mountsRef.current === 0) {
109
- geometry.dispose();
110
- material.dispose();
52
+ let bestDist = Infinity;
53
+ let roadY = 0;
54
+ const samples = road.samples;
55
+ for (let i = 0; i < samples.length - 1; i++) {
56
+ const a = samples[i]!;
57
+ const b = samples[i + 1]!;
58
+ const ax = b.pos[0] - a.pos[0];
59
+ const az = b.pos[2] - a.pos[2];
60
+ const lenSq = ax * ax + az * az || 1;
61
+ const t = Math.max(0, Math.min(1, ((x - a.pos[0]) * ax + (z - a.pos[2]) * az) / lenSq));
62
+ const px = a.pos[0] + ax * t;
63
+ const pz = a.pos[2] + az * t;
64
+ const d = Math.hypot(x - px, z - pz);
65
+ if (d < bestDist) {
66
+ bestDist = d;
67
+ roadY = a.pos[1] + (b.pos[1] - a.pos[1]) * t;
111
68
  }
112
- });
69
+ }
70
+
71
+ if (bestDist <= road.halfWidth + 2.5) return roadY;
72
+ if (bestDist < flatRadius) {
73
+ const u = (bestDist - (road.halfWidth + 2.5)) / Math.max(1, flatRadius - (road.halfWidth + 2.5));
74
+ const s = u * u * (3 - 2 * u);
75
+ return roadY + (raw - roadY) * s;
76
+ }
77
+ return raw;
113
78
  };
114
- }, [geometry, material]);
115
79
 
116
- useFrame((state) => {
117
- const cell = SEA_SIZE / SEA_SEGMENTS;
118
- const cam = state.camera.position;
119
- (material.uniforms.uOrigin!.value as THREE.Vector2).set(
120
- Math.round(cam.x / cell) * cell,
121
- Math.round(cam.z / cell) * cell,
122
- );
123
- material.uniforms.uTime!.value = clock.time;
124
- });
80
+ const heights = sampleRapierHeightfield(islandHeight, -192, -192, 384, 384, 128);
81
+ const carPose = computeSurfaceSpawnPose(islandHeight, 12, 6, 0.55, -0.62, 0.04);
82
+ const actor: [number, number, number] = [6, islandHeight(6, 10) + ACTOR_GROUND_CLEARANCE, 10];
83
+ const lots = frontage(road, { spacing: 24, setback: 6 });
84
+ const depotLot = lots[0];
85
+ const canopy: [number, number, number] = depotLot
86
+ ? [depotLot.front[0], depotLot.groundY, depotLot.front[2]]
87
+ : [-24, islandHeight(-24, -6), -6];
88
+ const pump: [number, number, number] = depotLot
89
+ ? [depotLot.front[0] + depotLot.facing[0] * 2.2, depotLot.groundY, depotLot.front[2] + depotLot.facing[2] * 2.2]
90
+ : [-21, islandHeight(-21, -6), -6];
91
+ const shoreSalvageA: [number, number, number] = [84, 0.35, 44];
92
+ const shoreSalvageB: [number, number, number] = [92, 0.35, 34];
125
93
 
126
- return <mesh geometry={geometry} material={material} frustumCulled={false} />;
127
- }
94
+ const radarSpec = {
95
+ range: 120,
96
+ headingUp: true,
97
+ roads: [radarRoadFromSpline(road, { id: "coastal-spur", maxStep: 6 })],
98
+ footprints: radarFootprintsFromBatches(batches),
99
+ };
128
100
 
129
- export default function App() {
130
- const actorRef = useRef<EcctrlHandle>(null);
131
- const world = useMemo(() => {
132
- const heights = sampleRapierHeightfield(islandHeight, -192, -192, 384, 384, 128);
133
- const actor: [number, number, number] = [0, islandHeight(0, 9) + ACTOR_GROUND_CLEARANCE, 9];
134
- const car: [number, number, number] = [9, islandHeight(9, -6), -6];
135
- const outpost: [number, number, number] = [-12, islandHeight(-12, 6), 6];
136
- const pump: [number, number, number] = [-12, islandHeight(-12, 0), 0];
137
- const cache: [number, number, number] = [15, islandHeight(15, 18), 18];
138
- return { heights, actor, car, outpost, pump, cache };
101
+ return {
102
+ road,
103
+ batches,
104
+ heights,
105
+ actor,
106
+ carPose,
107
+ canopy,
108
+ pump,
109
+ shoreSalvageA,
110
+ shoreSalvageB,
111
+ radarSpec,
112
+ };
139
113
  }, []);
140
114
 
141
115
  return (
142
116
  <>
143
- <Game skybox="day">
144
- <Terrain heights={world.heights} segments={128} size={[384, 384]} />
145
- <IslandSea />
117
+ <Game skybox="day" dropSpawn>
118
+ <Terrain heights={world.heights} segments={128} size={[384, 384]} color="#59503f" />
119
+ <Water size={[576, 576]} segments={96} seed={11} wavelength={20} amplitude={0.38} steepness={0.75} />
120
+ <RoadRibbon road={world.road} />
121
+ <Settlement batches={world.batches} />
146
122
  <Actor ref={actorRef} position={world.actor} />
147
- <Vehicle id="scrap" label="Scrap Hatchback" src={`${VAULT}/cars/kolmogorov_hatchback.glb`} position={world.car} />
148
- <Prop id="outpost" src={`${VAULT}/city/gas-canopy-roof.glb`} position={world.outpost} fixed />
149
- <Prop id="pump" src={`${VAULT}/city/gas-pump-twin.glb`} position={world.pump} fixed />
150
- <Prop id="cache" src={`${VAULT}/city/prop_arcade_cabinet.glb`} position={world.cache} fixed />
123
+ <Vehicle
124
+ id="scrap"
125
+ label="Scrap Hatchback"
126
+ src={`${VAULT}/cars/kolmogorov_hatchback.glb`}
127
+ buoyant
128
+ position={world.carPose.position}
129
+ quaternion={world.carPose.quaternion}
130
+ />
131
+ <Prop id="depot-canopy" src={`${VAULT}/city/gas-canopy-roof.glb`} position={world.canopy} fixed />
132
+ <Prop id="depot-pump" src={`${VAULT}/city/gas-pump-twin.glb`} position={world.pump} fixed />
133
+ <Prop id="salvage-a" src={`${VAULT}/city/prop_arcade_cabinet.glb`} position={world.shoreSalvageA} buoyant />
134
+ <Prop id="salvage-b" src={`${VAULT}/city/prop_arcade_cabinet.glb`} position={world.shoreSalvageB} buoyant />
151
135
  <Toolgun
152
136
  src={`${VAULT}/weapons/kolmogorov_pistol.glb`}
153
137
  actorRef={actorRef}
@@ -160,7 +144,7 @@ export default function App() {
160
144
  />
161
145
  </Game>
162
146
  <Hud />
163
- <Radar spec={{ range: 96, headingUp: true }} />
147
+ <Radar spec={world.radarSpec} />
164
148
  </>
165
149
  );
166
150
  }
@@ -6,9 +6,11 @@
6
6
  "moduleResolution": "bundler",
7
7
  "jsx": "react-jsx",
8
8
  "strict": true,
9
+ "noEmit": true,
10
+ "noUnusedLocals": true,
11
+ "noUnusedParameters": true,
9
12
  "skipLibCheck": true,
10
- "isolatedModules": true,
11
- "noEmit": true
13
+ "isolatedModules": true
12
14
  },
13
15
  "include": ["src", "vite.config.ts"]
14
16
  }
@@ -0,0 +1,15 @@
1
+ # Kolmo Evolution Gauntlet
2
+
3
+ 4-byte `uint32` BoxCar3D KHR evolutionary gauntlet built on `@pinkaphant/kolmo/cars`, `@khr3/core`, and `@khr3/roads` ([`./src/App.tsx`](./src/App.tsx)).
4
+
5
+ Compiles 8 simultaneous `0xXXXXXXXX` car genomes (`compileKolmogorovCarBundle`) with full-contact chassis/panel physics, steps deterministic spline-tracking pilots inside `useBeforePhysicsStep`, breeds elites + tournament crossovers (`breedNextGeneration`, `computeGauntletFitness`), tracks the leader or selected car with `maath/easing` `damp3`, and exports any genome directly to a Khronos glTF 2.0 `.glb` (`exportKolmogorovCarGlb`).
6
+
7
+ - **Space**: Pause / resume simulation
8
+ - **1** / **2** / **4**: Set `1x`, `2x`, or `4x` physics time scale
9
+ - **Click any `#1..#8` genome row**: Lock camera & inspect `describeKolmogorovGene` spec
10
+ - **INJECT HEX**: Splice any `0x00000000..0xFFFFFFFF` gene into the active slot
11
+ - **EXPORT .GLB**: Download a spec-valid `KHR_physics_rigid_bodies` + `OMI_vehicle_*` `.glb`
12
+
13
+ ```bash
14
+ npm create @pinkaphant/kolmo@latest my-evolution -- --template evolution
15
+ ```
@@ -0,0 +1,29 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
6
+ <title>Kolmo Evolution</title>
7
+ <link rel="preconnect" href="https://fonts.googleapis.com" />
8
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
9
+ <link
10
+ href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@500;600&family=Space+Grotesk:wght@500;600;700&display=swap"
11
+ rel="stylesheet"
12
+ />
13
+ <style>
14
+ html, body, #root {
15
+ margin: 0;
16
+ width: 100%;
17
+ height: 100%;
18
+ overflow: hidden;
19
+ background: oklch(13.5% 0.007 265);
20
+ font-family: "Space Grotesk", system-ui, sans-serif;
21
+ font-variant-numeric: tabular-nums;
22
+ }
23
+ </style>
24
+ </head>
25
+ <body>
26
+ <div id="root"></div>
27
+ <script type="module" src="/src/main.tsx"></script>
28
+ </body>
29
+ </html>
@@ -1,8 +1,8 @@
1
1
  {
2
- "name": "lonedrive",
2
+ "name": "kolmo-evolution",
3
3
  "version": "0.1.0",
4
4
  "private": true,
5
- "description": "Lonedrive: an 8.1 km streamed desert highway on a 3 m grid, roadside gas stops, and one car on @pinkaphant/kolmo.",
5
+ "description": "Evolution: 4-byte uint32 BoxCar3D KHR evolutionary gauntlet on @pinkaphant/kolmo, @khr3/core, and @khr3/roads.",
6
6
  "type": "module",
7
7
  "scripts": {
8
8
  "dev": "vite",
@@ -12,14 +12,15 @@
12
12
  },
13
13
  "dependencies": {
14
14
  "@dimforge/rapier3d-compat": "0.19.2",
15
- "@khr3/core": "^0.2.20",
15
+ "@khr3/core": "^0.2.21",
16
16
  "@khr3/roads": "^0.1.2",
17
17
  "@pinkaphant/ecctrl": "2.0.4-beta.9",
18
- "@pinkaphant/kolmo": "^0.14.0",
18
+ "@pinkaphant/kolmo": "^0.15.0",
19
19
  "@react-three/drei": "^10.7.7",
20
20
  "@react-three/fiber": "^9.6.1",
21
21
  "@react-three/rapier": "^2.2.0",
22
22
  "koota": "^0.6.6",
23
+ "maath": "^0.10.8",
23
24
  "react": "^19.2.7",
24
25
  "react-dom": "^19.2.7",
25
26
  "three": "0.184.0"
@@ -33,8 +34,8 @@
33
34
  "@types/react": "^19.2.16",
34
35
  "@types/react-dom": "^19.2.3",
35
36
  "@types/three": "0.184.0",
36
- "@vitejs/plugin-react": "^6.1.1",
37
- "typescript": "^7.0.2",
38
- "vite": "^8.3.0"
37
+ "@vitejs/plugin-react": "^6.3.1",
38
+ "typescript": "^5.8.3",
39
+ "vite": "^8.4.1"
39
40
  }
40
41
  }