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,6 +1,7 @@
1
1
  // Generated for you. The sea's tuning and its entire look live in this file, and ThreeNative does
2
2
  // not read it. `SpectralOcean` runs the simulation and draws nothing: the mesh, the material, the
3
- // colours, the foam line and the tessellation are all decisions this game makes here.
3
+ // colours, the reflection, the foam line and the tessellation are all decisions this game makes
4
+ // here.
4
5
  //
5
6
  // This replaces a two-wave `WaveField` under a `MeshBasicNodeMaterial`. Both halves of that were
6
7
  // the problem. Two analytic waves plus one domain warp is a corrugated sheet — it repeats visibly
@@ -13,20 +14,45 @@
13
14
  // A spectral ocean is cascaded wave spectra inverse-transformed on the GPU every frame, which is
14
15
  // what real water is, and a standard node material puts it back under the scene's own lights.
15
16
  import { type ISpectralOceanOptions, SpectralOcean } from "@threenative/core";
16
- import { Mesh, PlaneGeometry } from "three";
17
17
  import {
18
+ BufferGeometry,
19
+ DataTexture,
20
+ Float32BufferAttribute,
21
+ LinearFilter,
22
+ LinearMipmapLinearFilter,
23
+ Mesh,
24
+ type Object3D,
25
+ RepeatWrapping,
26
+ Vector2,
27
+ } from "three";
28
+ import {
29
+ Fn,
30
+ If,
31
+ abs,
32
+ cameraPosition,
18
33
  color,
34
+ dot,
19
35
  float,
36
+ max,
20
37
  mix,
38
+ normalWorld,
39
+ oneMinus,
21
40
  positionLocal,
22
41
  positionWorld,
42
+ pow,
43
+ reflect,
44
+ saturate,
23
45
  smoothstep,
46
+ texture,
24
47
  transformNormalToView,
48
+ uniform,
49
+ vec2,
25
50
  vec3,
26
51
  } from "three/tsl";
27
52
  import type { Node } from "three/webgpu";
28
53
  import { MeshStandardNodeMaterial } from "three/webgpu";
29
54
  import { palette } from "./palette.js";
55
+ import { SUN_DIRECTION } from "./sky.js";
30
56
 
31
57
  /**
32
58
  * The sea state. Every number is this game's.
@@ -36,10 +62,28 @@ import { palette } from "./palette.js";
36
62
  * vertically, which is what sharpens a crest into something a hull can be thrown by.
37
63
  */
38
64
  export const SEA = {
39
- amplitude: 0.0082,
65
+ // Sea state, and the two numbers that decide whether this reads as a passage or as a puddle.
66
+ //
67
+ // The frame this replaces was a mirror, and the spectrum is why. `windSpeed` sets where the
68
+ // Phillips spectrum's energy sits, through the largest wave `U²/g`: at 10.5 that is an eleven-metre
69
+ // scale, the energy-weighted mean wavelength came out at **42 m**, and a two-metre wave 42 m long
70
+ // is a 5% slope — a mirror with a texture on it. Nothing downstream can rescue that, because the
71
+ // normals really are almost flat. At 6 the mean wavelength is 13 m and the same height is a 15%
72
+ // slope, which is a sea with a shape.
73
+ //
74
+ // `amplitude` is the spectrum's scale, and height goes as its square root, so it was raised 15x
75
+ // to put the crest-to-trough back where it was. Calibrated against the field the CPU actually
76
+ // reads back, over a 70 m patch: 0.026 measured **3.15 m** trough to crest, which threw the ship
77
+ // bodily out of the water — the line of sight to its own keel cleared the sea half a metre astern
78
+ // and the whole hull, rudder and all, hung above the surface in almost every frame. 0.0038
79
+ // measures about 1.3 m, against 0.7 m of freeboard: the caravel is thrown, its rail is awash on
80
+ // the biggest crests, and its keel is under the water.
81
+ amplitude: 0.0046,
40
82
  // Largest patch first, and the bands do not overlap. One cascade is a toy — the join between
41
83
  // bands is where a spectral ocean visibly fails, so there is nothing to look at until there are
42
- // two.
84
+ // two. A third was measured and carries 0.01 m of the total: the 1/k⁴ term has already spent the
85
+ // short waves by the time a 9 m patch's band begins, so it buys nothing and costs two more reads
86
+ // in the vertex stage.
43
87
  cascades: [{ patchSize: 190 }, { patchSize: 37 }],
44
88
  choppiness: 1.2,
45
89
  directionality: 2.6,
@@ -54,19 +98,188 @@ export const SEA = {
54
98
  // calmer sea state below closes the rest of the gap. This is the cost of a spectral ocean over
55
99
  // an analytic one, and it is worth paying — but it has to be paid.
56
100
  readbackEveryFrames: 3,
57
- readbackResolution: 32,
101
+ // 64, and the paragraph above is the reason: at 32 the copy carried one height every six metres
102
+ // across the broad cascade, which is coarser than the ship is long, so both hull probes landed
103
+ // in the same cell and the ship barely answered the sea it was in.
104
+ readbackResolution: 64,
58
105
  resolution: 128,
59
106
  seed: 20_260_906,
60
- smallWaveCutoff: 0.32,
107
+ // The length below which the spectrum is damped out, in metres. 0.32 was a 2 m wavelength, which
108
+ // is where the geometric ripple normals already take over, so the sea was throwing away its whole
109
+ // last octave and reading as glass. 0.12 keeps it to about 1.2 m: short enough to carry a
110
+ // glitter path, long enough that the surface is not aliased into sparkle as the camera moves.
111
+ smallWaveCutoff: 0.12,
61
112
  windDirection: 0.55,
62
- windSpeed: 10.5,
113
+ windSpeed: 6,
63
114
  } satisfies ISpectralOceanOptions;
64
115
 
65
- /** The drawn surface's edge length in metres, and how finely it is tessellated. */
66
- export const SURFACE = { segments: 160, size: 300 } as const;
116
+ /**
117
+ * How fast the sea's dominant waves travel, and which way they run.
118
+ *
119
+ * A spectral ocean has no closed-form height, so the CPU copy a hull floats on is always some
120
+ * frames behind the field the GPU is drawing — the API says so, and reports the age. This is what
121
+ * a reader needs to *use* that age: deep-water waves travel, so the field at time `t + d` is very
122
+ * nearly the field at time `t` shifted downwind by `speed * d`. Sampling that far **upwind** of a
123
+ * point therefore reads what the water there is about to be doing.
124
+ *
125
+ * The peak angular frequency is the Pierson-Moskowitz one, `0.855 g / U`, and a deep-water wave's
126
+ * phase speed is `g / w`. Both come straight out of `SEA` above, so retuning the wind retunes
127
+ * this with it.
128
+ */
129
+ const PEAK_ANGULAR_FREQUENCY = (0.855 * SEA.gravity) / SEA.windSpeed;
130
+ export const SWELL = {
131
+ /** Metres per second. */
132
+ speed: SEA.gravity / PEAK_ANGULAR_FREQUENCY,
133
+ x: Math.cos(SEA.windDirection),
134
+ z: Math.sin(SEA.windDirection),
135
+ } as const;
136
+
137
+ /**
138
+ * The most wave-time any reader will extrapolate over, in seconds. See `surfaceHeight`.
139
+ *
140
+ * The lag being corrected for is a few frames in a real session and an order of magnitude worse
141
+ * inside a playtest, where the fixed step runs far faster than wall-clock and a copy in flight
142
+ * covers a hundred ticks. Correcting the first is what a floating thing needs; chasing the second
143
+ * would sample far upwind, where a spectral field has already decorrelated and the "prediction" is
144
+ * just a different wave.
145
+ *
146
+ * It is also short because the lead is measured in wavelengths, not in seconds. This sea state's
147
+ * dominant wavelength is 13 m, so a quarter of a second is 1.75 m upwind — an eighth of a wave, and
148
+ * the height comes back half a metre from the truth, which floats the drawn hull on water that is
149
+ * not being drawn. An eighth of a second is 0.9 m, or a fifteenth of a wave: worth correcting, and
150
+ * small enough not to invent a wave.
151
+ */
152
+ const MAX_LEAD_SECONDS = 0.12;
153
+
154
+ /**
155
+ * The sea's height at a world point, corrected for the age of the copy it came from.
156
+ *
157
+ * This is the call anything that floats should use, rather than `sampleHeight` raw: a hull, a
158
+ * buoy or a bit of flotsam put straight onto the returned number rides water the renderer stopped
159
+ * drawing several frames ago, and the tell is a hull that cuts down through a crest and then hangs
160
+ * over the following trough.
161
+ *
162
+ * `undefined` before the first copy lands, exactly as `sampleHeight` is, so a caller still has to
163
+ * decide what an unknown sea level means for it.
164
+ */
165
+ export function surfaceHeight(
166
+ ocean: SpectralOcean,
167
+ x: number,
168
+ z: number,
169
+ deltaTime: number,
170
+ ): number | undefined {
171
+ const probe = ocean.sampleHeight(x, z);
172
+ if (probe === undefined) return undefined;
173
+ const lead = Math.min(MAX_LEAD_SECONDS, Math.max(0, probe.staleFrames) * deltaTime);
174
+ const run = SWELL.speed * lead;
175
+ return ocean.sampleHeight(x - SWELL.x * run, z - SWELL.z * run)?.height ?? probe.height;
176
+ }
177
+
178
+ /**
179
+ * The drawn surface, as a logarithmic disc: rings of quads whose spacing grows with the radius.
180
+ *
181
+ * A square patch cannot do this job at any size. A 300 m square nailed to the ship puts its far
182
+ * edge a hundred and fifty metres out, which is inside the haze, so the player sails to a visible
183
+ * rectangular hem where the sea stops and the photograph starts; and a square big enough to reach
184
+ * the horizon needs 300 m quads near the ship, which is coarser than the waves and throws away
185
+ * everything the cascade buffers are carrying. Rings solve both at once: the innermost quad is a
186
+ * third of a metre beside the hull and the outermost is half a kilometre at the horizon, for
187
+ * *fewer* triangles than the 128×128 grid this replaced.
188
+ */
189
+ export const SURFACE = {
190
+ /** Quads around the circle. */
191
+ segments: 160,
192
+ /** Rings from the ship to the horizon. */
193
+ rings: 96,
194
+ /** Radius of the first ring, in metres. */
195
+ inner: 1.5,
196
+ /** Radius of the last ring. Past the eye's own horizon at this height, and fully hazed. */
197
+ reach: 6_000,
198
+ } as const;
199
+
200
+ /**
201
+ * The step the surface normal is differenced over, in metres.
202
+ *
203
+ * Deliberately finer than the mesh's own quad, which is a third of a metre here. Differencing at
204
+ * the quad size throws away every wave shorter than about four metres *before it can shade
205
+ * anything*, and a sea with no short waves in its normals has no glitter: the sun arrives as one
206
+ * smooth mirror lobe a third of the frame wide, blooms, and blows out. Shading detail below the
207
+ * geometric resolution is the whole point of a normal, and the fine cascade already carries it at
208
+ * 0.29 m per texel. This sits between the two: fine enough to break the highlight into a glitter
209
+ * path, coarse enough not to alias into sparkle noise as the camera moves.
210
+ */
211
+ const NORMAL_STEP = 0.7;
212
+
213
+ /** Crest foam, whitecap and hull wash. Near-white, and not a seventh palette role: the sea's look is owned here. */
214
+ const FOAM = 0xd6e6ea;
67
215
 
68
- /** Crest foam. Near-white, and not a seventh palette role: the sea's look is owned here. */
69
- const FOAM = 0xe9f4f6;
216
+ /**
217
+ * Light coming **through** a wave, which is what makes a crest read as water and not as a ridge.
218
+ *
219
+ * A backlit crest is lit from behind by the sun under the water, and that light is green. It only
220
+ * shows where the face is turned away from the sun and high enough to be near the surface, so it
221
+ * is a product of the face's own slope and its height — which is why it costs two nodes and no
222
+ * texture.
223
+ */
224
+ const SUBSURFACE = 0x1f6a4c;
225
+
226
+ /**
227
+ * How much of the mirror the sea shows.
228
+ *
229
+ * The mirrored pass draws the world *and the sky behind it*, so what arrives in this texture is a
230
+ * photograph of the clouds. That is the whole defect the owner is looking at: a planar mirror of a
231
+ * partly-cloudy sky reflects every cumulus crisply across six kilometres of water, and a sea that
232
+ * does that is a lake. The sky is therefore **not in the mirror** — see `sky.ts`, where the dome
233
+ * lives on layer 0 and the mirror draws layer 1 only — so what is left in here is the hull, the
234
+ * marks and the headland: the silhouettes a player reads in the water, and the one thing a
235
+ * prefiltered environment cannot do for a sea.
236
+ *
237
+ * Below one because a render target is written linear, where the screen is tone-mapped, so what
238
+ * arrives is the raw 2.5-range photograph and the water would mirror it at full stops.
239
+ */
240
+ const MIRROR_GAIN = 0.55;
241
+
242
+ /**
243
+ * The layer the water's mirror draws. An object on it is **also** on layer 0, so the main camera
244
+ * is unaffected and only the mirrored pass narrows.
245
+ *
246
+ * It is the hull, the marks and the headland — the silhouettes a player actually reads in the
247
+ * water. The sea itself is not on it, which is what stops the mirror from redrawing the mirror,
248
+ * and the sky is not on it because the sky arrives through `reflectedSky` instead: the mirrored
249
+ * pass is a second draw of the world, and putting a 4096-wide photograph in it would buy a
250
+ * lower-resolution copy of a lookup this material can already do for free.
251
+ */
252
+ export const REFLECTED_LAYER = 1;
253
+ /**
254
+ * How the sea's mirror is built. The *decision* lives here; the construction is the scene's,
255
+ * because `src/render/` reaches the engine only for the wave simulation it draws.
256
+ *
257
+ * Half is the honest resolution for a reflection seen through moving water — the surface itself is
258
+ * the blur, and a sharp half-res copy of a hull in a swell reads no better than a soft full-res
259
+ * one. The layer mask is what keeps the pass affordable: it is a second draw of the world, so
260
+ * `markReflected` is what names the handful of objects worth paying for.
261
+ */
262
+ export const SEA_MIRROR = {
263
+ level: 0,
264
+ // Never read: this sea is deep everywhere and has no bed to see. The option is required, and
265
+ // this is the depth of water a fully hazed fragment stands behind.
266
+ maxThickness: 24,
267
+ reflection: { resolutionScale: 0.5, layers: 1 << REFLECTED_LAYER },
268
+ } as const;
269
+
270
+ /** The one thing this material asks of the mirror. Structural, so the type is not an import. */
271
+ interface ISeaMirror {
272
+ reflectionAt(offset?: Node<"vec2">): Node<"vec3">;
273
+ dispose(): void;
274
+ }
275
+
276
+ /**
277
+ * Put an object in the mirror, and every child of it. Layers are not inherited in three, so a
278
+ * merged hull of seven meshes needs the walk.
279
+ */
280
+ export function markReflected(object: Object3D): void {
281
+ object.traverse((part) => part.layers.enable(REFLECTED_LAYER));
282
+ }
70
283
 
71
284
  export function createOcean(): SpectralOcean {
72
285
  return new SpectralOcean(SEA);
@@ -76,7 +289,7 @@ export function createOcean(): SpectralOcean {
76
289
  * Read one cascade's displacement at a world position, **bilinearly**.
77
290
  *
78
291
  * Nearest-texel sampling is the obvious way to write this and it is visibly wrong here. The mesh
79
- * carries one vertex per 1.6 m while the fine cascade's texel is 0.29 m, so every vertex grabbed a
292
+ * carries one vertex per 0.3 m while the fine cascade's texel is 0.29 m, so every vertex grabbed a
80
293
  * different texel of a field it was far too coarse to resolve — and the normal, being a difference
81
294
  * of two of those, came out piecewise-constant. The frame showed the sun's reflection broken into
82
295
  * hard axis-aligned white rectangles, which is a sampling artefact and reads as a bug in the water.
@@ -112,68 +325,442 @@ function displacementAt(ocean: SpectralOcean, x: Node<"float">, z: Node<"float">
112
325
  return vec3(broad.x.add(fine.x), broad.y.add(fine.y), broad.z.add(fine.z));
113
326
  }
114
327
 
328
+ /** A sea surface, and the handle that keeps it under the ship. */
329
+ export interface IWaterSurface {
330
+ readonly mesh: Mesh;
331
+ /** Move the drawn sea to follow a position, keeping the wave field anchored to the world. */
332
+ follow(x: number, z: number): void;
333
+ /** The sea's own clock, for the ripple normals. The wave field has the game's `advance`. */
334
+ advance(elapsed: number): void;
335
+ /**
336
+ * Where the ship is, which way it is pointing, and how hard it is pushing water aside.
337
+ *
338
+ * `strength` is 0..1 and is the speed made good over the hull's own maximum: a ship lying to
339
+ * with no way on leaves no wake, which is the point.
340
+ */
341
+ wake(x: number, z: number, forwardX: number, forwardZ: number, strength: number): void;
342
+ /** Releases the mirror's render target. The scene calls this on `exit`. */
343
+ dispose(): void;
344
+ }
345
+
115
346
  /**
116
- * The sea surface: displaced by the simulation, and lit by the scene.
347
+ * The wake's shape: how far astern it reaches in metres, how fast the wedge opens, and how wide it
348
+ * is at the transom.
117
349
  *
118
- * The vertex stage reads the cascade buffers directly, so what is drawn is the same field the
119
- * height query is copied from. If the two disagreed the ship would ride water nothing renders and
120
- * every assertion in this template would still be green.
350
+ * The half-angle of a real Kelvin wedge is about nineteen degrees whatever the hull is doing,
351
+ * which is a `spread` near 0.34 — and at that width, over thirty-four metres, the wake covers so
352
+ * much of a low-camera frame that it stops reading as a wake and becomes a pale smear across the
353
+ * bottom third. Narrower and shorter is the lie worth telling.
121
354
  */
122
- export function createWaterMesh(ocean: SpectralOcean): Mesh {
123
- const geometry = new PlaneGeometry(
124
- SURFACE.size,
125
- SURFACE.size,
126
- SURFACE.segments,
127
- SURFACE.segments,
128
- );
129
- geometry.rotateX(-Math.PI / 2);
355
+ const WAKE = { length: 26, spread: 0.21, waist: 0.5 } as const;
356
+
357
+ /**
358
+ * The wash the hull stands in, as half of the hull's length and beam in metres.
359
+ *
360
+ * A ship that leaves the surface exactly as it found it is a model on a backdrop. This is the ring
361
+ * of broken water at its own waterline: the ellipse is the hull's plan, `wash` is the band just
362
+ * outside it, and it is strongest under way because it is `wakeStrength` — a ship lying to with no
363
+ * way on stops pushing water aside, which is the point. The numbers are the hull's own, from
364
+ * `HULL_STATIONS` in `props.ts` after the 4.6 m normalisation.
365
+ */
366
+ const HULL_WASH = { halfBeam: 0.62, halfLength: 2.35 } as const;
367
+
368
+ /**
369
+ * The ripples, as a 256² normal map made of periodic value noise — no file, no fetch, no bytes.
370
+ *
371
+ * The FFT carries energy down to 0.29 m and the geometry can only be tessellated so far, so the
372
+ * last two octaves of a real sea — the chop between the wave crests — have to come from somewhere
373
+ * that is not the mesh. Two scrolling octaves of this are what break the sun's highlight into a
374
+ * glitter path instead of one blown lobe, and they are the reason a wave crest has a skin on it.
375
+ */
376
+ function rippleNormals(): DataTexture {
377
+ const n = 256;
378
+ const data = new Uint8Array(n * n * 4);
379
+ // Periodic value noise on a `k`-cell grid, so the texture tiles without a visible seam.
380
+ const hash = (x: number, z: number): number => {
381
+ const a = Math.sin(x * 127.1 + z * 311.7) * 43758.5453;
382
+ return a - Math.floor(a);
383
+ };
384
+ const noise = (u: number, v: number, k: number): number => {
385
+ const x = u * k;
386
+ const z = v * k;
387
+ const i = Math.floor(x);
388
+ const j = Math.floor(z);
389
+ let a = x - i;
390
+ let b = z - j;
391
+ a = a * a * a * (a * (a * 6 - 15) + 10);
392
+ b = b * b * b * (b * (b * 6 - 15) + 10);
393
+ const h = (hx: number, hz: number): number => hash(((hx % k) + k) % k, ((hz % k) + k) % k);
394
+ return (
395
+ (h(i, j) * (1 - a) + h(i + 1, j) * a) * (1 - b) +
396
+ (h(i, j + 1) * (1 - a) + h(i + 1, j + 1) * a) * b
397
+ );
398
+ };
399
+ const height = (u: number, v: number): number =>
400
+ noise(u, v, 8) * 0.58 +
401
+ noise(u, v, 16) * 0.28 +
402
+ noise(u, v, 32) * 0.11 +
403
+ noise(u, v, 64) * 0.03;
404
+ for (let j = 0; j < n; j += 1) {
405
+ for (let i = 0; i < n; i += 1) {
406
+ const u = i / n;
407
+ const v = j / n;
408
+ const e = 1 / n;
409
+ const nx = (height(u + e, v) - height(u - e, v)) * 6;
410
+ const nz = (height(u, v + e) - height(u, v - e)) * 6;
411
+ const at = (j * n + i) * 4;
412
+ data[at] = Math.max(0, Math.min(255, (nx * 0.5 + 0.5) * 255));
413
+ data[at + 1] = Math.max(0, Math.min(255, (nz * 0.5 + 0.5) * 255));
414
+ data[at + 2] = 240;
415
+ data[at + 3] = height(u, v) * 255;
416
+ }
417
+ }
418
+ const map = new DataTexture(data, n, n);
419
+ map.wrapS = RepeatWrapping;
420
+ map.wrapT = RepeatWrapping;
421
+ map.magFilter = LinearFilter;
422
+ map.minFilter = LinearMipmapLinearFilter;
423
+ map.generateMipmaps = true;
424
+ map.needsUpdate = true;
425
+ return map;
426
+ }
427
+
428
+ /** The logarithmic disc, in the sea patch's own space: one vertex at the centre, then the rings. */
429
+ function seaDisc(): BufferGeometry {
430
+ const { inner, reach, rings, segments } = SURFACE;
431
+ const growth = Math.log(1 + reach / inner) / rings;
432
+ const positions: number[] = [0, 0, 0];
433
+ const indices: number[] = [];
434
+ for (let ring = 0; ring < rings; ring += 1) {
435
+ const radius = inner * (Math.exp((ring + 1) * growth) - 1);
436
+ for (let step = 0; step < segments; step += 1) {
437
+ const angle = (step / segments) * Math.PI * 2;
438
+ positions.push(Math.cos(angle) * radius, 0, Math.sin(angle) * radius);
439
+ }
440
+ }
441
+ for (let step = 0; step < segments; step += 1) {
442
+ indices.push(0, 1 + ((step + 1) % segments), 1 + step);
443
+ }
444
+ for (let ring = 1; ring < rings; ring += 1) {
445
+ for (let step = 0; step < segments; step += 1) {
446
+ const near = 1 + (ring - 1) * segments + step;
447
+ const nearNext = 1 + (ring - 1) * segments + ((step + 1) % segments);
448
+ const far = 1 + ring * segments + step;
449
+ const farNext = 1 + ring * segments + ((step + 1) % segments);
450
+ indices.push(near, farNext, far, near, nearNext, farNext);
451
+ }
452
+ }
453
+ const geometry = new BufferGeometry();
454
+ geometry.setAttribute("position", new Float32BufferAttribute(positions, 3));
455
+ geometry.setIndex(indices);
456
+ geometry.computeBoundingSphere();
457
+ return geometry;
458
+ }
459
+
460
+ /**
461
+ * The slope of the swell at a world position, by central difference.
462
+ *
463
+ * Without this the surface is lit by the flat plane's normals — every vertex pointing straight up
464
+ * — and a perfectly simulated ocean shades like a sheet of paper. The step is `NORMAL_STEP`, not
465
+ * the mesh's quad; see the note on that constant.
466
+ */
467
+ function surfaceSlope(ocean: SpectralOcean, x: Node<"float">, z: Node<"float">): Node<"vec2"> {
468
+ const step = float(NORMAL_STEP);
469
+ const east = displacementAt(ocean, x.add(step), z);
470
+ const west = displacementAt(ocean, x.sub(step), z);
471
+ const north = displacementAt(ocean, x, z.add(step));
472
+ const south = displacementAt(ocean, x, z.sub(step));
473
+ const twice = step.mul(2);
474
+ return vec2(west.y.sub(east.y).div(twice), south.y.sub(north.y).div(twice));
475
+ }
476
+
477
+ /**
478
+ * Two scrolling octaves of the ripple map, as a slope in the same units as `surfaceSlope`.
479
+ *
480
+ * Only ever called inside an `Fn`, because `If` needs a shader stage to build against — and it is
481
+ * called from two of them, one per stage, which is why it returns a graph rather than a value.
482
+ */
483
+ function rippleSlope(ripples: DataTexture, time: Node<"float">, fade: Node<"float">): Node<"vec2"> {
484
+ const slope = vec2(0, 0).toVar();
485
+ If(fade.greaterThan(0.02), () => {
486
+ const micro = texture(
487
+ ripples,
488
+ vec2(positionWorld.x, positionWorld.z)
489
+ .mul(vec2(0.022, 0.045))
490
+ .add(time.mul(vec2(0.006, 0.003))),
491
+ );
492
+ const finer = texture(
493
+ ripples,
494
+ vec2(positionWorld.x, positionWorld.z)
495
+ .mul(vec2(0.1, 0.075))
496
+ .add(time.mul(vec2(-0.014, 0.009))),
497
+ );
498
+ slope.assign(micro.rg.mul(2).sub(1).add(finer.rg.mul(2).sub(1).mul(0.32)));
499
+ });
500
+ return slope;
501
+ }
130
502
 
131
- // Standard, not basic. This is the whole reason the sea now has a sun on it rather than a
132
- // hand-rolled `pow()` blob: a lit material gets the scene's key light, its hemisphere fill and
133
- // its specular response for free, and gets them consistent with the hull floating on it.
503
+ export function createWaterMesh(
504
+ ocean: SpectralOcean,
505
+ mirror: ISeaMirror,
506
+ options: { readonly software?: boolean } = {},
507
+ ): IWaterSurface {
508
+ // A CPU rasteriser draws this material's full graph (cascade normals, foam, wake, mirror) so
509
+ // slowly that the sea-height readback never lands inside a scenario's ticks (measured on four
510
+ // cores: `readbackStaleFrames` stays -1 with the full graph and lands with this one).
511
+ // `ctx.renderer.softwareAdapter` names that machine; the swell, the readback and the hull still
512
+ // run, and only the shading that needs a GPU is left off.
513
+ const cheap = options.software === true;
514
+ const geometry = seaDisc();
515
+ const ripples = rippleNormals();
516
+
517
+ // Where the drawn patch sits in the world.
518
+ //
519
+ // The disc is nailed to the ship rather than to the origin, and the field it reads does **not**
520
+ // travel with it — the cascade lookup adds this offset back, so a wave stays where it is in the
521
+ // world while the mesh slides underneath it. Without that the whole ocean would be dragged along
522
+ // by the ship and the sea would appear to stand still.
523
+ const seaOrigin = uniform(new Vector2());
524
+ const seaTime = uniform(0);
525
+ const shipOrigin = uniform(new Vector2());
526
+ const shipForward = uniform(new Vector2(0, -1));
527
+ const wakeStrength = uniform(0);
528
+
529
+ // Standard, not basic. This is the whole reason the sea has a sun on it rather than a
530
+ // hand-rolled `pow()` blob: a lit material gets the scene's key light and its specular response
531
+ // for free, and gets them consistent with the hull floating on it.
134
532
  const material = new MeshStandardNodeMaterial({
135
- metalness: 0.02,
136
- // Not glass. At 0.08 the key light landed as one blown white disc on the swell in front of the
137
- // camera; water this side of a dead calm scatters enough to spread that into a glitter path.
138
- roughness: 0.29,
533
+ metalness: 0,
534
+ // The sun's own highlight is the one term this material does **not** need help with, and it is
535
+ // the term that ruins the frame when it is too sharp. A GGX lobe at 0.16 peaks thousands of
536
+ // times brighter than its own average, and a low chase camera sees most of the sea at a
537
+ // grazing angle — so the peak lands across a third of the water at once and ACES turns the
538
+ // whole middle distance into a white sheet. The sea is rough instead (see `roughnessNode`),
539
+ // which spreads the same energy over several times the area: the glitter path is still a
540
+ // glitter path, and the sea around it is still sea.
541
+ roughness: 0.13,
139
542
  });
543
+ // **On**, and this is the fix for the mirror the owner is looking at. `scene.environment` is the
544
+ // sky photograph, three prefilters it, and a standard material's image-based specular then reads
545
+ // that prefiltered sky *at this fragment's own roughness* — a rough, blurred sky reflection,
546
+ // Fresnel-weighted by the same Schlick curve the rest of the scene's materials use. Looked
547
+ // straight down into, water reflects about 2%; looked along, it reflects nearly all of it. A
548
+ // hand-written `pow(1 - N·V, 5)` on a planar mirror photograph cannot do either of those things
549
+ // and is why every sea past a hundred metres was one even sheet of cloud.
550
+ material.envMapIntensity = 0.32;
140
551
 
141
- const offset = displacementAt(ocean, positionLocal.x, positionLocal.z);
552
+ const worldX = positionLocal.x.add(seaOrigin.x);
553
+ const worldZ = positionLocal.z.add(seaOrigin.y);
554
+ const offset = displacementAt(ocean, worldX, worldZ);
142
555
  material.positionNode = positionLocal.add(offset);
143
556
 
144
- // Normals by central difference. Without this the surface is lit by the flat plane's normals —
145
- // every vertex pointing straight up — and a perfectly simulated ocean shades like a sheet of
146
- // paper.
147
- //
148
- // The step is the mesh's own quad size, not a texel. Differencing finer than the mesh can
149
- // represent measures detail that is never drawn and turns the highlight into noise.
150
- const step = float(SURFACE.size / SURFACE.segments);
151
- const east = displacementAt(ocean, positionLocal.x.add(step), positionLocal.z);
152
- const west = displacementAt(ocean, positionLocal.x.sub(step), positionLocal.z);
153
- const north = displacementAt(ocean, positionLocal.x, positionLocal.z.add(step));
154
- const south = displacementAt(ocean, positionLocal.x, positionLocal.z.sub(step));
155
- const twice = step.mul(2);
156
- // `transformNormalToView`, not the raw vector. `normalNode` overrides `normalView`, so a
157
- // material handed a world-space normal lights the surface in the camera's frame instead of the
158
- // world's: the sun's reflection stopped being a place on the sea and became a column of glare
159
- // pointing at the camera, sliding across the water as the ship turned.
160
- material.normalNode = transformNormalToView(
161
- vec3(west.y.sub(east.y).div(twice), float(1), south.y.sub(north.y).div(twice)).normalize(),
162
- );
557
+ const eye = cameraPosition.sub(positionWorld);
558
+ const distance = eye.length();
559
+ // How far off the ship a ripple can still be told apart, from range alone. A vertex shader cannot
560
+ // ask how big its own fragment is, so this is the vertex stage's half of the answer and
561
+ // `subpixel` below is the fragment stage's.
562
+ const far = float(1).div(distance.mul(0.003).add(1));
163
563
 
164
- // Colour by height: deep in the troughs, lit water on the shoulders, foam on the crests. The
165
- // band is narrower than the wave amplitude on purpose, so the tops read as foam-lit rather than
166
- // as a gentle gradient.
167
- const shade = smoothstep(float(-2.4), float(1.8), positionWorld.y);
564
+ // How much of a wave a pixel can still resolve, as a 0..1 fraction. Past a ~4 m footprint the
565
+ // swell is sub-pixel and the ripples mip to flat, which is what turned every sea beyond ~130 m
566
+ // into a mirror. The slope that is lost does not vanish physically, it becomes roughness — so it
567
+ // is spent as roughness below, on both the mirror and the sun.
568
+ const footprint = positionWorld.dFdx().length().max(positionWorld.dFdy().length());
569
+ const subpixel = smoothstep(0.4, 4, footprint);
570
+ const detail = far.mul(oneMinus(subpixel));
571
+
572
+ // The swell's own slope, once, in the vertex stage. `transformNormalToView`, not the raw vector:
573
+ // `normalNode` overrides `normalView`, so a material handed a world-space normal lights the
574
+ // surface in the camera's frame instead of the world's — the sun's reflection stopped being a
575
+ // place on the sea and became a column of glare pointing at the camera.
576
+ if (!cheap)
577
+ material.normalNode = Fn(() => {
578
+ const slope = surfaceSlope(ocean, worldX, worldZ);
579
+ return transformNormalToView(vec3(slope.x.negate(), 1, slope.y.negate()).normalize());
580
+ })();
581
+
582
+ // Colour by height: deep blue-green in the troughs, lit water on the shoulders, foam on the
583
+ // crests.
584
+ //
585
+ // These numbers are in metres of wave height, so they move with `SEA.amplitude` and are wrong the
586
+ // moment it changes. The sea state above measures 1.99 m crest to trough, so the surface runs
587
+ // about -0.65 m to +0.65 m and the band has to sit inside that: a band centred on zero is above its
588
+ // own threshold across half the sea and the water comes back one even mid teal from bow to
589
+ // horizon. Put the band where the crests are and the sea is deep water everywhere except its
590
+ // tops, which is the only way a height ramp reads as a swell.
591
+ const shade = smoothstep(float(-0.5), float(0.4), positionWorld.y);
168
592
  const water = mix(color(palette.floor), color(palette.accent), shade);
169
- const crest = smoothstep(float(1.6), float(3), positionWorld.y);
170
- material.colorNode = mix(water, color(FOAM), crest);
171
- // Foam is not a mirror. Roughening the crests is what stops them reading as chrome.
172
- material.roughnessNode = mix(float(0.29), float(0.82), crest);
593
+ // The light coming through a wave from behind, which is green and is the difference between a
594
+ // crest and a ridge. It needs a face turned away from the sun and a height near the surface, so
595
+ // it is the product of the two, and it is added rather than mixed so a deep trough stays deep.
596
+ const through = saturate(
597
+ normalWorld.dot(vec3(SUN_DIRECTION.x, SUN_DIRECTION.y, SUN_DIRECTION.z).negate()),
598
+ )
599
+ .mul(shade)
600
+ .mul(0.26);
601
+ // Foam on the tops, not on the faces. The band has to sit near the **highest** water the field
602
+ // reaches, not near its mean: a threshold clearing across whole wave faces at once reads as snow
603
+ // rather than as sea. A field this size is a normal distribution about its mean with a standard
604
+ // deviation near 0.25 m, and at 0.46 m and 0.74 m that is the top one to three per cent of the
605
+ // surface — which is what whitecaps are, and it is the top of the distribution that breaks, not
606
+ // the mean. The band that came back first was at 0.55 m on a field twice this size, which is barely
607
+ // one deviation: a third of the sea came back white and the frame read as pack ice.
608
+ //
609
+ // A height band alone gives foam a *contour line*, because a smooth wave crossing a smooth
610
+ // threshold is a smooth curve: the crests came back as glossy white ribbons laid along the sea,
611
+ // which read as plastic rather than as water. One more octave of the ripple map tears the edge,
612
+ // and it is the same texture the normals already read, so it costs one fetch.
613
+ //
614
+ // **Remapped so it reaches zero.** It used to run 0.45 to 1.0, which is a tint and not a tear:
615
+ // multiplied into the wake it left every fragment of foam at least 45% opaque, and a hard white
616
+ // U came down the frame from under the stern of a ship making no way at all. Foam is patches —
617
+ // there is water between them, and the mask has to say so or it is a decal.
618
+ const torn = Fn(() => {
619
+ const grain = texture(
620
+ ripples,
621
+ vec2(positionWorld.x, positionWorld.z).mul(0.26).add(seaTime.mul(0.02)),
622
+ ).a;
623
+ return smoothstep(float(0.4), float(0.74), grain);
624
+ })();
625
+ const crest = smoothstep(float(0.46), float(0.74), positionWorld.y).mul(torn);
626
+
627
+ // The wake, computed rather than drawn.
628
+ //
629
+ // A hull moving through water at six knots that leaves the surface exactly as it found it is the
630
+ // single clearest tell that a sea is a backdrop rather than something the ship is in — and it
631
+ // was, because nothing in this material knew the ship existed. This costs no geometry, no
632
+ // particles and no second pass: the surface already knows its own world position, so it can be
633
+ // told where the ship is and work out whether it is standing in its wake.
634
+ //
635
+ // Everything is in the ship's frame. `astern` is metres behind it and `across` is metres off its
636
+ // centreline, so the wedge is a comparison rather than a rotation.
637
+ const toShip = vec2(positionWorld.x.sub(shipOrigin.x), positionWorld.z.sub(shipOrigin.y));
638
+ const starboardAxis = vec2(shipForward.y.negate(), shipForward.x);
639
+ const astern = dot(toShip, shipForward).negate();
640
+ const across = abs(dot(toShip, starboardAxis));
641
+ // A Kelvin wedge, and it needs both of its parts.
642
+ //
643
+ // Filling the wedge evenly gives a soft triangle that reads as haze on the water. What a wake
644
+ // actually looks like from astern is a churned band directly behind the transom with two bright
645
+ // arms running out from it at the edges of the wedge, and the arms are the half of it the eye
646
+ // recognises: they are the only straight lines in a scene made entirely of swell.
647
+ const halfWidth = astern.mul(WAKE.spread).add(WAKE.waist);
648
+ const churn = smoothstep(halfWidth.mul(0.62), halfWidth.mul(0.12), across).mul(0.6);
649
+ const arms = smoothstep(halfWidth.mul(0.5), float(0), abs(across.sub(halfWidth)));
650
+ const reach = smoothstep(float(WAKE.length), float(0), astern);
651
+ const begins = smoothstep(float(-1.4), float(1.6), astern);
652
+ // Never quite to full foam. At 1.0 the arms are the brightest thing in the frame and read as two
653
+ // searchlights laid on the sea rather than as broken water.
654
+ //
655
+ // Torn by the same grain as the whitecaps, and this is the term that has to have it. `arms` is
656
+ // the only straight line in a scene made entirely of swell, so an untiled one is read as a line
657
+ // somebody drew: the frame came back with a hard white U running from under the stern to the
658
+ // bottom edge, off a hull making no way at all.
659
+ const wake = max(churn, arms).mul(reach).mul(begins).mul(wakeStrength).mul(torn).mul(0.78);
660
+ // The wash at the hull's own waterline: an ellipse in the ship's plan, and a band just outside
661
+ // it. Cheaper than the wake and it is the half the player is closest to — without it the hull
662
+ // meets the sea on a clean line, and a clean line is the tell that nothing here is water.
663
+ const plan = vec2(astern.div(HULL_WASH.halfLength), across.div(HULL_WASH.halfBeam));
664
+ //
665
+ // **Gated on way on**, which it was not, and that was the other half of the U. A hull lying to
666
+ // is not working water against its own topsides — it is sitting in it — and the lie this told
667
+ // was a bright unbroken annulus around a stationary ship, which the eye reads as a decal rather
668
+ // than as a wake no matter how well it is torn. Under way it is a ring of broken water at the
669
+ // waterline; at rest there is nothing, and the hull sits in a swell like anything else.
670
+ //
671
+ // The band is a quarter as wide as the ellipse's own radius and the edges are soft, because a
672
+ // narrow hard ring at this distance photographs as a drawn circle however broken its fill is.
673
+ const wash = smoothstep(float(1.34), float(0.94), plan.length()).mul(
674
+ smoothstep(float(0.62), float(0.94), plan.length()),
675
+ );
676
+ // Plus a little standing white at the bow, where the stem pushes a bow wave ahead of it.
677
+ //
678
+ // Bounded ahead as well: `smoothstep` with its edges reversed clamps to 1 on the far side, so
679
+ // without the second ramp this was a strip of foam from the stem to the horizon.
680
+ const bow = smoothstep(float(-1.4), float(-2.5), astern)
681
+ .mul(smoothstep(float(-5), float(-3.5), astern))
682
+ .mul(smoothstep(float(1.3), float(0.2), across))
683
+ .mul(wakeStrength)
684
+ .mul(torn);
685
+ const broken = max(max(wake, bow), wash.mul(torn).mul(wakeStrength));
686
+ material.colorNode = cheap
687
+ ? water
688
+ : mix(water.add(color(SUBSURFACE).mul(through)), color(FOAM), max(crest, broken));
689
+
690
+ // The one thing the prefiltered environment cannot do: the hull, the marks and the headland, in
691
+ // the water, sharp.
692
+ //
693
+ // Fresnel is the term that decides how much. The sky's own reflection is already handled above by
694
+ // the material's image-based specular, which applies the same Schlick curve on its own; this
695
+ // applies the same one to the mirror, so the two agree at the horizon and the silhouettes fade
696
+ // out as the eye comes down onto the water.
697
+ if (!cheap)
698
+ material.emissiveNode = Fn(() => {
699
+ // The interpolated vertex normal, which is the swell, plus this fragment's own ripple. Adding
700
+ // the ripple here rather than in the vertex stage is what makes it affordable: the swell's
701
+ // central difference is four cascade reads, and doing that per *fragment* on a full-screen sea
702
+ // cost sixteen texture fetches a pixel to arrive at a vector the vertex stage had already
703
+ // computed. The ripple is a texture read either way, and per fragment is finer, which is the
704
+ // whole point of a normal map.
705
+ const normal = normalWorld
706
+ .add(vec3(rippleSlope(ripples, seaTime, detail).mul(-0.47).mul(detail), 0))
707
+ .normalize();
708
+ const facing = saturate(dot(normal, eye.normalize()));
709
+ // Exponent five is water's own Schlick curve, and the 0.97963/0.02037 pair is its reflectance
710
+ // at the horizon and at normal incidence.
711
+ const fresnel = pow(oneMinus(facing), float(5)).mul(0.97963).add(0.02037);
712
+ // The normal's own slope is the offset: it is the same slope that is bending the light, so the
713
+ // mirror wobbles with the wave it is standing on.
714
+ const reflected = mirror.reflectionAt(normal.xz.mul(0.02)).mul(MIRROR_GAIN);
715
+ // Rough water does not mirror at grazing angles the way a flat facet does: the microfacets that
716
+ // survive are not aligned with the view, so reflectance falls off with roughness.
717
+ const rough = max(crest, broken);
718
+ return reflected.mul(fresnel).mul(oneMinus(max(subpixel, rough).mul(0.75)));
719
+ })();
720
+ // Roughness is spent, not lost: the slope a distant pixel can no longer resolve reappears here.
721
+ //
722
+ // This is now the term that decides the whole look, because it is what the prefiltered sky is
723
+ // sampled at. A sea at 0.13 returns a sharp horizon and a broken cloud; at 0.5 it returns a broad
724
+ // luminous sheet, which is a mirror again. **Sharp is the word that matters here**: a rough
725
+ // surface *averages* the sky over a wide cone, so every facet returns nearly the same pale value
726
+ // and the wave shape disappears into a field of ice — which is exactly what the first two frames
727
+ // looked like. A sharp one returns a different piece of sky per facet and the shape comes back.
728
+ // Near the ship the ripple normals carry the detail, and past the point where a pixel can no
729
+ // longer resolve a metre of wave the roughness takes over and the middle distance turns into the
730
+ // soft band a real sea shows. Broken water is not a mirror either, and roughening it is what
731
+ // stops the foam reading as chrome.
732
+ if (!cheap)
733
+ material.roughnessNode = max(float(0.13).add(subpixel.mul(0.3)), max(crest, broken).mul(0.9));
173
734
 
174
735
  const mesh = new Mesh(geometry, material);
175
736
  mesh.receiveShadow = true;
176
737
  mesh.frustumCulled = false;
177
738
  mesh.name = "sea-surface";
178
- return mesh;
739
+
740
+ // Snapped, because following continuously would slide every vertex through the wave field by a
741
+ // fraction of its size every frame and the surface would visibly crawl. A whole-metre step is
742
+ // coarse enough to stop the crawl and fine enough that the snap itself cannot be seen.
743
+ return {
744
+ mesh,
745
+ advance(elapsed: number): void {
746
+ seaTime.value = elapsed;
747
+ },
748
+ wake(x: number, z: number, forwardX: number, forwardZ: number, strength: number): void {
749
+ shipOrigin.value.set(x, z);
750
+ shipForward.value.set(forwardX, forwardZ);
751
+ wakeStrength.value = Math.max(0, Math.min(1, strength));
752
+ },
753
+ follow(x: number, z: number): void {
754
+ const snappedX = Math.round(x);
755
+ const snappedZ = Math.round(z);
756
+ mesh.position.set(snappedX, 0, snappedZ);
757
+ seaOrigin.value.set(snappedX, snappedZ);
758
+ },
759
+ dispose(): void {
760
+ mirror.dispose();
761
+ ripples.dispose();
762
+ geometry.dispose();
763
+ material.dispose();
764
+ },
765
+ };
179
766
  }