threedog 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +4 -4
  3. package/core/assets/Animator.js +66 -12
  4. package/core/assets/ik.js +144 -18
  5. package/core/assets/maskLayer.js +377 -0
  6. package/core/assets/rootMotion.js +148 -0
  7. package/core/audio/Audio.js +100 -4
  8. package/core/base/errorCodes.js +6 -369
  9. package/core/base/errorCodesModules.js +378 -0
  10. package/core/engine/Engine.js +8 -5
  11. package/core/engine/Loading.js +8 -4
  12. package/core/engine/copies.js +1 -1
  13. package/core/engine/headlessLoad.js +15 -4
  14. package/core/engine/lifecycle.js +1 -0
  15. package/core/engine/loop.js +23 -3
  16. package/core/engine/moduleSlots.js +3 -7
  17. package/core/engine/modules.js +30 -58
  18. package/core/engine/startup.js +3 -3
  19. package/core/input/Input.js +7 -3
  20. package/core/input/inputContext.js +3 -2
  21. package/core/input/inputSeat.js +1 -1
  22. package/core/inspect/DebugOverrides.js +1 -1
  23. package/core/inspect/Describe.js +7 -2
  24. package/core/inspect/describeRender.js +4 -1
  25. package/core/inspect/describeText.js +2 -2
  26. package/core/inspect/metadata.generated.js +380 -74
  27. package/core/inspect/pictureMenu.js +2 -0
  28. package/core/inspect/pictureWriters.js +4 -3
  29. package/core/ops/Ops.js +9 -3
  30. package/core/ops/actor.js +10 -0
  31. package/core/ops/control.js +17 -6
  32. package/core/ops/holds.js +1 -1
  33. package/core/ops/opsAtomic.js +6 -1
  34. package/core/ops/opsGuard.js +2 -2
  35. package/core/ops/owned.js +37 -11
  36. package/core/ops/sharedPoint.js +5 -1
  37. package/core/ops/stacks.js +30 -7
  38. package/core/saves/Saves.js +0 -2
  39. package/core/saves/saveApply.js +7 -7
  40. package/core/saves/session.js +6 -3
  41. package/core/saves/stateReplace.js +71 -41
  42. package/core/scene/Rays.js +74 -26
  43. package/core/scene/canvasBox.js +9 -0
  44. package/core/scene/gameLights.js +19 -11
  45. package/core/scene/sceneDelta.js +8 -4
  46. package/core/scene/sceneMethods.js +2 -1
  47. package/core/stream/chunkStream.js +21 -0
  48. package/core/stream/dirtyWatch.js +37 -0
  49. package/core/time/skip.js +9 -6
  50. package/core/time/time.js +72 -18
  51. package/docs/AI.md +22 -21
  52. package/docs/API.md +5 -4
  53. package/docs/CODEMAP.md +16 -10
  54. package/docs/COMMANDS.md +5 -5
  55. package/docs/CONVENTIONS.md +9 -25
  56. package/docs/api/ambience.md +1 -0
  57. package/docs/api/assets.md +10 -3
  58. package/docs/api/audio.md +5 -3
  59. package/docs/api/decals.md +16 -0
  60. package/docs/api/engine.md +1 -0
  61. package/docs/api/tools.md +3 -1
  62. package/docs/api/water.md +3 -0
  63. package/docs/recipes/09-materials-lights-models.md +15 -1
  64. package/docs/recipes/13-animation.md +51 -10
  65. package/docs/recipes/16-dev-bridge.md +4 -4
  66. package/docs/recipes/31-audio.md +15 -9
  67. package/docs/recipes/34-environment-lighting.md +11 -1
  68. package/docs/recipes/44-water-weather-hooks.md +1 -0
  69. package/examples/action/.threedog/content-index.json +1 -0
  70. package/examples/perf-island/.threedog/content-index.json +1 -0
  71. package/examples/plain-picture/.threedog/content-index.json +1 -0
  72. package/examples/rc2d/.threedog/content-index.json +1 -0
  73. package/examples/styletest/.threedog/content-index.json +1 -0
  74. package/examples/techniques/outlines-and-rim/main.js +1 -1
  75. package/examples/techniques/procedural-surface/main.js +1 -1
  76. package/examples/techniques/stylized-shading/main.js +1 -1
  77. package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
  78. package/examples/world/.threedog/content-index.json +1 -0
  79. package/index.d.ts +6 -2
  80. package/index.js +3 -2
  81. package/llms.txt +11 -10
  82. package/modules/ambience/Ambience.js +97 -15
  83. package/modules/camera/common.js +18 -12
  84. package/modules/characters/Character.js +30 -3
  85. package/modules/characters/NPC.js +2 -5
  86. package/modules/characters/astar.js +45 -14
  87. package/modules/characters/movers/rapier.js +53 -41
  88. package/modules/characters/movers/simple.js +37 -24
  89. package/modules/characters/npcView.js +2 -2
  90. package/modules/characters/pathAsync.js +3 -3
  91. package/modules/collision/contract.js +2 -2
  92. package/modules/content/index.js +3 -0
  93. package/modules/content/models.js +11 -4
  94. package/modules/content/templates.js +11 -11
  95. package/modules/debug/DebugPanel.js +1 -0
  96. package/modules/decals/Decals.js +393 -0
  97. package/modules/decals/index.js +1 -0
  98. package/modules/gameplay/Container.js +2 -0
  99. package/modules/gameplay/Containers.js +17 -3
  100. package/modules/gameplay/Dialogue.js +1 -1
  101. package/modules/gameplay/Interactions.js +7 -6
  102. package/modules/gameplay/Inventory.js +5 -1
  103. package/modules/gameplay/Quests.js +4 -3
  104. package/modules/gameplay/inventoryOps.js +2 -2
  105. package/modules/gameplay/pickups.js +32 -12
  106. package/modules/gameplay/questSave.js +2 -2
  107. package/modules/grid/index.js +8 -2
  108. package/modules/hud/index.js +1 -1
  109. package/modules/level/heightfield.js +1 -0
  110. package/modules/level/index.js +3 -2
  111. package/modules/level/nodes.js +2 -1
  112. package/modules/lights/index.js +27 -4
  113. package/modules/lights/slots.js +33 -16
  114. package/modules/nav/contract.js +4 -4
  115. package/modules/nav/index.js +6 -2
  116. package/modules/net/Client.js +24 -11
  117. package/modules/net/Host.js +73 -20
  118. package/modules/net/index.js +33 -21
  119. package/modules/net/sync.js +38 -8
  120. package/modules/net/transports.js +7 -3
  121. package/modules/particles/Particles.js +11 -4
  122. package/modules/particles/contract.js +6 -6
  123. package/modules/particles/effect.js +0 -1
  124. package/modules/rigid/RigidBodies.js +69 -57
  125. package/modules/rigid/Vehicles.js +8 -7
  126. package/modules/rigid/ragdoll.js +4 -6
  127. package/modules/rigid/rapierCompat.js +90 -0
  128. package/modules/rigid/sync.js +2 -5
  129. package/modules/settings/Settings.js +10 -4
  130. package/modules/sky/Sky.js +10 -2
  131. package/modules/sky/environment.js +29 -13
  132. package/modules/sky/frame.js +2 -2
  133. package/modules/sky/shader.js +5 -2
  134. package/modules/sky/skyModule.js +2 -2
  135. package/modules/swarm/Swarm.js +3 -2
  136. package/modules/swarm/grid.js +12 -7
  137. package/modules/terrain/ChunkManager.js +16 -26
  138. package/modules/triggers/index.js +5 -6
  139. package/modules/vegetation/draw.js +62 -26
  140. package/modules/vegetation/groundChunks.js +8 -22
  141. package/modules/water/Water.js +152 -24
  142. package/modules/water/surface.js +43 -20
  143. package/modules/weather/weatherDraw.js +4 -1
  144. package/modules/world/World.js +21 -2
  145. package/modules/world/index.js +5 -0
  146. package/modules/world/persist.js +1 -0
  147. package/modules/world/records.js +3 -1
  148. package/modules/world/sim.js +3 -2
  149. package/modules/world/simFar.js +4 -2
  150. package/modules/world/state.js +7 -1
  151. package/package.json +2 -2
  152. package/presets.js +30 -0
  153. package/render/PostFX.js +24 -17
  154. package/render/backend.js +72 -31
  155. package/render/cascades.js +25 -14
  156. package/render/cascades.tsl.js +32 -21
  157. package/render/fogLook.js +2 -1
  158. package/render/fx/detail.tsl.js +3 -0
  159. package/render/fx/library.tsl.js +1 -1
  160. package/render/fx/particles.tsl.js +4 -18
  161. package/render/fx/pcss.tsl.js +2 -2
  162. package/render/fx/postWebGPU.tsl.js +47 -25
  163. package/render/fx/sky.tsl.js +6 -18
  164. package/render/fx/uniforms.tsl.js +16 -0
  165. package/render/fx/water.tsl.js +24 -5
  166. package/render/fxNumbers.js +2 -0
  167. package/render/impostor.tsl.js +10 -6
  168. package/render/lights.js +6 -6
  169. package/render/occlusion.js +17 -6
  170. package/render/patches.js +40 -28
  171. package/render/postWebGL.js +6 -4
  172. package/render/reflectionProbes.js +302 -0
  173. package/render/shaderErrors.js +18 -8
  174. package/render/shadowCache.tsl.js +10 -5
  175. package/render/shadows.js +70 -49
  176. package/render/threeCompat.js +166 -0
  177. package/types/core.d.ts +33 -3
  178. package/types/gameplay.d.ts +80 -0
  179. package/types/generated/core/audio/Audio.d.ts +18 -1
  180. package/types/generated/core/ops/Ops.d.ts +2 -1
  181. package/types/generated/core/ops/control.d.ts +7 -3
  182. package/types/generated/core/saves/session.d.ts +4 -1
  183. package/types/generated/modules/ambience/Ambience.d.ts +6 -0
  184. package/types/generated/modules/debug/DebugPanel.d.ts +1 -0
  185. package/types/generated/modules/grid/index.d.ts +27 -3
  186. package/types/generated/modules/net/index.d.ts +8 -3
  187. package/types/generated/modules/sky/Sky.d.ts +1 -0
  188. package/types/generated/modules/water/Water.d.ts +15 -0
  189. package/types/generated/modules/world/index.d.ts +5 -0
  190. package/types/generated/render/patches.d.ts +5 -0
  191. package/types/physics.d.ts +66 -9
  192. package/types/tsl.d.ts +2 -0
  193. package/types/world.d.ts +2 -0
  194. package/ui/Parts.js +3 -2
  195. package/docs/MIGRATING-0.7.md +0 -39
  196. package/docs/MIGRATING-0.8.md +0 -171
  197. package/modules/rigid/refresh.js +0 -10
package/render/shadows.js CHANGED
@@ -13,7 +13,7 @@ import { codedError } from '../core/base/errorHints.js';
13
13
  import { warnOnce, fmt } from '../core/base/validate.js';
14
14
  import { readParams } from '../core/base/params.js';
15
15
  import { defineOwned, dropOwned, ownedRow } from '../core/ops/owned.js';
16
- import { isWebGPU, onRendererSwap, setShadowUpdate, shadowsOn, webgpuPart } from './backend.js';
16
+ import { isWebGPU, onRendererSwap, redrawLightShadow, leftQuarter, shadowsOn, webgpuPart } from './backend.js';
17
17
  import { CASCADE_DEFAULTS, CASCADE_SPLITS, createCascades, dropCascades, includeInCascades } from './cascades.js';
18
18
 
19
19
  const WHERE = 'engine.shadows.cascades';
@@ -60,7 +60,7 @@ function readBox(o) {
60
60
  /** Where a light's box goes: the followed thing (and `ahead`), snapped. Shared by a game's light and the engine sun */
61
61
  function boxCenter(e, light) {
62
62
  const f = new THREE.Vector3(), r = new THREE.Vector3(), u = new THREE.Vector3(), ahead = new THREE.Vector3(), last = new THREE.Vector3();
63
- let key = '', seen = false;
63
+ let ka = NaN, kb = NaN, km = -1, seen = false;
64
64
  /** @param {THREE.Vector3} at written with the center @param {THREE.Vector3} dir unit vector toward the light @param {any} o the box options */
65
65
  return (at, dir, o) => {
66
66
  const cam = e.camera, s = light.shadow;
@@ -71,28 +71,28 @@ function boxCenter(e, light) {
71
71
  // ahead along the level part of the view, scaled by it (not normalized): a view tilting toward straight down slides the shift to 0 smoothly. Normalized
72
72
  // with a cut-off, a near-vertical camera jumped the whole shift for a tiny turn and a straight-down one got none
73
73
  if (o.ahead) { cam.getWorldDirection(ahead); ahead.y = 0; at.addScaledVector(ahead, o.ahead); }
74
- let now;
74
+ let na, nb, nm;
75
75
  if (o.snap === 'texel') {
76
76
  // the light-space right and up axes (matching the shadow camera lookAt), rounded to one shadow pixel along each
77
- const sc = s.camera, texel = (sc.right - sc.left) / s.mapSize.x;
77
+ const sc = s.camera, texX = (sc.right - sc.left) / s.mapSize.x, texY = (sc.top - sc.bottom) / s.mapSize.y;
78
78
  f.copy(dir).negate();
79
- r.crossVectors(f, cam.up); if (r.lengthSq() < 1e-8) r.set(1, 0, 0); r.normalize();
79
+ r.crossVectors(f, sc.up); if (r.lengthSq() < 1e-8) r.set(1, 0, 0); r.normalize();
80
80
  u.crossVectors(r, f);
81
- const a = Math.round(at.dot(r) / texel), b = Math.round(at.dot(u) / texel), c = at.dot(f);
82
- at.copy(r).multiplyScalar(a * texel).addScaledVector(u, b * texel).addScaledVector(f, c);
83
- now = a + ',' + b;
81
+ const a = Math.round(at.dot(r) / texX), b = Math.round(at.dot(u) / texY), c = at.dot(f);
82
+ at.copy(r).multiplyScalar(a * texX).addScaledVector(u, b * texY).addScaledVector(f, c);
83
+ na = a; nb = b; nm = 1;
84
84
  } else {
85
85
  const g = o.snap || 1e-3;
86
86
  at.x = Math.round(at.x / g) * g; at.z = Math.round(at.z / g) * g;
87
- now = at.x + ',' + at.z;
87
+ na = at.x; nb = at.z; nm = 0;
88
88
  }
89
89
  // under a budget: redraw early only when the center left a quarter of the box (teleport, fast travel); otherwise the budget's own rhythm
90
90
  if (!seen) { last.copy(at); seen = true; }
91
91
  // a kept map is only good while the light stands still, so the box holds until the center left a quarter of it; moving things stay inside it meanwhile
92
- if (s.shadowNode?.isCachedShadowNode) { if (last.distanceToSquared(at) > (s.camera.right / 4) ** 2) last.copy(at); else at.copy(last); key = now; return; }
93
- if (!s.autoUpdate && now !== key && last.distanceToSquared(at) > (s.camera.right / 4) ** 2) s.needsUpdate = true;
92
+ if (s.shadowNode?.isCachedShadowNode) { if (leftQuarter(last, at, s.camera.right)) last.copy(at); else at.copy(last); ka = na; kb = nb; km = nm; return; }
93
+ if (!s.autoUpdate && (na !== ka || nb !== kb || nm !== km) && leftQuarter(last, at, s.camera.right)) s.needsUpdate = true;
94
94
  if (s.needsUpdate) last.copy(at);
95
- key = now;
95
+ ka = na; kb = nb; km = nm;
96
96
  };
97
97
  }
98
98
 
@@ -100,39 +100,60 @@ function boxCenter(e, light) {
100
100
  function setExtent(light, ext) { const c = light.shadow.camera; c.left = c.bottom = -ext; c.right = c.top = ext; c.updateProjectionMatrix(); }
101
101
 
102
102
  /**
103
- * A box on a game's light: position and target hold the placement, what the game writes stays the direction (see the header)
104
- * @param {any} e @param {any} light @param {object} first
105
- * @param {number} [back] meters the light stands behind the center, the shadow camera reaching extent past it; left out: where the game put it, its near / far as they are
103
+ * Hold a stand-in target on a game's light so placement moves light.position / target without clobbering what the game wrote;
104
+ * later writes to light.position or light.target keep setting the direction, and restore() puts both back as the game left them.
105
+ * @param {any} light
106
106
  */
107
- function gameBox(e, light, first, back) {
108
- let o = readBox(first), sized = false;
109
- const sc = light.shadow.camera, was = { left: sc.left, right: sc.right, top: sc.top, bottom: sc.bottom, near: sc.near, far: sc.far };
107
+ function trackLightProxy(light) {
110
108
  const own = { position: light.position.clone(), target: light.target };
111
- const proxy = new THREE.Object3D(), placed = new THREE.Vector3(Infinity, 0, 0), at = new THREE.Vector3(), dir = new THREE.Vector3(), center = boxCenter(e, light);
109
+ const proxy = new THREE.Object3D(), placed = new THREE.Vector3(Infinity, 0, 0);
110
+ proxy.position.copy(light.target.position);
112
111
  light.target = proxy;
113
- const size = ext => { setExtent(light, ext); sized = true; };
114
- if (back !== undefined) Object.assign(sc, { near: 1, far: back + o.extent });
115
- if (o.extent !== undefined) size(o.extent);
116
- const readGame = () => {
112
+ const read = () => {
117
113
  if (light.target !== proxy) { own.target = light.target; light.target = proxy; }
118
114
  if (!light.position.equals(placed)) own.position.copy(light.position);
119
115
  };
120
116
  return {
121
- frame() {
122
- readGame();
117
+ proxy,
118
+ /** Sync game writes, compute world target position into `at` and vector toward the light into `dir` */
119
+ aim(at, dir) {
120
+ read();
123
121
  own.target.updateWorldMatrix(true, false);
124
122
  at.setFromMatrixPosition(own.target.matrixWorld);
125
123
  dir.copy(own.position).sub(at);
124
+ },
125
+ /** Record the placed light position and refresh the off-scene stand-in target */
126
+ mark() { placed.copy(light.position); proxy.updateMatrixWorld(); },
127
+ /** Put back the game's latest position and target */
128
+ restore() { read(); light.position.copy(own.position); light.target = own.target; },
129
+ };
130
+ }
131
+
132
+ /**
133
+ * A box on a game's light: position and target hold the placement, what the game writes stays the direction (see the header)
134
+ * @param {any} e @param {any} light @param {object} first
135
+ * @param {number} [back] meters the light stands behind the center, the shadow camera reaching extent past it; left out: where the game put it, its near / far as they are
136
+ */
137
+ function gameBox(e, light, first, back) {
138
+ let o = readBox(first), sized = false;
139
+ const sc = light.shadow.camera, was = { left: sc.left, right: sc.right, top: sc.top, bottom: sc.bottom, near: sc.near, far: sc.far };
140
+ const tr = trackLightProxy(light), at = new THREE.Vector3(), dir = new THREE.Vector3(), center = boxCenter(e, light);
141
+ const size = ext => { if (back !== undefined) sc.far = back + ext; setExtent(light, ext); sized = true; };
142
+ if (back !== undefined) { Object.assign(sc, { near: 1, far: back + (o.extent ?? sc.right) }); sc.updateProjectionMatrix(); sized = true; }
143
+ if (o.extent !== undefined) size(o.extent);
144
+ return {
145
+ frame() {
146
+ tr.aim(at, dir);
126
147
  const dist = dir.length();
127
148
  dir.normalize();
128
149
  if (o.follow !== false) center(at, dir, o);
129
- proxy.position.copy(at); proxy.updateMatrixWorld(); // not in the scene: nothing else refreshes it
130
- light.position.copy(at).addScaledVector(dir, back ?? dist); placed.copy(light.position);
150
+ tr.proxy.position.copy(at);
151
+ light.position.copy(at).addScaledVector(dir, back ?? dist);
152
+ tr.mark();
131
153
  },
132
154
  set(next) { o = readBox({ ...o, ...next }); if (next.extent !== undefined) size(o.extent); },
133
155
  remove() {
134
- readGame();
135
- light.position.copy(own.position); light.target = own.target;
156
+ tr.restore();
136
157
  if (sized) { Object.assign(sc, was); sc.updateProjectionMatrix(); } // never sized: what the game wrote there is the game's
137
158
  },
138
159
  };
@@ -145,7 +166,7 @@ function gameBox(e, light, first, back) {
145
166
  function sunBox(e, light, first, distance) {
146
167
  let o = readBox(first);
147
168
  const dir = new THREE.Vector3(), tp = light.target.position, center = boxCenter(e, light);
148
- const held = defineOwned(e, { id: 'shadow.follow', part: 'shadow', key: 'follow', read: () => tp.toArray(), objects: [light.target, tp],
169
+ const held = defineOwned(e, { id: 'shadow.follow', part: 'shadow', key: 'follow', read: out => (out ? (out[0] = tp.x, out[1] = tp.y, out[2] = tp.z, out.length = 3, out) : tp.toArray()), objects: [light.target, tp],
149
170
  levels: { manual: 'engine.shadows.box(engine.lights.sun, { follow: false })', back: "engine.shadows.box(engine.lights.sun, { follow: 'focus' })" } });
150
171
  if (o.extent !== undefined) setExtent(light, o.extent);
151
172
  if (o.follow === false) held.manual(true);
@@ -203,25 +224,30 @@ function switchShadows(e, on) {
203
224
  e.scene.traverse(o => { if (o.material) [].concat(o.material).forEach(m => { m.needsUpdate = true; }); });
204
225
  }
205
226
 
227
+ /** Stable key for cascade split options: distinct closure functions with identical source text still get distinct keys */
228
+ const splitIds = { map: new WeakMap(), next: 0 };
229
+ const splitKey = s => {
230
+ if (typeof s !== 'function') return s;
231
+ let id = splitIds.map.get(s);
232
+ if (id === undefined) splitIds.map.set(s, id = ++splitIds.next);
233
+ return 'fn#' + id;
234
+ };
235
+
206
236
  /** The running handle's cascades. The WebGL half keeps what the game wrote apart from the placement; see the header */
207
237
  function ownCascades(e, light, first, gameExtent = () => undefined) {
208
- let o = readOptions(first), c = null, key = '', own = null, box = null, sunSize = null; // sunSize: puts the engine sun's box size back
209
- const proxy = new THREE.Object3D(), placed = new THREE.Vector3(), dir = new THREE.Vector3();
210
- const readGame = () => {
211
- if (light.target !== proxy) { own.target = light.target; light.target = proxy; }
212
- if (!light.position.equals(placed)) own.position.copy(light.position);
213
- };
238
+ let o = readOptions(first), c = null, key = '', tr = null, box = null, sunSize = null; // sunSize: puts the engine sun's box size back
239
+ const at = new THREE.Vector3(), dir = new THREE.Vector3();
214
240
  const off = () => {
215
241
  box?.remove(); box = null;
216
242
  sunSize?.(); sunSize = null;
217
243
  if (!c) return;
218
- if (own) { readGame(); light.position.copy(own.position); light.target = own.target; own = null; }
244
+ if (tr) { tr.restore(); tr = null; }
219
245
  dropCascades(e);
220
246
  c = null; key = '';
221
247
  };
222
248
  const sync = () => {
223
249
  const n = e.tier === 'low' ? o.low?.count ?? 1 : o.count; // low tier: one map unless the game says so
224
- const want = (n > 1 ? [n, o.maxFar, o.fade, o.lightMargin, o.split] : [o.count, o.maxFar, o.lightMargin]).join('|'); // one map's size reads count too
250
+ const want = (n > 1 ? [n, o.maxFar, o.fade, o.lightMargin, splitKey(o.split)] : [o.count, o.maxFar, o.lightMargin]).join('|'); // one map's size reads count too
225
251
  if (want === key) return;
226
252
  off();
227
253
  key = want;
@@ -245,10 +271,7 @@ function ownCascades(e, light, first, gameExtent = () => undefined) {
245
271
  }
246
272
  c = createCascades(e, light, { ...o, cascades: n }, WHERE);
247
273
  if (c.isCascadeNode) return;
248
- own = { position: light.position.clone(), target: light.target };
249
- proxy.position.copy(light.target.position);
250
- placed.set(Infinity, 0, 0);
251
- light.target = proxy;
274
+ tr = trackLightProxy(light);
252
275
  e.scene.traverse(l => { // on WebGL the cascade order is the order of the shadow-casting lights
253
276
  if (l.isDirectionalLight && l.castShadow && l.visible && !c.lights.includes(l)) warnOnce(`${WHERE}: DirectionalLight '${l.name || l.uuid.slice(0, 8)}' casts shadows too, which breaks the cascade order; set castShadow = false on it`);
254
277
  });
@@ -262,12 +285,10 @@ function ownCascades(e, light, first, gameExtent = () => undefined) {
262
285
  if (!c) return;
263
286
  const every = light.shadow.autoUpdate && e.renderer.shadowMap.autoUpdate ? 1 : 2; // 2 = "not every frame": a budget, or a game's own autoUpdate = false
264
287
  if (c.isCascadeNode) { light.target.updateMatrixWorld(); c.frame(null, every); return; }
265
- readGame();
266
- own.target.updateWorldMatrix(true, false);
267
- dir.setFromMatrixPosition(own.target.matrixWorld).negate().add(own.position).normalize();
288
+ tr.aim(at, dir);
289
+ dir.normalize();
268
290
  c.frame(dir, every);
269
- placed.copy(light.position);
270
- proxy.updateMatrixWorld(); // not in the scene: nothing else refreshes it
291
+ tr.mark();
271
292
  },
272
293
  set(next) { o = readOptions({ ...o, ...next }); sync(); },
273
294
  remove() { off(); swap.remove(); tier.remove(); },
@@ -422,7 +443,7 @@ export function defineShadows(e, { owned }) {
422
443
  cache(light, options) {
423
444
  if (!light?.isDirectionalLight) refuse(`${CACHE}(light): needs a three.js DirectionalLight; got ${light?.type ?? light}`);
424
445
  if (caches.has(light)) refuse(`${CACHE}(light): this light has a cache already; change it with handle.set({ static }) or call handle.remove() first`);
425
- if (e._cascades?.light === light) refuse(`${CACHE}(light): this light has cascades, and the cache works on one plain map; call the cascades handle's remove() first`);
446
+ if (e._cascades?.light === light || live?.boxed === light) refuse(`${CACHE}(light): this light has cascades, and the cache works on one plain map; call the cascades handle's remove() first`);
426
447
  const h = ownCache(e, light, options ?? {});
427
448
  return { set: o => h.set(o), redraw: () => h.redraw(), remove: hold(caches, light, h) };
428
449
  },
@@ -445,7 +466,7 @@ export function defineShadows(e, { owned }) {
445
466
  sh.mapSize.set(width, height); changed = true;
446
467
  if (!gpu) { sh.map?.dispose(); sh.map = null; }
447
468
  }
448
- if (changed) setShadowUpdate(e.renderer, e.scene, { now: true }); // a resized map is empty until redrawn (a budget)
469
+ if (changed) redrawLightShadow(e.renderer, light, c); // a resized map is empty until redrawn (without waking other budgeted lights)
449
470
  },
450
471
  /**
451
472
  * Let cascades patch a ShaderMaterial (lights: true) of yours. Built-in lit materials need nothing.
@@ -0,0 +1,166 @@
1
+ // Three.js 0.187 compatibility layer: centralizes internal/private Three.js field access and shadow autoUpdate coordination.
2
+ // Upgrading three.js should only require adjusting this file (alongside render/backend.js for WebGL/WebGPU counters).
3
+ // Imports nothing from three so both WebGL and threedog/tsl bundles can share it without pulling WebGLRenderer into TSL.
4
+
5
+ /**
6
+ * @internal Enable or disable automatic shadow-map redraw for a single three.js light.
7
+ * When re-enabling (or when `redraw: true`), also flags `needsUpdate = true` so the next frame redraws immediately.
8
+ * @param {any} light
9
+ * @param {boolean} enabled
10
+ * @param {{ redraw?: boolean }} [opts]
11
+ */
12
+ export function setLightShadowAutoUpdate(light, enabled, { redraw = enabled } = {}) {
13
+ const s = light?.shadow;
14
+ if (!s) return;
15
+ s.autoUpdate = !!enabled;
16
+ if (redraw) s.needsUpdate = true;
17
+ }
18
+
19
+ /**
20
+ * @internal WebGPURenderer internal node frame (available after init()).
21
+ * @param {any} renderer
22
+ */
23
+ export function nodeFrameOf(renderer) {
24
+ return renderer?._nodes?.nodeFrame ?? null;
25
+ }
26
+
27
+ /**
28
+ * @internal Start WebGPURenderer's internal animation tick so frameId advances before the first manual draw.
29
+ * @param {any} renderer
30
+ */
31
+ export function startRendererAnimation(renderer) {
32
+ renderer?._animation?.start?.();
33
+ }
34
+
35
+ /**
36
+ * @internal WebGPURenderer canvas target internal viewport (holds minDepth / maxDepth not copied by getViewport()).
37
+ * @param {any} renderer
38
+ */
39
+ export function canvasViewportOf(renderer) {
40
+ return renderer?.getCanvasTarget?.()?._viewport ?? null;
41
+ }
42
+
43
+ /**
44
+ * @internal Initialize a three.js CSMShadowNode with an explicit camera and renderer before its first setup.
45
+ * @param {any} node @param {any} camera @param {any} renderer
46
+ */
47
+ export function initCascadeShadowNode(node, camera, renderer) {
48
+ node._init({ camera, renderer });
49
+ }
50
+
51
+ /**
52
+ * @internal Per-cascade child shadow nodes owned by a CSMShadowNode (empty before first build).
53
+ * @param {any} node @returns {any[]}
54
+ */
55
+ export function cascadeShadowNodesOf(node) {
56
+ return node?._shadowNodes ?? [];
57
+ }
58
+
59
+ /**
60
+ * @internal Already-built NodeBuilderState of a three.js RenderObject without triggering a new build.
61
+ * @param {any} renderObject
62
+ */
63
+ export function nodeBuilderStateOf(renderObject) {
64
+ return renderObject?._nodeBuilderState ?? null;
65
+ }
66
+
67
+ /**
68
+ * @internal Keep an EffectComposer's internal pixel ratio and CSS dimensions aligned with the renderer.
69
+ * @param {any} composer @param {number} width @param {number} height @param {number} pixelRatio
70
+ */
71
+ export function syncComposerSize(composer, width, height, pixelRatio) {
72
+ if (composer._pixelRatio !== pixelRatio) composer.setPixelRatio(pixelRatio);
73
+ if (composer._width !== width || composer._height !== height) composer.setSize(width, height);
74
+ }
75
+
76
+ /**
77
+ * @internal First opaque object in WebGLRenderer's internal render list for a scene (where WebGLBackground places its background mesh).
78
+ * @param {any} renderer @param {any} scene
79
+ */
80
+ export function firstOpaqueObject(renderer, scene) {
81
+ return renderer?.renderLists?.get(scene, 0)?.opaque?.[0]?.object ?? null;
82
+ }
83
+
84
+ /**
85
+ * @internal Whether a three.js Pass is an SMAAPass (identified by its internal edges render target, surviving minification).
86
+ * @param {any} pass @returns {boolean}
87
+ */
88
+ export function isSmaaPass(pass) {
89
+ return Boolean(pass?._edgesRT);
90
+ }
91
+
92
+ /**
93
+ * @internal First raw input of a TSL fog(color, factor) node.
94
+ * @param {any} fogNode
95
+ */
96
+ export function fogNodeColorInput(fogNode) {
97
+ return fogNode?.rawInputs?.[0] ?? null;
98
+ }
99
+
100
+ /**
101
+ * @internal Wrap a WebGPU backend's resolveOccludedAsync to ignore errors accepted by `shouldIgnore`.
102
+ * @param {any} backend @param {(err: any) => boolean} shouldIgnore @returns {boolean}
103
+ */
104
+ export function wrapOcclusionReadback(backend, shouldIgnore) {
105
+ const read = backend?.resolveOccludedAsync;
106
+ if (typeof read !== 'function') return false;
107
+ backend.resolveOccludedAsync = function (context) {
108
+ return read.call(this, context).catch(err => {
109
+ if (shouldIgnore(err)) return;
110
+ throw err;
111
+ });
112
+ };
113
+ return true;
114
+ }
115
+
116
+ const SCISSOR_CACHE = new WeakMap();
117
+
118
+ /**
119
+ * @internal Read WebGLRenderer's current drawing scissor box (into `outBox`) and scissor-test flag without per-frame `gl.getParameter(SCISSOR_BOX)` stalls.
120
+ * Seeds once from GL on first borrow, then mirrors every `r.state.scissor` / `setScissorTest` / `enable` / `disable` / `reset` call.
121
+ * @param {any} renderer @param {any} outBox @returns {boolean}
122
+ */
123
+ export function readScissorState(renderer, outBox) {
124
+ const gl = renderer?.getContext?.();
125
+ if (!gl || gl.isContextLost?.()) return false;
126
+ const st = renderer.state;
127
+ if (st && typeof st.scissor === 'function' && typeof st.setScissorTest === 'function') {
128
+ let c = SCISSOR_CACHE.get(st);
129
+ if (!c) {
130
+ const b = gl.getParameter(gl.SCISSOR_BOX);
131
+ if (!b) return !!gl.isEnabled(gl.SCISSOR_TEST);
132
+ c = { x: b[0], y: b[1], z: b[2], w: b[3], test: !!gl.isEnabled(gl.SCISSOR_TEST) };
133
+ SCISSOR_CACHE.set(st, c);
134
+ const scCap = gl.SCISSOR_TEST;
135
+ const origScissor = st.scissor, origSetTest = st.setScissorTest, origEnable = st.enable, origDisable = st.disable, origReset = st.reset;
136
+ st.scissor = function (v) {
137
+ const res = origScissor.call(this, v);
138
+ if (v) { c.x = v.x; c.y = v.y; c.z = v.z; c.w = v.w; }
139
+ return res;
140
+ };
141
+ st.setScissorTest = function (on) {
142
+ const res = origSetTest.call(this, on);
143
+ c.test = !!on;
144
+ return res;
145
+ };
146
+ if (typeof origEnable === 'function') {
147
+ st.enable = function (cap) { const res = origEnable.call(this, cap); if (cap === scCap) c.test = true; return res; };
148
+ }
149
+ if (typeof origDisable === 'function') {
150
+ st.disable = function (cap) { const res = origDisable.call(this, cap); if (cap === scCap) c.test = false; return res; };
151
+ }
152
+ if (typeof origReset === 'function') {
153
+ st.reset = function () {
154
+ const res = origReset.call(this);
155
+ c.x = 0; c.y = 0; c.z = gl.canvas?.width ?? c.z; c.w = gl.canvas?.height ?? c.w; c.test = false;
156
+ return res;
157
+ };
158
+ }
159
+ }
160
+ outBox.set(c.x, c.y, c.z, c.w);
161
+ return c.test;
162
+ }
163
+ const b = gl.getParameter(gl.SCISSOR_BOX);
164
+ if (b) outBox.set(b[0], b[1], b[2], b[3]);
165
+ return !!gl.isEnabled(gl.SCISSOR_TEST);
166
+ }
package/types/core.d.ts CHANGED
@@ -31,7 +31,7 @@ import type { PostFX } from './generated/render/PostFX';
31
31
  import type { Occlusion } from './generated/render/occlusion';
32
32
  import type {
33
33
  Timeline, Level, LevelLoadedEvent, LevelLoadingEvent, LevelFailedEvent, LevelPlayableEvent, LevelUnloadedEvent, Triggers, TriggerEvent, TemplateStageEvent,
34
- Particles, SwarmMaker, Settings, Music, MusicChangeEvent, CharactersApi, NPCManager, Character,
34
+ Particles, Decals, SwarmMaker, Settings, Music, MusicChangeEvent, CharactersApi, NPCManager, Character,
35
35
  Interactions, Dialogue, Inventory, ItemEvent, ItemUseEvent, PickupEvent, Pickups, PickupsOptions, Quests, Photo, PhotoShot, Ambience, DebugPanel,
36
36
  Clock, Vars, Content, Flow, Hud,
37
37
  } from './gameplay';
@@ -737,11 +737,13 @@ export interface AudioVolumeData { base?: number; add?: Record<string, number>;
737
737
  export type AudioVolume = number | AudioVolumeData | ((e: Engine, ...extra: any[]) => number);
738
738
  /** One ambience rule: while `when` holds, `sound` plays at `volume`. With `every` it is a one-shot repeated at random gaps, else a loop */
739
739
  export interface AmbienceRule {
740
- /** A name from audio.sounds; required unless the rule is a reverb rule */
740
+ /** A name from audio.sounds; required unless the rule is a reverb / filter acoustic zone rule */
741
741
  sound?: string;
742
742
  when?: AudioCondition;
743
- /** Instead of a sound: the reverb's wet (0-1, or the volume forms) while `when` holds; the highest holding one wins, none gives engine.audio.reverb's own wet back. Not with sound / volume / every / bus @experimental */
743
+ /** Instead of a sound: the reverb's wet (0-1, or the volume forms) while `when` holds; the highest holding one wins, none gives engine.audio.reverb's own wet back. May combine with filter; not with sound / volume / every / bus @experimental */
744
744
  reverb?: number | AudioVolumeData | ((e: Engine, ambience: import('./gameplay').Ambience) => number);
745
+ /** Instead of a sound: low-pass filter cutoff Hz (80..20000 for sfx / ambience / music, or bus -> Hz map) while `when` holds; the lowest cutoff per bus wins, none restores 20000 Hz. May combine with reverb; not with sound / volume / every / bus @experimental */
746
+ filter?: number | Record<string, number> | ((e: Engine, ambience: import('./gameplay').Ambience) => number | Record<string, number>);
745
747
  /** 0-1, data { base, add: { measure: factor }, min, max }, or a function of the moment (e, ambience) => 0-1 (code only) */
746
748
  volume?: number | AudioVolumeData | ((e: Engine, ambience: import('./gameplay').Ambience) => number);
747
749
  /** Fade seconds when the rule turns on / off (1) */
@@ -1977,6 +1979,8 @@ export declare class Engine {
1977
1979
  triggers?: Triggers;
1978
1980
  /** Particles (particles() module) */
1979
1981
  particles?: Particles;
1982
+ /** Surface decals (decals() module) */
1983
+ decals?: Decals;
1980
1984
  /** Makes a swarm of same-kind gameplay objects (swarm() module): engine.swarm({ name, capacity, geometry, material, fields }) @experimental */
1981
1985
  swarm?: SwarmMaker;
1982
1986
  /** Settings menu (settings() module) */
@@ -2152,6 +2156,15 @@ export declare class Engine {
2152
2156
  * @experimental
2153
2157
  */
2154
2158
  loadProbes(json: ProbeData, opts?: { owner?: string }): ProbeSet;
2159
+ /**
2160
+ * Capture a local prefiltered PMREM reflection probe for `bounds` (rooms, caves, tunnels, courtyards) so metallic and glossy surfaces inside `bounds`
2161
+ * reflect their local surroundings instead of the outdoor sky. Nested bounds pick the smallest enclosing volume; moving objects added with
2162
+ * `probe.addTarget(player.root)` transition between zones automatically.
2163
+ * @example const roomProbe = engine.addReflectionProbe({ bounds: { min: [-8, 0, -8], max: [8, 4, 8] } });
2164
+ * @experimental
2165
+ */
2166
+ addReflectionProbe(opts: { bounds: import('three').Box3 | { min: PositionLike; max: PositionLike }; position?: PositionLike; resolution?: number;
2167
+ near?: number; far?: number; intensity?: number; autoAssign?: boolean; include?: (o: Object3D) => boolean; owner?: string }): ReflectionProbe;
2155
2168
  /**
2156
2169
  * Put a baked lightmap on the scene: `threedog bake light` wrote the file from the meshes the game marked `userData.static = true`; this rebuilds each with
2157
2170
  * its second UV set and sets plain `material.lightMap`, on WebGL and WebGPU alike. Call it once the level is built, with its lights as they will be
@@ -2587,3 +2600,20 @@ export interface ProbeSet extends Handle {
2587
2600
  /** takes the grid out of the scene and frees its texture; sample / toJSON still work */
2588
2601
  remove(): void;
2589
2602
  }
2603
+ /** A local prefiltered PMREM reflection probe (engine.addReflectionProbe); describe().render.reflectionProbes lists the live ones @experimental */
2604
+ export interface ReflectionProbe extends Handle {
2605
+ /** Prefiltered PMREM environment texture */
2606
+ readonly texture: import('three').Texture | null;
2607
+ /** World bounds volume */
2608
+ readonly box: import('three').Box3;
2609
+ /** Capture origin in world space */
2610
+ readonly position: Vector3;
2611
+ /** Last capture duration in ms */
2612
+ bakeMs: number;
2613
+ /** Re-capture the local scene into the PMREM texture */
2614
+ bake(): ReflectionProbe;
2615
+ /** Bind an Object3D subtree (follows across zones by default) or Material to local reflection probes */
2616
+ addTarget(target: Object3D | Material, opts?: { follow?: boolean }): Handle;
2617
+ /** Restore bound materials and free GPU memory */
2618
+ remove(): void;
2619
+ }
@@ -1527,6 +1527,8 @@ export interface Inventory {
1527
1527
  contents(): Record<string, any[]>;
1528
1528
  /** Replace containers' items from contents() data, silently like a save load; a null entry empties that container, only: true empties the rest too @experimental */
1529
1529
  setContents(data: Record<string, any[] | null>, opts?: { only?: boolean }): void;
1530
+ /** @internal Subscribe to container mutations for incremental sync */
1531
+ trackDirty?(): { dirty: Set<string>; all: boolean; read(id: string): any[] | undefined; remove(): void };
1530
1532
  }
1531
1533
  export interface InventoryOptions {
1532
1534
  /** Action name that opens the inventory, default 'inventory' */
@@ -2196,3 +2198,81 @@ export interface Hud {
2196
2198
  * behind the camera
2197
2199
  */
2198
2200
  export interface ScreenPoint { x: number; y: number; onScreen: boolean; behind: boolean }
2201
+
2202
+ // ======================================================================
2203
+ // Surface decals engine.decals (decals() module)
2204
+ // ======================================================================
2205
+
2206
+ /** Options of decals.define(name, opts) and decals({ default }) */
2207
+ export interface DecalKindOptions {
2208
+ /** Width and height in meters (a single number = square, or [w, h] / [w, h, depth] / { x, y, z }), default 1 */
2209
+ size?: number | number[] | { x?: number; y?: number; z?: number };
2210
+ /** Projection depth in meters, default 0.6 */
2211
+ depth?: number;
2212
+ /** Color map: registered asset name or THREE.Texture */
2213
+ map?: string | import('three').Texture;
2214
+ /** Normal map: registered asset name or THREE.Texture */
2215
+ normalMap?: string | import('three').Texture;
2216
+ /** Tint color */
2217
+ color?: ColorLike;
2218
+ /** Opacity 0..1, default 1 */
2219
+ opacity?: number;
2220
+ /** Seconds before removal (Infinity = permanent), default Infinity */
2221
+ lifetime?: number;
2222
+ /** Seconds at the end of lifetime over which opacity fades to 0, default 0.6 */
2223
+ fade?: number;
2224
+ /** Pool cap for this kind (oldest evicted when full) */
2225
+ max?: number;
2226
+ /** Custom base Material cloned for each decal of this kind */
2227
+ material?: Material;
2228
+ /** Parent mesh decals to a hit target so they move with it */
2229
+ attach?: boolean;
2230
+ /** Grid subdivisions when conforming to procedural ground height */
2231
+ segments?: number;
2232
+ /** Surface lift in meters on ground grids, default 0.015 */
2233
+ offset?: number;
2234
+ }
2235
+ /** Options of decals.add(at, opts) */
2236
+ export interface DecalAddOptions extends DecalKindOptions {
2237
+ /** Defined decal kind name */
2238
+ kind?: string;
2239
+ /** Target mesh or root to project onto (omitted: hit.object, static ray probe, or ground grid) */
2240
+ target?: Object3D | null;
2241
+ /** Surface normal direction (omitted: hit normal or +Y) */
2242
+ normal?: PositionLike;
2243
+ /** Roll angle around the surface normal in radians, default 0 */
2244
+ roll?: number;
2245
+ }
2246
+ /** Options of decals({ ... }) */
2247
+ export interface DecalsOptions {
2248
+ /** Global live decal cap (default 128, 64 on low tier) */
2249
+ max?: number;
2250
+ /** Named decal kinds defined at install */
2251
+ effects?: Record<string, DecalKindOptions>;
2252
+ /** Base options every decal inherits */
2253
+ default?: DecalKindOptions;
2254
+ }
2255
+ /** Handle returned by decals.add() */
2256
+ export interface DecalHandle extends Handle {
2257
+ /** Placed THREE.Mesh */
2258
+ readonly object: import('three').Mesh;
2259
+ /** Kind name, or null when unnamed */
2260
+ readonly kind: string | null;
2261
+ /** Update live properties in place; returns the handle */
2262
+ set(patch: { color?: ColorLike; opacity?: number; lifetime?: number; fade?: number; visible?: boolean }): DecalHandle;
2263
+ /** Remove the decal and dispose its geometry and cloned material */
2264
+ remove(): void;
2265
+ }
2266
+ /** engine.decals: conforming surface decals (bullet holes, footprints, ground rings, stains) */
2267
+ export interface Decals {
2268
+ /** Default base material cloned for decals without a material of their own */
2269
+ material: Material;
2270
+ /** Define a named decal kind */
2271
+ define(name: string, opts?: DecalKindOptions): DecalKindOptions;
2272
+ /** Project a decal at a position or raycast hit */
2273
+ add(at: PositionLike | { point: Vector3; normal?: Vector3; face?: any; object?: Object3D }, opts?: DecalAddOptions): DecalHandle;
2274
+ /** Remove live decals of `kind`, or every live decal when `kind` is omitted */
2275
+ remove(kind?: string): void;
2276
+ /** Live decal count (for one kind, or all when omitted) */
2277
+ count(kind?: string): number;
2278
+ }
@@ -84,6 +84,21 @@ export class Audio {
84
84
  }): {
85
85
  remove(fade?: number): void;
86
86
  };
87
+ /**
88
+ * Low-pass filter buses (e.g. underwater, cave, muffled room) until the handle is removed.
89
+ * Several holders stack: each bus takes the lowest active cutoff Hz; removing all restores 20000 Hz.
90
+ * @param {number | Record<string, number>} cutoff Hz (80..20000) for sfx / ambience / music, or bus -> Hz map
91
+ * @param {{ fade?: number }} [opts] fade seconds both ways (0.35)
92
+ * @returns {{ set(cutoff: number | Record<string, number>, fade?: number): void, remove(fade?: number): void }}
93
+ * @example const f = engine.audio.filter(800, { fade: 0.5 }); f.set(400); f.remove();
94
+ * @experimental
95
+ */
96
+ filter(cutoff: number | Record<string, number>, opts?: {
97
+ fade?: number;
98
+ }): {
99
+ set(cutoff: number | Record<string, number>, fade?: number): void;
100
+ remove(fade?: number): void;
101
+ };
87
102
  /**
88
103
  * Add a condition key for music / ambience rule lists: `when: { [name]: value }` calls test(value, engine). Modules add theirs
89
104
  * (calendar: time, weather: weather, triggers: zone); the engine has `state` (engine.audio.state).
@@ -155,8 +170,9 @@ export class Audio {
155
170
  /**
156
171
  * What is playing (describe().audio shows it while something is ducked or playing): bus levels, the duck multiplier per bus, live voices per sound name.
157
172
  * ducks is the level the active ducks ask for (1 = not lowered), read at once even while a fade is still ramping or the audio clock does not run (headless page).
173
+ * filters is the lowest active low-pass cutoff Hz per bus ({} when none).
158
174
  * reverb (only once reverb() was called): its targets, `place` while an ambience rule sets wet, `built` once audio unlocked.
159
- * @returns {{ running: boolean, state: string | null, levels: Record<string, number>, ducks: Record<string, number>, voices: Record<string, number>, reverb?: { wet: number, decay: number, size: number, sends: Record<string, number>, place?: number, built: boolean } }}
175
+ * @returns {{ running: boolean, state: string | null, levels: Record<string, number>, ducks: Record<string, number>, filters: Record<string, number>, voices: Record<string, number>, reverb?: { wet: number, decay: number, size: number, sends: Record<string, number>, place?: number, built: boolean } }}
160
176
  * @example engine.audio.duck({ music: 0.3 }); engine.audio.info.ducks.music // 0.3
161
177
  */
162
178
  get info(): {
@@ -164,6 +180,7 @@ export class Audio {
164
180
  state: string | null;
165
181
  levels: Record<string, number>;
166
182
  ducks: Record<string, number>;
183
+ filters: Record<string, number>;
167
184
  voices: Record<string, number>;
168
185
  reverb?: {
169
186
  wet: number;
@@ -111,12 +111,13 @@ export class Ops {
111
111
  * @param {object} args
112
112
  * @param {any} value
113
113
  * @param {{ actor?: string }} [opts]
114
- * @returns {{ ok: boolean, code?: string, facts?: object, nextActions?: { op: string, args?: object }[] }}
114
+ * @returns {{ ok: boolean, revision: number, code?: string, facts?: object, nextActions?: { op: string, args?: object }[] }}
115
115
  */
116
116
  undo(name: string, args: object, value: any, opts?: {
117
117
  actor?: string;
118
118
  }): {
119
119
  ok: boolean;
120
+ revision: number;
120
121
  code?: string;
121
122
  facts?: object;
122
123
  nextActions?: {
@@ -12,11 +12,11 @@ export namespace TASK_ENDS {
12
12
  export class Control {
13
13
  constructor(engine: any);
14
14
  /**
15
- * Take a character's control. step (optional): (dt, character) => ({ x, y?, z, run? }) | null | false, called each fixed step while this owner is in
16
- * charge (dt on the character's time channel): a direction moves it, null stands still (gravity and the idle pose go on), false skips the
15
+ * Take a character's control. step (optional): (dt, character) => ({ x, y?, z, run? } | { dx, dz, dy? }) | null | false, called each fixed step while this owner is in
16
+ * charge (dt on the character's time channel): a direction moves it, { dx, dz, dy? } steps an exact displacement (root motion, bypassing walk speed and auto-turn), null stands still (gravity and the idle pose go on), false skips the
17
17
  * move this step (you placed it yourself). Without step, move it with handle.move(x, z, run, dt), which does nothing while paused.
18
18
  * @param {any} who a Character, an NPC handle or a character id ('player', an NPC id)
19
- * @param {{ owner: string, layer?: 'base' | 'script' | 'cutscene' | 'physics' | 'net', step?: (dt: number, ch: any) => ({ x: number, y?: number, z: number, run?: boolean } | null | false | void) }} o
19
+ * @param {{ owner: string, layer?: 'base' | 'script' | 'cutscene' | 'physics' | 'net', step?: (dt: number, ch: any) => ({ x: number, y?: number, z: number, run?: boolean } | { dx: number, dz: number, dy?: number } | null | false | void) }} o
20
20
  * @returns {{ owner: string, layer: string, id: string, readonly active: boolean, move(x: number, z: number, run?: boolean, dt?: number): boolean, remove(): void }}
21
21
  * @example const h = engine.control.take(player, { owner: 'tutorial', layer: 'script', step: () => ({ x: 0, z: 1 }) }); ... h.remove();
22
22
  */
@@ -28,6 +28,10 @@ export class Control {
28
28
  y?: number;
29
29
  z: number;
30
30
  run?: boolean;
31
+ } | {
32
+ dx: number;
33
+ dz: number;
34
+ dy?: number;
31
35
  } | null | false | void);
32
36
  }): {
33
37
  owner: string;