create-threenative 0.2.17 → 0.2.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (387) hide show
  1. package/agent-docs/kit-mcp.md +1 -1
  2. package/agent-docs/kit-router.md +1 -1
  3. package/agent-docs/references/assertion-reference.md +54 -110
  4. package/agent-docs/references/capability-reference.md +790 -24
  5. package/agent-docs/references/conventions.md +28 -0
  6. package/agent-docs/references/kit-racing.md +4 -2
  7. package/agent-docs/references/performance-basics.md +10 -5
  8. package/agent-docs/references/terrain-authoring.md +21 -7
  9. package/agent-files/.agents/skills/ponytail/SKILL.md +1 -1
  10. package/agent-files/.agents/skills/prd-creator/SKILL.md +24 -0
  11. package/agent-files/.agents/skills/threenative-capabilities/SKILL.md +7 -4
  12. package/agent-files/.claude/hooks/discovery-gate.mjs +2 -2
  13. package/dist/index.d.ts +97 -6
  14. package/dist/index.js +1040 -529
  15. package/dist/quality.d.ts +5 -1
  16. package/dist/quality.js +75 -6
  17. package/dist/terrain-kit.js +1 -1
  18. package/dist/threenative.js +98 -17
  19. package/dist/web-engine-ccd-ik-solver.js +127 -0
  20. package/dist/web-engine-gltf-loader.js +52 -14
  21. package/dist/web-engine-post-effects.js +11 -10
  22. package/dist/web-engine-runtime.js +3638 -361
  23. package/package.json +8 -7
  24. package/template-assets/assets/floor-fern-0.glb +0 -0
  25. package/template-assets/assets/floor-litter-0.glb +0 -0
  26. package/template-assets/assets/floor-log-0.glb +0 -0
  27. package/template-assets/assets/floor-log-1.glb +0 -0
  28. package/template-assets/assets/floor-stump-0.glb +0 -0
  29. package/template-assets/assets/floor-twig-0.glb +0 -0
  30. package/template-assets/clearwater/README.md +1 -1
  31. package/template-assets/patches/manifest.json +18 -0
  32. package/template-assets/quality/eslint.config.js +1 -1
  33. package/templates/action-rpg/AGENTS.md +8 -4
  34. package/templates/action-rpg/CLAUDE.md +8 -4
  35. package/templates/action-rpg/package.json +7 -7
  36. package/templates/action-rpg/src/game.ts +1 -1
  37. package/templates/action-rpg/src/loot/drops.ts +3 -7
  38. package/templates/action-rpg/src/render/atmosphere.ts +6 -0
  39. package/templates/action-rpg/src/render/backlightControls.ts +10 -0
  40. package/templates/action-rpg/src/render/backlightMaterial.ts +4 -4
  41. package/templates/action-rpg/src/render/camera.ts +2 -2
  42. package/templates/action-rpg/src/render/clouds.ts +16 -1
  43. package/templates/action-rpg/src/render/materialLighting.ts +5 -5
  44. package/templates/action-rpg/src/render/materials.ts +3 -2
  45. package/templates/action-rpg/src/render/quality.ts +7 -32
  46. package/templates/action-rpg/src/render/touch-controls.ts +7 -6
  47. package/templates/action-rpg/src/scenes/Play.ts +5 -16
  48. package/templates/action-rpg/src/style.css +4 -0
  49. package/templates/action-rpg/vite.config.ts +2 -0
  50. package/templates/adventure/AGENTS.md +10 -5
  51. package/templates/adventure/CLAUDE.md +10 -5
  52. package/templates/adventure/kit.json +5 -1
  53. package/templates/adventure/native-playtests/survives.playtest.json +12 -0
  54. package/templates/adventure/native-playtests/woodland-floor.playtest.json +61 -0
  55. package/templates/adventure/package.json +7 -7
  56. package/templates/adventure/playtests/grass.playtest.json +61 -0
  57. package/templates/adventure/playtests/performance.playtest.json +1 -1
  58. package/templates/adventure/playtests/survives.playtest.json +2 -2
  59. package/templates/adventure/playtests/woodland-floor.playtest.json +61 -0
  60. package/templates/adventure/src/entities/LockOn.ts +42 -4
  61. package/templates/adventure/src/entities/Warden.ts +4 -1
  62. package/templates/adventure/src/game.ts +1 -1
  63. package/templates/adventure/src/level/Vale.ts +241 -16
  64. package/templates/adventure/src/render/camera.ts +2 -2
  65. package/templates/adventure/src/render/foliage.ts +64 -20
  66. package/templates/adventure/src/render/grass.ts +325 -0
  67. package/templates/adventure/src/render/materials.ts +3 -2
  68. package/templates/adventure/src/render/palette.ts +3 -0
  69. package/templates/adventure/src/render/touch-controls.ts +4 -1
  70. package/templates/adventure/src/scenes/Play.ts +96 -1
  71. package/templates/adventure/src/style.css +4 -0
  72. package/templates/adventure/tsconfig.json +1 -1
  73. package/templates/adventure/vite.config.ts +2 -0
  74. package/templates/collectathon/AGENTS.md +7 -2
  75. package/templates/collectathon/CLAUDE.md +7 -2
  76. package/templates/collectathon/package.json +7 -7
  77. package/templates/collectathon/src/game.ts +1 -1
  78. package/templates/collectathon/src/level/Course.ts +55 -14
  79. package/templates/collectathon/src/level/terrain.ts +29 -7
  80. package/templates/collectathon/src/main.ts +1 -0
  81. package/templates/collectathon/src/render/camera.ts +2 -2
  82. package/templates/collectathon/src/render/foliage.ts +359 -98
  83. package/templates/collectathon/src/render/ground.ts +4 -4
  84. package/templates/collectathon/src/render/hero.ts +1 -1
  85. package/templates/collectathon/src/render/materials.ts +0 -1
  86. package/templates/collectathon/src/render/sky.ts +80 -15
  87. package/templates/collectathon/src/render/water.ts +32 -10
  88. package/templates/collectathon/src/scenes/Play.ts +18 -5
  89. package/templates/collectathon/src/style.css +4 -0
  90. package/templates/collectathon/tsconfig.json +1 -1
  91. package/templates/collectathon/vite.config.ts +2 -0
  92. package/templates/kart/AGENTS.md +7 -2
  93. package/templates/kart/CLAUDE.md +7 -2
  94. package/templates/kart/package.json +6 -6
  95. package/templates/kart/src/entities/Kart.ts +2 -1
  96. package/templates/kart/src/game.ts +1 -1
  97. package/templates/kart/src/main.ts +1 -0
  98. package/templates/kart/src/render/course.ts +2 -1
  99. package/templates/kart/src/style.css +4 -0
  100. package/templates/kart/src/track/Course.ts +3 -1
  101. package/templates/kart/tsconfig.json +1 -1
  102. package/templates/kart/vite.config.ts +2 -0
  103. package/templates/minimal/AGENTS.md +8 -3
  104. package/templates/minimal/CLAUDE.md +8 -3
  105. package/templates/minimal/package.json +6 -6
  106. package/templates/minimal/playtests/stands-still.playtest.json +30 -0
  107. package/templates/minimal/src/game.ts +1 -1
  108. package/templates/minimal/src/render/atmosphere.ts +6 -0
  109. package/templates/minimal/src/render/backlightControls.ts +10 -0
  110. package/templates/minimal/src/render/backlightMaterial.ts +4 -4
  111. package/templates/minimal/src/render/camera.ts +14 -3
  112. package/templates/minimal/src/render/clouds.ts +16 -1
  113. package/templates/minimal/src/render/lighting.ts +4 -2
  114. package/templates/minimal/src/render/materialLighting.ts +5 -5
  115. package/templates/minimal/src/render/materials.ts +13 -2
  116. package/templates/minimal/src/render/quality.ts +7 -32
  117. package/templates/minimal/src/render/touch-controls.ts +7 -6
  118. package/templates/minimal/src/scenes/Play.ts +4 -1
  119. package/templates/minimal/vite.config.ts +7 -1
  120. package/templates/platformer/AGENTS.md +9 -4
  121. package/templates/platformer/CLAUDE.md +9 -4
  122. package/templates/platformer/index.html +1 -1
  123. package/templates/platformer/main.html +12 -0
  124. package/templates/platformer/package.json +7 -7
  125. package/templates/platformer/playtests/collect.playtest.json +4 -1
  126. package/templates/platformer/playtests/gamepad-idle.playtest.json +21 -0
  127. package/templates/platformer/playtests/gamepad.playtest.json +30 -0
  128. package/templates/platformer/src/entities/Fox.ts +21 -6
  129. package/templates/platformer/src/game.ts +1 -1
  130. package/templates/platformer/src/level/Stage.ts +2 -6
  131. package/templates/platformer/src/main.ts +1 -0
  132. package/templates/platformer/src/render/backlightControls.ts +10 -0
  133. package/templates/platformer/src/render/backlightMaterial.ts +4 -4
  134. package/templates/platformer/src/render/materialLighting.ts +5 -5
  135. package/templates/platformer/src/render/quality.ts +7 -32
  136. package/templates/platformer/src/scenes/Play.ts +4 -2
  137. package/templates/platformer/src/style.css +4 -0
  138. package/templates/platformer/src/worker-page.ts +29 -0
  139. package/templates/platformer/src/worker.ts +5 -0
  140. package/templates/platformer/tsconfig.json +1 -1
  141. package/templates/platformer/vite.config.ts +4 -0
  142. package/templates/puzzle/AGENTS.md +7 -2
  143. package/templates/puzzle/CLAUDE.md +7 -2
  144. package/templates/puzzle/package.json +7 -7
  145. package/templates/puzzle/src/entities/Warden.ts +3 -3
  146. package/templates/puzzle/src/game.ts +1 -1
  147. package/templates/puzzle/src/render/backlightControls.ts +10 -0
  148. package/templates/puzzle/src/render/backlightMaterial.ts +4 -4
  149. package/templates/puzzle/src/render/camera.ts +2 -2
  150. package/templates/puzzle/src/render/materialLighting.ts +5 -5
  151. package/templates/puzzle/src/render/quality.ts +7 -32
  152. package/templates/puzzle/src/render/touch-controls.ts +7 -6
  153. package/templates/puzzle/src/scenes/Play.ts +1 -1
  154. package/templates/puzzle/src/style.css +4 -0
  155. package/templates/puzzle/tsconfig.json +1 -1
  156. package/templates/puzzle/vite.config.ts +2 -0
  157. package/templates/racing/AGENTS.md +9 -4
  158. package/templates/racing/CLAUDE.md +9 -4
  159. package/templates/racing/CREDITS.md +29 -0
  160. package/templates/racing/assets/engine-loop.wav +0 -0
  161. package/templates/racing/assets/grass/Grass004_color.jpg +0 -0
  162. package/templates/racing/assets/grass/Grass004_normal.jpg +0 -0
  163. package/templates/racing/assets/grass/Grass004_roughness.jpg +0 -0
  164. package/templates/racing/assets/nitro-burst.wav +0 -0
  165. package/templates/racing/assets/tyre-squeal.wav +0 -0
  166. package/templates/racing/package.json +7 -7
  167. package/templates/racing/playtests/drift-natural.playtest.json +68 -0
  168. package/templates/racing/playtests/drift.playtest.json +100 -0
  169. package/templates/racing/playtests/hud.playtest.json +117 -0
  170. package/templates/racing/playtests/launch-pose.playtest.json +34 -0
  171. package/templates/racing/playtests/nitro.playtest.json +158 -0
  172. package/templates/racing/playtests/outcome.playtest.json +4 -4
  173. package/templates/racing/playtests/performance.playtest.json +1 -1
  174. package/templates/racing/playtests/steady-camera.playtest.json +88 -0
  175. package/templates/racing/src/audio/engine.ts +138 -0
  176. package/templates/racing/src/entities/CarBody.ts +83 -10
  177. package/templates/racing/src/entities/Drift.ts +243 -0
  178. package/templates/racing/src/entities/LineDriver.ts +2 -2
  179. package/templates/racing/src/entities/Nitro.ts +72 -0
  180. package/templates/racing/src/entities/RacingCar.ts +86 -21
  181. package/templates/racing/src/entities/Rival.ts +35 -21
  182. package/templates/racing/src/game.ts +7 -1
  183. package/templates/racing/src/gauges.ts +74 -0
  184. package/templates/racing/src/render/atmosphere.ts +6 -0
  185. package/templates/racing/src/render/backlightControls.ts +10 -0
  186. package/templates/racing/src/render/backlightMaterial.ts +4 -4
  187. package/templates/racing/src/render/camera.ts +29 -4
  188. package/templates/racing/src/render/clouds.ts +16 -1
  189. package/templates/racing/src/render/effects.ts +244 -0
  190. package/templates/racing/src/render/materialLighting.ts +5 -5
  191. package/templates/racing/src/render/materials.ts +43 -8
  192. package/templates/racing/src/render/quality.ts +7 -32
  193. package/templates/racing/src/render/shapes.ts +37 -0
  194. package/templates/racing/src/render/skids.ts +84 -0
  195. package/templates/racing/src/render/touch-controls.ts +10 -10
  196. package/templates/racing/src/scenes/Race.ts +281 -26
  197. package/templates/racing/src/state.ts +35 -0
  198. package/templates/racing/src/style.css +7 -0
  199. package/templates/racing/src/track/Track.ts +132 -58
  200. package/templates/racing/src/track/TrackSector.ts +19 -1
  201. package/templates/racing/src/track/circuit.ts +21 -15
  202. package/templates/racing/src/ui/GameUi.tsx +0 -2
  203. package/templates/racing/src/ui/Hud.tsx +417 -50
  204. package/templates/racing/threenative.config.ts +15 -0
  205. package/templates/racing/tools/make-racing-audio.mjs +388 -0
  206. package/templates/racing/tsconfig.json +1 -1
  207. package/templates/racing/vite.config.ts +2 -0
  208. package/templates/rain/AGENTS.md +6 -2
  209. package/templates/rain/CLAUDE.md +6 -2
  210. package/templates/rain/package.json +6 -6
  211. package/templates/rain/src/game.ts +1 -1
  212. package/templates/rain/src/render/noise-volume.ts +2 -1
  213. package/templates/rain/src/state.ts +3 -1
  214. package/templates/rain/src/ui/GameUi.tsx +1 -1
  215. package/templates/rain/src/ui/automation.ts +10 -8
  216. package/templates/rain/src/ui/tempest.ts +3 -4
  217. package/templates/rain/vite.config.ts +6 -0
  218. package/templates/rts/AGENTS.md +6 -2
  219. package/templates/rts/CLAUDE.md +6 -2
  220. package/templates/rts/package.json +6 -6
  221. package/templates/rts/src/game.ts +1 -1
  222. package/templates/rts/src/render/backlightControls.ts +10 -0
  223. package/templates/rts/src/render/backlightMaterial.ts +4 -4
  224. package/templates/rts/src/render/materialLighting.ts +5 -5
  225. package/templates/rts/src/render/quality.ts +7 -31
  226. package/templates/rts/src/scenes/Play.ts +1 -1
  227. package/templates/rts/src/sim/terrain.ts +1 -0
  228. package/templates/rts/src/sim/types.ts +1 -0
  229. package/templates/rts/src/style.css +4 -0
  230. package/templates/rts/vite.config.ts +2 -0
  231. package/templates/runner/AGENTS.md +7 -2
  232. package/templates/runner/CLAUDE.md +7 -2
  233. package/templates/runner/package.json +7 -7
  234. package/templates/runner/src/game.ts +1 -1
  235. package/templates/runner/src/render/atmosphere.ts +6 -0
  236. package/templates/runner/src/render/backlightControls.ts +10 -0
  237. package/templates/runner/src/render/backlightMaterial.ts +4 -4
  238. package/templates/runner/src/render/clouds.ts +16 -1
  239. package/templates/runner/src/render/materialLighting.ts +5 -5
  240. package/templates/runner/src/render/materials.ts +3 -2
  241. package/templates/runner/src/render/quality.ts +7 -32
  242. package/templates/runner/src/render/touch-controls.ts +7 -6
  243. package/templates/runner/src/scenes/Run.ts +8 -10
  244. package/templates/runner/src/style.css +4 -0
  245. package/templates/runner/tsconfig.json +1 -1
  246. package/templates/runner/vite.config.ts +2 -0
  247. package/templates/sailing/AGENTS.md +7 -2
  248. package/templates/sailing/CLAUDE.md +7 -2
  249. package/templates/sailing/package.json +7 -7
  250. package/templates/sailing/src/game.ts +1 -1
  251. package/templates/sailing/src/render/backlightControls.ts +10 -0
  252. package/templates/sailing/src/render/backlightMaterial.ts +4 -4
  253. package/templates/sailing/src/render/environmentSetup.ts +1 -1
  254. package/templates/sailing/src/render/materialLighting.ts +5 -5
  255. package/templates/sailing/src/render/quality.ts +7 -32
  256. package/templates/sailing/src/render/touch-controls.ts +7 -6
  257. package/templates/sailing/src/style.css +5 -0
  258. package/templates/sailing/vite.config.ts +6 -0
  259. package/templates/shooter/AGENTS.md +6 -2
  260. package/templates/shooter/CLAUDE.md +6 -2
  261. package/templates/shooter/package.json +7 -7
  262. package/templates/shooter/src/game.ts +3 -2
  263. package/templates/shooter/src/render/atmosphere.ts +6 -0
  264. package/templates/shooter/src/render/backlightControls.ts +10 -0
  265. package/templates/shooter/src/render/backlightMaterial.ts +4 -4
  266. package/templates/shooter/src/render/clouds.ts +16 -1
  267. package/templates/shooter/src/render/materialLighting.ts +5 -5
  268. package/templates/shooter/src/render/quality.ts +7 -32
  269. package/templates/shooter/src/scenes/Play.ts +4 -1
  270. package/templates/shooter/src/style.css +4 -0
  271. package/templates/shooter/vite.config.ts +2 -0
  272. package/templates/snow/AGENTS.md +7 -2
  273. package/templates/snow/CLAUDE.md +7 -2
  274. package/templates/snow/package.json +7 -7
  275. package/templates/snow/src/entities/Explorer.ts +6 -12
  276. package/templates/snow/src/game.ts +1 -1
  277. package/templates/snow/src/render/backlightControls.ts +10 -0
  278. package/templates/snow/src/render/backlightMaterial.ts +4 -4
  279. package/templates/snow/src/render/bootPrint.ts +3 -1
  280. package/templates/snow/src/render/camera.ts +3 -2
  281. package/templates/snow/src/render/materialLighting.ts +5 -5
  282. package/templates/snow/src/render/quality.ts +7 -32
  283. package/templates/snow/src/render/scenery.ts +3 -3
  284. package/templates/snow/src/render/touch-controls.ts +7 -6
  285. package/templates/snow/src/render/weather.ts +3 -5
  286. package/templates/snow/src/style.css +5 -0
  287. package/templates/snow/src/terrain.ts +2 -1
  288. package/templates/snow/vite.config.ts +6 -0
  289. package/templates/starter/AGENTS.md +8 -3
  290. package/templates/starter/CLAUDE.md +8 -3
  291. package/templates/starter/native-playtests/render-chain.playtest.json +9 -9
  292. package/templates/starter/package.json +7 -7
  293. package/templates/starter/src/entities/Crate.ts +5 -2
  294. package/templates/starter/src/entities/Player.ts +10 -2
  295. package/templates/starter/src/game.ts +4 -3
  296. package/templates/starter/src/render/adaptiveQuality.ts +17 -0
  297. package/templates/starter/src/render/atmosphere.ts +6 -0
  298. package/templates/starter/src/render/backlightControls.ts +10 -0
  299. package/templates/starter/src/render/backlightMaterial.ts +4 -4
  300. package/templates/starter/src/render/camera.ts +2 -2
  301. package/templates/starter/src/render/clouds.ts +16 -1
  302. package/templates/starter/src/render/contactShadow.ts +1 -1
  303. package/templates/starter/src/render/materialLighting.ts +5 -5
  304. package/templates/starter/src/render/materials.ts +3 -2
  305. package/templates/starter/src/render/postprocessing.ts +11 -10
  306. package/templates/starter/src/render/quality.ts +14 -1
  307. package/templates/starter/src/render/touch-controls.ts +7 -6
  308. package/templates/starter/src/scenes/Play.ts +13 -17
  309. package/templates/starter/src/state.ts +2 -0
  310. package/templates/starter/src/style.css +4 -0
  311. package/templates/starter/src/ui/Menu.tsx +5 -1
  312. package/templates/starter/vite.config.ts +2 -0
  313. package/templates/tower-defense/AGENTS.md +7 -2
  314. package/templates/tower-defense/CLAUDE.md +7 -2
  315. package/templates/tower-defense/package.json +7 -7
  316. package/templates/tower-defense/src/game.ts +1 -1
  317. package/templates/tower-defense/src/render/backlightControls.ts +10 -0
  318. package/templates/tower-defense/src/render/backlightMaterial.ts +4 -4
  319. package/templates/tower-defense/src/render/materialLighting.ts +5 -5
  320. package/templates/tower-defense/src/render/quality.ts +7 -32
  321. package/templates/tower-defense/src/render/shapes.ts +1 -2
  322. package/templates/tower-defense/src/scenes/Battle.ts +4 -9
  323. package/templates/tower-defense/src/style.css +4 -0
  324. package/templates/tower-defense/tsconfig.json +1 -1
  325. package/templates/tower-defense/vite.config.ts +2 -0
  326. package/templates/action-rpg/src/render/environmentContribution.ts +0 -188
  327. package/templates/action-rpg/src/render/environmentRadiance.ts +0 -36
  328. package/templates/action-rpg/src/render/environmentSampleCache.ts +0 -43
  329. package/templates/action-rpg/src/render/environmentSampling.ts +0 -193
  330. package/templates/action-rpg/src/render/environmentSnapshot.ts +0 -53
  331. package/templates/minimal/src/render/environmentContribution.ts +0 -188
  332. package/templates/minimal/src/render/environmentRadiance.ts +0 -36
  333. package/templates/minimal/src/render/environmentSampleCache.ts +0 -43
  334. package/templates/minimal/src/render/environmentSampling.ts +0 -193
  335. package/templates/minimal/src/render/environmentSnapshot.ts +0 -53
  336. package/templates/platformer/src/render/environmentContribution.ts +0 -188
  337. package/templates/platformer/src/render/environmentRadiance.ts +0 -36
  338. package/templates/platformer/src/render/environmentSampleCache.ts +0 -43
  339. package/templates/platformer/src/render/environmentSampling.ts +0 -193
  340. package/templates/platformer/src/render/environmentSnapshot.ts +0 -53
  341. package/templates/puzzle/src/render/environmentContribution.ts +0 -188
  342. package/templates/puzzle/src/render/environmentRadiance.ts +0 -36
  343. package/templates/puzzle/src/render/environmentSampleCache.ts +0 -43
  344. package/templates/puzzle/src/render/environmentSampling.ts +0 -193
  345. package/templates/puzzle/src/render/environmentSnapshot.ts +0 -53
  346. package/templates/racing/src/render/environmentContribution.ts +0 -188
  347. package/templates/racing/src/render/environmentRadiance.ts +0 -36
  348. package/templates/racing/src/render/environmentSampleCache.ts +0 -43
  349. package/templates/racing/src/render/environmentSampling.ts +0 -193
  350. package/templates/racing/src/render/environmentSnapshot.ts +0 -53
  351. package/templates/racing/src/ui/Menu.tsx +0 -7
  352. package/templates/rts/src/render/environmentContribution.ts +0 -188
  353. package/templates/rts/src/render/environmentRadiance.ts +0 -36
  354. package/templates/rts/src/render/environmentSampleCache.ts +0 -43
  355. package/templates/rts/src/render/environmentSampling.ts +0 -193
  356. package/templates/rts/src/render/environmentSnapshot.ts +0 -53
  357. package/templates/runner/src/render/environmentContribution.ts +0 -188
  358. package/templates/runner/src/render/environmentRadiance.ts +0 -36
  359. package/templates/runner/src/render/environmentSampleCache.ts +0 -43
  360. package/templates/runner/src/render/environmentSampling.ts +0 -193
  361. package/templates/runner/src/render/environmentSnapshot.ts +0 -53
  362. package/templates/sailing/src/render/environmentContribution.ts +0 -188
  363. package/templates/sailing/src/render/environmentRadiance.ts +0 -36
  364. package/templates/sailing/src/render/environmentSampleCache.ts +0 -43
  365. package/templates/sailing/src/render/environmentSampling.ts +0 -193
  366. package/templates/sailing/src/render/environmentSnapshot.ts +0 -53
  367. package/templates/shooter/src/render/environmentContribution.ts +0 -188
  368. package/templates/shooter/src/render/environmentRadiance.ts +0 -36
  369. package/templates/shooter/src/render/environmentSampleCache.ts +0 -43
  370. package/templates/shooter/src/render/environmentSampling.ts +0 -193
  371. package/templates/shooter/src/render/environmentSnapshot.ts +0 -53
  372. package/templates/snow/src/render/environmentContribution.ts +0 -188
  373. package/templates/snow/src/render/environmentRadiance.ts +0 -36
  374. package/templates/snow/src/render/environmentSampleCache.ts +0 -43
  375. package/templates/snow/src/render/environmentSampling.ts +0 -193
  376. package/templates/snow/src/render/environmentSnapshot.ts +0 -53
  377. package/templates/starter/src/render/environmentContribution.ts +0 -188
  378. package/templates/starter/src/render/environmentRadiance.ts +0 -36
  379. package/templates/starter/src/render/environmentSampleCache.ts +0 -43
  380. package/templates/starter/src/render/environmentSampling.ts +0 -193
  381. package/templates/starter/src/render/environmentSnapshot.ts +0 -53
  382. package/templates/starter/src/render/rendererGate.ts +0 -36
  383. package/templates/tower-defense/src/render/environmentContribution.ts +0 -188
  384. package/templates/tower-defense/src/render/environmentRadiance.ts +0 -36
  385. package/templates/tower-defense/src/render/environmentSampleCache.ts +0 -43
  386. package/templates/tower-defense/src/render/environmentSampling.ts +0 -193
  387. package/templates/tower-defense/src/render/environmentSnapshot.ts +0 -53
@@ -1,13 +1,24 @@
1
+ import { ScatterField3D } from "@threenative/core";
1
2
  import {
3
+ Box3,
2
4
  BoxGeometry,
5
+ type BufferGeometry,
3
6
  CylinderGeometry,
4
7
  Group,
8
+ type Material,
9
+ MathUtils,
5
10
  Mesh,
6
11
  type Object3D,
7
12
  PlaneGeometry,
8
13
  Vector3,
9
14
  } from "three";
10
- import { type IValeSite, plantVale, valeGround } from "../render/foliage.js";
15
+ import {
16
+ type FloorKind,
17
+ type IValeSite,
18
+ floorPart,
19
+ plantVale,
20
+ valeGround,
21
+ } from "../render/foliage.js";
11
22
  import { flat, mottle } from "../render/materials.js";
12
23
  import { C } from "../render/palette.js";
13
24
  import { createHut, createPitcherLantern, createSign } from "../render/props.js";
@@ -17,6 +28,7 @@ import { surfaced } from "../render/surface.js";
17
28
  export function makeRng(seed: number): () => number {
18
29
  let state = seed >>> 0;
19
30
  return () => {
31
+ // eslint-disable-next-line no-restricted-syntax -- The clearing is authored against this mulberry32 stream; the engine's seeded RNG is an LCG, so swapping it builds a different level.
20
32
  state = (state + 0x6d2b79f5) >>> 0;
21
33
  let t = state;
22
34
  t = Math.imul(t ^ (t >>> 15), t | 1);
@@ -44,6 +56,15 @@ export interface IVale {
44
56
  readonly hut: { readonly at: Vector3; readonly lanterns: number };
45
57
  /** Flagstones laid along the path, and the share of the path's centre line they cover. */
46
58
  readonly path: { readonly stones: number; readonly cover: number };
59
+ /** True on open ground: off the path, out of the ruin's lane and clear of the play spaces. */
60
+ readonly clear: (x: number, z: number, width: number) => boolean;
61
+ /** The old trees that frame the clearing, with the trunk radius nothing scatters inside. */
62
+ readonly trees: readonly { readonly radius: number; readonly x: number; readonly z: number }[];
63
+ /**
64
+ * 0..1 leaf litter under the old trees, easing out to the open meadow. The ground paints its soil
65
+ * by it, the grass thins by it and the debris scatters by it, so the three cannot disagree.
66
+ */
67
+ readonly floorZone: (x: number, z: number) => number;
47
68
  }
48
69
 
49
70
  // ------------------------------------------------------------------------------------ the ground
@@ -52,7 +73,7 @@ export interface IVale {
52
73
 
53
74
  const smooth = (a: number, b: number, t: number): number => {
54
75
  const u = Math.min(1, Math.max(0, (t - a) / (b - a)));
55
- return u * u * (3 - 2 * u);
76
+ return MathUtils.smoothstep(u, 0, 1);
56
77
  };
57
78
  /** 0..1 rolling noise from two crossed sine sheets. */
58
79
  const wave = (x: number, z: number, f: number): number =>
@@ -103,16 +124,24 @@ export const STREAM = {
103
124
  water: -0.3,
104
125
  };
105
126
 
106
- const distanceToSegment = (
127
+ /** Plain length: `Math.hypot` costs several times more, and the grass asks once per blade. */
128
+ const hyp = (dx: number, dz: number): number => Math.sqrt(dx * dx + dz * dz);
129
+
130
+ /** Squared distance to a segment; the caller takes one square root for the nearest. */
131
+ const distanceSqToSegment = (
107
132
  x: number,
108
133
  z: number,
109
- [ax, az]: readonly [number, number],
110
- [bx, bz]: readonly [number, number],
134
+ a: readonly [number, number],
135
+ b: readonly [number, number],
111
136
  ): number => {
112
- const dx = bx - ax;
113
- const dz = bz - az;
137
+ const ax = a[0];
138
+ const az = a[1];
139
+ const dx = b[0] - ax;
140
+ const dz = b[1] - az;
114
141
  const t = Math.min(1, Math.max(0, ((x - ax) * dx + (z - az) * dz) / (dx * dx + dz * dz)));
115
- return Math.hypot(x - ax - t * dx, z - az - t * dz);
142
+ const ex = x - ax - t * dx;
143
+ const ez = z - az - t * dz;
144
+ return ex * ex + ez * ez;
116
145
  };
117
146
 
118
147
  /** Metres from the stream's centre line. */
@@ -121,18 +150,35 @@ export function streamDistance(x: number, z: number): number {
121
150
  for (let i = 1; i < STREAM.points.length; i += 1) {
122
151
  const a = STREAM.points[i - 1];
123
152
  const b = STREAM.points[i];
124
- if (a !== undefined && b !== undefined) best = Math.min(best, distanceToSegment(x, z, a, b));
153
+ if (a !== undefined && b !== undefined) best = Math.min(best, distanceSqToSegment(x, z, a, b));
125
154
  }
126
- return best;
155
+ return Math.sqrt(best);
156
+ }
157
+
158
+ /** Where the streamed grass grows, 0..1: bare on the path, in the stream, under the hut and in the cave mouth. */
159
+ export function grassCover(x: number, z: number): number {
160
+ if (z < CLEARING.north + 1 && Math.abs(x) < 3.5) return 0;
161
+ return (
162
+ smooth(1.5, 2.3, Math.abs(x - pathX(z))) *
163
+ smooth(1.3, 2.4, streamDistance(x, z)) *
164
+ smooth(2.4, 3.4, hyp(x - HUT.x, z - HUT.z))
165
+ );
127
166
  }
128
167
 
168
+ /** The square the grass grows in: the clearing and the first hills round it. */
169
+ export const GRASS_BOUNDS = {
170
+ maxX: CLEARING.half + 10,
171
+ maxZ: CLEARING.south + 10,
172
+ minX: -CLEARING.half - 10,
173
+ minZ: CLEARING.north - 6,
174
+ };
175
+
129
176
  /** 1 on a play space, the path or the cave approach, easing to 0 over a few metres round them. */
130
177
  function flatness(x: number, z: number): number {
131
178
  let f = 1 - smooth(2.2, 4.4, Math.abs(x - pathX(z)));
132
179
  if (z < -15) f = Math.max(f, 1 - smooth(3.5, 5.5, Math.abs(x)));
133
- f = Math.max(f, 1 - smooth(HUT.radius, HUT.radius + 1.6, Math.hypot(x - HUT.x, z - HUT.z)));
134
- for (const [px, pz, r] of PADS)
135
- f = Math.max(f, 1 - smooth(r, r + 3.2, Math.hypot(x - px, z - pz)));
180
+ f = Math.max(f, 1 - smooth(HUT.radius, HUT.radius + 1.6, hyp(x - HUT.x, z - HUT.z)));
181
+ for (const [px, pz, r] of PADS) f = Math.max(f, 1 - smooth(r, r + 3.2, hyp(x - px, z - pz)));
136
182
  return f;
137
183
  }
138
184
 
@@ -140,15 +186,14 @@ function flatness(x: number, z: number): number {
140
186
  export function valeHeight(x: number, z: number): number {
141
187
  // The rise to the cave mouth: the clearing's north end climbs 1.2 m to the cliff.
142
188
  const rise = 1.2 * smooth(-11, -17, z);
143
- const ledge =
144
- HUT.lift * (1 - smooth(HUT.radius, HUT.radius + 1.6, Math.hypot(x - HUT.x, z - HUT.z)));
189
+ const ledge = HUT.lift * (1 - smooth(HUT.radius, HUT.radius + 1.6, hyp(x - HUT.x, z - HUT.z)));
145
190
  // Inside the walls: rolling banks, higher toward the walls, and the outcrops.
146
191
  const edge = Math.min(CLEARING.half - Math.abs(x), z - CLEARING.north, CLEARING.south - z);
147
192
  const tunnel = Math.abs(x) < 3.5 && z < CLEARING.north + 1;
148
193
  let relief = 0.35 + 1.3 * wave(x, z, 0.23) + 0.45 * wave(x + 7, z - 3, 0.61);
149
194
  if (edge > 0) relief += 1.4 * (1 - smooth(0, 4.5, edge));
150
195
  for (const [ox, oz, r, h] of OUTCROPS)
151
- relief += h * (1 - smooth(r * 0.5, r, Math.hypot(x - ox, z - oz)));
196
+ relief += h * (1 - smooth(r * 0.5, r, hyp(x - ox, z - oz)));
152
197
  // Outside them: a steep rocky bank, then wooded hills.
153
198
  if (edge < 0 && !tunnel)
154
199
  relief += 2.2 * smooth(0, 3, -edge) + (0.8 + 3.4 * wave(x, z, 0.09)) * smooth(2, 14, -edge);
@@ -357,8 +402,19 @@ export function buildVale(rng: () => number): IVale {
357
402
  ground.inner.userData.solid = true;
358
403
  group.add(planting.group, ground.inner, ground.outer);
359
404
 
405
+ const oldTrees = trees.map(([x, z, s]) => ({ radius: 0.6 * s, x, z }));
360
406
  return {
361
407
  caveExit: at(0, -17),
408
+ clear: site.clear,
409
+ floorZone: (x, z) => {
410
+ let zone = 0;
411
+ for (const tree of oldTrees) {
412
+ const d = Math.hypot(x - tree.x, z - tree.z);
413
+ zone = Math.max(zone, 1 - smooth(tree.radius * 2.4, tree.radius * 8, d));
414
+ }
415
+ return zone;
416
+ },
417
+ trees: oldTrees,
362
418
  caveMouth: at(0, -23),
363
419
  dummies: [at(-1.6, 4), at(1.8, 4.5)],
364
420
  group,
@@ -381,3 +437,172 @@ export function buildVale(rng: () => number): IVale {
381
437
  export function isSolid(object: Object3D): boolean {
382
438
  return object.userData.solid === true;
383
439
  }
440
+
441
+ // ------------------------------------------------------------------------- the woodland floor
442
+ // Baked props, streamed round Wren. The generators live in @threenative/procedural-vegetation and
443
+ // the bytes in ../template-assets/assets (regenerate with `pnpm tsx scripts/bake-floor-assets.ts`);
444
+ // the material is the kit's own, in render/foliage.ts.
445
+
446
+ /** What this needs of the loader: `ctx.assets` satisfies it. */
447
+ export interface IFloorLoader {
448
+ model(path: string): Promise<{ readonly scene: Object3D }>;
449
+ }
450
+
451
+ /** One baked prop, its levels of detail near to far, and how many a square metre holds. */
452
+ interface IFloorProp {
453
+ readonly density: number;
454
+ readonly drawDistance: number;
455
+ readonly files: readonly string[];
456
+ readonly kind: FloorKind;
457
+ readonly scale: readonly [number, number];
458
+ }
459
+
460
+ const FLOOR_PROPS: Readonly<Record<string, IFloorProp>> = {
461
+ // The kit's grass stands knee-high, so a prop that should read is sized to clear it.
462
+ fern: {
463
+ density: 0.5,
464
+ drawDistance: 24,
465
+ files: ["floor-fern-0.glb"],
466
+ kind: "frond",
467
+ scale: [1.5, 2.2],
468
+ },
469
+ litter: {
470
+ density: 1.6,
471
+ drawDistance: 18,
472
+ files: ["floor-litter-0.glb"],
473
+ kind: "litter",
474
+ scale: [2.2, 3.2],
475
+ },
476
+ log: {
477
+ density: 0.08,
478
+ drawDistance: 30,
479
+ files: ["floor-log-0.glb", "floor-log-1.glb"],
480
+ kind: "wood",
481
+ scale: [1.6, 2.2],
482
+ },
483
+ stump: {
484
+ density: 0.07,
485
+ drawDistance: 30,
486
+ files: ["floor-stump-0.glb"],
487
+ kind: "wood",
488
+ scale: [1.5, 2.1],
489
+ },
490
+ twig: {
491
+ density: 0.35,
492
+ drawDistance: 20,
493
+ files: ["floor-twig-0.glb"],
494
+ kind: "wood",
495
+ scale: [2.2, 3.2],
496
+ },
497
+ };
498
+
499
+ export interface IWoodlandFloor {
500
+ readonly group: Group;
501
+ /** One streamed field per prop; the playtest reads their totals. */
502
+ readonly fields: readonly ScatterField3D[];
503
+ /** Builds every tile on the next update regardless of budget: on load, behind the curtain. */
504
+ prewarm(): void;
505
+ update(follow: Vector3): void;
506
+ }
507
+
508
+ /** 0..1 from a point and a salt: a placement is the same whatever order the tiles build in. */
509
+ const jitter = (x: number, z: number, salt: number): number => {
510
+ const h = Math.sin(x * 127.1 + z * 311.7 + salt * 74.7) * 43758.5453;
511
+ return h - Math.floor(h);
512
+ };
513
+
514
+ /** A loaded GLB's primitives in the kit's look: one part per glTF material. */
515
+ function chainsOf(
516
+ model: { readonly scene: Object3D },
517
+ kind: FloorKind,
518
+ ): {
519
+ geometries: BufferGeometry[];
520
+ material: Material;
521
+ }[] {
522
+ const chains: { geometries: BufferGeometry[]; material: Material }[] = [];
523
+ model.scene.traverse((object) => {
524
+ const mesh = object as Mesh;
525
+ if (mesh.isMesh !== true) return;
526
+ const part = floorPart(mesh, kind);
527
+ chains.push({ geometries: [part.geometry], material: part.material });
528
+ });
529
+ return chains;
530
+ }
531
+
532
+ /**
533
+ * The forest floor: logs, stumps, twigs and leaf litter under the old trees, with ferns among them.
534
+ * Every prop is a baked GLB streamed by `ScatterField3D`, placed off the path, out of the play spaces
535
+ * and clear of the trunks, so nothing floats over the ruin's lane or grows out of a tree.
536
+ */
537
+ export async function buildWoodlandFloor(
538
+ assets: IFloorLoader,
539
+ vale: IVale,
540
+ seed = 1986,
541
+ ): Promise<IWoodlandFloor> {
542
+ const group = new Group();
543
+ group.name = "woodland floor";
544
+ const fields: ScatterField3D[] = [];
545
+ let salt = 1;
546
+ for (const [name, prop] of Object.entries(FLOOR_PROPS)) {
547
+ const models = await Promise.all(prop.files.map((file) => assets.model(file)));
548
+ const near = models[0] as { scene: Object3D };
549
+ // Each baked level replaces its part's geometry; the kit's material and the instances stay.
550
+ const chains = chainsOf(near, prop.kind);
551
+ for (const model of models.slice(1)) {
552
+ chainsOf(model, prop.kind).forEach((deeper, index) => {
553
+ const chain = chains[index];
554
+ if (chain !== undefined) chain.geometries.push(...deeper.geometries);
555
+ });
556
+ }
557
+ const propSalt = salt;
558
+ salt += 1;
559
+ // The bake leaves each prop where its own generator put it — a fern's fronds start 0.19 m under
560
+ // its origin, a stump's base 0.06 m over — so the prop is lifted by its own lowest point once
561
+ // the instance scale is known, and nothing floats or sinks.
562
+ const sunk = new Box3().setFromObject(near.scene).min.y;
563
+ const lift = Number.isFinite(sunk) ? -sunk : 0;
564
+ const field = new ScatterField3D({
565
+ // A tile draws once per part, so the floor takes tiles four times the default area: five
566
+ // fields at 16 m tiles add enough lone draws to tip the scene's projection to declining.
567
+ chunkSize: 32,
568
+ density: prop.density,
569
+ drawDistance: prop.drawDistance,
570
+ // The same zone the ground paints and the grass thins by: debris gathers at the foot of the
571
+ // old trees instead of sprinkling evenly over ground that is all grass.
572
+ getDensity: (x, z) => vale.floorZone(x, z),
573
+ getHeight: valeHeight,
574
+ parts: chains.map(({ geometries, material }) => ({ lods: geometries, material })),
575
+ place: (point, out) => {
576
+ if (!vale.clear(point.x, point.z, 0.9)) return false;
577
+ // Deadwood and litter gather at the foot of the old trees, so only the trunk itself is out of
578
+ // bounds: a prop half a metre from a trunk is the look, one inside it is a clipped mesh.
579
+ for (const tree of vale.trees)
580
+ if (Math.hypot(point.x - tree.x, point.z - tree.z) < tree.radius) return false;
581
+ out.x = point.x;
582
+ out.z = point.z;
583
+ out.yaw = jitter(point.x, point.z, propSalt) * Math.PI * 2;
584
+ out.scale =
585
+ prop.scale[0] + jitter(point.x, point.z, propSalt + 7) * (prop.scale[1] - prop.scale[0]);
586
+ out.y = point.y + lift * out.scale + 0.002;
587
+ return true;
588
+ },
589
+ farDensity: 0.45,
590
+ seed: seed + propSalt,
591
+ thinEnd: 24,
592
+ thinStart: 8,
593
+ });
594
+ field.name = `floor ${name}`;
595
+ fields.push(field);
596
+ group.add(field);
597
+ }
598
+ return {
599
+ fields,
600
+ group,
601
+ prewarm: () => {
602
+ for (const field of fields) field.prewarm();
603
+ },
604
+ update: (follow) => {
605
+ for (const field of fields) field.update(follow);
606
+ },
607
+ };
608
+ }
@@ -335,8 +335,8 @@ export function setupCamera(
335
335
  return yaw;
336
336
  },
337
337
  update(focus: Vector3, lock: ILockFrame | undefined, dt: number, watch?: Box3): void {
338
- const rate = 1 - Math.exp(-YAW_RATE * dt);
339
- const quick = 1 - Math.exp(-FRAME_RATE * dt);
338
+ const rate = MathUtils.damp(0, 1, YAW_RATE, dt);
339
+ const quick = MathUtils.damp(0, 1, FRAME_RATE, dt);
340
340
  if (lock !== undefined) {
341
341
  lock.bounds.getCenter(middle);
342
342
  const line = Math.atan2(focus.x - middle.x, focus.z - middle.z);
@@ -3,7 +3,7 @@
3
3
  // The vale's planting and its floor, an old misty forest built in code. Giant gnarled trees (a
4
4
  // twisted trunk with ridged bark, thick roots and limbs, moss on every upward face) under broad
5
5
  // crowns of leaf clumps that sway; far trees in a lighter cut; big lobed broadleaf plants, ferns,
6
- // purple and pink flowers and grass tufts; mossy boulders; an irregular flagstone path; a stream;
6
+ // purple and pink flowers; mossy boulders; an irregular flagstone path; a stream;
7
7
  // mushrooms and logs; ivy and vines on the cliff. Every kind is one `InstancedMesh`, so a forest
8
8
  // costs a few dozen draws and no light of its own. Nothing here is solid: `level/Vale.ts` decides
9
9
  // what blocks, and its height function is the floor everything here stands on.
@@ -20,11 +20,14 @@ import {
20
20
  ConeGeometry,
21
21
  CylinderGeometry,
22
22
  DoubleSide,
23
+ FrontSide,
23
24
  Group,
24
25
  IcosahedronGeometry,
25
26
  InstancedMesh,
26
27
  type Material,
28
+ MathUtils,
27
29
  Mesh,
30
+ MeshStandardMaterial,
28
31
  Object3D,
29
32
  OctahedronGeometry,
30
33
  SphereGeometry,
@@ -333,10 +336,19 @@ function limb(
333
336
  return tube;
334
337
  }
335
338
 
336
- /** Colours bark by its normal: moss on every face that looks up, bark below, darker at the foot. */
337
- export function mossBark(geometry: BufferGeometry, moss: number): BufferGeometry {
339
+ /**
340
+ * Colours bark by its normal: moss on every face that looks up, bark below, darker at the foot.
341
+ * `keepNormals` trusts the normals the geometry already carries instead of recomputing them, for a
342
+ * baked mesh: a recomputed normal on a two-centimetre triangle collapses to NaN, and the NaN lands
343
+ * in the vertex colours this function writes, where bloom carries it across the whole frame.
344
+ */
345
+ export function mossBark(
346
+ geometry: BufferGeometry,
347
+ moss: number,
348
+ keepNormals = false,
349
+ ): BufferGeometry {
338
350
  const g = geometry.index === null ? geometry : geometry.toNonIndexed();
339
- g.computeVertexNormals();
351
+ if (!keepNormals || g.attributes.normal === undefined) g.computeVertexNormals();
340
352
  const normal = g.attributes.normal;
341
353
  const position = g.attributes.position;
342
354
  if (normal === undefined || position === undefined) return g;
@@ -641,19 +653,8 @@ export function plantVale(site: IValeSite): {
641
653
  group.add(instanced(cluster(head), swaying(0.25), placements, false));
642
654
  }
643
655
 
644
- // Grass tufts in the open spaces off the path, where the canopy lets light in.
645
- const tufts: Placement[] = [];
646
- for (let i = 0; i < 340; i += 1) {
647
- // Half of them fringe the path, where the cobbles meet the moss.
648
- const z = clearing.north + rng() * (clearing.south - clearing.north);
649
- const x =
650
- i % 2 === 0
651
- ? site.pathX(z) + (rng() < 0.5 ? -1 : 1) * (1.75 + rng() * 1.4)
652
- : (rng() * 2 - 1) * clearing.half;
653
- if (Math.abs(x - site.pathX(z)) < 1.7 || site.stream.distance(x, z) < 1.4) continue;
654
- tufts.push(P(x, 0, z, 0.7 + rng() * 0.9, 0.6 + rng() * 0.9));
655
- }
656
- group.add(instanced(fan(4, 0.04, 0.42, 0.4, C.grassTip), swaying(0.6), tufts, false));
656
+ // The grass itself is streamed: `render/grass.ts` is its look, `GrassField3D` in `scenes/Play.ts`
657
+ // grows it.
657
658
 
658
659
  // Mushrooms in rings under the giants, fallen logs, and mossy boulders.
659
660
  const mushrooms: Placement[] = [];
@@ -1006,7 +1007,7 @@ export function valeGround(
1006
1007
  0.5 + 0.25 * (Math.sin(x * f + z * f * 0.55) + Math.sin(z * f * 1.4 - x * f * 0.37 + 1.3));
1007
1008
  const smooth = (a: number, b: number, t: number): number => {
1008
1009
  const u = Math.min(1, Math.max(0, (t - a) / (b - a)));
1009
- return u * u * (3 - 2 * u);
1010
+ return MathUtils.smoothstep(u, 0, 1);
1010
1011
  };
1011
1012
  const paintGround = (geometry: BufferGeometry): void => {
1012
1013
  const position = geometry.attributes.position;
@@ -1021,12 +1022,15 @@ export function valeGround(
1021
1022
  c.copy(soil).lerp(moss, 0.35 + 0.55 * smooth(0.35, 0.75, wave(x + 40, z - 17, 0.27)));
1022
1023
  c.lerp(mossBright, smooth(0.6, 0.85, wave(x - 3, z + 5, 0.45)) * 0.5);
1023
1024
  c.lerp(meadow, smooth(0.66, 0.82, wave(x * 0.7, z * 0.7 + 9, 0.21)) * 0.3);
1025
+ // Leaf litter and bare soil under the old trees. The same zone thins the grass and gathers the
1026
+ // scattered debris, so the ground the props stand on is the ground they are meant for.
1024
1027
  let nearTree = 0;
1025
1028
  for (const [tx, tz, ts] of site.trees) {
1026
1029
  const d = Math.hypot(x - tx, z - tz);
1027
- if (d < 5 * ts) nearTree = Math.max(nearTree, 1 - smooth(1.4 * ts, 4.5 * ts, d));
1030
+ nearTree = Math.max(nearTree, 1 - smooth(1.2 * ts, 4.2 * ts, d));
1028
1031
  }
1029
- c.lerp(litter, nearTree * 0.6 * (0.6 + 0.4 * wave(x, z, 0.9)));
1032
+ c.lerp(litter, nearTree * (0.62 + 0.34 * wave(x, z, 0.9)));
1033
+ c.lerp(soil, nearTree * 0.3);
1030
1034
  // Dark soil under the path, the flagstones on top of it.
1031
1035
  const off = Math.abs(x - site.pathX(z)) + (wave(x, z, 1.3) - 0.5) * 0.5;
1032
1036
  if (z > site.clearing.north - 9 && z < site.clearing.south + 1)
@@ -1070,3 +1074,43 @@ export function valeGround(
1070
1074
  meshes.inner.name = "vale-floor";
1071
1075
  return meshes;
1072
1076
  }
1077
+
1078
+ /** What a baked forest-floor part is, so it takes the matching look of the kit. */
1079
+ export type FloorKind = "frond" | "litter" | "wood";
1080
+
1081
+ /**
1082
+ * The forest floor in the kit's own look, tuned here and nowhere else. Wood (logs, stumps, twigs)
1083
+ * takes the old trees' mossy ridged bark, so a fallen log reads as one of them. Litter keeps the
1084
+ * bake's COLOR_0 times its base colour. A frond keeps Arbor's leaf atlas, cut out rather than
1085
+ * blended, exactly as the tree crowns are.
1086
+ */
1087
+ export function floorPart(
1088
+ mesh: Mesh,
1089
+ kind: FloorKind,
1090
+ ): { geometry: BufferGeometry; material: Material } {
1091
+ if (kind === "wood") {
1092
+ // The bake's own normals, never recomputed: see `mossBark`'s `keepNormals`.
1093
+ const baked = mesh.geometry.index === null ? mesh.geometry : mesh.geometry.toNonIndexed();
1094
+ return {
1095
+ // A little moss on the shoulders, never enough to paint a log the colour of the ground it
1096
+ // lies on: the debris has to read as deadwood, not as another patch of grass.
1097
+ geometry: mossBark(baked, 0.18, true),
1098
+ material: surfaced(0xffffff, "bark", { vertexColors: true }),
1099
+ };
1100
+ }
1101
+ const baked = mesh.material as MeshStandardMaterial;
1102
+ const frond = kind === "frond";
1103
+ return {
1104
+ geometry: mesh.geometry,
1105
+ material: new MeshStandardMaterial({
1106
+ // COLOR_0 is the bake's variation; the base colour is its tone, so both multiply.
1107
+ color: frond ? 0xffffff : baked.color,
1108
+ map: frond ? baked.map : null,
1109
+ metalness: 0,
1110
+ roughness: 0.9,
1111
+ side: frond ? DoubleSide : FrontSide,
1112
+ vertexColors: true,
1113
+ ...(frond ? { alphaTest: 0.45 } : {}),
1114
+ }),
1115
+ };
1116
+ }