@pinkaphant/create-kolmo 0.4.2 → 0.5.2

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 +10 -8
  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 +10 -9
  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 +13 -11
  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 +7 -7
  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
@@ -0,0 +1,495 @@
1
+ :root {
2
+ --surface-canvas: oklch(13.5% 0.007 265);
3
+ --surface-dock: oklch(16.5% 0.008 265);
4
+ --surface-control: oklch(21% 0.009 265);
5
+ --surface-hover: oklch(25% 0.01 265);
6
+ --border-hairline: oklch(27% 0.01 265);
7
+ --ink-primary: oklch(94% 0.008 85);
8
+ --ink-muted: oklch(66% 0.01 265);
9
+ --accent-signal: oklch(80% 0.165 78);
10
+ --accent-gizmo: oklch(78% 0.135 205);
11
+ --accent-valid: oklch(79% 0.15 158);
12
+ --accent-alert: oklch(68% 0.19 28);
13
+ --font-sans: "Space Grotesk", system-ui, sans-serif;
14
+ --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
15
+ color-scheme: dark;
16
+ }
17
+
18
+ * {
19
+ box-sizing: border-box;
20
+ }
21
+
22
+ html,
23
+ body,
24
+ #root {
25
+ height: 100%;
26
+ margin: 0;
27
+ overflow: hidden;
28
+ background: var(--surface-canvas);
29
+ color: var(--ink-primary);
30
+ font-family: var(--font-sans);
31
+ font-variant-numeric: tabular-nums;
32
+ -webkit-tap-highlight-color: transparent;
33
+ overscroll-behavior: none;
34
+ }
35
+
36
+ .loading {
37
+ margin: 0;
38
+ padding: 16px;
39
+ color: var(--ink-muted);
40
+ font: 600 12px/1.4 var(--font-mono);
41
+ letter-spacing: 0.06em;
42
+ }
43
+
44
+ .stage {
45
+ position: fixed;
46
+ inset: 0;
47
+ touch-action: none;
48
+ }
49
+
50
+ .hud {
51
+ position: fixed;
52
+ inset: 0;
53
+ pointer-events: none;
54
+ color: var(--ink-primary);
55
+ user-select: none;
56
+ -webkit-user-select: none;
57
+ }
58
+
59
+ .hud button {
60
+ pointer-events: auto;
61
+ font-family: var(--font-mono);
62
+ font-variant-numeric: tabular-nums;
63
+ cursor: pointer;
64
+ }
65
+
66
+ .hud button:focus-visible {
67
+ outline: 1px solid var(--accent-signal);
68
+ outline-offset: 1px;
69
+ }
70
+
71
+ .topbar {
72
+ position: absolute;
73
+ top: max(10px, env(safe-area-inset-top));
74
+ left: 12px;
75
+ right: 12px;
76
+ min-height: 36px;
77
+ display: flex;
78
+ flex-wrap: wrap;
79
+ justify-content: space-between;
80
+ align-items: center;
81
+ gap: 8px;
82
+ padding: 4px 10px;
83
+ background: var(--surface-dock);
84
+ border: 1px solid var(--border-hairline);
85
+ border-radius: 3px;
86
+ }
87
+
88
+ .topbar-group {
89
+ display: flex;
90
+ flex-wrap: wrap;
91
+ align-items: center;
92
+ gap: 8px;
93
+ font: 600 12px/1.3 var(--font-mono);
94
+ font-variant-numeric: tabular-nums;
95
+ }
96
+
97
+ .cell-label {
98
+ color: var(--ink-muted);
99
+ font-size: 11px;
100
+ letter-spacing: 0.06em;
101
+ }
102
+
103
+ .cell-meta {
104
+ color: var(--ink-primary);
105
+ font-size: 12px;
106
+ min-width: 72px;
107
+ }
108
+
109
+ .cell-value {
110
+ color: var(--accent-signal);
111
+ font-size: 13px;
112
+ min-width: 44px;
113
+ }
114
+
115
+ .divider {
116
+ width: 1px;
117
+ height: 14px;
118
+ background: var(--border-hairline);
119
+ }
120
+
121
+ .combo {
122
+ padding: 1px 6px;
123
+ border: 1px solid var(--accent-signal);
124
+ border-radius: 2px;
125
+ background: var(--surface-control);
126
+ color: var(--accent-signal);
127
+ font: 600 11px/1.2 var(--font-mono);
128
+ }
129
+
130
+ .clock {
131
+ min-width: 42px;
132
+ color: var(--accent-gizmo);
133
+ font: 600 13px/1.2 var(--font-mono);
134
+ font-variant-numeric: tabular-nums;
135
+ }
136
+
137
+ .clock.low {
138
+ color: var(--accent-alert);
139
+ }
140
+
141
+ .topbar-actions {
142
+ display: flex;
143
+ align-items: center;
144
+ gap: 6px;
145
+ }
146
+
147
+ .dock-btn {
148
+ min-height: 28px;
149
+ padding: 4px 9px;
150
+ border: 1px solid var(--border-hairline);
151
+ border-radius: 2px;
152
+ background: var(--surface-control);
153
+ color: var(--ink-primary);
154
+ font-size: 11px;
155
+ font-weight: 600;
156
+ letter-spacing: 0.04em;
157
+ }
158
+
159
+ .dock-btn:hover {
160
+ background: var(--surface-hover);
161
+ border-color: var(--ink-muted);
162
+ }
163
+
164
+ .dock-btn:active {
165
+ border-color: var(--accent-signal);
166
+ color: var(--accent-signal);
167
+ }
168
+
169
+ .paused-banner {
170
+ position: absolute;
171
+ top: 58px;
172
+ left: 50%;
173
+ translate: -50% 0;
174
+ padding: 6px 12px;
175
+ background: var(--surface-dock);
176
+ border: 1px solid var(--accent-signal);
177
+ border-radius: 2px;
178
+ color: var(--accent-signal);
179
+ font: 600 11px/1.3 var(--font-mono);
180
+ letter-spacing: 0.06em;
181
+ }
182
+
183
+ .toast {
184
+ position: absolute;
185
+ top: 24%;
186
+ left: 50%;
187
+ translate: -50% 0;
188
+ padding: 4px 10px;
189
+ background: var(--surface-dock);
190
+ border: 1px solid var(--accent-valid);
191
+ border-radius: 2px;
192
+ color: var(--accent-valid);
193
+ font: 600 15px/1.2 var(--font-mono);
194
+ font-variant-numeric: tabular-nums;
195
+ animation: toast 0.9s ease-out forwards;
196
+ }
197
+
198
+ @keyframes toast {
199
+ from {
200
+ opacity: 1;
201
+ transform: translateY(0);
202
+ }
203
+ to {
204
+ opacity: 0;
205
+ transform: translateY(-28px);
206
+ }
207
+ }
208
+
209
+ .radar {
210
+ position: absolute;
211
+ right: max(12px, env(safe-area-inset-right));
212
+ bottom: max(12px, env(safe-area-inset-bottom));
213
+ }
214
+
215
+ .warning {
216
+ position: absolute;
217
+ left: 50%;
218
+ bottom: 16%;
219
+ translate: -50% 0;
220
+ padding: 5px 12px;
221
+ border: 1px solid var(--accent-alert);
222
+ border-radius: 2px;
223
+ background: var(--surface-dock);
224
+ color: var(--accent-alert);
225
+ font: 600 11px/1.3 var(--font-mono);
226
+ letter-spacing: 0.05em;
227
+ opacity: 0;
228
+ transition: opacity 0.16s linear;
229
+ }
230
+
231
+ .touch {
232
+ position: absolute;
233
+ left: 0;
234
+ right: 0;
235
+ bottom: max(12px, env(safe-area-inset-bottom));
236
+ display: flex;
237
+ justify-content: space-between;
238
+ padding: 0 12px;
239
+ pointer-events: none;
240
+ }
241
+
242
+ .touch-side {
243
+ display: flex;
244
+ gap: 8px;
245
+ }
246
+
247
+ .touch button {
248
+ min-width: 64px;
249
+ min-height: 52px;
250
+ padding: 0 12px;
251
+ border: 1px solid var(--border-hairline);
252
+ border-radius: 3px;
253
+ background: var(--surface-dock);
254
+ color: var(--ink-primary);
255
+ font-size: 11px;
256
+ font-weight: 600;
257
+ letter-spacing: 0.05em;
258
+ touch-action: none;
259
+ }
260
+
261
+ .touch button:active {
262
+ background: var(--surface-control);
263
+ border-color: var(--accent-signal);
264
+ color: var(--accent-signal);
265
+ }
266
+
267
+ .panel {
268
+ position: absolute;
269
+ left: 50%;
270
+ top: 50%;
271
+ translate: -50% -50%;
272
+ width: min(92vw, 420px);
273
+ padding: 16px;
274
+ border: 1px solid var(--border-hairline);
275
+ border-radius: 3px;
276
+ background: var(--surface-dock);
277
+ pointer-events: auto;
278
+ }
279
+
280
+ .panel-header {
281
+ display: flex;
282
+ justify-content: space-between;
283
+ align-items: center;
284
+ padding-bottom: 8px;
285
+ margin-bottom: 10px;
286
+ border-bottom: 1px solid var(--border-hairline);
287
+ }
288
+
289
+ .spec-tag {
290
+ color: var(--ink-muted);
291
+ font: 600 10px/1.2 var(--font-mono);
292
+ letter-spacing: 0.08em;
293
+ }
294
+
295
+ .panel h1 {
296
+ margin: 0;
297
+ font-size: 22px;
298
+ font-weight: 700;
299
+ letter-spacing: 0.04em;
300
+ }
301
+
302
+ .panel h2 {
303
+ margin: 0;
304
+ font-size: 16px;
305
+ font-weight: 700;
306
+ letter-spacing: 0.05em;
307
+ }
308
+
309
+ .tag {
310
+ margin: 6px 0 14px;
311
+ color: var(--ink-muted);
312
+ font-size: 13px;
313
+ line-height: 1.45;
314
+ }
315
+
316
+ .seas {
317
+ display: grid;
318
+ grid-template-columns: repeat(3, 1fr);
319
+ gap: 6px;
320
+ }
321
+
322
+ .sea {
323
+ min-height: 48px;
324
+ display: flex;
325
+ flex-direction: column;
326
+ align-items: flex-start;
327
+ justify-content: center;
328
+ gap: 3px;
329
+ padding: 8px 9px;
330
+ border: 1px solid var(--border-hairline);
331
+ border-radius: 2px;
332
+ background: var(--surface-control);
333
+ color: var(--ink-primary);
334
+ text-align: left;
335
+ }
336
+
337
+ .sea:hover {
338
+ background: var(--surface-hover);
339
+ }
340
+
341
+ .sea-head {
342
+ display: flex;
343
+ align-items: center;
344
+ gap: 5px;
345
+ font-size: 12px;
346
+ }
347
+
348
+ .sea-idx {
349
+ color: var(--ink-muted);
350
+ font-size: 10px;
351
+ }
352
+
353
+ .sea-meta {
354
+ font-size: 10px;
355
+ color: var(--ink-muted);
356
+ }
357
+
358
+ .sea.selected {
359
+ border-color: var(--accent-signal);
360
+ }
361
+
362
+ .sea.selected strong {
363
+ color: var(--accent-signal);
364
+ }
365
+
366
+ .best-row {
367
+ display: flex;
368
+ justify-content: space-between;
369
+ align-items: center;
370
+ margin: 12px 0;
371
+ padding: 8px 0;
372
+ border-top: 1px solid var(--border-hairline);
373
+ border-bottom: 1px solid var(--border-hairline);
374
+ font: 600 11px/1.2 var(--font-mono);
375
+ }
376
+
377
+ .best-label {
378
+ color: var(--ink-muted);
379
+ }
380
+
381
+ .best-val {
382
+ color: var(--accent-valid);
383
+ }
384
+
385
+ .best {
386
+ margin: 6px 0;
387
+ color: var(--ink-muted);
388
+ font: 600 12px/1.3 var(--font-mono);
389
+ }
390
+
391
+ .newbest {
392
+ margin: 6px 0;
393
+ color: var(--accent-valid);
394
+ font: 600 12px/1.3 var(--font-mono);
395
+ letter-spacing: 0.05em;
396
+ }
397
+
398
+ .go,
399
+ .secondary {
400
+ min-height: 36px;
401
+ padding: 8px 14px;
402
+ border: 1px solid var(--border-hairline);
403
+ border-radius: 2px;
404
+ font-size: 12px;
405
+ font-weight: 600;
406
+ letter-spacing: 0.05em;
407
+ }
408
+
409
+ .go {
410
+ width: 100%;
411
+ background: var(--accent-signal);
412
+ border-color: var(--accent-signal);
413
+ color: var(--surface-canvas);
414
+ }
415
+
416
+ .go:hover {
417
+ filter: brightness(1.06);
418
+ }
419
+
420
+ .secondary {
421
+ background: var(--surface-control);
422
+ color: var(--ink-primary);
423
+ }
424
+
425
+ .secondary:hover {
426
+ background: var(--surface-hover);
427
+ }
428
+
429
+ .row {
430
+ display: grid;
431
+ grid-template-columns: 1fr auto;
432
+ gap: 8px;
433
+ margin-top: 14px;
434
+ }
435
+
436
+ .big {
437
+ margin-top: 6px;
438
+ color: var(--accent-signal);
439
+ font: 600 32px/1.1 var(--font-mono);
440
+ font-variant-numeric: tabular-nums;
441
+ }
442
+
443
+ .stats {
444
+ margin: 6px 0 0;
445
+ color: var(--ink-muted);
446
+ font: 500 12px/1.4 var(--font-mono);
447
+ }
448
+
449
+ .keys {
450
+ margin: 12px 0 0;
451
+ color: var(--ink-muted);
452
+ font: 500 11px/1.5 var(--font-mono);
453
+ }
454
+
455
+ kbd {
456
+ padding: 1px 5px;
457
+ border: 1px solid var(--border-hairline);
458
+ border-radius: 2px;
459
+ background: var(--surface-control);
460
+ color: var(--ink-primary);
461
+ font: 600 10px/1.2 var(--font-mono);
462
+ }
463
+
464
+ .fatal {
465
+ position: fixed;
466
+ inset: 0;
467
+ display: grid;
468
+ place-content: center;
469
+ gap: 8px;
470
+ padding: 24px;
471
+ text-align: center;
472
+ background: var(--surface-canvas);
473
+ color: var(--ink-primary);
474
+ }
475
+
476
+ .fatal h1 {
477
+ margin: 0;
478
+ font-size: 18px;
479
+ }
480
+
481
+ .fatal p {
482
+ margin: 0;
483
+ color: var(--ink-muted);
484
+ font-size: 13px;
485
+ }
486
+
487
+ @media (pointer: coarse) {
488
+ .dock-btn,
489
+ .go,
490
+ .secondary,
491
+ .sea {
492
+ min-height: 44px;
493
+ min-width: 44px;
494
+ }
495
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
6
+ "skipLibCheck": true,
7
+ "moduleResolution": "bundler",
8
+ "isolatedModules": true,
9
+ "moduleDetection": "force",
10
+ "jsx": "react-jsx",
11
+ "strict": true,
12
+ "noUncheckedIndexedAccess": true,
13
+ "noImplicitOverride": true,
14
+ "noEmit": true,
15
+ "types": ["node", "vite/client"]
16
+ },
17
+ "include": ["src", "vite.config.ts"]
18
+ }
@@ -0,0 +1,16 @@
1
+ import react from "@vitejs/plugin-react";
2
+ import { defineConfig } from "vite";
3
+ import { KOLMO_SINGLETON_DEDUPE } from "@pinkaphant/kolmo/vite";
4
+
5
+ export default defineConfig({
6
+ plugins: [react()],
7
+ resolve: {
8
+ dedupe: KOLMO_SINGLETON_DEDUPE,
9
+ },
10
+ optimizeDeps: {
11
+ exclude: ["@dimforge/rapier3d-compat"],
12
+ },
13
+ build: {
14
+ chunkSizeWarningLimit: 2600,
15
+ },
16
+ });
@@ -1,11 +0,0 @@
1
- # Lonedrive
2
-
3
- An 8.1 km seeded desert highway streamed in seamless 288 m (96 × 3 m) heightfield sectors, roadside gas stops, and one beater car. Respectful spoof of The Long Drive (not Longline, the tugboat).
4
-
5
- - **E** / **F**: Board or exit the car
6
- - **WASD** / **Arrows**: Drive or walk
7
- - **R**: Flip upright
8
-
9
- ```bash
10
- npm create @pinkaphant/kolmo@latest my-drive -- --template lonedrive
11
- ```
@@ -1,15 +0,0 @@
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>Lonedrive</title>
7
- <style>
8
- html, body, #root { margin: 0; width: 100%; height: 100%; overflow: hidden; background: #1a120c; }
9
- </style>
10
- </head>
11
- <body>
12
- <div id="root"></div>
13
- <script type="module" src="/src/main.tsx"></script>
14
- </body>
15
- </html>
@@ -1,149 +0,0 @@
1
- import { useEffect, useMemo, useRef, useState } from "react";
2
- import { useFrame } from "@react-three/fiber";
3
- import {
4
- ACTOR_GROUND_CLEARANCE,
5
- Actor,
6
- Game,
7
- Hud,
8
- Prop,
9
- Radar,
10
- RoadRibbon,
11
- Terrain,
12
- Vehicle,
13
- radarRoadFromSpline,
14
- type EcctrlHandle,
15
- } from "@pinkaphant/kolmo";
16
- import {
17
- frontage,
18
- growRoad,
19
- makeTerrain,
20
- sampleRapierHeightfield,
21
- type Terrain as RoadTerrain,
22
- } from "@khr3/roads";
23
-
24
- const VAULT = "https://khr3.optimuspi.workers.dev/assets";
25
- const CHUNK_SIZE = 288;
26
- const CHUNK_SEGMENTS = 96;
27
-
28
- function StreamedHighwayTerrain({ land, initialPos }: { land: RoadTerrain; initialPos: [number, number, number] }) {
29
- const cacheRef = useRef<Map<string, Float32Array>>(new Map());
30
- const camXZRef = useRef<[number, number]>([initialPos[0], initialPos[2]]);
31
- const [sector, setSector] = useState<[number, number]>(() => [
32
- Math.floor(initialPos[0] / CHUNK_SIZE),
33
- Math.floor(initialPos[2] / CHUNK_SIZE),
34
- ]);
35
- const sectorRef = useRef(sector);
36
-
37
- useFrame((state) => {
38
- camXZRef.current[0] = state.camera.position.x;
39
- camXZRef.current[1] = state.camera.position.z;
40
- });
41
-
42
- useEffect(() => {
43
- const timer = window.setInterval(() => {
44
- const cx = Math.floor(camXZRef.current[0] / CHUNK_SIZE);
45
- const cz = Math.floor(camXZRef.current[1] / CHUNK_SIZE);
46
- if (cx !== sectorRef.current[0] || cz !== sectorRef.current[1]) {
47
- sectorRef.current = [cx, cz];
48
- setSector([cx, cz]);
49
- }
50
- }, 150);
51
- return () => window.clearInterval(timer);
52
- }, []);
53
-
54
- const chunks = useMemo(() => {
55
- const list: Array<{ key: string; heights: Float32Array; position: [number, number, number] }> = [];
56
- for (let dz = -1; dz <= 1; dz++) {
57
- for (let dx = -1; dx <= 1; dx++) {
58
- const cx = sector[0] + dx;
59
- const cz = sector[1] + dz;
60
- const key = `${cx},${cz}`;
61
- let heights = cacheRef.current.get(key);
62
- if (!heights) {
63
- heights = sampleRapierHeightfield(land, [cx * CHUNK_SIZE, 0, cz * CHUNK_SIZE], CHUNK_SIZE, CHUNK_SEGMENTS);
64
- cacheRef.current.set(key, heights);
65
- }
66
- list.push({
67
- key,
68
- heights,
69
- position: [(cx + 0.5) * CHUNK_SIZE, 0, (cz + 0.5) * CHUNK_SIZE],
70
- });
71
- }
72
- }
73
- return list;
74
- }, [land, sector]);
75
-
76
- return (
77
- <>
78
- {chunks.map((chunk) => (
79
- <Terrain
80
- key={chunk.key}
81
- heights={chunk.heights}
82
- segments={CHUNK_SEGMENTS}
83
- size={[CHUNK_SIZE, CHUNK_SIZE]}
84
- position={chunk.position}
85
- color="#6e5842"
86
- />
87
- ))}
88
- </>
89
- );
90
- }
91
-
92
- export default function App() {
93
- const actorRef = useRef<EcctrlHandle>(null);
94
- const world = useMemo(() => {
95
- const road = growRoad(14, {
96
- length: 8100,
97
- halfWidth: 4.5,
98
- controlSpacing: 78,
99
- maxTurn: 0.16,
100
- maxGrade: 0.05,
101
- hilliness: 21,
102
- start: [0, 3, 0],
103
- });
104
- const land = makeTerrain(14, road, {
105
- amplitude: 15,
106
- noise: { wavelength: 216, octaves: 4, gain: 0.5, lacunarity: 2 },
107
- maxSlope: 0.45,
108
- minShoulder: 9,
109
- verge: 3,
110
- });
111
- const at = road.at(36).pos;
112
- const stops = frontage(road, { spacing: 1080, setback: 9 }).slice(0, 6);
113
- const radarSpec = {
114
- range: 180,
115
- headingUp: true,
116
- roads: [radarRoadFromSpline(road, { id: "highway-14", maxStep: 18 })],
117
- };
118
- return {
119
- road,
120
- land,
121
- radarSpec,
122
- car: [at[0], at[1], at[2]] as [number, number, number],
123
- stops: stops.map((lot, idx) => ({
124
- key: `stop-${idx}`,
125
- canopy: [lot.front[0], lot.groundY, lot.front[2]] as [number, number, number],
126
- sign: [lot.front[0] + lot.facing[0] * 3, lot.groundY, lot.front[2] + lot.facing[2] * 3] as [number, number, number],
127
- })),
128
- };
129
- }, []);
130
-
131
- return (
132
- <>
133
- <Game skybox="dusk">
134
- <StreamedHighwayTerrain land={world.land} initialPos={world.car} />
135
- <RoadRibbon road={world.road} />
136
- {world.stops.map((stop) => (
137
- <Prop key={stop.key} id={stop.key} src={`${VAULT}/city/gas-canopy-roof.glb`} position={stop.canopy} fixed />
138
- ))}
139
- {world.stops.map((stop) => (
140
- <Prop key={`${stop.key}-sign`} id={`${stop.key}-sign`} src={`${VAULT}/city/neon-petro-sign.glb`} position={stop.sign} fixed />
141
- ))}
142
- <Vehicle id="gt" label="Long-Haul Coupe" src={`${VAULT}/cars/toyota_supra_a80.glb`} position={world.car} />
143
- <Actor ref={actorRef} position={[world.car[0] - 3, world.car[1] + ACTOR_GROUND_CLEARANCE, world.car[2]]} />
144
- </Game>
145
- <Hud />
146
- <Radar spec={world.radarSpec} />
147
- </>
148
- );
149
- }