threedog 1.0.1 → 1.2.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 (364) hide show
  1. package/CHANGELOG.md +90 -0
  2. package/README.md +1 -1
  3. package/core/assets/Animator.js +41 -3
  4. package/core/assets/Assets.js +100 -24
  5. package/core/assets/assetEntry.js +73 -20
  6. package/core/assets/assetHot.js +68 -16
  7. package/core/assets/assetLoad.js +6 -6
  8. package/core/assets/assetLod.js +9 -2
  9. package/core/assets/assetManifest.js +12 -2
  10. package/core/assets/assetPart.js +54 -0
  11. package/core/assets/ik.js +271 -0
  12. package/core/assets/modelNeeds.js +37 -0
  13. package/core/assets/namedModel.js +102 -29
  14. package/core/assets/nodeVisibility.js +15 -0
  15. package/core/audio/Audio.js +36 -4
  16. package/core/audio/audioReverb.js +99 -0
  17. package/core/audio/audioRules.js +1 -1
  18. package/core/audio/audioVoice.js +1 -1
  19. package/core/base/Events.js +14 -4
  20. package/core/base/Random.js +1 -1
  21. package/core/base/Vars.js +1 -1
  22. package/core/base/docRef.js +51 -0
  23. package/core/base/errorCodes.js +178 -126
  24. package/core/base/errorHints.js +9 -7
  25. package/core/base/errors.js +25 -10
  26. package/core/base/events.generated.js +2 -0
  27. package/core/base/freeParts.js +76 -0
  28. package/core/base/math.js +28 -0
  29. package/core/base/sections.js +5 -5
  30. package/core/base/validate.js +31 -3
  31. package/core/engine/Engine.js +16 -6
  32. package/core/engine/Loading.js +5 -3
  33. package/core/engine/copies.js +1 -1
  34. package/core/engine/headlessLoad.js +4 -1
  35. package/core/engine/lifecycle.js +32 -16
  36. package/core/engine/loop.js +71 -27
  37. package/core/engine/moduleSlots.js +2 -2
  38. package/core/engine/moduleTypes.js +3 -3
  39. package/core/engine/modules.js +65 -39
  40. package/core/engine/page.js +6 -3
  41. package/core/engine/services.js +6 -5
  42. package/core/engine/startup.js +5 -5
  43. package/core/input/Input.js +28 -14
  44. package/core/input/inputContext.js +28 -16
  45. package/core/input/inputKeyboard.js +31 -3
  46. package/core/input/inputPad.js +4 -0
  47. package/core/input/inputPointer.js +2 -1
  48. package/core/input/inputSeat.js +1 -1
  49. package/core/inspect/Budget.js +109 -19
  50. package/core/inspect/DebugOverrides.js +28 -4
  51. package/core/inspect/Describe.js +17 -9
  52. package/core/inspect/Inspect.js +4 -2
  53. package/core/inspect/InspectMaterials.js +3 -1
  54. package/core/inspect/InspectPerf.js +19 -9
  55. package/core/inspect/InspectScene.js +32 -7
  56. package/core/inspect/MaterialInfo.js +19 -2
  57. package/core/inspect/UrlState.js +46 -27
  58. package/core/inspect/catalog.js +28 -9
  59. package/core/inspect/debugView.js +2 -1
  60. package/core/inspect/describeRender.js +25 -13
  61. package/core/inspect/describeText.js +14 -6
  62. package/core/inspect/lightWatch.js +1 -1
  63. package/core/inspect/metadata.generated.js +35 -17
  64. package/core/inspect/pictureChecks.js +148 -0
  65. package/core/inspect/pictureMenu.js +84 -0
  66. package/core/inspect/pictureWriters.js +26 -6
  67. package/core/inspect/textureBytes.js +12 -2
  68. package/core/inspect/toolDoor.js +2 -4
  69. package/core/ops/Ops.js +11 -4
  70. package/core/ops/holds.js +27 -10
  71. package/core/ops/opsAtomic.js +15 -7
  72. package/core/ops/opsGuard.js +2 -2
  73. package/core/ops/opsRun.js +8 -7
  74. package/core/ops/sharedPoint.js +72 -21
  75. package/core/ops/stacks.js +56 -16
  76. package/core/saves/SaveStore.js +9 -3
  77. package/core/saves/Saves.js +32 -23
  78. package/core/saves/saveApply.js +96 -44
  79. package/core/saves/saveIds.js +1 -1
  80. package/core/saves/saveVersions.js +7 -5
  81. package/core/saves/session.js +17 -8
  82. package/core/saves/stateReplace.js +34 -15
  83. package/core/scene/Rays.js +52 -10
  84. package/core/scene/Views.js +13 -7
  85. package/core/scene/adaptive.js +144 -21
  86. package/core/scene/drawOnly.js +17 -0
  87. package/core/scene/gameLights.js +44 -3
  88. package/core/scene/sceneMethods.js +13 -11
  89. package/core/scene/stepPoses.js +11 -3
  90. package/core/scene/targeting.js +5 -3
  91. package/core/scene/thingOps.js +1 -1
  92. package/core/scene/tier.js +15 -0
  93. package/core/stream/Batching.js +30 -7
  94. package/core/stream/Stream.js +26 -7
  95. package/core/stream/batchGroups.js +2 -2
  96. package/core/stream/chunkStream.js +7 -5
  97. package/core/stream/prepare.js +77 -0
  98. package/core/time/skip.js +3 -1
  99. package/core/time/time.js +4 -2
  100. package/docs/AI.md +82 -83
  101. package/docs/API.md +16 -16
  102. package/docs/CODEMAP.md +16 -11
  103. package/docs/COMMANDS.md +31 -33
  104. package/docs/CONVENTIONS.md +37 -49
  105. package/docs/MIGRATING-0.8.md +2 -2
  106. package/docs/MIGRATING-1.0.md +2 -2
  107. package/docs/THREE.md +28 -35
  108. package/docs/api/assets.md +3 -1
  109. package/docs/api/audio.md +4 -2
  110. package/docs/api/budget.md +5 -0
  111. package/docs/api/cameraRig.md +2 -2
  112. package/docs/api/characters.md +10 -8
  113. package/docs/api/collision.md +6 -4
  114. package/docs/api/engine.md +16 -16
  115. package/docs/api/events.md +3 -2
  116. package/docs/api/ground.md +6 -5
  117. package/docs/api/hud.md +4 -2
  118. package/docs/api/input.md +5 -5
  119. package/docs/api/particles.md +2 -1
  120. package/docs/api/photo.md +3 -0
  121. package/docs/api/post.md +7 -4
  122. package/docs/api/quests.md +2 -2
  123. package/docs/api/rays.md +1 -2
  124. package/docs/api/saves.md +7 -7
  125. package/docs/api/settings.md +2 -2
  126. package/docs/api/tools.md +3 -1
  127. package/docs/api/vars.md +1 -1
  128. package/docs/api/vegetation.md +4 -2
  129. package/docs/api/world.md +1 -1
  130. package/docs/recipes/01-new-game.md +16 -17
  131. package/docs/recipes/02-npc.md +22 -18
  132. package/docs/recipes/03-items-pickups.md +37 -35
  133. package/docs/recipes/04-quests.md +15 -10
  134. package/docs/recipes/05-props-bake.md +101 -95
  135. package/docs/recipes/06-clock-events.md +28 -28
  136. package/docs/recipes/07-flow-scenes-pause.md +29 -26
  137. package/docs/recipes/08-weather-sky.md +52 -64
  138. package/docs/recipes/09-materials-lights-models.md +26 -17
  139. package/docs/recipes/10-blender-level.md +15 -10
  140. package/docs/recipes/11-vehicles.md +12 -7
  141. package/docs/recipes/12-navmesh.md +44 -26
  142. package/docs/recipes/13-animation.md +56 -45
  143. package/docs/recipes/14-custom-module.md +21 -18
  144. package/docs/recipes/15-perf.md +61 -55
  145. package/docs/recipes/16-dev-bridge.md +23 -33
  146. package/docs/recipes/18-world.md +36 -42
  147. package/docs/recipes/19-shooting-picking.md +20 -15
  148. package/docs/recipes/20-content-actions-save.md +48 -56
  149. package/docs/recipes/21-camera.md +45 -54
  150. package/docs/recipes/22-shop-gold.md +12 -7
  151. package/docs/recipes/23-ops.md +25 -23
  152. package/docs/recipes/26-ui-parts.md +67 -47
  153. package/docs/recipes/27-net.md +12 -7
  154. package/docs/recipes/28-terrain.md +24 -21
  155. package/docs/recipes/29-grid.md +32 -27
  156. package/docs/recipes/30-templates.md +21 -20
  157. package/docs/recipes/31-audio.md +39 -22
  158. package/docs/recipes/32-action-game.md +19 -14
  159. package/docs/recipes/33-stream-sources.md +15 -11
  160. package/docs/recipes/34-environment-lighting.md +126 -70
  161. package/docs/recipes/35-picture-from-reference.md +8 -8
  162. package/docs/recipes/36-ground-plants.md +27 -21
  163. package/docs/recipes/40-scene.md +19 -28
  164. package/docs/recipes/43-shader-patches-surfaces.md +15 -12
  165. package/docs/recipes/44-water-weather-hooks.md +34 -31
  166. package/docs/recipes/45-cascaded-shadows.md +35 -26
  167. package/docs/recipes/46-blender-art-route.md +6 -1
  168. package/docs/recipes/49-game-module-contract.md +13 -8
  169. package/docs/recipes/50-own-renderer.md +6 -2
  170. package/docs/recipes/51-capability-catalog.md +15 -8
  171. package/docs/recipes/52-around-the-picture.md +34 -32
  172. package/docs/recipes/53-ground-up-close.md +6 -1
  173. package/docs/recipes/55-mods-time-wrap.md +27 -19
  174. package/docs/recipes/56-webgpu-tsl.md +74 -43
  175. package/docs/recipes/57-control.md +18 -13
  176. package/docs/recipes/58-input.md +26 -16
  177. package/docs/recipes/59-depth-post-effects.md +8 -3
  178. package/docs/recipes/60-judge-the-picture.md +9 -8
  179. package/docs/recipes/61-deploy.md +5 -0
  180. package/docs/recipes/62-picture-code.md +70 -79
  181. package/docs/recipes/63-third-person-start.md +47 -45
  182. package/docs/recipes/64-particles.md +22 -10
  183. package/docs/recipes/65-swarm.md +18 -13
  184. package/docs/recipes/66-common-tasks.md +38 -35
  185. package/examples/action/GAMEMAP.md +2 -3
  186. package/examples/action/main.js +3 -3
  187. package/examples/action/picture/lights.js +3 -1
  188. package/examples/perf-island/GAMEMAP.md +3 -3
  189. package/examples/perf-island/picture/lights.js +2 -1
  190. package/examples/plain-picture/GAMEMAP.md +1 -1
  191. package/examples/rc2d/GAMEMAP.md +1 -1
  192. package/examples/styletest/GAMEMAP.md +2 -2
  193. package/examples/styletest/main.js +1 -1
  194. package/examples/techniques/interior-light/README.md +3 -3
  195. package/examples/techniques/interior-light/interiorLight.js +2 -4
  196. package/examples/techniques/interior-light/picture/lights.js +2 -1
  197. package/examples/techniques/modular-building/picture/lights.js +3 -1
  198. package/examples/techniques/outlines-and-rim/picture/lights.js +3 -1
  199. package/examples/techniques/procedural-animation/README.md +1 -1
  200. package/examples/techniques/procedural-animation/main.js +1 -1
  201. package/examples/webgpu-tsl/GAMEMAP.md +1 -1
  202. package/examples/world/GAMEMAP.md +2 -3
  203. package/examples/world/art/humanoid.js +1 -1
  204. package/examples/world/main.js +6 -3
  205. package/index.d.ts +2 -2
  206. package/llms.txt +101 -0
  207. package/modules/ambience/Ambience.js +21 -5
  208. package/modules/calendar/index.js +9 -5
  209. package/modules/calendar/schedule.js +23 -8
  210. package/modules/camera/FirstPersonCamera.js +3 -1
  211. package/modules/camera/FollowCamera.js +10 -5
  212. package/modules/camera/RtsCamera.js +4 -3
  213. package/modules/camera/common.js +70 -8
  214. package/modules/camera/contract.js +1 -1
  215. package/modules/characters/Character.js +16 -10
  216. package/modules/characters/NPC.js +31 -19
  217. package/modules/characters/assetModel.js +14 -9
  218. package/modules/characters/astar.js +6 -1
  219. package/modules/characters/contract.js +2 -2
  220. package/modules/characters/index.js +34 -22
  221. package/modules/characters/movers/manual.js +1 -1
  222. package/modules/characters/movers/rapier.js +17 -2
  223. package/modules/characters/movers/simple.js +1 -1
  224. package/modules/characters/movers/support.js +16 -7
  225. package/modules/characters/npcAvoid.js +2 -2
  226. package/modules/characters/npcSim.js +3 -2
  227. package/modules/characters/pathAsync.js +24 -8
  228. package/modules/characters/pathJob.js +1 -1
  229. package/modules/characters/player.js +10 -9
  230. package/modules/characters/playerStrings.js +5 -5
  231. package/modules/characters/proceduralRig.js +5 -5
  232. package/modules/characters/useModel.js +6 -0
  233. package/modules/characters/walkTo.js +1 -1
  234. package/modules/collision/Collision.js +29 -18
  235. package/modules/collision/grid.js +22 -4
  236. package/modules/content/index.js +3 -1
  237. package/modules/content/loader.js +1 -1
  238. package/modules/content/models.js +82 -33
  239. package/modules/content/props.js +2 -1
  240. package/modules/content/rules.js +11 -5
  241. package/modules/content/templates.js +3 -3
  242. package/modules/content/words.js +2 -2
  243. package/modules/debug/DebugPanel.js +9 -9
  244. package/modules/flow/index.js +9 -6
  245. package/modules/gameplay/Dialogue.js +34 -20
  246. package/modules/gameplay/Interactions.js +19 -15
  247. package/modules/gameplay/Inventory.js +9 -4
  248. package/modules/gameplay/Quests.js +12 -10
  249. package/modules/gameplay/pickups.js +23 -11
  250. package/modules/grid/index.js +1 -1
  251. package/modules/grid/preview.js +2 -2
  252. package/modules/grid/tiles.js +1 -1
  253. package/modules/hlod/index.js +4 -1
  254. package/modules/hud/index.js +47 -10
  255. package/modules/hud/parts.js +28 -9
  256. package/modules/level/geometry.js +8 -3
  257. package/modules/level/index.js +10 -5
  258. package/modules/level/load.js +4 -2
  259. package/modules/lights/sources.js +1 -1
  260. package/modules/music/Music.js +22 -4
  261. package/modules/nav/index.js +20 -10
  262. package/modules/particles/Particles.js +31 -14
  263. package/modules/particles/effect.js +20 -5
  264. package/modules/particles/lit.js +72 -0
  265. package/modules/photo/Photo.js +72 -28
  266. package/modules/photo/pathTrace.js +106 -0
  267. package/modules/rigid/RigidBodies.js +23 -14
  268. package/modules/rigid/Vehicles.js +3 -13
  269. package/modules/rigid/sync.js +2 -1
  270. package/modules/settings/Settings.js +52 -20
  271. package/modules/settings/apply.js +23 -9
  272. package/modules/settings/sections.js +39 -6
  273. package/modules/settings/strings.js +2 -0
  274. package/modules/settings/view.js +19 -3
  275. package/modules/sky/dome.js +15 -3
  276. package/modules/sky/environment.js +28 -12
  277. package/modules/sky/fog.js +1 -1
  278. package/modules/sky/frame.js +6 -1
  279. package/modules/sky/shader.js +4 -3
  280. package/modules/sky/skyModule.js +8 -4
  281. package/modules/swarm/Swarm.js +1 -1
  282. package/modules/terrain/ChunkManager.js +61 -15
  283. package/modules/terrain/chunkJob.js +2 -2
  284. package/modules/terrain/index.js +20 -5
  285. package/modules/terrain/terrainEdit.js +8 -4
  286. package/modules/terrain/terrainTexture.js +4 -2
  287. package/modules/timeline/Timeline.js +4 -3
  288. package/modules/timeline/Tween.js +3 -0
  289. package/modules/timeline/letterbox.js +1 -0
  290. package/modules/triggers/index.js +36 -17
  291. package/modules/vegetation/Vegetation.js +81 -19
  292. package/modules/vegetation/densityMap.js +13 -8
  293. package/modules/vegetation/draw.js +147 -24
  294. package/modules/vegetation/groundChunks.js +20 -5
  295. package/modules/vegetation/index.js +3 -3
  296. package/modules/vegetation/modelGeometry.js +9 -4
  297. package/modules/water/Water.js +11 -8
  298. package/modules/weather/Weather.js +7 -2
  299. package/modules/weather/shaders.js +25 -5
  300. package/modules/weather/weatherDraw.js +20 -6
  301. package/modules/world/World.js +2 -1
  302. package/modules/world/index.js +2 -2
  303. package/modules/world/persist.js +6 -2
  304. package/modules/world/views.js +15 -2
  305. package/package.json +4 -1
  306. package/presets.js +5 -5
  307. package/render/PostFX.js +84 -41
  308. package/render/backend.js +137 -16
  309. package/render/cascades.js +3 -1
  310. package/render/cascades.tsl.js +2 -0
  311. package/render/daylight.js +7 -1
  312. package/render/detail.js +7 -4
  313. package/render/effects.js +27 -8
  314. package/render/fogLook.js +24 -0
  315. package/render/fuse.js +5 -2
  316. package/render/fx/detail.tsl.js +9 -7
  317. package/render/fx/index.js +7 -2
  318. package/render/fx/library.tsl.js +1 -0
  319. package/render/fx/lightShaft.tsl.js +114 -0
  320. package/render/fx/noise.tsl.js +25 -8
  321. package/render/fx/objectOrigin.tsl.js +39 -10
  322. package/render/fx/particles.tsl.js +23 -6
  323. package/render/fx/patchNodes.tsl.js +17 -12
  324. package/render/fx/pcss.tsl.js +51 -0
  325. package/render/fx/postWebGPU.tsl.js +89 -29
  326. package/render/fx/sky.tsl.js +3 -9
  327. package/render/fxNumbers.js +10 -4
  328. package/render/impostor.tsl.js +107 -0
  329. package/render/lighting.js +33 -1
  330. package/render/lightmap.js +42 -28
  331. package/render/lights.js +19 -3
  332. package/render/materials.js +6 -4
  333. package/render/mergeCommon.js +4 -1
  334. package/render/occlusion.js +14 -4
  335. package/render/patches.js +79 -41
  336. package/render/postRuns.js +32 -0
  337. package/render/postWebGL.js +97 -10
  338. package/render/probes.js +10 -14
  339. package/render/shaderErrors.js +2 -1
  340. package/render/shadowCache.tsl.js +33 -5
  341. package/render/shadows.js +42 -16
  342. package/render/slots.js +8 -5
  343. package/render/vertexInputs.js +52 -0
  344. package/types/core.d.ts +114 -46
  345. package/types/gameplay.d.ts +56 -23
  346. package/types/generated/core/audio/Audio.d.ts +27 -1
  347. package/types/generated/core/base/Random.d.ts +1 -1
  348. package/types/generated/core/input/Input.d.ts +6 -8
  349. package/types/generated/core/input/inputSeat.d.ts +1 -1
  350. package/types/generated/core/inspect/Budget.d.ts +26 -0
  351. package/types/generated/core/inspect/DebugOverrides.d.ts +0 -2
  352. package/types/generated/core/saves/Saves.d.ts +10 -7
  353. package/types/generated/core/saves/session.d.ts +8 -2
  354. package/types/generated/core/scene/Rays.d.ts +1 -3
  355. package/types/generated/modules/particles/Particles.d.ts +1 -1
  356. package/types/generated/modules/world/World.d.ts +2 -1
  357. package/types/generated/render/PostFX.d.ts +35 -9
  358. package/types/physics.d.ts +43 -11
  359. package/types/pixel.d.ts +1 -1
  360. package/types/tsl.d.ts +62 -1
  361. package/types/world.d.ts +12 -3
  362. package/ui/Focus.js +7 -5
  363. package/ui/Parts.js +1 -1
  364. package/ui/touchPart.js +6 -3
@@ -42,8 +42,8 @@ export class PostFX {
42
42
  } | null;
43
43
  /**
44
44
  * The one way to add a post effect. x is a three.js Pass (WebGL), a TSL node function (input, ctx) => node (WebGPU), or an effect
45
- * { name, create | node | fuse, slot, order, params, needsDepth, needsBuffers, backend, skipOnLowTier, facts } (both renderers when it gives create and node, or a fuse). A wrong shape throws with nothing added.
46
- * needsDepth, needsBuffers ('normal' | 'diffuse' | 'velocity', WebGPU), backend ('webgpu': not on the WebGL2 backend), skipOnLowTier (held when engine.tier is 'low') and facts (shown by describe().render.post) are explained on PostEffect.
45
+ * { name, create | node | fuse, slot, order, params, needsDepth, needsBuffers, backend, skipOnLowTier, cheaper, facts } (both renderers when it gives create and node, or a fuse). A wrong shape throws with nothing added.
46
+ * needsDepth, needsBuffers ('normal' | 'diffuse' | 'velocity' | 'metalRough', WebGPU), backend ('webgpu': not on the WebGL2 backend), skipOnLowTier (held when engine.tier is 'low') and facts (shown by describe().render.post) are explained on PostEffect.
47
47
  * A Pass that draws engine.scene takes the 'scene' slot, FXAA / SMAA / TAA 'final', any other 'hdr' after the effects already there, or 'ldr' once an
48
48
  * OutputPass was added. A RenderPass of engine.scene and an OutputPass are the engine's own stages: skipped and said once (an OutputPass still marks where display color starts).
49
49
  * @example const glow = engine.post.add(new UnrealBloomPass(size, 0.6, 0.4, 0.85), { name: 'glow' }); glow.enabled = false;
@@ -61,9 +61,18 @@ export class PostFX {
61
61
  * @example engine.post.get('bloom').set({ strength: 0.6 });
62
62
  * @param {string} name
63
63
  * @returns {PostHandle | undefined}
64
- * @experimental
65
64
  */
66
65
  get(name: string): PostHandle | undefined;
66
+ /**
67
+ * The added effects that declare this role in about.acts ('glow', 'ao', 'exposure'): found by what they do, never by name; the settings rows and
68
+ * photo follow every one of them. Only when NO effect declares the role does the effect named `name` stand in (a game's own 'bloom' written before
69
+ * roles existed); with no `name` that case gives [].
70
+ * @param {string} role
71
+ * @param {string} [name] fallback effect name
72
+ * @returns {PostHandle[]}
73
+ * @experimental
74
+ */
75
+ byRole(role: string, name?: string): PostHandle[];
67
76
  /**
68
77
  * Hand the built chain to the game: the engine stops rebuilding it, so the composer's passes (post.object().passes) or the WebGPU pipeline's
69
78
  * outputNode are the game's to edit. own(false) gives it back and rebuilds from the list. describe().owned shows who has it.
@@ -76,7 +85,6 @@ export class PostFX {
76
85
  /**
77
86
  * Effects in render order: [{ name, slot, order, enabled }]
78
87
  * @returns {{ name: string, slot: PostSlot, order: number, enabled: boolean }[]}
79
- * @experimental
80
88
  */
81
89
  list(): {
82
90
  name: string;
@@ -99,8 +107,16 @@ export class PostFX {
99
107
  * ldr: sRGB color after tone mapping (LUT, palette, grain, vignette); final: last of all (FXAA / SMAA).
100
108
  */
101
109
  export type PostSlot = "scene" | "hdr" | "tone" | "ldr" | "final";
110
+ export type BorrowRenderer = (renderer: any, draw: () => any, opts?: {
111
+ scene?: import("three").Scene;
112
+ camera?: import("three").Camera;
113
+ clean?: boolean;
114
+ }) => any;
102
115
  /**
103
- * width / height are in device pixels.
116
+ * width / height are in device pixels. borrowRenderer(renderer, draw, { scene, camera, clean }): run draw() with the renderer borrowed, the engine's one
117
+ * borrow (render/backend.js): target with cube face and mip, viewport, scissor, clear color, autoClear, tone mapping, shadowMap.autoUpdate (and with scene
118
+ * / camera their overrideMaterial, background, fog, layers) are put back afterwards, also when draw throws. For an effect that draws an extra pass of
119
+ * its own; its targets and materials stay the effect's. clean (WebGPU): start from three's reset state (no MRT), for a quad drawn inside a node frame.
104
120
  */
105
121
  export type PostContext = {
106
122
  engine: Engine;
@@ -109,6 +125,7 @@ export type PostContext = {
109
125
  width: number;
110
126
  height: number;
111
127
  params: Record<string, any>;
128
+ borrowRenderer: BorrowRenderer;
112
129
  };
113
130
  /**
114
131
  * A GLSL snippet that colors the pixel; neighboring effects with a fuse run as ONE fullscreen pass. glsl is statements that edit
@@ -127,8 +144,8 @@ export type PostFuse = {
127
144
  reads?: boolean;
128
145
  };
129
146
  /**
130
- * WebGPU only. scenePass: the scene's pass() node (.getTextureNode('depth'), getViewZNode() ...; .getTextureNode('normal' | 'diffuse' | 'velocity')
131
- * when an effect that is on says so in needsBuffers); tsl: three/tsl; display: three's display nodes (bloom, ao from three/addons/tsl/display) plus
147
+ * WebGPU only. scenePass: the scene's pass() node (.getTextureNode('depth'), getViewZNode() ...); buffer(name): a needsBuffers output as a texture node
148
+ * ('normal' | 'diffuse' | 'velocity' | 'metalRough', the last as .x metalness, .y roughness: it may share velocity's target, so read it here, not from scenePass); tsl: three/tsl; display: three's display nodes (bloom, ao from three/addons/tsl/display) plus
132
149
  * pass (an extra scene render), texture (the color so far as a texture to sample at other uvs) and own (a node the effect made itself, disposed with the chain),
133
150
  * handed in so the main entry of an effect package never imports three/webgpu (its /tsl subpath may, a WebGL game never loads that) and so the nodes they make are disposed with the chain;
134
151
  * fx: the threedog/tsl functions (noise, hash ...), handed in for the same reason;
@@ -143,10 +160,12 @@ export type PostNodeContext = {
143
160
  height: number;
144
161
  params: Record<string, any>;
145
162
  scenePass: any;
163
+ buffer: (name: string) => any;
146
164
  tsl: any;
147
165
  fx: Record<string, Function>;
148
166
  display: Record<string, Function>;
149
167
  p: Record<string, any>;
168
+ borrowRenderer: BorrowRenderer;
150
169
  };
151
170
  /**
152
171
  * An effect as data, the form post.add() takes. node (WebGPURenderer): returns the effect's output color node built on input (the color node so far); called again only when a param
@@ -163,11 +182,16 @@ export type PostNodeContext = {
163
182
  * RenderPixelatedPass, or the tone-mapping output); the chain throws when it would not. A pass that writes the scene depth into its own output (gl_FragDepth, then set pass.keepsDepth = true; dof does) does not count as a swap. update: apply new params in place;
164
183
  * without it set() rebuilds the implementation.
165
184
  * needsBuffers (WebGPU): extra outputs of the one scene render, merged across every effect that is on, so two effects never overwrite each other's setMRT:
166
- * 'normal' (view space, raw), 'diffuse' (surface color), 'velocity' (a temporal resolve follows, so the scene pass runs without MSAA).
185
+ * 'normal' (view space, raw), 'diffuse' (surface color), 'velocity' (a temporal resolve follows, so the scene pass runs without MSAA), 'metalRough' (metalness, roughness).
186
+ * More targets than the device takes (WebGPU's default: 32 bytes per pixel, four with the color) throws naming the effects.
167
187
  * backend: 'webgpu' = needs three's WebGPU backend itself (storage textures; WebGPURenderer on its WebGL2 backend cannot run it, so it is held there).
168
188
  * skipOnLowTier: the effect's own statement that engine.tier 'low' is too weak for it. The rule: an effect declares this itself and the engine only follows the declaration; no list of
169
189
  * expensive effects lives in the engine, and an effect that does not declare it runs on every tier. A held effect costs nothing, describe().render.post says why in `held`, the console says it once; the game's enabled stays as written.
190
+ * cheaper: the effect's own cheaper params ({ quality: 0.25 }), the first step adaptive quality takes under load before the resolution (core/scene/adaptive.js); only
191
+ * params that change in place belong here (live uniforms, or WebGL update()): a param that rebuilds the chain would cause the hitch the step is meant to cure. A declared
192
+ * skipOnLowTier is the ladder's last step: the effect held off. Neither is a list in the engine; the game reorders or drops them with engine.adaptive.steps.
170
193
  * facts: read by describe().render.post (a voxel size, what the effect still misses).
194
+ * about: what the picture menu (engine.catalog('picture')) prints for it: { cost, on, recipe, limits, webgpuOnly?, acts? } (acts: 'glow' | 'exposure' | 'ao', what the combination checks, the settings rows and photo read in place of a name);
171
195
  */
172
196
  export type PostEffect = {
173
197
  name: string;
@@ -178,10 +202,12 @@ export type PostEffect = {
178
202
  order?: number;
179
203
  enabled?: boolean;
180
204
  needsDepth?: boolean;
181
- needsBuffers?: ("normal" | "diffuse" | "velocity")[];
205
+ needsBuffers?: ("normal" | "diffuse" | "velocity" | "metalRough")[];
182
206
  backend?: "webgpu";
183
207
  skipOnLowTier?: boolean;
208
+ cheaper?: Record<string, any>;
184
209
  facts?: () => Record<string, any> | null;
210
+ about?: Record<string, any>;
185
211
  params?: Record<string, any>;
186
212
  update?: (impl: any, params: Record<string, any>) => void;
187
213
  };
@@ -23,7 +23,7 @@ export interface CollisionOptions {
23
23
  cameraOcclusion?: 'colliders' | 'meshes' | 'both';
24
24
  }
25
25
  /** Circle collider: center x/z, radius r, height h (meters), occ false when added with occluder: false */
26
- export interface CircleCollider { x: number; z: number; r: number; h: number; occ: boolean }
26
+ export interface CircleCollider { x: number; z: number; r: number; h: number; occ: boolean; /** its layer option */ ly?: string }
27
27
  /** Box collider: center x/z, half width hw, half depth hd, rotation around Y rot (radians), height h, bottom height y (meters), occ as in CircleCollider */
28
28
  export interface BoxCollider { x: number; z: number; hw: number; hd: number; rot: number; h: number; y?: number; occ: boolean; [k: string]: any }
29
29
 
@@ -35,6 +35,8 @@ export interface CircleColliderOptions {
35
35
  height?: number;
36
36
  /** false: walkers are still stopped but the follow camera's occlusion check ignores it (forest trunks the camera may pass through). Default true */
37
37
  occluder?: boolean;
38
+ /** A name: movers whose passes list names it go through it (walking, paths, navmesh), every other mover is stopped, e.g. a gate only some characters use. Omitted: it stops every mover. Sight lines and the camera ignore it */
39
+ layer?: string;
38
40
  }
39
41
  /** Parameters of addBox() (meters, radians) */
40
42
  export interface BoxColliderOptions {
@@ -50,6 +52,8 @@ export interface BoxColliderOptions {
50
52
  y?: number;
51
53
  /** false: walkers are still stopped but the follow camera's occlusion check ignores it (forest trunks the camera may pass through). Default true */
52
54
  occluder?: boolean;
55
+ /** A name: movers whose passes list names it go through it (walking, paths, navmesh), every other mover is stopped, e.g. a gate only some characters use. Omitted: it stops every mover. Sight lines and the camera ignore it */
56
+ layer?: string;
53
57
  }
54
58
 
55
59
  /** engine.collision (lightweight collision: no walking through things, the camera is not blocked). Real physics is a separate module, engine.rigid */
@@ -67,22 +71,22 @@ export interface Collision {
67
71
  addCircle(position: PositionLike, opts?: CircleColliderOptions): Handle;
68
72
  /** Add a box collider (house, fence): position is the center, e.g. addBox(house, { halfWidth: 3, halfDepth: 2, rotation: 0.3 }). Returns a handle { remove() } */
69
73
  addBox(position: PositionLike, opts?: BoxColliderOptions): Handle;
70
- /** Add a thin wall along a -> b (fence). Options: thickness (default 0.3), height, y, occluder (as in addBox). A gap between segments is a gate. Returns a handle { remove() } */
71
- addSegment(a: PositionLike, b: PositionLike, opts?: { thickness?: number; height?: number; y?: number; occluder?: boolean }): Handle;
74
+ /** Add a thin wall along a -> b (fence). Options: thickness (default 0.3), height, y, occluder, layer (as in addBox). A gap between segments is a gate. Returns a handle { remove() } */
75
+ addSegment(a: PositionLike, b: PositionLike, opts?: { thickness?: number; height?: number; y?: number; occluder?: boolean; layer?: string }): Handle;
72
76
  /** Mark ground impassable where fn(x, z) is true (river, lava); fn must be pure (no side effects, same answer for the same (x, z)); reading engine.ground in it is fine. findPathAsync caches the answers, so after the ground or your own state changes, remove() and add the field again. bounds { minX, maxX, minZ, maxZ } (world metres, the field's x / z extent) skips fn outside it; give it to keep findPathAsync's ground sampling cheap. Returns a handle { remove() } */
73
77
  addBlocked(fn: (x: number, z: number) => boolean, opts?: { bounds?: { minX: number; maxX: number; minZ: number; maxZ: number } }): Handle;
74
78
  /** Is a character of this radius touching addBlocked ground at (x, z) @experimental */
75
79
  blockedAt(x: number, z: number, radius?: number): boolean;
76
- /** Add a collider from an object's bounding box, pad expands outward (meters), occluder as in addBox. Returns a handle { remove() } */
77
- addObject(obj: Object3D, opts?: { pad?: number; occluder?: boolean }): Handle;
80
+ /** Add a collider from an object's bounding box, pad expands outward (meters), occluder and layer as in addBox. Returns a handle { remove() } */
81
+ addObject(obj: Object3D, opts?: { pad?: number; occluder?: boolean; layer?: string }): Handle;
78
82
  /** Iterate all static colliders added by hand @experimental */
79
83
  forEachStatic(fn: (type: 'box' | 'circle', data: any) => void): void;
80
84
  /** Keep an outside copy of the static colliders in step (physics colliders, navmesh obstacles): add builds one piece, remove drops one; sync() diffs only when colliders changed and returns whether it compared; clear() forgets every piece without remove (the outside world was thrown away) @experimental */
81
85
  mirror<P>(fns: { add(type: 'box' | 'circle', data: any): P; remove(piece: P, data: any): void }): { sync(): boolean; clear(): void; readonly size: number };
82
- /** Whether someone can stand at this position (for pathfinding): not in water, not too steep, not inside an obstacle. radius is the character radius (meters, default engine.movement.radius) */
83
- walkable(position: PositionLike, opts?: { radius?: number }): boolean;
84
- /** walkable with plain numbers, allocating nothing (A* inner loops); radius defaults to engine.movement.radius */
85
- walkableAt(x: number, z: number, radius?: number): boolean;
86
+ /** Whether someone can stand at this position (for pathfinding): not in water, not too steep, not inside an obstacle. radius is the character radius (meters, default engine.movement.radius), passes the collider layers it goes through */
87
+ walkable(position: PositionLike, opts?: { radius?: number; passes?: string[] }): boolean;
88
+ /** walkable with plain numbers, allocating nothing (A* inner loops); radius defaults to engine.movement.radius; y picks the floor; passes as in walkable */
89
+ walkableAt(x: number, z: number, radius?: number, y?: number, passes?: readonly string[]): boolean;
86
90
  /** Line of sight with height: is the 3D segment a -> b free of boxes, circles and terrain trees? radius fattens the line; addBlocked water is ignored. Give eye heights in a / b */
87
91
  lineClear(a: PositionLike, b: PositionLike, opts?: { radius?: number; /** who is looking (names the line in the event trace) */ who?: string }): boolean;
88
92
  }
@@ -414,6 +418,22 @@ export interface AnimatorOptions {
414
418
  /** Initial parameter values */
415
419
  params?: Record<string, number>;
416
420
  }
421
+ /** Where a look-at layer looks: an object, a point, [x, y, z] (exactly three numbers, as ik.js checks), or null to look ahead */
422
+ export type AimTarget = Object3D | Vector3 | [number, number, number] | null;
423
+ /** What an IK layer reports (anim.addAim / addFeet handles) */
424
+ export interface IkLayerInfo { kind: string; bones: string[]; weight: number }
425
+ /** A look-at layer (anim.addAim): set() takes what addAim took except bones and forward, which are fixed when it is made; remove() puts the pose back at once */
426
+ export interface AimLayer {
427
+ set(opts: { target?: AimTarget; limit?: number; speed?: number; weight?: number; fade?: number }): AimLayer;
428
+ remove(): void;
429
+ describe(): IkLayerInfo;
430
+ }
431
+ /** A feet layer (anim.addFeet): set() takes what addFeet took except legs and hips, which are fixed when it is made; remove() puts the pose back at once */
432
+ export interface FeetLayer {
433
+ set(opts: { reach?: number; far?: number; speed?: number; weight?: number; fade?: number; ground?: (x: number, z: number, y: number) => number }): FeetLayer;
434
+ remove(): void;
435
+ describe(): IkLayerInfo;
436
+ }
417
437
  /** Skeletal animation state machine (returned by engine.assets.animate(model, config)) */
418
438
  export declare class Animator {
419
439
  constructor(engine: Engine, root: Object3D, opts?: AnimatorOptions);
@@ -447,6 +467,18 @@ export declare class Animator {
447
467
  * @example anim.check(['idle', 'walk', 'attack', 'hurt'])
448
468
  */
449
469
  check(actions?: string[]): string[];
470
+ /**
471
+ * Look-at IK, the last layer on the clips: a bone or a chain from the body out turns toward target, within limit degrees of the animated pose.
472
+ * Weight 0 leaves the pose exactly; target null looks ahead; forward: the last bone's own front axis when the bind pose does not say (recipe 13 §3e)
473
+ * @example const look = npc.anim.addAim({ bones: ['Neck', 'Head'], target: engine.player.root, limit: 70 });
474
+ */
475
+ addAim(opts: { bones: string | string[]; target?: AimTarget; limit?: number; speed?: number; weight?: number; fade?: number; forward?: [number, number, number] }): AimLayer;
476
+ /**
477
+ * Feet on the ground: each [upper, lower, foot] leg bends onto the model's own ground (a Character's includes platforms; off while it jumps or swims,
478
+ * beyond far from the camera, while hidden); the hips lower for the foot that reaches down. legs: bone names when they are not recognised
479
+ * @example const feet = engine.player.anim.addFeet();
480
+ */
481
+ addFeet(opts?: { legs?: string[][]; hips?: string; reach?: number; far?: number; speed?: number; weight?: number; fade?: number; ground?: (x: number, z: number, y: number) => number }): FeetLayer;
450
482
  /** Stop the per-frame update when no longer needed */
451
483
  dispose(): void;
452
484
  }
@@ -506,9 +538,9 @@ export interface FollowCameraOptions {
506
538
  smoothing?: number;
507
539
  /** Drag sensitivity, default 1 */
508
540
  sensitivity?: number;
509
- /** Pitch range (radians) */
541
+ /** Pitch range (radians), default 0.05 to 1.35. The camera never goes below the look point, so the view cannot look up (a tall building's roof stays out of sight); a negative minPitch looks up (recipe 21 section 4b) */
510
542
  minPitch?: number;
511
- /** @experimental */ maxPitch?: number;
543
+ /** Upper pitch limit (looking down), default 1.35 (about 77 degrees, not straight down) @experimental */ maxPitch?: number;
512
544
  /** Zoom ratio per wheel notch, default 0.1 @experimental */
513
545
  zoomStep?: number;
514
546
  /** Minimum camera height above the ground (meters), default 1.2 @experimental */
package/types/pixel.d.ts CHANGED
@@ -67,7 +67,7 @@ export interface PixelSpriteOptions {
67
67
  * Works as a character's `model`. mesh.position stays exact; only what is drawn is rounded.
68
68
  * @example
69
69
  * const hero = pixelSprite({ grid: engine.cameraRig.pixelSnap.grid, material, width: 16, height: 24, columns: 4, rows: 3, snap: 'followed' });
70
- * engine.characters.createPlayer({ ...presets.player.thirdPerson, model: hero });
70
+ * engine.characters.addPlayer({ ...presets.player.thirdPerson, model: hero });
71
71
  */
72
72
  export function pixelSprite(options: PixelSpriteOptions): Mesh;
73
73
 
package/types/tsl.d.ts CHANGED
@@ -44,7 +44,7 @@ export function objectOrigin(): Node;
44
44
  */
45
45
  export function instanceOffset(offset: Node): Node;
46
46
  /**
47
- * GLSL float threedogHash(vec2 p): a repeatable random number 0-1 from a 2D position.
47
+ * GLSL float threedogHash(vec2 p): a repeatable random number 0-1 from a 2D position (an integer hash of its bits: the same on WebGL and WebGPU).
48
48
  * @experimental
49
49
  */
50
50
  export function hash(p: Node): Node;
@@ -107,6 +107,22 @@ export function rim(normal: Node, viewDir: Node, color: Node, strength: Node | n
107
107
  * @experimental
108
108
  */
109
109
  export function celLighting(): import('three/webgpu').LightingModel;
110
+ /**
111
+ * A shadow filter for a DirectionalLight whose edge softens with the distance from caster to receiver (PCSS). The game assigns it before the first frame; it reaches the engine's cascades too.
112
+ * lightSize: edge width per world unit of that distance; samples: filter taps; maxDistance: where the edge stops growing. A spot or point light throws by name.
113
+ * @example
114
+ * sun.shadow.filterNode = pcss({ lightSize: 0.04, samples: 16 });
115
+ * @experimental
116
+ */
117
+ export function pcss(o?: { lightSize?: number; samples?: number; maxDistance?: number }): any;
118
+
119
+ // three reads light.shadow.filterNode on WebGPURenderer (ShadowNode); @types/three does not declare it, so `sun.shadow.filterNode = pcss()` would not type-check
120
+ declare module 'three/src/lights/LightShadow.js' {
121
+ interface LightShadow<TCamera extends import('three').Camera = import('three').Camera> {
122
+ /** A TSL shadow filter ({ depthTexture, shadowCoord, shadow, depthLayer }) => float lit, e.g. pcss(); read when the shadow node builds */
123
+ filterNode: any;
124
+ }
125
+ }
110
126
  /**
111
127
  * GLSL float threedogWaterWave(vec3 p, float t): the built-in wave sum (height before waveHeight). p = world position * waveScale, t = time * waveSpeed.
112
128
  * @example
@@ -125,3 +141,48 @@ export function waterSurface(spec?: { depth?: { shallow?: any, deep?: any, curve
125
141
  (base: Node, wave: Node, facing: Node, worldPos: Node, time: Node) => Node;
126
142
  /** The water's fresnel blend: color mixed toward `towards` (the engine uses the fog color) by pow(1 - |viewDir . normal|, 3) * strength, view space @experimental */
127
143
  export function waterFresnel(color: Node, normal: Node, viewDir: Node, strength: Node | number, towards: Node): Node;
144
+ /** lightShaft options: shape and look are the game's; nothing here has a finished look */
145
+ export interface LightShaftOptions {
146
+ /** Follow this light every frame: a SpotLight gives position, aim, cone width and colour; a DirectionalLight gives aim and colour (the game places the opening) */
147
+ light?: import('three').SpotLight | import('three').DirectionalLight;
148
+ /** metres from the opening to the far end (default: the spot light's distance, else 4) */
149
+ length?: number;
150
+ /** radius at the opening in m (0.3) */
151
+ radiusTop?: number;
152
+ /** radius at the far end in m (default: from the spot light's angle, else radiusTop) */
153
+ radiusBottom?: number;
154
+ /** beam colour (default: the light's colour, followed live; else white) */
155
+ color?: import('three').ColorRepresentation;
156
+ /** brightness added at the core (1) */
157
+ intensity?: number;
158
+ /** 0 hard sides .. 1 fades to the centre (0.6) */
159
+ softness?: number;
160
+ /** how much dimmer the far end is, 0..1 (0.5) */
161
+ fallOff?: number;
162
+ /** metres over which it fades into walls and floor (0.5); 0 = off and no depth read (fixed at creation) */
163
+ fadeAtGeometry?: number;
164
+ /** metres in front of the camera over which it fades out (1) */
165
+ fadeNear?: number;
166
+ /** drifting dust in the beam, 0..1 (0); off on engine.tier 'low' */
167
+ dust?: number;
168
+ /** dust size: higher = finer (2) */
169
+ dustScale?: number;
170
+ /** dust drift down the beam, m/s (0.3) */
171
+ dustSpeed?: number;
172
+ /** sides of the cone (24) */
173
+ segments?: number;
174
+ }
175
+ /** The returned beam: a plain Mesh; `shaft` holds its numbers as { value } objects to change live (shape is fixed: make a new one) */
176
+ export type LightShaft = import('three').Mesh & { shaft: { color: { value: import('three').Color }; intensity: { value: number }; softness: { value: number };
177
+ fallOff: { value: number }; fadeAtGeometry: { value: number }; fadeNear: { value: number }; dust: { value: number }; dustScale: { value: number }; dustSpeed: { value: number } } };
178
+ /**
179
+ * A cheap visible light beam (ceiling hole, window, stage light): an additive open cone, top at the mesh origin pointing down -Y, sides softened by view angle,
180
+ * faded where it meets geometry and near the camera, dimmed (not tinted) by scene fog. Occluders do not cut it (for that: sunShafts / lightVolumes).
181
+ * WebGPURenderer only (both backends); WebGLRenderer throws by name. Add / move / remove it like any mesh; engine.remove frees it.
182
+ * @example
183
+ * const beam = lightShaft(engine, { radiusTop: 0.6, radiusBottom: 1.2, length: 5, color: 0xfff1d0, intensity: 0.4, dust: 0.5 });
184
+ * beam.position.set(0, 5, 0); engine.scene.add(beam);
185
+ * beam.shaft.intensity.value = 0.2; // live
186
+ * @experimental
187
+ */
188
+ export function lightShaft(engine: { renderer: any; uniforms: object; tier: string }, opts?: LightShaftOptions): LightShaft;
package/types/world.d.ts CHANGED
@@ -390,6 +390,8 @@ export interface VegetationOptions {
390
390
  fade?: false | { start?: number; end?: number };
391
391
  /** Switch to the low-detail model beyond this many rings, default 1 */
392
392
  lodRing?: number;
393
+ /** Beyond lodRing, draw camera-facing cards baked from this species' own model and materials: one draw for all far chunks, lit through baked normals, no shadow there. views around the plant (default 8), size in pixels per view (default 128). Not with lodGeometry. WebGPU only (WebGL draws the mesh and warns) */
394
+ impostor?: boolean | { views?: number; size?: number };
393
395
  /** Cast shadows */
394
396
  castShadow?: boolean;
395
397
  /** Cast shadows within this many rings */
@@ -465,16 +467,19 @@ export interface Vegetation {
465
467
  define(name: string, opts: VegetationOptions): Species | Promise<Species>;
466
468
  get(name: string): Species | undefined;
467
469
  list(): Species[];
468
- /** @experimental */ isRemoved(species: string, cx: number, cz: number, id: number): boolean;
470
+ /** Was this instance removed (removeInstance) and not restored */
471
+ isRemoved(species: string, cx: number, cz: number, id: number): boolean;
469
472
  /**
470
473
  * Remove one (chop a tree). regrowSeconds: grows back after this many calendar seconds, 0 = permanent. The record is saved with the save (save key
471
474
  * 'vegetation'). Returns the entry name
472
475
  */
473
476
  removeInstance(species: string, cx: number, cz: number, id: number, opts?: { regrowSeconds?: number }): string;
474
- /** Restore one @experimental */
477
+ /** Restore one removed instance */
475
478
  restoreInstance(species: string, cx: number, cz: number, id: number): void;
476
479
  /** The one nearest to position within radius meters (default 2) (species restricts to one kind), null if none */
477
480
  instanceAt(position: PositionLike, opts?: { radius?: number; species?: string | null }): VegetationHit | null;
481
+ /** The plant a ray hit, read from the hit itself (no spatial guess): the same VegetationHit instanceAt returns (goes to removeInstance), null if not vegetation or a far impostor card */
482
+ plantOf(hit: { object?: unknown; instanceId?: number } | null | undefined): VegetationHit | null;
478
483
  }
479
484
 
480
485
  // ======================================================================
@@ -1076,6 +1081,8 @@ export interface BudgetLimits {
1076
1081
  triangles?: number;
1077
1082
  /** Texture count */
1078
1083
  textures?: number;
1084
+ /** GPU memory in MB as three counts it (WebGPURenderer only: an estimate, not driver VRAM) */
1085
+ gpuMemoryMB?: number;
1079
1086
  /** Terrain chunk upload milliseconds per frame */
1080
1087
  chunkApplyMs?: number;
1081
1088
  /** Rigid body count */
@@ -1098,8 +1105,10 @@ export interface BudgetLimits {
1098
1105
  startupMs?: number;
1099
1106
  /** Single module startup (init + wait for ready, milliseconds); when exceeded, that module is named */
1100
1107
  moduleMs?: number;
1108
+ /** Hook ms per frame of one module, { terrain: 1.5 } (median of engine.profile(), on in dev builds); reported as category 'modules.<name>' */
1109
+ modules?: Record<string, number>;
1101
1110
  /** Custom module categories (registered via budget.metric) */
1102
- [metric: string]: number | undefined;
1111
+ [metric: string]: number | Record<string, number> | undefined;
1103
1112
  }
1104
1113
  /** One overrun: top is the biggest draw-call contributors grouped by userData.budgetTag */
1105
1114
  export interface BudgetOver { category: string; value: number; limit: number; top: BudgetTagStat[] }
package/ui/Focus.js CHANGED
@@ -8,7 +8,8 @@
8
8
  // nav: () => Element cursor over the controls inside it (buttons, inputs, selects, [data-nav]); the selected one gets the class is-cursor
9
9
  // nav: { count(), confirm(i), moved?(i) } a list the owner draws itself (dialogue choices); h.setNav(nav | null) changes it while pushed
10
10
  // an entry with a nav is something to click, so pushing it (or giving it a nav later) lets go of a locked mouse; the next click on the view locks again
11
- // h.index the selected control / choice; h.consumed the cursor used confirm this frame (the owner's own confirm handling skips it)
11
+ // h.index the selected control / choice; h.consumed the cursor used confirm on any entry of the stack this frame (the owner's own confirm handling skips it, also when a window above it just closed itself with that press)
12
+ // h.onTop this entry is the top of the stack (a window without a cursor over a dialogue never uses confirm, so consumed alone would let the dialogue advance)
12
13
  // h.fresh pushed this frame: the key press that opened it (E, Space) must not count as its own action
13
14
  // h.remove() pop (safe to call repeatedly)
14
15
  // f.setRoot(() => settings.open()) // what the back key does on an empty stack; returns a handle { remove() }
@@ -29,7 +30,7 @@ export function uiFocus(engine) {
29
30
  let f = stacks.get(engine);
30
31
  if (f) return f;
31
32
  const entries = [], stick = { key: '', t: 0 };
32
- let root = null;
33
+ let root = null, lastUsed = -1; // lastUsed: the frame the cursor used confirm on any entry; the entry may be gone by the time its owner looks (a window that closes itself), the press is spent either way
33
34
  const frame = () => engine.input.frameCount;
34
35
  // One place for every window, menu and choice list: under a lock the cursor is gone and a click lands on the canvas. The engine's own release, so it is not read as Esc
35
36
  const freeMouse = () => engine.page.releaseLock();
@@ -40,9 +41,10 @@ export function uiFocus(engine) {
40
41
  /** Push: { cancel, nav }. Returns a handle { id, fresh, index, consumed, setNav(nav), remove() } */
41
42
  push(id, { cancel = null, nav = null } = {}) {
42
43
  const h = {
43
- id, cancel, nav, index: null, at: frame(), used: -1,
44
+ id, cancel, nav, index: null, at: frame(),
44
45
  get fresh() { return h.at === frame(); },
45
- get consumed() { return h.used === frame(); },
46
+ get consumed() { return lastUsed === frame(); },
47
+ get onTop() { return entries.at(-1) === h; },
46
48
  setNav(n) { forgetNav(h); h.nav = n; h.index = null; if (n) freeMouse(); },
47
49
  remove() { forgetNav(h); const i = entries.indexOf(h); if (i >= 0) entries.splice(i, 1); },
48
50
  };
@@ -57,7 +59,7 @@ export function uiFocus(engine) {
57
59
  // the cursor of the top entry moves / presses (before the dialogue's own confirm check, which reads h.consumed)
58
60
  f.hook = engine.onFrame(dt => {
59
61
  const top = entries.at(-1);
60
- if (top?.nav && stepCursor(engine, top, stick, dt)) top.used = frame();
62
+ if (top?.nav && stepCursor(engine, top, stick, dt)) lastUsed = frame();
61
63
  if (!engine.input.pressedRaw('cancel')) return;
62
64
  if (entries.at(-1)) entries.at(-1).cancel?.();
63
65
  else root?.();
package/ui/Parts.js CHANGED
@@ -95,7 +95,7 @@ export class UIParts {
95
95
 
96
96
  /**
97
97
  * Replace a part with your own, give the default options, or turn it off. Affects parts created after this call (set before engine.start()).
98
- * @param {string} name e.g. 'loading' 'toast' 'title' 'hud.marker' 'hud.counter' 'hud.bar'
98
+ * @param {string} name e.g. 'loading' 'toast' 'title' 'hud.marker' 'hud.counter' 'hud.bar' 'hud.button'
99
99
  * @param {UIPartValue} value false off · true default · { ...options } default with options · (engine, options) => ({ show, update, hide, dispose })
100
100
  * @returns {void}
101
101
  * @example engine.ui.set('toast', (engine) => ({ show: ({ text, kind }) => { if (kind !== 'quest') myToast(text); } }))
package/ui/touchPart.js CHANGED
@@ -12,6 +12,8 @@ export function touchPart(engine) {
12
12
  injectUICSS();
13
13
  let pad = null, bar = null, labels = '';
14
14
  /** @type {TouchView} */ let cur;
15
+ const held = new Set(); // actions a finger is on now: a button that goes away mid-press never sees its pointerup, so this view lets go for it
16
+ const letGo = () => { for (const a of held) cur.release(a); held.clear(); };
15
17
  const makeStick = () => {
16
18
  pad = document.createElement('div'); const knob = document.createElement('div');
17
19
  pad.className = 'threedog-stick'; knob.className = 'threedog-stick-knob';
@@ -30,8 +32,8 @@ export function touchPart(engine) {
30
32
  };
31
33
  const button = b => {
32
34
  const el = document.createElement('button'); el.type = 'button'; el.className = 'threedog-touch-btn'; el.textContent = b.label;
33
- el.addEventListener('pointerdown', ev => { ev.preventDefault(); cur.press(b.action); });
34
- const up = () => cur.release(b.action);
35
+ el.addEventListener('pointerdown', ev => { ev.preventDefault(); held.add(b.action); cur.press(b.action); });
36
+ const up = () => { held.delete(b.action); cur.release(b.action); };
35
37
  el.addEventListener('pointerup', up); el.addEventListener('pointercancel', up); el.addEventListener('pointerleave', up);
36
38
  return el;
37
39
  };
@@ -42,8 +44,9 @@ export function touchPart(engine) {
42
44
  const key = v.buttons.map(b => b.action + ':' + b.label).join('|');
43
45
  if (key === labels) return; // rebuild the buttons only when the set or a label changed
44
46
  labels = key;
47
+ letGo();
45
48
  if (!bar) { bar = document.createElement('div'); bar.className = 'threedog-touch-bar'; engine.uiRoot.appendChild(bar); }
46
49
  bar.replaceChildren(...v.buttons.map(button));
47
50
  };
48
- return { show: draw, update: draw, dispose() { pad?.remove(); bar?.remove(); pad = bar = null; } };
51
+ return { show: draw, update: draw, dispose() { if (cur) { letGo(); cur.move(0, 0); } pad?.remove(); bar?.remove(); pad = bar = null; } };
49
52
  }