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
@@ -0,0 +1,185 @@
1
+ # Materials, lights and models: the game's own picture
2
+
3
+ **In this recipe**: 0. Where the picture lives · 1. Materials are plain three.js · 1a. The engine's big pieces · 1b. Lights and stalls · 1c. The UI's picture ·
4
+ 2. Using your own models instead of procedural ones · 2a. Reusing art · 2b. Wind, cloud shadows and season tint on your own materials ·
5
+ 3. When the engine gets a new picture value · 4. Verify · 5. Sounds and music
6
+
7
+ ```js
8
+ // picture/materials.js: the game's materials are its own three.js objects
9
+ const wood = new THREE.MeshStandardMaterial({ color: 0x8a5a36, roughness: 0.8 });
10
+ const crate = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1), wood);
11
+ engine.water.material.color.set(0x3070a0); // a big engine piece hands out its material the same way
12
+ ```
13
+
14
+ **The engine ships no art.** No default picture, character model, terrain drawing or terrain generator: until the game gives one, everything is a
15
+ plain neutral placeholder (a gray capsule for characters, a gray box for props and pickups, flat gray ground at y = 0, one white hemisphere light plus
16
+ one neutral directional light without shadows or tone mapping), and the console says once in dev what is missing and how to fix it.
17
+
18
+ ## 0. Where the picture lives
19
+ The picture is code of the game: a `picture/` folder of plain three.js, and recipe 62 is its home. Any art direction fits: realistic, toon, pixel, painterly,
20
+ flat, noir. Not part of the picture: model / texture / sound files and procedural models content names (an **asset pack**, `engine.assets.manifest`, recipe 05
21
+ "Asset packs"), sounds (section 5), gameplay data and timing (a **content pack**, recipe 20; `calendar({ hoursPerDay })`).
22
+
23
+ Swapping the picture must never change the map or the rules, so a thing that changes the world (water level, terrain seed, a size) is a module option, and a
24
+ thing that only changes pixels is a write on the module's three.js material. The terrain generator `terrainPreset` / `riverAt` / `BIOMES` / `terrainStrings` is a
25
+ separate package, `@threedog/terrain-noise`, because the shape of the world is gameplay. Post effects such as `bloom` / `ao` / `outline` come from
26
+ `@threedog/post-effects` and go in as `plugins/` files (recipe 40 §1, chain order: recipe 52).
27
+
28
+ ## 1. Materials are plain three.js
29
+ `new THREE.MeshStandardMaterial(...)`, `MeshToonMaterial`, `ShaderMaterial`, `onBeforeCompile`: all work as in any three.js project, and a plain material gets fog and
30
+ cascaded shadows by itself. Keep them in `picture/materials.js` by name, and let other code ask for `picture.materials.wall`, so a change of picture touches one folder.
31
+ ```js
32
+ // Solid prop with vertex colors (merged model)
33
+ const prop = new THREE.MeshLambertMaterial({ vertexColors: true });
34
+
35
+ // See-through, double-sided
36
+ const banner = new THREE.MeshLambertMaterial({ color: 0xd04a3a, transparent: true, opacity: 0.8, side: THREE.DoubleSide });
37
+
38
+ // Glowing lamp
39
+ const lamp = new THREE.MeshStandardMaterial({ color: 0x6b5a40, emissive: 0xffc070, emissiveIntensity: 1.2 });
40
+
41
+ // Toon with an explicit light ramp: three.js's gradientMap; rampTexture takes grays, dark to light, and how far the bands melt (0-1). three's toon reads only
42
+ // the red channel, so a colored ramp needs celLighting on the WebGPU route (recipe 56); on WebGL a colored shade is a lighting patch (recipe 43)
43
+ import { rampTexture } from 'threedog';
44
+ const skin = new THREE.MeshToonMaterial({ color: 0xe8a0a0, gradientMap: rampTexture([0.25, 0.6, 1], 0.2) });
45
+ ```
46
+ **Textures by asset name.** `engine.assets.texture(name)` returns a promise of a `THREE.Texture`; a data map (normal, roughness, ao) takes `{ color: false }`. The
47
+ `assets.useTexture` form fills a slot when the image arrives and warns once if it fails, so the material can be used at once. Tiling is three.js:
48
+ ```js
49
+ const rock = new THREE.MeshStandardMaterial({ roughness: 0.9 });
50
+ engine.assets.useTexture('rock.png', t => { t.wrapS = t.wrapT = THREE.RepeatWrapping; t.repeat.set(4, 4); rock.map = t; rock.needsUpdate = true; });
51
+ engine.assets.useTexture('rock_n.png', t => { rock.normalMap = t; rock.needsUpdate = true; }, { opts: { color: false } });
52
+ ```
53
+ Changing what compiles into the program (`vertexColors`, `flatShading`, `transparent`, adding a map) after the first render needs `material.needsUpdate = true`, as in
54
+ three.js. `material.clone()` does not carry engine patches (three's `Material.copy` skips `onBeforeCompile`): apply the effects to the clone again.
55
+ Grain, your own GLSL and the engine's shader functions on these materials: section 2b and recipe 43.
56
+
57
+ ## 1a. The engine's big pieces
58
+ Terrain, water, plants, rain and snow, pickups and grid layers keep their engineering in the engine and hand out their picture as plain three.js. The same four doors on each:
59
+
60
+ | Door | What it is | Example |
61
+ |---|---|---|
62
+ | `.material` | The three.js material it draws with; set it and it swaps on every mesh, drawn as given (nothing added behind your back) | `engine.terrain.material`, `engine.vegetation.material`, `engine.pickups.material`, `layer.material`, `engine.weather.particles.rain.material` |
63
+ | `.uniforms` | Plain `{ value }` objects for what the shader reads, written directly and live | `engine.water.uniforms.uWave.value = 1.5` |
64
+ | `.patches` | The engine's shader patches for that piece, so your own material keeps its behavior | `engine.water.material = applyEffects(new THREE.MeshPhongMaterial(), { patches: engine.water.patches })` |
65
+ | Module options and a plain method | Values baked when the module builds (terrain colors, normal map tiling) | `terrain({ colors })`, `engine.terrain.recolor({ colors })`, `engine.water.normalMap(name, { repeat })` |
66
+
67
+ Each piece's own recipe has its details: water and weather 44, terrain 37, plants 36, pickups 03, grids 29.
68
+
69
+ ## 1b. Lights and stalls
70
+ The placeholder lights and your own: recipe 38. This section is what a changing light setup costs.
71
+
72
+ three.js builds one shader program per material for each light setup. `engine.start()` compiles everything visible behind the
73
+ loading screen (`engine.startup.compileMs`), but adding or removing a light later, or toggling `visible` on one, changes the setup and compiles again:
74
+ a frame can freeze for hundreds of milliseconds. Keep the number of lights fixed: create them up front and fade with `intensity` (0 = off, no
75
+ recompile). In dev the console warns (code `light-recompile`) when programs were compiled in a frame where the lights changed.
76
+
77
+ For many torches, street lamps, campfires, muzzle flashes or neon signs use the light pool: a fixed number of real lights, created once at install,
78
+ moves to the sources that matter most (near the camera, bright, high `priority`) and fades with intensity, so the light setup never changes. Install
79
+ it before `engine.start()` so the startup compile covers its lights:
80
+ ```js
81
+ import { lightPool } from 'threedog';
82
+ engine.use(lightPool({ point: 8 })); // 8 PointLights; lightPool({ spot: 2, shadows: 1 }) adds spots / lets one point light cast
83
+ for (const t of torches) engine.lightPool.add(t, { // an Object3D is followed; a position stays put
84
+ color: 0xffa040, intensity: 4, distance: 8,
85
+ flicker: (time, i) => 0.85 + 0.15 * Math.sin(time * 13 + i),
86
+ glow: t.getObjectByName('halo'), // stand-in while it has no real light: its material's opacity / emissiveIntensity fades to 0 as the light fades in
87
+ });
88
+ const flash = engine.lightPool.add(gun.muzzle, { intensity: 0, priority: 5, distance: 6 });
89
+ flash.set({ intensity: 8 }); /* next frame */ flash.set({ intensity: 0 }); // muzzle flash: no light is created
90
+ ```
91
+ `engine.lightPool.usage()` (and `describe().lightPool`) lists which source each real light holds; `focus` measures from the player instead of the
92
+ camera. Options and handle: `../api/lightPool.md`. Windows and signs that light up at night need no real light each: see below.
93
+
94
+ ### Night glow: emissive that follows daylight
95
+ Lit windows, neon signs, lamp bulbs, glowing mushrooms, screens. `engine.uniforms.uNight` is 0 by day and 1 at night, on the curve `dusk` lamps fade on
96
+ (the calendar's daylight, else the sky's sun), so a window and the lamp outside it switch on together. One write per material per frame; the color stays the
97
+ material's `emissive`:
98
+ ```js
99
+ // picture/glow.js
100
+ const windows = new THREE.MeshLambertMaterial({ color: 0x202020, emissive: 0xffcc66 });
101
+ const neon = new THREE.MeshStandardMaterial({ emissive: 0x33ccff });
102
+ engine.onFrame(() => {
103
+ const night = engine.uniforms.uNight.value, day = engine.uniforms.uDaylight.value;
104
+ windows.emissiveIntensity = 2 * night;
105
+ neon.emissiveIntensity = 0.4 + 2.6 * (1 - THREE.MathUtils.smoothstep(day, 0, 0.6)); // its own dusk: faintly lit by day, on while the sky is still bright
106
+ });
107
+ ```
108
+ Share one Material between the meshes that glow together. Models built later bring their own copies: collect them when the model is made
109
+ (`model.traverse(o => { if (o.material?.name === 'window') glowing.add(o.material); })`, a `Set` the frame loop walks), and take them out when it leaves. `uNight`
110
+ starts at daylight 0.3, roughly 17:00 to 18:00 and back in the morning: a starting value, not a rule. Judge it in shots at dusk.
111
+
112
+ **Headroom: why a glow turns into glare.** What reaches the tone curve is the emissive color times `emissiveIntensity`. A near-white color
113
+ (`#ffe6c0`) has no headroom: all three channels already sit near 1, so multiplied past 1 they clip to the same white under tone mapping, and
114
+ bloom spreads that white over what is around it (a lit sign becomes a white block with a smear). A saturated color at a lower intensity still
115
+ reads as light: its strongest channel carries the brightness, the others keep the hue, and bloom carries the halo. The numbers above are the
116
+ examples' current values, not targets. Judge the result with the picture check of `threedog shot` or `threedog snap` at night: it names each
117
+ glowing material and light that blows pixels out, with its current emissive and intensity and how much detail is lost under it, as a fact to
118
+ weigh against what the game wants (some games want a blinding sign).
119
+ For the light those windows throw on the street, add a few `lightPool` sources above; a pool source's `glow` stand-in is for one object near one light.
120
+
121
+ Top-down or side-view games whose light should spread over the floor and stop at walls (soft shadows, any number or shape of emissive
122
+ lights) can copy the optional 2D radiance cascades example instead: `examples/rc2d/` (README there: when it fits, cost, limits). It is not a module.
123
+
124
+ ## 1c. The UI's picture
125
+ `createEngine({ ui: { theme, css, fonts, templates } })`: `theme` sets the colors and the `font` of the default parts (they are CSS variables), `css` adds your own
126
+ rules, `fonts` lists font asset names to load at start (the files sit in an asset pack: recipe 05 §3b), `templates` replace a whole UI piece. Parts and their keys: recipe 26.
127
+
128
+ ## 2. Using your own models instead of procedural ones
129
+ Models are assets: content names them, an asset pack maps the names to files or generators. Register a later manifest with the same
130
+ name to swap one:
131
+ ```js
132
+ engine.assets.manifest(yourAssets); // assets from an asset pack you have: trees, rocks, flowers... built in code
133
+ engine.assets.manifest({ name: 'mine', models: { pine: () => myPineGeometry(), well: '/models/well.glb' } }); // replaces pine, adds well
134
+ ```
135
+ Vegetation takes a geometry (`geometry: await engine.assets.geometry('pine')`, the first mesh in the model) or a whole model with one material per
136
+ mesh, e.g. bark trunk + alpha-cut leaf cards:
137
+ `engine.vegetation.define('oak', { model: await engine.assets.model('oak'), wind: 0.02 })` (still one draw call per part; felling hides every part). For
138
+ the import workflow see `10-blender-level.md`.
139
+ `mergeColored(parts, { flat: false })` keeps smooth normals; UVs survive when every part has them.
140
+ A generator in `models` may also return an Object3D with its own materials; those are used as they are.
141
+
142
+ ### 2a. Reusing art from somewhere else: copy it in, do not depend on it
143
+ Art code you already have (generator modules such as `art/my-crate.js` from an earlier game, a folder of your own, files someone gave you, a package
144
+ you installed) is reused by **copying** it into this game. The copy is the game's own: edit it freely; nothing links back and nothing updates it.
145
+ ```sh
146
+ threedog art list ../earlier-game # modules, exported functions with their first JSDoc line, asset files (uses its art/ folder)
147
+ threedog art copy ../earlier-game crate lamp # by file or function name; none = every module
148
+ threedog art copy ../earlier-game crate --dry # what would be written, nothing written
149
+ ```
150
+ It copies the named modules, every local file they import and every texture / model file they name ('./wood.png', `new URL(...)`, '/models/x.glb'
151
+ from the source's `public/`), rewrites relative import paths to the new layout (outside-the-art-folder helpers land in `art/shared/`), keeps package
152
+ imports and lists them, and prints the `engine.assets.manifest` lines to register the generators. An existing file with different content stops the
153
+ whole copy (nothing written) unless `--force`. The engine ships no art library and names no source: which art to reuse is yours to choose.
154
+ GLB files from Blender are copied the same way and checked with recipe 46 section 3.
155
+
156
+ ## 2b. Wind, cloud shadows and season tint on your own materials
157
+ The engine's shader effects are named patches that work on any material that has the usual three.js chunks (WebGL only):
158
+ ```js
159
+ import { applyEffects } from 'threedog';
160
+ const leaves = applyEffects(new THREE.MeshToonMaterial({ color: 0x5a8a3a }), { wind: 0.03, season: 'foliage' }); // clouds default on
161
+ engine.vegetation.define('bush', { geometry, material: leaves }); // vegetation adds them itself; effects: false keeps the material untouched
162
+ ```
163
+ The shadow sways with the wind automatically. Your own effect (pixel snapping, dissolve...) is a patch too, and stacks with the built-in ones and with
164
+ the material's own `onBeforeCompile`:
165
+ `applyEffects(mat, { patches:
166
+ [{ name: 'snap', cacheKey: 64, uniforms, glsl: { vertex: { pars: '...', project_vertex: '...code after #include <project_vertex>' } } }] })`.
167
+ A missing `#include` anchor throws. A hand-written `ShaderMaterial` can `#include <threedog_wind_vertex>`, `<threedog_clouds_pars_fragment>` etc. (see
168
+ `render/effects.js`) with `engine.uniforms` as its uniforms.
169
+ What a patch declares (`needs`, `conflicts`, `shadow`, `cacheKey`), the chunk names and the engine GLSL functions you can call in your own shader: recipe 43.
170
+
171
+ ## 3. When the engine gets a new picture value
172
+ For engine developers. Hard rule 1: a module shows neutral gray until the game writes something. It makes its material with `neutralMaterial(what, params)` from
173
+ `render/neutral.js` and hands it out through the doors of section 1a. A shader-side value is a `{ value }` in `.uniforms`; a value baked at build time is a module option, with
174
+ one plain method when it can change at run time. There is no table of picture values to add to. A value that changes the world (a level, a size, a seed) is a module option only.
175
+
176
+ ## 4. Verify
177
+ - `npm run check`: R14 reports "creates a material directly" in engine code (games and examples are plain three.js and not checked), R35 a reach into the old look
178
+ table, R39 a "non-gray fallback color".
179
+ - Take screenshots only when the picture changed, and compare two times of day: `npm run shot -- / --time 12:00`, `npm run shot -- / --time 18:30`
180
+ (images go to .threedog/shots/). Against a reference picture: `threedog picture compare` (recipe 60).
181
+ - It must still run with no picture code: start once with `createEngine({ canvas })` (gray placeholders, one console note per missing piece).
182
+
183
+ ## 5. Sounds and music (the game's, not the picture's)
184
+ Sounds are game config, passed to `createEngine({ audio: { sounds, ambience, music, footsteps, levels } })` and read back as `engine.audio.config`. The engine plays
185
+ nothing the game did not name. Buses, sounds by name, the ambience rule table, music rules, footsteps and ducking: `recipes/31-audio.md`.
@@ -14,7 +14,7 @@
14
14
  Export glTF/GLB (tick "Custom Properties") into `art/models/` (create it if missing).
15
15
 
16
16
  ## 2. Compression
17
- `npm run assets` compresses to `public/models/<same name>.glb` (Meshopt geometry + WebP textures; `-- --ktx2` uses KTX2 textures). Object names and
17
+ `npm run assets` compresses to `public/optimized/<same name>.glb` (Meshopt geometry + KTX2 textures; needs the `ktx` command for textures) and points `assets.js` at the results (`/optimized/<name>.glb`). Object names and
18
18
  hierarchy are kept; faces are not reduced. Only changed files are processed; `-- --force` redoes everything.
19
19
 
20
20
  ## 3. Putting it in the game (main.js)
@@ -71,7 +71,7 @@ are refused. The id of a listed plant is its index in the list. After what a den
71
71
  A game that wants every instance under its own code still builds a plain `THREE.InstancedMesh` and adds it to the scene.
72
72
 
73
73
  ## 5. Verify
74
- - `npm run assets` prints each file's size before and after compression; a browser 404 appears in `.threedog/errors.log` (asset load failure).
74
+ - `npm run assets` prints each file's size before and after compression (`-- --dry` only estimates); a browser 404 appears in `.threedog/errors.log` (asset load failure).
75
75
  - `describe()`: `ready` is true and `loading` is empty; the player's coordinates are at the spawn point; `nearby` contains trigger zones
76
76
  (`kind: 'trigger'`) and NPCs.
77
77
  Text version: `npm run shot -- /your-page.html --describe-only`.
@@ -10,14 +10,14 @@ downloaded and initialized, so build the car after `engine:ready`.
10
10
 
11
11
  ## 1. Build a car (main.js)
12
12
  ```js
13
- import { presets, THREE, makeMaterial } from 'threedog';
13
+ import { presets, THREE } from 'threedog';
14
14
 
15
15
  function makeCar() {
16
16
  const car = new THREE.Group();
17
- const body = new THREE.Mesh(new THREE.BoxGeometry(1.8, 0.6, 3.6), makeMaterial('vehicle', { color: 0xc04a3a }));
17
+ const body = new THREE.Mesh(new THREE.BoxGeometry(1.8, 0.6, 3.6), new THREE.MeshLambertMaterial({ color: 0xc04a3a }));
18
18
  body.position.y = 0.3; body.castShadow = true; car.add(body);
19
19
  const wheels = [[-0.85, 1.2, true, false], [0.85, 1.2, true, false], [-0.85, -1.2, false, true], [0.85, -1.2, false, true]].map(([x, z, steer, drive]) => {
20
- const w = new THREE.Mesh(new THREE.CylinderGeometry(0.35, 0.35, 0.25, 10).rotateZ(Math.PI / 2), makeMaterial('vehicle', { color: 0x333333 }));
20
+ const w = new THREE.Mesh(new THREE.CylinderGeometry(0.35, 0.35, 0.25, 10).rotateZ(Math.PI / 2), new THREE.MeshLambertMaterial({ color: 0x333333 }));
21
21
  w.position.set(x, 0, z); car.add(w); // wheels are children of the body: they follow suspension, steering and rolling
22
22
  return { position: [x, 0, z], radius: 0.35, steer, drive, object: w };
23
23
  });
@@ -4,7 +4,7 @@ There is a single entry point: `engine.assets.animate(model, config)` -> Animato
4
4
  For characters (player, NPCs), passing `model` builds the Animator automatically and switches clips by character state (idle walk run swim jump fall drive).
5
5
 
6
6
  ## 1. The model
7
- Export a glTF with animations from Blender, put it in `art/models/` -> `npm run assets` -> `public/models/hero.glb`. Register it and fetch a copy (the
7
+ Export a glTF with animations from Blender, put it in `art/models/` -> `npm run assets` -> `public/optimized/hero.glb`. Register it and fetch a copy (the
8
8
  skeleton is cloned correctly; clips are in `userData.animations`):
9
9
  ```js
10
10
  engine.assets.manifest({ models: { hero: '/models/hero.glb', dog: '/models/dog.glb' } });
@@ -27,7 +27,7 @@ engine.assets.manifest({ name: 'heroes', models: { hero: { url: '/models/hero.gl
27
27
  engine.characters.createPlayer({ ...presets.player.thirdPerson, model: 'hero' }); // no clips / animation in code
28
28
  engine.assets.mapping(engine.player.anim.root); // after whenReady: the entry's mapping, or null
29
29
  ```
30
- A character's default names (`Idle`, `Walk`...) never shadow a mapped state, and the entry's `fade` beats the style's.
30
+ A character's default names (`Idle`, `Walk`...) never shadow a mapped state, and the entry's `fade` beats `characters({ animation })`.
31
31
 
32
32
  - A clip name also matches the part after the last `|`: Blender / FBX2glTF exports `CharacterArmature|Idle`, you write `Idle`.
33
33
  - Dev checks: a state whose clip is not in the model warns at `assets.animate()` with the available clip names and where to fix it
@@ -50,7 +50,8 @@ engine.player.anim.state; // current s
50
50
  ```
51
51
  **The game's own states** (crouch, climb, glide, dash, roll) go on top of the built-in ones through the `states` option, without taking the mover
52
52
  over: it runs after the mover's state each step and returns a state name or null (keep the built-in `facts.base`); the clip comes from `clips`
53
- like any other state, a speed change stays `engine.mod('move.speed')`.
53
+ like any other state, a speed change stays `engine.mod('move.speed')`. A state only names the pose: climbing also needs someone to move the body
54
+ (recipe 57, Moved by script, has a ladder).
54
55
  ```js
55
56
  createPlayer({ ...presets.player.thirdPerson, model: hero, clips: { crouch: 'Crouch', glide: 'Glide' },
56
57
  states: (c, f) => f.grounded && engine.input.down('crouch') ? 'crouch' : !f.grounded && f.vy < 0 && gliding ? 'glide' : null });
@@ -66,7 +67,12 @@ engine.characters.createPlayer({ ...presets.player.thirdPerson, model: hero, ani
66
67
  jump: { clip: 'Jump', loop: false },
67
68
  } } });
68
69
  ```
69
- The default transition time comes from the style's `style.character.animation.fade`.
70
+ The default transition time for every character is `characters({ animation: { fade: 0.15 } })`; a model's manifest mapping and the character's own
71
+ `animation` win over it.
72
+
73
+ **The placeholder capsule.** A character without a model draws with `engine.characters.material`, one plain three.js material shared by every capsule:
74
+ `engine.characters.material = new THREE.MeshToonMaterial({ color: 0xd9a066 })` swaps them all, as given. `colors: { body }` gives one character a copy in
75
+ that color. A model keeps its own materials.
70
76
 
71
77
  **By asset name.** `model` also takes the name of a registered model asset: a file model, or a procedural builder. The character is built at once
72
78
  with a gray capsule; when the asset loads, a skeleton-correct copy replaces it under the same root, so position, facing, state, collision and the
@@ -79,7 +85,7 @@ await p.whenReady; // p.anim is
79
85
  ```
80
86
 
81
87
  ## 3b. Procedural bodies are assets too (`model: 'humanoid'`)
82
- Character bodies are assets, never style: every character picks one with `model`, the same path for a GLB and a procedural builder. an asset
88
+ Character bodies are assets: every character picks one with `model`, the same path for a GLB and a procedural builder. an asset
83
89
  pack can supply a code-built humanoid (e.g. box limbs, swung by the engine while walking, running, swimming, jumping); a builder is built at once, so its joints
84
90
  (`player.armL`, `legR`...) exist right after `createPlayer`. Without `model` (and without `rig`) a character is a gray capsule, warned once.
85
91
  ```js
@@ -88,8 +94,8 @@ engine.assets.manifest(assets);
88
94
  engine.characters.createPlayer({ ...presets.player.thirdPerson, model: 'humanoid' });
89
95
  engine.npcs.add({ id: 'fisher', model: 'humanoid', colors: { body: 0x4f6d8f } }); // per-character part colors
90
96
  ```
91
- - **Colors**: the humanoid's parts use material roles `cloth`, `skin`, `trousers`, `hair`, so any style tints every humanoid
92
- (`style: [basePack, { materials: { cloth: { color: 0x3a6ea5 } } }]`); `colors: { body, skin, legs, hair }` recolors one character.
97
+ - **Colors**: a builder's materials are its own three.js materials, and colors shared by many bodies come from `this.palette` (recipe 05);
98
+ `colors: { body, skin, legs, hair }` recolors one character's marked parts.
93
99
  - **Your own procedural body**: a builder that returns an Object3D with `root.userData.rig = { body: 'hips', head: 'head', joints: ['armL'],
94
100
  limbs: [{ joint: 'legL', offset: 0, amp: 0.9, kind: 'leg' }] }` (object names, so it survives copies and baking) animates like the humanoid; mark
95
101
  meshes `userData.part = 'body'` for `colors`. A hand-built one-off passes `{ rig }` instead ([02-npc](02-npc.md)).
@@ -5,6 +5,8 @@ counter). The contracts every module should follow (state, game time, skip, desc
5
5
  `49-game-module-contract.md`; this page is the template and the hook cheat sheet. A module is a file of your game (next to `main.js`, or in `plugins/`);
6
6
  keep art and text out of its code (style values, `i18n`) so it can go to another game through your asset library (`threedog lib add`).
7
7
 
8
+ **A whole system to reuse.** A folder `systems/<name>/` with a `system.json` (`{ "summary", "module", "plug", "requires", "entries", "content", "text" }`) carries the module, its content piece, its words and its tests (`tests/*.mjs`, game specs) as one unit: fishing, a day-night shop, wave spawning, tides. `threedog lib add systems/fishing --kind system` refuses colors, art files and text in the code and a `requires` left out of `system.json`, then proves an entry with tests by pulling it into an empty game and running them (`--no-proof` skips that). `threedog lib pull fishing` puts it in `systems/fishing/`, writes its wiring file in `plugins/`, puts its tests in `tests/specs/` and merges its content in `content/index.js`.
9
+
8
10
  ## 1. Template (example: stamina, in the game as `stamina.js`)
9
11
  ```js
10
12
  // Stamina: running drains it, standing recovers it; at 0 you can't run. engine.stamina.value is 0..max
@@ -51,14 +53,14 @@ Install it: `engine.use(openWorld({ camera: 'follow', ...}), stamina({ max: 80 }
51
53
  |---|---|---|
52
54
  | `'rules'` | game logic: save parts, ops, events; may take input, control or the camera for a while. The usual one for a game module | - |
53
55
  | `'world'` | game state: records, ops, ground / collision / navigation data | drawing (rule R47: no `scene.add`, `renderer.` in its file) |
54
- | `'look'` | what is seen and heard: look values, three.js objects, particles, sounds | `ops.define`, writing world records |
56
+ | `'picture'` | what is seen and heard: picture values, three.js objects, particles, sounds | `ops.define`, writing world records |
55
57
  | `'ui'` | panels and menus: declares input actions, runs ops | `input.bind` (keys are the game's), `saves.register` (preferences are not game saves) |
56
58
  | `'actor'` | characters and their control | - |
57
59
  | `'net'` | multiplayer: remote characters, the transport | - |
58
60
  | `'tool'` | a one-shot job that undoes itself (a photo, a bake) | - |
59
61
 
60
62
  No subtypes: inside a type the differences are declarations (`provides`, `requires`, `ctx.mod` values, material slots, post stage, sounds).
61
- A module that does two kinds of thing is two definitions returned together (`weather()` returns the `weather` state and the `weatherLook` look;
63
+ A module that does two kinds of thing is two definitions returned together (`weather()` returns the `weather` state and the `weatherDraw` drawing part;
62
64
  `engine.use(weather())` installs both). The refusal names the module, its type, what it did, why not, and the fix; copy the fix.
63
65
 
64
66
  ## 2. Hooks and order cheat sheet
@@ -81,7 +83,7 @@ A module that does two kinds of thing is two definitions returned together (`wea
81
83
  false: a failed init is reported and start goes on). A module installed after start gets no `fixed` / `frame` before its `init` finished:
82
84
  `engine.moduleStates` shows `initializing` / `running` / `failed`, and `await engine.loading.settled()` waits for it. A module whose `isReady` never
83
85
  turns true makes `start()` reject after `engine.loading.timeoutMs` (default 120 s), naming it.
84
- - The `type` decides what an error does: in a `look` or `ui` module (gameplay works without it) an error in a hook only switches that module off
86
+ - The `type` decides what an error does: in a `picture` or `ui` module (gameplay works without it) an error in a hook only switches that module off
85
87
  (`module:disabled`, listed in `engine.disabledModules`); in any other type it freezes the game in development/tests and is recorded in `engine.error`.
86
88
  - Listeners and timers the module adds go through `ctx.track(...)`: `ctx.track(e.events.on('item:add', fn))`, also `onFixed` / `onFrame` /
87
89
  `clock.after` / `audio.measure` / a `makeWindow` window, anything with `remove()`. They leave with the module: when its `engine.use(...)` batch
@@ -92,7 +94,7 @@ A module that does two kinds of thing is two definitions returned together (`wea
92
94
  physics world, WASM objects and real-time timers, and is called in reverse install order.
93
95
  - A module's changes to shared values go through `ctx.mod(point, { mul: 0.8, layer: 'effect' })` (= `ctx.track(e.mod(point, { owner: ctx.name, ... }))`),
94
96
  so they leave with it too. A module that must be the only one of its kind declares `provides: ['inventory']`; others `requires: ['inventory']`
95
- (a capability, never a module name), and a game swaps it with `engine.use(mine(), { replaces: 'inventory' })` (`55-mods-time-wrap.md`):
97
+ (a capability, never a module name), and a game swaps it with `engine.use(mine(), { replaces: 'inventory' })` (`55-mods-time-wrap.md`). `engine.unuse('name')` removes a module with nothing in its place, and refuses while another still requires it. Picture slots: `62-picture-code.md` 3e:
96
98
  `engine.inventory` is then the new module's API, so the dependents keep working. A missing capability throws naming both fixes: install the
97
99
  engine's part of that name first, or your own module with `provides`.
98
100
  - `engine.phase` says where the engine is: `'constructed'` -> `'loading'` (start() running: frame hooks run, fixed steps do not, so no game
@@ -114,7 +116,7 @@ A module that does two kinds of thing is two definitions returned together (`wea
114
116
 
115
117
  ## 3. Extra steps when it goes into the engine
116
118
  - Write the declarations and JSDoc in `index.d.ts` (or `types/*.d.ts`) of the engine package; `npm run types` checks that the exports of index.js are declared.
117
- - Add look parameters to the style (see `09-style.md`), put text in i18n, then `npm run map` to generate API.md + `api/` / CODEMAP.md.
119
+ - Hand out a picture as `.material`, `.uniforms`, `.patches` (see `09-materials-lights-models.md` §3), put text in i18n, then `npm run map` to generate API.md + `api/` / CODEMAP.md.
118
120
 
119
121
  ## 4. Verify
120
122
  - `npm run check` (hard rules + types + generated docs up to date).
@@ -20,7 +20,7 @@ Which renderer measures: tests that compare pixels run on software rendering (Sw
20
20
  - **Which materials cost**: `engine.debug.view('shaderCost')` colors each material green -> red by its compiled program (fragment code lines + samplers,
21
21
  approximate; gray = not compiled yet); `engine.debug.view('overdraw')` shows pixels drawn many times over (bright = many layers: foliage cards, particles).
22
22
  `'off'` restores. For real GPU timings use `threedog capture` (Spector.js) or the browser's GPU profiler.
23
- - **Other view modes and the panel**: `debug.view('triggers')` shows hidden zones; modules add their own modes (`engine.debug.defineView(name, { what, apply })`)
23
+ - **Other view modes and the panel**: `debug.view('triggers')` shows hidden zones (`triggers({ debugColor, debugOpacity })` colors them); modules add their own modes (`engine.debug.defineView(name, { what, apply })`)
24
24
  and `engine.debug.viewModes()` lists every mode. `engine.debug.panel` is the F3 panel (dev builds; null without the `debug()` module).
25
25
  - **F3 panel** (`debug()` module, included in openWorld, collapsed by default; the action `debugPanel` opens it, `presets.bindings.debug` binds F3): frame rate, CPU ms/frame, draw calls, triangles,
26
26
  chunks visible/loaded, vegetation instances, chunk upload ms, pending generation, time of day;
@@ -46,7 +46,7 @@ Which renderer measures: tests that compare pixels run on software rendering (Sw
46
46
  ## 2. Set a budget (so going over reports itself)
47
47
  Off by default and costs nothing. The game gives the limits in `createEngine` (only the given categories are checked):
48
48
  ```js
49
- const engine = createEngine({ canvas, style, budget: { drawCalls: 250, fps: 55, low1: 30, triangles: 600000, chunkApplyMs: 3, rigidBodies: 300, startupMs: 5000 } });
49
+ const engine = createEngine({ canvas, budget: { drawCalls: 250, fps: 55, low1: 30, triangles: 600000, chunkApplyMs: 3, rigidBodies: 300, startupMs: 5000 } });
50
50
  // or at runtime: engine.budget.enable({ drawCalls: 200 });
51
51
  const r = engine.budget.report(); // { ok, over: [{ category, value, limit, top }] }; going over also prints one console hint
52
52
  ```
@@ -71,7 +71,7 @@ and they get timed.
71
71
  | Symptom | Fix |
72
72
  |---|---|
73
73
  | Many draw calls | Use `vegetation` / InstancedMesh for repeated objects; install `hlod()` for a block of buildings; share geometry and materials between copies of a model (`assets.model` shares by default) |
74
- | Expensive shadows | Style `sky.shadow.updateEvery: 3` (update every 3 frames), reduce `mapSize`/`extent`; filter `look.shadow.set({ type: 'basic' })` (hard edge, cheapest) / `'pcf'` (default) / `'vsm'` (softest, costliest), switch live with `engine.look.shadow.set({ type: 'vsm', radius: 3 })` (radius: pcf and vsm only; blurSamples: vsm only; a switch recompiles materials, so avoid doing it every frame); the vegetation species option `shadowRing` (default 1) sets within how many chunk rings it casts shadows; change it while playing with `engine.vegetation.setShadowRing('tree', 0)` |
74
+ | Expensive shadows | `engine.shadows.budget(light, { every: 3 })` (update every 3 frames), reduce `light.shadow.mapSize` / the box's `extent`; filter `renderer.shadowMap.type = THREE.BasicShadowMap` (hard edge, cheapest) / `THREE.PCFShadowMap` (default) / `THREE.VSMShadowMap` (softest, costliest), blur with `light.shadow.radius` (pcf and vsm only) and `.blurSamples` (vsm only); a switch recompiles materials, so avoid doing it every frame; the vegetation species option `shadowRing` (default 1) sets within how many chunk rings it casts shadows; change it while playing with `engine.vegetation.setShadowRing('tree', 0)` |
75
75
  | Stutter while walking | Put generation work in `engine.jobs.add(function* () { ...; yield; })` or `engine.stream.add`; chunk upload budget `engine.terrain.applyBudgetMs` |
76
76
  | Slow start | Look at which is slowest in `engine.startup.modules`; `npm run bake` for large models; preload only the necessary assets |
77
77
  | Slow physics | Keep dynamic rigid bodies within a few hundred (the `rigidBodies` budget); `rigid({ terrainRing: 1 })` |
@@ -22,7 +22,7 @@ game only advances on step); once you open the page in a browser, commands go to
22
22
  | Command | What it does | Example output |
23
23
  |---|---|---|
24
24
  | `describe` | One-line scene summary: position / time and weather / nearby / quest | `player (4.0, 7.0) in forest · 07:11 day 1 · clear` |
25
- | `describe --full` | The state as text, summary first (`engine.describeText()`: at most 30 lines, the nearest things, the game's `describe.add` sections, one line per module with its key counts, the engine tables (shared, slots, look...) as one count line, and a last line on how to expand). Details: `describe <path>` for one part (in code `engine.describe('look')` or `describe({ only: ['look', 'shared'] })`), `engine.describeText({ full: true })` for everything | `quests: active[1], done=0, failed=0` |
25
+ | `describe --full` | The state as text, summary first (`engine.describeText()`: at most 30 lines, the nearest things, the game's `describe.add` sections, one line per module with its key counts, the engine tables (shared, slots, owned...) as one count line, and a last line on how to expand). Details: `describe <path>` for one part (in code `engine.describe('picture')` or `describe({ only: ['picture', 'shared'] })`), `engine.describeText({ full: true })` for everything | `quests: active[1], done=0, failed=0` |
26
26
  | `describe --all` | Everything: every nearby thing and every module's full data (`describeText({ full: true })`); large, prefer a path | |
27
27
  | `describe render` | How the picture is set: tone mapping, exposure, shadow filter, post effects with params, default lights, each tagged `engine` (default), `style` or `game` (changed after). Also the `renderer:` lines of `describe --full`. Information only, never warns | `{ "toneMapping": { "value": "aces", "by": "style" }, ... }` |
28
28
  | `describe player.position` | Player coordinates { x, y, z } (numbers) | `{ "x": 4, "y": 1.2, "z": 7 }` |
@@ -37,9 +37,9 @@ game only advances on step); once you open the page in a browser, commands go to
37
37
  | `pick 480,270` | What is at that screen pixel: record id, kind, template, the content file and line that defines it, its fields (recipes/30-templates.md section 5) | `✓ chest-home (kind chest, template chest) …` / `defined in content/props.js:14: edit it there …` |
38
38
  | `explain op shop.buy shop=trader item=ammo` / `explain quest my-quest` | Why an op cannot run now (the reason and the op's note on fixing it first; `--full` adds the last attempt and events around it), or where a quest is stuck (`engine.explain`) | `✗ shop.buy {...} cannot run now: noMoney (Not enough gold)` |
39
39
  | `scenario barter` | Run `tests/scenarios/barter.json` (recipes/23-ops.md section 7); prints failed checks, leaves it paused | `✓ barter: 6 checks passed` |
40
- | `state time=18:30 weather=rain pos=40,-20` | Set the scene (like URL parameters: time weather pos save wait cutscene state) | `✓ Set · 18:30 day 1 · rain` |
40
+ | `state time=18:30 weather=rain pos=40,-20` | Set the scene (like URL parameters: time weather pos save wait cutscene state play fresh) | `✓ Set · 18:30 day 1 · rain` |
41
41
  | `js "engine.calendar.timeOfDay"` (alias `eval`) | Evaluate an expression in the page; `engine` is available directly and `await` works inside; multi-line statements need their own `return` (e.g. `js "const p = engine.player.position; return p.x + p.z"`). Long scripts: `js --file script.js` | `✓ 0.77` |
42
- | `snap name` | Screenshot to `.threedog/shots/name.png` | `✓ Screenshot .threedog/shots/t1.png (163 KB)` |
42
+ | `snap name` | Screenshot to `.threedog/shots/name.png`, saying which backend drew it; `--play` first leaves the title, as `shot --play` | `✓ Screenshot .threedog/shots/t1.png (163 KB, drawn by WebGL2 (fallback: WebGPU was asked for, this is not a WebGPU picture))` |
43
43
  | `snap-describe save` / `snap-describe diff` + name | Describe snapshot instead of a screenshot: save the gameplay part of `describe()` as a baseline, or print how the running page differs from it (section 7) | `✗ describe "market" differs from the baseline in 1 place:` |
44
44
  | `errors` | Page errors added since last time (full log: `.threedog/errors.log`). Known classes get a cause + recipe line (section 8) | `✗ 1 new error` / `✗ 3 new errors` / `✓ No new errors` |
45
45
  | `loading` / `loading hero` | What loading waits for, what failed (file, HTTP status, fallback) and whether it blocks the start; works while `start()` is stuck. With a name: that task with its manifest and path (`recipes/05-props-bake.md` section 3) | `… waiting: decoding model "hero" (…)` / `✗ Loading finished, 4/5 ok, 1 failed` |
@@ -53,7 +53,7 @@ game only advances on step); once you open the page in a browser, commands go to
53
53
  game itself it belongs in an op (a teleporter pad). `step 1` after it collects `auto` pickups: the pickup check runs in the fixed step after any move.
54
54
  - **Ops with a reach** (`interaction.use`, `pickup.take`) check the player's distance as a key press would, also from the bridge: put the player next
55
55
  to the thing first (`threedog state "pos=x,z"`), then `threedog op interaction.use id=gate`. A `tooFar` result carries `facts: { distance, radius, at }`.
56
- - **`shot` always starts a fresh game** (`?save=slot1` loads one); after playing use `snap name`. `shot --keep` adds a timestamp to the file name (no overwrite); every shot prints the look numbers and hints (recipes/35 "Look check after every shot"; `--no-look` skips them).
56
+ - **`shot` always starts a fresh game** (`?save=slot1` loads one); after playing use `snap name`. `shot --keep` adds a timestamp to the file name (no overwrite); every shot prints the picture numbers and hints (recipes/35 "Picture check after every shot"; `--no-picture` skips them).
57
57
  - **`step` / `press` pause the real page**; resume with `threedog resume` when done (they pause as owner `threedog`, so a game's own pause stays). A headless page only advances on step anyway.
58
58
  - **Run state** is printed after `step` / `press` / `skip` / `resume` and by `threedog status`: `running`, `title-frozen` (title screen waiting for start), `test-paused` (only the bridge paused it), `paused(by owners)` (every `pause` / `freeze` owner, e.g. `ui-inventory`) or `loading`. The same object is `engine.runState` and `describe().time.run`: `{ state, owners, blockedBy }`, where `blockedBy` lists what keeps input from driving the game (opaque input contexts such as `win-settings`, `ui-title`, `dialogue`, `cutscene`, plus `error` and `loading`); the bridge and the MCP tools copy it as-is. A test that pauses passes `pause(owner, { kind: 'test' })` to read as `test-paused`.
59
59
  - **Who holds what**: `describe().holds` lists every holder in one place: `pause / freeze / camera / debugView` as `[{ owner, at }]` (`at` = game clock time of the take, `engine.clock.now`, so two new games read the same), `input` (pushed contexts `[{ context, owner, pass }]`), `gates` (`input.gate` owners by action) and `stacks` (every other `engine.mod` quantity), so a stuck pause, a closed jump or a camera nobody gave back has a name.
@@ -75,7 +75,8 @@ game only advances on step); once you open the page in a browser, commands go to
75
75
 
76
76
  ## 2b. A scripted playthrough, and three kinds of check
77
77
  ```
78
- threedog state pos=0,0 time=12:00 # known start
78
+ threedog state fresh=1 play=1 # clean start: no saves, past the title
79
+ threedog state pos=0,0 time=12:00 # known place
79
80
  threedog hold moveForward 1.5 # walk (real key path, advances 1.5 s)
80
81
  threedog press interact # one key press (~0.117 s)
81
82
  threedog step 2 # let things happen
@@ -85,7 +86,16 @@ threedog snap after-walk # only now look at pixels
85
86
  The same steps as a file: `tests/scenarios/<name>.json` with `{ "press": … }`, `{ "step": … }`, `{ "expect": { path: value } }` (section 9; no `hold` there).
86
87
  - **State checks** (`op`, `expect`, `describe`, `js`): fast and exact, but they skip input. They prove rules, not that the player can reach them.
87
88
  - **Simulated-input checks** (`press`, `hold`, `engine.input.simulate`): bridge key events through the game's input path, never a physical keyboard/mouse. `verify` prints `Layers: direct N, simulated-input N, real-browser-input 0 (not verified), visual 0`, then an **Evidence** block (each check's layer and what it asserted), a fixed **NOT proven** line (pointer lock and mouse look, real GPU/visuals, real FPS) and **Coverage** (ops run vs defined, refused ops counted as run and marked; modules in three groups: tested = an op ran, indirect = no op but describe section compared / save part changed / events fired, untested; lists capped at 10 with "+N more"; uses `engine.catalog()`). `threedog scenario` prints the same Coverage block; the full lists are in `--json` (`data.evidence.coverage`, `data.coverage`). Not yet covered: content ids (defined vs touched).
88
- - **Visual checks** (`snap`, `shot`): the only ones that see the look (exposure, color, UI overlap). Slowest; take them last.
89
+ - **Visual checks** (`snap`, `shot`): the only ones that see the picture (exposure, color, UI overlap). Slowest; take them last.
90
+
91
+ Playing a game through from a script, the four things that cost the most time:
92
+ - **Start clean.** Enter on a title picks Continue when a save exists, so a rerun by keys plays the last autosave. `state fresh=1` deletes the saves and
93
+ goes back to the title, `play=1` starts the run; `?fresh&play` does the same in a URL. `session.newGame()` alone leaves the title open.
94
+ - **Advance time yourself.** On a headless page the clock moves only on `step`, `press` and `hold`, so `await player.walkTo(spot)` never returns. Start it,
95
+ step, then await: `const w = engine.player.walkTo(spot); step(5); return await w`. A `js` script whose page clock stands still for 20 s ends with that reason.
96
+ - **Read why it was refused.** `interaction.use` fails with `inputLocked` and `facts: { by }` (`title`, `dialogue`, `settings`...), `tooFar` with the distance.
97
+ - **Press real keys when input is the question**: the title menu, whether a key reaches the action, a hold. For rules use `op` and `state`: faster and exact.
98
+ Neither tells you how the game feels or sounds, and a headless picture is usually WebGL2 (the `shot` / `snap` line says): report those as not verified.
89
99
 
90
100
  ## 3. Windows / PowerShell notes
91
101
  - **Quote commas**: PowerShell splits `pos=1,-8` into two arguments and the coordinates become NaN. Write `threedog state "pos=1,-8"` (the bridge
@@ -150,7 +160,7 @@ import { expectDescribe } from '@threedog/tools/describe-snapshot'; // in the
150
160
  await expectDescribe({ check, ev }, 'market-noon', { only: ['player', 'quests', 'nearby'], tolerance: { default: 0.5, player: 1 } });
151
161
  ```
152
162
  Update after an intended change: `threedog test <name> --update-snapshots` (writes instead of comparing) or `threedog snap-describe save <name>`.
153
- Review the JSON diff in git before committing. Take a screenshot only when the look changed.
163
+ Review the JSON diff in git before committing. Take a screenshot only when the picture changed.
154
164
 
155
165
  ## 8. Errors carry a code, a fix and a doc page
156
166
  Every error and warning the engine raises carries a stable **code**: `err.code`, `err.fix` (what to do) and `err.docs` (pages to read), and its message
@@ -169,7 +179,7 @@ combination so tests and scenarios reuse it.
169
179
 
170
180
  ## 10. MCP server: Claude Code, Cursor and other MCP clients
171
181
  `threedog mcp` runs the dev bridge as an MCP server over stdio. Each command becomes a tool (`play`, `status`, `describe`, `step`, `press`, `hold`, `skip`, `state`, `ops`,
172
- `op`, `catalog`, `inspect`, `scene`, `pick`, `thing`, `explain`, `errors`, `loading`, `snap`, `snap_describe`, `style_palette`, `style_compare`, `scenario`, `verify`, `reload`, `resume`, and the static `how`, `check`, `art_list` and `lib_list`;
182
+ `op`, `catalog`, `inspect`, `scene`, `pick`, `thing`, `explain`, `errors`, `loading`, `snap`, `snap_describe`, `picture_palette`, `picture_compare`, `scenario`, `verify`, `reload`, `resume`, and the static `how`, `check`, `art_list` and `lib_list`;
173
183
  tests/mcp.mjs fails when this list and the server's tools differ) and returns the same text as the
174
184
  command line (every default answer fits in about 4 KB, `tests/tool-output-sizes.mjs` guards it; a `data` payload over 3 KB keeps its small fields and names `threedog <cmd> --json` for the rest); `snap` also returns the PNG as an image, 480 px wide by default (`size` for more; the full file is saved). `style_palette` and `style_compare` need no game (recipe 35). It finds the dev server through `.threedog/dev.json` like the CLI; with none running, call the `play` tool (it starts the server and waits for the bridge)
175
185
  (or start `npm run dev` yourself; a tool call without a server answers with that fix). It is only a local client of the bridge and opens no port; every check in section 5 still applies. As
@@ -195,10 +205,10 @@ Tools: MCP, or `node node_modules/@threedog/tools/bin/threedog.mjs <cmd>` (`COMM
195
205
  - What is this object, why can't I click it -> `thing(id).explain()`.
196
206
  - Stuck, or a value is not what you set -> `describe().holds` / `.shared` / `.control`.
197
207
  - What caused this -> `events.trace(name)`, `traceFocus(id)`.
198
- - Placeholders (gray look, capsule, boxes) -> the look is not made yet: `style/` (recipe 09), code models (05), tuning (35).
199
- - The picture looks wrong -> `engine.debug.view('lighting')`, `describe().look`, `threedog inspect materials`.
208
+ - Placeholders (gray picture, capsule, boxes) -> the picture is not made yet: `picture/` (recipes 62, 09), code models (05), tuning (35).
209
+ - The picture looks wrong -> `engine.debug.view('lighting')`, `describe().picture`, `threedog inspect materials`.
200
210
  - Slow or stutters -> `threedog inspect perf`, `debug.view('shaderCost')`.
201
- - "... so the engine stopped writing it" -> your direct write owns it now: `look.<part>.manual(key)`, `describe().owned` (recipe 52).
211
+ - "... so the engine stopped writing it" -> your direct write owns it now: `engine.view.manual(key)`, `describe().owned` (recipe 52).
202
212
  - Models made in code -> hot swap, `threedog gallery --shots` (recipe 05 §2c); another game's art -> `threedog art copy`.
203
- - Verifying a change -> `describeText()` for logic, shots for looks, `threedog verify <scenario>` (read "not proven").
213
+ - Verifying a change -> `describeText()` for logic, shots for the picture, `threedog verify <scenario>` (read "not proven").
204
214
  - Saves or time skips broken -> `checkSave`, `checkSkip`.
@@ -17,13 +17,13 @@ transient effects. Everything placed in a level comes from content, so a new gam
17
17
  Many copies of one interactive object (chests, beds, campfires) with the same model, interaction and container: define it once as a content template
18
18
  and place instances (recipe 30-templates.md); the template is the shared read-only definition, the record holds only the instance state.
19
19
 
20
- ## 1. Three steps: data, look, change
20
+ ## 1. Three steps: data, picture, change
21
21
  ```js
22
22
  const W = engine.world;
23
23
  W.add({ id: 'zombie_1', kind: 'zombie', position: [10, 0, -4], hp: 10 }); // fields must be plain values; without an id one is numbered automatically (saved)
24
24
  W.present('zombie', {
25
25
  build: rec => new THREE.Mesh(zombieGeo, zombieMat), // required: built when the camera is near (may be async); world adds it to the scene at rec.position
26
- update: (rec, obj, dt) => { obj.visible = rec.hp > 0; }, // optional: called every frame for records that have a model; change the look from the data
26
+ update: (rec, obj, dt) => { obj.visible = rec.hp > 0; }, // optional: called every frame for records that have a model; change the picture from the data
27
27
  dispose: (rec, obj) => engine.remove(obj), // optional: first argument is the data, second the model; this is the default
28
28
  show: rec => rec.hp > 0, // optional: false = this record has no model right now (picked up, waiting to respawn)
29
29
  radius: 40, // optional: how near to build the model (meters or a function); default world.radius (60)
@@ -37,14 +37,16 @@ W.simulate('zombie', {
37
37
  (`world.ready`); it retries when you walk away and come back.
38
38
  - `show` is re-evaluated when `world.set` changes data of that kind. Calling `present` again for the same kind tears down old models with the old
39
39
  dispose and rebuilds them with the new one.
40
- - Animation, particles and other things that only matter per frame go in `present.update`, not in simulate.
40
+ - Animation, particles and other things that only matter per frame go in `present.update`, not in simulate. It runs after world placed the model
41
+ on its record, so picture-only motion written there stays: `update: (rec, obj, dt) => { obj.getObjectByName('legL').rotation.x = Math.sin(rec.walk * 9) * 0.5;
42
+ obj.position.x += rec.stagger * 0.1; }` (a leg swing, a stagger offset). Moving the model from anywhere else is put back next frame, with a warning.
41
43
 
42
44
  ## 2. How to change data
43
45
  - Discrete changes (open a chest, switch growth stage, get picked up, change direction) use `W.set(id, { opened: true })`: it emits `world:change` and
44
46
  re-evaluates `show`. Don't `set` every step. id / kind cannot be changed (to change the kind, remove then add).
45
47
  - Things that change every step (position, timers, pathfinding state) are changed directly on the rec's fields inside simulate, and position with
46
48
  `W.move`: no event, cheap.
47
- - Both ways are saved (a save compares contents, it does not rely on events). `move` emits no event: if the look needs to follow position, compare in
49
+ - Both ways are saved (a save compares contents, it does not rely on events). `move` emits no event: if the picture needs to follow position, compare in
48
50
  `update` (see `content/props.js`).
49
51
  - Don't hold a rec object for long: loading a save replaces it with a new object. Keep the id and call `W.get(id)` when you need it.
50
52
  - Position forms: Vector3 / object / `[x, y, z]` / `{ x, z }` (a missing y keeps the old one). In development NaN or an array with only two numbers
@@ -54,7 +56,7 @@ W.simulate('zombie', {
54
56
  The key idea: **don't accumulate every step; record the time it was planted, `plantedAt = clock.now`, and growth = now - planted time**. Whether the
55
57
  player walked away, loaded a save, or fast-forwarded with `engine.step(60)`, the result is right, and no simulate is needed.
56
58
  ```js
57
- import { presets, THREE, makeMaterial } from 'threedog';
59
+ import { presets, THREE } from 'threedog';
58
60
 
59
61
  const GROW = 120; // ripe after 120 game seconds (the unit of clock.now)
60
62
  const growth = rec => Math.min(1, (engine.clock.now - rec.plantedAt) / GROW); // 0..1
@@ -62,7 +64,7 @@ const geo = new THREE.ConeGeometry(0.25, 0.8, 6);
62
64
 
63
65
  engine.world.present('crop', {
64
66
  build(rec) {
65
- const m = new THREE.Mesh(geo, makeMaterial('prop', { color: 0x6aa84f }));
67
+ const m = new THREE.Mesh(geo, new THREE.MeshLambertMaterial({ color: 0x6aa84f }));
66
68
  m.castShadow = true;
67
69
  m.userData.use = engine.interactions.add(m, { label: 'Harvest', radius: 2, enabled: () => growth(rec) >= 1, onUse: () => harvest(rec) }); // can be harvested only when ripe
68
70
  return m;
@@ -114,9 +116,9 @@ generated at runtime (planted by the player, spawned) are saved whole; `add(def,
114
116
  described at the top of `modules/world/persist.js`.
115
117
  World models are in the thing registry too (`engine.thing(id)` answers with the record, saved `'record'`): do not move them from code. Change the
116
118
  record (`ops.run('thing.set', { id, position })`, `world.set` / `world.move`); dev reports code that moves a `positionFrom: 'record'` model, and
117
- `engine.add` of a model throws (recipe 41).
119
+ `engine.add` of a model throws (recipe 40).
118
120
 
119
- A world record's model belongs to the scene too (`40-scene.md`; `engine.thing(id)` shows it, recipe 41). Do not move that model from code: the record owns its <!-- r18-ignore-line -->
121
+ A world record's model belongs to the scene too (`40-scene.md`; `engine.thing(id)` shows it, recipe 40). Do not move that model from code: the record owns its <!-- r18-ignore-line -->
120
122
  position, so change the record (`world.set`, `world.move`) and the model follows.
121
123
 
122
124
  ## 5. Example: something that wanders
@@ -8,20 +8,22 @@ ray registration is needed.**
8
8
 
9
9
  ## 1. A first-person shooting range (copy it and it runs)
10
10
  ```js
11
- import { createEngine, presets, openWorld, hud, THREE, makeMaterial } from 'threedog';
12
- import style from './style/index.js'; // the game's own style
11
+ import { createEngine, presets, openWorld, hud, THREE } from 'threedog';
12
+ import { createPicture } from './picture/index.js'; // the game's own picture, plain three.js (recipe 62)
13
13
  import { terrainPreset } from '@threedog/terrain-noise';
14
14
 
15
- const engine = createEngine({ canvas: document.getElementById('view'), style, saveKey: 'range' });
15
+ const engine = createEngine({ canvas: document.getElementById('view'), lights: false, saveKey: 'range' });
16
16
  engine.use(openWorld({ seed: 7, terrain: terrainPreset(), camera: 'firstPerson' }), hud()); // camera (required): 'follow' | 'firstPerson' | 'rts' | 'fixed', or pass a module like firstPersonCamera({ height: 1.7 })
17
+ const picture = createPicture(engine);
17
18
  engine.input.action('shoot', { label: 'Shoot', keys: ['Mouse0', 'KeyF'] }); // the left mouse button is a key too (Mouse0 / Mouse1 / Mouse2); either it or KeyF works
18
19
  engine.characters.createPlayer({ ...presets.player.aim, spawn: engine.characters.findSpawn([0, 0, 0], { minH: 3, maxH: 14 }) });
20
+ Object.assign(window, { engine, picture });
19
21
  await engine.start(); // place targets after the terrain is generated
20
22
 
21
23
  // Targets: ordinary three.js objects. Put your own data in target.userData; managing them with a Map / Set is faster than traversing the scene
22
24
  const targets = [];
23
25
  function addTarget(x, z) {
24
- const t = new THREE.Mesh(new THREE.CylinderGeometry(0.5, 0.5, 0.1, 16), makeMaterial('prop', { color: 0xd9534f }));
26
+ const t = new THREE.Mesh(new THREE.CylinderGeometry(0.5, 0.5, 0.1, 16), new THREE.MeshLambertMaterial({ color: 0xd9534f }));
25
27
  t.rotation.x = Math.PI / 2;
26
28
  t.position.set(x, engine.surface(x, z) + 1.5, z);
27
29
  engine.add(t); targets.push(t);
@@ -58,7 +60,7 @@ engine.onFixed(() => { // firing is gameplay:
58
60
  bodies too, pass `targets: 'all'`.
59
61
 
60
62
  ## 2. What happens after a hit
61
- - Hit-point effect: `engine.particles.emit(name, hit.point)` (install `particles()` first).
63
+ - Hit-point effect: `engine.particles.emit(name, hit.point)` (install `particles()` first, recipe 64).
62
64
  - For bullets with flight time (arcs, enemies dodging): don't use a ray; write `world.add({ kind: 'bullet', ... })` + `world.simulate`, see `18-world.md`.
63
65
  - Distance limit: `engine.pick(0, 0, { targets, far: 60 })`.
64
66
  - Score, ammo: `hud.counter` / `hud.bar`; numbers that must be saved go in `engine.vars` (`engine.vars.bump('score')`); after changing them call