threedog 0.5.0 → 0.7.0

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 (511) hide show
  1. package/CHANGELOG.md +81 -1
  2. package/README.md +21 -13
  3. package/core/Assets.js +23 -12
  4. package/core/Audio.js +1 -1
  5. package/core/Baked.js +14 -23
  6. package/core/Budget.js +2 -2
  7. package/core/DebugOverrides.js +33 -18
  8. package/core/Describe.js +10 -11
  9. package/core/Engine.js +50 -46
  10. package/core/I18n.js +2 -2
  11. package/core/Input.js +11 -5
  12. package/core/Inspect.js +6 -3
  13. package/core/InspectMaterials.js +2 -3
  14. package/core/InspectPerf.js +11 -4
  15. package/core/MaterialInfo.js +7 -5
  16. package/core/Rays.js +7 -2
  17. package/core/Stream.js +2 -3
  18. package/core/UrlState.js +49 -9
  19. package/core/Views.js +1 -0
  20. package/core/adaptive.js +2 -2
  21. package/core/assetEntry.js +5 -2
  22. package/core/assetLoad.js +13 -15
  23. package/core/assetManifest.js +6 -3
  24. package/core/assetReport.js +4 -4
  25. package/core/batchGroups.js +9 -1
  26. package/core/catalog.js +16 -3
  27. package/core/chunkStream.js +1 -1
  28. package/core/copies.js +1 -1
  29. package/core/debugView.js +4 -4
  30. package/core/describeRender.js +104 -28
  31. package/core/describeText.js +6 -6
  32. package/core/errorCodes.js +72 -45
  33. package/core/errorHints.js +4 -1
  34. package/core/errors.js +4 -4
  35. package/core/events.generated.js +1 -0
  36. package/core/gameLights.js +9 -2
  37. package/core/lifecycle.js +2 -4
  38. package/core/lightWatch.js +5 -3
  39. package/core/loop.js +18 -11
  40. package/core/math.js +7 -0
  41. package/core/moduleSlots.js +32 -7
  42. package/core/moduleTypes.js +20 -7
  43. package/core/modules.js +7 -7
  44. package/core/namedModel.js +8 -4
  45. package/core/owned.js +33 -30
  46. package/core/page.js +43 -10
  47. package/core/pictureSlots.js +33 -0
  48. package/core/pictureWriters.js +343 -0
  49. package/core/plugins.js +64 -96
  50. package/core/sceneDelta.js +12 -4
  51. package/core/sceneMethods.js +2 -9
  52. package/core/services.js +1 -1
  53. package/core/shadowTypes.js +1 -1
  54. package/core/shadows.js +405 -0
  55. package/core/sharedPoint.js +5 -19
  56. package/core/stackFrames.js +16 -5
  57. package/core/stacks.js +6 -6
  58. package/core/startup.js +9 -11
  59. package/core/thingExplain.js +1 -1
  60. package/core/things.js +1 -1
  61. package/core/tier.js +1 -1
  62. package/core/util.js +1 -1
  63. package/core/validate.js +1 -1
  64. package/core/view.js +43 -0
  65. package/docs/AI.md +62 -58
  66. package/docs/API.md +15 -15
  67. package/docs/CODEMAP.md +36 -54
  68. package/docs/COMMANDS.md +28 -25
  69. package/docs/CONVENTIONS.md +36 -30
  70. package/docs/MIGRATING-0.4.md +93 -1
  71. package/docs/MIGRATING-0.6.md +126 -0
  72. package/docs/MIGRATING-0.7.md +39 -0
  73. package/docs/THREE.md +24 -22
  74. package/docs/api/assets.md +5 -3
  75. package/docs/api/audio.md +2 -2
  76. package/docs/api/budget.md +4 -0
  77. package/docs/api/characters.md +3 -1
  78. package/docs/api/collision.md +2 -2
  79. package/docs/api/engine.md +47 -20
  80. package/docs/api/events.md +2 -1
  81. package/docs/api/grids.md +8 -1
  82. package/docs/api/ground.md +1 -1
  83. package/docs/api/hud.md +3 -0
  84. package/docs/api/input.md +3 -2
  85. package/docs/api/interactions.md +3 -1
  86. package/docs/api/inventory.md +1 -2
  87. package/docs/api/level.md +0 -1
  88. package/docs/api/lightPool.md +1 -1
  89. package/docs/api/occlusion.md +5 -0
  90. package/docs/api/particles.md +6 -3
  91. package/docs/api/pickups.md +6 -0
  92. package/docs/api/post.md +5 -3
  93. package/docs/api/sky.md +12 -10
  94. package/docs/api/terrain.md +12 -6
  95. package/docs/api/terrainDraw.md +12 -0
  96. package/docs/api/tools.md +8 -7
  97. package/docs/api/triggers.md +2 -0
  98. package/docs/api/vegetation.md +7 -2
  99. package/docs/api/vegetationDraw.md +10 -0
  100. package/docs/api/water.md +6 -2
  101. package/docs/api/weather.md +5 -0
  102. package/docs/api/weatherDraw.md +10 -0
  103. package/docs/api/world.md +1 -1
  104. package/docs/recipes/01-new-game.md +19 -23
  105. package/docs/recipes/03-items-pickups.md +25 -4
  106. package/docs/recipes/05-props-bake.md +53 -37
  107. package/docs/recipes/06-clock-events.md +3 -3
  108. package/docs/recipes/07-flow-scenes-pause.md +12 -3
  109. package/docs/recipes/08-weather-sky.md +45 -57
  110. package/docs/recipes/09-materials-lights-models.md +185 -0
  111. package/docs/recipes/10-blender-level.md +2 -2
  112. package/docs/recipes/11-vehicles.md +3 -3
  113. package/docs/recipes/13-animation.md +13 -7
  114. package/docs/recipes/14-custom-module.md +7 -5
  115. package/docs/recipes/15-perf.md +3 -3
  116. package/docs/recipes/16-dev-bridge.md +22 -12
  117. package/docs/recipes/18-world.md +10 -8
  118. package/docs/recipes/19-shooting-picking.md +7 -5
  119. package/docs/recipes/20-content-actions-save.md +6 -2
  120. package/docs/recipes/21-camera.md +8 -3
  121. package/docs/recipes/23-ops.md +1 -1
  122. package/docs/recipes/26-ui-parts.md +35 -11
  123. package/docs/recipes/28-terrain.md +12 -12
  124. package/docs/recipes/29-grid.md +14 -5
  125. package/docs/recipes/30-templates.md +8 -3
  126. package/docs/recipes/31-audio.md +4 -4
  127. package/docs/recipes/32-action-game.md +18 -4
  128. package/docs/recipes/34-environment-lighting.md +102 -38
  129. package/docs/recipes/35-picture-from-reference.md +147 -0
  130. package/docs/recipes/36-sky-ground-plants.md +158 -0
  131. package/docs/recipes/{37-terrain-look-hooks.md → 37-terrain-hooks.md} +9 -13
  132. package/docs/recipes/38-environment-hooks.md +67 -0
  133. package/docs/recipes/40-scene.md +106 -27
  134. package/docs/recipes/42-terrain-shape.md +1 -1
  135. package/docs/recipes/{43-shader-patches-surface-looks.md → 43-shader-patches-surfaces.md} +66 -77
  136. package/docs/recipes/44-water-weather-hooks.md +191 -0
  137. package/docs/recipes/45-cascaded-shadows.md +121 -23
  138. package/docs/recipes/46-blender-art-route.md +17 -20
  139. package/docs/recipes/47-island-snow-backdrop.md +10 -12
  140. package/docs/recipes/49-game-module-contract.md +1 -1
  141. package/docs/recipes/50-own-renderer.md +3 -3
  142. package/docs/recipes/52-around-the-picture.md +181 -0
  143. package/docs/recipes/53-ground-up-close.md +12 -12
  144. package/docs/recipes/54-three-idioms.md +18 -18
  145. package/docs/recipes/55-mods-time-wrap.md +17 -5
  146. package/docs/recipes/56-webgpu-tsl.md +66 -23
  147. package/docs/recipes/57-control.md +39 -0
  148. package/docs/recipes/58-input.md +3 -0
  149. package/docs/recipes/59-depth-post-effects.md +5 -5
  150. package/docs/recipes/60-judge-the-picture.md +39 -24
  151. package/docs/recipes/61-deploy.md +27 -0
  152. package/docs/recipes/62-picture-code.md +244 -0
  153. package/docs/recipes/63-third-person-start.md +77 -0
  154. package/docs/recipes/64-particles.md +35 -0
  155. package/examples/action/.threedog/content-index.json +1 -1
  156. package/examples/action/GAMEMAP.md +7 -5
  157. package/examples/action/main.js +5 -4
  158. package/examples/action/models.js +12 -14
  159. package/examples/action/picture/index.js +13 -0
  160. package/examples/action/picture/lights.js +35 -0
  161. package/examples/action/picture/materials.js +8 -0
  162. package/examples/action/picture/palette.js +33 -0
  163. package/examples/plain-picture/.threedog/content-index.json +1 -0
  164. package/examples/plain-picture/FINDINGS.md +53 -0
  165. package/examples/plain-picture/GAMEMAP.md +90 -0
  166. package/examples/plain-picture/main.js +48 -0
  167. package/examples/plain-picture/picture/index.js +21 -0
  168. package/examples/plain-picture/picture/lights.js +54 -0
  169. package/examples/plain-picture/picture/materials.js +24 -0
  170. package/examples/plain-picture/picture/palette.js +16 -0
  171. package/examples/plain-picture/picture/sky.js +37 -0
  172. package/examples/pullable.json +31 -9
  173. package/examples/rc2d/GAMEMAP.md +8 -3
  174. package/examples/rc2d/README.md +11 -6
  175. package/examples/rc2d/main.js +25 -33
  176. package/examples/rc2d/picture/index.js +18 -0
  177. package/examples/rc2d/picture/lights.js +11 -0
  178. package/examples/rc2d/picture/materials.js +18 -0
  179. package/examples/rc2d/picture/palette.js +15 -0
  180. package/examples/rc2d/picture/post.js +11 -0
  181. package/examples/rc2d/rc2d.js +18 -28
  182. package/examples/sheepisland/.threedog/content-index.json +1 -1
  183. package/examples/sheepisland/GAMEMAP.md +13 -10
  184. package/examples/sheepisland/assets.js +2 -2
  185. package/examples/sheepisland/content/templates.js +1 -1
  186. package/examples/sheepisland/content/vegetation.js +3 -1
  187. package/examples/sheepisland/main.js +15 -9
  188. package/examples/sheepisland/{style/models.js → models.js} +13 -24
  189. package/examples/sheepisland/picture/index.js +20 -0
  190. package/examples/sheepisland/picture/lights.js +34 -0
  191. package/examples/sheepisland/picture/materials.js +61 -0
  192. package/examples/sheepisland/picture/palette.js +60 -0
  193. package/examples/sheepisland/picture/sky.js +20 -0
  194. package/examples/sheepisland/views.js +1 -1
  195. package/examples/styletest/.threedog/content-index.json +1 -1
  196. package/examples/styletest/GAMEMAP.md +15 -11
  197. package/examples/styletest/main.js +20 -30
  198. package/examples/styletest/models.js +29 -29
  199. package/examples/styletest/params.js +1 -4
  200. package/examples/styletest/picture/env.js +38 -0
  201. package/examples/styletest/picture/index.js +16 -0
  202. package/examples/styletest/picture/lights.js +9 -0
  203. package/examples/styletest/picture/materials.js +28 -0
  204. package/examples/styletest/picture/palette.js +22 -0
  205. package/examples/techniques/contact-shadows/README.md +22 -23
  206. package/examples/techniques/contact-shadows/contactShadows.js +32 -16
  207. package/examples/techniques/contact-shadows/main.js +20 -18
  208. package/examples/techniques/contact-shadows/picture/index.js +14 -0
  209. package/examples/techniques/contact-shadows/picture/lights.js +34 -0
  210. package/examples/techniques/contact-shadows/picture/materials.js +12 -0
  211. package/examples/techniques/contact-shadows/picture/palette.js +17 -0
  212. package/examples/techniques/day-night-grade/README.md +13 -16
  213. package/examples/techniques/day-night-grade/main.js +15 -25
  214. package/examples/techniques/day-night-grade/picture/index.js +20 -0
  215. package/examples/techniques/day-night-grade/picture/lights.js +45 -0
  216. package/examples/techniques/day-night-grade/picture/materials.js +15 -0
  217. package/examples/techniques/day-night-grade/picture/palette.js +59 -0
  218. package/examples/techniques/day-night-grade/picture/post.js +25 -0
  219. package/examples/techniques/day-night-grade/picture/sky.js +33 -0
  220. package/examples/techniques/interior-light/README.md +16 -13
  221. package/examples/techniques/interior-light/interiorLight.js +19 -17
  222. package/examples/techniques/interior-light/main.js +30 -67
  223. package/examples/techniques/interior-light/picture/index.js +24 -0
  224. package/examples/techniques/interior-light/picture/lights.js +52 -0
  225. package/examples/techniques/interior-light/picture/materials.js +13 -0
  226. package/examples/techniques/interior-light/picture/palette.js +32 -0
  227. package/examples/techniques/interior-light/picture/sky.js +40 -0
  228. package/examples/techniques/modular-building/README.md +4 -3
  229. package/examples/techniques/modular-building/kit.js +2 -2
  230. package/examples/techniques/modular-building/main.js +9 -17
  231. package/examples/techniques/modular-building/picture/index.js +17 -0
  232. package/examples/techniques/modular-building/picture/lights.js +26 -0
  233. package/examples/techniques/modular-building/picture/materials.js +13 -0
  234. package/examples/techniques/modular-building/picture/palette.js +23 -0
  235. package/examples/techniques/night-lights/README.md +15 -14
  236. package/examples/techniques/night-lights/main.js +20 -43
  237. package/examples/techniques/night-lights/nightLights.js +25 -21
  238. package/examples/techniques/night-lights/picture/index.js +18 -0
  239. package/examples/techniques/night-lights/picture/lights.js +44 -0
  240. package/examples/techniques/night-lights/picture/materials.js +15 -0
  241. package/examples/techniques/night-lights/picture/palette.js +34 -0
  242. package/examples/techniques/night-lights/picture/post.js +9 -0
  243. package/examples/techniques/night-lights/picture/sky.js +36 -0
  244. package/examples/techniques/outlines-and-rim/README.md +2 -2
  245. package/examples/techniques/outlines-and-rim/main.js +15 -38
  246. package/examples/techniques/outlines-and-rim/outlines.js +3 -3
  247. package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
  248. package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
  249. package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
  250. package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
  251. package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
  252. package/examples/techniques/procedural-animation/README.md +5 -3
  253. package/examples/techniques/procedural-animation/main.js +9 -7
  254. package/examples/techniques/procedural-animation/picture/index.js +15 -0
  255. package/examples/techniques/procedural-animation/picture/lights.js +35 -0
  256. package/examples/techniques/procedural-animation/picture/materials.js +10 -0
  257. package/examples/techniques/procedural-animation/picture/palette.js +16 -0
  258. package/examples/techniques/procedural-animation/picture/sky.js +31 -0
  259. package/examples/techniques/procedural-animation/proceduralAnim.js +1 -1
  260. package/examples/techniques/procedural-surface/README.md +2 -0
  261. package/examples/techniques/procedural-surface/main.js +17 -55
  262. package/examples/techniques/procedural-surface/picture/index.js +14 -0
  263. package/examples/techniques/procedural-surface/picture/lights.js +18 -0
  264. package/examples/techniques/procedural-surface/picture/materials.js +34 -0
  265. package/examples/techniques/procedural-surface/picture/palette.js +15 -0
  266. package/examples/techniques/stylized-shading/README.md +13 -14
  267. package/examples/techniques/stylized-shading/main.js +11 -42
  268. package/examples/techniques/stylized-shading/picture/index.js +14 -0
  269. package/examples/techniques/stylized-shading/picture/lights.js +23 -0
  270. package/examples/techniques/stylized-shading/picture/materials.js +18 -0
  271. package/examples/techniques/stylized-shading/picture/palette.js +19 -0
  272. package/examples/techniques/stylized-shading/shading.js +2 -2
  273. package/examples/techniques/sun-and-key-light/README.md +20 -22
  274. package/examples/techniques/sun-and-key-light/keyLight.js +47 -29
  275. package/examples/techniques/sun-and-key-light/main.js +19 -63
  276. package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
  277. package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
  278. package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
  279. package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
  280. package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
  281. package/examples/techniques/three-looks/README.md +21 -0
  282. package/examples/techniques/three-looks/main.js +58 -0
  283. package/examples/techniques/three-looks/picture/cartoon.js +23 -0
  284. package/examples/techniques/three-looks/picture/cinematic.js +27 -0
  285. package/examples/techniques/three-looks/picture/comic.js +27 -0
  286. package/examples/techniques/three-looks/picture/index.js +14 -0
  287. package/examples/techniques/three-looks/picture/sun.js +23 -0
  288. package/examples/techniques/wet-road/README.md +7 -4
  289. package/examples/techniques/wet-road/main.js +18 -38
  290. package/examples/techniques/wet-road/picture/index.js +17 -0
  291. package/examples/techniques/wet-road/picture/lights.js +57 -0
  292. package/examples/techniques/wet-road/picture/materials.js +16 -0
  293. package/examples/techniques/wet-road/picture/palette.js +24 -0
  294. package/examples/techniques/wet-road/picture/sky.js +46 -0
  295. package/examples/webgpu-tsl/GAMEMAP.md +9 -4
  296. package/examples/webgpu-tsl/README.md +13 -10
  297. package/examples/webgpu-tsl/main.js +30 -7
  298. package/examples/webgpu-tsl/picture/index.js +18 -0
  299. package/examples/webgpu-tsl/picture/lights.js +25 -0
  300. package/examples/webgpu-tsl/picture/materials.js +36 -0
  301. package/examples/webgpu-tsl/picture/palette.js +23 -0
  302. package/examples/webgpu-tsl/picture/post.js +16 -0
  303. package/examples/webgpu-tsl/picture/sky.js +30 -0
  304. package/examples/world/.threedog/content-index.json +1 -1
  305. package/examples/world/GAMEMAP.md +15 -12
  306. package/examples/world/art/humanoid.js +9 -13
  307. package/examples/world/art/index.js +2 -2
  308. package/examples/world/art/models.js +3 -4
  309. package/examples/world/art/shapes.js +2 -2
  310. package/examples/world/assets.js +2 -2
  311. package/examples/world/content/audio.js +1 -1
  312. package/examples/world/content/items.js +1 -1
  313. package/examples/world/content/props.js +1 -1
  314. package/examples/world/content/templates.js +1 -1
  315. package/examples/world/content/vegetation.js +1 -1
  316. package/examples/world/main.js +10 -10
  317. package/examples/world/models.js +17 -7
  318. package/examples/world/picture/index.js +20 -0
  319. package/examples/world/picture/lights.js +41 -0
  320. package/examples/world/picture/materials.js +34 -0
  321. package/examples/world/picture/palette.js +74 -0
  322. package/examples/world/picture/post.js +9 -0
  323. package/examples/world/picture/sky.js +39 -0
  324. package/index.d.ts +7 -16
  325. package/index.js +7 -7
  326. package/llms.txt +15 -13
  327. package/modules/ambience/Ambience.js +1 -1
  328. package/modules/calendar/Calendar.js +1 -1
  329. package/modules/calendar/index.js +1 -0
  330. package/modules/camera/FirstPersonCamera.js +1 -1
  331. package/modules/camera/FixedCamera.js +2 -2
  332. package/modules/camera/RtsCamera.js +1 -1
  333. package/modules/camera/common.js +7 -5
  334. package/modules/characters/Character.js +15 -10
  335. package/modules/characters/NPC.js +5 -5
  336. package/modules/characters/assetModel.js +5 -4
  337. package/modules/characters/index.js +28 -3
  338. package/modules/characters/movers/common.js +6 -1
  339. package/modules/characters/movers/manual.js +3 -0
  340. package/modules/characters/movers/support.js +25 -11
  341. package/modules/characters/npcSim.js +5 -1
  342. package/modules/characters/proceduralRig.js +18 -4
  343. package/modules/characters/useModel.js +2 -2
  344. package/modules/collision/Collision.js +4 -2
  345. package/modules/content/index.js +8 -0
  346. package/modules/content/models.js +56 -11
  347. package/modules/content/props.js +5 -3
  348. package/modules/content/rules.js +12 -4
  349. package/modules/content/templates.js +5 -3
  350. package/modules/gameplay/Interactions.js +91 -16
  351. package/modules/gameplay/Inventory.js +3 -3
  352. package/modules/gameplay/dialogueBox.js +1 -1
  353. package/modules/gameplay/dialogueBubbles.js +1 -1
  354. package/modules/gameplay/interactionPrompt.js +1 -1
  355. package/modules/gameplay/interactions.contract.js +1 -1
  356. package/modules/gameplay/inventoryOps.js +2 -2
  357. package/modules/gameplay/pickups.js +62 -24
  358. package/modules/gameplay/questLog.js +2 -2
  359. package/modules/grid/Layer.js +13 -0
  360. package/modules/grid/index.js +40 -11
  361. package/modules/grid/preview.js +24 -15
  362. package/modules/grid/tiles.js +15 -19
  363. package/modules/hlod/index.js +3 -2
  364. package/modules/hud/index.js +13 -0
  365. package/modules/hud/parts.js +9 -7
  366. package/modules/level/index.js +5 -4
  367. package/modules/lights/index.js +12 -8
  368. package/modules/music/Music.js +1 -1
  369. package/modules/particles/Particles.js +41 -20
  370. package/modules/particles/effect.js +21 -6
  371. package/modules/photo/Photo.js +11 -10
  372. package/modules/settings/Settings.js +7 -7
  373. package/modules/settings/apply.js +5 -5
  374. package/modules/settings/sections.js +2 -2
  375. package/modules/settings/strings.js +1 -1
  376. package/modules/sky/Sky.js +104 -89
  377. package/modules/sky/clouds.js +16 -17
  378. package/modules/sky/dome.js +100 -0
  379. package/modules/sky/domeLayers.js +5 -5
  380. package/modules/sky/environment.js +45 -169
  381. package/modules/sky/fog.js +5 -180
  382. package/modules/sky/frame.js +26 -90
  383. package/modules/sky/season.js +3 -3
  384. package/modules/sky/shader.js +35 -29
  385. package/modules/sky/skyModule.js +25 -22
  386. package/modules/sky/tint.js +9 -11
  387. package/modules/terrain/ChunkManager.js +29 -12
  388. package/modules/terrain/draw.js +154 -0
  389. package/modules/terrain/index.js +44 -66
  390. package/modules/terrain/terrainDefaults.js +2 -2
  391. package/modules/terrain/terrainEdit.js +1 -1
  392. package/modules/terrain/terrainGen.js +2 -2
  393. package/modules/triggers/index.js +10 -6
  394. package/modules/vegetation/Vegetation.js +58 -17
  395. package/modules/vegetation/draw.js +191 -0
  396. package/modules/vegetation/groundChunks.js +1 -1
  397. package/modules/vegetation/index.js +10 -10
  398. package/modules/water/Water.js +135 -88
  399. package/modules/water/surface.js +53 -53
  400. package/modules/weather/Weather.js +52 -17
  401. package/modules/weather/particles.js +13 -5
  402. package/modules/weather/shaders.js +1 -1
  403. package/modules/weather/weatherDraw.js +141 -0
  404. package/modules/world/World.js +2 -2
  405. package/modules/world/views.js +1 -1
  406. package/package.json +3 -2
  407. package/presets.js +2 -2
  408. package/render/PostFX.js +199 -41
  409. package/render/backend.js +52 -6
  410. package/render/cascades.js +195 -0
  411. package/render/cascades.tsl.js +96 -0
  412. package/render/daylight.js +39 -0
  413. package/render/detail.js +5 -5
  414. package/render/effects.js +41 -26
  415. package/render/fx/cel.tsl.js +42 -0
  416. package/render/fx/index.js +7 -5
  417. package/render/fx/patchNodes.tsl.js +1 -1
  418. package/render/fx/postWebGPU.tsl.js +30 -7
  419. package/render/fx/sky.tsl.js +19 -92
  420. package/render/fx/water.tsl.js +1 -1
  421. package/render/layers.js +14 -0
  422. package/render/lighting.js +6 -5
  423. package/render/lightmap.js +142 -0
  424. package/render/lights.js +23 -201
  425. package/render/materials.js +44 -160
  426. package/render/neutral.js +23 -0
  427. package/render/occlusion.js +184 -0
  428. package/render/ownFrame.js +1 -1
  429. package/render/patches.js +34 -29
  430. package/render/postWebGL.js +11 -3
  431. package/render/probes.js +179 -122
  432. package/render/slots.js +4 -4
  433. package/render/terms.js +53 -101
  434. package/render/uniformDecl.js +1 -1
  435. package/types/core.d.ts +333 -296
  436. package/types/gameplay.d.ts +65 -26
  437. package/types/generated/core/Audio.d.ts +1 -1
  438. package/types/generated/core/DebugOverrides.d.ts +14 -6
  439. package/types/generated/core/Input.d.ts +9 -2
  440. package/types/generated/core/page.d.ts +9 -2
  441. package/types/generated/modules/grid/Layer.d.ts +8 -0
  442. package/types/generated/modules/grid/index.d.ts +29 -5
  443. package/types/generated/modules/particles/Particles.d.ts +13 -6
  444. package/types/generated/modules/sky/Sky.d.ts +85 -18
  445. package/types/generated/modules/sky/skyModule.d.ts +1 -1
  446. package/types/generated/modules/water/Water.d.ts +50 -3
  447. package/types/generated/modules/weather/Weather.d.ts +33 -3
  448. package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
  449. package/types/generated/modules/world/World.d.ts +2 -2
  450. package/types/generated/render/PostFX.d.ts +53 -10
  451. package/types/generated/render/lighting.d.ts +29 -0
  452. package/types/generated/render/materials.d.ts +19 -44
  453. package/types/generated/render/occlusion.d.ts +13 -0
  454. package/types/physics.d.ts +5 -3
  455. package/types/tsl.d.ts +8 -0
  456. package/types/world.d.ts +376 -57
  457. package/ui/Focus.js +12 -2
  458. package/ui/LoadingScreen.js +2 -2
  459. package/ui/Parts.js +8 -4
  460. package/ui/UI.js +10 -10
  461. package/ui/cursor.js +1 -1
  462. package/ui/theme.js +33 -27
  463. package/ui/touchPart.js +1 -1
  464. package/core/look/coreParts.js +0 -219
  465. package/core/look/part.js +0 -253
  466. package/core/look/points.js +0 -255
  467. package/core/look/report.js +0 -96
  468. package/core/look/shadowPart.js +0 -63
  469. package/core/look/state.js +0 -45
  470. package/core/look/write.js +0 -70
  471. package/core/styleParts.js +0 -114
  472. package/docs/api/style.md +0 -136
  473. package/docs/api/terrainLook.md +0 -10
  474. package/docs/api/vegetationLook.md +0 -10
  475. package/docs/api/weatherLook.md +0 -10
  476. package/docs/recipes/09-style.md +0 -218
  477. package/docs/recipes/35-style-from-reference.md +0 -153
  478. package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
  479. package/docs/recipes/38-environment-look-hooks.md +0 -99
  480. package/docs/recipes/41-thing-registry.md +0 -97
  481. package/docs/recipes/44-water-weather-look-hooks.md +0 -144
  482. package/docs/recipes/48-make-material.md +0 -75
  483. package/docs/recipes/52-look.md +0 -282
  484. package/examples/action/look.js +0 -5
  485. package/examples/sheepisland/style/index.js +0 -79
  486. package/examples/styletest/look.js +0 -11
  487. package/examples/techniques/day-night-grade/dayNightGrade.js +0 -76
  488. package/examples/webgpu-tsl/tslScene.js +0 -75
  489. package/examples/world/style/index.js +0 -61
  490. package/examples/world/style/plugins/10-bloom.js +0 -5
  491. package/modules/sky/cascades.js +0 -186
  492. package/modules/sky/cascades.tsl.js +0 -82
  493. package/modules/sky/look.js +0 -54
  494. package/modules/sky/lookFog.js +0 -76
  495. package/modules/sky/lookShadow.js +0 -62
  496. package/modules/sky/lookSky.js +0 -169
  497. package/modules/sky/shadow.js +0 -98
  498. package/modules/terrain/look.js +0 -83
  499. package/modules/terrain/lookGround.js +0 -66
  500. package/modules/vegetation/look.js +0 -119
  501. package/modules/vegetation/lookWind.js +0 -98
  502. package/modules/water/look.js +0 -91
  503. package/modules/water/surfaceDefaults.js +0 -3
  504. package/modules/weather/look.js +0 -74
  505. package/modules/weather/weatherLook.js +0 -135
  506. package/render/lookGlow.js +0 -139
  507. package/render/lookSurface.js +0 -224
  508. package/render/postLook.js +0 -164
  509. package/render/surface.js +0 -105
  510. package/types/generated/modules/weather/weatherLook.d.ts +0 -12
  511. package/types/style.d.ts +0 -671
package/CHANGELOG.md CHANGED
@@ -1,6 +1,86 @@
1
1
  # Changelog (threedog)
2
2
 
3
- The engine has not been released yet, so this log is not maintained before release. At release time it is written in one pass from git history and `docs/API.md`: "what changed, how a game upgrades", placed under the version heading.
3
+ What changed in each version and how a game upgrades.
4
+
5
+ ## 0.7.0 (2026-11-05)
6
+
7
+ - Public surface audit (`threedog api-count --unused`): removed `engine.level.object` (same as `level.root`); dropped from the public types (code stays, engine-internal) `engine.triggers.action`, `engine.settings.action`, `engine.interactions.action` (copies of the module option), `engine.inventory.defs`, `engine.quests.defs` (use `inventory.item(id)` and `quests.list()`). 98 more unused names are kept on purpose, each with a reason in `packages/tools/api-count.mjs`
8
+ - Follow camera: `collision({ cameraOcclusion })` now defaults to `'both'`: meshes registered with `engine.rays.addStatic(mesh, { occluder: true })` stop the arm without a gameplay collider (a crown, an eave). Level buildings count too; `'colliders'` keeps the old test.
9
+ - `character.placeAt` over a registered support stands on it; `mover: 'manual'` runs the `states` hook. Recipe 57 "Moved by script" (ride, lift, ladder), recipe 32 says what a support needs.
10
+ - Script runs: `?fresh` / `applyState({ fresh })` / `threedog state fresh=1` delete the saves for a clean start; `inputLocked` carries `facts.by`; `snap --play`; `shot` and `snap` name the backend that drew the picture; `snap` timeouts say what the page was doing; a `js` script waiting on a stopped clock ends with the reason; the WebGPU fallback is one line in errors.log.
11
+ - `threedog assets optimize [--dry]`: Meshopt + KTX2 copies of art/models/ in public/optimized/, textures encoded by slot (a normal map is never compressed as color), `assets.js` pointed at the results, reruns skip unchanged files, per-file size / GPU memory / problems. `npm run assets` crashed on start (a name used twice); fixed.
12
+ - Light probes: `engine.bakeProbes` now builds three's per-pixel probe grid on both renderers, stored in half precision; `follow`, `height`, `probes.probe` and `own()` are gone, probe files are version 2 (MIGRATING-0.7.md). `describe().render.probes` reports lit objects outside the grid and light counted twice.
13
+ - Real-time light on WebGPU: `@threedog/post-effects/tsl` adds `voxelGI`, `temporalAA`, `sunShafts`, `lightVolumes`. Post effects gain `needsBuffers` (normal, diffuse, velocity merged into one scene render), `backend`, `skipOnLowTier` and `facts`; `describe().render.post` says `held` and why.
14
+ - Occlusion culling: `engine.occlusion.enabled` skips hlod cells and batched groups while hidden, on both renderers; `describe().render.occlusion`.
15
+ - Lightmaps: `threedog bake light` (system Chrome, real WebGPU) and `engine.loadLightmap(file)`; `describe().render.lightmap`.
16
+ - `celLighting` in `threedog/tsl`: colored cel bands on `MeshToonNodeMaterial`, cast shadows in the same bands. `paletteLut` in `@threedog/post-effects`: a fixed palette for `lut()`. Docs no longer say `rampTexture` colors work on three's toon: it reads only the red channel.
17
+ - New games start on WebGPU with TSL: `threedog new-game` and `init` write `import 'threedog/tsl'` and `createEngine({ renderer: 'webgpu' })`; `--webgl` starts the GLSL form instead. `--example` and `templates/example` are removed. `createEngine` called with no `renderer` still builds the WebGL renderer. With no WebGPU in the browser the game runs on three's WebGL2 backend, slower.
18
+ - `engine.hud.value(id)` reads the current value of a counter or bar. `describe().renderer` gives `requested`, `backend`, `reason`, and `gpu`, `tsl`, `glsl`, `compute` (what that backend can run).
19
+ - `threedog/layers` exports `RESERVED_LAYERS`, the one table of the three.js layers the engine keeps (26 to 29 and 31); a game's own layers are 1 to 25.
20
+ - `threedog js --wait <seconds>`: a script waiting on the game clock on a page nobody steps ends with the reason instead of a silent timeout.
21
+
22
+ ## 0.6.0 (2026-11-04)
23
+
24
+ - Fixed: on WebGPU, cascades on a light whose `target` has a parent took the target's local position, so shadows fell another way than the light shone; they use its world position now, as WebGL does.
25
+ - Breaking: `grids.preview({ look })` is `{ draw }` and a layer's `tiles: { look }` is `tiles: { color }`; an unknown `tiles` key now throws.
26
+ - New: picture parts. `PICTURE_SLOTS` and the type `PictureSlot` name the picture values only one writer may hold (sky, fog, tone, environment, background, sun); `describe('picture').picture.slots` shows the holders; `engine.unuse(name)` removes a module. On the dev server a write to a value another part holds warns `picture-held`, and a removed picture part's leftovers warn `picture-leftover` (recipes/62-picture-code.md 3e).
27
+ - Fixed: the sky dome stayed in the scene after `engine.use(mySky(), { replaces: 'sky' })`.
28
+ - Breaking: `look` no longer names picture things. The game folder is `picture/` and `createPicture(engine)`, gameplay calls `picture.lamp(id)`; the module type is `'picture'`; the drawing parts are `terrainDraw`, `vegetationDraw`, `weatherDraw` with slots `terrain-draw`, `vegetation-draw`.
29
+ - Breaking: the look check is the picture check: `--no-picture`, `picture` and `pictureMs` in `shot --json`, the `Picture intent:` line in DESIGN.md, `lib add --kind picture`, `@threedog/tools/picture-check`. Seven recipes and the `plain-picture` example are renamed. Every old and new name is in MIGRATING-0.6.md.
30
+ - New (dev server only): `describe('picture').writers` and `engine.explain({ picture: 'fog.far' })` (`threedog explain picture fog.far`) name the file:line that last changed a light, fog, tone, environment, background or material value; a value not tracked says so. Two places writing one value in one frame with different results give one warning (`picture-conflict`) naming both. The look check adds measured facts: a `ShaderMaterial` that ignores fog or tone, a light layout changed during play, transparent meshes whose pixels depend on draw order. Recipe 62 "Wiring `picture/` parts".
31
+ - Breaking: `makeMaterial`, `engine.makeMaterial`, `look.materials`, `look.surface` and the glow verb are gone, and so are the material and patch plugin slots: materials are plain three.js. New: `applyEffects(mat, { lighting })`, `rampTexture`, the `uNight` signal.
32
+ - Breaking: `createEngine({ style })` is gone and throws with the fix: the look is plain three.js in the game's `picture/` code, UI colors go in `createEngine({ ui })`, season tints are `engine.sky.seasonTints`; `types/style.d.ts` and `core/styleParts.js` are deleted.
33
+ - Docs: recipes 09 (style folder) and 48 (makeMaterial) are merged into `recipes/09-materials-lights-models.md`: materials are plain three.js in `picture/`, module looks are `.material`, the UI look is `createEngine({ ui })`. Recipe 43 teaches shader code through `applyEffects` only; the `lighting` spec key becomes a plain `lighting` slot patch there.
34
+ - Breaking: the dev panel (`?panel=1`) reads and writes three.js objects directly; its style export, "apply and rebuild" and `?ov=` are gone, `engine.styleWorkbench` is `engine.devPanel`, and the `threedog tune` block holds plain three.js writes.
35
+ - Breaking: `threedog style check` is removed; `threedog style palette | compare` are now `threedog picture palette | compare` (bridge `picture-palette`, `picture-compare`; MCP `picture_palette`, `picture_compare`).
36
+ - Breaking: `style.character` is gone: `characters({ animation })`, and `engine.characters.material` is the plain three.js material of every placeholder capsule.
37
+ - Breaking: `style.triggers` is gone: `triggers({ debugColor, debugOpacity })`.
38
+ - Breaking: `style.palette` is gone: `engine.assets.palette`, a plain writable object that generators read as `this.palette`; a write rebuilds what is asked for after it.
39
+ - Breaking: cached and baked models read their materials back as recorded (plain three.js, `neutralMaterial`), no longer rebuilt from a material role. `assets.report()` says `madeByEngine`; `explain().materials` lost `keys`.
40
+ - Breaking: `style.grid` is gone: `grids({ ok, bad, previewOpacity, previewHeight, tiles, tileLift })`; the preview's and tiles' plain three.js materials are `pv.material` and `layer.material`.
41
+ - Breaking: `style.pickup` is gone: `pickups({ color, size, lift })`, and `engine.pickups.material` is the plain three.js material of boxes and geometry-only models.
42
+ - Breaking: `style.ui` is gone; the UI look sits in `createEngine({ ui: { theme, css, fonts, templates } })` beside the part names, and `engine.ui.templates` is writable.
43
+ - Breaking: `look.ground` and `style.terrain` are gone. The ground's look is `terrain({ colors, biomeColors, steep, variation, detail })`, `engine.terrain.material` (get / set), `.uniforms`, `.patches`, `.recolor()` (recipe 36).
44
+ - Breaking: `look.water` and `style.water` are gone. The water's look is `engine.water.material` (get / set), `.uniforms`, `.patches`, `.shader()`, `.normalMap()` (recipe 44).
45
+ - Breaking: `style.particles` is gone: `particles({ effects, default })`; an effect's `.material` is get / set and drawn as given, `.uniforms` its `{ value }` objects (recipe 64).
46
+ - Breaking: weather looks are `weather({ rain, snow, area, lightning, lightningBrightness, overcastColor })` options; `engine.weather.define(field, spec)` and `engine.weather.particles` (plain `.material`, `.uniforms`, `.spec`) replace `look.weather`.
47
+ - Breaking: plants take plain materials. `engine.vegetation.material`, `.patches`, `.sway()` and `.color()` replace `look.wind` and `look.vegetation`; wind strength and speed are `engine.uniforms.uWindAmp` / `uWindFreq`.
48
+ - `threedog art board`: every art resource of a game on one page, with where it is used, what is unused, missing or not traced, and copy lines for the AI; `--json` is the same data, `--live` and the dev panel's "art" folder show what the running game really loaded.
49
+ - `?at=<place>` (`threedog shot --at <place>`, `applyState({ at })`): skips the start screen and stands the player at a named place with the game's camera on it at once. `?pos` no longer opens on a camera glide either (new event `state:placed`).
50
+ - `interactions.add(mesh, { label, onUse, once, counter })`: `once` hides the mesh after a use, `counter` adds to a HUD counter (new `hud.add(name, n)`), both saved in the new `interactions` save part; pick-and-count things no longer need pickups and an inventory. Recipe 03 says which to use when.
51
+ - `createEngine({ ui: { theme } })` is the one place to reskin: every default part (dialogue, prompt, HUD, toast, menus, title) reads its variables, and recipe 26 "Reskin" lists them on one screen. The HUD now follows `bg` / `fg` / `accent` unless `hudBg` / `hudFg` / `hudAccent` are set; new `radiusSmall` and `shadowSmall` replace the corners and shadows that were fixed in the CSS (the default toast is no longer a pill).
52
+ - Breaking: the sky writes no light, fog, exposure or environment; it computes the signals and draws the dome. Your `picture/` code reads `engine.uniforms` and writes three.js (recipe 62).
53
+ - Breaking: `sky({ sun | hemisphere | fog })` throw naming what to write; delete the option. `createEngine({ lights: false })` drops the placeholder lights, which are now still.
54
+ - Breaking: no fog by default. `style.sky.fog` and `look.fog.set` write `scene.fog` once; a fog that changes over the day is yours.
55
+ - Breaking: no default tone curve (`renderer.toneMapping` stays three.js's default unless `style.toneMapping` names one), and no room environment map unless `look.lights` `env.intensity` is above 0. `env.share` is gone.
56
+ - Breaking: `style.exposure` and `look.tone` exposure are numbers, and `look.lights` keys take no function: exposure and light over the day are your `picture/` code.
57
+ - Breaking: weather no longer multiplies `look.lights.*` or `look.fog.far`; it writes the signals `uWeatherLight` and `uWeatherFog`. `uViewDistance` is new (stream radius without terrain, a fog's far; `terrain({ viewFog: true })` writes it).
58
+ - Breaking: plain game materials get the cloud-shadow patch only once the game turns cloud shadow on, in one recompile at that moment.
59
+ - Breaking: `style.sky.groundTint` and `part.author.drive / driven / feed` are gone (nothing left reads them).
60
+ - `describe().render.defaults` lists what the engine itself still puts on the picture, each with how to stop it.
61
+ - The `look.*` verbs are deprecated: no new features, recipe 52 says what to write instead. Removal is a later step.
62
+ - `threedog new-game`: `main.js` wires a start screen, autosave and Esc pause + settings menu (delete a line to drop one), the template's CLAUDE.md opens with an "Already here" table, recipe 63 is a 16-line third-person start. R40 hints at a hand-written localStorage save or pause; `shot` says when the start screen covers the picture.
63
+ - Esc under pointer lock opens the menu on the first press: the browser keeps that key, so a lock the player ended counts as the back key when nothing else is open and the game is running. `page:pointerlock` also says `byEngine`.
64
+ - `threedog lib add --kind look` stores one file from `picture/` (or a `.glsl`) in the library and `lib pull` puts it back under `picture/` (`picture/shaders/` for `.glsl`); a look file that imports siblings is refused at add. `art copy` of a folder takes `.glsl` files along. Recipe 62 section 3c.
65
+ - `engine.shadows.cascades(light, { count: 3 })`: cascaded shadows for a game's own DirectionalLight, with or without a sky, on both renderers; returns a handle (`set`, `remove`). `look.shadow.set({ cascades })` runs on the same code; the look check's usage line for a game's own light points here; recipe 45.
66
+ - The look check points the way: over-budget facts (new budget entries `shadowMaps`, `shadowMapSize`), usage lines for cascaded shadows and `lightPool`, new facts for near-black shadows, shadow stripes and stepped edges, and fog named first when it is most of the picture. They read the game's own lights too. Recipe 60 "When the look check names a feature".
67
+ - `threedog new-game` generates a `picture/` folder instead of `style/`: the gray starting picture as plain three.js the game owns (`index`, `palette`, `lights`,
68
+ `materials`), with `createEngine({ lights: false })`; recipe 62. Styles keep working. Water with no fog reflects the sky's horizon color, not a fixed gray.
69
+ - Prop and template `collide: 'circle'` now stands on the model's base (the lowest fifth of its height above the ground), not on its widest extent: a lamp's arm or a tree's crown no longer blocks walkers or pulls the follow camera in. Characters can walk closer to such models; a box is unchanged. New form: `collide: { circle: 0.25, occluder: false }`. A mistyped `collide` is refused at load.
70
+ - `lightPool`: a camera cut (`engine.views.show`, a fixed-camera shot) moves the lights at once, without the fade; `shot --view` drew the old spot's lamps. `views.show` emits `camera:shot`.
71
+ - `threedog shot <url>`: a local dev server of another game's folder is refused; one that cannot say is reported. The scene is counted again after the picture, with a warning if it changed.
72
+ - Black-frame hint lists shader programs that failed to compile. Test runner: a second argument to `ev` fails.
73
+ - `threedog shot` and `threedog capture` wait for the game's code after `await engine.start()` (lamps added after a later await): no request in
74
+ flight and the scene's objects / lights / materials unchanged for 0.3 s, at most 10 s; shot says how long it waited and what was added.
75
+ - `presets.camera.overShoulder` looks up (minPitch -1.05) like `thirdPersonAction`; every camera preset that locks the mouse can look up (tested).
76
+ - The look check names the material whose hiding brings a black frame back (a ShaderMaterial with NaN / Inf, spread by bloom), and reports fog
77
+ that is most of the color in a large share of the picture, with its near / far and color.
78
+ - Deploying under a sub-path: `threedog build my-game --base /my-game/` (Git Bash's rewrite of `/my-game/` is undone), and root-relative
79
+ manifest paths (`'/models/x.glb'`) now follow the build's base; recipes/61-deploy.md. The pack test builds and serves under a sub-path.
80
+ - `threedog describe` and the other bridge commands: when a threedog dev server of another folder answers, the message says so instead of
81
+ "no dev server".
82
+ - Dev error log: a repeated warning (warned again after each reload) is counted, not written again.
83
+ - Recipe 32: bullet time needs `engine.time.channel('enemies')` first, and world records follow it through `world.simulate(kind, { channel })`.
4
84
 
5
85
  ## 0.5.0 (2026-11-04)
6
86
 
package/README.md CHANGED
@@ -1,41 +1,49 @@
1
1
  # threedog
2
2
 
3
- A web 3D game engine on three.js 0.187: **core** (rendering, main loop, input, audio, saving, UI) -> **modules** (terrain, sky and weather, physics, characters, dialogue, inventory, quests... installed on demand); all art is the game's own (`style/` folder, `assets.js`).
3
+ A web 3D game engine on three.js 0.187: **core** (rendering, main loop, input, audio, saving, UI) -> **modules** (terrain, sky and weather, physics, characters, dialogue, inventory, quests... installed on demand); all art is the game's own (`picture/` folder, `assets.js`).
4
4
 
5
5
  ## Install
6
- This README describes threedog 0.5.0 (older 0.2 releases on npm do not match it). To work on the engine itself, clone the [repository](https://github.com/penstic123-code/ThreeDog.js-Game-Engine), run `npm install`, then `npm run new-game -- my-game`. A game in its own folder:
6
+ This README describes threedog 0.7.0 (older releases on npm do not match it; upgrade steps are in `docs/MIGRATING-0.7.md`). To work on the engine itself, clone the [repository](https://github.com/penstic123-code/ThreeDog.js-Game-Engine), run `npm install`, then `npm run new-game -- my-game`. A game in its own folder:
7
7
  ```sh
8
- npm install threedog@0.5 three@~0.187.0
9
- npm install @threedog/terrain-noise@0.5 # optional: the noise terrain generator terrainPreset() (without one the ground is flat)
10
- npm install -D vite @threedog/tools@0.5 # optional: the vite preset and the threedog command line
8
+ npm install threedog@0.7 three@~0.187.0
9
+ npm install @threedog/terrain-noise@0.7 # optional: the noise terrain generator terrainPreset() (without one the ground is flat)
10
+ npm install -D vite @threedog/tools@0.7 # optional: the vite preset and the threedog command line
11
11
  ```
12
- Then let it set up the folder: `node node_modules/@threedog/tools/bin/threedog.mjs init` (flags: `--open-world` for generated ground, sky, follow camera and a player, `--example` for a small gameplay sample on top; the default is a blank scene with a camera and an empty style in `style/`) writes index.html, main.js, vite.config.js, content/, CLAUDE.md and `.mcp.json` (Claude Code then starts the threedog MCP server by itself), never overwriting a file you have.
12
+ Then let it set up the folder: `node node_modules/@threedog/tools/bin/threedog.mjs init` (flags: `--open-world` for generated ground, sky, follow camera and a player; the default is a blank scene with a camera and a gray starter picture in `picture/`) writes index.html, main.js, vite.config.js, content/, CLAUDE.md and `.mcp.json` (Claude Code then starts the threedog MCP server by itself), never overwriting a file you have.
13
13
  `three` is a peer dependency: your game and the engine share one copy. Types for three come with the engine (`@types/three`, same version), so `// @ts-check` JS and TypeScript both see real three.js types.
14
14
 
15
15
  ## Minimal usage
16
16
  ```js
17
+ import 'threedog/tsl'; // WebGPU with TSL, what a new game starts on; a game started with --webgl leaves this line out and the renderer option below
17
18
  import { createEngine, presets, openWorld } from 'threedog';
18
19
  import { terrainPreset } from '@threedog/terrain-noise'; // optional terrain generator (npm install @threedog/terrain-noise)
19
20
 
20
- const engine = createEngine({ canvas: document.getElementById('view') }); // no style: gray placeholders
21
+ const engine = createEngine({ canvas: document.getElementById('view'), renderer: 'webgpu' }); // no picture code yet: gray placeholders
21
22
  engine.use(openWorld({ camera: 'follow', seed: 7, terrain: terrainPreset() }));
22
23
  engine.characters.createPlayer({ ...presets.player.thirdPerson });
23
24
  engine.start();
24
25
  ```
25
- A look is the game's own `style/` folder, passed in: `createEngine({ canvas, style })`.
26
+ The picture is the game's own: plain three.js in its `picture/` folder (what `threedog new-game` generates), reading signals from `engine.uniforms`. A new game runs on WebGPU with TSL shaders, or on WebGL with GLSL shaders through `--webgl`. A browser without WebGPU still runs the WebGPU form, on three's WebGL2 backend, slower; `describe().renderer` says why.
26
27
  `vite.config.js` with the preset: `import { gameConfig } from '@threedog/tools/vite'; export default gameConfig(import.meta.dirname);`
27
28
 
28
29
  ## Entry points
29
30
  - `threedog`: the whole public API (`THREE` is re-exported, so `import { THREE } from 'threedog'` is the same three instance).
30
- - A style is the game's own folder (there are no published style packages): the engine ships no art (visuals only; the noise terrain generator `terrainPreset()` is `@threedog/terrain-noise`); without a style everything is a neutral gray placeholder.
31
+ - The engine ships no art (visuals only; the noise terrain generator `terrainPreset()` is `@threedog/terrain-noise`); without picture code everything is a neutral gray placeholder.
32
+ - `threedog/tsl`: the WebGPU route; import it before `createEngine({ renderer: 'webgpu' })`. Also TSL helpers for materials and lighting.
33
+ - `threedog/layers`: `RESERVED_LAYERS`, the three.js layers the engine keeps (a game's own are 1 to 25).
34
+ - `threedog/grid`: `sampleGrid`, `gridFromPixels`, `decodePng` (2D fields; no three.js, works in workers and tests).
35
+ - `threedog/worker`: `serve(handler)`, the worker side of `engine.threads` lanes.
31
36
  - `threedog/error-hints`: the developer error hint table (used by `@threedog/tools`).
32
37
 
33
38
  Nothing else is a public path; files under `core/`, `modules/` etc. may move between versions.
34
39
 
35
- ## Global changes to three.js
36
- Importing the engine changes two defaults on `THREE.Mesh.prototype`, for every mesh in the page:
37
- - `Mesh.prototype.raycast` is replaced by three-mesh-bvh's accelerated raycast (`BufferGeometry.prototype.computeBoundsTree` / `disposeBoundsTree` are added). Results are the same as three's own raycast; meshes without a bounds tree fall back to it.
38
- - `Mesh.prototype.customDepthMaterial` and `customDistanceMaterial` become accessors: when nothing was assigned, a mesh whose material has engine vertex patches (wind sway) returns a matching depth material, so its shadow moves with it. Assigning a value (including in your own code) still wins; assigning `undefined` restores the default. The value is stored under a symbol, so `Object.hasOwn(mesh, 'customDepthMaterial')` is false.
40
+ ## Changes to three.js
41
+ The engine changes three.js in a few places, because three.js has no per-object hook for what it needs. `describe().threePatches` lists every one at run time, `threePatches.off(id)` turns off the ones that can be turned off, and `docs/THREE.md` says what each does to your code. Importing the engine does these page-wide:
42
+ - `Object3D.prototype.add` / `remove` are wrapped once, so `scene.add` is adopted like `engine.add`.
43
+ - `Mesh.prototype.customDepthMaterial` and `customDistanceMaterial` become accessors: when nothing was assigned, a mesh whose material has engine vertex patches (wind sway) returns a matching depth material, so its shadow moves with it. Assigning a value still wins; assigning `undefined` restores the default.
44
+ - `THREE.ShaderChunk` gains `threedog_*` entries (new names, none of three's replaced).
45
+
46
+ Raycasting is not a global change: a mesh registered as static gets its own bounds tree and its own `raycast`; `Mesh.prototype.raycast` is untouched.
39
47
 
40
48
  ## Docs
41
49
  Shipped in the package: `docs/AI.md` (how to use the engine, written for AI assistants), `docs/API.md` + `docs/api/` (per module), `docs/recipes/` (task guides), `docs/THREE.md` (using three.js directly).
package/core/Assets.js CHANGED
@@ -4,7 +4,7 @@
4
4
  // 3. Cache and reuse: one file downloads once; models return independent copies (geometry and materials shared), so you can place many.
5
5
  // 4. Release: models count usage per copy; release(name) frees only when the last copy is removed, trim() frees every model with no copy in use (see their docs
6
6
  // below).
7
- // 5. Compression: Draco / Meshopt models and .ktx2 textures load as-is; the decoder downloads on first use (npm run assets produces compressed files).
7
+ // 5. Compression: Draco / Meshopt models and .ktx2 textures load as-is; the decoder downloads on first use (npm run assets produces compressed files in public/optimized/).
8
8
  // 6. Made in code: a model / texture / sound may be a function in the manifest instead of a file, used by name exactly like a file (content, model(),
9
9
  // pickups, vegetation, audio.sounds). Models are built on demand and cached automatically (baked file -> dev cache -> build, the internal cached()).
10
10
  // 7. Observable: every load is a task in engine.loading. A registered file that fails falls back (gray placeholder / silence / the entry's fallback)
@@ -19,7 +19,7 @@
19
19
  // models: { house: '/models/house.glb', hero: { url: '/models/hero.glb', critical: true }, block: buildBlock },
20
20
  // textures: { paper: { url: '/textures/paper.jpg', color: true }, ground: '/textures/ground.ktx2' },
21
21
  // sounds: { bgm: '/sounds/morning.mp3', ding: (audio, p, out) => { audio.tone({ freq: 880 * p.pitch, dur: 0.2, out }); return 0.2; } },
22
- // fonts: { pixel: '/fonts/pixel.woff2', pixelBold: { url: '/fonts/pixel-bold.woff2', family: 'pixel', weight: 700 } }, // style.ui.fonts names them
22
+ // fonts: { pixel: '/fonts/pixel.woff2', pixelBold: { url: '/fonts/pixel-bold.woff2', family: 'pixel', weight: 700 } }, // ui.fonts names them
23
23
  // });
24
24
  // engine.assets.manifest({ name: 'forest', base: '/packs/forest/', models: { oak: 'oak.glb' } }); // -> /packs/forest/oak.glb
25
25
  // await engine.assets.preload(p => console.log(p)); // p: 0-1 (code-generated models are built ahead only if marked preload)
@@ -61,6 +61,13 @@ export class Assets {
61
61
  this._instances = new WeakMap(); // model copy root -> asset entry (counts usage)
62
62
  this._animators = new WeakMap(); // model root -> Animator from animate(): engine.remove disposes it with the model
63
63
  this.cacheMinMs = 20; // builds faster than this are not cached (reading the file would be slower)
64
+ /**
65
+ * Named colors for what is made in code: a generator written with `function` reads this.palette. Plain data, read or replace it freely:
66
+ * it is part of the cache key, so a model or texture asked for after a write is built from the new colors. Copies already placed keep theirs.
67
+ * @example engine.assets.palette = { leaf: 0xd98a3a, bark: 0x6b4a30 };
68
+ * @type {Record<string, any>}
69
+ */
70
+ this.palette = {};
64
71
  this._loaders = {};
65
72
  }
66
73
 
@@ -72,8 +79,8 @@ export class Assets {
72
79
  * Per entry: critical: true = start() stops if it fails (otherwise it falls back and the game continues); fallback: 'otherName' replaces the gray
73
80
  * placeholder.
74
81
  * name labels the manifest in engine.loading (default 'manifest#1', '#2'...), so a failure says which list it came from.
75
- * base (a pack's folder: '/packs/forest/', a CDN URL, or new URL('./files/', import.meta.url)) resolves the relative paths of this manifest; '/x' and full
76
- * URLs stay as written.
82
+ * base (a pack's folder: '/packs/forest/', a CDN URL, or new URL('./files/', import.meta.url)) resolves the relative paths of this manifest; full URLs stay
83
+ * as written, and '/x' is the game's public/ folder under the build's base (BASE_URL in core/validate.js: '/' unless built with --base).
77
84
  * @example engine.assets.manifest({ name: 'level-1', models: { hero: { url: '/models/hero.glb', critical: true }, bush: { url: '/models/bush.glb', fallback:
78
85
  * 'rock' } } });
79
86
  * @example import forest from 'my-forest-assets'; engine.assets.manifest(forest); // { name: 'forest', base, models: { oak: 'oak.glb' } }
@@ -122,12 +129,16 @@ export class Assets {
122
129
  if (!e) { e = { type, name: nameOrUrl, url: nameOrUrl, opts: {}, promise: null }; this.entries.set(nameOrUrl, e); }
123
130
  return e;
124
131
  }
132
+ /** @internal the palette as a cache key */
133
+ get _paletteKey() { return JSON.stringify(this.palette); }
134
+ /** @internal A generated model or texture built from a palette that has since been written */
135
+ _stale(e) { return !!e.promise && !!e.opts.build && e.type !== 'sound' && e.palette !== this._paletteKey; }
125
136
  /** @internal Load an entry as a task in engine.loading (assetEntry.js) */
126
137
  _fetch(e) { return fetchEntry(this, e); }
127
138
 
128
139
  /**
129
140
  * Preload manifest assets (all by default; onlyMarked=true loads only those marked preload). Code-generated models and fonts are loaded ahead only if marked
130
- * preload (style.ui.fonts loads its own at start()). onProgress(0-1, current name).
141
+ * preload (ui.fonts loads its own at start()). onProgress(0-1, current name).
131
142
  * Finishing is not succeeding: failed lists every entry that failed, including those now showing their fallback (details in engine.loading).
132
143
  */
133
144
  async preload(onProgress, { onlyMarked = false } = {}) {
@@ -136,8 +147,8 @@ export class Assets {
136
147
 
137
148
  /**
138
149
  * A font from an asset pack, by name: downloads it once, adds it to document.fonts and resolves to the FontFace (null when the file
139
- * failed and the entry is not critical: text then shows the next family of style.ui.font). Only registered names work, because a font
140
- * needs its CSS family and descriptors; style.ui.fonts calls this for you at start().
150
+ * failed and the entry is not critical: text then shows the next family of ui.theme.font). Only registered names work, because a font
151
+ * needs its CSS family and descriptors; ui.fonts calls this for you at start().
141
152
  * @example engine.assets.manifest({ name: 'ui', fonts: { pixel: '/fonts/pixel.woff2' } }); await engine.assets.font('pixel');
142
153
  * @param {string} name
143
154
  * @returns {Promise<FontFace | null>}
@@ -163,7 +174,7 @@ export class Assets {
163
174
  */
164
175
  modelNow(nameOrUrl, opts = {}) {
165
176
  const e = this.entries.get(nameOrUrl);
166
- if (e?.type === 'model' && e.value) return this._copy(e, e.value, opts);
177
+ if (e?.type === 'model' && e.value && !this._stale(e)) return this._copy(e, e.value, opts);
167
178
  // Why warn: generated models also need one load() first (dev reads the baked-cache GLB, release reads the baked file), so before any await model() this is null;
168
179
  // in one playtest world.present only called modelNow, the model never showed up and nothing said why. Already loading (promise present) = no warning: that is a normal "not ready yet"
169
180
  if (DEV && e?.type === 'model' && !e.promise) warnOnce(coded('asset-not-loaded', fmt(STRINGS.notLoaded, { name: nameOrUrl })));
@@ -181,7 +192,7 @@ export class Assets {
181
192
  }
182
193
  /**
183
194
  * Import report of a loaded model: materials, textures with their colorSpace, normal maps, clips, nodes, template / id nodes and col_ colliders,
184
- * with issues for what the file has but the scene lost (normal map, material replaced by a style role, clip not loaded, clip mapping that names
195
+ * with issues for what the file has but the scene lost (normal map, material replaced by an engine one, clip not loaded, clip mapping that names
185
196
  * no clip) and for wrong color spaces. Pass a name (the loaded template) or a copy from model() (what the game shows). Text: assets.reportText(name)
186
197
  * @example console.table(engine.assets.report('hero').issues);
187
198
  * @param {string | any} nameOrRoot
@@ -205,7 +216,7 @@ export class Assets {
205
216
  * Get a texture (name or path; .ktx2 works too). Color textures default to sRGB; pass { color: false } for normal/roughness maps.
206
217
  * opts is part of the cache key: the same image fetched with different opts gives two separately configured textures (never silently reuses the first one's
207
218
  * settings). A texture made in code is registered by name too and comes back as made (its colorSpace / wrap / repeat are yours):
208
- * @example engine.assets.manifest({ textures: { brick: () => makeBrickTexture(), sign: mySignCanvasTexture } }); makeMaterial('wall', { map: 'brick' });
219
+ * @example engine.assets.manifest({ textures: { brick: () => makeBrickTexture(), sign: mySignCanvasTexture } }); new THREE.MeshLambertMaterial({ map: await engine.assets.texture('brick') });
209
220
  */
210
221
  async texture(nameOrUrl, opts = {}) {
211
222
  const base = this._resolve(nameOrUrl, 'texture');
@@ -281,7 +292,7 @@ export class Assets {
281
292
  /**
282
293
  * @internal Only core/namedModel.js calls this (the one path for "a model made in code, used by name"): games name the model instead.
283
294
  * Code-generated model (build returns an Object3D or BufferGeometry): built once per name + params, returns a copy (geometry returns the same instance).
284
- * A generator written with `function` (not an arrow) can read this.palette = style.palette (the key includes it, so a new palette rebuilds).
295
+ * A generator written with `function` (not an arrow) can read this.palette = engine.assets.palette (the key includes it, so a new palette rebuilds).
285
296
  * Cache key = name + generator source + params: outer variables build uses (colors, sizes, seeds in the closure...) must go in params,
286
297
  * otherwise changing a variable still reads the stale cache. In dev, one name paired with different source warns once.
287
298
  * Lookup order: files baked by npm run bake (public/models/baked/) -> the dev auto-cache (.threedog/cache, invalidated when code changes) -> build now.
@@ -291,7 +302,7 @@ export class Assets {
291
302
  const src = String(build), seen = (this._cachedSrc ||= new Map()).get(name);
292
303
  if (seen != null && seen !== src) warnOnce(coded('asset-name-clash', fmt(STRINGS.sameName, { name })));
293
304
  else this._cachedSrc.set(name, src);
294
- const key = 'cached:' + name + ':' + JSON.stringify(params ?? null) + ':' + JSON.stringify(this.engine.style.palette ?? null) + ':' + srcHash(src);
305
+ const key = 'cached:' + name + ':' + JSON.stringify(params ?? null) + ':' + this._paletteKey + ':' + srcHash(src);
295
306
  const e = this.entries.get(key) || this.entries.set(key, { type: 'model', url: name, opts: { build, params }, promise: null }).get(key);
296
307
  const g = await this._fetch(e);
297
308
  e.pinned = true; // neither copies nor geometry are counted: trim does not free it
package/core/Audio.js CHANGED
@@ -165,7 +165,7 @@ export class Audio {
165
165
  * @param {(e: any) => number} fn
166
166
  * @returns {{ remove(): void }}
167
167
  * @example engine.audio.measure('danger', e => e.vars.counter('alarm') / 10); // data: when: { danger: { gt: 0.5 } }
168
- * Measures are not only for sound: render/lookGlow.js reads 'daylight' for night glow, so the calendar (or the sky without one) registers it once
168
+ * Measures are not only for sound: render/daylight.js reads 'daylight' for night glow, so the calendar (or the sky without one) registers it once
169
169
  * and nothing else has to know which module tells day from night. remove() drops only this registration (a later one under the name stays).
170
170
  */
171
171
  measure(name, fn) {
package/core/Baked.js CHANGED
@@ -3,37 +3,34 @@
3
3
  // fromGLTF(gltf) -> object or geometry: restores the shadow flags, visibility and materials recorded at export
4
4
  // What glTF cannot record goes in userData (glTF extras):
5
5
  // object userData.threedog = { cast, receive, hidden }; material userData.threedogMat = material JSON (no textures).
6
- // A material with userData.purpose (made by makeMaterial) is rebuilt by purpose, so style texture swaps and shader injections (wind etc.) still apply;
7
- // otherwise it is rebuilt as-is from the recorded type and params (a MeshLambertMaterial stays Lambert, not glTF's default Standard).
8
- // Not recorded: onBeforeCompile (own shader patches; applyEffects patches come back only through a purpose), lightMap / specularMap / envMap and a
9
- // toon gradientMap made by hand (glTF has no slot for them: toGLB warns once naming the model and the slots),
6
+ // Every material is rebuilt as-is from the recorded type and params (a MeshLambertMaterial stays Lambert, not glTF's default Standard); one the engine
7
+ // made (neutralMaterial, userData.purpose) comes back engine-made.
8
+ // Not recorded: onBeforeCompile (own shader patches and applyEffects patches), lightMap / specularMap / envMap and a
9
+ // toon gradientMap (glTF has no slot for them: toGLB warns once naming the model and the slots),
10
10
  // ShaderMaterial texture uniforms and the identity of uniform objects (code holding a uniform reference stops driving the copy). Such a model's
11
11
  // manifest entry takes cache: false, or the material is made at use time.
12
12
  import * as THREE from 'three';
13
- import { makeMaterial } from '../render/materials.js';
13
+ import { neutralMaterial } from '../render/neutral.js';
14
+ import { markEngineMade } from '../render/patches.js';
14
15
  import { warnOnce } from './validate.js';
15
16
 
16
- // When rebuilding by purpose, keep these per-material settings from the recorded params (look params such as roughness and shininess still come from the style).
17
- // The map strengths ride along: a model baked with aoMapIntensity 0.4 must not come back at 1 (three's toJSON records each only while its map is set)
18
- const KEEP_KEYS = ['flatShading', 'emissive', 'emissiveIntensity', 'transparent', 'opacity', 'side', 'alphaTest', 'depthWrite', 'wireframe',
19
- 'aoMapIntensity', 'lightMapIntensity', 'bumpScale', 'normalScale', 'normalMapType', 'displacementScale', 'displacementBias', 'envMapIntensity'];
20
17
  const TEX_KEYS = ['map', 'normalMap', 'roughnessMap', 'metalnessMap', 'emissiveMap', 'aoMap', 'alphaMap', 'bumpMap', 'lightMap', 'specularMap', 'envMap', 'gradientMap', 'displacementMap'];
21
- // Slots glTF has no place for (the exporter drops them). A toon gradientMap of a makeMaterial role is rebuilt from the style, so only a hand-made one counts
18
+ // Slots glTF has no place for (the exporter drops them)
22
19
  const LOST_SLOTS = ['lightMap', 'specularMap', 'gradientMap', 'envMap'];
23
20
  const LOST = "[bake] '{name}': {list} cannot be stored in the cached / baked GLB and would come back missing. " +
24
21
  "Keep this model out of the cache: assets.manifest({ models: { {name}: { build, cache: false } } }), or set {first} after loading";
25
22
 
26
- /** Texture slots of m the GLB loses (hand-made toon ramp, lightMap, specularMap, envMap); [] when nothing is lost @param {any} m */
27
- function lostSlots(m) { return LOST_SLOTS.filter(k => m[k]?.isTexture && !(k === 'gradientMap' && m.userData?.purpose)); }
23
+ /** Texture slots of m the GLB loses (toon ramp, lightMap, specularMap, envMap); [] when nothing is lost @param {any} m */
24
+ function lostSlots(m) { return LOST_SLOTS.filter(k => m[k]?.isTexture); }
28
25
 
29
26
  /**
30
27
  * Object (or geometry) -> GLB. Marks are written on a copy; the original is untouched.
31
28
  * @returns {Promise<ArrayBuffer>}
32
29
  */
33
- export async function toGLB(value, engine, name = 'model') {
30
+ export async function toGLB(value, name = 'model') {
34
31
  const { GLTFExporter } = await import('three/addons/exporters/GLTFExporter.js');
35
32
  const geo = value.isBufferGeometry;
36
- const root = geo ? new THREE.Mesh(value, makeMaterial('default', { vertexColors: !!value.attributes.color }, engine)) : value.clone();
33
+ const root = geo ? new THREE.Mesh(value, neutralMaterial('default', { vertexColors: !!value.attributes.color })) : value.clone();
37
34
  if (geo) root.userData.threedogGeometry = true;
38
35
  const mats = new Map(), lost = new Set();
39
36
  root.traverse(o => { for (const m of [].concat(o.material ?? [])) for (const k of lostSlots(m)) lost.add(k); });
@@ -59,21 +56,15 @@ export async function toGLB(value, engine, name = 'model') {
59
56
  }
60
57
 
61
58
  /** The part of a GLTFLoader result that toGLB exported: restores shadow flags, visibility and materials in place (other glTF files are unaffected). Returns the gltf. */
62
- export function restoreBaked(gltf, engine) {
59
+ export function restoreBaked(gltf) {
63
60
  const mats = new Map();
64
61
  const rebuild = m => {
65
62
  const spec = m.userData.threedogMat; if (!spec) return m;
66
63
  if (!mats.has(m)) {
67
- const { purpose } = m.userData;
68
- const keep = {};
69
- for (const k of KEEP_KEYS) if (spec[k] !== undefined) keep[k] = spec[k];
70
- if (Array.isArray(keep.normalScale)) keep.normalScale = new THREE.Vector2().fromArray(keep.normalScale); // JSON gives [x, y]; the material wants a Vector2
71
- // the color is kept only when the generator's makeMaterial call set it: a color the style gave the role comes from the current style,
72
- // so a cached or baked model recolors when the pack changes (materialSource.keys = that call's own params)
73
- const own = m.userData.materialSource?.keys, color = !own || own.includes('color') ? { color: m.color } : {};
74
- const out = purpose ? makeMaterial(purpose, { ...color, vertexColors: m.vertexColors, ...keep }, engine) : new THREE.MaterialLoader().parse(spec);
64
+ const out = new THREE.MaterialLoader().parse(spec), { purpose } = m.userData;
75
65
  for (const k of TEX_KEYS) if (m[k] && k in out) out[k] = m[k];
76
66
  out.name = m.name;
67
+ if (purpose) { out.userData.purpose = purpose; markEngineMade(out); } // inspect.scene names it, and the fog / shadow walks count it as the engine's
77
68
  mats.set(m, out);
78
69
  }
79
70
  return mats.get(m);
package/core/Budget.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // createEngine({ budget: { drawCalls: 250, fps: 55 } }) or engine.budget.enable({ drawCalls: 250 })
3
3
  // engine.budget.report() // { ok, over: [{ category, value, limit, top }] }; null when off
4
4
  // Off by default; when off, sample() returns immediately and costs nothing. The engine presets no limit numbers.
5
- // Categories: drawCalls, triangles, textures, cpuMs, fps, low1 (the last two are lower bounds) + module-registered metrics (chunkApplyMs, rigidBodies...)
5
+ // Categories: drawCalls, triangles, textures, cpuMs, fps, low1 (fps and low1 are lower bounds) + registered metrics (lights, shadowLights, shadowMaps, shadowMapSize, chunkApplyMs, rigidBodies...)
6
6
  // + the apply-cost stages (applyTransitMs, applyBuildMs, applyColliderMs, applyUploadMs, applyStreamMs: ms per frame, see ApplyCost).
7
7
  // "Who uses the most": draw calls are estimated by the userData.budgetTag of an object (or its parent); untagged counts as 'other'.
8
8
  /** @import { Handle } from '../types/common' */
@@ -217,7 +217,7 @@ export class Budget {
217
217
  * @returns {BudgetTagStat[]}
218
218
  */
219
219
  byTag() {
220
- const e = this.engine, cam = e.camera, out = new Map(), shadows = e.renderer.shadowMap.enabled, shadowCost = SHADOW_TYPES[e.look.shadow?.value('type')]?.cost ?? 1;
220
+ const e = this.engine, cam = e.camera, out = new Map(), shadows = e.renderer.shadowMap.enabled, shadowCost = Object.values(SHADOW_TYPES).find(t => t.three === e.renderer.shadowMap.type)?.cost ?? 1;
221
221
  // shadow passes a caster is drawn in: one per shadow map the renderer draws (each cascade on both renderers), six for a point light
222
222
  const passes = Math.max(1, shadowMaps(e.renderer, e.scene).reduce((n, m) => n + m.faces, 0));
223
223
  cam.updateMatrixWorld();
@@ -1,7 +1,7 @@
1
1
  // engine.debug: diagnostic overrides with an owner ("show me this without X") and the diagnostic view modes. They change only what the screen shows,
2
2
  // never the game state or a save, and describe().scene.overrides lists them so an AI knows the picture is not the real state. Why an owner: a tool
3
3
  // (view mode, probe, AI session) removes everything it set with one clear(owner), whatever it forgot to remove(); a tool never touches another owner's.
4
- // Generic on purpose: a patch is { visible?, material?, apply? }, and apply(obj) -> undo covers any other look (the view modes in debugView.js use it).
4
+ // Generic on purpose: a patch is { visible?, material?, apply? }, and apply(obj) -> undo covers any other picture (the view modes in debugView.js use it).
5
5
  // All of engine.debug is core (it works without the debug panel); the F3 panel module only adds engine.debug.panel next to it (composition).
6
6
  // One chain: every material / visibility change, from override() and from a view, is an entry in this._l. Removing any entry undoes the whole chain
7
7
  // in reverse and re-applies the rest in order, so a view and an override on the same mesh can never restore each other's stale material, and nothing
@@ -11,7 +11,6 @@ import { DebugView } from './debugView.js';
11
11
  import { isWebGPU, webgpuPart } from '../render/backend.js';
12
12
  import { reloadGlsl } from '../render/hotGlsl.js';
13
13
  import { reloadAssets } from './assetHot.js';
14
- import { ownersOn, ownerValues } from './look/points.js';
15
14
 
16
15
  const KEYS = ['visible', 'material', 'apply'];
17
16
  const MATERIALS = ['flat', 'wire']; // 'cost' (the shaderCost view) is internal: it needs patch.colorOf
@@ -19,6 +18,8 @@ const MATERIALS = ['flat', 'wire']; // 'cost' (the shaderCost view) is interna
19
18
  /** Drawable parts under obj (obj itself included) */
20
19
  function meshes(obj) { const out = []; obj.traverse(o => { if (o.isMesh || o.isPoints || o.isLine) out.push(o); }); return out; }
21
20
  const patchInfo = p => ({ ...p, ...(p.apply && { apply: 'function' }) });
21
+ /** A value in describe(): plain data as is, a three.js object by its type (describe() stays JSON) */
22
+ const plain = v => (v === null || typeof v !== 'object' ? v : v.isColor ? `#${v.getHexString()}` : `<${v.type ?? 'object'}>`);
22
23
 
23
24
  export class DebugOverrides {
24
25
  /** @internal */
@@ -35,7 +36,7 @@ export class DebugOverrides {
35
36
  * Diagnostic view: 'albedo' | 'lighting' | 'shadow' | 'normals' to look at one part of the render, 'overdraw' (bright = many layers on a pixel),
36
37
  * 'shaderCost' (materials green -> red by compiled program cost, approximate), 'off' to restore; modules add their own (triggers: 'triggers' draws
37
38
  * the trigger zones), viewModes() lists them all. Temporary and owner-scoped; never saved
38
- * (describe().render says which view is active, so it is not mistaken for the real look). While one owner's view is on, another owner can neither switch it
39
+ * (describe().render says which view is active, so it is not mistaken for the real picture). While one owner's view is on, another owner can neither switch it
39
40
  * nor turn it off without force: true; engine.debug.clear(owner) turns that owner's view off too.
40
41
  * @example engine.debug.view('normals'); // look at the screenshot, then engine.debug.view('off')
41
42
  * @param {'albedo' | 'lighting' | 'shadow' | 'normals' | 'overdraw' | 'shaderCost' | 'off' | string} mode @param {{ owner?: string, force?: boolean }} [opts]
@@ -72,14 +73,20 @@ export class DebugOverrides {
72
73
  /**
73
74
  * Change how an object looks for diagnosis, owned by `owner`. Returns { remove() }. Never saved, never part of the game state; listed in
74
75
  * describe().scene.overrides while active. A thing id is remembered as the id: when that thing is removed, or a load replaces it, the override is dropped.
76
+ * Any three.js value: override(owner, object, key, value) writes object[key] and keeps it there every frame, above picture code that writes it in
77
+ * onRender, so "show me this with exposure 3" holds; remove() puts the old value back.
75
78
  * @param {string} owner who sets it (a tool or session name); engine.debug.clear(owner) removes all of that owner's overrides
76
- * @param {string | import('three').Object3D} target a thing id (engine.thing), an object name or any Object3D, or a look part id ('look.tone'): then patch is that part's set() values, written on its debug layer above every game owner
77
- * @param {{ visible?: boolean, material?: 'flat' | 'wire', apply?: (obj: any) => (() => void) | void }} patch flat = unlit base colour, wire = wireframe, apply = your own change (return its undo)
79
+ * @param {any} target a thing id (engine.thing), an object name or any Object3D; with a key, any three.js object (renderer, scene, a light, a material) is that part's set() values, written on its debug layer above every game owner
80
+ * @param {string | { visible?: boolean, material?: 'flat' | 'wire', apply?: (obj: any) => (() => void) | void }} patch flat = unlit base colour, wire = wireframe, apply = your own change (return its undo); a string: the property to write
81
+ * @param {any} [value] with a property name: its value, of the type the property holds (null works: scene.fog off)
78
82
  * @example const h = engine.debug.override('ai-session', 'windmill', { material: 'flat' }); h.remove(); // or engine.debug.clear('ai-session')
83
+ * @example engine.debug.override('ai-session', engine.renderer, 'toneMappingExposure', 3);
84
+ * engine.debug.override('ai-session', engine.scene, 'fog', null); // the same picture with no fog
85
+ * @returns {{ remove(): void }}
79
86
  */
80
- override(owner, target, patch) {
87
+ override(owner, target, patch, value) {
81
88
  if (!owner || typeof owner !== 'string') throw codedError('debug-override', "engine.debug.override(owner, target, patch): owner is a non-empty string naming who sets it, e.g. 'ai-session', so engine.debug.clear(owner) can remove it");
82
- if (typeof target === 'string' && target.startsWith('look.')) return this._look(owner, target, patch);
89
+ if (typeof patch === 'string') return this._value(owner, target, patch, value);
83
90
  for (const k of Object.keys(patch ?? {})) if (!KEYS.includes(k)) throw codedError('debug-override', `engine.debug.override: unknown field '${k}'. Fields: ${KEYS.join(', ')}, e.g. { visible: false } or { material: 'flat' }`);
84
91
  if (patch.material !== undefined && !MATERIALS.includes(patch.material)) throw codedError('debug-override', `engine.debug.override: material must be ${MATERIALS.map(m => `'${m}'`).join(' or ')} (unlit base colour / wireframe), got ${JSON.stringify(patch.material)}`);
85
92
  const byId = typeof target === 'string';
@@ -88,28 +95,36 @@ export class DebugOverrides {
88
95
  return this._add({ owner, id, byId, obj, patch: { ...patch }, undo: null });
89
96
  }
90
97
  /**
91
- * Remove every override of one owner (nothing else), its look-part debug values and its view; returns how many were removed
98
+ * Remove every override of one owner (nothing else), and its view; returns how many were removed
92
99
  * @param {string} owner
93
100
  */
94
101
  clear(owner) {
95
102
  const mine = this._l.filter(o => o.owner === owner && !o.view);
96
103
  if (mine.length) this._rebuild(() => { this._l = this._l.filter(o => !mine.includes(o)); });
97
- let looks = 0;
98
- for (const p of Object.values(this.e.look ?? {})) if (p._drop('debug', owner)) looks++;
99
104
  const view = this._view.releaseOwner(owner) ? 1 : 0;
100
- return mine.length + looks + view;
105
+ return mine.length + view;
101
106
  }
102
107
  /** Active overrides as plain data (describe().scene.overrides) */
103
108
  overrides() {
104
109
  this._prune();
105
- const looks = Object.values(this.e.look ?? {}).flatMap(p => ownersOn(p, 'debug').map(owner => ({ owner, target: p.id, ...ownerValues(p, 'debug', owner) })));
106
- return [...this._l.filter(o => !o.view).map(o => ({ owner: o.owner, target: o.id, ...patchInfo(o.patch) })), ...looks];
110
+ return [...this._l.filter(o => !o.view).map(o => ({ owner: o.owner, target: o.id, ...patchInfo(o.patch) }))];
107
111
  }
108
- /** A look part's debug layer (look/part.js): same validation as set(), describe().look tags the keys 'debug:<owner>' */
109
- _look(owner, id, values) {
110
- const p = this.e.look?.[id.slice(5)];
111
- if (!p) throw codedError('debug-override', `engine.debug.override: no look part '${id}'; parts: ${Object.keys(this.e.look ?? {}).map(k => 'look.' + k).join(', ') || 'none'}`);
112
- return p._setOn('debug', owner, values ?? {}); // one path with set(): normalize, flatten, check (look/part.js, review M8)
112
+ /** @internal One three.js value on the chain: written now and again before each draw, so picture code that writes it per frame does not end the diagnosis */
113
+ _value(owner, obj, key, value) {
114
+ const say = why => codedError('debug-override', `engine.debug.override(owner, object, key, value): ${why}`);
115
+ if (obj === null || typeof obj !== 'object') throw say(`object is the three.js object itself (engine.renderer, engine.scene, a light, a material), got ${JSON.stringify(obj)}`);
116
+ const label = obj === this.e.renderer ? 'renderer' : obj.type ?? 'object'; // a class name is minified in a built page
117
+ if (!(key in obj)) throw say(`${label} has no property '${key}'`);
118
+ const now = obj[key];
119
+ if (now != null && value != null && typeof now !== typeof value) throw say(`'${key}' holds a ${typeof now}, got ${typeof value}${now.isColor ? ': pass a THREE.Color' : ''}`);
120
+ if (value === undefined) throw say(`give the value for '${key}' (null to clear it)`);
121
+ const apply = o => {
122
+ const was = o[key], put = () => { o[key] = value; };
123
+ put();
124
+ const h = this.e.onRender(put);
125
+ return () => { h.remove(); o[key] = was; };
126
+ };
127
+ return this._add({ owner, id: `${label}.${key}`, byId: false, obj, patch: { key, value: plain(value), apply }, undo: null });
113
128
  }
114
129
  /** Active overrides on one object, for engine.thing(id).explain() */
115
130
  overridesOn(obj) { this._prune(); return this._l.filter(o => o.obj === obj && !o.view).map(o => ({ owner: o.owner, ...patchInfo(o.patch) })); }
package/core/Describe.js CHANGED
@@ -22,9 +22,8 @@ import { inspectMaterials } from './InspectMaterials.js';
22
22
  import { inspectPerf } from './InspectPerf.js';
23
23
  import { codedError, coded } from './errorHints.js';
24
24
  import { r1 } from './math.js';
25
- import { describeRender } from './describeRender.js';
26
- import { describeLook } from './look/report.js';
27
- import { describeOwned } from './owned.js';
25
+ import { describeRender, describePicture, describeBackend } from './describeRender.js';
26
+ import { describeOwned, checkWrittenOnce } from './owned.js';
28
27
  import { describeScene } from './thingOps.js';
29
28
  import { describeHolds } from './holds.js';
30
29
  import { warnOnce } from './validate.js';
@@ -37,7 +36,7 @@ const drawStats = r => { const s = stats(r); return { drawCalls: s.drawCalls, tr
37
36
  const NEAR_RADIUS = 30, NEAR_MAX = 15;
38
37
  const COMPASS = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW']; // north = -Z, east = +X
39
38
  const RELATIVE = ['front', 'front-right', 'right', 'back-right', 'back', 'back-left', 'left', 'front-left']; // relative to the camera heading
40
- const STANDARD = new Set(['ready', 'error', 'disabledModules', 'moduleStates', 'loading', 'time', 'player', 'camera', 'nearbyRadius', 'nearby', 'actions', 'ui', 'cutscene', 'modules', 'perf', 'scene', 'render', 'look', 'owned', 'shared', 'control']);
39
+ const STANDARD = new Set(['ready', 'error', 'disabledModules', 'moduleStates', 'loading', 'time', 'player', 'camera', 'nearbyRadius', 'nearby', 'actions', 'ui', 'cutscene', 'modules', 'perf', 'scene', 'render', 'picture', 'owned', 'shared', 'control']);
41
40
  const ACTIONS_MAX = 8; // what the player can do now, with why not: saves the AI a guess for a few dozen characters // the core's own fields
42
41
  const sector = a => Math.round(((a % (Math.PI * 2)) + Math.PI * 2) / (Math.PI / 4)) % 8;
43
42
 
@@ -54,8 +53,8 @@ export function describeApi(e) {
54
53
  /**
55
54
  * Current game state (plain object, JSON.stringify-able). radius: how far counts as "nearby" (meters), default 30
56
55
  * @param {string | string[] | { radius?: number, center?: { x: number, z: number }, only?: string[] }} [opts] center: measure "nearby" from here instead
57
- * of the player (inspect uses it); only: just these top-level sections (a name or an array is short for { only }), e.g. describe('look')
58
- * or describe({ only: ['look', 'shared'] }). Why: the whole object is ~40 KB on a mid-size world, most of it engine tables (shared, look, slots)
56
+ * of the player (inspect uses it); only: just these top-level sections (a name or an array is short for { only }), e.g. describe('picture')
57
+ * or describe({ only: ['picture', 'shared'] }). Why: the whole object is ~40 KB on a mid-size world, most of it engine tables (shared, slots)
59
58
  * that a question about one part does not need, and only the asked sections are built. An unknown section name is reported in the result as unknownSections, never a silent {}
60
59
  * @example engine.describe('player').player.x
61
60
  */
@@ -98,7 +97,7 @@ function pendingModules(e) {
98
97
 
99
98
  // Engine tables no module hook writes into (hooks add to time / player / camera / ui / perf / cutscene / nearby): a describe({ only }) that asks
100
99
  // for nothing else skips the hooks, describe.add and the action list
101
- const TABLES = new Set(['ready', 'error', 'disabledModules', 'loading', 'holds', 'input', 'control', 'shared', 'modules', 'slots', 'scene', 'threePatches', 'owned', 'look', 'render', 'renderer']);
100
+ const TABLES = new Set(['ready', 'error', 'disabledModules', 'loading', 'holds', 'input', 'control', 'shared', 'modules', 'slots', 'scene', 'threePatches', 'owned', 'render', 'picture', 'renderer']);
102
101
  const NONE = Symbol('none'); // a conditional section that is absent this time
103
102
 
104
103
  /**
@@ -107,13 +106,14 @@ const NONE = Symbol('none'); // a conditional section that is absent this time
107
106
  * name is not a section this time: api() then builds everything to name the sections that exist
108
107
  */
109
108
  function describe(e, { radius = NEAR_RADIUS, center: at, only } = {}, extras) {
109
+ checkWrittenOnce(e);
110
110
  const p = e.player?.position, center = at || p || e.focus, cam = e.camera;
111
111
  /** @type {Record<string, () => any>} the core's sections in output order; NONE = left out */
112
112
  const core = {
113
113
  ready: () => e.ready,
114
114
  error: () => e.error, // gameplay error in dev / tests (gameplay is frozen)
115
115
  unhandled: () => e._unhandled || NONE, // dev: first promise rejection nobody caught, and how many followed (errors.js)
116
- disabledModules: () => [...e.disabledModules], // look / ui modules disabled after an error
116
+ disabledModules: () => [...e.disabledModules], // picture / ui modules disabled after an error
117
117
  moduleStates: () => pendingModules(e) ?? NONE, // while a module is initializing or failed
118
118
  loading: () => e.loading.view(), // what is pending / failed and whether it blocks the start (Loading.js)
119
119
  time: () => ({ tick: e.tick, real: r1(e.time.now('real')), ambient: r1(e.time.now('ambient')), calendar: r1(e.clock.now), paused: e.paused, frozen: e.frozen, ...(e.frozen ? { frozenBy: e.stacks.get('freeze').names() } : {}), headless: e.headless, run: e.runState,
@@ -142,10 +142,9 @@ function describe(e, { radius = NEAR_RADIUS, center: at, only } = {}, extras) {
142
142
  scene: () => describeScene(e), // engine.add / world things: counts by save tier and what will not survive a load (thingOps.js)
143
143
  threePatches: () => threePatches.list(), // page-wide changes to three.js classes still on (core/threePatches.js)
144
144
  owned: () => describeOwned(e), // every property the engine writes on its own and who writes it now (owned.js)
145
- look: () => describeLook(e), // every look part key, its value and who set it (look/report.js)
146
145
  render: () => describeRender(e), // renderer / post / lights and who set each (describeRender.js)
147
- // which renderer was asked for and which backend draws; reason = why not WebGPU (core/startup.js _startRenderer). backend null before start()
148
- renderer: () => e._backend ?? { requested: e._backendWant.requested, backend: null, reason: null },
146
+ picture: () => describePicture(e), // tone, fog, environment, background, lights, shadows as three.js holds them now (describeRender.js)
147
+ renderer: () => describeBackend(e), // asked for, drawing, why not WebGPU and what that backend can run (describeRender.js)
149
148
  perf: () => ({
150
149
  fps: e.paused ? null : Math.round(e.fps), cpuMs: e.paused ? null : r1(e.cpuMs),
151
150
  cpu: e.paused ? null : Object.fromEntries(Object.entries(e.cpuPhases).map(([k, v]) => [k, r1(v)])),