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.
- package/core/Animator.js +1 -0
- package/core/Assets.js +16 -0
- package/core/DebugOverrides.js +143 -0
- package/core/Describe.js +14 -3
- package/core/Engine.js +32 -69
- package/core/Events.js +59 -1
- package/core/I18n.js +2 -2
- package/core/Inspect.js +12 -32
- package/core/InspectScene.js +7 -3
- package/core/MaterialInfo.js +32 -0
- package/core/Ops.js +43 -59
- package/core/Saves.js +5 -4
- package/core/UrlState.js +3 -2
- package/core/Vars.js +1 -0
- package/core/Views.js +49 -0
- package/core/actor.js +2 -2
- package/core/assetReport.js +83 -0
- package/core/catalog.js +169 -0
- package/core/checks.js +67 -0
- package/core/claims.js +51 -0
- package/core/debugView.js +76 -0
- package/core/describeRender.js +45 -0
- package/core/describeText.js +11 -4
- package/core/errorCodes.js +33 -0
- package/core/errorHints.js +6 -1
- package/core/holds.js +106 -0
- package/core/lifecycle.js +1 -0
- package/core/lightWatch.js +23 -3
- package/core/look/coreParts.js +112 -0
- package/core/look/layers.js +136 -0
- package/core/look/part.js +173 -0
- package/core/look/report.js +79 -0
- package/core/look/write.js +86 -0
- package/core/loop.js +15 -14
- package/core/modules.js +19 -5
- package/core/opsAtomic.js +31 -0
- package/core/opsCheck.js +25 -14
- package/core/opsFail.js +20 -0
- package/core/opsHistory.js +6 -6
- package/core/opsRun.js +77 -0
- package/core/params.js +132 -0
- package/core/renamed.js +21 -0
- package/core/saveApply.js +2 -2
- package/core/sceneMethods.js +9 -34
- package/core/services.js +73 -0
- package/core/startup.js +3 -1
- package/core/styleParts.js +2 -2
- package/core/thingExplain.js +68 -0
- package/core/thingOps.js +35 -24
- package/core/things.js +15 -1
- package/core/util.js +11 -0
- package/core/validate.js +23 -7
- package/docs/AI.md +83 -109
- package/docs/API.md +7 -8
- package/docs/CODEMAP.md +63 -51
- package/docs/COMMANDS.md +17 -5
- package/docs/CONVENTIONS.md +17 -6
- package/docs/THREE.md +3 -3
- package/docs/api/assets.md +2 -0
- package/docs/api/characters.md +2 -0
- package/docs/api/collision.md +4 -0
- package/docs/api/content.md +1 -0
- package/docs/api/engine.md +20 -11
- package/docs/api/events.md +5 -1
- package/docs/api/post.md +5 -4
- package/docs/api/saves.md +2 -1
- package/docs/api/sky.md +3 -3
- package/docs/api/style.md +3 -3
- package/docs/api/tools.md +2 -0
- package/docs/api/weather.md +1 -1
- package/docs/recipes/02-npc.md +16 -0
- package/docs/recipes/03-items-pickups.md +1 -1
- package/docs/recipes/06-clock-events.md +13 -0
- package/docs/recipes/07-flow-scenes-pause.md +4 -0
- package/docs/recipes/08-weather-sky.md +1 -1
- package/docs/recipes/09-style-pack.md +5 -5
- package/docs/recipes/12-navmesh.md +22 -0
- package/docs/recipes/13-animation.md +3 -0
- package/docs/recipes/15-perf.md +1 -1
- package/docs/recipes/16-dev-bridge.md +51 -17
- package/docs/recipes/21-camera.md +51 -2
- package/docs/recipes/23-ops.md +45 -9
- package/docs/recipes/27-net.md +1 -1
- package/docs/recipes/29-grid.md +1 -1
- package/docs/recipes/34-environment-lighting.md +9 -8
- package/docs/recipes/38-environment-look-hooks.md +8 -6
- package/docs/recipes/40-scene.md +29 -0
- package/docs/recipes/41-thing-registry.md +29 -0
- package/docs/recipes/43-shader-patches-surface-looks.md +2 -0
- package/docs/recipes/44-water-weather-look-hooks.md +6 -4
- package/docs/recipes/45-cascaded-shadows.md +1 -1
- package/docs/recipes/46-blender-art-route.md +22 -0
- package/docs/recipes/48-make-material.md +70 -0
- package/docs/recipes/49-game-module-contract.md +71 -0
- package/docs/recipes/50-own-renderer.md +12 -0
- package/docs/recipes/51-capability-catalog.md +63 -0
- package/docs/recipes/52-look.md +108 -0
- package/examples/action/GAMEMAP.md +5 -5
- package/examples/action/content/index.js +2 -1
- package/examples/action/content/views.js +6 -0
- package/examples/sheepisland/GAMEMAP.md +2 -3
- package/examples/styletest/GAMEMAP.md +3 -3
- package/examples/styletest/main.js +1 -1
- package/examples/styletest/panel.js +3 -3
- package/examples/world/GAMEMAP.md +3 -3
- package/index.d.ts +27 -0
- package/index.js +3 -1
- package/llms.txt +5 -0
- package/modules/ambience/Ambience.js +5 -2
- package/modules/camera/FirstPersonCamera.js +3 -5
- package/modules/camera/FixedCamera.js +19 -12
- package/modules/camera/FollowCamera.js +14 -8
- package/modules/camera/RtsCamera.js +3 -5
- package/modules/camera/common.js +40 -10
- package/modules/camera/index.js +1 -1
- package/modules/camera/projection.js +34 -0
- package/modules/characters/Character.js +29 -17
- package/modules/characters/astar.js +14 -7
- package/modules/characters/index.js +6 -3
- package/modules/characters/movers/simple.js +6 -1
- package/modules/characters/npcSim.js +8 -2
- package/modules/characters/pathAsync.js +12 -6
- package/modules/characters/pathJob.js +2 -1
- package/modules/characters/proceduralRig.js +5 -1
- package/modules/characters/useModel.js +22 -0
- package/modules/characters/walkTo.js +58 -0
- package/modules/collision/Collision.js +102 -4
- package/modules/content/explain.js +13 -0
- package/modules/content/index.js +2 -0
- package/modules/content/loader.js +3 -0
- package/modules/content/rules.js +1 -0
- package/modules/debug/DebugPanel.js +11 -5
- package/modules/entities/Entities.js +6 -2
- package/modules/flow/index.js +5 -2
- package/modules/gameplay/Dialogue.js +5 -2
- package/modules/gameplay/Interactions.js +12 -2
- package/modules/gameplay/Inventory.js +21 -11
- package/modules/gameplay/Quests.js +13 -3
- package/modules/gameplay/pickups.js +5 -3
- package/modules/grid/Layer.js +1 -1
- package/modules/grid/index.js +1 -1
- package/modules/grid/tiles.js +9 -5
- package/modules/hlod/index.js +5 -2
- package/modules/hud/index.js +5 -2
- package/modules/level/index.js +5 -3
- package/modules/lights/index.js +5 -2
- package/modules/music/Music.js +6 -2
- package/modules/nav/index.js +5 -3
- package/modules/net/Client.js +4 -3
- package/modules/net/Host.js +2 -2
- package/modules/net/index.js +5 -3
- package/modules/particles/Particles.js +1 -1
- package/modules/photo/Photo.js +10 -7
- package/modules/rigid/RigidBodies.js +5 -2
- package/modules/settings/Settings.js +6 -3
- package/modules/settings/apply.js +2 -1
- package/modules/sky/Sky.js +21 -19
- package/modules/sky/cascades.js +6 -6
- package/modules/sky/domeLayers.js +1 -1
- package/modules/sky/environment.js +39 -13
- package/modules/sky/fog.js +9 -6
- package/modules/sky/frame.js +4 -3
- package/modules/sky/look.js +3 -2
- package/modules/sky/lookFog.js +80 -0
- package/modules/sky/lookShadow.js +50 -0
- package/modules/sky/lookSky.js +108 -0
- package/modules/sky/shader.js +2 -2
- package/modules/sky/shadow.js +4 -10
- package/modules/sky/skyModule.js +4 -3
- package/modules/terrain/ChunkManager.js +2 -33
- package/modules/terrain/chunkLevels.js +40 -0
- package/modules/terrain/index.js +10 -2
- package/modules/terrain/lookGround.js +61 -0
- package/modules/timeline/Timeline.js +7 -3
- package/modules/timeline/Tween.js +3 -7
- package/modules/timeline/shots.js +6 -4
- package/modules/triggers/index.js +9 -2
- package/modules/vegetation/Vegetation.js +2 -1
- package/modules/vegetation/index.js +6 -3
- package/modules/vegetation/lookWind.js +37 -0
- package/modules/water/Water.js +19 -3
- package/modules/water/look.js +80 -0
- package/modules/weather/Weather.js +22 -31
- package/modules/weather/look.js +75 -0
- package/modules/weather/particles.js +1 -1
- package/modules/weather/strings.js +15 -0
- package/modules/world/explain.js +11 -0
- package/modules/world/index.js +11 -4
- package/modules/world/thingSource.js +44 -0
- package/package.json +1 -1
- package/render/PostFX.js +48 -51
- package/render/effects.js +4 -2
- package/render/fuse.js +12 -0
- package/render/lights.js +4 -2
- package/render/lookSurface.js +161 -0
- package/render/materials.js +27 -10
- package/render/postLook.js +86 -0
- package/render/surface.js +3 -1
- package/types/core.d.ts +216 -24
- package/types/gameplay.d.ts +10 -0
- package/types/generated/core/DebugOverrides.d.ts +52 -0
- package/types/generated/core/Events.d.ts +43 -0
- package/types/generated/core/Ops.d.ts +62 -21
- package/types/generated/core/Saves.d.ts +1 -0
- package/types/generated/core/Views.d.ts +33 -0
- package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
- package/types/generated/modules/grid/Layer.d.ts +1 -0
- package/types/generated/modules/sky/Sky.d.ts +10 -17
- package/types/generated/modules/weather/Weather.d.ts +5 -15
- package/types/generated/render/PostFX.d.ts +20 -23
- package/types/generated/render/materials.d.ts +10 -0
- package/types/physics.d.ts +8 -0
- package/types/style.d.ts +16 -6
- package/ui/Parts.js +6 -2
- package/ui/UI.js +1 -1
- package/ui/defaults.js +1 -1
- package/docs/api/debug.md +0 -10
package/modules/hud/index.js
CHANGED
|
@@ -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);
|
package/modules/level/index.js
CHANGED
|
@@ -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 {
|
|
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({
|
package/modules/lights/index.js
CHANGED
|
@@ -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);
|
package/modules/music/Music.js
CHANGED
|
@@ -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
|
-
|
|
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
|
},
|
package/modules/nav/index.js
CHANGED
|
@@ -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 {
|
|
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
|
},
|
package/modules/net/Client.js
CHANGED
|
@@ -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
|
|
47
|
-
if (!this.synced) return
|
|
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,
|
|
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) */
|
package/modules/net/Host.js
CHANGED
|
@@ -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,
|
|
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.
|
|
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) {
|
package/modules/net/index.js
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
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(
|
|
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
|
package/modules/photo/Photo.js
CHANGED
|
@@ -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.
|
|
6
|
-
// When the photo key's op is refused the module emits photo:denied { reason } (the game shows it; a button reads r.
|
|
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.
|
|
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.
|
|
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.
|
|
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 {
|
|
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) {
|
|
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':
|
|
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; }
|
package/modules/sky/Sky.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
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
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
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(
|
|
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
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
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(
|
|
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
|
}
|
package/modules/sky/cascades.js
CHANGED
|
@@ -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: '
|
|
24
|
-
split: "
|
|
25
|
-
maxFar: '
|
|
26
|
-
noSun: "
|
|
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
|
|
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
|
|
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) {
|
|
@@ -10,14 +10,15 @@
|
|
|
10
10
|
// - The hemisphere light adds on top of it. A style that turns the environment on usually lowers its ambient column of sky.keyframes.
|
|
11
11
|
// The engine sets no environment by default, so the plain low-poly Lambert look is unchanged until a style or the game asks for one.
|
|
12
12
|
import * as THREE from 'three';
|
|
13
|
-
import {
|
|
13
|
+
import { warnOnce } from '../../core/validate.js';
|
|
14
|
+
import { defineLookPart, REPLACE } from '../../core/look/part.js';
|
|
14
15
|
|
|
15
16
|
const KEYS = ['source', 'intensity', 'rotation', 'interval'];
|
|
16
17
|
const DEFAULT_INTERVAL = 1; // seconds between regenerations of a procedural environment (only when the sky actually changed)
|
|
17
18
|
const STRINGS = {
|
|
18
|
-
noSource: "
|
|
19
|
-
"or
|
|
20
|
-
badSource: "
|
|
19
|
+
noSource: "look.env.replace(source): source is missing. Use 'sky' (built from the procedural sky) or the name of an HDR / panorama asset, " +
|
|
20
|
+
"or look.env.replace(false) to turn the environment lighting off",
|
|
21
|
+
badSource: "look.env.replace(source): source must be 'sky', an asset name / path (.hdr, .jpg, .ktx2...) or null; got {got}",
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
/**
|
|
@@ -37,16 +38,41 @@ function skyKey(u) {
|
|
|
37
38
|
return [...u.uTop.value.toArray(), ...u.uHorizon.value.toArray(), ...u.uSunDir.value.toArray(), ...u.uSunColor.value.toArray(), u.uNight.value, u.uCloud.value].map(f).join(',');
|
|
38
39
|
}
|
|
39
40
|
|
|
41
|
+
/**
|
|
42
|
+
* look.env: environment lighting as a look part. set({ intensity, rotation, interval }) tunes it, replace(source) swaps the map ('sky', an asset
|
|
43
|
+
* name, or false = off), replace(null) gives it back to the style. The style layer is style.sky.environment merged with sky({ environment }).
|
|
44
|
+
* Why the asset stays a name: loading belongs to engine.assets; the part only says which map to use.
|
|
45
|
+
* @param {any} sky @param {object | null} env environmentFor(...) at start
|
|
46
|
+
*/
|
|
47
|
+
export function defineEnvLook(sky, env) {
|
|
48
|
+
const e = sky.engine, scene = e.scene;
|
|
49
|
+
let src = null, vals = { intensity: 1, rotation: 0, interval: DEFAULT_INTERVAL };
|
|
50
|
+
const sync = () => (src ? sky._envApply({ source: src, ...vals }) : sky._envOff());
|
|
51
|
+
const { source, low, ...tune } = env ?? {};
|
|
52
|
+
defineLookPart(e, {
|
|
53
|
+
id: 'env', group: 'atmosphere', module: 'sky', object: () => scene.environment, docs: ['recipes/52-look.md'],
|
|
54
|
+
params: {
|
|
55
|
+
intensity: { type: 'number', default: 1, min: 0, neutral: true, cost: 'uniform', desc: 'scene.environmentIntensity' },
|
|
56
|
+
rotation: { type: 'number', default: 0, neutral: true, cost: 'uniform', desc: 'turns the map around Y (radians)' },
|
|
57
|
+
interval: { type: 'number', default: DEFAULT_INTERVAL, min: 0, neutral: true, cost: 'gpu', desc: "seconds between rebuilds of a 'sky' map (only when the sky changed)" },
|
|
58
|
+
},
|
|
59
|
+
style: () => ({ ...tune, ...(source ? { [REPLACE]: source } : {}) }),
|
|
60
|
+
read: () => (src ? { intensity: scene.environmentIntensity, rotation: scene.environmentRotation.y } : {}),
|
|
61
|
+
apply(v) { vals = v; sync(); },
|
|
62
|
+
replace: { accepts: "'sky' (built from the procedural sky) | an asset name or path (.hdr, .jpg, .ktx2) | false (off)", loses: ['nothing: intensity and rotation still apply to your map'] },
|
|
63
|
+
applyReplace(impl) {
|
|
64
|
+
if (impl != null && impl !== false && typeof impl !== 'string') throw new Error(STRINGS.badSource.replace('{got}', String(impl)));
|
|
65
|
+
src = impl || null; sync();
|
|
66
|
+
},
|
|
67
|
+
noPatch: 'environment lighting has no GLSL hook: it is a texture; swap it with look.env.replace(...) or tune it with look.env.set({ intensity })',
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
40
71
|
export const environmentMethods = {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
* (.hdr, .jpg, .ktx2) is an equirectangular panorama. intensity scales the light (default 1), rotation turns it around Y (radians)
|
|
45
|
-
*/
|
|
46
|
-
setEnvironment(o) {
|
|
72
|
+
// (the environment is changed through engine.look.env.replace(source) / .set({ intensity, rotation, interval }))
|
|
73
|
+
// Apply settings to the scene (look.env's apply): a changed source rebuilds or reloads the map, the same source only retunes it
|
|
74
|
+
_envApply(o) {
|
|
47
75
|
const cur = this._env;
|
|
48
|
-
if (o == null || o === false || o.source === null) { this._envOff(); return this; }
|
|
49
|
-
checkOptions('sky.setEnvironment()', o, KEYS);
|
|
50
76
|
const next = { source: cur?.source, intensity: cur?.intensity ?? 1, rotation: cur?.rotation ?? 0, interval: cur?.interval ?? DEFAULT_INTERVAL };
|
|
51
77
|
for (const k of KEYS) if (o[k] !== undefined) next[k] = o[k];
|
|
52
78
|
if (!next.source) throw new Error(STRINGS.noSource);
|
|
@@ -89,7 +115,7 @@ export const environmentMethods = {
|
|
|
89
115
|
e.builds++; e.key = skyKey(this.uniforms);
|
|
90
116
|
},
|
|
91
117
|
|
|
92
|
-
// Panorama asset (.hdr goes through HDRLoader in the asset loader). A newer
|
|
118
|
+
// Panorama asset (.hdr goes through HDRLoader in the asset loader). A newer look.env.replace call makes the token stale and the late result is dropped
|
|
93
119
|
_envFromAsset(name, token) {
|
|
94
120
|
this.engine.assets.texture(name).then(t => {
|
|
95
121
|
if (this._env?.token !== token || this.engine.disposed) return;
|