threedog 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/core/Animator.js +1 -0
  2. package/core/Assets.js +16 -0
  3. package/core/DebugOverrides.js +143 -0
  4. package/core/Describe.js +14 -3
  5. package/core/Engine.js +32 -69
  6. package/core/Events.js +59 -1
  7. package/core/I18n.js +2 -2
  8. package/core/Inspect.js +12 -32
  9. package/core/InspectScene.js +7 -3
  10. package/core/MaterialInfo.js +32 -0
  11. package/core/Ops.js +43 -59
  12. package/core/Saves.js +5 -4
  13. package/core/UrlState.js +3 -2
  14. package/core/Vars.js +1 -0
  15. package/core/Views.js +49 -0
  16. package/core/actor.js +2 -2
  17. package/core/assetReport.js +83 -0
  18. package/core/catalog.js +169 -0
  19. package/core/checks.js +67 -0
  20. package/core/claims.js +51 -0
  21. package/core/debugView.js +76 -0
  22. package/core/describeRender.js +45 -0
  23. package/core/describeText.js +11 -4
  24. package/core/errorCodes.js +33 -0
  25. package/core/errorHints.js +6 -1
  26. package/core/holds.js +106 -0
  27. package/core/lifecycle.js +1 -0
  28. package/core/lightWatch.js +23 -3
  29. package/core/look/coreParts.js +112 -0
  30. package/core/look/layers.js +136 -0
  31. package/core/look/part.js +173 -0
  32. package/core/look/report.js +79 -0
  33. package/core/look/write.js +86 -0
  34. package/core/loop.js +15 -14
  35. package/core/modules.js +19 -5
  36. package/core/opsAtomic.js +31 -0
  37. package/core/opsCheck.js +25 -14
  38. package/core/opsFail.js +20 -0
  39. package/core/opsHistory.js +6 -6
  40. package/core/opsRun.js +77 -0
  41. package/core/params.js +132 -0
  42. package/core/renamed.js +21 -0
  43. package/core/saveApply.js +2 -2
  44. package/core/sceneMethods.js +9 -34
  45. package/core/services.js +73 -0
  46. package/core/startup.js +3 -1
  47. package/core/styleParts.js +2 -2
  48. package/core/thingExplain.js +68 -0
  49. package/core/thingOps.js +35 -24
  50. package/core/things.js +15 -1
  51. package/core/util.js +11 -0
  52. package/core/validate.js +23 -7
  53. package/docs/AI.md +83 -109
  54. package/docs/API.md +7 -8
  55. package/docs/CODEMAP.md +63 -51
  56. package/docs/COMMANDS.md +17 -5
  57. package/docs/CONVENTIONS.md +17 -6
  58. package/docs/THREE.md +3 -3
  59. package/docs/api/assets.md +2 -0
  60. package/docs/api/characters.md +2 -0
  61. package/docs/api/collision.md +4 -0
  62. package/docs/api/content.md +1 -0
  63. package/docs/api/engine.md +20 -11
  64. package/docs/api/events.md +5 -1
  65. package/docs/api/post.md +5 -4
  66. package/docs/api/saves.md +2 -1
  67. package/docs/api/sky.md +3 -3
  68. package/docs/api/style.md +3 -3
  69. package/docs/api/tools.md +2 -0
  70. package/docs/api/weather.md +1 -1
  71. package/docs/recipes/02-npc.md +16 -0
  72. package/docs/recipes/03-items-pickups.md +1 -1
  73. package/docs/recipes/06-clock-events.md +13 -0
  74. package/docs/recipes/07-flow-scenes-pause.md +4 -0
  75. package/docs/recipes/08-weather-sky.md +1 -1
  76. package/docs/recipes/09-style-pack.md +5 -5
  77. package/docs/recipes/12-navmesh.md +22 -0
  78. package/docs/recipes/13-animation.md +3 -0
  79. package/docs/recipes/15-perf.md +1 -1
  80. package/docs/recipes/16-dev-bridge.md +51 -17
  81. package/docs/recipes/21-camera.md +51 -2
  82. package/docs/recipes/23-ops.md +45 -9
  83. package/docs/recipes/27-net.md +1 -1
  84. package/docs/recipes/29-grid.md +1 -1
  85. package/docs/recipes/34-environment-lighting.md +9 -8
  86. package/docs/recipes/38-environment-look-hooks.md +8 -6
  87. package/docs/recipes/40-scene.md +29 -0
  88. package/docs/recipes/41-thing-registry.md +29 -0
  89. package/docs/recipes/43-shader-patches-surface-looks.md +2 -0
  90. package/docs/recipes/44-water-weather-look-hooks.md +6 -4
  91. package/docs/recipes/45-cascaded-shadows.md +1 -1
  92. package/docs/recipes/46-blender-art-route.md +22 -0
  93. package/docs/recipes/48-make-material.md +70 -0
  94. package/docs/recipes/49-game-module-contract.md +71 -0
  95. package/docs/recipes/50-own-renderer.md +12 -0
  96. package/docs/recipes/51-capability-catalog.md +63 -0
  97. package/docs/recipes/52-look.md +108 -0
  98. package/examples/action/GAMEMAP.md +5 -5
  99. package/examples/action/content/index.js +2 -1
  100. package/examples/action/content/views.js +6 -0
  101. package/examples/sheepisland/GAMEMAP.md +2 -3
  102. package/examples/styletest/GAMEMAP.md +3 -3
  103. package/examples/styletest/main.js +1 -1
  104. package/examples/styletest/panel.js +3 -3
  105. package/examples/world/GAMEMAP.md +3 -3
  106. package/index.d.ts +27 -0
  107. package/index.js +3 -1
  108. package/llms.txt +5 -0
  109. package/modules/ambience/Ambience.js +5 -2
  110. package/modules/camera/FirstPersonCamera.js +3 -5
  111. package/modules/camera/FixedCamera.js +19 -12
  112. package/modules/camera/FollowCamera.js +14 -8
  113. package/modules/camera/RtsCamera.js +3 -5
  114. package/modules/camera/common.js +40 -10
  115. package/modules/camera/index.js +1 -1
  116. package/modules/camera/projection.js +34 -0
  117. package/modules/characters/Character.js +29 -17
  118. package/modules/characters/astar.js +14 -7
  119. package/modules/characters/index.js +6 -3
  120. package/modules/characters/movers/simple.js +6 -1
  121. package/modules/characters/npcSim.js +8 -2
  122. package/modules/characters/pathAsync.js +12 -6
  123. package/modules/characters/pathJob.js +2 -1
  124. package/modules/characters/proceduralRig.js +5 -1
  125. package/modules/characters/useModel.js +22 -0
  126. package/modules/characters/walkTo.js +58 -0
  127. package/modules/collision/Collision.js +102 -4
  128. package/modules/content/explain.js +13 -0
  129. package/modules/content/index.js +2 -0
  130. package/modules/content/loader.js +3 -0
  131. package/modules/content/rules.js +1 -0
  132. package/modules/debug/DebugPanel.js +11 -5
  133. package/modules/entities/Entities.js +6 -2
  134. package/modules/flow/index.js +5 -2
  135. package/modules/gameplay/Dialogue.js +5 -2
  136. package/modules/gameplay/Interactions.js +12 -2
  137. package/modules/gameplay/Inventory.js +21 -11
  138. package/modules/gameplay/Quests.js +13 -3
  139. package/modules/gameplay/pickups.js +5 -3
  140. package/modules/grid/Layer.js +1 -1
  141. package/modules/grid/index.js +1 -1
  142. package/modules/grid/tiles.js +9 -5
  143. package/modules/hlod/index.js +5 -2
  144. package/modules/hud/index.js +5 -2
  145. package/modules/level/index.js +5 -3
  146. package/modules/lights/index.js +5 -2
  147. package/modules/music/Music.js +6 -2
  148. package/modules/nav/index.js +5 -3
  149. package/modules/net/Client.js +4 -3
  150. package/modules/net/Host.js +2 -2
  151. package/modules/net/index.js +5 -3
  152. package/modules/particles/Particles.js +1 -1
  153. package/modules/photo/Photo.js +10 -7
  154. package/modules/rigid/RigidBodies.js +5 -2
  155. package/modules/settings/Settings.js +6 -3
  156. package/modules/settings/apply.js +2 -1
  157. package/modules/sky/Sky.js +21 -19
  158. package/modules/sky/cascades.js +6 -6
  159. package/modules/sky/domeLayers.js +1 -1
  160. package/modules/sky/environment.js +39 -13
  161. package/modules/sky/fog.js +9 -6
  162. package/modules/sky/frame.js +4 -3
  163. package/modules/sky/look.js +3 -2
  164. package/modules/sky/lookFog.js +80 -0
  165. package/modules/sky/lookShadow.js +50 -0
  166. package/modules/sky/lookSky.js +108 -0
  167. package/modules/sky/shader.js +2 -2
  168. package/modules/sky/shadow.js +4 -10
  169. package/modules/sky/skyModule.js +4 -3
  170. package/modules/terrain/ChunkManager.js +2 -33
  171. package/modules/terrain/chunkLevels.js +40 -0
  172. package/modules/terrain/index.js +10 -2
  173. package/modules/terrain/lookGround.js +61 -0
  174. package/modules/timeline/Timeline.js +7 -3
  175. package/modules/timeline/Tween.js +3 -7
  176. package/modules/timeline/shots.js +6 -4
  177. package/modules/triggers/index.js +9 -2
  178. package/modules/vegetation/Vegetation.js +2 -1
  179. package/modules/vegetation/index.js +6 -3
  180. package/modules/vegetation/lookWind.js +37 -0
  181. package/modules/water/Water.js +19 -3
  182. package/modules/water/look.js +80 -0
  183. package/modules/weather/Weather.js +22 -31
  184. package/modules/weather/look.js +75 -0
  185. package/modules/weather/particles.js +1 -1
  186. package/modules/weather/strings.js +15 -0
  187. package/modules/world/explain.js +11 -0
  188. package/modules/world/index.js +11 -4
  189. package/modules/world/thingSource.js +44 -0
  190. package/package.json +1 -1
  191. package/render/PostFX.js +48 -51
  192. package/render/effects.js +4 -2
  193. package/render/fuse.js +12 -0
  194. package/render/lights.js +4 -2
  195. package/render/lookSurface.js +161 -0
  196. package/render/materials.js +27 -10
  197. package/render/postLook.js +86 -0
  198. package/render/surface.js +3 -1
  199. package/types/core.d.ts +216 -24
  200. package/types/gameplay.d.ts +10 -0
  201. package/types/generated/core/DebugOverrides.d.ts +52 -0
  202. package/types/generated/core/Events.d.ts +43 -0
  203. package/types/generated/core/Ops.d.ts +62 -21
  204. package/types/generated/core/Saves.d.ts +1 -0
  205. package/types/generated/core/Views.d.ts +33 -0
  206. package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
  207. package/types/generated/modules/grid/Layer.d.ts +1 -0
  208. package/types/generated/modules/sky/Sky.d.ts +10 -17
  209. package/types/generated/modules/weather/Weather.d.ts +5 -15
  210. package/types/generated/render/PostFX.d.ts +20 -23
  211. package/types/generated/render/materials.d.ts +10 -0
  212. package/types/physics.d.ts +8 -0
  213. package/types/style.d.ts +16 -6
  214. package/ui/Parts.js +6 -2
  215. package/ui/UI.js +1 -1
  216. package/ui/defaults.js +1 -1
  217. package/docs/api/debug.md +0 -10
@@ -13,13 +13,14 @@
13
13
  // }
14
14
  // Role names are open: a game can add its own and fetch it with makeMaterial('furniture', { color: 0x8a5a36 }).
15
15
  import * as THREE from 'three';
16
- import { closest, warnMissing, warnOnce } from '../core/validate.js';
16
+ import { closest, warnMissing, warnOnce, checkOptions } from '../core/validate.js';
17
17
  import { patchMaterial, copyPatches } from './patches.js';
18
18
  import { declareUniforms } from './uniformDecl.js';
19
19
  import { EFFECTS } from './effects.js';
20
20
  import { detailPatch } from './detail.js';
21
21
  import { applySurface } from './surface.js';
22
22
  import { lightingPatch, rampTexture } from './lighting.js';
23
+ import { groundDetail, materialOverrides, materialReplace, materialPatches, materialMade, surfaceLighting, surfaceRamp } from './lookSurface.js';
23
24
  /** @import { ColorLike, Material, BufferGeometry } from '../types/common' */
24
25
 
25
26
  // ---------- style pack per engine ----------
@@ -64,6 +65,8 @@ export const MATERIAL_PURPOSES = ['default', 'terrain', 'vegetation', 'character
64
65
 
65
66
  // The style pack's materials[role] (or materials.default) decides the material; params are this call's specifics (color, vertex colors, double-sided...).
66
67
  // Only properties the material has are set, so one params object works for any material, built-in or custom.
68
+ // Spec keys handled by makeMaterial / applySurface rather than copied onto the material
69
+ const SPEC_KEYS = ['steps', 'ramp', 'soften', 'repeat', 'wrap', 'detail', 'lighting'];
67
70
  const isSpec = e => e && !e.isMaterial && typeof e !== 'function';
68
71
  /**
69
72
  * Create a material by role: makeMaterial('furniture', { color: 0x8a5a36 }); the look comes from the style pack's materials[role] (unlisted roles use materials.default).
@@ -91,7 +94,8 @@ export function makeMaterial(purpose = 'default', params = {}, engine = undefine
91
94
  const known = [...new Set([...MATERIAL_PURPOSES, ...Object.keys(M)])];
92
95
  if (closest(purpose, known)) warnMissing('material', purpose, known);
93
96
  }
94
- const entry = M[purpose] ?? M.default, key = purpose in M ? purpose : 'default', eng = owner(engine);
97
+ const eng = owner(engine), rep = materialReplace(eng, purpose); // look.materials.replace(role, ...) beats the style's entry
98
+ const entry = rep ?? M[purpose] ?? M.default, key = purpose in M ? purpose : 'default';
95
99
  let m, props = params;
96
100
  if (entry?.isMaterial) m = copyPatches(entry, entry.clone());
97
101
  else if (typeof entry === 'function') {
@@ -99,30 +103,43 @@ export function makeMaterial(purpose = 'default', params = {}, engine = undefine
99
103
  if (!m?.isMaterial) throw new Error(`style.materials.${key} returned ${m}; the function must return a three.js Material`);
100
104
  } else {
101
105
  // A spec layers on top of materials.default when that is a spec too
102
- const { type = 'lambert', steps = 3, ramp, soften, ...rest } = { ...(isSpec(M.default) ? M.default : {}), ...entry, ...params };
106
+ // look.materials.set layers (game / debug) lie over the style's spec; look.surface.ramp over a toon material's own ramp
107
+ const merged = { ...(isSpec(M.default) ? M.default : {}), ...entry, ...materialOverrides(eng, 'default'), ...(purpose === 'default' ? {} : materialOverrides(eng, purpose)), ...params };
108
+ if ((merged.type ?? 'lambert') === 'toon') Object.assign(merged, surfaceRamp(eng)); // the pack-wide ramp wins over the spec's own
109
+ const { type = 'lambert', steps = 3, ramp, soften, ...rest } = merged;
103
110
  const Ctor = TYPES[type];
104
111
  if (!Ctor) throw new Error(`style.materials.${key}: unknown type '${type}'; use ${Object.keys(TYPES).join(' | ')}, or give a Material instance or a function (params, purpose) => Material`);
105
112
  m = new Ctor();
106
113
  if (type === 'toon') m.gradientMap = ramp ? rampTexture(ramp, soften) : toonRamp(steps);
107
114
  else if (ramp || soften !== undefined) throw new Error(`style.materials.${key}: ramp / soften belong to type 'toon' (this is '${type}')`);
108
- props = applySurface(m, rest, `style.materials.${key}`, eng, eng?.style?.lighting);
115
+ props = applySurface(m, rest, `style.materials.${key}`, eng, surfaceLighting(eng));
109
116
  }
110
117
  // the pack's style.lighting also shapes pack Materials and function results that are plain three.js lit materials (specs got it above)
111
- if (props === params && eng?.style?.lighting && (m.isMeshStandardMaterial || m.isMeshLambertMaterial || m.isMeshPhongMaterial || m.isMeshToonMaterial))
112
- patchMaterial(m, [lightingPatch(eng.style.lighting, 'style.lighting')]);
118
+ if (props === params && surfaceLighting(eng) && (m.isMeshStandardMaterial || m.isMeshLambertMaterial || m.isMeshPhongMaterial || m.isMeshToonMaterial))
119
+ patchMaterial(m, [lightingPatch(surfaceLighting(eng), 'style.lighting')]);
113
120
  for (const k in props) {
114
121
  if (k === 'type' || !(k in m)) continue;
115
122
  const v = props[k];
116
123
  if (m[k]?.isColor) m[k].set(v); else if (m[k]?.isVector2 && Array.isArray(v)) m[k].set(...v); else m[k] = v;
117
124
  }
125
+ // A key this material lacks is skipped on purpose (one params object works for any material type), but a key that looks like a typo of a real
126
+ // property ('roughnes') warns once with the suggestion. loose: keys with no close match (a spec shared across types) stay silent.
127
+ // `k in m` also finds accessor properties on the prototype (MeshPhysicalMaterial clearcoat, sheen, ...), which Object.keys does not list
128
+ const unknown = Object.fromEntries(Object.entries(params).filter(([k]) => !(k in m)));
129
+ checkOptions(`makeMaterial('${purpose}')`, unknown, [...Object.keys(m), ...SPEC_KEYS, 'type'], { loose: true });
118
130
  m.userData.purpose = purpose;
131
+ // Minimal provenance for inspect.scene (diagnostic only, one small object per material): which layer supplied the spec
132
+ m.userData.materialSource = { role: purpose, from: !entry ? (Object.keys(params).length ? 'call-params' : 'default') : entry.isMaterial ? 'pack-instance' : typeof entry === 'function' ? 'pack-function' : 'pack-spec', keys: Object.keys(params) };
133
+ const added = materialPatches(eng, purpose); // look.materials.patch(name, patch, { roles })
134
+ if (added.length) patchMaterial(m, added);
135
+ materialMade(eng, purpose, m);
119
136
  m.needsUpdate = true;
120
137
  return m;
121
138
  }
122
139
 
123
140
  // ---------- shader effects (named patches, see patches.js; the built-in ones are in effects.js) ----------
124
141
  // A style's own sway function (style.wind.glsl): must define threedogWind(); its uniforms are declared for it
125
- function windCustom({ glsl, uniforms }) {
142
+ export function windCustom({ glsl, uniforms }) {
126
143
  if (!/void\s+threedogWind\s*\(/.test(glsl || '')) throw new Error('style.wind.glsl must define `void threedogWind(inout vec3 transformed, vec3 ip, vec3 position)`: move the vertex (object space) by the sway; ip = world position of this instance, uTime / uWind / uWindFreq / THREEDOG_WIND_AMP are in scope');
127
144
  return { glsl, ...declareUniforms('style.wind.uniforms', uniforms) };
128
145
  }
@@ -164,10 +181,10 @@ export function applyEffects(material, { wind, clouds = true, season, detail, en
164
181
  */
165
182
  export function terrainMaterial(base = null, engine = undefined) {
166
183
  const e = owner(engine);
167
- // style.terrain.detail is the `detail` patch with its texture-only options (top-down world projection, multiply)
168
- const det = e?.style?.terrain?.detail, tex = det?.texture && e?.assets;
184
+ // look.ground.detail (style.terrain.detail) is the `detail` patch with its options (texture, or noise / glsl; top-down world projection, multiply)
185
+ const det = groundDetail(e), on = det && ((det.texture && e?.assets) || det.noise || det.glsl);
169
186
  return applyEffects(base || makeMaterial('terrain', { vertexColors: true }, e ?? undefined),
170
- { season: 'ground', engine: e ?? undefined, ...(tex && { detail: { texture: det.texture, scale: det.scale ?? 0.25, strength: det.strength ?? 0.35 } }) });
187
+ { season: 'ground', engine: e ?? undefined, ...(on && { detail: { scale: 0.25, strength: 0.35, ...det } }) });
171
188
  }
172
189
 
173
190
  /**
@@ -0,0 +1,86 @@
1
+ // look.post: the post-processing chain as a look part (recipes/52-look.md).
2
+ // set({ bloom: { strength: 0.6 }, vignette: false }) keys are '<effect>.<param>' and '<effect>.enabled'; false / true is the same as enabled
3
+ // patch('grain', glsl | { glsl, slot, order, uniforms, values }) generates a fuse effect named 'grain' (PostFuse in PostFX.js); patch('grain', null) removes it
4
+ // add(effect, { owner }) adds ONE custom pass (name, create | fuse, slot, order, params) without replacing the chain; returns { remove() }
5
+ // replace([effect, ...]) swaps the whole chain for these effects; replace(null) gives the style's chain back
6
+ // The old engine.post.add / enable and handle set / enable / remove were removed in 0.2 (they throw renamed-api): this part is the one way to change the chain, so describe().look
7
+ // and describe().render say who changed what. Style-pack effects (bloom, ao, outline ...) are the style layer; the keys come and go with the
8
+ // effects, so the part adds and removes its params as the chain changes (core/look/dynamic.js).
9
+ // Why '<effect>.<param>' keys and not one object per effect: layering and owners are per key, so a game can change bloom.strength and leave
10
+ // the style's bloom.threshold alone.
11
+ import { defineLookPart } from '../core/look/part.js';
12
+ import { codedError } from '../core/errorHints.js';
13
+
14
+ /** @param {any} post PostFX @param {any[]} styleDefs the style pack's effects */
15
+ export function definePostLook(post, styleDefs) {
16
+ const e = post.engine, low = e.tier === 'low', generated = new Map(), source = new Map();
17
+ const defaultOn = d => (d.enabled ?? true) && !(d.costly && low); // a costly effect starts off on low-tier devices unless the game said otherwise
18
+ const decl = h => {
19
+ const d = h._def, n = h.name;
20
+ return { [`${n}.enabled`]: { type: 'bool', default: !!defaultOn(d), cost: d.costly ? 'gpu' : 'uniform',
21
+ why: low && d.costly ? (post._offWhy[n] ?? `costly effect: off on low-tier devices`) : `post effect '${n}'${styleDefs.includes(d) ? ' of the style pack' : ''}`,
22
+ off: `look.post.set({ ${n}: ${defaultOn(d) ? 'false' : 'true'} })` },
23
+ ...Object.fromEntries(Object.entries(d.params ?? {}).map(([k, v]) => [`${n}.${k}`, { type: 'any', default: v, neutral: true, cost: d.fuse ? 'uniform' : 'recompile' }])) };
24
+ };
25
+ const styleValues = () => Object.fromEntries(post._list.filter(h => styleDefs.includes(h._def)).flatMap(h => Object.entries(h.params).map(([k, v]) => [`${h.name}.${k}`, v])));
26
+ /** The game layer records what differs from the default (createEngine({ post }), or an effect the game added) */
27
+ const record = h => { if (!styleDefs.includes(h._def) || h.enabled !== !!defaultOn(h._def)) part.write('game', { [`${h.name}.enabled`]: h.enabled }); };
28
+ const split = k => { const i = k.indexOf('.'); return [k.slice(0, i), k.slice(i + 1)]; };
29
+ const part = defineLookPart(e, {
30
+ id: 'post', group: 'screen', module: 'core', object: () => post.composer, docs: ['recipes/52-look.md'], applyAtStart: false,
31
+ params: Object.assign({}, ...post._list.map(decl)), style: styleValues,
32
+ read: () => ({}),
33
+ normalize(p) { // post.set({ vignette: false }) -> { 'vignette.enabled': false }
34
+ return Object.fromEntries(Object.entries(p).map(([k, v]) => (typeof v === 'boolean' && part.has(`${k}.enabled`) ? [`${k}.enabled`, v] : [k, v])));
35
+ },
36
+ apply(v, changed) {
37
+ const sets = new Map();
38
+ for (const k of changed) {
39
+ const [n, p] = split(k), h = post.get(n);
40
+ if (!h) continue;
41
+ if (p === 'enabled') { if (h.enabled !== !!v[k]) h._enable(!!v[k]); } else if (h.params[p] !== v[k]) (sets.get(h) ?? sets.set(h, {}).get(h))[p] = v[k];
42
+ }
43
+ for (const [h, p] of sets) h._set(p);
44
+ },
45
+ hooks: { '*': { signature: 'GLSL statements that edit `vec4 color` (see PostFuse in render/PostFX.js); spec { glsl, slot: "ldr", order, uniforms, values }', scope: ['vUv', 'tDiffuse', 'uTime', 'uResolution', 'fxHash(vec2)'] } },
46
+ extraSignatures: { add: 'add(effect, { owner })' },
47
+ applyHook(name, impl) {
48
+ if (impl != null && generated.has(name) && source.get(name) === impl) return; // the same spec again (a rolled-back write re-applies every hook): keep the built effect
49
+ generated.get(name)?._remove();
50
+ source.delete(name);
51
+ if (generated.delete(name)) part.retract(name + '.');
52
+ if (impl == null) return;
53
+ if (post.get(name)) throw new Error(`look.post.patch/add('${name}'): an effect named '${name}' already exists; pick another name, or change it with look.post.set({ '${name}.<param>': value })`);
54
+ const s = typeof impl === 'string' ? { glsl: impl } : impl, { slot, order, params, ...fuse } = s;
55
+ // add(effect) passes a whole effect (create | fuse): it keeps its own slot / order / enabled; patch(name, spec) is a fuse snippet in 'ldr'
56
+ const h = s.create || s.fuse ? post._add({ ...s, name }) : post._add({ name, fuse, slot: slot ?? 'ldr', order, params });
57
+ generated.set(name, h); source.set(name, impl); part.extend(decl(h));
58
+ },
59
+ replace: { accepts: 'an array of post effects ({ name, create | fuse, slot, order, params }); null gives the style\'s chain back',
60
+ loses: ['every effect the style, patch() or a replaced chain brought (their look.post values go with them)'] },
61
+ // checked before the record is written, so a wrong replace never reaches applyReplace (review H1)
62
+ validate: (k, v) => (k === '@replace' && !Array.isArray(v) ? 'is an array of effects like [bloom({ strength: 0.4 }), myGrain]; null gives the style chain back' : null),
63
+ applyReplace(impl) {
64
+ if (impl != null && !Array.isArray(impl)) throw new Error('look.post.replace(effects): effects is an array like [bloom({ strength: 0.4 }), myGrain]; null gives the style chain back');
65
+ post._building = true;
66
+ try {
67
+ for (const h of [...post._list]) { h._remove(); part.retract(h.name + '.'); }
68
+ generated.clear(); source.clear();
69
+ for (const d of impl ?? styleDefs) { const lowOff = impl == null && d.costly && low; const h = post._add(d, { enabled: lowOff ? false : undefined }); part.extend(decl(h)); }
70
+ part.restyle(impl ? {} : styleValues());
71
+ } finally { post._building = false; post._sync(); }
72
+ },
73
+ });
74
+ /** Add one custom pass; it is a patch under the effect's name, so owner layers, describe, remove and rollback work like every look verb */
75
+ part.add = (effect, o) => {
76
+ if (!effect || typeof effect.name !== 'string' || (typeof effect.create !== 'function' && !effect.fuse))
77
+ throw codedError('look-verb', "look.post.add(effect): needs { name: 'myEffect', create: (ctx) => pass } (or a fuse snippet { name, fuse: { glsl } }, see PostEffect)");
78
+ // checked here, before any write: the hook key is the effect name, so a second write under it would replace (and tear down) the first effect
79
+ if (post.get(effect.name)) throw codedError('look-verb', `look.post.add: post effect '${effect.name}' is already added; change it with look.post.set({ '${effect.name}.<param>': value }), or drop it with its handle.remove() / look.post.replace([...])`);
80
+ part.patch(effect.name, effect, o);
81
+ // patch's handle would drop the owner's WHOLE post layer (every other effect this owner added); remove only this effect's hook
82
+ return { remove: () => { part.patch(effect.name, null, o); } };
83
+ };
84
+ for (const h of post._list) record(h);
85
+ return { part };
86
+ }
package/render/surface.js CHANGED
@@ -6,6 +6,7 @@ import { placeholderTexture, EFFECTS } from './effects.js';
6
6
  import { detailPatch } from './detail.js';
7
7
  import { lightingPatch } from './lighting.js';
8
8
  import { patchMaterial } from './patches.js';
9
+ import { surfaceDetail } from './lookSurface.js';
9
10
 
10
11
  // Color textures are sRGB; the rest hold data and stay linear (three would otherwise gamma-decode normals and roughness)
11
12
  const COLOR_SLOTS = ['map', 'emissiveMap', 'lightMap', 'sheenColorMap', 'specularColorMap'];
@@ -60,7 +61,8 @@ export function applySurface(m, props, where, engine, lit) {
60
61
  loadSlot(m, k, v, tex, where, engine);
61
62
  } else rest[k] = v;
62
63
  }
63
- if (props.detail) patchMaterial(m, [EFFECTS.world(), detailPatch(props.detail, engine, `${where}.detail`)]);
64
+ const det = props.detail === false ? null : props.detail ?? surfaceDetail(engine); // look.surface.detail is the pack-wide default
65
+ if (det) patchMaterial(m, [EFFECTS.world(), detailPatch(det, engine, `${where}.detail`)]);
64
66
  const l = props.lighting === false ? null : { ...lit, ...props.lighting };
65
67
  if (l && Object.keys(l).length) patchMaterial(m, [lightingPatch(l, `${where}.lighting`)]);
66
68
  return rest;
package/types/core.d.ts CHANGED
@@ -6,6 +6,7 @@ import type {
6
6
  } from './world';
7
7
  import type { World } from './generated/modules/world/World';
8
8
  import type { Net } from './generated/modules/net/Net';
9
+ import type { PostEffect } from './generated/render/PostFX';
9
10
  import type { Grids } from './generated/modules/grid/index';
10
11
  import type { Collision, RigidBodies, CameraRig, CameraKind, CameraShotEvent, Animator, AnimatorOptions, Vehicle } from './physics';
11
12
  import type { Nav } from './nav';
@@ -22,6 +23,8 @@ import type { Events } from './generated/core/Events';
22
23
  import type { Commits } from './generated/core/Commits';
23
24
  import type { Threads } from './generated/core/Threads';
24
25
  import type { Ops } from './generated/core/Ops';
26
+ import type { Views } from './generated/core/Views';
27
+ import type { DebugOverrides } from './generated/core/DebugOverrides';
25
28
  import type { Jobs } from './generated/core/Jobs';
26
29
  import type { Random } from './generated/core/Random';
27
30
  import type { PostFX } from './generated/render/PostFX';
@@ -188,7 +191,7 @@ export interface EventMap extends GameEvents {
188
191
  /** Client (net): host state applied (full: a whole snapshot, else a diff); redraw UI from state here */
189
192
  'net:sync': [{ tick: number; full: boolean }];
190
193
  /** Client (net): the host's answer to an op request (seq from ops.run's return value; tick is the host's), sent after the state it caused */
191
- 'net:result': [{ seq: number; name: string; ok: boolean; reason: string | null; value?: any; tick: number }];
194
+ 'net:result': [{ seq: number; name: string; ok: boolean; code: string | null; value?: any; tick: number }];
192
195
  /** A gameplay error in development / testing; gameplay is frozen (error severity levels, see engine.error) */
193
196
  'engine:error': [EngineError];
194
197
  /** A presentation module errored and was disabled (the game continues) */
@@ -290,6 +293,8 @@ export interface SaveProvider {
290
293
  load: (data: any) => void | Promise<void>;
291
294
  /** Load before the other parts (such as the level) */
292
295
  first?: boolean;
296
+ /** Join atomic ops: copied before an atomic op runs, put back if it fails (plain data; afterLoad does not run on rollback) */
297
+ atomic?: boolean;
293
298
  /** This part's format version, default 1: raise it by 1 when what save() returns changes shape. A save with a newer version is refused */
294
299
  version?: number;
295
300
  /** Upgrade steps: old version -> data => data in the next version's shape, e.g. { 1: d => ({ ...d, beds: [] }) }.
@@ -446,6 +451,18 @@ export interface Assets {
446
451
  draco: any;
447
452
  /** three.js KTX2Loader (created only the first time a KTX2 texture is met, null before) */
448
453
  ktx2: any;
454
+ /** Import report of a loaded model (by name, or a copy from model()): materials, textures with colorSpace, clips, colliders, templates, and issues for what the file has but the scene lost */
455
+ report(nameOrRoot: string | Object3D): AssetReport;
456
+ /** assets.report as text for the console / describe */
457
+ reportText(nameOrRoot: string | Object3D): string;
458
+ }
459
+ /** engine.assets.report(): see recipes/46-blender-art-route.md */
460
+ export interface AssetReport {
461
+ name: string | null; url: string | null; fromFile: boolean;
462
+ counts: Record<string, number>;
463
+ materials: { name: string; type: string; maps: Record<string, any>; flatShading: boolean; vertexColors: boolean; madeByStyle: boolean }[];
464
+ textures: any[]; clips: { name: string; seconds: number }[]; colliders: any[]; templates: any[];
465
+ issues: { severity: 'warn' | 'info'; code: string; msg: string }[];
449
466
  }
450
467
 
451
468
  /** Phase of a loading task */
@@ -622,7 +639,7 @@ export type UIPartValue = boolean | Record<string, any> | UIPartFactory;
622
639
  export interface UIPartDef {
623
640
  on?: boolean;
624
641
  multi?: boolean;
625
- modal?: { freeze?: boolean; cancel?: (engine: Engine) => void; data?: (engine: Engine, options: Record<string, any>) => object } | null;
642
+ modal?: { freeze?: boolean | ((engine: Engine) => boolean); cancel?: (engine: Engine) => void; data?: (engine: Engine, options: Record<string, any>) => object } | null;
626
643
  }
627
644
  /**
628
645
  * What the 'touch' UI part receives in show(view) and update(view) (buttons added later, language changed). Call move / press / release from your controls:
@@ -811,14 +828,17 @@ export type ModuleInput = ModuleDef | ModuleInput[] | false | null | undefined;
811
828
  // ======================================================================
812
829
 
813
830
  export interface EngineOptions {
814
- /** Canvas element (required), e.g. document.getElementById('view') */
815
- canvas: HTMLCanvasElement | HTMLElement;
831
+ /** Canvas element (required unless renderer is given), e.g. document.getElementById('view') */
832
+ canvas?: HTMLCanvasElement | HTMLElement;
833
+ /** A ready three.js renderer (WebGLRenderer or compatible) to use instead of creating one; canvas then defaults to renderer.domElement. The engine configures
834
+ * (pixel ratio, size, tone mapping, shadows) only a renderer it created itself. WebGL is the fully supported path; WebGPU-style renderers may not run shader patches or post effects (recipe 48) */
835
+ renderer?: any;
816
836
  /** Style pack (looks only: materials, sky, lighting, post, UI look), e.g. import lowpoly from '@threedog/style-lowpoly', or a list of parts
817
837
  * deep-merged left to right: [lowpoly, { sky: { sunSize: 600 } }]. Without one: neutral gray placeholders */
818
838
  style?: StyleInput;
819
839
  /** Real-time shadows, default true */
820
840
  shadows?: boolean;
821
- /** Shadow filter: 'basic' (hard edge) | 'pcf' | 'vsm' (softest, costliest), default 'pcf'. Change later with engine.sky.setShadow({ type }) */
841
+ /** Shadow filter: 'basic' (hard edge) | 'pcf' | 'vsm' (softest, costliest), default 'pcf'. Change later with engine.look.shadow.set({ type }) */
822
842
  shadowType?: 'basic' | 'pcf' | 'vsm';
823
843
  /** MSAA anti-aliasing (kept with post effects on), default style.antialias, else on for desktop and off for low-tier devices */
824
844
  antialias?: boolean;
@@ -891,6 +911,8 @@ export interface EngineOptions {
891
911
  threads?: 'auto' | number | false;
892
912
  /** Gameplay waits while the window is in the background or the tab is hidden; default true (engine.page) */
893
913
  pauseOnBlur?: boolean;
914
+ /** false: no default lights in the scene at all (engine.lights.sun / hemi still exist, detached, so sky and describe never see undefined); the game adds its own. Default true */
915
+ lights?: boolean;
894
916
  /** Automatic instancing of repeated static models (engine.batching): false turns it off; default { minCount: 8, cell: engine.stream.cellSize } */
895
917
  batching?: false | BatchingOptions;
896
918
  }
@@ -955,6 +977,22 @@ export interface Thing extends HitThing {
955
977
  id: string; owner: string; at: string | null; phase: 'setup' | 'play'; saved: 'record' | 'code' | 'session' | 'engine'; keeps: string[]; loses: string[];
956
978
  /** the live object (the record's current model, null when not built) */
957
979
  readonly object: Object3D | null;
980
+ /** everything about this id in one JSON-able object: definition file:line, template, model, materials, state, collision rules, related ops, save status, how to change it. Not engine.explain(): that answers "why can this op / quest not run" (recipes/41 section 6) */
981
+ explain(): ThingExplanation;
982
+ }
983
+ /** What thing.explain() returns (`threedog thing <id>` prints the same JSON); modules add keys to rules / state through their explainers */
984
+ export interface ThingExplanation {
985
+ id: string; kind: string; owner: string;
986
+ /** at: 'content/props.js:14' (null in release builds and for code without a file) */
987
+ definition: { at: string | null; template: string | null; templateAt: string | null; level?: string; node?: string; spawned?: boolean; [k: string]: any };
988
+ model: string | null;
989
+ materials: ({ role: string | null; name: string | null; from: string | null; keys: string[]; type: string; color: string | null; mesh: string | null } | { more: number })[];
990
+ state: { position?: number[]; visible?: boolean; scale?: number[]; [k: string]: any };
991
+ rules: { height?: number; blocksMovement?: any; pickable?: boolean; interact?: any; [k: string]: any };
992
+ ops: { op: string; desc: string | null; args: any }[];
993
+ saved: { tier: 'record' | 'code' | 'session' | 'engine'; keeps: string[]; loses: string[]; overridden?: boolean; removed?: boolean };
994
+ change: { runtime: string; permanent: string; diagnostic: string };
995
+ overrides?: any[];
958
996
  }
959
997
  /**
960
998
  * What a ray hit is (RayHit.thing, engine.inspect(id).thing; engine.thing gives the same plus owner / saved): the world record it belongs to, else the
@@ -1117,7 +1155,19 @@ export interface StateParams {
1117
1155
  cutscene?: 'skip' | 'keep';
1118
1156
  }
1119
1157
 
1120
- /** Camera takeover: when non-null no camera module moves the camera (for cutscenes); set back to null when done */
1158
+ /** A claim on something only its owner releases (pause, freeze, takeCamera, views) */
1159
+ export interface OwnerHandle { owner: string; remove(): void }
1160
+ /** What pause / freeze return: the claim handle, plus the old chaining calls forwarded to the engine */
1161
+ export interface ChainedHandle extends OwnerHandle {
1162
+ pause(owner?: string | { owner?: string; kind?: 'test' }, opts?: { kind?: 'test' }): ChainedHandle;
1163
+ resume(owner?: string | { owner?: string }): Engine;
1164
+ freeze(owner?: string | { owner?: string; kind?: 'title' }, opts?: { kind?: 'title' }): ChainedHandle;
1165
+ unfreeze(owner?: string | { owner?: string }): Engine;
1166
+ step(seconds: number, opts?: { render?: boolean; frameEvery?: number; describe?: boolean }): GameState | null;
1167
+ }
1168
+ /** engine.runState: state in one word, by = every pause / freeze owner, blockedBy = opaque input contexts plus 'error' / 'loading' */
1169
+ export interface RunState { state: 'loading' | 'title-frozen' | 'test-paused' | 'paused' | 'running'; by: string[]; blockedBy: string[] }
1170
+ /** Camera takeover: when non-null no camera module moves the camera (for cutscenes); see engine.takeCamera */
1121
1171
  export interface CameraOverride {
1122
1172
  /** Who took over (any name) */
1123
1173
  owner: string;
@@ -1128,6 +1178,128 @@ export interface CameraOverride {
1128
1178
  /** State of automatic resolution */
1129
1179
  export interface AdaptiveState { paused: boolean; on: boolean; target: number; min: number; max: number; [key: string]: any }
1130
1180
 
1181
+ // ======================================================================
1182
+ // Look parts engine.look.<part> (recipes/52-look.md)
1183
+ // ======================================================================
1184
+
1185
+ /** Returned by set / patch / replace: remove() takes that owner's layer back off */
1186
+ export interface LookHandle { remove(): void }
1187
+ /** engine.look.post: a LookPart with add() for one custom pass */
1188
+ export interface LookPost extends LookPart {
1189
+ /** Add ONE custom post pass (name, create | fuse, slot, order, params) without replacing the chain; remove() takes it out again. Slot, order and depth-order errors throw and add nothing. Change its params with set({ '<name>.<param>': v }) */
1190
+ add(effect: PostEffect, opts?: LookOptions): LookHandle;
1191
+ }
1192
+ /** owner: who writes the layer (non-empty name, default 'game'); roles: only materials.patch, the material roles that get the patch */
1193
+ export interface LookOptions { owner?: string; roles?: string[] }
1194
+ /** patch(name, spec): a spec instead of plain GLSL. post: fuse snippet (glsl, slot, order, uniforms, values); sky 'layer:<name>': glsl, blend, order, uniforms */
1195
+ export interface LookPatchSpec {
1196
+ glsl?: string | Record<string, any>;
1197
+ /** post: 'hdr' | 'ldr' */
1198
+ slot?: string;
1199
+ /** post and sky layers: draw order, smaller first */
1200
+ order?: number;
1201
+ uniforms?: Record<string, any>;
1202
+ /** post: live values of the generated effect */
1203
+ values?: Record<string, any>;
1204
+ /** sky layer: 'mix' | 'add' */
1205
+ blend?: string;
1206
+ }
1207
+
1208
+ /**
1209
+ * One look part. Layers, upper wins: engine default < style < game (per owner, last write wins) < engine.debug.override.
1210
+ * A part offers only the verbs that make sense for it; the others throw naming the verb to use.
1211
+ */
1212
+ export interface LookPart<P = Record<string, any>> {
1213
+ /** 'look.<part>': the id engine.catalog() and debug.override use */
1214
+ readonly id: string;
1215
+ /** Shallow-merge into the owner's layer, only the keys given; null drops a key so the layer below shows again. Keys that recompile shaders warn once in dev */
1216
+ set(params: { [K in keyof P]?: P[K] | null } & Record<string, any>, opts?: LookOptions): LookHandle;
1217
+ /** Swap one named GLSL hook the part registered (names: engine.catalog('look.<part>').hooks); the same name again overrides; patch(name, null) restores the default */
1218
+ patch(name: string, glsl: string | LookPatchSpec | null, opts?: LookOptions): LookHandle;
1219
+ /** Take the whole part over (Material, texture, object, effect list ...: see the catalog); replace(null) gives it back. materials.replace takes the role first */
1220
+ replace(impl: any, opts?: LookOptions): LookHandle;
1221
+ replace(role: string, impl: any, opts?: LookOptions): LookHandle;
1222
+ /** Drop every game and debug layer of that owner (the style value shows again); returns how many layers were removed, like engine.debug.clear */
1223
+ clear(owner: string): number;
1224
+ /** The resolved value of a key (what is in use now) */
1225
+ value(key: string): any;
1226
+ /** The value from the highest game / debug layer for the key (undefined when only style or default gives it) */
1227
+ top(key: string): any;
1228
+ /** The three.js object(s) behind the part (renderer, lights, scene.fog ...); changing it directly works but describe tags it 'three'.
1229
+ * look.materials: a function, object('wool') = the last Material made for that role, object() = all of them */
1230
+ readonly object: any;
1231
+ /** Each verb's call shape, e.g. { set: 'set(params, { owner })', replace: 'replace(role, ...)' } (also in engine.catalog('look.<part>')) */
1232
+ readonly signatures: Record<string, string>;
1233
+ // ---- for authors of a part made with defineLookPart (recipes/52-look.md) ----
1234
+ /** Write raw keys (params, 'hook:<name>', '@replace') for an owner, no normalize; null drops a key */
1235
+ write(owner: string, values: Record<string, any>, opts?: { layer?: 'game' | 'debug' }): LookHandle;
1236
+ /** What one owner holds for a key, or undefined */
1237
+ ownerValue(owner: string, key: string, opts?: { layer?: 'game' | 'debug' }): any;
1238
+ /** Add declared keys to a started part (same fields as defineLookPart params) */
1239
+ extend(params: Record<string, any>): void;
1240
+ /** Remove every key starting with prefix, with every layer's value for them */
1241
+ retract(prefix: string): void;
1242
+ /** Is key a declared param */
1243
+ has(key: string): boolean;
1244
+ /** [key, value] pairs in effect whose key starts with prefix */
1245
+ resolved(prefix?: string): Array<[string, any]>;
1246
+ /** Replace the style layer */
1247
+ restyle(values: Record<string, any>): void;
1248
+ /** Declare keys a style-driven system writes every frame (by = the driver's module name); drive(keys, null) hands them back */
1249
+ drive(keys: string[], by: string | null): void;
1250
+ /** Unregister the part (its module went away) */
1251
+ dispose(): void;
1252
+ }
1253
+
1254
+ export interface LookTone { mapping: string; exposure: number | Array<[number, number]> | ((t: number) => number) }
1255
+ export interface LookLightSide { color?: ColorLike; intensity?: number }
1256
+ export interface LookLights { sun: LookLightSide | 'manual' | false; hemi: LookLightSide | 'manual' | false }
1257
+ /** The map itself is the replace slot: look.env.replace('sky' | Texture | null) */
1258
+ export interface LookEnv { intensity: number; rotation: number; interval: number }
1259
+ export interface LookFog { kind: string; color: ColorLike | 'horizon'; density: number; near: number; far: number; height: number; falloff: number; enabled: boolean }
1260
+ export interface LookSky { clouds: Record<string, any>; backdrop: ColorLike | null }
1261
+ export interface LookShadow {
1262
+ type: 'basic' | 'pcf' | 'vsm'; radius: number; blurSamples: number; bias: number; normalBias: number; mapSize: number; updateEvery: number;
1263
+ snap: number | 'texel'; ahead: number; cascades: number; maxFar: number; fade: boolean; lightMargin: number; enabled: boolean;
1264
+ split: 'practical' | 'uniform' | 'logarithmic' | ((count: number, near: number, far: number, out: number[]) => void);
1265
+ }
1266
+ export interface LookCloudShadow { shadow: number; scale: number; speed: [number, number] }
1267
+ export interface LookWind { frequency: number; amplitude: number }
1268
+ export interface LookGround {
1269
+ colors: Record<string, ColorLike>; biomeColors: Record<string, string | string[]>; steep: Array<{ maxNormalY: number; colors: any }>;
1270
+ variation: any; detail: any; shading: string;
1271
+ }
1272
+ export interface LookSurface { lighting: Record<string, any>; detail: Record<string, any>; ramp: number[]; soften: number }
1273
+ export interface LookWater {
1274
+ color: ColorLike; opacity: number; depthColor: { shallow?: ColorLike; deep?: ColorLike }; foam: Record<string, any>;
1275
+ waveHeight: number; waveScale: number; waveSpeed: number; fresnel: number;
1276
+ }
1277
+
1278
+ /** engine.look: the parts by name. A part exists only when the module that provides it is installed (fog / sky / shadow / env: sky(); ground: terrain(); wind: vegetation(); water; weather) */
1279
+ export interface Look {
1280
+ tone: LookPart<LookTone>;
1281
+ lights: LookPart<LookLights>;
1282
+ cloudShadow: LookPart<LookCloudShadow>;
1283
+ /** Old name of cloudShadow (recipes/52-look.md, Old names) */
1284
+ clouds: LookPart<LookCloudShadow>;
1285
+ env: LookPart<LookEnv>;
1286
+ fog: LookPart<LookFog>;
1287
+ sky: LookPart<LookSky>;
1288
+ shadow: LookPart<LookShadow>;
1289
+ /** Roles are the keys: set({ wool: { roughness: 0.4 } }), patch(name, spec, { roles }), replace('wool', Material | fn) */
1290
+ materials: LookPart<Record<string, Record<string, any>>>;
1291
+ surface: LookPart<LookSurface>;
1292
+ ground: LookPart<LookGround>;
1293
+ wind: LookPart<LookWind>;
1294
+ water: LookPart<LookWater>;
1295
+ /** Keys 'rain.speed', 'snow.size', 'lightning.brightness', overcastColor ...; patch('rain.fragment', wholeShaderText) */
1296
+ weather: LookPart;
1297
+ /** Per effect: set({ bloom: { strength: 0.6 }, vignette: false }); patch(name, { glsl, slot, order, uniforms, values }); add(effect, { owner }); replace([effects]) */
1298
+ post: LookPost;
1299
+ /** Parts made with defineLookPart */
1300
+ [custom: string]: LookPart;
1301
+ }
1302
+
1131
1303
  /**
1132
1304
  * The engine. Created by createEngine({ canvas, style }); engine.use(module...) installs modules, engine.start() starts it.
1133
1305
  * Installed modules hang on the engine (engine.terrain, engine.sky...); modules not installed are undefined, check with engine.xxx?.method().
@@ -1160,7 +1332,7 @@ export declare class Engine {
1160
1332
  focus: Vector3;
1161
1333
  /** Whether shadows are on */
1162
1334
  shadows: boolean;
1163
- /** Shadow filter in use; change it with sky.setShadow({ type }) */
1335
+ /** Shadow filter in use; change it with look.shadow.set({ type }) */
1164
1336
  shadowType: 'basic' | 'pcf' | 'vsm';
1165
1337
  /** Current ground */
1166
1338
  ground: Ground;
@@ -1195,6 +1367,12 @@ export declare class Engine {
1195
1367
  * A module installed after start() runs no fixed / frame hook until it is 'running'; `await engine.loading.settled()` waits for that
1196
1368
  */
1197
1369
  readonly moduleStates: Record<string, 'registered' | 'initializing' | 'running' | 'failed' | 'disposed'>;
1370
+ /**
1371
+ * What this game can do, read from the existing registrations (modules, ops, save parts, describe, params schemas).
1372
+ * No argument: short list; a module id / op name: that entry expanded (null if unknown); { find }: the short list filtered. recipes/51-capability-catalog.md
1373
+ * @example engine.catalog('shop').ops[0].failures // ['soldOut', 'noMoney']
1374
+ */
1375
+ catalog(id?: string | { find?: string }): any;
1198
1376
  /**
1199
1377
  * Gameplay error in development / testing (module hooks, onFixed / onFrame / clock callbacks, event listeners): { where (location of the error),
1200
1378
  * message }, gameplay is frozen; null when there is no error. A release build does not freeze, it reports once in the console
@@ -1235,6 +1413,8 @@ export declare class Engine {
1235
1413
  readonly loading: Loading;
1236
1414
  /** Post-processing: named effects in slots (add / get / enable / list) */
1237
1415
  post: PostFX;
1416
+ /** Every look in one place: engine.look.<part>.set / patch / replace (recipes/52-look.md) */
1417
+ look: Look;
1238
1418
  /** UI parts: every piece of screen UI is replaceable or off (see recipes/26-ui-parts.md) */
1239
1419
  ui: UIParts;
1240
1420
  /** Automatic resolution state */
@@ -1246,8 +1426,12 @@ export declare class Engine {
1246
1426
  cpuMs: number;
1247
1427
  /** cpuMs split by phase (last frame): fixed = input + fixed steps, frame = frame hooks incl. stream / jobs, render = draw submission, afterRender = its hooks */
1248
1428
  cpuPhases: { fixed: number; frame: number; render: number; afterRender: number };
1249
- /** Camera takeover (for cutscenes), null when unused */
1429
+ /** The camera holder in charge (latest engine.takeCamera claim), null when nobody holds it. Assigning { owner } / null is the old alias of takeCamera */
1250
1430
  cameraOverride: CameraOverride | null;
1431
+ /** Take the camera over (camera modules leave it alone) until remove(); the latest holder is in charge, releasing hands it back to the previous one */
1432
+ takeCamera(owner: string | ({ owner: string } & Partial<CameraOverride>), opts?: Partial<CameraOverride>): OwnerHandle;
1433
+ /** Why the page is (not) advancing; the dev bridge and MCP tools copy it as-is */
1434
+ readonly runState: RunState;
1251
1435
  /** Draco/KTX2 decoder directory */
1252
1436
  decoders: string;
1253
1437
  /** Game clock: game seconds now, after / every (clock-time / season timers are on engine.sky) */
@@ -1269,6 +1453,8 @@ export declare class Engine {
1269
1453
  threads: Threads;
1270
1454
  /** One entry point for actions players and NPCs decide to do: define / run / can / list / recent, see Ops and recipes/23-ops.md */
1271
1455
  ops: Ops;
1456
+ /** Named fixed camera views for repeatable screenshots: define / show / release (recipes/46-blender-art-route.md) */
1457
+ views: Views;
1272
1458
  /** Fixed-step count (the gameplay timeline: does not advance while frozen; commits due times, event history and the operation log use it) */
1273
1459
  readonly tick: number;
1274
1460
  /** Seeded random numbers (use for gameplay randomness: reproducible and saved with the game) */
@@ -1363,8 +1549,8 @@ export declare class Engine {
1363
1549
  photo?: Photo;
1364
1550
  /** Ambience (ambience() module) */
1365
1551
  ambience?: Ambience;
1366
- /** F3 debug panel (debug() module) */
1367
- debug?: DebugPanel;
1552
+ /** Diagnostic overrides and view modes with an owner (override / clear / view: core, always there); panel is the F3 panel, null without the debug() module */
1553
+ debug: DebugOverrides & { panel: DebugPanel | null };
1368
1554
  /** Navmesh (nav() module) */
1369
1555
  nav?: Nav;
1370
1556
  /** HLOD, merged distant geometry (hlod() module) @experimental */
@@ -1460,15 +1646,7 @@ export declare class Engine {
1460
1646
  setShadows(on: boolean): void;
1461
1647
  /** Fog distance (meters), also adjusts the camera far plane */
1462
1648
  setFogFar(d: number): void;
1463
- /** Tone mapping at run time ('aces' | 'agx' | 'neutral' | 'none'); materials recompile on their next draw, so not every frame */
1464
- setToneMapping(kind: 'aces' | 'agx' | 'neutral' | 'none'): void;
1465
- /**
1466
- * Exposure at run time: a number, [[time 0-1, exposure], ...] over the day or (sky) => number (both evaluated by the sky module each frame);
1467
- * replaces style.exposure
1468
- * @example engine.setExposure(1.4); engine.setExposure(sky => sky.isDay ? 1 : 1.5);
1469
- */
1470
- setExposure(v: number | [number, number][] | ((sky: any) => number)): void;
1471
- /** Exposure per frame from style.exposure / setExposure keyframes or function, null for a plain number; the sky module calls it with engine.sky @readonly */
1649
+ /** Exposure per frame from style.exposure / look.tone keyframes or function, null for a plain number; the sky module calls it with engine.sky @readonly */
1472
1650
  exposureDriver: ((sky: any) => number) | null;
1473
1651
 
1474
1652
  // ---------- Rays, scenarios ----------
@@ -1506,18 +1684,20 @@ export declare class Engine {
1506
1684
  * Pause the real-time loop: the picture stops and even rendering stops, only step() advances (for tests and screenshots). Use freeze() for a game menu
1507
1685
  * pause
1508
1686
  */
1509
- pause(): this;
1510
- /** Resume the real-time loop */
1511
- resume(): this;
1687
+ pause(owner?: string | { owner?: string; kind?: 'test' }, opts?: { kind?: 'test' }): ChainedHandle;
1688
+ /** Resume the real-time loop (only this owner's pause) */
1689
+ resume(owner?: string | { owner?: string }): this;
1690
+ /** Run fn at the start of the next fixed step (via commits); a Promise of fn's value */
1691
+ nextFixed<T>(fn: () => T): Promise<T>;
1512
1692
  /**
1513
1693
  * Gameplay pause (menu, flow's paused): fixed steps are skipped entirely (onFixed, module fixed, the game clock and engine.elapsed all stop), frame
1514
1694
  * hooks and rendering continue and the UI works.
1515
1695
  * So gameplay logic (movement, timing, quest checks, cutscene waits) belongs in fixed, or check engine.frozen first in frame. owner is the freezer's
1516
1696
  * name, default 'game'
1517
1697
  */
1518
- freeze(owner?: string): this;
1698
+ freeze(owner?: string | { owner?: string; kind?: 'title' }, opts?: { kind?: 'title' }): ChainedHandle;
1519
1699
  /** Release the freeze of owner (gameplay resumes only when all freezers are released) */
1520
- unfreeze(owner?: string): this;
1700
+ unfreeze(owner?: string | { owner?: string }): this;
1521
1701
  /** Is anyone freezing gameplay? */
1522
1702
  readonly frozen: boolean;
1523
1703
  /**
@@ -1541,6 +1721,18 @@ export declare class Engine {
1541
1721
  * @example engine.skip({ seconds: 600 })
1542
1722
  */
1543
1723
  skip(opts: SkipOptions): Promise<{ seconds: number; clock: string | null; day: number | null } | null>;
1724
+ /**
1725
+ * Consistency check: engine.skip({ seconds }) vs stepping the same span in fixed steps; compares the saved state. Leaves the world at the stepped state (use a scratch playthrough or a test).
1726
+ * @param ignore state paths (or prefixes) not to compare
1727
+ * @returns a = after skip, b = after stepping
1728
+ * @example const r = await engine.checkSkip(600); if (!r.ok) console.log(r.diffs);
1729
+ */
1730
+ checkSkip(seconds: number, opts?: { ignore?: string[] }): Promise<{ ok: boolean; diffs: { path: string; a: any; b: any }[] }>;
1731
+ /**
1732
+ * Consistency check: save -> load gives the same saved state back (nothing is written to the browser).
1733
+ * @example const r = await engine.checkSave(); if (!r.ok) console.log(r.diffs);
1734
+ */
1735
+ checkSave(opts?: { ignore?: string[] }): Promise<{ ok: boolean; diffs: { path: string; a: any; b: any }[] }>;
1544
1736
  /**
1545
1737
  * Call engine.describe(opts?: { radius?: number }) to get the current game state (a plain object, JSON.stringify-able); radius is how far counts as
1546
1738
  * "nearby" (meters, default 30).
@@ -698,6 +698,11 @@ export declare class Character {
698
698
  exit(): void;
699
699
  /** Play a one-shot action (e.g. 'wave'); skipped if the model has no such clip */
700
700
  playAction(name: string): void;
701
+ /**
702
+ * Run fn(character, dt) every frame right after the animation pose is applied (model clips or procedural rig): attach things to bones or adjust bones. h.remove() stops it. Presentation only.
703
+ * @example const h = player.onPose(() => sword.position.copy(hand.getWorldPosition(v)));
704
+ */
705
+ onPose(fn: (character: Character, dt: number) => void): { remove(): void };
701
706
  /**
702
707
  * Fully delete this character: exits the vehicle first, releases animation and movement, removes it from the scene and releases geometry and materials
703
708
  * (used by npcs.remove / removePlayer)
@@ -714,6 +719,11 @@ export declare class Character {
714
719
  * after has it
715
720
  */
716
721
  syncRecord(): this;
722
+ /**
723
+ * Walk to a point along characters.findPath on fixed steps; never rejects. One walk per character: a new walkTo, dispose() or a save load ends the old
724
+ * one with 'cancelled'. Transient: not saved, not fast-forwarded by engine.skip
725
+ */
726
+ walkTo(target: Vector3 | { x: number; z: number } | [number, number, number], opts?: { speed?: number; arrive?: number; turnRate?: number; stuckSeconds?: number; maxRepaths?: number; run?: boolean }): Promise<{ status: 'arrived' | 'noPath' | 'stuck' | 'cancelled' }> & { remove(): void };
717
727
  /** Move in a direction (called once per fixed step): dirX/dirZ is the world direction (length 0–1), run to run, dt in seconds */
718
728
  move(dirX: number, dirZ: number, run: boolean, dt: number, speedOverride?: number): void;
719
729
  /** Ground type underfoot ('water' while swimming) */