threedog 0.8.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (372) hide show
  1. package/CHANGELOG.md +219 -4
  2. package/README.md +6 -6
  3. package/core/assets/Animator.js +2 -0
  4. package/core/assets/Assets.js +44 -13
  5. package/core/assets/assetEntry.js +87 -22
  6. package/core/assets/assetHot.js +2 -1
  7. package/core/assets/assetReport.js +1 -2
  8. package/core/audio/Audio.js +24 -5
  9. package/core/base/I18n.js +6 -3
  10. package/core/base/Random.js +3 -1
  11. package/core/base/Vars.js +14 -4
  12. package/core/base/errorCodes.js +54 -16
  13. package/core/base/errorHints.js +12 -1
  14. package/core/base/errors.js +6 -4
  15. package/core/base/events.generated.js +10 -0
  16. package/core/base/follows.js +26 -0
  17. package/core/base/math.js +15 -8
  18. package/core/base/params.js +2 -2
  19. package/core/{saves → base}/saveValues.js +24 -6
  20. package/core/base/sections.js +97 -0
  21. package/core/base/spelling.js +32 -0
  22. package/core/base/validate.js +8 -29
  23. package/core/engine/Engine.js +61 -18
  24. package/core/engine/Loading.js +30 -3
  25. package/core/engine/copies.js +1 -1
  26. package/core/engine/headlessLoad.js +30 -13
  27. package/core/engine/lifecycle.js +30 -25
  28. package/core/engine/loop.js +22 -4
  29. package/core/engine/moduleSlots.js +91 -15
  30. package/core/engine/moduleTypes.js +13 -0
  31. package/core/engine/modules.js +248 -62
  32. package/core/engine/page.js +25 -8
  33. package/core/engine/plugins.js +15 -3
  34. package/core/engine/services.js +3 -0
  35. package/core/engine/startup.js +46 -36
  36. package/core/input/Input.js +39 -19
  37. package/core/input/inputKeyboard.js +39 -0
  38. package/core/input/inputPad.js +23 -2
  39. package/core/input/inputPointer.js +3 -1
  40. package/core/input/inputSeat.js +66 -0
  41. package/core/input/inputTouch.js +23 -6
  42. package/core/inspect/DebugOverrides.js +13 -2
  43. package/core/inspect/Describe.js +10 -6
  44. package/core/inspect/Inspect.js +31 -4
  45. package/core/inspect/UrlState.js +14 -10
  46. package/core/inspect/catalog.js +12 -5
  47. package/core/inspect/describeRender.js +3 -2
  48. package/core/inspect/describeText.js +6 -2
  49. package/core/inspect/metadata.generated.js +4140 -0
  50. package/core/inspect/pictureWriters.js +117 -33
  51. package/core/inspect/toolDoor.js +21 -0
  52. package/core/inspect/valueHistory.js +35 -0
  53. package/core/ops/Ops.js +32 -7
  54. package/core/ops/control.js +48 -23
  55. package/core/ops/holds.js +4 -3
  56. package/core/ops/opsAtomic.js +18 -6
  57. package/core/ops/opsCheck.js +7 -5
  58. package/core/ops/opsFail.js +5 -7
  59. package/core/ops/opsRun.js +2 -2
  60. package/core/ops/owned.js +20 -3
  61. package/core/ops/sharedPoint.js +7 -10
  62. package/core/ops/stacks.js +22 -1
  63. package/core/saves/SaveStore.js +52 -26
  64. package/core/saves/Saves.js +122 -27
  65. package/core/saves/saveApply.js +159 -61
  66. package/core/saves/saveFiles.js +30 -25
  67. package/core/saves/saveVersions.js +20 -6
  68. package/core/saves/session.js +76 -33
  69. package/core/saves/stateReplace.js +184 -0
  70. package/core/scene/Rays.js +21 -5
  71. package/core/scene/Views.js +6 -6
  72. package/core/scene/adaptive.js +13 -10
  73. package/core/scene/canvasBox.js +2 -0
  74. package/core/scene/compositeGround.js +72 -0
  75. package/core/scene/floor.js +17 -0
  76. package/core/scene/grid.js +2 -0
  77. package/core/scene/ground.contract.js +14 -0
  78. package/core/scene/ground.js +52 -17
  79. package/core/scene/pixel.js +154 -0
  80. package/core/scene/pixelRatio.js +167 -0
  81. package/core/scene/sceneDelta.js +3 -3
  82. package/core/scene/sceneMethods.js +11 -6
  83. package/core/scene/stepPoses.js +6 -1
  84. package/core/scene/thingExplain.js +1 -1
  85. package/core/scene/thingOps.js +22 -14
  86. package/core/scene/things.js +1 -1
  87. package/core/scene/tier.js +10 -0
  88. package/core/scene/view.js +126 -9
  89. package/core/stream/Batching.js +0 -1
  90. package/core/stream/Stream.js +24 -12
  91. package/core/stream/batchGroups.js +1 -0
  92. package/core/stream/scatter.js +5 -2
  93. package/core/stream/streamSources.js +2 -1
  94. package/core/threads/Commits.js +12 -7
  95. package/core/threads/Jobs.js +15 -5
  96. package/core/threads/Threads.js +5 -2
  97. package/core/time/Clock.js +3 -1
  98. package/core/time/skip.js +10 -4
  99. package/core/time/time.js +16 -10
  100. package/docs/AI.md +89 -72
  101. package/docs/API.md +18 -14
  102. package/docs/CODEMAP.md +68 -40
  103. package/docs/COMMANDS.md +22 -23
  104. package/docs/CONVENTIONS.md +120 -17
  105. package/docs/MIGRATING-0.8.md +2 -0
  106. package/docs/MIGRATING-1.0.md +101 -0
  107. package/docs/THREE.md +65 -12
  108. package/docs/api/cameraRig.md +3 -0
  109. package/docs/api/characters.md +13 -7
  110. package/docs/api/collider3d.md +9 -0
  111. package/docs/api/content.md +16 -15
  112. package/docs/api/dialogue.md +2 -1
  113. package/docs/api/engine.md +18 -16
  114. package/docs/api/events.md +14 -4
  115. package/docs/api/ground.md +2 -2
  116. package/docs/api/i18n.md +1 -1
  117. package/docs/api/input.md +2 -1
  118. package/docs/api/interactions.md +1 -1
  119. package/docs/api/inventory.md +1 -1
  120. package/docs/api/level.md +3 -2
  121. package/docs/api/nav.md +4 -2
  122. package/docs/api/particles.md +8 -5
  123. package/docs/api/pickups.md +1 -1
  124. package/docs/api/post.md +3 -4
  125. package/docs/api/quests.md +4 -2
  126. package/docs/api/rays.md +2 -0
  127. package/docs/api/rigid.md +3 -2
  128. package/docs/api/saves.md +8 -7
  129. package/docs/api/stream.md +4 -5
  130. package/docs/api/terrain.md +3 -4
  131. package/docs/api/terrainDraw.md +1 -1
  132. package/docs/api/timeline.md +2 -2
  133. package/docs/api/tools.md +3 -1
  134. package/docs/api/triggers.md +2 -0
  135. package/docs/api/vegetationDraw.md +1 -1
  136. package/docs/api/water.md +6 -2
  137. package/docs/api/weather.md +19 -4
  138. package/docs/api/weatherDraw.md +1 -1
  139. package/docs/api/world.md +1 -1
  140. package/docs/recipes/01-new-game.md +3 -3
  141. package/docs/recipes/02-npc.md +3 -4
  142. package/docs/recipes/03-items-pickups.md +11 -11
  143. package/docs/recipes/04-quests.md +2 -0
  144. package/docs/recipes/05-props-bake.md +9 -9
  145. package/docs/recipes/06-clock-events.md +6 -6
  146. package/docs/recipes/07-flow-scenes-pause.md +18 -15
  147. package/docs/recipes/08-weather-sky.md +5 -5
  148. package/docs/recipes/09-materials-lights-models.md +3 -3
  149. package/docs/recipes/10-blender-level.md +16 -4
  150. package/docs/recipes/11-vehicles.md +18 -6
  151. package/docs/recipes/12-navmesh.md +52 -8
  152. package/docs/recipes/13-animation.md +34 -8
  153. package/docs/recipes/14-custom-module.md +20 -8
  154. package/docs/recipes/15-perf.md +4 -4
  155. package/docs/recipes/16-dev-bridge.md +9 -8
  156. package/docs/recipes/18-world.md +13 -5
  157. package/docs/recipes/19-shooting-picking.md +3 -2
  158. package/docs/recipes/20-content-actions-save.md +26 -6
  159. package/docs/recipes/21-camera.md +17 -23
  160. package/docs/recipes/22-shop-gold.md +21 -12
  161. package/docs/recipes/23-ops.md +19 -15
  162. package/docs/recipes/26-ui-parts.md +3 -2
  163. package/docs/recipes/27-net.md +3 -3
  164. package/docs/recipes/28-terrain.md +3 -3
  165. package/docs/recipes/29-grid.md +1 -1
  166. package/docs/recipes/30-templates.md +10 -13
  167. package/docs/recipes/31-audio.md +2 -2
  168. package/docs/recipes/32-action-game.md +6 -5
  169. package/docs/recipes/33-stream-sources.md +4 -1
  170. package/docs/recipes/34-environment-lighting.md +7 -8
  171. package/docs/recipes/35-picture-from-reference.md +13 -9
  172. package/docs/recipes/36-ground-plants.md +3 -2
  173. package/docs/recipes/40-scene.md +11 -10
  174. package/docs/recipes/43-shader-patches-surfaces.md +7 -7
  175. package/docs/recipes/44-water-weather-hooks.md +9 -8
  176. package/docs/recipes/45-cascaded-shadows.md +3 -4
  177. package/docs/recipes/46-blender-art-route.md +3 -3
  178. package/docs/recipes/49-game-module-contract.md +2 -1
  179. package/docs/recipes/50-own-renderer.md +1 -0
  180. package/docs/recipes/51-capability-catalog.md +14 -8
  181. package/docs/recipes/52-around-the-picture.md +4 -4
  182. package/docs/recipes/55-mods-time-wrap.md +5 -4
  183. package/docs/recipes/56-webgpu-tsl.md +12 -1
  184. package/docs/recipes/57-control.md +30 -10
  185. package/docs/recipes/58-input.md +13 -0
  186. package/docs/recipes/60-judge-the-picture.md +1 -1
  187. package/docs/recipes/62-picture-code.md +106 -48
  188. package/docs/recipes/63-third-person-start.md +2 -1
  189. package/docs/recipes/64-particles.md +53 -4
  190. package/docs/recipes/65-swarm.md +2 -2
  191. package/docs/recipes/66-common-tasks.md +313 -0
  192. package/examples/action/.threedog/content-index.json +1 -1
  193. package/examples/action/GAMEMAP.md +3 -3
  194. package/examples/perf-island/.threedog/content-index.json +1 -1
  195. package/examples/perf-island/GAMEMAP.md +3 -3
  196. package/examples/perf-island/main.js +2 -2
  197. package/examples/plain-picture/GAMEMAP.md +3 -1
  198. package/examples/rc2d/GAMEMAP.md +1 -1
  199. package/examples/rc2d/rc2d.js +1 -1
  200. package/examples/styletest/.threedog/content-index.json +1 -1
  201. package/examples/styletest/GAMEMAP.md +3 -3
  202. package/examples/webgpu-tsl/GAMEMAP.md +1 -1
  203. package/examples/world/.threedog/content-index.json +1 -1
  204. package/examples/world/GAMEMAP.md +5 -4
  205. package/examples/world/main.js +3 -3
  206. package/index.d.ts +8 -5
  207. package/index.js +22 -1
  208. package/llms.txt +2 -1
  209. package/modules/ambience/Ambience.js +5 -3
  210. package/modules/calendar/index.js +7 -5
  211. package/modules/camera/FirstPersonCamera.js +3 -3
  212. package/modules/camera/FixedCamera.js +34 -20
  213. package/modules/camera/FollowCamera.js +20 -11
  214. package/modules/camera/RtsCamera.js +1 -0
  215. package/modules/camera/common.js +33 -22
  216. package/modules/camera/pixelSnap.js +62 -0
  217. package/modules/characters/Character.js +136 -43
  218. package/modules/characters/NPC.js +60 -28
  219. package/modules/characters/assetModel.js +2 -2
  220. package/modules/characters/astar.js +47 -28
  221. package/modules/characters/character.contract.js +21 -0
  222. package/modules/characters/contract.js +17 -3
  223. package/modules/characters/index.js +94 -34
  224. package/modules/characters/moveHelpers.js +80 -15
  225. package/modules/characters/mover.contract.js +14 -0
  226. package/modules/characters/movers/common.js +6 -4
  227. package/modules/characters/movers/rapier.js +12 -5
  228. package/modules/characters/movers/simple.js +25 -12
  229. package/modules/characters/movers/support.js +18 -7
  230. package/modules/characters/npcAvoid.js +15 -12
  231. package/modules/characters/npcSim.js +75 -25
  232. package/modules/characters/npcView.js +13 -6
  233. package/modules/characters/pathAsync.js +74 -24
  234. package/modules/characters/pathJob.js +38 -21
  235. package/modules/characters/player.js +59 -47
  236. package/modules/characters/seat.js +56 -0
  237. package/modules/characters/vehicle.contract.js +8 -5
  238. package/modules/characters/walkTo.js +31 -18
  239. package/modules/collision/Collision.js +44 -26
  240. package/modules/collision/contract.js +2 -2
  241. package/modules/collision/grid.js +6 -1
  242. package/modules/content/explain.js +1 -1
  243. package/modules/content/fields.js +3 -3
  244. package/modules/content/ids.js +3 -1
  245. package/modules/content/index.js +83 -27
  246. package/modules/content/loader.js +110 -130
  247. package/modules/content/markers.js +1 -1
  248. package/modules/content/models.js +48 -14
  249. package/modules/content/packs.js +2 -1
  250. package/modules/content/places.js +5 -4
  251. package/modules/content/props.js +8 -6
  252. package/modules/content/rules.js +29 -47
  253. package/modules/content/templates.js +66 -35
  254. package/modules/content/words.js +19 -6
  255. package/modules/debug/DebugPanel.js +4 -2
  256. package/modules/flow/contract.js +1 -0
  257. package/modules/flow/index.js +24 -14
  258. package/modules/gameplay/Container.js +5 -2
  259. package/modules/gameplay/Containers.js +9 -1
  260. package/modules/gameplay/Dialogue.js +82 -25
  261. package/modules/gameplay/Interactions.js +61 -32
  262. package/modules/gameplay/Inventory.js +56 -13
  263. package/modules/gameplay/Quests.js +133 -24
  264. package/modules/gameplay/boxOps.js +7 -0
  265. package/modules/gameplay/dialogueBubbles.js +14 -9
  266. package/modules/gameplay/inventoryOps.js +11 -7
  267. package/modules/gameplay/pickups.js +43 -16
  268. package/modules/gameplay/questLog.js +4 -2
  269. package/modules/gameplay/questSave.js +6 -1
  270. package/modules/gameplay/quests.contract.js +1 -1
  271. package/modules/grid/Grid.js +1 -1
  272. package/modules/grid/Layer.js +8 -4
  273. package/modules/grid/index.js +21 -15
  274. package/modules/grid/ops.js +43 -46
  275. package/modules/grid/tiles.js +1 -1
  276. package/modules/hlod/index.js +6 -3
  277. package/modules/hud/index.js +6 -4
  278. package/modules/hud/parts.js +4 -4
  279. package/modules/level/contract.js +2 -2
  280. package/modules/level/heightfield.js +17 -21
  281. package/modules/level/index.js +83 -26
  282. package/modules/level/load.js +165 -48
  283. package/modules/level/nodes.js +34 -16
  284. package/modules/lights/index.js +6 -3
  285. package/modules/lights/sources.js +3 -1
  286. package/modules/music/Music.js +4 -2
  287. package/modules/nav/contract.js +7 -5
  288. package/modules/nav/index.js +174 -44
  289. package/modules/nav/navPath.js +45 -10
  290. package/modules/net/index.js +1 -1
  291. package/modules/particles/Particles.js +85 -22
  292. package/modules/particles/effect.js +80 -28
  293. package/modules/particles/shaders.js +17 -0
  294. package/modules/photo/Photo.js +12 -10
  295. package/modules/rigid/RigidBodies.js +200 -57
  296. package/modules/rigid/Vehicles.js +15 -5
  297. package/modules/rigid/collider3d.contract.js +26 -0
  298. package/modules/rigid/ragdoll.js +55 -44
  299. package/modules/rigid/ragdollBones.js +83 -33
  300. package/modules/rigid/refresh.js +10 -0
  301. package/modules/rigid/sync.js +46 -15
  302. package/modules/settings/Settings.js +84 -37
  303. package/modules/settings/apply.js +15 -8
  304. package/modules/settings/sections.js +7 -4
  305. package/modules/settings/strings.js +2 -2
  306. package/modules/sky/skyModule.js +3 -1
  307. package/modules/swarm/Swarm.js +16 -6
  308. package/modules/terrain/ChunkManager.js +10 -16
  309. package/modules/terrain/index.js +17 -11
  310. package/modules/terrain/terrainEdit.js +13 -2
  311. package/modules/terrain/terrainGen.js +5 -3
  312. package/modules/terrain/terrainShape.js +1 -1
  313. package/modules/timeline/Timeline.js +58 -26
  314. package/modules/timeline/Tween.js +19 -13
  315. package/modules/timeline/shots.js +19 -10
  316. package/modules/triggers/index.js +87 -20
  317. package/modules/vegetation/Vegetation.js +4 -3
  318. package/modules/vegetation/draw.js +16 -0
  319. package/modules/vegetation/groundChunks.js +10 -7
  320. package/modules/vegetation/index.js +30 -7
  321. package/modules/water/Water.js +6 -2
  322. package/modules/weather/Weather.js +16 -15
  323. package/modules/weather/weatherDraw.js +7 -6
  324. package/modules/world/World.js +20 -7
  325. package/modules/world/explain.js +1 -1
  326. package/modules/world/index.js +13 -6
  327. package/modules/world/persist.js +23 -8
  328. package/modules/world/pos.js +4 -4
  329. package/modules/world/records.js +13 -7
  330. package/modules/world/sim.js +74 -23
  331. package/modules/world/simFar.js +2 -2
  332. package/modules/world/state.js +31 -6
  333. package/modules/world/thingSource.js +16 -3
  334. package/modules/world/views.js +19 -8
  335. package/package.json +7 -1
  336. package/render/PostFX.js +47 -29
  337. package/render/backend.js +5 -1
  338. package/render/fx/particles.tsl.js +8 -6
  339. package/render/fx/postWebGPU.tsl.js +3 -3
  340. package/render/layers.js +1 -1
  341. package/render/lightmap.js +23 -3
  342. package/render/occlusion.js +43 -12
  343. package/render/patches.js +2 -2
  344. package/render/postWebGL.js +4 -3
  345. package/render/probes.js +25 -0
  346. package/render/shadows.js +2 -2
  347. package/types/core.d.ts +142 -55
  348. package/types/gameplay.d.ts +92 -40
  349. package/types/generated/core/base/I18n.d.ts +2 -2
  350. package/types/generated/core/input/Input.d.ts +16 -2
  351. package/types/generated/core/input/inputSeat.d.ts +26 -0
  352. package/types/generated/core/inspect/DebugOverrides.d.ts +15 -1
  353. package/types/generated/core/ops/Ops.d.ts +2 -1
  354. package/types/generated/core/ops/control.d.ts +12 -2
  355. package/types/generated/core/saves/Saves.d.ts +26 -6
  356. package/types/generated/core/saves/session.d.ts +1 -1
  357. package/types/generated/core/scene/Views.d.ts +1 -1
  358. package/types/generated/core/stream/Stream.d.ts +6 -4
  359. package/types/generated/modules/grid/Grid.d.ts +1 -0
  360. package/types/generated/modules/particles/Particles.d.ts +4 -3
  361. package/types/generated/modules/timeline/Timeline.d.ts +5 -4
  362. package/types/generated/modules/weather/Weather.d.ts +1 -7
  363. package/types/generated/modules/world/World.d.ts +6 -4
  364. package/types/generated/render/PostFX.d.ts +6 -14
  365. package/types/nav.d.ts +36 -4
  366. package/types/physics.d.ts +55 -7
  367. package/types/pixel.d.ts +75 -0
  368. package/types/world.d.ts +14 -8
  369. package/ui/Parts.js +9 -2
  370. package/ui/theme.js +2 -2
  371. package/core/scene/engineCamera.js +0 -32
  372. package/modules/camera/projection.js +0 -21
@@ -3,7 +3,7 @@
3
3
  /** engine.session: new game / continue / back to title, each from a clean slate. */
4
4
  export class Session {
5
5
  /**
6
- * True while a playthrough runs: start() has finished, no newGame / load / quit is replacing the state, and the title screen is not up.
6
+ * True while a playthrough runs: start() has finished, no newGame / load / quit is replacing the state, and neither the title screen nor a finished quit stands in its place.
7
7
  * Autosave and other "only during play" work check it.
8
8
  * @type {boolean}
9
9
  * @experimental
@@ -3,7 +3,7 @@ export class Views {
3
3
  /** @param {any} engine */
4
4
  constructor(engine: any);
5
5
  map: Map<any, any>;
6
- current: string;
6
+ /** Name of the view in use, null while none is @type {string | null} */ current: string | null;
7
7
  /**
8
8
  * Declare a view. position and target are [x, y, z]; fov (degrees) is optional (the camera's own when left out). Returns { remove() } (undeclares it).
9
9
  * @param {string} name @param {{ position: number[], target?: number[], fov?: number }} v
@@ -21,13 +21,11 @@ export class Stream {
21
21
  set radius(m: number | null);
22
22
  /**
23
23
  * Build radius in meters around each full-detail stream source (a source radius caps it); null = follow the terrain view distance (the uViewDistance signal
24
- * without terrain). Writing it takes effect like setRadius.
24
+ * without terrain).
25
25
  * @type {number | null}
26
26
  */
27
27
  get radius(): number | null;
28
- /** Set the build radius in meters @param {number} m @experimental */
29
- setRadius(m: number): void;
30
- /** Everything registered within radius is built (start() waits for it before the loading screen goes away) @returns {boolean} */
28
+ /** No build within radius is still waiting (start() waits for it before the loading screen goes away). Nothing pending, not everything built: a build that failed is reported and left out; a game that needs a thing built checks it itself (handle.built) @returns {boolean} */
31
29
  get ready(): boolean;
32
30
  /** entries is the registered count, built the built count, queued the queued count @returns {{ entries: number, built: number, queued: number }} */
33
31
  get stats(): {
@@ -54,6 +52,10 @@ export class Stream {
54
52
  * (terrain chunks, collision, nearby models) the player stays where it is. move replaces the default placement (for a vehicle or a custom character).
55
53
  * timeout (seconds of frame time, default 60; Infinity waits forever): when the destination is still not ready, the Promise rejects (code stream-timeout,
56
54
  * naming the loaders still waiting) and the player is not moved.
55
+ * Ready means nothing is pending, not that everything built: a stream entry or world model whose build failed is reported and left out, and the trip still lands. A terrain chunk that
56
+ * failed stays not ready, as there is no ground to stand on, so that trip ends in stream-timeout. A game that needs a thing built checks it itself (handle.built, engine.world.view(id)).
57
+ * A trip belongs to the state it was asked in: it does not land while a load runs, and a newGame, load or saves.load that goes through abandons it (it rejects with
58
+ * code stream-removed and the player stays where the new state put it). A load that fails leaves it going.
57
59
  * @example await engine.stream.teleport([800, 0, 300]);
58
60
  * @example await engine.stream.teleport(door.target, { radius: 40, move: p => engine.player.placeAt(p) });
59
61
  * @param {any} position
@@ -2,6 +2,7 @@
2
2
  /** The default occupancy layer of an item that names none */
3
3
  export const MAIN: "main";
4
4
  export function occKey(occupy: any, level: any, i: any, j: any): string;
5
+ export function planar(v: any): any[];
5
6
  /**
6
7
  * A placement grid. Several can exist at once (a yard outdoors, a room indoors); each has its own cell size, origin and bounds.
7
8
  * @example
@@ -32,7 +32,7 @@ export class Particles {
32
32
  */
33
33
  has(name: string): boolean;
34
34
  /**
35
- * Burst: emit count particles at once (default 10) at position (Vector3 / Object3D / [x, y, z] / {x, y, z}). overrides affect this batch only (color, speed, direction...; max/texture/blending cannot be changed temporarily)
35
+ * Burst: emit count particles at once (default 10) at position (Vector3 / Object3D / [x, y, z] / {x, y, z}). overrides affect this batch only (color, speed, direction...; max/texture/blending/soft cannot be changed temporarily)
36
36
  * @param {string} name
37
37
  * @param {PositionLike} position
38
38
  * @param {{ count?: number, overrides?: ParticleOptions | null }} [opts]
@@ -43,14 +43,15 @@ export class Particles {
43
43
  overrides?: ParticleOptions | null;
44
44
  }): void;
45
45
  /**
46
- * Keep emitting while following an object: rate per second, offset in the object's local coordinates [x, y, z] (meters). Returns a handle { remove(), rate, active } (active = false pauses)
46
+ * Keep emitting while following an object: rate per second, ratePerMeter per meter it moves (spread along the path, on top of rate), offset in the object's local coordinates [x, y, z] (meters). Returns a handle { remove(), rate, ratePerMeter, active } (active = false pauses)
47
47
  * @param {string} name
48
48
  * @param {Object3D} object3d
49
- * @param {{ rate?: number, offset?: number[], overrides?: ParticleOptions | null }} [opts]
49
+ * @param {{ rate?: number, ratePerMeter?: number, offset?: number[], overrides?: ParticleOptions | null }} [opts]
50
50
  * @returns {ParticleEmitter}
51
51
  */
52
52
  attach(name: string, object3d: THREE.Object3D, opts?: {
53
53
  rate?: number;
54
+ ratePerMeter?: number;
54
55
  offset?: number[];
55
56
  overrides?: ParticleOptions | null;
56
57
  }): ParticleEmitter;
@@ -19,7 +19,7 @@ export class Timeline {
19
19
  get playing(): boolean;
20
20
  /**
21
21
  * General tween (the only entry point for tweens in the engine): await engine.timeline.tween(mesh, { 'position.y': 2 }, { duration: 1, ease: 'outCubic' }); duration in seconds (default 1), ease default 'inOutCubic'; tween(mesh, to, 1) throws in dev.
22
- * Returns a Promise (with finish() / remove())
22
+ * Returns a Promise (with finish() / remove()); a write that throws ends the tween and rejects it
23
23
  * @param {any} target
24
24
  * @param {TweenTo} to
25
25
  * @param {{ duration?: number, ease?: Ease }} [opts]
@@ -30,13 +30,14 @@ export class Timeline {
30
30
  ease?: Ease;
31
31
  }): TweenPromise;
32
32
  /**
33
- * Play a timeline; resolves with { skipped } when it ends
33
+ * Play a timeline; resolves with { ending, error? } when it ends: 'finished', 'skipped', 'dropped' (a load, a new game or dispose took its state) or 'failed' (a step threw; error says what)
34
34
  * @param {TimelineStep | TimelineStep[]} steps
35
35
  * @param {TimelinePlayOptions} [opts]
36
- * @returns {Promise<{ skipped: boolean }>}
36
+ * @returns {Promise<{ ending: 'finished' | 'skipped' | 'dropped' | 'failed', error?: string }>}
37
37
  */
38
38
  play(steps: TimelineStep | TimelineStep[], opts?: TimelinePlayOptions): Promise<{
39
- skipped: boolean;
39
+ ending: "finished" | "skipped" | "dropped" | "failed";
40
+ error?: string;
40
41
  }>;
41
42
  /**
42
43
  * Skip all (or one) playing timelines
@@ -56,16 +56,10 @@ export class Weather {
56
56
  defineField(field: string, spec: WeatherParticles | null): WeatherParticleSystem | null;
57
57
  set auto(on: boolean);
58
58
  /**
59
- * Automatic weather on/off. Writing it takes effect like setAuto.
59
+ * Automatic weather on/off.
60
60
  * @type {boolean}
61
61
  */
62
62
  get auto(): boolean;
63
- /**
64
- * Automatic weather on/off
65
- * @param {boolean} on
66
- * @returns {void}
67
- */
68
- setAuto(on: boolean): void;
69
63
  /**
70
64
  * Switch weather. seconds: transition seconds, default 15; 0 switches at once (current is the new weather before the next step, so a
71
65
  * screenshot or test right after shows all of it). Options in an object like every other engine call: set('rain', 20) throws
@@ -108,7 +108,9 @@ export class World {
108
108
  set(id: string, patch: Record<string, any>): WorldRecord;
109
109
  /**
110
110
  * Move a record (no event; use it in simulate for things that move every step); still saved (saves diff against content).
111
- * The model of a positionFrom 'record' (default) record follows this frame; to do something else with the position in presentation, compare in update
111
+ * The model of a positionFrom 'record' (default) record follows this frame; to do something else with the position in presentation, compare in update.
112
+ * On a live character (the player, an NPC with a model) this is its placeAt: the character owns its position, so it goes there and the record says where it stands.
113
+ * A seated rider gets out to go there (placeAt ends a ride); a write equal to where it sits only follows the seat
112
114
  * @example engine.world.move(rec.id, { x: rec.position.x + 1, z: rec.position.z })
113
115
  * @param {string} id
114
116
  * @param {any} position Vector3 / object / [x, y, z] / { x, z } (y stays unchanged if omitted)
@@ -158,7 +160,7 @@ export class World {
158
160
  * radius: meters, or a function (for distances that change, like terrain view distance); defaults to world.radius. Registering the same kind again: old
159
161
  * models are torn down with the old dispose and rebuilt with the new one.
160
162
  * positionFrom: 'record' (default, the model follows the record every frame) or 'view' (the model moves itself, e.g. driven by a character mover; model
161
- * position is copied back to the record at the end of each fixed step).
163
+ * position is copied back to the record at the end of each fixed step, and a write to the record moves the model and a rigid body on it).
162
164
  * @example engine.world.present('chest', { build: rec => new THREE.Mesh(boxGeo, new THREE.MeshStandardMaterial()), dispose: (rec, obj) => engine.remove(obj), show: rec
163
165
  * => !rec.looted })
164
166
  * @param {string} kind
@@ -204,8 +206,8 @@ export class World {
204
206
  * far → near step, far runs first to pay back the owed time.
205
207
  * With only far (crops), near also advances via far; with only near, far records are not simulated and owed time is not made up.
206
208
  * Both dt are accumulated real (fixed-step) seconds (not multiplied by clock.rate). For things measured in game clock (grows over days) store engine.clock.now
207
- * and compare. channel: a time channel name (or rec => name) the kind lives on; then both dt are multiplied by that channel's speed (and the record's
208
- * engine.time.local stack), so bullet time on 'enemies' slows near and far records alike (NPCs use it with their own channel).
209
+ * and compare. channel: a time channel name (or rec => name) the kind lives on; then both dt are the channel time the record lived through (its
210
+ * engine.time.local stack too), whatever the speed when far settles, so bullet time on 'enemies' slows near and far records alike (NPCs use it with their own channel).
209
211
  * radius defaults to the present radius ('view' widened by 1.25), or world.radius without present; may also be a function.
210
212
  * fullRadius + nearEvery (tiers, for crowds): records within fullRadius m (number or function) run near every step; the rest of the near zone runs near
211
213
  * once every nearEvery seconds, dt being the seconds since its last turn (deterministic: turns go by hashed id and step count, saved).
@@ -2,19 +2,20 @@
2
2
  export class PostFX {
3
3
  set antialias(on: boolean);
4
4
  /**
5
- * MSAA on. Writing it takes effect like setAntialias.
5
+ * MSAA on or off in the post chain's render targets, for what runs through the chain. It is a render setting, not a drawing part. With no effect on nothing runs through the chain:
6
+ * the canvas's own MSAA shows, fixed when the context was made (createEngine({ antialias })).
7
+ * @example engine.post.antialias = false;
6
8
  * @type {boolean}
7
9
  * @experimental
8
10
  */
9
11
  get antialias(): boolean;
10
12
  /**
11
- * Whether the post chain runs: an effect is on, or antialias differs from the canvas's own MSAA (fixed when the renderer was made, so a
12
- * runtime switch away from it goes through the chain's targets)
13
+ * Whether the post chain runs: an effect is on
13
14
  * @returns {boolean}
14
15
  */
15
16
  get active(): boolean;
16
17
  /**
17
- * What the chain runs in, for reading, or null while no post work has run yet (built the first time an effect or MSAA is on; it is not built here, so asking never costs a
18
+ * What the chain runs in, for reading, or null while no post work has run yet (built the first time an effect is on; it is not built here, so asking never costs a
18
19
  * render target). WebGLRenderer: the three.js EffectComposer (pass list, sizes, its targets). WebGPURenderer: { pipeline, scenePass }, three's RenderPipeline and the scene's pass() node. Read-only by rule, not by lock:
19
20
  * the engine owns it, rebuilds the chain whenever the list changes and disposes it with the engine. To add a pass use post.add,
20
21
  * to own the whole chain post.own() (recipe 52). Why public: a game reading the chain had to dig into an internal field (review 2026-11-03)
@@ -28,7 +29,7 @@ export class PostFX {
28
29
  * output; EffectComposer swaps them after every pass with needsSwap (most passes; the scene RenderPass does not). The last pass draws to the
29
30
  * canvas and still swaps, so after the frame (engine.onRender(fn, { when: 'after' })) neither target holds the final picture: writeBuffer holds
30
31
  * the input of that last pass (readBuffer when the last pass does not swap) and readBuffer is stale. For the final image, render into a target of your own.
31
- * Owned by the engine like object(): it resizes them, changes samples on setAntialias and adds a depth texture when an effect needs depth;
32
+ * Owned by the engine like object(): it resizes them, changes samples when antialias is written and adds a depth texture when an effect needs depth;
32
33
  * do not dispose them or swap their textures. A target of your own: new THREE.WebGLRenderTarget in onRender (THREE.md)
33
34
  * @returns {{ renderTarget1: any, renderTarget2: any, readBuffer: any, writeBuffer: any } | null}
34
35
  * @experimental
@@ -72,15 +73,6 @@ export class PostFX {
72
73
  * @experimental
73
74
  */
74
75
  own(on?: boolean): void;
75
- /**
76
- * Turn MSAA on or off. It is a render setting, not a drawing part. With no effect on, the start value is the canvas's own MSAA (free: no
77
- * post chain); the other value, and any effect, draws through the chain, whose render targets carry the MSAA.
78
- * @example engine.post.setAntialias(false);
79
- * @param {boolean} on
80
- * @returns {void}
81
- * @experimental
82
- */
83
- setAntialias(on: boolean): void;
84
76
  /**
85
77
  * Effects in render order: [{ name, slot, order, enabled }]
86
78
  * @returns {{ name: string, slot: PostSlot, order: number, enabled: boolean }[]}
package/types/nav.d.ts CHANGED
@@ -5,7 +5,7 @@ import type { XZ, PositionLike } from './common';
5
5
  export interface NavOptions {
6
6
  /** Voxel cell size (meters), default 0.3; smaller is more accurate but slower to build */
7
7
  cellSize?: number;
8
- /** Character radius (meters), default reads engine.movement.radius (this is an override) */
8
+ /** Character radius (meters), default reads engine.movement.radius (this is an override). The mesh built at load; a path with another radius gets a mesh of its own, on first ask */
9
9
  agentRadius?: number;
10
10
  /** Character height (meters), default reads engine.movement.height */
11
11
  agentHeight?: number;
@@ -25,6 +25,36 @@ export interface NavOptions {
25
25
  maxAgents?: number;
26
26
  /** Meters past the character's radius a path may end short of its goal and still count as arrived, default 0.6 */
27
27
  arrive?: number;
28
+ /** Places joined by a jump or a climb instead of walking (Recast off-mesh connections); walkers cross them straight unless the game says otherwise @experimental */
29
+ links?: NavLink[];
30
+ }
31
+
32
+ /** One link of nav({ links }) @experimental */
33
+ export interface NavLink {
34
+ /** Name in path points and link events; default its index */
35
+ id?: string | number;
36
+ /** One end, on or near walkable ground (no y: the ground there). A link joins neighbouring tiles at most: keep it under tileSize x cellSize meters */
37
+ from: PositionLike;
38
+ /** The other end */
39
+ to: PositionLike;
40
+ /** Only from -> to, default false */
41
+ oneWay?: boolean;
42
+ /** How far (meters) an end may be from the mesh and still attach, default the agent radius + 2 cells */
43
+ radius?: number;
44
+ }
45
+
46
+ /** A path point that starts a link: the leg to the next point is the crossing @experimental */
47
+ export interface NavPathPoint extends XZ {
48
+ link?: { id: string | number; from: { x: number; y: number; z: number }; to: { x: number; y: number; z: number } };
49
+ }
50
+
51
+ /** A crossing under way: plain data, saved with an NPC. seconds may be set at link:enter @experimental */
52
+ export interface LinkCrossing {
53
+ link: string | number;
54
+ from: { x: number; y: number; z: number };
55
+ to: { x: number; y: number; z: number };
56
+ seconds: number;
57
+ time: number;
28
58
  }
29
59
 
30
60
  /**
@@ -35,6 +65,8 @@ export interface NavOptions {
35
65
  export interface Nav {
36
66
  /** The navmesh has been generated */
37
67
  readonly ready: boolean;
68
+ /** The links in effect, ends in 3D, in the order given to nav({ links }); empty until the mesh is built @experimental */
69
+ readonly links: readonly { id: string | number; from: { x: number; y: number; z: number }; to: { x: number; y: number; z: number }; oneWay: boolean; radius: number }[];
38
70
  /** Native Recast NavMesh (null until ready) @experimental */
39
71
  navMesh: any;
40
72
  /** Native Recast NavMeshQuery @experimental */
@@ -47,10 +79,10 @@ export interface Nav {
47
79
  helper: any;
48
80
  /** +1 on rebuild / unload: code that cached native objects (crowd agents etc.) must recreate them when it changes @experimental */
49
81
  readonly version: number;
50
- /** Path from from to to [{ x, z }…] (meters); null if not ready or unreachable. Usually use engine.characters.findPath */
51
- findPath(from: PositionLike, to: PositionLike, opts?: { radius?: number; detailed?: false }): XZ[] | null;
82
+ /** Path from from to to [{ x, y, z }…] (meters); null if not ready or unreachable; radius: the body it must fit, default agentRadius. Usually use engine.characters.findPath */
83
+ findPath(from: PositionLike, to: PositionLike, opts?: { radius?: number; detailed?: false }): NavPathPoint[] | null;
52
84
  /** Pass detailed: true: returns { status: 'ok' | 'noPath' | 'notReady', path }, telling "unreachable" from "mesh not generated yet" */
53
- findPath(from: PositionLike, to: PositionLike, opts: { radius?: number; detailed: true }): { status: 'ok' | 'noPath' | 'notReady'; path: XZ[] | null };
85
+ findPath(from: PositionLike, to: PositionLike, opts: { radius?: number; detailed: true }): { status: 'ok' | 'noPath' | 'notReady'; path: NavPathPoint[] | null };
54
86
  /** Character size actually in effect (from engine.movement, or the override in nav()) @experimental */
55
87
  readonly agent: { radius: number; height: number; maxClimb: number; maxSlope: number } | null;
56
88
  /** Unload the navmesh (frees native objects); characters.findPath then falls back to A* */
@@ -112,6 +112,8 @@ export interface RigidOptions {
112
112
  treeRadius?: number;
113
113
  /** Player capsule size (meters), default computed from engine.movement radius / height @experimental */
114
114
  playerCapsule?: { halfHeight: number; radius: number };
115
+ /** The flat plane at y = 0 when the ground has no collision of its own, default true. false: only your own bodies and colliders are there (a sky of islands) */
116
+ fallbackFloor?: boolean;
115
117
  }
116
118
  /** Parameters for adding a physics body */
117
119
  export interface RigidBodyOptions {
@@ -165,18 +167,38 @@ export interface RigidEntry extends Handle {
165
167
 
166
168
  /** Options of engine.rigid.ragdoll @experimental */
167
169
  export interface RagdollOptions {
168
- /** A push (kg*m/s) on the part nearest position, else on hips. A hit stronger than the part can take spreads to the whole body, total momentum unchanged */
170
+ /** A push (kg*m/s) on the part nearest position, else on the root part. A hit stronger than the part can take spreads to the whole body, total momentum unchanged */
169
171
  impulse?: Vec3Like;
170
172
  /** Where the push lands (world) */
171
173
  position?: PositionLike;
172
- /** Part -> bone name or bone, over the auto-detection. Parts: hips, chest, head, upperArmL, lowerArmL, upperArmR, lowerArmR, upperLegL, lowerLegL, upperLegR, lowerLegR */
174
+ /** Humanoid graph only: part -> bone name or bone, over the auto-detection. Parts: hips, chest, head, upperArmL, lowerArmL, upperArmR, lowerArmR, upperLegL, lowerLegL, upperLegR, lowerLegR */
173
175
  bones?: Record<string, string | Object3D>;
174
176
  /** Part or kind ('lowerLeg', 'upperArm', 'chest', 'head'...) -> [min, max] radians from the bind pose: bend forward (a knee: backward), side, twist along the bone */
175
177
  limits?: Record<string, { bend?: [number, number]; side?: [number, number]; twist?: [number, number] }>;
176
- /** Whole body, kg (default 70) */
178
+ /** Whole body, kg (default the graph's; humanoid 70). The graph's proportions stay */
177
179
  mass?: number;
178
180
  }
179
181
 
182
+ /** One part of a ragdoll graph, the value of the rule 'ragdoll.graph': { body: { bone: 'Spine' }, tail: { bone: 'Tail1', parent: 'body', mass: 2 } } @experimental */
183
+ export interface RagdollPart {
184
+ /** Bone name or bone */
185
+ bone: string | Object3D;
186
+ /** The part this one hangs from; its bone must be above this bone. Exactly one part has none: the root, which leads the body */
187
+ parent?: string;
188
+ /** Range of motion, [min, max] radians from the bind pose; default loose (45° bend and side, 30° twist) */
189
+ limits?: { bend?: [number, number]; side?: [number, number]; twist?: [number, number] };
190
+ /** kg; default 70 shared equally */
191
+ mass?: number;
192
+ /** The part this bone points at; default the middle of its child parts, then its first child bone. 'top' measures it from the mesh along up (a head) */
193
+ end?: string;
194
+ /** Which way a positive bend moves the tip, in bind space; default [0, 0, 1] */
195
+ forward?: Vec3Like;
196
+ /** Fallback for forward and the direction of end: 'top'; default [0, 1, 0] */
197
+ up?: Vec3Like;
198
+ /** Name shared by several parts, so one limits entry of rigid.ragdoll covers them ('leg') */
199
+ kind?: string;
200
+ }
201
+
180
202
  /** What engine.rigid.ragdoll returns. remove() gives the character back; safe to call twice @experimental */
181
203
  export interface Ragdoll extends Handle {
182
204
  /** False once removed (remove(), a load, the character deleted) */
@@ -187,6 +209,25 @@ export interface Ragdoll extends Handle {
187
209
  readonly parts: Record<string, RigidEntry>;
188
210
  }
189
211
 
212
+ /** A hit of Collider3D.sweep */
213
+ export interface SweepHit {
214
+ /** The ball's center at the hit */
215
+ point: Vector3;
216
+ /** World direction out of what it hit */
217
+ normal: Vector3;
218
+ /** How far the ball got (meters) */
219
+ distance: number;
220
+ }
221
+ /** engine.collider3d: collision on all three axes (modules/rigid/collider3d.contract.js). rigid provides it; engine.use(mine(), { replaces: 'collider3d' }) swaps in your own @experimental */
222
+ export interface Collider3D {
223
+ /** A fixed solid turned any way. size [x, y, z] for a box or radius for a ball; rotation [x, y, z] radians or a quaternion. Callable before start(); newGame and a load keep it. engine.collision does not know it */
224
+ addSolid(opts: { position: PositionLike; size?: number[]; radius?: number; rotation?: number[] | { x: number; y: number; z: number; w: number }; friction?: number }): Handle;
225
+ /** Is a ball here inside something solid. Skips the player's capsule */
226
+ overlap(position: PositionLike, radius?: number): boolean;
227
+ /** Move a ball from there to there: null when clear, else the first hit. Skips the player's capsule */
228
+ sweep(from: PositionLike, to: PositionLike, radius?: number): SweepHit | null;
229
+ }
230
+
190
231
  /** engine.rigid (real physics; bodies can only be added after start(), or in the engine:ready event) */
191
232
  export interface RigidBodies {
192
233
  /** Is the physics engine ready (downloaded and initialized at start()) */
@@ -215,7 +256,8 @@ export interface RigidBodies {
215
256
  /**
216
257
  * Turn a skinned character limp in one call; rd.remove() returns it to animation. who: a Character, an NPC handle, a character id or a skinned Object3D.
217
258
  * Its mover, animator, capsule and camera yield until then; calling again on the same one pushes it again and returns the same ragdoll.
218
- * Not saved: any load ends it. A skeleton it cannot read throws, naming the missing parts. @experimental
259
+ * Not saved: any load ends it. A skeleton it cannot read throws, naming the missing parts. The rule 'ragdoll.graph' (per character id) gives the parts: 'humanoid' (default),
260
+ * Record<string, RagdollPart> for any other body, a function (facts: { character, root, mesh }, engine) => one of those, or false for no ragdoll (returns null). @experimental
219
261
  */
220
262
  ragdoll(who: any, opts?: RagdollOptions): Ragdoll | null;
221
263
  /** Give it a push: impulse vector impulse (Vector3 / [x, y, z] / { x, y, z }), e.g. impulse(ball, [0, 3, 5]) */
@@ -288,7 +330,7 @@ export interface Vehicle extends RigidEntry, Rideable {
288
330
  /** World position of a seat (default 0, the driver's) */
289
331
  seatPosition(seat?: number): Vector3;
290
332
  /** Where to get out of a seat (outside the door on that seat's side, world coordinates) */
291
- exitPosition(seat?: number): Vector3;
333
+ exitPosition(seat?: number, n?: number): Vector3;
292
334
  }
293
335
  /**
294
336
  * What character.enter(vehicle) needs from anything it rides (modules/characters/vehicle.contract.js): rigid.addWheeled's car passes it, and so does a
@@ -316,7 +358,7 @@ export interface Rideable {
316
358
  /** World position of a seat (default 0, the driver's; a rider is kept there) */
317
359
  seatPosition(seat?: number): Vector3 | Vec3Like;
318
360
  /** Where to get out of a seat (world coordinates; rigid cars: outside the door on that seat's side) */
319
- exitPosition(seat?: number): Vector3 | Vec3Like;
361
+ exitPosition(seat?: number, n?: number): Vector3 | Vec3Like;
320
362
  }
321
363
 
322
364
  // ======================================================================
@@ -422,6 +464,8 @@ export interface CameraRigBase {
422
464
  kind: CameraKind;
423
465
  /** The object being followed */
424
466
  target: Object3D | null;
467
+ /** The pixelSnap option at work, or null: grid (give it to pixelSprite), error (last rounding in art pixels), agrees (false: something else set the view height, rounding stopped) */
468
+ pixelSnap?: { readonly grid: import('./pixel').PixelGrid; readonly error: { x: number; y: number }; readonly agrees: boolean; bounds: import('./pixel').PixelBounds | null } | null;
425
469
  /** Follow someone (called automatically when the player is created), null to cancel. opts temporarily changes distance / height (used while driving), restored when the target changes */
426
470
  follow(obj: Object3D | null, opts?: { distance?: number; height?: number }): void;
427
471
  /** The "forward" direction on the horizontal plane (player movement is relative to it) */
@@ -491,6 +535,8 @@ export interface FollowCameraOptions {
491
535
  hideTargetNear?: number;
492
536
  /** Layer used to hide the followed object (0-31), default 30 */
493
537
  hideLayer?: number;
538
+ /** Art-pixel rounding, orthographic only: rounds the camera on screen axes, clamps to bounds there first, and decides the view height (buffer height / pixelsPerMeter), so no size with it. Recipe 62 section 4b */
539
+ pixelSnap?: { pixelsPerMeter: number; bounds?: import('./pixel').PixelBounds | null };
494
540
  }
495
541
  /** What a followCamera({ ground: fn }) function receives each frame */
496
542
  export interface FollowCameraGroundFacts {
@@ -522,7 +568,7 @@ export interface FollowCameraView {
522
568
  look: Vec3Like;
523
569
  }
524
570
  /** Third-person follow camera */
525
- export interface FollowCamera extends CameraRigBase, Required<Omit<FollowCameraOptions, 'lockPitch'>> {
571
+ export interface FollowCamera extends CameraRigBase, Required<Omit<FollowCameraOptions, 'lockPitch' | 'pixelSnap'>> {
526
572
  /** Smoothed follow point */
527
573
  focus: Vector3;
528
574
  lockPitch?: boolean;
@@ -602,6 +648,8 @@ export interface CameraShot {
602
648
  }
603
649
  /** fixedCamera / setCamera('fixed', ...) options; the shot fields (position, lookAt, projection, size...) at the top level are a one-shot form: shots = { main: them } */
604
650
  export interface FixedCameraOptions extends Partial<CameraShot> {
651
+ /** Art-pixel rounding, orthographic only: rounds the camera on screen axes, clamps to bounds there first, and decides the view height (buffer height / pixelsPerMeter), so no size with it. Recipe 62 section 4b */
652
+ pixelSnap?: { pixelsPerMeter: number; bounds?: import('./pixel').PixelBounds | null };
605
653
  /** Shots: name → shot */
606
654
  shots?: Record<string, CameraShot>;
607
655
  /** Initial shot name */
@@ -0,0 +1,75 @@
1
+ // threedog/pixel: art pixel math on an orthographic camera, and a sprite built on it. See recipes/62-picture-code.md section 4b.
2
+ import type { Camera, Material, Mesh, Vector3 } from 'three';
3
+
4
+ type Point = { x: number; y: number; z: number };
5
+
6
+ /** Level rectangle for a camera's pixelSnap, world units. minY / maxY default to 0 (flat ground) */
7
+ export interface PixelBounds { minX: number; maxX: number; minZ: number; maxZ: number; minY?: number; maxY?: number }
8
+
9
+ export interface PixelGrid {
10
+ readonly camera: Camera;
11
+ readonly pixelsPerMeter: number;
12
+ /** World size of one art pixel: 1 / pixelsPerMeter */
13
+ readonly cell: number;
14
+ /** The camera's unit axes now (reused between calls). Throws on a perspective camera */
15
+ axes(): { right: Vector3; up: Vector3; forward: Vector3 };
16
+ /** World point to meters along the screen axes: x right, y up, z forward */
17
+ toScreen(world: Point, out?: Vector3): Vector3;
18
+ /** Meters along the screen axes to a world point */
19
+ toWorld(screen: Point, out?: Vector3): Vector3;
20
+ /** World point rounded to the art grid on the two screen axes; depth stays */
21
+ snap(world: Point, out?: Vector3): Vector3;
22
+ /** How far snap moves this point, in art pixels (-0.5 to 0.5) */
23
+ error(world: Point): { x: number; y: number };
24
+ /** snap for the one object the camera follows: takes the camera's own rounding, so the two step together */
25
+ snapFollowed(world: Point, out?: Vector3): Vector3;
26
+ /** World units of view height a picture of `rows` art pixels needs */
27
+ viewHeight(rows: number): number;
28
+ /** Does the camera show exactly rows / pixelsPerMeter of the world? camera.zoom counts */
29
+ agrees(rows: number): boolean;
30
+ /** Where a camera wanting position goes: clamp on the screen axes, then round. Result reused between calls */
31
+ place(position: Point, view: { columns: number; rows: number; bounds?: PixelBounds | null }): { position: Vector3; error: { x: number; y: number } };
32
+ }
33
+
34
+ /**
35
+ * The art pixel grid of an orthographic camera. Pure math.
36
+ * @example
37
+ * const grid = pixelGrid({ camera: engine.camera, pixelsPerMeter: 32 });
38
+ * const drawn = grid.snap(thing.position);
39
+ */
40
+ export function pixelGrid(options: { camera: Camera; pixelsPerMeter: number }): PixelGrid;
41
+
42
+ export interface PixelSpriteOptions {
43
+ /** From pixelGrid(), or engine.cameraRig.pixelSnap.grid */
44
+ grid: PixelGrid;
45
+ /** Your own three.js material; the engine brings no look */
46
+ material: Material;
47
+ /** One frame's width in texels */
48
+ width: number;
49
+ /** One frame's height in texels */
50
+ height: number;
51
+ /** Frames across the sheet (default 1) */
52
+ columns?: number;
53
+ /** Frames down the sheet (default 1) */
54
+ rows?: number;
55
+ /** Starting frame, left to right, top to bottom */
56
+ frame?: number;
57
+ /** Start mirrored */
58
+ flip?: boolean;
59
+ /** The point of the frame at the mesh's origin, 0 to 1 from the bottom left; default [0.5, 0], the feet. Rounds to a whole texel */
60
+ anchor?: [number, number];
61
+ /** 'world' (default) rounds the drawn position to the grid; 'followed' is for the one object the camera follows; false leaves it exact */
62
+ snap?: 'world' | 'followed' | false;
63
+ }
64
+
65
+ /**
66
+ * A plain THREE.Mesh: a vertical plane that turns around Y with the camera's forward direction, stretched so one texel is one art pixel.
67
+ * Works as a character's `model`. mesh.position stays exact; only what is drawn is rounded.
68
+ * @example
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 });
71
+ */
72
+ export function pixelSprite(options: PixelSpriteOptions): Mesh;
73
+
74
+ /** Show a sheet frame (left to right, top to bottom); flip mirrors it, left out it stays as it was */
75
+ export function spriteFrame(mesh: Mesh, frame: number, flip?: boolean): Mesh;
package/types/world.d.ts CHANGED
@@ -145,6 +145,8 @@ export interface TerrainOptions extends Partial<TerrainConfig> {
145
145
  density?: number;
146
146
  /** true: the signal engine.uniforms.uViewDistance follows the view distance, so a game's fog can read it and fade the far chunk edge out (openWorld() sets true) */
147
147
  viewFog?: boolean;
148
+ /** true: do not take the ground slot; compositeGround({ parts: [{ of: 'terrain' }] }) does and reads terrain.ground (so a terrain and a level can both run) */
149
+ part?: boolean;
148
150
  /** Ground material (default neutral gray with vertex colors); chunks have position, normal, color and uv = world xz / chunk size. Cloud shadows, season tint and detail are added */
149
151
  material?: Material | ((engine: Engine) => Material);
150
152
  /** With material: false = draw it exactly as given, no cloud shadow / season / detail patch */
@@ -275,18 +277,14 @@ export interface Terrain {
275
277
  readonly voidY: number;
276
278
  /** Loaded chunks: 'cx,cz' → chunk */
277
279
  chunks: Map<string, TerrainChunk>;
278
- /** View distance (in chunks); writing it takes effect like setViewChunks @experimental */
280
+ /** View distance (in chunks). Writing it moves the camera far plane out too, and with viewFog uViewDistance @experimental */
279
281
  viewChunks: number;
280
- /** Vegetation density multiplier; writing it takes effect like setDensity */
282
+ /** Vegetation density multiplier. Writing it places plants again on the loaded chunks: it thins plants without a collider, blocking plants stand at every density, so collision does not change */
281
283
  density: number;
282
284
  /** Time budget (milliseconds) for uploading chunks per frame */
283
285
  applyBudgetMs: number;
284
286
  /** Statistics (for the debug panel); failed = chunks that failed every try (terrain:chunkFailed) */
285
287
  stats: { builtThisFrame: number; applyMs: number; queued: number; failed: number; visible?: number; loaded?: number; instances?: number };
286
- /** Change the view distance (in chunks); camera far plane and, with viewFog, uViewDistance adjust too @experimental */
287
- setViewChunks(n: number): void;
288
- /** Change the vegetation density: plants are placed again on the loaded chunks; the ground and its collision stay @experimental */
289
- setDensity(d: number): void;
290
288
  /**
291
289
  * Draw these chunks: the hooks a draw part that replaces 'terrain-draw' uses. add(c): generated (c.data holds pos / nor / col / uv / tex arrays,
292
290
  * c.cx / c.cz the chunk); change(c): an edit rewrote c.data (the vertex count can differ on the rim of a shape with diagonal 'adaptive'); remove(c): released; show(c, visible): in view or not.
@@ -835,8 +833,16 @@ export type { WeatherDraw };
835
833
  * rectangle
836
834
  */
837
835
  export interface WaterBodyOptions {
838
- position: PositionLike;
839
- level: number;
836
+ position?: PositionLike;
837
+ level?: number;
838
+ /** Your own water (the engine draws nothing): level at (x, z) for a body at height y, or null where this body has none */
839
+ query?: (x: number, z: number, y?: number) => number | null;
840
+ /** Box3-like { min, max } that lets waterAt skip the query outside it */
841
+ bounds?: { min: { x: number; y: number; z: number }; max: { x: number; y: number; z: number } };
842
+ /** The mesh you draw for it (kept for reference; add it to the scene yourself) */
843
+ mesh?: Object3D;
844
+ /** A plain volume with contains({ x, y, z }); with level it is water inside the volume */
845
+ volume?: { contains(p: { x: number; y: number; z: number }): boolean; bounds?: WaterBodyOptions['bounds'] };
840
846
  radius?: number;
841
847
  halfWidth?: number;
842
848
  halfDepth?: number;
package/ui/Parts.js CHANGED
@@ -79,11 +79,18 @@ export class UIParts {
79
79
  * @param {string} name
80
80
  * @param {UIPartFactory} factory default implementation (engine, options) => part
81
81
  * @param {UIPartDef} [def] on: shown unless the game asks (default true); multi: one part per item (markers, counters); modal: full-screen, opened with ui.open
82
- * @returns {void}
82
+ * @returns {{ remove(): void }} remove() closes the part, disposes its live copy and takes the definition out (what a module's ctx.ui.define does when it leaves)
83
83
  * @example engine.ui.define('hud.ammo', (e, o) => ({ update: d => {...} }), { multi: true })
84
84
  */
85
85
  define(name, factory, { on = true, multi = false, modal = null } = {}) {
86
- this.defs.set(name, { factory, on, multi, modal });
86
+ const d = { factory, on, multi, modal };
87
+ this.defs.set(name, d);
88
+ return { remove: () => {
89
+ if (this.defs.get(name) !== d) return;
90
+ this.close(name);
91
+ this.live.get(name)?.dispose?.();
92
+ this.live.delete(name); this.defs.delete(name);
93
+ } };
87
94
  }
88
95
 
89
96
  /**
package/ui/theme.js CHANGED
@@ -17,7 +17,7 @@ const DEFAULT_UI = {
17
17
  const BASE_CSS = `
18
18
  :where(.threedog-root > *){pointer-events:auto}
19
19
  .threedog-ui{font:14px/1.55 var(--threedog-font);color:var(--threedog-fg)}
20
- .threedog-win{box-sizing:border-box;position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);width:min(480px,calc(100% - 32px));
20
+ .threedog-win{box-sizing:border-box;overflow-wrap:anywhere;position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);width:min(480px,calc(100% - 32px));
21
21
  max-height:min(70%,560px);overflow:auto;
22
22
  background:var(--threedog-bg);border:1px solid var(--threedog-line);border-radius:var(--threedog-radius);padding:16px 18px;z-index:25;
23
23
  box-shadow:var(--threedog-shadow)}
@@ -45,7 +45,7 @@ const BASE_CSS = `
45
45
  .threedog-prompt{position:fixed;left:0;top:0;transform:translate(-50%,-100%);padding:6px 10px;border-radius:var(--threedog-radius-small);background:var(--threedog-bg);
46
46
  color:var(--threedog-fg);font:13px var(--threedog-font);cursor:pointer;z-index:15;white-space:nowrap}
47
47
  .threedog-prompt-hold{background:linear-gradient(90deg,var(--threedog-accent) calc(var(--progress,0)*100%),var(--threedog-bg) 0)}
48
- .threedog-dlg{position:fixed;left:50%;transform:translateX(-50%);bottom:calc(24px + env(safe-area-inset-bottom,0px));
48
+ .threedog-dlg{box-sizing:border-box;overflow-wrap:anywhere;position:fixed;left:50%;transform:translateX(-50%);bottom:calc(24px + env(safe-area-inset-bottom,0px));
49
49
  width:min(640px,calc(100% - 32px));
50
50
  background:var(--threedog-bg);color:var(--threedog-fg);border:1px solid var(--threedog-line);border-radius:var(--threedog-radius);
51
51
  padding:14px 18px 16px;font:15px/1.6 var(--threedog-font);z-index:20;cursor:pointer}
@@ -1,32 +0,0 @@
1
- // engine.camera's class: a THREE.PerspectiveCamera that can also draw orthographic (camera rigs with projection: 'orthographic').
2
- //
3
- // Why a subclass and not a swap to THREE.OrthographicCamera: engine.camera is one object that the render pass, post chain, cascaded shadows,
4
- // sky, particles and every module hold a reference to; a swap would leave them drawing with the old camera. Why not a method replaced on the
5
- // instance: that would be a second, invisible takeover form on a plain three.js object that nothing reports. Here the behavior is the class's
6
- // own method, marked by camera.isEngineCamera and reported by describe().camera.projection; a game that wants a real THREE.OrthographicCamera renders with its own (engine.renderer.render(scene, cam)).
7
- // While orthoSize is set, isPerspectiveCamera / isOrthographicCamera and left / right / top / bottom follow, so code that branches on the camera
8
- // type (three's renderer, raycaster, CSM) keeps working. Resize needs nothing extra: the resize follow-up (canvasBox.js) writes camera.aspect and calls updateProjectionMatrix().
9
- import * as THREE from 'three';
10
-
11
- export class EngineCamera extends THREE.PerspectiveCamera {
12
- constructor(fov, aspect, near, far) {
13
- super(fov, aspect, near, far);
14
- /** World units covered by the view height while orthographic (before zoom); 0 = perspective. Set through a camera rig's projection */
15
- this.orthoSize = 0;
16
- /** Marks engine.camera's class (minified builds rename it): the orthographic switch lives in this class, never on the instance */
17
- this.isEngineCamera = true;
18
- }
19
- updateProjectionMatrix() {
20
- if (!this.orthoSize) return super.updateProjectionMatrix();
21
- const top = this.orthoSize / 2 / this.zoom, right = top * this.aspect;
22
- this.left = -right; this.right = right; this.top = top; this.bottom = -top;
23
- this.projectionMatrix.makeOrthographic(-right, right, top, -top, this.near, this.far, this.coordinateSystem);
24
- this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
25
- }
26
- copy(source, recursive) {
27
- super.copy(source, recursive);
28
- this.orthoSize = source.orthoSize ?? 0;
29
- this.isOrthographicCamera = !!this.orthoSize; this.isPerspectiveCamera = !this.orthoSize;
30
- return this;
31
- }
32
- }