create-threenative 0.2.17 → 0.2.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (387) hide show
  1. package/agent-docs/kit-mcp.md +1 -1
  2. package/agent-docs/kit-router.md +1 -1
  3. package/agent-docs/references/assertion-reference.md +54 -110
  4. package/agent-docs/references/capability-reference.md +790 -24
  5. package/agent-docs/references/conventions.md +28 -0
  6. package/agent-docs/references/kit-racing.md +4 -2
  7. package/agent-docs/references/performance-basics.md +10 -5
  8. package/agent-docs/references/terrain-authoring.md +21 -7
  9. package/agent-files/.agents/skills/ponytail/SKILL.md +1 -1
  10. package/agent-files/.agents/skills/prd-creator/SKILL.md +24 -0
  11. package/agent-files/.agents/skills/threenative-capabilities/SKILL.md +7 -4
  12. package/agent-files/.claude/hooks/discovery-gate.mjs +2 -2
  13. package/dist/index.d.ts +97 -6
  14. package/dist/index.js +1040 -529
  15. package/dist/quality.d.ts +5 -1
  16. package/dist/quality.js +75 -6
  17. package/dist/terrain-kit.js +1 -1
  18. package/dist/threenative.js +98 -17
  19. package/dist/web-engine-ccd-ik-solver.js +127 -0
  20. package/dist/web-engine-gltf-loader.js +52 -14
  21. package/dist/web-engine-post-effects.js +11 -10
  22. package/dist/web-engine-runtime.js +3638 -361
  23. package/package.json +8 -7
  24. package/template-assets/assets/floor-fern-0.glb +0 -0
  25. package/template-assets/assets/floor-litter-0.glb +0 -0
  26. package/template-assets/assets/floor-log-0.glb +0 -0
  27. package/template-assets/assets/floor-log-1.glb +0 -0
  28. package/template-assets/assets/floor-stump-0.glb +0 -0
  29. package/template-assets/assets/floor-twig-0.glb +0 -0
  30. package/template-assets/clearwater/README.md +1 -1
  31. package/template-assets/patches/manifest.json +18 -0
  32. package/template-assets/quality/eslint.config.js +1 -1
  33. package/templates/action-rpg/AGENTS.md +8 -4
  34. package/templates/action-rpg/CLAUDE.md +8 -4
  35. package/templates/action-rpg/package.json +7 -7
  36. package/templates/action-rpg/src/game.ts +1 -1
  37. package/templates/action-rpg/src/loot/drops.ts +3 -7
  38. package/templates/action-rpg/src/render/atmosphere.ts +6 -0
  39. package/templates/action-rpg/src/render/backlightControls.ts +10 -0
  40. package/templates/action-rpg/src/render/backlightMaterial.ts +4 -4
  41. package/templates/action-rpg/src/render/camera.ts +2 -2
  42. package/templates/action-rpg/src/render/clouds.ts +16 -1
  43. package/templates/action-rpg/src/render/materialLighting.ts +5 -5
  44. package/templates/action-rpg/src/render/materials.ts +3 -2
  45. package/templates/action-rpg/src/render/quality.ts +7 -32
  46. package/templates/action-rpg/src/render/touch-controls.ts +7 -6
  47. package/templates/action-rpg/src/scenes/Play.ts +5 -16
  48. package/templates/action-rpg/src/style.css +4 -0
  49. package/templates/action-rpg/vite.config.ts +2 -0
  50. package/templates/adventure/AGENTS.md +10 -5
  51. package/templates/adventure/CLAUDE.md +10 -5
  52. package/templates/adventure/kit.json +5 -1
  53. package/templates/adventure/native-playtests/survives.playtest.json +12 -0
  54. package/templates/adventure/native-playtests/woodland-floor.playtest.json +61 -0
  55. package/templates/adventure/package.json +7 -7
  56. package/templates/adventure/playtests/grass.playtest.json +61 -0
  57. package/templates/adventure/playtests/performance.playtest.json +1 -1
  58. package/templates/adventure/playtests/survives.playtest.json +2 -2
  59. package/templates/adventure/playtests/woodland-floor.playtest.json +61 -0
  60. package/templates/adventure/src/entities/LockOn.ts +42 -4
  61. package/templates/adventure/src/entities/Warden.ts +4 -1
  62. package/templates/adventure/src/game.ts +1 -1
  63. package/templates/adventure/src/level/Vale.ts +241 -16
  64. package/templates/adventure/src/render/camera.ts +2 -2
  65. package/templates/adventure/src/render/foliage.ts +64 -20
  66. package/templates/adventure/src/render/grass.ts +325 -0
  67. package/templates/adventure/src/render/materials.ts +3 -2
  68. package/templates/adventure/src/render/palette.ts +3 -0
  69. package/templates/adventure/src/render/touch-controls.ts +4 -1
  70. package/templates/adventure/src/scenes/Play.ts +96 -1
  71. package/templates/adventure/src/style.css +4 -0
  72. package/templates/adventure/tsconfig.json +1 -1
  73. package/templates/adventure/vite.config.ts +2 -0
  74. package/templates/collectathon/AGENTS.md +7 -2
  75. package/templates/collectathon/CLAUDE.md +7 -2
  76. package/templates/collectathon/package.json +7 -7
  77. package/templates/collectathon/src/game.ts +1 -1
  78. package/templates/collectathon/src/level/Course.ts +55 -14
  79. package/templates/collectathon/src/level/terrain.ts +29 -7
  80. package/templates/collectathon/src/main.ts +1 -0
  81. package/templates/collectathon/src/render/camera.ts +2 -2
  82. package/templates/collectathon/src/render/foliage.ts +359 -98
  83. package/templates/collectathon/src/render/ground.ts +4 -4
  84. package/templates/collectathon/src/render/hero.ts +1 -1
  85. package/templates/collectathon/src/render/materials.ts +0 -1
  86. package/templates/collectathon/src/render/sky.ts +80 -15
  87. package/templates/collectathon/src/render/water.ts +32 -10
  88. package/templates/collectathon/src/scenes/Play.ts +18 -5
  89. package/templates/collectathon/src/style.css +4 -0
  90. package/templates/collectathon/tsconfig.json +1 -1
  91. package/templates/collectathon/vite.config.ts +2 -0
  92. package/templates/kart/AGENTS.md +7 -2
  93. package/templates/kart/CLAUDE.md +7 -2
  94. package/templates/kart/package.json +6 -6
  95. package/templates/kart/src/entities/Kart.ts +2 -1
  96. package/templates/kart/src/game.ts +1 -1
  97. package/templates/kart/src/main.ts +1 -0
  98. package/templates/kart/src/render/course.ts +2 -1
  99. package/templates/kart/src/style.css +4 -0
  100. package/templates/kart/src/track/Course.ts +3 -1
  101. package/templates/kart/tsconfig.json +1 -1
  102. package/templates/kart/vite.config.ts +2 -0
  103. package/templates/minimal/AGENTS.md +8 -3
  104. package/templates/minimal/CLAUDE.md +8 -3
  105. package/templates/minimal/package.json +6 -6
  106. package/templates/minimal/playtests/stands-still.playtest.json +30 -0
  107. package/templates/minimal/src/game.ts +1 -1
  108. package/templates/minimal/src/render/atmosphere.ts +6 -0
  109. package/templates/minimal/src/render/backlightControls.ts +10 -0
  110. package/templates/minimal/src/render/backlightMaterial.ts +4 -4
  111. package/templates/minimal/src/render/camera.ts +14 -3
  112. package/templates/minimal/src/render/clouds.ts +16 -1
  113. package/templates/minimal/src/render/lighting.ts +4 -2
  114. package/templates/minimal/src/render/materialLighting.ts +5 -5
  115. package/templates/minimal/src/render/materials.ts +13 -2
  116. package/templates/minimal/src/render/quality.ts +7 -32
  117. package/templates/minimal/src/render/touch-controls.ts +7 -6
  118. package/templates/minimal/src/scenes/Play.ts +4 -1
  119. package/templates/minimal/vite.config.ts +7 -1
  120. package/templates/platformer/AGENTS.md +9 -4
  121. package/templates/platformer/CLAUDE.md +9 -4
  122. package/templates/platformer/index.html +1 -1
  123. package/templates/platformer/main.html +12 -0
  124. package/templates/platformer/package.json +7 -7
  125. package/templates/platformer/playtests/collect.playtest.json +4 -1
  126. package/templates/platformer/playtests/gamepad-idle.playtest.json +21 -0
  127. package/templates/platformer/playtests/gamepad.playtest.json +30 -0
  128. package/templates/platformer/src/entities/Fox.ts +21 -6
  129. package/templates/platformer/src/game.ts +1 -1
  130. package/templates/platformer/src/level/Stage.ts +2 -6
  131. package/templates/platformer/src/main.ts +1 -0
  132. package/templates/platformer/src/render/backlightControls.ts +10 -0
  133. package/templates/platformer/src/render/backlightMaterial.ts +4 -4
  134. package/templates/platformer/src/render/materialLighting.ts +5 -5
  135. package/templates/platformer/src/render/quality.ts +7 -32
  136. package/templates/platformer/src/scenes/Play.ts +4 -2
  137. package/templates/platformer/src/style.css +4 -0
  138. package/templates/platformer/src/worker-page.ts +29 -0
  139. package/templates/platformer/src/worker.ts +5 -0
  140. package/templates/platformer/tsconfig.json +1 -1
  141. package/templates/platformer/vite.config.ts +4 -0
  142. package/templates/puzzle/AGENTS.md +7 -2
  143. package/templates/puzzle/CLAUDE.md +7 -2
  144. package/templates/puzzle/package.json +7 -7
  145. package/templates/puzzle/src/entities/Warden.ts +3 -3
  146. package/templates/puzzle/src/game.ts +1 -1
  147. package/templates/puzzle/src/render/backlightControls.ts +10 -0
  148. package/templates/puzzle/src/render/backlightMaterial.ts +4 -4
  149. package/templates/puzzle/src/render/camera.ts +2 -2
  150. package/templates/puzzle/src/render/materialLighting.ts +5 -5
  151. package/templates/puzzle/src/render/quality.ts +7 -32
  152. package/templates/puzzle/src/render/touch-controls.ts +7 -6
  153. package/templates/puzzle/src/scenes/Play.ts +1 -1
  154. package/templates/puzzle/src/style.css +4 -0
  155. package/templates/puzzle/tsconfig.json +1 -1
  156. package/templates/puzzle/vite.config.ts +2 -0
  157. package/templates/racing/AGENTS.md +9 -4
  158. package/templates/racing/CLAUDE.md +9 -4
  159. package/templates/racing/CREDITS.md +29 -0
  160. package/templates/racing/assets/engine-loop.wav +0 -0
  161. package/templates/racing/assets/grass/Grass004_color.jpg +0 -0
  162. package/templates/racing/assets/grass/Grass004_normal.jpg +0 -0
  163. package/templates/racing/assets/grass/Grass004_roughness.jpg +0 -0
  164. package/templates/racing/assets/nitro-burst.wav +0 -0
  165. package/templates/racing/assets/tyre-squeal.wav +0 -0
  166. package/templates/racing/package.json +7 -7
  167. package/templates/racing/playtests/drift-natural.playtest.json +68 -0
  168. package/templates/racing/playtests/drift.playtest.json +100 -0
  169. package/templates/racing/playtests/hud.playtest.json +117 -0
  170. package/templates/racing/playtests/launch-pose.playtest.json +34 -0
  171. package/templates/racing/playtests/nitro.playtest.json +158 -0
  172. package/templates/racing/playtests/outcome.playtest.json +4 -4
  173. package/templates/racing/playtests/performance.playtest.json +1 -1
  174. package/templates/racing/playtests/steady-camera.playtest.json +88 -0
  175. package/templates/racing/src/audio/engine.ts +138 -0
  176. package/templates/racing/src/entities/CarBody.ts +83 -10
  177. package/templates/racing/src/entities/Drift.ts +243 -0
  178. package/templates/racing/src/entities/LineDriver.ts +2 -2
  179. package/templates/racing/src/entities/Nitro.ts +72 -0
  180. package/templates/racing/src/entities/RacingCar.ts +86 -21
  181. package/templates/racing/src/entities/Rival.ts +35 -21
  182. package/templates/racing/src/game.ts +7 -1
  183. package/templates/racing/src/gauges.ts +74 -0
  184. package/templates/racing/src/render/atmosphere.ts +6 -0
  185. package/templates/racing/src/render/backlightControls.ts +10 -0
  186. package/templates/racing/src/render/backlightMaterial.ts +4 -4
  187. package/templates/racing/src/render/camera.ts +29 -4
  188. package/templates/racing/src/render/clouds.ts +16 -1
  189. package/templates/racing/src/render/effects.ts +244 -0
  190. package/templates/racing/src/render/materialLighting.ts +5 -5
  191. package/templates/racing/src/render/materials.ts +43 -8
  192. package/templates/racing/src/render/quality.ts +7 -32
  193. package/templates/racing/src/render/shapes.ts +37 -0
  194. package/templates/racing/src/render/skids.ts +84 -0
  195. package/templates/racing/src/render/touch-controls.ts +10 -10
  196. package/templates/racing/src/scenes/Race.ts +281 -26
  197. package/templates/racing/src/state.ts +35 -0
  198. package/templates/racing/src/style.css +7 -0
  199. package/templates/racing/src/track/Track.ts +132 -58
  200. package/templates/racing/src/track/TrackSector.ts +19 -1
  201. package/templates/racing/src/track/circuit.ts +21 -15
  202. package/templates/racing/src/ui/GameUi.tsx +0 -2
  203. package/templates/racing/src/ui/Hud.tsx +417 -50
  204. package/templates/racing/threenative.config.ts +15 -0
  205. package/templates/racing/tools/make-racing-audio.mjs +388 -0
  206. package/templates/racing/tsconfig.json +1 -1
  207. package/templates/racing/vite.config.ts +2 -0
  208. package/templates/rain/AGENTS.md +6 -2
  209. package/templates/rain/CLAUDE.md +6 -2
  210. package/templates/rain/package.json +6 -6
  211. package/templates/rain/src/game.ts +1 -1
  212. package/templates/rain/src/render/noise-volume.ts +2 -1
  213. package/templates/rain/src/state.ts +3 -1
  214. package/templates/rain/src/ui/GameUi.tsx +1 -1
  215. package/templates/rain/src/ui/automation.ts +10 -8
  216. package/templates/rain/src/ui/tempest.ts +3 -4
  217. package/templates/rain/vite.config.ts +6 -0
  218. package/templates/rts/AGENTS.md +6 -2
  219. package/templates/rts/CLAUDE.md +6 -2
  220. package/templates/rts/package.json +6 -6
  221. package/templates/rts/src/game.ts +1 -1
  222. package/templates/rts/src/render/backlightControls.ts +10 -0
  223. package/templates/rts/src/render/backlightMaterial.ts +4 -4
  224. package/templates/rts/src/render/materialLighting.ts +5 -5
  225. package/templates/rts/src/render/quality.ts +7 -31
  226. package/templates/rts/src/scenes/Play.ts +1 -1
  227. package/templates/rts/src/sim/terrain.ts +1 -0
  228. package/templates/rts/src/sim/types.ts +1 -0
  229. package/templates/rts/src/style.css +4 -0
  230. package/templates/rts/vite.config.ts +2 -0
  231. package/templates/runner/AGENTS.md +7 -2
  232. package/templates/runner/CLAUDE.md +7 -2
  233. package/templates/runner/package.json +7 -7
  234. package/templates/runner/src/game.ts +1 -1
  235. package/templates/runner/src/render/atmosphere.ts +6 -0
  236. package/templates/runner/src/render/backlightControls.ts +10 -0
  237. package/templates/runner/src/render/backlightMaterial.ts +4 -4
  238. package/templates/runner/src/render/clouds.ts +16 -1
  239. package/templates/runner/src/render/materialLighting.ts +5 -5
  240. package/templates/runner/src/render/materials.ts +3 -2
  241. package/templates/runner/src/render/quality.ts +7 -32
  242. package/templates/runner/src/render/touch-controls.ts +7 -6
  243. package/templates/runner/src/scenes/Run.ts +8 -10
  244. package/templates/runner/src/style.css +4 -0
  245. package/templates/runner/tsconfig.json +1 -1
  246. package/templates/runner/vite.config.ts +2 -0
  247. package/templates/sailing/AGENTS.md +7 -2
  248. package/templates/sailing/CLAUDE.md +7 -2
  249. package/templates/sailing/package.json +7 -7
  250. package/templates/sailing/src/game.ts +1 -1
  251. package/templates/sailing/src/render/backlightControls.ts +10 -0
  252. package/templates/sailing/src/render/backlightMaterial.ts +4 -4
  253. package/templates/sailing/src/render/environmentSetup.ts +1 -1
  254. package/templates/sailing/src/render/materialLighting.ts +5 -5
  255. package/templates/sailing/src/render/quality.ts +7 -32
  256. package/templates/sailing/src/render/touch-controls.ts +7 -6
  257. package/templates/sailing/src/style.css +5 -0
  258. package/templates/sailing/vite.config.ts +6 -0
  259. package/templates/shooter/AGENTS.md +6 -2
  260. package/templates/shooter/CLAUDE.md +6 -2
  261. package/templates/shooter/package.json +7 -7
  262. package/templates/shooter/src/game.ts +3 -2
  263. package/templates/shooter/src/render/atmosphere.ts +6 -0
  264. package/templates/shooter/src/render/backlightControls.ts +10 -0
  265. package/templates/shooter/src/render/backlightMaterial.ts +4 -4
  266. package/templates/shooter/src/render/clouds.ts +16 -1
  267. package/templates/shooter/src/render/materialLighting.ts +5 -5
  268. package/templates/shooter/src/render/quality.ts +7 -32
  269. package/templates/shooter/src/scenes/Play.ts +4 -1
  270. package/templates/shooter/src/style.css +4 -0
  271. package/templates/shooter/vite.config.ts +2 -0
  272. package/templates/snow/AGENTS.md +7 -2
  273. package/templates/snow/CLAUDE.md +7 -2
  274. package/templates/snow/package.json +7 -7
  275. package/templates/snow/src/entities/Explorer.ts +6 -12
  276. package/templates/snow/src/game.ts +1 -1
  277. package/templates/snow/src/render/backlightControls.ts +10 -0
  278. package/templates/snow/src/render/backlightMaterial.ts +4 -4
  279. package/templates/snow/src/render/bootPrint.ts +3 -1
  280. package/templates/snow/src/render/camera.ts +3 -2
  281. package/templates/snow/src/render/materialLighting.ts +5 -5
  282. package/templates/snow/src/render/quality.ts +7 -32
  283. package/templates/snow/src/render/scenery.ts +3 -3
  284. package/templates/snow/src/render/touch-controls.ts +7 -6
  285. package/templates/snow/src/render/weather.ts +3 -5
  286. package/templates/snow/src/style.css +5 -0
  287. package/templates/snow/src/terrain.ts +2 -1
  288. package/templates/snow/vite.config.ts +6 -0
  289. package/templates/starter/AGENTS.md +8 -3
  290. package/templates/starter/CLAUDE.md +8 -3
  291. package/templates/starter/native-playtests/render-chain.playtest.json +9 -9
  292. package/templates/starter/package.json +7 -7
  293. package/templates/starter/src/entities/Crate.ts +5 -2
  294. package/templates/starter/src/entities/Player.ts +10 -2
  295. package/templates/starter/src/game.ts +4 -3
  296. package/templates/starter/src/render/adaptiveQuality.ts +17 -0
  297. package/templates/starter/src/render/atmosphere.ts +6 -0
  298. package/templates/starter/src/render/backlightControls.ts +10 -0
  299. package/templates/starter/src/render/backlightMaterial.ts +4 -4
  300. package/templates/starter/src/render/camera.ts +2 -2
  301. package/templates/starter/src/render/clouds.ts +16 -1
  302. package/templates/starter/src/render/contactShadow.ts +1 -1
  303. package/templates/starter/src/render/materialLighting.ts +5 -5
  304. package/templates/starter/src/render/materials.ts +3 -2
  305. package/templates/starter/src/render/postprocessing.ts +11 -10
  306. package/templates/starter/src/render/quality.ts +14 -1
  307. package/templates/starter/src/render/touch-controls.ts +7 -6
  308. package/templates/starter/src/scenes/Play.ts +13 -17
  309. package/templates/starter/src/state.ts +2 -0
  310. package/templates/starter/src/style.css +4 -0
  311. package/templates/starter/src/ui/Menu.tsx +5 -1
  312. package/templates/starter/vite.config.ts +2 -0
  313. package/templates/tower-defense/AGENTS.md +7 -2
  314. package/templates/tower-defense/CLAUDE.md +7 -2
  315. package/templates/tower-defense/package.json +7 -7
  316. package/templates/tower-defense/src/game.ts +1 -1
  317. package/templates/tower-defense/src/render/backlightControls.ts +10 -0
  318. package/templates/tower-defense/src/render/backlightMaterial.ts +4 -4
  319. package/templates/tower-defense/src/render/materialLighting.ts +5 -5
  320. package/templates/tower-defense/src/render/quality.ts +7 -32
  321. package/templates/tower-defense/src/render/shapes.ts +1 -2
  322. package/templates/tower-defense/src/scenes/Battle.ts +4 -9
  323. package/templates/tower-defense/src/style.css +4 -0
  324. package/templates/tower-defense/tsconfig.json +1 -1
  325. package/templates/tower-defense/vite.config.ts +2 -0
  326. package/templates/action-rpg/src/render/environmentContribution.ts +0 -188
  327. package/templates/action-rpg/src/render/environmentRadiance.ts +0 -36
  328. package/templates/action-rpg/src/render/environmentSampleCache.ts +0 -43
  329. package/templates/action-rpg/src/render/environmentSampling.ts +0 -193
  330. package/templates/action-rpg/src/render/environmentSnapshot.ts +0 -53
  331. package/templates/minimal/src/render/environmentContribution.ts +0 -188
  332. package/templates/minimal/src/render/environmentRadiance.ts +0 -36
  333. package/templates/minimal/src/render/environmentSampleCache.ts +0 -43
  334. package/templates/minimal/src/render/environmentSampling.ts +0 -193
  335. package/templates/minimal/src/render/environmentSnapshot.ts +0 -53
  336. package/templates/platformer/src/render/environmentContribution.ts +0 -188
  337. package/templates/platformer/src/render/environmentRadiance.ts +0 -36
  338. package/templates/platformer/src/render/environmentSampleCache.ts +0 -43
  339. package/templates/platformer/src/render/environmentSampling.ts +0 -193
  340. package/templates/platformer/src/render/environmentSnapshot.ts +0 -53
  341. package/templates/puzzle/src/render/environmentContribution.ts +0 -188
  342. package/templates/puzzle/src/render/environmentRadiance.ts +0 -36
  343. package/templates/puzzle/src/render/environmentSampleCache.ts +0 -43
  344. package/templates/puzzle/src/render/environmentSampling.ts +0 -193
  345. package/templates/puzzle/src/render/environmentSnapshot.ts +0 -53
  346. package/templates/racing/src/render/environmentContribution.ts +0 -188
  347. package/templates/racing/src/render/environmentRadiance.ts +0 -36
  348. package/templates/racing/src/render/environmentSampleCache.ts +0 -43
  349. package/templates/racing/src/render/environmentSampling.ts +0 -193
  350. package/templates/racing/src/render/environmentSnapshot.ts +0 -53
  351. package/templates/racing/src/ui/Menu.tsx +0 -7
  352. package/templates/rts/src/render/environmentContribution.ts +0 -188
  353. package/templates/rts/src/render/environmentRadiance.ts +0 -36
  354. package/templates/rts/src/render/environmentSampleCache.ts +0 -43
  355. package/templates/rts/src/render/environmentSampling.ts +0 -193
  356. package/templates/rts/src/render/environmentSnapshot.ts +0 -53
  357. package/templates/runner/src/render/environmentContribution.ts +0 -188
  358. package/templates/runner/src/render/environmentRadiance.ts +0 -36
  359. package/templates/runner/src/render/environmentSampleCache.ts +0 -43
  360. package/templates/runner/src/render/environmentSampling.ts +0 -193
  361. package/templates/runner/src/render/environmentSnapshot.ts +0 -53
  362. package/templates/sailing/src/render/environmentContribution.ts +0 -188
  363. package/templates/sailing/src/render/environmentRadiance.ts +0 -36
  364. package/templates/sailing/src/render/environmentSampleCache.ts +0 -43
  365. package/templates/sailing/src/render/environmentSampling.ts +0 -193
  366. package/templates/sailing/src/render/environmentSnapshot.ts +0 -53
  367. package/templates/shooter/src/render/environmentContribution.ts +0 -188
  368. package/templates/shooter/src/render/environmentRadiance.ts +0 -36
  369. package/templates/shooter/src/render/environmentSampleCache.ts +0 -43
  370. package/templates/shooter/src/render/environmentSampling.ts +0 -193
  371. package/templates/shooter/src/render/environmentSnapshot.ts +0 -53
  372. package/templates/snow/src/render/environmentContribution.ts +0 -188
  373. package/templates/snow/src/render/environmentRadiance.ts +0 -36
  374. package/templates/snow/src/render/environmentSampleCache.ts +0 -43
  375. package/templates/snow/src/render/environmentSampling.ts +0 -193
  376. package/templates/snow/src/render/environmentSnapshot.ts +0 -53
  377. package/templates/starter/src/render/environmentContribution.ts +0 -188
  378. package/templates/starter/src/render/environmentRadiance.ts +0 -36
  379. package/templates/starter/src/render/environmentSampleCache.ts +0 -43
  380. package/templates/starter/src/render/environmentSampling.ts +0 -193
  381. package/templates/starter/src/render/environmentSnapshot.ts +0 -53
  382. package/templates/starter/src/render/rendererGate.ts +0 -36
  383. package/templates/tower-defense/src/render/environmentContribution.ts +0 -188
  384. package/templates/tower-defense/src/render/environmentRadiance.ts +0 -36
  385. package/templates/tower-defense/src/render/environmentSampleCache.ts +0 -43
  386. package/templates/tower-defense/src/render/environmentSampling.ts +0 -193
  387. package/templates/tower-defense/src/render/environmentSnapshot.ts +0 -53
package/dist/quality.d.ts CHANGED
@@ -3,10 +3,14 @@ import { Linter } from 'eslint';
3
3
  interface IQualityOptions {
4
4
  /** The project root: where `tsconfig.json` lives and the typed rules resolve from. */
5
5
  readonly root: string;
6
+ /** The reinvention rows (`reinventions.ts`). A scaffolded config turns them on; a game made
7
+ * before they existed passes only `root`, and an upgrade never rewrites that file, so its own
8
+ * code keeps the rules it was made with. */
9
+ readonly reinventions?: boolean;
6
10
  }
7
11
  /** The default correctness gate for a generated game: TypeScript-aware async rules, React hook
8
12
  * rules when React is installed, scoped suppressions, and the ThreeNative game rules (`threenative/*`: frame-callback cost, UI state use).
9
13
  * Formatting is Biome's job, not this config's. */
10
- declare function qualityConfig({ root }: IQualityOptions): Linter.Config[];
14
+ declare function qualityConfig({ root, reinventions }: IQualityOptions): Linter.Config[];
11
15
 
12
16
  export { type IQualityOptions, qualityConfig };
package/dist/quality.js CHANGED
@@ -166368,6 +166368,7 @@ var import_parser = __toESM(require_dist9());
166368
166368
 
166369
166369
  // src/quality/hotCallbacks.ts
166370
166370
  var FRAME_METHODS = /* @__PURE__ */ new Set(["render", "update"]);
166371
+ var ENTITY_FRAME_METHODS = /* @__PURE__ */ new Set(["fixedUpdate", "step", "tick", "update"]);
166371
166372
  var FRAME_HOOKS = /* @__PURE__ */ new Map([
166372
166373
  ["afterPhysics", "ctx.afterPhysics"],
166373
166374
  ["beforeRender", "ctx.beforeRender"],
@@ -166402,16 +166403,25 @@ function hookName(parent, node) {
166402
166403
  const name = calleeMember(parent, node);
166403
166404
  return name === void 0 ? void 0 : FRAME_HOOKS.get(name);
166404
166405
  }
166406
+ function methodLabel(parent, sceneLocals) {
166407
+ if (parent.type !== "MethodDefinition" || parent.static || parent.key.type !== "Identifier")
166408
+ return void 0;
166409
+ const owner = parent.parent?.parent ?? void 0;
166410
+ const base = owner?.superClass;
166411
+ const isSceneBase = base?.type === "Identifier" && sceneLocals.has(base.name);
166412
+ if (isSceneBase)
166413
+ return FRAME_METHODS.has(parent.key.name) ? `Scene.${parent.key.name}` : void 0;
166414
+ if (!ENTITY_FRAME_METHODS.has(parent.key.name)) return void 0;
166415
+ const className2 = owner?.id?.name;
166416
+ return className2 === void 0 ? parent.key.name : `${className2}.${parent.key.name}`;
166417
+ }
166405
166418
  function trackHotCallbacks() {
166406
166419
  const sceneLocals = /* @__PURE__ */ new Set();
166407
166420
  const frames = [];
166408
166421
  const frameName = (node) => {
166409
166422
  const parent = node.parent;
166410
- if (parent.type === "MethodDefinition" && !parent.static && parent.key.type === "Identifier") {
166411
- const base = parent.parent?.parent?.superClass;
166412
- const isSceneBase = base?.type === "Identifier" && sceneLocals.has(base.name);
166413
- if (isSceneBase && FRAME_METHODS.has(parent.key.name)) return `Scene.${parent.key.name}`;
166414
- }
166423
+ const method = methodLabel(parent, sceneLocals);
166424
+ if (method !== void 0) return method;
166415
166425
  const hook = hookName(parent, node);
166416
166426
  if (hook !== void 0) return hook;
166417
166427
  const member = calleeMember(parent, node);
@@ -166634,6 +166644,64 @@ var threenativePlugin = {
166634
166644
  }
166635
166645
  };
166636
166646
 
166647
+ // src/quality/reinventions.ts
166648
+ var PRNG_OUTSIDE = ["src/audio.ts", "src/audio/**", "src/render/**", "src/ui/**"];
166649
+ var REINVENTIONS = [
166650
+ {
166651
+ selector: ':matches(CallExpression[callee.object.name="Math"][callee.property.name="random"], Literal[value=1664525], Literal[value=1013904223], Literal[value=1831565813])',
166652
+ capability: "createRandom",
166653
+ source: "core",
166654
+ outside: PRNG_OUTSIDE,
166655
+ message: "A hand-written PRNG (Math.random or the LCG constants) is a capability the engine ships: use `createRandom(seed)` from `@threenative/core`, or `ctx.random`, so the same seed replays the same game."
166656
+ },
166657
+ {
166658
+ selector: 'BinaryExpression[operator="-"][left.value=1][right.callee.object.name="Math"][right.callee.property.name="exp"]',
166659
+ capability: "MathUtils.damp",
166660
+ source: "three",
166661
+ message: "`1 - Math.exp(-\u2026)` is a damp factor the engine ships: use `MathUtils.damp(current, target, rate, dt)` from `three`, which is the same curve with the rate named."
166662
+ },
166663
+ {
166664
+ selector: ':matches(MemberExpression[object.name="location"][property.name="search"], MemberExpression[object.property.name="location"][property.name="search"])',
166665
+ capability: "debugFlag",
166666
+ source: "core",
166667
+ message: "Reading `location.search` by hand is a launch seam the engine owns: use `debugFlag(name)` or `debugValue(name)` from `@threenative/core` (`?name` on web, `TN_DEBUG_NAME` on native)."
166668
+ },
166669
+ {
166670
+ selector: 'AssignmentExpression[left.property.name="matrixWorldAutoUpdate"][right.value=false]',
166671
+ capability: "renderer.matrixWorld",
166672
+ source: "core",
166673
+ message: "Turning `matrixWorldAutoUpdate` off by hand is the engine's own walk: set `renderer.matrixWorld` in the game config for a whole scene, or `markStatic(node)` for one node that never moves."
166674
+ },
166675
+ {
166676
+ selector: 'BinaryExpression[operator="-"][left.type="ConditionalExpression"][left.consequent.value=1][left.alternate.value=0][right.type="ConditionalExpression"][right.consequent.value=1][right.alternate.value=0]',
166677
+ capability: "InputMap.axis",
166678
+ source: "core",
166679
+ message: "An axis built from raw keys is a binding the engine already reads: declare it in `defineGame({ input })` and use `ctx.input.axis(name)` from `@threenative/core`."
166680
+ },
166681
+ {
166682
+ selector: 'BinaryExpression[operator="*"][right.type="BinaryExpression"][right.operator="-"][right.left.value=3][right.right.type="BinaryExpression"][right.right.operator="*"][right.right.left.value=2]',
166683
+ capability: "MathUtils.smoothstep",
166684
+ source: "three",
166685
+ message: "`x * x * (3 - 2 * x)` is the engine's smoothstep: use `MathUtils.smoothstep(x, 0, 1)` from `three`, which clamps the same way."
166686
+ }
166687
+ ];
166688
+ function reinventionRules(rows) {
166689
+ return {
166690
+ "no-restricted-syntax": [
166691
+ "error",
166692
+ ...rows.map(({ selector, message }) => ({ selector, message }))
166693
+ ]
166694
+ };
166695
+ }
166696
+ function reinventionConfigs(files) {
166697
+ const always = REINVENTIONS.filter((row) => row.outside === void 0);
166698
+ const ignores = [...new Set(REINVENTIONS.flatMap((row) => row.outside ?? []))];
166699
+ return [
166700
+ { files: [...files], rules: reinventionRules(always) },
166701
+ { files: [...files], ignores, rules: reinventionRules(REINVENTIONS) }
166702
+ ];
166703
+ }
166704
+
166637
166705
  // src/quality/index.ts
166638
166706
  var asPlugin = (plugin) => plugin;
166639
166707
  var SOURCE = ["src/**/*.ts", "src/**/*.tsx"];
@@ -166641,7 +166709,7 @@ function hasReact(root) {
166641
166709
  const manifest = JSON.parse(readFileSync(path.join(root, "package.json"), "utf8"));
166642
166710
  return ["dependencies", "devDependencies"].some((field) => manifest[field]?.react !== void 0);
166643
166711
  }
166644
- function qualityConfig({ root }) {
166712
+ function qualityConfig({ root, reinventions = false }) {
166645
166713
  const config = [
166646
166714
  { ignores: ["**/node_modules/**", "**/dist/**", "**/.threenative/**", "**/dist-native/**"] },
166647
166715
  {
@@ -166675,6 +166743,7 @@ function qualityConfig({ root }) {
166675
166743
  }
166676
166744
  }
166677
166745
  ];
166746
+ if (reinventions) config.push(...reinventionConfigs(SOURCE));
166678
166747
  if (hasReact(root)) {
166679
166748
  config.push({
166680
166749
  files: ["src/**/*.tsx"],
@@ -4,7 +4,7 @@ import path from 'path';
4
4
  import { fileURLToPath } from 'url';
5
5
 
6
6
  createRequire(import.meta.url);
7
- var KITS = ["alpine", "coastal", "desert", "forest", "tundra"];
7
+ var KITS = ["alpine", "coastal", "desert", "tundra"];
8
8
  var COPIED = [
9
9
  "assets.json",
10
10
  "bake.mjs",
@@ -13,6 +13,7 @@ import { compileAssets, parsePng, parseAudioConfig } from '@threenative/assets';
13
13
  import { read, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_FORMAT_ASTC_4x4_SRGB_BLOCK, KHR_SUPERCOMPRESSION_NONE, KHR_DF_MODEL_ASTC, KHR_DF_TRANSFER_SRGB, KHR_DF_TRANSFER_LINEAR } from 'ktx-parse';
14
14
  import { brotliCompressSync, constants as constants$1, gzipSync } from 'zlib';
15
15
  import { platform, homedir } from 'os';
16
+ import { fixAuthoringLayer, authoringLayerStatus } from './index.js';
16
17
 
17
18
  createRequire(import.meta.url);
18
19
  var BUILD_REPORT_SUFFIX = ".build-report.json";
@@ -184,6 +185,13 @@ function positiveInteger(value, fallback, code, label) {
184
185
  }
185
186
  return value;
186
187
  }
188
+ function priorityValue(value) {
189
+ if (value === void 0) return "game";
190
+ if (value !== "game" && value !== "normal") {
191
+ fail("TN_CONFIG_PRIORITY_INVALID", 'display.priority must be "game" or "normal".');
192
+ }
193
+ return value;
194
+ }
187
195
  function maxFpsValue(value) {
188
196
  if (value === void 0) return 60;
189
197
  if (!Number.isSafeInteger(value) || value < 0 || value > 1e3) {
@@ -285,6 +293,10 @@ function resolveEsbuild(cwd) {
285
293
  }
286
294
  }
287
295
  }
296
+ var configLoadSequence = 0;
297
+ function configTempName(cwd, pid, now, sequence) {
298
+ return path5.join(cwd, `.threenative.config.${pid}.${now}.${sequence}.mjs`);
299
+ }
288
300
  async function importConfig(cwd) {
289
301
  const sourcePath = path5.join(cwd, CONFIG_FILE);
290
302
  try {
@@ -347,7 +359,8 @@ async function importConfig(cwd) {
347
359
  error instanceof Error ? error.message : String(error)
348
360
  );
349
361
  }
350
- const compiledPath = path5.join(cwd, `.threenative.config.${process.pid}.${Date.now()}.mjs`);
362
+ configLoadSequence += 1;
363
+ const compiledPath = configTempName(cwd, process.pid, Date.now(), configLoadSequence);
351
364
  try {
352
365
  await writeFile(compiledPath, code, "utf8");
353
366
  } catch (error) {
@@ -622,7 +635,13 @@ async function validateIconVariants(raw, cwd) {
622
635
  }
623
636
  function validateDisplay(raw) {
624
637
  const display = assertRecord(raw, "display");
625
- assertKeys(display, "display", ["orientation", "fullscreen", "keepScreenOn", "maxFps"]);
638
+ assertKeys(display, "display", [
639
+ "orientation",
640
+ "fullscreen",
641
+ "keepScreenOn",
642
+ "priority",
643
+ "maxFps"
644
+ ]);
626
645
  const orientation = display.orientation === void 0 ? "landscape" : display.orientation;
627
646
  if (typeof orientation !== "string" || !ORIENTATIONS.includes(orientation)) {
628
647
  fail(
@@ -644,6 +663,7 @@ function validateDisplay(raw) {
644
663
  "TN_CONFIG_KEEP_SCREEN_ON_INVALID",
645
664
  "display.keepScreenOn"
646
665
  ),
666
+ priority: priorityValue(display.priority),
647
667
  maxFps: maxFpsValue(display.maxFps)
648
668
  };
649
669
  }
@@ -1713,8 +1733,8 @@ function describeNativeCssFindings(findings) {
1713
1733
  (f) => ` ${f.file}:${f.line}:${f.column}${f.authored === void 0 ? "" : ` authored ${f.authored}`} ${f.what} \u2014 ${f.why}`
1714
1734
  ).join("\n");
1715
1735
  }
1716
- function webRuntimeDecoders(config) {
1717
- return config.engine === "threejs" ? { ktx2: true, meshopt: true } : { ktx2: false, meshopt: false };
1736
+ function webRuntimeDecoders(_config) {
1737
+ return { ktx2: true, meshopt: true };
1718
1738
  }
1719
1739
 
1720
1740
  // src/build.ts
@@ -2371,7 +2391,7 @@ async function buildWeb(cwd, viteArgs = [], profile) {
2371
2391
  config: config.assets,
2372
2392
  cwd,
2373
2393
  platform: "web",
2374
- runtimeDecoders: webRuntimeDecoders(config),
2394
+ runtimeDecoders: webRuntimeDecoders(),
2375
2395
  ...config.engine !== "threejs" && { runtimeIdentity: "web:native-engine" }
2376
2396
  });
2377
2397
  const assets = assetRoot(cwd, config);
@@ -2686,6 +2706,10 @@ async function buildEngineDesktop(cwd, config, entry) {
2686
2706
  String(config.window.height),
2687
2707
  "--title",
2688
2708
  config.window.title,
2709
+ "--priority",
2710
+ config.display.priority,
2711
+ "--fullscreen",
2712
+ String(config.display.fullscreen),
2689
2713
  "--output",
2690
2714
  output
2691
2715
  ]);
@@ -3245,11 +3269,11 @@ var MCP_SERVERS = Object.freeze({
3245
3269
  })
3246
3270
  });
3247
3271
  var MCP_PACKAGES = Object.freeze({
3248
- assets: Object.freeze({ name: "threenative-asset-mcp", version: "0.15.0" }),
3249
- terrain: Object.freeze({ name: "@threenative/terrain", version: "0.1.8" }),
3272
+ assets: Object.freeze({ name: "threenative-asset-mcp", version: "0.16.0" }),
3273
+ terrain: Object.freeze({ name: "@threenative/terrain", version: "0.1.11" }),
3250
3274
  sculpt: Object.freeze({ name: "threenative-sculpt-mcp", version: "0.2.2" }),
3251
- engine: Object.freeze({ name: "threenative-engine-mcp", version: "0.2.12" }),
3252
- animation: Object.freeze({ name: "threenative-animation-mcp", version: "0.1.9" }),
3275
+ engine: Object.freeze({ name: "threenative-engine-mcp", version: "0.2.15" }),
3276
+ animation: Object.freeze({ name: "threenative-animation-mcp", version: "0.1.12" }),
3253
3277
  // `args` fixes the launch for every host. The Chrome flags are `WEBGPU_BROWSER_ARGS` from
3254
3278
  // `@threenative/playtest`, so a DevTools trace profiles the same adapter a playtest does and not
3255
3279
  // SwiftShader. An isolated profile keeps the user's own Chrome profile out, and the two opt-outs
@@ -3362,7 +3386,12 @@ var MCP_HOSTS = Object.freeze([
3362
3386
  Object.freeze({ id: "zed", label: "Zed", file: ".zed/settings.json", format: "zed" })
3363
3387
  ]);
3364
3388
 
3389
+ // ../core/src/version.ts
3390
+ var CORE_VERSION = "0.3.15";
3391
+
3365
3392
  // src/mcp-servers.ts
3393
+ var CORE_PACKAGE_NAME = "@threenative/core";
3394
+ var CORE_PACKAGE_VERSION = CORE_VERSION;
3366
3395
  function serverEntryPath(server) {
3367
3396
  const entry = server.args[0];
3368
3397
  if (entry === void 0) {
@@ -3408,8 +3437,6 @@ function requiredAndroidSdkFromRoot(root) {
3408
3437
  return DEFAULT_ANDROID_COMPILE_SDK;
3409
3438
  }
3410
3439
  }
3411
- var CORE_PACKAGE_NAME = "@threenative/core";
3412
- var CORE_PACKAGE_VERSION = "0.3.12";
3413
3440
  var CORE_RESOLVED_SERVERS = /* @__PURE__ */ new Set([
3414
3441
  "threenative-engine",
3415
3442
  "threenative-animation"
@@ -3735,7 +3762,7 @@ function probeMcpServer(projectRoot, spec) {
3735
3762
  method: "initialize",
3736
3763
  params: {
3737
3764
  capabilities: {},
3738
- clientInfo: { name: "threenative-doctor", version: "0.3.12" },
3765
+ clientInfo: { name: "threenative-doctor", version: CORE_PACKAGE_VERSION },
3739
3766
  protocolVersion: "2025-06-18"
3740
3767
  }
3741
3768
  });
@@ -4744,6 +4771,7 @@ function diagnoseProject(snapshot, options = {}) {
4744
4771
  },
4745
4772
  sceneShapeCheck(snapshot),
4746
4773
  ...capabilitySearchChecks(snapshot),
4774
+ ...snapshot.authoringLayer === void 0 ? [] : [authoringLayerCheck(snapshot.authoringLayer)],
4747
4775
  editorActivationCheck(snapshot),
4748
4776
  ...blender === void 0 ? [] : [blender]
4749
4777
  ];
@@ -4753,6 +4781,22 @@ function diagnoseProject(snapshot, options = {}) {
4753
4781
  });
4754
4782
  return { checks: scoped, pass: scoped.every(({ status }) => status !== "fail") };
4755
4783
  }
4784
+ var AUTHORING_LAYER_FIX = "After 'pnpm up --latest create-threenative', run 'pnpm exec threenative doctor --fix'; add --force to overwrite files this game edited.";
4785
+ function authoringLayerCheck(layer) {
4786
+ const name = "authoring layer";
4787
+ if (layer.problem !== void 0)
4788
+ return { detail: layer.problem, fix: AUTHORING_LAYER_FIX, name, status: "warn" };
4789
+ const where = `installed create-threenative ${layer.installed} (${layer.kit} kit)`;
4790
+ if (layer.stamped === layer.installed && layer.stale.length === 0)
4791
+ return { detail: `stamp matches ${where}`, name, status: "ok" };
4792
+ const count = `${layer.stale.length} stale file${layer.stale.length === 1 ? "" : "s"}`;
4793
+ return {
4794
+ detail: `stamp ${layer.stamped ?? "absent"}, ${where}: ${count}`,
4795
+ fix: AUTHORING_LAYER_FIX,
4796
+ name,
4797
+ status: "warn"
4798
+ };
4799
+ }
4756
4800
  async function collectFiles(root, relative = "", depth = 0) {
4757
4801
  if (depth > 3) return [];
4758
4802
  const absolute = path5.join(root, relative);
@@ -4808,6 +4852,13 @@ async function readProject(root) {
4808
4852
  const runtimeVersion = installedVersions.get(RUNTIME_PACKAGE);
4809
4853
  const runtimeManifestUrl = runtimeRoot === void 0 || runtimeVersion === void 0 ? void 0 : await runtimeReleaseManifestUrl(runtimeRoot, runtimeVersion);
4810
4854
  const playtestRunnerPath = resolveBinaryFrom(projectRoot, PLAYTEST_BINARY);
4855
+ const authoringLayer = await authoringLayerStatus(projectRoot).catch(
4856
+ (error) => ({
4857
+ installed: "unknown",
4858
+ problem: error instanceof Error ? error.message : String(error),
4859
+ stale: []
4860
+ })
4861
+ );
4811
4862
  const mcpServerHealth = /* @__PURE__ */ new Map();
4812
4863
  if (SHAPE_VERIFIABLE_HOSTS.some(({ file }) => files.has(file))) {
4813
4864
  for (const spec of MCP_SERVER_SPECS) {
@@ -4819,6 +4870,7 @@ async function readProject(root) {
4819
4870
  }
4820
4871
  }
4821
4872
  return {
4873
+ authoringLayer,
4822
4874
  config,
4823
4875
  files,
4824
4876
  installedVersions,
@@ -4876,7 +4928,7 @@ async function readTypeScriptConfig(root) {
4876
4928
  function formatDoctorReport(report) {
4877
4929
  const symbols = { fail: "\u2717", ok: "\u2713", warn: "!" };
4878
4930
  const isBaseline = (name) => ["package.json", "dependencies", "versions"].includes(name);
4879
- const isCraft = (name) => name.startsWith("capability search");
4931
+ const isCraft = (name) => name.startsWith("capability search") || name === "authoring layer";
4880
4932
  const isTest = (name) => name === "playtest" || name === "playtests";
4881
4933
  const groups = [
4882
4934
  ["Baseline", isBaseline],
@@ -4900,8 +4952,6 @@ function formatDoctorReport(report) {
4900
4952
  return `${lines.join("\n")}
4901
4953
  `;
4902
4954
  }
4903
-
4904
- // src/threenative.ts
4905
4955
  var DOCTOR_TARGETS = ["web", "desktop", "android", "ios"];
4906
4956
  var DOCTOR_MODES = ["debug", "release"];
4907
4957
  function cliHelp(command) {
@@ -4909,7 +4959,7 @@ function cliHelp(command) {
4909
4959
  if (command === "doctor") {
4910
4960
  return `${[
4911
4961
  "Usage: threenative doctor [--target web|desktop|android|ios] [--mode debug|release]",
4912
- " [--text] [--capture <path>]",
4962
+ " [--text] [--capture <path>] [--fix [--force]]",
4913
4963
  "",
4914
4964
  "Checks this project against what the build and the native host assume about it:",
4915
4965
  "installed and version-matched @threenative packages, a portable entry that",
@@ -4926,6 +4976,11 @@ function cliHelp(command) {
4926
4976
  " need once PRD-212 ships it, so a green report here is a forecast, not a release.",
4927
4977
  "Prints JSON by default; --text prints the same report for a person.",
4928
4978
  "--capture forwards a browser census JSON or native TN_PIPELINE_EVENT log to the playtest doctor.",
4979
+ "--fix rewrites this game's authoring layer (AGENTS.md, CLAUDE.md, skills, hooks, MCP configs)",
4980
+ " from the installed create-threenative, then checks again. To update an existing game:",
4981
+ " 'pnpm up --latest create-threenative @threenative/*', then 'pnpm exec threenative doctor --fix'.",
4982
+ " A file this game edited is kept and listed, and the run exits 1 (TN_AUTHORING_LAYER_EDITED);",
4983
+ " --force overwrites it. Git is the undo. .threenative/agent-files.json records what was written.",
4929
4984
  "Exits 0 when nothing failed, 1 when a check failed."
4930
4985
  ].join("\n")}
4931
4986
  `;
@@ -4950,6 +5005,8 @@ ${cliHelp()}`);
4950
5005
  }
4951
5006
  async function runDoctorCommand(argv, cwd = process.cwd()) {
4952
5007
  let capturePath;
5008
+ let fix = false;
5009
+ let force = false;
4953
5010
  let mode;
4954
5011
  let target;
4955
5012
  const valueFor = (flag, value) => {
@@ -4960,6 +5017,11 @@ async function runDoctorCommand(argv, cwd = process.cwd()) {
4960
5017
  for (let index = 0; index < argv.length; index += 1) {
4961
5018
  const flag = argv[index];
4962
5019
  if (flag === "--text") continue;
5020
+ if (flag === "--fix" || flag === "--force") {
5021
+ if (flag === "--fix") fix = true;
5022
+ else force = true;
5023
+ continue;
5024
+ }
4963
5025
  if (flag === "--capture") {
4964
5026
  capturePath = valueFor(flag, argv[index + 1]);
4965
5027
  index += 1;
@@ -4985,12 +5047,31 @@ async function runDoctorCommand(argv, cwd = process.cwd()) {
4985
5047
  }
4986
5048
  if (mode !== void 0 && target === void 0)
4987
5049
  throw new Error("doctor: '--mode' requires '--target'.");
5050
+ if (force && !fix) throw new Error("doctor: '--force' requires '--fix'.");
5051
+ let kept = 0;
5052
+ if (fix) {
5053
+ const result = await fixAuthoringLayer(cwd, { force });
5054
+ const lines = [
5055
+ ...result.written.map((file) => `wrote ${file}`),
5056
+ ...result.deleted.map((file) => `deleted ${file}`),
5057
+ ...result.kept.map((file) => `kept ${file}`)
5058
+ ];
5059
+ kept = result.kept.length;
5060
+ if (kept > 0)
5061
+ lines.push(
5062
+ `TN_AUTHORING_LAYER_EDITED: kept ${kept} file${kept === 1 ? "" : "s"} this game edited; rerun with --force to overwrite (git is the undo).`
5063
+ );
5064
+ process.stderr.write(
5065
+ lines.length === 0 ? "authoring layer already current\n" : `${lines.join("\n")}
5066
+ `
5067
+ );
5068
+ }
4988
5069
  const report = diagnoseProject(await readProject(cwd), { capturePath, mode, target });
4989
5070
  process.stdout.write(
4990
5071
  argv.includes("--text") ? formatDoctorReport(report) : `${JSON.stringify(report, null, 2)}
4991
5072
  `
4992
5073
  );
4993
- return report.pass ? 0 : 1;
5074
+ return report.pass && kept === 0 ? 0 : 1;
4994
5075
  }
4995
5076
  async function main(argv = process.argv.slice(2)) {
4996
5077
  if (argv.includes("--help") || argv.includes("-h")) {
@@ -0,0 +1,127 @@
1
+ import { Quaternion, Vector3 } from 'three';
2
+
3
+ // ../three-native/src/addons/ccd-ik-solver.ts
4
+ var modulo = (n, m) => (n % m + m) % m;
5
+ var CCDIKSolver = class {
6
+ constructor(mesh, iks = []) {
7
+ this.mesh = mesh;
8
+ this.iks = iks;
9
+ this.#initialQuaternions = iks.map((ik) => ik.links.map(() => new Quaternion()));
10
+ this.#valid();
11
+ }
12
+ mesh;
13
+ iks;
14
+ #quaternion = new Quaternion();
15
+ #targetPos = new Vector3();
16
+ #targetVec = new Vector3();
17
+ #effectorPos = new Vector3();
18
+ #effectorVec = new Vector3();
19
+ #linkPos = new Vector3();
20
+ #invLinkQ = new Quaternion();
21
+ #linkScale = new Vector3();
22
+ #axis = new Vector3();
23
+ #vector = new Vector3();
24
+ #center = new Vector3();
25
+ #workingQuaternion = new Quaternion();
26
+ #initialQuaternions;
27
+ update(globalBlendFactor = 1) {
28
+ for (const ik of this.iks) this.updateOne(ik, globalBlendFactor);
29
+ return this;
30
+ }
31
+ updateOne(ik, overrideBlend = 1) {
32
+ const chainBlend = ik.blendFactor ?? overrideBlend;
33
+ const bones = this.mesh.skeleton.bones;
34
+ const initialQuaternions = this.#initialQuaternions[this.iks.indexOf(ik)] ?? [];
35
+ const effector = bones[ik.effector];
36
+ const target = bones[ik.target];
37
+ this.#targetPos.setFromMatrixPosition(target.matrixWorld);
38
+ const links = ik.links;
39
+ if (chainBlend < 1)
40
+ for (const [j, link] of links.entries())
41
+ initialQuaternions[j]?.copy(bones[link.index].quaternion);
42
+ for (let i = 0; i < (ik.iteration ?? 1); i++) if (!this.#iterate(ik, bones, effector)) break;
43
+ if (chainBlend < 1) this.#blend(links, bones, initialQuaternions, chainBlend);
44
+ return this;
45
+ }
46
+ createHelper() {
47
+ throw new Error(
48
+ "TN_NATIVE_UNSUPPORTED_CCDIKHELPER: CCDIKSolver.createHelper needs three's CCDIKHelper, which the engine does not bind; draw the chain from skeleton.bones instead."
49
+ );
50
+ }
51
+ // One pass over the chain; false when no link turned, which ends the solve.
52
+ #iterate(ik, bones, effector) {
53
+ let rotated = false;
54
+ for (const entry of ik.links) {
55
+ if (entry.enabled === false) break;
56
+ if (this.#rotateLink(ik, entry, bones[entry.index], effector)) rotated = true;
57
+ }
58
+ return rotated;
59
+ }
60
+ // A chain blend under 1 slerps each link from its pose before the solve toward the solved pose.
61
+ #blend(links, bones, initial, chainBlend) {
62
+ for (const [j, entry] of links.entries()) {
63
+ const link = bones[entry.index];
64
+ this.#workingQuaternion.copy(initial[j]).slerp(link.quaternion, chainBlend);
65
+ link.quaternion.copy(this.#workingQuaternion);
66
+ link.updateMatrixWorld(true);
67
+ }
68
+ }
69
+ // One CCD step on one link: rotate it so the effector points at the target. False when the angle
70
+ // is too small to turn, which three skips to prevent bone vibration.
71
+ #rotateLink(ik, entry, link, effector) {
72
+ link.matrixWorld.decompose(this.#linkPos, this.#invLinkQ, this.#linkScale);
73
+ this.#invLinkQ.invert();
74
+ this.#effectorPos.setFromMatrixPosition(effector.matrixWorld);
75
+ this.#effectorVec.subVectors(this.#effectorPos, this.#linkPos).applyQuaternion(this.#invLinkQ).normalize();
76
+ this.#targetVec.subVectors(this.#targetPos, this.#linkPos).applyQuaternion(this.#invLinkQ).normalize();
77
+ let angle = Math.acos(Math.min(1, Math.max(-1, this.#targetVec.dot(this.#effectorVec))));
78
+ if (angle < 1e-5) return false;
79
+ if (ik.minAngle !== void 0 && angle < ik.minAngle) angle = ik.minAngle;
80
+ if (ik.maxAngle !== void 0 && angle > ik.maxAngle) angle = ik.maxAngle;
81
+ this.#axis.crossVectors(this.#effectorVec, this.#targetVec).normalize();
82
+ this.#quaternion.setFromAxisAngle(this.#axis, angle);
83
+ link.quaternion.multiply(this.#quaternion);
84
+ this.#limit(entry, link);
85
+ link.updateMatrixWorld(true);
86
+ return true;
87
+ }
88
+ // three's link limits: a hinge axis, then Euler angle bounds.
89
+ #limit(entry, link) {
90
+ const { limitation, rotationMin, rotationMax } = entry;
91
+ if (limitation !== void 0) {
92
+ const q = link.quaternion;
93
+ const c = Math.min(q.w, 1);
94
+ const dot = q.x * limitation.x + q.y * limitation.y + q.z * limitation.z;
95
+ const c2 = (dot < 0 ? -1 : 1) * Math.sqrt(1 - c * c);
96
+ q.set(limitation.x * c2, limitation.y * c2, limitation.z * c2, c);
97
+ }
98
+ if (rotationMin !== void 0 || rotationMax !== void 0) {
99
+ const v = this.#vector.setFromEuler(link.rotation);
100
+ if (rotationMin !== void 0 && rotationMax !== void 0) {
101
+ const c = this.#center.addVectors(rotationMin, rotationMax).multiplyScalar(0.5);
102
+ v.x = c.x + modulo(v.x - c.x + Math.PI, 2 * Math.PI) - Math.PI;
103
+ v.y = c.y + modulo(v.y - c.y + Math.PI, 2 * Math.PI) - Math.PI;
104
+ v.z = c.z + modulo(v.z - c.z + Math.PI, 2 * Math.PI) - Math.PI;
105
+ }
106
+ if (rotationMin !== void 0) v.max(rotationMin);
107
+ if (rotationMax !== void 0) v.min(rotationMax);
108
+ link.rotation.setFromVector3(v);
109
+ }
110
+ }
111
+ #valid() {
112
+ const bones = this.mesh.skeleton.bones;
113
+ for (const ik of this.iks) {
114
+ let child = bones[ik.effector];
115
+ for (const entry of ik.links) {
116
+ const parent = bones[entry.index];
117
+ if (child.parent !== parent)
118
+ console.warn(
119
+ `THREE.CCDIKSolver: bone ${child.name} is not the child of bone ${parent.name}`
120
+ );
121
+ child = parent;
122
+ }
123
+ }
124
+ }
125
+ };
126
+
127
+ export { CCDIKSolver };