create-threenative 0.2.17 → 0.2.20

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 (387) hide show
  1. package/agent-docs/kit-mcp.md +1 -1
  2. package/agent-docs/kit-router.md +1 -1
  3. package/agent-docs/references/assertion-reference.md +54 -110
  4. package/agent-docs/references/capability-reference.md +790 -24
  5. package/agent-docs/references/conventions.md +28 -0
  6. package/agent-docs/references/kit-racing.md +4 -2
  7. package/agent-docs/references/performance-basics.md +10 -5
  8. package/agent-docs/references/terrain-authoring.md +21 -7
  9. package/agent-files/.agents/skills/ponytail/SKILL.md +1 -1
  10. package/agent-files/.agents/skills/prd-creator/SKILL.md +24 -0
  11. package/agent-files/.agents/skills/threenative-capabilities/SKILL.md +7 -4
  12. package/agent-files/.claude/hooks/discovery-gate.mjs +2 -2
  13. package/dist/index.d.ts +97 -6
  14. package/dist/index.js +1040 -529
  15. package/dist/quality.d.ts +5 -1
  16. package/dist/quality.js +75 -6
  17. package/dist/terrain-kit.js +1 -1
  18. package/dist/threenative.js +98 -17
  19. package/dist/web-engine-ccd-ik-solver.js +127 -0
  20. package/dist/web-engine-gltf-loader.js +52 -14
  21. package/dist/web-engine-post-effects.js +11 -10
  22. package/dist/web-engine-runtime.js +3638 -361
  23. package/package.json +8 -7
  24. package/template-assets/assets/floor-fern-0.glb +0 -0
  25. package/template-assets/assets/floor-litter-0.glb +0 -0
  26. package/template-assets/assets/floor-log-0.glb +0 -0
  27. package/template-assets/assets/floor-log-1.glb +0 -0
  28. package/template-assets/assets/floor-stump-0.glb +0 -0
  29. package/template-assets/assets/floor-twig-0.glb +0 -0
  30. package/template-assets/clearwater/README.md +1 -1
  31. package/template-assets/patches/manifest.json +18 -0
  32. package/template-assets/quality/eslint.config.js +1 -1
  33. package/templates/action-rpg/AGENTS.md +8 -4
  34. package/templates/action-rpg/CLAUDE.md +8 -4
  35. package/templates/action-rpg/package.json +7 -7
  36. package/templates/action-rpg/src/game.ts +1 -1
  37. package/templates/action-rpg/src/loot/drops.ts +3 -7
  38. package/templates/action-rpg/src/render/atmosphere.ts +6 -0
  39. package/templates/action-rpg/src/render/backlightControls.ts +10 -0
  40. package/templates/action-rpg/src/render/backlightMaterial.ts +4 -4
  41. package/templates/action-rpg/src/render/camera.ts +2 -2
  42. package/templates/action-rpg/src/render/clouds.ts +16 -1
  43. package/templates/action-rpg/src/render/materialLighting.ts +5 -5
  44. package/templates/action-rpg/src/render/materials.ts +3 -2
  45. package/templates/action-rpg/src/render/quality.ts +7 -32
  46. package/templates/action-rpg/src/render/touch-controls.ts +7 -6
  47. package/templates/action-rpg/src/scenes/Play.ts +5 -16
  48. package/templates/action-rpg/src/style.css +4 -0
  49. package/templates/action-rpg/vite.config.ts +2 -0
  50. package/templates/adventure/AGENTS.md +10 -5
  51. package/templates/adventure/CLAUDE.md +10 -5
  52. package/templates/adventure/kit.json +5 -1
  53. package/templates/adventure/native-playtests/survives.playtest.json +12 -0
  54. package/templates/adventure/native-playtests/woodland-floor.playtest.json +61 -0
  55. package/templates/adventure/package.json +7 -7
  56. package/templates/adventure/playtests/grass.playtest.json +61 -0
  57. package/templates/adventure/playtests/performance.playtest.json +1 -1
  58. package/templates/adventure/playtests/survives.playtest.json +2 -2
  59. package/templates/adventure/playtests/woodland-floor.playtest.json +61 -0
  60. package/templates/adventure/src/entities/LockOn.ts +42 -4
  61. package/templates/adventure/src/entities/Warden.ts +4 -1
  62. package/templates/adventure/src/game.ts +1 -1
  63. package/templates/adventure/src/level/Vale.ts +241 -16
  64. package/templates/adventure/src/render/camera.ts +2 -2
  65. package/templates/adventure/src/render/foliage.ts +64 -20
  66. package/templates/adventure/src/render/grass.ts +325 -0
  67. package/templates/adventure/src/render/materials.ts +3 -2
  68. package/templates/adventure/src/render/palette.ts +3 -0
  69. package/templates/adventure/src/render/touch-controls.ts +4 -1
  70. package/templates/adventure/src/scenes/Play.ts +96 -1
  71. package/templates/adventure/src/style.css +4 -0
  72. package/templates/adventure/tsconfig.json +1 -1
  73. package/templates/adventure/vite.config.ts +2 -0
  74. package/templates/collectathon/AGENTS.md +7 -2
  75. package/templates/collectathon/CLAUDE.md +7 -2
  76. package/templates/collectathon/package.json +7 -7
  77. package/templates/collectathon/src/game.ts +1 -1
  78. package/templates/collectathon/src/level/Course.ts +55 -14
  79. package/templates/collectathon/src/level/terrain.ts +29 -7
  80. package/templates/collectathon/src/main.ts +1 -0
  81. package/templates/collectathon/src/render/camera.ts +2 -2
  82. package/templates/collectathon/src/render/foliage.ts +359 -98
  83. package/templates/collectathon/src/render/ground.ts +4 -4
  84. package/templates/collectathon/src/render/hero.ts +1 -1
  85. package/templates/collectathon/src/render/materials.ts +0 -1
  86. package/templates/collectathon/src/render/sky.ts +80 -15
  87. package/templates/collectathon/src/render/water.ts +32 -10
  88. package/templates/collectathon/src/scenes/Play.ts +18 -5
  89. package/templates/collectathon/src/style.css +4 -0
  90. package/templates/collectathon/tsconfig.json +1 -1
  91. package/templates/collectathon/vite.config.ts +2 -0
  92. package/templates/kart/AGENTS.md +7 -2
  93. package/templates/kart/CLAUDE.md +7 -2
  94. package/templates/kart/package.json +6 -6
  95. package/templates/kart/src/entities/Kart.ts +2 -1
  96. package/templates/kart/src/game.ts +1 -1
  97. package/templates/kart/src/main.ts +1 -0
  98. package/templates/kart/src/render/course.ts +2 -1
  99. package/templates/kart/src/style.css +4 -0
  100. package/templates/kart/src/track/Course.ts +3 -1
  101. package/templates/kart/tsconfig.json +1 -1
  102. package/templates/kart/vite.config.ts +2 -0
  103. package/templates/minimal/AGENTS.md +8 -3
  104. package/templates/minimal/CLAUDE.md +8 -3
  105. package/templates/minimal/package.json +6 -6
  106. package/templates/minimal/playtests/stands-still.playtest.json +30 -0
  107. package/templates/minimal/src/game.ts +1 -1
  108. package/templates/minimal/src/render/atmosphere.ts +6 -0
  109. package/templates/minimal/src/render/backlightControls.ts +10 -0
  110. package/templates/minimal/src/render/backlightMaterial.ts +4 -4
  111. package/templates/minimal/src/render/camera.ts +14 -3
  112. package/templates/minimal/src/render/clouds.ts +16 -1
  113. package/templates/minimal/src/render/lighting.ts +4 -2
  114. package/templates/minimal/src/render/materialLighting.ts +5 -5
  115. package/templates/minimal/src/render/materials.ts +13 -2
  116. package/templates/minimal/src/render/quality.ts +7 -32
  117. package/templates/minimal/src/render/touch-controls.ts +7 -6
  118. package/templates/minimal/src/scenes/Play.ts +4 -1
  119. package/templates/minimal/vite.config.ts +7 -1
  120. package/templates/platformer/AGENTS.md +9 -4
  121. package/templates/platformer/CLAUDE.md +9 -4
  122. package/templates/platformer/index.html +1 -1
  123. package/templates/platformer/main.html +12 -0
  124. package/templates/platformer/package.json +7 -7
  125. package/templates/platformer/playtests/collect.playtest.json +4 -1
  126. package/templates/platformer/playtests/gamepad-idle.playtest.json +21 -0
  127. package/templates/platformer/playtests/gamepad.playtest.json +30 -0
  128. package/templates/platformer/src/entities/Fox.ts +21 -6
  129. package/templates/platformer/src/game.ts +1 -1
  130. package/templates/platformer/src/level/Stage.ts +2 -6
  131. package/templates/platformer/src/main.ts +1 -0
  132. package/templates/platformer/src/render/backlightControls.ts +10 -0
  133. package/templates/platformer/src/render/backlightMaterial.ts +4 -4
  134. package/templates/platformer/src/render/materialLighting.ts +5 -5
  135. package/templates/platformer/src/render/quality.ts +7 -32
  136. package/templates/platformer/src/scenes/Play.ts +4 -2
  137. package/templates/platformer/src/style.css +4 -0
  138. package/templates/platformer/src/worker-page.ts +29 -0
  139. package/templates/platformer/src/worker.ts +5 -0
  140. package/templates/platformer/tsconfig.json +1 -1
  141. package/templates/platformer/vite.config.ts +4 -0
  142. package/templates/puzzle/AGENTS.md +7 -2
  143. package/templates/puzzle/CLAUDE.md +7 -2
  144. package/templates/puzzle/package.json +7 -7
  145. package/templates/puzzle/src/entities/Warden.ts +3 -3
  146. package/templates/puzzle/src/game.ts +1 -1
  147. package/templates/puzzle/src/render/backlightControls.ts +10 -0
  148. package/templates/puzzle/src/render/backlightMaterial.ts +4 -4
  149. package/templates/puzzle/src/render/camera.ts +2 -2
  150. package/templates/puzzle/src/render/materialLighting.ts +5 -5
  151. package/templates/puzzle/src/render/quality.ts +7 -32
  152. package/templates/puzzle/src/render/touch-controls.ts +7 -6
  153. package/templates/puzzle/src/scenes/Play.ts +1 -1
  154. package/templates/puzzle/src/style.css +4 -0
  155. package/templates/puzzle/tsconfig.json +1 -1
  156. package/templates/puzzle/vite.config.ts +2 -0
  157. package/templates/racing/AGENTS.md +9 -4
  158. package/templates/racing/CLAUDE.md +9 -4
  159. package/templates/racing/CREDITS.md +29 -0
  160. package/templates/racing/assets/engine-loop.wav +0 -0
  161. package/templates/racing/assets/grass/Grass004_color.jpg +0 -0
  162. package/templates/racing/assets/grass/Grass004_normal.jpg +0 -0
  163. package/templates/racing/assets/grass/Grass004_roughness.jpg +0 -0
  164. package/templates/racing/assets/nitro-burst.wav +0 -0
  165. package/templates/racing/assets/tyre-squeal.wav +0 -0
  166. package/templates/racing/package.json +7 -7
  167. package/templates/racing/playtests/drift-natural.playtest.json +68 -0
  168. package/templates/racing/playtests/drift.playtest.json +100 -0
  169. package/templates/racing/playtests/hud.playtest.json +117 -0
  170. package/templates/racing/playtests/launch-pose.playtest.json +34 -0
  171. package/templates/racing/playtests/nitro.playtest.json +158 -0
  172. package/templates/racing/playtests/outcome.playtest.json +4 -4
  173. package/templates/racing/playtests/performance.playtest.json +1 -1
  174. package/templates/racing/playtests/steady-camera.playtest.json +88 -0
  175. package/templates/racing/src/audio/engine.ts +138 -0
  176. package/templates/racing/src/entities/CarBody.ts +83 -10
  177. package/templates/racing/src/entities/Drift.ts +243 -0
  178. package/templates/racing/src/entities/LineDriver.ts +2 -2
  179. package/templates/racing/src/entities/Nitro.ts +72 -0
  180. package/templates/racing/src/entities/RacingCar.ts +86 -21
  181. package/templates/racing/src/entities/Rival.ts +35 -21
  182. package/templates/racing/src/game.ts +7 -1
  183. package/templates/racing/src/gauges.ts +74 -0
  184. package/templates/racing/src/render/atmosphere.ts +6 -0
  185. package/templates/racing/src/render/backlightControls.ts +10 -0
  186. package/templates/racing/src/render/backlightMaterial.ts +4 -4
  187. package/templates/racing/src/render/camera.ts +29 -4
  188. package/templates/racing/src/render/clouds.ts +16 -1
  189. package/templates/racing/src/render/effects.ts +244 -0
  190. package/templates/racing/src/render/materialLighting.ts +5 -5
  191. package/templates/racing/src/render/materials.ts +43 -8
  192. package/templates/racing/src/render/quality.ts +7 -32
  193. package/templates/racing/src/render/shapes.ts +37 -0
  194. package/templates/racing/src/render/skids.ts +84 -0
  195. package/templates/racing/src/render/touch-controls.ts +10 -10
  196. package/templates/racing/src/scenes/Race.ts +281 -26
  197. package/templates/racing/src/state.ts +35 -0
  198. package/templates/racing/src/style.css +7 -0
  199. package/templates/racing/src/track/Track.ts +132 -58
  200. package/templates/racing/src/track/TrackSector.ts +19 -1
  201. package/templates/racing/src/track/circuit.ts +21 -15
  202. package/templates/racing/src/ui/GameUi.tsx +0 -2
  203. package/templates/racing/src/ui/Hud.tsx +417 -50
  204. package/templates/racing/threenative.config.ts +15 -0
  205. package/templates/racing/tools/make-racing-audio.mjs +388 -0
  206. package/templates/racing/tsconfig.json +1 -1
  207. package/templates/racing/vite.config.ts +2 -0
  208. package/templates/rain/AGENTS.md +6 -2
  209. package/templates/rain/CLAUDE.md +6 -2
  210. package/templates/rain/package.json +6 -6
  211. package/templates/rain/src/game.ts +1 -1
  212. package/templates/rain/src/render/noise-volume.ts +2 -1
  213. package/templates/rain/src/state.ts +3 -1
  214. package/templates/rain/src/ui/GameUi.tsx +1 -1
  215. package/templates/rain/src/ui/automation.ts +10 -8
  216. package/templates/rain/src/ui/tempest.ts +3 -4
  217. package/templates/rain/vite.config.ts +6 -0
  218. package/templates/rts/AGENTS.md +6 -2
  219. package/templates/rts/CLAUDE.md +6 -2
  220. package/templates/rts/package.json +6 -6
  221. package/templates/rts/src/game.ts +1 -1
  222. package/templates/rts/src/render/backlightControls.ts +10 -0
  223. package/templates/rts/src/render/backlightMaterial.ts +4 -4
  224. package/templates/rts/src/render/materialLighting.ts +5 -5
  225. package/templates/rts/src/render/quality.ts +7 -31
  226. package/templates/rts/src/scenes/Play.ts +1 -1
  227. package/templates/rts/src/sim/terrain.ts +1 -0
  228. package/templates/rts/src/sim/types.ts +1 -0
  229. package/templates/rts/src/style.css +4 -0
  230. package/templates/rts/vite.config.ts +2 -0
  231. package/templates/runner/AGENTS.md +7 -2
  232. package/templates/runner/CLAUDE.md +7 -2
  233. package/templates/runner/package.json +7 -7
  234. package/templates/runner/src/game.ts +1 -1
  235. package/templates/runner/src/render/atmosphere.ts +6 -0
  236. package/templates/runner/src/render/backlightControls.ts +10 -0
  237. package/templates/runner/src/render/backlightMaterial.ts +4 -4
  238. package/templates/runner/src/render/clouds.ts +16 -1
  239. package/templates/runner/src/render/materialLighting.ts +5 -5
  240. package/templates/runner/src/render/materials.ts +3 -2
  241. package/templates/runner/src/render/quality.ts +7 -32
  242. package/templates/runner/src/render/touch-controls.ts +7 -6
  243. package/templates/runner/src/scenes/Run.ts +8 -10
  244. package/templates/runner/src/style.css +4 -0
  245. package/templates/runner/tsconfig.json +1 -1
  246. package/templates/runner/vite.config.ts +2 -0
  247. package/templates/sailing/AGENTS.md +7 -2
  248. package/templates/sailing/CLAUDE.md +7 -2
  249. package/templates/sailing/package.json +7 -7
  250. package/templates/sailing/src/game.ts +1 -1
  251. package/templates/sailing/src/render/backlightControls.ts +10 -0
  252. package/templates/sailing/src/render/backlightMaterial.ts +4 -4
  253. package/templates/sailing/src/render/environmentSetup.ts +1 -1
  254. package/templates/sailing/src/render/materialLighting.ts +5 -5
  255. package/templates/sailing/src/render/quality.ts +7 -32
  256. package/templates/sailing/src/render/touch-controls.ts +7 -6
  257. package/templates/sailing/src/style.css +5 -0
  258. package/templates/sailing/vite.config.ts +6 -0
  259. package/templates/shooter/AGENTS.md +6 -2
  260. package/templates/shooter/CLAUDE.md +6 -2
  261. package/templates/shooter/package.json +7 -7
  262. package/templates/shooter/src/game.ts +3 -2
  263. package/templates/shooter/src/render/atmosphere.ts +6 -0
  264. package/templates/shooter/src/render/backlightControls.ts +10 -0
  265. package/templates/shooter/src/render/backlightMaterial.ts +4 -4
  266. package/templates/shooter/src/render/clouds.ts +16 -1
  267. package/templates/shooter/src/render/materialLighting.ts +5 -5
  268. package/templates/shooter/src/render/quality.ts +7 -32
  269. package/templates/shooter/src/scenes/Play.ts +4 -1
  270. package/templates/shooter/src/style.css +4 -0
  271. package/templates/shooter/vite.config.ts +2 -0
  272. package/templates/snow/AGENTS.md +7 -2
  273. package/templates/snow/CLAUDE.md +7 -2
  274. package/templates/snow/package.json +7 -7
  275. package/templates/snow/src/entities/Explorer.ts +6 -12
  276. package/templates/snow/src/game.ts +1 -1
  277. package/templates/snow/src/render/backlightControls.ts +10 -0
  278. package/templates/snow/src/render/backlightMaterial.ts +4 -4
  279. package/templates/snow/src/render/bootPrint.ts +3 -1
  280. package/templates/snow/src/render/camera.ts +3 -2
  281. package/templates/snow/src/render/materialLighting.ts +5 -5
  282. package/templates/snow/src/render/quality.ts +7 -32
  283. package/templates/snow/src/render/scenery.ts +3 -3
  284. package/templates/snow/src/render/touch-controls.ts +7 -6
  285. package/templates/snow/src/render/weather.ts +3 -5
  286. package/templates/snow/src/style.css +5 -0
  287. package/templates/snow/src/terrain.ts +2 -1
  288. package/templates/snow/vite.config.ts +6 -0
  289. package/templates/starter/AGENTS.md +8 -3
  290. package/templates/starter/CLAUDE.md +8 -3
  291. package/templates/starter/native-playtests/render-chain.playtest.json +9 -9
  292. package/templates/starter/package.json +7 -7
  293. package/templates/starter/src/entities/Crate.ts +5 -2
  294. package/templates/starter/src/entities/Player.ts +10 -2
  295. package/templates/starter/src/game.ts +4 -3
  296. package/templates/starter/src/render/adaptiveQuality.ts +17 -0
  297. package/templates/starter/src/render/atmosphere.ts +6 -0
  298. package/templates/starter/src/render/backlightControls.ts +10 -0
  299. package/templates/starter/src/render/backlightMaterial.ts +4 -4
  300. package/templates/starter/src/render/camera.ts +2 -2
  301. package/templates/starter/src/render/clouds.ts +16 -1
  302. package/templates/starter/src/render/contactShadow.ts +1 -1
  303. package/templates/starter/src/render/materialLighting.ts +5 -5
  304. package/templates/starter/src/render/materials.ts +3 -2
  305. package/templates/starter/src/render/postprocessing.ts +11 -10
  306. package/templates/starter/src/render/quality.ts +14 -1
  307. package/templates/starter/src/render/touch-controls.ts +7 -6
  308. package/templates/starter/src/scenes/Play.ts +13 -17
  309. package/templates/starter/src/state.ts +2 -0
  310. package/templates/starter/src/style.css +4 -0
  311. package/templates/starter/src/ui/Menu.tsx +5 -1
  312. package/templates/starter/vite.config.ts +2 -0
  313. package/templates/tower-defense/AGENTS.md +7 -2
  314. package/templates/tower-defense/CLAUDE.md +7 -2
  315. package/templates/tower-defense/package.json +7 -7
  316. package/templates/tower-defense/src/game.ts +1 -1
  317. package/templates/tower-defense/src/render/backlightControls.ts +10 -0
  318. package/templates/tower-defense/src/render/backlightMaterial.ts +4 -4
  319. package/templates/tower-defense/src/render/materialLighting.ts +5 -5
  320. package/templates/tower-defense/src/render/quality.ts +7 -32
  321. package/templates/tower-defense/src/render/shapes.ts +1 -2
  322. package/templates/tower-defense/src/scenes/Battle.ts +4 -9
  323. package/templates/tower-defense/src/style.css +4 -0
  324. package/templates/tower-defense/tsconfig.json +1 -1
  325. package/templates/tower-defense/vite.config.ts +2 -0
  326. package/templates/action-rpg/src/render/environmentContribution.ts +0 -188
  327. package/templates/action-rpg/src/render/environmentRadiance.ts +0 -36
  328. package/templates/action-rpg/src/render/environmentSampleCache.ts +0 -43
  329. package/templates/action-rpg/src/render/environmentSampling.ts +0 -193
  330. package/templates/action-rpg/src/render/environmentSnapshot.ts +0 -53
  331. package/templates/minimal/src/render/environmentContribution.ts +0 -188
  332. package/templates/minimal/src/render/environmentRadiance.ts +0 -36
  333. package/templates/minimal/src/render/environmentSampleCache.ts +0 -43
  334. package/templates/minimal/src/render/environmentSampling.ts +0 -193
  335. package/templates/minimal/src/render/environmentSnapshot.ts +0 -53
  336. package/templates/platformer/src/render/environmentContribution.ts +0 -188
  337. package/templates/platformer/src/render/environmentRadiance.ts +0 -36
  338. package/templates/platformer/src/render/environmentSampleCache.ts +0 -43
  339. package/templates/platformer/src/render/environmentSampling.ts +0 -193
  340. package/templates/platformer/src/render/environmentSnapshot.ts +0 -53
  341. package/templates/puzzle/src/render/environmentContribution.ts +0 -188
  342. package/templates/puzzle/src/render/environmentRadiance.ts +0 -36
  343. package/templates/puzzle/src/render/environmentSampleCache.ts +0 -43
  344. package/templates/puzzle/src/render/environmentSampling.ts +0 -193
  345. package/templates/puzzle/src/render/environmentSnapshot.ts +0 -53
  346. package/templates/racing/src/render/environmentContribution.ts +0 -188
  347. package/templates/racing/src/render/environmentRadiance.ts +0 -36
  348. package/templates/racing/src/render/environmentSampleCache.ts +0 -43
  349. package/templates/racing/src/render/environmentSampling.ts +0 -193
  350. package/templates/racing/src/render/environmentSnapshot.ts +0 -53
  351. package/templates/racing/src/ui/Menu.tsx +0 -7
  352. package/templates/rts/src/render/environmentContribution.ts +0 -188
  353. package/templates/rts/src/render/environmentRadiance.ts +0 -36
  354. package/templates/rts/src/render/environmentSampleCache.ts +0 -43
  355. package/templates/rts/src/render/environmentSampling.ts +0 -193
  356. package/templates/rts/src/render/environmentSnapshot.ts +0 -53
  357. package/templates/runner/src/render/environmentContribution.ts +0 -188
  358. package/templates/runner/src/render/environmentRadiance.ts +0 -36
  359. package/templates/runner/src/render/environmentSampleCache.ts +0 -43
  360. package/templates/runner/src/render/environmentSampling.ts +0 -193
  361. package/templates/runner/src/render/environmentSnapshot.ts +0 -53
  362. package/templates/sailing/src/render/environmentContribution.ts +0 -188
  363. package/templates/sailing/src/render/environmentRadiance.ts +0 -36
  364. package/templates/sailing/src/render/environmentSampleCache.ts +0 -43
  365. package/templates/sailing/src/render/environmentSampling.ts +0 -193
  366. package/templates/sailing/src/render/environmentSnapshot.ts +0 -53
  367. package/templates/shooter/src/render/environmentContribution.ts +0 -188
  368. package/templates/shooter/src/render/environmentRadiance.ts +0 -36
  369. package/templates/shooter/src/render/environmentSampleCache.ts +0 -43
  370. package/templates/shooter/src/render/environmentSampling.ts +0 -193
  371. package/templates/shooter/src/render/environmentSnapshot.ts +0 -53
  372. package/templates/snow/src/render/environmentContribution.ts +0 -188
  373. package/templates/snow/src/render/environmentRadiance.ts +0 -36
  374. package/templates/snow/src/render/environmentSampleCache.ts +0 -43
  375. package/templates/snow/src/render/environmentSampling.ts +0 -193
  376. package/templates/snow/src/render/environmentSnapshot.ts +0 -53
  377. package/templates/starter/src/render/environmentContribution.ts +0 -188
  378. package/templates/starter/src/render/environmentRadiance.ts +0 -36
  379. package/templates/starter/src/render/environmentSampleCache.ts +0 -43
  380. package/templates/starter/src/render/environmentSampling.ts +0 -193
  381. package/templates/starter/src/render/environmentSnapshot.ts +0 -53
  382. package/templates/starter/src/render/rendererGate.ts +0 -36
  383. package/templates/tower-defense/src/render/environmentContribution.ts +0 -188
  384. package/templates/tower-defense/src/render/environmentRadiance.ts +0 -36
  385. package/templates/tower-defense/src/render/environmentSampleCache.ts +0 -43
  386. package/templates/tower-defense/src/render/environmentSampling.ts +0 -193
  387. package/templates/tower-defense/src/render/environmentSnapshot.ts +0 -53
@@ -1,4 +1,5 @@
1
1
  import {
2
+ GPUParticles3D,
2
3
  Scene,
3
4
  type SceneFrame,
4
5
  afterPhysics,
@@ -6,23 +7,37 @@ import {
6
7
  isMobile,
7
8
  isTouchscreenAvailable,
8
9
  } from "@threenative/core";
10
+ import { type IEnvironmentSample, sampleEnvironment } from "@threenative/core/render/environment";
9
11
  import type { IPhysicsContext } from "@threenative/physics";
10
- import { type PerspectiveCamera, type Texture, Vector3 } from "three";
12
+ import {
13
+ MathUtils,
14
+ type Object3D,
15
+ type PerspectiveCamera,
16
+ RepeatWrapping,
17
+ type Texture,
18
+ Vector3,
19
+ } from "three";
20
+ import { EngineAudio } from "../audio/engine.js";
11
21
  import { type CarCtx, FEEL } from "../entities/CarBody.js";
12
22
  import { RacingCar } from "../entities/RacingCar.js";
13
- import { Rival } from "../entities/Rival.js";
23
+ import { RIVALS, Rival } from "../entities/Rival.js";
24
+ import { Gauges } from "../gauges.js";
14
25
  import { emitPlaytestEvent } from "../playtest-events.js";
15
- import { cameraBank, chaseCamera, setupCamera } from "../render/camera.js";
16
- import { type IEnvironmentSample, sampleEnvironment } from "../render/environmentSampling.js";
26
+ import { BASE_FOV, cameraBank, chaseCamera, setupCamera } from "../render/camera.js";
27
+ import { cloudTextures, primeCloudTextures } from "../render/clouds.js";
28
+ import { BURSTS, EFFECTS } from "../render/effects.js";
17
29
  import { setupLighting } from "../render/lighting.js";
18
30
  import { createLoadingScreen } from "../render/loading.js";
19
31
  import { createMaterialLighting } from "../render/materialLighting.js";
32
+ import type { IGrassMaps } from "../render/materials.js";
20
33
  import { setupPost } from "../render/postprocessing.js";
21
34
  import {
22
35
  type QualityTier,
23
36
  isWebGLFallbackRenderer,
24
37
  materialLightingEnabled,
25
38
  } from "../render/quality.js";
39
+ import { EXHAUST } from "../render/shapes.js";
40
+ import { SkidMarks } from "../render/skids.js";
26
41
  import { SKY_OPTIONS, SUN_DIRECTION, setupSky } from "../render/sky.js";
27
42
  import { TouchControls } from "../render/touch-controls.js";
28
43
  import { type GameState, type RaceStatus, resolveRaceStatus } from "../state.js";
@@ -35,15 +50,16 @@ import {
35
50
  gridPosition,
36
51
  intersectRay,
37
52
  roadRayProbe,
53
+ terrainHeight,
38
54
  } from "../track/Track.js";
39
55
  import { TrackSector } from "../track/TrackSector.js";
40
- import { CIRCUIT, GRID_DISTANCE } from "../track/circuit.js";
56
+ import { CIRCUIT, PLAYER_SLOT, gridSlot } from "../track/circuit.js";
41
57
 
42
58
  export type GameCtx = CarCtx;
43
59
 
44
60
  /** The player starts on the second grid slot, one ride height above the tarmac. */
45
- const SPAWN = gridPosition("player", new Vector3());
46
- SPAWN.y = CIRCUIT.at(GRID_DISTANCE.player, CIRCUIT.createSample()).point.y + 0.22;
61
+ const SPAWN = gridPosition(PLAYER_SLOT, new Vector3());
62
+ SPAWN.y = CIRCUIT.at(gridSlot(PLAYER_SLOT).distance, CIRCUIT.createSample()).point.y + 0.22;
47
63
  /**
48
64
  * The race is three laps of 55-60 s, so a time limit under four minutes is a limit nobody reaches
49
65
  * and one that only fires on a car that has already been rescued four times.
@@ -58,6 +74,55 @@ function playerRanking(ranked: readonly IRankedRacer[]): IRankedRacer | undefine
58
74
  return undefined;
59
75
  }
60
76
 
77
+ const DEG = 180 / Math.PI;
78
+
79
+ /**
80
+ * The shake meter: the worst tick-to-tick step of the camera's bank and of the body's lean, and
81
+ * the worst second difference of the camera's yaw. A steady turn has a steady yaw rate, so its
82
+ * second difference is near zero; a camera that twitches from tick to tick does not.
83
+ */
84
+ function createShakeMeter() {
85
+ let roll = 0;
86
+ let yaw = 0;
87
+ let yawRate = 0;
88
+ let lean = 0;
89
+ let samples = 0;
90
+ const dir = new Vector3();
91
+ const right = new Vector3();
92
+ const meter = {
93
+ cameraRollStep: 0,
94
+ cameraYawJerk: 0,
95
+ leanRollStep: 0,
96
+ /** The body's roll and pitch this tick, in degrees: + rolls toward the right, + lifts the nose. */
97
+ leanRoll: 0,
98
+ leanPitch: 0,
99
+ /** A camera cut is not a shake: the next two samples rebuild the history. */
100
+ reset(): void {
101
+ samples = 0;
102
+ },
103
+ sample(camera: PerspectiveCamera, body: Object3D): void {
104
+ camera.getWorldDirection(dir);
105
+ right.setFromMatrixColumn(camera.matrixWorld, 0);
106
+ const nextYaw = Math.atan2(dir.z, dir.x);
107
+ const rate = Math.atan2(Math.sin(nextYaw - yaw), Math.cos(nextYaw - yaw));
108
+ const nextRoll = Math.asin(MathUtils.clamp(right.y, -1, 1));
109
+ if (samples >= 2) {
110
+ meter.cameraRollStep = Math.max(meter.cameraRollStep, Math.abs(nextRoll - roll) * DEG);
111
+ meter.cameraYawJerk = Math.max(meter.cameraYawJerk, Math.abs(rate - yawRate) * DEG);
112
+ meter.leanRollStep = Math.max(meter.leanRollStep, Math.abs(body.rotation.x - lean) * DEG);
113
+ }
114
+ samples += 1;
115
+ roll = nextRoll;
116
+ yaw = nextYaw;
117
+ yawRate = rate;
118
+ lean = body.rotation.x;
119
+ meter.leanRoll = body.rotation.x * DEG;
120
+ meter.leanPitch = body.rotation.z * DEG;
121
+ },
122
+ };
123
+ return meter;
124
+ }
125
+
61
126
  function quantize(value: number, scale: number): number {
62
127
  return Math.round(value * scale) / scale;
63
128
  }
@@ -70,11 +135,30 @@ export class Race extends Scene<GameState, IPhysicsContext> {
70
135
  boostActive: false,
71
136
  boostPeakSpeed: 0,
72
137
  boostUses: 0,
138
+ drifting: false,
139
+ driftAngle: 0,
140
+ driftScore: 0,
141
+ driftsBanked: 0,
142
+ driftSpins: 0,
143
+ nitro: 1,
144
+ nitroActive: false,
145
+ nitroDriftGain: 0,
146
+ gear: 1,
147
+ rpm: 0,
148
+ driftLast: 0,
149
+ driftPopup: 0,
150
+ fov: BASE_FOV,
151
+ fovPeak: BASE_FOV,
152
+ engineRate: 0,
73
153
  completedLaps: 0,
74
154
  elapsed: 0,
75
155
  lastOnRoad: [SPAWN.x, SPAWN.y, SPAWN.z],
76
156
  place: 1,
157
+ racers: RIVALS.length + 1,
77
158
  position: "P1",
159
+ bestLap: 0,
160
+ lastLap: 0,
161
+ rankings: [],
78
162
  raceStatus: "RACING",
79
163
  rescueHeading: 0,
80
164
  // Before any rescue, both errors are the worst they could be: the car is facing the wrong way
@@ -94,6 +178,7 @@ export class Race extends Scene<GameState, IPhysicsContext> {
94
178
  };
95
179
 
96
180
  #sky: Texture | undefined;
181
+ #grass: IGrassMaps | undefined;
97
182
 
98
183
  /**
99
184
  * The sky photograph, **awaited** before the scene enters.
@@ -110,15 +195,19 @@ export class Race extends Scene<GameState, IPhysicsContext> {
110
195
  #environmentSample: IEnvironmentSample | undefined;
111
196
  #materialLighting: ReturnType<typeof createMaterialLighting> | undefined;
112
197
  #lightingGeneration = 0;
198
+ #audio: EngineAudio | undefined;
113
199
 
114
200
  override async load(ctx: GameCtx): Promise<void> {
115
201
  const generation = ++this.#lightingGeneration;
116
202
  // Only the photo-sky override reads the photograph; the atmosphere sky is computed.
117
203
  const texture = SKY_OPTIONS.sky === "photo" ? await ctx.assets.texture("sky.jpg") : undefined;
204
+ this.#grass = await loadGrassTextures(ctx);
118
205
  if (generation !== this.#lightingGeneration) return;
119
206
  this.#sky = texture;
120
207
  const scene = ctx.scene;
121
208
  if (scene === undefined) return;
209
+ // The cloud noise is the same every run of this build: generate it once, then read it back.
210
+ primeCloudTextures(await ctx.assets.memo("clouds", () => cloudTextures()));
122
211
  setupSky(scene, texture, ctx.renderer.softwareAdapter !== undefined);
123
212
  // The measurement is not awaited: it reads the GPU back and must not hold the first frame.
124
213
  void this.#sampleSky(ctx, scene, generation);
@@ -190,15 +279,18 @@ export class Race extends Scene<GameState, IPhysicsContext> {
190
279
  const touchControls = showTouchControls
191
280
  ? ctx.entities.add("touch-controls", new TouchControls(camera))
192
281
  : undefined;
193
- const track = buildTrack(ctx);
194
- const car = new RacingCar(ctx, SPAWN, gridHeading("player"));
195
- // The rival's own grid slot, projected onto the circuit it drives: on pole, four metres up the
196
- // road and 4.4 m to the other side, facing the same way. It used to be placed a whole lap
197
- // ahead and then copied onto the player's position, so the two cars were the same point in
198
- // space and the player drove through a rival that had no body.
199
- const rival = new Rival(ctx, GRID_DISTANCE.rival);
282
+ const track = buildTrack(ctx, this.#grass);
283
+ const car = new RacingCar(ctx, SPAWN, gridHeading(PLAYER_SLOT));
284
+ // Display only, both of them: the rev counter's needle and the engine note it pitches. Neither
285
+ // touches the chassis, so a wrong needle is a wrong gauge and never a wrong lap.
286
+ const gauges = new Gauges();
287
+ this.#audio = new EngineAudio(camera, (name) => ctx.assets.audio(name));
288
+ // The field, each car on its own grid slot projected onto the circuit it drives. The pole car
289
+ // is the entity `rival`, the car to beat; the others are `rival-2` to `rival-5`.
290
+ const rivals = RIVALS.map((_, index) => new Rival(ctx, index));
200
291
  ctx.entities.add("player", car);
201
- ctx.entities.add("rival", rival);
292
+ for (const [index, rival] of rivals.entries())
293
+ ctx.entities.add(index === 0 ? "rival" : `rival-${index + 1}`, rival);
202
294
  // The sun's aim as three reads it: the target's world matrix, which only a scene traversal refreshes.
203
295
  ctx.entities.add("sun", {
204
296
  get targetGap(): number {
@@ -211,19 +303,38 @@ export class Race extends Scene<GameState, IPhysicsContext> {
211
303
  // `travelDirection` is the car's **measured** velocity, not the heading it was asked for: a
212
304
  // car that is sliding through a corner is travelling somewhere other than where it points, and
213
305
  // a lap counted on the intent is a lap counted on a wish.
306
+ // Lap times read the same race clock the HUD's timer publishes.
307
+ let elapsed = 0;
308
+ let bestLap = 0;
309
+ let lastLap = 0;
310
+ let lapStartedAt = 0;
214
311
  const lap = new Lap(
215
312
  { body: car.body.body, forward: car.travelDirection },
216
313
  track.gates,
217
314
  TOTAL_LAPS,
218
- (completed) => emitPlaytestEvent({ entity: "player", lap: completed, name: "lap-completed" }),
315
+ (completed) => {
316
+ lastLap = elapsed - lapStartedAt;
317
+ lapStartedAt = elapsed;
318
+ if (bestLap === 0 || lastLap < bestLap) bestLap = lastLap;
319
+ emitPlaytestEvent({ entity: "player", lap: completed, name: "lap-completed" });
320
+ },
219
321
  );
220
322
  const playerRankingInput = { id: "player", lap: lap.completed, position: car.body.position };
221
- const rivalRankingInput = { id: "rival", lap: rival.lap, position: rival.mesh.position };
222
- const rankingInputs = [playerRankingInput, rivalRankingInput];
323
+ const rivalRankingInputs = rivals.map((rival, index) => ({
324
+ id: index === 0 ? "rival" : `rival-${index + 1}`,
325
+ lap: rival.lap,
326
+ position: rival.mesh.position,
327
+ }));
328
+ const rankingInputs = [playerRankingInput, ...rivalRankingInputs];
223
329
  const rankingBuffer: IRankedRacerScratch[] = [];
224
330
  const rankRace = () => {
225
331
  playerRankingInput.lap = lap.completed;
226
- rivalRankingInput.lap = rival.lap;
332
+ // Indexed loop, not `.entries()`: this runs every frame and the runtime-cost gate holds the
333
+ // scene to zero per-frame iterator allocations.
334
+ for (let index = 0; index < rivalRankingInputs.length; index += 1) {
335
+ const input = rivalRankingInputs[index];
336
+ if (input !== undefined) input.lap = rivals[index]?.lap ?? 0;
337
+ }
227
338
  return rankRacers(CIRCUIT, rankingInputs, undefined, rankingBuffer);
228
339
  };
229
340
  const initialRanked = rankRace();
@@ -233,6 +344,12 @@ export class Race extends Scene<GameState, IPhysicsContext> {
233
344
  const sector = new TrackSector({
234
345
  route: CIRCUIT,
235
346
  intersectRay: intersectRay(ctx.physics, fallbackProbe),
347
+ // The grass is a heightfield collider now; this stays as the last-resort net for a car that
348
+ // leaves the world another way (a jump over the armco, or a future gap). The rescue fires the
349
+ // tick the car is clearly below the surface it should be standing on.
350
+ groundAt: terrainHeight,
351
+ // A metre below the drawn ground is not a crest or a berm, it is a car with no world under it.
352
+ fallDepth: 1.2,
236
353
  });
237
354
  track.boostArea.on("bodyEntered", (body) => {
238
355
  if (body === car.body.body) {
@@ -241,7 +358,6 @@ export class Race extends Scene<GameState, IPhysicsContext> {
241
358
  }
242
359
  });
243
360
  car.boost.update(0);
244
- let elapsed = 0;
245
361
  let status: RaceStatus = "RACING";
246
362
  let rescues = 0;
247
363
  // Before any rescue, both are the worst they can be: a car facing the wrong way, a whole lap
@@ -253,6 +369,9 @@ export class Race extends Scene<GameState, IPhysicsContext> {
253
369
  let place = initialPlayer.place;
254
370
  let positionLabel = `P${place}`;
255
371
  const lastOnRoad: [number, number, number] = [SPAWN.x, SPAWN.y, SPAWN.z];
372
+ // A rescue or the autopilot's rejoin teleports the car, so the camera cuts to it instead of
373
+ // flying across the circuit.
374
+ let teleports = car.body.teleports;
256
375
  const observedPosition = SPAWN.clone();
257
376
  sector.update(SPAWN, car.forward, 0, 0);
258
377
  chaseCamera(camera, car.body.position, car.forward, 1, undefined);
@@ -266,7 +385,8 @@ export class Race extends Scene<GameState, IPhysicsContext> {
266
385
  dt,
267
386
  touchControls?.update(frameCtx.input.raw.pointers, frameCtx.viewport.size),
268
387
  );
269
- rival.update(dt);
388
+ for (let index = 0; index < rivals.length; index += 1) rivals[index]?.update(dt);
389
+ gauges.update(car.speed, dt);
270
390
  sector.update(car.body.position, car.forward, dt, car.speed, car.driving);
271
391
  if (sector.rescue(car)) {
272
392
  rescues += 1;
@@ -281,6 +401,68 @@ export class Race extends Scene<GameState, IPhysicsContext> {
281
401
  };
282
402
 
283
403
  const statePatch: Partial<GameState> = {};
404
+ const shake = ctx.entities.add("camera-rig", createShakeMeter());
405
+
406
+ // Effects: two pooled emitters and one instanced ring of skid marks, every look parameter in
407
+ // `render/effects.ts` and `render/skids.ts`.
408
+ const make = (name: keyof typeof EFFECTS): GPUParticles3D => {
409
+ const emitter = ctx.add(new GPUParticles3D(EFFECTS[name]()));
410
+ emitter.name = `effects-${name}`;
411
+ return emitter;
412
+ };
413
+ const emitters = { nitro: make("nitro"), smoke: make("smoke") };
414
+ const burstOrigin = { x: 0, y: 0, z: 0 };
415
+ const burstShape = { x: 0, y: 0, z: 0 };
416
+ const burst = (kind: keyof typeof BURSTS, at: Vector3): void => {
417
+ const { count, emitter, shape } = BURSTS[kind];
418
+ burstOrigin.x = at.x;
419
+ burstOrigin.y = at.y;
420
+ burstOrigin.z = at.z;
421
+ burstShape.x = shape[0];
422
+ burstShape.y = shape[1];
423
+ burstShape.z = shape[2];
424
+ emitters[emitter].emitParticle({ count, direction: burstShape, origin: burstOrigin });
425
+ };
426
+ const skids = new SkidMarks(ctx.scene);
427
+ // What the effects did, for a scenario: ticks a tyre smoked, ticks the flame burned.
428
+ const effects = ctx.entities.add("effects", {
429
+ flameTicks: 0,
430
+ skidMarks: 0,
431
+ smokeTicks: 0,
432
+ });
433
+ const REAR_WHEELS = [2, 3] as const;
434
+ const rearRadius = car.body.body.wheels[2]?.wheelRadius ?? 0.37;
435
+ const contact = new Vector3();
436
+ let effectTick = 0;
437
+ const emitEffects = (): void => {
438
+ effectTick += 1;
439
+ if (car.skidding) {
440
+ let smoked = false;
441
+ for (const index of REAR_WHEELS) {
442
+ const wheel = car.body.wheels[index];
443
+ if (wheel === undefined || !car.body.body.wheelContact(index)) continue;
444
+ wheel.getWorldPosition(contact);
445
+ contact.y -= rearRadius;
446
+ skids.lay(index === 2 ? "rear-a" : "rear-b", contact.x, contact.y, contact.z);
447
+ // Alternate tyres, one burst a tick: a puff a tick a wheel is a wall, not smoke.
448
+ if ((effectTick + index) % 2 === 0) {
449
+ contact.y += 0.12;
450
+ burst("smoke", contact);
451
+ smoked = true;
452
+ }
453
+ }
454
+ if (smoked) effects.smokeTicks += 1;
455
+ effects.skidMarks = skids.laid;
456
+ }
457
+ if (car.nitro.engaged) {
458
+ effects.flameTicks += 1;
459
+ for (const side of [-1, 1]) {
460
+ contact.set(EXHAUST.x - 0.5, EXHAUST.y, side * EXHAUST.z);
461
+ car.body.lean.localToWorld(contact);
462
+ burst("nitro", contact);
463
+ }
464
+ }
465
+ };
284
466
 
285
467
  // The suspension and the camera both read the **solved** chassis, so they run in the
286
468
  // afterPhysics phase rather than in the scene frame: a wheel's spin angle and a car's velocity
@@ -289,14 +471,43 @@ export class Race extends Scene<GameState, IPhysicsContext> {
289
471
  // The sun's shadow camera follows the car. It used to be a fixed 30 m box around the origin,
290
472
  // which on an 830 m circuit put every shadow on the grass and left the car's own shadow — the
291
473
  // speed cue a driver actually reads — somewhere else entirely.
474
+ // The lens's own reading: the nitro kick is measured on the camera, not restated from a
475
+ // constant, so a camera that stops widening fails the scenario that promises it does.
476
+ let fov = BASE_FOV;
477
+ let fovPeak = BASE_FOV;
478
+
292
479
  afterPhysics(ctx, (dt) => {
293
- car.body.settleVisuals();
294
- rival.car.settleVisuals();
480
+ car.body.settleVisuals(car.nitro.engaged, dt);
481
+ for (let index = 0; index < rivals.length; index += 1) rivals[index]?.car.settleVisuals();
482
+ if (status === "RACING") emitEffects();
295
483
  lighting.key.target.position.copy(car.body.position);
296
484
  lighting.key.position.copy(car.body.position).addScaledVector(SUN_DIRECTION, 90);
297
485
  const solved = car.body.body.linearVelocity;
298
- chaseCamera(camera, car.body.position, car.travelDirection, dt, solved);
486
+ const cut = car.body.teleports !== teleports;
487
+ teleports = car.body.teleports;
488
+ chaseCamera(
489
+ camera,
490
+ car.body.position,
491
+ car.travelDirection,
492
+ cut ? 1 : dt,
493
+ solved,
494
+ car.boosting,
495
+ );
299
496
  camera.rotateZ(cameraBank(car.lateralLoad, FEEL.lateral));
497
+ fov = camera.fov;
498
+ fovPeak = Math.max(fovPeak, fov);
499
+ this.#audio?.update({
500
+ running: status === "RACING",
501
+ rpm: gauges.rpm,
502
+ driftAngle: car.drift.angle,
503
+ sliding: car.skidding,
504
+ nitroActive: car.nitro.engaged,
505
+ });
506
+ if (cut) {
507
+ ctx.resetInterpolation(camera);
508
+ shake.reset();
509
+ }
510
+ shake.sample(camera, car.body.lean);
300
511
  });
301
512
 
302
513
  // Collect only after the loaded character and scene receivers are attached.
@@ -331,7 +542,7 @@ export class Race extends Scene<GameState, IPhysicsContext> {
331
542
  const ranked = rankRace();
332
543
  const player = playerRanking(ranked);
333
544
  if (player === undefined) throw new Error("Race ranking lost the player.");
334
- sameDistanceRanking = ranked[0]?.id === "rival" ? "lap-ahead" : "lap-behind";
545
+ sameDistanceRanking = ranked[0]?.id === "player" ? "lap-behind" : "lap-ahead";
335
546
  status = resolveRaceStatus(status, lap.completed, TOTAL_LAPS, player.place);
336
547
  if (player.place !== place) {
337
548
  place = player.place;
@@ -345,9 +556,27 @@ export class Race extends Scene<GameState, IPhysicsContext> {
345
556
  statePatch.autopilot = car.autopilotEngaged;
346
557
  statePatch.boostActive = car.boosting;
347
558
  statePatch.boostPeakSpeed = boostPeakSpeed;
348
- statePatch.boostUses = car.boost.uses;
559
+ statePatch.boostUses = car.boost.uses + car.nitro.uses;
560
+ statePatch.drifting = car.drift.drifting;
561
+ statePatch.driftAngle = quantize(car.drift.angle, 1000);
562
+ statePatch.driftScore = Math.round(car.drift.score);
563
+ statePatch.driftsBanked = car.drift.banked;
564
+ statePatch.driftSpins = car.drift.spins;
565
+ statePatch.nitro = quantize(car.nitro.tank, 1000);
566
+ statePatch.nitroActive = car.nitro.engaged;
567
+ statePatch.nitroDriftGain = quantize(car.nitro.driftGain, 1000);
568
+ statePatch.gear = gauges.gear;
569
+ statePatch.rpm = quantize(gauges.rpm, 1000);
570
+ statePatch.driftLast = Math.round(car.drift.lastBanked);
571
+ statePatch.driftPopup = quantize(car.drift.popup, 100);
572
+ statePatch.fov = quantize(fov, 100);
573
+ statePatch.fovPeak = quantize(fovPeak, 100);
574
+ statePatch.engineRate = quantize(this.#audio?.rate ?? 0, 1000);
349
575
  statePatch.completedLaps = lap.completed;
350
576
  statePatch.elapsed = elapsed;
577
+ statePatch.bestLap = bestLap;
578
+ statePatch.lastLap = lastLap;
579
+ statePatch.rankings = ranked;
351
580
  statePatch.lastOnRoad = lastOnRoad;
352
581
  statePatch.place = player.place;
353
582
  statePatch.position = positionLabel;
@@ -368,6 +597,8 @@ export class Race extends Scene<GameState, IPhysicsContext> {
368
597
  }
369
598
 
370
599
  override exit(ctx: GameCtx): void {
600
+ this.#audio?.dispose();
601
+ this.#audio = undefined;
371
602
  this.#materialLighting?.dispose();
372
603
  this.#materialLighting = undefined;
373
604
  this.#post?.dispose();
@@ -377,3 +608,27 @@ export class Race extends Scene<GameState, IPhysicsContext> {
377
608
  super.exit(ctx);
378
609
  }
379
610
  }
611
+
612
+ /** The real ground PBR set (Poly Haven/ambientCG Grass004, CC0), configured for the 9 m ground UVs. */
613
+ async function loadGrassTextures(ctx: GameCtx): Promise<IGrassMaps> {
614
+ const [color, normal, roughness] = await Promise.all([
615
+ ctx.assets.texture("grass/Grass004_color.jpg", {
616
+ anisotropy: 8,
617
+ repeat: 6.43,
618
+ wrap: RepeatWrapping,
619
+ }),
620
+ ctx.assets.texture("grass/Grass004_normal.jpg", {
621
+ anisotropy: 8,
622
+ data: true,
623
+ repeat: 6.43,
624
+ wrap: RepeatWrapping,
625
+ }),
626
+ ctx.assets.texture("grass/Grass004_roughness.jpg", {
627
+ anisotropy: 8,
628
+ data: true,
629
+ repeat: 6.43,
630
+ wrap: RepeatWrapping,
631
+ }),
632
+ ]);
633
+ return { color, normal, roughness };
634
+ }
@@ -1,3 +1,5 @@
1
+ import type { IRankedRacer } from "./track/Ranking.js";
2
+
1
3
  export type RaceStatus = "DNF" | "RACING" | "WON";
2
4
 
3
5
  export function resolveRaceStatus(
@@ -21,10 +23,43 @@ export type GameState = {
21
23
  boostPeakSpeed: number;
22
24
  speedAfterBoost: number;
23
25
  boostUses: number;
26
+ /** The handbrake drift: in a scored slide, its slip angle in radians, and the banked score. */
27
+ drifting: boolean;
28
+ driftAngle: number;
29
+ driftScore: number;
30
+ driftsBanked: number;
31
+ driftSpins: number;
32
+ /** The nitro tank, 0 to 1, and whether it is burning. */
33
+ nitro: number;
34
+ nitroActive: boolean;
35
+ /** Tank the drift path filled this race, which is what "drifting refills faster" is measured on. */
36
+ nitroDriftGain: number;
37
+ /** The gearbox: the gear engaged and the needle, 0 to 1 of that gear's band. Display only. */
38
+ gear: number;
39
+ rpm: number;
40
+ /** The last banked drift's score, which the HUD pops up for a moment after each one. */
41
+ driftLast: number;
42
+ /**
43
+ * Seconds that popup still shows, in game time: the drift owns the clock, so a pause freezes the
44
+ * popup instead of ageing it while the car is standing still.
45
+ */
46
+ driftPopup: number;
47
+ /** The camera's lens: its reading now, and the widest it has been — the nitro kick, measured. */
48
+ fov: number;
49
+ fovPeak: number;
50
+ /** The engine loop's playback rate: the sound follows the revs where the runtime allows it. */
51
+ engineRate: number;
24
52
  completedLaps: number;
25
53
  elapsed: number;
54
+ /** Best and last completed lap, in seconds; 0 until the first lap is banked. */
55
+ bestLap: number;
56
+ lastLap: number;
57
+ /** The field as ranked this frame, player included: the HUD's live leaderboard. */
58
+ rankings: readonly IRankedRacer[];
26
59
  lastOnRoad: [number, number, number];
27
60
  place: number;
61
+ /** Cars in the race, the player included: the HUD's "P3 / 6". */
62
+ racers: number;
28
63
  position: string;
29
64
  raceStatus: RaceStatus;
30
65
  rescueHeading: number;
@@ -2,6 +2,10 @@
2
2
 
3
3
  @source "../index.html";
4
4
  @source "./";
5
+ /* `src/render/` is shader and material source: a word in its comments ("blur", "filter",
6
+ "table") became a real utility rule, which is what made a clean HUD look like a native-css
7
+ profile failure. Tailwind scans what it is told to scan. */
8
+ @source not "./render";
5
9
 
6
10
  @theme {
7
11
  --color-ink: #07111d;
@@ -12,7 +16,10 @@
12
16
  --color-danger: #ff6c6c;
13
17
  --color-text: #c2d6df;
14
18
  --color-muted: #6b8c9b;
19
+ --color-cyan: #38d7e7;
15
20
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;
21
+ --font-racing: "Arial Narrow", "Roboto Condensed", "Liberation Sans Narrow", "Helvetica Neue",
22
+ sans-serif;
16
23
  }
17
24
 
18
25
  html,