threedog 2.0.0 → 2.1.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 (97) hide show
  1. package/CHANGELOG.md +15 -1
  2. package/core/assets/assetEntry.js +1 -1
  3. package/core/assets/assetPart.js +1 -1
  4. package/core/base/events.generated.js +1 -2
  5. package/core/engine/Engine.js +9 -5
  6. package/core/engine/copies.js +1 -1
  7. package/core/engine/modules.js +4 -4
  8. package/core/engine/services.js +5 -4
  9. package/core/inspect/DebugOverrides.js +2 -2
  10. package/core/inspect/describeRender.js +0 -7
  11. package/core/inspect/metadata.generated.js +106 -36
  12. package/core/inspect/pictureChecks.js +2 -27
  13. package/core/ops/sharedPoint.js +11 -2
  14. package/core/saves/saveApply.js +1 -1
  15. package/core/scene/adaptive.js +3 -2
  16. package/core/scene/pixelRatio.js +39 -17
  17. package/core/scene/sceneMethods.js +1 -1
  18. package/core/scene/tier.js +2 -33
  19. package/core/scene/view.js +14 -0
  20. package/core/time/skip.js +1 -1
  21. package/docs/CODEMAP.md +3 -3
  22. package/docs/api/ambience.md +2 -2
  23. package/docs/api/cameraRig.md +7 -0
  24. package/docs/api/engine.md +1 -1
  25. package/docs/api/events.md +1 -2
  26. package/docs/api/photo.md +5 -0
  27. package/docs/api/sky.md +10 -0
  28. package/docs/api/terrain.md +19 -0
  29. package/docs/api/tools.md +1 -1
  30. package/docs/recipes/05-props-bake.md +1 -1
  31. package/docs/recipes/07-flow-scenes-pause.md +3 -3
  32. package/docs/recipes/09-materials-lights-models.md +1 -1
  33. package/docs/recipes/14-custom-module.md +1 -1
  34. package/docs/recipes/15-perf.md +1 -1
  35. package/docs/recipes/16-dev-bridge.md +1 -1
  36. package/docs/recipes/18-world.md +1 -1
  37. package/docs/recipes/26-ui-parts.md +2 -2
  38. package/docs/recipes/40-scene.md +1 -1
  39. package/docs/recipes/51-capability-catalog.md +1 -1
  40. package/docs/recipes/52-around-the-picture.md +2 -2
  41. package/docs/recipes/55-mods-time-wrap.md +3 -3
  42. package/docs/recipes/57-control.md +1 -1
  43. package/docs/recipes/59-depth-post-effects.md +1 -1
  44. package/docs/recipes/60-judge-the-picture.md +5 -5
  45. package/examples/techniques/interior-light/README.md +1 -1
  46. package/examples/techniques/night-lights/README.md +1 -1
  47. package/examples/techniques/outlines-and-rim/README.md +1 -1
  48. package/examples/techniques/procedural-animation/README.md +1 -1
  49. package/examples/techniques/procedural-surface/README.md +1 -1
  50. package/examples/techniques/wet-road/README.md +1 -1
  51. package/modules/camera/contract.js +1 -1
  52. package/modules/characters/mover.contract.js +1 -1
  53. package/modules/characters/movers/rapier.js +7 -9
  54. package/modules/characters/player.js +1 -1
  55. package/modules/collision/Collision.js +1 -1
  56. package/modules/collision/grid.js +1 -1
  57. package/modules/content/index.js +2 -2
  58. package/modules/content/models.js +1 -1
  59. package/modules/flow/index.js +3 -3
  60. package/modules/gameplay/inventory.contract.js +1 -1
  61. package/modules/grid/tiles.js +6 -3
  62. package/modules/level/contract.js +2 -2
  63. package/modules/particles/Particles.js +1 -2
  64. package/modules/photo/pathTrace.js +1 -1
  65. package/modules/rigid/RigidBodies.js +13 -0
  66. package/modules/rigid/ragdoll.js +1 -1
  67. package/modules/settings/Settings.js +3 -2
  68. package/modules/settings/apply.js +4 -3
  69. package/modules/settings/sections.js +1 -1
  70. package/modules/sky/environment.js +1 -1
  71. package/modules/terrain/index.js +1 -2
  72. package/modules/timeline/Timeline.js +8 -4
  73. package/modules/vegetation/Vegetation.js +1 -1
  74. package/modules/vegetation/index.js +1 -1
  75. package/modules/weather/weatherDraw.js +1 -2
  76. package/package.json +1 -1
  77. package/render/PostFX.js +7 -7
  78. package/render/lightmap.js +1 -1
  79. package/render/lights.js +1 -2
  80. package/render/neutral.js +1 -1
  81. package/render/patches.js +3 -3
  82. package/render/probes.js +27 -2
  83. package/render/shaderErrors.js +1 -1
  84. package/render/shadows.js +1 -3
  85. package/types/core.d.ts +2 -4
  86. package/types/gameplay.d.ts +7 -2
  87. package/types/generated/ui/UI.d.ts +2 -1
  88. package/types/world.d.ts +4 -2
  89. package/ui/UI.js +18 -14
  90. package/ui/cursor.js +2 -2
  91. package/examples/action/.threedog/content-index.json +0 -1
  92. package/examples/perf-island/.threedog/content-index.json +0 -1
  93. package/examples/plain-picture/.threedog/content-index.json +0 -1
  94. package/examples/rc2d/.threedog/content-index.json +0 -1
  95. package/examples/styletest/.threedog/content-index.json +0 -1
  96. package/examples/webgpu-tsl/.threedog/content-index.json +0 -1
  97. package/examples/world/.threedog/content-index.json +0 -1
package/CHANGELOG.md CHANGED
@@ -2,7 +2,21 @@
2
2
 
3
3
  What changed in each version and how a game upgrades.
4
4
 
5
- ## Unreleased
5
+ ## 2.1.0 (2026-11-18)
6
+
7
+ Upgrading from 2.0: nothing to change unless your game listens to `module:restored` (now `module:fresh`) or `settings:shadows` (follow the shared point `shadows.enabled`); the player's render-scale choice is now a ceiling for `engine.setPixelRatio` (see below). The pre-2.0 `Unreleased` notes follow.
8
+
9
+ - Changed: a render scale the player picks in settings below the device default is now a ceiling: `engine.setPixelRatio` can only go under it, and the player's `settings.reset('pixelRatio')` hands the ratio back to the game (before, the last write won and the menu choice was overridden). Nothing to change in a game; to force a ratio regardless of the player, call three.js `renderer.setPixelRatio` (the engine yields)
10
+ - Changed: event `module:restored` is now `module:fresh` (it fires for modules that are fresh after a `replaces` or a failed one put back; the old name is gone, listen to `module:fresh`)
11
+ - Fixed: a cutscene that ends on a dark step hands its cover to the scene change, so the next `flow.transition` lifts it (a lift of your own: `fadeScreen(engine, 0, { owner: 'flow' })`)
12
+ - Fixed: the api pages and `threedog catalog` now list option keys a module's options interface inherits (terrain, photo, sky, cameraRig showed them as missing)
13
+ - Fixed: grid tiles now redraw on a ground the game swaps in with `engine.setGround` (they only followed level load and unload before)
14
+ - Fixed: `fadeScreen` gains an `owner` option (default `'game'`). Each owner keeps its own cover and the screen shows the darkest, so a `flow.transition` or a cutscene no longer clears a cover the game holds
15
+ - Removed: event `settings:shadows` (follow the shared point `shadows.enabled` instead)
16
+ - Fixed: contract check: a module that registers a save part its contract does not list now fails
17
+ - Fixed: a character with `mover: 'rapier'` but no rigid module now gets a dev warning (`module-requires`) and walks with the simple mover; the rapier mover no longer reads rigid's internals (rigid gains `layered`, `layerOf(collider)`, `fitPlayerCapsule(radius)`, all @internal)
18
+ - Changed: shared points follow changes through one entry (`watch(fn)`, `setBase(v)`, both @internal); the tier follower list and `onTierChange` are gone
19
+ - Fixed: check rules: R2 counts names read through `(await load(file)).name` in tools (no more false "unused" on `handRolled`), R10 skips `*.generated.js`, R22 no longer flags README and README.zh-CN sharing a sentence
6
20
 
7
21
  ## 2.0.0 (2026-11-16)
8
22
 
@@ -91,7 +91,7 @@ function checkNeeds(name, e, g) {
91
91
  }
92
92
 
93
93
  /** Load an entry as a task in engine.loading; a registered, non-critical file that fails resolves to its fallback */
94
- export function fetchEntry(a, e) {
94
+ function fetchEntry(a, e) {
95
95
  if (a._disposed) return NEVER;
96
96
  if (a._stale(e)) retireEntry(a, e);
97
97
  if (e.promise) { if (e.load) e.load.waits++; return e.promise; }
@@ -18,7 +18,7 @@ const BONES = 'node "{node}" in {url} holds a skinned mesh whose bones are outsi
18
18
  * Geometry and materials are shared with the file (SkeletonUtils clone: a skinned part gets its own bones); the file's scene is not changed.
19
19
  * @returns {{ scene: THREE.Group, animations: THREE.AnimationClip[] }}
20
20
  */
21
- export function partOf(gltf, node, url) {
21
+ function partOf(gltf, node, url) {
22
22
  const all = [];
23
23
  gltf.scene.traverse(o => { if (o !== gltf.scene && o.name) all.push(o.name); });
24
24
  const name = all.includes(node) ? node : sanitize(node);
@@ -11,7 +11,6 @@ export const ENGINE_EVENTS = [
11
11
  'save:loaded',
12
12
  'ui:open',
13
13
  'ui:close',
14
- 'settings:shadows',
15
14
  'settings:change',
16
15
  'tier:change',
17
16
  'post:add',
@@ -86,7 +85,7 @@ export const ENGINE_EVENTS = [
86
85
  'net:result',
87
86
  'engine:error',
88
87
  'module:disabled',
89
- 'module:restored',
88
+ 'module:fresh',
90
89
  'op:rolledBack',
91
90
  'state:replaced',
92
91
  'vehicle:enter',
@@ -28,7 +28,7 @@ import { recordSweep } from '../../render/recordSweep.js';
28
28
  import { dressNodeTwins } from '../../render/patches.js';
29
29
  import { lifecycleMethods, clearHooks, checkCanvasUsable } from './lifecycle.js';
30
30
  import { createAdaptive, GpuTimer } from '../scene/adaptive.js';
31
- import { firstRatio, noteDeviceBox, pixelSizeOn } from '../scene/pixelRatio.js';
31
+ import { firstRatio, defineRatio, noteDeviceBox, pixelSizeOn } from '../scene/pixelRatio.js';
32
32
  import { watchRejections } from '../base/errors.js';
33
33
  import { createMovement } from '../scene/movement.js';
34
34
  import { moduleMethods } from './modules.js';
@@ -43,7 +43,7 @@ import { installPictureWriters } from '../inspect/pictureWriters.js';
43
43
  import { ownHook } from './moduleTypes.js';
44
44
  import { defineShadows } from '../../render/shadows.js';
45
45
  import { defineTerms } from '../../render/terms.js';
46
- import { defineView, checkCamera } from '../scene/view.js';
46
+ import { defineView, defineTone, checkCamera } from '../scene/view.js';
47
47
  import { nameShaderErrors } from '../../render/shaderErrors.js';
48
48
  import { probeMethods } from '../../render/probes.js';
49
49
  import { lightmapMethods } from '../../render/lightmap.js';
@@ -165,10 +165,14 @@ export class Engine {
165
165
  /** @internal */ this.baseBackgroundHex = this.baseBackground.getHex();
166
166
  this.scene.background = this.baseBackground;
167
167
  this.stacks = new Stacks(this); // shared points: before the lights, whose shadow size reads engine.tier, and the first engine.shadows / engine.post point
168
+ // the one quality value (engine.tier): the device gives the base, the player's preset sets over it; settingsSet: here the player's choice is a choice, not a
169
+ // restriction. Defined before the lights, the first part that follows it (stacks.get('tier').watch: lights, post chain, cascades, terrain, weather)
170
+ this.stacks.define('tier', { kind: 'value', base: this._deviceTier, save: false, settingsSet: true });
168
171
  /** Placeholder lights { sun: DirectionalLight, hemi: HemisphereLight }: neutral and still; createEngine({ lights: false }) leaves them out of the scene @type {{ sun: any, hemi: any }} */
169
172
  this.lights = createDefaultLights(this, { add: lights !== false });
170
173
  // the engine's own renderer gets soft shadows by default; tone curve and environment stay three.js's defaults
171
174
  defineShadows(this, { owned }); // engine.shadows: master switch, cascades, box, budget on the lights a game hands in (render/shadows.js)
175
+ defineTone(this, { owned }); // engine.renderer.toneMapping as one owned value (core/scene/view.js)
172
176
  recordRender(this, { owned }); // baseline for describe().render (after the shadow defaults are written): which values the engine set
173
177
  // Dev server only. A bundled build (npm test, threedog shot, release) is one minified file, so a stack there names assets/index-x.js:1 for every value: a
174
178
  // wrong answer. Written as the literal, not DEV_SERVER: only the literal folds at build time, so the tracker leaves a release bundle altogether
@@ -248,6 +252,7 @@ export class Engine {
248
252
  this.ui.get('loading')?.show({});
249
253
  const adaptiveOn = adaptiveResolution && !headless;
250
254
  this.adaptive = createAdaptive({ on: adaptiveOn, target: targetFps, max: r.getPixelRatio(), held: () => pixelSizeOn(this) });
255
+ defineRatio(this); // render.pixelRatio: base, the game's setPixelRatio and the player's choice as entries; adaptive.max follows it
251
256
  this._gpu = adaptiveOn ? new GpuTimer(timerContext(r)) : null; // GPU frame time for adaptive resolution where the browser offers the timer query
252
257
  // follow the canvas's own CSS box, not the window: a canvas in a page section or editor panel renders at its own size.
253
258
  // The window event stays for a canvas outside the page (no box, falls back to the window) and for moves that do not resize the canvas
@@ -285,12 +290,11 @@ export class Engine {
285
290
 
286
291
  get waterLevel() { return this.ground.waterLevel; }
287
292
  /** The one quality value, 'low' | 'high', what everything that scales by quality reads: the device's tier, unless the player's preset says otherwise (shared point 'tier') @type {'low' | 'high'} */
288
- get tier() { return this.stacks.has('tier') ? this.stacks.get('tier').value() : this._deviceTier; }
293
+ get tier() { return this.stacks.get('tier').value(); }
289
294
  /** The device's tier, the base under a player's preset */
290
295
  set tier(t) {
291
296
  this._deviceTier = t;
292
- const st = this.stacks.has('tier') ? this.stacks.get('tier') : null;
293
- if (st && st.base !== t) { st.base = t; st._changed(); } // through the stack's change path: onTierChange followers (post, cascades) run once; writing base alone told nobody
297
+ this.stacks.get('tier').setBase(t); // setBase tells the tier's followers once; a bare write to base told nobody
294
298
  }
295
299
  /** True once the world is built (phase 'ready' or 'running'): fixed steps, ops and rendering run from here on @type {boolean} */
296
300
  get ready() { return this.phase === 'ready' || this.phase === 'running'; }
@@ -6,7 +6,7 @@
6
6
  // A hot reload re-runs the same file (same path, a ?t= query): that is one copy, not two, so the path without the query decides.
7
7
  import { coded } from '../base/errorHints.js';
8
8
 
9
- export const VERSION = '2.0.0'; // kept equal to package.json by the "[guard] engine copies" spec
9
+ export const VERSION = '2.1.0'; // kept equal to package.json by the "[guard] engine copies" spec
10
10
 
11
11
  const KEY = Symbol.for('threedog.engine.copies');
12
12
 
@@ -40,7 +40,7 @@
40
40
  // Exclusive slots: provides: ['inventory'] takes each named slot (a kind 'one' shared point, core/ops/sharedPoint.js) for the module before its install;
41
41
  // a second provider is shared-taken. requires may name a slot instead of a module. engine.use(mine(), { replaces: 'inventory' }) unloads the
42
42
  // holder first (its handles, slot, drawing parts, dispose), and puts it back if the new install fails, with its save data and content sections (_putBack). Either way the holder now is a fresh install that has none of what
43
- // others put into the old one, so 'module:restored' tells whoever fed it, once its init is done: they feed it again. The word means "this module is back and holds nothing yet", not that its old state came back; its save data did, its definitions did not.
43
+ // others put into the old one, so 'module:fresh' tells whoever fed it, once its init is done: they feed it again. The word means "this module is back and holds nothing yet", not that its old state came back; its save data did, its definitions did not.
44
44
  // critical: true on a module makes a failed init() stop engine.start() with the reason; without it a failed init is reported (picture / ui: disabled;
45
45
  // other types: error tiers in errors.js) and start() goes on.
46
46
  // Dependencies: requires must be installed first (throws if missing). optional is a soft dependency: an array is only recorded (for GAMEMAP and rule R16);
@@ -198,19 +198,19 @@ export const moduleMethods = {
198
198
  if (removed.length && plan.length) this._tellRestored(plan);
199
199
  },
200
200
  /**
201
- * @internal 'module:restored' for these fresh modules, after their init: what is fed then lands as it does on a running game, where content.load comes after init
201
+ * @internal 'module:fresh' for these fresh modules, after their init: what is fed then lands as it does on a running game, where content.load comes after init
202
202
  * (a level's own url would otherwise overtake the pack's level). Nothing in flight tells at once. One replaced again meanwhile is not told about
203
203
  */
204
204
  _tellRestored(modules) {
205
205
  const tell = () => {
206
206
  const live = modules.filter(m => this.modules.get(m.name) === m);
207
- if (live.length && !this.disposed) this.events.emit('module:restored', { modules: live });
207
+ if (live.length && !this.disposed) this.events.emit('module:fresh', { modules: live });
208
208
  };
209
209
  if (this.loading._inits.size) this.loading.settled().then(tell); else tell();
210
210
  },
211
211
  /**
212
212
  * @internal a failed swap leaves the game as it was: the replaced modules install fresh (their old handles already went), their save parts take back their data as a part registered
213
- * late does (Saves.define), and 'module:restored' tells whoever fed them, because a fresh install has no definitions, as after a swap that worked: content sections load again (modules/content).
213
+ * late does (Saves.define), and 'module:fresh' tells whoever fed them, because a fresh install has no definitions, as after a swap that worked: content sections load again (modules/content).
214
214
  * What game code defined by hand it defines again on that event. Colliders of the level and of props need no event: they check the holder themselves.
215
215
  * @param {any[]} removed in install order @param {string[]} order the module names to go back to @param {string | null} base the new-game state to go back to
216
216
  */
@@ -41,7 +41,6 @@ import { defineSkipOp } from '../time/skip.js';
41
41
  import { installThings } from '../scene/thingOps.js';
42
42
  import { Plugins } from './plugins.js';
43
43
  import { watchGameLights } from '../scene/gameLights.js';
44
- import { tierChanged, tierDefined } from '../scene/tier.js';
45
44
 
46
45
  /**
47
46
  * Create the engine services on `engine` (called once from the Engine constructor, after the renderer, scene and uniforms exist).
@@ -82,9 +81,11 @@ export function createServices(engine, { canvas, validate, locale, strings, save
82
81
  engine._urlState = new UrlState(engine, { fromUrl: urlState });
83
82
  // who holds the engine still: three named stacks (stacks.js: same owner rules as every shared quantity, holders in describe); haltLoop / freeze / takeCamera in holds.js
84
83
  defineHoldStacks(engine);
85
- // the one quality value (engine.tier): the device gives the base, the player's preset sets over it. settingsSet: on this point the player's choice is a choice, not a restriction
86
- engine.stacks.define('tier', { kind: 'value', base: engine._deviceTier, save: false, settingsSet: true, onChange: () => tierChanged(engine) }); // the post chain and cascades follow it (core/scene/tier.js onTierChange)
87
- tierDefined(engine);
84
+ // the 'tier' shared point is defined in Engine.js right after the stacks, before the lights that follow it (followers: engine.stacks.get('tier').watch(fn))
85
+ // the public 'tier:change' event (game code sizes what it makes from engine.tier): fires when the tier differs from the last one announced, so a preset equal to the device's tier says nothing.
86
+ // Nothing during dispose: settings gives its tier back then, and a follower would allocate on an engine being torn down
87
+ let announced = engine.tier;
88
+ engine.stacks.get('tier').watch(() => { if (engine.disposed) return; const t = engine.tier; if (t === announced) return; announced = t; engine.events.emit('tier:change', { tier: t }); });
88
89
  engine.commits = new Commits(engine); // background results that affect gameplay take effect on a fixed tick (see Commits.js)
89
90
  engine.ops = new Ops(engine); // one entry point for actions (define / run / can / list / recent), see Ops.js
90
91
  engine.views = new Views(engine); // named fixed camera views for repeatable screenshots (Views.js)
@@ -1,5 +1,5 @@
1
- // engine.debug: diagnostic overrides with an owner ("show me this without X") and the diagnostic view modes. They change only what the screen shows,
2
- // never the game state or a save, and describe().scene.overrides lists them so an AI knows the picture is not the real state. Why an owner: a tool
1
+ // engine.debug: diagnostic overrides with an owner ("show me this without X") and the diagnostic view modes. They change only what the screen shows
2
+ // (and hot-swap an asset or a shader in place, which assetHot.js and hotGlsl.js do), never the game state or a save, and describe().scene.overrides lists them so an AI knows the picture is not the real state. Why an owner: a tool
3
3
  // (view mode, probe, AI session) removes everything it set with one clear(owner), whatever it forgot to remove(); a tool never touches another owner's.
4
4
  // Generic on purpose: a patch is { visible?, material?, apply? }, and apply(obj) -> undo covers any other picture (the view modes in debugView.js use it).
5
5
  // All of engine.debug is core (it works without the debug panel); the F3 panel module only adds engine.debug.panel next to it (composition).
@@ -6,7 +6,6 @@ import { NoToneMapping, LinearToneMapping, ReinhardToneMapping, CineonToneMappin
6
6
  import { SHADOW_TYPES } from '../../render/shadowTypes.js';
7
7
  import { rv } from '../base/math.js';
8
8
  import { hex } from './MaterialInfo.js';
9
- import { defineOwned } from '../ops/owned.js';
10
9
  import { slotHolders } from '../scene/pictureSlots.js';
11
10
  import { isShown } from '../base/util.js';
12
11
  import { backendFacts } from '../../render/backend.js';
@@ -60,12 +59,6 @@ export function describePicture(e) {
60
59
  * @param {{ owned: boolean }} o owned: false when the game passed its own renderer
61
60
  */
62
61
  export function recordRender(e, { owned }) {
63
- // who writes tone mapping now is one owned record like every other picture value (core/ops/owned.js),
64
- // not a comparison against a remembered creation value here: a direct renderer.toneMapping write yields it ('three (engine yielded)'), quietly (once),
65
- // because that write is the documented way to change the curve. A game-supplied renderer (owned false) starts manual: the engine never wrote it
66
- e._oTone = defineOwned(e, { id: 'toneMapping', part: 'tone', key: 'toneMapping', read: () => e.renderer.toneMapping, objects: [e.renderer], once: true,
67
- write: v => { e.renderer.toneMapping = v; }, levels: { manual: 'engine.renderer.toneMapping = THREE.AgXToneMapping' } });
68
- if (owned) e._oTone.mark(); else e._oTone.manual(true, 'game renderer');
69
62
  e._renderBase = { owned };
70
63
  }
71
64
 
@@ -71,12 +71,14 @@ export const metadata = {
71
71
  "rules": {
72
72
  "type": "any",
73
73
  "optional": true,
74
- "docType": "import('./core').AmbienceRule[]"
74
+ "docType": "import('./core').AmbienceRule[]",
75
+ "desc": "Rules added after the ones in createEngine({ audio: { ambience } })"
75
76
  },
76
77
  "interval": {
77
78
  "type": "any",
78
79
  "optional": true,
79
- "docType": "number"
80
+ "docType": "number",
81
+ "desc": "Seconds between rule checks, default 0.25"
80
82
  }
81
83
  },
82
84
  "page": true,
@@ -1617,23 +1619,33 @@ export const metadata = {
1617
1619
  },
1618
1620
  "scale": {
1619
1621
  "type": "any",
1620
- "optional": true
1622
+ "optional": true,
1623
+ "docType": "number",
1624
+ "desc": "Resolution multiplier, default 1.6"
1621
1625
  },
1622
1626
  "shadowMapSize": {
1623
1627
  "type": "any",
1624
- "optional": true
1628
+ "optional": true,
1629
+ "docType": "number",
1630
+ "desc": "Shadow resolution (pixels), default 4096"
1625
1631
  },
1626
1632
  "bloom": {
1627
1633
  "type": "any",
1628
- "optional": true
1634
+ "optional": true,
1635
+ "docType": "boolean | null",
1636
+ "desc": "Bloom for the shot: null (default) keeps what the game's post has; true / false forces it for that shot only"
1629
1637
  },
1630
1638
  "quality": {
1631
1639
  "type": "any",
1632
- "optional": true
1640
+ "optional": true,
1641
+ "docType": "number",
1642
+ "desc": "Image quality 0–1"
1633
1643
  },
1634
1644
  "format": {
1635
1645
  "type": "any",
1636
- "optional": true
1646
+ "optional": true,
1647
+ "docType": "string",
1648
+ "desc": "Image format, e.g. 'image/jpeg'"
1637
1649
  }
1638
1650
  },
1639
1651
  "page": true,
@@ -2051,43 +2063,63 @@ export const metadata = {
2051
2063
  },
2052
2064
  "clouds": {
2053
2065
  "type": "any",
2054
- "optional": true
2066
+ "optional": true,
2067
+ "docType": "SkyCloudOptions",
2068
+ "desc": "Clouds in the sky (cloud cover follows the weather); see SkyCloudOptions"
2055
2069
  },
2056
2070
  "backdrop": {
2057
2071
  "type": "any",
2058
- "optional": true
2072
+ "optional": true,
2073
+ "docType": "ColorLike",
2074
+ "desc": "A flat background color in place of the dome (no gradient, horizon line, sun / moon disk, stars or clouds). Drawn as written (no tone mapping); a fog asked for in the default horizon color takes it (a fog.color of your own still wins). Leave out for the dome. recipes/08. Example: `backdrop: 0xefebe4`"
2059
2075
  },
2060
2076
  "keyframes": {
2061
2077
  "type": "any",
2062
- "optional": true
2078
+ "optional": true,
2079
+ "docType": "SkyKeyframe[]",
2080
+ "desc": "Rows [time, zenith, horizon, sunColor, ambient]. time: share of the day (0 = 00:00, 0.5 = noon), sorted, first row 0, last 1 (midnight again: same values as 0). They color the dome and the signals uSkyTop / uSkyHorizon, and light nothing: sunColor is the sun disk and the signal uSunColor, ambient dims a skybox and the weather's sky tint (recipe 08). Example: `[[0, 0x0b1030, 0x1c2440, 0x8090c0, 0.25], [0.5, 0x5a8fd0, 0xbcd4ea, 0xfff4e0, 1.1], [1, 0x0b1030, 0x1c2440, 0x8090c0, 0.25]]`"
2063
2081
  },
2064
2082
  "sunSize": {
2065
2083
  "type": "any",
2066
- "optional": true
2084
+ "optional": true,
2085
+ "docType": "number",
2086
+ "desc": "Sharpness exponent of the sun disk, default 900 (about 2 deg); larger = smaller. Not a size in degrees: 10 is ~20 deg, under ~3 the \"disk\" washes most of the sky toward the sun color"
2067
2087
  },
2068
2088
  "sunGlow": {
2069
2089
  "type": "any",
2070
- "optional": true
2090
+ "optional": true,
2091
+ "docType": "number",
2092
+ "desc": "Sun glow, default 0.18"
2071
2093
  },
2072
2094
  "sunBrightness": {
2073
2095
  "type": "any",
2074
- "optional": true
2096
+ "optional": true,
2097
+ "docType": "number",
2098
+ "desc": "(experimental) Sun brightness, default 6"
2075
2099
  },
2076
2100
  "moonColor": {
2077
2101
  "type": "any",
2078
- "optional": true
2102
+ "optional": true,
2103
+ "docType": "ColorLike",
2104
+ "desc": "(experimental) Color of the moon disk drawn at night, default 0xdcdcdc"
2079
2105
  },
2080
2106
  "moonBrightness": {
2081
2107
  "type": "any",
2082
- "optional": true
2108
+ "optional": true,
2109
+ "docType": "number",
2110
+ "desc": "(experimental) Brightness of the moon disk drawn at night, default 3"
2083
2111
  },
2084
2112
  "starDensity": {
2085
2113
  "type": "any",
2086
- "optional": true
2114
+ "optional": true,
2115
+ "docType": "number",
2116
+ "desc": "Share of the sky grid cells (0-1) that hold a star at night, default 0.0025 (0 = no stars). A probability, not a brightness: near 1 every cell is lit and the upper sky turns into a white sheet."
2087
2117
  },
2088
2118
  "dim": {
2089
2119
  "type": "any",
2090
- "optional": true
2120
+ "optional": true,
2121
+ "docType": "{ tint?: boolean; stars?: boolean }",
2122
+ "desc": "What the sky dims for every game unless the style says no (each default true; false turns that one off, the rest stay). The one place these picture decisions are switched: - tint: a sky.tint color (weather grey, a cave tint) dims with the sky's own light, so a grey rain tint stays dark at night. Example: `sky({ dim: { stars: false } }) // live: engine.sky.dim.tint = false`"
2091
2123
  }
2092
2124
  },
2093
2125
  "page": true,
@@ -2228,77 +2260,107 @@ export const metadata = {
2228
2260
  "seed": {
2229
2261
  "type": "any",
2230
2262
  "optional": true,
2231
- "default": 1337
2263
+ "default": 1337,
2264
+ "docType": "number",
2265
+ "desc": "Random seed; the same seed gives the same terrain"
2232
2266
  },
2233
2267
  "chunkSize": {
2234
2268
  "type": "any",
2235
2269
  "optional": true,
2236
- "default": 64
2270
+ "default": 64,
2271
+ "docType": "number",
2272
+ "desc": "Chunk edge length (meters), default 64"
2237
2273
  },
2238
2274
  "resolution": {
2239
2275
  "type": "any",
2240
2276
  "optional": true,
2241
- "default": 16
2277
+ "default": 16,
2278
+ "docType": "number",
2279
+ "desc": "Cells per chunk; smaller is more \"low poly\", default 16"
2242
2280
  },
2243
2281
  "waterLevel": {
2244
2282
  "type": "any",
2245
2283
  "optional": true,
2246
- "default": null
2284
+ "default": null,
2285
+ "docType": "number",
2286
+ "desc": "Water level (meters), default -Infinity = no water (terrainPreset() from"
2247
2287
  },
2248
2288
  "flatten": {
2249
2289
  "type": "any",
2250
2290
  "optional": true,
2251
- "default": []
2291
+ "default": [],
2292
+ "docType": "FlattenZone[]",
2293
+ "desc": "Flattened plots"
2252
2294
  },
2253
2295
  "heightmap": {
2254
2296
  "type": "any",
2255
2297
  "optional": true,
2256
- "default": null
2298
+ "default": null,
2299
+ "docType": "{ url?, size?, min?, max?, center?, outside?, … } | null",
2300
+ "desc": "Heightmap (used when there is no height function): url grayscale image, size [width m, length m], min/max height (meters), center [x, z]"
2257
2301
  },
2258
2302
  "height": {
2259
2303
  "type": "any",
2260
2304
  "optional": true,
2261
- "default": null
2305
+ "default": null,
2306
+ "docType": "((x, z, n) => number) | string | null",
2307
+ "desc": "Height generator: (x, z, n) => meters. Without one (and without a heightmap) the ground is flat at y = 0, a placeholder (dev warning). Runs in workers, so it must be pure (only its parameters and globals like Math); an outside variable throws at terrain() naming it. n = { fbm(x, z, octaves?), noise(x, z), hash(x, z, salt?), seed, waterLevel, params }. Example: `terrain({ height: (x, z, n) => 4 + 12 * n.fbm(x * 0.01, z * 0.01) })`"
2262
2308
  },
2263
2309
  "groundType": {
2264
2310
  "type": "any",
2265
2311
  "optional": true,
2266
- "default": null
2312
+ "default": null,
2313
+ "docType": "((x, z, h, slope, n) => string | null) | string | null",
2314
+ "desc": "Ground type: (x, z, h, slope, n) => type name (null = 'default'). Pure, like height. Colors come from biomeColors[type]; vegetation rules and footsteps match by name. Example: `terrain({ groundType: (x, z, h, slope) => slope > 0.7 ? 'rock' : h < 2 ? 'beach' : 'grass' })`"
2267
2315
  },
2268
2316
  "params": {
2269
2317
  "type": "any",
2270
2318
  "optional": true,
2271
- "default": null
2319
+ "default": null,
2320
+ "docType": "Record<string, any> | null",
2321
+ "desc": "Plain data handed to height / groundType as n.params (a preset's settings); must be serializable"
2272
2322
  },
2273
2323
  "shading": {
2274
2324
  "type": "any",
2275
2325
  "optional": true,
2276
- "default": "smooth"
2326
+ "default": "smooth",
2327
+ "docType": "'flat' | 'smooth' | 'texture'",
2328
+ "desc": "How the ground gets its color: 'smooth' (default) blended per grid point / 'flat' one color and normal per triangle (low poly) / 'texture' per-chunk color map sampled per pixel, so color borders (a river bank) are not confined to triangle edges and the mesh can stay coarse. See recipes/53-ground-up-close.md."
2277
2329
  },
2278
2330
  "colorResolution": {
2279
2331
  "type": "any",
2280
2332
  "optional": true,
2281
- "default": 128
2333
+ "default": 128,
2334
+ "docType": "number",
2335
+ "desc": "Texture shading: color map pixels per chunk edge (default 128, 64 on low-tier devices; independent of `resolution`)"
2282
2336
  },
2283
2337
  "normals": {
2284
2338
  "type": "any",
2285
2339
  "optional": true,
2286
- "default": null
2340
+ "default": null,
2341
+ "docType": "'smooth' | 'flat' | null",
2342
+ "desc": "Texture shading only: lighting normals 'smooth' (default) / 'flat'"
2287
2343
  },
2288
2344
  "normalFn": {
2289
2345
  "type": "any",
2290
2346
  "optional": true,
2291
- "default": null
2347
+ "default": null,
2348
+ "docType": "((i, j, h, cell) => number[]) | string | null",
2349
+ "desc": "Replace the smooth normal at grid point (i, j): (i, j, h, cell) => [nx, ny, nz] (any length; the engine normalizes). h(i, j) is a grid-point height, cell the grid spacing in meters. Pure, like height (workers get its source). Default: central difference of the neighbors. Example: `terrain({ normalFn: (i, j, h, cell) => [(h(i - 1, j) - h(i + 1, j)) / (2 * cell), 2, (h(i, j - 1) - h(i, j + 1)) / (2 * cell)] }) // flatter lighting`"
2292
2350
  },
2293
2351
  "diagonal": {
2294
2352
  "type": "any",
2295
2353
  "optional": true,
2296
- "default": "fixed"
2354
+ "default": "fixed",
2355
+ "docType": "'fixed' | 'adaptive' | 'alternate'",
2356
+ "desc": "How each cell is cut into two triangles: 'fixed' (default, the same diagonal everywhere) / 'adaptive' (along the diagonal with the smaller height difference, fewer zigzag ridges on slopes) / 'alternate' (flips every other cell). It is shape: engine.surface follows it"
2297
2357
  },
2298
2358
  "shape": {
2299
2359
  "type": "any",
2300
2360
  "optional": true,
2301
- "default": null
2361
+ "default": null,
2362
+ "docType": "TerrainShape | null",
2363
+ "desc": "World outline (default null = ground everywhere): an island, a floating rock, a coastline that ends"
2302
2364
  },
2303
2365
  "boundsPad": {
2304
2366
  "type": "any",
@@ -2306,22 +2368,30 @@ export const metadata = {
2306
2368
  "default": {
2307
2369
  "up": 3,
2308
2370
  "radius": 8
2309
- }
2371
+ },
2372
+ "docType": "{ up?: number; radius?: number }",
2373
+ "desc": "Chunk bounding sphere margin in meters (default { up: 3, radius: 8 }): center raised by `up`, radius grown by `radius`. Raise it when a shader moves vertices far"
2310
2374
  },
2311
2375
  "colors": {
2312
2376
  "type": "any",
2313
2377
  "optional": true,
2314
- "default": {}
2378
+ "default": {},
2379
+ "docType": "Record<string, ColorLike>",
2380
+ "desc": "Palette: color name → color"
2315
2381
  },
2316
2382
  "biomeColors": {
2317
2383
  "type": "any",
2318
2384
  "optional": true,
2319
- "default": {}
2385
+ "default": {},
2386
+ "docType": "Record<string, string[]>",
2387
+ "desc": "Ground type → palette color names (two are blended by noise); a type left out is neutral gray"
2320
2388
  },
2321
2389
  "steep": {
2322
2390
  "type": "any",
2323
2391
  "optional": true,
2324
- "default": []
2392
+ "default": [],
2393
+ "docType": "SteepRule[]",
2394
+ "desc": "Steep-slope color rule"
2325
2395
  }
2326
2396
  },
2327
2397
  "page": true,
@@ -6,7 +6,8 @@
6
6
  // drawn picture could prove it (a top-down view never shows the horizon, a metal can glow on its own): the facts, never "must fix".
7
7
  // Never taste ("too dark", "too much bloom"), never a target value. Runs on describe() and at load, never per frame: some walk the scene.
8
8
  import * as THREE from 'three';
9
- import { mats, noteFillLight, noteEnvironment } from '../../render/lit.js';
9
+ import { mats } from '../../render/lit.js';
10
+ import { litTwice, bakeSeenScene } from '../../render/probes.js';
10
11
  import { cameraFrustum } from '../base/math.js';
11
12
  import { drawnAFrame } from '../../render/backend.js';
12
13
  import { fogLook } from '../../render/fogLook.js';
@@ -30,32 +31,6 @@ function metalNoEnv(e, out) {
30
31
  note(out, 'metal-no-env', `no environment reflection on ${metal.size} metal mesh(es) (${[...metal][0]}): what metal reflects comes from scene.environment or material.envMap, and neither is set${bg}.`);
31
32
  }
32
33
 
33
- /**
34
- * Baked light (a probe set or a lightmap) plus a light the bake already saw: that light counts twice. Exported for the load-time warning of
35
- * render/probes.js and render/lightmap.js (the same words there). @param {any} e @returns {string | null}
36
- */
37
- export function litTwice(e) {
38
- const probes = !!e._probeSets?.size, lightmap = !!e._lightmap;
39
- if (!probes && !lightmap) return null;
40
- const doubled = [];
41
- let mapped = 0;
42
- e.scene.traverseVisible(o => {
43
- if (noteFillLight(o, doubled)) return;
44
- if (lightmap && o.isLightProbeGrid) doubled.push(`probe grid ${o.name}`); // the lightmap baked the bounce the grid adds again
45
- else if (probes && !lightmap && o.isMesh && mats(o).some(m => m?.lightMap)) mapped++; // a game's own lightMap under a probe grid
46
- });
47
- noteEnvironment(e.scene, doubled);
48
- if (mapped) doubled.push(`material.lightMap on ${mapped} mesh(es)`);
49
- if (!doubled.length) return null;
50
- const what = [probes && 'probe', lightmap && 'lightmap'].filter(Boolean).join(' and ');
51
- const list = doubled.slice(0, 2).join(', ') + (doubled.length > 2 ? ` and ${doubled.length - 2} more` : '');
52
- if (!bakeSeenScene(e)) return `${what} light is added on top of ${list}. If the bake saw it, it counts twice (a loaded file does not say which lights it saw). Fix: lower it where the bake takes over, or bake without it.`;
53
- return `${what} light is added on top of ${list}, which the bake already saw, so it counts twice. Fix: lower it where the bake takes over, or bake without it.`;
54
- }
55
-
56
- /** True only when every baked light came from a bake made in this session (engine.bakeProbes): it saw this scene's lights. A loaded file or a lightmap carries no record of them */
57
- const bakeSeenScene = e => !e._lightmap && [...(e._probeSets ?? [])].every(s => s.source === 'bake');
58
-
59
34
  /**
60
35
  * A glow before the exposure that applies after it: its threshold acts on light the screen shows scaled. A note: how much of the picture passes the
61
36
  * threshold depends on the light in view, which only the pixels say. Effects are found by what they declare (about.acts, @threedog/post-effects
@@ -80,7 +80,8 @@ export class Stack {
80
80
  if (kind === 'number' && !Number.isFinite(this.base)) throw codedError('shared-value', `engine.stacks.define('${name}', { base }): base is a finite number, got ${shown(this.base)}. Fix: { base: 1 }`);
81
81
  for (const [k, b] of [['min', min], ['max', max]]) if (typeof b !== 'number' || Number.isNaN(b)) throw codedError('shared-value', `engine.stacks.define('${name}', { ${k} }): ${k} is a number (leave it out for no bound), got ${shown(b)}`);
82
82
  if (min > max) throw codedError('shared-value', `engine.stacks.define('${name}', { min, max }): min must be <= max, got min ${min} > max ${max}. Fix: { min: ${max}, max: ${min} }`);
83
- this.min = min; this.max = max; this.save = save; this.per = per; this.onChange = onChange;
83
+ this.min = min; this.max = max; this.save = save; this.per = per;
84
+ /** @type {Set<(id: string | null) => void>} define's onChange is the first follower */ this._watchers = new Set(); if (onChange) this._watchers.add(onChange);
84
85
  /** the copyable "take it over on purpose" call the conflict error offers (a module's own takeover entry); default: a set on the system layer */
85
86
  this.manual = manual;
86
87
  /** the settings layer may set here (key bindings: the player's rebinding replaces the game's keys, it is not a restriction) */
@@ -219,7 +220,15 @@ export class Stack {
219
220
  return true;
220
221
  }
221
222
  /** @internal */
222
- _changed(id) { this._ver++; this.all._version++; this.onChange?.(id ?? null); }
223
+ _changed(id) { this._ver++; this.all._version++; for (const fn of [...this._watchers]) fn(id ?? null); }
224
+ /** @internal Follow every change, in registration order: several parts follow one point (the tier: lights, post chain, cascades, terrain, weather) @param {(id: string | null) => void} fn @returns {{ remove(): void }} */
225
+ watch(fn) { this._watchers.add(fn); return { remove: () => { this._watchers.delete(fn); } }; }
226
+ /** @internal The one way to change the base: it tells the followers, which a bare write to .base did not @param {any} v */
227
+ setBase(v) {
228
+ if (Object.is(this.base, v)) return;
229
+ if (this.kind === 'number' && !Number.isFinite(v)) throw codedError('shared-value', `engine.stacks.get('${this.name}').setBase(v): v is a finite number, got ${shown(v)}. Fix: setBase(1)`);
230
+ this.base = v; this._changed();
231
+ }
223
232
  /** @internal End owner's entry by name (engine holds: the halt handle); games end theirs with the handle's remove(). false when it held none @param {string} owner @param {{ id?: string }} [o] */
224
233
  release(owner, { id } = {}) { return this._drop(owner, id); }
225
234
  /** Drop every entry for record id (world.remove does it, so no orphan entries) @param {string} id */
@@ -211,7 +211,7 @@ export const restoreParts = (s, list, where) => { runParts(s, list, where, [], o
211
211
  export function adoptPart(s, key, part) {
212
212
  const f = s._foreign, q = s._replace, where = fmt(DEV_STRINGS.adoptAt, { k: key }), L = s.engine.loading;
213
213
  // engine.loading.settled() waits for it: use(mod); await loading.settled() says the module runs with its data back, and gameplay is no longer held for it.
214
- // Its own set, not the inits': a failed replaces tells module:restored once the inits are done, and its content must land on the line after use() threw
214
+ // Its own set, not the inits': a failed replaces tells module:fresh once the inits are done, and its content must land on the line after use() threw
215
215
  L._track(q.run(null, () => {
216
216
  // the provider this data was kept for: one removed meanwhile, or another under the same key, does not get it (review l2 #4)
217
217
  if (s._foreign !== f || s.providers.get(key) !== part || !Object.hasOwn(f.parts, key)) return;
@@ -7,7 +7,7 @@
7
7
  // Frames that compiled shaders (ApplyCost.rendered reports them) and the first GRACE seconds after ready are not judged: startup hitches are
8
8
  // one-off costs that lowering cannot fix, and a step that rebuilds the post chain must not judge its own compile.
9
9
  //
10
- // The ladder (engine.adaptive.steps; docs/plans/2026-11-09-quality-ladder.md): the game says what may be lowered and in which order. Default, cheapest
10
+ // The ladder (engine.adaptive.steps; docs/plans/done/2026-11-09-quality-ladder.md): the game says what may be lowered and in which order. Default, cheapest
11
11
  // to see first (Unity's Adaptive Performance lowers low-visual-impact scalers first): each post effect's own `cheaper` params (live uniforms: no
12
12
  // recompile), then the resolution, then the effects that declare skipOnLowTier held off (a chain rebuild and a compile: last, and never back and forth,
13
13
  // see FLAP). No list of expensive effects lives here: an effect declares cheaper / skipOnLowTier itself, the engine follows. Only downward: nothing is
@@ -58,7 +58,8 @@ function checkSteps(v) {
58
58
  const keyOf = s => (typeof s === 'string' ? s : `game.${s.name}`);
59
59
 
60
60
  /**
61
- * The engine.adaptive state object: the public fields (on, target, min, max, base, lowered, from, steps; base is what this device or game starts at, the settings presets' base) plus the
61
+ * The engine.adaptive state object: the public fields (on, target, min, max, base, lowered, from, steps; max follows the shared value render.pixelRatio and base mirrors its base,
62
+ * the device default the settings presets take shares of) plus the
62
63
  * controller's own counters. on is an accessor because every reader (the loop's GPU timer, describe, settings) must see false under pixelSize; what was asked for stays and returns with setPixelSize(null).
63
64
  * held: what the ladder lowers now besides the resolution, key -> { text, undo }; the resolution needs no entry (renderer ratio against max says it).
64
65
  * @param {{ on: boolean, target: number, max: number, held: () => boolean }} o held: pixelSize decides the ratio now