create-threenative 0.2.6 → 0.2.8

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 (756) hide show
  1. package/README.md +5 -3
  2. package/agent-docs/references/build-profiles.md +126 -0
  3. package/agent-docs/references/capability-reference.md +607 -26
  4. package/agent-docs/references/performance-basics.md +8 -5
  5. package/agent-docs/references/sculpt-from-a-reference.md +1 -1
  6. package/agent-docs/references/trace-a-slow-frame.md +1 -1
  7. package/agent-docs/references/visual-baseline.md +8 -4
  8. package/agent-files/.agents/skills/file-engine-bug/SKILL.md +15 -4
  9. package/agent-files/.agents/skills/threenative-assets/SKILL.md +5 -5
  10. package/agent-files/.agents/skills/threenative-capabilities/SKILL.md +1 -1
  11. package/agent-files/.agents/skills/threenative-context/SKILL.md +1 -1
  12. package/agent-files/.agents/skills/threenative-performance/SKILL.md +3 -3
  13. package/agent-files/.agents/skills/threenative-playtest/SKILL.md +1 -1
  14. package/agent-files/.agents/skills/threenative-ui/SKILL.md +1 -1
  15. package/agent-files/.agents/skills/threenative-visuals/SKILL.md +4 -4
  16. package/capabilities.json +801 -24
  17. package/dist/index.d.ts +30 -1
  18. package/dist/index.js +300 -56
  19. package/dist/threenative.js +717 -156
  20. package/package.json +6 -6
  21. package/template-assets/assets/mannequin-combat.glb +0 -0
  22. package/template-assets/assets/mannequin.glb +0 -0
  23. package/template-assets/assets/player-viewmodel.glb +0 -0
  24. package/template-assets/assets/sky.jpg +0 -0
  25. package/template-assets/clearwater/README.md +141 -0
  26. package/template-assets/clearwater/install.mjs +50 -0
  27. package/template-assets/clearwater/src/clearwater.ts +180 -0
  28. package/template-assets/clearwater/src/clearwaterDemo.ts +28 -0
  29. package/template-assets/clearwater/src/clearwaterLifetime.ts +28 -0
  30. package/{LICENSE → template-assets/clearwater/src/render/CLEARWATER-LICENSE.txt} +4 -1
  31. package/template-assets/clearwater/src/render/clearwater.ts +278 -0
  32. package/template-assets/clearwater/src/render/clearwaterCaustics.ts +138 -0
  33. package/template-assets/clearwater/src/render/clearwaterDemo.ts +65 -0
  34. package/template-assets/clearwater/src/render/clearwaterOptics.ts +33 -0
  35. package/template-assets/clearwater/src/render/clearwaterOptions.ts +177 -0
  36. package/template-assets/clearwater/src/render/clearwaterPass.ts +51 -0
  37. package/template-assets/patches/three@0.185.1.patch +2101 -138
  38. package/template-assets/worldEnvironment.ts +52 -1
  39. package/templates/action-rpg/AGENTS.md +42 -42
  40. package/templates/action-rpg/CLAUDE.md +42 -42
  41. package/templates/action-rpg/kit.json +1 -1
  42. package/templates/action-rpg/package.json +13 -7
  43. package/templates/action-rpg/playtests/combat.playtest.json +162 -23
  44. package/templates/action-rpg/playtests/performance.playtest.json +4 -3
  45. package/templates/action-rpg/playtests/survives.playtest.json +25 -8
  46. package/templates/action-rpg/src/conventions.ts +24 -18
  47. package/templates/action-rpg/src/entities/Enemy.ts +74 -24
  48. package/templates/action-rpg/src/entities/Fighter.ts +127 -0
  49. package/templates/action-rpg/src/entities/Player.ts +102 -32
  50. package/templates/action-rpg/src/game.ts +3 -3
  51. package/templates/action-rpg/src/render/camera.ts +18 -16
  52. package/templates/action-rpg/src/render/dungeon.ts +192 -0
  53. package/templates/action-rpg/src/render/lighting.ts +45 -28
  54. package/templates/action-rpg/src/render/loading.ts +4 -4
  55. package/templates/action-rpg/src/render/materials.ts +191 -47
  56. package/templates/action-rpg/src/render/palette.ts +14 -13
  57. package/templates/action-rpg/src/render/postprocessing.ts +12 -2
  58. package/templates/action-rpg/src/render/props.ts +117 -0
  59. package/templates/action-rpg/src/render/quality.ts +40 -82
  60. package/templates/action-rpg/src/render/sky.ts +36 -13
  61. package/templates/action-rpg/src/render/touch-controls.ts +1 -1
  62. package/templates/action-rpg/src/render/worldEnvironment.ts +52 -1
  63. package/templates/action-rpg/src/scenes/Play.ts +61 -39
  64. package/templates/action-rpg/src/style.css +9 -7
  65. package/templates/action-rpg/src/ui/AbilityBar.tsx +3 -1
  66. package/templates/action-rpg/src/ui/Hud.tsx +3 -3
  67. package/templates/action-rpg/threenative.config.ts +14 -1
  68. package/templates/action-rpg/vite.config.ts +4 -1
  69. package/templates/minimal/AGENTS.md +10 -10
  70. package/templates/minimal/CLAUDE.md +10 -10
  71. package/templates/minimal/package.json +12 -6
  72. package/templates/minimal/playtests/play.playtest.json +6 -5
  73. package/templates/minimal/playtests/sky.playtest.json +27 -0
  74. package/templates/minimal/src/conventions.ts +6 -3
  75. package/templates/minimal/src/entities/Player.ts +73 -27
  76. package/templates/minimal/src/main.ts +2 -3
  77. package/templates/minimal/src/render/camera.ts +22 -4
  78. package/templates/minimal/src/render/lighting.ts +24 -48
  79. package/templates/minimal/src/render/materials.ts +158 -13
  80. package/templates/minimal/src/render/palette.ts +10 -7
  81. package/templates/minimal/src/render/postprocessing.ts +12 -25
  82. package/templates/minimal/src/render/quality.ts +35 -69
  83. package/templates/minimal/src/render/sky.ts +35 -54
  84. package/templates/minimal/src/render/touch-controls.ts +1 -1
  85. package/templates/minimal/src/render/worldEnvironment.ts +52 -1
  86. package/templates/minimal/src/scenes/Play.ts +121 -111
  87. package/templates/minimal/src/state.ts +0 -4
  88. package/templates/minimal/src/style.css +0 -10
  89. package/templates/minimal/threenative.config.ts +14 -1
  90. package/templates/minimal/vite.config.ts +4 -1
  91. package/templates/platformer/AGENTS.md +18 -56
  92. package/templates/platformer/CLAUDE.md +18 -56
  93. package/templates/platformer/kit.json +2 -2
  94. package/templates/platformer/package.json +13 -9
  95. package/templates/platformer/playtests/buffer.playtest.json +15 -5
  96. package/templates/platformer/playtests/collect.playtest.json +8 -34
  97. package/templates/platformer/playtests/coyote.playtest.json +12 -34
  98. package/templates/platformer/playtests/damage.playtest.json +40 -15
  99. package/templates/platformer/playtests/hud.playtest.json +34 -0
  100. package/templates/platformer/playtests/move.playtest.json +24 -0
  101. package/templates/platformer/playtests/performance.playtest.json +24 -7
  102. package/templates/platformer/playtests/respawn.playtest.json +46 -11
  103. package/templates/platformer/playtests/stomp.playtest.json +49 -12
  104. package/templates/platformer/playtests/survives.playtest.json +3 -19
  105. package/templates/platformer/playtests/world.playtest.json +26 -0
  106. package/templates/platformer/src/entities/Fox.ts +273 -0
  107. package/templates/platformer/src/entities/Pickup.ts +43 -60
  108. package/templates/platformer/src/entities/Walker.ts +88 -0
  109. package/templates/platformer/src/game.ts +11 -8
  110. package/templates/platformer/src/level/Checkpoints.ts +29 -16
  111. package/templates/platformer/src/level/Stage.ts +469 -0
  112. package/templates/platformer/src/render/blocks.ts +94 -0
  113. package/templates/platformer/src/render/camera.ts +28 -3
  114. package/templates/platformer/src/render/fox.ts +196 -0
  115. package/templates/platformer/src/render/lighting.ts +42 -33
  116. package/templates/platformer/src/render/materials.ts +115 -5
  117. package/templates/platformer/src/render/palette.ts +68 -53
  118. package/templates/platformer/src/render/pickups.ts +142 -0
  119. package/templates/platformer/src/render/postprocessing.ts +12 -2
  120. package/templates/platformer/src/render/props.ts +147 -0
  121. package/templates/platformer/src/render/quality.ts +47 -99
  122. package/templates/platformer/src/render/scenery.ts +172 -0
  123. package/templates/platformer/src/render/sky.ts +120 -31
  124. package/templates/platformer/src/render/touch-controls.ts +5 -2
  125. package/templates/platformer/src/render/walkers.ts +96 -0
  126. package/templates/platformer/src/render/waterfall.ts +85 -0
  127. package/templates/platformer/src/render/worldEnvironment.ts +52 -1
  128. package/templates/platformer/src/scenes/Boot.ts +3 -4
  129. package/templates/platformer/src/scenes/Play.ts +362 -0
  130. package/templates/platformer/src/state.ts +16 -14
  131. package/templates/platformer/src/style.css +9 -8
  132. package/templates/platformer/src/ui/Hud.tsx +62 -29
  133. package/templates/platformer/src/ui/Menu.tsx +2 -2
  134. package/templates/platformer/threenative.config.ts +14 -1
  135. package/templates/platformer/vite.config.ts +4 -1
  136. package/templates/puzzle/AGENTS.md +19 -20
  137. package/templates/puzzle/CLAUDE.md +19 -20
  138. package/templates/puzzle/assets/native-proof.glb +0 -0
  139. package/templates/puzzle/assets/native-proof.png +0 -0
  140. package/templates/puzzle/kit.json +1 -1
  141. package/templates/puzzle/package.json +13 -7
  142. package/templates/puzzle/playtests/axis.playtest.json +20 -0
  143. package/templates/puzzle/playtests/blocked.playtest.json +73 -0
  144. package/templates/puzzle/playtests/caused.playtest.json +65 -0
  145. package/templates/puzzle/playtests/lit.playtest.json +74 -0
  146. package/templates/puzzle/playtests/performance.playtest.json +24 -7
  147. package/templates/{starter/playtests/respawn.playtest.json → puzzle/playtests/push.playtest.json} +24 -19
  148. package/templates/puzzle/playtests/replay.playtest.json +81 -0
  149. package/templates/puzzle/playtests/restart.playtest.json +108 -0
  150. package/templates/puzzle/playtests/seal.playtest.json +98 -0
  151. package/templates/puzzle/playtests/settle.playtest.json +100 -0
  152. package/templates/puzzle/playtests/survives.playtest.json +6 -29
  153. package/templates/{starter/playtests/hot-reload.playtest.json → puzzle/playtests/travel.playtest.json} +6 -5
  154. package/templates/puzzle/src/entities/Crate.ts +99 -42
  155. package/templates/puzzle/src/entities/Seal.ts +69 -0
  156. package/templates/puzzle/src/entities/Warden.ts +135 -0
  157. package/templates/puzzle/src/game.ts +15 -11
  158. package/templates/puzzle/src/render/camera.ts +66 -31
  159. package/templates/puzzle/src/render/crateShape.ts +70 -0
  160. package/templates/puzzle/src/render/lighting.ts +41 -41
  161. package/templates/puzzle/src/render/loading.ts +4 -4
  162. package/templates/puzzle/src/render/materials.ts +131 -27
  163. package/templates/puzzle/src/render/palette.ts +19 -29
  164. package/templates/puzzle/src/render/postprocessing.ts +15 -3
  165. package/templates/puzzle/src/render/quality.ts +71 -80
  166. package/templates/puzzle/src/render/shapes.ts +109 -108
  167. package/templates/puzzle/src/render/sky.ts +18 -10
  168. package/templates/puzzle/src/render/touch-controls.ts +8 -51
  169. package/templates/puzzle/src/render/vault.ts +315 -0
  170. package/templates/puzzle/src/render/warden.ts +46 -0
  171. package/templates/puzzle/src/render/worldEnvironment.ts +52 -1
  172. package/templates/puzzle/src/scenes/Play.ts +793 -0
  173. package/templates/puzzle/src/state.ts +55 -24
  174. package/templates/puzzle/src/style.css +7 -8
  175. package/templates/puzzle/src/ui/App.tsx +2 -2
  176. package/templates/puzzle/src/ui/Hud.tsx +92 -40
  177. package/templates/puzzle/src/ui/Menu.tsx +40 -2
  178. package/templates/puzzle/threenative.config.ts +14 -1
  179. package/templates/puzzle/vite.config.ts +4 -1
  180. package/templates/racing/AGENTS.md +19 -20
  181. package/templates/racing/CLAUDE.md +19 -20
  182. package/templates/racing/package.json +13 -7
  183. package/templates/racing/playtests/boost.playtest.json +33 -12
  184. package/templates/racing/playtests/outcome.playtest.json +32 -50
  185. package/templates/racing/playtests/performance.playtest.json +2 -1
  186. package/templates/racing/playtests/ranking.playtest.json +5 -14
  187. package/templates/racing/playtests/rescue.playtest.json +2 -2
  188. package/templates/racing/playtests/reverse.playtest.json +30 -8
  189. package/templates/racing/playtests/shortcut.playtest.json +54 -9
  190. package/templates/racing/playtests/touch-controls.playtest.json +32 -5
  191. package/templates/racing/src/entities/CarBody.ts +327 -0
  192. package/templates/racing/src/entities/LineDriver.ts +220 -0
  193. package/templates/racing/src/entities/RacingCar.ts +150 -89
  194. package/templates/racing/src/entities/Rival.ts +61 -24
  195. package/templates/racing/src/game.ts +5 -0
  196. package/templates/racing/src/render/camera.ts +49 -7
  197. package/templates/racing/src/render/lighting.ts +36 -37
  198. package/templates/racing/src/render/materials.ts +239 -19
  199. package/templates/racing/src/render/palette.ts +19 -21
  200. package/templates/racing/src/render/postprocessing.ts +12 -2
  201. package/templates/racing/src/render/quality.ts +43 -82
  202. package/templates/racing/src/render/shapes.ts +20 -6
  203. package/templates/racing/src/render/sky.ts +47 -39
  204. package/templates/racing/src/render/touch-controls.ts +1 -1
  205. package/templates/racing/src/render/worldEnvironment.ts +52 -1
  206. package/templates/racing/src/scenes/Race.ts +107 -54
  207. package/templates/racing/src/state.ts +2 -0
  208. package/templates/racing/src/track/Checkline.ts +22 -7
  209. package/templates/racing/src/track/Lap.ts +64 -36
  210. package/templates/racing/src/track/Ranking.ts +20 -11
  211. package/templates/racing/src/track/Track.ts +809 -361
  212. package/templates/racing/src/track/TrackSector.ts +40 -11
  213. package/templates/racing/src/track/circuit.ts +477 -0
  214. package/templates/racing/src/track/rescue.ts +16 -4
  215. package/templates/racing/threenative.config.ts +14 -1
  216. package/templates/racing/vite.config.ts +4 -1
  217. package/templates/rain/AGENTS.md +96 -0
  218. package/templates/rain/CLAUDE.md +98 -0
  219. package/templates/rain/assets/rain-loop.wav +0 -0
  220. package/templates/rain/assets/thunder.wav +0 -0
  221. package/templates/rain/assets/wind-loop.wav +0 -0
  222. package/templates/rain/index.html +18 -0
  223. package/templates/rain/kit.json +7 -0
  224. package/templates/rain/native-playtests/boot.playtest.json +13 -0
  225. package/templates/rain/native-playtests/lightning.playtest.json +173 -0
  226. package/templates/rain/package.json +56 -0
  227. package/templates/rain/playtests/auto-lightning-clear.playtest.json +66 -0
  228. package/templates/rain/playtests/auto-lightning.playtest.json +26 -0
  229. package/templates/rain/playtests/automation.playtest.json +133 -0
  230. package/templates/rain/playtests/cinematic.playtest.json +59 -0
  231. package/templates/rain/playtests/flash.playtest.json +27 -0
  232. package/templates/rain/playtests/fly.playtest.json +54 -0
  233. package/templates/rain/playtests/lightning.playtest.json +220 -0
  234. package/templates/rain/playtests/loading.playtest.json +57 -0
  235. package/templates/rain/playtests/paused.playtest.json +59 -0
  236. package/templates/rain/playtests/performance.playtest.json +22 -0
  237. package/templates/rain/playtests/reduced-motion.playtest.json +87 -0
  238. package/templates/rain/playtests/simulation.playtest.json +20 -0
  239. package/templates/rain/playtests/storm.playtest.json +150 -0
  240. package/templates/rain/playtests/survives.playtest.json +58 -0
  241. package/templates/rain/playtests/tiers.playtest.json +179 -0
  242. package/templates/rain/playtests/weather.playtest.json +77 -0
  243. package/templates/rain/public/favicon.svg +5 -0
  244. package/templates/rain/src/audio/storm.ts +314 -0
  245. package/templates/rain/src/game.ts +114 -0
  246. package/templates/rain/src/render/bloom-shader.ts +65 -0
  247. package/templates/rain/src/render/camera.ts +160 -0
  248. package/templates/rain/src/render/clouds-shader.ts +242 -0
  249. package/templates/rain/src/render/clouds.ts +142 -0
  250. package/templates/rain/src/render/lighting.ts +39 -0
  251. package/templates/rain/src/render/lightning.ts +360 -0
  252. package/templates/rain/src/render/loading.ts +327 -0
  253. package/templates/rain/src/render/materials.ts +19 -0
  254. package/templates/rain/src/render/noise-volume.ts +159 -0
  255. package/templates/rain/src/render/palette.ts +18 -0
  256. package/templates/rain/src/render/post-shader.ts +178 -0
  257. package/templates/rain/src/render/postprocessing.ts +226 -0
  258. package/templates/rain/src/render/quality.ts +135 -0
  259. package/templates/rain/src/render/rain.ts +299 -0
  260. package/templates/rain/src/render/sky.ts +28 -0
  261. package/templates/rain/src/render/world-shader.ts +680 -0
  262. package/templates/rain/src/render/world.ts +146 -0
  263. package/templates/{defense → rain}/src/render/worldEnvironment.ts +52 -1
  264. package/templates/rain/src/scenes/Boot.ts +334 -0
  265. package/templates/rain/src/state.ts +257 -0
  266. package/templates/rain/src/style.css +1160 -0
  267. package/templates/rain/src/ui/App.tsx +29 -0
  268. package/templates/rain/src/ui/GameUi.tsx +187 -0
  269. package/templates/rain/src/ui/Hud.tsx +327 -0
  270. package/templates/rain/src/ui/LoadingOverlay.tsx +46 -0
  271. package/templates/rain/src/ui/Menu.tsx +370 -0
  272. package/templates/rain/src/ui/automation.ts +60 -0
  273. package/templates/rain/src/ui/main.tsx +7 -0
  274. package/templates/rain/src/ui/tempest.ts +149 -0
  275. package/templates/rain/tailwind.config.ts +2 -0
  276. package/templates/rain/threenative.config.ts +66 -0
  277. package/templates/rain/tools/generate-shaders.mjs +656 -0
  278. package/templates/rain/tools/make-storm-audio.mjs +387 -0
  279. package/templates/rain/tools/storm-dsp.mjs +177 -0
  280. package/templates/rain/tools/tempest-bloom.frag +10 -0
  281. package/templates/rain/tools/tempest-clouds.frag +86 -0
  282. package/templates/rain/tools/tempest-post.frag +47 -0
  283. package/templates/rain/tools/tempest-world.frag +210 -0
  284. package/templates/rain/tools/verify-noise-volume.mjs +61 -0
  285. package/templates/rain/tsconfig.json +17 -0
  286. package/templates/rain/vite.config.ts +37 -0
  287. package/templates/rts/.codex/config.toml +19 -0
  288. package/templates/rts/.cursor/mcp.json +32 -0
  289. package/templates/rts/.gemini/settings.json +32 -0
  290. package/templates/rts/.mcp.json +32 -0
  291. package/templates/rts/.vscode/mcp.json +36 -0
  292. package/templates/rts/.zed/settings.json +36 -0
  293. package/templates/rts/AGENTS.md +96 -0
  294. package/templates/rts/CLAUDE.md +98 -0
  295. package/templates/rts/kit.json +7 -0
  296. package/templates/rts/opencode.json +41 -0
  297. package/templates/{defense → rts}/package.json +13 -7
  298. package/templates/rts/playtests/performance.playtest.json +41 -0
  299. package/templates/rts/playtests/rts-ai-attack.playtest.json +24 -0
  300. package/templates/rts/playtests/rts-attack.playtest.json +75 -0
  301. package/templates/rts/playtests/rts-build.playtest.json +68 -0
  302. package/templates/rts/playtests/rts-orders.playtest.json +150 -0
  303. package/templates/rts/playtests/rts-train.playtest.json +62 -0
  304. package/templates/rts/playtests/survives.playtest.json +58 -0
  305. package/templates/rts/public/favicon.svg +4 -0
  306. package/templates/rts/src/game.ts +64 -0
  307. package/templates/rts/src/main.ts +15 -0
  308. package/templates/rts/src/orders.ts +22 -0
  309. package/templates/rts/src/render/army.ts +346 -0
  310. package/templates/rts/src/render/camera.ts +123 -0
  311. package/templates/rts/src/render/lighting.ts +61 -0
  312. package/templates/rts/src/render/loading.ts +33 -0
  313. package/templates/rts/src/render/materials.ts +152 -0
  314. package/templates/rts/src/render/models.ts +705 -0
  315. package/templates/rts/src/render/palette.ts +17 -0
  316. package/templates/rts/src/render/picking.ts +93 -0
  317. package/templates/rts/src/render/postprocessing.ts +46 -0
  318. package/templates/rts/src/render/quality.ts +128 -0
  319. package/templates/rts/src/render/resources.ts +141 -0
  320. package/templates/rts/src/render/sky.ts +44 -0
  321. package/templates/rts/src/render/terrain.ts +116 -0
  322. package/templates/rts/src/render/worldEnvironment.ts +809 -0
  323. package/templates/rts/src/scenes/Play.ts +650 -0
  324. package/templates/rts/src/sim/ai.ts +1140 -0
  325. package/templates/rts/src/sim/combat.ts +416 -0
  326. package/templates/rts/src/sim/construction.ts +374 -0
  327. package/templates/rts/src/sim/economy.ts +167 -0
  328. package/templates/rts/src/sim/game.ts +1082 -0
  329. package/templates/rts/src/sim/movement.ts +371 -0
  330. package/templates/rts/src/sim/nav.ts +276 -0
  331. package/templates/rts/src/sim/production.ts +180 -0
  332. package/templates/rts/src/sim/terrain.ts +170 -0
  333. package/templates/rts/src/sim/types.ts +647 -0
  334. package/templates/rts/src/sim/vision.ts +46 -0
  335. package/templates/rts/src/state.ts +100 -0
  336. package/templates/{defense → rts}/src/style.css +21 -8
  337. package/templates/rts/src/ui/App.tsx +21 -0
  338. package/templates/rts/src/ui/Commands.tsx +129 -0
  339. package/templates/rts/src/ui/GameUi.tsx +22 -0
  340. package/templates/rts/src/ui/Hud.tsx +165 -0
  341. package/templates/rts/src/ui/Minimap.tsx +84 -0
  342. package/templates/rts/tailwind.config.ts +2 -0
  343. package/templates/rts/threenative.config.ts +56 -0
  344. package/templates/rts/tsconfig.json +17 -0
  345. package/templates/{defense → rts}/vite.config.ts +4 -1
  346. package/templates/runner/AGENTS.md +6 -10
  347. package/templates/runner/CLAUDE.md +6 -10
  348. package/templates/runner/README.md +3 -3
  349. package/templates/runner/package.json +13 -7
  350. package/templates/runner/playtests/performance.playtest.json +2 -2
  351. package/templates/runner/src/conventions.ts +4 -3
  352. package/templates/runner/src/entities/Runner.ts +54 -7
  353. package/templates/runner/src/game.ts +2 -0
  354. package/templates/runner/src/render/camera.ts +4 -2
  355. package/templates/runner/src/render/dust.ts +5 -2
  356. package/templates/runner/src/render/lighting.ts +41 -45
  357. package/templates/runner/src/render/loading.ts +2 -2
  358. package/templates/runner/src/render/materials.ts +165 -25
  359. package/templates/runner/src/render/palette.ts +17 -28
  360. package/templates/runner/src/render/postprocessing.ts +12 -2
  361. package/templates/runner/src/render/quality.ts +42 -96
  362. package/templates/runner/src/render/shapes.ts +59 -37
  363. package/templates/runner/src/render/sky.ts +32 -41
  364. package/templates/runner/src/render/touch-controls.ts +1 -1
  365. package/templates/runner/src/render/worldEnvironment.ts +52 -1
  366. package/templates/runner/src/scenes/Run.ts +26 -6
  367. package/templates/runner/src/track.ts +6 -1
  368. package/templates/runner/threenative.config.ts +14 -1
  369. package/templates/runner/vite.config.ts +4 -1
  370. package/templates/sailing/AGENTS.md +12 -12
  371. package/templates/sailing/CLAUDE.md +12 -12
  372. package/templates/sailing/assets/ship.glb +0 -0
  373. package/templates/sailing/package.json +13 -7
  374. package/templates/sailing/playtests/float-after-the-run-ends.playtest.json +10 -6
  375. package/templates/sailing/playtests/sails.playtest.json +33 -0
  376. package/templates/sailing/playtests/win.playtest.json +156 -8
  377. package/templates/sailing/src/conventions.ts +29 -2
  378. package/templates/sailing/src/entities/Ship.ts +381 -57
  379. package/templates/sailing/src/game.ts +14 -0
  380. package/templates/sailing/src/render/camera.ts +63 -9
  381. package/templates/sailing/src/render/lighting.ts +49 -27
  382. package/templates/sailing/src/render/materials.ts +50 -15
  383. package/templates/sailing/src/render/ocean.ts +647 -60
  384. package/templates/sailing/src/render/palette.ts +16 -12
  385. package/templates/sailing/src/render/postprocessing.ts +12 -2
  386. package/templates/sailing/src/render/props.ts +316 -442
  387. package/templates/sailing/src/render/quality.ts +14 -4
  388. package/templates/sailing/src/render/sky.ts +116 -23
  389. package/templates/sailing/src/render/worldEnvironment.ts +52 -1
  390. package/templates/sailing/src/scenes/Boot.ts +21 -0
  391. package/templates/sailing/src/scenes/Sailing.ts +173 -39
  392. package/templates/sailing/src/state.ts +6 -0
  393. package/templates/sailing/src/ui/Hud.tsx +41 -9
  394. package/templates/sailing/threenative.config.ts +14 -1
  395. package/templates/sailing/vite.config.ts +4 -1
  396. package/templates/shooter/AGENTS.md +27 -42
  397. package/templates/shooter/CLAUDE.md +27 -42
  398. package/templates/shooter/index.html +1 -0
  399. package/templates/shooter/package.json +13 -7
  400. package/templates/shooter/playtests/aim-alignment.playtest.json +58 -0
  401. package/templates/shooter/playtests/breakable-shatters.playtest.json +62 -0
  402. package/templates/shooter/playtests/bullet-holes.playtest.json +56 -0
  403. package/templates/shooter/playtests/camera-tracks-body-vertically.playtest.json +61 -0
  404. package/templates/shooter/playtests/crouch-lowers-the-eye.playtest.json +41 -0
  405. package/templates/shooter/playtests/death-no-snap.playtest.json +77 -0
  406. package/templates/shooter/playtests/debug-ads.playtest.json +58 -0
  407. package/templates/shooter/playtests/debug-clear.playtest.json +383 -0
  408. package/templates/shooter/playtests/debug-endurance.playtest.json +61 -0
  409. package/templates/shooter/playtests/debug-fire.playtest.json +119 -0
  410. package/templates/shooter/playtests/debug-restart.playtest.json +24 -0
  411. package/templates/shooter/playtests/enemy-body-is-a-body.playtest.json +79 -0
  412. package/templates/shooter/playtests/enemy-death-settles.playtest.json +64 -0
  413. package/templates/shooter/playtests/enemy-flinches-when-hit.playtest.json +75 -0
  414. package/templates/shooter/playtests/enemy-foot-contact.playtest.json +41 -0
  415. package/templates/shooter/playtests/enemy-material-is-not-shared.playtest.json +59 -0
  416. package/templates/shooter/playtests/enemy-reaches-walkway.playtest.json +80 -0
  417. package/templates/shooter/playtests/enemy-rifle-grip.playtest.json +101 -0
  418. package/templates/shooter/playtests/enemy-scale.playtest.json +56 -0
  419. package/templates/shooter/playtests/enemy-stops-without-snapping.playtest.json +486 -0
  420. package/templates/shooter/playtests/enemy-stride-matches-speed.playtest.json +198 -0
  421. package/templates/shooter/playtests/enemy-stride-under-crouch.playtest.json +87 -0
  422. package/templates/shooter/playtests/enemy-uses-crouch-clips.playtest.json +74 -0
  423. package/templates/shooter/playtests/five-soldiers.playtest.json +83 -0
  424. package/templates/shooter/playtests/flash-retires.playtest.json +62 -0
  425. package/templates/shooter/playtests/headshot-hits-head.playtest.json +132 -0
  426. package/templates/shooter/playtests/hold-to-fire.playtest.json +45 -0
  427. package/templates/shooter/playtests/input-control.playtest.json +43 -98
  428. package/templates/shooter/playtests/minimap-state.playtest.json +75 -0
  429. package/templates/shooter/playtests/performance.playtest.json +62 -26
  430. package/templates/{starter/playtests/forward.playtest.json → shooter/playtests/round-clock.playtest.json} +11 -16
  431. package/templates/shooter/playtests/shot-tracks-crosshair.playtest.json +79 -0
  432. package/templates/shooter/playtests/survives.playtest.json +36 -30
  433. package/templates/shooter/playtests/walkway-reachable.playtest.json +67 -0
  434. package/templates/shooter/src/entities/Breakables.ts +412 -0
  435. package/templates/shooter/src/entities/Enemy.ts +2095 -0
  436. package/templates/shooter/src/entities/FpsPlayer.ts +283 -0
  437. package/templates/shooter/src/entities/Rifle.ts +442 -0
  438. package/templates/shooter/src/entities/Target.ts +199 -83
  439. package/templates/shooter/src/entities/TouchControls.ts +276 -0
  440. package/templates/shooter/src/game.ts +75 -41
  441. package/templates/shooter/src/main.ts +0 -1
  442. package/templates/shooter/src/postPhysics.ts +36 -0
  443. package/templates/shooter/src/render/camera.ts +78 -74
  444. package/templates/shooter/src/render/decals.ts +142 -82
  445. package/templates/shooter/src/render/facade.ts +1373 -0
  446. package/templates/shooter/src/render/gunfx.ts +704 -0
  447. package/templates/shooter/src/render/lighting.ts +52 -38
  448. package/templates/shooter/src/render/loading.ts +2 -2
  449. package/templates/shooter/src/render/materials.ts +100 -88
  450. package/templates/shooter/src/render/occlusion.ts +108 -0
  451. package/templates/shooter/src/render/palette.ts +10 -10
  452. package/templates/shooter/src/render/palm.ts +455 -0
  453. package/templates/shooter/src/render/pooled-billboards.ts +144 -0
  454. package/templates/shooter/src/render/postprocessing.ts +15 -3
  455. package/templates/shooter/src/render/quality.ts +40 -82
  456. package/templates/shooter/src/render/scale.ts +148 -15
  457. package/templates/shooter/src/render/shapes.ts +138 -613
  458. package/templates/shooter/src/render/sky.ts +35 -35
  459. package/templates/shooter/src/render/town-schematic.ts +120 -0
  460. package/templates/shooter/src/render/town.ts +986 -0
  461. package/templates/shooter/src/render/townMaterials.ts +160 -0
  462. package/templates/shooter/src/render/vehicles.ts +741 -0
  463. package/templates/shooter/src/render/worldEnvironment.ts +52 -1
  464. package/templates/shooter/src/scenes/Play.ts +727 -650
  465. package/templates/shooter/src/state.ts +26 -41
  466. package/templates/shooter/src/style.css +207 -11
  467. package/templates/shooter/src/surfaces.ts +131 -0
  468. package/templates/shooter/src/ui/App.tsx +9 -10
  469. package/templates/shooter/src/ui/Crosshair.tsx +25 -18
  470. package/templates/shooter/src/ui/GameUi.tsx +6 -9
  471. package/templates/shooter/src/ui/Hud.tsx +428 -39
  472. package/templates/shooter/src/ui/Minimap.tsx +164 -0
  473. package/templates/shooter/src/ui/TouchOverlay.tsx +54 -0
  474. package/templates/shooter/src/ui/main.tsx +2 -3
  475. package/templates/shooter/threenative.config.ts +14 -1
  476. package/templates/shooter/vite.config.ts +4 -1
  477. package/templates/snow/.codex/config.toml +19 -0
  478. package/templates/snow/.cursor/mcp.json +32 -0
  479. package/templates/snow/.gemini/settings.json +32 -0
  480. package/templates/snow/.mcp.json +32 -0
  481. package/templates/snow/.vscode/mcp.json +36 -0
  482. package/templates/snow/.zed/settings.json +36 -0
  483. package/templates/snow/AGENTS.md +88 -0
  484. package/templates/snow/CLAUDE.md +90 -0
  485. package/templates/snow/README.md +26 -0
  486. package/templates/snow/assets/crunch.wav +0 -0
  487. package/templates/snow/assets/wind.wav +0 -0
  488. package/templates/snow/index.html +12 -0
  489. package/templates/snow/kit.json +7 -0
  490. package/templates/snow/native-playtests/snow-physics.playtest.json +150 -0
  491. package/templates/snow/native-playtests/survives.playtest.json +47 -0
  492. package/templates/snow/opencode.json +41 -0
  493. package/templates/snow/package.json +58 -0
  494. package/templates/snow/playtests/footsteps.playtest.json +95 -0
  495. package/templates/{defense → snow}/playtests/performance.playtest.json +4 -7
  496. package/templates/snow/playtests/snow-physics.playtest.json +154 -0
  497. package/templates/{defense → snow}/playtests/survives.playtest.json +26 -6
  498. package/templates/snow/playtests/touch-controls.playtest.json +71 -0
  499. package/templates/snow/playtests/weather.playtest.json +119 -0
  500. package/templates/snow/public/favicon.svg +5 -0
  501. package/templates/snow/src/audio.ts +58 -0
  502. package/templates/snow/src/commands.ts +8 -0
  503. package/templates/snow/src/entities/Explorer.ts +279 -0
  504. package/templates/snow/src/game.ts +69 -0
  505. package/templates/snow/src/main.ts +15 -0
  506. package/templates/snow/src/render/bootPrint.ts +50 -0
  507. package/templates/snow/src/render/camera.ts +84 -0
  508. package/templates/snow/src/render/explorer.ts +321 -0
  509. package/templates/snow/src/render/lighting.ts +50 -0
  510. package/templates/snow/src/render/loading.ts +325 -0
  511. package/templates/snow/src/render/materials.ts +36 -0
  512. package/templates/snow/src/render/palette.ts +17 -0
  513. package/templates/{defense → snow}/src/render/postprocessing.ts +12 -2
  514. package/templates/snow/src/render/props.ts +42 -0
  515. package/templates/{defense → snow}/src/render/quality.ts +37 -72
  516. package/templates/snow/src/render/scenery.ts +244 -0
  517. package/templates/snow/src/render/sky.ts +57 -0
  518. package/templates/snow/src/render/snowSurface.ts +259 -0
  519. package/templates/snow/src/render/touch-controls.ts +143 -0
  520. package/templates/snow/src/render/weather.ts +279 -0
  521. package/templates/snow/src/render/worldEnvironment.ts +809 -0
  522. package/templates/{defense → snow}/src/scenes/Boot.ts +4 -4
  523. package/templates/snow/src/scenes/Snow.ts +635 -0
  524. package/templates/snow/src/state.ts +46 -0
  525. package/templates/snow/src/style.css +143 -0
  526. package/templates/snow/src/terrain.ts +64 -0
  527. package/templates/snow/src/ui/App.tsx +15 -0
  528. package/templates/snow/src/ui/Controls.tsx +322 -0
  529. package/templates/snow/src/ui/GameUi.tsx +354 -0
  530. package/templates/snow/src/ui/icons.tsx +54 -0
  531. package/templates/snow/src/ui/main.tsx +7 -0
  532. package/templates/snow/tailwind.config.ts +2 -0
  533. package/templates/snow/threenative.config.ts +51 -0
  534. package/templates/snow/tsconfig.json +17 -0
  535. package/templates/snow/vite.config.ts +37 -0
  536. package/templates/starter/AGENTS.md +17 -17
  537. package/templates/starter/CLAUDE.md +17 -17
  538. package/templates/starter/native-playtests/render-chain.playtest.json +13 -45
  539. package/templates/starter/package.json +13 -7
  540. package/templates/starter/playtests/play.playtest.json +2 -1
  541. package/templates/starter/playtests/survives.playtest.json +1 -1
  542. package/templates/starter/src/conventions.ts +6 -3
  543. package/templates/starter/src/entities/Goal.ts +35 -42
  544. package/templates/starter/src/entities/Player.ts +99 -16
  545. package/templates/starter/src/render/arena.ts +131 -0
  546. package/templates/starter/src/render/lighting.ts +27 -44
  547. package/templates/starter/src/render/materials.ts +164 -35
  548. package/templates/starter/src/render/palette.ts +16 -16
  549. package/templates/starter/src/render/postprocessing.ts +6 -7
  550. package/templates/starter/src/render/quality.ts +43 -101
  551. package/templates/starter/src/render/shapes.ts +1 -1
  552. package/templates/starter/src/render/sky.ts +39 -45
  553. package/templates/starter/src/render/touch-controls.ts +3 -1
  554. package/templates/starter/src/render/worldEnvironment.ts +52 -1
  555. package/templates/starter/src/scenes/Play.ts +82 -81
  556. package/templates/starter/threenative.config.ts +14 -1
  557. package/templates/starter/vite.config.ts +4 -1
  558. package/templates/tower-defense/.codex/config.toml +19 -0
  559. package/templates/tower-defense/.cursor/mcp.json +32 -0
  560. package/templates/tower-defense/.gemini/settings.json +32 -0
  561. package/templates/tower-defense/.mcp.json +32 -0
  562. package/templates/tower-defense/.vscode/mcp.json +36 -0
  563. package/templates/tower-defense/.zed/settings.json +36 -0
  564. package/templates/{defense → tower-defense}/AGENTS.md +14 -12
  565. package/templates/{defense → tower-defense}/CLAUDE.md +14 -12
  566. package/templates/tower-defense/README.md +16 -0
  567. package/templates/tower-defense/index.html +12 -0
  568. package/templates/tower-defense/kit.json +7 -0
  569. package/templates/tower-defense/opencode.json +41 -0
  570. package/templates/tower-defense/package.json +56 -0
  571. package/templates/tower-defense/playtests/arsenal.playtest.json +214 -0
  572. package/templates/tower-defense/playtests/defeat.playtest.json +85 -0
  573. package/templates/tower-defense/playtests/look.playtest.json +130 -0
  574. package/templates/tower-defense/playtests/performance.playtest.json +77 -0
  575. package/templates/tower-defense/playtests/placement.playtest.json +115 -0
  576. package/templates/{defense → tower-defense}/playtests/pointer-placement.playtest.json +21 -49
  577. package/templates/tower-defense/playtests/strike.playtest.json +98 -0
  578. package/templates/tower-defense/playtests/survives.playtest.json +85 -0
  579. package/templates/tower-defense/playtests/target-priority.playtest.json +177 -0
  580. package/templates/tower-defense/playtests/upgrade-recycle.playtest.json +124 -0
  581. package/templates/tower-defense/playtests/victory.playtest.json +810 -0
  582. package/templates/tower-defense/src/balance.ts +187 -0
  583. package/templates/tower-defense/src/board/Board.ts +100 -0
  584. package/templates/tower-defense/src/board/Route.ts +84 -0
  585. package/templates/tower-defense/src/camera-rig.ts +62 -0
  586. package/templates/tower-defense/src/economy.ts +64 -0
  587. package/templates/tower-defense/src/effects/Effects.ts +284 -0
  588. package/templates/tower-defense/src/enemies/Enemy.ts +198 -0
  589. package/templates/tower-defense/src/game.ts +72 -0
  590. package/templates/tower-defense/src/intents.ts +21 -0
  591. package/templates/tower-defense/src/main.ts +15 -0
  592. package/templates/tower-defense/src/physics.ts +6 -0
  593. package/templates/tower-defense/src/render/camera.ts +38 -0
  594. package/templates/tower-defense/src/render/lighting.ts +42 -0
  595. package/templates/{defense → tower-defense}/src/render/loading.ts +3 -3
  596. package/templates/tower-defense/src/render/materials.ts +103 -0
  597. package/templates/tower-defense/src/render/palette.ts +58 -0
  598. package/templates/tower-defense/src/render/postprocessing.ts +46 -0
  599. package/templates/tower-defense/src/render/quality.ts +128 -0
  600. package/templates/tower-defense/src/render/shapes.ts +550 -0
  601. package/templates/tower-defense/src/render/sky.ts +27 -0
  602. package/templates/tower-defense/src/render/worldEnvironment.ts +809 -0
  603. package/templates/tower-defense/src/scenes/Battle.ts +539 -0
  604. package/templates/{shooter → tower-defense}/src/scenes/Boot.ts +3 -3
  605. package/templates/tower-defense/src/state.ts +88 -0
  606. package/templates/tower-defense/src/style.css +137 -0
  607. package/templates/tower-defense/src/towers/Tower.ts +230 -0
  608. package/templates/tower-defense/src/towers/targeting.ts +97 -0
  609. package/templates/tower-defense/src/ui/Hud.tsx +270 -0
  610. package/templates/tower-defense/src/ui/Menu.tsx +134 -0
  611. package/templates/tower-defense/src/ui/icons.tsx +54 -0
  612. package/templates/tower-defense/src/ui/main.tsx +14 -0
  613. package/templates/tower-defense/src/waves.ts +90 -0
  614. package/templates/{defense → tower-defense}/threenative.config.ts +14 -1
  615. package/templates/tower-defense/vite.config.ts +41 -0
  616. package/agent-files/.claude/skills/file-engine-bug/SKILL.md +0 -59
  617. package/agent-files/.claude/skills/ponytail/SKILL.md +0 -68
  618. package/agent-files/.claude/skills/prd-creator/SKILL.md +0 -40
  619. package/agent-files/.claude/skills/threenative-assets/SKILL.md +0 -53
  620. package/agent-files/.claude/skills/threenative-capabilities/SKILL.md +0 -27
  621. package/agent-files/.claude/skills/threenative-context/SKILL.md +0 -65
  622. package/agent-files/.claude/skills/threenative-performance/SKILL.md +0 -58
  623. package/agent-files/.claude/skills/threenative-playtest/SKILL.md +0 -44
  624. package/agent-files/.claude/skills/threenative-ui/SKILL.md +0 -20
  625. package/agent-files/.claude/skills/threenative-visuals/SKILL.md +0 -41
  626. package/agent-files/AGENT-ROLES.md +0 -26
  627. package/templates/action-rpg/src/render/shapes.ts +0 -269
  628. package/templates/action-rpg/src/render/types.ts +0 -3
  629. package/templates/action-rpg/src/scenes/Boot.ts +0 -12
  630. package/templates/defense/README.md +0 -10
  631. package/templates/defense/kit.json +0 -7
  632. package/templates/defense/playtests/leak.playtest.json +0 -23
  633. package/templates/defense/playtests/placement.playtest.json +0 -40
  634. package/templates/defense/playtests/scan.playtest.json +0 -20
  635. package/templates/defense/playtests/survive.playtest.json +0 -45
  636. package/templates/defense/src/attackers/Attacker.ts +0 -120
  637. package/templates/defense/src/board/Route.ts +0 -94
  638. package/templates/defense/src/conventions.ts +0 -18
  639. package/templates/defense/src/economy.ts +0 -36
  640. package/templates/defense/src/entities/Player.ts +0 -52
  641. package/templates/defense/src/game.ts +0 -51
  642. package/templates/defense/src/physics.ts +0 -13
  643. package/templates/defense/src/placement/Buildable.ts +0 -49
  644. package/templates/defense/src/render/camera.ts +0 -16
  645. package/templates/defense/src/render/lighting.ts +0 -37
  646. package/templates/defense/src/render/materials.ts +0 -22
  647. package/templates/defense/src/render/palette.ts +0 -28
  648. package/templates/defense/src/render/shapes.ts +0 -246
  649. package/templates/defense/src/render/sky.ts +0 -45
  650. package/templates/defense/src/scenes/Defense.ts +0 -231
  651. package/templates/defense/src/state.ts +0 -56
  652. package/templates/defense/src/towers/Tower.ts +0 -95
  653. package/templates/defense/src/towers/targeting.ts +0 -53
  654. package/templates/defense/src/ui/Hud.tsx +0 -62
  655. package/templates/defense/src/ui/Menu.tsx +0 -7
  656. package/templates/defense/src/waves.ts +0 -40
  657. package/templates/minimal/playtests/atmosphere.playtest.json +0 -32
  658. package/templates/minimal/src/render/hud.ts +0 -69
  659. package/templates/platformer/playtests/avoidance.playtest.json +0 -28
  660. package/templates/platformer/playtests/chase.playtest.json +0 -21
  661. package/templates/platformer/playtests/collision-layers.playtest.json +0 -36
  662. package/templates/platformer/playtests/oneway.playtest.json +0 -44
  663. package/templates/platformer/playtests/patrol.playtest.json +0 -13
  664. package/templates/platformer/playtests/physics.playtest.json +0 -14
  665. package/templates/platformer/playtests/stomp-rise.playtest.json +0 -55
  666. package/templates/platformer/playtests/terminal-loop-fail.playtest.json +0 -41
  667. package/templates/platformer/playtests/terminal-loop-win.playtest.json +0 -52
  668. package/templates/platformer/src/conventions.ts +0 -18
  669. package/templates/platformer/src/entities/Character.ts +0 -286
  670. package/templates/platformer/src/entities/Chaser.ts +0 -118
  671. package/templates/platformer/src/entities/Patrol.ts +0 -93
  672. package/templates/platformer/src/level/Platform.ts +0 -46
  673. package/templates/platformer/src/render/rig.ts +0 -60
  674. package/templates/platformer/src/render/terrain.ts +0 -31
  675. package/templates/platformer/src/scenes/Level.ts +0 -241
  676. package/templates/puzzle/README.md +0 -43
  677. package/templates/puzzle/playtests/carry.playtest.json +0 -71
  678. package/templates/puzzle/playtests/swing.playtest.json +0 -38
  679. package/templates/puzzle/src/conventions.ts +0 -25
  680. package/templates/puzzle/src/entities/Ball.ts +0 -70
  681. package/templates/puzzle/src/entities/Gripper.ts +0 -69
  682. package/templates/puzzle/src/entities/Pendulum.ts +0 -89
  683. package/templates/puzzle/src/physics.ts +0 -19
  684. package/templates/puzzle/src/room.ts +0 -83
  685. package/templates/puzzle/src/scenes/Boot.ts +0 -12
  686. package/templates/puzzle/src/scenes/Puzzle.ts +0 -158
  687. package/templates/shooter/playtests/combat.playtest.json +0 -48
  688. package/templates/shooter/playtests/fail.playtest.json +0 -31
  689. package/templates/shooter/playtests/per-item.playtest.json +0 -59
  690. package/templates/shooter/playtests/shooter.playtest.json +0 -99
  691. package/templates/shooter/playtests/touch-controls.playtest.json +0 -42
  692. package/templates/shooter/playtests/weapon-cycle.playtest.json +0 -164
  693. package/templates/shooter/src/combat/damage.ts +0 -40
  694. package/templates/shooter/src/conventions.ts +0 -51
  695. package/templates/shooter/src/entities/Pickup.ts +0 -70
  696. package/templates/shooter/src/entities/Player.ts +0 -310
  697. package/templates/shooter/src/level/SpawnPoints.ts +0 -28
  698. package/templates/shooter/src/playtest-events.ts +0 -15
  699. package/templates/shooter/src/render/touch-controls.ts +0 -305
  700. package/templates/shooter/src/render/types.ts +0 -3
  701. package/templates/shooter/src/render/ui.css +0 -330
  702. package/templates/shooter/src/render/ui.ts +0 -75
  703. package/templates/shooter/src/render/vfx.ts +0 -215
  704. package/templates/shooter/src/ui/Menu.tsx +0 -41
  705. package/templates/shooter/src/waves.ts +0 -50
  706. package/templates/shooter/src/weapons/Hitscan.ts +0 -42
  707. package/templates/shooter/src/weapons/Projectile.ts +0 -92
  708. package/templates/shooter/src/weapons/Viewmodel.ts +0 -275
  709. package/templates/starter/playtests/assets.playtest.json +0 -65
  710. package/templates/starter/playtests/buffer.playtest.json +0 -79
  711. package/templates/starter/playtests/cloth.playtest.json +0 -113
  712. package/templates/starter/playtests/coyote.playtest.json +0 -87
  713. package/templates/starter/playtests/gameover.playtest.json +0 -66
  714. package/templates/starter/playtests/goal.playtest.json +0 -67
  715. package/templates/starter/playtests/look.playtest.json +0 -175
  716. package/templates/starter/playtests/models-baseline.png +0 -0
  717. package/templates/starter/playtests/models.playtest.json +0 -74
  718. package/templates/starter/playtests/monitoring.playtest.json +0 -72
  719. package/templates/starter/playtests/odometer.playtest.json +0 -54
  720. package/templates/starter/playtests/restart.playtest.json +0 -91
  721. package/templates/starter/playtests/seed.playtest.json +0 -54
  722. package/templates/starter/playtests/textures-baseline.png +0 -0
  723. package/templates/starter/playtests/textures.playtest.json +0 -74
  724. package/templates/starter/playtests/touch-controls.playtest.json +0 -42
  725. package/templates/starter/playtests/zoom-pinch.playtest.json +0 -86
  726. package/templates/starter/playtests/zoom-wheel.playtest.json +0 -59
  727. package/templates/starter/src/render/coast.ts +0 -199
  728. package/templates/starter/src/render/hero.ts +0 -88
  729. package/templates/starter/src/render/implicitSurface.ts +0 -199
  730. package/templates/starter/src/render/kuwahara.ts +0 -174
  731. package/templates/starter/src/render/outline.ts +0 -141
  732. package/templates/starter/src/render/painterly.ts +0 -86
  733. package/templates/starter/src/render/rockRidge.ts +0 -198
  734. package/templates/starter/src/render/rockRidge.worker.ts +0 -77
  735. package/templates/starter/src/render/scenery.ts +0 -40
  736. package/templates/starter/src/render/textureLifetime.ts +0 -53
  737. package/templates/starter/src/render/water.ts +0 -38
  738. package/templates/starter/src/render/watercolor.ts +0 -85
  739. /package/templates/{starter → puzzle}/playtests/boot-failure.playtest.json +0 -0
  740. /package/templates/{starter → puzzle}/playtests/pause.playtest.json +0 -0
  741. /package/templates/{defense → rain}/.codex/config.toml +0 -0
  742. /package/templates/{defense → rain}/.cursor/mcp.json +0 -0
  743. /package/templates/{defense → rain}/.gemini/settings.json +0 -0
  744. /package/templates/{defense → rain}/.mcp.json +0 -0
  745. /package/templates/{defense → rain}/.vscode/mcp.json +0 -0
  746. /package/templates/{defense → rain}/.zed/settings.json +0 -0
  747. /package/templates/{defense → rain}/opencode.json +0 -0
  748. /package/templates/{defense → rain}/src/main.ts +0 -0
  749. /package/templates/{defense → rts}/index.html +0 -0
  750. /package/templates/{defense → rts}/src/ui/main.tsx +0 -0
  751. /package/templates/{defense → tower-defense}/public/favicon.svg +0 -0
  752. /package/templates/{defense → tower-defense}/src/playtest-events.ts +0 -0
  753. /package/templates/{defense → tower-defense}/src/ui/App.tsx +0 -0
  754. /package/templates/{defense → tower-defense}/src/ui/GameUi.tsx +0 -0
  755. /package/templates/{defense → tower-defense}/tailwind.config.ts +0 -0
  756. /package/templates/{defense → tower-defense}/tsconfig.json +0 -0
@@ -1,193 +1,830 @@
1
- import { type ICtx, InstancedBatch, PathFollow3D } from "@threenative/core";
1
+ import { type ICtx, InstancedBatch } from "@threenative/core";
2
2
  import { Area3D, CollisionShape3D, type IPhysicsContext, RigidBody3D } from "@threenative/physics";
3
3
  import {
4
4
  BoxGeometry,
5
- CapsuleGeometry,
5
+ BufferAttribute,
6
+ BufferGeometry,
6
7
  Group,
7
8
  Mesh,
8
- MeshStandardMaterial,
9
9
  Raycaster,
10
- SphereGeometry,
11
10
  Vector3,
12
11
  } from "three";
13
-
14
- /** Reused by the grandstand crowd placement; a fresh axis per seat is pure garbage. */
15
- const UP = new Vector3(0, 1, 0);
16
12
  import { Boost } from "../kart/boost.js";
17
13
  import { createMaterials } from "../render/materials.js";
18
- import { palette } from "../render/palette.js";
19
- import { grandstand, hoardingGeometry, treeGeometry, tyreStackGeometry } from "../render/shapes.js";
14
+ import { grandstand, treeGeometry, tyreStackGeometry } from "../render/shapes.js";
20
15
  import type { GameState } from "../state.js";
21
- import { Checkline } from "./Checkline.js";
16
+ import { Checkline, type ChecklineId } from "./Checkline.js";
22
17
  import type { IRayHit, IntersectRay } from "./TrackSector.js";
18
+ import {
19
+ BARRIER_OFFSET,
20
+ CIRCUIT,
21
+ GRID,
22
+ GRID_DISTANCE,
23
+ HALF,
24
+ type ICircuitSample,
25
+ KERB_HEIGHT,
26
+ KERB_WIDTH,
27
+ LINE_AT,
28
+ ROAD_LIFT,
29
+ RUNOFF,
30
+ TRACK_WIDTH,
31
+ groundHeight,
32
+ lineDistance,
33
+ terrainHeight,
34
+ } from "./circuit.js";
23
35
 
24
36
  export type TrackCtx = ICtx<GameState, IPhysicsContext>;
25
37
 
26
- export const TRACK_WIDTH = 7;
27
38
  export const TOTAL_LAPS = 3;
28
- export const ROUTE_POINTS = [
29
- new Vector3(10, 0, -18),
30
- new Vector3(18, 0, -18),
31
- new Vector3(18, 0, 18),
32
- new Vector3(-18, 0, 18),
33
- new Vector3(-18, 0, -18),
34
- ] as const;
35
39
 
36
- export const RACING_LINE = new PathFollow3D({ loop: true, points: ROUTE_POINTS });
40
+ /**
41
+ * Godot's `collision_layer` for the circuit, so a car's `collision_mask` can say what it may hit.
42
+ *
43
+ * The kerbs are on the road's layer: a wheel ray that finds one rides over it, which is what a
44
+ * kerb is for, and a car that puts two wheels on the rumble strip gets the same bump a real one
45
+ * does instead of stopping dead against an invisible wall.
46
+ */
47
+ export const LAYER = { barrier: 8, car: 1, field: 4, road: 2 } as const;
37
48
 
38
- export interface ITrackBuild {
39
- readonly boost: Boost;
40
- readonly boostArea: Area3D;
41
- readonly gates: readonly Checkline[];
42
- readonly route: PathFollow3D;
43
- readonly roadMeshes: readonly Mesh[];
49
+ /** One station of the build: the centreline here, and the surfaces derived from it. */
50
+ /** The kerb's inner edge is a ramp this long, not a step. See `buildKerbs`. */
51
+ const CHAMFER = 0.35;
52
+
53
+ /**
54
+ * How much of the local radius the drivable surface may claim, as a fraction.
55
+ *
56
+ * A fixed-width ribbon cannot follow a hairpin: this circuit's tightest corner is 15.5 m of radius
57
+ * and the two legs of the loop pass 25 m apart, so a 22 m-wide ribbon puts its inside edge within
58
+ * 1.5 m of the corner's centre — where it **crosses the other leg's ribbon** at a different height.
59
+ * The result is a 40-degree wall of tarmac in the middle of the hairpin, which is what the demo
60
+ * driver kept driving into. Inside 55% of the radius the ribbon stops and the infield takes over,
61
+ * which is also what the inside of a real hairpin is.
62
+ */
63
+ const DRIVABLE_RADIUS_SHARE = 0.55;
64
+
65
+ function drivableHalf(station: IStation): number {
66
+ const radius = station.sample.radius;
67
+ if (!Number.isFinite(radius)) return HALF + RUNOFF;
68
+ return Math.min(HALF + RUNOFF, Math.max(2.2, radius * DRIVABLE_RADIUS_SHARE));
69
+ }
70
+
71
+ interface IStation {
72
+ readonly distance: number;
73
+ readonly sample: ICircuitSample;
74
+ /** The banking rise, positive raising the outside edge. */
75
+ readonly bank: number;
76
+ }
77
+
78
+ function clamp(value: number, low: number, high: number): number {
79
+ return value < low ? low : value > high ? high : value;
80
+ }
81
+
82
+ /**
83
+ * A point `offset` metres right of the centreline, on the banked tarmac surface.
84
+ *
85
+ * The height is the **centreline's** ground height tilted by the banking, not the ground height
86
+ * under the point: that is what makes the cross-section a plane pivoting on the crown of the road,
87
+ * which is what `terrainHeight` then cuts and fills the ground to meet.
88
+ */
89
+ function onTrack(
90
+ station: IStation,
91
+ offset: number,
92
+ lift = ROAD_LIFT,
93
+ target = new Vector3(),
94
+ ): Vector3 {
95
+ const { point, right } = station.sample;
96
+ target.set(point.x + right.x * offset, 0, point.z + right.z * offset);
97
+ target.y = point.y - ROAD_LIFT + lift - offset * station.bank;
98
+ return target;
99
+ }
100
+
101
+ /** A point `offset` metres right of the centreline, on the ground rather than on the tarmac. */
102
+ function onGround(station: IStation, offset: number, lift = 0, target = new Vector3()): Vector3 {
103
+ const { point, right } = station.sample;
104
+ target.set(point.x + right.x * offset, 0, point.z + right.z * offset);
105
+ target.y = terrainHeight(target.x, target.z) + lift;
106
+ return target;
107
+ }
108
+
109
+ function stationAt(distance: number): IStation {
110
+ const sample = CIRCUIT.at(distance, CIRCUIT.createSample());
111
+ return { bank: sample.bank, distance, sample };
112
+ }
113
+
114
+ /** Every `every`-th station around the lap. */
115
+ function stations(every: number): IStation[] {
116
+ const built: IStation[] = [];
117
+ for (let distance = 0; distance < CIRCUIT.totalLength; distance += CIRCUIT.spacing * every) {
118
+ built.push(stationAt(distance));
119
+ }
120
+ return built;
121
+ }
122
+
123
+ /**
124
+ * A quad strip from cross-sections.
125
+ *
126
+ * Every surface on this circuit is a ribbon — the road, the white lines, the run-off, the kerbs,
127
+ * the armco and the pit wall are all "a row of cross-sections, one per station, stitched into
128
+ * quads". One function for all of them is the difference between five hundred draw calls and six.
129
+ *
130
+ * The winding is not negotiable: rows advance along the driving direction and points inside a row
131
+ * advance to the driver's right, which puts the road's normals **up**. A strip wound the other way
132
+ * is invisible from the chase camera and green in every assertion.
133
+ */
134
+ function quadStrip(
135
+ rows: readonly (readonly Vector3[])[],
136
+ uv: (row: number, column: number) => [number, number],
137
+ ): BufferGeometry {
138
+ const width = rows[0]?.length ?? 0;
139
+ if (width < 2) throw new Error("quadStrip needs at least two points per cross-section.");
140
+ const positions = new Float32Array(rows.length * width * 3);
141
+ const uvs = new Float32Array(rows.length * width * 2);
142
+ const indices: number[] = [];
143
+ for (let row = 0; row < rows.length; row += 1) {
144
+ const section = rows[row];
145
+ if (section === undefined || section.length !== width)
146
+ throw new Error("quadStrip cross-sections must all have the same width.");
147
+ for (let column = 0; column < width; column += 1) {
148
+ const point = section[column];
149
+ if (point === undefined) throw new Error("quadStrip cross-section point is missing.");
150
+ positions.set([point.x, point.y, point.z], (row * width + column) * 3);
151
+ const [u, v] = uv(row, column);
152
+ uvs.set([u, v], (row * width + column) * 2);
153
+ }
154
+ }
155
+ for (let row = 0; row + 1 < rows.length; row += 1) {
156
+ for (let column = 0; column + 1 < width; column += 1) {
157
+ const a = row * width + column;
158
+ indices.push(a, a + 1, a + width, a + 1, a + width + 1, a + width);
159
+ }
160
+ }
161
+ const geometry = new BufferGeometry();
162
+ geometry.setAttribute("position", new BufferAttribute(positions, 3));
163
+ geometry.setAttribute("uv", new BufferAttribute(uvs, 2));
164
+ geometry.setIndex(indices);
165
+ geometry.computeVertexNormals();
166
+ return geometry;
167
+ }
168
+
169
+ /** Closes a ribbon back on itself, so the last station joins the first. */
170
+ function looped<T>(rows: readonly T[]): readonly T[] {
171
+ const first = rows[0];
172
+ if (first === undefined) throw new Error("looped needs at least one row.");
173
+ return [...rows, first];
44
174
  }
45
175
 
46
- function roadSegment(
176
+ /**
177
+ * A fixed trimesh for a surface the car drives on or hits.
178
+ *
179
+ * The geometry is already in world coordinates and the mesh sits at the origin, so the body's
180
+ * translation is zero and the collider is the triangles on screen. One body for the whole road
181
+ * rather than one box per segment: 750 boxes for a smooth ribbon is 750 shapes a wheel ray
182
+ * considers every step.
183
+ */
184
+ function fixedTrimesh(
47
185
  ctx: TrackCtx,
48
- a: Vector3,
49
- b: Vector3,
50
- materials: ReturnType<typeof createMaterials>,
51
- ): Mesh {
52
- const midpoint = a.clone().lerp(b, 0.5);
53
- const length = a.distanceTo(b);
54
- const road = new Mesh(new BoxGeometry(length, 0.28, TRACK_WIDTH), materials.road);
55
- road.position.set(midpoint.x, -0.14, midpoint.z);
56
- road.rotation.y = Math.atan2(b.z - a.z, b.x - a.x);
57
- road.receiveShadow = true;
58
- ctx.add(road);
59
- new RigidBody3D({
60
- collisionLayer: 2,
61
- collisionMask: 1,
62
- object: road,
186
+ mesh: Mesh,
187
+ collisionLayer: number,
188
+ name: string,
189
+ ): RigidBody3D {
190
+ mesh.name = name;
191
+ return new RigidBody3D({
192
+ collisionLayer,
193
+ collisionMask: LAYER.car,
194
+ object: mesh,
63
195
  physics: ctx.physics,
64
- shape: CollisionShape3D.box(length, 0.28, TRACK_WIDTH),
196
+ shape: CollisionShape3D.fromMesh(mesh, "trimesh"),
65
197
  type: "fixed",
66
198
  });
67
- return road;
199
+ }
200
+
201
+ /** The ground is drawn this far below the height the road is laid to. A 5 m grid cannot follow a
202
+ * banked cross-section exactly, and where it errs high the grass shows through the tarmac in
203
+ * patches; sinking it 30 cm turns that into a road bed standing proud of the field. It is drawn,
204
+ * never collided, so nothing but the picture depends on it. */
205
+ const TERRAIN_SINK = 0.3;
206
+
207
+ function buildTerrain(ctx: TrackCtx, materials: ReturnType<typeof createMaterials>): void {
208
+ // The ground is a grid over the circuit's bounding box and a long way past it, its height read
209
+ // from the same {@link groundHeight} the road is draped on. That is why nothing here can be
210
+ // airborne over a crest: the tarmac cannot be somewhere the ground is not.
211
+ let minX = Number.POSITIVE_INFINITY;
212
+ let maxX = Number.NEGATIVE_INFINITY;
213
+ let minZ = Number.POSITIVE_INFINITY;
214
+ let maxZ = Number.NEGATIVE_INFINITY;
215
+ for (const station of stations(4)) {
216
+ minX = Math.min(minX, station.sample.point.x);
217
+ maxX = Math.max(maxX, station.sample.point.x);
218
+ minZ = Math.min(minZ, station.sample.point.z);
219
+ maxZ = Math.max(maxZ, station.sample.point.z);
220
+ }
221
+ const margin = 180;
222
+ const step = 5;
223
+ // The column and row counts are computed from the bounds rather than counted inside the loop:
224
+ // counting a running total and then using it as the row stride builds an index buffer for a
225
+ // 63-by-4977 grid, which Rapier rejects as an out-of-range index rather than as a bad shape.
226
+ const minColumn = minX - margin;
227
+ const minRow = minZ - margin;
228
+ const width = Math.floor((maxX + margin - minColumn) / step) + 1;
229
+ const rows = Math.floor((maxZ + margin - minRow) / step) + 1;
230
+ const positions = new Float32Array(rows * width * 3);
231
+ const uvs = new Float32Array(rows * width * 2);
232
+ const indices: number[] = [];
233
+ for (let row = 0; row < rows; row += 1) {
234
+ for (let column = 0; column < width; column += 1) {
235
+ const x = minColumn + column * step;
236
+ const z = minRow + row * step;
237
+ const at = row * width + column;
238
+ positions[at * 3] = x;
239
+ positions[at * 3 + 1] = terrainHeight(x, z) - TERRAIN_SINK;
240
+ positions[at * 3 + 2] = z;
241
+ uvs[at * 2] = x / 9;
242
+ uvs[at * 2 + 1] = z / 9;
243
+ if (row + 1 < rows && column + 1 < width) {
244
+ indices.push(at, at + width, at + 1, at + 1, at + width, at + width + 1);
245
+ }
246
+ }
247
+ }
248
+ const geometry = new BufferGeometry();
249
+ geometry.setAttribute("position", new BufferAttribute(new Float32Array(positions), 3));
250
+ geometry.setAttribute("uv", new BufferAttribute(new Float32Array(uvs), 2));
251
+ geometry.setIndex(indices);
252
+ geometry.computeVertexNormals();
253
+ // **Drawn, not collided.** Everything the wheels can reach is the drivable ribbon, and the
254
+ // armco is what bounds it: a car cannot get further than 7.7 m from the centreline, and the
255
+ // ribbon is 11 m of it. A second collider under the road can only disagree with the road — a 5 m
256
+ // grid cannot follow a banked cross-section exactly, and the disagreement is a 10 cm ridge the
257
+ // car rides up and beaches on. Measured, twice, at two different corners.
258
+ const ground = new Mesh(geometry, materials.grass);
259
+ ground.receiveShadow = true;
260
+ ctx.add(ground);
261
+ }
262
+
263
+ function buildRoad(
264
+ ctx: TrackCtx,
265
+ materials: ReturnType<typeof createMaterials>,
266
+ ): readonly IStation[] {
267
+ const all = stations(1);
268
+ // `u` spans the road once, `v` runs 8 m per tile: the asphalt texture carries the racing-line
269
+ // rubber across the width, so the u axis must not repeat.
270
+ const tarmacUV = (row: number, column: number): [number, number] => [
271
+ column,
272
+ (all[row]?.distance ?? 0) / 8,
273
+ ];
274
+ // The drivable surface, and the one body the wheels touch. It runs the full width of the road
275
+ // **and** its run-off as a single ribbon, because two coplanar trimeshes meeting at the white line
276
+ // leave a seam a wheel ray can fall through, and a seam under a car at speed is a bump.
277
+ // It is not drawn: the tarmac and the run-off are drawn on top of it, a few millimetres up.
278
+ const drivable = new Mesh(
279
+ quadStrip(
280
+ looped(
281
+ all.map((station) => {
282
+ const half = drivableHalf(station);
283
+ return [onTrack(station, -half), onTrack(station, half)];
284
+ }),
285
+ ),
286
+ tarmacUV,
287
+ ),
288
+ materials.road,
289
+ );
290
+ drivable.visible = false;
291
+ ctx.add(drivable);
292
+ fixedTrimesh(ctx, drivable, LAYER.road, "road");
293
+
294
+ // The tarmac: 9 m of it, drawn on the drivable ribbon.
295
+ const road = new Mesh(
296
+ quadStrip(
297
+ looped(all.map((station) => [onTrack(station, -HALF, 0.004), onTrack(station, HALF, 0.004)])),
298
+ tarmacUV,
299
+ ),
300
+ materials.road,
301
+ );
302
+ road.receiveShadow = false;
303
+ ctx.add(road);
304
+
305
+ // The paved run-off past the white line: a different surface, drivable, and lighter. One strip
306
+ // per side and **not under the tarmac**: run underneath it, it sat 2 mm below the road and
307
+ // z-fought it into light and dark bands across the whole width at any distance.
308
+ for (const side of [1, -1] as const) {
309
+ const runoff = new Mesh(
310
+ quadStrip(
311
+ looped(
312
+ all.map((station) => {
313
+ const edge = onTrack(station, side * HALF, 0.002);
314
+ const far = onTrack(station, side * drivableHalf(station), 0.002);
315
+ return side > 0 ? [edge, far] : [far, edge];
316
+ }),
317
+ ),
318
+ (row, column) => [column * RUNOFF, (all[row]?.distance ?? 0) / 8],
319
+ ),
320
+ materials.runoff,
321
+ );
322
+ runoff.receiveShadow = true;
323
+ ctx.add(runoff);
324
+ }
325
+
326
+ // White edge lines, laid on the tarmac and a centimetre above it.
327
+ // One strip per side: interleaving the two edges into one strip joins them with a quad across
328
+ // the whole road, which draws as a white transverse bar at every station.
329
+ for (const [from, to] of [
330
+ [-HALF, -HALF + 0.4],
331
+ [HALF - 0.4, HALF],
332
+ ] as const) {
333
+ const edge = new Mesh(
334
+ quadStrip(
335
+ looped(
336
+ all.map((station) => [
337
+ onTrack(station, from, ROAD_LIFT + 0.012),
338
+ onTrack(station, to, ROAD_LIFT + 0.012),
339
+ ]),
340
+ ),
341
+ (row, column) => [column, row * 1.1],
342
+ ),
343
+ materials.line,
344
+ );
345
+ ctx.add(edge);
346
+ }
347
+ return all;
348
+ }
349
+
350
+ /** Where a kerb stands: the inside of every corner, and the outside of the tight ones. */
351
+ function kerbSides(station: IStation): { left: number; right: number } {
352
+ const curvature = station.sample.curvature;
353
+ const inside = Math.abs(curvature) > 1 / 150;
354
+ const outside = Math.abs(curvature) > 1 / 42;
355
+ return {
356
+ left: curvature < 0 ? (inside ? 1 : 0) : outside ? 1 : 0,
357
+ right: curvature > 0 ? (inside ? 1 : 0) : outside ? 1 : 0,
358
+ };
359
+ }
360
+
361
+ function buildKerbs(
362
+ ctx: TrackCtx,
363
+ all: readonly IStation[],
364
+ materials: ReturnType<typeof createMaterials>,
365
+ ): void {
366
+ // Every second station: a 15 m hairpin still turns within 3 cm of its design radius at 2.2 m.
367
+ const coarse = all.filter((_station, index) => index % 2 === 0);
368
+ let runs = 0;
369
+ for (const side of [1, -1] as const) {
370
+ // **Only real kerb becomes geometry.** A station with no kerb would contribute a cross-section
371
+ // of zero width, and the quads between two of those are zero-area triangles — which a Rapier
372
+ // trimesh happily accepts and a wheel ray then reports a meaningless normal for. The car ends
373
+ // up pitched onto its nose with the strut at maximum compression, and no throttle moves it.
374
+ // Measured: the demo driver beached on a straight, in the middle of the road, twice.
375
+ //
376
+ // So the stations are grouped into **runs** and each run is its own strip, its own mesh and its
377
+ // own collider. A circuit has a handful of kerbed corners, so a handful of draws.
378
+ let run: Vector3[][] = [];
379
+ const flush = (): void => {
380
+ if (run.length < 2) {
381
+ run = [];
382
+ return;
383
+ }
384
+ runs += 1;
385
+ const kerbs = new Mesh(
386
+ quadStrip(run, (row, column) => [column, (row * 2.2) / 1.2]),
387
+ materials.kerb,
388
+ );
389
+ kerbs.castShadow = true;
390
+ kerbs.receiveShadow = true;
391
+ ctx.add(kerbs);
392
+ fixedTrimesh(ctx, kerbs, LAYER.road, `kerbs-${side > 0 ? "right" : "left"}-${runs}`);
393
+ run = [];
394
+ };
395
+ for (const station of coarse) {
396
+ const sides = kerbSides(station);
397
+ const width = KERB_WIDTH * (side > 0 ? sides.right : sides.left);
398
+ if (width <= 0) {
399
+ flush();
400
+ continue;
401
+ }
402
+ const inner = side * HALF;
403
+ const outer = side * (HALF + width);
404
+ const rise = KERB_HEIGHT;
405
+ // **Chamfered**, and that is the whole reason the kerb is a kerb. A 5 cm vertical face is a
406
+ // step: at 14 m/s a wheel that finds one is launched, and the car leaves the road sideways.
407
+ // A kerb is a rumble strip, so it is a ramp: 5 cm over 35 cm, which any speed rolls over.
408
+ const shoulder = side * (HALF + Math.min(CHAMFER, width));
409
+ run.push(
410
+ side > 0
411
+ ? [
412
+ onTrack(station, inner, 0.004),
413
+ onTrack(station, shoulder, 0.004 + rise),
414
+ onTrack(station, outer, 0.004 + rise),
415
+ onTrack(station, outer, 0.004),
416
+ ]
417
+ : [
418
+ onTrack(station, outer, 0.004),
419
+ onTrack(station, shoulder, 0.004 + rise),
420
+ onTrack(station, inner, 0.004 + rise),
421
+ onTrack(station, inner, 0.004),
422
+ ],
423
+ );
424
+ }
425
+ flush();
426
+ }
68
427
  }
69
428
 
70
429
  /**
71
- * One kerb stone, recorded into a shared batch rather than drawn on its own.
430
+ * The barrier line: armco all the way round, at a distance that follows the corner.
72
431
  *
73
- * Every kerb is the same box at a different length and angle, so a unit box scaled per placement
74
- * draws exactly what a per-segment `BoxGeometry` drew — as one draw for the whole track instead of
75
- * two per sector. Change `materials.curb` and every kerb changes with it; the batch picks nothing.
432
+ * A constant offset does not work on a 10 m hairpin — the inside barrier would land on the
433
+ * centreline — so the inside follows the local radius and stops 1.2 m past the white line, while
434
+ * the outside keeps the full run-off. That is what makes the circuit impossible to leave: there is
435
+ * a collider the whole way round, so a car that runs wide loses time instead of losing the race.
76
436
  */
77
- function addCurb(
78
- curbs: InstancedBatch,
79
- alternate: InstancedBatch,
80
- a: Vector3,
81
- b: Vector3,
82
- side: number,
437
+ function barrierOffset(station: IStation, side: 1 | -1): number {
438
+ const curvature = station.sample.curvature;
439
+ if (curvature * side <= 1 / 90) return BARRIER_OFFSET;
440
+ return clamp(station.sample.radius - HALF - 1.2, 0.4, BARRIER_OFFSET);
441
+ }
442
+
443
+ function buildBarriers(
444
+ ctx: TrackCtx,
445
+ all: readonly IStation[],
446
+ materials: ReturnType<typeof createMaterials>,
83
447
  ): void {
84
- const direction = b.clone().sub(a).setY(0).normalize();
85
- const normal = new Vector3(-direction.z, 0, direction.x).multiplyScalar(
86
- side * (TRACK_WIDTH / 2 + 0.28),
448
+ const coarse = all.filter((_station, index) => index % 3 === 0);
449
+ const rows: Vector3[][] = [];
450
+ for (const station of coarse) {
451
+ for (const side of [1, -1] as const) {
452
+ const offset = barrierOffset(station, side);
453
+ const inner = offset - 0.14;
454
+ const outer = offset + 0.14;
455
+ const low = 0.4;
456
+ const high = 1.04;
457
+ rows.push(
458
+ side > 0
459
+ ? [
460
+ onGround(station, inner, low),
461
+ onGround(station, outer, low),
462
+ onGround(station, outer, high),
463
+ onGround(station, inner, high),
464
+ ]
465
+ : [
466
+ onGround(station, outer, low),
467
+ onGround(station, inner, low),
468
+ onGround(station, inner, high),
469
+ onGround(station, outer, high),
470
+ ],
471
+ );
472
+ }
473
+ }
474
+ const armco = new Mesh(
475
+ quadStrip(looped(rows), (row, column) => [column, row * 3.3]),
476
+ materials.armco,
87
477
  );
88
- // Both ends are pulled in by half the track width plus the kerb's own offset. Run to the raw
89
- // route point and the kerbs of two sectors cross at right angles inside the corner; the overlap
90
- // shows as a bitten-out notch in the middle of the stripe pattern. The square corner blocks that
91
- // `buildTrack` places take over from here.
92
- const inset = TRACK_WIDTH / 2 + 0.28;
93
- const from = a.clone().addScaledVector(direction, inset);
94
- const length = Math.max(a.distanceTo(b) - inset * 2, 0.6);
95
- // Kerbing is **striped**, and the stripes are what make a corner readable at speed. One long
96
- // cream box per sector is what shipped, and the first frame showed a plain white line: correct
97
- // geometry, no information. Two batches alternating along the sector cost one extra draw for the
98
- // whole circuit.
99
- const blocks = Math.max(2, Math.round(length / 1.3));
100
- const step = length / blocks;
101
- for (let index = 0; index < blocks; index += 1) {
102
- const centre = from
103
- .clone()
104
- .addScaledVector(direction, step * (index + 0.5))
105
- .add(normal);
106
- (index % 2 === 0 ? curbs : alternate).place({
107
- position: [centre.x, 0.08, centre.z],
108
- rotation: [0, Math.atan2(direction.z, direction.x), 0],
109
- scale: [step * 0.98, 0.18, 0.5],
110
- });
478
+ armco.castShadow = true;
479
+ ctx.add(armco);
480
+ fixedTrimesh(ctx, armco, LAYER.barrier, "armco");
481
+
482
+ // The posts. Decoration: the rail above them is the collider, and a hundred-odd fixed bodies for
483
+ // the same line was the cost `buildStaticColliders` used to pay.
484
+ const posts = new InstancedBatch({
485
+ geometry: new BoxGeometry(0.16, 1.2, 0.16),
486
+ material: materials.structure,
487
+ });
488
+ for (const station of all) {
489
+ if (station.distance % 8 >= CIRCUIT.spacing) continue;
490
+ for (const side of [1, -1] as const) {
491
+ const at = onGround(station, barrierOffset(station, side), 0.6);
492
+ posts.place({
493
+ position: [at.x, at.y, at.z],
494
+ rotation: [0, Math.atan2(station.sample.right.z, station.sample.right.x), 0],
495
+ scale: [1, 1, 1],
496
+ });
497
+ }
111
498
  }
499
+ const postMesh = posts.build({ castShadow: true, name: "armco-posts" });
500
+ if (postMesh !== undefined) ctx.add(postMesh);
112
501
  }
113
502
 
114
503
  function gate(
115
504
  ctx: TrackCtx,
116
- id: Checkline["id"],
117
- at: Vector3,
118
- forward: Vector3,
119
- width: number,
505
+ id: ChecklineId,
506
+ fraction: number,
507
+ materials: ReturnType<typeof createMaterials>,
120
508
  ): Checkline {
509
+ const distance = lineDistance(fraction);
510
+ const station = stationAt(distance);
511
+ const at = onTrack(station, 0, 0, new Vector3());
512
+ const forward = station.sample.tangent.clone();
513
+ const along = Math.abs(forward.x) > Math.abs(forward.z);
121
514
  const group = new Group();
122
- const material = new MeshStandardMaterial({
123
- color: id === "finish" ? palette.accent : palette.skyLow,
124
- metalness: 0.2,
125
- roughness: 0.45,
126
- });
127
- const post = new Mesh(new BoxGeometry(0.28, 3.4, 0.28), material);
128
- const otherPost = post.clone();
129
- const top = new Mesh(new BoxGeometry(width + 1.2, 0.34, 0.34), material);
130
- const banner = new Mesh(new BoxGeometry(width + 0.6, 0.7, 0.08), material);
131
- post.position.set(-(width / 2 + 0.5), 1.7, 0);
132
- otherPost.position.set(width / 2 + 0.5, 1.7, 0);
133
- top.position.y = 3.55;
134
- banner.position.y = 3.0;
135
- for (const mesh of [post, otherPost, top, banner]) mesh.castShadow = true;
136
- group.add(post, otherPost, top, banner);
137
- group.position.set(at.x, 0, at.z);
138
- // A gate spans the road, so it is rotated when the road runs along **X**, not along Z. The
139
- // condition used to be the other way round, which laid both gantries down the racing line: from
140
- // the chase camera the finish gantry read as a stray yellow post and a bar going nowhere.
141
- if (Math.abs(forward.x) > Math.abs(forward.z)) group.rotation.y = Math.PI / 2;
515
+ const span = TRACK_WIDTH + 3;
516
+ for (const side of [-1, 1] as const) {
517
+ const post = new Mesh(new BoxGeometry(0.34, 6, 0.34), materials.structure);
518
+ post.position.set((side * span) / 2, 3, 0);
519
+ post.castShadow = true;
520
+ group.add(post);
521
+ }
522
+ const beam = new Mesh(new BoxGeometry(span + 0.4, 0.4, 0.4), materials.armco);
523
+ beam.position.y = 5.9;
524
+ beam.castShadow = true;
525
+ const banner = new Mesh(
526
+ new BoxGeometry(span - 2, 1.1, 0.12),
527
+ id === "finish" ? materials.boost : materials.structure,
528
+ );
529
+ banner.position.y = 4.9;
530
+ banner.castShadow = true;
531
+ group.add(beam, banner);
532
+ group.position.copy(at);
533
+ // The gantry spans the road, so it turns with the road. Unrotated it lies along the racing line
534
+ // and reads as a bar going nowhere.
535
+ group.rotation.y = along ? Math.PI / 2 : 0;
142
536
  ctx.add(group);
143
- const area = new Area3D({
144
- collisionMask: 1,
145
- entity: `gate.${id}`,
146
- physics: ctx.physics,
147
- position: { x: at.x, y: 0.7, z: at.z },
148
- shape: CollisionShape3D.box(
149
- Math.abs(forward.z) > Math.abs(forward.x) ? 0.65 : width / 2,
150
- 1.1,
151
- Math.abs(forward.z) > Math.abs(forward.x) ? width / 2 : 0.65,
152
- ),
153
- });
154
- return new Checkline(id, at, forward, area);
537
+ // The line is where the gantry's posts stand, and it is as wide as the road plus a car's width:
538
+ // a car that is off the tarmac is not crossing the start line.
539
+ void along;
540
+ return new Checkline(id, at, forward, TRACK_WIDTH / 2 + 1.8);
155
541
  }
156
542
 
157
543
  function boostPad(
158
544
  ctx: TrackCtx,
159
- at: Vector3,
545
+ fraction: number,
160
546
  materials: ReturnType<typeof createMaterials>,
161
547
  ): { area: Area3D; boost: Boost } {
162
- // Chevrons, not a slab. A flat yellow rectangle across the road reads as a painting mistake;
163
- // arrows read as "drive here and go faster" without a word of UI.
548
+ const station = stationAt(lineDistance(fraction));
549
+ const at = onTrack(station, 0, 0, new Vector3());
550
+ const along = Math.abs(station.sample.tangent.x) > Math.abs(station.sample.tangent.z);
164
551
  const pad = new Group();
165
- const base = new Mesh(new BoxGeometry(3.2, 0.04, TRACK_WIDTH - 0.6), materials.carbon);
166
- base.position.y = 0.005;
552
+ const base = new Mesh(new BoxGeometry(3.6, 0.04, TRACK_WIDTH - 1), materials.carbon);
553
+ base.position.y = 0.02;
167
554
  base.receiveShadow = true;
168
555
  pad.add(base);
169
556
  for (let index = 0; index < 3; index += 1) {
170
- for (const side of [-1, 1]) {
171
- const arm = new Mesh(new BoxGeometry(1.5, 0.05, 0.42), materials.boost);
172
- arm.position.set(-1.0 + index * 1.0, 0.03, side * 0.9);
173
- arm.rotation.y = side * 0.62;
557
+ for (const side of [-1, 1] as const) {
558
+ const arm = new Mesh(new BoxGeometry(1.7, 0.05, 0.46), materials.boost);
559
+ arm.position.set(-1.2 + index * 1.2, 0.045, side * 1.2);
560
+ arm.rotation.y = side * 0.6;
174
561
  arm.receiveShadow = true;
175
562
  pad.add(arm);
176
563
  }
177
564
  }
178
- pad.position.set(at.x, 0.12, at.z);
565
+ pad.position.copy(at);
566
+ pad.rotation.y = along ? 0 : Math.PI / 2;
179
567
  ctx.add(pad);
180
568
  const boost = new Boost();
569
+ const half = TRACK_WIDTH / 2 - 0.5;
181
570
  const area = new Area3D({
182
- collisionMask: 1,
571
+ collisionMask: LAYER.car,
183
572
  entity: "boost-pad",
184
573
  physics: ctx.physics,
185
- position: { x: at.x, y: 0.35, z: at.z },
186
- shape: CollisionShape3D.box(1.6, 0.45, TRACK_WIDTH / 2),
574
+ position: { x: at.x, y: at.y + 0.45, z: at.z },
575
+ shape: along ? CollisionShape3D.box(1.8, 0.5, half) : CollisionShape3D.box(half, 0.5, 1.8),
187
576
  });
188
577
  return { area, boost };
189
578
  }
190
579
 
580
+ /**
581
+ * Everything beside the road, placed off the same centreline.
582
+ *
583
+ * Delete a line here and that piece of furniture is gone; nothing else depends on it. Every
584
+ * repeated prop goes into an `InstancedBatch` and every static run into one merged mesh, because
585
+ * the performance playtest bounds this circuit at 330 draw calls and 105,000 triangles.
586
+ */
587
+ function dressCircuit(
588
+ ctx: TrackCtx,
589
+ all: readonly IStation[],
590
+ materials: ReturnType<typeof createMaterials>,
591
+ ): void {
592
+ const at = (fraction: number, offset: number, lift = 0, target = new Vector3()): Vector3 =>
593
+ onGround(stationAt(lineDistance(fraction)), offset, lift, target);
594
+ const heading = (fraction: number): number => {
595
+ const sample = CIRCUIT.at(lineDistance(fraction), CIRCUIT.createSample());
596
+ return Math.atan2(sample.tangent.z, sample.tangent.x);
597
+ };
598
+
599
+ // **The finish line**: the one transverse mark the road is allowed to carry. It is a `quadStrip`,
600
+ // like every other surface here, so it sits on the banked tarmac rather than a flat plane through it.
601
+ const finishRows = [
602
+ stationAt(lineDistance(LINE_AT.finish) - 3),
603
+ stationAt(lineDistance(LINE_AT.finish)),
604
+ ].map((station) => [
605
+ onTrack(station, -HALF, ROAD_LIFT + 0.014),
606
+ onTrack(station, HALF, ROAD_LIFT + 0.014),
607
+ ]);
608
+ const finishLine = new Mesh(
609
+ quadStrip(finishRows, (row, column) => [column * 4, row * 2]),
610
+ materials.checker,
611
+ );
612
+ ctx.add(finishLine);
613
+
614
+ // **Start lights**: two rows of five on the finish gantry. This is the one piece of furniture a
615
+ // first frame cannot be without, because it is what says *this is a start line*.
616
+ const lights = new InstancedBatch({
617
+ geometry: new BoxGeometry(0.4, 0.72, 0.4),
618
+ material: materials.taillamp,
619
+ });
620
+ for (let row = 0; row < 2; row += 1)
621
+ for (let column = 0; column < 5; column += 1) {
622
+ const lamp = at(LINE_AT.finish, -2.6 + column * 1.3, 4.1 + row * 0.9);
623
+ lights.place({
624
+ position: [lamp.x, lamp.y, lamp.z],
625
+ rotation: [0, heading(LINE_AT.finish), 0],
626
+ scale: [1, 1, 1],
627
+ });
628
+ }
629
+ const lightMesh = lights.build({ name: "start-lights" });
630
+ if (lightMesh !== undefined) ctx.add(lightMesh);
631
+
632
+ // **Grandstands**, set back past the barriers: close in they climbed into the chase camera and
633
+ // hid the corner the driver was aiming at. The crowd is one batch for the whole circuit.
634
+ const crowd = new InstancedBatch({
635
+ geometry: new BoxGeometry(0.36, 0.72, 0.32),
636
+ material: materials.crowd,
637
+ });
638
+ const stands: [number, number, number][] = [];
639
+ for (const fraction of [0.015, 0.1, 0.44, 0.52]) {
640
+ const sample = CIRCUIT.at(lineDistance(fraction), CIRCUIT.createSample());
641
+ const side = sample.curvature > 0 ? -1 : 1;
642
+ stands.push([
643
+ fraction,
644
+ side * (HALF + RUNOFF + 7),
645
+ sample.curvature > 0 ? Math.PI / 2 : -Math.PI / 2,
646
+ ]);
647
+ }
648
+ for (const [fraction, offset, turn] of stands) {
649
+ const stand = grandstand(materials.structure, materials.line);
650
+ const origin = at(fraction, offset);
651
+ stand.group.position.copy(origin);
652
+ stand.group.rotation.y = turn;
653
+ ctx.add(stand.group);
654
+ for (const [seatX, seatY, seatZ] of stand.crowd) {
655
+ const turned = new Vector3(seatX, seatY, seatZ).applyAxisAngle(new Vector3(0, 1, 0), turn);
656
+ crowd.place({
657
+ position: [origin.x + turned.x, origin.y + turned.y, origin.z + turned.z],
658
+ scale: [1, 1, 1],
659
+ });
660
+ }
661
+ }
662
+ const crowdMesh = crowd.build({ castShadow: true, name: "grandstand-crowd" });
663
+ if (crowdMesh !== undefined) ctx.add(crowdMesh);
664
+
665
+ // **Pit lane and pit wall**, on the inside of the main straight. Both read the straight's own
666
+ // distance, so the lane is parallel to it by construction and cannot drift onto the track.
667
+ const pitStations: IStation[] = [];
668
+ for (let distance = lineDistance(0.005); distance <= lineDistance(0.145); distance += 2.4)
669
+ pitStations.push(stationAt(distance));
670
+ const pit = new Mesh(
671
+ quadStrip(
672
+ pitStations.map((station) => [
673
+ onGround(station, HALF + 0.5, 0.02),
674
+ onGround(station, HALF + 7.4, 0.02),
675
+ ]),
676
+ (row, column) => [column * 7, row * 2.4],
677
+ ),
678
+ materials.runoff,
679
+ );
680
+ pit.receiveShadow = true;
681
+ ctx.add(pit);
682
+ const pitWall = new Mesh(
683
+ quadStrip(
684
+ pitStations.map((station) => [
685
+ onGround(station, HALF + 7.4, 0),
686
+ onGround(station, HALF + 7.7, 0),
687
+ onGround(station, HALF + 7.7, 1.15),
688
+ onGround(station, HALF + 7.4, 1.15),
689
+ ]),
690
+ (row, column) => [column, row * 2.4],
691
+ ),
692
+ materials.armco,
693
+ );
694
+ pitWall.castShadow = true;
695
+ ctx.add(pitWall);
696
+ fixedTrimesh(ctx, pitWall, LAYER.barrier, "pit-wall");
697
+
698
+ // **Marshal posts** on the outside of the corners, where a flag marshal would stand.
699
+ const posts = new InstancedBatch({
700
+ geometry: new BoxGeometry(2.8, 2.6, 1.9),
701
+ material: materials.structure,
702
+ });
703
+ for (const fraction of [0.2, 0.4, 0.58, 0.72]) {
704
+ const sample = CIRCUIT.at(lineDistance(fraction), CIRCUIT.createSample());
705
+ const side = sample.curvature > 0 ? -1 : 1;
706
+ const origin = at(fraction, side * (HALF + RUNOFF + 3.5));
707
+ posts.place({
708
+ position: [origin.x, origin.y + 1.3, origin.z],
709
+ rotation: [0, heading(fraction), 0],
710
+ scale: [1, 1, 1],
711
+ });
712
+ }
713
+ const postMesh = posts.build({ castShadow: true, name: "marshal-posts" });
714
+ if (postMesh !== undefined) ctx.add(postMesh);
715
+
716
+ // **Tyre walls** on the outside of every corner tight enough to run wide at.
717
+ const tyres = new InstancedBatch({ geometry: tyreStackGeometry(3), material: materials.tire });
718
+ for (let index = 0; index < all.length; index += 7) {
719
+ const station = all[index];
720
+ if (station === undefined || Math.abs(station.sample.curvature) < 1 / 70) continue;
721
+ const side = station.sample.curvature > 0 ? -1 : 1;
722
+ const origin = onGround(station, side * (HALF + KERB_WIDTH + 3), 0, new Vector3());
723
+ tyres.place({
724
+ position: [origin.x, origin.y, origin.z],
725
+ rotation: [0, heading(station.distance / CIRCUIT.totalLength), 0],
726
+ scale: [1, 1, 1],
727
+ });
728
+ }
729
+ const tyreMesh = tyres.build({ castShadow: true, name: "tyre-walls" });
730
+ if (tyreMesh !== undefined) ctx.add(tyreMesh);
731
+
732
+ let midX = 0;
733
+ let midZ = 0;
734
+ for (const station of all) {
735
+ midX += station.sample.point.x;
736
+ midZ += station.sample.point.z;
737
+ }
738
+ midX /= all.length;
739
+ midZ /= all.length;
740
+
741
+ // **Trees** beyond the circuit, on a seeded jitter so two captures frame the same world. The
742
+ // distance test is why a conifer never stands in the run-off.
743
+ const pine = treeGeometry();
744
+ const trunks = new InstancedBatch({ geometry: pine.trunk, material: materials.trunk });
745
+ const canopies = new InstancedBatch({ geometry: pine.canopy, material: materials.canopy });
746
+ let seed = 6132;
747
+ const jitter = (): number => {
748
+ seed = (seed * 1103515245 + 12345) & 0x7fffffff;
749
+ return seed / 0x7fffffff;
750
+ };
751
+ for (let index = 0; index < 190; index += 1) {
752
+ const angle = (index / 190) * Math.PI * 2 + jitter() * 0.09;
753
+ const reach = 230 + jitter() * 150;
754
+ const x = midX + Math.cos(angle) * reach;
755
+ const z = midZ + Math.sin(angle) * reach;
756
+ let near = Number.POSITIVE_INFINITY;
757
+ for (const station of all) {
758
+ const gap = (station.sample.point.x - x) ** 2 + (station.sample.point.z - z) ** 2;
759
+ if (gap < near) near = gap;
760
+ }
761
+ if (near < 36 * 36) continue;
762
+ const scale = 1.7 + jitter() * 2.4;
763
+ const placement = {
764
+ position: [x, terrainHeight(x, z), z] as [number, number, number],
765
+ rotation: [0, jitter() * Math.PI, 0] as [number, number, number],
766
+ scale: [scale, scale, scale] as [number, number, number],
767
+ };
768
+ trunks.place(placement);
769
+ canopies.place(placement);
770
+ }
771
+ for (const [batch, name] of [
772
+ [trunks, "treeline-trunks"],
773
+ [canopies, "treeline-canopies"],
774
+ ] as const) {
775
+ const mesh = batch.build({ castShadow: true, name });
776
+ if (mesh !== undefined) ctx.add(mesh);
777
+ }
778
+
779
+ // **Distant hills**, so the horizon has a shape instead of a line. Placed relative to the
780
+ // circuit's own centre and at least 380 m out: a fixed world coordinate here reads as a nearby
781
+ // wall the moment the circuit's layout or orientation changes, because the two stop agreeing on
782
+ // where "far away" is. Several boxes per hill, jittered in height and offset, so the skyline is
783
+ // a ridge rather than one flat-faced slab.
784
+ let hillSeed = 4021;
785
+ const hillJitter = (): number => {
786
+ hillSeed = (hillSeed * 1103515245 + 12345) & 0x7fffffff;
787
+ return hillSeed / 0x7fffffff;
788
+ };
789
+ // Small and far, and buried to three quarters of their own height: a box this close to the
790
+ // camera's forward view reads as a wall, not a hill, the moment it is tall enough to fill more
791
+ // than a sliver of the horizon. A real hill's silhouette is a low ridge, not a slab.
792
+ for (const [angle, radius, reach] of [
793
+ [0.15, 55, 620],
794
+ [1.9, 70, 660],
795
+ [3.4, 50, 640],
796
+ [5.0, 60, 700],
797
+ ] as const) {
798
+ const cx = midX + Math.cos(angle) * reach;
799
+ const cz = midZ + Math.sin(angle) * reach;
800
+ for (let lump = 0; lump < 4; lump += 1) {
801
+ const lumpRadius = radius * (0.6 + hillJitter() * 0.5);
802
+ const x = cx + (hillJitter() - 0.5) * radius * 2.2;
803
+ const z = cz + (hillJitter() - 0.5) * radius * 2.2;
804
+ const hill = new Mesh(
805
+ new BoxGeometry(lumpRadius * 2, lumpRadius, lumpRadius * 2),
806
+ materials.distant,
807
+ );
808
+ hill.rotation.y = hillJitter() * Math.PI;
809
+ hill.position.set(x, terrainHeight(x, z) - lumpRadius * 0.78, z);
810
+ ctx.add(hill);
811
+ }
812
+ }
813
+ }
814
+
815
+ export function gridPosition(which: "player" | "rival", target: Vector3): Vector3 {
816
+ const distance = GRID_DISTANCE[which];
817
+ const station = stationAt(distance);
818
+ const at = onTrack(station, GRID[which], 0.05, target);
819
+ return at;
820
+ }
821
+
822
+ /** The direction a car on the grid is pointing: down the main straight. */
823
+ export function gridHeading(which: "player" | "rival"): number {
824
+ const sample = CIRCUIT.at(GRID_DISTANCE[which], CIRCUIT.createSample());
825
+ return Math.atan2(sample.tangent.z, sample.tangent.x);
826
+ }
827
+
191
828
  function normalizeRayHit(value: unknown): IRayHit | undefined {
192
829
  if (typeof value !== "object" || value === null) return undefined;
193
830
  const record = value as Record<string, unknown>;
@@ -224,7 +861,7 @@ export function intersectRay(physics: IPhysicsContext, fallback: IntersectRay):
224
861
  return (origin, direction, maxDistance) => {
225
862
  const to = origin.clone().addScaledVector(direction, maxDistance);
226
863
  const result = directSpaceState.intersectRay({
227
- collisionMask: 2,
864
+ collisionMask: LAYER.road,
228
865
  from: origin,
229
866
  to,
230
867
  });
@@ -232,8 +869,10 @@ export function intersectRay(physics: IPhysicsContext, fallback: IntersectRay):
232
869
  };
233
870
  }
234
871
 
872
+ const raycaster = new Raycaster();
873
+
874
+ /** The visual probe: it finds the same tarmac the physics does, from the road mesh itself. */
235
875
  export function roadRayProbe(meshes: readonly Mesh[]): IntersectRay {
236
- const raycaster = new Raycaster();
237
876
  return (origin, direction, maxDistance) => {
238
877
  raycaster.set(origin, direction);
239
878
  const hit = raycaster.intersectObjects([...meshes], false)[0];
@@ -242,240 +881,49 @@ export function roadRayProbe(meshes: readonly Mesh[]): IntersectRay {
242
881
  };
243
882
  }
244
883
 
884
+ export interface ITrackBuild {
885
+ readonly boost: Boost;
886
+ readonly boostArea: Area3D;
887
+ readonly gates: readonly Checkline[];
888
+ readonly roadMeshes: readonly Mesh[];
889
+ }
890
+
245
891
  export function buildTrack(ctx: TrackCtx): ITrackBuild {
246
892
  const materials = createMaterials();
247
- const field = new Mesh(new BoxGeometry(100, 0.3, 100), materials.field);
248
- field.position.y = -0.62;
249
- field.receiveShadow = true;
250
- ctx.add(field);
251
- new RigidBody3D({
252
- collisionLayer: 4,
253
- collisionMask: 1,
254
- object: field,
255
- physics: ctx.physics,
256
- shape: CollisionShape3D.box(50, 0.15, 50),
257
- type: "fixed",
258
- });
259
-
260
- // Every kerb is the same box at a different length and angle, so they are gathered into one
261
- // batch and drawn once instead of twice per sector. The count is not known before the route has
262
- // been walked, which is exactly what `InstancedBatch` is for — `new InstancedMesh` would need it
263
- // up front.
264
- const curbs = new InstancedBatch({
265
- geometry: new BoxGeometry(1, 1, 1),
266
- material: materials.curb,
267
- });
268
- const curbsAlt = new InstancedBatch({
269
- geometry: new BoxGeometry(1, 1, 1),
270
- material: materials.kerbAlt,
271
- });
272
-
273
- const roadMeshes: Mesh[] = [];
274
- for (let index = 0; index < ROUTE_POINTS.length; index += 1) {
275
- const a = ROUTE_POINTS[index];
276
- const b = ROUTE_POINTS[(index + 1) % ROUTE_POINTS.length];
277
- if (a === undefined || b === undefined) continue;
278
- roadMeshes.push(roadSegment(ctx, a, b, materials));
279
- addCurb(curbs, curbsAlt, a, b, 1);
280
- addCurb(curbs, curbsAlt, a, b, -1);
281
- }
282
- // A square of tarmac at every route point. Two straight sectors meeting at a right angle leave
283
- // the corner itself unpaved, and the frame showed grass biting into the racing line exactly
284
- // where the driver is turning.
285
- for (const point of ROUTE_POINTS) {
286
- const patch = new Mesh(new BoxGeometry(TRACK_WIDTH, 0.28, TRACK_WIDTH), materials.road);
287
- patch.position.set(point.x, -0.14, point.z);
288
- patch.receiveShadow = true;
289
- ctx.add(patch);
290
- new RigidBody3D({
291
- collisionLayer: 2,
292
- collisionMask: 1,
293
- object: patch,
294
- physics: ctx.physics,
295
- shape: CollisionShape3D.box(TRACK_WIDTH, 0.28, TRACK_WIDTH),
296
- type: "fixed",
297
- });
298
- roadMeshes.push(patch);
299
- }
300
-
301
- // The outside corner of the kerbing, filling the right angle the two inset runs leave open.
302
- for (const point of ROUTE_POINTS) {
303
- for (const [dx, dz] of [
304
- [1, 1],
305
- [1, -1],
306
- [-1, 1],
307
- [-1, -1],
308
- ] as const) {
309
- curbs.place({
310
- position: [
311
- point.x + dx * (TRACK_WIDTH / 2 + 0.28),
312
- 0.08,
313
- point.z + dz * (TRACK_WIDTH / 2 + 0.28),
314
- ],
315
- rotation: [0, 0, 0],
316
- scale: [0.5, 0.18, 0.5],
317
- });
318
- }
319
- }
320
-
321
- const curbMesh = curbs.build({ castShadow: true, name: "track-curbs" });
322
- if (curbMesh !== undefined) ctx.add(curbMesh);
323
- const curbAltMesh = curbsAlt.build({ castShadow: true, name: "track-curbs-alt" });
324
- if (curbAltMesh !== undefined) ctx.add(curbAltMesh);
325
-
893
+ buildTerrain(ctx, materials);
894
+ const all = buildRoad(ctx, materials);
895
+ buildKerbs(ctx, all, materials);
896
+ buildBarriers(ctx, all, materials);
897
+ // Finish first, then the two sector lines in driving order: `Lap` arms gate 0 and a car on the
898
+ // grid crosses it first, so a lap is measured on the start/finish line and nowhere else.
326
899
  const gates = [
327
- gate(ctx, "mid", new Vector3(18, 0, 0), new Vector3(0, 0, 1), TRACK_WIDTH),
328
- gate(ctx, "finish", new Vector3(10, 0, -18), new Vector3(1, 0, 0), TRACK_WIDTH),
900
+ gate(ctx, "finish", LINE_AT.finish, materials),
901
+ gate(ctx, "sector-1", LINE_AT.sector1, materials),
902
+ gate(ctx, "sector-2", LINE_AT.sector2, materials),
329
903
  ];
330
- const pad = boostPad(ctx, new Vector3(14, 0, -18), materials);
331
- dressCircuit(ctx, materials);
332
- return { boost: pad.boost, boostArea: pad.area, gates, roadMeshes, route: RACING_LINE };
333
- }
334
-
335
- /**
336
- * Everything beside the road.
337
- *
338
- * This used to be five thin coloured posts at the route corners, and the first frame showed why
339
- * that is not enough: past the kerbs the world was one unbroken green plane to the horizon, so a
340
- * corner arrived with nothing to judge it against and the circuit had no sense of place. Stands,
341
- * trees, tyre walls and hoardings cost one function and give the driver landmarks.
342
- *
343
- * Delete a line here and that piece of furniture is gone; nothing else depends on it.
344
- */
345
- function dressCircuit(ctx: TrackCtx, materials: ReturnType<typeof createMaterials>): void {
346
- // Grass run-off inside the kerbs, a shade drier than the outfield, so the two read as two
347
- // surfaces rather than one flat colour.
348
- const apron = new Mesh(new BoxGeometry(52, 0.16, 52), materials.runoff);
349
- apron.position.y = -0.5;
350
- apron.receiveShadow = true;
351
- ctx.add(apron);
352
-
353
- // Grandstands, set back past the hoardings. Placed nearer the road they climbed into the chase
354
- // camera and hid the corner the driver was aiming at.
355
- const crowd = new InstancedBatch({
356
- geometry: new CapsuleGeometry(0.16, 0.24, 1, 4),
357
- material: materials.crowd,
358
- });
359
- for (const [x, z, turn, seats] of [
360
- [2, -34, 0, materials.kerbAlt],
361
- [-2, 34, Math.PI, materials.hoardingBoard],
362
- ] as const) {
363
- const stand = grandstand(materials.structure, seats);
364
- stand.group.position.set(x, 0, z);
365
- stand.group.rotation.y = turn;
366
- ctx.add(stand.group);
367
- for (const [seatX, seatY, seatZ] of stand.crowd) {
368
- const turned = new Vector3(seatX, seatY, seatZ).applyAxisAngle(UP, turn);
369
- crowd.place({ position: [x + turned.x, turned.y, z + turned.z], scale: [1, 1, 1] });
370
- }
371
- }
372
- const crowdMesh = crowd.build({ castShadow: true, name: "grandstand-crowd" });
373
- if (crowdMesh !== undefined) ctx.add(crowdMesh);
374
-
375
- // Tyre walls on the outside of all four corners, five stacks to an arc.
376
- const tyres = new InstancedBatch({
377
- geometry: tyreStackGeometry(3),
378
- material: materials.tire,
379
- });
380
- for (const [cornerX, cornerZ] of [
381
- [24.5, -24.5],
382
- [24.5, 24.5],
383
- [-24.5, 24.5],
384
- [-24.5, -24.5],
385
- ] as const) {
386
- const radius = Math.hypot(cornerX, cornerZ);
387
- for (let index = 0; index < 5; index += 1) {
388
- const angle = Math.atan2(cornerZ, cornerX) + (index - 2) * 0.09;
389
- tyres.place({
390
- position: [Math.cos(angle) * radius, 0, Math.sin(angle) * radius],
391
- rotation: [0, angle, 0],
392
- scale: [1, 1, 1],
393
- });
394
- }
395
- }
396
- const tyreMesh = tyres.build({ castShadow: true, name: "tyre-walls" });
397
- if (tyreMesh !== undefined) ctx.add(tyreMesh);
398
-
399
- // Sponsor hoardings around all four straights, turned to **face** the road. Left unrotated they
400
- // presented their broad faces down the racing line, which from the chase camera looked like
401
- // blue plates hanging in the air.
402
- const board = hoardingGeometry(5);
403
- const frames = new InstancedBatch({ geometry: board.frame, material: materials.structure });
404
- const boardsA = new InstancedBatch({ geometry: board.board, material: materials.hoardingBoard });
405
- const boardsB = new InstancedBatch({ geometry: board.board, material: materials.kerbAlt });
406
- const OUTSIDE = 22.8;
407
- for (let index = 0; index < 7; index += 1) {
408
- const along = -18 + index * 6;
409
- for (const side of [-1, 1] as const) {
410
- for (const [position, turn, batch] of [
411
- [
412
- [along, 0, side * OUTSIDE] as const,
413
- side < 0 ? Math.PI / 2 : -Math.PI / 2,
414
- side < 0 ? boardsA : boardsB,
415
- ],
416
- [[side * OUTSIDE, 0, along] as const, side < 0 ? Math.PI : 0, side < 0 ? boardsB : boardsA],
417
- ] as const) {
418
- const placement = {
419
- position: [position[0], position[1], position[2]] as [number, number, number],
420
- rotation: [0, turn, 0] as [number, number, number],
421
- scale: [1, 1, 1] as [number, number, number],
422
- };
423
- frames.place(placement);
424
- batch.place(placement);
425
- }
426
- }
427
- }
428
- for (const [batch, name] of [
429
- [frames, "hoarding-frames"],
430
- [boardsA, "hoarding-boards-a"],
431
- [boardsB, "hoarding-boards-b"],
432
- ] as const) {
433
- const mesh = batch.build({ castShadow: true, name });
434
- if (mesh !== undefined) ctx.add(mesh);
435
- }
436
-
437
- // A treeline outside the circuit. Deterministic placement — a seeded jitter, not Math.random —
438
- // so two captures of the same build frame the same world.
439
- const pine = treeGeometry();
440
- const trunks = new InstancedBatch({ geometry: pine.trunk, material: materials.trunk });
441
- const canopies = new InstancedBatch({ geometry: pine.canopy, material: materials.canopy });
442
- let seed = 6132;
443
- const jitter = (): number => {
444
- seed = (seed * 1103515245 + 12345) & 0x7fffffff;
445
- return seed / 0x7fffffff;
904
+ const pad = boostPad(ctx, 0.3, materials);
905
+ dressCircuit(ctx, all, materials);
906
+ const road = ctx.scene.getObjectByName("road");
907
+ return {
908
+ boost: pad.boost,
909
+ boostArea: pad.area,
910
+ gates,
911
+ roadMeshes: road instanceof Mesh ? [road] : [],
446
912
  };
447
- for (let index = 0; index < 44; index += 1) {
448
- const angle = (index / 44) * Math.PI * 2 + jitter() * 0.1;
449
- const distance = 42 + jitter() * 22;
450
- const scale = 1.4 + jitter() * 1.5;
451
- const placement = {
452
- position: [Math.cos(angle) * distance, 0, Math.sin(angle) * distance] as [
453
- number,
454
- number,
455
- number,
456
- ],
457
- rotation: [0, jitter() * Math.PI, 0] as [number, number, number],
458
- scale: [scale, scale, scale] as [number, number, number],
459
- };
460
- trunks.place(placement);
461
- canopies.place(placement);
462
- }
463
- for (const [batch, name] of [
464
- [trunks, "treeline-trunks"],
465
- [canopies, "treeline-canopies"],
466
- ] as const) {
467
- const mesh = batch.build({ castShadow: true, name });
468
- if (mesh !== undefined) ctx.add(mesh);
469
- }
470
-
471
- // Distant hills: three low domes past the treeline to give the horizon a shape.
472
- for (const [x, z, radius] of [
473
- [-70, -110, 46],
474
- [90, -120, 58],
475
- [130, 60, 40],
476
- ] as const) {
477
- const hill = new Mesh(new SphereGeometry(radius, 12, 6), materials.distant);
478
- hill.position.set(x, -radius * 0.72, z);
479
- ctx.add(hill);
480
- }
481
913
  }
914
+
915
+ export {
916
+ CIRCUIT,
917
+ GRID,
918
+ GRID_DISTANCE,
919
+ HALF,
920
+ KERB_HEIGHT,
921
+ KERB_WIDTH,
922
+ LINE_AT,
923
+ RUNOFF,
924
+ TRACK_WIDTH,
925
+ groundHeight,
926
+ lineDistance,
927
+ terrainHeight,
928
+ };
929
+ export type { ICircuitSample, IntersectRay };