threedog 0.8.0 → 1.0.1

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 +223 -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
@@ -43,7 +43,7 @@ Both functions run in workers, so they are **pure**: they see only their paramet
43
43
 
44
44
  ## 2. Changing the ground: `engine.terrain.edit`
45
45
  ```js
46
- const at = { x: 12, z: 20 };
46
+ const at = [12, 0, 20]; // an op's 'position' argument is [x, y, z]
47
47
  engine.ops.define('ground.dig', { args: { at: 'position' }, run(e, a) { e.terrain?.edit(a.at, { radius: 3, lower: 1.5 }); } });
48
48
  engine.ops.define('ground.level', { args: { at: 'position' }, run(e, a) {
49
49
  e.terrain?.edit(a.at, { shape: 'square', radius: 6, flatten: e.surface(a.at) }); // a flat foundation at the height of its center
@@ -155,7 +155,7 @@ Limits:
155
155
  `engine.vegetation`: species, placement, tree collision, felling) and the picture (`engine.terrainDraw`, slot `'terrain-draw'`;
156
156
  `engine.vegetationDraw`, slot `'vegetation-draw'`). Collision, paths, `engine.surface`, `instanceAt` and saves read only the data, so a game that
157
157
  replaces a picture keeps all of play. A picture listens to the data part's `view` hooks and never changes the data:
158
- ```js
158
+ ```js fragment
159
159
  engine.use({ name: 'myGround', type: 'picture', provides: ['terrain-draw'], install(e, ctx) {
160
160
  const meshes = new Map();
161
161
  ctx.track(e.terrain.view({
@@ -196,7 +196,7 @@ ground-type weight, spawn density, a walkable mask, danger, travel cost.
196
196
  `interp` is the picture between nodes, and none of them is the right one: `'nearest'` for terraces, blocky ground, tile masks and ids; `'linear'` (default) for most fields;
197
197
  `'cubic'` for slopes without cell creases, which can overshoot beside a sharp step (`clamp: true` keeps it inside the four corner values).
198
198
 
199
- ```js
199
+ ```js fragment
200
200
  const g = await engine.assets.gridFromImage('/maps/height16.png', { range: [-5, 60] }); // meters, 16-bit file
201
201
  const heightAt = sampleGrid(g.data, { ...g, size: [512, 512], origin: [-256, -256], interp: 'cubic', clamp: true });
202
202
  heightAt(10, 20); // gameplay side: where to put a camp, a mine, a lighthouse
@@ -64,7 +64,7 @@ used by `toCell`, `toWorld`, tiles and flatness (footprints stay rectangles of c
64
64
 
65
65
  ## 3. Layers: per-cell state (soil, creep, paint)
66
66
  ```js
67
- const soil = plot.layer('soil'); // created on first use; saved with the game (only cells that differ from content)
67
+ const soil = plot.layer('soil', { tiles: true }); // created on first use, options read then; saved with the game (only cells that differ from content)
68
68
  engine.ops.define('plot.till', { args: { cell: 'any' },
69
69
  can: (e, { cell }) => (!plot.inside(cell) ? 'outOfBounds' : plot.at(cell) ? 'occupied' : true),
70
70
  run: (e, { cell }) => soil.set(cell, { tilled: true }) });
@@ -66,8 +66,7 @@ are the record's own.
66
66
  its changes by id, and an index id (`<template>:<index>`, `pickup:<item>:<index>`) moves to another entry when one is inserted above it. Without one,
67
67
  dev warns once per load and names the id to write. Pure decoration may keep its index id. Two entries with the same id in one load throw with the fix;
68
68
  an authored id may not contain `#` or `/` (those are kept for records made during play and for level nodes). Places computed from the seed (a flat
69
- spot near the river) stay in code and come in through `content.load(data, { places })`. Records made during play are numbered `<kind>#<n>`
70
- (`chest#4`), so they never meet an authored id.
69
+ spot near the river) stay in code and come in through `content.load(data, { places })`.
71
70
 
72
71
  **Writing the ids, renaming them.** `threedog content ids [-w game]` lists each stateful entry that still relies on its index id with the id it
73
72
  has now (`-`/`+` lines, dry run); `--write` writes them into the content files. Writing today's id changes nothing for old saves. To give an entry a
@@ -80,8 +79,9 @@ and drops `prop:rock:12`'s data quietly. `npm run check` errors on a target no e
80
79
  orphan near an existing id with the exact pair to add.
81
80
 
82
81
  **Physics props.** `body: { shape: 'box' | 'ball' | 'hull', mass, friction?, restitution?, damping?, angularDamping? }` in a definition makes each
83
- copy a rigid body (needs `rigid()`). The copy rests on the ground asleep until something hits it; then the record follows the model, so a pushed
84
- crate's place is saved like any other change.
82
+ copy a rigid body (needs `rigid()`). The copy rests on the ground asleep until something hits it; then the record follows the body, and a save keeps
83
+ the crate's place like any other change, with its turn, speed and sleep in the save part `rigid` under the record id. A load puts it back as it was, in
84
+ the air if it was falling. A copy nothing has touched stays out of the save, however it settled on the ground.
85
85
  ```js
86
86
  // content/templates.js
87
87
  export default { crate: { model: 'crate', body: { shape: 'box', mass: 2 } } };
@@ -89,9 +89,8 @@ export default { crate: { model: 'crate', body: { shape: 'box', mass: 2 } } };
89
89
 
90
90
  **Grid items and level nodes.** A props entry `{ id: 'bed-home', grid: 'farm', item: 'bed', cell: [4, 4], rotation: 1 }` is the record `grid.place`
91
91
  would make, as authored data (the grid comes from the content key `grids`, `{ farm: { cell: 1, origin: [0, 0], size: [16, 12] } }`, or
92
- `engine.grids.add`). In a level model, a node with the Blender custom property `template = 'door'` becomes an instance of that template (its other
93
- custom properties fill the template's state), and one with `id = true` becomes a record of kind `levelNode` whose model is the node itself. Their id
94
- is `<level file name>/<node name>`, for example `town/door_front` (recipe 10).
92
+ `engine.grids.add`). In a level model, a node tagged `template = 'door'` becomes an instance of that template and one tagged `id = true` a record of kind `levelNode`, with id
93
+ `<level file name>/<node name>` (recipe 10).
95
94
 
96
95
  At runtime (inside an op or a fixed step), `engine.content.spawn(name, at, fields)` places a new instance and returns its record (without `fields.id`
97
96
  the id is numbered `<template>#<n>`, for example `chest#3`):
@@ -136,7 +135,7 @@ export default {
136
135
  **Many placements: split a kind into a folder.** Any content kind may be a folder instead of one file: `content/props/<area>.js`… (by area,
137
136
  by theme, as you like). The parts are joined in file-name order; in `content/index.js` write `const props = contentParts(import.meta.glob('./props/*.js', { eager: true }));`
138
137
  (`import { contentParts } from 'threedog'`). An id must be unique across all parts (the content check names both files). The content check hints at splitting past
139
- about 2000 entries in one file; it also writes `.threedog/content-index.json` (id -> file:line), so `threedog content set/add/remove` opens only the one part it edits.
138
+ about 2000 entries in one file; it also writes `.threedog/content-index.json` (id -> file:line), so `threedog content set/add/remove` opens only the one part it edits. After a hand edit or a rename the next write rebuilds it first, and refuses while a content file does not load.
140
139
  Add new entries at the end of a part with a written id: an entry without an id gets its position in the joined list, which an insert above it would shift.
141
140
 
142
141
  ## 3. What belongs to the definition, what to the instance
@@ -175,9 +174,7 @@ Plain three.js or a template: recipe 40 sections 1 and 2 decide. Game code keeps
175
174
  `engine.content.spawn`, `pickups.spawn` or `npcs.add` at module top level or in an `engine:ready` / `level:loaded` / `session:start`
176
175
  handler, because those are saved whole and the startup code would make a second copy after every load. Error: `world.add(…, { initial: true })`
177
176
  anywhere, which corrupts what saves compare against. Warning: code that `engine.add`s a `world.view(id)` model or writes its position / rotation / scale (world puts it back every frame).
178
- The fix is a placement in content, or an op. Places computed from the seed (a flat spot for `home`) stay in code and are passed as `places` to
179
- `content.load`; a mesh built in code becomes a model by name (`engine.assets.manifest({ models: { cabin } })`) when you want it as a template.
180
- A line that really must do it from code at startup carries `// runtime: <reason>`.
177
+ The fix is a placement in content, or an op; a mesh built in code becomes a model by name (`engine.assets.manifest({ models: { cabin } })`) when you want it as a template.
181
178
 
182
179
  ## 7. A group of things
183
180
  A market stall, a gun nest, a pit lane, a shop shelf, a puzzle room: several things that belong together. Content stays flat. Each thing is its own plain
@@ -219,6 +216,6 @@ export default [
219
216
  ```
220
217
  Copied to `stall-1`, part `chest` becomes `{ id: 'stall-1-chest', template: 'chest', place: 'stall-1', x: 1, source: 'stall' }`.
221
218
 
222
- **Deleting.** Delete an entry and a save that changed it still loads: the change is an orphan, kept in the save, listed in `engine.describe().world.orphans` and warned
223
- about once; the `renames` content file says where it went (`null` = deleted on purpose). Delete a place and `threedog check` names every entry still standing on it; the
219
+ **Deleting.** Delete an entry and a save that changed it still loads: the change is an orphan (recipe 20, "Orphans are kept");
220
+ the `renames` content file says where it went (`null` = deleted on purpose). Delete a place and `threedog check` names every entry still standing on it; the
224
221
  load refuses it too (`content-place`), because an entry with no place has no position.
@@ -35,7 +35,7 @@ Buses are real Web Audio `GainNode`s: `master`, `music`, `sfx`, `ambience`, `ui`
35
35
  `engine.audio.addBus('voice')`). `engine.audio.setVolume('music', 0.3)` sets one; `engine.audio.buses.sfx` is the node to connect your own nodes to, and `buses.master` (also `audio.master`) is the total. `buses` is empty until audio
36
36
  unlocks on the player's first click or key: build your own nodes on the `audio:ready` event. A name that is no bus warns once and gives `master`, so the sound still plays.
37
37
 
38
- ```js
38
+ ```js fragment
39
39
  engine.audio.sfx('door'); // plays on its bus (default sfx)
40
40
  const h = engine.audio.sfx('shot', { at: enemy.root }); // 3D: a PannerNode that follows the Object3D every frame
41
41
  const hum = engine.audio.sfx('engine-hum', { loop: true, at: [4, 0, 2] });
@@ -117,7 +117,7 @@ export default {
117
117
  footsteps: { beach: 'step.sand', default: 'footstep' },
118
118
  };
119
119
  ```
120
- ```js
120
+ ```js fragment
121
121
  engine.assets.manifest({ name: 'sfx', base: '/sounds/', sounds: { door: 'door.ogg', hit1: 'hit1.ogg', hit2: 'hit2.ogg', shot: 'shot.ogg', 'music-day': 'day.ogg' } });
122
122
  engine.content.load([base, forest]); // each pack's audio merges in
123
123
  ```
@@ -23,6 +23,8 @@ working example is `examples/action/` (page `/action.html`, the rules in `main.j
23
23
  or test shapes instead (recipe 19).
24
24
  - `player.die` decides what death does. The example offers `respawn` (`player.placeAt(spawn)`, full hp), `restart` and `gameover` (both end in
25
25
  `engine.session.newGame()`, which is async flow and so runs from the frame hook, not inside the op).
26
+ - What a fight sets up, falling undoes. `respawn` leaves the world as it was, so a closed arena gate, a blocked area, a locked camera or a boss phase is still there when the player returns, and a spawn point can end up inside ground that is no longer walkable. Keep one function that undoes the fight and call it from `player.die`; a win calls it too.
27
+ - A blow that ends a contact ends it for both sides: a stomp, a dash through or a parry needs a short window in which that enemy cannot hurt the player, or its touch damage lands the step after. Each of these gets a scenario that loses as well as one that wins (recipe 16 section 2b).
26
28
  - Win and lose are the game's rule too: one state field, judged last in the fixed step so it sees this step's hits. The end screen is a `makeWindow`
27
29
  with `closable: false` (recipe 26).
28
30
 
@@ -42,8 +44,8 @@ looks, so a swing goes where you aim. The rules do not need the picture: `?pictu
42
44
  `examples/action/picture/`.
43
45
 
44
46
  ## 4. Movement: jumps, speed effects, bullet time, platforms, falling
45
- ```js
46
- createPlayer({ ...presets.player.thirdPerson, maxJumps: 2 }); // double jump: the same jump key twice
47
+ ```js fragment
48
+ engine.characters.createPlayer({ ...presets.player.thirdPerson, maxJumps: 2 }); // double jump: the same jump key twice
47
49
  engine.player.launch(16, { owner: 'pad' }); // a jump pad / spring
48
50
  engine.mod('move.speed', { owner: 'haste', id: 'player', mul: 1.2, for: 5 }); // haste for 5 s; no id = every character (mud, wind)
49
51
  engine.time.channel('enemies'); // once, before anything uses it: a channel of your own
@@ -74,15 +76,14 @@ engine.player.mover = 'manual'; /* a cutscene, your own physics */ engine.player
74
76
  floor mesh, not the whole model: a group with a mast or a railing has its top up there, and the character passes under it to whatever is below (a
75
77
  boat at sea leaves it on the sea floor). A character gets on when its feet are at most `stepHeight` below the top, or it falls or is placed onto
76
78
  it (`placeAt` over a support stands on it). Moving the parent moves the floor mesh, so move the whole model as you like.
77
- ```js
79
+ ```js fragment
78
80
  const raft = new THREE.Group(), deck = new THREE.Mesh(new THREE.BoxGeometry(3, 0.2, 2), wood);
79
81
  raft.add(deck, mast); engine.scene.add(raft);
80
82
  engine.characters.support(deck, { id: 'raft' }); // the deck, not the raft with its mast
81
83
  engine.onFixed(dt => { raft.position.x += 1.5 * dt; }); // the player on it is carried
82
84
  ```
83
85
  A ride the player does not steer is `engine.control` instead (recipe 57, Moved by script).
84
- - **Falling out**: `createPlayer({ ..., fall: { belowY: -20 } })` fires `character:fall { character, safe, preventDefault() }` once and puts the player
85
- back on `player.safeGround` (the last spot it stood still on safe, unmoving ground; saved). Take hp in the listener; `preventDefault()` to handle it yourself.
86
+ - **Falling out**: `createPlayer({ ..., fall: { belowY: -20 } })` fires `character:fall { character, safe }` once. Take hp in the listener. The rule `fall` decides what happens, and the engine alone decides nothing: `engine.mod('fall', { owner: 'game', set: 'rescue' })` (or `characters({ fall: 'rescue' })`; `openWorld` and the new-game templates choose it) puts the player back on `player.safeGround`, the last spot it stood still on safe, unmoving ground (saved); `set: false` handles it yourself, a function `(facts, engine) => 'rescue' | false` decides per fall (`facts.kind` is `'character'` or `'body'`), and without `id` it covers everything that falls, rigid bodies below y = -200 too.
86
87
  - **Your own controller**: `mover: 'manual'` = you write the position; `move()` then only updates `grounded`, `support` (platforms still carry),
87
88
  `safeGround` and the fall check. Switch at any time (`player.mover = 'manual'` / `'simple'`): a cutscene, a grapple, a ladder.
88
89
  - **Knockback / dashes**: `player.push(vx, vz, seconds)`. Writing `player.velocity` or `player.vy` is an impulse: the mover keeps integrating from
@@ -12,8 +12,9 @@ list, the sources of `engine.stream`:
12
12
  | `engine.stream.camera` (built in: `engine.focus`) | full | no |
13
13
  | `engine.stream.source(p, { radius, detail, physics, until })` | `detail: 'full'` (default) or `'simple'` (terrain and hlod proxies only) | `physics` (default true for `'full'`) |
14
14
 
15
- ```js
15
+ ```js fragment
16
16
  // teleport: the player moves only after the destination's terrain, collision and nearby models are ready
17
+ // a new game or load during the trip abandons it: it rejects with code stream-removed and the player stays
17
18
  await engine.stream.teleport([800, 0, 300]);
18
19
 
19
20
  // the same by hand (for a door animation or a fade while it loads)
@@ -31,6 +32,8 @@ const vista = engine.stream.source(towerTop, { detail: 'simple', radius: 600 });
31
32
  - `radius` caps every loader's own range around that source (terrain view distance, present radius, `stream.radius`); without it each loader uses its own.
32
33
  - `source.ready` is checked at the end of each frame; a new source counts after one full frame, so every loader has seen it. Fixed steps must run
33
34
  (collision takes effect on a tick), so do not wait while `engine.haltLoop()` is on without stepping.
35
+ - `ready` means nothing is pending, not that everything built: a stream entry or world model whose build failed is reported and left out, and `teleport` still lands. Need a thing built?
36
+ Check it yourself: `handle.built`, `engine.world.view(id)`. A failed terrain chunk (recipe 28) is different: no ground, never ready, `teleport` ends in `stream-timeout`.
34
37
  - Leaving a place and coming back is safe: models unload, but records (an opened chest, a dropped item, a removed rock) stay in `engine.world` and the
35
38
  models are rebuilt from them.
36
39
  - Module authors with their own distance-based loader: read `engine.stream.sources({ detail: 'full' })` / `sources({ physics: true })` and
@@ -31,8 +31,7 @@ engine.onRender(() => { // a fog
31
31
  ```
32
32
  There is no fog until your code makes one, and nothing writes it after that.
33
33
 
34
- - Signals to read: `uSkyHorizon` is the color at the horizon, so fog in that color hides the line where the dome meets the ground; `uWeatherFog` is what the weather asks for, a
35
- multiplier your code applies; `uViewDistance` says how far the world is meant to be seen (`terrain({ viewFog: true })` writes it).
34
+ - 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.
36
35
  - 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.
37
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.
38
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`:
@@ -50,7 +49,7 @@ The engine picks no curve: `renderer.toneMapping` stays three.js's default (`NoT
50
49
  ## Environment maps
51
50
  `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.
52
51
 
53
- ```js
52
+ ```js fragment
54
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
55
54
  engine.scene.environmentIntensity = 0.8; // intensity and rotation are three.js
56
55
  engine.scene.environmentRotation.y = Math.PI / 2;
@@ -82,7 +81,7 @@ The engine's neutral materials are Lambert, so this is what most surfaces do by
82
81
  ## Light probes (baked indirect light)
83
82
  An environment map lights everything as seen from one point. Light probes (`engine.bakeProbes`) record how the light changes from place to place (a colored glow beside
84
83
  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.
85
- ```js
84
+ ```js fragment
86
85
  const probes = await engine.bakeProbes({ bounds: { min: [-30, 0, -30], max: [30, 8, 30] }, spacing: 4, include: o => !o.userData.moving });
87
86
  const file = JSON.stringify(probes.toJSON()); // ship this (half precision, a few tens of KB)
88
87
  const shipped = engine.loadProbes(json); // at start-up, instead of the bake; either renderer reads either renderer's file
@@ -103,7 +102,7 @@ probes.remove();
103
102
 
104
103
  ## Lightmaps (baked light on what never moves)
105
104
  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.
106
- ```js
105
+ ```js fragment
107
106
  floor.userData.static = true; wall.userData.static = true; // named meshes that never move
108
107
  // npx threedog bake light --page "/?bake=1" --out public/light/level.lightmap --size 1024
109
108
  const baking = new URLSearchParams(location.search).has('bake'); // the bake must see the lights the map replaces
@@ -124,7 +123,7 @@ floor.material.lightMapIntensity = 1.2; // plain thre
124
123
 
125
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.
126
125
 
127
- ```js
126
+ ```js fragment
128
127
  import { voxelGI, temporalAA } from '@threedog/post-effects/tsl';
129
128
  engine.post.add(voxelGI({ bounds: new THREE.Box3(min, max), intensity: 1 }));
130
129
  engine.post.add(temporalAA()); // clears the dots; it replaces MSAA while it is on
@@ -151,7 +150,7 @@ What runs where, for `voxelGI` and the three effects around it (`temporalAA`, an
151
150
 
152
151
  Pick by the light. These two are WebGPU only; a WebGL game keeps the depth haze of recipe 59.
153
152
 
154
- ```js
153
+ ```js fragment
155
154
  import { sunShafts, lightVolumes } from '@threedog/post-effects/tsl';
156
155
  engine.post.add(sunShafts({ light: engine.lights.sun })); // sun through gaps
157
156
  engine.post.add(lightVolumes({ bounds: new THREE.Box3(min, max) })); // spot cones, point glows
@@ -166,6 +165,6 @@ engine.post.add(lightVolumes({ bounds: new THREE.Box3(min, max) })); // spot
166
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.
167
166
 
168
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.
169
- - Hidden things stay in shadows, in `engine.rays` and in `voxelGI`'s volume, and `visible` stays yours. Nothing else sees them while hidden: a second camera of yours and a `THREE.Raycaster` of your own do not (their layers lack it; enable `RESERVED_LAYERS.occlusionHidden` from `threedog/layers` if they must).
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.
170
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.
171
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.
@@ -67,21 +67,25 @@ world (a canyon instead of hills), say so instead of faking it with colors.
67
67
  The first frame should already be close: if it is far from the reference, fix sky, exposure, palette and material type before adding anything.
68
68
  5. **Check.** `npm run check` type-checks `picture/`, and a misspelled option or a bad call fails on the page with a line in `.threedog/errors.log`.
69
69
  6. **Picture: the loop above.** Take pictures with the same arguments every round so only the picture differs, from named places (`shot --at <place>`), not free `--pos` shots.
70
- `picture compare` prints brightness, saturation, contrast, fine detail, average and main color of both and one sentence such as "the screenshot is darker and more broken up", with deliberately no
71
- "similarity %". Dirty = lower saturation or an off hue, fragmented = fine detail ratio well above 1, dark or flat = brightness and contrast. Keep a change if its number moved toward
70
+ `picture compare` prints the differences as numbers and one sentence such as "the screenshot is darker and more broken up".
71
+ Dirty = lower saturation or an off hue, fragmented = fine detail ratio well above 1, dark or flat = brightness and contrast. Keep a change if its number moved toward
72
72
  the reference and the picture looks better. A phone UI frame in the screenshot skews the numbers: compare a `--region`.
73
73
  `--out side.png` (MCP `picture_compare` always writes `<shot>.compare.png`) is one image, reference left, screenshot right.
74
74
  7. **Stop** when the biggest remaining difference is a silhouette or a world rule: that is the assets or the game, not the picture code.
75
75
 
76
76
  ## Picture check after every shot
77
- Every `threedog shot` prints picture numbers and hints (`--no-picture` skips them). The numbers are luminance, contrast (std and p5-p95 range of
78
- luminance), saturation, clipped and near-black shares, and the shadow area. Hints come in three kinds:
77
+ Every `threedog shot` prints picture numbers and hints (`--no-picture` skips them). The numbers are mean luminance, contrast (std and p5-p95 range of
78
+ luminance), saturation, clipped-white and near-black shares, the shadow area and how much shadows darken. Hints come in three kinds:
79
79
  - **Contradictions**, whatever the art direction: the settings say one thing and the pixels another. Shadows on but none measurable (with the cause it found:
80
- the light's `shadow.bias` as meters of shadow depth, the view outside the shadow box, texel size, or fill light washing them out), a light that changes
80
+ the light's `shadow.bias` as meters of shadow depth, the view outside the shadow box, texel size, or fill light washing them out), a light the game added that changes
81
81
  no pixel.
82
- - **Facts**: measured, maybe wanted, with what sets them: glare, large clipped or near-black areas, a night that is not dark from lighting (and
83
- whether the brightness at 00:00 is lighting at all), the key / fill balance. Each becomes a contradiction only where DESIGN.md declares the
84
- opposite.
82
+ - **Facts**: measured, maybe wanted, with what sets them. Each becomes a contradiction only where DESIGN.md declares the opposite (the `Picture intent:` word in brackets):
83
+ glare, naming each light or glowing material that blows pixels out with its current values and the detail lost under it, and large clipped areas (`no-glare`);
84
+ large near-black areas (`no-pitch-black`); time of day that barely changes the picture or a night not dark from lighting, and whether the brightness at 00:00 is lighting at all
85
+ (renders 12:00 and 00:00 when the game runs calendar + sky or the shot sets `--time`; `dark-nights`); `light:` the share of the lit brightness from the sun / key and from the fill
86
+ (each turned off once) and how much darker shadowed areas are (`strong-light`); the camera standing inside a closed mesh; a black frame, naming the material whose hiding alone
87
+ brings the picture back (newest materials first; a ShaderMaterial is told the usual NaN / Inf causes, and shader programs that failed to compile are listed); fog that is most of
88
+ the color in a large share of the picture, with its near / far and color.
85
89
  - **Intent**, only against what the game declared: DESIGN.md's optional `Picture intent:` line (listed words such as `no-glare`, `dark-nights`,
86
90
  `strong-light`, `muted`; the template lists them all; the table's free text is not read), or the reference given with `--ref`. A muted,
87
91
  low-contrast game is told when its shot measures saturated and contrasty, never the other way round unless it said so. No declaration and
@@ -136,5 +140,5 @@ wood / stone / metal surfaces, a lit room (outside and inside) and the UI parts,
136
140
  A production build of the vite preset gets a stub instead (no panel, no tweakpane in the bundle); dev and test builds get the real one.
137
141
  It reads the three.js objects and writes them directly: exposure, `scene.fog`, each light, `engine.water` / `terrain` / `vegetation` materials and uniforms
138
142
  (when installed), a material picked by name, `engine.uniforms`, post effects, UI colors. "write back" saves the changes to
139
- `.threedog/tune.json` on the dev server; then `threedog tune write <file>` prints the code change as a diff (one `// threedog:tune begin ... end` block
143
+ `.threedog/tune.json` on the dev server; then `threedog tune write <file>` prints the code change as a diff (one block
140
144
  of plain three.js writes) and `--apply` writes it. Review it, then keep the block or move each value where it belongs (`picture/palette.js`, the material's definition).
@@ -1,6 +1,7 @@
1
1
  # Ground color and plants
2
2
 
3
3
  ```js
4
+ import { terrainPreset } from '@threedog/terrain-noise';
4
5
  engine.use(terrain({ ...terrainPreset(), colors: { grass: 0x6a8a3a, rock: 0x777066 }, biomeColors: { meadow: ['grass'], cliff: ['rock'] } }));
5
6
  engine.terrain.material.flatShading = true; // the ground's picture is a plain three.js material
6
7
  engine.terrain.recolor({ colors: { grass: 0xa8a050, rock: 0x777066 } }); // what the workers baked in, changed at run time
@@ -45,7 +46,7 @@ patch your material again; the engine only rebuilds its own.
45
46
 
46
47
  Chunk geometry has `position`, `normal`, `color` and `uv = world xz / chunk size`, continuous across chunk borders, so a repeating texture is seamless whatever chunk it lands in. `texture.repeat.set(8, 8)` = 8 tiles per chunk. Without
47
48
  UVs (steep sides stretch a top-down map), project from the world position in a patch instead (`needs.patches: ['world']` gives `vThreedogWorld`):
48
- ```js
49
+ ```js fragment
49
50
  engine.terrain.material = applyEffects(new THREE.MeshLambertMaterial({ vertexColors: true }), { clouds: false, patches: [{
50
51
  name: 'triplanar', needs: { patches: ['world'] }, uniforms: { uTex: { value: groundTexture }, uTexScale: { value: 0.1 } }, // groundTexture: repeat wrapping
51
52
  glsl: { fragment: { pars: 'uniform sampler2D uTex; uniform float uTexScale;',
@@ -62,7 +63,7 @@ The lighter alternative, with no material of your own: `terrain({ detail })`, or
62
63
  ## Plants and wind
63
64
  `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
64
65
  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`.
65
- ```js
66
+ ```js fragment
66
67
  engine.vegetation.define('oak', { model: await engine.assets.model('oak'), wind: 0.02 }); // per species: its own material, wind, fade
67
68
  engine.vegetation.define('fern', { geometry, material: new THREE.MeshToonMaterial({ vertexColors: true }), wind: 0.08 });
68
69
  engine.vegetation.material = applyEffects(new THREE.MeshToonMaterial({ vertexColors: true }), { patches: engine.vegetation.patches }); // the shared default
@@ -23,7 +23,7 @@ A scene object comes in either of two ways, and both end up in the same scene:
23
23
 
24
24
  The same windmill, both ways:
25
25
 
26
- ```js
26
+ ```js fragment
27
27
  // A. plain three.js: your code builds it on every start
28
28
  const mill = buildWindmill(); // THREE.Group
29
29
  mill.position.set(20, 0, -10);
@@ -41,7 +41,7 @@ export default { windmill: { model: 'windmill', collide: 'circle' } };
41
41
  // content/props.js
42
42
  export default [{ id: 'windmill-hill', template: 'windmill', x: 20, z: -10 }];
43
43
  ```
44
- ```js
44
+ ```js fragment
45
45
  // main.js: a code-built model registered by name
46
46
  engine.assets.manifest({ models: { windmill: buildWindmill } });
47
47
  ```
@@ -75,15 +75,15 @@ inside an op with `engine.content.spawn(name, at)`: a record is saved whole.
75
75
 
76
76
  ## 4. Give it an id
77
77
  ```js
78
- const windmill = buildWindmill(); // any Object3D
78
+ const windmill = new THREE.Group(); // any Object3D
79
79
  engine.add(windmill, { id: 'windmill' }); // at setup: thing.set / thing.remove changes to it are saved
80
- engine.add(spark); // effects need no id: obj#7, this session only
80
+ engine.add(new THREE.Group()); // effects need no id: obj#7, this session only
81
81
  engine.thing('windmill');
82
82
  // { id: 'windmill', kind: 'Group', owner: 'game', at: 'main.js:50', phase: 'setup', saved: 'code',
83
83
  // keeps: ['position, rotation, scale, visibility and removal made with thing.set / thing.remove (scene save part)'],
84
84
  // loses: ['geometry and material changes', 'children added later', 'userData', ...], edit: 'added by code at main.js:50 (id ...)' }
85
85
  engine.thing('windmill').object; // the live Object3D (not enumerable, so the result stays JSON-able)
86
- engine.thing(engine.pick(0, 0).object).id; // any child resolves to its registered root; hit.thing says the same
86
+ engine.pick(0, 0)?.thing; // any child resolves to its registered root
87
87
  ```
88
88
  - 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
89
  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.
@@ -98,7 +98,8 @@ engine.thing(engine.pick(0, 0).object).id; // any child resolves to its
98
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]
99
99
  const r = engine.ops.run('thing.set', args);
100
100
  engine.ops.undo('thing.set', args, r.value); // back where it was
101
- engine.ops.run('thing.remove', { id: 'windmill' }); // detached and kept: undo puts it back
101
+ const gone = engine.ops.run('thing.remove', { id: 'windmill' }); // detached and kept: undo puts it back
102
+ engine.ops.undo('thing.remove', { id: 'windmill' }, gone.value);
102
103
  ```
103
104
  - A world record id turns into `world.set` / `world.move` (`rot` / `scale` are template instance fields) and `world.remove`; the model follows the
104
105
  record. `visible` is refused for a record (`recordVisible`): hide its model with `present({ show })` and a field.
@@ -152,15 +153,15 @@ Plain three.js is always allowed (`engine.scene`, `engine.renderer`, `engine.cam
152
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).
153
154
  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.
154
155
 
155
- ## 9. One id, everything: explain() and the three kinds of change
156
+ ## 9. One id, everything: explain and the three kinds of change
156
157
  ```js
157
- engine.thing('chest-home').explain(); // CLI: threedog thing chest-home (MCP: thing); the same JSON
158
+ engine.explain({ thing: 'chest-home' }).detail; // CLI: threedog explain thing chest-home --full (MCP: explain); the same JSON
158
159
  // { id, kind, owner, definition: { at: 'content/props.js:14', template, templateAt, level?, node?, spawned? }, model, materials: [{ role, name, from, keys }],
159
160
  // state, rules: { blocksMovement, pickable, interact, height }, ops: [{ op, desc, args }], saved: { tier, keeps, loses }, change: {…}, overrides? }
160
161
  ```
161
162
  `ops` lists the ops whose definition names this id, kind or template in the optional `targets` field (`engine.ops.define('chest.toggle', { targets: 'chest', … })`;
162
163
  `'*'` = any thing, which `thing.set` / `thing.remove` use). `definition.at` is null in release builds and for code run without a file (page `eval`).
163
- `thing.explain()` (type `ThingExplanation`) is not `engine.explain({ op | quest | … })`: that one takes a question and answers `{ ok, text }` about why an op or quest cannot run now (recipe 23); this one takes no question and returns the facts about one id. `rules.blocksMovement` is the template's / prop's `collide` shape; the engine does not model blocking sight. Pick the kind of change first:
164
+ `text` says in one line where the id comes from and how to change it for good; `detail` has type `ThingExplanation`. The same `engine.explain` answers an op, a quest, a value, a module and a capability (recipe 23).
164
165
 
165
166
  | Kind | How | Lasts |
166
167
  |---|---|---|
@@ -170,7 +171,7 @@ engine.thing('chest-home').explain(); // CLI: threedog thing chest-home (MCP:
170
171
 
171
172
  ```js
172
173
  const h = engine.debug.override('ai-session', 'windmill', { material: 'flat' }); // unlit base colour: is the colour wrong, or the light?
173
- engine.debug.override('ai-session', 'fence', { visible: false });
174
+ engine.debug.override('ai-session', engine.player.root, { visible: false });
174
175
  engine.debug.override('ai-session', engine.renderer, 'toneMappingExposure', 3); // any three.js value: (object, key, value); held above picture code until remove()
175
176
  engine.describe().scene.overrides; // [{ owner, target, material: 'flat' }, …]: the screen differs from the real state while this is non-empty
176
177
  h.remove(); engine.debug.clear('ai-session'); // clear removes every override of that owner (and its debug.view) and nothing else
@@ -5,7 +5,7 @@
5
5
  A new game draws on WebGPU, where shaders are TSL: start with [recipe 56](56-webgpu-tsl.md), whose node materials and `tsl:` patch fields do these same jobs. This page is the GLSL route, for a game made with `threedog new-game --webgl`: **write your own material or `ShaderMaterial`**, or **patch a slot** of any material with your own GLSL. The picture is the
6
6
  game's own; this page gives building blocks, not finished pictures. There is one entry for shader code: `applyEffects`.
7
7
 
8
- ```js
8
+ ```js fragment
9
9
  const fragmentShader = '#include <threedog_lighting>\n' + myFragmentBody; // 3. engine GLSL, called inside 1 or 2
10
10
  const mat = new THREE.ShaderMaterial({ uniforms: { ...engine.uniforms }, vertexShader, fragmentShader }); // 1. your own shader
11
11
  applyEffects(mat2, { patches: [{ name: 'tint', slot: 'color', glsl: 'diffuseColor.rgb *= 0.9;' }] }); // 2. patch a slot
@@ -24,8 +24,8 @@ engine.water.material = applyEffects(new THREE.MeshPhongMaterial({ color: 0x3070
24
24
  ## Patch a slot: your own GLSL
25
25
  Write a **named patch** that names a **slot** (where the code goes) and add it with `applyEffects(material, { patches: [...] })`:
26
26
  ```js fragment
27
- { name: 'tint', slot: 'color', glsl: 'diffuseColor.rgb *= 0.9;' } // one slot
28
- { name: 'sway', slot: 'position', shadow: true, glsl: 'transformed.x += sin(position.y) * 0.1;' } // moves vertices: the shadow follows
27
+ { name: 'tint', slot: 'color', glsl: 'diffuseColor.rgb *= 0.9;' }, // one slot
28
+ { name: 'sway', slot: 'position', shadow: true, glsl: 'transformed.x += sin(position.y) * 0.1;' }, // moves vertices: the shadow follows
29
29
  { name: 'glow', pars: 'uniform float uGlow;', uniforms: { uGlow: { value: 0.5 } },
30
30
  glsl: { color: 'diffuseColor.rgb *= 0.95;', output: 'outgoingLight += uGlow * 0.1;' } } // several slots; pars = declarations
31
31
  ```
@@ -90,7 +90,7 @@ Patches on one material must agree. Each patch declares what it relies on, and a
90
90
  | `uniforms` | A uniform name belongs to one patch; share `engine.uniforms` (`uTime`, `uWind`, `uWeatherCloud`...) instead of making your own `uTime` | when added |
91
91
  | `shadow` | Render steps: without it the color pass only; `true` also runs its vertex code in the depth (sun / spot shadows) and distance (point-light shadows) passes | - |
92
92
  | `cacheKey` | Changes whenever the GLSL text changes (defines, branches), never for uniform values; the program key joins every patch's `name=cacheKey` in order | same name + cacheKey with different code throws. On WebGPU the program also follows the identity of each `tsl` function, so make it once and reuse it: one written fresh per material costs a program per material |
93
- ```js
93
+ ```js fragment
94
94
  applyEffects(mat, { wind: 0.03, season: 'foliage', patches: [{ name: 'ripple', needs: { patches: ['world'] }, conflicts: ['wind'],
95
95
  slot: 'color', glsl: 'diffuseColor.rgb *= 0.9 + 0.1 * sin(vThreedogWorld.x);' }] }); // throws: 'wind' and 'ripple' cannot be combined
96
96
  ```
@@ -100,7 +100,7 @@ declarations at the top of that stage). A missing chunk throws when the patch is
100
100
  what is in scope. `worldPosition` exists after `worldpos_vertex` only when shadows, env maps or transmission need it.
101
101
 
102
102
  ### Engine effects in your own ShaderMaterial
103
- ```js
103
+ ```js fragment
104
104
  const mat = new THREE.ShaderMaterial({ uniforms: { ...engine.uniforms, uMine: { value: 1 } }, vertexShader, fragmentShader });
105
105
  ```
106
106
  The engine never patches a ShaderMaterial of yours; call its effects as functions instead (the automatic patches call the same ones):
@@ -148,13 +148,13 @@ Which channels (color, normal, roughness) are on is fixed when the material is m
148
148
  The ground takes the same object as `terrain({ detail })`, its live numbers are `engine.terrain.uniforms`; which detail suits which ground: recipe 53.
149
149
 
150
150
  **Light shaping** is a patch in the `lighting` slot, after the lights are summed. three has no "shadow color": a shadow only removes the sun's light. The ready-made form:
151
- ```js
151
+ ```js fragment
152
152
  applyEffects(mat, { lighting: { wrap: 0.4, shadowTint: { color: 0x4060a0, strength: 0.6, soft: 0.3 }, rim: { color: 0xffe0b0, strength: 0.4, power: 3, shadowSide: 0 } } });
153
153
  applyEffects(mat, { lighting: { glsl: 'void threedogLighting(inout ReflectedLight light, vec3 normal, vec3 viewDir, vec3 sunDir, float sunShadow, vec3 albedo){ ... }' } }); // your own function
154
154
  ```
155
155
  All numbers are uniforms, and materials with the same options share one program. Written by hand, the first directional
156
156
  light is the sun (three sorts shadow casters first), so a patch reads it there and calls `threedogRim`, `threedogWrapDiffuse` or `threedogShadowTint`:
157
- ```js
157
+ ```js fragment
158
158
  const rim = { name: 'rim', slot: 'lighting', pars: '#include <threedog_lighting>', glsl: `
159
159
  #if NUM_DIR_LIGHTS > 0
160
160
  float nl = dot(normal, directionalLights[0].direction);
@@ -66,7 +66,7 @@ engine.water.shader({
66
66
  (`myMaterial.normalMap = engine.water.normalTexture`); the tiling and the scroll run whatever material draws.
67
67
 
68
68
  ## Water: your own material (reflections, refraction)
69
- ```js
69
+ ```js fragment
70
70
  engine.water.material = applyEffects(new THREE.MeshPhongMaterial({ color: 0x3070a0, shininess: 90, specular: 0xaaaaaa, transparent: true, opacity: 0.85 }),
71
71
  { patches: engine.water.patches }); // keep the waves, the surface and the fresnel
72
72
  engine.water.material = new THREE.ShaderMaterial({ uniforms: engine.water.uniforms, vertexShader, fragmentShader }); // or all your own
@@ -125,7 +125,7 @@ you when one comes or goes, so swimming, buoyancy and anything else reading the
125
125
  ## Weather particles: rain and snow parameters
126
126
  `weather({ rain, snow })` (left-out keys keep the built-in picture):
127
127
 
128
- ```js
128
+ ```js fragment
129
129
  weather({ types,
130
130
  rain: { color: 0xa8b8d0, opacity: 0.6, length: 1.2, speed: 26, slant: 1.5, density: a => a * a }, // streaks; sparse in a drizzle
131
131
  // rain: { shape: 'soft', size: 10, maxSize: 6, sway: 0.3 }, // drops as soft sprites instead of streaks
@@ -135,9 +135,9 @@ weather({ types,
135
135
  ```
136
136
  The keys and defaults are `WeatherParticles` in `types/world.d.ts`. `density` decides how many particles show at a weather amount; opacity follows the amount as well. Coverage is `weather({ area })`.
137
137
 
138
- At run time each system is in `engine.weather.particles`, and every number is a plain write, live on both renderers:
138
+ At run time each system is in `engine.weather.particles`, and every number is a plain write, live on both renderers. `particles.rain` exists only when the weather table has a `rain` field (`particles.snow` likewise for `snow`); with a table of your own, read it as `particles.rain?.`:
139
139
  ```js
140
- const rain = engine.weather.particles.rain;
140
+ const rain = engine.weather.particles.rain, myFragment = 'void main() { gl_FragColor = vec4(0.7, 0.8, 1.0, 0.4); }';
141
141
  rain.spec.speed = 30; rain.spec.opacity = 0.3; rain.spec.slant = 2; // read each frame; density too
142
142
  rain.uniforms.uColor.value.set(0xa8b8d0); rain.uniforms.uLen.value = 1.2; // sprites: uPx (size), uMaxPx (maxSize), uSwayAmp (sway)
143
143
  rain.material = new THREE.ShaderMaterial({ uniforms: rain.uniforms, vertexShader: rain.material.vertexShader,
@@ -147,7 +147,7 @@ engine.weather.overcastColor.set(0x667788); engine.weather.lightningBrightness =
147
147
  The fall and the follow-the-camera wrap live in the vertex shader, so a material of your own shares `uniforms` and keeps a vertex shader like it.
148
148
 
149
149
  ## Weather particles: replace the shaders (GLSL)
150
- ```js
150
+ ```js fragment
151
151
  weather({ types, snow: { uniforms: { uTint: [1, 0.85, 0.9] }, glsl: { fragment: `uniform float uOpacity;
152
152
  void main(){
153
153
  vec2 d = gl_PointCoord - 0.5;
@@ -162,7 +162,7 @@ start (what is in scope: `glsl` in `WeatherParticles`; the attribute `aEnd` is 0
162
162
  the two `#include` lines so the color matches three's materials with and without post-processing. WebGPURenderer does not compile GLSL text: `engine.weather.defineField(field, { create })` with a node material there.
163
163
 
164
164
  ## Snow that settles: `weather({ snow: { cover } })`
165
- ```js
165
+ ```js fragment
166
166
  weather({ types, snow: { size: 18, cover: { foliage: 0xf2f4f6, ground: 0xeef0f2, strength: 0.8 } } });
167
167
  ```
168
168
  - While the weather's `snow` amount rises (any type with `snow > 0`), the foliage / ground season tint moves `strength` of the way toward
@@ -173,7 +173,7 @@ weather({ types, snow: { size: 18, cover: { foliage: 0xf2f4f6, ground: 0xeef0f2,
173
173
  - Ash, frost or anything else: `engine.mod('ground.cover', { owner: 'ash', value: { ground: 0x555555, amount: 0.6 } })` (one entry per owner, the handle's `remove()` ends it).
174
174
 
175
175
  ## Lightning picture
176
- ```js
176
+ ```js fragment
177
177
  weather({ types, lightning: f => f * f * 0.8 }); // flash 1 at the strike -> sky flash amount (default flickers)
178
178
  weather({ types, lightning: () => 0 }); // no sky flash: draw your own bolt instead
179
179
  engine.events.on('weather:lightning', () => spawnBolt()); // when it strikes stays the weather table's (lightning > 0.5)
@@ -185,7 +185,8 @@ A field of the game's own weather table (`ash`, `petals`, `sparks`) gets particl
185
185
  round sprites), or `create` for a system of your own:
186
186
 
187
187
  ```js
188
- engine.use(sky(), weather({ types: { clear: {}, ashfall: { ash: 1, grey: 0.5, sun: 0.6 } } }));
188
+ const engine = createEngine({ canvas });
189
+ engine.use(sky(), weather({ types: { clear: {}, shower: { rain: 1 }, ashfall: { ash: 1, grey: 0.5, sun: 0.6 } } }));
189
190
  engine.weather.defineField('ash', { shape: 'soft', color: 0x555555, size: 14, speed: 0.8, sway: 3 });
190
191
  engine.weather.defineField('rain', { create: (engine, { area, count }) => { // the same call replaces rain or snow
191
192
  const drops = new THREE.InstancedMesh(new THREE.SphereGeometry(0.03), new THREE.MeshBasicMaterial({ color: 0x99bbff }), count);
@@ -84,7 +84,7 @@ const sun = new THREE.DirectionalLight('#fff', 3);
84
84
  sun.position.set(40, 80, 30); sun.castShadow = true;
85
85
  engine.scene.add(sun);
86
86
 
87
- const box = engine.shadows.box(sun, { follow: player, extent: 40, snap: 'texel' });
87
+ const box = engine.shadows.box(sun, { follow: engine.player.root, extent: 40, snap: 'texel' });
88
88
  box.set({ extent: 60 }); // a wider view
89
89
  box.remove(); // position, target and the shadow camera come back
90
90
  ```
@@ -96,14 +96,13 @@ box.remove(); // position, target and the shadow camera come back
96
96
  | `snap` | 0.5 | center snap grid in meters, or `'texel'`: one shadow pixel, no shimmer on a moving camera |
97
97
  | `ahead` | 0 | meters the center is shifted in front of the view |
98
98
 
99
- - A game light gets no box unless you call this. The light keeps its direction, which is its position minus its target, so aim it as usual; a `light.target` you assigned
100
- (your player, say) is never moved. It works like cascades here: `position` and `target` hold the placement while the box is on, and writes to `light.position` or a new `light.target` set the direction.
99
+ - A game light gets no box unless you call this. The light keeps its direction, which is its position minus its target, so aim it as usual. `position`, `target` and a `light.target` you assigned work as under cascades above.
101
100
  - The engine's placeholder sun under `sky()` has a box already, following `engine.focus`, 30 m each way. `engine.shadows.box(engine.lights.sun, { follow: false, extent: 9 })` changes that one
102
101
  box and `remove()` restores it. Writing `engine.lights.sun.target.position` yourself takes the box's center over, with one warning; `{ follow: 'focus' }` gives it back.
103
102
 
104
103
  ## Keep what does not move
105
104
 
106
- ```js
105
+ ```js fragment
107
106
  const kept = engine.shadows.cache(sun, { static: mesh => mesh !== cars.mesh }); // a test on each mesh; or an Object3D, or a list of them
108
107
  kept.redraw(); // a static object moved, hid or left
109
108
  kept.set({ static: town }); // say again what is static
@@ -44,9 +44,9 @@ colliders, template / id nodes, spawn / trigger_ / npc_ / marker_ points; warnin
44
44
  | Step | What it does | When it matters |
45
45
  |---|---|---|
46
46
  | Meshopt | compresses geometry; the decoder ships with the engine | always on; smaller download, no visual change |
47
- | KTX2 | textures stay compressed on the GPU too, and the download shrinks | always on for a model with textures; encoded by the `ktx` tool when it is on PATH, else by the WebAssembly encoder of `ktx2-encoder`, which comes with the tools; if neither runs, that model fails, the command says why, and the game's `assets.js` stays as it was |
47
+ | KTX2 | textures stay compressed on the GPU too, and the download shrinks | always on for a model with textures; if no encoder runs (`assets optimize` in `../COMMANDS.md`), that model fails, the command says why, and the game's `assets.js` stays as it was |
48
48
 
49
- It needs `@gltf-transform/cli` (`npm i -D @gltf-transform/cli`). Unchanged files are skipped; `--force` redoes everything.
49
+ It needs `@gltf-transform/cli` (`npm i -D @gltf-transform/cli`); its current release pulls a `glob`/`minimatch` that `npm audit` flags (moderate, build time only), so add `"overrides": { "@donmccurdy/caporal": { "glob": "^14.0.4" } }` to your package.json. `--force` redoes unchanged files too.
50
50
 
51
51
  ### The same shot again, before and after
52
52
  Declare fixed views once: `engine.views.define('gate', { position: [10, 4, 12], target: [0, 1, 0], fov: 50 })` (`views.show(name)` also works in code). Then
@@ -81,7 +81,7 @@ that is what lets a painted or baked texture show. One scene can mix GLB props a
81
81
 
82
82
  There is no automatic mapping from a GLB material name to anything. To give a GLB your game's materials, do it in your game code, per model: name the
83
83
  material in Blender (`cloth`, `metal`, `glass`) and look it up in your `picture/materials.js`:
84
- ```js
84
+ ```js fragment
85
85
  const m = await engine.assets.model('hat');
86
86
  m.traverse(o => { if (o.isMesh && materials[o.material.name]) o.material = materials[o.material.name]; });
87
87
  ```
@@ -13,6 +13,7 @@ shows in `describe()` and the dev bridge, and can be driven by ops, without spec
13
13
  3. **Time, skipped** (`engine.skip`, the op `time.skip`, recipe 06 section 2). `fixed` hooks, physics and near simulation do **not** run during a skip.
14
14
  A state derived from `clock.now` is exact for free. A module that accumulates in `fixed` must also implement `skip(dt, e, done)` (called once per
15
15
  segment, `done` on the last; do heavy work once when `done`), or put the logic in a world record `far(rec, dt)`, which gets one catch-up call.
16
+ Say which on the definition with `skipKind`: `exact`, `approx`, `step` or `none` (`ModuleDefinition` in the types says what each means); `engine.catalog` reports a module with a `fixed` or `skip` hook that does not.
16
17
  4. **Observable.** Module hook `describe(e, ctx)` puts its return value in `describe().<module name>` (plain JSON; the bridge `describe <name>` and
17
18
  `describeText()` show it). A game without a module uses `engine.describe.add(name, fn)`. The name must be new (it throws on a clash).
18
19
  Keep it compact: the state an AI checks to verify the module worked.
@@ -66,7 +67,7 @@ Both runs must give equal `describe machines` (and `describe time`); if B differ
66
67
  ## Checking it: a contract file and the shared contract test
67
68
  Write the five points down as data in `contract.js` (`{ name, api, ops, events, saves: { key: version }, describe, options, probe }`, see
68
69
  `modules/gameplay/inventory.contract.js`) and run it from your tests (works in a game installed from npm):
69
- ```js
70
+ ```js fragment
70
71
  import { runContract } from '@threedog/tools/contract';
71
72
  runContract(contract, () => myModule(contract.options), { check }); // check(label, ok, detail?)
72
73
  ```