threedog 1.1.0 → 1.3.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 (370) hide show
  1. package/CHANGELOG.md +893 -798
  2. package/README.md +1 -1
  3. package/core/assets/Animator.js +41 -3
  4. package/core/assets/Assets.js +100 -24
  5. package/core/assets/assetEntry.js +73 -20
  6. package/core/assets/assetHot.js +68 -16
  7. package/core/assets/assetLoad.js +6 -6
  8. package/core/assets/assetLod.js +9 -2
  9. package/core/assets/assetManifest.js +12 -2
  10. package/core/assets/assetPart.js +54 -0
  11. package/core/assets/ik.js +271 -0
  12. package/core/assets/modelNeeds.js +37 -0
  13. package/core/assets/namedModel.js +102 -29
  14. package/core/assets/nodeVisibility.js +15 -0
  15. package/core/audio/Audio.js +36 -4
  16. package/core/audio/audioReverb.js +99 -0
  17. package/core/audio/audioRules.js +1 -1
  18. package/core/audio/audioVoice.js +1 -1
  19. package/core/base/Events.js +14 -4
  20. package/core/base/Random.js +1 -1
  21. package/core/base/Vars.js +1 -1
  22. package/core/base/docRef.js +51 -0
  23. package/core/base/errorCodes.js +187 -126
  24. package/core/base/errorHints.js +9 -7
  25. package/core/base/errors.js +25 -10
  26. package/core/base/events.generated.js +2 -0
  27. package/core/base/freeParts.js +76 -0
  28. package/core/base/math.js +28 -0
  29. package/core/base/sections.js +5 -5
  30. package/core/base/validate.js +31 -3
  31. package/core/engine/Engine.js +17 -7
  32. package/core/engine/Loading.js +5 -3
  33. package/core/engine/copies.js +1 -1
  34. package/core/engine/headlessLoad.js +4 -1
  35. package/core/engine/lifecycle.js +32 -16
  36. package/core/engine/loop.js +71 -27
  37. package/core/engine/moduleSlots.js +2 -2
  38. package/core/engine/moduleTypes.js +3 -3
  39. package/core/engine/modules.js +65 -39
  40. package/core/engine/page.js +6 -3
  41. package/core/engine/services.js +6 -5
  42. package/core/engine/startup.js +8 -7
  43. package/core/input/Input.js +28 -14
  44. package/core/input/inputContext.js +28 -16
  45. package/core/input/inputKeyboard.js +31 -3
  46. package/core/input/inputPad.js +4 -0
  47. package/core/input/inputPointer.js +2 -1
  48. package/core/input/inputSeat.js +1 -1
  49. package/core/inspect/Budget.js +109 -19
  50. package/core/inspect/DebugOverrides.js +28 -4
  51. package/core/inspect/Describe.js +17 -9
  52. package/core/inspect/Inspect.js +4 -2
  53. package/core/inspect/InspectMaterials.js +3 -1
  54. package/core/inspect/InspectPerf.js +19 -9
  55. package/core/inspect/InspectScene.js +32 -7
  56. package/core/inspect/MaterialInfo.js +19 -2
  57. package/core/inspect/UrlState.js +50 -28
  58. package/core/inspect/catalog.js +28 -9
  59. package/core/inspect/debugView.js +2 -1
  60. package/core/inspect/describeRender.js +25 -13
  61. package/core/inspect/describeText.js +14 -6
  62. package/core/inspect/lightWatch.js +1 -1
  63. package/core/inspect/metadata.generated.js +35 -17
  64. package/core/inspect/pictureChecks.js +148 -0
  65. package/core/inspect/pictureMenu.js +84 -0
  66. package/core/inspect/pictureWriters.js +26 -6
  67. package/core/inspect/textureBytes.js +12 -2
  68. package/core/inspect/toolDoor.js +2 -4
  69. package/core/ops/Ops.js +11 -4
  70. package/core/ops/holds.js +27 -10
  71. package/core/ops/opsAtomic.js +15 -7
  72. package/core/ops/opsGuard.js +2 -2
  73. package/core/ops/opsRun.js +8 -7
  74. package/core/ops/sharedPoint.js +72 -21
  75. package/core/ops/stacks.js +56 -16
  76. package/core/saves/SaveStore.js +9 -3
  77. package/core/saves/Saves.js +32 -23
  78. package/core/saves/saveApply.js +96 -44
  79. package/core/saves/saveIds.js +1 -1
  80. package/core/saves/saveVersions.js +7 -5
  81. package/core/saves/session.js +17 -8
  82. package/core/saves/stateReplace.js +34 -15
  83. package/core/scene/Rays.js +52 -10
  84. package/core/scene/Views.js +36 -15
  85. package/core/scene/adaptive.js +144 -21
  86. package/core/scene/drawOnly.js +17 -0
  87. package/core/scene/gameLights.js +47 -4
  88. package/core/scene/sceneMethods.js +13 -11
  89. package/core/scene/stepPoses.js +11 -3
  90. package/core/scene/targeting.js +5 -3
  91. package/core/scene/thingOps.js +1 -1
  92. package/core/scene/tier.js +15 -0
  93. package/core/stream/Batching.js +30 -7
  94. package/core/stream/Stream.js +26 -7
  95. package/core/stream/batchGroups.js +2 -2
  96. package/core/stream/chunkStream.js +7 -5
  97. package/core/stream/prepare.js +77 -0
  98. package/core/time/skip.js +3 -1
  99. package/core/time/time.js +4 -2
  100. package/docs/AI.md +82 -83
  101. package/docs/API.md +16 -16
  102. package/docs/CODEMAP.md +17 -11
  103. package/docs/COMMANDS.md +139 -142
  104. package/docs/CONVENTIONS.md +37 -49
  105. package/docs/MIGRATING-0.8.md +2 -2
  106. package/docs/MIGRATING-1.0.md +2 -2
  107. package/docs/THREE.md +30 -35
  108. package/docs/api/assets.md +3 -1
  109. package/docs/api/audio.md +4 -2
  110. package/docs/api/budget.md +5 -0
  111. package/docs/api/characters.md +10 -8
  112. package/docs/api/collision.md +6 -4
  113. package/docs/api/engine.md +16 -16
  114. package/docs/api/events.md +3 -2
  115. package/docs/api/ground.md +6 -5
  116. package/docs/api/hud.md +4 -2
  117. package/docs/api/input.md +5 -5
  118. package/docs/api/particles.md +2 -1
  119. package/docs/api/photo.md +3 -0
  120. package/docs/api/post.md +7 -4
  121. package/docs/api/quests.md +2 -2
  122. package/docs/api/rays.md +1 -2
  123. package/docs/api/saves.md +7 -7
  124. package/docs/api/settings.md +2 -2
  125. package/docs/api/tools.md +3 -1
  126. package/docs/api/vars.md +1 -1
  127. package/docs/api/vegetation.md +4 -2
  128. package/docs/api/world.md +1 -1
  129. package/docs/recipes/01-new-game.md +16 -17
  130. package/docs/recipes/02-npc.md +22 -18
  131. package/docs/recipes/03-items-pickups.md +37 -35
  132. package/docs/recipes/04-quests.md +15 -10
  133. package/docs/recipes/05-props-bake.md +101 -95
  134. package/docs/recipes/06-clock-events.md +28 -28
  135. package/docs/recipes/07-flow-scenes-pause.md +29 -26
  136. package/docs/recipes/08-weather-sky.md +52 -64
  137. package/docs/recipes/09-materials-lights-models.md +26 -17
  138. package/docs/recipes/10-blender-level.md +15 -10
  139. package/docs/recipes/11-vehicles.md +12 -7
  140. package/docs/recipes/12-navmesh.md +44 -26
  141. package/docs/recipes/13-animation.md +56 -45
  142. package/docs/recipes/14-custom-module.md +21 -18
  143. package/docs/recipes/15-perf.md +61 -55
  144. package/docs/recipes/16-dev-bridge.md +24 -33
  145. package/docs/recipes/18-world.md +36 -42
  146. package/docs/recipes/19-shooting-picking.md +20 -15
  147. package/docs/recipes/20-content-actions-save.md +48 -56
  148. package/docs/recipes/21-camera.md +45 -54
  149. package/docs/recipes/22-shop-gold.md +12 -7
  150. package/docs/recipes/23-ops.md +25 -23
  151. package/docs/recipes/26-ui-parts.md +67 -47
  152. package/docs/recipes/27-net.md +12 -7
  153. package/docs/recipes/28-terrain.md +24 -21
  154. package/docs/recipes/29-grid.md +32 -27
  155. package/docs/recipes/30-templates.md +21 -20
  156. package/docs/recipes/31-audio.md +39 -22
  157. package/docs/recipes/32-action-game.md +19 -14
  158. package/docs/recipes/33-stream-sources.md +15 -11
  159. package/docs/recipes/34-environment-lighting.md +126 -70
  160. package/docs/recipes/35-picture-from-reference.md +8 -8
  161. package/docs/recipes/36-ground-plants.md +27 -21
  162. package/docs/recipes/40-scene.md +19 -28
  163. package/docs/recipes/43-shader-patches-surfaces.md +15 -12
  164. package/docs/recipes/44-water-weather-hooks.md +34 -31
  165. package/docs/recipes/45-cascaded-shadows.md +35 -26
  166. package/docs/recipes/46-blender-art-route.md +7 -2
  167. package/docs/recipes/49-game-module-contract.md +13 -8
  168. package/docs/recipes/50-own-renderer.md +6 -2
  169. package/docs/recipes/51-capability-catalog.md +15 -8
  170. package/docs/recipes/52-around-the-picture.md +34 -32
  171. package/docs/recipes/53-ground-up-close.md +6 -1
  172. package/docs/recipes/55-mods-time-wrap.md +27 -19
  173. package/docs/recipes/56-webgpu-tsl.md +75 -43
  174. package/docs/recipes/57-control.md +18 -13
  175. package/docs/recipes/58-input.md +26 -16
  176. package/docs/recipes/59-depth-post-effects.md +8 -3
  177. package/docs/recipes/60-judge-the-picture.md +10 -9
  178. package/docs/recipes/61-deploy.md +5 -0
  179. package/docs/recipes/62-picture-code.md +72 -79
  180. package/docs/recipes/63-third-person-start.md +48 -45
  181. package/docs/recipes/64-particles.md +22 -10
  182. package/docs/recipes/65-swarm.md +18 -13
  183. package/docs/recipes/66-common-tasks.md +38 -35
  184. package/examples/action/.threedog/content-index.json +1 -1
  185. package/examples/action/GAMEMAP.md +2 -3
  186. package/examples/action/main.js +3 -3
  187. package/examples/action/picture/lights.js +3 -1
  188. package/examples/perf-island/.threedog/content-index.json +1 -1
  189. package/examples/perf-island/GAMEMAP.md +3 -3
  190. package/examples/perf-island/picture/lights.js +2 -1
  191. package/examples/plain-picture/GAMEMAP.md +1 -1
  192. package/examples/rc2d/GAMEMAP.md +1 -1
  193. package/examples/styletest/.threedog/content-index.json +1 -1
  194. package/examples/styletest/GAMEMAP.md +2 -2
  195. package/examples/styletest/main.js +1 -1
  196. package/examples/techniques/interior-light/README.md +3 -3
  197. package/examples/techniques/interior-light/interiorLight.js +2 -4
  198. package/examples/techniques/interior-light/picture/lights.js +2 -1
  199. package/examples/techniques/modular-building/picture/lights.js +3 -1
  200. package/examples/techniques/outlines-and-rim/picture/lights.js +3 -1
  201. package/examples/techniques/procedural-animation/README.md +1 -1
  202. package/examples/techniques/procedural-animation/main.js +1 -1
  203. package/examples/webgpu-tsl/GAMEMAP.md +1 -1
  204. package/examples/world/.threedog/content-index.json +1 -1
  205. package/examples/world/GAMEMAP.md +2 -3
  206. package/examples/world/art/humanoid.js +1 -1
  207. package/examples/world/main.js +6 -3
  208. package/index.d.ts +2 -2
  209. package/llms.txt +101 -0
  210. package/modules/ambience/Ambience.js +21 -5
  211. package/modules/calendar/index.js +9 -5
  212. package/modules/calendar/schedule.js +23 -8
  213. package/modules/camera/FirstPersonCamera.js +3 -1
  214. package/modules/camera/FollowCamera.js +10 -5
  215. package/modules/camera/RtsCamera.js +4 -3
  216. package/modules/camera/common.js +70 -8
  217. package/modules/camera/contract.js +1 -1
  218. package/modules/characters/Character.js +16 -10
  219. package/modules/characters/NPC.js +31 -19
  220. package/modules/characters/assetModel.js +14 -9
  221. package/modules/characters/astar.js +6 -1
  222. package/modules/characters/contract.js +2 -2
  223. package/modules/characters/index.js +34 -22
  224. package/modules/characters/movers/manual.js +1 -1
  225. package/modules/characters/movers/rapier.js +17 -2
  226. package/modules/characters/movers/simple.js +1 -1
  227. package/modules/characters/movers/support.js +16 -7
  228. package/modules/characters/npcAvoid.js +2 -2
  229. package/modules/characters/npcSim.js +3 -2
  230. package/modules/characters/pathAsync.js +24 -8
  231. package/modules/characters/pathJob.js +1 -1
  232. package/modules/characters/player.js +10 -9
  233. package/modules/characters/playerStrings.js +5 -5
  234. package/modules/characters/proceduralRig.js +5 -5
  235. package/modules/characters/useModel.js +6 -0
  236. package/modules/characters/walkTo.js +1 -1
  237. package/modules/collision/Collision.js +29 -18
  238. package/modules/collision/grid.js +22 -4
  239. package/modules/content/index.js +3 -1
  240. package/modules/content/loader.js +1 -1
  241. package/modules/content/models.js +82 -33
  242. package/modules/content/props.js +2 -1
  243. package/modules/content/rules.js +11 -5
  244. package/modules/content/templates.js +3 -3
  245. package/modules/content/words.js +2 -2
  246. package/modules/debug/DebugPanel.js +9 -9
  247. package/modules/flow/index.js +9 -6
  248. package/modules/gameplay/Dialogue.js +34 -20
  249. package/modules/gameplay/Interactions.js +19 -15
  250. package/modules/gameplay/Inventory.js +9 -4
  251. package/modules/gameplay/Quests.js +12 -10
  252. package/modules/gameplay/pickups.js +23 -11
  253. package/modules/grid/index.js +1 -1
  254. package/modules/grid/preview.js +2 -2
  255. package/modules/grid/tiles.js +1 -1
  256. package/modules/hlod/index.js +4 -1
  257. package/modules/hud/index.js +47 -10
  258. package/modules/hud/parts.js +28 -9
  259. package/modules/level/geometry.js +8 -3
  260. package/modules/level/index.js +10 -5
  261. package/modules/level/load.js +4 -2
  262. package/modules/lights/sources.js +1 -1
  263. package/modules/music/Music.js +22 -4
  264. package/modules/nav/index.js +20 -10
  265. package/modules/particles/Particles.js +31 -14
  266. package/modules/particles/effect.js +20 -5
  267. package/modules/particles/lit.js +72 -0
  268. package/modules/photo/Photo.js +72 -28
  269. package/modules/photo/pathTrace.js +106 -0
  270. package/modules/rigid/RigidBodies.js +23 -14
  271. package/modules/rigid/Vehicles.js +3 -13
  272. package/modules/rigid/sync.js +2 -1
  273. package/modules/settings/Settings.js +52 -20
  274. package/modules/settings/apply.js +23 -9
  275. package/modules/settings/sections.js +39 -6
  276. package/modules/settings/strings.js +2 -0
  277. package/modules/settings/view.js +19 -3
  278. package/modules/sky/dome.js +15 -3
  279. package/modules/sky/environment.js +28 -12
  280. package/modules/sky/fog.js +1 -1
  281. package/modules/sky/frame.js +6 -1
  282. package/modules/sky/shader.js +4 -3
  283. package/modules/sky/skyModule.js +8 -4
  284. package/modules/swarm/Swarm.js +1 -1
  285. package/modules/terrain/ChunkManager.js +61 -15
  286. package/modules/terrain/chunkJob.js +2 -2
  287. package/modules/terrain/index.js +20 -5
  288. package/modules/terrain/terrainEdit.js +8 -4
  289. package/modules/terrain/terrainTexture.js +4 -2
  290. package/modules/timeline/Timeline.js +4 -3
  291. package/modules/timeline/Tween.js +3 -0
  292. package/modules/timeline/letterbox.js +1 -0
  293. package/modules/triggers/index.js +36 -17
  294. package/modules/vegetation/Vegetation.js +81 -19
  295. package/modules/vegetation/densityMap.js +13 -8
  296. package/modules/vegetation/draw.js +147 -24
  297. package/modules/vegetation/groundChunks.js +20 -5
  298. package/modules/vegetation/index.js +3 -3
  299. package/modules/vegetation/modelGeometry.js +9 -4
  300. package/modules/water/Water.js +11 -8
  301. package/modules/weather/Weather.js +7 -2
  302. package/modules/weather/shaders.js +25 -5
  303. package/modules/weather/weatherDraw.js +20 -6
  304. package/modules/world/World.js +2 -1
  305. package/modules/world/index.js +2 -2
  306. package/modules/world/persist.js +6 -2
  307. package/modules/world/views.js +15 -2
  308. package/package.json +5 -1
  309. package/presets.js +5 -5
  310. package/render/PostFX.js +102 -42
  311. package/render/backend.js +142 -16
  312. package/render/bindingLimits.js +59 -0
  313. package/render/cascades.js +3 -1
  314. package/render/cascades.tsl.js +2 -0
  315. package/render/daylight.js +7 -1
  316. package/render/detail.js +7 -4
  317. package/render/effects.js +27 -8
  318. package/render/fogLook.js +24 -0
  319. package/render/fuse.js +5 -2
  320. package/render/fx/compareLevel.tsl.js +23 -0
  321. package/render/fx/detail.tsl.js +9 -7
  322. package/render/fx/index.js +9 -2
  323. package/render/fx/library.tsl.js +1 -0
  324. package/render/fx/lightShaft.tsl.js +114 -0
  325. package/render/fx/noise.tsl.js +25 -8
  326. package/render/fx/objectOrigin.tsl.js +39 -10
  327. package/render/fx/particles.tsl.js +23 -6
  328. package/render/fx/patchNodes.tsl.js +17 -12
  329. package/render/fx/pcss.tsl.js +51 -0
  330. package/render/fx/postWebGPU.tsl.js +104 -29
  331. package/render/fx/sky.tsl.js +3 -9
  332. package/render/fxNumbers.js +10 -4
  333. package/render/impostor.tsl.js +107 -0
  334. package/render/lighting.js +33 -1
  335. package/render/lightmap.js +42 -28
  336. package/render/lights.js +19 -3
  337. package/render/materials.js +6 -4
  338. package/render/mergeCommon.js +4 -1
  339. package/render/occlusion.js +14 -4
  340. package/render/patches.js +79 -41
  341. package/render/postRuns.js +32 -0
  342. package/render/postWebGL.js +97 -10
  343. package/render/probes.js +10 -14
  344. package/render/shaderErrors.js +44 -7
  345. package/render/shadowCache.tsl.js +33 -5
  346. package/render/shadows.js +42 -16
  347. package/render/slots.js +8 -5
  348. package/render/vertexInputs.js +52 -0
  349. package/types/core.d.ts +115 -47
  350. package/types/gameplay.d.ts +56 -23
  351. package/types/generated/core/audio/Audio.d.ts +27 -1
  352. package/types/generated/core/base/Random.d.ts +1 -1
  353. package/types/generated/core/input/Input.d.ts +6 -8
  354. package/types/generated/core/input/inputSeat.d.ts +1 -1
  355. package/types/generated/core/inspect/Budget.d.ts +26 -0
  356. package/types/generated/core/inspect/DebugOverrides.d.ts +0 -2
  357. package/types/generated/core/saves/Saves.d.ts +10 -7
  358. package/types/generated/core/saves/session.d.ts +8 -2
  359. package/types/generated/core/scene/Rays.d.ts +1 -3
  360. package/types/generated/core/scene/Views.d.ts +17 -3
  361. package/types/generated/modules/particles/Particles.d.ts +1 -1
  362. package/types/generated/modules/world/World.d.ts +2 -1
  363. package/types/generated/render/PostFX.d.ts +35 -9
  364. package/types/physics.d.ts +796 -764
  365. package/types/pixel.d.ts +1 -1
  366. package/types/tsl.d.ts +62 -1
  367. package/types/world.d.ts +12 -3
  368. package/ui/Focus.js +7 -5
  369. package/ui/Parts.js +1 -1
  370. package/ui/touchPart.js +6 -3
@@ -1,6 +1,9 @@
1
1
  # Lights, fog, exposure and environment lighting
2
2
 
3
- **In this recipe**: Lights · Fog · Exposure and the tone curve · The sky as a map · Light probes · Lightmaps · Real-time bounced light · Light you can see in the air · Occlusion culling
3
+ > **Covers:** lights, fog, exposure, environment maps, probes, lightmaps, light you can see in the air (light beams, shafts).
4
+ > **Use when:** lighting a scene or making its light change.
5
+ > **Shortest:** your own `THREE.DirectionalLight` added in `picture/`.
6
+ > **Sections:** Lights the placeholders, and · A light the player carries · Fog plain three.js, signals · Exposure and the tone · Environment maps · Light probes baked indirect · Lightmaps baked light on · Real-time bounced light WebGPU · Reflections · Light you can see · Soft shadows, area lights · Occlusion culling
4
7
 
5
8
  Lights, fog and exposure are your own three.js code ([recipe 62](62-picture-code.md)): the sky computes signals and draws its dome, it writes none of them. The sky itself is `08-weather-sky.md`.
6
9
 
@@ -9,22 +12,36 @@ The engine has one directional light (`engine.lights.sun`) and one hemisphere (`
9
12
  with no picture code is neutral gray and not black. Nothing moves them, with or without a sky.
10
13
 
11
14
  ```js
12
- const engine = createEngine({ canvas, lights: false }); // the placeholders stay out of the scene
13
- const sun = new THREE.DirectionalLight(0xffd0a0, 2); engine.scene.add(sun, sun.target); // add your own lights before engine.start()
15
+ const engine = createEngine({ canvas, lights: false }); // the placeholders stay out of the scene
16
+ const sun = new THREE.DirectionalLight(0xffd0a0, 2); engine.scene.add(sun, sun.target); // add your own lights before engine.start()
14
17
  engine.onRender(() => { sun.position.copy(engine.uniforms.uSunDir.value).multiplyScalar(100); sun.intensity = 2 * engine.uniforms.uDaylight.value * engine.uniforms.uWeatherLight.value; });
15
18
  const torch = new THREE.PointLight(0xffa040, 6, 12); engine.add(torch);
16
19
  ```
17
20
 
18
- - `createEngine({ lights: false })`: the default sun and hemisphere are never put in the scene, `engine.lights.sun` / `hemi`
19
- stay as detached objects so nothing reads `undefined`. Use it for a scene lit entirely by your own lights.
20
- - Shadows: only the engine sun's box is managed. Your own `castShadow` lights work as in three.js, each costing its
21
- own shadow pass; `engine.shadows` (recipe 45) takes them when you hand them in, and `engine.shadows.enabled = false` turns every shadow off.
21
+ - `createEngine({ lights: false })`: the placeholders never enter the scene; `engine.lights.sun` / `hemi` stay as detached objects so nothing reads `undefined`.
22
+ - Shadows: only the engine sun's box is managed. Your own `castShadow` lights work as in three.js (one shadow pass each); `engine.shadows` (recipe 45) takes those you hand in, and `engine.shadows.enabled = false` turns every shadow off.
22
23
  - Add or remove lights before `engine.start()`; what a change costs mid-play, and many lamps with `lightPool`: recipe 09 "Lights and stalls".
24
+ - A light the player carries (head lamp, torch, flashlight): place it every frame next to `engine.camera` or parent it to the player, as in three.js; nothing to call. While the camera hides the body (first person, a follow close-up), a shadow-casting point or spot light within one body width of the body is not shadowed by it, on both renderers, so the lamp pool has no black wedge; the sun and the other lights still cast the body's shadow. A body that is seen (third person) shadows every light, a torch in the hand too, as in plain three.js. The lamp's own fixture mesh is yours: give it `castShadow = false`, or it shadows its own light.
25
+
26
+ ## A light the player carries (headlamp, lantern, flashlight): one spot that follows, with a shadow
27
+ One plain three.js `SpotLight`, moved with the view each frame (also a car's beam). `lightPool` is for many cheap lights sharing a few real ones (recipe 09), not for this.
28
+ ```js
29
+ const beam = new THREE.SpotLight(0xffd8a0, 80, 18, 0.6, 0.5, 2); // color, intensity (candela), distance, angle, penumbra, decay
30
+ beam.castShadow = true; beam.shadow.mapSize.set(1024, 1024); beam.shadow.camera.near = 0.2;
31
+ engine.scene.add(beam, beam.target); // add before engine.start(), like any light
32
+ const ahead = new THREE.Vector3();
33
+ engine.onRender(() => { // after the camera moved this frame: the light never lags the view
34
+ const cam = engine.camera; beam.position.copy(cam.position);
35
+ beam.target.position.copy(cam.getWorldDirection(ahead)).multiplyScalar(4).add(cam.position);
36
+ });
37
+ ```
38
+ - **Intensity is candela** (decay 2): a lantern with a short `distance` takes tens to a few hundred. Judge it in a shot of the darkest place.
39
+ - **Shadow cost**: one extra caster render per frame (a point light: six). Keep `distance` short (it bounds the shadow camera), `mapSize` modest; make it a quality setting. For a hand or shoulder, use that object's `getWorldPosition`.
23
40
 
24
41
  ## Fog: plain three.js, signals, your own math
25
42
  ```js
26
- const fog = engine.scene.fog = new THREE.Fog(0x99bbbb, 60, 220); // or new THREE.FogExp2(color, density)
27
- engine.onRender(() => { // a fog that follows the day and the weather: your picture/ code
43
+ const fog = engine.scene.fog = new THREE.Fog(0x99bbbb, 60, 220); // or new THREE.FogExp2(color, density)
44
+ engine.onRender(() => { // a fog that follows the day and the weather: your picture/ code
28
45
  fog.color.copy(engine.uniforms.uSkyHorizon.value);
29
46
  fog.far = 220 / engine.uniforms.uWeatherFog.value;
30
47
  });
@@ -33,27 +50,29 @@ There is no fog until your code makes one, and nothing writes it after that.
33
50
 
34
51
  - Signals to read (table in recipe 62): fog in the color of `uSkyHorizon` hides the line where the dome meets the ground; `uWeatherFog` and `uViewDistance` feed your own fog distance.
35
52
  - A fog color of your own that differs from the horizon: the dome fades its lower band to it, so fogged ground and sky still meet without a line.
36
- - Color, near, far and density are live. Adding or removing `scene.fog`, or changing its type, recompiles materials once: do it at a scene change, not every frame.
37
- - Your own fog math (height fog, a warm far haze): the `fogPars` and `fog` slots on a material, WebGL only (recipe 43), or your own `ShaderMaterial`:
53
+ - Color, near, far and density are live. Adding, removing or retyping `scene.fog` recompiles materials once: do it at a scene change.
54
+ - Your own fog math (height fog, a warm far haze): on WebGPU `scene.fogNode` (recipe 56); on WebGL the `fogPars` and `fog` slots on a material (recipe 43) or your own `ShaderMaterial`:
38
55
  `applyEffects(material, { patches: [{ name: 'haze', slot: 'fog', glsl: 'float f = 1.0 - exp(-fogDensity * vFogDepth); gl_FragColor.rgb = mix(gl_FragColor.rgb, vec3(1.0, 0.85, 0.7), f * 0.3);' }] })`.
39
56
  - Check the result with `engine.describe('picture').picture.fog`; `threedog shot` says how much of the picture the fog makes up.
40
57
 
41
58
  ## Exposure and the tone curve
42
59
  ```js
43
60
  engine.renderer.toneMappingExposure = 1.3;
44
- engine.onRender(() => { engine.renderer.toneMappingExposure = 1 + 0.5 * (1 - engine.uniforms.uDaylight.value); }); // over the day: your picture/ code
45
- engine.renderer.toneMapping = THREE.NeutralToneMapping; // the curve; materials recompile on their next draw
61
+ engine.onRender(() => { engine.renderer.toneMappingExposure = 1 + 0.5 * (1 - engine.uniforms.uDaylight.value); }); // over the day: your picture/ code
62
+ engine.renderer.toneMapping = THREE.NeutralToneMapping; // the curve; materials recompile on their next draw
46
63
  ```
47
64
  The engine picks no curve: `renderer.toneMapping` stays three.js's default (`NoToneMapping`) until your code writes it. A curve of your own is a post effect in the `'tone'` slot (recipe 52).
48
65
 
66
+ Exposure that adapts like an eye (WebGPU): `engine.post.add(autoExposure({ min: 0.25, max: 4 }))` from `@threedog/post-effects/tsl` measures the average brightness on the GPU and eases toward `key`. It multiplies after everything that adds light, before tone mapping (`toneMappingExposure` still applies on top). Bloom runs before it, so in bright daylight large areas glow and are then darkened: raise bloom's `threshold` or give it an `order` above 800. Narrow `min` / `max` for an authored look; `speedUp` / `speedDown` set the speed, on `engine.time`; a chain rebuild keeps the adapted value. It measures a 64x64 sample: a small, very bright thing can nudge it.
67
+
49
68
  ## Environment maps
50
69
  `scene.environment` is plain three.js and stays `null` until your code writes it. The background (the sky dome or a skybox) and the environment lighting are two separate fields.
51
70
 
52
71
  ```js fragment
53
- const env = engine.sky.environment({ into: engine.scene }); // the sky as a map: follows the time of day; env.texture is the live map
54
- engine.scene.environmentIntensity = 0.8; // intensity and rotation are three.js
72
+ const env = engine.sky.environment({ into: engine.scene }); // the sky as a map: follows the time of day; env.texture is the live map
73
+ engine.scene.environmentIntensity = 0.8; // intensity and rotation are three.js
55
74
  engine.scene.environmentRotation.y = Math.PI / 2;
56
- env.remove(); // takes the map off, frees it
75
+ env.remove(); // takes the map off, frees it
57
76
  // an asset panorama: plain PMREMGenerator
58
77
  const pmrem = new THREE.PMREMGenerator(engine.renderer);
59
78
  engine.assets.useTexture('hdr/studio.hdr', t => { t.mapping = THREE.EquirectangularReflectionMapping; engine.scene.environment = pmrem.fromEquirectangular(t).texture; });
@@ -63,19 +82,15 @@ engine.scene.environment = myPmremTarget.texture;
63
82
  On `renderer: 'webgpu'` take `PMREMGenerator` from `three/webgpu`. A map you made is yours to dispose.
64
83
 
65
84
  ### The sky as a map: `engine.sky.environment({ into?, interval? })`
66
- - Nothing is built before this call. Without `into` nothing is written anywhere: read `handle.texture` (a live getter) and put it on the materials you choose (`material.envMap`).
85
+ - Nothing is built before this call. Without `into` nothing is written: put `handle.texture` (a live getter) on the materials you choose (`material.envMap`).
67
86
  - With `into`, that object's `.environment` gets the map at each rebuild. A map you write there yourself stays: the rebuilds go on, but only `handle.texture` follows them.
68
- - The dome is rendered into a cube and prefiltered with `PMREMGenerator`. It is rebuilt only when the sky colors, sun direction or cloud
69
- cover actually changed AND at least `interval` seconds (default 1, 4 on a low-tier device; a number the game gives stands) passed since the last check, never every frame. A fixed time of
70
- day builds once. A call before the first frame waits for that frame, so the map uses real colors. One map at a time: a second call replaces the first.
71
- - The cube is at least 256 px per face (PMREMGenerator's floor in 0.187), so a low tier saves time by rebuilding less often, or by your `picture/` code skipping the call on `engine.tier === 'low'`.
87
+ - The dome is rendered into a cube (at least 256 px a face) and prefiltered with `PMREMGenerator`, rebuilt only when sky colors, sun direction or cloud cover changed
88
+ AND `interval` seconds passed (default 1, 4 on a low tier; yours stands). A fixed time of day builds once; a call before the first frame waits for it. A second call replaces the first.
72
89
  - An asset map is a fixed photo: it does not dim at night. Write `scene.environmentIntensity` from your own frame code reading `engine.uniforms.uDaylight`.
73
90
 
74
91
  ### What a MeshLambertMaterial does with it (three 0.187)
75
- The engine's neutral materials are Lambert, so this is what most surfaces do by default.
76
- - A Lambert material gets soft, direction-dependent ambient light colored by the environment (sky blue from above, ground color from below), and no specular: for reflections use a Standard / Physical material.
77
- - The hemisphere light stays and adds on top. When you turn the environment on, lower your hemisphere light so shadows do not wash out.
78
- - The first frame with an environment recompiles every Lambert program once; do it at start-up, not mid-game.
92
+ The engine's neutral materials are Lambert: they get soft ambient light colored by the environment by direction, and no specular (reflections need Standard / Physical).
93
+ The hemisphere light still adds on top, so lower it when the environment comes on. The first frame with an environment recompiles every Lambert program once: do it at start-up.
79
94
  - Toon, Basic and ShaderMaterial surfaces ignore it.
80
95
 
81
96
  ## Light probes (baked indirect light)
@@ -83,88 +98,129 @@ An environment map lights everything as seen from one point. Light probes (`engi
83
98
  a bright wall, dimmer light under a roof), and every lit pixel takes its own light from the grid, on WebGL and WebGPU, with no shader of your own.
84
99
  ```js fragment
85
100
  const probes = await engine.bakeProbes({ bounds: { min: [-30, 0, -30], max: [30, 8, 30] }, spacing: 4, include: o => !o.userData.moving });
86
- const file = JSON.stringify(probes.toJSON()); // ship this (half precision, a few tens of KB)
87
- const shipped = engine.loadProbes(json); // at start-up, instead of the bake; either renderer reads either renderer's file
88
- probes.sample(cart.position); // the SH at any point, for a "how dark is it here"
101
+ const file = JSON.stringify(probes.toJSON()); // ship this (half precision, a few tens of KB)
102
+ const shipped = engine.loadProbes(json); // at start-up, instead of the bake; either renderer reads either renderer's file
103
+ probes.sample(cart.position); // the SH at any point, for a "how dark is it here"
89
104
  probes.remove();
90
105
  ```
91
- - What it builds: three's probe grid over `bounds` (`LightProbeGridWebGL` or `LightProbeGrid`; step at most `spacing`, at least 2 layers per axis), in the scene as
92
- `probes.grid`, a plain three.js light: `priority` and `visible` are yours; `intensity` works on WebGPU only, three's WebGL shader ignores it. The light costs almost nothing per frame.
93
- - **Outside the grid there is no probe light**, and with no other ambient light a mesh goes black there. The light reaches half a step past `bounds`, so a roof on the edge is fine.
94
- Size `bounds` to where things are.
95
- - **Light counted twice**: the bake saw the hemisphere light and the environment, and they still add at run time. Lower them where the probes take over, or bake without them.
96
- A `material.lightMap` inside the grid doubles the same way. A warning says so when the set is added, and describe keeps saying it.
97
- - Dark bake indoors: `scene.background` is a display color, far weaker than the sun, so a room lit by the sky comes out black. Raise the sky just for the bake
98
- (a brighter `scene.background` or `backgroundIntensity`, put back after), and keep a little fill for walls that face away from every window.
99
- - Cost: 6 renders per probe at load time, a few probes per task, so the page keeps drawing (`probes.bakeMs` says how long). Bake once and ship the JSON: phones often cannot bake, but
100
- they all read the file. Meshes `include` rejects are hidden only while the cubes render. Adding a grid recompiles lit materials once, so do it at start-up.
106
+ - What it builds: three's probe grid over `bounds` (step at most `spacing`, at least 2 layers per axis) as `probes.grid`, a plain three.js light that costs almost nothing per frame:
107
+ `priority` and `visible` are yours; `intensity` works on WebGPU only.
108
+ - **Outside the grid there is no probe light** (half a step past `bounds`), and with no other ambient light a mesh goes black there: size `bounds` to where things are.
109
+ - **Light counted twice**: the bake saw the hemisphere light, the environment and any `material.lightMap`, and they still add at run time. Lower them where the probes take over, or bake without them (a warning and describe say so).
110
+ - Dark bake indoors: `scene.background` is a display color, far weaker than the sun. Raise it (or `backgroundIntensity`) for the bake only, and keep a little fill for walls no window sees.
111
+ - Cost: 6 renders per probe, a few per task, so the page keeps drawing (`probes.bakeMs`). Bake once and ship the JSON (phones often cannot bake, all read the file). Adding a grid recompiles lit materials once: at start-up.
101
112
  - Check it: `engine.describe().render.probes` (count, step, source, owner, `outside`: lit objects the grid does not hold, `doubled`: what counts twice) and `engine.debug.view('probes')` (a dot per probe in its average color).
102
113
 
103
114
  ## Lightmaps (baked light on what never moves)
104
115
  The best-looking baked light, and free at run time: it is plain `material.lightMap` on a second UV set, so a file baked on WebGPU draws the same on WebGL. Baking needs a real GPU and Google Chrome on the machine that bakes, not on the player's.
105
116
  ```js fragment
106
- floor.userData.static = true; wall.userData.static = true; // named meshes that never move
117
+ floor.userData.static = true; wall.userData.static = true; // named meshes that never move
107
118
  // npx threedog bake light --page "/?bake=1" --out public/light/level.lightmap --size 1024
108
119
  const baking = new URLSearchParams(location.search).has('bake'); // the bake must see the lights the map replaces
109
120
  if (!baking) {
110
- const light = await engine.loadLightmap('light/level.lightmap'); // once the level is built
111
- hemi.visible = false; // the bake saw it: keep the sun, drop the ambient
121
+ const light = await engine.loadLightmap('light/level.lightmap'); // once the level is built
122
+ hemi.visible = false; // the bake saw it: keep the sun, drop the ambient
112
123
  }
113
- floor.material.lightMapIntensity = 1.2; // plain three.js, yours
124
+ floor.material.lightMapIntensity = 1.2; // plain three.js, yours
114
125
  ```
115
- - What is baked: sky and bounced light, by rays traced from every lightmap texel through the static meshes, so light stops at walls and a pillar shades what stands behind it. The sun stays real-time where it lands, so moving things keep their shadows, and its bounce is in the map. The game's hemisphere or ambient light is the sky during the bake, at the same strength: an open floor comes out as bright as under that light.
116
- - Turning the ambient off: a line that sets `intensity` once is lost if picture code writes it every frame, as the template's `picture/lights.js` does. So hide the light (`visible = false`, which that code leaves alone) or change it where it is written. Do it behind a URL flag as above, not in the palette: with the ambient gone for good, the next bake sees no sky. A bake that sees no light at all stops and writes nothing.
126
+ - Baked: sky and bounced light, by rays from every texel through the static meshes (walls stop light, a pillar shades what is behind it). The sun stays real-time, so moving things keep their shadows; its bounce is in the map. The game's hemisphere or ambient light is the sky during the bake, at the same strength.
127
+ - Turning the ambient off: picture code that writes `intensity` every frame (the template's `picture/lights.js`) undoes a one-off write, so hide the light (`visible = false`) behind a URL flag as above, never in the palette (the next bake would see no sky; a bake that sees no light writes nothing).
117
128
  - Instanced and skinned meshes and anything moving cannot hold a lightmap: give them `engine.bakeProbes`. A grid also lights the baked meshes, so where the two overlap the light doubles; keep the grid's `bounds` to where the moving things go, or turn `lightMapIntensity` down.
118
- - Files are large: half precision, 8 MB at 1024, 32 MB at 2048, before the server's compression. Start small.
129
+ - Files are large (half precision): 8 MB at 1024, 32 MB at 2048 before compression. Start small.
119
130
  - Check it: `engine.describe().render.lightmap` lists `skipped` (instanced), `missing` (not found, or changed since the bake: bake again), `moved`, `doubled` (ambient light or a grid on top) and `shared` (an unbaked mesh on a baked material: give it its own).
120
131
  - WebGPU and TSL: nothing changes. `material.lightMap` is read by node materials too, so there is no separate form.
121
132
 
122
133
  ## Real-time bounced light (WebGPU games only)
123
134
 
124
- Bake first when the scene holds still: probes and lightmaps match it and cost nearly nothing. Real-time bounce is for light that changes while the world stands: a sun that moves, a lamp the player carries, a door that lets a room fill. It needs `renderer: 'webgpu'` chosen when the game starts, and three's real WebGPU backend; there is no WebGL version.
135
+ Bake first when the scene holds still (probes and lightmaps cost nearly nothing). Real-time bounce is for light that changes while the world stands (moving sun, carried lamp, opening door). WebGPU only (table below).
125
136
 
126
137
  ```js fragment
127
138
  import { voxelGI, temporalAA } from '@threedog/post-effects/tsl';
128
139
  engine.post.add(voxelGI({ bounds: new THREE.Box3(min, max), intensity: 1 }));
129
- engine.post.add(temporalAA()); // clears the dots; it replaces MSAA while it is on
140
+ engine.post.add(temporalAA()); // clears the dots; it replaces MSAA while it is on
130
141
  ```
131
142
 
132
- - `bounds` is the world box to voxelize. Keep it tight: the same voxels spread over a town are too coarse for a room. `describe().render.post` gives `voxelSize`; judge it against the smallest thing that should throw color.
133
- - Lights can move every frame. Geometry cannot: moving things go outside the volume (`setup: gi => gi.volume.layers...`), and a rare change (a wall falls) calls `gi.needsUpdate = true`, a stall of many milliseconds.
134
- - It bounces direct light only, so sky light stays yours: a low hemisphere or environment light, judged by eye once the bounce is on. How to judge: a colored wall should tint what stands next to it, and a sunlit floor should lift the ceiling, without the shadows turning flat. A cartoon look may want one soft bounce; a realistic interior wants more with less fill.
135
- - Changing any post effect (add, remove, on / off, a setting that rebuilds) rebuilds the chain, and that voxelizes the scene again: a stall. Set the chain at a scene change, not during play.
136
- - `occlusion` (0 to 1) darkens corners from the voxels. It darkens direct light too, which is why it starts at 0.
137
- - It costs real frame time on weak GPUs, so it declares `skipOnLowTier` and is held off on `engine.tier === 'low'`. It is also held on a device that fell back from WebGPU and under `forceWebGL: true`. Nothing breaks, `describe().render.post` says `held` and why, so give those players probes or a lightmap as the base.
138
- - Does not work: metal gets a diffuse bounce instead of a reflection; anything moving is not in the bounce; transparent things are not handled; one volume does not cover a big open world.
143
+ - `bounds` is the world box to voxelize. Keep it tight: the same voxels over a town are too coarse for a room. `describe().render.post` gives `voxelSize`; judge it against the smallest thing that should throw color.
144
+ - Lights can move every frame. Geometry cannot: moving things go outside the volume (`setup: gi => gi.volume.layers...`), and a rare change (a wall falls) calls `gi.needsUpdate = true`, a stall.
145
+ - It bounces direct light only; sky light stays yours (a low hemisphere or environment light). Judge: a colored wall tints what stands next to it and a sunlit floor lifts the ceiling, shadows not flat.
146
+ - A chain change at or before it (add, remove, on / off, a rebuilding setting, MSAA, a new scene buffer) voxelizes again, a stall: set the chain at a scene change. Effects after it (vignette, grain) switch freely.
147
+ - `occlusion` (0 to 1) darkens corners, direct light too, so it starts at 0.
148
+ - Where it is held (table below), give those players probes or a lightmap.
149
+ - Does not work: metal bounces as diffuse; moving and transparent things are not in the bounce; one volume cannot cover a big open world.
139
150
 
140
- What runs where, for `voxelGI` and the three effects around it (`temporalAA`, and `sunShafts` and `lightVolumes` of the next section). Held means the game's `enabled` stays as written, the effect costs nothing, and `describe().render.post` says why:
151
+ What runs where (held: the game's `enabled` stays, the effect costs nothing, `describe().render.post` says why):
141
152
 
142
- | Case | voxelGI | temporalAA, sunShafts, lightVolumes |
153
+ | Case | voxelGI | reflections (held on 'low'), temporalAA, sunShafts, lightVolumes, autoExposure |
143
154
  |---|---|---|
144
155
  | Real WebGPU | runs (held on `engine.tier` 'low') | run |
145
- | WebGL2 backend (no WebGPU in the browser, or `forceWebGL: true`) | held | run |
146
- | Fell back to `WebGLRenderer` (`start()` found no WebGPU) | held | held |
156
+ | WebGL2 backend (no WebGPU or `forceWebGL: true`) | held | run |
157
+ | Fell back to `WebGLRenderer` | held | held |
147
158
  | Game chose WebGL (`--webgl`, `WebGLRenderer`) | throws by name | throw by name |
148
159
 
149
- ## Light you can see in the air
160
+ ## Reflections
161
+
162
+ Screen-space (three's `SSRNode`): only what is on screen, elsewhere the environment map.
163
+
164
+ ```js fragment
165
+ import { reflections } from '@threedog/post-effects/tsl';
166
+ const shine = engine.post.add(reflections({ maxDistance: 5 }));
167
+ shine.set({ intensity: 0.8 }); // in place
168
+ ```
169
+
170
+ - It follows metalness (0 and Lambert: none), not base color; roughness blurs it; a wet road wants a little metalness.
171
+ - Known limits: where a ray hits, the environment's specular stays and the reflection adds on top (indoors lower the mirror's `envMapIntensity`, under open sky `intensity`, until a dark thing on it reads dark). Added after fog, a far wet road shows through thick fog: lower `intensity` or `maxDistance`.
172
+ - Cost: a screen-filling mirror at 1080p on an integrated GPU: +2.9 ms at the default `resolutionScale: 0.5`, +12.5 at 1 (sharp). It grows with pixels (pixel ratio too), `maxDistance` and `quality`.
173
+
174
+ ## Light you can see in the air: a beam of daylight through a hole or window, sun shafts, lamp cones
150
175
 
151
- Pick by the light. These two are WebGPU only; a WebGL game keeps the depth haze of recipe 59.
176
+ Pick by cost and by what must cut the light. All three need WebGPURenderer; a game on `WebGLRenderer` keeps the depth haze of recipe 59.
177
+
178
+ | Want | Use | Cost |
179
+ |---|---|---|
180
+ | One beam you place: a ceiling hole, window, stage light, lighthouse, torch | `lightShaft(engine, …)` from `threedog/tsl`, a mesh | one transparent draw; any tier |
181
+ | Sun through every gap, cut by what stands in it | `sunShafts` (post effect) | high |
182
+ | Spot cones and point glows with shadows, in a box of air | `lightVolumes` (post effect) | high |
183
+
184
+ ```js fragment
185
+ import { lightShaft } from 'threedog/tsl';
186
+ const beam = lightShaft(engine, { radiusTop: 0.6, radiusBottom: 1.1, length: 5, color: 0xfff0d0, intensity: 0.5, dust: 0.6 });
187
+ beam.position.set(2, 5, -3); // the opening (top) at the hole; it points down its -Y axis
188
+ engine.scene.add(beam);
189
+ beam.shaft.intensity.value = 0.3; // numbers live (`beam.shaft.*.value`); size and segments are fixed, make a new one
190
+ // lightShaft(engine, { light: spot }) follows a SpotLight (position, aim, cone width, colour) or a DirectionalLight (aim, colour)
191
+ ```
192
+
193
+ - An additive cone, not a volume (fades: `softness`, `fadeAtGeometry`, `fadeNear`; api/tools.md). **What stands in it does not cut it** (that is `sunShafts`).
194
+ - Start `intensity` low (0.2 to 0.5 over a dark cave) and raise it until the beam reads; with `bloom` it wants less. `dust` is skipped on `engine.tier` 'low'; floating motes are particles (recipe 64).
152
195
 
153
196
  ```js fragment
154
197
  import { sunShafts, lightVolumes } from '@threedog/post-effects/tsl';
155
- engine.post.add(sunShafts({ light: engine.lights.sun })); // sun through gaps
156
- engine.post.add(lightVolumes({ bounds: new THREE.Box3(min, max) })); // spot cones, point glows
198
+ engine.post.add(sunShafts({ light: engine.lights.sun })); // sun through gaps
199
+ engine.post.add(lightVolumes({ bounds: new THREE.Box3(min, max) })); // spot cones, point glows
200
+ ```
201
+
202
+ - `sunShafts` (three's `GodraysNode`) marches the sun's shadow map, so the sun and whatever makes the gaps must cast shadows. Made for air mostly in shadow (a room with a window, a forest); open daylight reads as haze, so lower `density`. Raise it until the beam reads against the dark, before the far wall washes out.
203
+ - `lightVolumes` (three's `VolumeNodeMaterial`) fills a box of air and lights it from point and spot lights, shadows included. **The sun does nothing here**, three skips lights at infinity. It is dithered, so run `temporalAA` after it. `scattering: (tsl, { positionRay, density }) => ...` gives density per point for smoke or ground fog; times `uWeatherFog` (recipe 62) to follow the weather.
204
+ - Does not work: shafts from more than one light at once, cones through transparent glass. For crisp beams in open air, aim a spot light along the sun under `lightVolumes`.
205
+
206
+ ## Soft shadows, area lights, translucency, lens flare
207
+
208
+ ```js fragment
209
+ import { pcss } from 'threedog/tsl';
210
+ const sun = new THREE.DirectionalLight(0xffffff, 3);
211
+ sun.shadow.filterNode = pcss({ lightSize: 0.04, samples: 16 }); // before the first frame, as any filterNode
157
212
  ```
158
213
 
159
- - `sunShafts` (three's `GodraysNode`) marches the sun's shadow map, so the sun and whatever makes the gaps must cast shadows. It is made for air that is mostly in shadow: a room with a window, a forest. In open daylight every pixel of air is lit and it reads as haze; there, lower `density` or leave it out. Raise `density` until the beam reads against the dark behind it, and stop before the far wall washes out. A misty horror game and a clean sunny one will end far apart.
160
- - `lightVolumes` (three's `VolumeNodeMaterial`) fills a box of air and lights it from point and spot lights, shadows included. **The sun does nothing here**, three skips lights at infinity. It is dithered, so run `temporalAA` after it. `scattering: (tsl, { positionRay, density }) => ...` gives density per point for smoke or ground fog; multiply by `uniforms(engine).uWeatherFog` from `threedog/tsl` to follow the weather.
161
- - Does not work: shafts from more than one light at once, cones through transparent glass, and either effect on WebGLRenderer (`engine.post.add` throws by name there). If you need crisp sun beams in open air, a spot light aimed along the sun with `lightVolumes` gives a shaft you can place by hand.
214
+ - `pcss` (WebGPU, DirectionalLight, cascades included): the edge widens with the caster-receiver distance, by `lightSize` per world unit (the sun about 0.01) up to `maxDistance`. About ten times PCF's lookups at `samples: 16`. The caster distance is found at four depths, jittered per pixel: a sloped caster's edge widens smoothly, with a fine static grain in wide edges.
215
+ - `RectAreaLight`: just add it, the engine loads three's tables for it on both renderers. No shadow; lights only MeshStandard / MeshPhysical.
216
+ - Light through skin, leaves, wax: three's `MeshSSSNodeMaterial` (`thicknessColorNode` ...), cheap, per light; three's `SSSNode` is screen-space shadows, not this. Glass, jade, liquid: `transmission` + `thickness` + `attenuationColor` on MeshPhysicalMaterial.
217
+ - Lens flare: three's `LensflareNode` (`three/addons/tsl/display/`) fed by `ctx.display.bloom` in a post effect of your own (recipe 52), or `LensflareMesh` on a light.
162
218
 
163
219
  ## Occlusion culling
164
220
 
165
- `engine.occlusion.enabled = true` skips the engine's big things while something hides them: hlod cells and `engine.batching` groups. Works on both renderers. Ordinary objects are not watched. Turn it on only when heavy things stand behind others (a walled town, a building full of rooms). In a scene of many small things it is a loss: each box costs CPU, more so on WebGPU. Measure with `describe().render.occlusion` (`hidden`, `trianglesSkipped`) and the frame time, on and off.
221
+ `engine.occlusion.enabled = true` skips the engine's big things while something hides them: hlod cells and `engine.batching` groups. Works on both renderers. Ordinary objects are not watched. Only for heavy things behind others (a walled town, a building of rooms); with many small things it is a loss (each box costs CPU, more on WebGPU). Measure with `describe().render.occlusion` (`hidden`, `trianglesSkipped`) and frame time, on and off.
166
222
 
167
- - Three things share the word occlusion and are separate: occlusion culling (this section) skips drawing what is hidden; camera occlusion (`cameraOcclusion` of `collision()`, recipe 21) moves the camera so a wall does not stand between it and the player; `voxelGI`'s `occlusion` only darkens corners of its bounced light.
168
- - Culling hides things from `engine.camera` alone. Every other camera (a minimap, a mirror, a security view), shadows, `engine.rays`, a `THREE.Raycaster` of your own and `voxelGI`'s volume see them as ever; `visible` and `layers` stay yours.
169
- - **Step mode hides nothing.** The answers arrive over drawn frames, so under `threedog step` / `engine.step()` (no real frames) `hidden` stays 0 and `inspect perf` counts every draw. Judge occlusion with `threedog resume` and real time, never from a step-mode reading.
170
- - Answers come a few frames late. Camera moves and cuts are covered. A big occluder that moves fast (a falling wall, a gate thrown open) can show a gap of a few frames.
223
+ - Not to be confused with `cameraOcclusion` of `collision()` (recipe 21: walls between camera and player) or `voxelGI`'s `occlusion` (darker corners).
224
+ - Culling hides things from `engine.camera` alone. Every other camera (a minimap, a mirror), shadows, `engine.rays`, a `THREE.Raycaster` of your own and `voxelGI`'s volume see them as ever; `visible` and `layers` stay yours.
225
+ - **Step mode hides nothing**: answers arrive over drawn frames, so under `threedog step` / `engine.step()` `hidden` stays 0 and `inspect perf` counts every draw. Judge occlusion with `threedog resume` and real time.
226
+ - Answers come a few frames late: camera moves and cuts are covered, a big occluder that moves fast (a falling wall) can show a gap for a few frames.
@@ -1,7 +1,9 @@
1
1
  # Making a new picture from a reference picture
2
2
 
3
- **In this recipe**: Example · The loop · What picture code can change, and what it cannot · Steps · Picture check after every shot · Picture questions ·
4
- Guard rails · A fixed scene to judge by
3
+ > **Covers:** matching a reference picture: the loop, the picture check after every shot, a fixed scene to judge by.
4
+ > **Use when:** the look should come close to a given image.
5
+ > **Shortest:** `threedog picture palette ref.png`, then `threedog shot`.
6
+ > **Sections:** The loop every round · What picture code can · Steps · Picture check after every · Picture questions · Guard rails · A fixed scene to
5
7
 
6
8
  ```sh
7
9
  threedog picture palette art/reference/ref.png --n 8 --average # the colors: they go in picture/palette.js
@@ -12,9 +14,8 @@ threedog picture compare art/reference/ref.png .threedog/shots/now.png --out sid
12
14
  No reference picture? Skip the measuring (step 2, `picture palette`, `picture compare` against a reference); judge each shot against DESIGN.md and
13
15
  its "Loved / Not for this game" list, and use the rest: the loop, the picture check after every shot and the picture questions.
14
16
 
15
- For an AI that is given one picture ("make it look like this") and has to turn it into the game's picture. The tools keep the work measurable: `threedog picture palette`
16
- and `picture compare` measure pictures, your game's `picture/` folder holds the result in plain three.js (recipe 62). They never say which colors are right; the taste is
17
- yours. How the `picture/` folder is laid out and which signals it reads are in `62-picture-code.md`; this page is the order of work.
17
+ For turning one given picture ("make it look like this") into the game's picture. `threedog picture palette` and `picture compare` measure; the game's `picture/` folder
18
+ holds the result in plain three.js (recipe 62). They never say which colors are right: the taste is yours. This page is the order of work.
18
19
 
19
20
  ## The loop (every round, in this order)
20
21
  Looping "edit, screenshot, read the image" costs the most tokens and fixes the least. Numbers come first, pictures last.
@@ -27,14 +28,13 @@ Looping "edit, screenshot, read the image" costs the most tokens and fixes the l
27
28
  pixel diff and the picture differences. Through MCP the `snap` tool is 480 px wide by default; `picture_compare` gives the numbers.
28
29
  4. **Read the numbers first, then at most one image per round.** Name the biggest remaining difference and fix only that. With no reference, read the shot's hints (below). Then look at the image as a player would and judge it
29
30
  against the picture DESIGN.md wants and its "Loved / Not for this game" list (never against a technique example): what would a player read as a
30
- mistake? Typical ones are objects floating or cutting into each other, odd flat discs or blobs (a hard-edged opaque "puddle" reads as a gray ball),
31
- glare, areas too dark or busy to read, placeholder-looking shapes; these are prompts, not a list to tick. Fix what you find, or note it in
31
+ mistake (objects floating or cutting into each other, odd flat discs, glare, areas too dark or busy to read, placeholder shapes)? Fix what you find, or note it in
32
32
  STATUS.md with why it stays. Before calling a picture done, go through the "Picture questions" below that matter for this game.
33
33
  5. **Wrong in a way the numbers do not explain?** Diagnose before guessing: `engine.debug.view('albedo' | 'lighting' | 'shadow' | 'normals')` shows which
34
34
  layer is off, and every value has one writer, a line in your `picture/` code. Nothing drawn: `threedog scene --hidden` (reasons per mesh).
35
35
  Washed-out or too-dark textures, odd normals: `threedog inspect materials` (wrong color spaces first, sizes, who made each material).
36
36
  6. **If the biggest difference stops shrinking over a few rounds, change approach** (in this order) and tell the user which and why:
37
- painted textures (`map`, `normalMap`) -> `onBeforeCompile` on your own material -> your own `ShaderMaterial`.
37
+ painted textures (`map`, `normalMap`) -> node inputs (`colorNode` ...) on your own node material (WebGPU, recipe 56; on WebGL `onBeforeCompile`) -> a whole shader of your own (TSL, or `ShaderMaterial` on WebGL).
38
38
  Never call it "close" to stop tuning.
39
39
  7. **Every few rounds show the user the shot and the numbers.**
40
40
 
@@ -1,11 +1,16 @@
1
1
  # Ground color and plants
2
2
 
3
+ > **Covers:** ground colors by height and slope, plants and their wind.
4
+ > **Use when:** coloring terrain or covering it with plants.
5
+ > **Shortest:** `terrain({ colors: { grass: 0x6a8a3a } })`.
6
+ > **Sections:** Ground color terrain { · Plants and wind
7
+
3
8
  ```js
4
9
  import { terrainPreset } from '@threedog/terrain-noise';
5
10
  engine.use(terrain({ ...terrainPreset(), colors: { grass: 0x6a8a3a, rock: 0x777066 }, biomeColors: { meadow: ['grass'], cliff: ['rock'] } }));
6
- engine.terrain.material.flatShading = true; // the ground's picture is a plain three.js material
7
- engine.terrain.recolor({ colors: { grass: 0xa8a050, rock: 0x777066 } }); // what the workers baked in, changed at run time
8
- engine.terrain.material = applyEffects(new THREE.MeshToonMaterial({ vertexColors: true }), { patches: engine.terrain.patches }); // your own, effects kept
11
+ engine.terrain.material.flatShading = true; // the ground's picture is a plain three.js material
12
+ engine.terrain.recolor({ colors: { grass: 0xa8a050, rock: 0x777066 } }); // what the workers baked in, changed at run time
13
+ engine.terrain.material = applyEffects(new THREE.MeshToonMaterial({ vertexColors: true }), { patches: engine.terrain.patches }); // your own, effects kept
9
14
  engine.vegetation.material = applyEffects(new THREE.MeshToonMaterial({ vertexColors: true }), { patches: engine.vegetation.patches });
10
15
  ```
11
16
 
@@ -19,9 +24,9 @@ color is neutral gray. The `variation` defaults are shown (plain data, so it tra
19
24
  ```js fragment
20
25
  terrain({ colors: { ... }, biomeColors: { ... },
21
26
  variation: {
22
- blend: { size: 33, strength: 1 }, // wavelength in m of the two-color noise; strength > 1 = harder contrast, < 1 = flatter
23
- jitter: { size: 0.33, min: 0.92, range: 0.12 }, // grain cell in m; darkest multiplier; how much brighter it can get (0 range = no grain)
24
- patches: { size: 90, strength: 0.15, levels: 0, tint: 0xb59a5a }, // optional (example values): a second, large layer of color blocks
27
+ blend: { size: 33, strength: 1 }, // wavelength in m of the two-color noise; strength > 1 = harder contrast, < 1 = flatter
28
+ jitter: { size: 0.33, min: 0.92, range: 0.12 }, // grain cell in m; darkest multiplier; how much brighter it can get (0 range = no grain)
29
+ patches: { size: 90, strength: 0.15, levels: 0, tint: 0xb59a5a }, // optional (example values): a second, large layer of color blocks
25
30
  } })
26
31
  ```
27
32
  `patches` is off unless given. It is a noise much larger than `blend`; `levels: 4` snaps it to 4 flat steps (hard-edged color blocks instead of a
@@ -31,8 +36,8 @@ interpolate across a chunk cell (4 m at the default resolution), so blocks small
31
36
 
32
37
  ### Changing it at run time: `engine.terrain.recolor`
33
38
  ```js fragment
34
- engine.terrain.recolor({ colors, biomeColors, steep, variation, shading, normals }); // every chunk is rebuilt; edits stay, collision does not change
35
- engine.terrain.recolor({ detail: { noise: 'paper', strength: 0.2 } }); // only the material: no chunk is rebuilt
39
+ engine.terrain.recolor({ colors, biomeColors, steep, variation, shading, normals }); // every chunk is rebuilt; edits stay, collision does not change
40
+ engine.terrain.recolor({ detail: { noise: 'paper', strength: 0.2 } }); // only the material: no chunk is rebuilt
36
41
  ```
37
42
  Each value is given whole, not merged, and `null` takes it out (`shading: null` goes back to what `terrain({...})` was given). Keys left out stay.
38
43
  `recolor` throws under a picture that replaced `'terrain-draw'`, which draws the ground its own way.
@@ -48,7 +53,7 @@ Chunk geometry has `position`, `normal`, `color` and `uv = world xz / chunk size
48
53
  UVs (steep sides stretch a top-down map), project from the world position in a patch instead (`needs.patches: ['world']` gives `vThreedogWorld`):
49
54
  ```js fragment
50
55
  engine.terrain.material = applyEffects(new THREE.MeshLambertMaterial({ vertexColors: true }), { clouds: false, patches: [{
51
- name: 'triplanar', needs: { patches: ['world'] }, uniforms: { uTex: { value: groundTexture }, uTexScale: { value: 0.1 } }, // groundTexture: repeat wrapping
56
+ name: 'triplanar', needs: { patches: ['world'] }, uniforms: { uTex: { value: groundTexture }, uTexScale: { value: 0.1 } }, // groundTexture: repeat wrapping
52
57
  glsl: { fragment: { pars: 'uniform sampler2D uTex; uniform float uTexScale;',
53
58
  color_fragment: `vec3 n = abs(normalize(cross(dFdx(vThreedogWorld), dFdy(vThreedogWorld)))); n /= n.x + n.y + n.z;
54
59
  diffuseColor.rgb *= texture2D(uTex, vThreedogWorld.zy * uTexScale).rgb * n.x + texture2D(uTex, vThreedogWorld.xz * uTexScale).rgb * n.y
@@ -64,15 +69,14 @@ The lighter alternative, with no material of your own: `terrain({ detail })`, or
64
69
  `vegetation.define` works at any time after `engine.use`, before or after `content.load` and `engine.start`. A species named by a model (`model: 'oak'`) appears when its promise settles, so `vegetation.list()` right after
65
70
  that call does not show it yet. To keep plants off a road or a yard, give the species a `densityMap: (x, z) => 0..1`, or a ground type of its own that the species' `biomes` leave out. Per-species options are in `../api/vegetation.md`; `castShadow` defaults to not `nearOnly`.
66
71
  ```js fragment
67
- engine.vegetation.define('oak', { model: await engine.assets.model('oak'), wind: 0.02 }); // per species: its own material, wind, fade
72
+ engine.vegetation.define('oak', { model: await engine.assets.model('oak'), wind: 0.02 }); // per species: its own material, wind, fade
68
73
  engine.vegetation.define('fern', { geometry, material: new THREE.MeshToonMaterial({ vertexColors: true }), wind: 0.08 });
69
- engine.vegetation.material = applyEffects(new THREE.MeshToonMaterial({ vertexColors: true }), { patches: engine.vegetation.patches }); // the shared default
70
- engine.uniforms.uWindAmp.value = 0.5; engine.uniforms.uWindFreq.value = 2; // how hard and how fast: plain signals, live (uWindAmp 0 = plants stand still)
74
+ engine.vegetation.material = applyEffects(new THREE.MeshToonMaterial({ vertexColors: true }), { patches: engine.vegetation.patches }); // the shared default
75
+ engine.uniforms.uWindAmp.value = 0.5; engine.uniforms.uWindFreq.value = 2; // how hard and how fast: plain signals, live (uWindAmp 0 = plants stand still)
71
76
  ```
72
- `engine.vegetation.material` is what every species with no material or model of its own draws. Set it and it is drawn as given, on plants already
73
- planted too: nothing is added behind it, so hand it `engine.vegetation.patches` (season tint, sway at one amplitude, the `color()` code) to keep those.
74
- `null` gives the neutral default back. A species' own amplitude and near fade need a material of its own: `define(name, { material })` adds wind, cloud
75
- shadows, season tint and the fade to it unless `effects: false`. Each species' live material is `engine.vegetationDraw.kind(name).material`.
77
+ `engine.vegetation.material` (species with no material or model of their own) is drawn as given, planted ones too: hand it `engine.vegetation.patches`
78
+ to keep the season tint, sway and `color()` code; `null` restores the default. A species' own amplitude and near fade need `define(name, { material })`,
79
+ which gets wind, cloud shadows, season tint and the fade unless `effects: false`; its live material is `engine.vegetationDraw.kind(name).material`.
76
80
 
77
81
  The placement, rings and instancing are mechanism and stay (the whole picture is replaceable: recipe 28 section 6). The picture has three entries:
78
82
  - **Sway shape**: built in, two sines with a phase from each plant's origin, weighted by height, leaning with wind strength. `engine.vegetation.sway(glsl)` replaces it (below).
@@ -80,7 +84,7 @@ The placement, rings and instancing are mechanism and stay (the whole picture is
80
84
  - **Season tint**: `engine.sky.seasonTints = { mode: 'multiply' | 'mix', strength, autumn: { foliage: 0xffb070, ground: 0xc8a060 } }`, plain data read every frame, blended to the next season over the last fifth of a season. `'multiply'` (default) multiplies the surface; `'mix'` moves it `strength` (default 0.5) of the way to the color, so orange on green leaves stays orange instead of turning muddy.
81
85
 
82
86
  ```js
83
- engine.vegetation.sway({ uniforms: { uSteps: 3 }, // stepped sway: plants snap between 3 poses instead of a smooth sine
87
+ engine.vegetation.sway({ uniforms: { uSteps: 3 }, // stepped sway: plants snap between 3 poses instead of a smooth sine
84
88
  glsl: `void threedogWind(inout vec3 transformed, vec3 ip, vec3 position){
85
89
  float s = floor(sin(uTime * uWindFreq + ip.x * 0.3 + ip.z * 0.2) * uSteps) / uSteps;
86
90
  transformed.x += s * max(position.y, 0.0) * THREEDOG_WIND_AMP * uWind;
@@ -92,11 +96,13 @@ engine.vegetation.sway({ uniforms: { uSteps: 3 }, // stepped sway: plants sna
92
96
  `sway(null)` gives the built-in sway back. A shared material the game set keeps what it was built with: apply the new `engine.vegetation.patches` to it. The same object works in code:
93
97
  `applyEffects(mat, { wind: { amplitude: 0.03, glsl, uniforms } })`.
94
98
 
95
- Two entries, two scopes: `sway()` is the default shape for all plants, and `vegetation.define(name, { wind: { amplitude, glsl, tsl, uniforms } })` is one species' own
96
- sway. When both are set the species' own wins, and `sway()` and `sway(null)` leave it as it is. Use one `sway()` for the world and a `wind` object for the plant that moves differently.
99
+ `sway()` is the world's default shape; one species' own `define(name, { wind: { amplitude, glsl, tsl, uniforms } })` wins over it, and `sway()` / `sway(null)` leave that one as it is.
100
+
101
+ Grass costs vertex count and fill, not sway: lower `rule.perChunk` or `maxRing`, or use `nearOnly`.
102
+ Grass has no blade-shape setting: give `vegetation.define` your own `geometry` or `model`.
97
103
 
98
- The sway function is not where grass time goes (vertex count and fill are): reduce grass cost with `rule.perChunk`, `maxRing` and `nearOnly`, not the wind.
99
- Grass has no billboard or blade-shape setting: give `vegetation.define` your own `geometry` or `model`.
104
+ ### Far trees as cards: `impostor`
105
+ `define('pine', { model, impostor: true })` (or `{ views, size }`, default 8 x 128 px), instead of `lodGeometry`: beyond `lodRing` each plant is a camera-facing card baked from its own model and materials, lit through baked normals, one draw per species. No shadow or sway there. WebGPU only (WebGL draws the mesh and warns).
100
106
 
101
107
  ### Near-only plants fade out by distance
102
108
  Any `nearOnly` species (grass, flowers, pebbles, twigs, snow tufts, debris ...) is placed per chunk ring
@@ -1,8 +1,9 @@
1
1
  # Scene: what is in the world, where, who manages it, and what a save keeps (engine.thing)
2
2
 
3
- **In this recipe**: 1. Two doors into one scene · 2. What goes in content, what stays three.js · 3. Which state a save keeps · 4. Give it an id ·
4
- 4b. Change it: thing.set / thing.remove · 4c. Saves: the scene part · 5. Moving from three.js to a template · 6. Verify and dev checks ·
5
- 7. Why is this mesh this colour? · 8. When to write plain three.js directly · 9. One id, everything: explain() and the three kinds of change
3
+ > **Covers:** the scene: content and code as two doors, ids, what a save keeps, explain.
4
+ > **Use when:** deciding where an object is written and what persists.
5
+ > **Shortest:** `engine.add(mesh, { id: 'mill' })`.
6
+ > **Sections:** 1 Two doors into · 2 What goes in · 3 Which state a · 4 Give it an · 4b Change it thing.set · 4c Saves the scene · 5 Moving from three.js · 6 Verify and dev · 7 Why is this · 8 When to write · 9 One id, everything
6
7
 
7
8
  The engine's three outward concepts are **Scene** (what stands in the world, where it is, how you interact with it), **Assets** (models, textures,
8
9
  sounds, fonts: `05-props-bake.md` §3b) and **Picture** (how it looks: `09-materials-lights-models.md`). Content packs belong to Scene: they are the data form of it.
@@ -21,17 +22,7 @@ A scene object comes in either of two ways, and both end up in the same scene:
21
22
  - **A template.** Define it in `content/templates.js`, place it in `content/props.js` with an `id`, or create it during play with
22
23
  `engine.content.spawn(name, at)`. This is the right way for anything that must be saved, be editable without code, or exist in many copies.
23
24
 
24
- The same windmill, both ways:
25
-
26
- ```js fragment
27
- // A. plain three.js: your code builds it on every start
28
- const mill = buildWindmill(); // THREE.Group
29
- mill.position.set(20, 0, -10);
30
- engine.snapToGround(mill);
31
- engine.add(mill, { id: 'mill' });
32
- engine.collision?.addCircle(mill, { radius: 1.3 }); // also pulls the follow camera in; { occluder: false } only stops walkers (forest trunks)
33
- engine.onFrame(dt => { mill.userData.blades.rotation.z += dt * 1.5; });
34
- ```
25
+ The same windmill, both ways. A, plain three.js built on every start: `THREE.md §"Example: a spinning windmill"` (with `engine.add(mill, { id: 'mill' })` for a stable id). B:
35
26
  ```js
36
27
  // B. template: the definition is data; the model is a name in the asset manifest
37
28
  // content/templates.js
@@ -75,15 +66,15 @@ inside an op with `engine.content.spawn(name, at)`: a record is saved whole.
75
66
 
76
67
  ## 4. Give it an id
77
68
  ```js
78
- const windmill = new THREE.Group(); // any Object3D
79
- engine.add(windmill, { id: 'windmill' }); // at setup: thing.set / thing.remove changes to it are saved
80
- engine.add(new THREE.Group()); // effects need no id: obj#7, this session only
69
+ const windmill = new THREE.Group(); // any Object3D
70
+ engine.add(windmill, { id: 'windmill' }); // at setup: thing.set / thing.remove changes to it are saved
71
+ engine.add(new THREE.Group()); // effects need no id: obj#7, this session only
81
72
  engine.thing('windmill');
82
73
  // { id: 'windmill', kind: 'Group', owner: 'game', at: 'main.js:50', phase: 'setup', saved: 'code',
83
74
  // keeps: ['position, rotation, scale, visibility and removal made with thing.set / thing.remove (scene save part)'],
84
75
  // loses: ['geometry and material changes', 'children added later', 'userData', ...], edit: 'added by code at main.js:50 (id ...)' }
85
- engine.thing('windmill').object; // the live Object3D (not enumerable, so the result stays JSON-able)
86
- engine.pick(0, 0)?.thing; // any child resolves to its registered root
76
+ engine.thing('windmill').object; // the live Object3D (not enumerable, so the result stays JSON-able)
77
+ engine.pick(0, 0)?.thing; // any child resolves to its registered root
87
78
  ```
88
79
  - The id is `{ id }`, else a session id `obj#n` (session tier: never saved). `obj.name` is not an id (GLB roots are all called `Scene`): it only helps `engine.thing(name)` find the object. An id is a non-empty string without `#`,
89
80
  unique across `engine.add` objects and world records: a clash throws (`thing-id`) from either side (`engine.add` or `world.add`) and says which one holds it.
@@ -95,10 +86,10 @@ engine.pick(0, 0)?.thing; // any child resolves to its
95
86
 
96
87
  ## 4b. Change it: thing.set / thing.remove (ops, undoable)
97
88
  ```js
98
- const args = { id: 'windmill', position: [5, 0, 2], rotation: 1.2 }; // rotation: a number is yaw, or [x, y, z]; scale: a number or [x, y, z]
89
+ const args = { id: 'windmill', position: [5, 0, 2], rotation: 1.2 }; // rotation: a number is yaw, or [x, y, z]; scale: a number or [x, y, z]
99
90
  const r = engine.ops.run('thing.set', args);
100
- engine.ops.undo('thing.set', args, r.value); // back where it was
101
- const gone = engine.ops.run('thing.remove', { id: 'windmill' }); // detached and kept: undo puts it back
91
+ engine.ops.undo('thing.set', args, r.value); // back where it was
92
+ const gone = engine.ops.run('thing.remove', { id: 'windmill' }); // detached and kept: undo puts it back
102
93
  engine.ops.undo('thing.remove', { id: 'windmill' }, gone.value);
103
94
  ```
104
95
  - A world record id turns into `world.set` / `world.move` (`rot` / `scale` are template instance fields) and `world.remove`; the model follows the
@@ -150,12 +141,12 @@ Plain three.js is always allowed (`engine.scene`, `engine.renderer`, `engine.cam
150
141
  | your own `EffectComposer` / render call to the canvas | the engine yields the frame (`[own-frame]`), so `engine.post` effects, adaptive resolution, photo mode, `describe().render.post`; keep them with `engine.post.add(pass)` instead |
151
142
  | `renderer.toneMappingExposure = x`, `scene.fog = ...` | the debug layer's restore (`engine.debug.override` gives the old value back) |
152
143
 
153
- The engine adds nothing to your materials. The cloud shadow is a signal (`engine.uniforms.uCloudShadow`, `uCloudShadowScale`, `uCloudShadowSpeed`) and a function: `applyEffects(mat)` gives a lit three.js material the engine's term, so it darkens under the drifting clouds like the engine's ground, on WebGL and WebGPU; your own shader calls `threedogCloudShadow(worldPos)` (recipe 43). Clouds dim the sun only (directional lights, every cascade included): a `PointLight` street lamp or a torch is never shaded by them. At 0 a uniform branch skips the cloud noise, and one program per material type stays. Snow and season cover work the same way: `applyEffects(mat, { season: 'ground' })` (`'foliage'` for leaves).
144
+ The engine adds nothing to your materials. The cloud shadow is a signal (`engine.uniforms.uCloudShadow`, `uCloudShadowScale`, `uCloudShadowSpeed`) and a function: `applyEffects(mat)` gives a lit three.js material the engine's term (darkens under the drifting clouds like the engine's ground, on WebGL and WebGPU); your own shader calls `threedogCloudShadow(worldPos)` (recipe 43). Clouds dim the sun only (directional lights, every cascade): a `PointLight` lamp or torch is never shaded. At 0 a uniform branch skips the cloud noise; one program per material type stays. Snow and season cover work the same way: `applyEffects(mat, { season: 'ground' })` (`'foliage'` for leaves).
154
145
  Keep the integrations by going through the engine: `applyEffects(mat, { wind, season, detail, lighting, patches })` on your material, `engine.post.add(pass | { name, fuse: { glsl }, slot })` for a screen effect.
155
146
 
156
147
  ## 9. One id, everything: explain and the three kinds of change
157
148
  ```js
158
- engine.explain({ thing: 'chest-home' }).detail; // CLI: threedog explain thing chest-home --full (MCP: explain); the same JSON
149
+ engine.explain({ thing: 'chest-home' }).detail; // CLI: threedog explain thing chest-home --full (MCP: explain); the same JSON
159
150
  // { id, kind, owner, definition: { at: 'content/props.js:14', template, templateAt, level?, node?, spawned? }, model, materials: [{ role, name, from, keys }],
160
151
  // state, rules: { blocksMovement, pickable, interact, height }, ops: [{ op, desc, args }], saved: { tier, keeps, loses }, change: {…}, overrides? }
161
152
  ```
@@ -170,11 +161,11 @@ engine.explain({ thing: 'chest-home' }).detail; // CLI: threedog explain thin
170
161
  | Diagnostic override ("show me without it") | `engine.debug.override(owner, id, { visible: false, material: 'flat' \| 'wire', apply })` | until `handle.remove()` / `engine.debug.clear(owner)`; never saved |
171
162
 
172
163
  ```js
173
- const h = engine.debug.override('ai-session', 'windmill', { material: 'flat' }); // unlit base colour: is the colour wrong, or the light?
164
+ const h = engine.debug.override('ai-session', 'windmill', { material: 'flat' }); // unlit base colour: is the colour wrong, or the light?
174
165
  engine.debug.override('ai-session', engine.player.root, { visible: false });
175
- engine.debug.override('ai-session', engine.renderer, 'toneMappingExposure', 3); // any three.js value: (object, key, value); held above picture code until remove()
176
- engine.describe().scene.overrides; // [{ owner, target, material: 'flat' }, …]: the screen differs from the real state while this is non-empty
177
- h.remove(); engine.debug.clear('ai-session'); // clear removes every override of that owner (and its debug.view) and nothing else
166
+ engine.debug.override('ai-session', engine.renderer, 'toneMappingExposure', 3); // any three.js value: (object, key, value); held above picture code until remove()
167
+ engine.describe().scene.overrides; // [{ owner, target, material: 'flat' }, …]: the screen differs from the real state while this is non-empty
168
+ h.remove(); engine.debug.clear('ai-session'); // clear removes every override of that owner (and its debug.view) and nothing else
178
169
  ```
179
170
  `apply(obj)` may return its undo function: any other picture (a view mode) uses the same owner mechanism. Overrides do not touch game state, ops or saves.
180
171