threedog 0.1.0 → 0.2.1

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 (244) hide show
  1. package/README.md +4 -4
  2. package/core/Animator.js +1 -0
  3. package/core/Assets.js +28 -0
  4. package/core/DebugOverrides.js +143 -0
  5. package/core/Describe.js +14 -3
  6. package/core/Engine.js +44 -72
  7. package/core/Events.js +59 -1
  8. package/core/I18n.js +2 -2
  9. package/core/Inspect.js +12 -32
  10. package/core/InspectScene.js +7 -3
  11. package/core/MaterialInfo.js +32 -0
  12. package/core/Ops.js +43 -59
  13. package/core/Saves.js +5 -4
  14. package/core/UrlState.js +3 -2
  15. package/core/Vars.js +1 -0
  16. package/core/Views.js +49 -0
  17. package/core/actor.js +2 -2
  18. package/core/assetReport.js +83 -0
  19. package/core/catalog.js +169 -0
  20. package/core/checks.js +67 -0
  21. package/core/claims.js +51 -0
  22. package/core/debugView.js +76 -0
  23. package/core/describeRender.js +51 -0
  24. package/core/describeText.js +11 -4
  25. package/core/errorCodes.js +33 -0
  26. package/core/errorHints.js +6 -1
  27. package/core/grid.js +127 -0
  28. package/core/gridLoad.js +19 -0
  29. package/core/holds.js +106 -0
  30. package/core/lifecycle.js +1 -0
  31. package/core/lightWatch.js +23 -3
  32. package/core/look/coreParts.js +112 -0
  33. package/core/look/layers.js +136 -0
  34. package/core/look/part.js +173 -0
  35. package/core/look/report.js +79 -0
  36. package/core/look/write.js +86 -0
  37. package/core/loop.js +22 -16
  38. package/core/modules.js +19 -5
  39. package/core/opsAtomic.js +31 -0
  40. package/core/opsCheck.js +25 -14
  41. package/core/opsFail.js +20 -0
  42. package/core/opsHistory.js +6 -6
  43. package/core/opsRun.js +77 -0
  44. package/core/params.js +132 -0
  45. package/core/renamed.js +22 -0
  46. package/core/saveApply.js +2 -2
  47. package/core/sceneMethods.js +9 -34
  48. package/core/services.js +73 -0
  49. package/core/startup.js +3 -1
  50. package/core/styleParts.js +11 -9
  51. package/core/thingExplain.js +68 -0
  52. package/core/thingOps.js +35 -24
  53. package/core/things.js +15 -1
  54. package/core/util.js +11 -0
  55. package/core/validate.js +23 -7
  56. package/docs/AI.md +93 -114
  57. package/docs/API.md +8 -9
  58. package/docs/CODEMAP.md +67 -53
  59. package/docs/COMMANDS.md +21 -7
  60. package/docs/CONVENTIONS.md +22 -11
  61. package/docs/THREE.md +3 -3
  62. package/docs/api/assets.md +3 -0
  63. package/docs/api/characters.md +5 -2
  64. package/docs/api/collision.md +4 -0
  65. package/docs/api/content.md +1 -0
  66. package/docs/api/engine.md +23 -14
  67. package/docs/api/events.md +5 -1
  68. package/docs/api/post.md +5 -4
  69. package/docs/api/saves.md +2 -1
  70. package/docs/api/sky.md +3 -3
  71. package/docs/api/style.md +8 -8
  72. package/docs/api/tools.md +5 -2
  73. package/docs/api/vegetation.md +1 -0
  74. package/docs/api/weather.md +1 -1
  75. package/docs/recipes/01-new-game.md +41 -43
  76. package/docs/recipes/02-npc.md +38 -22
  77. package/docs/recipes/03-items-pickups.md +4 -4
  78. package/docs/recipes/04-quests.md +23 -23
  79. package/docs/recipes/05-props-bake.md +5 -5
  80. package/docs/recipes/06-clock-events.md +13 -0
  81. package/docs/recipes/07-flow-scenes-pause.md +6 -2
  82. package/docs/recipes/08-weather-sky.md +6 -6
  83. package/docs/recipes/09-style-pack.md +35 -100
  84. package/docs/recipes/12-navmesh.md +22 -0
  85. package/docs/recipes/13-animation.md +25 -6
  86. package/docs/recipes/14-custom-module.md +6 -7
  87. package/docs/recipes/15-perf.md +9 -1
  88. package/docs/recipes/16-dev-bridge.md +52 -18
  89. package/docs/recipes/18-world.md +5 -2
  90. package/docs/recipes/19-shooting-picking.md +9 -8
  91. package/docs/recipes/20-content-actions-save.md +10 -10
  92. package/docs/recipes/21-camera.md +51 -2
  93. package/docs/recipes/22-shop-gold.md +16 -16
  94. package/docs/recipes/23-ops.md +46 -10
  95. package/docs/recipes/27-net.md +3 -3
  96. package/docs/recipes/28-terrain.md +2 -2
  97. package/docs/recipes/29-grid.md +47 -27
  98. package/docs/recipes/34-environment-lighting.md +11 -10
  99. package/docs/recipes/35-style-from-reference.md +41 -46
  100. package/docs/recipes/36-sky-ground-plant-looks.md +22 -20
  101. package/docs/recipes/37-terrain-look-hooks.md +34 -13
  102. package/docs/recipes/38-environment-look-hooks.md +49 -42
  103. package/docs/recipes/40-scene.md +29 -0
  104. package/docs/recipes/41-thing-registry.md +29 -0
  105. package/docs/recipes/42-terrain-shape.md +1 -1
  106. package/docs/recipes/43-shader-patches-surface-looks.md +37 -20
  107. package/docs/recipes/44-water-weather-look-hooks.md +11 -9
  108. package/docs/recipes/45-cascaded-shadows.md +2 -2
  109. package/docs/recipes/46-blender-art-route.md +26 -4
  110. package/docs/recipes/47-island-snow-backdrop.md +4 -3
  111. package/docs/recipes/48-make-material.md +70 -0
  112. package/docs/recipes/49-game-module-contract.md +71 -0
  113. package/docs/recipes/50-own-renderer.md +12 -0
  114. package/docs/recipes/51-capability-catalog.md +63 -0
  115. package/docs/recipes/52-look.md +146 -0
  116. package/docs/recipes/53-ground-up-close.md +58 -0
  117. package/examples/action/GAMEMAP.md +7 -7
  118. package/examples/action/content/index.js +2 -1
  119. package/examples/action/content/views.js +6 -0
  120. package/examples/action/main.js +3 -2
  121. package/examples/sheepisland/GAMEMAP.md +3 -4
  122. package/examples/styletest/GAMEMAP.md +3 -3
  123. package/examples/styletest/content/npcs.js +1 -1
  124. package/examples/styletest/main.js +2 -2
  125. package/examples/styletest/panel.js +3 -3
  126. package/examples/world/GAMEMAP.md +3 -3
  127. package/examples/world/content/npcs.js +1 -1
  128. package/examples/world/main.js +1 -1
  129. package/index.d.ts +35 -2
  130. package/index.js +6 -3
  131. package/llms.txt +13 -7
  132. package/modules/ambience/Ambience.js +5 -2
  133. package/modules/camera/FirstPersonCamera.js +3 -5
  134. package/modules/camera/FixedCamera.js +19 -12
  135. package/modules/camera/FollowCamera.js +14 -8
  136. package/modules/camera/RtsCamera.js +3 -5
  137. package/modules/camera/common.js +40 -10
  138. package/modules/camera/index.js +1 -1
  139. package/modules/camera/projection.js +34 -0
  140. package/modules/characters/Character.js +45 -31
  141. package/modules/characters/assetModel.js +35 -7
  142. package/modules/characters/astar.js +14 -7
  143. package/modules/characters/index.js +6 -3
  144. package/modules/characters/movers/simple.js +6 -1
  145. package/modules/characters/npcSim.js +8 -2
  146. package/modules/characters/pathAsync.js +12 -6
  147. package/modules/characters/pathJob.js +2 -1
  148. package/modules/characters/proceduralRig.js +50 -11
  149. package/modules/characters/useModel.js +22 -0
  150. package/modules/characters/walkTo.js +58 -0
  151. package/modules/collision/Collision.js +102 -4
  152. package/modules/content/explain.js +13 -0
  153. package/modules/content/index.js +3 -1
  154. package/modules/content/loader.js +3 -0
  155. package/modules/content/rules.js +1 -0
  156. package/modules/debug/DebugPanel.js +11 -5
  157. package/modules/entities/Entities.js +6 -2
  158. package/modules/flow/index.js +5 -2
  159. package/modules/gameplay/Dialogue.js +5 -2
  160. package/modules/gameplay/Interactions.js +12 -2
  161. package/modules/gameplay/Inventory.js +21 -11
  162. package/modules/gameplay/Quests.js +13 -3
  163. package/modules/gameplay/pickups.js +6 -4
  164. package/modules/grid/Layer.js +1 -1
  165. package/modules/grid/index.js +1 -1
  166. package/modules/grid/tiles.js +9 -5
  167. package/modules/hlod/index.js +5 -2
  168. package/modules/hud/index.js +5 -2
  169. package/modules/level/index.js +5 -3
  170. package/modules/lights/index.js +5 -2
  171. package/modules/music/Music.js +6 -2
  172. package/modules/nav/index.js +5 -3
  173. package/modules/net/Client.js +4 -3
  174. package/modules/net/Host.js +2 -2
  175. package/modules/net/index.js +5 -3
  176. package/modules/particles/Particles.js +1 -1
  177. package/modules/photo/Photo.js +10 -7
  178. package/modules/rigid/RigidBodies.js +5 -2
  179. package/modules/settings/Settings.js +6 -3
  180. package/modules/settings/apply.js +2 -1
  181. package/modules/sky/Sky.js +21 -19
  182. package/modules/sky/cascades.js +6 -6
  183. package/modules/sky/domeLayers.js +1 -1
  184. package/modules/sky/environment.js +39 -13
  185. package/modules/sky/fog.js +9 -6
  186. package/modules/sky/frame.js +4 -3
  187. package/modules/sky/look.js +3 -2
  188. package/modules/sky/lookFog.js +80 -0
  189. package/modules/sky/lookShadow.js +50 -0
  190. package/modules/sky/lookSky.js +108 -0
  191. package/modules/sky/shader.js +2 -2
  192. package/modules/sky/shadow.js +4 -10
  193. package/modules/sky/skyModule.js +4 -3
  194. package/modules/terrain/ChunkManager.js +2 -33
  195. package/modules/terrain/chunkLevels.js +40 -0
  196. package/modules/terrain/index.js +10 -2
  197. package/modules/terrain/lookGround.js +61 -0
  198. package/modules/timeline/Timeline.js +7 -3
  199. package/modules/timeline/Tween.js +3 -7
  200. package/modules/timeline/shots.js +6 -4
  201. package/modules/triggers/index.js +9 -2
  202. package/modules/vegetation/Vegetation.js +17 -4
  203. package/modules/vegetation/index.js +7 -4
  204. package/modules/vegetation/lookWind.js +37 -0
  205. package/modules/vegetation/nearFade.js +39 -0
  206. package/modules/water/Water.js +19 -3
  207. package/modules/water/look.js +80 -0
  208. package/modules/weather/Weather.js +22 -31
  209. package/modules/weather/look.js +75 -0
  210. package/modules/weather/particles.js +1 -1
  211. package/modules/weather/strings.js +15 -0
  212. package/modules/world/explain.js +11 -0
  213. package/modules/world/index.js +11 -4
  214. package/modules/world/thingSource.js +44 -0
  215. package/package.json +2 -1
  216. package/render/PostFX.js +48 -51
  217. package/render/detail.js +39 -15
  218. package/render/effects.js +4 -2
  219. package/render/fuse.js +12 -0
  220. package/render/lights.js +4 -2
  221. package/render/lookSurface.js +161 -0
  222. package/render/materials.js +27 -10
  223. package/render/postLook.js +86 -0
  224. package/render/surface.js +3 -1
  225. package/types/core.d.ts +223 -29
  226. package/types/gameplay.d.ts +22 -6
  227. package/types/generated/core/DebugOverrides.d.ts +52 -0
  228. package/types/generated/core/Events.d.ts +43 -0
  229. package/types/generated/core/Ops.d.ts +62 -21
  230. package/types/generated/core/Saves.d.ts +1 -0
  231. package/types/generated/core/Views.d.ts +33 -0
  232. package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
  233. package/types/generated/modules/grid/Layer.d.ts +1 -0
  234. package/types/generated/modules/sky/Sky.d.ts +10 -17
  235. package/types/generated/modules/weather/Weather.d.ts +5 -15
  236. package/types/generated/render/PostFX.d.ts +20 -23
  237. package/types/generated/render/materials.d.ts +10 -0
  238. package/types/physics.d.ts +8 -0
  239. package/types/style.d.ts +35 -20
  240. package/types/world.d.ts +7 -1
  241. package/ui/Parts.js +6 -2
  242. package/ui/UI.js +1 -1
  243. package/ui/defaults.js +1 -1
  244. package/docs/api/debug.md +0 -10
@@ -14,6 +14,7 @@
14
14
  import * as THREE from 'three';
15
15
  import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js';
16
16
  import { checkOptions } from '../../core/validate.js';
17
+ import { readParams, keysSchema } from '../../core/params.js';
17
18
  import { movesVertices } from '../../render/patches.js';
18
19
  /** @import { ModuleDef } from '../../types/core' */
19
20
  /** @import { Hlod, HlodOptions } from '../../types/world' */
@@ -39,6 +40,8 @@ function mergeGroup(meshes) {
39
40
  }
40
41
 
41
42
  const FULL = { detail: 'full' };
43
+ const HLOD_PARAMS = keysSchema(['level', ...ADD_KEYS]);
44
+
42
45
  /**
43
46
  * HLOD (merge far buildings into a few meshes) -> engine.hlod
44
47
  * @param {HlodOptions} [opts]
@@ -46,6 +49,7 @@ const FULL = { detail: 'full' };
46
49
  * @experimental
47
50
  */
48
51
  export function hlod(opts = {}) {
52
+ readParams('hlod', HLOD_PARAMS, opts);
49
53
  const { level: autoLevel = true, ...defaults } = opts;
50
54
  let e = null, timer = 0, levelHandle = null;
51
55
  const handles = new Set();
@@ -148,10 +152,9 @@ export function hlod(opts = {}) {
148
152
 
149
153
  const addLevel = root => { levelHandle?.remove(); levelHandle = root ? api.add(root) : null; };
150
154
  return {
151
- name: 'hlod', label: 'HLOD', optional: ['terrain', 'level'], presentation: true,
155
+ name: 'hlod', params: HLOD_PARAMS, options: opts, label: 'HLOD', optional: ['terrain', 'level'], presentation: true,
152
156
  install(engine) {
153
157
  e = engine;
154
- checkOptions('hlod()', opts, ['level', ...ADD_KEYS]);
155
158
  if (autoLevel) {
156
159
  e.events.on('level:loaded', ({ root }) => addLevel(root));
157
160
  if (e.level?.ready && e.level.root) addLevel(e.level.root); // install hlod only after the level is ready
@@ -13,6 +13,7 @@
13
13
  import * as THREE from 'three';
14
14
  import { injectUICSS, worldToScreen } from '../../ui/UI.js';
15
15
  import { checkOptions } from '../../core/validate.js';
16
+ import { readParams, keysSchema } from '../../core/params.js';
16
17
  import { vec3 } from '../../core/math.js';
17
18
  import { surfaceOr } from '../../core/ground.js';
18
19
  import { CSS, defineHudParts } from './parts.js';
@@ -27,12 +28,15 @@ const MARKER_KEYS = ['label', 'icon', 'offscreen', 'distance', 'height'];
27
28
  const _size = new THREE.Vector2();
28
29
  const EDGE = 28; // how far the arrow sits from the screen edge (px)
29
30
 
31
+ const HUD_PARAMS = keysSchema(['questMarkers']);
32
+
30
33
  /**
31
34
  * Objective markers, counters, progress bars -> engine.hud
32
35
  * @param {HudOptions} [opts]
33
36
  * @returns {ModuleDef<Hud>}
34
37
  */
35
38
  export function hud(opts = {}) {
39
+ readParams('hud', HUD_PARAMS, opts);
36
40
  let e = null, root = null;
37
41
  const items = new Map(); // counters, bars: id -> { kind, o, part }
38
42
  const quest = new Map(); // quest id -> auto marker
@@ -141,10 +145,9 @@ export function hud(opts = {}) {
141
145
  };
142
146
 
143
147
  return {
144
- name: 'hud', label: 'Objective markers', optional: ['inventory', 'content', 'level', 'quests'], stage: 'presentation', after: ['particles', 'settings'], presentation: true,
148
+ name: 'hud', params: HUD_PARAMS, options: opts, label: 'Objective markers', optional: ['inventory', 'content', 'level', 'quests'], stage: 'presentation', after: ['particles', 'settings'], presentation: true,
145
149
  install(engine) {
146
150
  e = engine;
147
- checkOptions('hud()', opts, ['questMarkers']);
148
151
  e.i18n.add(STRINGS);
149
152
  defineHudParts(e, containers);
150
153
  for (const ev of ['quest:start', 'quest:step', 'quest:part', 'quest:done', 'quest:fail', 'save:loaded', 'session:start']) e.events.on(ev, syncQuests);
@@ -60,7 +60,7 @@
60
60
  import * as THREE from 'three';
61
61
  import { buildHeightfield } from './heightfield.js';
62
62
  import { toast } from '../../ui/UI.js';
63
- import { checkOptions } from '../../core/validate.js';
63
+ import { readParams, keysSchema } from '../../core/params.js';
64
64
  import { MARKER_RE, levelNodes } from './nodes.js';
65
65
  import { worldTrimeshes, colliderBoxes } from './geometry.js';
66
66
 
@@ -82,7 +82,10 @@ function chainValue(o, root, key) {
82
82
  return undefined;
83
83
  }
84
84
 
85
+ const LEVEL_PARAMS = keysSchema(['url', 'scene', 'walkable', 'colliders', 'cellSize', 'outside', 'waterLevel', 'colliderPad', 'colliderHeight', 'sharpEdge', 'hideMarkers', 'addToScene']);
86
+
85
87
  export function level(opts = {}) {
88
+ readParams('level', LEVEL_PARAMS, opts);
86
89
  const { url = null, scene = null, walkable = null, colliders = 'named', cellSize = 0.5, outside = 0, waterLevel = -Infinity,
87
90
  colliderPad = 0, colliderHeight = 0, sharpEdge = 0.6, hideMarkers = true, addToScene = true } = opts;
88
91
  let e = null, hf = null, done = false, version = 0, trimeshCache = null, pendingColliders = null;
@@ -197,11 +200,10 @@ export function level(opts = {}) {
197
200
  }
198
201
 
199
202
  return {
200
- name: 'level', label: 'Level', stage: 'world', after: ['terrain'], optional: ['world', 'content'],
203
+ name: 'level', params: LEVEL_PARAMS, options: opts, label: 'Level', stage: 'world', after: ['terrain'], optional: ['world', 'content'],
201
204
  install(engine) {
202
205
  e = engine;
203
206
  nodeSet = levelNodes(e, () => api.root, () => current);
204
- checkOptions('level()', opts, ['url', 'scene', 'walkable', 'colliders', 'cellSize', 'outside', 'waterLevel', 'colliderPad', 'colliderHeight', 'sharpEdge', 'hideMarkers', 'addToScene']);
205
207
  e.i18n.add(STRINGS);
206
208
  // ground API: before the heightfield is built, return the outside height
207
209
  e.setGround({
@@ -15,6 +15,7 @@
15
15
  // When every point light casts (shadows >= point) there are no plain ones, so sources without castShadow also take the shadow lights (they cast then) instead of never lighting.
16
16
  import * as THREE from 'three';
17
17
  import { checkOptions, warnOnce } from '../../core/validate.js';
18
+ import { readParams, keysSchema } from '../../core/params.js';
18
19
  import { vec3 } from '../../core/math.js';
19
20
  /** @import { ModuleDef } from '../../types/core' */
20
21
  /** @import { LightPool, LightPoolOptions } from '../../types/world' */
@@ -40,6 +41,8 @@ function glowOf(g) {
40
41
  return { m, key, base: m[key], k: -1 };
41
42
  }
42
43
 
44
+ const LIGHT_POOL_PARAMS = keysSchema(OPT_KEYS);
45
+
43
46
  /**
44
47
  * Light pool (many light sources, a fixed number of real lights) -> engine.lightPool
45
48
  * @param {LightPoolOptions} [opts]
@@ -49,6 +52,7 @@ function glowOf(g) {
49
52
  * for (const t of torchMeshes) engine.lightPool.add(t, { color: 0xffa040, intensity: 4, distance: 8, flicker: (time, i) => 0.85 + 0.15 * Math.sin(time * 13 + i) });
50
53
  */
51
54
  export function lightPool(opts = {}) {
55
+ readParams('lightPool', LIGHT_POOL_PARAMS, opts);
52
56
  const { point = 8, spot = 0, shadows = 0, every = 0.1, fade = 0.3 } = opts;
53
57
  let e = null, timer = Infinity, time = 0, seq = 0;
54
58
  const sources = [], groups = [], tmp = new THREE.Vector3(), at = new THREE.Vector3();
@@ -198,10 +202,9 @@ export function lightPool(opts = {}) {
198
202
  }
199
203
 
200
204
  return {
201
- name: 'lightPool', label: 'Light pool', stage: 'late', presentation: true,
205
+ name: 'lightPool', params: LIGHT_POOL_PARAMS, options: opts, label: 'Light pool', stage: 'late', presentation: true,
202
206
  install(engine) {
203
207
  e = engine;
204
- checkOptions('lightPool()', opts, OPT_KEYS);
205
208
  const k = Math.max(0, Math.min(shadows, point));
206
209
  if (k > 0 && k >= point) warnOnce(STRINGS.allShadow.replace('{n}', String(point)).replace('{m}', String(k + 2)).replaceAll('{k}', String(k)));
207
210
  makeGroup('point', true, k);
@@ -26,6 +26,7 @@
26
26
  // Events: music:change { from, to }, music:stinger { name }
27
27
 
28
28
  import { checkOptions, warnMissing, warnOnce } from '../../core/validate.js';
29
+ import { readParams, keysSchema } from '../../core/params.js';
29
30
  import { pickTrack, evaluateRules } from './rules.js';
30
31
  /** @import { ModuleDef } from '../../types/core' */
31
32
  /** @import { MusicTrack, MusicRule, MusicOptions } from '../../types/gameplay' */
@@ -269,6 +270,8 @@ export class Music {
269
270
  }
270
271
  }
271
272
 
273
+ const MUSIC_PARAMS = keysSchema(['tracks', 'rules', ...Object.keys(DEFAULTS)], DEFAULTS);
274
+
272
275
  /**
273
276
  * Background music -> engine.music. tracks; rules; fade: default fade seconds (2); duckDialogue: duck the music bus to this level during dialogue (default
274
277
  * false = off; e.g. 0.35); duckFade; hold: rule debounce seconds (2)
@@ -277,11 +280,12 @@ export class Music {
277
280
  * @example engine.use(music({ tracks: { explore: '/music/explore.ogg' }, rules: [{ track: 'explore' }] }));
278
281
  */
279
282
  export function music(opts = {}) {
283
+ readParams('music', MUSIC_PARAMS, opts);
280
284
  let m = null;
281
285
  return {
282
- name: 'music', label: 'Music', optional: ['dialogue'], stage: 'audio', presentation: true,
286
+ name: 'music', params: MUSIC_PARAMS, options: opts, label: 'Music', optional: ['dialogue'], stage: 'audio', presentation: true,
283
287
  install(e) {
284
- checkOptions('music()', opts, ['tracks', 'rules', ...Object.keys(DEFAULTS)]); m = new Music(e, opts);
288
+ m = new Music(e, opts);
285
289
  e.events.on('session:end', () => m.stop(0)); // a playthrough ends: its music stops at once
286
290
  return m;
287
291
  },
@@ -10,11 +10,14 @@
10
10
  // The mesh is built once per level: ground edits (engine.terrain.edit, 'ground:change') do not update it, so paths keep following the ground as it was
11
11
  // at level load (rebuilding all tiles per edit is too slow to do automatically). A game that reshapes walkable ground at runtime leaves nav out:
12
12
  // characters.findPath then uses A*, which resamples the edited area (its rasters are dropped on 'ground:change').
13
- import { checkOptions } from '../../core/validate.js';
13
+ import { readParams, keysSchema } from '../../core/params.js';
14
14
  import { xzOf } from '../../core/math.js';
15
15
  import { navSearch } from './navPath.js';
16
16
 
17
+ const NAV_PARAMS = keysSchema(['cellSize', 'agentRadius', 'agentHeight', 'maxClimb', 'maxSlope', 'tileSize', 'crowd', 'debug']);
18
+
17
19
  export function nav(opts = {}) {
20
+ readParams('nav', NAV_PARAMS, opts);
18
21
  const { cellSize = 0.3, tileSize = 32, crowd = false, debug = false } = opts;
19
22
  // agent size defaults come from engine.movement (filled at install); opts values override them
20
23
  let agentRadius, agentHeight, maxClimb, maxSlope;
@@ -129,13 +132,12 @@ export function nav(opts = {}) {
129
132
  function flush() { queued = 0; for (let i = 0; i < 256 && !api.tileCache.update(api.navMesh).upToDate; i++); }
130
133
 
131
134
  return {
132
- name: 'nav', label: 'Navmesh',
135
+ name: 'nav', params: NAV_PARAMS, options: opts, label: 'Navmesh',
133
136
  install(engine) {
134
137
  e = engine;
135
138
  const mv = e.movement;
136
139
  ({ agentRadius = mv.radius, agentHeight = mv.height, maxClimb = mv.stepHeight, maxSlope = mv.maxSlope } = opts);
137
140
  api.agent = { radius: agentRadius, height: agentHeight, maxClimb, maxSlope };
138
- checkOptions('nav()', opts, ['cellSize', 'agentRadius', 'agentHeight', 'maxClimb', 'maxSlope', 'tileSize', 'crowd', 'debug']);
139
141
  e.events.on('level:loaded', () => { if (lib) build(); else pending = true; });
140
142
  return api;
141
143
  },
@@ -7,6 +7,7 @@
7
7
  // prediction / rollback is a later step).
8
8
  // - world.simulate does not run here: the host simulates and the result arrives as diffs (two simulations would fight).
9
9
  import { applyPart, idMap } from './sync.js';
10
+ import { failure } from '../../core/opsFail.js';
10
11
 
11
12
  const STEP = 1 / 60;
12
13
  const ASK_EVERY = 30; // steps between snapshot requests while out of step
@@ -43,8 +44,8 @@ export class NetClient {
43
44
 
44
45
  route(d, args, opts) {
45
46
  if (d.net === 'local') return null;
46
- if (d.net !== 'peer') return { ok: false, reason: 'notAllowed' };
47
- if (!this.synced) return { ok: false, reason: 'offline' };
47
+ if (d.net !== 'peer') return failure('notAllowed');
48
+ if (!this.synced) return failure('offline');
48
49
  const c = this.e.ops.can(d.name, args, opts);
49
50
  if (!c.ok) return c;
50
51
  const seq = ++this.seq, out = {};
@@ -80,7 +81,7 @@ export class NetClient {
80
81
  if (this.synced && m.n > this.n) this.gap();
81
82
  } else if (m.t === 'r') {
82
83
  this.pending.delete(m.seq);
83
- e.events.emit('net:result', { seq: m.seq, name: m.name, ok: m.ok, reason: m.reason, value: m.value, tick: m.tick });
84
+ e.events.emit('net:result', { seq: m.seq, name: m.name, ok: m.ok, code: m.code, value: m.value, tick: m.tick });
84
85
  }
85
86
  }
86
87
  /** a diff was lost: stop applying diffs and ask for a snapshot (frame asks again if that is lost too) */
@@ -57,7 +57,7 @@ export class NetHost {
57
57
 
58
58
  request(peer, m) {
59
59
  const e = this.e, seq = isNum(m.seq) ? m.seq : 0, name = typeof m.name === 'string' ? m.name : '';
60
- const reply = (ok, reason, value) => peer.results.push({ t: 'r', seq, name, ok, reason: reason ?? null, value: plain(value), tick: e.tick });
60
+ const reply = (ok, code, value) => peer.results.push({ t: 'r', seq, name, ok, code: code ?? null, value: plain(value), tick: e.tick });
61
61
  const d = e.ops.defs.get(name), args = m.args ?? {};
62
62
  const reason = this.gate(peer, d, args);
63
63
  if (reason) {
@@ -67,7 +67,7 @@ export class NetHost {
67
67
  return;
68
68
  }
69
69
  const r = e.ops.run(name, args, { source: 'net', actor: peer.actor });
70
- reply(r.ok, r.reason, r.value);
70
+ reply(r.ok, r.code, r.value);
71
71
  }
72
72
  /** returns a reason string when the request is refused at the door */
73
73
  gate(peer, d, args) {
@@ -3,7 +3,7 @@
3
3
  // engine.use(net({ role: 'client', transport })) // friends: mirror the host, send op requests
4
4
  // Only ops defined with net: 'peer' can be requested by clients (default deny); the actor comes from the connection, not the message.
5
5
  // Transports: fakeNetwork() (in-process, tests) and webSocket(url) (with packages/tools/net-relay.mjs); see transports.js for the shape.
6
- import { checkOptions } from '../../core/validate.js';
6
+ import { readParams, keysSchema } from '../../core/params.js';
7
7
  import { Net } from './Net.js';
8
8
 
9
9
  export { fakeNetwork, webSocket } from './transports.js';
@@ -14,6 +14,8 @@ const STRINGS = {
14
14
  transport: 'net(): transport is required, e.g. net({ role, transport: webSocket(url) }) or fakeNetwork().connect() in tests',
15
15
  };
16
16
 
17
+ const NET_PARAMS = keysSchema(OPTS);
18
+
17
19
  /**
18
20
  * Optional co-op multiplayer: one host owns the state, clients mirror it and ask for changes through ops. Installed as engine.net.
19
21
  * Host: peers' requests run as `ops.run(name, args, { source: 'net', actor })` only for ops defined with net: 'peer', with the op's args shape
@@ -41,7 +43,7 @@ const STRINGS = {
41
43
  * @experimental
42
44
  */
43
45
  export function net(opts = {}) {
44
- checkOptions('net()', opts, OPTS);
46
+ readParams('net', NET_PARAMS, opts);
45
47
  if (opts.role !== 'host' && opts.role !== 'client') throw new Error(STRINGS.role.replace('{got}', JSON.stringify(opts.role)));
46
48
  if (!opts.transport) throw new Error(STRINGS.transport);
47
49
  const left = new Map(); // actor -> last position, so a peer that reconnects comes back where it left
@@ -65,7 +67,7 @@ export function net(opts = {}) {
65
67
  };
66
68
  let n = null;
67
69
  return {
68
- name: 'net', label: 'Multiplayer', stage: 'late', optional: ['world', 'inventory'],
70
+ name: 'net', params: NET_PARAMS, options: opts, label: 'Multiplayer', stage: 'late', optional: ['world', 'inventory'],
69
71
  install(e) { return (n = new Net(e, o)); },
70
72
  fixed(dt) { n._fixed(dt); },
71
73
  frame(dt) { n._frame(dt); },
@@ -148,7 +148,7 @@ export class Particles {
148
148
  * @internal
149
149
  */
150
150
  update(dt) {
151
- const pr = this.engine.renderer.getPixelRatio(), scale = this.engine.renderer.getSize(_vs).y * pr / (2 * Math.tan(THREE.MathUtils.degToRad(this.engine.camera.fov) / 2));
151
+ const cam = this.engine.camera, pr = this.engine.renderer.getPixelRatio(), scale = this.engine.renderer.getSize(_vs).y * pr / (cam.orthoSize ? cam.orthoSize / cam.zoom : 2 * Math.tan(THREE.MathUtils.degToRad(cam.fov) / 2)); // orthographic: pixels per world unit
152
152
  for (const h of this.emitters) {
153
153
  if (!h.active) continue;
154
154
  if (!h.object.parent) { h.remove(); continue; } // object removed from the scene: stop automatically
@@ -2,13 +2,14 @@
2
2
  //
3
3
  // Taking a photo is the op photo.take (recipes/23-ops.md): the photo key, a game's shutter button, the dev bridge and tests all run it, and
4
4
  // photo.canTake (true or a reason) is its can. engine.photo.take() is the low-level capture the op calls (no checks).
5
- // const r = engine.ops.run('photo.take'); // r.value = { url, time, position, subject } or r.reason (e.g. 'noFilm')
6
- // When the photo key's op is refused the module emits photo:denied { reason } (the game shows it; a button reads r.reason itself).
5
+ // const r = engine.ops.run('photo.take'); // r.value = { url, time, position, subject } or r.code (e.g. 'noFilm')
6
+ // When the photo key's op is refused the module emits photo:denied { reason } (the game shows it; a button reads r.code itself).
7
7
  // subject is what is in the middle of the frame { name, kind, distance }: NPC (kind 'npc'), entity ('entity'), named object ('object'),
8
8
  // vegetation ('vegetation'; after hitting an instanced mesh, vegetation.instanceAt looks up the kind); null when it hits the sky or an unnamed ground.
9
9
  // The photo key (action 'photo') is the game's: photo({ keys: ['KeyC'], pad: ['PadX'] }), photo({ ...presets.keys.photo }) (P / gamepad RB) or keys: [] for no key
10
10
  // Shutter sound: the game's createEngine({ audio: { sounds: { shutter } } }) supplies a file, otherwise a synthesized fallback
11
11
  import { checkOptions, moduleKeys } from '../../core/validate.js';
12
+ import { readParams, keysSchema } from '../../core/params.js';
12
13
  import { toast } from '../../ui/UI.js';
13
14
  const GROUP = 'photo'; // group name in the blobs store of engine.saves.store
14
15
  const TAKE_KEYS = ['scale', 'shadowMapSize', 'bloom', 'quality', 'format'];
@@ -30,13 +31,13 @@ export class Photo {
30
31
  const pr = Math.min(3, prevPR * o.scale);
31
32
  r.setPixelRatio(pr); e.post.setPixelRatio(pr);
32
33
  if (e.shadows && sky) sky.setShadowMapSize(o.shadowMapSize);
33
- e.post.enable('bloom', o.bloom);
34
+ e.look.post.set({ 'bloom.enabled': o.bloom });
34
35
  r.shadowMap.needsUpdate = true; // shadows may update only every few frames (sky's shadow.updateEvery); force an update on the photo frame
35
36
  e.post.render(0);
36
37
  const url = r.domElement.toDataURL(o.format, o.quality);
37
38
  r.setPixelRatio(prevPR); e.post.setPixelRatio(prevPR);
38
39
  if (e.shadows && sky) sky.setShadowMapSize(prevMap);
39
- if (prevBloom !== undefined) e.post.enable('bloom', prevBloom);
40
+ if (prevBloom !== undefined) e.look.post.set({ 'bloom.enabled': prevBloom });
40
41
  const p = e.actorPosition() ?? e.cameraRig?.target?.position; // where whoever the user controls stands (engine.actor)
41
42
  const shot = { url, time: sky?.clock ?? '', position: p ? { x: Math.round(p.x), z: Math.round(p.z) } : null, subject: this.subject() };
42
43
  this.album.unshift(shot); if (this.album.length > this.maxAlbum) this._drop(this.album.pop());
@@ -105,15 +106,17 @@ function under(o, set) { for (let p = o; p; p = p.parent) if (set.has(p)) return
105
106
 
106
107
  const STRINGS = { 'zh-CN': { 'photo.action': '拍照' }, en: { 'photo.action': 'Take photo' } };
107
108
 
109
+ const PHOTO_PARAMS = keysSchema(['keys', 'pad', 'maxAlbum', ...TAKE_KEYS]);
110
+
108
111
  /** Photo module. Once installed: engine.ops.run('photo.take') takes a photo through photo.canTake; engine.photo.take() captures without checks */
109
112
  export function photo(all = {}) {
113
+ readParams('photo', PHOTO_PARAMS, all);
110
114
  const { keys: keys0, pad, ...opts } = all;
111
115
  let bound = false; // the photo action has a key or pad button (set at install)
112
116
  let ph = null;
113
117
  return {
114
- name: 'photo', label: 'Photo mode', optional: ['cameraRig', 'sky', 'vegetation', 'entities'],
118
+ name: 'photo', params: PHOTO_PARAMS, options: all, label: 'Photo mode', optional: ['cameraRig', 'sky', 'vegetation', 'entities'],
115
119
  install(e) {
116
- checkOptions('photo()', all, ['keys', 'pad', 'maxAlbum', ...TAKE_KEYS]);
117
120
  e.i18n.add(STRINGS);
118
121
  const keys = moduleKeys('photo()', 'photo', keys0, 'photo', e.input); // the game's key or a presets.keys bundle, never a built-in one
119
122
  bound = keys.length > 0 || !!pad;
@@ -137,7 +140,7 @@ export function photo(all = {}) {
137
140
  frame(dt, e) {
138
141
  if (!bound || !e.input.pressed('photo')) return;
139
142
  const r = e.ops.run('photo.take', {}, { source: 'player' });
140
- if (!r.ok && r.reason !== 'halted') e.events.emit('photo:denied', { reason: r.reason });
143
+ if (!r.ok && r.code !== 'halted') e.events.emit('photo:denied', { reason: r.code });
141
144
  },
142
145
  };
143
146
  }
@@ -17,6 +17,7 @@
17
17
  import * as THREE from 'three';
18
18
  import { vec3, xzOf } from '../../core/math.js';
19
19
  import { checkOptions } from '../../core/validate.js';
20
+ import { readParams, keysSchema } from '../../core/params.js';
20
21
  import { cellsChanged } from '../../core/streamCells.js';
21
22
  import { createVehicle, VEHICLE_KEYS, STRINGS } from './Vehicles.js';
22
23
  import { syncTerrain, syncTrees, treesChanged, syncGroundTrees, syncStatics, syncLevel } from './sync.js';
@@ -241,13 +242,15 @@ export class RigidBodies {
241
242
  }
242
243
  }
243
244
 
245
+ const RIGID_PARAMS = keysSchema(['gravity', 'terrainRing', 'buoyancy', 'buoyancyForce', 'waterDrag', 'floatLine', 'floatDepth', 'treeColliderHeight', 'treeRadius', 'playerCapsule']);
246
+
244
247
  /** Real physics module (Rapier). Installs as engine.rigid. Requires collision() to be installed first */
245
248
  export function rigid(opts = {}) {
249
+ readParams('rigid', RIGID_PARAMS, opts);
246
250
  let r = null;
247
251
  return {
248
- name: 'rigid', label: 'Physics', optional: ['interactions'], requires: ['collision'],
252
+ name: 'rigid', params: RIGID_PARAMS, options: opts, label: 'Physics', noSkip: 'bodies rest while time jumps (stepping seconds of physics would only scatter them)', optional: ['interactions'], requires: ['collision'],
249
253
  install(e) {
250
- checkOptions('rigid()', opts, ['gravity', 'terrainRing', 'buoyancy', 'buoyancyForce', 'waterDrag', 'floatLine', 'floatDepth', 'treeColliderHeight', 'treeRadius', 'playerCapsule']);
251
254
  e.i18n.add(STRINGS); r = new RigidBodies(e, opts);
252
255
  e.budget.metric('rigidBodies', () => r.bodies.length);
253
256
  e.stream.readyCheck('rigid', s => !s.physics || r.ready && r.groundReady(s)); // a physics stream source waits for the collider under it
@@ -32,7 +32,7 @@ import { BUILTIN_SECTIONS } from './sections.js';
32
32
  import { STRINGS, CSS } from './strings.js';
33
33
  import { SettingsView } from './view.js';
34
34
  import { applySetting } from './apply.js';
35
- import { checkOptions } from '../../core/validate.js';
35
+ import { readParams, keysSchema } from '../../core/params.js';
36
36
 
37
37
  // Graphics presets. Values are performance tiers, not art; a game can override with settings({ presets: { low: {...} } })
38
38
  const PRESETS = {
@@ -276,6 +276,8 @@ export class Settings extends SettingsView {
276
276
  }
277
277
 
278
278
 
279
+ const SETTINGS_PARAMS = keysSchema(['action', 'keys', 'storageKey', 'presets', 'sections', 'freezeWorld']);
280
+
279
281
  /**
280
282
  * Settings menu module. Installs engine.settings. Install it after the other modules.
281
283
  * @param opts action/keys action that opens the menu (default 'menu' = Esc); storageKey storage key; presets override graphics presets;
@@ -284,10 +286,11 @@ export class Settings extends SettingsView {
284
286
  * freezeWorld pause gameplay while the menu is open (with flow it switches to flow's 'paused', otherwise engine.freeze; rendering continues), default false
285
287
  */
286
288
  export function settings(opts = {}) {
289
+ readParams('settings', SETTINGS_PARAMS, opts);
287
290
  let s = null;
288
291
  return {
289
- name: 'settings', label: 'Settings', optional: ['terrain', 'vegetation'], stage: 'presentation',
290
- install(e) { checkOptions('settings()', opts, ['action', 'keys', 'storageKey', 'presets', 'sections', 'freezeWorld']); s = new Settings(e, opts); return s; },
292
+ name: 'settings', params: SETTINGS_PARAMS, options: opts, label: 'Settings', optional: ['terrain', 'vegetation'], stage: 'presentation',
293
+ install(e) { s = new Settings(e, opts); return s; },
291
294
  init() { s.init(); },
292
295
  frame(dt) { s.frame(dt); },
293
296
  };
@@ -7,7 +7,8 @@ export function applySetting(s, key, val) {
7
7
  switch (key) {
8
8
  case 'pixelRatio': if (e.adaptive) e.adaptive.max = val; if (Math.abs(e.renderer.getPixelRatio() - val) > 0.001) e.setPixelRatio(val); break;
9
9
  case 'shadows': if (e.shadows !== val) e.setShadows(val); break;
10
- case 'antialias': case 'bloom': case 'ao': e.post.enable(key, val); break;
10
+ case 'antialias': e.post.setAntialias(val); break;
11
+ case 'bloom': case 'ao': if (e.post.get(key)) e.look.post.set({ [key + '.enabled']: val }); break; // a style without this effect has nothing to switch (look.post.set would throw on the unknown key)
11
12
  case 'adaptive': if (e.adaptive) { e.adaptive.on = val; if (!val && e.adaptive.max) e.setPixelRatio(e.adaptive.max); } break;
12
13
  case 'viewChunks': { const H = s.chunkHost(); if (H?.setViewChunks && H.viewChunks !== val) H.setViewChunks(val); break; }
13
14
  case 'density': { const H = s.chunkHost(); if (H?.setDensity && H.density !== val) H.setDensity(val); break; }
@@ -18,8 +18,12 @@
18
18
  import * as THREE from 'three';
19
19
  import { NEUTRAL_KEYFRAMES, checkKeyframes, makeSkyUniforms, makeDome, loadSkybox } from './shader.js';
20
20
  import { shadowMethods, shadowFor } from './shadow.js';
21
+ import { renamed } from '../../core/errorHints.js';
22
+ import { defineSkyLook } from './lookSky.js';
23
+ import { defineFogLook } from './lookFog.js';
24
+ import { defineShadowLook } from './lookShadow.js';
21
25
  import { layerMethods, blankLayer } from './layers.js';
22
- import { environmentMethods, environmentFor } from './environment.js';
26
+ import { environmentMethods, environmentFor, defineEnvLook } from './environment.js';
23
27
  import { updateSky, watchOwned } from './frame.js';
24
28
  import { prepareLook } from './look.js';
25
29
  import { makeFog, applyFogChunks } from './fog.js';
@@ -81,6 +85,7 @@ export class Sky {
81
85
 
82
86
  scene.fog = this._drive.fog === false ? null : makeFog(this._fog, engine.fogFar);
83
87
  /** @internal */ this._fogOff = this._drive.fog === false ? () => {} : applyFogChunks(this._fog); // throws when another engine holds a different custom fog
88
+ defineFogLook(this, this._fogSpec); // look.fog: style.sky.fog / sky({ fog }) is its style layer
84
89
  /** Hemisphere ambient light (engine.lights.hemi, driven by the sky) @type {any} */
85
90
  this.hemi = engine.lights.hemi;
86
91
  /** Sun directional light (engine.lights.sun driven by the sky; moonlight at night, shadows live on it) @type {any} */
@@ -97,14 +102,14 @@ export class Sky {
97
102
  */
98
103
  this.orbit = { tilt: st.orbitTilt ?? 0.45, sway: st.orbitSway ?? 0.8, distance: sh.distance ?? 160 };
99
104
  // Shadow update policy (default: every frame, center snapped to 0.5 m)
100
- /** Current shadow params (change via setShadow) @readonly @type {SkyShadowParams} */
105
+ /** Current shadow params (change via look.shadow.set) @readonly @type {SkyShadowParams} */
101
106
  this.shadow = { bias: -0.0006, normalBias: 0.04, updateEvery: 1, snap: 0.5, ahead: 0, type: engine.shadowType, radius: 1, blurSamples: 8,
102
107
  cascades: 1, maxFar: 120, fade: true, lightMargin: 100, split: 'practical' };
103
108
  /** three's CSM (addons/csm) while shadow.cascades > 1, else null; its lights[0] is sun (recipes/45) @type {any} */
104
109
  this.csm = null;
105
110
  /** @internal */ this._shadowFrame = 0;
106
111
  /** @internal */ this._snapKey = '';
107
- this.setShadow(sh);
112
+ defineShadowLook(this, sh); // look.shadow: the style / options shadow is its style layer; look.shadow.set writes the game layer
108
113
  /** Hours per day @type {number} */
109
114
  this.hoursPerDay = over.hoursPerDay ?? 24; // gameplay timing (clock notation, schedules): a sky() option only, never read from the style pack
110
115
  // Modifier layers: weather and games each write their own layer (modify); sky composites them into modifiers every frame
@@ -116,7 +121,11 @@ export class Sky {
116
121
  /** @internal */ this._lightDir = new THREE.Vector3();
117
122
  /** @internal */ this._env = null;
118
123
  const env = environmentFor(engine.tier, engine.style.sky?.environment, over.environment);
119
- if (env) this.setEnvironment(env);
124
+ defineEnvLook(this, env); // look.env: the style / options environment is its style layer, look.env.replace writes the game layer
125
+ defineSkyLook(this, st); // look.sky: live cloud uniforms, backdrop, the clouds / layer:<name> hooks, skybox
126
+ // the keyframes write these light keys every frame: describe().look shows them as style (driver sky) with the live value
127
+ const D = this._drive;
128
+ engine.look.lights.drive([...(D.sun === true ? ['sun.intensity', 'sun.color'] : []), ...(D.hemi === true ? ['hemi.intensity', 'hemi.color', 'hemi.ground'] : [])], 'sky');
120
129
  // Per-frame recomputed properties: direct edits by games get overwritten, so warn once in dev (frame.js)
121
130
  /** @internal */ this._owned = watchOwned(this);
122
131
  }
@@ -226,14 +235,11 @@ export class Sky {
226
235
 
227
236
  // Public shadow methods: implemented in shadow.js, declared here so type and doc tools see them (the rest is mixed in below)
228
237
  /**
229
- * Change shadow params (only the given fields): bias / normalBias prevent banding; updateEvery updates shadows every N frames (1 = every frame);
230
- * snap snap = shadow center snap grid (meters, or 'texel' to snap to shadow pixels); ahead = meters to shift the shadow center in front of the view;
231
- * type = 'basic' (hard edge) | 'pcf' | 'vsm' (soft, costlier; switching rebuilds the shadow map and recompiles materials, so do it rarely);
232
- * radius = edge softness (pcf, vsm; no effect on basic); blurSamples = blur quality (vsm only); cascades 2-4 = cascaded shadows, 1 = off (recipes/45)
233
- * @param {Partial<SkyShadowParams>} [opts]
234
- * @returns {this}
238
+ * Renamed in 0.2: throws and names the new call, engine.look.shadow.set(opts) (fields: bias, normalBias, updateEvery, snap, ahead, type, radius, blurSamples, cascades; recipes/45)
239
+ * @param {Partial<SkyShadowParams>} [_opts]
240
+ * @returns {never}
235
241
  */
236
- setShadow(opts) { return shadowMethods.setShadow.call(this, opts); }
242
+ setShadow(_opts) { return renamed('setShadow'); }
237
243
  /**
238
244
  * Change shadow resolution (raise temporarily for photo mode)
239
245
  * @param {number} n pixels
@@ -241,15 +247,11 @@ export class Sky {
241
247
  */
242
248
  setShadowMapSize(n) { return shadowMethods.setShadowMapSize.call(this, n); }
243
249
  /**
244
- * Environment lighting (scene.environment), separate from the background and off by default. source 'sky' builds it from the procedural sky (rebuilt at
245
- * most every `interval` seconds, only when the sky changed); an asset name or path (.hdr, .jpg, .ktx2) is an equirectangular panorama. intensity scales
246
- * the light (default 1), rotation turns it around Y (radians). Given fields change, the rest stay; null turns it off. Lambert surfaces get soft ambient
247
- * light from it (no reflections); lower the hemisphere ambient when you turn it on (recipes/09)
248
- * @example engine.sky.setEnvironment({ source: 'sky', intensity: 0.8 }); engine.sky.setEnvironment(null);
249
- * @param {{ source?: string | null, intensity?: number, rotation?: number, interval?: number } | null} [opts]
250
- * @returns {this}
250
+ * Renamed in 0.2: throws and names the new call, engine.look.env.replace(source) then engine.look.env.set({ intensity, rotation, interval })
251
+ * @param {{ source?: string | null, intensity?: number, rotation?: number, interval?: number } | null} [_opts]
252
+ * @returns {never}
251
253
  */
252
- setEnvironment(opts) { return environmentMethods.setEnvironment.call(this, opts); }
254
+ setEnvironment(_opts) { return renamed('setEnvironment'); }
253
255
  /** Environment lighting now: { source, intensity, rotation, interval, builds }, null when off @type {SkyEnvironmentInfo | null} */
254
256
  get environment() { return environmentMethods._envInfo.call(this); }
255
257
  }
@@ -20,15 +20,15 @@ const LIT = new Set(['MeshLambertMaterial', 'MeshPhongMaterial', 'MeshStandardMa
20
20
  const lit = m => m.isShaderMaterial ? m.lights && m.fragmentShader.includes('#include <lights_fragment_begin>') : LIT.has(m.type);
21
21
  const SPLITS = ['practical', 'uniform', 'logarithmic'];
22
22
  const STRINGS = {
23
- count: 'sky.setShadow({ cascades }): a whole number 1 (one shadow map, the default) to 4; got {got}',
24
- split: "sky.setShadow({ split }): 'practical' (default) | 'uniform' | 'logarithmic' | (count, near, far, out) => void; got {got}",
25
- maxFar: 'sky.setShadow({ maxFar }): meters from the camera that cascades cover, a number > 0; got {got}',
26
- noSun: "sky.setShadow({ cascades }): cascaded shadows split the engine sun's shadow, and sky({ sun: false }) has no engine sun. " +
23
+ count: 'look.shadow.set({ cascades }): a whole number 1 (one shadow map, the default) to 4; got {got}',
24
+ split: "look.shadow.set({ split }): 'practical' (default) | 'uniform' | 'logarithmic' | (count, near, far, out) => void; got {got}",
25
+ maxFar: 'look.shadow.set({ maxFar }): meters from the camera that cascades cover, a number > 0; got {got}',
26
+ noSun: "look.shadow.set({ cascades }): cascaded shadows split the engine sun's shadow, and sky({ sun: false }) has no engine sun. " +
27
27
  "With your own lights use three's CSM addon on them, or keep sun: true / 'manual'",
28
28
  };
29
29
  const bad = (k, v) => { throw new Error(STRINGS[k].replace('{got}', JSON.stringify(v) ?? String(v))); };
30
30
 
31
- /** Throw on cascade fields a setShadow call gets wrong, before anything is applied */
31
+ /** Throw on cascade fields a look.shadow.set call gets wrong, before anything is applied */
32
32
  export function checkCascades(sky, o) {
33
33
  if (o.cascades !== undefined && !(Number.isInteger(o.cascades) && o.cascades >= 1 && o.cascades <= 4)) bad('count', o.cascades);
34
34
  if (o.split !== undefined && typeof o.split !== 'function' && !SPLITS.includes(o.split)) bad('split', o.split);
@@ -74,7 +74,7 @@ class SkyCSM extends CSM {
74
74
  }
75
75
  }
76
76
 
77
- /** Create, rebuild or remove the cascades after setShadow changed shadow fields; copy bias / softness to the extra lights */
77
+ /** Create, rebuild or remove the cascades after look.shadow.set changed shadow fields; copy bias / softness to the extra lights */
78
78
  export function syncCascades(sky) {
79
79
  const S = sky.shadow, e = sky.engine, want = S.cascades > 1;
80
80
  const key = want ? [S.cascades, S.maxFar, S.fade, S.lightMargin, S.split].join('|') : '';
@@ -11,7 +11,7 @@
11
11
  import { checkOptions } from '../../core/validate.js';
12
12
  import { declareUniforms } from '../../render/uniformDecl.js';
13
13
 
14
- const KEYS = ['glsl', 'uniforms', 'order', 'blend'];
14
+ const KEYS = ['glsl', 'uniforms', 'order', 'blend', 'name']; // name: the layer's name for look.sky.patch('layer:<name>')
15
15
 
16
16
  /** Check the layer list and return { uniforms, decl, body } for the dome shader (empty strings without layers) */
17
17
  export function resolveDomeLayers(list) {