threedog 0.8.0 → 1.0.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 (372) hide show
  1. package/CHANGELOG.md +219 -4
  2. package/README.md +6 -6
  3. package/core/assets/Animator.js +2 -0
  4. package/core/assets/Assets.js +44 -13
  5. package/core/assets/assetEntry.js +87 -22
  6. package/core/assets/assetHot.js +2 -1
  7. package/core/assets/assetReport.js +1 -2
  8. package/core/audio/Audio.js +24 -5
  9. package/core/base/I18n.js +6 -3
  10. package/core/base/Random.js +3 -1
  11. package/core/base/Vars.js +14 -4
  12. package/core/base/errorCodes.js +54 -16
  13. package/core/base/errorHints.js +12 -1
  14. package/core/base/errors.js +6 -4
  15. package/core/base/events.generated.js +10 -0
  16. package/core/base/follows.js +26 -0
  17. package/core/base/math.js +15 -8
  18. package/core/base/params.js +2 -2
  19. package/core/{saves → base}/saveValues.js +24 -6
  20. package/core/base/sections.js +97 -0
  21. package/core/base/spelling.js +32 -0
  22. package/core/base/validate.js +8 -29
  23. package/core/engine/Engine.js +61 -18
  24. package/core/engine/Loading.js +30 -3
  25. package/core/engine/copies.js +1 -1
  26. package/core/engine/headlessLoad.js +30 -13
  27. package/core/engine/lifecycle.js +30 -25
  28. package/core/engine/loop.js +22 -4
  29. package/core/engine/moduleSlots.js +91 -15
  30. package/core/engine/moduleTypes.js +13 -0
  31. package/core/engine/modules.js +248 -62
  32. package/core/engine/page.js +25 -8
  33. package/core/engine/plugins.js +15 -3
  34. package/core/engine/services.js +3 -0
  35. package/core/engine/startup.js +46 -36
  36. package/core/input/Input.js +39 -19
  37. package/core/input/inputKeyboard.js +39 -0
  38. package/core/input/inputPad.js +23 -2
  39. package/core/input/inputPointer.js +3 -1
  40. package/core/input/inputSeat.js +66 -0
  41. package/core/input/inputTouch.js +23 -6
  42. package/core/inspect/DebugOverrides.js +13 -2
  43. package/core/inspect/Describe.js +10 -6
  44. package/core/inspect/Inspect.js +31 -4
  45. package/core/inspect/UrlState.js +14 -10
  46. package/core/inspect/catalog.js +12 -5
  47. package/core/inspect/describeRender.js +3 -2
  48. package/core/inspect/describeText.js +6 -2
  49. package/core/inspect/metadata.generated.js +4140 -0
  50. package/core/inspect/pictureWriters.js +117 -33
  51. package/core/inspect/toolDoor.js +21 -0
  52. package/core/inspect/valueHistory.js +35 -0
  53. package/core/ops/Ops.js +32 -7
  54. package/core/ops/control.js +48 -23
  55. package/core/ops/holds.js +4 -3
  56. package/core/ops/opsAtomic.js +18 -6
  57. package/core/ops/opsCheck.js +7 -5
  58. package/core/ops/opsFail.js +5 -7
  59. package/core/ops/opsRun.js +2 -2
  60. package/core/ops/owned.js +20 -3
  61. package/core/ops/sharedPoint.js +7 -10
  62. package/core/ops/stacks.js +22 -1
  63. package/core/saves/SaveStore.js +52 -26
  64. package/core/saves/Saves.js +122 -27
  65. package/core/saves/saveApply.js +159 -61
  66. package/core/saves/saveFiles.js +30 -25
  67. package/core/saves/saveVersions.js +20 -6
  68. package/core/saves/session.js +76 -33
  69. package/core/saves/stateReplace.js +184 -0
  70. package/core/scene/Rays.js +21 -5
  71. package/core/scene/Views.js +6 -6
  72. package/core/scene/adaptive.js +13 -10
  73. package/core/scene/canvasBox.js +2 -0
  74. package/core/scene/compositeGround.js +72 -0
  75. package/core/scene/floor.js +17 -0
  76. package/core/scene/grid.js +2 -0
  77. package/core/scene/ground.contract.js +14 -0
  78. package/core/scene/ground.js +52 -17
  79. package/core/scene/pixel.js +154 -0
  80. package/core/scene/pixelRatio.js +167 -0
  81. package/core/scene/sceneDelta.js +3 -3
  82. package/core/scene/sceneMethods.js +11 -6
  83. package/core/scene/stepPoses.js +6 -1
  84. package/core/scene/thingExplain.js +1 -1
  85. package/core/scene/thingOps.js +22 -14
  86. package/core/scene/things.js +1 -1
  87. package/core/scene/tier.js +10 -0
  88. package/core/scene/view.js +126 -9
  89. package/core/stream/Batching.js +0 -1
  90. package/core/stream/Stream.js +24 -12
  91. package/core/stream/batchGroups.js +1 -0
  92. package/core/stream/scatter.js +5 -2
  93. package/core/stream/streamSources.js +2 -1
  94. package/core/threads/Commits.js +12 -7
  95. package/core/threads/Jobs.js +15 -5
  96. package/core/threads/Threads.js +5 -2
  97. package/core/time/Clock.js +3 -1
  98. package/core/time/skip.js +10 -4
  99. package/core/time/time.js +16 -10
  100. package/docs/AI.md +89 -72
  101. package/docs/API.md +18 -14
  102. package/docs/CODEMAP.md +68 -40
  103. package/docs/COMMANDS.md +22 -23
  104. package/docs/CONVENTIONS.md +120 -17
  105. package/docs/MIGRATING-0.8.md +2 -0
  106. package/docs/MIGRATING-1.0.md +101 -0
  107. package/docs/THREE.md +65 -12
  108. package/docs/api/cameraRig.md +3 -0
  109. package/docs/api/characters.md +13 -7
  110. package/docs/api/collider3d.md +9 -0
  111. package/docs/api/content.md +16 -15
  112. package/docs/api/dialogue.md +2 -1
  113. package/docs/api/engine.md +18 -16
  114. package/docs/api/events.md +14 -4
  115. package/docs/api/ground.md +2 -2
  116. package/docs/api/i18n.md +1 -1
  117. package/docs/api/input.md +2 -1
  118. package/docs/api/interactions.md +1 -1
  119. package/docs/api/inventory.md +1 -1
  120. package/docs/api/level.md +3 -2
  121. package/docs/api/nav.md +4 -2
  122. package/docs/api/particles.md +8 -5
  123. package/docs/api/pickups.md +1 -1
  124. package/docs/api/post.md +3 -4
  125. package/docs/api/quests.md +4 -2
  126. package/docs/api/rays.md +2 -0
  127. package/docs/api/rigid.md +3 -2
  128. package/docs/api/saves.md +8 -7
  129. package/docs/api/stream.md +4 -5
  130. package/docs/api/terrain.md +3 -4
  131. package/docs/api/terrainDraw.md +1 -1
  132. package/docs/api/timeline.md +2 -2
  133. package/docs/api/tools.md +3 -1
  134. package/docs/api/triggers.md +2 -0
  135. package/docs/api/vegetationDraw.md +1 -1
  136. package/docs/api/water.md +6 -2
  137. package/docs/api/weather.md +19 -4
  138. package/docs/api/weatherDraw.md +1 -1
  139. package/docs/api/world.md +1 -1
  140. package/docs/recipes/01-new-game.md +3 -3
  141. package/docs/recipes/02-npc.md +3 -4
  142. package/docs/recipes/03-items-pickups.md +11 -11
  143. package/docs/recipes/04-quests.md +2 -0
  144. package/docs/recipes/05-props-bake.md +9 -9
  145. package/docs/recipes/06-clock-events.md +6 -6
  146. package/docs/recipes/07-flow-scenes-pause.md +18 -15
  147. package/docs/recipes/08-weather-sky.md +5 -5
  148. package/docs/recipes/09-materials-lights-models.md +3 -3
  149. package/docs/recipes/10-blender-level.md +16 -4
  150. package/docs/recipes/11-vehicles.md +18 -6
  151. package/docs/recipes/12-navmesh.md +52 -8
  152. package/docs/recipes/13-animation.md +34 -8
  153. package/docs/recipes/14-custom-module.md +20 -8
  154. package/docs/recipes/15-perf.md +4 -4
  155. package/docs/recipes/16-dev-bridge.md +9 -8
  156. package/docs/recipes/18-world.md +13 -5
  157. package/docs/recipes/19-shooting-picking.md +3 -2
  158. package/docs/recipes/20-content-actions-save.md +26 -6
  159. package/docs/recipes/21-camera.md +17 -23
  160. package/docs/recipes/22-shop-gold.md +21 -12
  161. package/docs/recipes/23-ops.md +19 -15
  162. package/docs/recipes/26-ui-parts.md +3 -2
  163. package/docs/recipes/27-net.md +3 -3
  164. package/docs/recipes/28-terrain.md +3 -3
  165. package/docs/recipes/29-grid.md +1 -1
  166. package/docs/recipes/30-templates.md +10 -13
  167. package/docs/recipes/31-audio.md +2 -2
  168. package/docs/recipes/32-action-game.md +6 -5
  169. package/docs/recipes/33-stream-sources.md +4 -1
  170. package/docs/recipes/34-environment-lighting.md +7 -8
  171. package/docs/recipes/35-picture-from-reference.md +13 -9
  172. package/docs/recipes/36-ground-plants.md +3 -2
  173. package/docs/recipes/40-scene.md +11 -10
  174. package/docs/recipes/43-shader-patches-surfaces.md +7 -7
  175. package/docs/recipes/44-water-weather-hooks.md +9 -8
  176. package/docs/recipes/45-cascaded-shadows.md +3 -4
  177. package/docs/recipes/46-blender-art-route.md +3 -3
  178. package/docs/recipes/49-game-module-contract.md +2 -1
  179. package/docs/recipes/50-own-renderer.md +1 -0
  180. package/docs/recipes/51-capability-catalog.md +14 -8
  181. package/docs/recipes/52-around-the-picture.md +4 -4
  182. package/docs/recipes/55-mods-time-wrap.md +5 -4
  183. package/docs/recipes/56-webgpu-tsl.md +12 -1
  184. package/docs/recipes/57-control.md +30 -10
  185. package/docs/recipes/58-input.md +13 -0
  186. package/docs/recipes/60-judge-the-picture.md +1 -1
  187. package/docs/recipes/62-picture-code.md +106 -48
  188. package/docs/recipes/63-third-person-start.md +2 -1
  189. package/docs/recipes/64-particles.md +53 -4
  190. package/docs/recipes/65-swarm.md +2 -2
  191. package/docs/recipes/66-common-tasks.md +313 -0
  192. package/examples/action/.threedog/content-index.json +1 -1
  193. package/examples/action/GAMEMAP.md +3 -3
  194. package/examples/perf-island/.threedog/content-index.json +1 -1
  195. package/examples/perf-island/GAMEMAP.md +3 -3
  196. package/examples/perf-island/main.js +2 -2
  197. package/examples/plain-picture/GAMEMAP.md +3 -1
  198. package/examples/rc2d/GAMEMAP.md +1 -1
  199. package/examples/rc2d/rc2d.js +1 -1
  200. package/examples/styletest/.threedog/content-index.json +1 -1
  201. package/examples/styletest/GAMEMAP.md +3 -3
  202. package/examples/webgpu-tsl/GAMEMAP.md +1 -1
  203. package/examples/world/.threedog/content-index.json +1 -1
  204. package/examples/world/GAMEMAP.md +5 -4
  205. package/examples/world/main.js +3 -3
  206. package/index.d.ts +8 -5
  207. package/index.js +22 -1
  208. package/llms.txt +2 -1
  209. package/modules/ambience/Ambience.js +5 -3
  210. package/modules/calendar/index.js +7 -5
  211. package/modules/camera/FirstPersonCamera.js +3 -3
  212. package/modules/camera/FixedCamera.js +34 -20
  213. package/modules/camera/FollowCamera.js +20 -11
  214. package/modules/camera/RtsCamera.js +1 -0
  215. package/modules/camera/common.js +33 -22
  216. package/modules/camera/pixelSnap.js +62 -0
  217. package/modules/characters/Character.js +136 -43
  218. package/modules/characters/NPC.js +60 -28
  219. package/modules/characters/assetModel.js +2 -2
  220. package/modules/characters/astar.js +47 -28
  221. package/modules/characters/character.contract.js +21 -0
  222. package/modules/characters/contract.js +17 -3
  223. package/modules/characters/index.js +94 -34
  224. package/modules/characters/moveHelpers.js +80 -15
  225. package/modules/characters/mover.contract.js +14 -0
  226. package/modules/characters/movers/common.js +6 -4
  227. package/modules/characters/movers/rapier.js +12 -5
  228. package/modules/characters/movers/simple.js +25 -12
  229. package/modules/characters/movers/support.js +18 -7
  230. package/modules/characters/npcAvoid.js +15 -12
  231. package/modules/characters/npcSim.js +75 -25
  232. package/modules/characters/npcView.js +13 -6
  233. package/modules/characters/pathAsync.js +74 -24
  234. package/modules/characters/pathJob.js +38 -21
  235. package/modules/characters/player.js +59 -47
  236. package/modules/characters/seat.js +56 -0
  237. package/modules/characters/vehicle.contract.js +8 -5
  238. package/modules/characters/walkTo.js +31 -18
  239. package/modules/collision/Collision.js +44 -26
  240. package/modules/collision/contract.js +2 -2
  241. package/modules/collision/grid.js +6 -1
  242. package/modules/content/explain.js +1 -1
  243. package/modules/content/fields.js +3 -3
  244. package/modules/content/ids.js +3 -1
  245. package/modules/content/index.js +83 -27
  246. package/modules/content/loader.js +110 -130
  247. package/modules/content/markers.js +1 -1
  248. package/modules/content/models.js +48 -14
  249. package/modules/content/packs.js +2 -1
  250. package/modules/content/places.js +5 -4
  251. package/modules/content/props.js +8 -6
  252. package/modules/content/rules.js +29 -47
  253. package/modules/content/templates.js +66 -35
  254. package/modules/content/words.js +19 -6
  255. package/modules/debug/DebugPanel.js +4 -2
  256. package/modules/flow/contract.js +1 -0
  257. package/modules/flow/index.js +24 -14
  258. package/modules/gameplay/Container.js +5 -2
  259. package/modules/gameplay/Containers.js +9 -1
  260. package/modules/gameplay/Dialogue.js +82 -25
  261. package/modules/gameplay/Interactions.js +61 -32
  262. package/modules/gameplay/Inventory.js +56 -13
  263. package/modules/gameplay/Quests.js +133 -24
  264. package/modules/gameplay/boxOps.js +7 -0
  265. package/modules/gameplay/dialogueBubbles.js +14 -9
  266. package/modules/gameplay/inventoryOps.js +11 -7
  267. package/modules/gameplay/pickups.js +43 -16
  268. package/modules/gameplay/questLog.js +4 -2
  269. package/modules/gameplay/questSave.js +6 -1
  270. package/modules/gameplay/quests.contract.js +1 -1
  271. package/modules/grid/Grid.js +1 -1
  272. package/modules/grid/Layer.js +8 -4
  273. package/modules/grid/index.js +21 -15
  274. package/modules/grid/ops.js +43 -46
  275. package/modules/grid/tiles.js +1 -1
  276. package/modules/hlod/index.js +6 -3
  277. package/modules/hud/index.js +6 -4
  278. package/modules/hud/parts.js +4 -4
  279. package/modules/level/contract.js +2 -2
  280. package/modules/level/heightfield.js +17 -21
  281. package/modules/level/index.js +83 -26
  282. package/modules/level/load.js +165 -48
  283. package/modules/level/nodes.js +34 -16
  284. package/modules/lights/index.js +6 -3
  285. package/modules/lights/sources.js +3 -1
  286. package/modules/music/Music.js +4 -2
  287. package/modules/nav/contract.js +7 -5
  288. package/modules/nav/index.js +174 -44
  289. package/modules/nav/navPath.js +45 -10
  290. package/modules/net/index.js +1 -1
  291. package/modules/particles/Particles.js +85 -22
  292. package/modules/particles/effect.js +80 -28
  293. package/modules/particles/shaders.js +17 -0
  294. package/modules/photo/Photo.js +12 -10
  295. package/modules/rigid/RigidBodies.js +200 -57
  296. package/modules/rigid/Vehicles.js +15 -5
  297. package/modules/rigid/collider3d.contract.js +26 -0
  298. package/modules/rigid/ragdoll.js +55 -44
  299. package/modules/rigid/ragdollBones.js +83 -33
  300. package/modules/rigid/refresh.js +10 -0
  301. package/modules/rigid/sync.js +46 -15
  302. package/modules/settings/Settings.js +84 -37
  303. package/modules/settings/apply.js +15 -8
  304. package/modules/settings/sections.js +7 -4
  305. package/modules/settings/strings.js +2 -2
  306. package/modules/sky/skyModule.js +3 -1
  307. package/modules/swarm/Swarm.js +16 -6
  308. package/modules/terrain/ChunkManager.js +10 -16
  309. package/modules/terrain/index.js +17 -11
  310. package/modules/terrain/terrainEdit.js +13 -2
  311. package/modules/terrain/terrainGen.js +5 -3
  312. package/modules/terrain/terrainShape.js +1 -1
  313. package/modules/timeline/Timeline.js +58 -26
  314. package/modules/timeline/Tween.js +19 -13
  315. package/modules/timeline/shots.js +19 -10
  316. package/modules/triggers/index.js +87 -20
  317. package/modules/vegetation/Vegetation.js +4 -3
  318. package/modules/vegetation/draw.js +16 -0
  319. package/modules/vegetation/groundChunks.js +10 -7
  320. package/modules/vegetation/index.js +30 -7
  321. package/modules/water/Water.js +6 -2
  322. package/modules/weather/Weather.js +16 -15
  323. package/modules/weather/weatherDraw.js +7 -6
  324. package/modules/world/World.js +20 -7
  325. package/modules/world/explain.js +1 -1
  326. package/modules/world/index.js +13 -6
  327. package/modules/world/persist.js +23 -8
  328. package/modules/world/pos.js +4 -4
  329. package/modules/world/records.js +13 -7
  330. package/modules/world/sim.js +74 -23
  331. package/modules/world/simFar.js +2 -2
  332. package/modules/world/state.js +31 -6
  333. package/modules/world/thingSource.js +16 -3
  334. package/modules/world/views.js +19 -8
  335. package/package.json +7 -1
  336. package/render/PostFX.js +47 -29
  337. package/render/backend.js +5 -1
  338. package/render/fx/particles.tsl.js +8 -6
  339. package/render/fx/postWebGPU.tsl.js +3 -3
  340. package/render/layers.js +1 -1
  341. package/render/lightmap.js +23 -3
  342. package/render/occlusion.js +43 -12
  343. package/render/patches.js +2 -2
  344. package/render/postWebGL.js +4 -3
  345. package/render/probes.js +25 -0
  346. package/render/shadows.js +2 -2
  347. package/types/core.d.ts +142 -55
  348. package/types/gameplay.d.ts +92 -40
  349. package/types/generated/core/base/I18n.d.ts +2 -2
  350. package/types/generated/core/input/Input.d.ts +16 -2
  351. package/types/generated/core/input/inputSeat.d.ts +26 -0
  352. package/types/generated/core/inspect/DebugOverrides.d.ts +15 -1
  353. package/types/generated/core/ops/Ops.d.ts +2 -1
  354. package/types/generated/core/ops/control.d.ts +12 -2
  355. package/types/generated/core/saves/Saves.d.ts +26 -6
  356. package/types/generated/core/saves/session.d.ts +1 -1
  357. package/types/generated/core/scene/Views.d.ts +1 -1
  358. package/types/generated/core/stream/Stream.d.ts +6 -4
  359. package/types/generated/modules/grid/Grid.d.ts +1 -0
  360. package/types/generated/modules/particles/Particles.d.ts +4 -3
  361. package/types/generated/modules/timeline/Timeline.d.ts +5 -4
  362. package/types/generated/modules/weather/Weather.d.ts +1 -7
  363. package/types/generated/modules/world/World.d.ts +6 -4
  364. package/types/generated/render/PostFX.d.ts +6 -14
  365. package/types/nav.d.ts +36 -4
  366. package/types/physics.d.ts +55 -7
  367. package/types/pixel.d.ts +75 -0
  368. package/types/world.d.ts +14 -8
  369. package/ui/Parts.js +9 -2
  370. package/ui/theme.js +2 -2
  371. package/core/scene/engineCamera.js +0 -32
  372. package/modules/camera/projection.js +0 -21
@@ -40,9 +40,7 @@ one line; the detail is here.
40
40
  The opts of `assets.texture(name, opts)` are part of the cache key: the same image with different opts gives two separately configured textures.
41
41
 
42
42
  ## Values the engine writes on its own (camera, shadow box)
43
- Lights, fog, exposure and the environment have one writer, the game's `picture/` code: the sky computes signals and no module writes them (`recipes/62-picture-code.md`). With a camera module the
44
- engine writes the `camera` pose every frame, and a sky keeps the shadow box around the focus. Setting one of those directly is plain three.js and works: the engine yields that value (stops
45
- writing it, warns once). The camera: `engine.takeCamera(owner)` or a timeline camera step.
43
+ Lights, fog, exposure and the environment have one writer, the game's `picture/` code (recipe 62). What the engine writes itself, the camera pose and the shadow box, and how to take it: recipe 52 "Who writes it".
46
44
 
47
45
  ## Layers the engine keeps
48
46
  The three.js layers below belong to the engine (one table: `RESERVED_LAYERS` in `threedog/layers`, file `render/layers.js`). A game's own layers are 1 to 25; 30 is the default camera `hideLayer`.
@@ -51,7 +49,7 @@ The three.js layers below belong to the engine (one table: `RESERVED_LAYERS` in
51
49
  | --- | --- | --- |
52
50
  | 26 | `lightVolumes` | the box of air and the lights `lightVolumes` reads |
53
51
  | 27 | `occlusionBox` | occlusion culling's query boxes, seen by the scene render of the view camera alone |
54
- | 28 | `occlusionHidden` | what culling is not drawing now, still seen by shadows, `engine.rays` and `voxelGI` |
52
+ | 28 | `occlusionHidden` | nothing sits here: culling sets it on shadow cameras, so what it hides still casts |
55
53
  | 29 | `outlineOff` | objects `outline({ offLayer })` leaves without lines; `OUTLINE_OFF_LAYER` from `@threedog/post-effects` is this same layer |
56
54
  | 31 | `batched` | originals drawn through `engine.batching`, still hit by `engine.rays` |
57
55
 
@@ -65,25 +63,25 @@ logic need none of this.
65
63
  | Let several systems change one shared value (speed, time scale, gravity, damage taken): the game sets, effects multiply, settings cap | `engine.mod(point, { owner, set \| add \| mul \| clamp, for })`, in a module `ctx.mod`; `mul` / `add` cooperate, two owners' `set` on one layer is an error with the fix; your own point: `engine.stacks.define` | `recipes/55-mods-time-wrap.md` |
66
64
  | Run code before / after / around a module method (a weight limit on `inventory.add`) | `engine.wrap(engine.inventory, 'add', (next, ...a) => next(...a), { owner })` | `recipes/55-mods-time-wrap.md` |
67
65
  | Close one action for a while (stunned: no jump) | `engine.input.gate(action, { owner, for })` | `recipes/55-mods-time-wrap.md` |
68
- | Replace a whole system (your own inventory, interactions, dialogue, quests, flow, characters, camera, collision, level, navmesh; your own vehicle for `character.enter`) | `engine.use(mine(), { replaces: '<slot>' })` for a part that `provides` that slot; a module (or object) that meets that contract (`<module>.contract.js`; vehicle: `modules/characters/vehicle.contract.js`), checked with `runContract` | `recipes/55-mods-time-wrap.md` "Replacing a module" |
69
- | Change a picture value (light, fog, sky, water, tone, post) | write it in your `picture/` code on the three.js object or the module's `material` (recipe 62); a value the engine drives (camera far, fov, pixel ratio): `engine.autoView.manual(key)` first; a screen effect: `engine.post.add(x)` |
66
+ | Replace a whole system (your own inventory, interactions, dialogue, quests, flow, characters, camera, collision, level; your own vehicle for `character.enter`) | `engine.use(mine(), { replaces: '<slot>' })` for a part that `provides` that slot; a module (or object) that meets that contract (`<module>.contract.js`; vehicle: `modules/characters/vehicle.contract.js`), checked with `runContract` | `recipes/55-mods-time-wrap.md` "Replacing a module" |
67
+ | Change a picture value (light, fog, sky, water, tone, post) | write it in your `picture/` code on the three.js object or the module's `material` (recipe 62); a value the engine drives (camera far, fov, pixel ratio): write it directly, the engine yields; `engine.autoView.manual(key)` is for borrowing one and giving it back; a screen effect: `engine.post.add(x)` |
70
68
  | Write the picture yourself | plain three.js on `engine.scene / camera / renderer` (own material, `ShaderMaterial`, pass); a direct write takes that value over and the engine yields | `THREE.md` |
71
69
 
72
- **What can be replaced**: a slot with a contract file (inventory, interactions, dialogue, quests, flow, characters, calendar, cameraRig, particles, collision, level, nav) lists what a replacement must supply, and `runContract` checks it. The slots below have no contract; a replacement must supply what the engine's own callers read:
70
+ **What can be replaced**: a slot with a contract file (inventory, interactions, dialogue, quests, flow, characters, calendar, cameraRig, particles, collision, level; nav only with a Recast-based implementation, see below) lists what a replacement must supply, and `runContract` checks it. `nav` is narrower than the others: the path search calls Recast's `findPath` and `findStraightPath` on `query` and `getOffMeshConnectionByRef` on `navMesh`, the path worker gives the bytes from `exportMesh` to Recast's `importNavMesh`, and NPC steering calls `addAgent` on `crowd`, so a replacement is Recast underneath (a different mesh build, say), not another navigation library. For a search of another kind, leave `nav()` out and call yours from game code. The slots below have no contract; a replacement must supply what the engine's own callers read:
73
71
 
74
72
  | Slot | A replacement must supply |
75
73
  |---|---|
76
74
  | `sky` | the `engine.uniforms` signals your `picture/` code reads; `dome` (the object a photo leaves out) if it has one |
77
75
  | `terrain` | the ground through `engine.setGround`; `chunkSize`, `stats`, `edit` (nav), `view` and `setPlanter` (vegetation). Replace `terrain-draw` with it: the drawing half reads the engine terrain's chunks |
78
- | `weather` | `types`, `name`, `current`, `label(name)`, `set(name, { seconds })`, `setAuto(on)`. Replace `weatherDraw` with it |
76
+ | `weather` | `types`, `name`, `current`, `label(name)`, `set(name, { seconds })`, `auto`. Replace `weatherDraw` with it |
79
77
  | `vegetation` | `define(name, rule)` (content), `instanceAt(point, { radius })` (photo), `host` (settings). Replace `vegetation-draw` with it |
80
- | `rigid` | `vehicles`, a list of objects that meet `modules/characters/vehicle.contract.js` |
78
+ | `rigid` | `vehicles`, a list of objects that meet `modules/characters/vehicle.contract.js`; `collider3d`, the three-axis slot (`modules/rigid/collider3d.contract.js`) |
81
79
  | `swarm` | nothing: no other module calls it |
82
80
 
83
81
  **Not replaceable**: `world` (saves, the shared id space, streaming and content stand on its records; it provides the slot so that `requires: ['world']` names a capability), and the player inside `characters` (a replacement of `characters` leaves a live player's `world` record behind, and `engine.player` is the engine's own character; steer it with `control.take`).
84
82
 
85
83
  The starting picture comes from the game's `picture/` folder; what it builds as a factory can also be passed at the call site, and the
86
- call site wins (`terrain({ material })` and the like; the water surface is `engine.water.material`); a new style factory ships with its call-site option. No module option starts a value taken over.
84
+ call site wins (`terrain({ material })` and the like; the water surface is `engine.water.material`); a new style factory ships with its call-site option.
87
85
 
88
86
  **Time channels**: most games use only the default (fixed `dt` in real seconds, `engine.clock` for calendar time). A channel exists so one group
89
87
  of things can run slower or faster than the rest (bullet time on enemies, haste on the player): `engine.onFixed(fn, { channel: 'enemies' })` gets
@@ -106,6 +104,112 @@ into, or a convenience for after.
106
104
  | Environment light | `engine.sky.environment({ into: engine.scene })`, or `scene.environment` | light that changes from place to place: `bakeProbes` |
107
105
  | Post effects | your own three.js Pass in the engine's chain: `engine.post.add(pass)`, the one way in (the engine renders through its composer) | ready-made effects as an optional convenience: `@threedog/post-effects` through the same call or a plugin file, tuned with its handle; a whole chain of your own: `engine.post.own()` |
108
106
  | Ambient occlusion | `engine.post.add(ao())` (screen space) | a model made in code: `bakeVertexAO(geometry)`; bounce light between places: `bakeProbes` |
107
+ | Days, months and seasons that pass | `calendar()`, read `engine.calendar` (recipe 06) | one fixed moment: `sky({ time })` |
108
+ | See through the hero's eyes | `firstPersonCamera()` (recipe 21) | switch at runtime: `setCamera(kind)` |
109
+ | Still view of a room, security-camera style | `fixedCamera({ position, lookAt })` (recipe 21) | a moving shot: `takeCamera(owner)` |
110
+ | Strategy view from above, edge scrolling | `rtsCamera()` (recipe 21) | a view of your own: a module writing `engine.camera` |
111
+ | A person who walks, follows a path, is steered | `engine.characters` (recipe 13, 57) | a mover of your own: `characters.kit` |
112
+ | Levels, items and quests written as data files | `content/` files, read by `engine.content` (recipe 20) | built at runtime: plain code in a module |
113
+ | Dev info on screen, a key that shows it | `debug()`: F3 opens the panel, `engine.debug` (recipe 15) | outside the page: `threedog describe` |
114
+ | Far buildings or forests merged into one cheap mesh | `engine.hlod.add(root)` (recipe 15) | close objects: `engine.batching` |
115
+ | Next map, next stage, change level | `engine.level.load(name)` (recipe 10) | a fade around it: `engine.flow` (recipe 07) |
116
+ | Background song that changes in a fight or a place | `engine.music`, rules as data (recipe 31) | one track: `engine.audio.play` |
117
+ | An enemy walks around obstacles to reach someone | `engine.characters.findPath` on `engine.nav` (recipe 12) | a search of your own is fine: it reads `engine.collision.walkable` |
118
+ | Two people play together over the internet | `engine.net` (recipe 27) | |
119
+ | Take a snapshot in the game and keep it | `photo()`, `engine.photo.take()` | the raw image: `renderer.domElement.toBlob` |
120
+ | A cutscene: steps in order; tween a value | `engine.timeline`, `engine.timeline.tween(target, to)` (recipe 07) | one delay: `engine.clock.after` |
121
+ | Something happens when the player enters a zone | `engine.triggers` (recipe 20) | a press inside it: `engine.interactions` |
122
+ | Raindrops and snow drawn on screen | `engine.weatherDraw` (recipe 08) | your own drawing: `THREE.md` |
123
+ | Lower the resolution when the frame rate drops | `engine.adaptive` (recipe 15) | a fixed size: `engine.setPixelRatio` |
124
+ | Draw many copies of one mesh in one call | `engine.batching` (recipe 05) | your own `InstancedMesh`: plain three.js |
125
+ | What each frame costs, against limits | `engine.budget` (recipe 15) | |
126
+ | A cutscene takes the view for a moment | `engine.takeCamera(owner)`, read `engine.cameraOverride` | a whole shot list: `engine.timeline` |
127
+ | Sweep a shape through solid things, overlap tests | `engine.collider3d` (recipe 11) | a line: `engine.rays` |
128
+ | Spread mesh changes over frames so nothing hitches | `engine.commits` (recipe 15) | any other work: `engine.jobs` |
129
+ | Message when the game crashes, the last error | `engine.error` and `.threedog/errors.log` (recipe 16) | |
130
+ | Tell other systems something happened | `engine.events` (recipe 06) | |
131
+ | Height of the floor under a point | `engine.ground.height(x, z)` (recipe 28) | |
132
+ | Heavy work done bit by bit without freezing a frame | `engine.jobs` (recipe 15) | off the main thread: `engine.threads` |
133
+ | Loading screen, progress bar while files load | `engine.loading` (recipe 07) | |
134
+ | Pause when the browser tab is hidden | `engine.page` does it: gameplay freezes under owner `page` (recipe 07) | |
135
+ | Style files that plug in with no main.js line | `plugins/`, `engine.plugins` (recipe 40) | |
136
+ | Seeded dice roll that replays the same | `engine.random` (recipe 06) | |
137
+ | What is the mouse pointing at, click an object | `engine.rays`, `engine.pick(x, y)` (recipe 19) | |
138
+ | Which systems are stopped and who stopped them | `engine.runState` (recipe 16) | |
139
+ | Remember progress between visits | `engine.saves` (recipe 20) | |
140
+ | New game and continue from the menu | `engine.session` (recipe 07) | |
141
+ | Cloud shadow and season in your own material | `engine.shaderTerms` (recipe 52) | |
142
+ | Stack bonuses from several sources on one value | `engine.stacks` (recipe 55) | one value, no bookkeeping: `engine.mod` |
143
+ | How long the first frame took to load | `engine.startup` (recipe 15) | |
144
+ | Load far parts of a big map only when near | `engine.stream` (recipe 33) | |
145
+ | Heavy work in a web worker | `engine.threads` (recipe 15) | bit by bit on the main thread: `engine.jobs` |
146
+ | How many seconds passed in the game | `engine.time.now()` (recipe 06) | |
147
+ | Remember a flag or a count, a door was opened | `engine.vars` (recipe 20) | |
148
+ | A named fixed view, a second camera to show | `engine.views` (recipe 46) | |
149
+ | Load a model, texture or sound file | `engine.assets` (recipe 05) | a format it does not read: a three.js loader |
150
+ | Something at a set hour of game time (a shop opens at nine) | `engine.clock`, `engine.calendar` (recipe 06) | |
151
+ | A guard patrols or wanders between points | `engine.characters` with `findPath` (recipe 12, 57) | |
152
+ | Back to the main menu after losing, game over, retry | `engine.flow`, `engine.session` (recipe 07) | the rules of the ending: recipe 32 |
153
+ | Sunset, sunrise, the sky's colors | `engine.sky`, `engine.calendar` (recipe 08) | your own sky: `THREE.md` |
154
+ | Mission marker, an arrow on screen | `engine.hud.marker()` (recipe 04) | |
155
+ | Place furniture and merge it for speed | content `props` (recipe 05) | |
156
+ | Your own colors, textures and models | plain three.js in `picture/` (recipe 09) | |
157
+ | A map or model from a 3D modeling tool (Blender) | `engine.level` (recipe 10) | art only: recipe 46 |
158
+ | Write your own engine system | a module (recipe 14) | one that plugs into saves and time: recipe 49 |
159
+ | Match the look of a reference painting or picture | recipe 35 | |
160
+ | The image looks flat, what to adjust | recipe 60 | |
161
+
162
+ ### Look-alike entries
163
+ Each of these does one job. Take the row for your job; none replaces another.
164
+
165
+ **What each wait waits for**
166
+
167
+ | Entry | Waits for |
168
+ |---|---|
169
+ | `engine.ready` (`await engine.start()`) | World built and the loading screen gone |
170
+ | `x.whenReady` (`x.ready` is the same as a boolean) | That one thing: a character's model, a stream source's area, `saves` storage |
171
+ | `engine.loading.settled()` | Every module installed after start() finished its init, also when one failed |
172
+ | `engine.stateApplied` | start() done and the URL parameters or latest `applyState` applied: for tests and screenshots |
173
+
174
+ **Time**
175
+
176
+ | Entry | Job |
177
+ |---|---|
178
+ | `engine.clock` | Timers: `after`, `every` |
179
+ | `engine.time` | Reading game time: ticks and each channel's `now` |
180
+ | `engine.calendar` | Time of day, days, seasons |
181
+
182
+ **Hooks**
183
+
184
+ | Entry | Runs | For |
185
+ |---|---|---|
186
+ | `onFixed` | 60 times a game second, stops when frozen | Rules: movement, damage, cooldowns |
187
+ | `onFrame` | Once a frame | Presentation: animation, UI, what the player sees |
188
+ | `onRender` | Around the frame's render | Extra three.js renders into your own targets |
189
+
190
+ **Loading a save**
191
+
192
+ | Entry | Job |
193
+ |---|---|
194
+ | `session.load` | The default: Continue or retry, nothing of the current playthrough left over |
195
+ | `saves.load` | A quick load inside the same playthrough |
196
+
197
+ **Putting something in**
198
+
199
+ | Entry | Use it for | Saved |
200
+ |---|---|---|
201
+ | `scene.add` | Plain three.js, rebuilt by code on every start | No |
202
+ | `engine.add(obj, { id })` | The same, with an id so changes to it persist | Its changes |
203
+ | `world.add` | A game object that lives on while far away or across levels | Yes |
204
+ | `content.spawn` | A placement of something written as data, at run time | Yes |
205
+
206
+ **Taking something out**
207
+
208
+ | Entry | Leaves the scene | Frees |
209
+ |---|---|---|
210
+ | `scene.remove` | Yes | Nothing: plain three.js, GPU memory stays until you dispose it |
211
+ | `obj.removeFromParent()` | Yes | Nothing, on purpose: you will add it back |
212
+ | `engine.remove` | Yes | Its and its children's geometry and materials; rays unregistered. Asset-shared data stays with the asset cache |
109
213
 
110
214
  ## Owners
111
215
  Everything that holds the engine is named by an owner, and only that owner releases it. Positional `freeze('menu')` and `freeze({ owner: 'menu' })` are the same.
@@ -166,11 +270,12 @@ inside template strings, which then throw on the first call).
166
270
  `ground.height(x, z)`; `{ place, x, z }` in content data is a data form.
167
271
  - **Registrations return a handle**: anything that registers a listener, timer, continuing effect or registration (`events.on/once`,
168
272
  `onFixed/onFrame`, `clock.after/every`, `calendar.at/between/daily/onSeason`, `collision.addBox/...`, `interactions.add`, `rays.addStatic`, `stream.add`,
169
- `triggers.add`, `hud.marker`, `hlod.add`, `particles.attach`, `pickups.spawn`, `rigid.addBox/...`, `audio.addBus`, `defineState`) returns a
273
+ `triggers.add`, `hud.marker`, `hlod.add`, `particles.attach`, `pickups.spawn`, `rigid.addBox/...`, `audio.addBus`, `defineState`, `ops.define`, `saves.register`, `ui.define`) returns a
170
274
  handle `{ owner?, remove() }`; `h.remove()` undoes it, the only give-back form (no `null` / `false` hand-back calls)
171
- (safe to call repeatedly), never a bare function. `remove()` undoes what that call did: models it created itself are deleted with it (such as a
275
+ (safe to call repeatedly, and it removes only its own registration, so `ctx.track` takes any of them), never a bare function. `remove()` undoes what that call did: models it created itself are deleted with it (such as a
172
276
  pickup); objects you passed in are not. APIs that add an object or change business data return what their own signature says: `engine.add(obj)`
173
277
  returns the added object, `inventory.add` returns a result, `world.add` a record; delete those with `engine.remove(obj)` / their own remove call.
278
+ A definition by name (`inventory.define`, `quests.define`, `settings.define`) is data, not a registration: it returns its own object, and defining the name again replaces it.
174
279
  - **Verbs**: defining a kind is `define` (`vegetation.define`, `particles.define`, `grids.define`, `ops.define`); placing one is `add` / `spawn`;
175
280
  hooking up a provider the engine calls back is `register` (`saves.register(key, { save, load })`: it defines no kind and places nothing).
176
281
  One timer entry: `engine.clock.after(seconds, fn, { data, channel })` (calendar seconds, or `'real'` / a time channel's seconds with `channel`);
@@ -204,9 +309,7 @@ inside template strings, which then throw on the first call).
204
309
  dev warning naming the fix.
205
310
  - Gameplay state (world, containers, vars, quests) changes only in fixed steps or inside ops; dev warns otherwise (`npm test` prints the first place, all in
206
311
  `<game>/.threedog/ops-guard.log`). (game side)
207
- - **One source for "can walk there"**: `createEngine({ movement: { radius, height, maxSlope, stepHeight } })` -> read-only `engine.movement`;
208
- collision, the Rapier capsule, navigation, A* and level steps all read it; don't write another 0.4 / 0.45 in a module. A character's position
209
- belongs to the Character mover; other systems only request movement (`placeAt` / `move` / vehicle `enter`) and never set `player.position` directly.
312
+ - **One source for "can walk there"**: `engine.movement`, and a character's position belongs to its mover (recipe 12 section 5).
210
313
  Who calls `move` is the character's control holder (`engine.control`, `recipes/57-control.md`): one per step; anyone else is `[control-bypass]`.
211
314
  - Units are meters, Y is up, north is -Z. Characters and vehicles face the model's +Z; `facing` 0 = +Z, forward = (sin f, cos f).
212
315
  - Never call `requestAnimationFrame` or `renderer.render` yourself. **Game logic always uses real seconds or calendar seconds** (the hook's `dt`,
@@ -247,7 +350,7 @@ Inside the engine a failure takes one of three forms, so every one reaches the r
247
350
  - **Effects still moving with three.js**: all of `threedog/tsl` and `@threedog/post-effects/tsl`.
248
351
  - **Names nothing uses yet**: a public name no game, recipe, example or template used at 0.8 stays marked until one does; `docs/api-surface.txt` lists them.
249
352
  - **Coordination no test game has used**: `engine.stacks`, `engine.wrap`, `engine.mod`, `time.channel / channels`.
250
- - **Systems still settling**: `net()`, `engine.threads`, `engine.commits`, `grids()`, `hlod()`, `swarm()`, `stream.source / teleport / addReadyCheck / sources`, `post.get / own / setAntialias / list`, `world.simulate({ worker })`, `terrain.edit`, `ops.guard / allow`, `terrainDraw`, `vegetationDraw`, `weatherDraw`, `engine.bakeProbes / loadProbes / loadLightmap`.
353
+ - **Systems still settling**: `net()`, `engine.threads`, `engine.commits`, `grids()`, `hlod()`, `swarm()`, `stream.source / teleport / addReadyCheck / sources`, `post.get / own / antialias / list`, `world.simulate({ worker })`, `terrain.edit`, `ops.guard / allow`, `terrainDraw`, `vegetationDraw`, `weatherDraw`, `engine.bakeProbes / loadProbes / loadLightmap`.
251
354
  - **Flat content**: an entry's `source`, `content stamp`, `content capture`.
252
- - **Tuning and readings**: `engine.moduleOrder / moduleStates / disabledModules`, `player.saveMotion / loadMotion`, `jobs.loadingMs / maxSteps / slowStepMs`, `stream.unloadFactor`, `batching.held`, `world.steps`, `level.heightfield`.
355
+ - **Tuning and readings**: `engine.moduleOrder / moduleStates`, `player.saveMotion / loadMotion`, `jobs.loadingMs / maxSteps / slowStepMs`, `stream.unloadFactor`, `batching.held`, `world.steps`, `level.heightfield`.
253
356
  - **Commands.** Only the `--json` and MCP shapes are an interface; printed text keeps changing for AI readers. An error's `code` string is frozen, its message is not.
@@ -2,6 +2,8 @@
2
2
 
3
3
  npm never had 0.7.1, so this page goes from 0.7.0 straight to 0.8.0.
4
4
 
5
+ First run `threedog doctor --fix`: it rewrites the `threedog` and `@threedog/*` pins in each game's `package.json`. A game in `games/` of a clone that still pins `^0.7.1` stops `npm install` with `ETARGET`.
6
+
5
7
  Names were settled before 1.0: a few were removed, a few renamed. Nothing below keeps working under its old name. A stale uniform name in shader text reads 0 with no error and no warning, so search for the old names below.
6
8
 
7
9
  ## Uniforms
@@ -0,0 +1,101 @@
1
+ # Moving a game from 0.9 to 1.0
2
+
3
+ First run `threedog doctor --fix`, then `npm run check`: a removed name shows up as a type error on the line that uses it. Most games need nothing else. The tables say what you will see and what to do, and every error below names its own fix.
4
+
5
+ ## What now stops with an error
6
+
7
+ | You will see | What changed | What to do |
8
+ |---|---|---|
9
+ | A game's own vehicle loses its rider after a load in a fresh session | Saved riders find vehicles through one registry, not through `rigid` | Call `engine.characters.addVehicle(vehicle)` once it is built, before or after the load |
10
+ | `exit()` returns `false` and the rider stays | No exit of the vehicle is walkable | Move the vehicle, offer more exits through `exitPosition(seat, n)`, or `exit({ force: true })` |
11
+ | `walkTo` answers `'cancelled'` after `placeAt`, `enter`, a level change or a ragdoll | Each of them ends the walk. It used to carry on, or wait under the ragdoll | A follower that wants to go on after being placed calls `walkTo` again |
12
+ | `walkTo` ends `'noPath'` before a gap where it ended `'stuck'` at it; small bodies take gaps they used to go round; a stall the first time a new size asks | Navmesh paths fit the radius that asks, on a mesh of that size built on first ask | Drop an `agentRadius` set to the widest walker unless `crowd: true` needs it. Ask once per size during loading to move the stall there (recipe 12 section 5) |
13
+ | `[shared-taken]` at `engine.use(...)`, naming `terrain` and `level` | `ground` is one exclusive slot. The later `setGround` used to win | Keep one, or swap with `engine.use(level(), { replaces: 'ground' })`. To run both: `terrain({ part: true })`, `level({ part: true })` and `compositeGround({ parts: [{ of: 'terrain' }, { of: 'level', region }] })` |
14
+ | `[shared-taken]` for any other slot, in a release build too | A second provider of an exclusive slot is refused in every build. A release build used to warn and let the later one win | Install one, or `engine.use(mine(), { replaces: 'slot' })` |
15
+ | `[shared-conflict]`, in a release build too | Two owners `set` one point on one layer. A release build used to warn and let the later write win | Contribute with `add` / `mul`, use another `layer`, or keep one owner. The message has each fix to copy |
16
+ | `[control-conflict]`, in a release build too | Two owners take one character on one control layer. A release build used to warn and let the later owner win | End the old hold first (`handle.remove()`), or take another layer. The message has both fixes to copy |
17
+ | `[container] ... must be a whole number >= 1` | `add`, `remove`, `setData`, `transfer` and `trade` refuse 0, negatives, fractions and NaN. `remove('apple', -2)` used to add stock | Pass a whole number of pieces. To put stock back, call `add` |
18
+ | `engine.disabledModules` | Removed: a switched-off module has state `'disabled'`, and one list is derived from it | `engine.describe().disabledModules` |
19
+ | `settings({ presets: { low: { viewChunks: 3 } } })` | `viewChunks` and `density` in a preset are shares (0 to 1) of the game's own value, as `pixelRatio` already was; above 1 throws | Write the share, e.g. `viewChunks: 0.6` |
20
+ | `engine.post.antialias` with no effect on | It no longer switches the post chain on to reach an MSAA the canvas lacks; MSAA is fixed with the canvas | `createEngine({ antialias })`; the settings row applies at the next launch |
21
+ | `settings.set(key)` on a key no row owns | Throws `settings-row` after start; before start it waits for a module's row and warns if none came | Define the row, or add the tab that has it |
22
+ | `applyState({ wether: 'rain' })` | A key no installed module names in `stateKeys` is refused in the answer, not thrown | Read `refused` |
23
+ | `[module-needs] content quests: no installed module reads this section` | A module owns its content section, and data for a module that is not installed stops the load | Add the module the message names, or remove the data |
24
+ | The same error after `engine.use(mine(), { replaces: 'quests' })` | Replacing a module replaces its section too | Give the replacement `content: { quests: { commit(d) { ... } } }` (recipe 14) |
25
+ | `[character-option] mover "...": use 'simple', 'rapier', 'manual' or your own` | An unknown mover name used to warn and walk with `'simple'` | Fix the name, or pass `(character, engine) => ({ name, move(x, z, run, dt, y) })` (recipe 57) |
26
+ | A player or a body that fell out of the world stays gone, and a dev build says `no rule 'fall' is set` | The engine no longer rescues by default: `character:fall` and the rule `fall` stay, `'rescue'` is a built-in the game chooses. `openWorld` and the new-game templates choose it | `engine.mod('fall', { owner: 'game', set: 'rescue' })`, or `characters({ fall: 'rescue' })`. A deep pit or a death that was fighting the rescue needs nothing |
27
+ | `preventDefault is not a function` in a `character:fall` listener | Falling is one rule, `fall`, for characters and rigid bodies | Remove the call. `engine.mod('fall', { owner: 'game', id: 'player', set: false })` leaves the fall to the game; a function `(facts, engine) => 'rescue' \| false` decides per fall |
28
+ | `nothing explains 'picture' (did you mean 'value'?)` | `explain({ picture })` is now `explain({ value })`, which also gives the short history | Rename the key. On the command line: `threedog explain value fog.far` |
29
+ | `explain is not a function` on a thing | `engine.explain` is the one way to ask why | `engine.thing(id).explain()` becomes `engine.explain({ thing: id }).detail`, and `threedog thing <id>` becomes `threedog explain thing <id> --full` (MCP: `explain` with `about: 'thing'`) |
30
+ | `[save-key-taken]` from `saves.register` | A second register on a held key used to take the part from its owner with nothing said, and that owner stopped being saved | Use another key, or `remove()` the first handle before registering again |
31
+ | `[skip-busy]` from `engine.skip` | A second skip during a first one's fade used to resolve and unfreeze the game mid-fade. The doc always said it rejects | Await the first skip, then skip again |
32
+ | `[save-busy]` from `saves.collect` | A load is running. `saves.save` waits for it, `collect` cannot | Collect after the load. Do not await `saves.apply` or `saves.load` inside a part's `load()` or an `afterLoad`: dev warns `save-nested`, because it would wait forever |
33
+ | `setViewChunks is not a function` or `setDensity is not a function` | One entry each: `terrain.viewChunks` and `terrain.density` take effect when written | `terrain.setViewChunks(n)` becomes `terrain.viewChunks = n`; `terrain.setDensity(d)` becomes `terrain.density = d`. Plants that block stand at every density |
34
+ | `[save-bad-record]` on loading a save, naming `the level file` or a record `model` | A save may name a registered asset or a relative path on this site, nothing else. A full URL, `//host`, a backslash or `..` used to be fetched | Register a level or model that lives on another host in the asset manifest and name it there: a registered entry passes whatever its URL |
35
+ | `setRadius is not a function`, `setAuto is not a function`, `setAntialias is not a function` | One entry each, like `terrain.viewChunks` | `stream.setRadius(m)` becomes `stream.radius = m`, `weather.setAuto(on)` becomes `weather.auto = on`, `post.setAntialias(on)` becomes `post.antialias = on` |
36
+ | `threedog eval` is an unknown command | It was a second name for `threedog js` | Use `threedog js` |
37
+ | A type error on `engine.moduleStates` | It was experimental and is internal now | Ask `engine.explain({ module: name })`, or read `engine.describe().moduleStates` for what is not running |
38
+ | An op that ends in `return e.content.run(...)` fails where it used to pass | `content.run` answers with a failure when a word failed, and an op that returns one fails with it (an atomic one rolls back) | Good if that is what you meant; else do not return the answer |
39
+ | A quest with a `give` reward and a full bag says the reward was not given, and pays it later | The items used to be lost. They are owed now | Nothing, or add `onUnpaid` to decide yourself (recipe 04) |
40
+ | An async `onUse` on a `once` item is not used up at once, and a second use is refused until it settles | It is judged when it settles. It used to spend the item straight away, whatever came back | Nothing. Read the answer with `await r.value` |
41
+ | `const { skipped } = await timeline.play(...)` is undefined, same for `timeline:end` | A run has one ending | Read `ending`: `'finished'`, `'skipped'`, `'dropped'` or `'failed'` (with `error`) |
42
+ | A cutscene's remaining `do` steps no longer run at a new game | A new game drops the run, as a load does. It used to skip it, running them on the new state | Put what must happen in `session:end` |
43
+ | `[engine-misuse] vars.bump` | `n` must be a finite number. NaN used to go into the counter | Pass a number |
44
+ | `[module-params] triggers.add({ radius })` | A NaN or negative radius used to sit in the zone list and never match | Pass a finite number >= 0 |
45
+ | `[grids-misuse] grids.add` | A cell, origin or size that is no valid number is refused | Cell > 0, a finite origin, size whole numbers > 0 or left out |
46
+ | `[quest-step] ... next` | A step's `next` must be a step of that quest or a function | Fix the id the message quotes |
47
+ | `[save-version]` at `saves.register` | A `migrate` key must be a whole version below the current one | Rename the key |
48
+ | `saves.save` answers false with `[save-part-threw]` | A part's `save()` returned a function, a symbol, NaN or an infinity, which a save cannot hold | Return plain data, or null for nothing |
49
+ | `[save-write]` from `saves.putAttachment` | Only a Blob is stored | Pass a Blob |
50
+ | `[terrain-option]` from a terrain edit | An edit that would touch more than about four million points is refused | Use a smaller radius or several edits |
51
+ | `[rigid-misuse] ... differs between axes` | A body cannot follow a parent scaled unevenly | Make the parent's scale equal on all axes |
52
+ | `[bad-position]`, `badArgs`, `[world-add]`, `[world-id]`, `[interaction-option]`, `[content-template]`, `[content-place]`, in a release build | These checks ran only in development. A game that passes its development run sees none of them | Fix what the message names |
53
+ | The contract check fails on a replacement's own `contract.js` that lists `methods` | Object contracts (`mover`, `vehicle`, `ground`, `collider3d`) list their members under `api` like every other contract | Rename `methods` to `api` |
54
+ | `module-order` from `use()` for an order written with a capability name | The same order by module name always threw | Put the provider in the stage the order needs (`stage: 'environment'`), or drop `before` / `after` from the module that says it |
55
+ | `engine.detach is not a function` | Removed: it only called three.js | `obj.removeFromParent()`. `engine.remove` stays |
56
+ | `Cannot set property locale` on `engine.i18n` | `locale` is read-only. Writing it skipped the name lookup and `i18n:change` | `engine.i18n.setLocale(name)` |
57
+
58
+ ## What now behaves differently, with no error
59
+
60
+ - A `level.load` or `content.load` inside a save part's `load()` or a module's `afterLoad` needs the turn they get: `load(d, turn) { return engine.level.load(d.level, { turn }); }`. Without it the call waits for that load to end, so awaiting or returning it never ends (dev: `[save-nested]` after 3 s). Calls that are not awaited run right after the load.
61
+ - A save part registered while a load runs gets its data after that load, not during it. Idle it is still before `register` returns.
62
+ - `content.load` returns a Promise of this load instead of `engine.content`. Chain with a second statement: `content.load(a).load(b)` becomes two lines. Bad data still throws on the line; a pack with nothing to wait for is still live on the next line.
63
+ - A pack that swapped the level and then failed now rejects, after the old level is back, where it used to throw at once while the old level loaded in the background. Read the failure with `await` or `.catch`. A failed restore is on `err.notRestored`.
64
+ - A collision module that throws from `addBox` while taking the level walls now fails its `use()`, and the module it replaced comes back. An old `engine.haltLoop` or `views.show` handle removed after a new one was taken does nothing.
65
+ - `world.simulate` with `channel`: `far` and a tiered `near` get the channel time the record lived through, not the seconds owed times the speed at that moment. Remove anything written to work around a far `dt` that followed the last speed. The world save part gains `marks`; older saves load without it.
66
+ - A level file that fails rejects even when the manifest gives it a fallback; a level never stands on a stand-in. Nothing to write unless a game relied on the gray box.
67
+ - `engine.loading.timeoutMs` is now the limit on every load, on each module's `init()` and on every wait for "settled", not only on `isReady`. A file with no sign of life for that long fails like any failed file. Raise it for a load that is silent for longer than 120 s.
68
+ - `flow.transition` rejects with `module-not-ready` when the world does not settle within the limit. The screen and input come back first. Catch it if the game has an answer.
69
+ - `level.load` during `saves.load`, `saves.apply` or a `session` call runs after it, so the level the load answered true for stands first. Do not await it inside a part's `load()` after an `await`: that waits for itself.
70
+ - Autosave does not fire during `flow.transition` or `timeline.play`; it fires on the first step after. A save the game asks for itself still goes at once.
71
+ - `content.load` during a state replacement commits after it.
72
+ - The `level` save part of a level built in code holds a token only that page can read. From another page the load stays on the level that stands, as before.
73
+
74
+ | You will see | What changed | What to do |
75
+ |---|---|---|
76
+ | An unhandled rejection from `level.load` | The new level is built first. On failure the old one stays, `level:failed` fires instead of `level:loaded`, and the Promise rejects | `await` it in a `try`, or add `.catch`. A save that names a broken level now rolls back |
77
+ | `ops.run` / `ops.can` / `ops.undo` answer `'loading'` | They change nothing for the whole of a state replacement, including a part's `load()` and `afterLoad` | Retry after the load: `await` it, or wait for `save:loaded` |
78
+ | A game's `applyState` hook no longer gets `?weather=rain` from the URL | Only core's own keys and the keys a module names in `stateKeys` are read from the URL. A hook with no `stateKeys` still gets such a key from a direct `applyState({ weather: 'rain' })`, but with the module that owned it absent, nothing reads it from the URL | Name the key in your module: `stateKeys: ['weather']` |
79
+ | A second `saves.apply` or `saves.load` waits | Overlapping loads now take turns and end as one whole save | Nothing, unless you relied on the second one starting at once |
80
+ | A `control.take` on a script, cutscene or physics layer, or a `world.anchor` set during play, stayed after a new game | Both end with the playthrough; `world.anchor` goes back to what boot left | Take or set it again from a `session:start` listener, or take the hold through `ctx.control` when it belongs to a module |
81
+ | `saves.load` or `saves.apply` left the title open | Any save put back closes it, and a rollback fires `session:failed` with `kind: 'quick'` | Drop your own `ui.close('title')`; a `session:failed` listener that only meant `session.*` checks `kind` |
82
+ | Code that looked for the freeze owners `threedog:load` / `threedog:load-parts` finds nothing | They are one owner now, `threedog:state-replace` | Wait for `save:loaded` |
83
+ | `thing.set`, `world.set` or `world.move` on the player or an NPC with a model now really moves it, and it lands on what stands there | The character owns its position, so these writes are its `placeAt`. They used to return ok and change the record until the next step put it back. A write that matches where the character stands changes nothing | Remove any `placeAt` you added beside such a write. To set the exact spot, `root.position` then `syncRecord()` from a control hold (recipe 57) |
84
+ | A seated character gets out when it is placed: `vehicle:exit` fires and the vehicle brakes | `placeAt`, `engine.stream.teleport` and any write to its record's position end the ride. The seat used to pull it back on the next step | To take the rider along, move the vehicle. To keep a stale position write from ending a ride, drop the write. Undo of such a `thing.set` seats it again, and can answer `ownerRefuses`: read the result |
85
+ | `placeAt` or a position write on a ragdoll moves the whole body, which stays limp | The next step used to put root back on the body. It arrives at rest, so a fall's speed is dropped | To stand it up elsewhere, `remove()` first as before; the result is the same |
86
+ | `rot` or `scale` on a live character's record turns or sizes it, and `thing.set` keeps all of `rotation` / `scale` given as `[x, y, z]` | They used to land on the record and do nothing, and the array forms kept only y and x. A tilt, a turn while seated or a value that is not a number or `[x, y, z]` is refused: `thing.set` answers `ownerRefuses`, `world.set` throws `[character-option]` | A field of your own called `rot` or `scale` on the player or an NPC needs another name |
87
+ | A write to a record with `positionFrom: 'view'` moves its model and rigid body, which comes to rest there | `world.move`, `world.set`, `thing.set` and `rec.position` used to be overwritten by the model at the end of the step. `rot` or `scale` on a template with a `body` now rebuilds the body | Drop a write that relied on being ignored; to push a body, use `rigid.impulse` |
88
+ | `engine.use(mine(), { replaces })` receives the old module's save data | A save part that leaves keeps its data and hands it to the next part with that key | Give `mine` its own key if the format differs |
89
+ | A module waits as `'blocked'`, with no `init` and no hooks | `requires` means the provider works, not only that it is installed | `engine.explain({ module: name })` says on what |
90
+ | The flat ground returns when a ground provider leaves | `ground` belongs to the module that holds the slot | A module of your own declares `provides: ['ground']` and calls `ctx.ground.provide(...)` |
91
+ | Paths are `{ x, y, z }` | `findPath`, `findPathAsync` and `engine.nav` keep the height | Read `y` if your game has floors; code that reads `x` and `z` is unchanged |
92
+ | With two engines on a page, only one reacts to a key or a gamepad | The engine last pressed or focused owns the keyboard and the gamepads, the first one until then. Both used to hear every key and pad | Nothing with one engine. To hand the keyboard over from code, focus something in that engine's `uiRoot` |
93
+ | The wheel changes the view height of a real `OrthographicCamera` under a default follow rig | It used to change `distance`, which shows nothing there | Nothing |
94
+ | `engine.camera` is another object after a rig or shot with `projection: 'orthographic'`, and `camera.orthoSize` and `camera.isEngineCamera` read `undefined` | The engine's first camera is a plain `THREE.PerspectiveCamera`. An orthographic view is now always a real `THREE.OrthographicCamera` in `engine.camera`, and the next perspective view brings the first camera back. It has no `fov` or `aspect` | Read `engine.camera` where you use it, not from a copy kept across a switch. The view height is `camera.top - camera.bottom` or `describe().camera.orthoSize` |
95
+ | `projection: 'orthographic'` over a real perspective camera you assigned works | It used to throw `[camera-option]`. The rig's own orthographic camera stands in until the next perspective view, which brings yours back | Nothing |
96
+ | With two tabs open, `saves.remove` keeps a slot and `putAttachment` / `removeAttachment` reject with `[save-stale]` | They follow the rule saves already had: a tab changes only what it last wrote or saw. A forgotten tab used to delete or replace newer progress | Nothing for one tab. On the rejection read `saves.attachments(group)` first, or use another id |
97
+ | A settings row or tab is gone after `engine.unuse` | A row or tab a module made in its install, init or a hook leaves with that module and gives its limits back. It used to stay, driving nothing | Define a row that must stay from the game, not from the module. The player's choice comes back when the module does |
98
+ | `findPath` without `nav` says `noPath`, and `walkTo` ends with that status | A goal on a floor the walker cannot reach used to be `ok`, with a path that ended under it | Handle `noPath` |
99
+ | `threedog how --list` is gone | `threedog how` or `--browse [category]` to browse, `--card <id>` for one capability. The MCP tool takes `browse` and `card` fields; `task: "--list"` is only words now | Use the new flags |
100
+
101
+ Everything else since 0.9.0 is new and opt-in, or changes nothing for a game: `CHANGELOG.md` has the full list.
package/docs/THREE.md CHANGED
@@ -10,8 +10,8 @@ pass is a three.js Pass (`engine.post.add(pass)`) before a ready-made effect.
10
10
  |---|---|---|
11
11
  | `engine.scene.add(obj)` / `group.add(obj)` | registers each root under the scene like `engine.add`: `engine.thing`, `describe().scene`, `thing.set` / `thing.remove` | a stable id so a save finds it: `engine.add(obj, { id: 'mill' })` |
12
12
  | `new THREE.PointLight(...)` / `SpotLight` added to the scene | a real light, adopted as a thing; counted by `engine.budget` `lights` / `shadowLights`, listed in `describe().render.lights`; a casting light at intensity 0 stops redrawing its shadow map; weather and day-night leave its values alone | many sources, few real lights: `lightPool` (recipe 09) |
13
- | `new THREE.MeshStandardMaterial(...)` | scene fog (height fog too), cascaded shadows | wind sway: `applyEffects(mat, { wind: 0.03 })` |
14
- | `engine.post.add(pass)`, the one way into the chain (the other renderer's form: recipe 56) | slots it after the scene render and before tone mapping (FXAA / SMAA last), or after tone mapping when you added it after an OutputPass; a pass that renders `engine.scene` itself (RenderPixelatedPass, SSAA, TAA) replaces the scene render, so the scene is drawn once; skips a RenderPass / OutputPass it already has; listed in `post.list()`; `remove()` leaves it undisposed | a settings name and position: `add(pass, { name: 'glow', order })`, then `engine.post.get('glow').enabled = false` |
13
+ | `new THREE.MeshStandardMaterial(...)` | cascaded shadows (`scene.fog` is three.js's own `material.fog`, untouched) | wind sway: `applyEffects(mat, { wind: 0.03 })` |
14
+ | `engine.post.add(pass)`, the one way into the chain (the other renderer's form: recipe 56) | slots it by kind (recipe 52, "Post effect chain"): after the scene render and before tone mapping, FXAA / SMAA last; listed in `post.list()` | a settings name and position: `add(pass, { name: 'glow', order })`, then `engine.post.get('glow').enabled = false` |
15
15
  | your own `EffectComposer` / `renderer.render` of the whole canvas, every frame | yields the frame (stops drawing its own, warns once `[own-frame]`); delete your render call to hand it back. A minimap / HUD layer on top (scissor, smaller viewport, or `autoClear = false` with another scene) is not a takeover | - |
16
16
  | `renderer.setSize` / `setPixelRatio` yourself | the post chain follows on its next draw | - |
17
17
  | `scene.fog.far = 80`, `sun.intensity = 3`, `renderer.toneMappingExposure = 1.4` | stays: the engine never writes these on its own | - |
@@ -57,22 +57,24 @@ that should not see it. It is page-wide: every engine on the page loses the chan
57
57
 
58
58
  | id | Change | Effect on your code | Off |
59
59
  |---|---|---|---|
60
+ | `occlusion-layers-test` | `layers.test` of a mesh `engine.occlusion` hides, an own property while it is hidden | `engine.camera` skips the mesh; every other camera, shadows and rays see it. `mask`, `visible` and clones stay yours | no; `engine.occlusion.enabled = false` removes it |
60
61
  | `shadow-accessors` | `Mesh.prototype.customDepthMaterial / customDistanceMaterial` become accessors | Unassigned, they return a shadow material only for a mesh whose material carries a vertex-moving engine patch (wind), so its shadow sways too; otherwise `undefined` as in three. An assignment always wins | yes |
61
62
  | `node-setup-position` | `NodeMaterial.prototype.setupPosition` wrapped | WebGPU only: runs the engine's vertex-moving patches (wind) first; other node materials unchanged | yes |
62
- | `scene-add-hook` | `Object3D.prototype.add / remove` wrapped (page-wide) | None to the call itself; the engine sees what enters and leaves its scene at any depth (adopting `scene.add`, fog, cascades, cloud shadow, light counts). Another library wrapping the same methods stacks with it | yes (`scene.add` no longer adopted) |
63
+ | `scene-add-hook` | `Object3D.prototype.add / remove` wrapped (page-wide) | None to the call itself; the engine sees what enters and leaves its scene at any depth (adopting `scene.add`, cascades, cloud shadow, light counts). Another library wrapping the same methods stacks with it | yes (`scene.add` no longer adopted) |
63
64
  | `mesh-material-accessor` | `material` on each object entering the engine's scene: an own get / set on that object (a class accessor, e.g. troika text, still runs) | In devtools `mesh.material` shows as an accessor; `mesh.material = other` works as in three and is seen | yes (new objects) |
64
- | `material-compile-accessor` | `onBeforeCompile` / `customProgramCacheKey` on each material the engine patches (what applyEffects was asked for, wind, fog) | Your own hook, assigned before or after, runs first, then the engine's | yes (new materials) |
65
+ | `material-compile-accessor` | `onBeforeCompile` / `customProgramCacheKey` on each material the engine patches (what applyEffects was asked for, wind, the game's own shader slots) | Your own hook, assigned before or after, runs first, then the engine's | yes (new materials) |
65
66
  | `renderer-render` | `engine.renderer.render` (that instance only) wrapped | Counts your full-canvas draws so the engine yields the frame; a scissored / smaller-viewport / `autoClear = false` layer (minimap, HUD) does not count | yes |
66
67
  | `shader-chunks` | `THREE.ShaderChunk.threedog_*` added (new names, nothing replaced) | None until you `#include` one | no (the engine's patches include them) |
67
68
  | `light-idle-shadow` | `shadow.autoUpdate` of your shadow-casting point / spot lights: off while intensity is 0, back on when lit | Only lights whose autoUpdate was on; writing autoUpdate yourself hands the light back; `light.userData.idleShadow = false` opts one out; `describe().render.lights` shows `shadowIdled` | yes |
68
69
  | `shadow-cache` | `light.shadow.shadowNode` of a light handed to `engine.shadows.cache`: a `ShadowNode` subclass with float depth, a second depth map and a draw filter | Only that light, only after the call; the handle's `remove()` puts three's node back |
69
70
  | `batching-draw-walk` | `children` of a parent holding batched meshes: those meshes leave the array during the engine's own draw and come back right after | None outside the draw: your code, raycasts and `scene.traverse` see the scene as built. A scene change made inside a render (`onBeforeRender`) on such a parent is lost | yes (three walks every batched original twice a frame again) |
70
- | `picture-writers` | Dev server only (absent from bundles and release builds): an own get / set on the picture values of objects in the engine's scene (light intensity / color / position, `scene.fog` and its values, tone and exposure, environment, background, material color / emissive / opacity), and on the `r g b` / `x y z` of those colors and positions | Every read and write goes through unchanged; in devtools these show as accessors. A write records who made it for `describe('picture').writers` and `engine.explain({ picture })` | yes: `threePatches.off('picture-writers')`, accessors stay and only pass values through |
71
+ | `picture-writers` | Dev server only (absent from bundles and release builds): an own get / set on the picture values of objects in the engine's scene (light intensity / color / position, `scene.fog` and its values, tone and exposure, environment, background, material color / emissive / opacity), on the values in `describe().owned` that are plain properties (the camera, `view.far`, the shadow target), on values named with `engine.debug.watch`, and on the components of those colors, vectors and rotations | Every read and write goes through unchanged; in devtools these show as accessors. A write records who made it for `describe('picture').writers` and `engine.explain({ value })` | yes: `threePatches.off('picture-writers')`, accessors stay and only pass values through |
71
72
  | `post-shadow-hold` | `render` of the first pass of the WebGL post chain wrapped (it may be your own Pass) | None to what the pass draws; shadow maps redraw once a frame | yes |
72
73
  | `post-background-tone` | `onBeforeRender` of three's own background mesh, while the engine draws straight to the canvas | A texture background is tone-mapped as it is through the post chain; your own `renderer.render` keeps three's rule | yes |
73
74
  | `node-twin-dress` | `renderer.library.fromMaterial` of a WebGPURenderer wrapped | WebGPU only: the node twin of a classic material gets its patches | no (patched materials would lose their picture on WebGPU) |
74
75
  | `node-builder-hook` | `renderer.debug.onNodeBuilderCreated` of a WebGPURenderer wrapped | WebGPU only: your own hook still runs; a later write of yours replaces the engine's | yes |
75
76
  | `device-lost-hook` | `renderer.onDeviceLost` of a WebGPURenderer wrapped | WebGPU only: three's hook still runs; a later write of yours replaces the engine's | yes |
77
+ | `occlusion-readback` | `resolveOccludedAsync` of the WebGPU backend (that one instance), once `engine.occlusion` is on | WebGPU only: an AbortError from a buffer destroyed with the renderer is dropped; any other error still reaches you | no (disposing an engine while occlusion answers are on their way would report an unhandled rejection) |
76
78
  | `lod-view-camera` | `update` and `clone` of the `THREE.LOD` objects `assets.lod` and a prop's `lod` make | Only the engine camera moves the level, and far off the full model waits on the batch layer with `visible` still true, so rays reach it | yes |
77
79
  | `webgpu-record-sweep` | A `'dispose'` event sent to objects drawn earlier that have left every Scene for a few seconds, found through WebGPURenderer's private record list | WebGPU only: your `'dispose'` listener on such an object runs; drawing it again rebuilds its record | yes |
78
80
 
@@ -111,23 +113,20 @@ Anywhere a position is accepted it is **one argument**: Vector3 / Object3D / `[x
111
113
  One exception, named: with cascaded shadows on (`engine.shadows.cascades(light)`) every built-in lit material gets the `csm` patch, or it would
112
114
  be lit N times; a lit `ShaderMaterial` of yours joins with `engine.shadows.include(mat)` (recipe 45).
113
115
  2. **Adding to the scene**: `engine.scene.add(obj)` is all it takes: every root under the scene is registered (`engine.thing(obj)` says what it
114
- is and what a save keeps). `engine.add(obj, { id })` is only for a stable id, so `thing.set` changes to it are saved. Plain three.js and
115
- templates (`engine.content.spawn`, content props) are two doors into one scene (`recipes/40-scene.md`). To attach to a character use `player.root.add(hat)`.
116
+ is and what a save keeps). `engine.add(obj, { id })` is only for a stable id, so `thing.set` changes to it are saved (`recipes/40-scene.md`). To attach to a character use `player.root.add(hat)`.
116
117
  3. **Per-frame logic goes in `engine.onFrame(dt => ...)`** (movement and timing use `engine.onFixed`); it returns a handle, cancel with `h.remove()`.
117
118
  Don't start your own `requestAnimationFrame` loop: the engine owns pausing, fast-forward in tests and ordering. Rendering the canvas
118
- yourself (own `EffectComposer`) takes the frame over: the engine stops drawing it and its post chain, adaptive resolution and photo mode stop applying. Rendering into your own render target is fine (mirror, minimap, portal, picking): do it in
119
- `engine.onRender(({ renderer, scene, camera, dt }) => ...)`, which runs after the camera update and batching, just before the frame
120
- (`{ when: 'after' }` runs right after it).
119
+ yourself (own `EffectComposer`) takes the frame over: the engine stops drawing it and its post chain, adaptive resolution and photo mode stop applying. Rendering into your own render target is fine: `engine.onRender`, in the table above.
121
120
  4. **Snap to ground**: get ground height with `engine.surface(x, z)`, or `engine.snapToGround(obj, heightAboveGround)`. Don't raycast the terrain.
122
121
  **Rays** always go through `engine.raycast / pick`: level meshes are registered automatically; register your own static objects with
123
122
  `engine.rays.addStatic(obj)` or `assets.model(name, { static: true })`.
124
123
  5. **Deleting**: when you no longer need an object use `engine.remove(obj)`: it removes it, unregisters it from `engine.rays` and frees the geometry
125
124
  and materials (`obj.removeFromParent()` / `scene.remove` leak GPU memory). To take it off only temporarily and `add` it back later use
126
- `engine.detach(obj)`. A copy from `assets.model()` shares resources with other copies (`remove` skips them); they are freed together by
125
+ `obj.removeFromParent()`. A copy from `assets.model()` shares resources with other copies (`remove` skips them); they are freed together by
127
126
  `assets.release(name)`.
128
127
  6. **The sky lights nothing**: it computes signals and draws the dome, and your `picture/` code writes the lights, the fog and the exposure (recipe 62); weather gives `uWeatherLight` / `uWeatherFog` to multiply in. Every engine-written value: recipe 52
129
128
  "Who writes it". Adding your own point lights (street lamps, campfires) is fine.
130
- 7. **Camera**: only change properties of `engine.camera`, never replace the object (post-processing is bound to it; `engine.setCamera('follow')` swaps the camera *module*, not the object). When a camera
129
+ 7. **Camera**: `engine.camera` is a three.js camera: change its properties, or assign your own real `THREE.PerspectiveCamera` or `THREE.OrthographicCamera` (`engine.camera = cam`, keep the old value to swap back). Rendering, post, picking, shadows, audio and an installed camera module all go on with it; any other class, a subclass too, is refused. Aspect, frustum and a rig's `projection`: recipe 21. `engine.setCamera('follow')` swaps the camera *module*, not the object. When a camera
131
130
  module is installed it places the camera every frame; to control the view yourself take it with `const cam = engine.takeCamera('me')` and `cam.remove()` it
132
131
  (`engine.cameraOverride` is read-only: it shows the holder in charge, or `null`).
133
132
  8. Collision: the player only respects `engine.collision` (`addCircle / addBox / addObject(mesh)`); a mesh alone does not block anyone.
@@ -154,6 +153,60 @@ engine.collision?.addCircle(mill, { radius: 1.3 }); // block the player (when th
154
153
  engine.onFrame(dt => { blades.rotation.z += dt * 1.5; });
155
154
  ```
156
155
 
156
+ ## Example: your own rain (three.js drops, a plain call or a module)
157
+ `weather({ rain })` is there if it fits. Your own effect of any kind is the same few steps: three.js builds it, a call adds it, a module only when something must clean up or swap it.
158
+
159
+ ```js
160
+ import { THREE } from 'threedog';
161
+ function makeRain({ count = 2000, area = 40, height = 20, speed = 18 } = {}) {
162
+ const pos = new Float32Array(count * 6); // one short line per drop
163
+ for (let i = 0; i < count; i++) pos.set([(i * 0.618 % 1 - 0.5) * area, i * 0.31 % 1 * height, (i * 0.754 % 1 - 0.5) * area], i * 6);
164
+ const geo = new THREE.BufferGeometry().setAttribute('position', new THREE.BufferAttribute(pos, 3));
165
+ const drops = new THREE.LineSegments(geo, new THREE.LineBasicMaterial({ color: 0x9fb8d0, transparent: true, opacity: 0.5 }));
166
+ drops.frustumCulled = false;
167
+ const step = dt => {
168
+ for (let i = 0; i < count; i++) {
169
+ const y = (pos[i * 6 + 1] - speed * dt + height) % height;
170
+ pos[i * 6 + 1] = y; pos[i * 6 + 3] = pos[i * 6]; pos[i * 6 + 4] = y + 0.4; pos[i * 6 + 5] = pos[i * 6 + 2];
171
+ }
172
+ geo.attributes.position.needsUpdate = true;
173
+ };
174
+ return { drops, step };
175
+ }
176
+
177
+ // A plain call is enough when the rain stays for the whole game
178
+ const rain = makeRain();
179
+ engine.scene.add(rain.drops);
180
+ engine.onFrame(rain.step);
181
+
182
+ // A module when it can leave or be swapped: the same code, the callbacks go through ctx.track
183
+ const rainEffect = o => ({ name: 'rain', install(e, ctx) {
184
+ const r = makeRain(o);
185
+ e.scene.add(r.drops);
186
+ ctx.track(e.onFrame(r.step));
187
+ ctx.track({ remove: () => e.remove(r.drops) });
188
+ } });
189
+ engine.use(rainEffect({ count: 4000 }));
190
+ ```
191
+
192
+ The engine then does the rest: `engine.unuse('rain')`, a failed install or `{ replaces }` runs what `ctx.track` holds, and two modules of one name or two owners of one slot are refused with the fix. A value that others change too (rain slowing the player) goes through `ctx.mod`.
193
+
194
+ ## Example: wet stone in rain (the engine gives the signal, the game decides)
195
+ The weather module knows how hard it rains. It does not know what your stone looks like wet, or whether wet stone is slick: those are this game's look and this game's rule.
196
+
197
+ ```js
198
+ import { THREE } from 'threedog';
199
+ const stone = new THREE.MeshStandardMaterial({ color: 0x777066, roughness: 0.9 });
200
+ engine.onFrame(() => { stone.roughness = 0.9 - 0.6 * engine.uniforms.uRain.value; }); // the look: the game's material reads the rain
201
+
202
+ let slick = null; // the rule, if the game wants one: in game time, through the shared value
203
+ engine.onFixed(() => {
204
+ const wet = (engine.weather?.current.rain ?? 0) > 0.5 && engine.groundType(engine.player.position) === 'stone';
205
+ if (wet && !slick) slick = engine.mod('move.speed', { owner: 'wet-stone', id: 'player', mul: 0.8 });
206
+ if (!wet && slick) { slick.remove(); slick = null; }
207
+ });
208
+ ```
209
+
157
210
  ## Code-built models: what three.js already has
158
211
  Models written in code (recipe 05, 2a) mostly need helpers three.js ships; import them inside the model generator, so the result is cached and baked with the model.
159
212
  `three`: `LatheGeometry`, `TubeGeometry`, `ExtrudeGeometry` (`extrudePath`), `ShapeGeometry`, `InstancedMesh`, `BatchedMesh`, `CanvasTexture`. `three/addons`: `BufferGeometryUtils` (`mergeGeometries`, `mergeVertices`, `toCreasedNormals`),
@@ -26,6 +26,7 @@ Current camera (one of followCamera / firstPersonCamera / fixedCamera / rtsCamer
26
26
  - `mouseLook?: boolean` false: the built-in mouse / stick look and wheel zoom are off, the game drives the view with setView() (default true)
27
27
  - `hideTargetNear?: number` Hide the followed object from the camera when the camera is closer than this to the look point (meters, 0 = never; default 0.9). The shadow stays
28
28
  - `hideLayer?: number` Layer used to hide the followed object (0-31), default 30
29
+ - `pixelSnap?: { pixelsPerMeter, bounds? }` Art-pixel rounding, orthographic only: rounds the camera on screen axes, clamps to bounds there first, and decides the view height (buffer height / pixelsPerMeter), so no size with it. Recipe 62 section 4b
29
30
  - firstPersonCamera options `FirstPersonCameraOptions`:
30
31
  - `height?: number` Eye height above the feet (meters), default 1.6
31
32
  - `sensitivity?: number` Mouse sensitivity, default 1
@@ -44,6 +45,7 @@ Current camera (one of followCamera / firstPersonCamera / fixedCamera / rtsCamer
44
45
  - `smoothing?: number` (experimental) Smoothing of the camera following the body
45
46
  - `invertY?: boolean` (experimental) Invert vertical
46
47
  - fixedCamera options `FixedCameraOptions` (also includes the fields of Partial<CameraShot>):
48
+ - `pixelSnap?: { pixelsPerMeter, bounds? }` Art-pixel rounding, orthographic only: rounds the camera on screen axes, clamps to bounds there first, and decides the view height (buffer height / pixelsPerMeter), so no size with it. Recipe 62 section 4b
47
49
  - `shots?: Record<string, CameraShot>` Shots: name → shot
48
50
  - `start?: string | null` Initial shot name
49
51
  - `auto?: false | 'nearest'` Automatic switching: false / 'nearest' (pick the one nearest to the player)
@@ -86,6 +88,7 @@ Current camera (one of followCamera / firstPersonCamera / fixedCamera / rtsCamer
86
88
  - Properties:
87
89
  - `kind: CameraKind` Current kind (the first argument of engine.setCamera)
88
90
  - `target: Object3D | null` The object being followed
91
+ - `pixelSnap?: { grid, error, agrees, bounds } | null` The pixelSnap option at work, or null: grid (give it to pixelSprite), error (last rounding in art pixels), agrees (false: something else set the view height, rounding stopped)
89
92
  - followCamera only: every item of the options (the options of `followCamera`) can be read and written at runtime, e.g. `engine.cameraRig.yaw = 1.2`, `pitch`
90
93
  - `cam.frame(target: Object3D | Vec3Like | null, opts?: { strength?: number })` — Lock-on framing: turn yaw each frame toward "behind the followed object, looking at target"; mouse yaw is ignored meanwhile; null hands yaw back. strength default 6 (1/s)
91
94
  - `cam.setView(view: { yaw?, pitch?, distance? })` — Set the view from game code: pitch is clamped to minPitch..maxPitch, distance to the zoom range. Negative pitch looks up. Pair with mouseLook: false to own it every frame