threedog 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (370) hide show
  1. package/CHANGELOG.md +893 -798
  2. package/README.md +1 -1
  3. package/core/assets/Animator.js +41 -3
  4. package/core/assets/Assets.js +100 -24
  5. package/core/assets/assetEntry.js +73 -20
  6. package/core/assets/assetHot.js +68 -16
  7. package/core/assets/assetLoad.js +6 -6
  8. package/core/assets/assetLod.js +9 -2
  9. package/core/assets/assetManifest.js +12 -2
  10. package/core/assets/assetPart.js +54 -0
  11. package/core/assets/ik.js +271 -0
  12. package/core/assets/modelNeeds.js +37 -0
  13. package/core/assets/namedModel.js +102 -29
  14. package/core/assets/nodeVisibility.js +15 -0
  15. package/core/audio/Audio.js +36 -4
  16. package/core/audio/audioReverb.js +99 -0
  17. package/core/audio/audioRules.js +1 -1
  18. package/core/audio/audioVoice.js +1 -1
  19. package/core/base/Events.js +14 -4
  20. package/core/base/Random.js +1 -1
  21. package/core/base/Vars.js +1 -1
  22. package/core/base/docRef.js +51 -0
  23. package/core/base/errorCodes.js +187 -126
  24. package/core/base/errorHints.js +9 -7
  25. package/core/base/errors.js +25 -10
  26. package/core/base/events.generated.js +2 -0
  27. package/core/base/freeParts.js +76 -0
  28. package/core/base/math.js +28 -0
  29. package/core/base/sections.js +5 -5
  30. package/core/base/validate.js +31 -3
  31. package/core/engine/Engine.js +17 -7
  32. package/core/engine/Loading.js +5 -3
  33. package/core/engine/copies.js +1 -1
  34. package/core/engine/headlessLoad.js +4 -1
  35. package/core/engine/lifecycle.js +32 -16
  36. package/core/engine/loop.js +71 -27
  37. package/core/engine/moduleSlots.js +2 -2
  38. package/core/engine/moduleTypes.js +3 -3
  39. package/core/engine/modules.js +65 -39
  40. package/core/engine/page.js +6 -3
  41. package/core/engine/services.js +6 -5
  42. package/core/engine/startup.js +8 -7
  43. package/core/input/Input.js +28 -14
  44. package/core/input/inputContext.js +28 -16
  45. package/core/input/inputKeyboard.js +31 -3
  46. package/core/input/inputPad.js +4 -0
  47. package/core/input/inputPointer.js +2 -1
  48. package/core/input/inputSeat.js +1 -1
  49. package/core/inspect/Budget.js +109 -19
  50. package/core/inspect/DebugOverrides.js +28 -4
  51. package/core/inspect/Describe.js +17 -9
  52. package/core/inspect/Inspect.js +4 -2
  53. package/core/inspect/InspectMaterials.js +3 -1
  54. package/core/inspect/InspectPerf.js +19 -9
  55. package/core/inspect/InspectScene.js +32 -7
  56. package/core/inspect/MaterialInfo.js +19 -2
  57. package/core/inspect/UrlState.js +50 -28
  58. package/core/inspect/catalog.js +28 -9
  59. package/core/inspect/debugView.js +2 -1
  60. package/core/inspect/describeRender.js +25 -13
  61. package/core/inspect/describeText.js +14 -6
  62. package/core/inspect/lightWatch.js +1 -1
  63. package/core/inspect/metadata.generated.js +35 -17
  64. package/core/inspect/pictureChecks.js +148 -0
  65. package/core/inspect/pictureMenu.js +84 -0
  66. package/core/inspect/pictureWriters.js +26 -6
  67. package/core/inspect/textureBytes.js +12 -2
  68. package/core/inspect/toolDoor.js +2 -4
  69. package/core/ops/Ops.js +11 -4
  70. package/core/ops/holds.js +27 -10
  71. package/core/ops/opsAtomic.js +15 -7
  72. package/core/ops/opsGuard.js +2 -2
  73. package/core/ops/opsRun.js +8 -7
  74. package/core/ops/sharedPoint.js +72 -21
  75. package/core/ops/stacks.js +56 -16
  76. package/core/saves/SaveStore.js +9 -3
  77. package/core/saves/Saves.js +32 -23
  78. package/core/saves/saveApply.js +96 -44
  79. package/core/saves/saveIds.js +1 -1
  80. package/core/saves/saveVersions.js +7 -5
  81. package/core/saves/session.js +17 -8
  82. package/core/saves/stateReplace.js +34 -15
  83. package/core/scene/Rays.js +52 -10
  84. package/core/scene/Views.js +36 -15
  85. package/core/scene/adaptive.js +144 -21
  86. package/core/scene/drawOnly.js +17 -0
  87. package/core/scene/gameLights.js +47 -4
  88. package/core/scene/sceneMethods.js +13 -11
  89. package/core/scene/stepPoses.js +11 -3
  90. package/core/scene/targeting.js +5 -3
  91. package/core/scene/thingOps.js +1 -1
  92. package/core/scene/tier.js +15 -0
  93. package/core/stream/Batching.js +30 -7
  94. package/core/stream/Stream.js +26 -7
  95. package/core/stream/batchGroups.js +2 -2
  96. package/core/stream/chunkStream.js +7 -5
  97. package/core/stream/prepare.js +77 -0
  98. package/core/time/skip.js +3 -1
  99. package/core/time/time.js +4 -2
  100. package/docs/AI.md +82 -83
  101. package/docs/API.md +16 -16
  102. package/docs/CODEMAP.md +17 -11
  103. package/docs/COMMANDS.md +139 -142
  104. package/docs/CONVENTIONS.md +37 -49
  105. package/docs/MIGRATING-0.8.md +2 -2
  106. package/docs/MIGRATING-1.0.md +2 -2
  107. package/docs/THREE.md +30 -35
  108. package/docs/api/assets.md +3 -1
  109. package/docs/api/audio.md +4 -2
  110. package/docs/api/budget.md +5 -0
  111. package/docs/api/characters.md +10 -8
  112. package/docs/api/collision.md +6 -4
  113. package/docs/api/engine.md +16 -16
  114. package/docs/api/events.md +3 -2
  115. package/docs/api/ground.md +6 -5
  116. package/docs/api/hud.md +4 -2
  117. package/docs/api/input.md +5 -5
  118. package/docs/api/particles.md +2 -1
  119. package/docs/api/photo.md +3 -0
  120. package/docs/api/post.md +7 -4
  121. package/docs/api/quests.md +2 -2
  122. package/docs/api/rays.md +1 -2
  123. package/docs/api/saves.md +7 -7
  124. package/docs/api/settings.md +2 -2
  125. package/docs/api/tools.md +3 -1
  126. package/docs/api/vars.md +1 -1
  127. package/docs/api/vegetation.md +4 -2
  128. package/docs/api/world.md +1 -1
  129. package/docs/recipes/01-new-game.md +16 -17
  130. package/docs/recipes/02-npc.md +22 -18
  131. package/docs/recipes/03-items-pickups.md +37 -35
  132. package/docs/recipes/04-quests.md +15 -10
  133. package/docs/recipes/05-props-bake.md +101 -95
  134. package/docs/recipes/06-clock-events.md +28 -28
  135. package/docs/recipes/07-flow-scenes-pause.md +29 -26
  136. package/docs/recipes/08-weather-sky.md +52 -64
  137. package/docs/recipes/09-materials-lights-models.md +26 -17
  138. package/docs/recipes/10-blender-level.md +15 -10
  139. package/docs/recipes/11-vehicles.md +12 -7
  140. package/docs/recipes/12-navmesh.md +44 -26
  141. package/docs/recipes/13-animation.md +56 -45
  142. package/docs/recipes/14-custom-module.md +21 -18
  143. package/docs/recipes/15-perf.md +61 -55
  144. package/docs/recipes/16-dev-bridge.md +24 -33
  145. package/docs/recipes/18-world.md +36 -42
  146. package/docs/recipes/19-shooting-picking.md +20 -15
  147. package/docs/recipes/20-content-actions-save.md +48 -56
  148. package/docs/recipes/21-camera.md +45 -54
  149. package/docs/recipes/22-shop-gold.md +12 -7
  150. package/docs/recipes/23-ops.md +25 -23
  151. package/docs/recipes/26-ui-parts.md +67 -47
  152. package/docs/recipes/27-net.md +12 -7
  153. package/docs/recipes/28-terrain.md +24 -21
  154. package/docs/recipes/29-grid.md +32 -27
  155. package/docs/recipes/30-templates.md +21 -20
  156. package/docs/recipes/31-audio.md +39 -22
  157. package/docs/recipes/32-action-game.md +19 -14
  158. package/docs/recipes/33-stream-sources.md +15 -11
  159. package/docs/recipes/34-environment-lighting.md +126 -70
  160. package/docs/recipes/35-picture-from-reference.md +8 -8
  161. package/docs/recipes/36-ground-plants.md +27 -21
  162. package/docs/recipes/40-scene.md +19 -28
  163. package/docs/recipes/43-shader-patches-surfaces.md +15 -12
  164. package/docs/recipes/44-water-weather-hooks.md +34 -31
  165. package/docs/recipes/45-cascaded-shadows.md +35 -26
  166. package/docs/recipes/46-blender-art-route.md +7 -2
  167. package/docs/recipes/49-game-module-contract.md +13 -8
  168. package/docs/recipes/50-own-renderer.md +6 -2
  169. package/docs/recipes/51-capability-catalog.md +15 -8
  170. package/docs/recipes/52-around-the-picture.md +34 -32
  171. package/docs/recipes/53-ground-up-close.md +6 -1
  172. package/docs/recipes/55-mods-time-wrap.md +27 -19
  173. package/docs/recipes/56-webgpu-tsl.md +75 -43
  174. package/docs/recipes/57-control.md +18 -13
  175. package/docs/recipes/58-input.md +26 -16
  176. package/docs/recipes/59-depth-post-effects.md +8 -3
  177. package/docs/recipes/60-judge-the-picture.md +10 -9
  178. package/docs/recipes/61-deploy.md +5 -0
  179. package/docs/recipes/62-picture-code.md +72 -79
  180. package/docs/recipes/63-third-person-start.md +48 -45
  181. package/docs/recipes/64-particles.md +22 -10
  182. package/docs/recipes/65-swarm.md +18 -13
  183. package/docs/recipes/66-common-tasks.md +38 -35
  184. package/examples/action/.threedog/content-index.json +1 -1
  185. package/examples/action/GAMEMAP.md +2 -3
  186. package/examples/action/main.js +3 -3
  187. package/examples/action/picture/lights.js +3 -1
  188. package/examples/perf-island/.threedog/content-index.json +1 -1
  189. package/examples/perf-island/GAMEMAP.md +3 -3
  190. package/examples/perf-island/picture/lights.js +2 -1
  191. package/examples/plain-picture/GAMEMAP.md +1 -1
  192. package/examples/rc2d/GAMEMAP.md +1 -1
  193. package/examples/styletest/.threedog/content-index.json +1 -1
  194. package/examples/styletest/GAMEMAP.md +2 -2
  195. package/examples/styletest/main.js +1 -1
  196. package/examples/techniques/interior-light/README.md +3 -3
  197. package/examples/techniques/interior-light/interiorLight.js +2 -4
  198. package/examples/techniques/interior-light/picture/lights.js +2 -1
  199. package/examples/techniques/modular-building/picture/lights.js +3 -1
  200. package/examples/techniques/outlines-and-rim/picture/lights.js +3 -1
  201. package/examples/techniques/procedural-animation/README.md +1 -1
  202. package/examples/techniques/procedural-animation/main.js +1 -1
  203. package/examples/webgpu-tsl/GAMEMAP.md +1 -1
  204. package/examples/world/.threedog/content-index.json +1 -1
  205. package/examples/world/GAMEMAP.md +2 -3
  206. package/examples/world/art/humanoid.js +1 -1
  207. package/examples/world/main.js +6 -3
  208. package/index.d.ts +2 -2
  209. package/llms.txt +101 -0
  210. package/modules/ambience/Ambience.js +21 -5
  211. package/modules/calendar/index.js +9 -5
  212. package/modules/calendar/schedule.js +23 -8
  213. package/modules/camera/FirstPersonCamera.js +3 -1
  214. package/modules/camera/FollowCamera.js +10 -5
  215. package/modules/camera/RtsCamera.js +4 -3
  216. package/modules/camera/common.js +70 -8
  217. package/modules/camera/contract.js +1 -1
  218. package/modules/characters/Character.js +16 -10
  219. package/modules/characters/NPC.js +31 -19
  220. package/modules/characters/assetModel.js +14 -9
  221. package/modules/characters/astar.js +6 -1
  222. package/modules/characters/contract.js +2 -2
  223. package/modules/characters/index.js +34 -22
  224. package/modules/characters/movers/manual.js +1 -1
  225. package/modules/characters/movers/rapier.js +17 -2
  226. package/modules/characters/movers/simple.js +1 -1
  227. package/modules/characters/movers/support.js +16 -7
  228. package/modules/characters/npcAvoid.js +2 -2
  229. package/modules/characters/npcSim.js +3 -2
  230. package/modules/characters/pathAsync.js +24 -8
  231. package/modules/characters/pathJob.js +1 -1
  232. package/modules/characters/player.js +10 -9
  233. package/modules/characters/playerStrings.js +5 -5
  234. package/modules/characters/proceduralRig.js +5 -5
  235. package/modules/characters/useModel.js +6 -0
  236. package/modules/characters/walkTo.js +1 -1
  237. package/modules/collision/Collision.js +29 -18
  238. package/modules/collision/grid.js +22 -4
  239. package/modules/content/index.js +3 -1
  240. package/modules/content/loader.js +1 -1
  241. package/modules/content/models.js +82 -33
  242. package/modules/content/props.js +2 -1
  243. package/modules/content/rules.js +11 -5
  244. package/modules/content/templates.js +3 -3
  245. package/modules/content/words.js +2 -2
  246. package/modules/debug/DebugPanel.js +9 -9
  247. package/modules/flow/index.js +9 -6
  248. package/modules/gameplay/Dialogue.js +34 -20
  249. package/modules/gameplay/Interactions.js +19 -15
  250. package/modules/gameplay/Inventory.js +9 -4
  251. package/modules/gameplay/Quests.js +12 -10
  252. package/modules/gameplay/pickups.js +23 -11
  253. package/modules/grid/index.js +1 -1
  254. package/modules/grid/preview.js +2 -2
  255. package/modules/grid/tiles.js +1 -1
  256. package/modules/hlod/index.js +4 -1
  257. package/modules/hud/index.js +47 -10
  258. package/modules/hud/parts.js +28 -9
  259. package/modules/level/geometry.js +8 -3
  260. package/modules/level/index.js +10 -5
  261. package/modules/level/load.js +4 -2
  262. package/modules/lights/sources.js +1 -1
  263. package/modules/music/Music.js +22 -4
  264. package/modules/nav/index.js +20 -10
  265. package/modules/particles/Particles.js +31 -14
  266. package/modules/particles/effect.js +20 -5
  267. package/modules/particles/lit.js +72 -0
  268. package/modules/photo/Photo.js +72 -28
  269. package/modules/photo/pathTrace.js +106 -0
  270. package/modules/rigid/RigidBodies.js +23 -14
  271. package/modules/rigid/Vehicles.js +3 -13
  272. package/modules/rigid/sync.js +2 -1
  273. package/modules/settings/Settings.js +52 -20
  274. package/modules/settings/apply.js +23 -9
  275. package/modules/settings/sections.js +39 -6
  276. package/modules/settings/strings.js +2 -0
  277. package/modules/settings/view.js +19 -3
  278. package/modules/sky/dome.js +15 -3
  279. package/modules/sky/environment.js +28 -12
  280. package/modules/sky/fog.js +1 -1
  281. package/modules/sky/frame.js +6 -1
  282. package/modules/sky/shader.js +4 -3
  283. package/modules/sky/skyModule.js +8 -4
  284. package/modules/swarm/Swarm.js +1 -1
  285. package/modules/terrain/ChunkManager.js +61 -15
  286. package/modules/terrain/chunkJob.js +2 -2
  287. package/modules/terrain/index.js +20 -5
  288. package/modules/terrain/terrainEdit.js +8 -4
  289. package/modules/terrain/terrainTexture.js +4 -2
  290. package/modules/timeline/Timeline.js +4 -3
  291. package/modules/timeline/Tween.js +3 -0
  292. package/modules/timeline/letterbox.js +1 -0
  293. package/modules/triggers/index.js +36 -17
  294. package/modules/vegetation/Vegetation.js +81 -19
  295. package/modules/vegetation/densityMap.js +13 -8
  296. package/modules/vegetation/draw.js +147 -24
  297. package/modules/vegetation/groundChunks.js +20 -5
  298. package/modules/vegetation/index.js +3 -3
  299. package/modules/vegetation/modelGeometry.js +9 -4
  300. package/modules/water/Water.js +11 -8
  301. package/modules/weather/Weather.js +7 -2
  302. package/modules/weather/shaders.js +25 -5
  303. package/modules/weather/weatherDraw.js +20 -6
  304. package/modules/world/World.js +2 -1
  305. package/modules/world/index.js +2 -2
  306. package/modules/world/persist.js +6 -2
  307. package/modules/world/views.js +15 -2
  308. package/package.json +5 -1
  309. package/presets.js +5 -5
  310. package/render/PostFX.js +102 -42
  311. package/render/backend.js +142 -16
  312. package/render/bindingLimits.js +59 -0
  313. package/render/cascades.js +3 -1
  314. package/render/cascades.tsl.js +2 -0
  315. package/render/daylight.js +7 -1
  316. package/render/detail.js +7 -4
  317. package/render/effects.js +27 -8
  318. package/render/fogLook.js +24 -0
  319. package/render/fuse.js +5 -2
  320. package/render/fx/compareLevel.tsl.js +23 -0
  321. package/render/fx/detail.tsl.js +9 -7
  322. package/render/fx/index.js +9 -2
  323. package/render/fx/library.tsl.js +1 -0
  324. package/render/fx/lightShaft.tsl.js +114 -0
  325. package/render/fx/noise.tsl.js +25 -8
  326. package/render/fx/objectOrigin.tsl.js +39 -10
  327. package/render/fx/particles.tsl.js +23 -6
  328. package/render/fx/patchNodes.tsl.js +17 -12
  329. package/render/fx/pcss.tsl.js +51 -0
  330. package/render/fx/postWebGPU.tsl.js +104 -29
  331. package/render/fx/sky.tsl.js +3 -9
  332. package/render/fxNumbers.js +10 -4
  333. package/render/impostor.tsl.js +107 -0
  334. package/render/lighting.js +33 -1
  335. package/render/lightmap.js +42 -28
  336. package/render/lights.js +19 -3
  337. package/render/materials.js +6 -4
  338. package/render/mergeCommon.js +4 -1
  339. package/render/occlusion.js +14 -4
  340. package/render/patches.js +79 -41
  341. package/render/postRuns.js +32 -0
  342. package/render/postWebGL.js +97 -10
  343. package/render/probes.js +10 -14
  344. package/render/shaderErrors.js +44 -7
  345. package/render/shadowCache.tsl.js +33 -5
  346. package/render/shadows.js +42 -16
  347. package/render/slots.js +8 -5
  348. package/render/vertexInputs.js +52 -0
  349. package/types/core.d.ts +115 -47
  350. package/types/gameplay.d.ts +56 -23
  351. package/types/generated/core/audio/Audio.d.ts +27 -1
  352. package/types/generated/core/base/Random.d.ts +1 -1
  353. package/types/generated/core/input/Input.d.ts +6 -8
  354. package/types/generated/core/input/inputSeat.d.ts +1 -1
  355. package/types/generated/core/inspect/Budget.d.ts +26 -0
  356. package/types/generated/core/inspect/DebugOverrides.d.ts +0 -2
  357. package/types/generated/core/saves/Saves.d.ts +10 -7
  358. package/types/generated/core/saves/session.d.ts +8 -2
  359. package/types/generated/core/scene/Rays.d.ts +1 -3
  360. package/types/generated/core/scene/Views.d.ts +17 -3
  361. package/types/generated/modules/particles/Particles.d.ts +1 -1
  362. package/types/generated/modules/world/World.d.ts +2 -1
  363. package/types/generated/render/PostFX.d.ts +35 -9
  364. package/types/physics.d.ts +796 -764
  365. package/types/pixel.d.ts +1 -1
  366. package/types/tsl.d.ts +62 -1
  367. package/types/world.d.ts +12 -3
  368. package/ui/Focus.js +7 -5
  369. package/ui/Parts.js +1 -1
  370. package/ui/touchPart.js +6 -3
@@ -1,6 +1,9 @@
1
1
  # Scene transitions and pause (flow)
2
2
 
3
- **In this recipe**: 1. Pause, title, ending · 1b. Start and continue · 2. Changing scene · 2b. Input contexts · 3. Verify · 4. Sessions · 5. Window and device
3
+ > **Covers:** flow states (title, playing, paused, ending), changing scene, input contexts, new game / continue.
4
+ > **Use when:** menus, pause, a title screen, moving between scenes.
5
+ > **Shortest:** `engine.use(flow({ start: 'title' }))`.
6
+ > **Sections:** 1 Pause / title · 1b Title -> start · 2 Changing scene / · 2b Input contexts menus · 3 Verify · 4 New game / · 5 Window and device
4
7
 
5
8
  Needs the module `flow()` (not in openWorld; add it yourself: `engine.use(openWorld({ camera: 'follow', ...}), flow())`).
6
9
  - **Flow states**: title, playing (built-in `playing`), paused (built-in `paused`: freezes gameplay + locks input), ending, ... Only one is active at a time.
@@ -10,20 +13,20 @@ Needs the module `flow()` (not in openWorld; add it yourself: `engine.use(openWo
10
13
  ## 1. Pause / title / ending (in main.js)
11
14
  ```js
12
15
  import { flow, toast } from 'threedog';
13
- const titleEl = document.getElementById('title'), startBtn = document.getElementById('start'); // elements you wrote in the page html
14
- engine.use(flow({ start: 'title' })); // start in the title state (entered after engine:ready)
16
+ const titleEl = document.getElementById('title'), startBtn = document.getElementById('start'); // elements you wrote in the page html
17
+ engine.use(flow({ start: 'title' })); // start in the title state (entered after engine:ready)
15
18
 
16
19
  engine.flow.define('title', {
17
- freeze: true, lockInput: true, music: 'title', // music: the track to play on entry (music module), null = stop
20
+ freeze: true, lockInput: true, music: 'title', // music: the track to play on entry (music module), null = stop
18
21
  enter: (e, from) => { titleEl.hidden = false; },
19
22
  exit: (e, to) => { titleEl.hidden = true; },
20
23
  });
21
24
  engine.flow.define('ending', { freeze: true, lockInput: true, enter: () => toast(engine, 'The end') });
22
25
  startBtn.onclick = () => engine.flow.go('playing');
23
26
 
24
- engine.input.action('pause', { label: 'Pause', keys: ['KeyO'] }); // read by action name; Esc is the back key (see below)
27
+ engine.input.define('pause', { label: 'Pause', keys: ['KeyO'] }); // read by action name; Esc is the back key (see below)
25
28
  engine.onFrame(() => {
26
- if (engine.input.pressedRaw('pause')) engine.flow.go(engine.flow.state === 'paused' ? 'playing' : 'paused'); // paused pushes an opaque input context, so use pressedRaw
29
+ if (engine.input.pressedRaw('pause')) engine.flow.go(engine.flow.state === 'paused' ? 'playing' : 'paused'); // paused pushes an opaque input context, so use pressedRaw
27
30
  });
28
31
  engine.events.on('flow:change', ({ from, to }) => console.log(from, '->', to));
29
32
  ```
@@ -39,8 +42,8 @@ To reset only part of the run, do not write positions, health and spawns inside
39
42
  Apply it on a fixed tick with `engine.nextFixed(fn)` or a flag read in `onFixed`. No fixed step runs while frozen, so on an end screen with `freeze: true` leave the freeze first:
40
43
  ```js
41
44
  engine.flow.define('gameOver', { freeze: true, lockInput: true });
42
- const resetRun = () => engine.vars.bump('tries', 1); // the game's own reset: positions, health, spawns
43
- const retry = async () => { engine.flow.go('playing'); await engine.nextFixed(resetRun); }; // this order: frozen, nextFixed never fires
45
+ const resetRun = () => engine.vars.bump('tries', 1); // the game's own reset: positions, health, spawns
46
+ const retry = async () => { engine.flow.go('playing'); await engine.nextFixed(resetRun); }; // this order: frozen, nextFixed never fires
44
47
  ```
45
48
 
46
49
  ### Back key (Esc): the UI focus stack
@@ -52,7 +55,7 @@ A game's own windows made with `makeWindow` are pushed automatically (`onCancel`
52
55
  `uiFocus` is experimental; `engine.input.push` is the stable route to take the keys for a screen of your own.
53
56
  ```js
54
57
  import { uiFocus } from 'threedog';
55
- const h = uiFocus(engine).push('myMap', { cancel: () => closeMap() }); // call h.remove() when closing; h.fresh = opened this very frame
58
+ const h = uiFocus(engine).push('myMap', { cancel: () => closeMap() }); // call h.remove() when closing; h.fresh = opened this very frame
56
59
  ```
57
60
  An entry with a `nav` (every window, the settings menu, dialogue choices) lets go of a locked mouse when it opens. For anything else, `engine.page.releaseLock()` frees the mouse
58
61
  (recipe 21); neither counts as the player's Esc, so the pause menu stays shut.
@@ -64,14 +67,14 @@ To open straight into play, pick the start state up front instead of leaving the
64
67
  own URL keys (`?time=22:20&weather=storm`, applied after `engine:ready`, weather at once, then `wait` seconds are advanced), so only the game's
65
68
  own state needs a key of its own.
66
69
  ```js fragment
67
- const q = new URLSearchParams(location.search), moment = q.get('moment'); // the game's own key: which lamps are lit, the score ...
70
+ const q = new URLSearchParams(location.search), moment = q.get('moment'); // the game's own key: which lamps are lit, the score ...
68
71
  engine.use(openWorld({ camera: 'follow' }), flow({ start: moment ? 'playing' : 'title' }));
69
72
  engine.flow.define('title', { freeze: true, lockInput: true,
70
73
  enter: () => showTitle({ canContinue: engine.saves.list().some(s => s.slot === 'auto') }), exit: () => hideTitle() });
71
- newBtn.onclick = () => engine.session.newGame(); // -> session:start -> 'playing'
74
+ newBtn.onclick = () => engine.session.newGame(); // -> session:start -> 'playing'
72
75
  continueBtn.onclick = () => engine.session.load('auto'); // the same, from the save
73
76
  await engine.start();
74
- if (moment) setUpMoment(moment); // the game's own data only; in code, time / weather are engine.calendar.timeOfDay = 0.93, weather.set('storm', { seconds: 0 })
77
+ if (moment) setUpMoment(moment); // the game's own data only; in code, time / weather are engine.calendar.timeOfDay = 0.93, weather.set('storm', { seconds: 0 })
75
78
  ```
76
79
  The engine's ready-made title (`createEngine({ ui: { title } })`, recipe 26 §5) opens in `start()` the same way: leave `title` out for a moment
77
80
  (`ui: { ...(moment ? {} : { title: { title: 'My Game', items: ['continue', 'start'] } }) }`).
@@ -91,10 +94,10 @@ color is one frame old (share `engine.uniforms.uSkyHorizon` instead, recipe 08).
91
94
  ```js fragment
92
95
  // A level-based game: switch to another map
93
96
  await engine.flow.transition(async () => {
94
- await engine.level.load('/models/town2.glb'); // or a name from the assets manifest
97
+ await engine.level.load('/models/town2.glb'); // or a name from the assets manifest
95
98
  engine.player.placeAt(engine.level.spawn);
96
- engine.cameraRig.follow(engine.player.root); // the camera jumps straight there instead of flying from far away
97
- }, { fade: 0.6, autosave: 'auto' }); // also save slot 'auto' before switching
99
+ engine.cameraRig.follow(engine.player.root); // the camera jumps straight there instead of flying from far away
100
+ }, { fade: 0.6, autosave: 'auto' }); // also save slot 'auto' before switching
98
101
 
99
102
  // Teleport within the same map: no save, music keeps playing
100
103
  engine.flow.transition(() => engine.player.placeAt([40, 0, -20]), { music: 'keep' });
@@ -121,17 +124,17 @@ through. Dialogue, windows, full-screen UI parts, cutscenes (while the player is
121
124
  opaque one: that is what "locks input" means (`input.enabled` is false while one is on the stack). Who moves a character is separate: a
122
125
  cutscene takes its actors' control ([57-control](57-control.md)).
123
126
  ```js
124
- engine.input.action('exit', { label: 'Get out', keys: ['KeyF'], context: 'vehicle' }); // 'interact' has E; give the vehicle its own keys
125
- engine.input.action('inspect', { label: 'Inspect', keys: ['KeyF'] }); // gameplay action on the same key
126
- const h = engine.input.push('vehicle', { pass: true }); // now F means exit, inspect is shadowed, WASD still works
127
- h.remove(); // back on foot
128
- engine.input.action('menuConfirm', { label: 'OK', keys: ['Space'], context: 'menu' }); // readable only while a window / menu is open
127
+ engine.input.define('exit', { label: 'Get out', keys: ['KeyF'], context: 'vehicle' }); // 'interact' has E; give the vehicle its own keys
128
+ engine.input.define('inspect', { label: 'Inspect', keys: ['KeyF'] }); // gameplay action on the same key
129
+ const h = engine.input.push('vehicle', { pass: true }); // now F means exit, inspect is shadowed, WASD still works
130
+ h.remove(); // back on foot
131
+ engine.input.define('menuConfirm', { label: 'OK', keys: ['Space'], context: 'menu' }); // readable only while a window / menu is open
129
132
  ```
130
133
  - A switch applies at the start of the next fixed step (the input snapshot), so the press that boarded cannot also get out in the same step. Actions
131
134
  the switch blocks lose their held state, and a key cleared this way stays dead until released: closing a menu never leaves a key "still held" and
132
135
  keyboard auto-repeat does not bring it back.
133
136
  - Losing focus (`blur`, tab hidden) releases every held key.
134
- - `describe().holds.input` lists the stack with owners (`input.push(name, { owner })`; `input.gate(action, owner)` closes one action, listed in `holds.gates`); the event `input:context { stack }` fires on every change. `characters()` pushes `'vehicle'` while
137
+ - `describe().holds.input` lists the stack with owners (`input.push(name, { owner })`; `input.gate(action, owner)` closes one action, listed in `holds.gates`; `holds.shadowed`: actions a pass context's key hides; `press` also names `shadowed-by:` / `context-off:`); the event `input:context { stack }` fires on every change. `characters()` pushes `'vehicle'` while
135
138
  the player drives (its `brake` action lives there).
136
139
  - Test: `engine.input.push('menu'); engine.step(1 / 60);` then `input.pressed('attack')` is false.
137
140
 
@@ -144,10 +147,10 @@ engine.input.action('menuConfirm', { label: 'OK', keys: ['Space'], context: 'men
144
147
  ## 4. New game / continue / back to title / retry (engine.session)
145
148
  Every playthrough starts from a clean slate, so a second new game is exactly like the first:
146
149
  ```js fragment
147
- await engine.session.newGame(); // the state right after start(): world, containers, vars, quests, clock, sky, weather, random
148
- await engine.session.load('slot1'); // continue (title "Continue", settings "Load"); retry: engine.session.load('checkpoint')
149
- await engine.session.quit(); // back to the title (settings "Back to title"); the title's Start calls newGame
150
- engine.session.track(engine.events.once('npc:talk', onTalk)); // anything the game adds during play: removed when the playthrough ends
150
+ await engine.session.newGame(); // the state right after start(): world, containers, vars, quests, clock, sky, weather, random
151
+ await engine.session.load('slot1'); // continue (title "Continue", settings "Load"); retry: engine.session.load('checkpoint')
152
+ await engine.session.quit(); // back to the title (settings "Back to title"); the title's Start calls newGame
153
+ engine.session.track(engine.events.once('npc:talk', onTalk)); // anything the game adds during play: removed when the playthrough ends
151
154
  ```
152
155
  Ending a playthrough drops a running cutscene, removes tracked handles, drops clock timers added after start(), drops background results not yet
153
156
  applied (commits), stops the music, applies the start state and snaps the camera to the player. flow goes back to its start state, then to
@@ -160,7 +163,7 @@ applied (commits), stops the music, applies the start state and snaps the camera
160
163
 
161
164
  ## 5. Window and device (engine.page)
162
165
  One place listens to window focus, tab visibility, mouse lock and the WebGL context; modules never add their own listeners.
163
- - Window in the background / tab hidden: gameplay is frozen by owner `'page'`, a full still (`freeze('page', { ambient: true })`; cutscenes stop too, rendering and UI go on; `engine.frozen` and `runState.owners` show it). `createEngine({ pauseOnBlur: false })` or
166
+ - Window in the background / tab hidden: gameplay is frozen by owner `'page'`, a full still (`freeze('page', { still: true })`; cutscenes stop too, rendering and UI go on; `engine.frozen` and `runState.owners` show it). `createEngine({ pauseOnBlur: false })` or
164
167
  `engine.page.pauseOnBlur = false` keeps playing. Coming back resumes with no catch-up burst; a long frame turns into at most 0.1 s of fixed steps,
165
168
  and fewer when the steps are heavy (at most about 33 ms of catch-up work per frame; the rest is dropped as a brief slow-down). `engine.step()` never drops time.
166
169
  - `engine.events.on('page:blur', () => engine.flow?.go('paused'))` also opens the pause menu. Other events: `page:focus`,
@@ -1,44 +1,41 @@
1
1
  # Add weather or change the sky
2
2
 
3
- **In this recipe**: 1. Switching weather · 2. The game's own weather table · 3. Sky colors, sun, stars (and the sky color for your own shader) · 4. Time and brightness · 5. Verify · 6. Day and night in game logic · 7. Wet roads · 8. Clouds · 9. Extra sky layers · 10. Flat backdrop
3
+ > **Covers:** weather, sky colors, sun and stars, clouds, sky layers, a flat backdrop.
4
+ > **Use when:** the sky or the weather should change.
5
+ > **Shortest:** `engine.use(sky({ clouds: { coverage: 0.6 } }), weather())`.
6
+ > **Sections:** 1 Switching weather / · 2 The game's own · 3 Changing sky colors · 4 Time and brightness · 5 Verify · 6 Day and night · 7 Wet roads and · 8 Clouds sky { · 9 Extra sky layers · 10 Flat backdrop no
4
7
 
5
8
  Modules: `sky()` (draws the dome from `engine.calendar`, sun and moon, and computes the signals; it writes no light, fog or exposure, those are your `picture/` code, recipe 62; the time itself is `calendar()`, recipe 06), `weather()` (the game's weather types, smooth transitions, rain and snow,
6
9
  lightning; their picture is `weather({ rain, snow, lightning })`, recipe 44). The engine has only a neutral fallback.
7
10
 
8
11
  ```js fragment
9
- engine.use(sky({ keyframes: ROWS, sunSize: 600, clouds: { coverage: 0.6 }, dim: { stars: false } })); // start values
10
- engine.uniforms.uSunBrightness.value = 4; // sun, moon, star and dome cloud numbers: engine.uniforms, the dome's own objects, on both renderers
11
- engine.uniforms.uCloudCover.value = 0.8; // also uSunSize uSunGlow uMoonSize uMoonBrightness uMoonColor uStars uStarScale uSkyCurve uSkyCloudScale uSkyCloudSpeed uCloudOpacity uCloudSoft uCloudColor uCloudShade
12
- engine.sky.top = boss ? '#400' : null; // plain fields, read each frame: top, horizon (color over the keyframes, null = keyframes), orbit.tilt / sway, dim.tint / stars
13
- engine.sky.backdrop = 0x335577; // one flat color in place of the dome; null gives the dome back
14
- engine.sky.keyframes(NIGHT_ROWS); // the day's rows, live
15
- engine.sky.clouds({ glsl, tsl }); // your cloud function; null = the built-in kind
16
- engine.sky.layer('aurora', { glsl, tsl, blend: 'add' }); // a named dome layer; null removes it
17
- const mySky = new THREE.Mesh(skyGeometry, skyMaterial); // or a skybox name, a Texture
18
- engine.sky.replace(mySky); // skybox name | Texture | CubeTexture | Object3D, never written; null gives the dome back, false draws no sky
19
- mySky.material.uniforms.sunPosition = engine.uniforms.uSunDir; // the same Vector3, refreshed every frame
12
+ engine.use(sky({ keyframes: ROWS, sunSize: 600, clouds: { coverage: 0.6 }, dim: { stars: false } })); // start values
13
+ engine.uniforms.uSunBrightness.value = 4; // sun, moon, star and dome cloud numbers: engine.uniforms, the dome's own objects, on both renderers
14
+ engine.uniforms.uCloudCover.value = 0.8; // also uSunSize uSunGlow uMoonSize uMoonBrightness uMoonColor uStars uStarScale uSkyCurve uSkyCloudScale uSkyCloudSpeed uCloudOpacity uCloudSoft uCloudColor uCloudShade
15
+ engine.sky.top = boss ? '#400' : null; // plain fields, read each frame: top, horizon (color over the keyframes, null = keyframes), orbit.tilt / sway, dim.tint / stars
16
+ engine.sky.backdrop = 0x335577; // one flat color in place of the dome; null gives the dome back
17
+ engine.sky.keyframes(NIGHT_ROWS); // the day's rows, live
18
+ engine.sky.clouds({ glsl, tsl }); // your cloud function; null = the built-in kind
19
+ engine.sky.layer('aurora', { glsl, tsl, blend: 'add' }); // a named dome layer; null removes it
20
+ const mySky = new THREE.Mesh(skyGeometry, skyMaterial); // or a skybox name, a Texture
21
+ engine.sky.replace(mySky); // skybox name | Texture | CubeTexture | Object3D, never written; null gives the dome back, false draws no sky
22
+ mySky.material.uniforms.sunPosition = engine.uniforms.uSunDir; // the same Vector3, refreshed every frame
20
23
  ```
21
24
 
22
25
  WebGPU (recipe 56): same dome as a node material. Hooks take `{ glsl, tsl: (ctx) => vec4 }` ([52](52-around-the-picture.md#tsl-forms)); GLSL alone throws `[webgpu-needs-tsl]`. Own sky: three's `SkyMesh` via `engine.sky.replace`, or a dome of your own with a node material (the `ShaderMaterial` below is the WebGL form): a `MeshBasicNodeMaterial` with `side: THREE.BackSide`, `fog: false`, `depthWrite: false`, `depthTest: false`, and a `colorNode` built on the view direction (world position minus camera position, normalized), on a sphere that follows the camera.
23
26
 
24
- The sky follows one contract: **inputs** time, weather, season,
25
- **outputs** the dome and the background, plus the shared `engine.uniforms`
26
- (`uSunDir`, `uSunColor`, `uDaylight`, `uTimeOfDay`, `uSkyTop`, `uSkyHorizon`, `uWind`, `uWeatherCloud`, `uRain`, `uSnow`, `uWeatherLight`, `uWeatherFog` (the weather state writes the last six every frame), season tints) and events (`day:start`, `season:change`, `weather:change`) that wind,
27
- rain and vegetation read. The keyframes are only the default implementation: `engine.sky.replace` swaps the whole dome and everything else keeps running (the whole sky module is
28
- `engine.use(mySky(), { replaces: 'sky' })`).
27
+ The sky's contract: **inputs** time, weather, season; **outputs** the dome and the background, the shared `engine.uniforms` (recipe 62 §2) and events
28
+ (`day:start`, `season:change`, `weather:change`). `engine.sky.replace` swaps the dome and everything else keeps running; the whole module: `engine.use(mySky(), { replaces: 'sky' })`.
29
29
 
30
30
  ### Your own sky object: what `engine.sky.replace(obj)` does with it
31
- The engine hides its dome, adds `obj` to the scene root when it has no parent yet (and removes it again on `replace(null)` only then), and from
32
- then on **never moves, scales or writes it**: it does not follow the camera, is not scaled to the far plane and is not exempted from culling.
33
- (The built-in dome does all three itself.) So a dome of your own must, on its own:
31
+ The engine hides its dome, adds `obj` to the scene root when it has no parent yet (and removes it on `replace(null)` only then), and **never moves, scales or
32
+ writes it**: no camera follow, no far-plane scaling, no culling exemption. So a dome of your own must:
34
33
 
35
34
  - **contain the camera and stay inside the far plane**: either a fixed sphere big enough for everywhere the camera goes (radius < `camera.far`,
36
35
  which the engine pulls in to the view range unless you take it: `engine.autoView.manual('far')`), or one that follows the camera; or skip
37
36
  depth altogether as below, so the radius no longer matters;
38
- - **compute the view direction per pixel from world space**: pass `worldPosition - cameraPosition` (linear, safe to interpolate) as the
39
- varying and do every non-linear step (normalize, `atan`, projecting onto a cloud plane, noise) in the fragment shader. A direction taken from
40
- the vertex's local `position`, or a non-linear value computed per vertex, is wrong once the dome is off-centre or its triangles are big:
41
- that is where arcs bend and seams show at the corners of the sphere's faces;
37
+ - **compute the view direction per pixel from world space**: interpolate `worldPosition - cameraPosition` (linear) and do every non-linear step (normalize,
38
+ `atan`, cloud-plane projection, noise) per pixel; a direction from the local `position` or computed per vertex bends arcs and shows seams at the sphere's face corners;
42
39
  - draw behind everything, as the block below does.
43
40
 
44
41
  ```js
@@ -49,8 +46,8 @@ const sky = new THREE.Mesh(new THREE.SphereGeometry(1, 32, 16), new THREE.Shader
49
46
  varying vec3 vDir;
50
47
  void main() {
51
48
  vec4 w = modelMatrix * vec4(position, 1.0);
52
- vDir = w.xyz - cameraPosition; // linear: interpolates correctly; normalize in the fragment shader
53
- gl_Position = (projectionMatrix * viewMatrix * w).xyww; // depth 1: never clipped by far, never in front of anything
49
+ vDir = w.xyz - cameraPosition; // linear: interpolates correctly; normalize in the fragment shader
50
+ gl_Position = (projectionMatrix * viewMatrix * w).xyww; // depth 1: never clipped by far, never in front of anything
54
51
  }`,
55
52
  fragmentShader: /* glsl */`
56
53
  uniform vec3 uTop, uLow; varying vec3 vDir;
@@ -61,16 +58,16 @@ const sky = new THREE.Mesh(new THREE.SphereGeometry(1, 32, 16), new THREE.Shader
61
58
  }`,
62
59
  }));
63
60
  sky.frustumCulled = false; sky.renderOrder = -1000;
64
- sky.onBeforeRender = (r, s, cam) => { sky.position.copy(cam.position); sky.updateMatrixWorld(); }; // centred on the camera: any radius works
61
+ sky.onBeforeRender = (r, s, cam) => { sky.position.copy(cam.position); sky.updateMatrixWorld(); }; // centred on the camera: any radius works
65
62
  engine.sky.replace(sky);
66
63
  ```
67
64
  Time of day still reaches it through `engine.uniforms` (`uSunDir`, `uDaylight`, `uTimeOfDay` ...): put them in its `uniforms` to follow the day.
68
65
 
69
66
  ## 1. Switching weather / automatic weather (main.js)
70
67
  ```js
71
- engine.weather.set('rain', { seconds: 20 }); // transition to rain over 20 seconds (a type of the game's table, see 2)
72
- engine.weather.set('storm', { seconds: 0 }); // at once: the full storm before the next step (a screenshot or test right after the call)
73
- engine.weather.auto = true; // change weather at random (openWorld({ camera: 'follow', autoWeather: true }) also works)
68
+ engine.weather.set('rain', { seconds: 20 }); // transition to rain over 20 seconds (a type of the game's table, see 2)
69
+ engine.weather.set('storm', { seconds: 0 }); // at once: the full storm before the next step (a screenshot or test right after the call)
70
+ engine.weather.auto = true; // change weather at random (openWorld({ camera: 'follow', autoWeather: true }) also works)
74
71
  engine.events.on('weather:lightning', () => { /* thunder */ });
75
72
  engine.events.on('weather:change', ({ from, to }) => { /* once per change of name, when the blend starts; set() with the same name again does not fire */ });
76
73
  ```
@@ -86,16 +83,16 @@ of a preset type: spread that one type, `const T = presets.weather.temperate.typ
86
83
  ```js
87
84
  import { createEngine, presets, sky, weather } from 'threedog';
88
85
  engine.use(sky(), weather({
89
- types: { clear: { cloud: 0.1 }, dust: { cloud: 0.5, sun: 0.6, fog: 0.35, wind: 2.2, grey: 0.4, heat: 1 } }, // heat: a field of the game's own, blends too
90
- autoPool: ['clear', 'clear', 'dust'], // candidates for automatic weather (repeats = higher probability; default: each type once)
86
+ types: { clear: { cloud: 0.1 }, dust: { cloud: 0.5, sun: 0.6, fog: 0.35, wind: 2.2, grey: 0.4, heat: 1 } }, // heat: a field of the game's own, blends too
87
+ autoPool: ['clear', 'clear', 'dust'], // candidates for automatic weather (repeats = higher probability; default: each type once)
91
88
  }));
92
- engine.weather.set('dust', { seconds: 15 }); engine.weather.current.heat; // 0..1 during the change
89
+ engine.weather.set('dust', { seconds: 15 }); engine.weather.current.heat; // 0..1 during the change
93
90
  ```
94
91
  Fields: `cloud` cloud cover 0-1, `sun` sunlight multiplier, `fog` fog distance multiplier (smaller = denser fog), `wind` wind strength, `rain`/`snow`
95
92
  0-1, `grey` how gray the sky turns, `lightning` lightning (a type above 0.5 strikes). A table where nothing rains or snows builds no particles.
96
93
  With openWorld the weather module is already installed; pass its options through the preset: `openWorld({ camera: 'follow', weather: { types, autoPool } })`.
97
94
 
98
- ## 3. Changing sky colors, sun, stars
95
+ ## 3. Changing sky colors, sun, stars: the day and night sky
99
96
  `sky({ keyframes })`:
100
97
  `[time 0-1, zenith color, horizon color, sun color, ambient intensity]`, interpolated by time; the rows are sorted and
101
98
  run from time 0 to time 1, else the sky throws (both ends are midnight: give the last row the first row's values, or the colors jump there). What each column drives
@@ -107,28 +104,25 @@ also `sunSize sunGlow starDensity clouds` (defaults and ranges there too; `hours
107
104
  from the dome (outdoor reflections show the sky, not a studio; it darkens by itself), recipe 34.
108
105
 
109
106
  ### Sky color for my shader (horizon color, zenith color)
110
- A shader of your own that should meet the sky (a sea fading to the horizon, distant cards, a reflection) reads the colors the sky draws this frame:
111
- `engine.uniforms.uSkyHorizon` and `engine.uniforms.uSkyTop` (`THREE.Color`, linear). They hold the keyframes, `engine.sky.top` / `horizon`,
112
- the weather's grey tint and lightning; with a backdrop the horizon is the backdrop color. A fog of yours that should melt into the sky copies
113
- it in `engine.onRender` (recipe 34). Share the object, do not copy it in `onFrame`: `onFrame` runs before the sky updates, so a copy is one
114
- frame old (after a time jump, the first picture shows the old hour's color).
107
+ A shader of your own that should meet the sky (a sea fading to the horizon, distant cards) reads the colors the sky draws this frame:
108
+ `engine.uniforms.uSkyHorizon` and `uSkyTop` (`THREE.Color`, linear: keyframes, `engine.sky.top` / `horizon`, the weather's grey tint and lightning; with a
109
+ backdrop the horizon is its color). On WebGPU they are `uniforms(engine).uSkyHorizon` nodes (recipe 56); the GLSL below is the WebGL form. Share the object; a fog of yours copies it in `engine.onRender`
110
+ (recipe 34), not `onFrame`, which runs before the sky updates.
115
111
  ```js
116
112
  const sea = new THREE.ShaderMaterial({ uniforms: { uHorizon: engine.uniforms.uSkyHorizon, uTop: engine.uniforms.uSkyTop, uSunDir: engine.uniforms.uSunDir },
117
113
  fragmentShader: '... gl_FragColor = vec4(mix(base, uHorizon, fresnel), 1.0); #include <tonemapping_fragment> #include <colorspace_fragment>' /* ... */ });
118
- engine.uniforms.uSkyHorizon.value.getHexString(); // read it in JS too (game logic, a HUD swatch)
114
+ engine.uniforms.uSkyHorizon.value.getHexString(); // read it in JS too (game logic, a HUD swatch)
119
115
  ```
120
116
  `engine.sky.horizon` is the override a game set (`null` = the keyframes), not the drawn color.
121
117
 
122
118
  ## 4. Time and brightness (game code)
123
119
  ```js
124
- await engine.skip({ to: '19:30' }); // jump forward to a time: timers, calendar.at / daily, day:start fire on the way (needs a calendar dayLength; recipe 06)
125
- engine.mod('clock.rate', { owner: 'game', set: 0 }); // the calendar and calendar seconds stop together, so the sky stops moving (set: 2 = double speed; remove() undoes it)
120
+ await engine.skip({ to: '19:30' }); // jump forward to a time: timers, calendar.at / daily, day:start fire on the way (needs a calendar dayLength; recipe 06)
121
+ engine.mod('clock.rate', { owner: 'game', set: 0 }); // the calendar and calendar seconds stop together, so the sky stops moving (set: 2 = double speed; remove() undoes it)
126
122
  ```
127
- **The sky draws the calendar's time; it does not own it.** Day, time of day, seasons and day length are the `calendar()` module (recipe 06 "The time table");
128
- the sky reads `engine.calendar.timeOfDay` each frame to place the sun and blend the keyframes, and `engine.calendar.season` for the season tint.
129
- Without a calendar, `sky({ time: '18:30' })` draws that one fixed time (an arena, a museum diorama, a space station window); with a calendar,
130
- `sky({ time })` warns and goes unused (start the day with `calendar({ time })`). A game that draws its own sky (a skybox shader, a 2D painted backdrop) keeps the
131
- calendar and reads it the same way; a game indoors keeps the calendar and installs no sky.
123
+ **The sky draws the calendar's time; it does not own it.** Day, time of day, seasons and day length are the `calendar()` module (recipe 06 "The time table").
124
+ Without a calendar, `sky({ time: '18:30' })` draws that one fixed time; with one, `sky({ time })` warns and goes unused (start the day with `calendar({ time })`).
125
+ A game with its own sky, or indoors with none, keeps the calendar.
132
126
  Fixed dusk in an open world: `openWorld({ time: 18.5 / 24, ... })` (a 0-1 fraction of the day; goes to the calendar) and do not pass
133
127
  `calendar: presets.calendar.cycle` (the template does; the cycle is what moves the clock). `engine.sky.isDay` is `sunHeight > 0` with `sunHeight = sin((timeOfDay - 0.25) * 2π)`: true strictly between timeOfDay 0.25 and 0.75 (06:00 to 18:00 on the default 24-hour face; with `hoursPerDay: H` the same fractions, 0.25H to 0.75H), false at exactly 06:00 and 18:00, so 18:30 already reads as "night" in `describe().time.isDay`. `daylight` = `max(0, sunHeight)`. Keyframes only change colors, not this flip.
134
128
  `engine.calendar.isDay` / `daylight` are the same formula from the clock (they work with no sky); the sky's are what it draws (its fixed time without a calendar).
@@ -140,8 +134,8 @@ Seasons are off by default (`engine.calendar.season` is `null`, no `season:chang
140
134
  The lights and the fog are your own three.js objects, so nothing overwrites them. To darken or tint everything (a cave, a horror segment), your `picture/` code reads one signal of yours and multiplies
141
135
  it in with the weather's (`uWeatherLight`, `uWeatherFog`); the sky color has its own shared points, which stack with the weather's without overwriting it ([recipe 55](55-mods-time-wrap.md#picture-points-follow-the-same-rule)):
142
136
  ```js
143
- const cave = engine.mod('sky.tint', { owner: 'cave', value: { color: 0x402030, amount: 0.5 } }); // amount = zenith, horizon: = horizon
144
- cave.remove(); // leave the cave
137
+ const cave = engine.mod('sky.tint', { owner: 'cave', value: { color: 0x402030, amount: 0.5 } }); // amount = zenith, horizon: = horizon
138
+ cave.remove(); // leave the cave
145
139
  ```
146
140
  `sky.flash` adds, `sky.tint` / `ground.cover` entries blend weighted by their amount, `{ for: 3 }` ends one by itself. A tint color dims with the sky's own light unless `engine.sky.dim.tint = false`.
147
141
 
@@ -151,24 +145,18 @@ cave.remove();
151
145
  - Take a screenshot only after the picture changed: `npm run shot -- / --time 19:30 --weather dust`.
152
146
 
153
147
  ## 6. Day and night in game logic
154
- Gameplay reads day and night from the calendar: test `engine.calendar.isDay`, and fade with `engine.calendar.daylight` (0-1); they work with or
155
- without a sky. Don't decide it from the clock text yourself, so a game with different day lengths or hours stays right. Lights and shop doors that
156
- follow the time of day use `engine.calendar.between(...)` (its page: `api/calendar.md`).
148
+ Gameplay reads `engine.calendar.isDay` and fades with `engine.calendar.daylight` (0-1), with or without a sky, never the clock text; things that follow the hour use `engine.calendar.between(...)` (`api/calendar.md`).
157
149
 
158
150
  ## 7. Wet roads and puddles after rain
159
- The engine gives the rain, not the wet look: `engine.weather.current.rain` (0-1) is the signal; what gets wet, how fast it dries and where
160
- puddles collect are the game's decisions. Water fills the pores of a rough surface, so wet reads as darker and glossier together (lower `color`
151
+ The engine gives the rain (`engine.weather.current.rain`, 0-1), not the wet look: what gets wet, how fast it dries and where puddles collect are the game's. Water fills the pores of a rough surface, so wet reads as darker and glossier together (lower `color`
161
152
  and `roughness`); darker alone reads as dirt or shadow. Gloss only shows when there is something bright to reflect: the sky by day, at night
162
- the lamps and windows as long streaks. A puddle needs a soft-rimmed mask; a hard cut-off makes opaque discs that read as holes. Judge it on a
163
- shot at noon and at night, in rain and after. To compare with your own result afterwards, the technique example `wet-road`
164
- (`threedog examples pull wet-road`) shows one way, with a dry-out delay in game time.
153
+ the lamps and windows as long streaks. A puddle needs a soft-rimmed mask; a hard cut-off makes opaque discs that read as holes. Judge it at noon and at night, in rain and after. One way to compare with: `threedog examples pull wet-road`.
165
154
 
166
155
  ## 8. Clouds: `sky({ clouds })`
167
156
  Keys and defaults are `SkyCloudOptions` in `types/world.d.ts`; at run time the numbers are the `engine.uniforms` of the block at the top of this page.
168
157
  `coverage` multiplies the weather's cloud amount. A `sky()` without `clouds` starts with the cover at 0: write `uCloudCover` to show any.
169
158
 
170
- Why a thin band at the horizon with `kind: 'plane'`: the plane projection divides by height, so near the horizon one screen pixel covers a lot of cloud plane
171
- and the noise is dense and small; overhead one pixel covers little and the same coverage looks sparse. For a sky full of big clouds use
159
+ `kind: 'plane'` crowds small clouds at the horizon (the projection divides by height) and looks sparse overhead; for a sky full of big clouds use
172
160
  `kind: 'cumulus'`, or raise `horizon` and lower `scale`. Cost: both are one 2D pass over the dome (no ray marching); cumulus does about
173
161
  2.7x the noise work of plane on the cloudy pixels (pixels below the horizon or with no cloud cover skip it). Cloud shadows on the ground
174
162
  (the signal `engine.uniforms.uCloudShadow`, a separate setting, off until written) follow the same weather cover, so more clouds still means more shadow.
@@ -179,7 +167,7 @@ sky: { clouds: { kind: 'cumulus', coverage: 1, scale: 0.45, color: 0xfff4e4, sha
179
167
  ```
180
168
 
181
169
  ### Your own cloud function
182
- `engine.sky.clouds(glsl | { glsl, tsl, uniforms })` is the one way in (a `glsl` key in `sky({ clouds })` throws and names it). It recompiles the dome once, so call it at a scene change. The GLSL defines `threedogClouds` as in the example below; the dome calls it for every upper-hemisphere pixel with cover above 0.01, then does `mix(sky, rgb, a)`.
170
+ `engine.sky.clouds(glsl | { glsl, tsl, uniforms })` is the one way in (a `glsl` key in `sky({ clouds })` throws and names it); a WebGPU game passes `tsl` (52 [tsl forms](52-around-the-picture.md#tsl-forms)), the GLSL below is the WebGL form. It recompiles the dome once, so call it at a scene change. The GLSL defines `threedogClouds` as in the example below; the dome calls it for every upper-hemisphere pixel with cover above 0.01, then does `mix(sky, rgb, a)`.
183
171
  `dir` is the unit view direction (`dir.y > 0`), `sunDir` points at the sun (the moon is opposite), `night` runs 0 to 1, `lit` / `shade` are `clouds.color` / `clouds.shade`, `cover` is the weather's cloud amount times `clouds.coverage`. Return the final color (dim it at night yourself) and the opacity (apply your own horizon fade).
184
172
  In scope: the GLSL noise helpers `float threedogHash(vec2 p)` and `float threedogNoise(vec2 p)`, the built-in cloud uniforms (`uSkyCloudScale`, `uSkyCloudSpeed`, `uCloudHorizon`, `uCloudFade`...) and
185
173
  the patch's `uniforms` (declared for you; number, `THREE.Color`, `THREE.Vector2/3/4`, array of 2-4 numbers, or `THREE.Texture`). Change one later
@@ -187,11 +175,11 @@ with `engine.sky.uniforms.uEdge.value = 0.1` (both renderers). A bad `kind`, GLS
187
175
  Flat painted cloud blobs with a hard edge, multiplied by a texture:
188
176
  ```js fragment
189
177
  // sky({ clouds: { color: 0xfff1dc, shade: 0x9aa8c4 } }) gives lit and shade; the function goes through the hook
190
- engine.sky.clouds({ uniforms: { uPaper: paperTexture, uEdge: 0.06 }, // paperTexture: any THREE.Texture, repeat wrapping
178
+ engine.sky.clouds({ uniforms: { uPaper: paperTexture, uEdge: 0.06 }, // paperTexture: any THREE.Texture, repeat wrapping
191
179
  glsl: `vec4 threedogClouds(vec3 d, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cover){
192
180
  vec2 p = d.xz / (d.y + 0.5) * 0.4 + vec2(0.004, 0.002) * time;
193
181
  float n = threedogNoise(p) * 0.65 + threedogNoise(p * 2.3 + 5.0) * 0.35;
194
- float a = smoothstep(1.0 - cover, 1.0 - cover + uEdge, n); // hard edge
182
+ float a = smoothstep(1.0 - cover, 1.0 - cover + uEdge, n); // hard edge
195
183
  float up = clamp(0.5 + (n - threedogNoise(p + sunDir.xz * 0.1)) * 6.0, 0.0, 1.0); // sun side
196
184
  vec3 c = mix(shade, lit, up) * texture2D(uPaper, p * 3.0).rgb * (0.35 + 0.65 * (1.0 - night));
197
185
  return vec4(c, a * smoothstep(0.0, 0.1, d.y));
@@ -214,8 +202,8 @@ renamed (`threedogSkyLayer0`, `1`, ...), so layers from different parts of the g
214
202
  ## 10. Flat backdrop: no horizon at all
215
203
  For a scene that should have no horizon (a menu stage, a board game, a diorama):
216
204
  ```js fragment
217
- sky({ backdrop: 0xefebe4 }); // one color
218
- engine.sky.backdrop = engine.sky.isDay ? 0xefebe4 : 0x2c3346; // live, from your own frame code; null gives the dome back
205
+ sky({ backdrop: 0xefebe4 }); // one color
206
+ engine.sky.backdrop = engine.sky.isDay ? 0xefebe4 : 0x2c3346; // live, from your own frame code; null gives the dome back
219
207
  ```
220
208
  - Hides the dome (no gradient, horizon line, sun / moon disk, stars or clouds) and sets `scene.background` to the color. A plain background
221
209
  color is not tone mapped, so what you write is what shows.
@@ -1,14 +1,15 @@
1
1
  # Materials, lights and models: the game's own picture
2
2
 
3
- **In this recipe**: 0. Where the picture lives · 1. Materials are plain three.js · 1a. The engine's big pieces · 1b. Lights and stalls · 1c. The UI's picture ·
4
- 2. Using your own models instead of procedural ones · 2a. Reusing art · 2b. Wind, cloud shadows and season tint on your own materials ·
5
- 3. When the engine gets a new picture value · 4. Verify
3
+ > **Covers:** the game's own materials, lights and models in plain three.js, which material kind looks how.
4
+ > **Use when:** giving things their look.
5
+ > **Shortest:** `new THREE.MeshStandardMaterial({ color, roughness })` in `picture/materials.js`.
6
+ > **Sections:** 0 Where the picture · 1 Materials are plain · 1a The engine's big · 1b Lights and stalls · 1c The UI's picture · 2 Using your own · 2b Wind, cloud shadows · 3 When the engine · 4 Verify
6
7
 
7
8
  ```js
8
9
  // picture/materials.js: the game's materials are its own three.js objects
9
10
  const wood = new THREE.MeshStandardMaterial({ color: 0x8a5a36, roughness: 0.8 });
10
11
  const crate = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1), wood);
11
- engine.water.material.color.set(0x3070a0); // a big engine piece hands out its material the same way
12
+ engine.water.material.color.set(0x3070a0); // a big engine piece hands out its material the same way
12
13
  ```
13
14
 
14
15
  **The engine ships no art.** No default picture, character model, terrain drawing or terrain generator: until the game gives one, everything is a
@@ -26,8 +27,18 @@ separate package, `@threedog/terrain-noise`, because the shape of the world is g
26
27
  `@threedog/post-effects` and go in as `plugins/` files (recipe 40 §1, chain order: recipe 52).
27
28
 
28
29
  ## 1. Materials are plain three.js
29
- `new THREE.MeshStandardMaterial(...)`, `MeshToonMaterial`, `ShaderMaterial`, `onBeforeCompile`: all work as in any three.js project, and a plain material gets fog and
30
+ `new THREE.MeshStandardMaterial(...)`, `MeshToonMaterial`, your own shading in TSL (WebGPU, recipe 56) or GLSL (WebGL only, recipe 43): all work as in any three.js project, and a plain material gets fog and
30
31
  cascaded shadows by itself. Keep them in `picture/materials.js` by name, and let other code ask for `picture.materials.wall`, so a change of picture touches one folder.
32
+
33
+ **Which kind gives which look** (three's own kinds; any of them suits any style, and one game may mix them):
34
+
35
+ | Kind | What it looks like | When it fits |
36
+ |---|---|---|
37
+ | `MeshLambertMaterial` | matte: light falls off smoothly, no highlight | cheap surfaces that never shine; many objects, low tiers |
38
+ | `MeshToonMaterial` | light in flat bands (`gradientMap` sets how many and how soft) | shading read as shapes of color rather than a gradient |
39
+ | `MeshStandardMaterial` / `MeshPhysicalMaterial` | physically based: roughness and metalness, reflections of the environment; Physical adds clearcoat, sheen, transmission | surfaces that should react to light and environment like real ones |
40
+ | `MeshBasicMaterial` | unlit: exactly its color or texture, no shading, no shadows received | color that must stay as painted: sprites, UI in the world, glowing signs, sky cards |
41
+ | Your own (`ShaderMaterial`, TSL node material, `onBeforeCompile`) | whatever the shader computes | a look none of these gives (recipe 43, recipe 56 on WebGPU) |
31
42
  ```js
32
43
  // Toon with an explicit light ramp: three.js's gradientMap; rampTexture takes grays, dark to light, and how far the bands melt (0-1). three's toon reads only
33
44
  // the red channel, so a colored ramp needs celLighting on the WebGPU route (recipe 56); on WebGL a colored shade is a lighting patch (recipe 43)
@@ -69,14 +80,14 @@ moves to the sources that matter most (near the camera, bright, high `priority`)
69
80
  it before `engine.start()` so the startup compile covers its lights:
70
81
  ```js fragment
71
82
  import { lightPool } from 'threedog';
72
- engine.use(lightPool({ point: 8 })); // 8 PointLights; lightPool({ spot: 2, shadows: 1 }) adds spots / lets one point light cast
73
- for (const t of torches) engine.lightPool.add(t, { // an Object3D is followed; a position stays put
83
+ engine.use(lightPool({ point: 8 })); // 8 PointLights; lightPool({ spot: 2, shadows: 1 }) adds spots / lets one point light cast
84
+ for (const t of torches) engine.lightPool.add(t, { // an Object3D is followed; a position stays put
74
85
  color: 0xffa040, intensity: 4, distance: 8,
75
86
  flicker: (time, i) => 0.85 + 0.15 * Math.sin(time * 13 + i),
76
- glow: t.getObjectByName('halo'), // stand-in while it has no real light: its material's opacity / emissiveIntensity fades to 0 as the light fades in
87
+ glow: t.getObjectByName('halo'), // stand-in while it has no real light: its material's opacity / emissiveIntensity fades to 0 as the light fades in
77
88
  });
78
89
  const flash = engine.lightPool.add(gun.muzzle, { intensity: 0, priority: 5, distance: 6 });
79
- flash.set({ intensity: 8 }); /* next frame */ flash.set({ intensity: 0 }); // muzzle flash: no light is created
90
+ flash.set({ intensity: 8 }); /* next frame */ flash.set({ intensity: 0 }); // muzzle flash: no light is created
80
91
  ```
81
92
  Pool lights cast no shadow unless you ask (`shadows`), and the pool picks by distance, brightness and `priority`: it knows nothing of rooms, so indoors a lamp shines through the wall into the next room.
82
93
  Three ways out, by how much of the picture depends on it: turn off the sources the player cannot see from where they are with `set({ intensity: 0 })` (the game knows its rooms; near a door keep both sides on, and a
@@ -97,7 +108,7 @@ const neon = new THREE.MeshStandardMaterial({ emissive: 0x33ccff });
97
108
  engine.onFrame(() => {
98
109
  const night = engine.uniforms.uNight.value, day = engine.uniforms.uDaylight.value;
99
110
  windows.emissiveIntensity = 2 * night;
100
- neon.emissiveIntensity = 0.4 + 2.6 * (1 - THREE.MathUtils.smoothstep(day, 0, 0.6)); // its own dusk: faintly lit by day, on while the sky is still bright
111
+ neon.emissiveIntensity = 0.4 + 2.6 * (1 - THREE.MathUtils.smoothstep(day, 0, 0.6)); // its own dusk: faintly lit by day, on while the sky is still bright
101
112
  });
102
113
  ```
103
114
  Share one Material between the meshes that glow together. Models built later bring their own copies: collect them when the model is made
@@ -121,15 +132,14 @@ rules, `fonts` lists font asset names to load at start (the files sit in an asse
121
132
  Models are assets: content names them, an asset pack maps the names to files or generators. Register a later manifest with the same
122
133
  name to swap one:
123
134
  ```js fragment
124
- engine.assets.manifest(yourAssets); // assets from an asset pack you have: trees, rocks, flowers... built in code
125
- engine.assets.manifest({ name: 'mine', models: { pine: () => myPineGeometry(), well: '/models/well.glb' } }); // replaces pine, adds well
135
+ engine.assets.manifest(yourAssets); // assets from an asset pack you have: trees, rocks, flowers... built in code
136
+ engine.assets.manifest({ name: 'mine', models: { pine: () => myPineGeometry(), well: '/models/well.glb' } }); // replaces pine, adds well
126
137
  ```
127
138
  Vegetation takes a geometry (`geometry: await engine.assets.geometry('pine')`, the first mesh in the model) or a whole model with one material per
128
139
  mesh, e.g. bark trunk + alpha-cut leaf cards:
129
140
  `engine.vegetation.define('oak', { model: await engine.assets.model('oak'), wind: 0.02 })` (still one draw call per part; felling hides every part). For
130
141
  the import workflow see `10-blender-level.md`.
131
142
  `mergeColored(parts, { flat: false })` keeps smooth normals; UVs survive when every part has them.
132
- A generator in `models` may also return an Object3D with its own materials; those are used as they are.
133
143
 
134
144
  ### 2a. Reusing art from somewhere else: copy it in, do not depend on it
135
145
  Art code you already have (generator modules such as `art/my-crate.js` from an earlier game, a folder of your own, files someone gave you, a package
@@ -149,11 +159,10 @@ GLB files from Blender are copied the same way and checked with recipe 46 sectio
149
159
  The engine's shader effects are named patches that work on any material that has the usual three.js chunks (WebGL only):
150
160
  ```js fragment
151
161
  import { applyEffects } from 'threedog';
152
- const leaves = applyEffects(new THREE.MeshToonMaterial({ color: 0x5a8a3a }), { wind: 0.03, season: 'foliage' }); // clouds default on
153
- engine.vegetation.define('bush', { geometry, material: leaves }); // vegetation adds them itself; effects: false keeps the material untouched
162
+ const leaves = applyEffects(new THREE.MeshToonMaterial({ color: 0x5a8a3a }), { wind: 0.03, season: 'foliage' }); // clouds default on
163
+ engine.vegetation.define('bush', { geometry, material: leaves }); // vegetation adds them itself; effects: false keeps the material untouched
154
164
  ```
155
- The shadow sways with the wind automatically. Your own effect (pixel snapping, dissolve...) is a patch too, and stacks with the built-in ones and with
156
- the material's own `onBeforeCompile`:
165
+ The shadow sways with the wind automatically. Your own effect (pixel snapping, dissolve...) is a patch too, stacking with the built-in ones; the GLSL form below is WebGL, a WebGPU game gives the patch a `tsl` field (recipe 56):
157
166
  `applyEffects(mat, { patches:
158
167
  [{ name: 'snap', cacheKey: 64, uniforms, glsl: { vertex: { pars: '...', project_vertex: '...code after #include <project_vertex>' } } }] })`.
159
168
  A missing `#include` anchor throws. A hand-written `ShaderMaterial` can `#include <threedog_wind_vertex>`, `<threedog_clouds_pars_fragment>` etc. (see
@@ -1,14 +1,19 @@
1
1
  # Importing Blender models and levels
2
2
 
3
+ > **Covers:** levels and models from Blender: naming conventions, compression, plants on a level.
4
+ > **Use when:** the map is built in a modeling tool.
5
+ > **Shortest:** `engine.use(level({ url: '/models/town.glb' }))`.
6
+ > **Sections:** 1 Place things in · 2 Compression · 3 Putting it in · 4 Grass and trees · 5 Verify · 6 A level and
7
+
3
8
  ## 1. Place things in Blender by naming convention (the level module recognizes names)
4
9
  | Purpose | How to name it |
5
10
  |---|---|
6
11
  | Walkable ground | Object name contains `ground` `floor` `road` `terrain` `stair(s)` `ramp`, or custom property `walkable = true` (if there are none, every mesh counts as walkable); ground type = custom property `groundType`, otherwise the material name |
7
- | Walls / obstacles | `col_xxx`: a hidden collision box that only blocks the player (hidden automatically after loading); or custom property `collider = true` (a visible object that also blocks) |
12
+ | Walls / obstacles | `col_xxx`: a hidden collision box that only blocks the player (hidden automatically after loading); or custom property `collider = true` (a visible object that also blocks); custom property `layer` (text): characters with it in `passes` walk through (recipe 12) |
8
13
  | Spawn point | Empty object `spawn` (or `spawn_2`...) |
9
- | NPC position | Empty object `npc_店主` |
10
- | Trigger zone | Empty object `trigger_门口`; the custom properties `shape` (cylinder/sphere/box), `radius`, `height` become trigger zone parameters |
11
- | Other markers | Empty object `marker_宝箱`; all custom properties go into `userData` unchanged |
14
+ | NPC position | Empty object `npc_shopkeeper` |
15
+ | Trigger zone | Empty object `trigger_door`; the custom properties `shape` (cylinder/sphere/box), `radius`, `height` become trigger zone parameters |
16
+ | Other markers | Empty object `marker_chest`; all custom properties go into `userData` unchanged |
12
17
  | Things a save must know (a door that opens, a rock that can be removed) | Custom property `template = 'door'` (an instance of a content template; its other custom properties fill the template's state) or `id = true` (the node itself is the model). The node becomes a world record with id `<level file name>/<node name>` (`town/door_front`), saved as a diff (needs `world()` installed, and `content()` for `template`); untagged meshes stay static scenery (recipe 30 §2) |
13
18
 
14
19
  Export glTF/GLB (tick "Custom Properties") into `art/models/` (create it if missing).
@@ -21,15 +26,15 @@ hierarchy are kept; faces are not reduced. Only changed files are processed; `--
21
26
  ```js fragment
22
27
  import { presets, level, collision, followCamera, characters, interactions, dialogue, triggers, content, hlod } from 'threedog';
23
28
  engine.use(level({ url: '/models/town.glb' }), collision(), followCamera(), characters(), interactions({ ...presets.interactions.nearest }), dialogue(), triggers(), content(), hlod());
24
- engine.events.once('level:loaded', () => { // once: level:loaded fires again on every level change
25
- engine.characters.createPlayer({ ...presets.player.thirdPerson, spawn: engine.level.spawn });
26
- engine.content.load(data); // a place in content can be a marker name directly: { place: 'npc_店主' }
29
+ engine.events.once('level:loaded', () => { // once: level:loaded fires again on every level change
30
+ engine.characters.addPlayer({ ...presets.player.thirdPerson, spawn: engine.level.spawn });
31
+ engine.content.load(data); // a place in content can be a marker name directly: { place: 'npc_shopkeeper' }
27
32
  });
28
33
  engine.start();
29
34
  ```
30
- - Trigger zone data: write `{ 门口: { fromLevel: true, onEnter: { toast: '欢迎' } } }` in `<game>/content/triggers.js` (tag = the name after `trigger_`).
35
+ - Trigger zone data: write `{ door: { fromLevel: true, onEnter: { toast: 'Welcome' } } }` in `<game>/content/triggers.js` (tag = the name after `trigger_`).
31
36
  - Content validation (`npm run check`) reads the level `.glb` files in `art/models/` and `public/models/` (needs `@gltf-transform/cli` installed):
32
- marker names used in content (`{ place: 'npc_店主' }`) need no description in `content/places.js`; a `fromLevel` trigger zone must have a
37
+ marker names used in content (`{ place: 'npc_shopkeeper' }`) need no description in `content/places.js`; a `fromLevel` trigger zone must have a
33
38
  `trigger_<tag>` node, and a node's `template` must exist in `content/templates.js`. Without a readable `.glb`, validation
34
39
  skips `fromLevel` and GAMEMAP says the markers cannot be read statically; `level.js` is only for code-built levels.
35
40
  - `npm run assets -- check` prints what the level will find in each model (spawns, colliders, triggers, template nodes, duplicate ids) plus
@@ -37,7 +42,7 @@ engine.start();
37
42
  - When the level changes, the
38
43
  old level's trigger zones and the like are deleted automatically (`level.track`); NPCs, pickups and props placed by marker only lose their model
39
44
  while their data stays (with a zone), and are rebuilt when you return to this level; things that were picked up / deleted stay gone.
40
- - Get a marker in code: `engine.level.marker('marker_宝箱')?.position`, `engine.level.markersWith('npc_')`.
45
+ - Get a marker in code: `engine.level.marker('marker_chest')?.position`, `engine.level.markersWith('npc_')`.
41
46
  - Many buildings: install `hlod()`, which merges distant ones into a few meshes. For a navmesh see `12-navmesh.md`.
42
47
  - A single model (not a level): `engine.assets.manifest({ models: { house: '/models/house.glb' } })`,
43
48
  `const h = await engine.assets.model('house', { static: true })` (static: registers it for rays).