@pinkaphant/create-kolmo 0.4.1 → 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.
- package/README.md +56 -17
- package/bin/create-kolmo.mjs +20 -12
- package/package.json +1 -1
- package/templates/demolition/README.md +17 -0
- package/templates/demolition/index.html +29 -0
- package/templates/demolition/package.json +39 -0
- package/templates/demolition/src/App.tsx +599 -0
- package/templates/{lonedrive → demolition}/tsconfig.json +4 -2
- package/templates/{lonedrive → demolition}/vite.config.ts +3 -1
- package/templates/dust/README.md +9 -1
- package/templates/dust/index.html +15 -1
- package/templates/dust/package.json +8 -6
- package/templates/dust/src/App.tsx +106 -122
- package/templates/dust/tsconfig.json +4 -2
- package/templates/evolution/README.md +15 -0
- package/templates/evolution/index.html +29 -0
- package/templates/{lonedrive → evolution}/package.json +8 -7
- package/templates/evolution/src/App.tsx +619 -0
- package/templates/evolution/src/main.tsx +10 -0
- package/templates/evolution/src/styles.css +237 -0
- package/templates/evolution/tsconfig.json +16 -0
- package/templates/evolution/vite.config.ts +10 -0
- package/templates/longline/README.md +16 -9
- package/templates/longline/index.html +26 -12
- package/templates/longline/package.json +11 -9
- package/templates/longline/src/App.tsx +191 -42
- package/templates/longline/src/highway.ts +222 -0
- package/templates/longline/src/main.tsx +7 -6
- package/templates/longline/tsconfig.json +14 -16
- package/templates/longline/vite.config.ts +5 -23
- package/templates/road/README.md +8 -4
- package/templates/road/index.html +15 -1
- package/templates/road/package.json +5 -5
- package/templates/road/src/App.tsx +21 -6
- package/templates/road/tsconfig.json +1 -0
- package/templates/tugline/README.md +16 -0
- package/templates/tugline/index.html +31 -0
- package/templates/tugline/package.json +41 -0
- package/templates/tugline/src/App.tsx +48 -0
- package/templates/{longline → tugline}/src/components/Boat.tsx +1 -2
- package/templates/{longline → tugline}/src/components/Crates.tsx +2 -2
- package/templates/tugline/src/components/Hud.tsx +281 -0
- package/templates/{longline → tugline}/src/components/Longline.tsx +2 -2
- package/templates/{longline → tugline}/src/components/Ocean.tsx +14 -3
- package/templates/{longline → tugline}/src/components/Radar.tsx +15 -14
- package/templates/{longline → tugline}/src/components/Referee.tsx +6 -4
- package/templates/{longline → tugline}/src/components/Scene.tsx +10 -9
- package/templates/{longline → tugline}/src/components/Sky.tsx +14 -8
- package/templates/{longline → tugline}/src/game/store.test.ts +2 -2
- package/templates/{longline → tugline}/src/game/store.ts +38 -19
- package/templates/tugline/src/main.tsx +13 -0
- package/templates/tugline/src/styles.css +495 -0
- package/templates/tugline/tsconfig.json +18 -0
- package/templates/tugline/vite.config.ts +16 -0
- package/templates/lonedrive/README.md +0 -11
- package/templates/lonedrive/index.html +0 -15
- package/templates/lonedrive/src/App.tsx +0 -149
- package/templates/longline/src/components/Hud.tsx +0 -197
- package/templates/longline/src/styles.css +0 -367
- /package/templates/{lonedrive → demolition}/src/main.tsx +0 -0
- /package/templates/{longline → tugline}/src/components/CameraRig.tsx +0 -0
- /package/templates/{longline → tugline}/src/components/ocean-material.ts +0 -0
- /package/templates/{longline → tugline}/src/components/round-context.ts +0 -0
- /package/templates/{longline → tugline}/src/game/boat-control.ts +0 -0
- /package/templates/{longline → tugline}/src/game/constants.ts +0 -0
- /package/templates/{longline → tugline}/src/game/input.test.ts +0 -0
- /package/templates/{longline → tugline}/src/game/input.ts +0 -0
- /package/templates/{longline → tugline}/src/game/logic.test.ts +0 -0
- /package/templates/{longline → tugline}/src/game/logic.ts +0 -0
- /package/templates/{longline → tugline}/src/game/physics.test.ts +0 -0
- /package/templates/{longline → tugline}/src/game/radar.ts +0 -0
- /package/templates/{longline → tugline}/src/game/registry.ts +0 -0
- /package/templates/{longline → tugline}/src/game/sea.ts +0 -0
- /package/templates/{longline → tugline}/src/game/session.ts +0 -0
- /package/templates/{longline → tugline}/src/game/simulation.test.ts +0 -0
- /package/templates/{longline → tugline}/src/game/simulation.ts +0 -0
- /package/templates/{longline → tugline}/src/game/test-world.ts +0 -0
- /package/templates/{longline → tugline}/src/sfx.ts +0 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computeSplineSpawnPose,
|
|
3
|
+
type SurfaceSpawnPose,
|
|
4
|
+
} from "@pinkaphant/kolmo";
|
|
5
|
+
import {
|
|
6
|
+
childSeed,
|
|
7
|
+
fbm2,
|
|
8
|
+
makeTerrain,
|
|
9
|
+
roadFromPoints,
|
|
10
|
+
sampleRapierHeightfield,
|
|
11
|
+
type Road,
|
|
12
|
+
type V3,
|
|
13
|
+
} from "@khr3/roads";
|
|
14
|
+
|
|
15
|
+
export const VAULT = "https://khr3.optimuspi.workers.dev/assets";
|
|
16
|
+
export const CHUNK_SIZE = 288;
|
|
17
|
+
export const CHUNK_SEGMENTS = 96;
|
|
18
|
+
export const HIGHWAY_HALF_WIDTH = 4.5;
|
|
19
|
+
export const HIGHWAY_SEED = 14;
|
|
20
|
+
export const MAX_CACHED_CHUNKS = 9;
|
|
21
|
+
|
|
22
|
+
const CONTROL_STEP_Z = 72;
|
|
23
|
+
const STOP_PERIOD_SECTORS = 3; // 864 m between roadside fuel/salvage stops
|
|
24
|
+
|
|
25
|
+
const SWAP_VEHICLES = [
|
|
26
|
+
{ id: "r34", label: "Salvage R34", src: `${VAULT}/cars/nissan_skyline_r34.glb` },
|
|
27
|
+
{ id: "hatch", label: "Desert Hatchback", src: `${VAULT}/cars/kolmogorov_hatchback.glb` },
|
|
28
|
+
{ id: "s15", label: "Roadside S15", src: `${VAULT}/cars/nissan_silvia_s15.glb` },
|
|
29
|
+
] as const;
|
|
30
|
+
|
|
31
|
+
export interface HighwayStopSpec {
|
|
32
|
+
readonly key: string;
|
|
33
|
+
readonly canopyPos: [number, number, number];
|
|
34
|
+
readonly pumpPos: [number, number, number];
|
|
35
|
+
readonly signPos: [number, number, number];
|
|
36
|
+
readonly swapVehicle: {
|
|
37
|
+
readonly id: string;
|
|
38
|
+
readonly label: string;
|
|
39
|
+
readonly src: string;
|
|
40
|
+
readonly pose: SurfaceSpawnPose;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface HighwaySectorChunk {
|
|
45
|
+
readonly sectorZ: number;
|
|
46
|
+
readonly road: Road;
|
|
47
|
+
readonly grid: ReadonlyArray<{
|
|
48
|
+
readonly key: string;
|
|
49
|
+
readonly heights: Float32Array;
|
|
50
|
+
readonly position: [number, number, number];
|
|
51
|
+
}>;
|
|
52
|
+
readonly stop: HighwayStopSpec | null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const lateralSeed = childSeed(HIGHWAY_SEED, "highway-x");
|
|
56
|
+
const elevationSeed = childSeed(HIGHWAY_SEED, "highway-y");
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Forever-straight-with-gentle-drift centerline for `z in (-infinity, +infinity)`.
|
|
60
|
+
* Purely closed-form in `z`, so adjacent `288 m` sectors join with $C^2$-smooth control points and zero seams.
|
|
61
|
+
*/
|
|
62
|
+
export function highwayCenterAtZ(z: number): V3 {
|
|
63
|
+
const driftX =
|
|
64
|
+
22 * Math.sin(z * 0.00145) +
|
|
65
|
+
9.5 * Math.cos(z * 0.0034) +
|
|
66
|
+
14 * fbm2(lateralSeed, z * 0.15, 0, { wavelength: 420, octaves: 3, gain: 0.5, lacunarity: 2 });
|
|
67
|
+
const crestY =
|
|
68
|
+
4.0 +
|
|
69
|
+
9.5 * Math.sin(z * 0.0021) +
|
|
70
|
+
4.2 * Math.cos(z * 0.0053) +
|
|
71
|
+
11 * fbm2(elevationSeed, 0, z * 0.18, { wavelength: 520, octaves: 3, gain: 0.5, lacunarity: 2 });
|
|
72
|
+
return [driftX, crestY, z];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Builds a `@khr3/roads` spline spanning `[zMin, zMax]` with padding control points on both ends
|
|
77
|
+
* so Catmull-Rom tangents match neighboring sectors identically at `zMin` and `zMax`.
|
|
78
|
+
*/
|
|
79
|
+
export function buildSectorRoad(sectorZ: number, spanSectors = 1): Road {
|
|
80
|
+
const zStart = sectorZ * CHUNK_SIZE;
|
|
81
|
+
const zEnd = (sectorZ + spanSectors) * CHUNK_SIZE;
|
|
82
|
+
const pts: V3[] = [];
|
|
83
|
+
for (let z = zStart - CONTROL_STEP_Z; z <= zEnd + CONTROL_STEP_Z + 1e-6; z += CONTROL_STEP_Z) {
|
|
84
|
+
pts.push(highwayCenterAtZ(z));
|
|
85
|
+
}
|
|
86
|
+
const full = roadFromPoints(pts, HIGHWAY_HALF_WIDTH, 3);
|
|
87
|
+
const clippedSamples = full.samples.filter((s) => s.pos[2] >= zStart - 0.5 && s.pos[2] <= zEnd + 0.5);
|
|
88
|
+
if (clippedSamples.length >= 2) {
|
|
89
|
+
const subPts: V3[] = [];
|
|
90
|
+
for (let z = zStart; z <= zEnd + 1e-6; z += 24) {
|
|
91
|
+
subPts.push(highwayCenterAtZ(z));
|
|
92
|
+
}
|
|
93
|
+
return roadFromPoints(subPts, HIGHWAY_HALF_WIDTH, 3);
|
|
94
|
+
}
|
|
95
|
+
return full;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Bounded LRU cache (`<= MAX_CACHED_CHUNKS` = 9) storing Rapier column-major `Float32Array` terrain tiles.
|
|
100
|
+
*/
|
|
101
|
+
export class HighwayChunkCache {
|
|
102
|
+
private readonly map = new Map<string, Float32Array>();
|
|
103
|
+
|
|
104
|
+
constructor(private readonly maxEntries = MAX_CACHED_CHUNKS) {}
|
|
105
|
+
|
|
106
|
+
get size(): number {
|
|
107
|
+
return this.map.size;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
getOrBuild(key: string, build: () => Float32Array): Float32Array {
|
|
111
|
+
const hit = this.map.get(key);
|
|
112
|
+
if (hit !== undefined) {
|
|
113
|
+
this.map.delete(key);
|
|
114
|
+
this.map.set(key, hit);
|
|
115
|
+
return hit;
|
|
116
|
+
}
|
|
117
|
+
const created = build();
|
|
118
|
+
this.map.set(key, created);
|
|
119
|
+
while (this.map.size > this.maxEntries) {
|
|
120
|
+
const oldestKey = this.map.keys().next().value;
|
|
121
|
+
if (oldestKey === undefined) break;
|
|
122
|
+
this.map.delete(oldestKey);
|
|
123
|
+
}
|
|
124
|
+
return created;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Builds the 3 sectors `[centerSectorZ - 1, centerSectorZ, centerSectorZ + 1]` around the active `Z` sector:
|
|
130
|
+
* - Continuous `@khr3/roads` corridor spline + graded desert terrain (`minShoulder: 16 m` for gas stops)
|
|
131
|
+
* - 3x3 (`9`) `288 m` heightfield chunks centered on the corridor's X sector and `[cz - 1, cz, cz + 1]`
|
|
132
|
+
* - Deterministic roadside gas canopy + twin fuel pump + petro sign + swap car every `STOP_PERIOD_SECTORS`
|
|
133
|
+
*/
|
|
134
|
+
export function buildActiveHighwayWindow(
|
|
135
|
+
centerSectorZ: number,
|
|
136
|
+
cache: HighwayChunkCache,
|
|
137
|
+
): {
|
|
138
|
+
readonly corridorRoad: Road;
|
|
139
|
+
readonly chunks: ReadonlyArray<{
|
|
140
|
+
readonly key: string;
|
|
141
|
+
readonly heights: Float32Array;
|
|
142
|
+
readonly position: [number, number, number];
|
|
143
|
+
}>;
|
|
144
|
+
readonly stops: ReadonlyArray<HighwayStopSpec>;
|
|
145
|
+
} {
|
|
146
|
+
const zWindowStart = (centerSectorZ - 2) * CHUNK_SIZE;
|
|
147
|
+
const zWindowEnd = (centerSectorZ + 3) * CHUNK_SIZE;
|
|
148
|
+
const pts: V3[] = [];
|
|
149
|
+
for (let z = zWindowStart; z <= zWindowEnd + 1e-6; z += CONTROL_STEP_Z) {
|
|
150
|
+
pts.push(highwayCenterAtZ(z));
|
|
151
|
+
}
|
|
152
|
+
const corridorLandRoad = roadFromPoints(pts, HIGHWAY_HALF_WIDTH, 3);
|
|
153
|
+
const land = makeTerrain(HIGHWAY_SEED, corridorLandRoad, {
|
|
154
|
+
amplitude: 16,
|
|
155
|
+
noise: { wavelength: 216, octaves: 4, gain: 0.5, lacunarity: 2 },
|
|
156
|
+
maxSlope: 0.44,
|
|
157
|
+
minShoulder: 16,
|
|
158
|
+
verge: 12,
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const visiblePts: V3[] = [];
|
|
162
|
+
const zVisStart = (centerSectorZ - 1) * CHUNK_SIZE;
|
|
163
|
+
const zVisEnd = (centerSectorZ + 2) * CHUNK_SIZE;
|
|
164
|
+
for (let z = zVisStart; z <= zVisEnd + 1e-6; z += 18) {
|
|
165
|
+
visiblePts.push(highwayCenterAtZ(z));
|
|
166
|
+
}
|
|
167
|
+
const corridorRoad = roadFromPoints(visiblePts, HIGHWAY_HALF_WIDTH, 3);
|
|
168
|
+
|
|
169
|
+
const centerX = highwayCenterAtZ((centerSectorZ + 0.5) * CHUNK_SIZE)[0];
|
|
170
|
+
const centerSectorX = Math.floor(centerX / CHUNK_SIZE);
|
|
171
|
+
|
|
172
|
+
const chunks: Array<{ key: string; heights: Float32Array; position: [number, number, number] }> = [];
|
|
173
|
+
for (let dz = -1; dz <= 1; dz++) {
|
|
174
|
+
const cz = centerSectorZ + dz;
|
|
175
|
+
for (let dx = -1; dx <= 1; dx++) {
|
|
176
|
+
const cx = centerSectorX + dx;
|
|
177
|
+
const key = `${cx},${cz}`;
|
|
178
|
+
const heights = cache.getOrBuild(key, () =>
|
|
179
|
+
sampleRapierHeightfield(land, [cx * CHUNK_SIZE, 0, cz * CHUNK_SIZE], CHUNK_SIZE, CHUNK_SEGMENTS),
|
|
180
|
+
);
|
|
181
|
+
chunks.push({
|
|
182
|
+
key,
|
|
183
|
+
heights,
|
|
184
|
+
position: [(cx + 0.5) * CHUNK_SIZE, 0, (cz + 0.5) * CHUNK_SIZE],
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const stops: HighwayStopSpec[] = [];
|
|
190
|
+
for (let dz = -1; dz <= 1; dz++) {
|
|
191
|
+
const cz = centerSectorZ + dz;
|
|
192
|
+
if (cz < 0 || cz % STOP_PERIOD_SECTORS !== 1) continue;
|
|
193
|
+
const stopRoad = buildSectorRoad(cz, 1);
|
|
194
|
+
const midS = stopRoad.length * 0.5;
|
|
195
|
+
const sample = stopRoad.at(midS);
|
|
196
|
+
const rightX = -sample.left[0];
|
|
197
|
+
const rightZ = -sample.left[2];
|
|
198
|
+
const fwdX = sample.tangent[0];
|
|
199
|
+
const fwdZ = sample.tangent[2];
|
|
200
|
+
const padLat = HIGHWAY_HALF_WIDTH + 7.5;
|
|
201
|
+
const baseX = sample.pos[0] + rightX * padLat;
|
|
202
|
+
const baseY = sample.pos[1];
|
|
203
|
+
const baseZ = sample.pos[2] + rightZ * padLat;
|
|
204
|
+
const swapSpec = SWAP_VEHICLES[Math.abs(cz) % SWAP_VEHICLES.length]!;
|
|
205
|
+
const swapPose = computeSplineSpawnPose(stopRoad, Math.min(stopRoad.length - 12, midS + 11), -(HIGHWAY_HALF_WIDTH + 5.2), -0.64, 0.04);
|
|
206
|
+
|
|
207
|
+
stops.push({
|
|
208
|
+
key: `stop-${cz}`,
|
|
209
|
+
canopyPos: [baseX, baseY, baseZ],
|
|
210
|
+
pumpPos: [baseX - rightX * 1.6, baseY, baseZ - rightZ * 1.6],
|
|
211
|
+
signPos: [baseX + fwdX * 8.5 - rightX * 2.2, baseY, baseZ + fwdZ * 8.5 - rightZ * 2.2],
|
|
212
|
+
swapVehicle: {
|
|
213
|
+
id: `swap-${cz}-${swapSpec.id}`,
|
|
214
|
+
label: swapSpec.label,
|
|
215
|
+
src: swapSpec.src,
|
|
216
|
+
pose: swapPose,
|
|
217
|
+
},
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return { corridorRoad, chunks, stops };
|
|
222
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
1
2
|
import { createRoot } from "react-dom/client";
|
|
2
|
-
import
|
|
3
|
-
import { game, helm } from "./game/session.js";
|
|
4
|
-
import "./styles.css";
|
|
3
|
+
import App from "./App.js";
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
createRoot(document.getElementById("root")!).render(
|
|
6
|
+
<React.StrictMode>
|
|
7
|
+
<App />
|
|
8
|
+
</React.StrictMode>,
|
|
9
|
+
);
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
-
"include": ["src", "vite.config.ts"]
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"moduleResolution": "bundler",
|
|
7
|
+
"jsx": "react-jsx",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"noEmit": true,
|
|
10
|
+
"noUnusedLocals": true,
|
|
11
|
+
"noUnusedParameters": true,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"isolatedModules": true
|
|
14
|
+
},
|
|
15
|
+
"include": ["src", "vite.config.ts"]
|
|
18
16
|
}
|
|
@@ -1,28 +1,10 @@
|
|
|
1
1
|
import react from "@vitejs/plugin-react";
|
|
2
2
|
import { defineConfig } from "vite";
|
|
3
|
+
import { KOLMO_SINGLETON_DEDUPE } from "@pinkaphant/kolmo/vite";
|
|
3
4
|
|
|
4
|
-
// One copy of each of these in the bundle: react-three-fiber, react-three-rapier and Kolmo's water hooks all talk to the
|
|
5
|
-
// same three, the same Rapier world and the same React.
|
|
6
5
|
export default defineConfig({
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
optimizeDeps: {
|
|
12
|
-
exclude: ["@dimforge/rapier3d-compat"],
|
|
13
|
-
},
|
|
14
|
-
build: {
|
|
15
|
-
chunkSizeWarningLimit: 2600,
|
|
16
|
-
rolldownOptions: {
|
|
17
|
-
output: {
|
|
18
|
-
codeSplitting: {
|
|
19
|
-
groups: [
|
|
20
|
-
{ name: "three", test: /node_modules[\\/]three/ },
|
|
21
|
-
{ name: "rapier", test: /node_modules[\\/](@dimforge[\\/]rapier3d-compat|@react-three[\\/]rapier)/ },
|
|
22
|
-
{ name: "r3f", test: /node_modules[\\/]@react-three[\\/]fiber/ },
|
|
23
|
-
],
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
},
|
|
6
|
+
plugins: [react()],
|
|
7
|
+
resolve: {
|
|
8
|
+
dedupe: KOLMO_SINGLETON_DEDUPE,
|
|
9
|
+
},
|
|
28
10
|
});
|
package/templates/road/README.md
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
# Kolmo Road Sandbox
|
|
2
2
|
|
|
3
|
-
Seeded `@khr3/roads` spline carriageway (`<RoadRibbon>`), cyclotomic `@khr3/c12` village (`<Settlement>`), Skyline R34, on-foot pilot controller, `<Toolgun>`, `<Radar>`, and
|
|
3
|
+
Seeded `@khr3/roads` spline carriageway (`<RoadRibbon>`), cyclotomic `@khr3/c12` village (`<Settlement>`), roadside `<Prop>` structures, spline-aligned Skyline R34 (`computeSplineSpawnPose`), on-foot pilot `<Actor>` controller, `<Toolgun>`, `<Radar>`, and `<Game dropSpawn>` `.glb` drop-to-drive ([`./src/App.tsx`](./src/App.tsx)).
|
|
4
4
|
|
|
5
5
|
- **WASD** / **Arrows**: Move or drive
|
|
6
|
-
- **Space**: Jump (on foot) /
|
|
7
|
-
- **
|
|
6
|
+
- **Space**: Jump (on foot) / brake (vehicle)
|
|
7
|
+
- **C**: Brake
|
|
8
|
+
- **Shift**: Sprint (on foot) / boost (vehicle)
|
|
8
9
|
- **E** / **F**: Board or exit vehicle
|
|
9
10
|
- **R**: Flip vehicle upright
|
|
11
|
+
- **V**: Toggle FPS / TPS camera
|
|
12
|
+
- **L**: Toggle vehicle headlights
|
|
13
|
+
- **N**: Cycle day / dusk / night sky
|
|
14
|
+
- **O** or **Drag & Drop `.glb`**: Auto-rig, spawn, and board any car `.glb`
|
|
10
15
|
- **T** / **Right-Click**: Spawn armed vehicle
|
|
11
|
-
- **Drag & Drop `.glb`**: Auto-rig, spawn, and board any car `.glb`
|
|
12
16
|
|
|
13
17
|
```bash
|
|
14
18
|
npm create @pinkaphant/kolmo@latest my-road-game
|
|
@@ -4,8 +4,22 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
|
|
6
6
|
<title>Kolmo Road</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
|
+
/>
|
|
7
13
|
<style>
|
|
8
|
-
html, body, #root {
|
|
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
|
+
}
|
|
9
23
|
</style>
|
|
10
24
|
</head>
|
|
11
25
|
<body>
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@dimforge/rapier3d-compat": "0.19.2",
|
|
15
15
|
"@khr3/c12": "^0.4.0",
|
|
16
|
-
"@khr3/core": "^0.2.
|
|
16
|
+
"@khr3/core": "^0.2.21",
|
|
17
17
|
"@khr3/roads": "^0.1.2",
|
|
18
18
|
"@pinkaphant/ecctrl": "2.0.4-beta.9",
|
|
19
|
-
"@pinkaphant/kolmo": "^0.
|
|
19
|
+
"@pinkaphant/kolmo": "^0.15.0",
|
|
20
20
|
"@react-three/drei": "^10.7.7",
|
|
21
21
|
"@react-three/fiber": "^9.6.1",
|
|
22
22
|
"@react-three/rapier": "^2.2.0",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"@types/react": "^19.2.16",
|
|
35
35
|
"@types/react-dom": "^19.2.3",
|
|
36
36
|
"@types/three": "0.184.0",
|
|
37
|
-
"@vitejs/plugin-react": "^6.
|
|
38
|
-
"typescript": "^
|
|
39
|
-
"vite": "^8.
|
|
37
|
+
"@vitejs/plugin-react": "^6.3.1",
|
|
38
|
+
"typescript": "^5.8.3",
|
|
39
|
+
"vite": "^8.4.1"
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
Terrain,
|
|
12
12
|
Toolgun,
|
|
13
13
|
Vehicle,
|
|
14
|
+
computeSplineSpawnPose,
|
|
14
15
|
radarFootprintsFromBatches,
|
|
15
16
|
radarRoadFromSpline,
|
|
16
17
|
settlementShoulderWidth,
|
|
@@ -24,7 +25,7 @@ const VAULT = "https://khr3.optimuspi.workers.dev/assets";
|
|
|
24
25
|
export default function App() {
|
|
25
26
|
const actorRef = useRef<EcctrlHandle>(null);
|
|
26
27
|
|
|
27
|
-
const { road, heights, batches, radarSpec,
|
|
28
|
+
const { road, heights, batches, radarSpec, r34Pose, actorPos, canopyPos, pumpPos } = useMemo(() => {
|
|
28
29
|
const builtRoad = growRoad(42, {
|
|
29
30
|
length: 540,
|
|
30
31
|
halfWidth: 4.5,
|
|
@@ -45,7 +46,10 @@ export default function App() {
|
|
|
45
46
|
verge: 4,
|
|
46
47
|
});
|
|
47
48
|
const hf = sampleRapierHeightfield(land, [-192, 0, -192], 384, 128);
|
|
48
|
-
const
|
|
49
|
+
const spawnPose = computeSplineSpawnPose(builtRoad, 36, 0, -0.64, 0.03);
|
|
50
|
+
const s0 = builtRoad.at(36);
|
|
51
|
+
const lx = s0.left[0];
|
|
52
|
+
const lz = s0.left[2];
|
|
49
53
|
const lots = frontage(builtRoad, { spacing: 24, setback: 7 });
|
|
50
54
|
const lotA = lots[0];
|
|
51
55
|
const lotB = lots[1];
|
|
@@ -60,7 +64,12 @@ export default function App() {
|
|
|
60
64
|
heights: hf,
|
|
61
65
|
batches: c12Batches,
|
|
62
66
|
radarSpec: spec,
|
|
63
|
-
|
|
67
|
+
r34Pose: spawnPose,
|
|
68
|
+
actorPos: [
|
|
69
|
+
s0.pos[0] + lx * 3.0,
|
|
70
|
+
s0.pos[1] + ACTOR_GROUND_CLEARANCE,
|
|
71
|
+
s0.pos[2] + lz * 3.0,
|
|
72
|
+
] as [number, number, number],
|
|
64
73
|
canopyPos: lotA
|
|
65
74
|
? ([lotA.front[0], lotA.groundY, lotA.front[2]] as [number, number, number])
|
|
66
75
|
: ([12, 0, -120] as [number, number, number]),
|
|
@@ -72,14 +81,20 @@ export default function App() {
|
|
|
72
81
|
|
|
73
82
|
return (
|
|
74
83
|
<>
|
|
75
|
-
<Game skybox="day">
|
|
84
|
+
<Game skybox="day" dropSpawn>
|
|
76
85
|
<Terrain heights={heights} segments={128} size={[384, 384]} />
|
|
77
86
|
<RoadRibbon road={road} />
|
|
78
87
|
<Settlement batches={batches} />
|
|
79
|
-
<Vehicle
|
|
88
|
+
<Vehicle
|
|
89
|
+
id="r34"
|
|
90
|
+
label="Skyline R34"
|
|
91
|
+
src={`${VAULT}/cars/nissan_skyline_r34.glb`}
|
|
92
|
+
position={r34Pose.position}
|
|
93
|
+
quaternion={r34Pose.quaternion}
|
|
94
|
+
/>
|
|
80
95
|
<Prop id="canopy" src={`${VAULT}/city/gas-canopy-roof.glb`} position={canopyPos} fixed />
|
|
81
96
|
<Prop id="pump" src={`${VAULT}/city/gas-pump-twin.glb`} position={pumpPos} fixed />
|
|
82
|
-
<Actor ref={actorRef} position={
|
|
97
|
+
<Actor ref={actorRef} position={actorPos} />
|
|
83
98
|
<Toolgun
|
|
84
99
|
src={`${VAULT}/weapons/kolmogorov_pistol.glb`}
|
|
85
100
|
actorRef={actorRef}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Tugline
|
|
2
|
+
|
|
3
|
+
90-second Gerstner ocean tugboat and tow-line arcade game built on `@pinkaphant/kolmo/water`, `@khr3/core` `<PhysicsWorld>`, React Three Fiber, and Rapier ([`./src/App.tsx`](./src/App.tsx), [`./src/game/simulation.ts`](./src/game/simulation.ts)).
|
|
4
|
+
|
|
5
|
+
- **WASD** / **Arrows**: Ahead, astern, port, starboard
|
|
6
|
+
- **1** / **2** / **3**: Select `Calm`, `Choppy`, or `Rough` sea state
|
|
7
|
+
- **Enter**: Launch round
|
|
8
|
+
- **Space**: Pause / resume physics
|
|
9
|
+
- **R**: Restart round
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm create @pinkaphant/kolmo@latest my-tugline -- --template tugline
|
|
13
|
+
cd my-tugline
|
|
14
|
+
npm test
|
|
15
|
+
npm run dev
|
|
16
|
+
```
|
|
@@ -0,0 +1,31 @@
|
|
|
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, user-scalable=no" />
|
|
6
|
+
<meta name="theme-color" content="#1e2028" />
|
|
7
|
+
<meta name="description" content="Tugline: tow a line of floats across a rolling Gerstner sea and haul in drifting crates on @pinkaphant/kolmo." />
|
|
8
|
+
<title>Tugline</title>
|
|
9
|
+
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
10
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
11
|
+
<link
|
|
12
|
+
href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@500;600&family=Space+Grotesk:wght@500;600;700&display=swap"
|
|
13
|
+
rel="stylesheet"
|
|
14
|
+
/>
|
|
15
|
+
<style>
|
|
16
|
+
html, body, #root {
|
|
17
|
+
margin: 0;
|
|
18
|
+
width: 100%;
|
|
19
|
+
height: 100%;
|
|
20
|
+
overflow: hidden;
|
|
21
|
+
background: oklch(13.5% 0.007 265);
|
|
22
|
+
font-family: "Space Grotesk", system-ui, sans-serif;
|
|
23
|
+
font-variant-numeric: tabular-nums;
|
|
24
|
+
}
|
|
25
|
+
</style>
|
|
26
|
+
</head>
|
|
27
|
+
<body>
|
|
28
|
+
<div id="root"><p class="loading">INITIALIZING SEA…</p></div>
|
|
29
|
+
<script type="module" src="/src/main.tsx"></script>
|
|
30
|
+
</body>
|
|
31
|
+
</html>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tugline-game",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "Tugline: Gerstner sea tugboat and tow-line arcade game on @pinkaphant/kolmo and @khr3/core.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"dev": "vite",
|
|
9
|
+
"typecheck": "tsc --noEmit",
|
|
10
|
+
"build": "tsc --noEmit && vite build",
|
|
11
|
+
"preview": "vite preview",
|
|
12
|
+
"test": "node --import tsx --test \"src/**/*.test.ts\""
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@dimforge/rapier3d-compat": "0.19.2",
|
|
16
|
+
"@khr3/core": "^0.2.21",
|
|
17
|
+
"@pinkaphant/ecctrl": "2.0.4-beta.9",
|
|
18
|
+
"@pinkaphant/kolmo": "^0.15.0",
|
|
19
|
+
"@react-three/drei": "^10.7.7",
|
|
20
|
+
"@react-three/fiber": "^9.6.1",
|
|
21
|
+
"@react-three/rapier": "^2.2.0",
|
|
22
|
+
"react": "^19.2.7",
|
|
23
|
+
"react-dom": "^19.2.7",
|
|
24
|
+
"three": "0.184.0"
|
|
25
|
+
},
|
|
26
|
+
"overrides": {
|
|
27
|
+
"@dimforge/rapier3d-compat": "0.19.2",
|
|
28
|
+
"@pinkaphant/ecctrl": "2.0.4-beta.9",
|
|
29
|
+
"three": "0.184.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/node": "^22.14.0",
|
|
33
|
+
"@types/react": "^19.2.16",
|
|
34
|
+
"@types/react-dom": "^19.2.3",
|
|
35
|
+
"@types/three": "0.184.0",
|
|
36
|
+
"@vitejs/plugin-react": "^6.3.1",
|
|
37
|
+
"tsx": "^4.21.0",
|
|
38
|
+
"typescript": "^5.8.3",
|
|
39
|
+
"vite": "^8.4.1"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Canvas } from "@react-three/fiber";
|
|
2
|
+
import { Component, Suspense, useEffect, useSyncExternalStore, type ReactNode } from "react";
|
|
3
|
+
import { Hud } from "./components/Hud.js";
|
|
4
|
+
import { PALETTE } from "./components/ocean-material.js";
|
|
5
|
+
import { Scene } from "./components/Scene.js";
|
|
6
|
+
import { attachKeyboard, type Helm } from "./game/input.js";
|
|
7
|
+
import type { Game } from "./game/store.js";
|
|
8
|
+
|
|
9
|
+
/** The canvas throws when the browser cannot make a WebGL context; say so instead of leaving a blank page. */
|
|
10
|
+
class CanvasBoundary extends Component<{ children: ReactNode }, { failed: boolean }> {
|
|
11
|
+
override state = { failed: false };
|
|
12
|
+
|
|
13
|
+
static getDerivedStateFromError(): { failed: boolean } {
|
|
14
|
+
return { failed: true };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
override render(): ReactNode {
|
|
18
|
+
if (this.state.failed) {
|
|
19
|
+
return (
|
|
20
|
+
<div className="fatal">
|
|
21
|
+
<h1>Tugline needs WebGL</h1>
|
|
22
|
+
<p>This browser could not start a WebGL canvas. Try another browser, or turn on hardware acceleration.</p>
|
|
23
|
+
</div>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
return this.props.children;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function App({ game, helm }: { game: Game; helm: Helm }) {
|
|
31
|
+
const snap = useSyncExternalStore(game.subscribe, game.getSnapshot);
|
|
32
|
+
useEffect(() => attachKeyboard(helm), [helm]);
|
|
33
|
+
return (
|
|
34
|
+
<>
|
|
35
|
+
<div className="stage">
|
|
36
|
+
<CanvasBoundary>
|
|
37
|
+
<Canvas flat dpr={[1, 2]} camera={{ fov: 58, near: 0.1, far: 600, position: [0, 8, 16] }}>
|
|
38
|
+
<color attach="background" args={[PALETTE.horizon]} />
|
|
39
|
+
<Suspense fallback={null}>
|
|
40
|
+
<Scene key={snap.runId} sea={snap.sea} runId={snap.runId} paused={snap.paused} game={game} helm={helm} />
|
|
41
|
+
</Suspense>
|
|
42
|
+
</Canvas>
|
|
43
|
+
</CanvasBoundary>
|
|
44
|
+
</div>
|
|
45
|
+
<Hud game={game} helm={helm} />
|
|
46
|
+
</>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
@@ -2,7 +2,7 @@ import { useBuoyancy } from "@pinkaphant/kolmo/water/react";
|
|
|
2
2
|
import { CuboidCollider, RigidBody, interactionGroups } from "@react-three/rapier";
|
|
3
3
|
import { useLayoutEffect, useRef } from "react";
|
|
4
4
|
import type { Object3D } from "three";
|
|
5
|
-
import { BOAT
|
|
5
|
+
import { BOAT } from "../game/constants.js";
|
|
6
6
|
import { useRound } from "./round-context.js";
|
|
7
7
|
|
|
8
8
|
/** Nothing in this game collides with anything: the rules look at distances, and the water does the pushing. */
|
|
@@ -74,7 +74,6 @@ export function Boat() {
|
|
|
74
74
|
const controller = useBuoyancy(registry.boat, {
|
|
75
75
|
surface: sea.surface,
|
|
76
76
|
clock,
|
|
77
|
-
timeStep: FIXED_DT,
|
|
78
77
|
cells: { slices: BOAT.slices },
|
|
79
78
|
drag: BOAT.drag,
|
|
80
79
|
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { useBuoyancy } from "@pinkaphant/kolmo/water/react";
|
|
2
2
|
import { CuboidCollider, RigidBody } from "@react-three/rapier";
|
|
3
|
-
import { CRATE
|
|
3
|
+
import { CRATE } from "../game/constants.js";
|
|
4
4
|
import { NO_CONTACT } from "./Boat.js";
|
|
5
5
|
import { useRound } from "./round-context.js";
|
|
6
6
|
|
|
7
7
|
function Crate({ index }: { index: number }) {
|
|
8
8
|
const { sea, clock, registry, simulation } = useRound();
|
|
9
9
|
const self = registry.crates[index]!;
|
|
10
|
-
useBuoyancy(self, { surface: sea.surface, clock
|
|
10
|
+
useBuoyancy(self, { surface: sea.surface, clock });
|
|
11
11
|
const start = simulation.initialCrates[index]!;
|
|
12
12
|
const y = sea.field.heightAt(start.x, start.z, 0);
|
|
13
13
|
const [hx, hy, hz] = CRATE.halfExtents;
|