create-threenative 0.2.3 → 0.2.4

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 (447) hide show
  1. package/README.md +53 -2
  2. package/agent-docs/references/assertion-reference.md +173 -6
  3. package/agent-docs/references/capability-reference.md +1303 -99
  4. package/agent-docs/references/capture-the-frame.md +7 -0
  5. package/agent-docs/references/creating-creatures.md +215 -0
  6. package/agent-docs/references/ctx-cookbook.md +69 -0
  7. package/agent-docs/references/debug-surface.md +8 -3
  8. package/agent-docs/references/dream-loop.md +150 -0
  9. package/agent-docs/references/finding-assets.md +70 -2
  10. package/agent-docs/references/sculpt-from-a-reference.md +3 -2
  11. package/agent-docs/references/trace-a-slow-frame.md +99 -0
  12. package/agent-docs/references/visual-baseline.md +41 -0
  13. package/agent-files/.agents/skills/file-engine-bug/SKILL.md +59 -0
  14. package/agent-files/.agents/skills/prd-creator/SKILL.md +40 -0
  15. package/agent-files/.agents/skills/threenative-assets/SKILL.md +45 -0
  16. package/agent-files/.agents/skills/threenative-builder/SKILL.md +1 -1
  17. package/agent-files/.agents/skills/threenative-capabilities/SKILL.md +27 -0
  18. package/agent-files/.agents/skills/threenative-context/SKILL.md +57 -0
  19. package/agent-files/.agents/skills/threenative-performance/SKILL.md +42 -0
  20. package/agent-files/.agents/skills/threenative-playtest/SKILL.md +44 -0
  21. package/agent-files/.agents/skills/threenative-ui/SKILL.md +20 -0
  22. package/agent-files/.agents/skills/threenative-verifier/SKILL.md +1 -1
  23. package/agent-files/.agents/skills/threenative-visuals/SKILL.md +41 -0
  24. package/agent-files/.claude/skills/file-engine-bug/SKILL.md +59 -0
  25. package/agent-files/.claude/skills/prd-creator/SKILL.md +40 -0
  26. package/agent-files/.claude/skills/threenative-assets/SKILL.md +45 -0
  27. package/agent-files/.claude/skills/threenative-capabilities/SKILL.md +27 -0
  28. package/agent-files/.claude/skills/threenative-context/SKILL.md +57 -0
  29. package/agent-files/.claude/skills/threenative-performance/SKILL.md +42 -0
  30. package/agent-files/.claude/skills/threenative-playtest/SKILL.md +44 -0
  31. package/agent-files/.claude/skills/threenative-ui/SKILL.md +20 -0
  32. package/agent-files/.claude/skills/threenative-visuals/SKILL.md +41 -0
  33. package/agent-files/scripts/reference.mjs +705 -0
  34. package/agent-files/scripts/visual-loop.mjs +382 -0
  35. package/capabilities.json +1881 -131
  36. package/dist/index.d.ts +39 -6
  37. package/dist/index.js +297 -32
  38. package/dist/threenative.js +822 -105
  39. package/package.json +30 -5
  40. package/template-assets/loading.ts +12 -2
  41. package/template-assets/patches/three@0.185.1.patch +249 -14
  42. package/template-assets/worldEnvironment.ts +758 -0
  43. package/templates/action-rpg/.codex/config.toml +4 -0
  44. package/templates/action-rpg/.cursor/mcp.json +32 -0
  45. package/templates/action-rpg/.gemini/settings.json +32 -0
  46. package/templates/action-rpg/.mcp.json +15 -3
  47. package/templates/action-rpg/.vscode/mcp.json +36 -0
  48. package/templates/action-rpg/.zed/settings.json +36 -0
  49. package/templates/action-rpg/AGENTS.md +69 -378
  50. package/templates/action-rpg/CLAUDE.md +69 -378
  51. package/templates/action-rpg/opencode.json +41 -0
  52. package/templates/action-rpg/package.json +7 -7
  53. package/templates/action-rpg/playtests/combat.playtest.json +9 -0
  54. package/templates/action-rpg/playtests/performance.playtest.json +24 -7
  55. package/templates/action-rpg/playtests/survives.playtest.json +27 -0
  56. package/templates/action-rpg/playtests/touch-controls.playtest.json +42 -0
  57. package/templates/action-rpg/src/conventions.ts +35 -0
  58. package/templates/action-rpg/src/entities/Enemy.ts +2 -3
  59. package/templates/action-rpg/src/entities/Player.ts +20 -3
  60. package/templates/action-rpg/src/render/camera.ts +7 -2
  61. package/templates/action-rpg/src/render/lighting.ts +5 -3
  62. package/templates/action-rpg/src/render/loading.ts +12 -2
  63. package/templates/action-rpg/src/render/materials.ts +11 -0
  64. package/templates/action-rpg/src/render/palette.ts +10 -3
  65. package/templates/action-rpg/src/render/postprocessing.ts +21 -58
  66. package/templates/action-rpg/src/render/quality.ts +170 -0
  67. package/templates/action-rpg/src/render/shapes.ts +185 -26
  68. package/templates/action-rpg/src/render/touch-controls.ts +185 -0
  69. package/templates/action-rpg/src/render/vfx.ts +257 -0
  70. package/templates/action-rpg/src/render/worldEnvironment.ts +208 -33
  71. package/templates/action-rpg/src/scenes/Play.ts +43 -6
  72. package/templates/action-rpg/src/style.css +20 -0
  73. package/templates/action-rpg/threenative.config.ts +7 -0
  74. package/templates/defense/.codex/config.toml +4 -0
  75. package/templates/defense/.cursor/mcp.json +32 -0
  76. package/templates/defense/.gemini/settings.json +32 -0
  77. package/templates/defense/.mcp.json +15 -3
  78. package/templates/defense/.vscode/mcp.json +36 -0
  79. package/templates/defense/.zed/settings.json +36 -0
  80. package/templates/defense/AGENTS.md +62 -385
  81. package/templates/defense/CLAUDE.md +62 -385
  82. package/templates/defense/opencode.json +41 -0
  83. package/templates/defense/package.json +7 -7
  84. package/templates/defense/playtests/performance.playtest.json +24 -7
  85. package/templates/defense/playtests/pointer-placement.playtest.json +87 -20
  86. package/templates/defense/playtests/scan.playtest.json +1 -1
  87. package/templates/defense/playtests/survive.playtest.json +14 -0
  88. package/templates/defense/src/attackers/Attacker.ts +4 -4
  89. package/templates/defense/src/board/Route.ts +22 -8
  90. package/templates/defense/src/conventions.ts +18 -0
  91. package/templates/defense/src/entities/Player.ts +11 -3
  92. package/templates/defense/src/game.ts +2 -3
  93. package/templates/defense/src/physics.ts +9 -39
  94. package/templates/defense/src/placement/Buildable.ts +4 -4
  95. package/templates/defense/src/render/camera.ts +9 -3
  96. package/templates/defense/src/render/loading.ts +12 -2
  97. package/templates/defense/src/render/materials.ts +9 -0
  98. package/templates/defense/src/render/palette.ts +12 -5
  99. package/templates/defense/src/render/postprocessing.ts +21 -58
  100. package/templates/defense/src/render/quality.ts +170 -0
  101. package/templates/defense/src/render/shapes.ts +142 -23
  102. package/templates/defense/src/render/sky.ts +2 -2
  103. package/templates/defense/src/render/worldEnvironment.ts +208 -33
  104. package/templates/defense/src/scenes/Boot.ts +2 -2
  105. package/templates/defense/src/scenes/Defense.ts +13 -6
  106. package/templates/defense/src/style.css +20 -0
  107. package/templates/defense/src/towers/Tower.ts +11 -12
  108. package/templates/defense/src/towers/targeting.ts +1 -1
  109. package/templates/defense/src/ui/App.tsx +2 -2
  110. package/templates/defense/threenative.config.ts +7 -0
  111. package/templates/minimal/.codex/config.toml +4 -0
  112. package/templates/minimal/.cursor/mcp.json +32 -0
  113. package/templates/minimal/.gemini/settings.json +32 -0
  114. package/templates/minimal/.mcp.json +15 -3
  115. package/templates/minimal/.vscode/mcp.json +36 -0
  116. package/templates/minimal/.zed/settings.json +36 -0
  117. package/templates/minimal/AGENTS.md +76 -485
  118. package/templates/minimal/CLAUDE.md +76 -485
  119. package/templates/minimal/opencode.json +41 -0
  120. package/templates/minimal/package.json +6 -6
  121. package/templates/minimal/playtests/play.playtest.json +2 -1
  122. package/templates/minimal/playtests/survives.playtest.json +48 -4
  123. package/templates/minimal/playtests/touch-controls.playtest.json +42 -0
  124. package/templates/minimal/src/conventions.ts +18 -0
  125. package/templates/minimal/src/entities/Player.ts +39 -6
  126. package/templates/minimal/src/main.ts +14 -4
  127. package/templates/minimal/src/render/materials.ts +7 -0
  128. package/templates/minimal/src/render/palette.ts +3 -3
  129. package/templates/minimal/src/render/postprocessing.ts +17 -56
  130. package/templates/minimal/src/render/quality.ts +162 -0
  131. package/templates/minimal/src/render/sky.ts +23 -9
  132. package/templates/minimal/src/render/touch-controls.ts +165 -0
  133. package/templates/minimal/src/render/worldEnvironment.ts +208 -33
  134. package/templates/minimal/src/scenes/Play.ts +47 -11
  135. package/templates/minimal/src/style.css +20 -0
  136. package/templates/minimal/threenative.config.ts +7 -0
  137. package/templates/platformer/.codex/config.toml +4 -0
  138. package/templates/platformer/.cursor/mcp.json +32 -0
  139. package/templates/platformer/.gemini/settings.json +32 -0
  140. package/templates/platformer/.mcp.json +15 -3
  141. package/templates/platformer/.vscode/mcp.json +36 -0
  142. package/templates/platformer/.zed/settings.json +36 -0
  143. package/templates/platformer/AGENTS.md +70 -430
  144. package/templates/platformer/CLAUDE.md +70 -430
  145. package/templates/platformer/opencode.json +41 -0
  146. package/templates/platformer/package.json +7 -7
  147. package/templates/platformer/playtests/oneway.playtest.json +29 -2
  148. package/templates/platformer/playtests/performance.playtest.json +2 -1
  149. package/templates/platformer/playtests/survives.playtest.json +31 -0
  150. package/templates/platformer/playtests/terminal-loop-fail.playtest.json +3 -0
  151. package/templates/platformer/playtests/touch-controls-web.playtest.json +15 -4
  152. package/templates/platformer/src/conventions.ts +18 -0
  153. package/templates/platformer/src/entities/Character.ts +63 -1
  154. package/templates/platformer/src/game.ts +3 -1
  155. package/templates/platformer/src/level/Platform.ts +13 -1
  156. package/templates/platformer/src/render/lighting.ts +7 -4
  157. package/templates/platformer/src/render/loading.ts +12 -2
  158. package/templates/platformer/src/render/palette.ts +4 -1
  159. package/templates/platformer/src/render/postprocessing.ts +32 -57
  160. package/templates/platformer/src/render/quality.ts +170 -0
  161. package/templates/platformer/src/render/worldEnvironment.ts +208 -33
  162. package/templates/platformer/src/scenes/Level.ts +52 -12
  163. package/templates/platformer/src/style.css +20 -0
  164. package/templates/platformer/threenative.config.ts +7 -0
  165. package/templates/puzzle/.codex/config.toml +19 -0
  166. package/templates/puzzle/.cursor/mcp.json +32 -0
  167. package/templates/puzzle/.gemini/settings.json +32 -0
  168. package/templates/puzzle/.mcp.json +32 -0
  169. package/templates/puzzle/.vscode/mcp.json +36 -0
  170. package/templates/puzzle/.zed/settings.json +36 -0
  171. package/templates/puzzle/AGENTS.md +96 -0
  172. package/templates/puzzle/CLAUDE.md +98 -0
  173. package/templates/puzzle/README.md +43 -0
  174. package/templates/puzzle/index.html +12 -0
  175. package/templates/puzzle/kit.json +7 -0
  176. package/templates/puzzle/opencode.json +41 -0
  177. package/templates/puzzle/package.json +50 -0
  178. package/templates/puzzle/playtests/carry.playtest.json +71 -0
  179. package/templates/puzzle/playtests/performance.playtest.json +23 -0
  180. package/templates/puzzle/playtests/survives.playtest.json +51 -0
  181. package/templates/puzzle/playtests/swing.playtest.json +38 -0
  182. package/templates/puzzle/public/favicon.svg +5 -0
  183. package/templates/puzzle/src/conventions.ts +25 -0
  184. package/templates/puzzle/src/entities/Ball.ts +70 -0
  185. package/templates/puzzle/src/entities/Crate.ts +76 -0
  186. package/templates/puzzle/src/entities/Gripper.ts +69 -0
  187. package/templates/puzzle/src/entities/Pendulum.ts +89 -0
  188. package/templates/puzzle/src/game.ts +48 -0
  189. package/templates/puzzle/src/main.ts +15 -0
  190. package/templates/puzzle/src/physics.ts +19 -0
  191. package/templates/puzzle/src/render/camera.ts +37 -0
  192. package/templates/puzzle/src/render/lighting.ts +55 -0
  193. package/templates/puzzle/src/render/loading.ts +325 -0
  194. package/templates/puzzle/src/render/materials.ts +28 -0
  195. package/templates/puzzle/src/render/palette.ts +31 -0
  196. package/templates/puzzle/src/render/postprocessing.ts +34 -0
  197. package/templates/puzzle/src/render/quality.ts +170 -0
  198. package/templates/puzzle/src/render/shapes.ts +134 -0
  199. package/templates/puzzle/src/render/sky.ts +16 -0
  200. package/templates/puzzle/src/render/touch-controls.ts +185 -0
  201. package/templates/puzzle/src/render/worldEnvironment.ts +758 -0
  202. package/templates/puzzle/src/room.ts +83 -0
  203. package/templates/puzzle/src/scenes/Boot.ts +12 -0
  204. package/templates/puzzle/src/scenes/Puzzle.ts +158 -0
  205. package/templates/puzzle/src/state.ts +30 -0
  206. package/templates/puzzle/src/style.css +96 -0
  207. package/templates/puzzle/src/ui/App.tsx +22 -0
  208. package/templates/puzzle/src/ui/GameUi.tsx +20 -0
  209. package/templates/puzzle/src/ui/Hud.tsx +57 -0
  210. package/templates/puzzle/src/ui/Menu.tsx +7 -0
  211. package/templates/puzzle/src/ui/main.tsx +14 -0
  212. package/templates/puzzle/tailwind.config.ts +1 -0
  213. package/templates/puzzle/threenative.config.ts +49 -0
  214. package/templates/puzzle/tsconfig.json +17 -0
  215. package/templates/puzzle/vite.config.ts +38 -0
  216. package/templates/racing/.codex/config.toml +4 -0
  217. package/templates/racing/.cursor/mcp.json +32 -0
  218. package/templates/racing/.gemini/settings.json +32 -0
  219. package/templates/racing/.mcp.json +15 -3
  220. package/templates/racing/.vscode/mcp.json +36 -0
  221. package/templates/racing/.zed/settings.json +36 -0
  222. package/templates/racing/AGENTS.md +63 -379
  223. package/templates/racing/CLAUDE.md +63 -379
  224. package/templates/racing/native-playtests/survives.playtest.json +43 -0
  225. package/templates/racing/opencode.json +41 -0
  226. package/templates/racing/package.json +8 -7
  227. package/templates/racing/playtests/performance.playtest.json +24 -7
  228. package/templates/racing/playtests/survives.playtest.json +36 -4
  229. package/templates/racing/playtests/touch-controls.playtest.json +41 -0
  230. package/templates/racing/src/conventions.ts +6 -0
  231. package/templates/racing/src/entities/RacingCar.ts +16 -4
  232. package/templates/racing/src/entities/Rival.ts +5 -2
  233. package/templates/racing/src/render/camera.ts +7 -4
  234. package/templates/racing/src/render/lighting.ts +22 -13
  235. package/templates/racing/src/render/loading.ts +12 -2
  236. package/templates/racing/src/render/materials.ts +54 -4
  237. package/templates/racing/src/render/palette.ts +23 -6
  238. package/templates/racing/src/render/postprocessing.ts +21 -58
  239. package/templates/racing/src/render/quality.ts +170 -0
  240. package/templates/racing/src/render/shapes.ts +537 -26
  241. package/templates/racing/src/render/sky.ts +5 -2
  242. package/templates/racing/src/render/touch-controls.ts +185 -0
  243. package/templates/racing/src/render/worldEnvironment.ts +208 -33
  244. package/templates/racing/src/scenes/Race.ts +17 -2
  245. package/templates/racing/src/style.css +20 -0
  246. package/templates/racing/src/track/Track.ts +270 -31
  247. package/templates/racing/threenative.config.ts +7 -0
  248. package/templates/runner/.codex/config.toml +19 -0
  249. package/templates/runner/.cursor/mcp.json +32 -0
  250. package/templates/runner/.gemini/settings.json +32 -0
  251. package/templates/runner/.mcp.json +32 -0
  252. package/templates/runner/.vscode/mcp.json +36 -0
  253. package/templates/runner/.zed/settings.json +36 -0
  254. package/templates/runner/AGENTS.md +96 -0
  255. package/templates/runner/CLAUDE.md +98 -0
  256. package/templates/runner/README.md +43 -0
  257. package/templates/runner/index.html +12 -0
  258. package/templates/runner/kit.json +7 -0
  259. package/templates/runner/opencode.json +41 -0
  260. package/templates/runner/package.json +50 -0
  261. package/templates/runner/playtests/performance.playtest.json +23 -0
  262. package/templates/runner/playtests/streams.playtest.json +38 -0
  263. package/templates/runner/playtests/survives.playtest.json +51 -0
  264. package/templates/runner/public/favicon.svg +5 -0
  265. package/templates/runner/src/conventions.ts +24 -0
  266. package/templates/runner/src/entities/Runner.ts +135 -0
  267. package/templates/runner/src/game.ts +50 -0
  268. package/templates/runner/src/main.ts +15 -0
  269. package/templates/runner/src/physics.ts +13 -0
  270. package/templates/runner/src/render/camera.ts +39 -0
  271. package/templates/runner/src/render/dust.ts +131 -0
  272. package/templates/runner/src/render/lighting.ts +57 -0
  273. package/templates/runner/src/render/loading.ts +325 -0
  274. package/templates/runner/src/render/materials.ts +27 -0
  275. package/templates/runner/src/render/palette.ts +30 -0
  276. package/templates/runner/src/render/postprocessing.ts +34 -0
  277. package/templates/runner/src/render/quality.ts +170 -0
  278. package/templates/runner/src/render/shapes.ts +68 -0
  279. package/templates/runner/src/render/sky.ts +51 -0
  280. package/templates/runner/src/render/touch-controls.ts +185 -0
  281. package/templates/runner/src/render/worldEnvironment.ts +758 -0
  282. package/templates/runner/src/scenes/Boot.ts +12 -0
  283. package/templates/runner/src/scenes/Run.ts +142 -0
  284. package/templates/runner/src/state.ts +29 -0
  285. package/templates/runner/src/style.css +96 -0
  286. package/templates/runner/src/track.ts +176 -0
  287. package/templates/runner/src/ui/App.tsx +22 -0
  288. package/templates/runner/src/ui/GameUi.tsx +20 -0
  289. package/templates/runner/src/ui/Hud.tsx +55 -0
  290. package/templates/runner/src/ui/Menu.tsx +7 -0
  291. package/templates/runner/src/ui/main.tsx +14 -0
  292. package/templates/runner/tailwind.config.ts +1 -0
  293. package/templates/runner/threenative.config.ts +49 -0
  294. package/templates/runner/tsconfig.json +17 -0
  295. package/templates/runner/vite.config.ts +38 -0
  296. package/templates/sailing/.codex/config.toml +4 -0
  297. package/templates/sailing/.cursor/mcp.json +32 -0
  298. package/templates/sailing/.gemini/settings.json +32 -0
  299. package/templates/sailing/.mcp.json +15 -3
  300. package/templates/sailing/.vscode/mcp.json +36 -0
  301. package/templates/sailing/.zed/settings.json +36 -0
  302. package/templates/sailing/AGENTS.md +62 -355
  303. package/templates/sailing/CLAUDE.md +62 -355
  304. package/templates/sailing/README.md +12 -9
  305. package/templates/sailing/native-playtests/float.playtest.json +55 -0
  306. package/templates/sailing/native-playtests/survives.playtest.json +20 -3
  307. package/templates/sailing/opencode.json +41 -0
  308. package/templates/sailing/package.json +8 -8
  309. package/templates/sailing/playtests/float-after-the-run-ends.playtest.json +75 -0
  310. package/templates/sailing/playtests/float.playtest.json +59 -0
  311. package/templates/sailing/playtests/performance.playtest.json +21 -6
  312. package/templates/sailing/playtests/survives.playtest.json +8 -0
  313. package/templates/sailing/playtests/touch-controls.playtest.json +48 -0
  314. package/templates/sailing/src/conventions.ts +8 -0
  315. package/templates/sailing/src/entities/Ship.ts +150 -13
  316. package/templates/sailing/src/render/camera.ts +15 -8
  317. package/templates/sailing/src/render/lighting.ts +10 -5
  318. package/templates/sailing/src/render/loading.ts +12 -2
  319. package/templates/sailing/src/render/materials.ts +24 -8
  320. package/templates/sailing/src/render/ocean.ts +179 -0
  321. package/templates/sailing/src/render/palette.ts +14 -21
  322. package/templates/sailing/src/render/postprocessing.ts +23 -22
  323. package/templates/sailing/src/render/props.ts +584 -34
  324. package/templates/sailing/src/render/quality.ts +140 -0
  325. package/templates/sailing/src/render/sky.ts +8 -3
  326. package/templates/sailing/src/render/touch-controls.ts +142 -0
  327. package/templates/sailing/src/render/worldEnvironment.ts +206 -38
  328. package/templates/sailing/src/scenes/Sailing.ts +43 -16
  329. package/templates/sailing/src/style.css +20 -0
  330. package/templates/sailing/threenative.config.ts +7 -1
  331. package/templates/shooter/.codex/config.toml +4 -0
  332. package/templates/shooter/.cursor/mcp.json +32 -0
  333. package/templates/shooter/.gemini/settings.json +32 -0
  334. package/templates/shooter/.mcp.json +15 -3
  335. package/templates/shooter/.vscode/mcp.json +36 -0
  336. package/templates/shooter/.zed/settings.json +36 -0
  337. package/templates/shooter/AGENTS.md +76 -415
  338. package/templates/shooter/CLAUDE.md +76 -415
  339. package/templates/shooter/kit.json +2 -2
  340. package/templates/shooter/opencode.json +41 -0
  341. package/templates/shooter/package.json +7 -7
  342. package/templates/shooter/playtests/combat.playtest.json +48 -0
  343. package/templates/shooter/playtests/input-control.playtest.json +165 -35
  344. package/templates/shooter/playtests/per-item.playtest.json +3 -3
  345. package/templates/shooter/playtests/performance.playtest.json +24 -7
  346. package/templates/shooter/playtests/shooter.playtest.json +13 -7
  347. package/templates/shooter/playtests/survives.playtest.json +27 -0
  348. package/templates/shooter/playtests/touch-controls.playtest.json +42 -0
  349. package/templates/shooter/playtests/weapon-cycle.playtest.json +164 -0
  350. package/templates/shooter/src/combat/damage.ts +1 -2
  351. package/templates/shooter/src/conventions.ts +51 -0
  352. package/templates/shooter/src/entities/Player.ts +235 -18
  353. package/templates/shooter/src/entities/Target.ts +2 -2
  354. package/templates/shooter/src/game.ts +13 -4
  355. package/templates/shooter/src/render/camera.ts +49 -39
  356. package/templates/shooter/src/render/decals.ts +211 -0
  357. package/templates/shooter/src/render/lighting.ts +7 -3
  358. package/templates/shooter/src/render/loading.ts +12 -2
  359. package/templates/shooter/src/render/materials.ts +56 -3
  360. package/templates/shooter/src/render/palette.ts +6 -3
  361. package/templates/shooter/src/render/postprocessing.ts +21 -58
  362. package/templates/shooter/src/render/quality.ts +170 -0
  363. package/templates/shooter/src/render/scale.ts +22 -0
  364. package/templates/shooter/src/render/shapes.ts +343 -62
  365. package/templates/shooter/src/render/sky.ts +5 -1
  366. package/templates/shooter/src/render/touch-controls.ts +305 -0
  367. package/templates/shooter/src/render/ui.css +85 -0
  368. package/templates/shooter/src/render/ui.ts +19 -3
  369. package/templates/shooter/src/render/vfx.ts +215 -0
  370. package/templates/shooter/src/render/worldEnvironment.ts +208 -33
  371. package/templates/shooter/src/scenes/Play.ts +171 -56
  372. package/templates/shooter/src/state.ts +5 -0
  373. package/templates/shooter/src/style.css +20 -0
  374. package/templates/shooter/src/ui/Crosshair.tsx +25 -0
  375. package/templates/shooter/src/ui/GameUi.tsx +2 -0
  376. package/templates/shooter/src/ui/Hud.tsx +7 -1
  377. package/templates/shooter/src/weapons/Hitscan.ts +3 -4
  378. package/templates/shooter/src/weapons/Projectile.ts +8 -3
  379. package/templates/shooter/src/weapons/Viewmodel.ts +275 -0
  380. package/templates/shooter/threenative.config.ts +7 -0
  381. package/templates/starter/.codex/config.toml +4 -0
  382. package/templates/starter/.cursor/mcp.json +32 -0
  383. package/templates/starter/.gemini/settings.json +32 -0
  384. package/templates/starter/.mcp.json +15 -3
  385. package/templates/starter/.vscode/mcp.json +36 -0
  386. package/templates/starter/.zed/settings.json +36 -0
  387. package/templates/starter/AGENTS.md +70 -527
  388. package/templates/starter/CLAUDE.md +70 -527
  389. package/templates/starter/native-playtests/render-chain.playtest.json +73 -4
  390. package/templates/starter/opencode.json +41 -0
  391. package/templates/starter/package.json +7 -7
  392. package/templates/starter/playtests/boot-failure.playtest.json +45 -0
  393. package/templates/starter/playtests/look.playtest.json +110 -6
  394. package/templates/starter/playtests/play.playtest.json +3 -2
  395. package/templates/starter/playtests/survives.playtest.json +21 -0
  396. package/templates/starter/playtests/touch-controls.playtest.json +42 -0
  397. package/templates/starter/src/conventions.ts +18 -0
  398. package/templates/starter/src/entities/Goal.ts +18 -3
  399. package/templates/starter/src/entities/Player.ts +72 -9
  400. package/templates/starter/src/game.ts +2 -0
  401. package/templates/starter/src/render/adaptiveQuality.ts +195 -0
  402. package/templates/starter/src/render/camera.ts +1 -1
  403. package/templates/starter/src/render/coast.ts +199 -0
  404. package/templates/starter/src/render/hero.ts +88 -0
  405. package/templates/starter/src/render/implicitSurface.ts +199 -0
  406. package/templates/starter/src/render/kuwahara.ts +174 -0
  407. package/templates/starter/src/render/lighting.ts +4 -4
  408. package/templates/starter/src/render/loading.ts +12 -2
  409. package/templates/starter/src/render/materials.ts +25 -6
  410. package/templates/starter/src/render/outline.ts +141 -0
  411. package/templates/starter/src/render/painterly.ts +86 -0
  412. package/templates/starter/src/render/palette.ts +15 -6
  413. package/templates/starter/src/render/postprocessing.ts +87 -36
  414. package/templates/starter/src/render/quality.ts +185 -0
  415. package/templates/starter/src/render/rockRidge.ts +198 -0
  416. package/templates/starter/src/render/rockRidge.worker.ts +77 -0
  417. package/templates/starter/src/render/scenery.ts +16 -59
  418. package/templates/starter/src/render/textureLifetime.ts +53 -0
  419. package/templates/starter/src/render/touch-controls.ts +165 -0
  420. package/templates/starter/src/render/water.ts +38 -0
  421. package/templates/starter/src/render/watercolor.ts +85 -0
  422. package/templates/starter/src/render/worldEnvironment.ts +208 -33
  423. package/templates/starter/src/scenes/Play.ts +103 -16
  424. package/templates/starter/src/style.css +27 -7
  425. package/templates/starter/threenative.config.ts +7 -7
  426. package/agent-docs/asset-mcp-loop.md +0 -33
  427. package/agent-docs/ctx-surface.md +0 -69
  428. package/agent-docs/engine-capabilities.md +0 -4
  429. package/agent-docs/framework-blocks-you.md +0 -60
  430. package/agent-docs/look-at-it-and-budget-the-look.md +0 -27
  431. package/agent-docs/performance-default.md +0 -42
  432. package/agent-docs/pixel-budget.md +0 -20
  433. package/agent-docs/playtest-fail-closed.md +0 -23
  434. package/agent-docs/sculpt-loop.md +0 -16
  435. package/templates/action-rpg/src/physics.ts +0 -40
  436. package/templates/defense/public/icon.png +0 -0
  437. package/templates/minimal/public/icon.png +0 -0
  438. package/templates/platformer/public/icon.png +0 -0
  439. package/templates/racing/public/icon.png +0 -0
  440. package/templates/sailing/public/icon.png +0 -0
  441. package/templates/sailing/src/render/water-material.ts +0 -14
  442. package/templates/sailing/src/render/water-shaders.ts +0 -12
  443. package/templates/sailing/src/render/wave-nodes.ts +0 -10
  444. package/templates/shooter/public/icon.png +0 -0
  445. package/templates/shooter/src/physics.ts +0 -49
  446. package/templates/starter/public/icon.png +0 -0
  447. /package/{templates/action-rpg/public → template-assets}/icon.png +0 -0
@@ -1,52 +1,602 @@
1
- // Generated for you. Geometry and surface choices for the sailing kit live in this file.
2
- import { BoxGeometry, CylinderGeometry, Group, Mesh, PlaneGeometry, SphereGeometry } from "three";
1
+ // Generated for you. Geometry and surface choices for the sailing kit live in this file, and
2
+ // ThreeNative does not read it.
3
+ //
4
+ // The ship is a **lofted hull with a rig**. What used to be here was a lathe cylinder lying on its
5
+ // side, a box and one flat plane, and the first frame of the template showed a brown log with a
6
+ // sheet of paper propped against it. A hull is a series of cross-sections whose beam and rail
7
+ // height change along the keel — that is the whole idea, and `loftHull` below is nineteen lines of
8
+ // it. Every dimension is a number in `HULL_STATIONS`; every colour comes from `materials.ts`.
9
+ import {
10
+ BoxGeometry,
11
+ BufferAttribute,
12
+ BufferGeometry,
13
+ ConeGeometry,
14
+ CylinderGeometry,
15
+ Group,
16
+ type Material,
17
+ MathUtils,
18
+ Mesh,
19
+ SphereGeometry,
20
+ } from "three";
21
+ import { mergeGeometries } from "three/addons/utils/BufferGeometryUtils.js";
3
22
  import type { ISailingMaterials } from "./materials.js";
4
23
 
24
+ /**
25
+ * One cross-section of the hull, at a station along the keel.
26
+ *
27
+ * `tumblehome` below 1 draws the section in above the widest point, so the deck is narrower than
28
+ * the beam. It is a small number with a large effect: at 1 the hull is a tub, and no amount of rig
29
+ * on top of a tub reads as a ship.
30
+ */
31
+ interface IHullStation {
32
+ readonly halfBeam: number;
33
+ readonly keel: number;
34
+ readonly rail: number;
35
+ readonly tumblehome: number;
36
+ readonly z: number;
37
+ }
38
+
39
+ /** Ring resolution. Half the points draw the deck line, half draw the submerged section. */
40
+ const RING_SEGMENTS = 22;
41
+
42
+ /**
43
+ * One point on a station's section, going clockwise from the starboard rail.
44
+ *
45
+ * The first half of the ring is the **deck line**: a straight run at rail height from starboard to
46
+ * port. The second half is the hull proper, bulging to its full beam a little below the rail and
47
+ * drawing in to the keel. Parameterised as one smooth loop instead — which is what this was — the
48
+ * section closes to a point at the top as well as the bottom, and the hull comes out as a
49
+ * symmetrical almond with a ridge down the middle. It photographed exactly like that: a wooden
50
+ * lens floating on its side with the rig apparently pointing sideways out of it.
51
+ */
52
+ function ringPoint(station: IHullStation, index: number): [number, number, number] {
53
+ const deckHalf = station.halfBeam * station.tumblehome;
54
+ const t = index / RING_SEGMENTS;
55
+ if (t < 0.5) {
56
+ const u = t / 0.5;
57
+ return [(1 - 2 * u) * deckHalf, station.rail, station.z];
58
+ }
59
+ const u = (t - 0.5) / 0.5;
60
+ const angle = Math.PI * u;
61
+ const across = -Math.cos(angle);
62
+ // `depth` in [0, 1]: 0 at the rail, 1 at the keel. The 1.5 power holds the section full for
63
+ // most of the draught and turns it into a V only near the keel.
64
+ const depth = Math.sin(angle) ** 1.5;
65
+ // 0.55 keeps the topsides fairly upright rather than rounding them off into a barrel.
66
+ const spread = Math.sign(across) * Math.abs(across) ** 0.55;
67
+ // Tumblehome applies only in the top third; below that the section carries its full beam.
68
+ const width = depth < 0.3 ? MathUtils.lerp(station.tumblehome, 1, depth / 0.3) : 1;
69
+ return [
70
+ spread * station.halfBeam * width,
71
+ station.rail - depth * (station.rail - station.keel),
72
+ station.z,
73
+ ];
74
+ }
75
+
76
+ /**
77
+ * Stitch the stations into a closed hull, capped at both ends.
78
+ *
79
+ * Stations are sorted by z first: the winding that makes a face point outwards depends on the sign
80
+ * of the step along the keel, so a list authored bow-first would build the whole hull inside-out
81
+ * and backface culling would then show its interior.
82
+ */
83
+ function loftHull(input: readonly IHullStation[]): BufferGeometry {
84
+ const stations = [...input].sort((a, b) => a.z - b.z);
85
+ const positions: number[] = [];
86
+ const push = (point: readonly [number, number, number]): void => {
87
+ positions.push(point[0], point[1], point[2]);
88
+ };
89
+ for (let s = 0; s < stations.length - 1; s += 1) {
90
+ const near = stations[s];
91
+ const far = stations[s + 1];
92
+ if (near === undefined || far === undefined) continue;
93
+ for (let i = 0; i < RING_SEGMENTS; i += 1) {
94
+ const next = (i + 1) % RING_SEGMENTS;
95
+ const a = ringPoint(near, i);
96
+ const b = ringPoint(far, i);
97
+ const c = ringPoint(far, next);
98
+ const d = ringPoint(near, next);
99
+ push(a);
100
+ push(c);
101
+ push(b);
102
+ push(a);
103
+ push(d);
104
+ push(c);
105
+ }
106
+ }
107
+ const cap = (station: IHullStation, forwards: boolean): void => {
108
+ const centre: [number, number, number] = [0, (station.rail + station.keel) / 2, station.z];
109
+ for (let i = 0; i < RING_SEGMENTS; i += 1) {
110
+ const next = (i + 1) % RING_SEGMENTS;
111
+ push(centre);
112
+ push(ringPoint(station, forwards ? next : i));
113
+ push(ringPoint(station, forwards ? i : next));
114
+ }
115
+ };
116
+ const first = stations[0];
117
+ const last = stations[stations.length - 1];
118
+ if (first !== undefined) cap(first, false);
119
+ if (last !== undefined) cap(last, true);
120
+ const geometry = new BufferGeometry();
121
+ geometry.setAttribute("position", new BufferAttribute(new Float32Array(positions), 3));
122
+ geometry.computeVertexNormals();
123
+ return geometry;
124
+ }
125
+
126
+ /**
127
+ * Bow at -Z, stern at +Z, y = 0 at the design waterline.
128
+ *
129
+ * **Freeboard is the number that matters here.** The rails used to sit 0.46 above the waterline
130
+ * against a 0.66 draught, which after normalising to the template's 4.6 m convention is 29 cm of
131
+ * hull showing and 41 cm submerged — the ship photographed as though it were sinking, decks awash,
132
+ * and no amount of buoyancy tuning could raise it because the hull genuinely was that shape. The
133
+ * rails now stand about twice the draught, which is what a caravel looks like.
134
+ *
135
+ * The waterline matters beyond looks: `Ship.ts` writes `Buoyancy3D` hull points against this
136
+ * origin, so moving y = 0 here silently changes how the ship floats.
137
+ *
138
+ * Read down `rail` and the sheer is visible — high at both ends, lowest in the waist. Read down
139
+ * `halfBeam` and so is the plan: a fine entry, full amidships, drawn in to a narrow transom.
140
+ */
141
+ const HULL_STATIONS: readonly IHullStation[] = [
142
+ { halfBeam: 0.1, keel: -0.4, rail: 1.16, tumblehome: 0.95, z: -3.2 },
143
+ { halfBeam: 0.34, keel: -0.56, rail: 1.02, tumblehome: 0.88, z: -2.6 },
144
+ { halfBeam: 0.66, keel: -0.66, rail: 0.89, tumblehome: 0.84, z: -1.8 },
145
+ { halfBeam: 0.86, keel: -0.72, rail: 0.82, tumblehome: 0.82, z: -0.8 },
146
+ { halfBeam: 0.94, keel: -0.73, rail: 0.8, tumblehome: 0.82, z: 0.2 },
147
+ { halfBeam: 0.91, keel: -0.7, rail: 0.84, tumblehome: 0.83, z: 1.2 },
148
+ { halfBeam: 0.78, keel: -0.61, rail: 1, tumblehome: 0.85, z: 2.1 },
149
+ { halfBeam: 0.62, keel: -0.5, rail: 1.18, tumblehome: 0.9, z: 2.8 },
150
+ { halfBeam: 0.5, keel: -0.36, rail: 1.24, tumblehome: 0.96, z: 3.2 },
151
+ ];
152
+
153
+ /** Rail height at a station, for hanging the wale and the gunwale on the same curve. */
154
+ function railAt(z: number): number {
155
+ let previous = HULL_STATIONS[0];
156
+ if (previous === undefined) return 0.5;
157
+ for (const station of HULL_STATIONS) {
158
+ if (station.z >= z) {
159
+ const span = station.z - previous.z;
160
+ const t = span === 0 ? 0 : (z - previous.z) / span;
161
+ return MathUtils.lerp(previous.rail, station.rail, t);
162
+ }
163
+ previous = station;
164
+ }
165
+ return previous.rail;
166
+ }
167
+
168
+ function halfBeamAt(z: number): number {
169
+ let previous = HULL_STATIONS[0];
170
+ if (previous === undefined) return 0.5;
171
+ for (const station of HULL_STATIONS) {
172
+ if (station.z >= z) {
173
+ const span = station.z - previous.z;
174
+ const t = span === 0 ? 0 : (z - previous.z) / span;
175
+ return MathUtils.lerp(previous.halfBeam, station.halfBeam, t);
176
+ }
177
+ previous = station;
178
+ }
179
+ return previous.halfBeam;
180
+ }
181
+
182
+ /**
183
+ * A sail with a belly in it.
184
+ *
185
+ * A `PlaneGeometry` is the wrong shape for canvas under load and it shows: flat, it catches the
186
+ * key light as one even value and reads as card. Bulging the grid on its own normal gives the
187
+ * gradient across the cloth that says "this is full of wind", and it is one `sin` per axis.
188
+ */
189
+ function belliedSail(width: number, height: number, belly: number, taper = 1): BufferGeometry {
190
+ const columns = 8;
191
+ const rows = 6;
192
+ const positions: number[] = [];
193
+ const at = (u: number, v: number): [number, number, number] => {
194
+ // `taper` narrows the head, which is the difference between a square course and a lateen.
195
+ const spread = MathUtils.lerp(1, taper, v);
196
+ return [
197
+ (u - 0.5) * width * spread,
198
+ (v - 0.5) * height,
199
+ Math.sin(Math.PI * u) * Math.sin(Math.PI * v) * belly,
200
+ ];
201
+ };
202
+ for (let row = 0; row < rows; row += 1) {
203
+ for (let column = 0; column < columns; column += 1) {
204
+ const u0 = column / columns;
205
+ const u1 = (column + 1) / columns;
206
+ const v0 = row / rows;
207
+ const v1 = (row + 1) / rows;
208
+ const a = at(u0, v0);
209
+ const b = at(u1, v0);
210
+ const c = at(u1, v1);
211
+ const d = at(u0, v1);
212
+ positions.push(...a, ...b, ...c, ...a, ...c, ...d);
213
+ }
214
+ }
215
+ const geometry = new BufferGeometry();
216
+ geometry.setAttribute("position", new BufferAttribute(new Float32Array(positions), 3));
217
+ geometry.computeVertexNormals();
218
+ return geometry;
219
+ }
220
+
221
+ function piece(geometry: BufferGeometry, material: Material, shadow = true): Mesh {
222
+ const mesh = new Mesh(geometry, material);
223
+ mesh.castShadow = shadow;
224
+ mesh.receiveShadow = shadow;
225
+ return mesh;
226
+ }
227
+
228
+ /**
229
+ * Collects rigid pieces and emits one mesh per material.
230
+ *
231
+ * A ship authored as a hundred and thirty little meshes is a hundred and thirty draw calls, and
232
+ * with the shadow pass that put the production-performance playtest at eight hundred against a
233
+ * budget of a hundred and twenty. None of the hull, rig or trim ever moves relative to the ship,
234
+ * so baking them costs nothing: the six materials stay separate and separately editable. Anything
235
+ * a game might want to animate — the sails, the pennant — is added outside this and stays its own
236
+ * transform.
237
+ */
238
+ class RigidAssembly {
239
+ readonly #byMaterial = new Map<Material, Mesh[]>();
240
+
241
+ add(mesh: Mesh): void {
242
+ const bucket = this.#byMaterial.get(mesh.material as Material);
243
+ if (bucket === undefined) this.#byMaterial.set(mesh.material as Material, [mesh]);
244
+ else bucket.push(mesh);
245
+ }
246
+
247
+ attachTo(root: Group): void {
248
+ for (const [material, meshes] of this.#byMaterial) {
249
+ const geometry = mergeGeometries(
250
+ meshes.map((mesh) => {
251
+ mesh.updateMatrix();
252
+ // `mergeGeometries` refuses a mix of indexed and non-indexed inputs, and a lofted hull is
253
+ // non-indexed while every Three.js primitive is indexed.
254
+ const placed = mesh.geometry.clone().applyMatrix4(mesh.matrix);
255
+ const cloned = placed.index === null ? placed : placed.toNonIndexed();
256
+ for (const name of Object.keys(cloned.attributes)) {
257
+ if (name !== "position") cloned.deleteAttribute(name);
258
+ }
259
+ return cloned;
260
+ }),
261
+ false,
262
+ );
263
+ if (geometry === null) throw new Error("mergeGeometries returned null for a ship part.");
264
+ geometry.computeVertexNormals();
265
+ const merged = new Mesh(geometry, material);
266
+ merged.castShadow = meshes[0]?.castShadow ?? true;
267
+ merged.receiveShadow = true;
268
+ root.add(merged);
269
+ }
270
+ }
271
+ }
272
+
273
+ /** A mast with its yard, sail, shrouds and truck. Returns the group so a game can reach the sail. */
274
+ function mast(
275
+ materials: ISailingMaterials,
276
+ rigid: RigidAssembly,
277
+ options: {
278
+ readonly height: number;
279
+ readonly sail: BufferGeometry;
280
+ readonly sailY: number;
281
+ readonly yardWidth: number;
282
+ readonly yardY: number;
283
+ readonly z: number;
284
+ },
285
+ ): Group {
286
+ const group = new Group();
287
+ const foot = railAt(options.z) - 0.1;
288
+ const pole = piece(new CylinderGeometry(0.035, 0.055, options.height, 7), materials.spar);
289
+ pole.position.set(0, foot + options.height / 2, options.z);
290
+ rigid.add(pole);
291
+
292
+ const yard = piece(new CylinderGeometry(0.03, 0.03, options.yardWidth, 6), materials.spar);
293
+ yard.rotation.z = Math.PI / 2;
294
+ yard.position.set(0, options.yardY, options.z);
295
+ rigid.add(yard);
296
+
297
+ const canvas = piece(options.sail, materials.sail, true);
298
+ canvas.position.set(0, options.sailY, options.z + 0.06);
299
+ canvas.name = "sail";
300
+ group.add(canvas);
301
+
302
+ // Shrouds: one line authored, placed to both rails. Without them the masts look stuck on.
303
+ const head = foot + options.height * 0.92;
304
+ for (const side of [-1, 1]) {
305
+ for (const aft of [-0.9, 0.9]) {
306
+ const anchorZ = options.z + aft;
307
+ const beam = halfBeamAt(anchorZ) * 0.86;
308
+ const anchorY = railAt(anchorZ);
309
+ const drop = head - anchorY;
310
+ const run = Math.hypot(side * beam, aft);
311
+ const shroud = piece(
312
+ new CylinderGeometry(0.009, 0.009, Math.hypot(drop, run), 4),
313
+ materials.cordage,
314
+ false,
315
+ );
316
+ shroud.position.set((side * beam) / 2, (head + anchorY) / 2, (options.z + anchorZ) / 2);
317
+ shroud.rotation.z = Math.atan2(side * beam, drop);
318
+ shroud.rotation.x = -Math.atan2(aft, drop);
319
+ rigid.add(shroud);
320
+ }
321
+ }
322
+ return group;
323
+ }
324
+
5
325
  export function createShipModel(materials: ISailingMaterials): Group {
6
326
  const ship = new Group();
7
- const hull = new Mesh(new CylinderGeometry(0.66, 0.52, 2.25, 12), materials.hull);
8
- hull.rotation.x = Math.PI / 2;
9
- hull.position.y = 0.02;
10
- hull.scale.z = 1.1;
11
- hull.castShadow = true;
12
-
13
- const deck = new Mesh(new BoxGeometry(1.18, 0.08, 1.65), materials.deck);
14
- deck.position.y = 0.34;
15
- deck.castShadow = true;
16
-
17
- const mast = new Mesh(new CylinderGeometry(0.045, 0.07, 2.5, 8), materials.deck);
18
- mast.position.set(0, 1.48, 0.12);
19
- mast.castShadow = true;
20
-
21
- const sail = new Mesh(new PlaneGeometry(1.55, 2.05), materials.sail);
22
- sail.position.set(0.32, 1.35, 0.08);
23
- sail.rotation.y = Math.PI / 2;
24
- sail.castShadow = true;
25
-
26
- ship.add(hull, deck, mast, sail);
327
+ const rigid = new RigidAssembly();
328
+
329
+ // blockout: the hull itself.
330
+ rigid.add(piece(loftHull(HULL_STATIONS), materials.hull));
331
+
332
+ // A planked weather deck, set below the rail so the gunwale stands proud of it.
333
+ for (let index = 0; index < 9; index += 1) {
334
+ const z = MathUtils.lerp(-2.5, 2.6, index / 8);
335
+ const plank = piece(new BoxGeometry(halfBeamAt(z) * 1.62, 0.05, 0.56), materials.deck);
336
+ plank.position.set(0, railAt(z) + 0.02, z);
337
+ rigid.add(plank);
338
+ }
339
+
340
+ // Gunwale and wale strakes, both following the sheer. Two curves, twelve boxes, and the hull
341
+ // stops being a smooth blob.
342
+ for (let index = 0; index < 24; index += 1) {
343
+ const z = MathUtils.lerp(-2.9, 3.1, index / 23);
344
+ const beam = halfBeamAt(z);
345
+ for (const side of [-1, 1]) {
346
+ const rail = piece(new BoxGeometry(0.07, 0.12, 0.3), materials.trim);
347
+ rail.position.set(side * beam * 0.9, railAt(z) + 0.05, z);
348
+ rigid.add(rail);
349
+ const wale = piece(new BoxGeometry(0.055, 0.08, 0.3), materials.trim);
350
+ wale.position.set(side * beam * 1.0, railAt(z) - 0.34, z);
351
+ rigid.add(wale);
352
+ }
353
+ }
354
+
355
+ // Sterncastle: a raised deck aft, and the things that stand on it.
356
+ //
357
+ // It used to be a box, a deck plate and two rails — an empty tray at the back of the ship, which
358
+ // is the one part of a caravel the chase camera looks straight into. A quarterdeck carries a
359
+ // lantern, a binnacle, a helm, a companionway and stowage, and each of those is three boxes.
360
+ const castle = piece(new BoxGeometry(1.12, 0.78, 1.7), materials.hull);
361
+ castle.position.set(0, 1.32, 2.4);
362
+ rigid.add(castle);
363
+ const castleDeck = piece(new BoxGeometry(1.2, 0.08, 1.78), materials.deck);
364
+ castleDeck.position.set(0, 1.75, 2.4);
365
+ rigid.add(castleDeck);
366
+
367
+ // A balustered rail around the quarterdeck rather than two slabs: the gaps are the read.
368
+ for (const [x, z, along] of [
369
+ [-0.58, 2.4, true],
370
+ [0.58, 2.4, true],
371
+ [0, 3.24, false],
372
+ ] as const) {
373
+ const cap = piece(
374
+ along ? new BoxGeometry(0.08, 0.08, 1.78) : new BoxGeometry(1.24, 0.08, 0.08),
375
+ materials.trim,
376
+ );
377
+ cap.position.set(x, 2.12, z);
378
+ rigid.add(cap);
379
+ const count = along ? 7 : 5;
380
+ for (let index = 0; index < count; index += 1) {
381
+ const t = index / (count - 1);
382
+ const baluster = piece(new BoxGeometry(0.06, 0.3, 0.06), materials.trim);
383
+ baluster.position.set(
384
+ along ? x : MathUtils.lerp(-0.56, 0.56, t),
385
+ 1.94,
386
+ along ? MathUtils.lerp(1.56, 3.24, t) : z,
387
+ );
388
+ rigid.add(baluster);
389
+ }
390
+ }
391
+
392
+ // Quarter windows in the transom, and a wale across it.
393
+ for (const x of [-0.34, 0, 0.34]) {
394
+ const window = piece(new BoxGeometry(0.24, 0.28, 0.06), materials.trim);
395
+ window.position.set(x, 1.36, 3.28);
396
+ rigid.add(window);
397
+ }
398
+ const transomWale = piece(new BoxGeometry(1.18, 0.09, 0.07), materials.trim);
399
+ transomWale.position.set(0, 1.66, 3.28);
400
+ rigid.add(transomWale);
401
+
402
+ // The stern lantern on the taffrail — the single most recognisable thing on the back of a ship.
403
+ const lanternPost = piece(new CylinderGeometry(0.035, 0.045, 0.34, 6), materials.spar);
404
+ lanternPost.position.set(0, 2.28, 3.2);
405
+ rigid.add(lanternPost);
406
+ const lantern = piece(new CylinderGeometry(0.11, 0.14, 0.24, 6), materials.trim);
407
+ lantern.position.set(0, 2.56, 3.2);
408
+ rigid.add(lantern);
409
+ const lanternCap = piece(new ConeGeometry(0.16, 0.14, 6), materials.trim);
410
+ lanternCap.position.set(0, 2.74, 3.2);
411
+ rigid.add(lanternCap);
412
+
413
+ // Binnacle and whipstaff, where the helmsman stands.
414
+ const binnacle = piece(new BoxGeometry(0.3, 0.34, 0.26), materials.deck);
415
+ binnacle.position.set(0, 1.96, 2.62);
416
+ rigid.add(binnacle);
417
+ const whipstaff = piece(new CylinderGeometry(0.035, 0.045, 0.8, 6), materials.spar);
418
+ whipstaff.rotation.x = -0.22;
419
+ whipstaff.position.set(0, 2.14, 2.16);
420
+ rigid.add(whipstaff);
421
+
422
+ // A companionway down off the quarterdeck, and stowage in the waist.
423
+ const companion = piece(new BoxGeometry(0.5, 0.26, 0.36), materials.deck);
424
+ companion.position.set(0, 1.9, 1.68);
425
+ rigid.add(companion);
426
+ const companionRoof = piece(new BoxGeometry(0.56, 0.06, 0.42), materials.trim);
427
+ companionRoof.position.set(0, 2.05, 1.68);
428
+ rigid.add(companionRoof);
429
+ const hatch = piece(new BoxGeometry(0.56, 0.1, 0.6), materials.deck);
430
+ hatch.position.set(0, railAt(-0.6) + 0.06, -0.6);
431
+ rigid.add(hatch);
432
+ const hatchRim = piece(new BoxGeometry(0.64, 0.06, 0.68), materials.trim);
433
+ hatchRim.position.set(0, railAt(-0.6) + 0.13, -0.6);
434
+ rigid.add(hatchRim);
435
+ for (const [x, z] of [
436
+ [-0.42, 0.9],
437
+ [0.42, 0.86],
438
+ [-0.36, -1.3],
439
+ ] as const) {
440
+ const barrel = piece(new CylinderGeometry(0.17, 0.15, 0.36, 8), materials.spar);
441
+ barrel.position.set(x, railAt(z) + 0.2, z);
442
+ rigid.add(barrel);
443
+ const band = piece(new CylinderGeometry(0.18, 0.18, 0.05, 8), materials.trim);
444
+ band.position.set(x, railAt(z) + 0.2, z);
445
+ rigid.add(band);
446
+ }
447
+
448
+ const beak = piece(new ConeGeometry(0.2, 0.9, 6), materials.hull);
449
+ beak.rotation.x = -Math.PI / 2;
450
+ beak.position.set(0, 0.42, -3.5);
451
+ rigid.add(beak);
452
+
453
+ // Bowsprit, raked up over the beakhead.
454
+ const bowsprit = piece(new CylinderGeometry(0.03, 0.05, 2.1, 6), materials.spar);
455
+ bowsprit.rotation.x = Math.PI / 2 - 0.38;
456
+ bowsprit.position.set(0, 1.36, -3.5);
457
+ rigid.add(bowsprit);
458
+
459
+ // Rudder and tiller, hung on the transom.
460
+ const rudder = piece(new BoxGeometry(0.08, 1.02, 0.3), materials.hull);
461
+ rudder.position.set(0, -0.02, 3.26);
462
+ rigid.add(rudder);
463
+ const tiller = piece(new CylinderGeometry(0.025, 0.025, 0.7, 5), materials.spar);
464
+ tiller.rotation.x = Math.PI / 2 - 0.25;
465
+ tiller.position.set(0, 2.0, 2.72);
466
+ rigid.add(tiller);
467
+
468
+ // The rig: two square courses of falling size and a raked lateen on the mizzen.
469
+ ship.add(
470
+ mast(materials, rigid, {
471
+ height: 3.2,
472
+ sail: belliedSail(1.5, 1.35, 0.4),
473
+ sailY: 2.8,
474
+ yardWidth: 1.7,
475
+ yardY: 3.5,
476
+ z: -1.55,
477
+ }),
478
+ );
479
+ ship.add(
480
+ mast(materials, rigid, {
481
+ height: 4.3,
482
+ sail: belliedSail(1.85, 1.8, 0.5),
483
+ sailY: 3.4,
484
+ yardWidth: 2.1,
485
+ yardY: 4.33,
486
+ z: 0.1,
487
+ }),
488
+ );
489
+
490
+ // Crow's nest on the main.
491
+ const nest = piece(new CylinderGeometry(0.26, 0.2, 0.24, 9), materials.deck);
492
+ nest.position.set(0, 4.51, 0.1);
493
+ rigid.add(nest);
494
+
495
+ // Mizzen: a lateen yard raked steeply, with a triangular sail hung from it.
496
+ const mizzen = piece(new CylinderGeometry(0.03, 0.045, 2.4, 6), materials.spar);
497
+ mizzen.position.set(0, 2.45, 1.9);
498
+ rigid.add(mizzen);
499
+ const lateenYard = piece(new CylinderGeometry(0.025, 0.025, 3.1, 5), materials.spar);
500
+ lateenYard.rotation.x = 0.85;
501
+ lateenYard.position.set(0, 3.05, 1.9);
502
+ rigid.add(lateenYard);
503
+ const lateen = piece(belliedSail(1.15, 2.3, 0.3, 0.12), materials.sail);
504
+ lateen.rotation.x = 0.85;
505
+ lateen.rotation.y = Math.PI / 2;
506
+ lateen.position.set(0.1, 2.95, 1.95);
507
+ lateen.name = "lateen";
508
+ ship.add(lateen);
509
+
510
+ // Pennant at the main truck: the one part of the silhouette that is meant to be seen moving.
511
+ const pennant = piece(belliedSail(0.62, 0.2, 0.05, 0.25), materials.trim, false);
512
+ pennant.position.set(0.34, 4.95, 0.1);
513
+ pennant.name = "pennant";
514
+ ship.add(pennant);
515
+
516
+ rigid.attachTo(ship);
27
517
  return ship;
28
518
  }
29
519
 
520
+ /** A course marker: a float with a banded topmark and a small flag. */
30
521
  export function createBuoy(materials: ISailingMaterials): Group {
31
522
  const buoy = new Group();
32
- const body = new Mesh(new CylinderGeometry(0.22, 0.3, 0.75, 12), materials.buoy);
33
- body.position.y = 0.25;
523
+ const rigid = new RigidAssembly();
524
+ const body = new Mesh(new CylinderGeometry(0.2, 0.26, 0.66, 10), materials.buoy);
525
+ body.position.y = 0.16;
34
526
  body.castShadow = true;
35
- const cap = new Mesh(new SphereGeometry(0.28, 12, 8), materials.buoy);
36
- cap.position.y = 0.67;
527
+ const band = new Mesh(new CylinderGeometry(0.22, 0.22, 0.13, 10), materials.trim);
528
+ band.position.y = 0.28;
529
+ band.castShadow = true;
530
+ const cap = new Mesh(new SphereGeometry(0.23, 10, 7), materials.buoy);
531
+ cap.position.y = 0.51;
37
532
  cap.scale.y = 0.6;
38
533
  cap.castShadow = true;
39
- const flag = new Mesh(new PlaneGeometry(0.48, 0.25), materials.sail);
40
- flag.position.set(0.22, 1.02, 0);
534
+ const pole = new Mesh(new CylinderGeometry(0.025, 0.025, 0.7, 5), materials.spar);
535
+ pole.position.y = 0.85;
536
+ const flag = new Mesh(belliedSail(0.4, 0.24, 0.05, 0.4), materials.trim);
41
537
  flag.rotation.y = Math.PI / 2;
42
- buoy.add(body, cap, flag);
538
+ flag.position.set(0, 1.04, 0.17);
539
+ for (const part of [body, band, cap, pole, flag]) rigid.add(part);
540
+ rigid.attachTo(buoy);
43
541
  return buoy;
44
542
  }
45
543
 
46
- export function createIsland(materials: ISailingMaterials): Mesh {
47
- const island = new Mesh(new CylinderGeometry(8, 10, 1.5, 24), materials.island);
48
- island.position.set(-7, -0.88, -9);
49
- island.scale.z = 0.7;
50
- island.receiveShadow = true;
544
+ /**
545
+ * A headland: a beach shelf, a rock mass and a stand of palms.
546
+ *
547
+ * The island this replaces sat at y = -0.88 with a height of 1.5, so its crown was thirteen
548
+ * centimetres *below* the waterline and the frame contained no land at all. The sea needs
549
+ * something with a horizon behind it or there is no sense of a passage being sailed.
550
+ */
551
+ export function createIsland(materials: ISailingMaterials): Group {
552
+ const island = new Group();
553
+ const rigid = new RigidAssembly();
554
+ const beach = new Mesh(new CylinderGeometry(9.5, 11.5, 1.6, 22), materials.sand);
555
+ beach.position.y = -0.4;
556
+ beach.scale.z = 0.72;
557
+ beach.receiveShadow = true;
558
+ rigid.add(beach);
559
+
560
+ const headland = new Mesh(new SphereGeometry(4.6, 14, 9), materials.island);
561
+ headland.position.set(-1.4, 0.1, -1.2);
562
+ headland.scale.set(1, 0.62, 0.78);
563
+ headland.castShadow = true;
564
+ headland.receiveShadow = true;
565
+ rigid.add(headland);
566
+ const knoll = new Mesh(new SphereGeometry(2.7, 12, 8), materials.island);
567
+ knoll.position.set(3.4, 0.1, 1.1);
568
+ knoll.scale.set(1, 0.5, 0.85);
569
+ knoll.castShadow = true;
570
+ rigid.add(knoll);
571
+
572
+ // A stand of palms, placed by a seeded jitter so two captures frame the same headland.
573
+ let seed = 41;
574
+ const jitter = (): number => {
575
+ seed = (seed * 1103515245 + 12345) & 0x7fffffff;
576
+ return seed / 0x7fffffff;
577
+ };
578
+ for (let index = 0; index < 7; index += 1) {
579
+ const angle = (index / 7) * Math.PI * 2 + jitter();
580
+ const radius = 3 + jitter() * 3.5;
581
+ const height = 1.9 + jitter() * 1.1;
582
+ const trunk = new Mesh(new CylinderGeometry(0.09, 0.15, height, 5), materials.spar);
583
+ trunk.position.set(Math.cos(angle) * radius, 0.9 + height / 2, Math.sin(angle) * radius * 0.7);
584
+ trunk.rotation.z = (jitter() - 0.5) * 0.24;
585
+ trunk.castShadow = true;
586
+ rigid.add(trunk);
587
+ for (let frond = 0; frond < 5; frond += 1) {
588
+ const blade = new Mesh(new ConeGeometry(0.24, 1.5, 4), materials.foliage);
589
+ blade.position.copy(trunk.position);
590
+ blade.position.y += height / 2 + 0.1;
591
+ blade.rotation.z = Math.PI / 2 - 0.5;
592
+ blade.rotation.y = (frond / 5) * Math.PI * 2;
593
+ blade.translateY(0.6);
594
+ blade.castShadow = true;
595
+ rigid.add(blade);
596
+ }
597
+ }
598
+
599
+ rigid.attachTo(island);
600
+ island.position.set(-13, 0, -17);
51
601
  return island;
52
602
  }