threedog 0.2.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (725) hide show
  1. package/CHANGELOG.md +371 -1
  2. package/README.md +21 -12
  3. package/core/Animator.js +15 -12
  4. package/core/Assets.js +92 -26
  5. package/core/Audio.js +45 -38
  6. package/core/Baked.js +30 -15
  7. package/core/Batching.js +102 -15
  8. package/core/Budget.js +40 -19
  9. package/core/Clock.js +40 -80
  10. package/core/DebugOverrides.js +75 -25
  11. package/core/Describe.js +105 -45
  12. package/core/Engine.js +203 -75
  13. package/core/Events.js +4 -1
  14. package/core/I18n.js +25 -13
  15. package/core/Input.js +175 -80
  16. package/core/Inspect.js +8 -5
  17. package/core/InspectMaterials.js +84 -0
  18. package/core/InspectPerf.js +68 -0
  19. package/core/InspectScene.js +13 -2
  20. package/core/Loading.js +2 -1
  21. package/core/MaterialInfo.js +7 -5
  22. package/core/Ops.js +50 -9
  23. package/core/Random.js +9 -2
  24. package/core/Rays.js +12 -7
  25. package/core/SaveStore.js +41 -9
  26. package/core/Saves.js +71 -15
  27. package/core/Stream.js +13 -10
  28. package/core/Threads.js +26 -7
  29. package/core/UrlState.js +69 -13
  30. package/core/Views.js +10 -6
  31. package/core/actor.js +1 -1
  32. package/core/adaptive.js +93 -0
  33. package/core/assetEntry.js +27 -7
  34. package/core/assetHot.js +176 -0
  35. package/core/assetLoad.js +44 -19
  36. package/core/assetManifest.js +53 -11
  37. package/core/assetReport.js +5 -5
  38. package/core/audioRules.js +13 -11
  39. package/core/audioVoice.js +69 -42
  40. package/core/batchGroups.js +9 -1
  41. package/core/canvasBox.js +1 -2
  42. package/core/catalog.js +21 -5
  43. package/core/cells.js +62 -0
  44. package/core/checks.js +10 -8
  45. package/core/chunkStream.js +87 -0
  46. package/core/control.js +149 -0
  47. package/core/copies.js +32 -0
  48. package/core/dayTime.js +12 -6
  49. package/core/debugView.js +85 -18
  50. package/core/describeRender.js +117 -21
  51. package/core/describeText.js +41 -21
  52. package/core/engineCamera.js +32 -0
  53. package/core/errorCodes.js +478 -32
  54. package/core/errorHints.js +41 -142
  55. package/core/errors.js +31 -8
  56. package/core/events.generated.js +13 -7
  57. package/core/gameLights.js +69 -0
  58. package/core/grayMap.js +20 -0
  59. package/core/grid.js +14 -13
  60. package/core/gridLoad.js +2 -1
  61. package/core/ground.js +6 -4
  62. package/core/headlessLoad.js +55 -0
  63. package/core/holds.js +78 -50
  64. package/core/inputContext.js +11 -7
  65. package/core/inputDefaults.js +24 -21
  66. package/core/inputPad.js +1 -1
  67. package/core/inputPointer.js +1 -1
  68. package/core/inputTouch.js +2 -2
  69. package/core/lifecycle.js +46 -12
  70. package/core/lightWatch.js +9 -5
  71. package/core/loop.js +109 -43
  72. package/core/math.js +18 -3
  73. package/core/moduleSlots.js +100 -0
  74. package/core/moduleTypes.js +86 -0
  75. package/core/modules.js +147 -29
  76. package/core/movement.js +2 -2
  77. package/core/namedModel.js +74 -0
  78. package/core/opsCheck.js +3 -3
  79. package/core/opsFail.js +15 -6
  80. package/core/opsGuard.js +4 -4
  81. package/core/opsRun.js +4 -3
  82. package/core/owned.js +171 -0
  83. package/core/page.js +44 -10
  84. package/core/params.js +30 -8
  85. package/core/pictureSlots.js +33 -0
  86. package/core/pictureWriters.js +343 -0
  87. package/core/plugins.js +245 -0
  88. package/core/saveApply.js +99 -17
  89. package/core/saveFiles.js +8 -6
  90. package/core/saveValues.js +46 -0
  91. package/core/saveVersions.js +20 -3
  92. package/core/scatter.js +48 -19
  93. package/core/sceneDelta.js +211 -0
  94. package/core/sceneMethods.js +31 -33
  95. package/core/screenToGround.js +1 -1
  96. package/core/services.js +27 -11
  97. package/core/session.js +28 -25
  98. package/core/shaderCost.js +78 -0
  99. package/core/shadowTypes.js +3 -2
  100. package/core/shadows.js +405 -0
  101. package/core/sharedPoint.js +303 -0
  102. package/core/skip.js +36 -28
  103. package/core/stackFrames.js +45 -0
  104. package/core/stacks.js +166 -0
  105. package/core/startup.js +153 -13
  106. package/core/streamSources.js +0 -11
  107. package/core/targeting.js +1 -1
  108. package/core/textureBytes.js +20 -0
  109. package/core/thingExplain.js +3 -3
  110. package/core/thingOps.js +29 -6
  111. package/core/things.js +22 -12
  112. package/core/threadPure.js +7 -3
  113. package/core/threePatches.js +47 -0
  114. package/core/tier.js +21 -10
  115. package/core/time.js +236 -0
  116. package/core/uiClock.js +25 -0
  117. package/core/util.js +8 -2
  118. package/core/validate.js +66 -87
  119. package/core/view.js +43 -0
  120. package/core/wrap.js +106 -0
  121. package/docs/AI.md +95 -104
  122. package/docs/API.md +35 -31
  123. package/docs/CODEMAP.md +231 -176
  124. package/docs/COMMANDS.md +63 -39
  125. package/docs/CONVENTIONS.md +99 -31
  126. package/docs/MIGRATING-0.3.md +248 -0
  127. package/docs/MIGRATING-0.4.md +320 -0
  128. package/docs/MIGRATING-0.5.md +68 -0
  129. package/docs/MIGRATING-0.6.md +126 -0
  130. package/docs/MIGRATING-0.7.md +39 -0
  131. package/docs/PERF.md +35 -7
  132. package/docs/THREE.md +82 -28
  133. package/docs/api/ambience.md +0 -1
  134. package/docs/api/assets.md +15 -11
  135. package/docs/api/audio.md +10 -14
  136. package/docs/api/budget.md +4 -0
  137. package/docs/api/calendar.md +41 -0
  138. package/docs/api/cameraRig.md +16 -5
  139. package/docs/api/characters.md +41 -24
  140. package/docs/api/clock.md +6 -5
  141. package/docs/api/collision.md +10 -7
  142. package/docs/api/content.md +6 -4
  143. package/docs/api/dialogue.md +9 -9
  144. package/docs/api/engine.md +95 -65
  145. package/docs/api/events.md +20 -14
  146. package/docs/api/grids.md +10 -3
  147. package/docs/api/ground.md +1 -1
  148. package/docs/api/hud.md +5 -2
  149. package/docs/api/i18n.md +1 -1
  150. package/docs/api/input.md +13 -7
  151. package/docs/api/interactions.md +10 -6
  152. package/docs/api/inventory.md +17 -17
  153. package/docs/api/level.md +0 -2
  154. package/docs/api/lightPool.md +3 -1
  155. package/docs/api/music.md +1 -1
  156. package/docs/api/nav.md +3 -0
  157. package/docs/api/occlusion.md +5 -0
  158. package/docs/api/openWorld.md +2 -1
  159. package/docs/api/particles.md +6 -3
  160. package/docs/api/photo.md +0 -2
  161. package/docs/api/pickups.md +21 -0
  162. package/docs/api/post.md +8 -5
  163. package/docs/api/quests.md +2 -3
  164. package/docs/api/rigid.md +16 -14
  165. package/docs/api/saves.md +6 -4
  166. package/docs/api/settings.md +2 -3
  167. package/docs/api/sky.md +18 -49
  168. package/docs/api/stream.md +1 -1
  169. package/docs/api/terrain.md +16 -7
  170. package/docs/api/terrainDraw.md +12 -0
  171. package/docs/api/timeline.md +3 -4
  172. package/docs/api/tools.md +32 -15
  173. package/docs/api/triggers.md +7 -10
  174. package/docs/api/vegetation.md +17 -9
  175. package/docs/api/vegetationDraw.md +10 -0
  176. package/docs/api/water.md +9 -21
  177. package/docs/api/weather.md +10 -15
  178. package/docs/api/weatherDraw.md +10 -0
  179. package/docs/api/world.md +3 -2
  180. package/docs/recipes/01-new-game.md +52 -42
  181. package/docs/recipes/02-npc.md +24 -7
  182. package/docs/recipes/03-items-pickups.md +57 -22
  183. package/docs/recipes/04-quests.md +12 -5
  184. package/docs/recipes/05-props-bake.md +174 -22
  185. package/docs/recipes/06-clock-events.md +100 -52
  186. package/docs/recipes/07-flow-scenes-pause.md +50 -10
  187. package/docs/recipes/08-weather-sky.md +134 -37
  188. package/docs/recipes/09-materials-lights-models.md +185 -0
  189. package/docs/recipes/10-blender-level.md +16 -4
  190. package/docs/recipes/11-vehicles.md +67 -10
  191. package/docs/recipes/13-animation.md +23 -9
  192. package/docs/recipes/14-custom-module.md +63 -29
  193. package/docs/recipes/15-perf.md +31 -10
  194. package/docs/recipes/16-dev-bridge.md +74 -40
  195. package/docs/recipes/18-world.md +26 -14
  196. package/docs/recipes/19-shooting-picking.md +12 -10
  197. package/docs/recipes/20-content-actions-save.md +60 -18
  198. package/docs/recipes/21-camera.md +55 -17
  199. package/docs/recipes/22-shop-gold.md +3 -3
  200. package/docs/recipes/23-ops.md +17 -11
  201. package/docs/recipes/26-ui-parts.md +86 -13
  202. package/docs/recipes/27-net.md +11 -5
  203. package/docs/recipes/28-terrain.md +36 -3
  204. package/docs/recipes/29-grid.md +46 -19
  205. package/docs/recipes/30-templates.md +72 -15
  206. package/docs/recipes/31-audio.md +20 -12
  207. package/docs/recipes/32-action-game.md +51 -4
  208. package/docs/recipes/34-environment-lighting.md +108 -21
  209. package/docs/recipes/35-picture-from-reference.md +147 -0
  210. package/docs/recipes/36-sky-ground-plants.md +158 -0
  211. package/docs/recipes/{37-terrain-look-hooks.md → 37-terrain-hooks.md} +9 -12
  212. package/docs/recipes/38-environment-hooks.md +67 -0
  213. package/docs/recipes/40-scene.md +114 -32
  214. package/docs/recipes/42-terrain-shape.md +2 -2
  215. package/docs/recipes/43-shader-patches-surfaces.md +206 -0
  216. package/docs/recipes/44-water-weather-hooks.md +191 -0
  217. package/docs/recipes/45-cascaded-shadows.md +130 -23
  218. package/docs/recipes/46-blender-art-route.md +17 -20
  219. package/docs/recipes/47-island-snow-backdrop.md +13 -15
  220. package/docs/recipes/49-game-module-contract.md +30 -17
  221. package/docs/recipes/50-own-renderer.md +4 -4
  222. package/docs/recipes/51-capability-catalog.md +3 -3
  223. package/docs/recipes/52-around-the-picture.md +181 -0
  224. package/docs/recipes/53-ground-up-close.md +12 -12
  225. package/docs/recipes/54-three-idioms.md +88 -0
  226. package/docs/recipes/55-mods-time-wrap.md +124 -0
  227. package/docs/recipes/56-webgpu-tsl.md +303 -0
  228. package/docs/recipes/57-control.md +104 -0
  229. package/docs/recipes/58-input.md +60 -0
  230. package/docs/recipes/59-depth-post-effects.md +83 -0
  231. package/docs/recipes/60-judge-the-picture.md +70 -0
  232. package/docs/recipes/61-deploy.md +27 -0
  233. package/docs/recipes/62-picture-code.md +244 -0
  234. package/docs/recipes/63-third-person-start.md +77 -0
  235. package/docs/recipes/64-particles.md +35 -0
  236. package/examples/action/.threedog/content-index.json +1 -0
  237. package/examples/action/GAMEMAP.md +20 -14
  238. package/examples/action/assets.js +8 -0
  239. package/examples/action/content/actions.js +1 -1
  240. package/examples/action/content/audio.js +5 -5
  241. package/examples/action/main.js +12 -15
  242. package/examples/action/models.js +23 -24
  243. package/examples/action/picture/index.js +13 -0
  244. package/examples/action/picture/lights.js +35 -0
  245. package/examples/action/picture/materials.js +8 -0
  246. package/examples/action/picture/palette.js +33 -0
  247. package/examples/plain-picture/.threedog/content-index.json +1 -0
  248. package/examples/plain-picture/FINDINGS.md +53 -0
  249. package/examples/plain-picture/GAMEMAP.md +90 -0
  250. package/examples/plain-picture/main.js +48 -0
  251. package/examples/plain-picture/picture/index.js +21 -0
  252. package/examples/plain-picture/picture/lights.js +54 -0
  253. package/examples/plain-picture/picture/materials.js +24 -0
  254. package/examples/plain-picture/picture/palette.js +16 -0
  255. package/examples/plain-picture/picture/sky.js +37 -0
  256. package/examples/pullable.json +133 -0
  257. package/examples/rc2d/.threedog/content-index.json +1 -0
  258. package/examples/rc2d/GAMEMAP.md +88 -0
  259. package/examples/rc2d/README.md +57 -0
  260. package/examples/rc2d/main.js +55 -0
  261. package/examples/rc2d/picture/index.js +18 -0
  262. package/examples/rc2d/picture/lights.js +11 -0
  263. package/examples/rc2d/picture/materials.js +18 -0
  264. package/examples/rc2d/picture/palette.js +15 -0
  265. package/examples/rc2d/picture/post.js +11 -0
  266. package/examples/rc2d/rc2d.js +187 -0
  267. package/examples/rc2d/shaders.js +144 -0
  268. package/examples/sheepisland/.threedog/content-index.json +1 -0
  269. package/examples/sheepisland/GAMEMAP.md +22 -17
  270. package/examples/sheepisland/assets.js +5 -0
  271. package/examples/sheepisland/content/templates.js +1 -1
  272. package/examples/sheepisland/content/vegetation.js +3 -1
  273. package/examples/sheepisland/main.js +29 -18
  274. package/examples/sheepisland/{style/models.js → models.js} +13 -24
  275. package/examples/sheepisland/picture/index.js +20 -0
  276. package/examples/sheepisland/picture/lights.js +34 -0
  277. package/examples/sheepisland/picture/materials.js +61 -0
  278. package/examples/sheepisland/picture/palette.js +60 -0
  279. package/examples/sheepisland/picture/sky.js +20 -0
  280. package/examples/sheepisland/views.js +1 -1
  281. package/examples/styletest/.threedog/content-index.json +1 -0
  282. package/examples/styletest/GAMEMAP.md +25 -22
  283. package/examples/styletest/assets.js +6 -0
  284. package/examples/styletest/content/templates.js +1 -1
  285. package/examples/styletest/content/vegetation.js +1 -1
  286. package/examples/styletest/main.js +25 -34
  287. package/examples/styletest/models.js +30 -30
  288. package/examples/styletest/params.js +2 -5
  289. package/examples/styletest/picture/env.js +38 -0
  290. package/examples/styletest/picture/index.js +16 -0
  291. package/examples/styletest/picture/lights.js +9 -0
  292. package/examples/styletest/picture/materials.js +28 -0
  293. package/examples/styletest/picture/palette.js +22 -0
  294. package/examples/techniques/contact-shadows/README.md +91 -0
  295. package/examples/techniques/contact-shadows/contactShadows.js +67 -0
  296. package/examples/techniques/contact-shadows/main.js +55 -0
  297. package/examples/techniques/contact-shadows/picture/index.js +14 -0
  298. package/examples/techniques/contact-shadows/picture/lights.js +34 -0
  299. package/examples/techniques/contact-shadows/picture/materials.js +12 -0
  300. package/examples/techniques/contact-shadows/picture/palette.js +17 -0
  301. package/examples/techniques/day-night-grade/README.md +83 -0
  302. package/examples/techniques/day-night-grade/main.js +41 -0
  303. package/examples/techniques/day-night-grade/picture/index.js +20 -0
  304. package/examples/techniques/day-night-grade/picture/lights.js +45 -0
  305. package/examples/techniques/day-night-grade/picture/materials.js +15 -0
  306. package/examples/techniques/day-night-grade/picture/palette.js +59 -0
  307. package/examples/techniques/day-night-grade/picture/post.js +25 -0
  308. package/examples/techniques/day-night-grade/picture/sky.js +33 -0
  309. package/examples/techniques/interior-light/README.md +106 -0
  310. package/examples/techniques/interior-light/interiorLight.js +47 -0
  311. package/examples/techniques/interior-light/main.js +87 -0
  312. package/examples/techniques/interior-light/picture/index.js +24 -0
  313. package/examples/techniques/interior-light/picture/lights.js +52 -0
  314. package/examples/techniques/interior-light/picture/materials.js +13 -0
  315. package/examples/techniques/interior-light/picture/palette.js +32 -0
  316. package/examples/techniques/interior-light/picture/sky.js +40 -0
  317. package/examples/techniques/modular-building/README.md +126 -0
  318. package/examples/techniques/modular-building/kit.js +426 -0
  319. package/examples/techniques/modular-building/main.js +39 -0
  320. package/examples/techniques/modular-building/picture/index.js +17 -0
  321. package/examples/techniques/modular-building/picture/lights.js +26 -0
  322. package/examples/techniques/modular-building/picture/materials.js +13 -0
  323. package/examples/techniques/modular-building/picture/palette.js +23 -0
  324. package/examples/techniques/night-lights/README.md +95 -0
  325. package/examples/techniques/night-lights/main.js +47 -0
  326. package/examples/techniques/night-lights/nightLights.js +95 -0
  327. package/examples/techniques/night-lights/picture/index.js +18 -0
  328. package/examples/techniques/night-lights/picture/lights.js +44 -0
  329. package/examples/techniques/night-lights/picture/materials.js +15 -0
  330. package/examples/techniques/night-lights/picture/palette.js +34 -0
  331. package/examples/techniques/night-lights/picture/post.js +9 -0
  332. package/examples/techniques/night-lights/picture/sky.js +36 -0
  333. package/examples/techniques/outlines-and-rim/README.md +59 -0
  334. package/examples/techniques/outlines-and-rim/main.js +61 -0
  335. package/examples/techniques/outlines-and-rim/outlines.js +64 -0
  336. package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
  337. package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
  338. package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
  339. package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
  340. package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
  341. package/examples/techniques/procedural-animation/README.md +79 -0
  342. package/examples/techniques/procedural-animation/creature.js +44 -0
  343. package/examples/techniques/procedural-animation/main.js +47 -0
  344. package/examples/techniques/procedural-animation/picture/index.js +15 -0
  345. package/examples/techniques/procedural-animation/picture/lights.js +35 -0
  346. package/examples/techniques/procedural-animation/picture/materials.js +10 -0
  347. package/examples/techniques/procedural-animation/picture/palette.js +16 -0
  348. package/examples/techniques/procedural-animation/picture/sky.js +31 -0
  349. package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
  350. package/examples/techniques/procedural-surface/README.md +69 -0
  351. package/examples/techniques/procedural-surface/main.js +65 -0
  352. package/examples/techniques/procedural-surface/picture/index.js +14 -0
  353. package/examples/techniques/procedural-surface/picture/lights.js +18 -0
  354. package/examples/techniques/procedural-surface/picture/materials.js +34 -0
  355. package/examples/techniques/procedural-surface/picture/palette.js +15 -0
  356. package/examples/techniques/procedural-surface/surface.js +120 -0
  357. package/examples/techniques/stylized-shading/README.md +74 -0
  358. package/examples/techniques/stylized-shading/main.js +62 -0
  359. package/examples/techniques/stylized-shading/picture/index.js +14 -0
  360. package/examples/techniques/stylized-shading/picture/lights.js +23 -0
  361. package/examples/techniques/stylized-shading/picture/materials.js +18 -0
  362. package/examples/techniques/stylized-shading/picture/palette.js +19 -0
  363. package/examples/techniques/stylized-shading/shading.js +131 -0
  364. package/examples/techniques/sun-and-key-light/README.md +133 -0
  365. package/examples/techniques/sun-and-key-light/keyLight.js +71 -0
  366. package/examples/techniques/sun-and-key-light/main.js +51 -0
  367. package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
  368. package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
  369. package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
  370. package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
  371. package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
  372. package/examples/techniques/three-looks/README.md +21 -0
  373. package/examples/techniques/three-looks/main.js +58 -0
  374. package/examples/techniques/three-looks/picture/cartoon.js +23 -0
  375. package/examples/techniques/three-looks/picture/cinematic.js +27 -0
  376. package/examples/techniques/three-looks/picture/comic.js +27 -0
  377. package/examples/techniques/three-looks/picture/index.js +14 -0
  378. package/examples/techniques/three-looks/picture/sun.js +23 -0
  379. package/examples/techniques/wet-road/README.md +102 -0
  380. package/examples/techniques/wet-road/main.js +48 -0
  381. package/examples/techniques/wet-road/picture/index.js +17 -0
  382. package/examples/techniques/wet-road/picture/lights.js +57 -0
  383. package/examples/techniques/wet-road/picture/materials.js +16 -0
  384. package/examples/techniques/wet-road/picture/palette.js +24 -0
  385. package/examples/techniques/wet-road/picture/sky.js +46 -0
  386. package/examples/techniques/wet-road/wetRoad.js +209 -0
  387. package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
  388. package/examples/webgpu-tsl/GAMEMAP.md +89 -0
  389. package/examples/webgpu-tsl/README.md +45 -0
  390. package/examples/webgpu-tsl/main.js +44 -0
  391. package/examples/webgpu-tsl/picture/index.js +18 -0
  392. package/examples/webgpu-tsl/picture/lights.js +25 -0
  393. package/examples/webgpu-tsl/picture/materials.js +36 -0
  394. package/examples/webgpu-tsl/picture/palette.js +23 -0
  395. package/examples/webgpu-tsl/picture/post.js +16 -0
  396. package/examples/webgpu-tsl/picture/sky.js +30 -0
  397. package/examples/world/.threedog/content-index.json +1 -0
  398. package/examples/world/GAMEMAP.md +31 -21
  399. package/examples/world/art/humanoid.js +38 -0
  400. package/examples/world/art/index.js +11 -0
  401. package/examples/world/art/models.js +57 -0
  402. package/examples/world/art/shapes.js +9 -0
  403. package/examples/world/assets.js +6 -0
  404. package/examples/world/content/audio.js +5 -5
  405. package/examples/world/content/items.js +1 -1
  406. package/examples/world/content/npcs.js +1 -1
  407. package/examples/world/content/props.js +1 -1
  408. package/examples/world/content/rules.js +1 -1
  409. package/examples/world/content/templates.js +1 -1
  410. package/examples/world/content/vegetation.js +1 -1
  411. package/examples/world/main.js +22 -18
  412. package/examples/world/models.js +17 -7
  413. package/examples/world/picture/index.js +20 -0
  414. package/examples/world/picture/lights.js +41 -0
  415. package/examples/world/picture/materials.js +34 -0
  416. package/examples/world/picture/palette.js +74 -0
  417. package/examples/world/picture/post.js +9 -0
  418. package/examples/world/picture/sky.js +39 -0
  419. package/index.d.ts +44 -54
  420. package/index.js +29 -25
  421. package/llms.txt +24 -15
  422. package/modules/ambience/Ambience.js +34 -23
  423. package/modules/calendar/Calendar.js +163 -0
  424. package/modules/calendar/contract.js +21 -0
  425. package/modules/calendar/index.js +82 -0
  426. package/modules/{sky → calendar}/schedule.js +17 -16
  427. package/modules/calendar/seasons.js +55 -0
  428. package/modules/camera/FirstPersonCamera.js +6 -15
  429. package/modules/camera/FixedCamera.js +33 -15
  430. package/modules/camera/FollowCamera.js +90 -16
  431. package/modules/camera/RtsCamera.js +18 -17
  432. package/modules/camera/common.js +73 -20
  433. package/modules/camera/contract.js +17 -0
  434. package/modules/camera/projection.js +11 -24
  435. package/modules/characters/Character.js +188 -48
  436. package/modules/characters/NPC.js +92 -41
  437. package/modules/characters/assetModel.js +8 -16
  438. package/modules/characters/behaviors.js +2 -1
  439. package/modules/characters/contract.js +13 -0
  440. package/modules/characters/footsteps.js +1 -1
  441. package/modules/characters/index.js +112 -49
  442. package/modules/characters/moveHelpers.js +4 -5
  443. package/modules/characters/movers/common.js +102 -19
  444. package/modules/characters/movers/manual.js +23 -0
  445. package/modules/characters/movers/rapier.js +19 -16
  446. package/modules/characters/movers/simple.js +14 -11
  447. package/modules/characters/movers/support.js +186 -0
  448. package/modules/characters/npcAvoid.js +47 -42
  449. package/modules/characters/npcSim.js +17 -9
  450. package/modules/characters/npcView.js +44 -16
  451. package/modules/characters/pathAsync.js +7 -3
  452. package/modules/characters/playerStrings.js +4 -3
  453. package/modules/characters/proceduralRig.js +19 -4
  454. package/modules/characters/useModel.js +2 -2
  455. package/modules/characters/vehicle.contract.js +21 -0
  456. package/modules/characters/walkTo.js +21 -7
  457. package/modules/collision/Collision.js +69 -27
  458. package/modules/collision/grid.js +8 -6
  459. package/modules/content/explain.js +2 -2
  460. package/modules/content/fields.js +102 -0
  461. package/modules/content/ids.js +8 -6
  462. package/modules/content/index.js +104 -27
  463. package/modules/content/loader.js +45 -33
  464. package/modules/content/models.js +58 -42
  465. package/modules/content/packs.js +6 -5
  466. package/modules/content/parts.js +41 -0
  467. package/modules/content/props.js +20 -11
  468. package/modules/content/rules.js +66 -0
  469. package/modules/content/stages.js +80 -0
  470. package/modules/content/templates.js +123 -30
  471. package/modules/debug/DebugPanel.js +24 -17
  472. package/modules/flow/contract.js +16 -0
  473. package/modules/flow/index.js +21 -15
  474. package/modules/gameplay/Container.js +41 -32
  475. package/modules/gameplay/Containers.js +30 -15
  476. package/modules/gameplay/Dialogue.js +113 -55
  477. package/modules/gameplay/Interactions.js +273 -72
  478. package/modules/gameplay/Inventory.js +72 -76
  479. package/modules/gameplay/Quests.js +75 -39
  480. package/modules/gameplay/boxOps.js +3 -3
  481. package/modules/gameplay/dialogue.contract.js +21 -0
  482. package/modules/gameplay/dialogueBox.js +4 -2
  483. package/modules/gameplay/dialogueBubbles.js +116 -0
  484. package/modules/gameplay/interactionPrompt.js +4 -1
  485. package/modules/gameplay/interactions.contract.js +16 -0
  486. package/modules/gameplay/inventory.contract.js +23 -0
  487. package/modules/gameplay/inventoryOps.js +19 -17
  488. package/modules/gameplay/pickups.js +306 -85
  489. package/modules/gameplay/questLog.js +6 -6
  490. package/modules/gameplay/quests.contract.js +17 -0
  491. package/modules/grid/Grid.js +92 -50
  492. package/modules/grid/Layer.js +27 -13
  493. package/modules/grid/index.js +96 -43
  494. package/modules/grid/ops.js +20 -18
  495. package/modules/grid/preview.js +37 -29
  496. package/modules/grid/strings.js +12 -0
  497. package/modules/grid/tiles.js +19 -22
  498. package/modules/hlod/index.js +52 -19
  499. package/modules/hud/index.js +48 -20
  500. package/modules/hud/parts.js +28 -13
  501. package/modules/level/heightfield.js +3 -1
  502. package/modules/level/index.js +49 -23
  503. package/modules/level/nodes.js +4 -3
  504. package/modules/lights/index.js +47 -19
  505. package/modules/music/Music.js +38 -21
  506. package/modules/music/rules.js +1 -1
  507. package/modules/nav/index.js +48 -42
  508. package/modules/net/Client.js +13 -6
  509. package/modules/net/Host.js +19 -5
  510. package/modules/net/Net.js +2 -1
  511. package/modules/net/index.js +13 -8
  512. package/modules/net/sync.js +9 -8
  513. package/modules/net/transports.js +77 -27
  514. package/modules/particles/Particles.js +58 -28
  515. package/modules/particles/contract.js +17 -0
  516. package/modules/particles/effect.js +54 -11
  517. package/modules/photo/Photo.js +56 -38
  518. package/modules/rigid/RigidBodies.js +194 -32
  519. package/modules/rigid/Vehicles.js +18 -15
  520. package/modules/rigid/sync.js +62 -17
  521. package/modules/settings/Settings.js +60 -55
  522. package/modules/settings/apply.js +38 -3
  523. package/modules/settings/sections.js +5 -3
  524. package/modules/settings/strings.js +3 -2
  525. package/modules/settings/view.js +5 -3
  526. package/modules/sky/Sky.js +132 -205
  527. package/modules/sky/clouds.js +37 -23
  528. package/modules/sky/dome.js +100 -0
  529. package/modules/sky/domeLayers.js +30 -15
  530. package/modules/sky/environment.js +45 -99
  531. package/modules/sky/fog.js +9 -139
  532. package/modules/sky/frame.js +60 -56
  533. package/modules/sky/season.js +21 -0
  534. package/modules/sky/shader.js +63 -35
  535. package/modules/sky/skyModule.js +52 -37
  536. package/modules/sky/tint.js +59 -0
  537. package/modules/terrain/ChunkManager.js +194 -110
  538. package/modules/terrain/chunkJob.js +1 -1
  539. package/modules/terrain/chunkQueries.js +6 -4
  540. package/modules/terrain/draw.js +154 -0
  541. package/modules/terrain/index.js +87 -54
  542. package/modules/terrain/terrainDefaults.js +2 -2
  543. package/modules/terrain/terrainEdit.js +18 -20
  544. package/modules/terrain/terrainGen.js +6 -4
  545. package/modules/terrain/terrainIsland.js +5 -4
  546. package/modules/terrain/terrainShape.js +12 -12
  547. package/modules/terrain/terrainShapeMain.js +8 -7
  548. package/modules/terrain/terrainTexture.js +21 -19
  549. package/modules/timeline/Timeline.js +95 -43
  550. package/modules/timeline/Tween.js +18 -10
  551. package/modules/timeline/letterbox.js +2 -2
  552. package/modules/timeline/shots.js +5 -1
  553. package/modules/triggers/index.js +111 -76
  554. package/modules/vegetation/Vegetation.js +229 -112
  555. package/modules/vegetation/densityMap.js +62 -0
  556. package/modules/vegetation/draw.js +191 -0
  557. package/modules/vegetation/groundChunks.js +52 -58
  558. package/modules/vegetation/index.js +32 -11
  559. package/modules/vegetation/modelGeometry.js +3 -2
  560. package/modules/vegetation/nearFade.js +8 -2
  561. package/modules/water/Water.js +157 -72
  562. package/modules/water/surface.js +86 -47
  563. package/modules/weather/Weather.js +96 -103
  564. package/modules/weather/particles.js +37 -14
  565. package/modules/weather/shaders.js +1 -1
  566. package/modules/weather/strings.js +2 -2
  567. package/modules/weather/weatherDraw.js +141 -0
  568. package/modules/world/World.js +26 -9
  569. package/modules/world/explain.js +1 -1
  570. package/modules/world/index.js +18 -4
  571. package/modules/world/persist.js +62 -2
  572. package/modules/world/pos.js +3 -2
  573. package/modules/world/records.js +8 -6
  574. package/modules/world/sim.js +60 -20
  575. package/modules/world/simFar.js +4 -3
  576. package/modules/world/state.js +3 -2
  577. package/modules/world/thingSource.js +1 -1
  578. package/modules/world/views.js +8 -6
  579. package/package.json +8 -3
  580. package/presets.js +43 -29
  581. package/render/PostFX.js +318 -135
  582. package/render/backend.js +486 -0
  583. package/render/cascades.js +195 -0
  584. package/render/cascades.tsl.js +96 -0
  585. package/render/daylight.js +39 -0
  586. package/render/detail.js +122 -41
  587. package/render/effects.js +155 -48
  588. package/render/engineUniforms.js +10 -1
  589. package/render/fuse.js +5 -4
  590. package/render/fx/cel.tsl.js +42 -0
  591. package/render/fx/cloudShadow.tsl.js +16 -0
  592. package/render/fx/detail.tsl.js +66 -0
  593. package/render/fx/index.js +28 -0
  594. package/render/fx/lighting.tsl.js +28 -0
  595. package/render/fx/nodeErrors.tsl.js +68 -0
  596. package/render/fx/noise.tsl.js +12 -0
  597. package/render/fx/objectOrigin.tsl.js +42 -0
  598. package/render/fx/particles.tsl.js +139 -0
  599. package/render/fx/patchNodes.tsl.js +403 -0
  600. package/render/fx/postWebGPU.tsl.js +181 -0
  601. package/render/fx/season.tsl.js +13 -0
  602. package/render/fx/sky.tsl.js +187 -0
  603. package/render/fx/uniforms.tsl.js +67 -0
  604. package/render/fx/water.tsl.js +53 -0
  605. package/render/fx/wind.tsl.js +22 -0
  606. package/render/fxNumbers.js +36 -0
  607. package/render/hotGlsl.js +24 -0
  608. package/render/layers.js +14 -0
  609. package/render/lighting.js +71 -18
  610. package/render/lightmap.js +142 -0
  611. package/render/lights.js +47 -6
  612. package/render/materials.js +55 -152
  613. package/render/modeling.js +73 -0
  614. package/render/neutral.js +23 -0
  615. package/render/occlusion.js +184 -0
  616. package/render/ownFrame.js +76 -0
  617. package/render/patches.js +317 -35
  618. package/render/postWebGL.js +205 -0
  619. package/render/probes.js +288 -0
  620. package/render/shaderErrors.js +154 -0
  621. package/render/slots.js +165 -0
  622. package/render/terms.js +163 -0
  623. package/render/uniformDecl.js +4 -3
  624. package/types/common.d.ts +2 -2
  625. package/types/core.d.ts +757 -346
  626. package/types/gameplay.d.ts +539 -330
  627. package/types/generated/core/Audio.d.ts +26 -42
  628. package/types/generated/core/Batching.d.ts +6 -2
  629. package/types/generated/core/Budget.d.ts +2 -8
  630. package/types/generated/core/DebugOverrides.d.ts +58 -9
  631. package/types/generated/core/I18n.d.ts +2 -2
  632. package/types/generated/core/Input.d.ts +110 -32
  633. package/types/generated/core/Ops.d.ts +31 -0
  634. package/types/generated/core/Random.d.ts +2 -2
  635. package/types/generated/core/Saves.d.ts +10 -2
  636. package/types/generated/core/Stream.d.ts +1 -1
  637. package/types/generated/core/Threads.d.ts +4 -1
  638. package/types/generated/core/Views.d.ts +0 -1
  639. package/types/generated/core/audioVoice.d.ts +17 -9
  640. package/types/generated/core/control.d.ts +55 -0
  641. package/types/generated/core/page.d.ts +9 -2
  642. package/types/generated/core/session.d.ts +2 -1
  643. package/types/generated/modules/ambience/Ambience.d.ts +0 -9
  644. package/types/generated/modules/calendar/Calendar.d.ts +84 -0
  645. package/types/generated/modules/calendar/index.d.ts +10 -0
  646. package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
  647. package/types/generated/modules/grid/Grid.d.ts +61 -25
  648. package/types/generated/modules/grid/Layer.d.ts +13 -5
  649. package/types/generated/modules/grid/index.d.ts +56 -20
  650. package/types/generated/modules/music/Music.d.ts +5 -3
  651. package/types/generated/modules/net/index.d.ts +3 -3
  652. package/types/generated/modules/net/transports.d.ts +12 -3
  653. package/types/generated/modules/particles/Particles.d.ts +13 -6
  654. package/types/generated/modules/sky/Sky.d.ts +85 -110
  655. package/types/generated/modules/sky/skyModule.d.ts +1 -1
  656. package/types/generated/modules/timeline/Timeline.d.ts +8 -6
  657. package/types/generated/modules/water/Water.d.ts +50 -3
  658. package/types/generated/modules/weather/Weather.d.ts +44 -15
  659. package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
  660. package/types/generated/modules/world/World.d.ts +20 -5
  661. package/types/generated/render/PostFX.d.ts +109 -29
  662. package/types/generated/render/lighting.d.ts +29 -0
  663. package/types/generated/render/materials.d.ts +31 -50
  664. package/types/generated/render/modeling.d.ts +30 -0
  665. package/types/generated/render/occlusion.d.ts +13 -0
  666. package/types/generated/render/patches.d.ts +16 -2
  667. package/types/generated/ui/UI.d.ts +6 -3
  668. package/types/nav.d.ts +6 -0
  669. package/types/physics.d.ts +140 -45
  670. package/types/tsl.d.ts +94 -0
  671. package/types/world.d.ts +489 -122
  672. package/ui/Focus.js +35 -14
  673. package/ui/LoadingScreen.js +3 -3
  674. package/ui/Parts.js +35 -15
  675. package/ui/UI.js +27 -17
  676. package/ui/cursor.js +115 -0
  677. package/ui/defaults.js +15 -11
  678. package/ui/theme.js +36 -27
  679. package/ui/touchPart.js +2 -2
  680. package/core/claims.js +0 -51
  681. package/core/look/coreParts.js +0 -112
  682. package/core/look/layers.js +0 -136
  683. package/core/look/part.js +0 -173
  684. package/core/look/report.js +0 -79
  685. package/core/look/write.js +0 -86
  686. package/core/renamed.js +0 -22
  687. package/core/styleParts.js +0 -98
  688. package/docs/api/entities.md +0 -61
  689. package/docs/api/style.md +0 -134
  690. package/docs/recipes/09-style-pack.md +0 -169
  691. package/docs/recipes/35-style-from-reference.md +0 -84
  692. package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
  693. package/docs/recipes/38-environment-look-hooks.md +0 -88
  694. package/docs/recipes/41-thing-registry.md +0 -93
  695. package/docs/recipes/43-shader-patches-surface-looks.md +0 -135
  696. package/docs/recipes/44-water-weather-look-hooks.md +0 -135
  697. package/docs/recipes/48-make-material.md +0 -70
  698. package/docs/recipes/52-look.md +0 -146
  699. package/examples/action/look.js +0 -5
  700. package/examples/sheepisland/style/index.js +0 -79
  701. package/examples/styletest/look.js +0 -11
  702. package/examples/styletest/overrides.js +0 -33
  703. package/examples/styletest/panel.js +0 -135
  704. package/modules/entities/Entities.js +0 -243
  705. package/modules/entities/build.js +0 -25
  706. package/modules/entities/index.js +0 -4
  707. package/modules/sky/calendar.js +0 -80
  708. package/modules/sky/cascades.js +0 -125
  709. package/modules/sky/layers.js +0 -69
  710. package/modules/sky/look.js +0 -51
  711. package/modules/sky/lookFog.js +0 -80
  712. package/modules/sky/lookShadow.js +0 -50
  713. package/modules/sky/lookSky.js +0 -108
  714. package/modules/sky/shadow.js +0 -74
  715. package/modules/terrain/chunkLevels.js +0 -40
  716. package/modules/terrain/lookGround.js +0 -61
  717. package/modules/terrain/mountTerrain.js +0 -32
  718. package/modules/vegetation/lookWind.js +0 -37
  719. package/modules/water/look.js +0 -80
  720. package/modules/weather/look.js +0 -75
  721. package/modules/world/cells.js +0 -42
  722. package/render/lookSurface.js +0 -161
  723. package/render/postLook.js +0 -86
  724. package/render/surface.js +0 -69
  725. package/types/style.d.ts +0 -643
package/types/core.d.ts CHANGED
@@ -1,18 +1,18 @@
1
1
  // Engine core: the Engine class, events, input, i18n, saves, assets, audio, the ground interface, module definitions.
2
2
  import type { Object3D, Vector3, Vector2, Color, Texture, BufferGeometry, Handle, PositionLike, Vec3Like, ColorLike, Material } from './common';
3
- import type { Style, StyleInput } from './style';
4
3
  import type {
5
- Terrain, Vegetation, Sky, Weather, Water, WaterBody, WaterBodyOptions, VegetationRemoveEvent, Hlod, LightPool, Budget, BudgetLimits, BudgetReport,
4
+ Terrain, TerrainDraw, Vegetation, VegetationDraw, Sky, Calendar, Weather, WeatherDraw, Water, WaterBody, WaterBodyOptions, VegetationRemoveEvent, Hlod, LightPool, Budget, BudgetLimits, BudgetReport,
6
5
  } from './world';
7
6
  import type { World } from './generated/modules/world/World';
8
7
  import type { Net } from './generated/modules/net/Net';
9
8
  import type { PostEffect } from './generated/render/PostFX';
10
9
  import type { Grids } from './generated/modules/grid/index';
11
- import type { Collision, RigidBodies, CameraRig, CameraKind, CameraShotEvent, Animator, AnimatorOptions, Vehicle } from './physics';
10
+ import type { Collision, RigidBodies, CameraRig, CameraKind, CameraShotEvent, Animator, AnimatorOptions, Vehicle, Rideable } from './physics';
12
11
  import type { Nav } from './nav';
13
12
  import type { Stream } from './generated/core/Stream';
14
13
  import type { Batching } from './generated/core/Batching';
15
14
  import type { Rays } from './generated/core/Rays';
15
+ import type { Control } from './generated/core/control';
16
16
  import type { I18n } from './generated/core/I18n';
17
17
  import type { Audio } from './generated/core/Audio';
18
18
  import type { Input } from './generated/core/Input';
@@ -28,10 +28,11 @@ import type { DebugOverrides } from './generated/core/DebugOverrides';
28
28
  import type { Jobs } from './generated/core/Jobs';
29
29
  import type { Random } from './generated/core/Random';
30
30
  import type { PostFX } from './generated/render/PostFX';
31
+ import type { Occlusion } from './generated/render/occlusion';
31
32
  import type {
32
- Timeline, Level, LevelLoadedEvent, Triggers, TriggerEvent, Entities, Entity, EntityStateEvent, EntityStageEvent,
33
+ Timeline, Level, LevelLoadedEvent, Triggers, TriggerEvent, TemplateStageEvent,
33
34
  Particles, Settings, Music, MusicChangeEvent, CharactersApi, NPCManager, Character,
34
- Interactions, Dialogue, Inventory, ItemEvent, ItemUseEvent, ContainerEvent, PickupEvent, Quests, Photo, PhotoShot, Ambience, DebugPanel,
35
+ Interactions, Dialogue, Inventory, ItemEvent, ItemUseEvent, PickupEvent, Pickups, PickupsOptions, Quests, Photo, PhotoShot, Ambience, DebugPanel,
35
36
  Clock, Vars, Content, Flow, Hud,
36
37
  } from './gameplay';
37
38
 
@@ -47,6 +48,12 @@ declare global {
47
48
  * interface GameEvents { 'fighter:hit': [{ attacker: string; victim: string; damage: number }] }
48
49
  */
49
50
  interface GameEvents {}
51
+ /**
52
+ * Vite's import.meta.glob, the documented way a game lists its plugins folder (import.meta.glob('./plugins/*.js', { eager: true }))
53
+ * and engine.plugins.add takes one. Declared here because a game's tsconfig has no vite/client types ("types": []), so the documented line
54
+ * failed the type check of a fresh game; with vite/client too, the two declarations merge as overloads.
55
+ */
56
+ interface ImportMeta { glob(pattern: string | string[], options?: { eager?: boolean; import?: string; query?: string | Record<string, string> }): Record<string, any>; }
50
57
  }
51
58
  /**
52
59
  * Events the engine and modules emit, and the arguments callbacks receive (written as an array: what each argument is).
@@ -83,10 +90,12 @@ export interface EventMap extends GameEvents {
83
90
  'water:add': [body: WaterBody];
84
91
  /** A water body was removed */
85
92
  'water:remove': [body: WaterBody];
86
- /** A new day (the argument is the day number, starting at 1; needs the sky module) */
93
+ /** A new day (the argument is the day number, starting at 1; needs the calendar module) */
87
94
  'day:start': [day: number];
88
95
  /** Season changed (the argument is the season name, e.g. 'autumn') */
89
96
  'season:change': [season: string];
97
+ /** A mod with `for` ran out (engine.mod(target, { owner, for })): target is the quantity's name, id the record for per-record ones */
98
+ 'mod:end': [{ target: string; owner: string; id: string | null }];
90
99
  /** engine.skip jumped game time forward (seconds = game seconds skipped); timers and world catch-up already ran */
91
100
  'time:skip': [{ seconds: number }];
92
101
  /** Lightning strike (weather module) */
@@ -98,11 +107,18 @@ export interface EventMap extends GameEvents {
98
107
  /** engine.setCamera switched the camera kind; settings that belong to the camera (sensitivity, invert Y, field of view) are re-applied on it */
99
108
  'camera:change': [{ kind: string; previous: string }];
100
109
  /** A character jumped */
101
- 'character:jump': [{ character: Character }];
110
+ 'character:jump': [{ character: Character; air: boolean; index: number }];
111
+ 'character:launch': [{ character: Character; speed: number; owner: string }];
112
+ 'character:fall': [{ character: Character; safe: Vector3 | null; preventDefault(): void }];
102
113
  /** A character's model named by asset finished loading and replaced the placeholder body (same root; anim is now set) */
103
114
  'character:model': [{ character: Character; model: Object3D }];
104
115
  /** A character landed; impact is the landing speed (m/s), the larger the harder the fall */
105
116
  'character:land': [{ character: Character; impact: number }];
117
+ /**
118
+ * A character went into or out of deep water (water option): in true on entering, mode what the water option did there ('swim' | 'block' | 'wade',
119
+ * or what the function returned)
120
+ */
121
+ 'character:water': [{ character: Character; in: boolean; mode: string; depth: number }];
106
122
  /** Dialogue started; the argument is the dialogue script name */
107
123
  'dialogue:start': [speaker: string];
108
124
  /**
@@ -110,18 +126,20 @@ export interface EventMap extends GameEvents {
110
126
  * shots without replacing the UI part
111
127
  */
112
128
  'dialogue:line': [{ script: string; node: string; speaker: string; text: string; data: Record<string, any> }];
129
+ /** A bubble line started showing (the bubble channel: lines over their speakers while play goes on); at is what it is attached to, null = a screen line */
130
+ 'dialogue:bubble': [{ speaker: string; text: string; at: any }];
113
131
  /** Dialogue ended; the argument is the dialogue script name */
114
132
  'dialogue:end': [speaker: string];
115
- /** An item was added to the inventory */
133
+ /** An item was added to a container (any bag or chest: container names it, actor says who did it) */
116
134
  'item:add': [ItemEvent];
117
- /** An item was removed from the inventory */
135
+ /** An item was removed from a container (container names it, actor says who did it) */
118
136
  'item:remove': [ItemEvent];
119
- /** An item was added to a non-player container (chest, corpse...); container is the container id */
120
- 'container:add': [ContainerEvent];
121
- /** An item was removed from a non-player container */
122
- 'container:remove': [ContainerEvent];
123
- /** An item on the ground was picked up */
124
- 'item:pickup': [PickupEvent];
137
+ /** A pickup was taken off the ground (pickup = world id, item = its item id or null for a give function, actor = who took it) */
138
+ 'pickup:take': [PickupEvent];
139
+ /** A hold interaction started (the key went down on it); seconds is its hold */
140
+ 'interaction:hold': [{ id: string; action: string; seconds: number }];
141
+ /** A hold interaction stopped before it completed: 'released' | 'tooFar' | 'disabled' | 'removed' | 'inputLocked' */
142
+ 'interaction:interrupt': [{ id: string; action: string; reason: string; progress: number }];
125
143
  /** An item was used through the inventory.use op (after use ran) */
126
144
  'item:use': [ItemUseEvent];
127
145
  /** A quest started */
@@ -148,18 +166,20 @@ export interface EventMap extends GameEvents {
148
166
  'timeline:start': [{ id: number }];
149
167
  /** A cutscene ended; skipped tells whether it was skipped */
150
168
  'timeline:end': [{ id: number; skipped: boolean }];
151
- /** An entity was spawned */
152
- 'entity:spawn': [Entity];
153
- /** An entity was removed */
154
- 'entity:remove': [Entity];
155
- /** A state value of an entity changed */
156
- 'entity:state': [EntityStateEvent];
157
- /** An entity entered a new growth stage */
158
- 'entity:stage': [EntityStageEvent];
169
+ /** A content template instance entered a new stage by growing (templates with stages) */
170
+ 'template:stage': [TemplateStageEvent];
159
171
  /** The ground's shape or type changed in this world-space box (engine.terrain.edit): cached ground samples (path rasters) inside it are stale */
160
172
  'ground:change': [{ x0: number; z0: number; x1: number; z1: number }];
173
+ /**
174
+ * rigid: newGame / a load rebuilt the physics world (a fresh page for physics) and the engine's bodies are back (entry.body is the rebuilt Rapier
175
+ * body; bodies maps the ids given to addBox / addBall / addHull / addWheeled). The old world's joints were freed with it: re-create the game's
176
+ * joints here (recipes/11-vehicles.md, Joints). Not emitted while a vehicle exists (the world is kept then, joints included)
177
+ */
178
+ 'rigid:rebuilt': [{ world: any; player: any; bodies: Record<string, any> }];
161
179
  /** terrain({ shape }): the player or a moving rigid body dropped below engine.terrain.voidY (once per fall). The engine does not respawn: the game decides */
162
180
  'terrain:void': [{ who: any; position: { x: number; y: number; z: number } }];
181
+ /** A terrain chunk job failed every try (usually the game's height / groundType / placement rule throws there): the chunk stays empty and the error is reported. engine.terrain.retry() sends failed chunks again */
182
+ 'terrain:chunkFailed': [{ cx: number; cz: number; error: any }];
163
183
  /** A vegetation instance was chopped / removed */
164
184
  'vegetation:remove': [VegetationRemoveEvent];
165
185
  /** A vegetation instance was restored */
@@ -170,6 +190,8 @@ export interface EventMap extends GameEvents {
170
190
  'music:stinger': [{ name: string }];
171
191
  /** Scenario parameters were applied (URL parameters or engine.applyState) */
172
192
  'state:applied': [StateParams];
193
+ /** A scenario (at, pos) moved the player: a camera or view that eases jumps there */
194
+ 'state:placed': [{ x: number; z: number }];
173
195
  /** A one-shot action of the animation state machine finished */
174
196
  'anim:end': [{ root: Object3D; state: string }];
175
197
  /** A record was added to world */
@@ -194,12 +216,12 @@ export interface EventMap extends GameEvents {
194
216
  'net:result': [{ seq: number; name: string; ok: boolean; code: string | null; value?: any; tick: number }];
195
217
  /** A gameplay error in development / testing; gameplay is frozen (error severity levels, see engine.error) */
196
218
  'engine:error': [EngineError];
197
- /** A presentation module errored and was disabled (the game continues) */
219
+ /** A picture or ui module errored and was disabled (the game continues) */
198
220
  'module:disabled': [{ name: string; message: string }];
199
221
  /** A character boarded a vehicle */
200
- 'vehicle:enter': [{ character: Character; vehicle: Vehicle }];
222
+ 'vehicle:enter': [{ character: Character; vehicle: Rideable }];
201
223
  /** A character exited a vehicle */
202
- 'vehicle:exit': [{ character: Character; vehicle: Vehicle }];
224
+ 'vehicle:exit': [{ character: Character; vehicle: Rideable }];
203
225
  /** Game flow state changed */
204
226
  'flow:change': [{ from: string; to: string }];
205
227
  /** Scene transition: phase 'start' begins fading to black, 'end' finishes fading back in */
@@ -208,6 +230,8 @@ export interface EventMap extends GameEvents {
208
230
  'session:end': [];
209
231
  /** A playthrough started from a clean slate: kind 'new' (newGame) or 'load' (session.load, with the slot) */
210
232
  'session:start': [{ kind: 'new' | 'load'; slot?: string }];
233
+ /** newGame / session.load failed (a save part's load() threw) and the game was rolled back: the old playthrough goes on, no session:start */
234
+ 'session:failed': [{ kind: 'new' | 'load'; slot?: string }];
211
235
  /** The page went away: the window lost focus or the tab was hidden (engine.page) */
212
236
  'page:blur': [{ focused: boolean; visible: boolean }];
213
237
  /** The page came back: focused and visible again */
@@ -219,6 +243,10 @@ export interface EventMap extends GameEvents {
219
243
  /** The WebGL context is back: gameplay resumes */
220
244
  'page:contextrestored': [];
221
245
  }
246
+ /** The renderer behind engine.renderer: a WebGLRenderer by default, three's WebGPURenderer on the WebGPU route (createEngine({ renderer: 'webgpu' })).
247
+ * Narrow before using one side's API: `if ('isWebGPURenderer' in r)`, or engine.describe().renderer.backend */
248
+ export type EngineRenderer = import('three').WebGLRenderer | import('three/webgpu').WebGPURenderer;
249
+
222
250
  /** Arguments a callback of the given event receives: known events follow EventMap, other names are not checked */
223
251
  export type EventArgs<K extends string> = K extends keyof EventMap ? EventMap[K] : any[];
224
252
  /** Event name: known events get autocompletion, any string is also allowed */
@@ -229,31 +257,88 @@ export type EventName = keyof EventMap | (string & {});
229
257
  // Input
230
258
  // ======================================================================
231
259
 
232
- /** Mouse / touch pointer. ndcX/ndcY are screen coordinates in -1..1 */
233
260
  /** Per-engine shader uniforms (engine.uniforms): { value } objects shared by every material of that engine */
234
261
  export interface EngineUniforms {
235
- /** Fixed seconds (= engine.elapsed) */
262
+ /** Ambient seconds (= engine.time.now('ambient')): keeps moving while gameplay is frozen; written only by the time source */
236
263
  uTime: { value: number };
237
264
  /** Wind strength multiplier (weather) */
238
265
  uWind: { value: number };
239
- /** Sway frequency multiplier (style.wind.frequency) */
266
+ /** Sway frequency multiplier */
240
267
  uWindFreq: { value: number };
268
+ /** Sway amplitude multiplier: every wind patch's amplitude is scaled by it */
269
+ uWindAmp: { value: number };
241
270
  /** Cloud cover 0-1 (weather) */
242
271
  uCloud: { value: number };
243
- /** Darkest cloud shadow 0-1 (style.clouds.shadow; 0 = none) */
272
+ /** Rain amount 0-1 (weather state, every frame): a signal for the game's own wet surfaces */
273
+ uRain: { value: number };
274
+ /** Snow amount 0-1 (weather state, every frame) */
275
+ uSnow: { value: number };
276
+ /** Weather's light multiplier (weather state, every frame; 1 = clear): your picture/ code multiplies its own lights by it */
277
+ uWeatherLight: { value: number };
278
+ /** Weather's fog multiplier (weather state, every frame; 1 = clear): your picture/ code multiplies its fog distance by it */
279
+ uWeatherFog: { value: number };
280
+ /** How far the world is meant to be seen, meters (default 600; terrain({ viewFog: true }) writes it): a fog's far, the stream radius without terrain */
281
+ uViewDistance: { value: number };
282
+ /** Darkest cloud shadow 0-1 (0 = none) */
244
283
  uCloudShadow: { value: number };
245
- /** Cloud size: smaller = bigger clouds (style.clouds.scale) */
284
+ /** Cloud size: smaller = bigger clouds */
246
285
  uCloudScale: { value: number };
247
- /** Cloud drift per second (style.clouds.speed) */
286
+ /** Cloud drift per second */
248
287
  uCloudSpeed: { value: Vector2 };
249
- /** Season tint of foliage (sky calendar) */
288
+ /** Unit vector toward the sun (sky, every frame); share the object in your own sky: mySky.material.uniforms.sunPosition = engine.uniforms.uSunDir */
289
+ uSunDir: { value: Vector3 };
290
+ /** Sun color now, from the sky's keyframes (white with no sky): what a game's own sun takes. Linear, like every THREE.Color */
291
+ uSunColor: { value: Color };
292
+ /** 0 at night .. 1 at noon (sky, the sun it draws) */
293
+ uDaylight: { value: number };
294
+ /** 0 by day, 1 at night: the curve lightPool sources with `dusk` fade on. For emissive windows and signs: mat.emissiveIntensity = 2 * engine.uniforms.uNight.value */
295
+ uNight: { value: number };
296
+ /** Time of day 0-1 the sky draws (calendar time, or the sky's fixed time) */
297
+ uTimeOfDay: { value: number };
298
+ /** Zenith color the sky draws this frame (keyframes, engine.sky.top, weather tint, lightning); linear, like every THREE.Color */
299
+ uSkyTop: { value: Color };
300
+ /** Horizon color the sky draws this frame (or the backdrop color). Read it for a shader that should meet the sky */
301
+ uSkyHorizon: { value: Color };
302
+ /** Sun disk sharpness (larger = smaller), shared with the dome: write .value; sky({ sunSize }) sets the start. The same for every value below */
303
+ uSunSize: { value: number };
304
+ uSunGlow: { value: number };
305
+ /** Sun disk brightness (sky({ sunBrightness })) */
306
+ uSunPower: { value: number };
307
+ /** Moon disk sharpness (larger = smaller) */
308
+ uMoonSize: { value: number };
309
+ /** Moon disk brightness (sky({ moonBrightness })) */
310
+ uMoonPower: { value: number };
311
+ uMoonColor: { value: Color };
312
+ /** Share of sky grid cells holding a star at night, 0-1 (sky({ starDensity })) */
313
+ uStars: { value: number };
314
+ /** Star grid resolution: larger = smaller, more numerous stars */
315
+ uStarScale: { value: number };
316
+ /** Horizon-to-zenith gradient exponent (sky({ gradientCurve })) */
317
+ uCurve: { value: number };
318
+ /** Dome cloud amount 0..1+ (sky({ clouds: { coverage } })), multiplied by the weather's uCloud */
319
+ uCloudCover: { value: number };
320
+ /** Dome cloud size, smaller = bigger clouds (sky({ clouds: { scale } })); uCloudScale is the cloud shadows' */
321
+ uSkyCloudScale: { value: number };
322
+ /** Dome cloud drift [x, z] per second; uCloudSpeed is the cloud shadows' */
323
+ uSkyCloudSpeed: { value: Vector2 };
324
+ uCloudOpacity: { value: number };
325
+ /** Dome cloud edge softness */
326
+ uCloudSoft: { value: number };
327
+ /** Lit side of the dome's clouds */
328
+ uCloudColor: { value: Color };
329
+ /** Shaded side of the dome's clouds */
330
+ uCloudShade: { value: Color };
331
+ /** Season tint of foliage (sky, by the calendar's season) */
250
332
  uFoliageTint: { value: Color };
251
- /** Season tint of the ground (sky calendar) */
333
+ /** Season tint of the ground (sky, by the calendar's season) */
252
334
  uGroundTint: { value: Color };
253
335
  uFoliageMix: { value: number };
254
336
  uGroundMix: { value: number };
337
+ /** Snow / ash cover amount alone, x foliage, y ground, 0-1 (the 'ground.cover' point); the tints above already hold it blended in */
338
+ uCover: { value: Vector2 };
255
339
  }
256
340
 
341
+ /** Mouse / touch pointer. ndcX/ndcY are screen coordinates in -1..1 */
257
342
  export interface Pointer {
258
343
  /** Pixels from the canvas's top-left corner (not the window's): the same space as worldToScreen and the UI root */
259
344
  x: number; y: number;
@@ -289,17 +374,26 @@ export type StringTables = Record<string, Record<string, string>>;
289
374
  * later parts wait for it to finish before loading).
290
375
  * first: true providers load first (parts such as the level, where the rest only makes sense after it is loaded) */
291
376
  export interface SaveProvider {
377
+ /** This part's data now: plain data (structuredClone can copy it; no functions, DOM nodes or three objects). It may be the live object the
378
+ * part keeps: the engine copies it for its rollback point before a load, so a load() that writes into that same object can still be undone.
379
+ * Data that cannot be copied makes a load refuse before anything changes (save-part-threw) */
292
380
  save: () => any;
381
+ /** Read data back; may return a Promise (later parts wait). Listener errors of events it emits count as the load throwing, also after an await */
293
382
  load: (data: any) => void | Promise<void>;
294
383
  /** Load before the other parts (such as the level) */
295
384
  first?: boolean;
296
385
  /** Join atomic ops: copied before an atomic op runs, put back if it fails (plain data; afterLoad does not run on rollback) */
297
386
  atomic?: boolean;
387
+ /** Dev only: called once start() finished with this part's data in the new-game state, to warn about what should not be there yet (world: records placed by code) */
388
+ checkNewGame?: (data: any) => void;
298
389
  /** This part's format version, default 1: raise it by 1 when what save() returns changes shape. A save with a newer version is refused */
299
390
  version?: number;
300
391
  /** Upgrade steps: old version -> data => data in the next version's shape, e.g. { 1: d => ({ ...d, beds: [] }) }.
301
392
  * The second argument is the whole save as read ({ parts, versions }, read only), for a step that depends on another part */
302
393
  migrate?: Record<number, (data: any, save: { parts: Record<string, any>, versions: Record<string, number> }) => any>;
394
+ /** This part's data used to be saved under another part's name: { oldPart: data => newData } (newData in this version's shape). An old save without
395
+ * this part but with oldPart loads it here; oldPart is then dropped unless a registered part still owns that name */
396
+ movedFrom?: Record<string, (data: any) => any>;
303
397
  }
304
398
 
305
399
 
@@ -318,8 +412,23 @@ export type AssetEntry = string | ModelBuilder | {
318
412
  url?: string;
319
413
  /** Model: generator function (instead of url) */
320
414
  build?: ModelBuilder;
321
- /** Model: parameters passed to build */
322
- params?: any;
415
+ /**
416
+ * Model: a params schema (core/params.js format plus 'color'), e.g. { height: { type: 'number', min: 1, max: 8, default: 3 } }: build gets one
417
+ * object (defaults < dev panel values < a call's own ['name', { ... }]) and the dev panel shows the fields
418
+ */
419
+ params?: Record<string, string | { type: string; default?: any; min?: number; max?: number; values?: any[]; desc?: string; optional?: boolean }>;
420
+ /**
421
+ * Model generator: false = never stored in the dev cache (.threedog/cache); for materials the GLB round trip cannot keep
422
+ * (own onBeforeCompile, ShaderMaterial uniforms that code keeps a reference to)
423
+ */
424
+ cache?: boolean;
425
+ /**
426
+ * Model: every mesh casts (receives) shadows, or none does. Left out: a generator that set the flag on any mesh keeps its own,
427
+ * otherwise (files, generators that set nothing) all meshes cast and receive
428
+ */
429
+ castShadow?: boolean;
430
+ /** Model: see castShadow */
431
+ receiveShadow?: boolean;
323
432
  /** Bake manifest (bake.js) only: 'file' = the baked file is the source of truth (edited in Blender), npm run bake no longer overwrites it */
324
433
  source?: 'file';
325
434
  /** Preload at startup */
@@ -354,11 +463,18 @@ export interface AssetManifest {
354
463
  base?: string | URL;
355
464
  /** Models (.glb / .gltf, Draco/Meshopt compression also works): name -> path or generator function */
356
465
  models?: Record<string, AssetEntry>;
357
- /** Textures: name -> path */
358
- textures?: Record<string, AssetEntry>;
359
- /** Sounds: name -> path */
360
- sounds?: Record<string, AssetEntry>;
361
- /** Fonts: name -> file, or { url, family, weight, style, ... } (family defaults to the name). style.ui.fonts lists the names the UI uses */
466
+ /**
467
+ * Textures: name -> path, or a texture made in code: a function returning a THREE.Texture (run once, on first use) or the Texture itself.
468
+ * Code textures come back as made (their colorSpace / wrap / repeat are yours) and are never disposed by the engine if passed as a Texture.
469
+ * Example: textures: { brick: () => makeBrickTexture(), sign: mySignTexture }
470
+ */
471
+ textures?: Record<string, AssetEntry | Texture | (() => Texture | Promise<Texture>)>;
472
+ /**
473
+ * Sounds: name -> file path, or a sound made in code: a synth function (SynthFn) or { build: synthFn, params } (params: its defaults). Used by name
474
+ * like a file: audio.sfx(name), audio.sounds rules (src / variants), music and ambience. Example: sounds: { step: '/sfx/step.ogg', ding: dingSynth }
475
+ */
476
+ sounds?: Record<string, AssetEntry | SynthFn | { build: SynthFn; params?: Record<string, any> }>;
477
+ /** Fonts: name -> file, or { url, family, weight, style, ... } (family defaults to the name). ui.fonts lists the names the UI uses */
362
478
  fonts?: Record<string, string | FontAssetEntry>;
363
479
  }
364
480
  /** One font of an asset pack: the file plus the FontFace descriptors (family defaults to the asset name) */
@@ -367,9 +483,9 @@ export interface FontAssetEntry {
367
483
  /** CSS font-family it registers (default: the asset name); several entries may share one family with different weight / style */
368
484
  family?: string;
369
485
  weight?: number | string; style?: string; stretch?: string; unicodeRange?: string; display?: string; featureSettings?: string; variationSettings?: string;
370
- /** start() stops if it fails (otherwise text falls back to the next family of style.ui.font) */
486
+ /** start() stops if it fails (otherwise text falls back to the next family of ui.theme.font) */
371
487
  critical?: boolean;
372
- /** Load at start() even if style.ui.fonts does not name it */
488
+ /** Load at start() even if ui.fonts does not name it */
373
489
  preload?: boolean;
374
490
  }
375
491
 
@@ -378,16 +494,20 @@ export interface Assets {
378
494
  * Register an asset manifest or asset pack (can be called several times; a later entry with the same name replaces the earlier one). Its name labels
379
495
  * it in engine.loading, base resolves its relative paths
380
496
  */
381
- manifest(m: AssetManifest): this;
497
+ manifest(m: AssetManifest | AssetManifest[]): this;
382
498
  /** The generator function registered under a model name, null for a file model or an unknown name (content builds [name, ...params] models with it) */
383
499
  builder(name: string): ((...args: any[]) => any) | null;
500
+ /** The params of a generator registered with a params schema: { schema, values (built with now), tuned (from setParams) }, or null */
501
+ paramsOf(name: string): { schema: Record<string, any>; values: Record<string, any>; tuned: Record<string, any> } | null;
502
+ /** Dev tuning: build a generator with these params (replacing its defaults) and swap every live copy in place; the dev panel's models folder calls it */
503
+ setParams(name: string, values: Record<string, any>): Promise<{ why: string; names: string[]; copies: Record<string, number>; ms: number; partsChanged?: string[] }>;
384
504
  /**
385
505
  * Preload (onProgress(0–1, current name)). Code-generated models and fonts are only loaded up front if marked preload. failed includes entries now
386
506
  * showing their fallback
387
507
  */
388
508
  preload(onProgress?: (p: number, name: string) => void, opts?: { onlyMarked?: boolean }): Promise<{ loaded: number; failed: string[]; ok: boolean }>;
389
509
  /**
390
- * A font from an asset pack by name: downloaded once, added to document.fonts; null when the file failed and it is not critical. style.ui.fonts calls
510
+ * A font from an asset pack by name: downloaded once, added to document.fonts; null when the file failed and it is not critical. ui.fonts calls
391
511
  * it at start()
392
512
  */
393
513
  font(name: string): Promise<FontFace | null>;
@@ -397,7 +517,8 @@ export interface Assets {
397
517
  */
398
518
  model(nameOrUrl: string, opts?: { castShadow?: boolean; receiveShadow?: boolean; static?: boolean }): Promise<Object3D>;
399
519
  /**
400
- * A model copy right now if it has already loaded, else null (never starts a load, never waits): lets code that rebuilds often skip the frame an await costs
520
+ * A model copy right now if it has already loaded, else null (never starts a load, never waits): lets code that rebuilds often skip the frame an await costs.
521
+ * Code-built models (a build function in the manifest) count too: they are null until one await model(name) or an entry with preload: true ran (dev warns [asset-not-loaded])
401
522
  * @example const m = engine.assets.modelNow('villager') ?? await engine.assets.model('villager');
402
523
  */
403
524
  modelNow(nameOrUrl: string, opts?: { castShadow?: boolean; receiveShadow?: boolean; static?: boolean }): Object3D | null;
@@ -407,14 +528,16 @@ export interface Assets {
407
528
  gridFromImage(nameOrUrl: string, opts?: { channel?: 'r' | 'g' | 'b' | 'a' | number; range?: [number, number]; bits?: 8 | 16 }): Promise<{ data: Float32Array; width: number; height: number; bits: number }>;
408
529
  /** Get a texture (.ktx2 compressed textures also work) */
409
530
  texture(nameOrUrl: string, opts?: { color?: boolean; pixelated?: boolean; repeat?: number[] }): Promise<Texture>;
531
+ /** Fetch a texture for something that already shows a stand-in: use(texture) runs when it arrives; a failed load is one load-failed dev warning naming `where` and what shows `instead`, and resolves false (an error inside use() is not swallowed). opts are texture()'s options */
532
+ useTexture(nameOrUrl: string, use: (texture: Texture) => void, o?: { where?: string; instead?: string; opts?: { color?: boolean; pixelated?: boolean; repeat?: number[] } }): Promise<boolean>;
410
533
  /**
411
534
  * Release a resource and return GPU memory. Not released while copies of the model are still in the scene; it is released when the last copy is
412
535
  * removed with engine.remove
413
536
  */
414
537
  release(name: string): void;
415
538
  /**
416
- * Release every model that has no copy in use (called automatically after level changes). Models whose shared geometry was taken by geometry() /
417
- * cached() are not released automatically. Returns the released names
539
+ * Release every model that has no copy in use (called automatically after level changes). Models whose shared geometry was taken by geometry() and
540
+ * code-generated models are not released automatically. Returns the released names
418
541
  */
419
542
  trim(): string[];
420
543
  /** How many copies of this model are in use now (taken with model() and not yet removed with engine.remove) */
@@ -424,15 +547,14 @@ export interface Assets {
424
547
  * under it
425
548
  */
426
549
  forget(obj: Object3D): void;
427
- /**
428
- * Code-generated model: generated only once per name + params, returns a copy (for geometry, the same one).
429
- * Order: files baked by npm run bake (public/models/baked/) -> automatic dev cache (.threedog/cache, invalidated automatically when the generator or
430
- * a file it imports changes) -> compute now.
431
- * When the generator is newer than the baked file during development, it computes now and prints a one-time hint "run npm run bake once it is final"
432
- */
433
- cached<T = any>(name: string, build: (params?: any) => T | Promise<T>, params?: any): Promise<T>;
434
550
  /** Generations faster than this many milliseconds are not written to the automatic cache (reading the file would be slower), default 20 */
435
551
  cacheMinMs: number;
552
+ /**
553
+ * Named colors for what is made in code: a generator written with `function` reads this.palette. Plain data, read, write or replace it freely: it is part
554
+ * of the cache key, so a model or texture asked for after a write is built from the new colors. Copies already placed keep theirs.
555
+ * @example engine.assets.palette = { leaf: 0xd98a3a, bark: 0x6b4a30 };
556
+ */
557
+ palette: Record<string, any>;
436
558
  /** Geometry and materials shared by model copies (engine.remove does not release them, use release) */
437
559
  shared: WeakSet<object>;
438
560
  /** Current GPU memory usage (number of geometries and textures) */
@@ -462,7 +584,7 @@ export interface Assets {
462
584
  export interface AssetReport {
463
585
  name: string | null; url: string | null; fromFile: boolean;
464
586
  counts: Record<string, number>;
465
- materials: { name: string; type: string; maps: Record<string, any>; flatShading: boolean; vertexColors: boolean; madeByStyle: boolean }[];
587
+ materials: { name: string; type: string; maps: Record<string, any>; flatShading: boolean; vertexColors: boolean; madeByEngine: boolean }[];
466
588
  textures: any[]; clips: { name: string; seconds: number }[]; colliders: any[]; templates: any[];
467
589
  issues: { severity: 'warn' | 'info'; code: string; msg: string }[];
468
590
  }
@@ -529,13 +651,15 @@ export type AudioBus = 'master' | 'music' | 'sfx' | 'ambience' | 'ui' | (string
529
651
  /** A playing sound (returned by audio.sfx / audio.play): stop(fade), fade(to, seconds), setPosition(at) */
530
652
  import type { SoundHandle } from './generated/core/audioVoice';
531
653
  export type { SoundHandle };
532
- /** One sounds entry in full form. src: a file or variants (random, no immediate repeat); synth: a registered synth name (default: the entry's own name) */
654
+ /**
655
+ * One sounds rule in full form: how a sound plays, never what it is made of (that is the asset manifest's: a file or a synth function).
656
+ * src: an asset pack sound name or a path, or variants (random, no immediate repeat); default: the asset of the rule's own name
657
+ */
533
658
  export interface SoundDef {
534
659
  src?: string | string[];
535
- synth?: string;
536
- /** Passed to the synth (merged over its registered defaults) */
660
+ /** Passed to a synth source (merged over the manifest entry's params) */
537
661
  params?: Record<string, any>;
538
- /** Bus it plays on (default 'sfx', or the synth's registered bus) */
662
+ /** Bus it plays on (default 'sfx', or the built-in synth's own bus) */
539
663
  bus?: AudioBus;
540
664
  volume?: number;
541
665
  /** Playback rate multiplier (1 = as recorded); synths get it as params.pitch */
@@ -550,7 +674,7 @@ export interface SoundDef {
550
674
  /** 3D falloff for sfx(name, { at }): ref meters at full volume (2), max meters (60), rolloff (1) */
551
675
  distance?: { ref?: number; max?: number; rolloff?: number };
552
676
  }
553
- /** A sounds entry: a file, variants, 'synth' (the synth registered under the same name) or the full form */
677
+ /** A sounds rule: a sound name / path, variants, or the full form */
554
678
  export type SoundSource = string | string[] | SoundDef;
555
679
  /** A measure comparison in a rule's `when`: every given key must hold ({ daylight: { gt: 0.15 } }, { rain: { lt: 0.2 } }) */
556
680
  export interface AudioCompare { gt?: number; gte?: number; lt?: number; lte?: number }
@@ -576,11 +700,14 @@ export interface AmbienceRule {
576
700
  /** Bus (default 'ambience') */
577
701
  bus?: AudioBus;
578
702
  }
579
- /** Synthesized sound: connect to `out` and return the length in seconds, or { stop(time) } for a loop (params.loop is true then) */
703
+ /**
704
+ * Synthesized sound, registered as a sound asset (assets.manifest({ sounds: { ding: fn } }) or { build: fn, params }): connect to `out` and return
705
+ * the length in seconds, or { stop(time) } for a loop (params.loop is true then)
706
+ */
580
707
  export type SynthFn = (audio: Audio, params: Record<string, any>, out: any) => number | void | { stop(time: number): void };
581
708
 
582
709
  /**
583
- * The audio table of a content pack (content.load({ audio })): data only. sounds name asset pack sounds ('synth' for a built-in);
710
+ * The audio table of a content pack (content.load({ audio })): data only. sounds are play rules naming asset pack sounds (files or synths);
584
711
  * ambience and music.rules use condition keys and measures, never functions. Merged with createEngine({ audio }); a name in both is an error
585
712
  */
586
713
  export interface ContentAudio {
@@ -589,9 +716,9 @@ export interface ContentAudio {
589
716
  music?: { tracks?: Record<string, import('./gameplay').MusicTrack>; rules?: import('./gameplay').MusicRule[] };
590
717
  footsteps?: Record<string, string>;
591
718
  }
592
- /** The game's sound config: createEngine({ audio }), read back as engine.audio.config (merged with content packs' ContentAudio). Not part of a style pack */
719
+ /** The game's sound config: createEngine({ audio }), read back as engine.audio.config (merged with content packs' ContentAudio). */
593
720
  export interface AudioConfig {
594
- /** Sound name -> file / variants / 'synth' / SoundDef */
721
+ /** Sound name -> play rule: an asset sound name / path, variants, or SoundDef */
595
722
  sounds?: Record<string, SoundSource>;
596
723
  /** ambience() rule table */
597
724
  ambience?: AmbienceRule[];
@@ -631,6 +758,8 @@ export interface UIPart {
631
758
  /** May return a promise that resolves when a fade-out has finished (engine.ui.settled() waits for it) */
632
759
  hide?(): void | Promise<void>;
633
760
  dispose?(): void;
761
+ /** A modal part's root element: the UI choice cursor (uiFocus nav) moves over the controls inside it, so the part works with a gamepad / keyboard only */
762
+ readonly el?: HTMLElement | null;
634
763
  [key: string]: any;
635
764
  }
636
765
  /** Your own part: called once per single part (loading, toast, title) or once per item (hud.*); options are what the game passed as an object */
@@ -662,14 +791,66 @@ export interface TouchView {
662
791
  press(action: string): void;
663
792
  release(action: string): void;
664
793
  }
665
- /** A title screen button: built-ins 'start' | 'continue' | 'settings', or your own */
794
+ /** A title screen button: built-ins 'start' | 'continue', a module's button by id (engine.ui.titleItem: 'settings'), or your own */
666
795
  export interface UITitleItem {
667
796
  id?: string;
668
797
  label: string | ((engine: Engine) => string);
669
798
  run(engine: Engine): any;
670
799
  }
800
+ /** Replaces a window's inner HTML (createEngine({ ui: { templates } }), engine.ui.templates) */
801
+ export type UITemplate = (data: any, tools: { esc: (s: any) => string; t: (key: string, params?: Record<string, any>) => string; icon?: (def: any) => string }) => string;
802
+ /** The CSS values of every default UI part: each key becomes the variable --threedog-<key> on engine.uiRoot */
803
+ export interface UITheme {
804
+ /** Background color */
805
+ bg?: string;
806
+ /** Text color */
807
+ fg?: string;
808
+ /** Secondary text color */
809
+ muted?: string;
810
+ /** Accent color */
811
+ accent?: string;
812
+ /** Color for good news such as "done" */
813
+ good?: string;
814
+ /** Divider color */
815
+ line?: string;
816
+ /** Font (CSS font-family) */
817
+ font?: string;
818
+ /** Corner radius of windows and the dialogue box (CSS, e.g. '12px') */
819
+ radius?: string;
820
+ /** Corner radius of small things: buttons, prompts, toasts, bubbles, HUD counters (CSS, default '8px') */
821
+ radiusSmall?: string;
822
+ /** Loading screen background */
823
+ loadingBg?: string;
824
+ /** Window shadow (CSS) */
825
+ shadow?: string;
826
+ /** Shadow of small things: speech bubbles, objective marker labels (CSS) */
827
+ shadowSmall?: string;
828
+ /** Fade color for scene transitions (CSS), default '#000' */
829
+ fadeBg?: string;
830
+ /** Background / text / accent of objective markers, counters and progress bars (CSS); default: follow bg, fg and accent */
831
+ hudBg?: string;
832
+ hudFg?: string;
833
+ hudAccent?: string;
834
+ /** Other CSS variables (become --threedog-name) */
835
+ [cssVar: string]: string | number | undefined;
836
+ }
837
+ /** createEngine({ ui }): the look of the default parts (theme, css, fonts, templates); every other key is a part name */
838
+ export interface UIOptions {
839
+ /** CSS values of every default part */
840
+ theme?: UITheme;
841
+ /** Extra CSS, placed after every default (overrides .threedog-* classes) */
842
+ css?: string;
843
+ /** Font asset names the UI uses (engine.assets.manifest({ fonts })); loaded at start(), then written in theme.font: '"pixel", system-ui' */
844
+ fonts?: string[];
845
+ /** Replace the content of a window wholesale: inventory, quests, settings, loading, hudMarker, hudCounter, hudBar… */
846
+ templates?: Record<string, UITemplate>;
847
+ /** Part name → false (off), true (default), options, or your own part */
848
+ [part: string]: UIPartValue | UITheme | string | string[] | Record<string, UITemplate> | undefined;
849
+ }
671
850
  /** engine.ui: every piece of screen UI is a named part a game can replace or turn off (see recipes/26-ui-parts.md) */
672
851
  export interface UIParts {
852
+ /** Window content by name: a function here replaces that window's default HTML, read each time it draws */
853
+ templates: Record<string, UITemplate>;
673
854
  /** Declare a part and its default (engine and modules; games use set) */
674
855
  define(name: string, factory: UIPartFactory, def?: UIPartDef): void;
675
856
  /**
@@ -687,6 +868,8 @@ export interface UIParts {
687
868
  /** Close a full-screen part, emits ui:close */
688
869
  close(name: string): void;
689
870
  isOpen(name: string): boolean;
871
+ /** Add a title screen button from a module (settings adds 'settings'): shown after continue / start, and nameable by id in the title's items. ctx.track the handle */
872
+ titleItem(id: string, item: { label: string | ((engine: Engine) => string); run(engine: Engine): any }): { remove(): void };
690
873
  /** name -> 'default' | 'custom' | 'off' */
691
874
  describe(): Record<string, string>;
692
875
  /**
@@ -700,6 +883,9 @@ export interface UIParts {
700
883
  // Ground interface
701
884
  // ======================================================================
702
885
 
886
+ /** Conventional names for the picture values only one writer may hold (core/pictureSlots.js), taken with provides like any other slot */
887
+ export type PictureSlot = 'sky' | 'fog' | 'tone' | 'environment' | 'background' | 'sun';
888
+
703
889
  /** Ground: whoever provides the ground height is the "terrain" (terrain module, level module, or the default flat y=0) */
704
890
  export interface Ground {
705
891
  /**
@@ -724,7 +910,7 @@ export interface Ground {
724
910
  forEachCollider?(x: number, z: number, range: number, fn: (cx: number, cz: number, r: number) => void): void;
725
911
  /** Optional: chunk edge length (meters) */
726
912
  chunkSize?: number;
727
- /** Optional: how far (meters) the ground is shown around a stream source now; stream entries build within it by default (else fogFar) */
913
+ /** Optional: how far (meters) the ground is shown around a stream source now; stream entries build within it by default (else engine.uniforms.uViewDistance) */
728
914
  viewRange?(): number;
729
915
  /** Optional: collision data of a chunk (used by the physics module) */
730
916
  chunkCollision?(cx: number, cz: number): any;
@@ -740,6 +926,37 @@ export interface Ground {
740
926
  // Module definition
741
927
  // ======================================================================
742
928
 
929
+ /** What a module's install / init receive: the module's name, track(handle) and mod(point, o), both tied to the module's life */
930
+ export interface ModuleCtx {
931
+ readonly name: string;
932
+ /** Keep handle (anything with remove(): events.on, onFixed, onFrame, clock timers, audio.measure...) until the module goes: removed when its use()
933
+ * batch rolls back, its init fails, it is replaced, or on engine.dispose() before its dispose hook. Returns the handle */
934
+ track<H extends { remove(): void }>(handle: H): H;
935
+ /**
936
+ * engine.mod with this module as the owner, tracked: the change goes when the module goes. Passing owner throws (use engine.mod for another name).
937
+ * @example ctx.mod('time.world', { mul: 0.8, layer: 'effect' })
938
+ */
939
+ mod(point: string, opts: Omit<import('./gameplay').ModOptions, 'owner'>): import('./gameplay').ModHandle;
940
+ /**
941
+ * engine.control with this module as the default owner, tracked: every character the module holds is handed back when the module goes.
942
+ * @example const h = ctx.control.take(guard, { layer: 'script', step: (dt, ch) => ({ x: 1, z: 0 }) })
943
+ */
944
+ control: {
945
+ take(who: any, opts?: Omit<Parameters<Control['take']>[1], 'owner'> & { owner?: string }): ReturnType<Control['take']>;
946
+ /** True while owner (default the module) holds the character */
947
+ has(who: any, owner?: string): boolean;
948
+ };
949
+ /**
950
+ * Run fn once while start() waits for the GPU to compile shaders (the page's thread is idle then), for a one-time warm-up that would
951
+ * otherwise land in the first frame: a WASM library's first call compiles its code. After start() it runs at once.
952
+ * @example ctx.whileCompiling(() => { const w = new R.World(g); w.step(); w.free(); })
953
+ */
954
+ whileCompiling(fn: () => void): void;
955
+ }
956
+
957
+ /** What a module may own (ModuleDef.type; core/moduleTypes.js) */
958
+ export type ModuleType = 'world' | 'picture' | 'actor' | 'rules' | 'ui' | 'net' | 'tool';
959
+
743
960
  /**
744
961
  * A module (the argument of engine.use). The name is the property name on the engine once installed.
745
962
  * Per-frame hook order follows stage, then before / after within a stage, then install order.
@@ -747,10 +964,25 @@ export interface Ground {
747
964
  export interface ModuleDef<Api = any> {
748
965
  /** Module name; after install, access the object returned by install through engine[name] */
749
966
  name: string;
967
+ /**
968
+ * What the module may own (required; core/moduleTypes.js): 'world' state, records, ops (draws nothing) | 'picture' what is seen and heard (changes no
969
+ * game state: no ops, no world record writes) | 'actor' characters | 'rules' game logic | 'ui' panels and menus (binds no keys, no game save part)
970
+ * | 'net' multiplayer | 'tool' a one-shot job. A game module is usually 'rules'. Breaking a rule throws in dev with the fix.
971
+ */
972
+ type: ModuleType;
750
973
  /** Display name (used by the loading screen) */
751
974
  label?: string;
752
- /** Names of other modules this depends on; they must be installed first (an error is thrown if not) */
975
+ /**
976
+ * Capabilities this depends on: slot names another module provides ('inventory', 'world', 'sky'), never a particular module. Missing throws with both
977
+ * fixes: install the engine's part of that name first, or your own module with provides: ['inventory']
978
+ */
753
979
  requires?: string[];
980
+ /**
981
+ * Capabilities this module holds while installed ("only one may hold this": 'sky', 'inventory'); engine.<slot> is its API too, so dependents keep
982
+ * working when a game swaps it: engine.use(mine(), { replaces: 'inventory' }). A second provider throws shared-taken. describe().shared shows the holder.
983
+ * Picture values only one writer may hold have conventional names (PictureSlot, PICTURE_SLOTS; recipes/62-picture-code.md "Picture parts").
984
+ */
985
+ provides?: (PictureSlot | (string & {}))[];
754
986
  /**
755
987
  * Optional dependencies (modules the code uses as e.xxx?. or guards with if (e.xxx); rule R16 requires listing them all).
756
988
  * An array only registers them; written as { moduleName: 'what is lost when missing' }, start() prints a one-time development hint when one is
@@ -758,34 +990,32 @@ export interface ModuleDef<Api = any> {
758
990
  */
759
991
  optional?: string[] | Record<string, string>;
760
992
  /**
761
- * Hook stages (first -> last): 'control' timeline, camera -> 'world' terrain, level -> 'environment' weather, sky, water -> 'gameplay' interactions,
762
- * dialogue, triggers, entities
763
- * -> 'presentation' particles, settings, objective markers -> 'late' (default) -> 'audio' music. Within a stage use before / after, then install order
993
+ * Hook stages, only the run order (first -> last): 'control' timeline, camera -> 'ground' terrain, level -> 'environment' weather, sky, water
994
+ * -> 'gameplay' interactions, dialogue, triggers -> 'effects' particles, settings, objective markers -> 'late' (default) -> 'audio' music.
995
+ * Within a stage use before / after, then install order. What the module may own and how its errors are handled come from type
764
996
  */
765
- stage?: 'control' | 'world' | 'environment' | 'gameplay' | 'presentation' | 'late' | 'audio';
997
+ stage?: 'control' | 'ground' | 'environment' | 'gameplay' | 'effects' | 'late' | 'audio';
766
998
  /** Hooks run before these modules, inside one stage (ignored if not installed;
767
999
  * use() throws on a cycle, or when the other module's stage already runs earlier) */
768
1000
  before?: string[];
769
1001
  /** Hooks run after these modules, inside one stage (ignored if not installed;
770
1002
  * use() throws on a cycle, or when the other module's stage already runs later) */
771
1003
  after?: string[];
772
- /**
773
- * Presentation modules (particles, sound effects, HLOD; gameplay is unaffected without them): when a hook errors only this module is disabled and the
774
- * game continues.
775
- * Without it the module counts as gameplay: during development / testing an error freezes gameplay and is recorded in engine.error (error severity levels)
776
- */
777
- presentation?: boolean;
778
1004
  /**
779
1005
  * The game cannot run without this module (default false): when its init() fails, engine.start() rejects with the module name and reason instead of
780
- * starting a broken game. Without it a failed init is reported by severity (presentation: disabled and the game carries on; gameplay: error tiers) and
1006
+ * starting a broken game. Without it a failed init is reported by severity (type picture / ui: disabled and the game carries on; other types: error tiers) and
781
1007
  * start() goes on. Only start() reads it; a critical module installed after start() is reported like any other
782
- * @example engine.use({ name: 'saveSlots', critical: true, async init(e) { await loadSlots(); } })
1008
+ * @example engine.use({ name: 'saveSlots', type: 'rules', critical: true, async init(e) { await loadSlots(); } })
783
1009
  */
784
1010
  critical?: boolean;
785
- /** Install: create and return the object the game uses (engine.name) */
786
- install?(e: Engine): Api;
787
- /** Called at startup (download things, wait for assets); may be async */
788
- init?(e: Engine): void | Promise<void>;
1011
+ /**
1012
+ * Install: create and return the object the game uses (engine.name). Register listeners / timers through ctx.track so they leave with the module
1013
+ * (a use() batch that rolls back, a failed init, engine.dispose)
1014
+ * @example install(e, ctx) { ctx.track(e.events.on('item:add', onAdd)); return api; }
1015
+ */
1016
+ install?(e: Engine, ctx: ModuleCtx): Api;
1017
+ /** Called at startup (download things, wait for assets); may be async. ctx is the same as install's */
1018
+ init?(e: Engine, ctx: ModuleCtx): void | Promise<void>;
789
1019
  /** The loading screen waits until this returns true before disappearing (the hook is called isReady; in the engine ready is always a boolean property) */
790
1020
  isReady?(e: Engine): boolean;
791
1021
  /** After a save loaded: rebuild what the loaded state needs nearby; gameplay waits frozen until the returned Promise resolves */
@@ -797,9 +1027,9 @@ export interface ModuleDef<Api = any> {
797
1027
  /** After rendering */
798
1028
  afterRender?(dt: number, e: Engine): void;
799
1029
  /**
800
- * engine.skip moved time without stepping: advance your own time by dt fixed seconds (game seconds = dt x clock.timeScale), no per-step work.
801
- * Called once per skip segment (segments end at timers and sky clock marks); done is true on the last one: do expensive catch-up only then.
802
- * Only for modules that keep time themselves (sky, world); modules that compare against clock.now need nothing
1030
+ * engine.skip moved time without stepping: advance your own time by dt fixed seconds (calendar seconds = dt x clock.speed), no per-step work.
1031
+ * Called once per skip segment (segments end at timers and calendar clock marks); done is true on the last one: do expensive catch-up only then.
1032
+ * Only for modules that keep time themselves (calendar, world); modules that compare against clock.now need nothing
803
1033
  */
804
1034
  skip?(dt: number, e: Engine, done: boolean): void;
805
1035
  /**
@@ -812,8 +1042,8 @@ export interface ModuleDef<Api = any> {
812
1042
  counts?(e: Engine): number | Record<string, number>;
813
1043
  /** Optional: answer engine.explain({ key: value }) for your own keys, e.g. explain: { quest: (e, id) => ({ ok: false, text: 'waits on step 2: ...' }) } */
814
1044
  explain?: Record<string, (e: Engine, value: any, query: Record<string, any>) => { ok: boolean; text: string; [k: string]: any }>;
815
- /** Optional: handle the keys of engine.applyState that this module owns (e.g. sky handles time) */
816
- applyState?(e: Engine, params: StateParams): void | Promise<void>;
1045
+ /** Optional: handle the keys of engine.applyState that this module owns (e.g. calendar handles time and season); for at, return the place's position */
1046
+ applyState?(e: Engine, params: StateParams): void | PositionLike | Promise<void>;
817
1047
  /**
818
1048
  * Optional: called on engine.dispose() (in reverse install order). Only clean up what the core cannot: Workers, the physics world, real-time timers,
819
1049
  * Audio nodes you connected yourself.
@@ -832,20 +1062,16 @@ export type ModuleInput = ModuleDef | ModuleInput[] | false | null | undefined;
832
1062
  export interface EngineOptions {
833
1063
  /** Canvas element (required unless renderer is given), e.g. document.getElementById('view') */
834
1064
  canvas?: HTMLCanvasElement | HTMLElement;
835
- /** A ready three.js renderer (WebGLRenderer or compatible) to use instead of creating one; canvas then defaults to renderer.domElement. The engine configures
836
- * (pixel ratio, size, tone mapping, shadows) only a renderer it created itself. WebGL is the fully supported path; WebGPU-style renderers may not run shader patches or post effects (recipe 48) */
837
- renderer?: any;
838
- /** Style pack (looks only: materials, sky, lighting, post, UI look), a pack you made or installed (import basePack from 'your-pack'), or a list of parts
839
- * deep-merged left to right: [basePack, { sky: { sunSize: 600 } }]. Without one: neutral gray placeholders */
840
- style?: StyleInput;
841
- /** Real-time shadows, default true */
842
- shadows?: boolean;
843
- /** Shadow filter: 'basic' (hard edge) | 'pcf' | 'vsm' (softest, costliest), default 'pcf'. Change later with engine.look.shadow.set({ type }) */
844
- shadowType?: 'basic' | 'pcf' | 'vsm';
845
- /** MSAA anti-aliasing (kept with post effects on), default style.antialias, else on for desktop and off for low-tier devices */
1065
+ /** 'webgl' (default): the engine builds a WebGLRenderer. 'webgpu': it builds three's WebGPURenderer (needs import 'threedog/tsl' first) and start() awaits its init().
1066
+ * Or a ready three.js renderer (WebGLRenderer or WebGPURenderer) used as is; canvas then defaults to renderer.domElement. The engine configures
1067
+ * (pixel ratio, size, tone mapping, shadows) only a renderer it created itself. A WebGPURenderer passed in goes the same way as 'webgpu' (start() inits it if needed) */
1068
+ renderer?: 'webgl' | 'webgpu' | EngineRenderer;
1069
+ /** WebGPU route only: what start() does when the browser gives no WebGPU. 'webgl2' (default): the same WebGPURenderer on its WebGL2 backend, TSL keeps
1070
+ * working; 'webgl': a WebGLRenderer instead (faster, but NodeMaterials cannot draw: start() fails if the scene has one); 'error': start() rejects.
1071
+ * Every fallback prints one '[threedog] WebGPU unavailable (...)' line and shows in describe().renderer */
1072
+ fallback?: 'webgl2' | 'webgl' | 'error';
1073
+ /** MSAA anti-aliasing (kept with post effects on), default on for desktop and off for low-tier devices; with a renderer of your own, its own antialias. The start value is the canvas's own MSAA (no post chain while no effect is on) */
846
1074
  antialias?: boolean;
847
- /** Turn style post effects on or off by name at startup, e.g. { bloom: false }; default: each effect's own setting (costly ones off on low-tier devices) */
848
- post?: Record<string, boolean>;
849
1075
  /** Render resolution, default min(device pixel ratio, 1.5); the low tier uses at least 0.75 x device pixel ratio (never below 1). describe().render.scale reports it */
850
1076
  pixelRatio?: number;
851
1077
  /** Automatically lower resolution when the frame rate is too low, default true. Never silent: a dev warning once, and describe().render.scale.autoLowered */
@@ -853,29 +1079,27 @@ export interface EngineOptions {
853
1079
  /** Target frame rate for automatic resolution lowering, default 55 */
854
1080
  targetFps?: number;
855
1081
  /**
856
- * UI parts: replace or turn off any piece of screen UI (loading, toast, title, hud.marker, hud.counter, hud.bar). Default title screen is off.
1082
+ * All screen UI: replace or turn off any part (loading, toast, title, hud.marker, hud.counter, hud.bar; the default title screen is off), and the look of the
1083
+ * default parts (theme, css, fonts, templates).
857
1084
  * @example createEngine({ canvas, ui: { loading: { title: 'My Game' }, title: { title: 'My Game' }, toast: false } })
1085
+ * @example createEngine({ canvas, ui: { theme: { bg: '#1c140e', accent: '#e8a13a' }, css: '.threedog-prompt{font-size:16px}' } })
858
1086
  */
859
- ui?: Record<string, UIPartValue>;
1087
+ ui?: UIOptions;
860
1088
  /** Volume of each channel, 0–1 */
861
1089
  audio?: AudioConfig;
862
1090
  /** Camera field of view (degrees), default 55 */
863
1091
  fov?: number;
864
1092
  /** Camera near clipping plane (meters), default 0.3 */
865
1093
  near?: number;
866
- /** Default fog distance (meters), default 600 */
867
- fogFar?: number;
868
- /** UI language: 'auto' (default) follows the browser (a language starting with zh gives 'zh-CN', anything else 'en'); or force 'zh-CN' | 'en' | your own */
1094
+ /** UI language: 'auto' (default) follows the browser (a language starting with zh gives 'zh-CN', anything else 'en'); or force 'zh-CN' | 'en' | your own. Matched by language: 'zh' / 'zh-Hans' give 'zh-CN', 'en-US' gives 'en'; a language with no strings warns once */
869
1095
  locale?: string;
870
1096
  /** Override / add UI strings: { 'zh-CN': { key: text } } */
871
1097
  strings?: StringTables;
872
1098
  /**
873
- * Keys per action: changes the neutral defaults (move / confirm / cancel) and binds gameplay actions, e.g. { interact: ['KeyE'], run: ['ShiftLeft'] };
874
- * a module's define() keeps these keys
1099
+ * The game's keys per action (keyboard, 'Mouse0', gamepad 'PadA' in one list), owner 'game': replaces the basics (move / confirm / cancel / UI
1100
+ * cursor) and binds every other action, e.g. { interact: ['KeyE', 'PadX'], ...presets.bindings.dialogNumbers }. Same as engine.input.bind(map)
875
1101
  */
876
- bindings?: Record<string, string[]>;
877
- /** Default gamepad buttons: { jump: 'PadA' } */
878
- padBindings?: Record<string, string>;
1102
+ bindings?: Readonly<Record<string, string | readonly string[]>>;
879
1103
  /** Save name prefix; must differ when several games share one site, default 'game' */
880
1104
  saveKey?: string;
881
1105
  /** On-screen joystick: 'auto' (only on touch devices) | true | false */
@@ -913,9 +1137,9 @@ export interface EngineOptions {
913
1137
  threads?: 'auto' | number | false;
914
1138
  /** Gameplay waits while the window is in the background or the tab is hidden; default true (engine.page) */
915
1139
  pauseOnBlur?: boolean;
916
- /** false: no default lights in the scene at all (engine.lights.sun / hemi still exist, detached, so sky and describe never see undefined); the game adds its own. Default true */
1140
+ /** false: no default lights in the scene at all (engine.lights.sun / hemi still exist, detached, so sky and describe never see undefined); the game adds its own. No light of the engine's reaches the picture. Default true */
917
1141
  lights?: boolean;
918
- /** Automatic instancing of repeated static models (engine.batching): false turns it off; default { minCount: 8, cell: engine.stream.cellSize } */
1142
+ /** Automatic instancing of repeated static models the engine places (engine.batching; your own meshes opt in with userData.batch = true): false turns it off; default { minCount: 8, cell: engine.stream.cellSize } */
919
1143
  batching?: false | BatchingOptions;
920
1144
  }
921
1145
 
@@ -988,7 +1212,7 @@ export interface ThingExplanation {
988
1212
  /** at: 'content/props.js:14' (null in release builds and for code without a file) */
989
1213
  definition: { at: string | null; template: string | null; templateAt: string | null; level?: string; node?: string; spawned?: boolean; [k: string]: any };
990
1214
  model: string | null;
991
- materials: ({ role: string | null; name: string | null; from: string | null; keys: string[]; type: string; color: string | null; mesh: string | null } | { more: number })[];
1215
+ materials: ({ role: string | null; name: string | null; from: 'engine' | 'game'; type: string; color: string | null; mesh: string | null } | { more: number })[];
992
1216
  state: { position?: number[]; visible?: boolean; scale?: number[]; [k: string]: any };
993
1217
  rules: { height?: number; blocksMovement?: any; pickable?: boolean; interact?: any; [k: string]: any };
994
1218
  ops: { op: string; desc: string | null; args: any }[];
@@ -1030,7 +1254,7 @@ export interface HitThing {
1030
1254
  phase?: 'setup' | 'play';
1031
1255
  op?: string | null;
1032
1256
  tick?: number;
1033
- /** how much a save keeps (recipe 41): record = world save; code = thing.set / thing.remove overrides; session = nothing; engine = its module's business */
1257
+ /** how much a save keeps (recipe 40): record = world save; code = thing.set / thing.remove overrides; session = nothing; engine = its module's business */
1034
1258
  saved?: 'record' | 'code' | 'session' | 'engine';
1035
1259
  /** what a save keeps / loses, in words */
1036
1260
  keeps?: string[];
@@ -1056,6 +1280,10 @@ export interface BatchingStats {
1056
1280
  instances: number;
1057
1281
  /** Draw calls saved per pass (instances - batches) */
1058
1282
  saved: number;
1283
+ /** Present while anything is batched: what batching did to the engine's content meshes and how to raycast / opt out / turn it off */
1284
+ note?: string;
1285
+ /** Dev only, while at least minCount identical game-made meshes draw unbatched: the opt-in line (obj.userData.batch = true) */
1286
+ hint?: string;
1059
1287
  }
1060
1288
  /** One entry of engine.batching.batches */
1061
1289
  export interface BatchInfo {
@@ -1127,10 +1355,15 @@ export interface StreamHandle { def: StreamEntryOptions; object: Object3D | null
1127
1355
  * Startup timing (milliseconds): totalMs page open to playable, startMs start() to playable, preloadMs preloading, streamMs the nearby builds required
1128
1356
  * by stream registrations finished, compileMs shader compilation before the first frame,
1129
1357
  * modules is the init / ready time of each module. With a budget on and startupMs (open to playable) / moduleMs (a single module) given, the slowest
1130
- * module is reported in the console when exceeded
1358
+ * module is reported in the console when exceeded.
1359
+ * firstFrameMs: page open to the end of the first frame drawn after the loading screen (null until that frame, and headless); phases add up to it:
1360
+ * script (page open until createEngine), construct (createEngine), setup (game code until start()), init (saves, renderer, module init), preload,
1361
+ * world (scenario parameters, nearby builds), compile (shaders + hidden warm-up frame), draw (ready until the first frame's draw calls were submitted)
1131
1362
  */
1132
1363
  export interface StartupReport {
1133
1364
  totalMs: number; startMs: number; preloadMs: number; streamMs: number | null; compileMs: number; modules: Record<string, { init?: number; ready?: number }>;
1365
+ firstFrameMs: number | null;
1366
+ phases: { script: number; construct: number; setup: number; init: number; preload: number; world: number; compile: number; draw: number | null };
1134
1367
  }
1135
1368
 
1136
1369
  // ======================================================================
@@ -1143,32 +1376,32 @@ export interface StateParams {
1143
1376
  state?: string;
1144
1377
  /** Time of day: 'HH:MM' or 0–1 */
1145
1378
  time?: string | number;
1146
- /** Season name from sky({ seasons }): jumps sky.day to that season's first day (time of day kept) */
1379
+ /** Season name from calendar({ seasons }): jumps calendar.day to that season's first day (time of day kept) */
1147
1380
  season?: string;
1148
1381
  /** Weather name */
1149
1382
  weather?: string;
1150
1383
  /** Player position: 'x,z' or a position (sets the focus when there is no player) */
1151
1384
  pos?: string | PositionLike;
1385
+ /** Start at a named place (content places, level markers): past the title like play, then the player stands there with the game's camera on it */
1386
+ at?: string;
1152
1387
  /** Which save slot to load */
1153
1388
  save?: string;
1154
- /** How many seconds to advance (fixed-step seconds, not multiplied by clock.timeScale) */
1389
+ /** How many seconds to advance (real seconds: fixed-step seconds, no scale) */
1155
1390
  wait?: number;
1156
1391
  /** Opening cutscene: 'skip' skips it | 'keep' plays it as usual */
1157
1392
  cutscene?: 'skip' | 'keep';
1393
+ /** A view declared with engine.views to show after engine:ready (?view=name); ignored when the game declared no views */
1394
+ view?: string;
1395
+ /** Present (?play, any value): leave the title screen the way its Start does (engine.session.newGame(), the title part closes; flow leaves its start state) before wait; nothing when no title is up */
1396
+ play?: string | boolean;
1397
+ /** Delete every save of this page first (no Continue on the title); on a running page also end the run and go back to the title. ?fresh in the URL */
1398
+ fresh?: string | boolean;
1158
1399
  }
1159
1400
 
1160
1401
  /** A claim on something only its owner releases (pause, freeze, takeCamera, views) */
1161
1402
  export interface OwnerHandle { owner: string; remove(): void }
1162
- /** What pause / freeze return: the claim handle, plus the old chaining calls forwarded to the engine */
1163
- export interface ChainedHandle extends OwnerHandle {
1164
- pause(owner?: string | { owner?: string; kind?: 'test' }, opts?: { kind?: 'test' }): ChainedHandle;
1165
- resume(owner?: string | { owner?: string }): Engine;
1166
- freeze(owner?: string | { owner?: string; kind?: 'title' }, opts?: { kind?: 'title' }): ChainedHandle;
1167
- unfreeze(owner?: string | { owner?: string }): Engine;
1168
- step(seconds: number, opts?: { render?: boolean; frameEvery?: number; describe?: boolean }): GameState | null;
1169
- }
1170
- /** engine.runState: state in one word, by = every pause / freeze owner, blockedBy = opaque input contexts plus 'error' / 'loading' */
1171
- export interface RunState { state: 'loading' | 'title-frozen' | 'test-paused' | 'paused' | 'running'; by: string[]; blockedBy: string[] }
1403
+ /** engine.runState: state in one word, owners = every pause / freeze owner, blockedBy = opaque input contexts plus 'error' / 'loading' */
1404
+ export interface RunState { state: 'loading' | 'title-frozen' | 'test-paused' | 'paused' | 'running'; owners: string[]; blockedBy: string[] }
1172
1405
  /** Camera takeover: when non-null no camera module moves the camera (for cutscenes); see engine.takeCamera */
1173
1406
  export interface CameraOverride {
1174
1407
  /** Who took over (any name) */
@@ -1181,129 +1414,121 @@ export interface CameraOverride {
1181
1414
  export interface AdaptiveState { paused: boolean; on: boolean; target: number; min: number; max: number; /** true once the render scale was lowered below max (a dev warning was logged) */ lowered?: boolean; [key: string]: any }
1182
1415
 
1183
1416
  // ======================================================================
1184
- // Look parts engine.look.<part> (recipes/52-look.md)
1417
+ // Shadows: engine.shadows (recipes/45-cascaded-shadows.md)
1185
1418
  // ======================================================================
1186
1419
 
1187
- /** Returned by set / patch / replace: remove() takes that owner's layer back off */
1188
- export interface LookHandle { remove(): void }
1189
- /** engine.look.post: a LookPart with add() for one custom pass */
1190
- export interface LookPost extends LookPart {
1191
- /** Add ONE custom post pass (name, create | fuse, slot, order, params) without replacing the chain; remove() takes it out again. Slot, order and depth-order errors throw and add nothing. Change its params with set({ '<name>.<param>': v }) */
1192
- add(effect: PostEffect, opts?: LookOptions): LookHandle;
1420
+ /** engine.shadows.cascades options (recipes/45) */
1421
+ export interface ShadowCascadeOptions {
1422
+ /** Shadow maps along the view, 1-4 (default 3; 1 = the plain single map) */
1423
+ count?: number;
1424
+ /** Meters from the camera they cover (default 120) */
1425
+ maxFar?: number;
1426
+ /** Where the borders fall (default 'practical') */
1427
+ split?: 'practical' | 'uniform' | 'logarithmic' | ((count: number, near: number, far: number, out: number[]) => void);
1428
+ /** Cross-fade at the borders (default true) */
1429
+ fade?: boolean;
1430
+ /** Meters behind each cascade box toward the light still caught as casters (default 100) */
1431
+ lightMargin?: number;
1432
+ /** On engine.tier 'low': { count } (default 1, one map) */
1433
+ low?: { count: number };
1193
1434
  }
1194
- /** owner: who writes the layer (non-empty name, default 'game'); roles: only materials.patch, the material roles that get the patch */
1195
- export interface LookOptions { owner?: string; roles?: string[] }
1196
- /** patch(name, spec): a spec instead of plain GLSL. post: fuse snippet (glsl, slot, order, uniforms, values); sky 'layer:<name>': glsl, blend, order, uniforms */
1197
- export interface LookPatchSpec {
1198
- glsl?: string | Record<string, any>;
1199
- /** post: 'hdr' | 'ldr' */
1200
- slot?: string;
1201
- /** post and sky layers: draw order, smaller first */
1202
- order?: number;
1203
- uniforms?: Record<string, any>;
1204
- /** post: live values of the generated effect */
1205
- values?: Record<string, any>;
1206
- /** sky layer: 'mix' | 'add' */
1207
- blend?: string;
1435
+ /** What engine.shadows.cascades returns */
1436
+ export interface ShadowCascades {
1437
+ /** The game's light it was given */
1438
+ readonly light: import('three').DirectionalLight;
1439
+ /** three's CSM object (the shadow node on WebGPURenderer); null while there is one map */
1440
+ readonly csm: any;
1441
+ /** Change options (a rebuild recompiles lit materials: a settings screen, not per frame) */
1442
+ set(options: ShadowCascadeOptions): void;
1443
+ /** Back to one plain shadow map: the light's position, target and shadow box as the game left them */
1444
+ remove(): void;
1208
1445
  }
1209
-
1210
- /**
1211
- * One look part. Layers, upper wins: engine default < style < game (per owner, last write wins) < engine.debug.override.
1212
- * A part offers only the verbs that make sense for it; the others throw naming the verb to use.
1213
- */
1214
- export interface LookPart<P = Record<string, any>> {
1215
- /** 'look.<part>': the id engine.catalog() and debug.override use */
1216
- readonly id: string;
1217
- /** Shallow-merge into the owner's layer, only the keys given; null drops a key so the layer below shows again. Keys that recompile shaders warn once in dev */
1218
- set(params: { [K in keyof P]?: P[K] | null } & Record<string, any>, opts?: LookOptions): LookHandle;
1219
- /** Swap one named GLSL hook the part registered (names: engine.catalog('look.<part>').hooks); the same name again overrides; patch(name, null) restores the default */
1220
- patch(name: string, glsl: string | LookPatchSpec | null, opts?: LookOptions): LookHandle;
1221
- /** Take the whole part over (Material, texture, object, effect list ...: see the catalog); replace(null) gives it back. materials.replace takes the role first */
1222
- replace(impl: any, opts?: LookOptions): LookHandle;
1223
- replace(role: string, impl: any, opts?: LookOptions): LookHandle;
1224
- /** Drop every game and debug layer of that owner (the style value shows again); returns how many layers were removed, like engine.debug.clear */
1225
- clear(owner: string): number;
1226
- /** The resolved value of a key (what is in use now) */
1227
- value(key: string): any;
1228
- /** The value from the highest game / debug layer for the key (undefined when only style or default gives it) */
1229
- top(key: string): any;
1230
- /** The three.js object(s) behind the part (renderer, lights, scene.fog ...); changing it directly works but describe tags it 'three'.
1231
- * look.materials: a function, object('wool') = the last Material made for that role, object() = all of them */
1232
- readonly object: any;
1233
- /** Each verb's call shape, e.g. { set: 'set(params, { owner })', replace: 'replace(role, ...)' } (also in engine.catalog('look.<part>')) */
1234
- readonly signatures: Record<string, string>;
1235
- // ---- for authors of a part made with defineLookPart (recipes/52-look.md) ----
1236
- /** Write raw keys (params, 'hook:<name>', '@replace') for an owner, no normalize; null drops a key */
1237
- write(owner: string, values: Record<string, any>, opts?: { layer?: 'game' | 'debug' }): LookHandle;
1238
- /** What one owner holds for a key, or undefined */
1239
- ownerValue(owner: string, key: string, opts?: { layer?: 'game' | 'debug' }): any;
1240
- /** Add declared keys to a started part (same fields as defineLookPart params) */
1241
- extend(params: Record<string, any>): void;
1242
- /** Remove every key starting with prefix, with every layer's value for them */
1243
- retract(prefix: string): void;
1244
- /** Is key a declared param */
1245
- has(key: string): boolean;
1246
- /** [key, value] pairs in effect whose key starts with prefix */
1247
- resolved(prefix?: string): Array<[string, any]>;
1248
- /** Replace the style layer */
1249
- restyle(values: Record<string, any>): void;
1250
- /** Declare keys a style-driven system writes every frame (by = the driver's module name); drive(keys, null) hands them back */
1251
- drive(keys: string[], by: string | null): void;
1252
- /** Unregister the part (its module went away) */
1253
- dispose(): void;
1446
+ /** engine.shadows.box options */
1447
+ export interface ShadowBoxOptions {
1448
+ /** What the box centers on: 'focus' (engine.focus, default) | 'camera' | an Object3D | () => Vector3 | false (it stays on the light's target) */
1449
+ follow?: 'focus' | 'camera' | import('three').Object3D | (() => import('three').Vector3) | false;
1450
+ /** Half size of the box in meters; left out: the light's own shadow camera stays as it is */
1451
+ extent?: number;
1452
+ /** Center snap grid in meters (default 0.5), or 'texel': one shadow pixel */
1453
+ snap?: number | 'texel';
1454
+ /** Meters the center is shifted in front of the view, default 0 */
1455
+ ahead?: number;
1254
1456
  }
1255
-
1256
- export interface LookTone { mapping: string; exposure: number | Array<[number, number]> | ((t: number) => number) }
1257
- export interface LookLightSide { color?: ColorLike; intensity?: number }
1258
- export interface LookLights { sun: LookLightSide | 'manual' | false; hemi: LookLightSide | 'manual' | false }
1259
- /** The map itself is the replace slot: look.env.replace('sky' | Texture | null) */
1260
- export interface LookEnv { intensity: number; rotation: number; interval: number }
1261
- export interface LookFog { kind: string; color: ColorLike | 'horizon'; density: number; near: number; far: number; height: number; falloff: number; enabled: boolean }
1262
- export interface LookSky { clouds: Record<string, any>; backdrop: ColorLike | null }
1263
- export interface LookShadow {
1264
- type: 'basic' | 'pcf' | 'vsm'; radius: number; blurSamples: number; bias: number; normalBias: number; mapSize: number; updateEvery: number;
1265
- snap: number | 'texel'; ahead: number; cascades: number; maxFar: number; fade: boolean; lightMargin: number; enabled: boolean;
1266
- split: 'practical' | 'uniform' | 'logarithmic' | ((count: number, near: number, far: number, out: number[]) => void);
1457
+ /** What engine.shadows.box returns */
1458
+ export interface ShadowBox {
1459
+ set(options: ShadowBoxOptions): void;
1460
+ /** Stop following: the light's position, target and shadow camera come back */
1461
+ remove(): void;
1267
1462
  }
1268
- export interface LookCloudShadow { shadow: number; scale: number; speed: [number, number] }
1269
- export interface LookWind { frequency: number; amplitude: number }
1270
- export interface LookGround {
1271
- colors: Record<string, ColorLike>; biomeColors: Record<string, string | string[]>; steep: Array<{ maxNormalY: number; colors: any }>;
1272
- variation: any; detail: any; shading: string;
1463
+ /** What engine.shadows.budget returns */
1464
+ export interface ShadowBudget {
1465
+ set(options: { every?: number }): void;
1466
+ /** Redraw this light's map on the next frame */
1467
+ redraw(): void;
1468
+ /** light.shadow.autoUpdate as it was */
1469
+ remove(): void;
1273
1470
  }
1274
- export interface LookSurface { lighting: Record<string, any>; detail: Record<string, any>; ramp: number[]; soften: number }
1275
- export interface LookWater {
1276
- color: ColorLike; opacity: number; depthColor: { shallow?: ColorLike; deep?: ColorLike }; foam: Record<string, any>;
1277
- waveHeight: number; waveScale: number; waveSpeed: number; fresnel: number;
1471
+ /** A game's own term: a patch, in place of the engine's on every material that carries it */
1472
+ export interface TermSpec {
1473
+ /** Slot code for WebGLRenderer */
1474
+ glsl?: string;
1475
+ /** (ctx) => node for WebGPURenderer */
1476
+ tsl?: any;
1477
+ uniforms?: Record<string, any>;
1478
+ /** Extra declarations for the glsl */
1479
+ pars?: string;
1480
+ /** Default 'lighting' for the cloud shadow, 'color' for the season tint */
1481
+ slot?: string;
1278
1482
  }
1279
-
1280
- /** engine.look: the parts by name. A part exists only when the module that provides it is installed (fog / sky / shadow / env: sky(); ground: terrain(); wind: vegetation(); water; weather) */
1281
- export interface Look {
1282
- tone: LookPart<LookTone>;
1283
- lights: LookPart<LookLights>;
1284
- cloudShadow: LookPart<LookCloudShadow>;
1285
- /** Old name of cloudShadow (recipes/52-look.md, Old names) */
1286
- clouds: LookPart<LookCloudShadow>;
1287
- env: LookPart<LookEnv>;
1288
- fog: LookPart<LookFog>;
1289
- sky: LookPart<LookSky>;
1290
- shadow: LookPart<LookShadow>;
1291
- /** Roles are the keys: set({ wool: { roughness: 0.4 } }), patch(name, spec, { roles }), replace('wool', Material | fn) */
1292
- materials: LookPart<Record<string, Record<string, any>>>;
1293
- surface: LookPart<LookSurface>;
1294
- ground: LookPart<LookGround>;
1295
- wind: LookPart<LookWind>;
1296
- water: LookPart<LookWater>;
1297
- /** Keys 'rain.speed', 'snow.size', 'lightning.brightness', overcastColor ...; patch('rain.fragment', wholeShaderText) */
1298
- weather: LookPart;
1299
- /** Per effect: set({ bloom: { strength: 0.6 }, vignette: false }); patch(name, { glsl, slot, order, uniforms, values }); add(effect, { owner }); replace([effects]) */
1300
- post: LookPost;
1301
- /** Parts made with defineLookPart */
1302
- [custom: string]: LookPart;
1483
+ /** engine.terms */
1484
+ export interface Terms {
1485
+ /**
1486
+ * Your own cloud shadow in place of the engine's on engine materials and on what you passed to applyEffects, built before the call too; false takes it off them
1487
+ * all. uCloud*, uTime and threedogCloudShadow(worldPos) stay in scope. remove() gives the engine's back.
1488
+ * @example const mine = engine.terms.cloudShadow({ glsl: 'reflectedLight.directDiffuse *= 0.5;', tsl: c => ({ directDiffuse: c.directDiffuse.mul(0.5) }) }); mine.remove();
1489
+ */
1490
+ cloudShadow(spec: TermSpec | false): { remove(): void };
1491
+ /**
1492
+ * Your own season and snow tint in place of the engine's on engine materials and on what you passed to applyEffects with a season, built before the call too; false
1493
+ * takes it off them all. uFoliageTint, uGroundTint, uFoliageMix, uGroundMix, uCover and threedogSeason(color, kind) stay in scope. remove() gives the engine's back.
1494
+ * @example const mine = engine.terms.season(kind => ({ glsl: 'diffuseColor.rgb = mix(diffuseColor.rgb, vec3(1.0), uCover.y);', tsl: c => c.color })); mine.remove();
1495
+ */
1496
+ season(spec: TermSpec | ((kind: 'foliage' | 'ground') => TermSpec) | false): { remove(): void };
1497
+ }
1498
+ /** engine.view */
1499
+ export interface View {
1500
+ /**
1501
+ * Stop the engine changing a camera or drawing-buffer value: it is yours until you hand it back (a direct write takes it too; this says so on purpose, with no
1502
+ * warning). 'camera' hands the pose back after a direct write (take it with engine.takeCamera(owner)). Pass false to hand back; remove() does the same.
1503
+ * @example const mine = engine.view.manual('far'); engine.camera.far = 5000; mine.remove();
1504
+ */
1505
+ manual(key: 'far' | 'fov' | 'pixelRatio' | 'camera', on?: boolean): { remove(): void };
1506
+ }
1507
+ /** engine.shadows */
1508
+ export interface Shadows {
1509
+ /**
1510
+ * Master switch: renderer.shadowMap.enabled, never a light's castShadow; materials recompile once. A cutscene holds it with
1511
+ * engine.mod('shadows.enabled', { owner, layer: 'system', set: false }); the settings menu restricts it.
1512
+ */
1513
+ enabled: boolean;
1514
+ /** Cascaded shadows for a DirectionalLight (in engine.scene, castShadow on): sharp near the camera, wide far away; color, intensity and shadow values stay yours */
1515
+ cascades(light: import('three').DirectionalLight, options?: ShadowCascadeOptions): ShadowCascades;
1516
+ /** Keep a DirectionalLight's one shadow map around something that moves; the light keeps its direction */
1517
+ box(light: import('three').DirectionalLight, options?: ShadowBoxOptions): ShadowBox;
1518
+ /** Redraw one light's shadow map every N frames; other lights are not touched */
1519
+ budget(light: import('three').Light, options?: { every?: number }): ShadowBudget;
1520
+ /** Change a light's shadow resolution at any time, with cascades every cascade's map (light.shadow.mapSize alone does nothing once a map exists) */
1521
+ mapSize(light: import('three').Light, width: number, height?: number): void;
1522
+ /**
1523
+ * Let cascaded shadows patch a lit ShaderMaterial of yours (lights: true, built from THREE.ShaderLib); built-in lit materials need nothing. Returns it.
1524
+ * @example engine.shadows.include(myShaderMaterial);
1525
+ */
1526
+ include<M extends import('three').Material>(material: M): M;
1527
+ /** The cascades on now (three's CSM, or the shadow node on WebGPURenderer); null when off */
1528
+ readonly csm: any;
1303
1529
  }
1304
-
1305
1530
  /**
1306
- * The engine. Created by createEngine({ canvas, style }); engine.use(module...) installs modules, engine.start() starts it.
1531
+ * The engine. Created by createEngine({ canvas }); engine.use(module...) installs modules, engine.start() starts it.
1307
1532
  * Installed modules hang on the engine (engine.terrain, engine.sky...); modules not installed are undefined, check with engine.xxx?.method().
1308
1533
  */
1309
1534
  export declare class Engine {
@@ -1312,30 +1537,23 @@ export declare class Engine {
1312
1537
  // ---------- Core objects ----------
1313
1538
  /** three.js (a game can also import { THREE } from 'threedog' directly) */
1314
1539
  THREE: typeof import('three');
1315
- /** Style pack */
1316
- style: Style;
1317
- /** three.js renderer */
1318
- renderer: import('three').WebGLRenderer;
1319
- /** Device tier: 'low' (phones, integrated graphics) | 'high' */
1540
+ /** three.js renderer: WebGLRenderer, or WebGPURenderer on the WebGPU route (EngineRenderer) */
1541
+ renderer: EngineRenderer;
1542
+ /** Device tier: 'low' (phones, integrated graphics) | 'high'. A headless page takes it from ?threedog-tier=low|high (threedog shot / gallery / capture pass high, shot --tier low checks the low tier) */
1320
1543
  tier: 'low' | 'high';
1321
1544
  /** three.js scene */
1322
1545
  scene: import('three').Scene;
1323
1546
  /**
1324
- * Default lights (neutral without sky; the sky module drives these same two). Hide or retune them for your own lighting: `engine.lights.sun.visible =
1325
- * false`
1547
+ * Placeholder lights: neutral and still, nothing moves them (the sky only gives signals). createEngine({ lights: false }) leaves them out of the scene
1326
1548
  */
1327
1549
  lights: { sun: import('three').DirectionalLight; hemi: import('three').HemisphereLight };
1328
- /** three.js perspective camera */
1550
+ /** three.js PerspectiveCamera (class EngineCamera, core/engineCamera.js): a camera rig with projection: 'orthographic' switches it to an orthographic matrix in place (orthoSize; describe().camera.projection says which) */
1329
1551
  camera: import('three').PerspectiveCamera;
1330
1552
  /**
1331
1553
  * Camera focus, updated every frame by the camera module: terrain, models etc. load around it. The center of gameplay simulation is world.anchor (the
1332
1554
  * player by default), which does not follow the camera
1333
1555
  */
1334
1556
  focus: Vector3;
1335
- /** Whether shadows are on */
1336
- shadows: boolean;
1337
- /** Shadow filter in use; change it with look.shadow.set({ type }) */
1338
- shadowType: 'basic' | 'pcf' | 'vsm';
1339
1557
  /** Current ground */
1340
1558
  ground: Ground;
1341
1559
  /**
@@ -1358,9 +1576,15 @@ export declare class Engine {
1358
1576
  * position; null when unknown. @example engine.actor = 'boat_1'; engine.actorPosition()
1359
1577
  */
1360
1578
  actorPosition(id?: string): { x: number; y: number; z: number } | null;
1361
- /** True once start() completes and the loading screen is gone (every "is it ready" in the engine is such a boolean property) */
1362
- ready: boolean;
1363
- /** True after dispose() */
1579
+ /**
1580
+ * Where the engine is in its life: 'constructed' (start() not called) -> 'loading' (start() running: frame hooks only, no fixed step, so no game
1581
+ * time passes and every machine opens at tick 0) -> 'ready' (world built: fixed steps run, engine:ready fires) -> 'running' (start() resolved)
1582
+ * -> 'disposed'. engine.step() during loading runs frame hooks only
1583
+ */
1584
+ readonly phase: 'constructed' | 'loading' | 'ready' | 'running' | 'disposed';
1585
+ /** phase is 'ready' or 'running': the world is built and the loading screen is gone (every "is it ready" in the engine is such a boolean property) */
1586
+ readonly ready: boolean;
1587
+ /** phase is 'disposed' */
1364
1588
  readonly disposed: boolean;
1365
1589
  /** Execution order of module hooks (module names, first -> last), for debugging "who runs before whom" */
1366
1590
  readonly moduleOrder: string[];
@@ -1371,8 +1595,9 @@ export declare class Engine {
1371
1595
  readonly moduleStates: Record<string, 'registered' | 'initializing' | 'running' | 'failed' | 'disposed'>;
1372
1596
  /**
1373
1597
  * What this game can do, read from the existing registrations (modules, ops, save parts, describe, params schemas).
1374
- * No argument: short list; a module id / op name: that entry expanded (null if unknown); { find }: the short list filtered. recipes/51-capability-catalog.md
1375
- * @example engine.catalog('shop').ops[0].failures // ['soldOut', 'noMoney']
1598
+ * No argument: the short list, an ARRAY of { id, kind, label, ops, saves, ... } (read .id, not Object.keys); a module id / op name: that entry
1599
+ * expanded (null if unknown); { find }: the short list filtered. recipes/51-capability-catalog.md
1600
+ * @example engine.catalog().map(s => s.id); engine.catalog('shop').ops[0].failures // ['soldOut', 'noMoney']
1376
1601
  */
1377
1602
  catalog(id?: string | { find?: string }): any;
1378
1603
  /**
@@ -1380,7 +1605,7 @@ export declare class Engine {
1380
1605
  * message }, gameplay is frozen; null when there is no error. A release build does not freeze, it reports once in the console
1381
1606
  */
1382
1607
  readonly error: EngineError | null;
1383
- /** Names of presentation modules disabled after an error (modules with presentation: true) */
1608
+ /** Names of picture / ui modules disabled after an error (a module's type decides: picture and ui fail soft) */
1384
1609
  readonly disabledModules: Set<string>;
1385
1610
  /**
1386
1611
  * The engine's cancel signal (AbortSignal): for DOM listeners write addEventListener(type, fn, { signal: engine.signal }), removed automatically on
@@ -1389,8 +1614,6 @@ export declare class Engine {
1389
1614
  readonly signal: AbortSignal;
1390
1615
  /** UI root node: UI elements of the engine and modules hang under it (don't attach to document.body directly), the whole tree is removed on dispose() */
1391
1616
  readonly uiRoot: HTMLDivElement;
1392
- /** Base fog distance (meters) */
1393
- fogFar: number;
1394
1617
  /** Installed modules: name -> module definition */
1395
1618
  modules: Map<string, ModuleDef>;
1396
1619
  /** Standalone water bodies (lakes, ponds) */
@@ -1415,8 +1638,8 @@ export declare class Engine {
1415
1638
  readonly loading: Loading;
1416
1639
  /** Post-processing: named effects in slots (add / get / enable / list) */
1417
1640
  post: PostFX;
1418
- /** Every look in one place: engine.look.<part>.set / patch / replace (recipes/52-look.md) */
1419
- look: Look;
1641
+ /** Occlusion culling of the engine's big things (hlod cells, batched groups) on both renderers. Off by default; it pays only when heavy things hide behind others (recipe 34) */
1642
+ occlusion: Occlusion;
1420
1643
  /** UI parts: every piece of screen UI is replaceable or off (see recipes/26-ui-parts.md) */
1421
1644
  ui: UIParts;
1422
1645
  /** Automatic resolution state */
@@ -1428,7 +1651,7 @@ export declare class Engine {
1428
1651
  cpuMs: number;
1429
1652
  /** cpuMs split by phase (last frame): fixed = input + fixed steps, frame = frame hooks incl. stream / jobs, render = draw submission, afterRender = its hooks */
1430
1653
  cpuPhases: { fixed: number; frame: number; render: number; afterRender: number };
1431
- /** The camera holder in charge (latest engine.takeCamera claim), null when nobody holds it. Assigning { owner } / null is the old alias of takeCamera */
1654
+ /** The camera holder in charge (latest engine.takeCamera claim), null when nobody holds it. Read-only */
1432
1655
  cameraOverride: CameraOverride | null;
1433
1656
  /** Take the camera over (camera modules leave it alone) until remove(); the latest holder is in charge, releasing hands it back to the previous one */
1434
1657
  takeCamera(owner: string | ({ owner: string } & Partial<CameraOverride>), opts?: Partial<CameraOverride>): OwnerHandle;
@@ -1436,12 +1659,50 @@ export declare class Engine {
1436
1659
  readonly runState: RunState;
1437
1660
  /** Draco/KTX2 decoder directory */
1438
1661
  decoders: string;
1439
- /** Game clock: game seconds now, after / every (clock-time / season timers are on engine.sky) */
1662
+ /** Calendar clock: calendar seconds now, after / every, the rate (clock-time / season timers are on engine.calendar) */
1440
1663
  clock: Clock;
1664
+ /**
1665
+ * The one way several systems change a shared quantity: an entry per owner, combined by layer, ended by its handle; nothing remembers an old value.
1666
+ * @example engine.time.channel('enemies'); engine.mod('time.enemies', { owner: 'bullet-time', mul: 0.35, for: 2 }) // bullet time on a channel the game made
1667
+ * @example engine.mod('time.player', { owner: 'haste', mul: 1.2, for: 5 }) // haste on the player
1668
+ * @example engine.mod('freeze', { owner: 'pause-menu' }) // pause menu (same as engine.freeze('pause-menu'))
1669
+ */
1670
+ mod(name: string, opts: import('./gameplay').ModOptions): import('./gameplay').ModHandle;
1671
+ /** Every shared quantity by name; define your own with engine.stacks.define(name, { base }) */
1672
+ stacks: import('./gameplay').Stacks;
1673
+ /**
1674
+ * Who decides where each character goes: one holder in charge per character, layers base < script < cutscene < net; a higher one pauses the
1675
+ * lower until it ends. engine.control.take(ch, { owner, layer, step }) / .of(ch). Recipe 57
1676
+ * @example const h = engine.control.take(npc, { owner: 'escort', layer: 'script', step: () => ({ x: 0, z: 1 }) }); ... h.remove();
1677
+ */
1678
+ control: Control;
1679
+ /**
1680
+ * The one way to change what a module's public method does without copying the module: fn(next, ...args) runs instead of it; call next(...args)
1681
+ * for the method (do work before, after, or skip it). Several wrappers compose (the last wrapped runs first); remove() takes one out; listed in
1682
+ * describe().wraps. Private (_) methods throw. The methods a module promises are its contract.js api.
1683
+ * @example engine.wrap(engine.inventory, 'add', (next, id, n = 1, o) => carried() + weightOf(id) * n > 30 ? false : next(id, n, o), { owner: 'weight' })
1684
+ */
1685
+ wrap<T extends object>(target: T, method: string, fn: (next: (...args: any[]) => any, ...args: any[]) => any, opts?: { owner?: string }): Handle;
1686
+ /** Time channels: read seconds with time.now('real' | 'ambient' | 'calendar' | a channel such as 'world'), speeds with scale(ch, id?) */
1687
+ time: import('./gameplay').Time;
1441
1688
  /** Story flags and counters (autosaved) */
1442
1689
  vars: Vars;
1443
1690
  /** Performance budget (off by default) */
1444
1691
  budget: Budget;
1692
+ /** The plugins folder: files in the game's plugins/ plugged at start by what they export (core/plugins.js); describe().slots lists them */
1693
+ plugins: {
1694
+ /** Plug a folder's modules yourself (the vite preset does it): import.meta.glob('./plugins/*.js', { eager: true }) */
1695
+ add(files: Record<string, any>, o?: { order?: string[]; off?: string[] }): any;
1696
+ /**
1697
+ * Unload: take everything a plugin plugged out again (file name without .js).
1698
+ * To pause a post effect in its place, engine.post.get(name).enabled = false is lighter. The result names what was switched and what stays.
1699
+ */
1700
+ off(name: string): { off: string[]; note: string };
1701
+ /** Plug a switched-off plugin again (same place in the post chain) */
1702
+ on(name: string): { on: string[]; note: string };
1703
+ /** In plug order. replacedBy: the plugin that holds it out (export const replaces) */
1704
+ list(): { name: string; file: string; on: boolean; slots: string[]; replacedBy: string | null }[];
1705
+ };
1445
1706
  /** Ray registry (what engine.raycast hits) */
1446
1707
  rays: Rays;
1447
1708
  /** Frame-spread job scheduler */
@@ -1457,28 +1718,25 @@ export declare class Engine {
1457
1718
  ops: Ops;
1458
1719
  /** Named fixed camera views for repeatable screenshots: define / show / release (recipes/46-blender-art-route.md) */
1459
1720
  views: Views;
1460
- /** Fixed-step count (the gameplay timeline: does not advance while frozen; commits due times, event history and the operation log use it) */
1721
+ /**
1722
+ * Fixed-step count (= engine.time.tick, the one time counter: does not advance while frozen; commits due times, event history and the operation
1723
+ * log use it). Seconds are views of it: engine.time.now('real' | 'ambient' | 'calendar' | channel)
1724
+ */
1461
1725
  readonly tick: number;
1462
- /** Seeded random numbers (use for gameplay randomness: reproducible and saved with the game) */
1726
+ /** Seeded random numbers, an object (not a function): engine.random.next() in [0, 1), .range(a, b), .int(a, b), .pick(list), .chance(p). Use it for gameplay randomness: reproducible and saved with the game */
1463
1727
  random: Random;
1464
1728
  /**
1465
1729
  * Spatial stream-in and the stream sources (where the world is loaded: terrain, colliders, models, stream entries; built-in player and camera sources,
1466
1730
  * add one for a teleport destination)
1467
1731
  */
1468
1732
  stream: Stream;
1469
- /** Automatic batching: the same static model placed many times in a cell is drawn as one InstancedMesh (createEngine({ batching })) */
1733
+ /** Automatic batching: the same static model the engine placed (world records, stream builds, level files) many times in a cell is drawn as one InstancedMesh; your own meshes only with userData.batch = true (createEngine({ batching })) */
1470
1734
  batching: Batching;
1471
1735
  /** Startup timing report (null until start() completes) */
1472
1736
  startup: StartupReport | null;
1473
- /**
1474
- * Run seconds: unaffected by the sky time scale, does not advance while frozen or paused; for presentation animation (swaying, floating).
1475
- * The other two "times": game seconds engine.clock.now (= fixed-step seconds x clock.timeScale, saved); sky time of day engine.sky.timeOfDay (0–1,
1476
- * one day = dayLength game seconds)
1477
- */
1478
- readonly elapsed: number;
1479
1737
  /**
1480
1738
  * This engine's shader uniforms, read by the built-in effects (wind, clouds, season, water, sky, rain). Share these objects in your
1481
- * own ShaderMaterial or patch instead of making your own uTime. Weather and sky write them; uTime follows engine.elapsed.
1739
+ * own ShaderMaterial or patch instead of making your own uTime. Weather and sky write them; uTime is engine.time.now('ambient').
1482
1740
  * @example
1483
1741
  * new THREE.ShaderMaterial({ uniforms: { uTime: engine.uniforms.uTime }, vertexShader, fragmentShader });
1484
1742
  */
@@ -1487,14 +1745,22 @@ export declare class Engine {
1487
1745
  readonly waterLevel: number;
1488
1746
 
1489
1747
  // ---------- Modules (undefined when not installed) ----------
1490
- /** Procedural terrain (terrain() module) */
1748
+ /** Procedural terrain, data part (terrain() module: chunks, heights, edits, collision) */
1491
1749
  terrain?: Terrain;
1750
+ /** Draws the terrain chunks (terrain()'s drawing module, slot 'terrain-draw'; undefined when a game replaced it) */
1751
+ terrainDraw?: TerrainDraw;
1492
1752
  /** Vegetation (vegetation() module; grows on terrain or on any ground provider) */
1493
1753
  vegetation?: Vegetation;
1494
- /** Sky, day/night, calendar (sky() module) */
1754
+ /** Draws the plants (vegetation()'s drawing module, slot 'vegetation-draw'; undefined when a game replaced it) */
1755
+ vegetationDraw?: VegetationDraw;
1756
+ /** Sky dome, sun / moon light and fog drawn from the calendar's time (sky() module) */
1495
1757
  sky?: Sky;
1496
- /** Weather (weather() module, needs sky) */
1758
+ /** Time of day, day, seasons and clock-time timers (calendar() module); NPC schedules, content clock conditions and audio time rules read it */
1759
+ calendar?: Calendar;
1760
+ /** Weather state (weather() module): the table, current values, set / setAuto, save, events */
1497
1761
  weather?: Weather;
1762
+ /** Weather drawing (installed by weather(), needs sky): rain / snow particle systems, lightning flash, the weather's effect on sun, fog and sky */
1763
+ weatherDraw?: WeatherDraw;
1498
1764
  /** Water surface (water() module) */
1499
1765
  water?: Water;
1500
1766
  /** World data (world() module): things that must be saved, survive level changes and keep changing while far away; the model is built only when nearby */
@@ -1510,25 +1776,21 @@ export declare class Engine {
1510
1776
  /** Current camera (one of followCamera / firstPersonCamera / fixedCamera / rtsCamera) */
1511
1777
  cameraRig?: CameraRig;
1512
1778
  /**
1513
- * Switch the camera at runtime (only exists with a camera module installed): the target and horizontal heading carry over; the first-person camera
1779
+ * Switch the camera at runtime between kinds, once a camera module is installed (openWorld installs followCamera; with none it throws camera-none
1780
+ * naming the module to install, e.g. engine.use(fixedCamera({ position, lookAt }))): the target and horizontal heading carry over; the first-person camera
1514
1781
  * hides the character body automatically (the shadow stays) and locks / releases the mouse; the camera switched out is kept, with its parameters, for
1515
1782
  * switching back.
1516
1783
  * Passing opts rebuilds this kind of camera with the new parameters. A wrong kind throws and lists the available options.
1517
1784
  * @example engine.onFrame(() => { if (engine.input.pressedRaw('toggleView')) engine.setCamera(engine.cameraRig.kind === 'follow' ? 'firstPerson' :
1518
1785
  * 'follow'); });
1519
1786
  */
1520
- setCamera?(kind: CameraKind, opts?: object): CameraRig;
1787
+ setCamera(kind: CameraKind, opts?: object): CameraRig;
1521
1788
  /** Cutscenes, tweens (timeline() module) */
1522
1789
  timeline?: Timeline;
1523
1790
  /** Hand-built level (level() module) */
1524
1791
  level?: Level;
1525
1792
  /** Trigger zones (triggers() module) */
1526
1793
  triggers?: Triggers;
1527
- /**
1528
- * Entities: single stateful, saved objects such as saplings, campfires and chests; the data is a record of engine.world, the model is built only when
1529
- * nearby (entities() module)
1530
- */
1531
- entities?: Entities;
1532
1794
  /** Particles (particles() module) */
1533
1795
  particles?: Particles;
1534
1796
  /** Settings menu (settings() module) */
@@ -1541,10 +1803,16 @@ export declare class Engine {
1541
1803
  npcs?: NPCManager;
1542
1804
  /** Interaction prompts (interactions() module) */
1543
1805
  interactions?: Interactions;
1544
- /** Dialogue (dialogue() module) */
1806
+ /**
1807
+ * Dialogue (dialogue() module). Ops: `dialogue.advance` (finish typing the line, else go on to the next one) and `dialogue.choose { index }` (pick
1808
+ * visible choice index, 0-based) are the only ways keys, clicks, tests and the dev bridge move a conversation on:
1809
+ * `engine.ops.run('dialogue.choose', { index: 0 })`
1810
+ */
1545
1811
  dialogue?: Dialogue;
1546
1812
  /** Inventory (inventory() module) */
1547
1813
  inventory?: Inventory;
1814
+ /** pickups() */
1815
+ pickups?: Pickups;
1548
1816
  /** Quests (quests() module) */
1549
1817
  quests?: Quests;
1550
1818
  /** Photo mode (photo() module) */
@@ -1557,6 +1825,12 @@ export declare class Engine {
1557
1825
  nav?: Nav;
1558
1826
  /** HLOD, merged distant geometry (hlod() module) @experimental */
1559
1827
  hlod?: Hlod;
1828
+ /** Shadow engineering on lights you hand in: enabled, cascades, box, budget, include (recipes/45): core, always there */
1829
+ shadows: Shadows;
1830
+ /** The camera and drawing-buffer values the engine changes on its own: manual() takes one (recipes/52): core, always there */
1831
+ view: View;
1832
+ /** Your own cloud shadow or season tint in place of the engine's (recipes/52): core, always there */
1833
+ terms: Terms;
1560
1834
  /** Light pool: many light sources, a fixed number of real lights (lightPool() module) */
1561
1835
  lightPool?: LightPool;
1562
1836
  /** Content loading (content() module) */
@@ -1567,13 +1841,21 @@ export declare class Engine {
1567
1841
  hud?: Hud;
1568
1842
 
1569
1843
  // ---------- Module system ----------
1570
- /** Install one or more modules (in order; dependencies must be installed first) */
1571
- use(...mods: ModuleInput[]): this;
1844
+ /**
1845
+ * Install one or more modules (in order; dependencies must be installed first). A last argument { replaces: 'slot' } swaps the module that holds
1846
+ * that exclusive slot: it is unloaded first (its handles, changes and dispose) and put back if the new install fails.
1847
+ * @example engine.use(myInventory(), { replaces: 'inventory' })
1848
+ */
1849
+ use(...mods: (ModuleInput | { replaces: string | string[] })[]): this;
1850
+ /**
1851
+ * Unload one installed module: its tracked handles, its slots and ctx.mod entries, its dispose. What it added some other way stays (dev reports a picture module's
1852
+ * leftovers). Throws while another module still requires it. To swap a holder use engine.use(mine(), { replaces: 'slot' }).
1853
+ * @example engine.unuse('rain');
1854
+ */
1855
+ unuse(name: string): void;
1572
1856
  /** Whether a module is installed */
1573
1857
  has(name: string): boolean;
1574
1858
 
1575
- /** Material by role from this engine's style pack: engine.makeMaterial('prop', { color: 0x8a5a36 }) */
1576
- makeMaterial(purpose?: string, params?: { color?: ColorLike, [prop: string]: any }): Material;
1577
1859
 
1578
1860
  // ---------- Ground ----------
1579
1861
  /** Set the ground (called by the terrain and level modules); missing parts fall back to flat ground */
@@ -1632,39 +1914,76 @@ export declare class Engine {
1632
1914
  detach(...objs: Object3D[]): void;
1633
1915
  /**
1634
1916
  * Fixed-step logic (60 times per second, dt in fixed seconds): movement, physics, cooldowns, and gameplay keys (read pressed() here: a per-step
1635
- * snapshot, independent of frame rate). Returns a handle { remove() }
1917
+ * snapshot, independent of frame rate). dt is real seconds (always 1/60) unless { channel } names a time channel: then the channel's scaled dt.
1918
+ * phase 'early' (default) runs before every module fixed hook (the player has not moved yet this step); 'late' after them, before the clock
1919
+ * (hit checks, reading this step's result). Returns a handle { remove() }
1920
+ * @example engine.onFixed(() => checkHits(engine.player.position), { phase: 'late' })
1636
1921
  */
1637
- onFixed(fn: (dt: number) => void): Handle;
1922
+ onFixed(fn: (dt: number) => void, opts?: { channel?: string, phase?: 'early' | 'late' }): Handle;
1638
1923
  /**
1639
1924
  * Once per frame (dt in frame seconds): animation, camera, UI and UI keys (menus read this frame's latest input). Gameplay keys belong in onFixed.
1640
1925
  * Returns a handle { remove() }
1641
1926
  */
1642
1927
  onFrame(fn: (dt: number) => void): Handle;
1928
+ /**
1929
+ * Around the main frame render, after the camera update and batching. when 'before' (default): render into your own render target here
1930
+ * (mirror, minimap, portal, picking); the render target is reset to the screen afterwards. 'after': right after the frame (read pixels).
1931
+ * The main frame render itself stays the engine's (post chain). Returns a handle { remove() }
1932
+ * @example const rt = new THREE.WebGLRenderTarget(256, 256);
1933
+ * engine.onRender(({ renderer, scene }) => { renderer.setRenderTarget(rt); renderer.render(scene, mapCam); });
1934
+ */
1935
+ onRender(fn: (ctx: { renderer: EngineRenderer; scene: import('three').Scene; camera: import('three').Camera; dt: number }) => void, opts?: { when?: 'before' | 'after' }): Handle;
1936
+
1937
+ /**
1938
+ * Draw one picture now, outside the loop, on either renderer. `renderOnce()`: the frame the player sees, onto the canvas through engine.post
1939
+ * (read the canvas in the same task, as photo mode does). `renderOnce(target)`: that frame through engine.post into a render target (the
1940
+ * canvas's pixels). `renderOnce(target, camera)` with another camera: the scene from that camera, without post. On WebGPURenderer each call is a fresh node frame, so two calls in one task give two pictures (a RenderPipeline draws its scene pass once per frame).
1941
+ * @example engine.renderOnce(); const url = engine.renderer.domElement.toDataURL('image/png');
1942
+ * engine.renderOnce(rt, mapCamera); // a minimap / thumbnail into your own render target
1943
+ */
1944
+ renderOnce(target?: import('three').RenderTarget | null, camera?: import('three').Camera): void;
1945
+
1946
+ // ---------- Light probes (render/probes.js) ----------
1947
+ /**
1948
+ * Bake a grid of light probes from the scene as it is now: three's probe grid renders a cube at every grid point and keeps spherical harmonics, and
1949
+ * every lit pixel inside the grid then takes its own interpolated light, on WebGL and WebGPU alike. The grid adds to whatever ambient light the
1950
+ * scene has (hemi, environment), which the bake also saw: lower those where the probes take over (a warning and describe().render.probes say so).
1951
+ * Outside the grid there is no probe light. A load-time cost, not per frame: 6 renders per probe, a few probes per task so the page keeps drawing;
1952
+ * ship the result with `toJSON()` + `engine.loadProbes(json)` instead of baking at every start. Adding a grid recompiles the lit materials once:
1953
+ * bake at start-up, not mid-play.
1954
+ * @example const probes = await engine.bakeProbes({ bounds: { min: [-20, 0, -20], max: [20, 6, 20] }, spacing: 4, include: o => !o.userData.moving });
1955
+ * saveFile('probes.json', JSON.stringify(probes.toJSON()));
1956
+ */
1957
+ bakeProbes(opts: { bounds: import('three').Box3 | { min: PositionLike; max: PositionLike }; spacing: number; resolution?: number;
1958
+ include?: (o: Object3D) => boolean; owner?: string }): Promise<ProbeSet>;
1959
+ /**
1960
+ * A probe set from a file made by `handle.toJSON()` (no baking), on either renderer whichever one baked it. A wrong shape is refused with code `probes-data` and nothing is added.
1961
+ * @example const probes = engine.loadProbes(await (await fetch('probes.json')).json());
1962
+ */
1963
+ loadProbes(json: ProbeData, opts?: { owner?: string }): ProbeSet;
1964
+ /**
1965
+ * Put a baked lightmap on the scene: `threedog bake light` wrote the file from the meshes the game marked `userData.static = true`; this rebuilds each with
1966
+ * its second UV set and sets plain `material.lightMap`, on WebGL and WebGPU alike. Call it once the level is built, with its lights as they will be
1967
+ * played. Nothing runs per frame. Keep the sun real-time; the ambient light the bake saw (hemisphere, environment) has to go, or it counts twice.
1968
+ * A wrong file is refused with code `lightmap-data` and nothing is changed. `material.lightMapIntensity` is yours. describe().render.lightmap says what
1969
+ * was skipped, moved or doubled.
1970
+ * @example const light = await engine.loadLightmap('light/level.lightmap');
1971
+ */
1972
+ loadLightmap(file: string | ArrayBuffer, opts?: { owner?: string }): Promise<Lightmap>;
1643
1973
 
1644
1974
  // ---------- Settings ----------
1645
1975
  /** Render resolution */
1646
1976
  setPixelRatio(p: number): void;
1647
- /** Shadow toggle */
1648
- setShadows(on: boolean): void;
1649
- /** Fog distance (meters), also adjusts the camera far plane */
1650
- setFogFar(d: number): void;
1651
- /** Exposure per frame from style.exposure / look.tone keyframes or function, null for a plain number; the sky module calls it with engine.sky @readonly */
1652
- exposureDriver: ((sky: any) => number) | null;
1653
1977
 
1654
1978
  // ---------- Rays, scenarios ----------
1655
1979
  /** Ray: shoot from origin along dir, returns the nearest hit or null (by default only registered static objects are hit) */
1656
1980
  raycast(origin: Vec3Like, dir: Vec3Like, opts?: RaycastOptions): RayHit | null;
1657
1981
  /** Shoot a ray through the camera from screen coordinates (-1..1, e.g. input.pointer.ndcX/ndcY) */
1658
1982
  pick(ndcX: number, ndcY: number, opts?: RaycastOptions): RayHit | null;
1659
- /**
1660
- * New runtime instance of a content template (inside an op or fixed step), saved whole; returns the world record (kind = template name). Needs content().
1661
- * e.g. engine.spawn('chest', { x: 10, z: 4 }, { opened: true })
1662
- */
1663
- spawn(name: string, at: any, fields?: { id?: string; rot?: number; scale?: number; y?: number; items?: Record<string, number>; [stateField: string]: any }): import('./generated/modules/world/World').WorldRecord;
1664
1983
  /** Set up a scenario: time of day, weather, player position, load a save, advance time, skip cutscenes; emits state:applied when done */
1665
1984
  applyState(params: StateParams): Promise<void>;
1666
- /** Name a group of scenario parameters, then use applyState({ state: name }) or URL ?state=name */
1667
- defineState(name: string, params: StateParams): this;
1985
+ /** Name a group of scenario parameters, then use applyState({ state: name }) or URL ?state=name. Returns a handle: remove() forgets the name */
1986
+ defineState(name: string, params: StateParams, opts?: { owner?: string }): { owner?: string; remove(): void };
1668
1987
  /**
1669
1988
  * Scenario is ready: start() completed, and the URL parameters / the latest applyState have all been applied. Tests and screenshots wait for it:
1670
1989
  * page.waitForFunction(() => window.engine?.stateApplied)
@@ -1686,26 +2005,22 @@ export declare class Engine {
1686
2005
  * Pause the real-time loop: the picture stops and even rendering stops, only step() advances (for tests and screenshots). Use freeze() for a game menu
1687
2006
  * pause
1688
2007
  */
1689
- pause(owner?: string | { owner?: string; kind?: 'test' }, opts?: { kind?: 'test' }): ChainedHandle;
1690
- /** Resume the real-time loop (only this owner's pause) */
1691
- resume(owner?: string | { owner?: string }): this;
2008
+ pause(owner?: string | { owner?: string; kind?: 'test' }, opts?: { kind?: 'test' }): OwnerHandle; // end it with the handle's remove()
1692
2009
  /** Run fn at the start of the next fixed step (via commits); a Promise of fn's value */
1693
2010
  nextFixed<T>(fn: () => T): Promise<T>;
1694
2011
  /**
1695
- * Gameplay pause (menu, flow's paused): fixed steps are skipped entirely (onFixed, module fixed, the game clock and engine.elapsed all stop), frame
2012
+ * Gameplay pause (menu, flow's paused): fixed steps are skipped entirely (onFixed, module fixed, tick and every time view but ambient stop), frame
1696
2013
  * hooks and rendering continue and the UI works.
1697
2014
  * So gameplay logic (movement, timing, quest checks, cutscene waits) belongs in fixed, or check engine.frozen first in frame. owner is the freezer's
1698
- * name, default 'game'
2015
+ * name, default 'game'. uniforms.uTime (wind, water, clouds) keeps moving while frozen; { ambient: true } stops it too
1699
2016
  */
1700
- freeze(owner?: string | { owner?: string; kind?: 'title' }, opts?: { kind?: 'title' }): ChainedHandle;
1701
- /** Release the freeze of owner (gameplay resumes only when all freezers are released) */
1702
- unfreeze(owner?: string | { owner?: string }): this;
2017
+ freeze(owner?: string | { owner?: string; kind?: 'title'; ambient?: boolean }, opts?: { kind?: 'title'; ambient?: boolean }): OwnerHandle;
1703
2018
  /** Is anyone freezing gameplay? */
1704
2019
  readonly frozen: boolean;
1705
2020
  /**
1706
2021
  * Advance seconds of fixed-step time synchronously; seconds must be a finite number >= 0: 0 advances nothing (no step, no render),
1707
- * negative or non-finite throws (code step-seconds), any positive value runs at least one fixed step (60Hz; when timeScale is not 1,
1708
- * game seconds clock.now and sky time of day run faster or slower than it;
2022
+ * negative or non-finite throws (code step-seconds), any positive value runs at least one fixed step (60Hz; time channels and
2023
+ * the calendar clock.now / sky time of day run at their own speeds;
1709
2024
  * frame hooks run once every frameEvery fixed steps, default 2; describe: false returns null instead of building describe()).
1710
2025
  * jobs ignore real time and finish every frame; results of stream's synchronous build are attached to the scene before returning. When render is true
1711
2026
  * (default) one frame is rendered at the end. Returns the describe() result after advancing
@@ -1715,7 +2030,7 @@ export declare class Engine {
1715
2030
  * Skip game time forward (sleep until morning, wait an hour) without stepping every fixed step.
1716
2031
  * clock.after / every, sky.at / daily / between, day:start and season:change fire in time order as if stepped (each crossing once);
1717
2032
  * world records with far catch up the span in one far(rec, dt). onFixed, module fixed hooks, physics and near simulation do not run;
1718
- * engine.elapsed does not move. Input is locked and gameplay frozen during the skip; emits time:skip.
2033
+ * every time view (tick, real, ambient, channels, calendar) moves as if stepped. Input is locked and gameplay frozen during the skip; emits time:skip.
1719
2034
  * fade 0 (default): the time has moved when skip returns. fade > 0: fade out, jump, save, fade in; the Promise resolves after the fade in (it needs frames).
1720
2035
  * session.newGame / load / quit cancel a running skip: it resolves null.
1721
2036
  * @example await engine.skip({ to: '06:00' })
@@ -1729,7 +2044,7 @@ export declare class Engine {
1729
2044
  * @returns a = after skip, b = after stepping
1730
2045
  * @example const r = await engine.checkSkip(600); if (!r.ok) console.log(r.diffs);
1731
2046
  */
1732
- checkSkip(seconds: number, opts?: { ignore?: string[] }): Promise<{ ok: boolean; diffs: { path: string; a: any; b: any }[] }>;
2047
+ checkSkip(seconds: number, opts?: { ignore?: string[] }): Promise<{ ok: boolean; code?: 'frozen' | 'rate0'; diffs: { path: string; a: any; b: any }[] }>;
1733
2048
  /**
1734
2049
  * Consistency check: save -> load gives the same saved state back (nothing is written to the browser).
1735
2050
  * @example const r = await engine.checkSave(); if (!r.ok) console.log(r.diffs);
@@ -1737,28 +2052,30 @@ export declare class Engine {
1737
2052
  checkSave(opts?: { ignore?: string[] }): Promise<{ ok: boolean; diffs: { path: string; a: any; b: any }[] }>;
1738
2053
  /**
1739
2054
  * Call engine.describe(opts?: { radius?: number }) to get the current game state (a plain object, JSON.stringify-able); radius is how far counts as
1740
- * "nearby" (meters, default 30).
2055
+ * "nearby" (meters, default 30). describe('picture') or describe({ only: ['picture', 'shared'] }) returns just those top-level sections (the whole object
2056
+ * is tens of KB on a big world); an unknown name comes back in unknownSections next to the list of sections.
1741
2057
  * engine.describe.add(name, fn) registers the game's own state in one line: the return value of fn(engine, ctx) goes into describe().<name>, and the
1742
2058
  * returned handle's remove() cancels it.
1743
2059
  * Small games use add; big games write the system as a module and use the module's describe hook. Example: engine.describe.add('range', () => ({
1744
2060
  * score, targets: targets.length }))
1745
2061
  */
1746
2062
  describe: {
1747
- (opts?: { radius?: number; center?: { x: number; z: number } }): GameState;
2063
+ (opts?: { radius?: number; center?: { x: number; z: number }; only?: string[] }): GameState;
2064
+ (section: string | string[]): Partial<GameState> & { unknownSections?: string[]; sections?: string[] };
1748
2065
  add(name: string, fn: (e: Engine, ctx: DescribeContext) => any): { remove(): void };
1749
2066
  };
1750
2067
  /**
1751
- * The same information as English text, summary first: at most 30 lines (standard lines, the 5 nearest things, one line per module with its key
1752
- * counts), ending with how to expand.
2068
+ * The same information as English text, summary first: at most 30 lines (standard lines, the 5 nearest things, the game's describe.add sections,
2069
+ * one line per module with its key counts, the engine tables such as shared / slots / owned as one count line), ending with how to expand.
1753
2070
  * { path: 'world.byKind' } returns one part of describe() as JSON; { full: true } returns everything (all nearby things, every module's full data).
1754
2071
  * @example engine.describeText() engine.describeText({ path: 'quests' }) engine.describeText({ full: true })
1755
2072
  */
1756
2073
  describeText(opts?: { radius?: number; full?: boolean; path?: string }): string;
1757
2074
  /**
1758
2075
  * What is around an actor or a spot, and what that actor can do now (each op offer checked with can, possible first, at most 8; failed ones carry
1759
- * reason and the op's reasons note).
2076
+ * code and the op's reasons note).
1760
2077
  * at: a world record id (that actor), [x, z] / { x, z } (a spot, ops as the player), or nothing (the player). radius default 10 m.
1761
- * @example engine.inspect(); // { actor: 'player', at: { x, z }, near: [...], ops: [{ op: 'shop.buy', args, ok: false, reason: 'noMoney',
2078
+ * @example engine.inspect(); // { actor: 'player', at: { x, z }, near: [...], ops: [{ op: 'shop.buy', args, ok: false, code: 'noMoney',
1762
2079
  * why: 'Not enough gold' }] }
1763
2080
  * @example engine.inspect('enemy_3'); // why is this enemy not attacking: its ops and their reasons
1764
2081
  * @example engine.inspect('chest-home').thing.definedAt // 'content/props.js:14': edit that line to change the level for good
@@ -1767,7 +2084,7 @@ export declare class Engine {
1767
2084
  inspect: {
1768
2085
  (at?: string | { x: number; z: number } | number[], opts?: { radius?: number }): {
1769
2086
  actor: string; at: { x: number; z: number }; near: any[]; thing?: HitThing;
1770
- ops: { op: string; args: any; ok: boolean; reason?: string; why?: string | null }[];
2087
+ ops: { op: string; args: any; ok: boolean; code?: string; why?: string | null; facts?: any; nextActions?: any[] }[];
1771
2088
  };
1772
2089
  /**
1773
2090
  * The mesh exists but is not drawn: use this first. Lists every Mesh / Points / Line / Sprite in the scene (name, type, world position, bounding radius,
@@ -1779,6 +2096,25 @@ export declare class Engine {
1779
2096
  * @example engine.inspect.scene().text
1780
2097
  */
1781
2098
  scene(opts?: { hidden?: boolean; limit?: number }): SceneInspect;
2099
+ /**
2100
+ * Every material in the scene with its textures (slot, size, color space, estimated GPU bytes, how many materials share it), who made it
2101
+ * (engine / game), its shader patches and their slots, and how many meshes share it. issues lists wrong color spaces first (a color map that is not
2102
+ * sRGB renders washed out; a normal / roughness map marked sRGB bends its data). Computed on call. Plain three.js: scene.traverse + texture.colorSpace.
2103
+ * @example engine.inspect.materials().issues // ['material "rock" (mesh "cliff"): normalMap "rock_n" holds data but is marked sRGB ...']
2104
+ */
2105
+ materials(opts?: { limit?: number }): { count: number; textures: number; textureBytes: number; issues: string[]; text: string;
2106
+ materials: { name: string | null; type: string; uuid: string; madeBy: 'engine' | 'game'; role: string | null; sharedBy: number; firstMesh: string | null;
2107
+ patches: { name: string; slots: string[] }[];
2108
+ textures: { slot: string; name: string | null; size: string; colorSpace: string; bytes: number; sharedBy: number; issue?: string }[] }[] };
2109
+ /**
2110
+ * The last frame's cost against budgets, each with the next call when over: draw calls, triangles, shader programs, texture memory (estimate),
2111
+ * JS ms per frame (cpuPhases), compile stalls during play (frames where three.js compiled new programs; startup compile ms), the costliest programs.
2112
+ * Budgets are the game's engine.budget limits, else a reference (desktop 60 fps; not enforced). Plain three.js: renderer.info.
2113
+ * @example engine.inspect.perf().text
2114
+ */
2115
+ perf(opts?: { top?: number }): { drawCalls: number; triangles: number; programs: number; textureMB: number; cpuMs: number; compileMs: number; ok: boolean; text: string;
2116
+ budgets: { name: string; value: number; budget: number; from: 'engine.budget' | 'reference'; ok: boolean; next?: string }[];
2117
+ compiles: { at: number; programs: number; ms: number }[]; [k: string]: any };
1782
2118
  };
1783
2119
  /**
1784
2120
  * Why something is the way it is. { op, args?, actor? }: text says whether it can run now, and if not the reason and the op's note on fixing it
@@ -1791,7 +2127,7 @@ export declare class Engine {
1791
2127
  * thing has the rest).
1792
2128
  */
1793
2129
  explain(q: { op: string; args?: any; actor?: string } | Record<string, any>): {
1794
- ok: boolean; reason?: string | null; text: string; detail?: string; recent?: any[]; events?: string[]; thing?: HitThing;
2130
+ ok: boolean; code?: string | null; text: string; detail?: string; recent?: any[]; events?: string[]; thing?: HitThing;
1795
2131
  };
1796
2132
  /**
1797
2133
  * Module hook timing: pass true to turn on, false to turn off (returns the engine); with no argument returns { moduleName: average milliseconds per
@@ -1802,9 +2138,11 @@ export declare class Engine {
1802
2138
  /**
1803
2139
  * Destroy the engine: stop the main loop, call each module's dispose(e) in reverse install order, then reclaim listeners, timers, audio, UI and GPU
1804
2140
  * memory (scene, assets cache, post-processing, renderer).
1805
- * After that no callbacks fire and step() returns null. Safe to call repeatedly. Don't use it for level changes; use level.track(handle)
2141
+ * After that no callbacks fire and step() returns null. Safe to call repeatedly. Don't use it for level changes; use level.track(handle).
2142
+ * The engine's own renderer gives its WebGL context back (browsers keep about 16 live ones), so that canvas cannot host a new engine; keepContext: true
2143
+ * keeps it. A renderer passed to createEngine({ renderer }) is never released.
1806
2144
  */
1807
- dispose(): void;
2145
+ dispose(opts?: { keepContext?: boolean }): void;
1808
2146
  /**
1809
2147
  * Counts for leak hunting: they should not keep growing after repeatedly entering / leaving levels or opening / closing windows. geometries / textures
1810
2148
  * come from three.js renderer.info.memory (counted only after rendering)
@@ -1812,7 +2150,6 @@ export declare class Engine {
1812
2150
  counts(): EngineCounts;
1813
2151
  }
1814
2152
 
1815
- /** Result of engine.counts() */
1816
2153
  /** engine.error and the engine:error event: where and why, plus a stable code, the fix and the pages to read (from the error or the hint table) */
1817
2154
  export interface EngineError {
1818
2155
  /** Where it happened, e.g. "fixed hook of module quests" or "load() of save part 'inventory'" */
@@ -1823,10 +2160,13 @@ export interface EngineError {
1823
2160
  code: string | null;
1824
2161
  /** What to do about it; null when unknown */
1825
2162
  fix: string | null;
2163
+ /** The first frame of the stack ("at onFixed (main.js:91:12)"): which line threw; null when the error has no stack */
2164
+ at: string | null;
1826
2165
  /** Doc pages to read, relative to the package docs */
1827
2166
  docs: string[];
1828
2167
  }
1829
2168
 
2169
+ /** Result of engine.counts() */
1830
2170
  export interface EngineCounts {
1831
2171
  /** Number of event listeners */
1832
2172
  listeners: number;
@@ -1855,7 +2195,7 @@ export interface EngineCounts {
1855
2195
  /** Only with particles() installed: alive is the number of live particles, emitters the number of attached emitters */
1856
2196
  particles?: { alive: number; emitters: number };
1857
2197
  /** Only with sky() installed: timers is the number of at / between / daily / onSeason timers */
1858
- sky?: { timers: number };
2198
+ calendar?: { timers: number };
1859
2199
  /** Any other module's counts(e) hook result, under the module name */
1860
2200
  [module: string]: any;
1861
2201
  }
@@ -1882,44 +2222,66 @@ export interface GameState {
1882
2222
  ready: boolean;
1883
2223
  /** Gameplay error in development / testing (gameplay is frozen), null when there is none */
1884
2224
  error: EngineError | null;
1885
- /** Presentation modules disabled after an error */
2225
+ /** picture / ui modules disabled after an error */
1886
2226
  disabledModules: string[];
1887
2227
  /** Modules that are initializing or failed ({ name: state }); absent when every module with an init is running (engine.moduleStates has all) */
1888
2228
  moduleStates?: Record<string, string>;
1889
2229
  /** What loading is waiting for, what failed, whether it blocks the start (engine.loading.view()) */
1890
2230
  loading: LoadingView;
1891
- /** elapsed is the run seconds (= engine.elapsed); with the sky module there are also clock, day, season, isDay, timeOfDay */
2231
+ /** tick / real / ambient / calendar are the time views (engine.time); with the calendar module there are also clock, day, season, isDay, timeOfDay */
1892
2232
  time: {
1893
- elapsed: number; paused: boolean; frozen: boolean; headless: boolean; clock?: string; day?: number; season?: string; isDay?: boolean;
2233
+ tick: number; real: number; ambient: number; calendar: number; paused: boolean; frozen: boolean; headless: boolean; clock?: string; day?: number; season?: string; isDay?: boolean;
1894
2234
  [key: string]: any;
1895
2235
  };
1896
- /** Player (null when there is no player), position in meters */
1897
- /** ground is the ground type, groundName its display name (i18n key ground.<type>, null if none) */
2236
+ /**
2237
+ * Everyone who holds the engine still (empty parts left out): pause / freeze / camera / debugView [{ owner, at? }], input [{ context, owner, pass }]
2238
+ * (input.push), gates { action: owners } (input.gate). Every other shared value is in `shared`
2239
+ */
2240
+ holds: { pause?: any[]; freeze?: any[]; camera?: any[]; debugView?: any[]; input?: { context: string; owner: string; pass: boolean }[];
2241
+ gates?: Record<string, string[]>; };
2242
+ /**
2243
+ * Every shared value and exclusive slot with entries, one row each ('move.speed[player]' for one record): the value, who decides it, how it
2244
+ * combined, and everyone else who wants it (hidden: a set above hides theirs).
2245
+ * @example engine.describe().shared['fog.far'] // { value: 72, writer: 'cave', layer: 'game', how: 'cave 180 × storm 0.4', also: [{ owner: 'storm', layer: 'effect', op: 'mul', value: 0.4 }] }
2246
+ */
2247
+ shared: Record<string, import('./gameplay').SharedRow>;
2248
+ /**
2249
+ * Player (null when there is no player), position in meters; ground is the ground type, groundName its display name
2250
+ * (i18n key ground.<type>, null if none)
2251
+ */
1898
2252
  player: {
1899
- x: number; y: number; z: number; ground: string; groundName: string | null; inWater: boolean; state: string | null;
1900
- running: boolean; jumping: boolean; [key: string]: any;
2253
+ x: number; y: number; z: number; ground: string; groundName: string | null; inWater: boolean;
2254
+ /** The character module's state name as it gives it ('idle', 'walk', 'run', 'jump'...): compare it yourself (state === 'run') */
2255
+ state: string | null; [key: string]: any;
1901
2256
  } | null;
1902
2257
  /** Camera: type 'follow' | 'first' | 'fixed' | 'rts', override is the takeover owner's name */
1903
- camera: { type: string | null; x: number; y: number; z: number; focus: { x: number; z: number }; override: string | null; [key: string]: any };
2258
+ camera: { type: string | null; /** a camera rig may switch engine.camera (an EngineCamera) to orthographic */ projection: 'perspective' | 'orthographic'; orthoSize?: number; x: number; y: number; z: number; focus: { x: number; z: number }; override: string | null; [key: string]: any };
1904
2259
  /** How far counts as nearby (meters) */
1905
2260
  nearbyRadius: number;
1906
2261
  /** Nearby things, sorted by distance (at most 15) */
1907
2262
  nearby: NearbyThing[];
1908
- /** UI: open windows, whether input is locked, the dialogue in progress */
1909
- /** windows: open windows and full-screen UI parts (e.g. 'title'); parts: each UI part 'default' | 'custom' | 'off' */
2263
+ /**
2264
+ * UI: open windows, whether input is locked, the dialogue in progress. windows: open windows and full-screen UI parts (e.g. 'title');
2265
+ * parts: each UI part 'default' | 'custom' | 'off'
2266
+ */
1910
2267
  ui: {
1911
2268
  windows: string[]; inputLocked: boolean; parts: Record<string, string>; [key: string]: any;
1912
2269
  dialogue: { speaker: string; text: string; choices: string[]; [key: string]: any } | null;
1913
2270
  };
1914
2271
  /** Cutscenes: count is how many are playing, skippable whether they can be skipped */
1915
2272
  cutscene: { count: number; skippable: boolean; [key: string]: any } | null;
1916
- /** Installed module names */
1917
- modules: string[];
2273
+ /** Installed modules in install order: name, type, and the capabilities it provides / requires when it has any */
2274
+ modules: { name: string; type: ModuleType; provides?: string[]; requires?: string[] }[];
2275
+ /** What is plugged in where: plugins/ files, scene.add roots, addPass passes, modules, plain lights (core/plugins.js) */
2276
+ slots: { slot: 'scene' | 'post' | 'module' | 'light'; plugged: string; file: string; on: boolean; affects: string[] }[];
1918
2277
  /**
1919
2278
  * engine.add / world things by save tier (counts only) and what will not survive a load: unsaved ('obj#3 (main.js:88, made during play by op x)'),
1920
2279
  * conflicts (two systems managing one object), orphans (saved ids no object has); atCapped when dev stopped taking stacks
1921
2280
  */
1922
- scene: { game: number; code: number; session: number; world: number; engine: number; unsaved: string[]; conflicts: string[]; orphans: string[]; atCapped?: boolean };
2281
+ scene: { game: number; code: number; session: number; world: number; engine: number; unsaved: string[]; conflicts: string[]; orphans: string[]; atCapped?: boolean; overrides?: { owner: string; target: string; [field: string]: any }[] };
2282
+ /** Which renderer was asked for, which backend draws and why not WebGPU; then what that backend can run: the GPU's name, whether TSL node materials and GLSL
2283
+ * (ShaderMaterial, onBeforeCompile) draw, and how renderer.compute() runs ('transform-feedback': no storage textures, atomics or workgroup memory). Null before start() */
2284
+ renderer: { requested: 'webgl' | 'webgpu'; backend: 'webgl' | 'webgpu' | 'webgl2' | null; reason: string | null; gpu: string | null; tsl: boolean | null; glsl: boolean | null; compute: 'compute-shaders' | 'transform-feedback' | null };
1923
2285
  /** Performance (fps/cpuMs are null while paused) */
1924
2286
  perf: {
1925
2287
  fps: number | null; cpuMs: number | null; drawCalls: number; triangles: number; pixelRatio: number;
@@ -1935,10 +2297,16 @@ export interface GameState {
1935
2297
  /** Number of unfinished frame-spread jobs */
1936
2298
  jobs?: number; [key: string]: any };
1937
2299
  /**
1938
- * Weather module additions: name (label is the display name), rain, snow, fog intensity 0–1, progress is the transition progress 0–1, rainVisible /
1939
- * snowVisible whether raindrops / snowflakes are drawn right now (object names weather-rain / weather-snow)
2300
+ * Weather state: name (label is the display name), rain, snow, fog intensity 0–1, progress is the transition progress 0–1
1940
2301
  */
1941
2302
  weather?: any;
2303
+ /** Weather drawing: rainVisible / snowVisible whether raindrops / snowflakes are drawn right now (object names weather-rain / weather-snow), flash 0–1 */
2304
+ weatherDraw?: { rainVisible: boolean; snowVisible: boolean; flash: number };
2305
+ /**
2306
+ * Every value the engine writes on its own (shadow box center, background, camera.far, pixel ratio, camera ...) and who writes it now (writer): 'engine',
2307
+ * 'manual:<who>' (engine.view.manual(key), or the entry that hands the value to the game) or 'three (engine yielded)' (the game wrote it directly). manual = the takeover call
2308
+ */
2309
+ owned?: Record<string, { part: string; key: string; writer: string; manual?: string }>;
1942
2310
  /** Content added by other modules */
1943
2311
  [module: string]: any;
1944
2312
  }
@@ -1956,7 +2324,7 @@ export interface DescribeContext {
1956
2324
 
1957
2325
  /** engine.skip options: pass to or seconds */
1958
2326
  export interface SkipOptions {
1959
- /** Until the sky clock next reads this time ('HH:MM' or 0-1; needs sky). The current time itself means a full day */
2327
+ /** Until the calendar clock next reads this time ('HH:MM' or 0-1; needs calendar). The current time itself means a full day */
1960
2328
  to?: string | number;
1961
2329
  /** Game seconds to skip (> 0) */
1962
2330
  seconds?: number;
@@ -1965,3 +2333,46 @@ export interface SkipOptions {
1965
2333
  /** Save slot written after the jump, before the fade in (true = 'auto') */
1966
2334
  save?: string | boolean;
1967
2335
  }
2336
+
2337
+ /** A loaded lightmap (engine.loadLightmap); describe().render.lightmap is its report */
2338
+ export interface Lightmap extends Handle {
2339
+ /** the map: a plain half-float DataTexture on uv1, set as material.lightMap */
2340
+ texture: import('three').DataTexture;
2341
+ /** file side length in pixels */
2342
+ size: number;
2343
+ /** meshes the bake left out, with why (instanced, skinned) */
2344
+ skipped: { name: string; why: string }[];
2345
+ /** baked meshes not found in the scene, or changed since the bake */
2346
+ missing: string[];
2347
+ /** takes the map off the meshes and frees it; the unwrapped geometry stays */
2348
+ remove(): void;
2349
+ }
2350
+ /** A probe file: what ProbeSet.toJSON() returns and engine.loadProbes reads (half: count x 27 half floats, base64; x fastest, then y, then z) */
2351
+ export interface ProbeData { format: 'threedog-probes'; version: 2; origin: [number, number, number]; step: [number, number, number]; counts: [number, number, number]; half: string }
2352
+ /** A baked or loaded grid of SH light probes (engine.bakeProbes / loadProbes); describe().render.probes lists the live ones */
2353
+ export interface ProbeSet extends Handle {
2354
+ /** number of probes */
2355
+ count: number;
2356
+ /** probes per axis [x, y, z] (at least 2 each) */
2357
+ counts: [number, number, number];
2358
+ /** the actual distance between neighbours per axis (<= spacing, so the probes end on the bounds) */
2359
+ step: [number, number, number];
2360
+ /** three's probe grid, a plain light in the scene: priority, visible and (WebGPU only: three's WebGL shader ignores it) intensity are yours */
2361
+ grid: import('three').Light & { isLightProbeGrid: true; priority: number; texture: import('three').Data3DTexture | null };
2362
+ /** the world box the grid lights: the probes plus half a step on every side */
2363
+ box: import('three').Box3;
2364
+ /** the probes' SH, 27 numbers each (half precision values) */
2365
+ sh: Float32Array;
2366
+ /** bake time in ms (null for a loaded set) */
2367
+ bakeMs: number | null;
2368
+ /** 'bake' | 'file' */
2369
+ source: string;
2370
+ /** the interpolated SH at a position (trilinear; outside the grid the nearest edge), written into target (a SphericalHarmonics3 or a LightProbe's sh) */
2371
+ sample(pos: PositionLike, target?: import('three').SphericalHarmonics3 | import('three').LightProbe): import('three').SphericalHarmonics3;
2372
+ /** world position of probe i */
2373
+ point(i: number, out?: Vector3): Vector3;
2374
+ /** plain data for a file: engine.loadProbes(json) makes the same set */
2375
+ toJSON(): ProbeData;
2376
+ /** takes the grid out of the scene and frees its texture; sample / toJSON still work */
2377
+ remove(): void;
2378
+ }