create-threenative 0.2.9 → 0.2.12

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 (737) hide show
  1. package/agent-docs/references/assertion-reference.md +109 -3
  2. package/agent-docs/references/auto-exposure.md +28 -45
  3. package/agent-docs/references/build-profiles.md +1 -1
  4. package/agent-docs/references/capability-reference.md +527 -44
  5. package/agent-docs/references/debug-surface.md +64 -0
  6. package/agent-docs/references/finding-assets.md +11 -12
  7. package/agent-docs/references/performance-basics.md +19 -0
  8. package/agent-docs/references/trace-a-slow-frame.md +21 -0
  9. package/agent-docs/references/visual-baseline.md +23 -4
  10. package/agent-files/.agents/skills/ponytail/SKILL.md +1 -1
  11. package/agent-files/.agents/skills/prd-creator/SKILL.md +17 -6
  12. package/agent-files/.agents/skills/threenative-capabilities/SKILL.md +87 -23
  13. package/agent-files/.agents/skills/threenative-performance/SKILL.md +12 -11
  14. package/agent-files/.claude/hooks/ponytail-context.mjs +1 -1
  15. package/agent-files/scripts/reference.mjs +9 -4
  16. package/capabilities.json +739 -50
  17. package/dist/index.d.ts +40 -6
  18. package/dist/index.js +229 -36
  19. package/dist/quality.d.ts +12 -0
  20. package/dist/quality.js +166747 -0
  21. package/dist/threenative.js +60 -44
  22. package/dist/web-engine-gltf-loader.js +2 -0
  23. package/dist/web-engine-mesh-bvh-webgpu.js +1 -1
  24. package/dist/web-engine-mesh-bvh.js +7 -0
  25. package/dist/web-engine-post-effects.js +645 -19
  26. package/dist/web-engine-runtime.js +3528 -343
  27. package/package.json +19 -9
  28. package/template-assets/assets/bay-PROVENANCE.md +21 -0
  29. package/template-assets/assets/bay-ground.webp +0 -0
  30. package/template-assets/assets/bay-metal.webp +0 -0
  31. package/template-assets/assets/bay-pavement-normal.webp +0 -0
  32. package/template-assets/assets/bay-pavement.webp +0 -0
  33. package/template-assets/assets/bay-plaster-normal.webp +0 -0
  34. package/template-assets/assets/bay-plaster.webp +0 -0
  35. package/template-assets/assets/bay-wood-normal.webp +0 -0
  36. package/template-assets/assets/bay-wood.webp +0 -0
  37. package/template-assets/assets/tex-PROVENANCE.md +25 -0
  38. package/template-assets/assets/tex-bark-normal.webp +0 -0
  39. package/template-assets/assets/tex-bark.webp +0 -0
  40. package/template-assets/assets/tex-birch-bark.webp +0 -0
  41. package/template-assets/assets/tex-grass.webp +0 -0
  42. package/template-assets/assets/tex-planks-normal.webp +0 -0
  43. package/template-assets/assets/tex-planks.webp +0 -0
  44. package/template-assets/assets/tex-rock-normal.webp +0 -0
  45. package/template-assets/assets/tex-rock.webp +0 -0
  46. package/template-assets/assets/tex-roof-tiles-normal.webp +0 -0
  47. package/template-assets/assets/tex-roof-tiles.webp +0 -0
  48. package/template-assets/assets/tex-sand-normal.webp +0 -0
  49. package/template-assets/assets/tex-sand.webp +0 -0
  50. package/template-assets/assets/tex-stone-wall-normal.webp +0 -0
  51. package/template-assets/assets/tex-stone-wall.webp +0 -0
  52. package/template-assets/kitExposure.ts +20 -0
  53. package/template-assets/patches/three@0.185.1.patch +481 -272
  54. package/template-assets/quality/biome.json +7 -0
  55. package/template-assets/quality/eslint.config.js +3 -0
  56. package/template-assets/realistic-ocean/README.md +113 -0
  57. package/template-assets/realistic-ocean/install.mjs +56 -0
  58. package/template-assets/realistic-ocean/src/realisticOcean.ts +151 -0
  59. package/template-assets/realistic-ocean/src/realisticOceanLifetime.ts +29 -0
  60. package/template-assets/realistic-ocean/src/render/REALISTIC-OCEAN-LICENSE.txt +25 -0
  61. package/template-assets/realistic-ocean/src/render/realisticSea.ts +642 -0
  62. package/template-assets/realistic-ocean/src/render/realisticSeaMaps.ts +311 -0
  63. package/template-assets/realistic-ocean/src/render/realisticSpectrum.ts +289 -0
  64. package/templates/AGENTS.md +21 -0
  65. package/templates/CLAUDE.md +23 -0
  66. package/templates/action-rpg/.codex/config.toml +6 -2
  67. package/templates/action-rpg/.cursor/mcp.json +8 -2
  68. package/templates/action-rpg/.gemini/settings.json +8 -2
  69. package/templates/action-rpg/.mcp.json +8 -2
  70. package/templates/action-rpg/.vscode/mcp.json +9 -2
  71. package/templates/action-rpg/.zed/settings.json +9 -2
  72. package/templates/action-rpg/AGENTS.md +11 -11
  73. package/templates/action-rpg/CLAUDE.md +11 -11
  74. package/templates/action-rpg/opencode.json +10 -2
  75. package/templates/action-rpg/package.json +17 -11
  76. package/templates/action-rpg/playtests/combat.playtest.json +6 -0
  77. package/templates/action-rpg/playtests/inventory.playtest.json +22 -0
  78. package/templates/action-rpg/playtests/performance.playtest.json +1 -1
  79. package/templates/action-rpg/playtests/roll.playtest.json +112 -0
  80. package/templates/action-rpg/playtests/swing.playtest.json +55 -0
  81. package/templates/action-rpg/playtests/win.playtest.json +4 -4
  82. package/templates/action-rpg/src/entities/Fighter.ts +44 -4
  83. package/templates/action-rpg/src/entities/Player.ts +64 -12
  84. package/templates/action-rpg/src/render/atmosphere.ts +444 -0
  85. package/templates/action-rpg/src/render/backlightMaterial.ts +49 -18
  86. package/templates/action-rpg/src/render/clouds.ts +605 -0
  87. package/templates/action-rpg/src/render/dungeon.ts +8 -6
  88. package/templates/action-rpg/src/render/exposure.ts +11 -109
  89. package/templates/action-rpg/src/render/gpuSky.ts +752 -0
  90. package/templates/action-rpg/src/render/lighting.ts +27 -4
  91. package/templates/action-rpg/src/render/materialLighting.ts +2 -11
  92. package/templates/action-rpg/src/render/palette.ts +1 -0
  93. package/templates/action-rpg/src/render/postprocessing.ts +4 -4
  94. package/templates/action-rpg/src/render/props.ts +10 -8
  95. package/templates/action-rpg/src/render/quality.ts +56 -108
  96. package/templates/action-rpg/src/render/sky.ts +74 -1
  97. package/templates/action-rpg/src/scenes/Play.ts +16 -12
  98. package/templates/action-rpg/src/ui/CharacterPanel.tsx +7 -2
  99. package/templates/action-rpg/src/ui/Hud.tsx +5 -7
  100. package/templates/action-rpg/src/ui/InventoryPanel.tsx +14 -14
  101. package/templates/action-rpg/threenative.config.ts +3 -0
  102. package/templates/adventure/.codex/config.toml +23 -0
  103. package/templates/adventure/.cursor/mcp.json +38 -0
  104. package/templates/adventure/.gemini/settings.json +38 -0
  105. package/templates/adventure/.mcp.json +38 -0
  106. package/templates/adventure/.vscode/mcp.json +43 -0
  107. package/templates/adventure/.zed/settings.json +43 -0
  108. package/templates/adventure/AGENTS.md +60 -0
  109. package/templates/adventure/CLAUDE.md +62 -0
  110. package/templates/adventure/index.html +14 -0
  111. package/templates/adventure/kit.json +8 -0
  112. package/templates/adventure/native-playtests/survives.playtest.json +52 -0
  113. package/templates/adventure/opencode.json +49 -0
  114. package/templates/adventure/package.json +65 -0
  115. package/templates/adventure/playtests/boss.playtest.json +406 -0
  116. package/templates/adventure/playtests/combat.playtest.json +342 -0
  117. package/templates/adventure/playtests/controls.playtest.json +142 -0
  118. package/templates/adventure/playtests/explore.playtest.json +45 -0
  119. package/templates/adventure/playtests/flicker.playtest.json +206 -0
  120. package/templates/adventure/playtests/hearts.playtest.json +171 -0
  121. package/templates/adventure/playtests/lockon.playtest.json +256 -0
  122. package/templates/adventure/playtests/look.playtest.json +72 -0
  123. package/templates/adventure/playtests/move-hollow.playtest.json +106 -0
  124. package/templates/adventure/playtests/move.playtest.json +84 -0
  125. package/templates/adventure/playtests/performance.playtest.json +55 -0
  126. package/templates/adventure/playtests/puzzle.playtest.json +250 -0
  127. package/templates/adventure/playtests/stride.playtest.json +67 -0
  128. package/templates/adventure/playtests/survives.playtest.json +171 -0
  129. package/templates/adventure/playtests/thornback.playtest.json +267 -0
  130. package/templates/adventure/public/favicon.svg +4 -0
  131. package/templates/adventure/src/entities/Block.ts +114 -0
  132. package/templates/adventure/src/entities/Chest.ts +69 -0
  133. package/templates/adventure/src/entities/Door.ts +81 -0
  134. package/templates/adventure/src/entities/Dummy.ts +69 -0
  135. package/templates/adventure/src/entities/Flicker.ts +239 -0
  136. package/templates/adventure/src/entities/Hero.ts +561 -0
  137. package/templates/adventure/src/entities/LockOn.ts +180 -0
  138. package/templates/adventure/src/entities/Mossling.ts +249 -0
  139. package/templates/adventure/src/entities/Switch.ts +49 -0
  140. package/templates/adventure/src/entities/Thornback.ts +238 -0
  141. package/templates/adventure/src/entities/Warden.ts +196 -0
  142. package/templates/adventure/src/game.ts +65 -0
  143. package/templates/adventure/src/interact.ts +63 -0
  144. package/templates/adventure/src/level/Hollow.ts +240 -0
  145. package/templates/adventure/src/level/Vale.ts +383 -0
  146. package/templates/adventure/src/main.ts +18 -0
  147. package/templates/adventure/src/render/camera.ts +416 -0
  148. package/templates/adventure/src/render/creatures.ts +405 -0
  149. package/templates/adventure/src/render/effects.ts +333 -0
  150. package/templates/adventure/src/render/foliage.ts +1072 -0
  151. package/templates/adventure/src/render/hero.ts +1447 -0
  152. package/templates/adventure/src/render/kitExposure.ts +20 -0
  153. package/templates/adventure/src/render/lighting.ts +74 -0
  154. package/templates/adventure/src/render/loading.ts +332 -0
  155. package/templates/adventure/src/render/materials.ts +179 -0
  156. package/templates/adventure/src/render/palette.ts +137 -0
  157. package/templates/adventure/src/render/postprocessing.ts +70 -0
  158. package/templates/adventure/src/render/props.ts +383 -0
  159. package/templates/adventure/src/render/quality.ts +46 -0
  160. package/templates/adventure/src/render/sky.ts +271 -0
  161. package/templates/adventure/src/render/surface.ts +259 -0
  162. package/templates/adventure/src/render/touch-controls.ts +137 -0
  163. package/templates/adventure/src/scenes/Play.ts +959 -0
  164. package/templates/adventure/src/state.ts +113 -0
  165. package/templates/adventure/src/style.css +98 -0
  166. package/templates/adventure/src/ui/App.tsx +22 -0
  167. package/templates/adventure/src/ui/GameUi.tsx +20 -0
  168. package/templates/adventure/src/ui/Hud.tsx +70 -0
  169. package/templates/adventure/src/ui/Menu.tsx +15 -0
  170. package/templates/adventure/src/ui/main.tsx +14 -0
  171. package/templates/adventure/tailwind.config.ts +2 -0
  172. package/templates/adventure/threenative.config.ts +62 -0
  173. package/templates/adventure/tsconfig.json +17 -0
  174. package/templates/adventure/vite.config.ts +49 -0
  175. package/templates/collectathon/.codex/config.toml +23 -0
  176. package/templates/collectathon/.cursor/mcp.json +38 -0
  177. package/templates/collectathon/.gemini/settings.json +38 -0
  178. package/templates/collectathon/.mcp.json +38 -0
  179. package/templates/collectathon/.vscode/mcp.json +43 -0
  180. package/templates/collectathon/.zed/settings.json +43 -0
  181. package/templates/collectathon/AGENTS.md +58 -0
  182. package/templates/collectathon/CLAUDE.md +60 -0
  183. package/templates/collectathon/index.html +14 -0
  184. package/templates/collectathon/kit.json +8 -0
  185. package/templates/collectathon/native-playtests/survives.playtest.json +52 -0
  186. package/templates/collectathon/opencode.json +49 -0
  187. package/templates/collectathon/package.json +65 -0
  188. package/templates/collectathon/playtests/acrobatics.playtest.json +238 -0
  189. package/templates/collectathon/playtests/camera.playtest.json +80 -0
  190. package/templates/collectathon/playtests/clipped-probe.playtest.json +101 -0
  191. package/templates/collectathon/playtests/collect.playtest.json +196 -0
  192. package/templates/collectathon/playtests/combat.playtest.json +246 -0
  193. package/templates/collectathon/playtests/double-tap-air.playtest.json +198 -0
  194. package/templates/collectathon/playtests/double-tap.playtest.json +136 -0
  195. package/templates/collectathon/playtests/effects.playtest.json +124 -0
  196. package/templates/collectathon/playtests/enemies.playtest.json +295 -0
  197. package/templates/collectathon/playtests/explore.playtest.json +45 -0
  198. package/templates/collectathon/playtests/hop-reach.playtest.json +117 -0
  199. package/templates/collectathon/playtests/jump-chain.playtest.json +274 -0
  200. package/templates/collectathon/playtests/ledge-angle.playtest.json +107 -0
  201. package/templates/collectathon/playtests/ledge-too-high.playtest.json +115 -0
  202. package/templates/collectathon/playtests/ledge.playtest.json +100 -0
  203. package/templates/collectathon/playtests/look.playtest.json +64 -0
  204. package/templates/collectathon/playtests/performance.playtest.json +55 -0
  205. package/templates/collectathon/playtests/stride.playtest.json +111 -0
  206. package/templates/collectathon/playtests/survives.playtest.json +123 -0
  207. package/templates/collectathon/playtests/telegraphs.playtest.json +132 -0
  208. package/templates/collectathon/playtests/thornback.playtest.json +157 -0
  209. package/templates/collectathon/playtests/wall-kick.playtest.json +206 -0
  210. package/templates/collectathon/playtests/win.playtest.json +166 -0
  211. package/templates/collectathon/public/favicon.svg +4 -0
  212. package/templates/collectathon/src/entities/Hero.ts +915 -0
  213. package/templates/collectathon/src/entities/Pickup.ts +63 -0
  214. package/templates/collectathon/src/entities/Walker.ts +248 -0
  215. package/templates/collectathon/src/game.ts +51 -0
  216. package/templates/collectathon/src/level/Course.ts +590 -0
  217. package/templates/collectathon/src/level/terrain.ts +144 -0
  218. package/templates/collectathon/src/main.ts +14 -0
  219. package/templates/collectathon/src/playtest-events.ts +15 -0
  220. package/templates/collectathon/src/render/camera.ts +163 -0
  221. package/templates/collectathon/src/render/castle.ts +408 -0
  222. package/templates/collectathon/src/render/effects.ts +284 -0
  223. package/templates/collectathon/src/render/foliage.ts +744 -0
  224. package/templates/collectathon/src/render/ground.ts +139 -0
  225. package/templates/collectathon/src/render/hero.ts +452 -0
  226. package/templates/collectathon/src/render/kitExposure.ts +20 -0
  227. package/templates/collectathon/src/render/lighting.ts +65 -0
  228. package/templates/collectathon/src/render/loading.ts +332 -0
  229. package/templates/collectathon/src/render/materials.ts +196 -0
  230. package/templates/collectathon/src/render/palette.ts +82 -0
  231. package/templates/collectathon/src/render/postprocessing.ts +79 -0
  232. package/templates/collectathon/src/render/props.ts +218 -0
  233. package/templates/collectathon/src/render/quality.ts +54 -0
  234. package/templates/collectathon/src/render/sky.ts +262 -0
  235. package/templates/collectathon/src/render/surface.ts +269 -0
  236. package/templates/collectathon/src/render/touch-controls.ts +179 -0
  237. package/templates/collectathon/src/render/touch-layout.ts +48 -0
  238. package/templates/collectathon/src/render/water.ts +191 -0
  239. package/templates/collectathon/src/scenes/Play.ts +481 -0
  240. package/templates/collectathon/src/state.ts +38 -0
  241. package/templates/collectathon/src/style.css +106 -0
  242. package/templates/collectathon/src/ui/App.tsx +22 -0
  243. package/templates/collectathon/src/ui/GameUi.tsx +20 -0
  244. package/templates/collectathon/src/ui/Hud.tsx +77 -0
  245. package/templates/collectathon/src/ui/Menu.tsx +13 -0
  246. package/templates/collectathon/src/ui/main.tsx +14 -0
  247. package/templates/collectathon/tailwind.config.ts +2 -0
  248. package/templates/collectathon/threenative.config.ts +62 -0
  249. package/templates/collectathon/tsconfig.json +17 -0
  250. package/templates/collectathon/vite.config.ts +49 -0
  251. package/templates/kart/.codex/config.toml +23 -0
  252. package/templates/kart/.cursor/mcp.json +38 -0
  253. package/templates/kart/.gemini/settings.json +38 -0
  254. package/templates/kart/.mcp.json +38 -0
  255. package/templates/kart/.vscode/mcp.json +43 -0
  256. package/templates/kart/.zed/settings.json +43 -0
  257. package/templates/kart/AGENTS.md +58 -0
  258. package/templates/kart/CLAUDE.md +60 -0
  259. package/templates/kart/index.html +14 -0
  260. package/templates/kart/kit.json +8 -0
  261. package/templates/kart/native-playtests/survives.playtest.json +65 -0
  262. package/templates/kart/opencode.json +49 -0
  263. package/templates/kart/package.json +64 -0
  264. package/templates/kart/playtests/drift.playtest.json +226 -0
  265. package/templates/kart/playtests/explore.playtest.json +45 -0
  266. package/templates/kart/playtests/hit-stays-above-road.playtest.json +92 -0
  267. package/templates/kart/playtests/item-key.playtest.json +108 -0
  268. package/templates/kart/playtests/items.playtest.json +143 -0
  269. package/templates/kart/playtests/lap-times.playtest.json +138 -0
  270. package/templates/kart/playtests/laps.playtest.json +149 -0
  271. package/templates/kart/playtests/performance.playtest.json +57 -0
  272. package/templates/kart/playtests/race.playtest.json +294 -0
  273. package/templates/kart/playtests/restart.playtest.json +87 -0
  274. package/templates/kart/playtests/rocket-start.playtest.json +56 -0
  275. package/templates/kart/playtests/smooth-drive.playtest.json +101 -0
  276. package/templates/kart/playtests/surfaces.playtest.json +113 -0
  277. package/templates/kart/playtests/survives.playtest.json +116 -0
  278. package/templates/kart/playtests/wall.playtest.json +118 -0
  279. package/templates/kart/public/favicon.svg +4 -0
  280. package/templates/kart/src/entities/Driver.ts +123 -0
  281. package/templates/kart/src/entities/Items.ts +194 -0
  282. package/templates/kart/src/entities/Kart.ts +517 -0
  283. package/templates/kart/src/game.ts +45 -0
  284. package/templates/kart/src/main.ts +14 -0
  285. package/templates/kart/src/playtest-events.ts +15 -0
  286. package/templates/kart/src/render/camera.ts +83 -0
  287. package/templates/kart/src/render/course.ts +579 -0
  288. package/templates/kart/src/render/effects.ts +266 -0
  289. package/templates/kart/src/render/items.ts +163 -0
  290. package/templates/kart/src/render/kart.ts +256 -0
  291. package/templates/kart/src/render/kitExposure.ts +20 -0
  292. package/templates/kart/src/render/lighting.ts +58 -0
  293. package/templates/kart/src/render/loading.ts +332 -0
  294. package/templates/kart/src/render/materials.ts +119 -0
  295. package/templates/kart/src/render/palette.ts +74 -0
  296. package/templates/kart/src/render/postprocessing.ts +79 -0
  297. package/templates/kart/src/render/quality.ts +54 -0
  298. package/templates/kart/src/render/skids.ts +86 -0
  299. package/templates/kart/src/render/sky.ts +105 -0
  300. package/templates/kart/src/render/touch-controls.ts +168 -0
  301. package/templates/kart/src/render/touch-layout.ts +48 -0
  302. package/templates/kart/src/scenes/Race.ts +850 -0
  303. package/templates/kart/src/state.ts +53 -0
  304. package/templates/kart/src/style.css +106 -0
  305. package/templates/kart/src/track/Course.ts +276 -0
  306. package/templates/kart/src/track/Race.ts +133 -0
  307. package/templates/kart/src/ui/App.tsx +21 -0
  308. package/templates/kart/src/ui/GameUi.tsx +20 -0
  309. package/templates/kart/src/ui/Hud.tsx +172 -0
  310. package/templates/kart/src/ui/Menu.tsx +13 -0
  311. package/templates/kart/src/ui/main.tsx +14 -0
  312. package/templates/kart/tailwind.config.ts +2 -0
  313. package/templates/kart/threenative.config.ts +62 -0
  314. package/templates/kart/tsconfig.json +17 -0
  315. package/templates/kart/vite.config.ts +49 -0
  316. package/templates/minimal/.codex/config.toml +6 -2
  317. package/templates/minimal/.cursor/mcp.json +8 -2
  318. package/templates/minimal/.gemini/settings.json +8 -2
  319. package/templates/minimal/.mcp.json +8 -2
  320. package/templates/minimal/.vscode/mcp.json +9 -2
  321. package/templates/minimal/.zed/settings.json +9 -2
  322. package/templates/minimal/AGENTS.md +11 -13
  323. package/templates/minimal/CLAUDE.md +11 -13
  324. package/templates/minimal/opencode.json +10 -2
  325. package/templates/minimal/package.json +16 -10
  326. package/templates/minimal/playtests/camera-wall.playtest.json +36 -0
  327. package/templates/minimal/playtests/jump.playtest.json +45 -0
  328. package/templates/minimal/playtests/play.playtest.json +1 -1
  329. package/templates/minimal/src/game.ts +2 -0
  330. package/templates/minimal/src/render/atmosphere.ts +444 -0
  331. package/templates/minimal/src/render/backlightMaterial.ts +49 -18
  332. package/templates/minimal/src/render/camera.ts +35 -4
  333. package/templates/minimal/src/render/clouds.ts +605 -0
  334. package/templates/minimal/src/render/exposure.ts +7 -111
  335. package/templates/minimal/src/render/gpuSky.ts +752 -0
  336. package/templates/minimal/src/render/lighting.ts +26 -4
  337. package/templates/minimal/src/render/materialLighting.ts +2 -10
  338. package/templates/minimal/src/render/postprocessing.ts +4 -4
  339. package/templates/minimal/src/render/quality.ts +10 -116
  340. package/templates/minimal/src/render/sky.ts +73 -1
  341. package/templates/minimal/src/scenes/Play.ts +18 -7
  342. package/templates/platformer/.codex/config.toml +6 -2
  343. package/templates/platformer/.cursor/mcp.json +8 -2
  344. package/templates/platformer/.gemini/settings.json +8 -2
  345. package/templates/platformer/.mcp.json +8 -2
  346. package/templates/platformer/.vscode/mcp.json +9 -2
  347. package/templates/platformer/.zed/settings.json +9 -2
  348. package/templates/platformer/AGENTS.md +13 -9
  349. package/templates/platformer/CLAUDE.md +13 -9
  350. package/templates/platformer/opencode.json +10 -2
  351. package/templates/platformer/package.json +17 -11
  352. package/templates/platformer/playtests/dash-jump.playtest.json +34 -0
  353. package/templates/platformer/playtests/finish.playtest.json +58 -0
  354. package/templates/platformer/playtests/idle.playtest.json +44 -0
  355. package/templates/platformer/playtests/performance.playtest.json +1 -1
  356. package/templates/platformer/src/entities/Fox.ts +19 -6
  357. package/templates/platformer/src/game.ts +1 -0
  358. package/templates/platformer/src/level/Stage.ts +4 -1
  359. package/templates/platformer/src/render/backlightMaterial.ts +49 -18
  360. package/templates/platformer/src/render/camera.ts +30 -1
  361. package/templates/platformer/src/render/exposure.ts +6 -111
  362. package/templates/platformer/src/render/fox.ts +5 -2
  363. package/templates/platformer/src/render/kitExposure.ts +20 -0
  364. package/templates/platformer/src/render/materialLighting.ts +2 -11
  365. package/templates/platformer/src/render/postprocessing.ts +4 -4
  366. package/templates/platformer/src/render/props.ts +1 -2
  367. package/templates/platformer/src/render/quality.ts +10 -118
  368. package/templates/platformer/src/scenes/Play.ts +31 -15
  369. package/templates/platformer/src/ui/Menu.tsx +1 -1
  370. package/templates/puzzle/.codex/config.toml +6 -2
  371. package/templates/puzzle/.cursor/mcp.json +8 -2
  372. package/templates/puzzle/.gemini/settings.json +8 -2
  373. package/templates/puzzle/.mcp.json +8 -2
  374. package/templates/puzzle/.vscode/mcp.json +9 -2
  375. package/templates/puzzle/.zed/settings.json +9 -2
  376. package/templates/puzzle/AGENTS.md +14 -17
  377. package/templates/puzzle/CLAUDE.md +14 -17
  378. package/templates/puzzle/opencode.json +10 -2
  379. package/templates/puzzle/package.json +17 -11
  380. package/templates/puzzle/playtests/performance.playtest.json +1 -1
  381. package/templates/puzzle/playtests/replay-keeps-progress.playtest.json +78 -0
  382. package/templates/puzzle/src/render/backlightMaterial.ts +49 -18
  383. package/templates/puzzle/src/render/exposure.ts +11 -109
  384. package/templates/puzzle/src/render/lighting.ts +3 -3
  385. package/templates/puzzle/src/render/materialLighting.ts +2 -11
  386. package/templates/puzzle/src/render/palette.ts +1 -1
  387. package/templates/puzzle/src/render/postprocessing.ts +4 -4
  388. package/templates/puzzle/src/render/quality.ts +44 -153
  389. package/templates/puzzle/src/render/vault.ts +18 -6
  390. package/templates/puzzle/src/scenes/Play.ts +6 -1
  391. package/templates/puzzle/src/ui/Hud.tsx +8 -43
  392. package/templates/racing/.codex/config.toml +6 -2
  393. package/templates/racing/.cursor/mcp.json +8 -2
  394. package/templates/racing/.gemini/settings.json +8 -2
  395. package/templates/racing/.mcp.json +8 -2
  396. package/templates/racing/.vscode/mcp.json +9 -2
  397. package/templates/racing/.zed/settings.json +9 -2
  398. package/templates/racing/AGENTS.md +10 -12
  399. package/templates/racing/CLAUDE.md +10 -12
  400. package/templates/racing/opencode.json +10 -2
  401. package/templates/racing/package.json +17 -11
  402. package/templates/racing/playtests/brake.playtest.json +54 -0
  403. package/templates/racing/playtests/outcome.playtest.json +19 -0
  404. package/templates/racing/playtests/performance.playtest.json +1 -1
  405. package/templates/racing/playtests/stopped-car-is-not-rescued.playtest.json +59 -0
  406. package/templates/racing/src/entities/RacingCar.ts +12 -3
  407. package/templates/racing/src/entities/Rival.ts +11 -2
  408. package/templates/racing/src/render/atmosphere.ts +444 -0
  409. package/templates/racing/src/render/backlightMaterial.ts +49 -18
  410. package/templates/racing/src/render/clouds.ts +605 -0
  411. package/templates/racing/src/render/exposure.ts +6 -111
  412. package/templates/racing/src/render/gpuSky.ts +752 -0
  413. package/templates/racing/src/render/kitExposure.ts +20 -0
  414. package/templates/racing/src/render/lighting.ts +26 -4
  415. package/templates/racing/src/render/materialLighting.ts +2 -11
  416. package/templates/racing/src/render/materials.ts +2 -1
  417. package/templates/racing/src/render/postprocessing.ts +4 -4
  418. package/templates/racing/src/render/quality.ts +27 -115
  419. package/templates/racing/src/render/sky.ts +76 -5
  420. package/templates/racing/src/scenes/Race.ts +53 -42
  421. package/templates/racing/src/track/TrackSector.ts +5 -2
  422. package/templates/racing/src/ui/Hud.tsx +12 -7
  423. package/templates/rain/.codex/config.toml +6 -2
  424. package/templates/rain/.cursor/mcp.json +8 -2
  425. package/templates/rain/.gemini/settings.json +8 -2
  426. package/templates/rain/.mcp.json +8 -2
  427. package/templates/rain/.vscode/mcp.json +9 -2
  428. package/templates/rain/.zed/settings.json +9 -2
  429. package/templates/rain/AGENTS.md +12 -12
  430. package/templates/rain/CLAUDE.md +12 -12
  431. package/templates/rain/opencode.json +10 -2
  432. package/templates/rain/package.json +16 -10
  433. package/templates/rain/playtests/performance.playtest.json +1 -1
  434. package/templates/rain/src/game.ts +1 -1
  435. package/templates/rain/src/render/bloom-shader.ts +1 -1
  436. package/templates/rain/src/render/clouds-shader.ts +2 -2
  437. package/templates/rain/src/render/clouds.ts +2 -1
  438. package/templates/rain/src/render/exposure.ts +11 -109
  439. package/templates/rain/src/render/post-shader.ts +7 -11
  440. package/templates/rain/src/render/postprocessing.ts +8 -24
  441. package/templates/rain/src/render/quality.ts +44 -98
  442. package/templates/rain/src/render/world-shader.ts +281 -97
  443. package/templates/rain/src/render/world.ts +82 -2
  444. package/templates/rain/src/style.css +1 -1
  445. package/templates/rain/src/ui/GameUi.tsx +6 -2
  446. package/templates/rain/src/ui/Hud.tsx +1 -1
  447. package/templates/rain/tools/generate-shaders.mjs +2 -2
  448. package/templates/rain/tools/tempest-post.frag +4 -6
  449. package/templates/rain/tools/tempest-world.frag +80 -12
  450. package/templates/rts/.codex/config.toml +6 -2
  451. package/templates/rts/.cursor/mcp.json +8 -2
  452. package/templates/rts/.gemini/settings.json +8 -2
  453. package/templates/rts/.mcp.json +8 -2
  454. package/templates/rts/.vscode/mcp.json +9 -2
  455. package/templates/rts/.zed/settings.json +9 -2
  456. package/templates/rts/AGENTS.md +15 -16
  457. package/templates/rts/CLAUDE.md +15 -16
  458. package/templates/rts/opencode.json +10 -2
  459. package/templates/rts/package.json +16 -10
  460. package/templates/rts/playtests/performance.playtest.json +1 -1
  461. package/templates/rts/playtests/rts-attack.playtest.json +5 -0
  462. package/templates/rts/playtests/rts-build.playtest.json +20 -1
  463. package/templates/rts/playtests/rts-orders.playtest.json +1 -1
  464. package/templates/rts/playtests/rts-pause.playtest.json +112 -0
  465. package/templates/rts/playtests/rts-train.playtest.json +1 -1
  466. package/templates/rts/playtests/rts-zoom.playtest.json +81 -0
  467. package/templates/rts/src/game.ts +29 -7
  468. package/templates/rts/src/render/army.ts +181 -49
  469. package/templates/rts/src/render/backlightMaterial.ts +49 -18
  470. package/templates/rts/src/render/environment.ts +276 -0
  471. package/templates/rts/src/render/exposure.ts +3 -65
  472. package/templates/rts/src/render/ground.ts +478 -0
  473. package/templates/rts/src/render/lighting.ts +62 -11
  474. package/templates/rts/src/render/materialLighting.ts +2 -11
  475. package/templates/rts/src/render/materials.ts +47 -118
  476. package/templates/rts/src/render/palette.ts +30 -13
  477. package/templates/rts/src/render/picking.ts +18 -0
  478. package/templates/rts/src/render/postprocessing.ts +4 -4
  479. package/templates/rts/src/render/quality.ts +64 -85
  480. package/templates/rts/src/render/resources.ts +21 -22
  481. package/templates/rts/src/render/sky.ts +9 -12
  482. package/templates/rts/src/render/terrain.ts +36 -11
  483. package/templates/rts/src/scenes/Play.ts +373 -38
  484. package/templates/rts/src/sim/ai.ts +0 -11
  485. package/templates/rts/src/state.ts +46 -0
  486. package/templates/rts/src/style.css +1543 -0
  487. package/templates/rts/src/ui/Commands.tsx +204 -107
  488. package/templates/rts/src/ui/GameUi.tsx +12 -5
  489. package/templates/rts/src/ui/Hud.tsx +611 -116
  490. package/templates/rts/src/ui/Minimap.tsx +103 -37
  491. package/templates/rts/src/ui/icons.tsx +116 -0
  492. package/templates/rts/src/ui/labels.ts +73 -0
  493. package/templates/rts/src/ui/minimapPoint.ts +30 -0
  494. package/templates/rts/threenative.config.ts +1 -1
  495. package/templates/runner/.codex/config.toml +6 -2
  496. package/templates/runner/.cursor/mcp.json +8 -2
  497. package/templates/runner/.gemini/settings.json +8 -2
  498. package/templates/runner/.mcp.json +8 -2
  499. package/templates/runner/.vscode/mcp.json +9 -2
  500. package/templates/runner/.zed/settings.json +9 -2
  501. package/templates/runner/AGENTS.md +12 -12
  502. package/templates/runner/CLAUDE.md +12 -12
  503. package/templates/runner/opencode.json +10 -2
  504. package/templates/runner/package.json +17 -11
  505. package/templates/runner/playtests/near-miss.playtest.json +48 -0
  506. package/templates/runner/playtests/performance.playtest.json +2 -2
  507. package/templates/runner/playtests/stride.playtest.json +27 -0
  508. package/templates/runner/playtests/survives.playtest.json +2 -2
  509. package/templates/runner/src/conventions.ts +3 -1
  510. package/templates/runner/src/entities/Runner.ts +11 -5
  511. package/templates/runner/src/render/atmosphere.ts +444 -0
  512. package/templates/runner/src/render/backlightMaterial.ts +49 -18
  513. package/templates/runner/src/render/clouds.ts +605 -0
  514. package/templates/runner/src/render/exposure.ts +6 -111
  515. package/templates/runner/src/render/gpuSky.ts +752 -0
  516. package/templates/runner/src/render/kitExposure.ts +20 -0
  517. package/templates/runner/src/render/lighting.ts +26 -4
  518. package/templates/runner/src/render/materialLighting.ts +2 -11
  519. package/templates/runner/src/render/postprocessing.ts +4 -4
  520. package/templates/runner/src/render/quality.ts +26 -114
  521. package/templates/runner/src/render/sky.ts +73 -1
  522. package/templates/runner/src/scenes/Run.ts +19 -15
  523. package/templates/runner/src/track.ts +12 -3
  524. package/templates/sailing/.codex/config.toml +6 -2
  525. package/templates/sailing/.cursor/mcp.json +8 -2
  526. package/templates/sailing/.gemini/settings.json +8 -2
  527. package/templates/sailing/.mcp.json +8 -2
  528. package/templates/sailing/.vscode/mcp.json +9 -2
  529. package/templates/sailing/.zed/settings.json +9 -2
  530. package/templates/sailing/AGENTS.md +10 -11
  531. package/templates/sailing/CLAUDE.md +10 -11
  532. package/templates/sailing/opencode.json +10 -2
  533. package/templates/sailing/package.json +17 -11
  534. package/templates/sailing/playtests/fail.playtest.json +46 -5
  535. package/templates/sailing/playtests/float-after-the-run-ends.playtest.json +7 -0
  536. package/templates/sailing/playtests/performance.playtest.json +1 -1
  537. package/templates/sailing/src/game.ts +1 -0
  538. package/templates/sailing/src/render/backlightMaterial.ts +49 -18
  539. package/templates/sailing/src/render/exposure.ts +6 -111
  540. package/templates/sailing/src/render/kitExposure.ts +20 -0
  541. package/templates/sailing/src/render/materialLighting.ts +2 -11
  542. package/templates/sailing/src/render/ocean.ts +0 -1
  543. package/templates/sailing/src/render/postprocessing.ts +4 -4
  544. package/templates/sailing/src/render/quality.ts +31 -138
  545. package/templates/sailing/src/scenes/Sailing.ts +12 -4
  546. package/templates/sailing/src/ui/Hud.tsx +6 -2
  547. package/templates/sailing/src/ui/Menu.tsx +1 -1
  548. package/templates/shooter/.codex/config.toml +6 -2
  549. package/templates/shooter/.cursor/mcp.json +8 -2
  550. package/templates/shooter/.gemini/settings.json +8 -2
  551. package/templates/shooter/.mcp.json +8 -2
  552. package/templates/shooter/.vscode/mcp.json +9 -2
  553. package/templates/shooter/.zed/settings.json +9 -2
  554. package/templates/shooter/AGENTS.md +13 -12
  555. package/templates/shooter/CLAUDE.md +13 -12
  556. package/templates/shooter/index.html +1 -1
  557. package/templates/shooter/main.html +13 -0
  558. package/templates/shooter/opencode.json +10 -2
  559. package/templates/shooter/package.json +17 -11
  560. package/templates/shooter/playtests/breakable-shatters.playtest.json +6 -0
  561. package/templates/shooter/playtests/enemy-body-is-a-body.playtest.json +6 -0
  562. package/templates/shooter/playtests/hands-authored-rate.playtest.json +54 -0
  563. package/templates/shooter/playtests/movement-eases.playtest.json +53 -0
  564. package/templates/shooter/playtests/performance.playtest.json +3 -3
  565. package/templates/shooter/playtests/stairs-smooth-the-eye.playtest.json +56 -0
  566. package/templates/shooter/playtests/weapon-sharp-while-turning.playtest.json +206 -0
  567. package/templates/shooter/src/entities/Breakables.ts +34 -10
  568. package/templates/shooter/src/entities/Enemy.ts +176 -54
  569. package/templates/shooter/src/entities/FpsPlayer.ts +55 -16
  570. package/templates/shooter/src/entities/Rifle.ts +83 -9
  571. package/templates/shooter/src/entities/movement.ts +96 -0
  572. package/templates/shooter/src/render/atmosphere.ts +444 -0
  573. package/templates/shooter/src/render/backlightMaterial.ts +49 -18
  574. package/templates/shooter/src/render/camera.ts +3 -1
  575. package/templates/shooter/src/render/clouds.ts +605 -0
  576. package/templates/shooter/src/render/exposure.ts +10 -109
  577. package/templates/shooter/src/render/facade.ts +26 -68
  578. package/templates/shooter/src/render/gpuSky.ts +752 -0
  579. package/templates/shooter/src/render/lighting.ts +27 -4
  580. package/templates/shooter/src/render/materialAssignments.ts +9 -1
  581. package/templates/shooter/src/render/materialLighting.ts +2 -11
  582. package/templates/shooter/src/render/occlusion.ts +13 -4
  583. package/templates/shooter/src/render/palette.ts +1 -0
  584. package/templates/shooter/src/render/postprocessing.ts +4 -4
  585. package/templates/shooter/src/render/quality.ts +50 -108
  586. package/templates/shooter/src/render/scale.ts +0 -11
  587. package/templates/shooter/src/render/sky.ts +103 -2
  588. package/templates/shooter/src/render/surface.ts +140 -0
  589. package/templates/shooter/src/render/town.ts +3 -6
  590. package/templates/shooter/src/render/townMaterials.ts +95 -42
  591. package/templates/shooter/src/render/vehicles.ts +2 -0
  592. package/templates/shooter/src/scenes/Play.ts +83 -23
  593. package/templates/shooter/src/ui/Hud.tsx +268 -193
  594. package/templates/shooter/src/worker-page.ts +29 -0
  595. package/templates/shooter/src/worker.ts +5 -0
  596. package/templates/shooter/threenative.config.ts +3 -0
  597. package/templates/shooter/vite.config.ts +2 -0
  598. package/templates/snow/.codex/config.toml +6 -2
  599. package/templates/snow/.cursor/mcp.json +8 -2
  600. package/templates/snow/.gemini/settings.json +8 -2
  601. package/templates/snow/.mcp.json +8 -2
  602. package/templates/snow/.vscode/mcp.json +9 -2
  603. package/templates/snow/.zed/settings.json +9 -2
  604. package/templates/snow/AGENTS.md +12 -10
  605. package/templates/snow/CLAUDE.md +12 -10
  606. package/templates/snow/opencode.json +10 -2
  607. package/templates/snow/package.json +17 -11
  608. package/templates/snow/playtests/performance.playtest.json +1 -1
  609. package/templates/snow/src/render/backlightMaterial.ts +49 -18
  610. package/templates/snow/src/render/exposure.ts +17 -106
  611. package/templates/snow/src/render/materialLighting.ts +2 -11
  612. package/templates/snow/src/render/postprocessing.ts +11 -5
  613. package/templates/snow/src/render/quality.ts +46 -126
  614. package/templates/snow/src/render/snowSurface.ts +32 -15
  615. package/templates/snow/src/scenes/Snow.ts +2 -1
  616. package/templates/starter/.codex/config.toml +6 -2
  617. package/templates/starter/.cursor/mcp.json +8 -2
  618. package/templates/starter/.gemini/settings.json +8 -2
  619. package/templates/starter/.mcp.json +8 -2
  620. package/templates/starter/.vscode/mcp.json +9 -2
  621. package/templates/starter/.zed/settings.json +9 -2
  622. package/templates/starter/AGENTS.md +18 -14
  623. package/templates/starter/CLAUDE.md +18 -14
  624. package/templates/starter/index.html +1 -1
  625. package/templates/starter/main.html +12 -0
  626. package/templates/starter/native-playtests/react-hud.playtest.json +1 -0
  627. package/templates/starter/native-playtests/render-chain.playtest.json +34 -21
  628. package/templates/starter/opencode.json +10 -2
  629. package/templates/starter/package.json +17 -11
  630. package/templates/starter/playtests/play.playtest.json +22 -2
  631. package/templates/starter/playtests/production-readiness.playtest.json +56 -0
  632. package/templates/starter/src/entities/Crate.ts +19 -1
  633. package/templates/starter/src/render/arena.ts +2 -2
  634. package/templates/starter/src/render/atmosphere.ts +444 -0
  635. package/templates/starter/src/render/backlightMaterial.ts +49 -18
  636. package/templates/starter/src/render/camera.ts +28 -0
  637. package/templates/starter/src/render/clouds.ts +605 -0
  638. package/templates/starter/src/render/contactShadow.ts +50 -0
  639. package/templates/starter/src/render/exposure.ts +9 -111
  640. package/templates/starter/src/render/gpuSky.ts +752 -0
  641. package/templates/starter/src/render/grade.ts +1 -1
  642. package/templates/starter/src/render/lighting.ts +34 -6
  643. package/templates/starter/src/render/materialLighting.ts +2 -11
  644. package/templates/starter/src/render/postprocessing.ts +53 -34
  645. package/templates/starter/src/render/quality.ts +18 -147
  646. package/templates/starter/src/render/sky.ts +90 -40
  647. package/templates/starter/src/render/temporalAA.ts +1 -1
  648. package/templates/starter/src/render/temporalAAStage.ts +1 -1
  649. package/templates/starter/src/render/temporalCurrentFootprint.ts +0 -1
  650. package/templates/starter/src/render/temporalDetailStage.ts +106 -0
  651. package/templates/starter/src/render/temporalRejectionCounter.ts +2 -2
  652. package/templates/starter/src/render/volumetricFogCamera.ts +32 -0
  653. package/templates/starter/src/render/volumetricFogOptions.ts +7 -0
  654. package/templates/starter/src/render/volumetricFogTransport.ts +27 -19
  655. package/templates/starter/src/render/volumetricFogVolume.ts +31 -7
  656. package/templates/starter/src/scenes/Play.ts +11 -8
  657. package/templates/starter/src/ui/Hud.tsx +1 -1
  658. package/templates/starter/src/worker-page.ts +29 -0
  659. package/templates/starter/src/worker.ts +5 -0
  660. package/templates/starter/vite.config.ts +2 -0
  661. package/templates/tower-defense/.codex/config.toml +6 -2
  662. package/templates/tower-defense/.cursor/mcp.json +8 -2
  663. package/templates/tower-defense/.gemini/settings.json +8 -2
  664. package/templates/tower-defense/.mcp.json +8 -2
  665. package/templates/tower-defense/.vscode/mcp.json +9 -2
  666. package/templates/tower-defense/.zed/settings.json +9 -2
  667. package/templates/tower-defense/AGENTS.md +10 -12
  668. package/templates/tower-defense/CLAUDE.md +10 -12
  669. package/templates/tower-defense/opencode.json +10 -2
  670. package/templates/tower-defense/package.json +17 -11
  671. package/templates/tower-defense/playtests/chill-tint.playtest.json +387 -0
  672. package/templates/tower-defense/playtests/performance.playtest.json +1 -1
  673. package/templates/tower-defense/src/enemies/Enemy.ts +9 -0
  674. package/templates/tower-defense/src/render/backlightMaterial.ts +49 -18
  675. package/templates/tower-defense/src/render/exposure.ts +11 -109
  676. package/templates/tower-defense/src/render/lighting.ts +4 -2
  677. package/templates/tower-defense/src/render/materialLighting.ts +2 -11
  678. package/templates/tower-defense/src/render/postprocessing.ts +4 -4
  679. package/templates/tower-defense/src/render/quality.ts +10 -116
  680. package/templates/tower-defense/src/render/sky.ts +2 -2
  681. package/templates/tower-defense/src/scenes/Battle.ts +4 -0
  682. package/template-assets/autoExposure.ts +0 -225
  683. package/template-assets/exposureGraph.ts +0 -178
  684. package/template-assets/exposureReadback.ts +0 -79
  685. package/template-assets/worldEnvironment.ts +0 -1212
  686. package/templates/action-rpg/src/render/autoExposure.ts +0 -225
  687. package/templates/action-rpg/src/render/exposureGraph.ts +0 -178
  688. package/templates/action-rpg/src/render/exposureReadback.ts +0 -79
  689. package/templates/action-rpg/src/render/worldEnvironment.ts +0 -1212
  690. package/templates/minimal/src/render/autoExposure.ts +0 -225
  691. package/templates/minimal/src/render/exposureGraph.ts +0 -178
  692. package/templates/minimal/src/render/exposureReadback.ts +0 -79
  693. package/templates/minimal/src/render/worldEnvironment.ts +0 -1212
  694. package/templates/platformer/src/render/autoExposure.ts +0 -225
  695. package/templates/platformer/src/render/exposureGraph.ts +0 -178
  696. package/templates/platformer/src/render/exposureReadback.ts +0 -79
  697. package/templates/platformer/src/render/worldEnvironment.ts +0 -1212
  698. package/templates/puzzle/src/render/autoExposure.ts +0 -225
  699. package/templates/puzzle/src/render/exposureGraph.ts +0 -178
  700. package/templates/puzzle/src/render/exposureReadback.ts +0 -79
  701. package/templates/puzzle/src/render/worldEnvironment.ts +0 -1212
  702. package/templates/racing/src/render/autoExposure.ts +0 -225
  703. package/templates/racing/src/render/exposureGraph.ts +0 -178
  704. package/templates/racing/src/render/exposureReadback.ts +0 -79
  705. package/templates/racing/src/render/worldEnvironment.ts +0 -1212
  706. package/templates/rain/src/render/autoExposure.ts +0 -225
  707. package/templates/rain/src/render/exposureGraph.ts +0 -178
  708. package/templates/rain/src/render/exposureReadback.ts +0 -79
  709. package/templates/rain/src/render/worldEnvironment.ts +0 -1212
  710. package/templates/rts/src/render/autoExposure.ts +0 -225
  711. package/templates/rts/src/render/exposureGraph.ts +0 -178
  712. package/templates/rts/src/render/exposureReadback.ts +0 -79
  713. package/templates/rts/src/render/worldEnvironment.ts +0 -1212
  714. package/templates/runner/src/render/autoExposure.ts +0 -225
  715. package/templates/runner/src/render/exposureGraph.ts +0 -178
  716. package/templates/runner/src/render/exposureReadback.ts +0 -79
  717. package/templates/runner/src/render/worldEnvironment.ts +0 -1212
  718. package/templates/sailing/src/render/autoExposure.ts +0 -225
  719. package/templates/sailing/src/render/exposureGraph.ts +0 -178
  720. package/templates/sailing/src/render/exposureReadback.ts +0 -79
  721. package/templates/sailing/src/render/worldEnvironment.ts +0 -1212
  722. package/templates/shooter/src/render/autoExposure.ts +0 -225
  723. package/templates/shooter/src/render/exposureGraph.ts +0 -178
  724. package/templates/shooter/src/render/exposureReadback.ts +0 -79
  725. package/templates/shooter/src/render/worldEnvironment.ts +0 -1212
  726. package/templates/snow/src/render/autoExposure.ts +0 -225
  727. package/templates/snow/src/render/exposureGraph.ts +0 -178
  728. package/templates/snow/src/render/exposureReadback.ts +0 -79
  729. package/templates/snow/src/render/worldEnvironment.ts +0 -1212
  730. package/templates/starter/src/render/autoExposure.ts +0 -225
  731. package/templates/starter/src/render/exposureGraph.ts +0 -178
  732. package/templates/starter/src/render/exposureReadback.ts +0 -79
  733. package/templates/starter/src/render/worldEnvironment.ts +0 -1212
  734. package/templates/tower-defense/src/render/autoExposure.ts +0 -225
  735. package/templates/tower-defense/src/render/exposureGraph.ts +0 -178
  736. package/templates/tower-defense/src/render/exposureReadback.ts +0 -79
  737. package/templates/tower-defense/src/render/worldEnvironment.ts +0 -1212
@@ -0,0 +1,1447 @@
1
+ // Generated for you. This is ordinary Three.js — edit or delete it freely.
2
+ //
3
+ // Wren, a lantern-bearing wanderer, modelled in code: no mesh file and no skin. Every joint is a
4
+ // group the pose below rotates; the idle, walk and run limbs are `AnimationClip`s that `Hero.ts` plays
5
+ // through `AnimationPlayer`, which times them to the ground she covers (`strideRoot`), so the feet
6
+ // keep pace with the floor. Each limb is an outer joint the poses turn holding an inner swing the
7
+ // clips turn. Local space is feet at y = 0, facing +Z, so her right is -X.
8
+ // The right hand is a real `Bone` named `RightHand`, so the blade is attached with the engine's
9
+ // `attachToBone` (a weapon stays in the hand that holds it) instead of being parented by hand.
10
+ //
11
+ // About 4.5 heads tall. Turned (lathe) and swept (tube) forms rather than stacked primitives: a
12
+ // jaw-tapered head with eyes, lids, brows, nose and mouth; side-swept hair locks; a dusk-blue hood
13
+ // with a rolled rim and a short soft tip, over a mantle clasped with a cord; a russet tunic with a
14
+ // V collar, a folded hem and a baldric; gloves, cuffed boots with soles. Each joint's parts merge
15
+ // into one mesh per surface (cloth, leather, metal, skin, hair), so she is a few dozen draws. The
16
+ // hood tip, the side locks, the pouch and the lantern are springs: they lag her bounce and stride.
17
+ import {
18
+ AdditiveBlending,
19
+ AnimationClip,
20
+ Bone,
21
+ BoxGeometry,
22
+ BufferAttribute,
23
+ BufferGeometry,
24
+ CatmullRomCurve3,
25
+ CircleGeometry,
26
+ Color,
27
+ ConeGeometry,
28
+ CylinderGeometry,
29
+ DoubleSide,
30
+ ExtrudeGeometry,
31
+ Group,
32
+ LatheGeometry,
33
+ type Material,
34
+ MathUtils,
35
+ Mesh,
36
+ MeshBasicMaterial,
37
+ type Object3D,
38
+ Quaternion,
39
+ QuaternionKeyframeTrack,
40
+ RingGeometry,
41
+ Shape,
42
+ SphereGeometry,
43
+ TorusGeometry,
44
+ TubeGeometry,
45
+ Vector2,
46
+ Vector3,
47
+ VectorKeyframeTrack,
48
+ } from "three";
49
+ import { flat, glow, lit } from "./materials.js";
50
+ import { C } from "./palette.js";
51
+
52
+ export type HeroPoseName =
53
+ | "idle"
54
+ | "run"
55
+ | "roll"
56
+ | "hop"
57
+ | "slash"
58
+ | "block"
59
+ | "push"
60
+ | "hurt"
61
+ | "dead";
62
+
63
+ export interface IHeroPose {
64
+ readonly dt: number;
65
+ readonly state: HeroPoseName;
66
+ /** Ground speed, m/s. */
67
+ readonly speed: number;
68
+ /** 0..1 through the current action (slash, roll, hurt). */
69
+ readonly progress: number;
70
+ /** She owns the Ember Blade: the scabbard is on her back. */
71
+ readonly sword: boolean;
72
+ /** The blade is in her hand and the shield on her arm; otherwise both ride her back. */
73
+ readonly drawn: boolean;
74
+ /** 1 the step the shield turns a hit, fading to 0. */
75
+ readonly flash: number;
76
+ }
77
+
78
+ export interface IHeroRig {
79
+ readonly group: Group;
80
+ /** "idle" (the neutral pose the procedural actions bend), "walk" and "run". */
81
+ readonly clips: readonly AnimationClip[];
82
+ update(pose: IHeroPose): void;
83
+ }
84
+
85
+ /** One key of a stride: each leg's swing about the hip and knee (+ swings the foot back), each arm's swing, the body's rise. */
86
+ interface ICycleKey {
87
+ readonly legs: readonly [number, number];
88
+ readonly knees: readonly [number, number];
89
+ readonly arms: readonly [number, number];
90
+ readonly bob: number;
91
+ }
92
+
93
+ const SIDES = ["L", "R"] as const;
94
+ const X_AXIS = new Vector3(1, 0, 0);
95
+
96
+ /** A looping clip sampled from `key(p)` at 33 keys over one cycle, p from 0 to 1. */
97
+ function cycleClip(name: string, period: number, key: (p: number) => ICycleKey): AnimationClip {
98
+ const keys = Array.from({ length: 33 }, (_, i) => key((i / 32) % 1));
99
+ const times = keys.map((_, i) => (i / 32) * period);
100
+ const q = new Quaternion();
101
+ const turn = (angle: (k: ICycleKey) => number) =>
102
+ keys.flatMap((k) => q.setFromAxisAngle(X_AXIS, angle(k)).toArray());
103
+ return new AnimationClip(name, period, [
104
+ ...SIDES.flatMap((side, i) => [
105
+ new QuaternionKeyframeTrack(
106
+ `legSwing${side}.quaternion`,
107
+ times,
108
+ turn((k) => k.legs[i] ?? 0),
109
+ ),
110
+ new QuaternionKeyframeTrack(
111
+ `kneeSwing${side}.quaternion`,
112
+ times,
113
+ turn((k) => k.knees[i] ?? 0),
114
+ ),
115
+ new QuaternionKeyframeTrack(
116
+ `armSwing${side}.quaternion`,
117
+ times,
118
+ turn((k) => k.arms[i] ?? 0),
119
+ ),
120
+ ]),
121
+ new VectorKeyframeTrack(
122
+ "bounce.position",
123
+ times,
124
+ keys.flatMap((k) => [0, k.bob, 0]),
125
+ ),
126
+ ]);
127
+ }
128
+
129
+ /**
130
+ * A stride: each foot is planted for half the cycle, sweeping from `reach` radians ahead of the hip
131
+ * to `reach` behind it, then swings forward with its knee folded by `fold`. The planted foot slides
132
+ * back at one steady speed (the angle is the arcsine of a linear sweep): a leg turning at a steady
133
+ * rate moves its foot fastest under the hip, so it would skate whatever rate the clip played at.
134
+ * The arms swing against the legs; the body rises `bob` as the legs spread.
135
+ */
136
+ function gait(reach: number, fold: number, bob: number) {
137
+ const leg = (p: number): readonly [number, number] => {
138
+ if (p < 0.5) return [Math.asin(Math.sin(reach) * (4 * p - 1)), 0];
139
+ const s = (p - 0.5) * 2;
140
+ return [
141
+ reach * Math.cos(Math.PI * s),
142
+ fold * MathUtils.smoothstep(s, 0, 0.3) * (1 - MathUtils.smoothstep(s, 0.95, 1)),
143
+ ];
144
+ };
145
+ return (p: number): ICycleKey => {
146
+ const [l, kneeL] = leg(p);
147
+ const [r, kneeR] = leg((p + 0.5) % 1);
148
+ return {
149
+ arms: [-0.85 * l, -0.85 * r],
150
+ bob: bob * Math.abs(Math.cos(Math.PI * 2 * p)),
151
+ knees: [kneeL, kneeR],
152
+ legs: [l, r],
153
+ };
154
+ };
155
+ }
156
+
157
+ const REST: ICycleKey = { arms: [0, 0], bob: 0, knees: [0, 0], legs: [0, 0] };
158
+ const CLIPS = [
159
+ cycleClip("idle", 1, () => REST),
160
+ cycleClip("walk", 0.8, gait(0.5, 0.35, 0.02)),
161
+ cycleClip("run", 0.65, gait(0.9, 1.3, 0.05)),
162
+ ];
163
+
164
+ /** Hip height: the body group's origin, and the pivot the run and the roll turn about. */
165
+ const HIP = 0.66;
166
+ /** The head's centre above the neck joint, and its radius before the jaw taper. */
167
+ const HC = 0.17;
168
+ const HR = 0.165;
169
+ /** How much the jaw narrows toward the chin. */
170
+ const JAW = 0.4;
171
+ /** The hood: a shell round the head, open over the face from the brim down. */
172
+ const HOOD = { r: 0.183, y: HC - 0.004, z: -0.006, brim: 1.1, window: 0.85, hem: 0.93 * Math.PI };
173
+ /** The chest's turned profile, [radius, height] from the waist up; its depth is 0.74 of its width. */
174
+ const CHEST: readonly (readonly [number, number])[] = [
175
+ [0.142, -0.03],
176
+ [0.148, 0.06],
177
+ [0.165, 0.16],
178
+ [0.18, 0.28],
179
+ [0.183, 0.36],
180
+ [0.168, 0.44],
181
+ [0.125, 0.51],
182
+ [0.065, 0.555],
183
+ [0.001, 0.565],
184
+ ];
185
+ const CHEST_DEPTH = 0.74;
186
+
187
+ type Surface = "cloth" | "hood" | "drape" | "skin" | "hair" | "leather" | "metal" | "eye";
188
+ /** A part: its geometry (already placed in its joint), its colour or a colour per point, its surface. */
189
+ type Part = readonly [BufferGeometry, number | ((p: Vector3) => number), Surface];
190
+ type Point = readonly [number, number, number];
191
+ const CASTS = new Set<Surface>(["cloth", "drape", "leather", "skin"]);
192
+
193
+ function surfaces(): Record<Surface, Material> {
194
+ return {
195
+ cloth: lit(0xffffff, { detail: true, roughness: 0.92, vertexColors: true }),
196
+ // The hood and the mantle are seen from inside through their openings.
197
+ hood: lit(0xffffff, { detail: true, doubleSided: true, roughness: 0.92, vertexColors: true }),
198
+ drape: lit(0xffffff, { detail: true, doubleSided: true, roughness: 0.92, vertexColors: true }),
199
+ // Skin carries a faint warm glow of its own, like light through it, so a face in shade stays warm.
200
+ skin: lit(0xffffff, { emissive: C.skinGlow, roughness: 0.6, vertexColors: true }),
201
+ hair: lit(0xffffff, { roughness: 0.5, vertexColors: true }),
202
+ leather: lit(0xffffff, { detail: true, roughness: 0.6, vertexColors: true }),
203
+ metal: lit(0xffffff, { metalness: 0.7, roughness: 0.3, vertexColors: true }),
204
+ eye: lit(0xffffff, { roughness: 0.15, vertexColors: true }),
205
+ };
206
+ }
207
+
208
+ /** Scales, turns (x, then y, then z) and moves a geometry in place. */
209
+ function at(
210
+ geometry: BufferGeometry,
211
+ x = 0,
212
+ y = 0,
213
+ z = 0,
214
+ rx = 0,
215
+ ry = 0,
216
+ rz = 0,
217
+ sx = 1,
218
+ sy = sx,
219
+ sz = sx,
220
+ ): BufferGeometry {
221
+ return geometry.scale(sx, sy, sz).rotateX(rx).rotateY(ry).rotateZ(rz).translate(x, y, z);
222
+ }
223
+
224
+ /**
225
+ * A turned form from a [radius, height] profile listed bottom to top (that order faces it
226
+ * outward). The seam sits at the back; `depth` flattens it front to back.
227
+ */
228
+ function lathe(
229
+ profile: readonly (readonly [number, number])[],
230
+ segments: number,
231
+ depth = 1,
232
+ phiStart = Math.PI,
233
+ phiLength = Math.PI * 2,
234
+ ): BufferGeometry {
235
+ const points = profile.map(([r, y]) => new Vector2(r, y));
236
+ return new LatheGeometry(points, segments, phiStart, phiLength).scale(1, 1, depth);
237
+ }
238
+
239
+ /** Moves every vertex through `move`, then relights the result. */
240
+ function shape(geometry: BufferGeometry, move: (v: Vector3) => void): BufferGeometry {
241
+ const position = geometry.attributes.position;
242
+ if (position === undefined) return geometry;
243
+ const v = new Vector3();
244
+ for (let i = 0; i < position.count; i += 1) {
245
+ move(v.fromBufferAttribute(position, i));
246
+ position.setXYZ(i, v.x, v.y, v.z);
247
+ }
248
+ geometry.computeVertexNormals();
249
+ return geometry;
250
+ }
251
+
252
+ /** A swept lock, strap or crease: a tube through `points` whose radius follows `radius(t)`. */
253
+ function strand(
254
+ points: readonly Point[],
255
+ radius: (t: number) => number,
256
+ radial = 6,
257
+ segments = 8,
258
+ ): BufferGeometry {
259
+ const curve = new CatmullRomCurve3(points.map(([x, y, z]) => new Vector3(x, y, z)));
260
+ const tube = new TubeGeometry(curve, segments, 1, radial, false);
261
+ const position = tube.attributes.position;
262
+ if (position === undefined) return tube;
263
+ const centre = new Vector3();
264
+ const v = new Vector3();
265
+ for (let i = 0; i <= segments; i += 1) {
266
+ curve.getPointAt(i / segments, centre);
267
+ const r = radius(i / segments);
268
+ for (let j = 0; j <= radial; j += 1) {
269
+ const k = i * (radial + 1) + j;
270
+ v.fromBufferAttribute(position, k).sub(centre).multiplyScalar(r).add(centre);
271
+ position.setXYZ(k, v.x, v.y, v.z);
272
+ }
273
+ }
274
+ return tube;
275
+ }
276
+
277
+ /** Merges a joint's parts into one mesh per surface, coloured per vertex. */
278
+ function bake(joint: Object3D, parts: readonly Part[]): void {
279
+ const materials = surfaces();
280
+ const bySurface = new Map<Surface, Part[]>();
281
+ for (const p of parts) bySurface.set(p[2], [...(bySurface.get(p[2]) ?? []), p]);
282
+ const p = new Vector3();
283
+ const tint = new Color();
284
+ for (const [surface, list] of bySurface) {
285
+ const geometries = list.map(([g]) => (g.index === null ? g : g.toNonIndexed()));
286
+ const count = geometries.reduce((n, g) => n + (g.attributes.position?.count ?? 0), 0);
287
+ const position = new Float32Array(count * 3);
288
+ const normal = new Float32Array(count * 3);
289
+ const uv = new Float32Array(count * 2);
290
+ const colour = new Float32Array(count * 3);
291
+ let offset = 0;
292
+ geometries.forEach((g, i) => {
293
+ const source = g.attributes.position;
294
+ const paint = list[i]?.[1] ?? 0xffffff;
295
+ if (source === undefined) return;
296
+ position.set(source.array, offset * 3);
297
+ normal.set(g.attributes.normal?.array ?? [], offset * 3);
298
+ uv.set(g.attributes.uv?.array ?? [], offset * 2);
299
+ for (let v = 0; v < source.count; v += 1) {
300
+ tint.set(typeof paint === "number" ? paint : paint(p.fromBufferAttribute(source, v)));
301
+ colour.set([tint.r, tint.g, tint.b], (offset + v) * 3);
302
+ }
303
+ offset += source.count;
304
+ });
305
+ const merged = new BufferGeometry();
306
+ merged.setAttribute("position", new BufferAttribute(position, 3));
307
+ merged.setAttribute("normal", new BufferAttribute(normal, 3));
308
+ merged.setAttribute("uv", new BufferAttribute(uv, 2));
309
+ merged.setAttribute("color", new BufferAttribute(colour, 3));
310
+ const mesh = new Mesh(merged, materials[surface]);
311
+ // Only the body's big forms cast. The hood does not, so it never darkens the face it frames;
312
+ // hair and fittings would double her shadow-pass triangles for nothing.
313
+ mesh.castShadow = CASTS.has(surface);
314
+ mesh.receiveShadow = true;
315
+ joint.add(mesh);
316
+ }
317
+ }
318
+
319
+ function part(geometry: BufferGeometry, material: Material, x = 0, y = 0, z = 0): Mesh {
320
+ const mesh = new Mesh(geometry, material);
321
+ mesh.position.set(x, y, z);
322
+ mesh.castShadow = true;
323
+ mesh.receiveShadow = true;
324
+ return mesh;
325
+ }
326
+
327
+ /** A group at (x, y, z) inside `parent`: a joint the pose rotates. */
328
+ function joint(parent: Object3D, x = 0, y = 0, z = 0): Group {
329
+ const group = new Group();
330
+ group.position.set(x, y, z);
331
+ parent.add(group);
332
+ return group;
333
+ }
334
+
335
+ /** The chest's front (or, negated, back) surface depth at (x, y) in the body. */
336
+ function chestZ(x: number, y: number): number {
337
+ let r = CHEST[0]?.[0] ?? 0;
338
+ for (let i = 1; i < CHEST.length; i += 1) {
339
+ const [r0, y0] = CHEST[i - 1] ?? [0, 0];
340
+ const [r1, y1] = CHEST[i] ?? [0, 0];
341
+ if (y >= y0 && y <= y1) r = r0 + ((r1 - r0) * (y - y0)) / (y1 - y0);
342
+ }
343
+ return CHEST_DEPTH * Math.sqrt(Math.max(0, r * r - x * x));
344
+ }
345
+
346
+ /** Below the eyes the head narrows and lengthens into a soft jaw and chin. */
347
+ function skull(v: Vector3): void {
348
+ const ny = v.y / HR;
349
+ if (ny >= 0) return;
350
+ v.y *= 1.12;
351
+ v.x *= 1 - JAW * ny * ny;
352
+ v.z *= v.z > 0 ? 1 - 0.12 * ny * ny : 1 - 0.3 * ny * ny;
353
+ }
354
+
355
+ /** The face's depth at (x, y) from the head centre, after `skull`. */
356
+ function faceZ(x: number, y: number): number {
357
+ if (y >= 0) return Math.sqrt(Math.max(0, HR * HR - x * x - y * y));
358
+ const y0 = y / 1.12;
359
+ const ny = y0 / HR;
360
+ const x0 = x / (1 - JAW * ny * ny);
361
+ return Math.sqrt(Math.max(0, HR * HR - x0 * x0 - y0 * y0)) * (1 - 0.12 * ny * ny);
362
+ }
363
+
364
+ /** Where the cloth gathers into a soft point, at the top of the back of the crown. */
365
+ const PEAK = new Vector3(0, 0.5, -0.87).normalize();
366
+ /** The mantle's outline (radius, height on the body), crown to hem; it is 0.8 as deep as wide. */
367
+ const MANTLE: readonly (readonly [number, number])[] = [
368
+ [0.262, 0.39],
369
+ [0.255, 0.42],
370
+ [0.225, 0.475],
371
+ [0.17, 0.535],
372
+ [0.12, 0.565],
373
+ [0.1, 0.585],
374
+ ];
375
+ /** The hood centre's height on the body: the head joint, the head centre, the hood's offset. */
376
+ const HOOD_ON_BODY = 0.585 + HOOD.y;
377
+
378
+ /** Where the hood folds at `v` (from its centre), -1 to 1: a ridge is positive, the crease between
379
+ * two ridges negative. Three broad folds run down the back from ear height, deepening where the
380
+ * hood meets the mantle. */
381
+ function foldAt(v: Vector3): number {
382
+ const ny = v.y / v.length();
383
+ const phi = Math.atan2(v.z, -v.x);
384
+ const back = Math.max(0, -Math.sin(phi));
385
+ return back * Math.cos(6 * (phi - (Math.PI * 3) / 2)) * MathUtils.clamp(0.25 - ny, 0, 1);
386
+ }
387
+
388
+ /** The mantle's radius at body height `y`, or 0 above it. */
389
+ function mantleRadius(y: number): number {
390
+ for (let i = 1; i < MANTLE.length; i += 1) {
391
+ const [r0, y0] = MANTLE[i - 1] as readonly [number, number];
392
+ const [r1, y1] = MANTLE[i] as readonly [number, number];
393
+ if (y <= y1) return MathUtils.lerp(r0, r1, MathUtils.clamp((y - y0) / (y1 - y0), 0, 1));
394
+ }
395
+ return 0;
396
+ }
397
+
398
+ /** The hood slumps to a soft point behind the crown and carries three broad folds down its back.
399
+ * Below the head it drapes wider and longer, falls straight down behind the neck, and lies on the
400
+ * mantle down to a dagged edge. */
401
+ function drape(v: Vector3): void {
402
+ const length = v.length();
403
+ const ny = v.y / length;
404
+ const peak = MathUtils.smoothstep(v.dot(PEAK) / length, 0.35, 1) ** 2;
405
+ v.addScaledVector(PEAK, 0.05 * peak);
406
+ const phi = Math.atan2(v.z, -v.x);
407
+ // Folds only stand out from the head, so the hair never shows through a crease.
408
+ const fold = 1 + (ny >= 0 ? 0.05 : 0.12) * Math.max(0, foldAt(v));
409
+ if (ny >= 0) {
410
+ v.x *= fold;
411
+ v.z *= fold;
412
+ return;
413
+ }
414
+ v.x *= (1 - 0.15 * ny) * fold;
415
+ v.z = Math.max(v.z * (1 - 0.2 * ny), -HOOD.r) * fold;
416
+ v.y *= 1 - 0.5 * ny;
417
+ const on = mantleRadius(v.y + HOOD_ON_BODY) + 0.01;
418
+ const across = Math.hypot(v.x, (v.z + HOOD.z) / 0.8);
419
+ if (across > 1e-4 && across < on) {
420
+ v.x *= on / across;
421
+ v.z = ((v.z + HOOD.z) * on) / across - HOOD.z;
422
+ }
423
+ if (ny < -0.95) v.y -= 0.025 * Math.max(0, Math.sin(8 * phi)) ** 2;
424
+ }
425
+
426
+ /** Where the face opening's arch closes, as a polar angle on the hood. */
427
+ const ARCH = HOOD.brim - 0.15;
428
+
429
+ /** Half the face opening's width, in radians round the hood, at polar angle `theta`: closed above the
430
+ * arch, rounding open to the brim, then widening toward the hem. */
431
+ function opening(theta: number): number {
432
+ if (theta <= ARCH) return 0;
433
+ if (theta < HOOD.brim) return HOOD.window * 0.55 * Math.sqrt((theta - ARCH) / (HOOD.brim - ARCH));
434
+ const u = MathUtils.clamp((theta - HOOD.brim) / 0.45, 0, 1);
435
+ return HOOD.window * (0.55 + 0.45 * Math.sin((u * Math.PI) / 2));
436
+ }
437
+
438
+ /** Spreads the hood's side piece, cut at the widest opening, so its edge follows `opening`. */
439
+ function narrow(v: Vector3): void {
440
+ const r = v.length();
441
+ const theta = Math.acos(MathUtils.clamp(v.y / r, -1, 1));
442
+ const from = Math.PI / 2 + HOOD.window;
443
+ let phi = Math.atan2(v.z, -v.x);
444
+ while (phi < from - 1e-4) phi += Math.PI * 2;
445
+ const w = opening(theta);
446
+ const spread = (Math.PI * 2 - 2 * w) / (Math.PI * 2 - 2 * HOOD.window);
447
+ const turned = Math.PI / 2 + w + (phi - from) * spread;
448
+ v.set(
449
+ -r * Math.cos(turned) * Math.sin(theta),
450
+ r * Math.cos(theta),
451
+ r * Math.sin(turned) * Math.sin(theta),
452
+ );
453
+ }
454
+
455
+ /** A point on the hood at sphere angles (phi, theta), in the head joint. */
456
+ function hoodPoint(phi: number, theta: number): Point {
457
+ const v = new Vector3(
458
+ -HOOD.r * Math.cos(phi) * Math.sin(theta),
459
+ HOOD.r * Math.cos(theta),
460
+ HOOD.r * Math.sin(phi) * Math.sin(theta),
461
+ );
462
+ drape(v);
463
+ return [v.x, v.y + HOOD.y, v.z + HOOD.z];
464
+ }
465
+
466
+ /** The Ember Blade: a bevelled short sword with a glowing fuller, gripped at its own origin. */
467
+ export function createBlade(): Group {
468
+ const blade = new Group();
469
+ const outline = new Shape();
470
+ outline.moveTo(-0.019, 0.1);
471
+ outline.lineTo(0.019, 0.1);
472
+ outline.lineTo(0.016, 0.55);
473
+ outline.lineTo(0, 0.66);
474
+ outline.lineTo(-0.016, 0.55);
475
+ outline.closePath();
476
+ const edge = new ExtrudeGeometry(outline, {
477
+ bevelEnabled: true,
478
+ bevelSegments: 1,
479
+ bevelSize: 0.008,
480
+ bevelThickness: 0.006,
481
+ depth: 0.003,
482
+ }).translate(0, 0, -0.0015);
483
+ const grip: [number, number][] = [];
484
+ for (let i = 0; i <= 10; i += 1) grip.push([i % 2 === 0 ? 0.019 : 0.0225, -0.085 + i * 0.015]);
485
+ bake(blade, [
486
+ [edge, C.blade, "metal"],
487
+ [lathe(grip, 10), C.leather, "leather"],
488
+ [
489
+ strand(
490
+ [
491
+ [-0.1, 0.105, 0],
492
+ [-0.05, 0.08, 0],
493
+ [0, 0.076, 0],
494
+ [0.05, 0.08, 0],
495
+ [0.1, 0.105, 0],
496
+ ],
497
+ (t) => 0.009 + 0.008 * Math.sin(Math.PI * t),
498
+ 8,
499
+ 12,
500
+ ),
501
+ C.brass,
502
+ "metal",
503
+ ],
504
+ [at(new SphereGeometry(0.024, 10, 8), 0, 0.08, 0, 0, 0, 0, 1, 0.8, 0.7), C.brass, "metal"],
505
+ [at(new SphereGeometry(0.027, 10, 8), 0, -0.1, 0), C.brass, "metal"],
506
+ ]);
507
+ blade.add(part(new BoxGeometry(0.01, 0.42, 0.0165), glow(C.ember, 3), 0, 0.33));
508
+ return blade;
509
+ }
510
+
511
+ /** The round shield, face toward +Z: a domed wooden board, an ochre cross, a brass rim and boss. */
512
+ function createShield(): Group {
513
+ const shield = new Group();
514
+ const face = lathe(
515
+ [
516
+ [0, -0.012],
517
+ [0.19, -0.012],
518
+ [0.2, -0.004],
519
+ [0.2, 0],
520
+ [0.17, 0.012],
521
+ [0.145, 0.019],
522
+ [0.105, 0.026],
523
+ [0.06, 0.031],
524
+ [0, 0.034],
525
+ ],
526
+ 24,
527
+ ).rotateX(Math.PI / 2);
528
+ // The dome's height at a radius, for the cross that lies on it.
529
+ const dome = (r: number): number => {
530
+ const top = [0.034, 0.031, 0.026, 0.019, 0.012, 0];
531
+ const rs = [0, 0.06, 0.105, 0.145, 0.17, 0.2];
532
+ const i = Math.max(0, rs.findIndex((x) => x >= r) - 1);
533
+ const t = MathUtils.clamp((r - (rs[i] ?? 0)) / ((rs[i + 1] ?? 1) - (rs[i] ?? 0)), 0, 1);
534
+ return (top[i] ?? 0) + ((top[i + 1] ?? 0) - (top[i] ?? 0)) * t;
535
+ };
536
+ const cross = [0, Math.PI / 2].map((turn) => {
537
+ const points: Point[] = [];
538
+ for (let i = 0; i <= 8; i += 1) {
539
+ const t = -0.17 + (0.34 * i) / 8;
540
+ points.push([Math.cos(turn) * t, Math.sin(turn) * t, dome(Math.abs(t)) + 0.003]);
541
+ }
542
+ return [strand(points, () => 0.012, 6, 16), C.tunicTrim, "leather"] as const;
543
+ });
544
+ bake(shield, [
545
+ [face, (p) => (Math.hypot(p.x, p.y) > 0.17 ? C.belt : C.shield), "leather"],
546
+ ...cross,
547
+ [new TorusGeometry(0.2, 0.014, 6, 28), C.brass, "metal"],
548
+ [
549
+ at(new SphereGeometry(0.042, 12, 6, 0, Math.PI * 2, 0, Math.PI / 2), 0, 0, 0.03, Math.PI / 2),
550
+ C.brass,
551
+ "metal",
552
+ ],
553
+ ]);
554
+ return shield;
555
+ }
556
+
557
+ export function createHero(): IHeroRig {
558
+ const root = new Group();
559
+ // The clips lift `bounce` with each step; the poses own `body` inside it.
560
+ const bounce = joint(root);
561
+ bounce.name = "bounce";
562
+ const body = joint(bounce, 0, HIP, 0);
563
+
564
+ // Torso: a turned chest with a V collar over the cream undershirt; it breathes.
565
+ const chest = joint(body);
566
+ const vNeck = (p: Vector3): number =>
567
+ p.z > 0.03 && p.y > 0.37 + 1.8 * Math.abs(p.x) ? C.undershirt : C.tunic;
568
+ const collar = [-1, 1].map((s) => {
569
+ const points: Point[] = [];
570
+ for (let i = 0; i <= 4; i += 1) {
571
+ const x = s * 0.088 * (1 - i / 4);
572
+ const y = 0.37 + 1.8 * Math.abs(x);
573
+ points.push([x, y, chestZ(x, y) + 0.004]);
574
+ }
575
+ return [strand(points, () => 0.009, 6, 6), C.tunicTrim, "cloth"] as const;
576
+ });
577
+ bake(chest, [[lathe(CHEST, 24, CHEST_DEPTH), vNeck, "cloth"], ...collar]);
578
+
579
+ // Belt with a square brass buckle, the pouch on her right hip, the lantern on her left.
580
+ bake(body, [
581
+ [
582
+ at(
583
+ new TorusGeometry(0.153, 0.022, 6, 32).rotateX(Math.PI / 2),
584
+ 0,
585
+ 0.02,
586
+ 0,
587
+ 0,
588
+ 0,
589
+ 0,
590
+ 1,
591
+ 1,
592
+ 0.76,
593
+ ),
594
+ C.belt,
595
+ "leather",
596
+ ],
597
+ [
598
+ at(new TorusGeometry(0.026, 0.0065, 6, 4), 0, 0.02, 0.136, 0, 0, Math.PI / 4),
599
+ C.brass,
600
+ "metal",
601
+ ],
602
+ [at(new CylinderGeometry(0.048, 0.05, 0.12, 12, 1, true), 0, 0.59, 0), C.skin, "skin"],
603
+ ]);
604
+ const pouch = joint(body, -0.16, -0.005, 0.07);
605
+ pouch.rotation.y = -0.8;
606
+ bake(pouch, [
607
+ [
608
+ at(new SphereGeometry(0.05, 10, 8), 0, -0.055, 0, 0, 0, 0, 1, 1.1, 0.65),
609
+ C.leather,
610
+ "leather",
611
+ ],
612
+ [
613
+ at(
614
+ new SphereGeometry(0.052, 10, 5, 0, Math.PI * 2, 0, Math.PI / 2),
615
+ 0,
616
+ -0.035,
617
+ 0.004,
618
+ 0,
619
+ 0,
620
+ 0,
621
+ 1,
622
+ 0.6,
623
+ 0.72,
624
+ ),
625
+ C.belt,
626
+ "leather",
627
+ ],
628
+ [at(new SphereGeometry(0.009, 6, 4), 0, -0.05, 0.036), C.brass, "metal"],
629
+ ]);
630
+ const lamp = joint(body, 0.19, 0, -0.07);
631
+ bake(lamp, [
632
+ [at(new TorusGeometry(0.012, 0.003, 4, 10), 0, -0.012, 0), C.iron, "metal"],
633
+ [
634
+ strand(
635
+ [
636
+ [-0.022, 0.012, 0],
637
+ [-0.006, 0.008, 0],
638
+ [0, 0, 0],
639
+ ],
640
+ () => 0.003,
641
+ 4,
642
+ 5,
643
+ ),
644
+ C.iron,
645
+ "metal",
646
+ ],
647
+ [at(new ConeGeometry(0.045, 0.04, 8), 0, -0.045, 0), C.iron, "metal"],
648
+ [at(new CylinderGeometry(0.042, 0.042, 0.014, 8), 0, -0.142, 0), C.iron, "metal"],
649
+ ...[0, 1, 2, 3].map(
650
+ (i) =>
651
+ [
652
+ at(
653
+ new CylinderGeometry(0.004, 0.004, 0.08, 4),
654
+ 0.036 * Math.cos((i * Math.PI) / 2 + 0.785),
655
+ -0.1,
656
+ 0.036 * Math.sin((i * Math.PI) / 2 + 0.785),
657
+ ),
658
+ C.iron,
659
+ "metal",
660
+ ] as const,
661
+ ),
662
+ ]);
663
+ lamp.add(part(new CylinderGeometry(0.032, 0.032, 0.075, 8), glow(C.lamp, 5), 0, -0.1));
664
+ // Big enough to read as her lantern from the chase camera.
665
+ lamp.scale.setScalar(1.4);
666
+
667
+ // The skirt of the tunic: a front and a back panel, lapped at the sides, flaring and folding toward
668
+ // a hem with an ochre band. It swings with the stride, and each leg pushes its panel open over the
669
+ // trousers.
670
+ const skirt = joint(body, 0, 0.03, 0);
671
+ const folds = (v: Vector3): void => {
672
+ const depth = MathUtils.clamp(-v.y / 0.28, 0, 1);
673
+ const phi = Math.atan2(v.x, v.z / 0.82);
674
+ const flare = 1 + 0.085 * depth * Math.sin(7 * phi);
675
+ v.x *= flare;
676
+ v.z *= flare;
677
+ v.y += 0.012 * depth * Math.sin(7 * phi + 0.8);
678
+ };
679
+ bake(skirt, [
680
+ [
681
+ lathe(
682
+ [
683
+ [0.15, -0.17],
684
+ [0.15, -0.1],
685
+ [0.14, 0],
686
+ ],
687
+ 16,
688
+ ),
689
+ C.trousers,
690
+ "cloth",
691
+ ],
692
+ ]);
693
+ const panels = [0, Math.PI].map((facing) => {
694
+ const panel = joint(skirt);
695
+ // The back panel sits a hair outside the front one where they lap.
696
+ if (facing > 0) panel.scale.set(1.012, 1, 1.012);
697
+ const from = facing - 1.6;
698
+ bake(panel, [
699
+ [
700
+ shape(
701
+ lathe(
702
+ [
703
+ [0.25, -0.291],
704
+ [0.262, -0.285],
705
+ [0.258, -0.264],
706
+ [0.235, -0.204],
707
+ [0.2, -0.119],
708
+ [0.165, -0.043],
709
+ [0.15, 0.005],
710
+ ],
711
+ 14,
712
+ 0.82,
713
+ from,
714
+ 3.2,
715
+ ),
716
+ folds,
717
+ ),
718
+ C.tunic,
719
+ "drape",
720
+ ],
721
+ [
722
+ shape(
723
+ lathe(
724
+ [
725
+ [0.254, -0.292],
726
+ [0.266, -0.286],
727
+ [0.264, -0.257],
728
+ ],
729
+ 14,
730
+ 0.82,
731
+ from,
732
+ 3.2,
733
+ ),
734
+ folds,
735
+ ),
736
+ C.hem,
737
+ "drape",
738
+ ],
739
+ ]);
740
+ return panel;
741
+ });
742
+
743
+ // The baldric runs from her right shoulder to her left hip, front and back, with the scabbard.
744
+ const baldric = joint(body);
745
+ bake(
746
+ baldric,
747
+ [1, -1].map((side) => {
748
+ const points: Point[] = [];
749
+ for (let i = 0; i <= 5; i += 1) {
750
+ const x = -0.15 + 0.06 * i;
751
+ const y = 0.45 - 0.082 * i;
752
+ points.push([x, y, side * (chestZ(x, y) + 0.011)]);
753
+ }
754
+ return [strand(points, () => 0.013, 6, 10), C.belt, "leather"] as const;
755
+ }),
756
+ );
757
+
758
+ // Head: a jaw-tapered skull, big dark eyes with lids and catchlights, brows, a small nose, a
759
+ // smile, warm cheeks; hair under the brim, a side-swept fringe.
760
+ const head = joint(body, 0, HOOD_ON_BODY - HOOD.y, 0);
761
+ const face: Part[] = [[at(shape(new SphereGeometry(HR, 24, 18), skull), 0, HC), C.skin, "skin"]];
762
+ const onFace = (x: number, y: number, lift: number): Point => [x, HC + y, faceZ(x, y) + lift];
763
+ const sparkle = glow(0xffffff, 1.5);
764
+ for (const s of [-1, 1]) {
765
+ const ex = 0.058 * s;
766
+ const ey = -0.022;
767
+ const z = faceZ(ex, ey);
768
+ face.push([
769
+ at(new SphereGeometry(0.03, 10, 8), ex, HC + ey, z - 0.008, -0.1, 0.38 * s, 0, 1, 1.25, 0.5),
770
+ C.sclera,
771
+ "eye",
772
+ ]);
773
+ face.push([
774
+ at(
775
+ new SphereGeometry(0.024, 10, 8),
776
+ ex - 0.003 * s,
777
+ HC + ey - 0.002,
778
+ z,
779
+ -0.1,
780
+ 0.3 * s,
781
+ 0,
782
+ 1,
783
+ 1.2,
784
+ 0.5,
785
+ ),
786
+ C.iris,
787
+ "eye",
788
+ ]);
789
+ head.add(
790
+ part(
791
+ new SphereGeometry(0.0055, 6, 4),
792
+ sparkle,
793
+ ex - 0.003 * s + 0.008,
794
+ HC + ey + 0.01,
795
+ z + 0.011,
796
+ ),
797
+ );
798
+ const lid = [Math.PI + 0.25, Math.PI - 0.35, Math.PI / 2, 0.4, -0.05].map((a) =>
799
+ onFace(ex + s * 0.034 * Math.cos(a), ey + 0.04 * Math.sin(a), 0.006),
800
+ );
801
+ face.push([strand(lid, (t) => 0.0025 + 0.003 * t, 5, 10), C.lid, "eye"]);
802
+ const brow = [
803
+ onFace(s * 0.026, 0.036, 0.006),
804
+ onFace(s * 0.058, 0.05, 0.006),
805
+ onFace(s * 0.094, 0.042, 0.006),
806
+ ];
807
+ face.push([strand(brow, (t) => 0.0075 - 0.004 * t, 5, 8), C.hair, "hair"]);
808
+ face.push([
809
+ at(
810
+ new SphereGeometry(0.026, 10, 6),
811
+ s * 0.09,
812
+ HC - 0.062,
813
+ faceZ(s * 0.09, -0.062) - 0.003,
814
+ 0,
815
+ 0.5 * s,
816
+ 0,
817
+ 1,
818
+ 0.6,
819
+ 0.22,
820
+ ),
821
+ C.blush,
822
+ "skin",
823
+ ]);
824
+ }
825
+ face.push([
826
+ at(
827
+ new SphereGeometry(0.017, 8, 6),
828
+ 0,
829
+ HC - 0.056,
830
+ faceZ(0, -0.056) - 0.004,
831
+ -0.2,
832
+ 0,
833
+ 0,
834
+ 1,
835
+ 0.9,
836
+ 0.85,
837
+ ),
838
+ C.skin,
839
+ "skin",
840
+ ]);
841
+ const mouth = [
842
+ onFace(-0.024, -0.097, 0.003),
843
+ onFace(-0.01, -0.103, 0.003),
844
+ onFace(0.01, -0.103, 0.003),
845
+ onFace(0.024, -0.097, 0.003),
846
+ ];
847
+ face.push([strand(mouth, (t) => 0.0016 + 0.0026 * Math.sin(Math.PI * t), 5, 8), C.mouth, "eye"]);
848
+ face.push([
849
+ at(new SphereGeometry(0.168, 20, 6, 0, Math.PI * 2, 0, 1), 0, HC + 0.002, -0.006),
850
+ C.hair,
851
+ "hair",
852
+ ]);
853
+ for (let i = 0; i < 6; i += 1) {
854
+ const x = -0.09 + 0.033 * i;
855
+ const drop = (i % 2) * 0.01;
856
+ const lock = [
857
+ onFace(x, 0.085, 0.004),
858
+ onFace(x + 0.012, 0.078, 0.012),
859
+ onFace(x + 0.026, 0.075 - drop, 0.01),
860
+ onFace(x + 0.034, 0.062 - drop, 0.004),
861
+ ];
862
+ face.push([
863
+ strand(lock, (t) => 0.016 * (1 - t) + 0.003, 6, 8),
864
+ i % 2 === 1 ? C.hairLight : C.hair,
865
+ "hair",
866
+ ]);
867
+ }
868
+
869
+ // The hood: one shell open over the face, a rolled rim round the opening, a mantle below.
870
+ const shell = new SphereGeometry(
871
+ HOOD.r,
872
+ 28,
873
+ 18,
874
+ Math.PI / 2 + HOOD.window,
875
+ Math.PI * 2 - 2 * HOOD.window,
876
+ 0,
877
+ HOOD.hem,
878
+ );
879
+ // The rim runs up one side of the opening, round the arch and down the other: dense at the arch.
880
+ const edge = [
881
+ ...Array.from({ length: 8 }, (_, i) => HOOD.hem - ((HOOD.hem - HOOD.brim) * i) / 8),
882
+ ...Array.from({ length: 7 }, (_, i) => ARCH + (HOOD.brim - ARCH) * ((6 - i) / 6) ** 2),
883
+ ];
884
+ const rim: Point[] = [
885
+ ...edge.map((theta) => hoodPoint(Math.PI / 2 + opening(theta), theta)),
886
+ ...[...edge]
887
+ .reverse()
888
+ .slice(1)
889
+ .map((theta) => hoodPoint(Math.PI / 2 - opening(theta), theta)),
890
+ ];
891
+ face.push(
892
+ [
893
+ at(
894
+ shape(shell, (v) => {
895
+ narrow(v);
896
+ drape(v);
897
+ }),
898
+ 0,
899
+ HOOD.y,
900
+ HOOD.z,
901
+ ),
902
+ // The cloth darkens from the crown down; the ridges catch a lighter blue, the creases between
903
+ // them fall to the dark blue.
904
+ (p: Vector3) => {
905
+ const v = p.clone().sub(new Vector3(0, HOOD.y, HOOD.z));
906
+ const f = foldAt(v);
907
+ const low = MathUtils.clamp((0.3 - v.y / v.length()) / 1.3, 0, 1);
908
+ return new Color(C.cap)
909
+ .lerp(new Color(C.capDark), 0.35 * low)
910
+ .lerp(new Color(f > 0 ? C.capLining : C.capDark), f > 0 ? 0.3 * f : -0.7 * f)
911
+ .getHex();
912
+ },
913
+ "hood",
914
+ ],
915
+ // A lighter lining rolled over the edge, so the opening reads from any side.
916
+ [strand(rim, () => 0.009, 6, 48), C.capLining, "cloth"],
917
+ // A seam down the middle of the back, crown to nape.
918
+ [
919
+ strand(
920
+ Array.from({ length: 12 }, (_, i) => {
921
+ const [x, y, z] = hoodPoint((Math.PI * 3) / 2, 0.15 + (2.45 * i) / 11);
922
+ return [x, (y - HOOD.y) * 1.01 + HOOD.y, (z - HOOD.z) * 1.01 + HOOD.z] as Point;
923
+ }),
924
+ () => 0.004,
925
+ 4,
926
+ 24,
927
+ ),
928
+ new Color(C.cap).lerp(new Color(C.capLining), 0.5).getHex(),
929
+ "cloth",
930
+ ],
931
+ );
932
+ bake(head, face);
933
+
934
+ // Side locks hang on their own joints: springs move them.
935
+ const locks = [-1, 1].map((s) => {
936
+ const lock = joint(head, s * 0.105, HC + 0.03, 0.11);
937
+ const hang = (dx: number, dz: number, length: number): Part => [
938
+ strand(
939
+ [
940
+ [dx, 0.012, dz],
941
+ [dx + s * 0.014, -0.05, dz + 0.004],
942
+ [dx + s * 0.016, -length * 0.7, dz + 0.006],
943
+ [dx + s * 0.006, -length, dz],
944
+ ],
945
+ (t) => 0.024 * (1 - t) + 0.004,
946
+ 6,
947
+ 8,
948
+ ),
949
+ dz < 0 ? C.hairLight : C.hair,
950
+ "hair",
951
+ ];
952
+ bake(lock, [hang(0, 0, 0.17), hang(s * 0.008, -0.03, 0.14)]);
953
+ return lock;
954
+ });
955
+ // The mantle over her shoulders, open at the front over the V collar, clasped with a cord.
956
+ const gap = 0.55;
957
+ // The hem is dagged: it hangs in soft points.
958
+ const wave = (phi: number, y: number): number =>
959
+ -0.03 * MathUtils.clamp((0.44 - y) / 0.05, 0, 1) * Math.max(0, Math.sin(8 * phi)) ** 2;
960
+ const mantle = shape(lathe(MANTLE, 40, 0.8, gap, Math.PI * 2 - 2 * gap), (v) => {
961
+ v.y += wave(Math.atan2(v.x, v.z / 0.8), v.y);
962
+ });
963
+ const around = (phi: number, [r, y]: readonly [number, number]): Point => [
964
+ r * Math.sin(phi),
965
+ y + wave(phi, y),
966
+ 0.8 * r * Math.cos(phi),
967
+ ];
968
+ const hem: Point[] = [];
969
+ for (let i = 0; i <= 48; i += 1)
970
+ hem.push(around(gap + ((Math.PI * 2 - 2 * gap) * i) / 48, [0.264, 0.39]));
971
+ const clasp = (s: number): Point => around(s * gap, [0.188, 0.515]);
972
+ bake(body, [
973
+ [mantle, C.cap, "drape"],
974
+ [strand(hem, () => 0.01, 5, 64), C.capLining, "cloth"],
975
+ ...[-1, 1].map(
976
+ (s) =>
977
+ [
978
+ strand(
979
+ MANTLE.map((p) => around(s * gap, p)),
980
+ () => 0.009,
981
+ 6,
982
+ 8,
983
+ ),
984
+ C.capDark,
985
+ "cloth",
986
+ ] as const,
987
+ ),
988
+ ...[-1, 1].map(
989
+ (s) => [at(new SphereGeometry(0.014, 8, 6), ...clasp(s)), C.brass, "metal"] as const,
990
+ ),
991
+ [
992
+ strand([clasp(-1), [0, 0.49, chestZ(0, 0.49) + 0.012], clasp(1)], () => 0.0045, 5, 10),
993
+ C.brass,
994
+ "metal",
995
+ ],
996
+ ]);
997
+
998
+ // Back gear. The scabbard runs from her right shoulder to her left hip under the shield, with
999
+ // the sheathed hilt over her shoulder; the shield sits on the scabbard.
1000
+ const scabbard = joint(body, 0, 0.2, -0.17);
1001
+ scabbard.rotation.z = 0.55;
1002
+ bake(scabbard, [
1003
+ [
1004
+ lathe(
1005
+ [
1006
+ [0, -0.33],
1007
+ [0.026, -0.315],
1008
+ [0.036, -0.24],
1009
+ [0.04, 0.3],
1010
+ [0.042, 0.37],
1011
+ [0, 0.371],
1012
+ ],
1013
+ 10,
1014
+ 0.45,
1015
+ ),
1016
+ C.leather,
1017
+ "leather",
1018
+ ],
1019
+ [
1020
+ lathe(
1021
+ [
1022
+ [0.046, 0.33],
1023
+ [0.046, 0.385],
1024
+ ],
1025
+ 10,
1026
+ 0.5,
1027
+ ),
1028
+ C.brass,
1029
+ "metal",
1030
+ ],
1031
+ [
1032
+ lathe(
1033
+ [
1034
+ [0, -0.345],
1035
+ [0.03, -0.32],
1036
+ [0.04, -0.26],
1037
+ ],
1038
+ 10,
1039
+ 0.5,
1040
+ ),
1041
+ C.brass,
1042
+ "metal",
1043
+ ],
1044
+ ]);
1045
+ const sheathed = createBlade();
1046
+ sheathed.rotation.z = Math.PI;
1047
+ sheathed.position.y = 0.48;
1048
+ scabbard.add(sheathed);
1049
+ const backShield = createShield();
1050
+ backShield.position.set(0.02, 0.2, -0.24);
1051
+ backShield.scale.setScalar(0.85);
1052
+ backShield.rotation.y = Math.PI;
1053
+ body.add(backShield);
1054
+
1055
+ // Arms: a puffed russet sleeve with an ochre band, a cream undersleeve at the elbow, a cuffed
1056
+ // leather glove and a gloved fist. Legs: dark trousers into boots with a folded cuff and a sole.
1057
+ const arms = { left: new Group(), right: new Group() };
1058
+ const fores = { left: new Group(), right: new Group() };
1059
+ const legs = { left: new Group(), right: new Group() };
1060
+ const shins = { left: new Group(), right: new Group() };
1061
+ for (const [name, side] of [
1062
+ ["left", 1],
1063
+ ["right", -1],
1064
+ ] as const) {
1065
+ const tag = name === "left" ? "L" : "R";
1066
+ const arm = arms[name];
1067
+ arm.position.set(0.2 * side, 0.43, 0);
1068
+ body.add(arm);
1069
+ // The poses turn `arm`; the clips turn the swing inside it.
1070
+ const armSwing = joint(arm);
1071
+ armSwing.name = `armSwing${tag}`;
1072
+ bake(armSwing, [
1073
+ [new SphereGeometry(0.068, 12, 8), C.tunic, "cloth"],
1074
+ [
1075
+ lathe(
1076
+ [
1077
+ [0.05, -0.275],
1078
+ [0.056, -0.245],
1079
+ [0.073, -0.13],
1080
+ [0.085, -0.06],
1081
+ [0.078, 0],
1082
+ ],
1083
+ 14,
1084
+ ),
1085
+ C.tunic,
1086
+ "cloth",
1087
+ ],
1088
+ [
1089
+ lathe(
1090
+ [
1091
+ [0.06, -0.275],
1092
+ [0.063, -0.25],
1093
+ ],
1094
+ 14,
1095
+ ),
1096
+ C.tunicTrim,
1097
+ "cloth",
1098
+ ],
1099
+ ]);
1100
+ const fore = fores[name];
1101
+ fore.position.y = -0.24;
1102
+ armSwing.add(fore);
1103
+ bake(fore, [
1104
+ [new SphereGeometry(0.05, 10, 8), C.tunic, "cloth"],
1105
+ [
1106
+ lathe(
1107
+ [
1108
+ [0.038, -0.215],
1109
+ [0.04, -0.19],
1110
+ [0.046, -0.15],
1111
+ [0.062, -0.13],
1112
+ [0.064, -0.105],
1113
+ [0.05, -0.09],
1114
+ [0.045, -0.08],
1115
+ [0.049, -0.03],
1116
+ ],
1117
+ 14,
1118
+ ),
1119
+ (p) => (p.y > -0.086 ? C.tunic : p.y > -0.135 ? C.bootCuff : C.gloves),
1120
+ "leather",
1121
+ ],
1122
+ [
1123
+ at(new SphereGeometry(0.052, 10, 8), 0, -0.248, 0.004, 0, 0, 0, 0.8, 1.05, 0.68),
1124
+ C.gloves,
1125
+ "leather",
1126
+ ],
1127
+ ...[-0.021, -0.007, 0.007, 0.021].map(
1128
+ (z, k) =>
1129
+ [
1130
+ strand(
1131
+ [
1132
+ [side * 0.004, -0.262, z + 0.004],
1133
+ [-side * 0.014, -0.29 + Math.abs(k - 1.5) * 0.004, z + 0.002],
1134
+ [-side * 0.03, -0.272, z],
1135
+ ],
1136
+ (t) => 0.0125 - 0.003 * t,
1137
+ 5,
1138
+ 5,
1139
+ ),
1140
+ C.gloves,
1141
+ "leather",
1142
+ ] as const,
1143
+ ),
1144
+ [
1145
+ strand(
1146
+ [
1147
+ [-side * 0.008, -0.228, 0.026],
1148
+ [-side * 0.022, -0.252, 0.04],
1149
+ [-side * 0.03, -0.268, 0.03],
1150
+ ],
1151
+ (t) => 0.017 - 0.005 * t,
1152
+ 5,
1153
+ 5,
1154
+ ),
1155
+ C.gloves,
1156
+ "leather",
1157
+ ],
1158
+ ]);
1159
+ const leg = legs[name];
1160
+ leg.position.set(0.085 * side, -0.04, 0);
1161
+ body.add(leg);
1162
+ const legSwing = joint(leg);
1163
+ legSwing.name = `legSwing${tag}`;
1164
+ bake(legSwing, [
1165
+ [
1166
+ lathe(
1167
+ [
1168
+ [0.058, -0.3],
1169
+ [0.066, -0.24],
1170
+ [0.076, -0.09],
1171
+ [0.078, 0.02],
1172
+ ],
1173
+ 14,
1174
+ ),
1175
+ C.trousers,
1176
+ "cloth",
1177
+ ],
1178
+ [at(new SphereGeometry(0.058, 10, 8), 0, -0.3, 0), C.trousers, "cloth"],
1179
+ ]);
1180
+ const shin = shins[name];
1181
+ shin.position.y = -0.3;
1182
+ legSwing.add(shin);
1183
+ const kneeSwing = joint(shin);
1184
+ kneeSwing.name = `kneeSwing${tag}`;
1185
+ // The sole's contact point, where the stride is read and the foot-slip scenario looks.
1186
+ joint(kneeSwing, 0, -0.317, 0.04).name = `foot${tag}`;
1187
+ bake(kneeSwing, [
1188
+ [
1189
+ lathe(
1190
+ [
1191
+ [0.05, -0.265],
1192
+ [0.062, -0.245],
1193
+ [0.047, -0.205],
1194
+ [0.058, -0.17],
1195
+ [0.075, -0.115],
1196
+ [0.07, -0.11],
1197
+ [0.09, -0.1],
1198
+ [0.092, -0.055],
1199
+ [0.062, -0.045],
1200
+ ],
1201
+ 16,
1202
+ ),
1203
+ (p) => (p.y > -0.106 ? C.bootCuff : C.leather),
1204
+ "leather",
1205
+ ],
1206
+ [
1207
+ lathe(
1208
+ [
1209
+ [0.054, -0.06],
1210
+ [0.058, 0.01],
1211
+ ],
1212
+ 12,
1213
+ ),
1214
+ C.trousers,
1215
+ "cloth",
1216
+ ],
1217
+ [
1218
+ at(new SphereGeometry(0.062, 12, 8), 0, -0.265, 0.045, -0.12, 0, 0, 0.95, 0.72, 1.75),
1219
+ C.leather,
1220
+ "leather",
1221
+ ],
1222
+ [
1223
+ at(new CylinderGeometry(0.06, 0.06, 0.022, 16), 0, -0.306, 0.042, -0.06, 0, 0, 1, 1, 1.72),
1224
+ C.sole,
1225
+ "leather",
1226
+ ],
1227
+ ]);
1228
+ }
1229
+
1230
+ // The right hand is a bone: `Hero.ts` attaches the blade to it once Wren has one.
1231
+ const hand = new Bone();
1232
+ hand.name = "RightHand";
1233
+ hand.position.set(0, -0.265, 0.02);
1234
+ hand.rotation.x = Math.PI / 2;
1235
+ fores.right.add(hand);
1236
+
1237
+ // The shield on the left forearm, face out, while drawn; a block turns it to face forward.
1238
+ const armShield = createShield();
1239
+ fores.left.add(armShield);
1240
+ const flashMaterial = new MeshBasicMaterial({
1241
+ blending: AdditiveBlending,
1242
+ color: C.flash,
1243
+ depthWrite: false,
1244
+ opacity: 0,
1245
+ side: DoubleSide,
1246
+ transparent: true,
1247
+ });
1248
+ const flash = new Mesh(new CircleGeometry(0.34, 24), flashMaterial);
1249
+ flash.position.z = 0.04;
1250
+ flash.renderOrder = 3;
1251
+ armShield.add(flash);
1252
+
1253
+ // The slash arc: a 120° fan in front of her at blade height, revealed right to left as the cut
1254
+ // sweeps, then faded. Its index order follows the angle, so the draw range is the reveal.
1255
+ const ARC_SEGMENTS = 24;
1256
+ const arcMaterial = new MeshBasicMaterial({
1257
+ blending: AdditiveBlending,
1258
+ color: C.slash,
1259
+ depthWrite: false,
1260
+ opacity: 0,
1261
+ side: DoubleSide,
1262
+ transparent: true,
1263
+ });
1264
+ const arc = new Mesh(
1265
+ new RingGeometry(0.5, 1.5, ARC_SEGMENTS, 1, -Math.PI / 2 - 1.05, 2.1),
1266
+ arcMaterial,
1267
+ );
1268
+ arc.rotation.x = -Math.PI / 2 - 0.35;
1269
+ arc.position.y = HIP + 0.3;
1270
+ arc.renderOrder = 3;
1271
+ arc.visible = false;
1272
+ root.add(arc);
1273
+
1274
+ // A blob under the feet keeps her planted on bright grass where the shadow map's own is faint.
1275
+ const blob = new Mesh(new CircleGeometry(0.36, 18), flat(0x0b1408, 0.32));
1276
+ blob.rotation.x = -Math.PI / 2;
1277
+ blob.position.y = 0.015;
1278
+ blob.renderOrder = 2;
1279
+ root.add(blob);
1280
+
1281
+ // Springs: an angle that chases a target and overshoots a little, so cloth and hair lag.
1282
+ const springs = { locks: [0, 0], pouch: [0, 0], lamp: [0, 0] };
1283
+ const chase = (s: number[], target: number, dt: number, stiffness = 80, damping = 9): number => {
1284
+ const angle = s[0] ?? 0;
1285
+ const speed = (s[1] ?? 0) + ((target - angle) * stiffness - (s[1] ?? 0) * damping) * dt;
1286
+ s[0] = angle + speed * dt;
1287
+ s[1] = speed;
1288
+ return s[0];
1289
+ };
1290
+
1291
+ let time = 0;
1292
+ let guard = 0;
1293
+ let lastY = HIP;
1294
+ const legSwings = [root.getObjectByName("legSwingL"), root.getObjectByName("legSwingR")];
1295
+ return {
1296
+ clips: CLIPS,
1297
+ group: root,
1298
+ update({ dt, drawn, flash: flashing, progress, speed, state, sword }: IHeroPose): void {
1299
+ time += dt;
1300
+ const run = Math.min(1, speed / 3);
1301
+ // The clips swing the limbs at the rate the ground asks for; read her left thigh's swing.
1302
+ const swing = legSwings[0]?.rotation.x ?? 0;
1303
+ const breath = Math.sin(time * 2.4) * (1 - run);
1304
+ guard += ((state === "block" ? 1 : 0) - guard) * Math.min(1, dt * 18);
1305
+
1306
+ // Gear: the blade in hand and the shield on the arm only while drawn or blocking.
1307
+ const armed = drawn || state === "block";
1308
+ scabbard.visible = sword;
1309
+ baldric.visible = sword;
1310
+ sheathed.visible = sword && !drawn;
1311
+ armShield.visible = armed;
1312
+ backShield.visible = !armed;
1313
+
1314
+ body.scale.setScalar(1);
1315
+ body.position.set(0, HIP + breath * 0.006, 0);
1316
+ body.rotation.set(run * 0.14, 0, 0);
1317
+ chest.scale.set(1 + breath * 0.01, 1 + breath * 0.008, 1 + breath * 0.012);
1318
+ skirt.rotation.set(-swing * 0.08 - run * 0.1, 0, swing * 0.05);
1319
+ skirt.scale.setScalar(1);
1320
+ legs.left.rotation.set(0, 0, 0);
1321
+ legs.right.rotation.set(0, 0, 0);
1322
+ // The clips fold a knee as its foot leaves the ground; an elbow bends more at a run.
1323
+ shins.left.rotation.set(0.08 + run * 0.15, 0, 0);
1324
+ shins.right.rotation.set(0.08 + run * 0.15, 0, 0);
1325
+ arms.left.rotation.set(0.25 * run, 0, 0.1 + breath * 0.02);
1326
+ arms.right.rotation.set(0.25 * run - (drawn ? 0.3 : 0), 0, -0.1 - breath * 0.02);
1327
+ fores.left.rotation.set(-0.42 - 0.33 * run, 0, 0);
1328
+ fores.right.rotation.set(-0.42 - 0.33 * run - (drawn ? 0.3 : 0), 0, 0);
1329
+ head.rotation.set(-run * 0.1, Math.sin(time * 0.9) * 0.08 * (1 - run), 0);
1330
+ armShield.position.set(0.055, -0.12, 0);
1331
+ armShield.rotation.set(0, Math.PI / 2, 0);
1332
+ flashMaterial.opacity = flashing * 0.85;
1333
+ flash.scale.setScalar(1 + (1 - flashing) * 0.6);
1334
+ arc.visible = false;
1335
+
1336
+ if (state === "slash") {
1337
+ // Windup cocks the blade over the right shoulder; the cut sweeps across to the left.
1338
+ const cut = progress < 0.33 ? progress / 0.33 : 1;
1339
+ const recover = progress > 0.58 ? (progress - 0.58) / 0.42 : 0;
1340
+ arms.right.rotation.set(
1341
+ -2.2 + cut * 1.1 + recover * 1.1,
1342
+ 0,
1343
+ -0.9 + cut * 2.1 - recover * 1.2,
1344
+ );
1345
+ fores.right.rotation.set(-0.2, 0, 0);
1346
+ body.rotation.y = 0.5 - cut * 1.1 + recover * 0.6;
1347
+ arms.left.rotation.set(-0.6, 0, 0.5);
1348
+ const reveal = MathUtils.clamp((progress - 0.3) / 0.22, 0, 1);
1349
+ const fade = 1 - MathUtils.clamp((progress - 0.58) / 0.2, 0, 1);
1350
+ arc.visible = drawn && reveal > 0 && fade > 0;
1351
+ arc.geometry.setDrawRange(0, Math.ceil(reveal * ARC_SEGMENTS) * 6);
1352
+ arcMaterial.opacity = 0.9 * fade;
1353
+ } else if (state === "block" || guard > 0.01) {
1354
+ // The shield comes up across her chest, face forward; she braces lower.
1355
+ arms.left.rotation.set(-1.45 * guard, 0, MathUtils.lerp(0.1, -0.3, guard));
1356
+ fores.left.rotation.set(MathUtils.lerp(-0.3, 0, guard), 0, 0);
1357
+ armShield.position.set(
1358
+ MathUtils.lerp(0.055, 0, guard),
1359
+ MathUtils.lerp(-0.12, -0.32, guard),
1360
+ 0,
1361
+ );
1362
+ armShield.rotation.set((Math.PI / 2) * guard, (Math.PI / 2) * (1 - guard), 0);
1363
+ body.position.y -= 0.06 * guard;
1364
+ body.rotation.x += 0.14 * guard;
1365
+ }
1366
+ if (state === "push") {
1367
+ // Both palms on the block's face: the body leans in from a step back, so her feet stay
1368
+ // out of the block while the stride stays short and behind her.
1369
+ body.position.z = -0.12;
1370
+ body.rotation.x = 0.3;
1371
+ arms.left.rotation.set(-1.25, 0, -0.2);
1372
+ arms.right.rotation.set(-1.25, 0, 0.2);
1373
+ fores.left.rotation.set(-0.3, 0, 0);
1374
+ fores.right.rotation.set(-0.3, 0, 0);
1375
+ legs.left.rotation.set(-0.35, 0, 0);
1376
+ legs.right.rotation.set(-0.35, 0, 0);
1377
+ shins.left.rotation.set(0.3, 0, 0);
1378
+ shins.right.rotation.set(0.3, 0, 0);
1379
+ } else if (state === "roll") {
1380
+ // A tucked somersault: knees to chest, head down, the ball turning about its own middle
1381
+ // (0.3 m above the hip, before the squash), which stays high enough that the hood never dips under the floor.
1382
+ const tuck = Math.sin(progress * Math.PI);
1383
+ const turn = progress * Math.PI * 2;
1384
+ // The spine squashes, cartoon-style, so she reads as a ball rather than a turning plank.
1385
+ const scale = 1 - 0.45 * tuck;
1386
+ const middle = MathUtils.lerp(HIP + 0.3, 0.42, tuck);
1387
+ body.rotation.x = turn;
1388
+ body.scale.set(1 - 0.15 * tuck, scale, 1 - 0.15 * tuck);
1389
+ body.position.set(0, middle - 0.3 * scale * Math.cos(turn), -0.3 * scale * Math.sin(turn));
1390
+ head.rotation.x = 0.7 * tuck;
1391
+ skirt.scale.set(1 - 0.45 * tuck, 1 - 0.5 * tuck, 1 - 0.45 * tuck);
1392
+ legs.left.rotation.x = -2.1 * tuck;
1393
+ legs.right.rotation.x = -2.1 * tuck;
1394
+ shins.left.rotation.x = 2.3 * tuck;
1395
+ shins.right.rotation.x = 2.3 * tuck;
1396
+ arms.left.rotation.set(-0.5 * tuck, 0, 0.35);
1397
+ arms.right.rotation.set(-0.5 * tuck, 0, -0.35);
1398
+ fores.left.rotation.x = -2.2 * tuck;
1399
+ fores.right.rotation.x = -2.2 * tuck;
1400
+ } else if (state === "hop") {
1401
+ legs.left.rotation.x = -0.5;
1402
+ legs.right.rotation.x = 0.4;
1403
+ shins.left.rotation.x = 0.6;
1404
+ shins.right.rotation.x = 0.3;
1405
+ arms.left.rotation.z = 0.6;
1406
+ arms.right.rotation.z = -0.6;
1407
+ } else if (state === "hurt") {
1408
+ body.rotation.x = -0.35 * (1 - progress);
1409
+ arms.left.rotation.z = 0.5;
1410
+ arms.right.rotation.z = -0.5;
1411
+ } else if (state === "dead") {
1412
+ body.rotation.x = MathUtils.lerp(0, -1.45, Math.min(1, progress * 2));
1413
+ body.position.y = MathUtils.lerp(HIP, 0.3, Math.min(1, progress * 2));
1414
+ }
1415
+
1416
+ // Secondary motion. Each hanging part chases where her motion would throw it: back with
1417
+ // speed, up as she drops, side to side with the stride, a slow sway at rest.
1418
+ const step = Math.min(dt, 1 / 30);
1419
+ const rise = body.position.y + bounce.position.y;
1420
+ const lift = MathUtils.clamp((rise - lastY) / Math.max(dt, 1e-3), -3, 3);
1421
+ lastY = rise;
1422
+ const idle = Math.sin(time * 1.7) * (1 - run);
1423
+ const thighs = [0, 1].map(
1424
+ (i) => legs[i ? "right" : "left"].rotation.x + (legSwings[i]?.rotation.x ?? 0),
1425
+ );
1426
+ panels[0]?.rotation.set(Math.max(-0.6, Math.min(0, ...thighs) * 0.7), 0, 0);
1427
+ panels[1]?.rotation.set(Math.max(0, ...thighs) * 0.7, 0, 0);
1428
+ const sway = chase(springs.locks, run * 0.35 - lift * 0.18 + idle * 0.04, step, 110, 10);
1429
+ for (const [i, lock] of locks.entries())
1430
+ lock.rotation.set(sway, 0, (i === 0 ? -1 : 1) * (0.04 + 0.05 * run));
1431
+ pouch.rotation.x = chase(
1432
+ springs.pouch,
1433
+ run * 0.4 - lift * 0.2 + swing * 0.22 + idle * 0.05,
1434
+ step,
1435
+ 60,
1436
+ 7,
1437
+ );
1438
+ lamp.rotation.x = chase(
1439
+ springs.lamp,
1440
+ run * 0.45 - lift * 0.25 - swing * 0.28 + idle * 0.06,
1441
+ step,
1442
+ 50,
1443
+ 6,
1444
+ );
1445
+ },
1446
+ };
1447
+ }