threedog 1.4.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +48 -0
- package/README.md +13 -7
- package/bin/threedog.mjs +42 -0
- package/core/assets/assetEntry.js +1 -1
- package/core/assets/assetPart.js +1 -1
- package/core/base/Events.js +7 -1
- package/core/base/errorCodes.js +1 -1
- package/core/base/events.generated.js +2 -2
- package/core/engine/Engine.js +11 -7
- package/core/engine/copies.js +1 -1
- package/core/engine/moduleTypes.js +1 -1
- package/core/engine/modules.js +23 -6
- package/core/engine/page.js +1 -0
- package/core/engine/services.js +5 -3
- package/core/engine/startup.js +4 -1
- package/core/inspect/DebugOverrides.js +2 -2
- package/core/inspect/InspectPerf.js +1 -1
- package/core/inspect/describeRender.js +0 -7
- package/core/inspect/metadata.generated.js +139 -50
- package/core/inspect/pictureChecks.js +2 -27
- package/core/ops/control.js +3 -3
- package/core/ops/holds.js +8 -3
- package/core/ops/sharedPoint.js +11 -2
- package/core/saves/saveApply.js +3 -3
- package/core/saves/session.js +20 -4
- package/core/scene/adaptive.js +5 -2
- package/core/scene/pixelRatio.js +39 -17
- package/core/scene/sceneMethods.js +1 -1
- package/core/scene/things.js +3 -2
- package/core/scene/tier.js +2 -16
- package/core/scene/view.js +14 -0
- package/core/time/skip.js +1 -1
- package/docs/AI.md +2 -2
- package/docs/CODEMAP.md +8 -8
- package/docs/COMMANDS.md +2 -2
- package/docs/CONVENTIONS.md +1 -0
- package/docs/THREE.md +1 -1
- package/docs/api/ambience.md +2 -2
- package/docs/api/cameraRig.md +7 -0
- package/docs/api/engine.md +6 -3
- package/docs/api/events.md +3 -3
- package/docs/api/particles.md +1 -1
- package/docs/api/photo.md +5 -0
- package/docs/api/pickups.md +1 -1
- package/docs/api/post.md +1 -1
- package/docs/api/rigid.md +1 -1
- package/docs/api/sky.md +11 -1
- package/docs/api/terrain.md +19 -0
- package/docs/api/tools.md +1 -1
- package/docs/recipes/01-new-game.md +1 -1
- package/docs/recipes/03-items-pickups.md +1 -1
- package/docs/recipes/05-props-bake.md +1 -1
- package/docs/recipes/06-clock-events.md +3 -10
- package/docs/recipes/07-flow-scenes-pause.md +3 -4
- package/docs/recipes/09-materials-lights-models.md +1 -1
- package/docs/recipes/10-blender-level.md +2 -2
- package/docs/recipes/{11-vehicles.md → 11-physics.md} +13 -5
- package/docs/recipes/12-navmesh.md +3 -3
- package/docs/recipes/14-custom-module.md +6 -5
- package/docs/recipes/15-perf.md +1 -1
- package/docs/recipes/16-dev-bridge.md +1 -1
- package/docs/recipes/18-world.md +1 -1
- package/docs/recipes/20-content-actions-save.md +0 -1
- package/docs/recipes/21-camera.md +11 -1
- package/docs/recipes/26-ui-parts.md +2 -2
- package/docs/recipes/27-net.md +1 -1
- package/docs/recipes/29-grid.md +1 -1
- package/docs/recipes/34-environment-lighting.md +5 -3
- package/docs/recipes/40-scene.md +1 -1
- package/docs/recipes/44-water-weather-hooks.md +1 -1
- package/docs/recipes/45-cascaded-shadows.md +6 -3
- package/docs/recipes/51-capability-catalog.md +1 -1
- package/docs/recipes/52-around-the-picture.md +8 -8
- package/docs/recipes/53-ground-up-close.md +2 -2
- package/docs/recipes/55-mods-time-wrap.md +6 -8
- package/docs/recipes/57-control.md +1 -1
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +7 -7
- package/docs/recipes/62-picture-code.md +13 -17
- package/examples/action/GAMEMAP.md +4 -2
- package/examples/action/picture/lights.js +3 -2
- package/examples/perf-island/GAMEMAP.md +2 -1
- package/examples/perf-island/picture/lights.js +3 -2
- package/examples/styletest/GAMEMAP.md +2 -2
- package/examples/styletest/picture/env.js +1 -2
- package/examples/techniques/contact-shadows/README.md +1 -1
- package/examples/techniques/day-night-grade/picture/lights.js +3 -1
- package/examples/techniques/interior-light/README.md +1 -1
- package/examples/techniques/interior-light/picture/lights.js +4 -2
- package/examples/techniques/modular-building/picture/lights.js +3 -2
- package/examples/techniques/night-lights/README.md +1 -1
- package/examples/techniques/night-lights/picture/lights.js +3 -1
- package/examples/techniques/night-lights/picture/post.js +2 -2
- package/examples/techniques/outlines-and-rim/README.md +1 -1
- package/examples/techniques/outlines-and-rim/picture/lights.js +3 -2
- package/examples/techniques/procedural-animation/README.md +1 -1
- package/examples/techniques/procedural-animation/picture/lights.js +3 -1
- package/examples/techniques/procedural-surface/README.md +1 -1
- package/examples/techniques/procedural-surface/picture/lights.js +3 -1
- package/examples/techniques/stylized-shading/picture/lights.js +3 -1
- package/examples/techniques/wet-road/README.md +1 -1
- package/examples/techniques/wet-road/picture/lights.js +3 -1
- package/examples/webgpu-tsl/GAMEMAP.md +4 -2
- package/examples/webgpu-tsl/picture/lights.js +3 -1
- package/examples/world/GAMEMAP.md +4 -3
- package/examples/world/picture/lights.js +3 -1
- package/examples/world/picture/post.js +2 -2
- package/llms.txt +33 -7
- package/modules/camera/common.js +22 -20
- package/modules/camera/contract.js +1 -1
- package/modules/characters/Character.js +2 -2
- package/modules/characters/NPC.js +7 -8
- package/modules/characters/index.js +8 -8
- package/modules/characters/mover.contract.js +1 -1
- package/modules/characters/movers/rapier.js +7 -9
- package/modules/characters/npcAvoid.js +2 -2
- package/modules/characters/player.js +11 -15
- package/modules/characters/playerStrings.js +1 -2
- package/modules/characters/seat.js +1 -1
- package/modules/collision/Collision.js +1 -1
- package/modules/collision/grid.js +1 -1
- package/modules/content/index.js +4 -3
- package/modules/content/models.js +1 -1
- package/modules/content/templates.js +3 -2
- package/modules/flow/index.js +8 -8
- package/modules/gameplay/Dialogue.js +1 -1
- package/modules/gameplay/Inventory.js +3 -3
- package/modules/gameplay/Quests.js +1 -0
- package/modules/gameplay/inventory.contract.js +1 -1
- package/modules/gameplay/pickups.js +1 -1
- package/modules/gameplay/questLog.js +0 -1
- package/modules/grid/index.js +1 -1
- package/modules/grid/tiles.js +6 -3
- package/modules/hud/index.js +2 -2
- package/modules/level/contract.js +2 -2
- package/modules/level/index.js +1 -1
- package/modules/music/Music.js +1 -1
- package/modules/nav/index.js +1 -1
- package/modules/net/sync.js +1 -1
- package/modules/particles/Particles.js +12 -5
- package/modules/particles/effect.js +17 -3
- package/modules/photo/pathTrace.js +1 -1
- package/modules/rigid/RigidBodies.js +23 -9
- package/modules/rigid/ragdoll.js +1 -1
- package/modules/rigid/sync.js +14 -0
- package/modules/settings/Settings.js +3 -2
- package/modules/settings/apply.js +4 -3
- package/modules/settings/sections.js +1 -1
- package/modules/sky/Sky.js +9 -4
- package/modules/sky/environment.js +5 -3
- package/modules/terrain/index.js +1 -2
- package/modules/timeline/Timeline.js +9 -6
- package/modules/vegetation/Vegetation.js +1 -1
- package/modules/vegetation/index.js +1 -1
- package/modules/weather/weatherDraw.js +1 -2
- package/modules/world/World.js +1 -0
- package/modules/world/index.js +1 -0
- package/modules/world/persist.js +1 -1
- package/package.json +6 -2
- package/render/PostFX.js +17 -12
- package/render/fx/postWebGPU.tsl.js +2 -1
- package/render/lightmap.js +1 -1
- package/render/lights.js +1 -2
- package/render/neutral.js +1 -1
- package/render/patches.js +3 -3
- package/render/probes.js +27 -2
- package/render/shaderErrors.js +1 -1
- package/render/shadows.js +1 -3
- package/types/core.d.ts +16 -9
- package/types/gameplay.d.ts +8 -3
- package/types/generated/modules/sky/Sky.d.ts +4 -4
- package/types/generated/render/PostFX.d.ts +2 -2
- package/types/generated/ui/UI.d.ts +2 -1
- package/types/physics.d.ts +1 -1
- package/types/world.d.ts +4 -2
- package/ui/UI.js +18 -14
- package/ui/cursor.js +2 -2
- package/examples/action/.threedog/content-index.json +0 -1
- package/examples/perf-island/.threedog/content-index.json +0 -1
- package/examples/plain-picture/.threedog/content-index.json +0 -1
- package/examples/rc2d/.threedog/content-index.json +0 -1
- package/examples/styletest/.threedog/content-index.json +0 -1
- package/examples/webgpu-tsl/.threedog/content-index.json +0 -1
- package/examples/world/.threedog/content-index.json +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "threedog",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Web 3D game engine on three.js:
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"description": "Web 3D game engine on three.js, built to be driven by an AI. Start: npm install threedog three && npm install -D @threedog/tools && npx threedog init (writes the game and its CLAUDE.md). No built-in art",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
"type": "module",
|
|
19
19
|
"main": "./index.js",
|
|
20
20
|
"types": "./index.d.ts",
|
|
21
|
+
"bin": {
|
|
22
|
+
"threedog": "./bin/threedog.mjs"
|
|
23
|
+
},
|
|
21
24
|
"exports": {
|
|
22
25
|
".": {
|
|
23
26
|
"types": "./index.d.ts",
|
|
@@ -47,6 +50,7 @@
|
|
|
47
50
|
"./package.json": "./package.json"
|
|
48
51
|
},
|
|
49
52
|
"files": [
|
|
53
|
+
"bin",
|
|
50
54
|
"index.js",
|
|
51
55
|
"index.d.ts",
|
|
52
56
|
"presets.js",
|
package/render/PostFX.js
CHANGED
|
@@ -15,7 +15,7 @@ import { warnOnce } from '../core/base/validate.js';
|
|
|
15
15
|
import { reportError } from '../core/base/errors.js';
|
|
16
16
|
import { readParams, keysSchema } from '../core/base/params.js';
|
|
17
17
|
import { isWebGPU, webgpuPart, ownMsaa } from './backend.js';
|
|
18
|
-
import { MSAA_KEY
|
|
18
|
+
import { MSAA_KEY } from '../core/scene/tier.js';
|
|
19
19
|
import { defineOwned } from '../core/ops/owned.js';
|
|
20
20
|
import { watchOwnFrame } from './ownFrame.js';
|
|
21
21
|
import { runsHere, OUTPUT_TWICE } from './postRuns.js';
|
|
@@ -45,7 +45,7 @@ import { runsHere, OUTPUT_TWICE } from './postRuns.js';
|
|
|
45
45
|
* @typedef {{ engine: Engine, scene: import('three').Scene, camera: import('three').Camera, width: number, height: number, params: Record<string, any>,
|
|
46
46
|
* scenePass: any, buffer: (name: string) => any, tsl: any, fx: Record<string, Function>, display: Record<string, Function>, p: Record<string, any>, borrowRenderer: BorrowRenderer }} PostNodeContext
|
|
47
47
|
* WebGPU only. scenePass: the scene's pass() node (.getTextureNode('depth'), getViewZNode() ...); buffer(name): a needsBuffers output as a texture node
|
|
48
|
-
* ('normal' | 'diffuse' | 'velocity' | 'metalRough', the last as .x metalness, .y roughness: it may share velocity's target, so read it here, not from scenePass); tsl: three/tsl; display: three's display nodes (bloom, ao from three/addons/tsl/display) plus
|
|
48
|
+
* ('normal' | 'diffuse' | 'velocity' | 'metalRough', the last as .x metalness, .y roughness: it may share velocity's target, so read it here, not from scenePass); tsl: three/tsl; display: three's display nodes (bloom, ao, denoise from three/addons/tsl/display) plus
|
|
49
49
|
* pass (an extra scene render), texture (the color so far as a texture to sample at other uvs) and own (a node the effect made itself, disposed with the chain),
|
|
50
50
|
* handed in so the main entry of an effect package never imports three/webgpu (its /tsl subpath may, a WebGL game never loads that) and so the nodes they make are disposed with the chain;
|
|
51
51
|
* fx: the threedog/tsl functions (noise, hash ...), handed in for the same reason;
|
|
@@ -123,7 +123,7 @@ export class PostFX {
|
|
|
123
123
|
// handed back: the kept WebGPU stages go too, the game may have edited those nodes while it owned them, so the declared chain is rebuilt whole
|
|
124
124
|
levels: { manual: 'engine.post.own()' }, onChange: o => { if (!o.on) return; if (this._pipe) { this._pipe.key = null; this._pipe.stages = []; } this._sync(); } });
|
|
125
125
|
this._sync();
|
|
126
|
-
|
|
126
|
+
engine.stacks.get('tier').watch(() => this._sync()); // effects held by tier (skipOnLowTier) follow it; after the first sync, so a throw there leaves no listener
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
/**
|
|
@@ -181,7 +181,7 @@ export class PostFX {
|
|
|
181
181
|
* The one way to add a post effect. x is a three.js Pass (WebGL), a TSL node function (input, ctx) => node (WebGPU), or an effect
|
|
182
182
|
* { name, create | node | fuse, slot, order, params, needsDepth, needsBuffers, backend, skipOnLowTier, cheaper, facts } (both renderers when it gives create and node, or a fuse). A wrong shape throws with nothing added.
|
|
183
183
|
* needsDepth, needsBuffers ('normal' | 'diffuse' | 'velocity' | 'metalRough', WebGPU), backend ('webgpu': not on the WebGL2 backend), skipOnLowTier (held when engine.tier is 'low') and facts (shown by describe().render.post) are explained on PostEffect.
|
|
184
|
-
* A Pass that draws engine.scene takes the 'scene' slot, FXAA / SMAA
|
|
184
|
+
* A Pass that draws engine.scene (RenderPass family, SSAA / TAA, RenderPixelatedPass; your own: `{ slot: 'scene' }`) takes the 'scene' slot, FXAA / SMAA 'final', any other 'hdr' after the effects already there, or 'ldr' once an
|
|
185
185
|
* OutputPass was added. A RenderPass of engine.scene and an OutputPass are the engine's own stages: skipped and said once (an OutputPass still marks where display color starts).
|
|
186
186
|
* @example const glow = engine.post.add(new UnrealBloomPass(size, 0.6, 0.4, 0.85), { name: 'glow' }); glow.enabled = false;
|
|
187
187
|
* @example engine.post.add({ name: 'dim', fuse: { glsl: 'color.rgb *= 0.9;' }, slot: 'ldr' });
|
|
@@ -214,8 +214,8 @@ export class PostFX {
|
|
|
214
214
|
if (odd.length) throw codedError('post-effect', `post effect '${effect.name}': cheaper names ${odd.join(', ')}, not in its params (${Object.keys(effect.params ?? {}).join(', ') || 'none'}); cheaper holds lower values of its own params`);
|
|
215
215
|
finiteParams(effect.name, effect.params, 'params');
|
|
216
216
|
const post = this, point = this.switchPoint(`post.${effect.name}.enabled`);
|
|
217
|
-
point.release('game'); point.
|
|
218
|
-
let on = !!point.value();
|
|
217
|
+
point.release('game'); point.setBase(effect.enabled ?? true); // only the game's own word starts over: the player's off and any other owner's hold stay on the effect that comes back
|
|
218
|
+
let on = !!point.value(), follow = /** @type {{ remove(): void } | null} */ (null); // follow is set after this effect's own setBase: no extra sync here
|
|
219
219
|
const h = {
|
|
220
220
|
name: effect.name, slot: s, order: effect.order ?? 0, seq: this._place(effect.name),
|
|
221
221
|
params: { ...effect.params }, _def: effect, _impl: /** @type {any} */ (null), _removed: false, _entry: /** @type {any} */ (null), _on: () => on,
|
|
@@ -252,7 +252,7 @@ export class PostFX {
|
|
|
252
252
|
remove() {
|
|
253
253
|
if (h._removed) return;
|
|
254
254
|
h._removed = true;
|
|
255
|
-
|
|
255
|
+
follow?.remove(); follow = null; point.release('game');
|
|
256
256
|
post._change(() => {
|
|
257
257
|
freeImpl(h);
|
|
258
258
|
post._list = post._list.filter(e => e !== h);
|
|
@@ -262,10 +262,10 @@ export class PostFX {
|
|
|
262
262
|
},
|
|
263
263
|
};
|
|
264
264
|
// a settings restriction or a hold ending turns it on or off here; a rebuild that throws leaves it as it was
|
|
265
|
-
|
|
265
|
+
follow = point.watch(() => { const was = on, now = !!point.value(); if (now !== was) this._change(() => { on = now; }, () => { on = was; }); });
|
|
266
266
|
// a create() that throws or an order that breaks depth leaves no half-added effect behind
|
|
267
267
|
try { this._change(() => this._list.push(h), () => { freeImpl(h); this._list = this._list.filter(e => e !== h); }); }
|
|
268
|
-
catch (err) {
|
|
268
|
+
catch (err) { follow?.remove(); follow = null; if (!this._kept.has(h.name)) this._seq.delete(h.name); throw err; }
|
|
269
269
|
this.engine._picture?.added('post effect', h, h.name); // dev: a picture part removed with this still on is reported (core/inspect/pictureWriters.js)
|
|
270
270
|
this.engine.events.emit('post:add', h.name); // the settings rows follow an effect by its role, so one added after them still gets the player's choice
|
|
271
271
|
return h;
|
|
@@ -471,13 +471,18 @@ function reslot(post) {
|
|
|
471
471
|
if (moved.length) post._change(() => { for (const [h, , s] of moved) h.slot = s; }, () => { for (const [h, was] of moved) h.slot = was; });
|
|
472
472
|
}
|
|
473
473
|
|
|
474
|
-
/**
|
|
475
|
-
|
|
474
|
+
/**
|
|
475
|
+
* A three.js Pass that draws the scene itself (RenderPixelatedPass, SSAARenderPass, TAARenderPass, a RenderPass): it replaces the scene render.
|
|
476
|
+
* Known by what only those have (isRenderPass; sampleLevel of SSAA / TAA; pixelSize of RenderPixelatedPass), not by "holds scene and camera":
|
|
477
|
+
* GTAOPass, SAOPass, SSAOPass, SSRPass and BokehPass hold both too but read the scene render before them, and taking them for a
|
|
478
|
+
* replacement left the screen at the background colour with no message. A game's own scene-drawing Pass says so: add(pass, { slot: 'scene' }).
|
|
479
|
+
*/
|
|
480
|
+
const drawsScene = (eng, p) => p.scene === eng.scene && !!p.camera && !!(p.isRenderPass || 'sampleLevel' in p || 'pixelSize' in p);
|
|
476
481
|
|
|
477
482
|
/**
|
|
478
483
|
* add()'s value as a post effect; null for a RenderPass of engine.scene and { output: true } for an OutputPass (the engine's own stages). The three accepted shapes and where a plain Pass goes:
|
|
479
484
|
* a pass that renders engine.scene itself goes in the 'scene' slot (it replaces the engine's scene render: stacked after it, the scene was
|
|
480
|
-
* drawn twice a frame), FXAA / SMAA
|
|
485
|
+
* drawn twice a frame), FXAA / SMAA in 'final', any other pass in 'hdr' after the other effects (order 1000+), where it would sit in
|
|
481
486
|
* a hand-built composer.
|
|
482
487
|
* @param {any} post @param {any} x @param {{ name?: string, slot?: string, order?: number }} o
|
|
483
488
|
*/
|
|
@@ -8,6 +8,7 @@ import { RenderPipeline, UnsignedByteType } from 'three/webgpu';
|
|
|
8
8
|
import * as TSL from 'three/tsl';
|
|
9
9
|
import { bloom } from 'three/addons/tsl/display/BloomNode.js';
|
|
10
10
|
import { ao } from 'three/addons/tsl/display/GTAONode.js';
|
|
11
|
+
import { denoise } from 'three/addons/tsl/display/DenoiseNode.js';
|
|
11
12
|
import { codedError } from '../../core/base/errorHints.js';
|
|
12
13
|
import { warnOnce } from '../../core/base/validate.js';
|
|
13
14
|
import { runsOnWebGPU, OUTPUT_TWICE } from '../postRuns.js';
|
|
@@ -72,7 +73,7 @@ function displayFor(made) {
|
|
|
72
73
|
// pass: an extra scene render (outline's normal / mask views); texture: the color so far as a texture, for effects that sample it at other
|
|
73
74
|
// uvs (dof). Both own render targets, so they go through the recorder too; a node that already is a texture comes back as is and is not ours to dispose.
|
|
74
75
|
const texture = n => { const t = convertToTexture(n); if (t !== n) made.push(t); return t; };
|
|
75
|
-
return { bloom: rec(bloom), ao: rec(ao), pass: rec(extraPass), texture, own: n => { made.push(n); return n; } };
|
|
76
|
+
return { bloom: rec(bloom), ao: rec(ao), denoise: rec(denoise), pass: rec(extraPass), texture, own: n => { made.push(n); return n; } };
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
/** An extra scene render: occlusion's boxes belong to the scene pass alone, drawn here they would show through an override material (outline's normal view) */
|
package/render/lightmap.js
CHANGED
|
@@ -9,7 +9,7 @@ import { readParams } from '../core/base/params.js';
|
|
|
9
9
|
import { codedError, coded } from '../core/base/errorHints.js';
|
|
10
10
|
import { warnOnce, fmt } from '../core/base/validate.js';
|
|
11
11
|
import { mats } from './lit.js';
|
|
12
|
-
import { litTwice } from '
|
|
12
|
+
import { litTwice } from './probes.js';
|
|
13
13
|
|
|
14
14
|
const FORMAT = 'threedog-lightmap', VERSION = 1, MAGIC = 0x4d4c4454; // 'TDLM'
|
|
15
15
|
const LOAD = { owner: { type: 'string', default: 'game', desc: 'who loaded it (describe().render.lightmap)' } };
|
package/render/lights.js
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
import { engineOwned } from '../core/scene/things.js';
|
|
6
6
|
import * as THREE from 'three';
|
|
7
7
|
import { defineOwned } from '../core/ops/owned.js';
|
|
8
|
-
import { onTierChange } from '../core/scene/tier.js';
|
|
9
8
|
|
|
10
9
|
const BOX = 30, SNAP = 0.5;
|
|
11
10
|
|
|
@@ -34,7 +33,7 @@ export function createDefaultLights(engine, { add = true } = {}) {
|
|
|
34
33
|
// One rule for both tier defaults, size and radius: a value still at the engine's default for the old tier follows the tier, any other value is the
|
|
35
34
|
// game's and stays. Known edge: a game that writes exactly the engine's default reads as untouched and still follows (no accessor: it would hide the
|
|
36
35
|
// value from engine.debug.watch / explain, which only hook plain properties)
|
|
37
|
-
|
|
36
|
+
engine.stacks.get('tier').watch(() => {
|
|
38
37
|
const was = map, next = map = sizeFor(), s = sun.shadow;
|
|
39
38
|
if (next === was) return;
|
|
40
39
|
if (s.mapSize.x === was && s.mapSize.y === was) { if (engine.shadows) engine.shadows.mapSize(sun, next); else s.mapSize.set(next, next); }
|
package/render/neutral.js
CHANGED
|
@@ -6,7 +6,7 @@ import * as THREE from 'three';
|
|
|
6
6
|
import { markEngineMade } from './patches.js';
|
|
7
7
|
|
|
8
8
|
/** The gray of everything the engine draws until the game gives it a picture */
|
|
9
|
-
|
|
9
|
+
const NEUTRAL = 0x8c8c8c;
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* A plain MeshLambertMaterial for engine code: neutral gray unless params say otherwise. params are three.js material properties.
|
package/render/patches.js
CHANGED
|
@@ -147,7 +147,7 @@ const PROTO_COMPILE = THREE.Material.prototype.onBeforeCompile, PROTO_KEY = THRE
|
|
|
147
147
|
// carries this key: a function handing back the game's part it wraps (null / three's method when the game had none). The WebGPU route names
|
|
148
148
|
// only the game's GLSL hook by it (render/backend.js), and cloneMaterial carries the game's part instead of a wrapper bound to the original
|
|
149
149
|
/** @internal */
|
|
150
|
-
|
|
150
|
+
const WRAPPED = Symbol.for('threedog.patchWrapper');
|
|
151
151
|
|
|
152
152
|
function apply(shader, list, m, renderer) {
|
|
153
153
|
for (const p of list) for (const d of p.needs?.data || []) if (!shader[d]) {
|
|
@@ -450,8 +450,8 @@ export function unpatchMaterial(material, name) {
|
|
|
450
450
|
|
|
451
451
|
// What three's clone leaves behind. NodeMaterial.copy (and Material.copy's fixed list) carries only properties a fresh instance of the class
|
|
452
452
|
// already has, so what a game set on the instance itself was dropped: its own lighting (mat.setupLightingModel = celLighting, the cel.tsl.js
|
|
453
|
-
// example), its own onBeforeCompile, a field its class never declares. The copy then drew with three's plain lighting (
|
|
454
|
-
//
|
|
453
|
+
// example), its own onBeforeCompile, a field its class never declares. The copy then drew with three's plain lighting (a game's own toon
|
|
454
|
+
// lighting on every cloned model was lost). Skipped as three's copy skips them: '_' internals, is* flags, ids, userData (copied by three)
|
|
455
455
|
const NOT_CARRIED = /^(?:is[A-Z]|_)|^(?:id|uuid|version|type|userData|clippingPlanes)$/;
|
|
456
456
|
/** The game's part under engine wrappers (WRAPPED), else the value itself */
|
|
457
457
|
const gamePart = v => { while (typeof v === 'function' && v[WRAPPED]) v = v[WRAPPED](); return v; };
|
package/render/probes.js
CHANGED
|
@@ -16,8 +16,33 @@ import { codedError, coded } from '../core/base/errorHints.js';
|
|
|
16
16
|
import { warnOnce, fmt } from '../core/base/validate.js';
|
|
17
17
|
import { vec3 } from '../core/base/math.js';
|
|
18
18
|
import { isWebGPU, webgpuPart, freshFrame, readLayer, onRendererSwap } from './backend.js';
|
|
19
|
-
import { mats, lit } from './lit.js';
|
|
20
|
-
|
|
19
|
+
import { mats, lit, noteFillLight, noteEnvironment } from './lit.js';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Baked light (a probe set or a lightmap) plus a light the bake already saw: that light counts twice. Said at load time by
|
|
23
|
+
* probes.js and lightmap.js, and again by the picture check (the same words). @param {any} e @returns {string | null}
|
|
24
|
+
*/
|
|
25
|
+
export function litTwice(e) {
|
|
26
|
+
const probes = !!e._probeSets?.size, lightmap = !!e._lightmap;
|
|
27
|
+
if (!probes && !lightmap) return null;
|
|
28
|
+
const doubled = [];
|
|
29
|
+
let mapped = 0;
|
|
30
|
+
e.scene.traverseVisible(o => {
|
|
31
|
+
if (noteFillLight(o, doubled)) return;
|
|
32
|
+
if (lightmap && o.isLightProbeGrid) doubled.push(`probe grid ${o.name}`); // the lightmap baked the bounce the grid adds again
|
|
33
|
+
else if (probes && !lightmap && o.isMesh && mats(o).some(m => m?.lightMap)) mapped++; // a game's own lightMap under a probe grid
|
|
34
|
+
});
|
|
35
|
+
noteEnvironment(e.scene, doubled);
|
|
36
|
+
if (mapped) doubled.push(`material.lightMap on ${mapped} mesh(es)`);
|
|
37
|
+
if (!doubled.length) return null;
|
|
38
|
+
const what = [probes && 'probe', lightmap && 'lightmap'].filter(Boolean).join(' and ');
|
|
39
|
+
const list = doubled.slice(0, 2).join(', ') + (doubled.length > 2 ? ` and ${doubled.length - 2} more` : '');
|
|
40
|
+
if (!bakeSeenScene(e)) return `${what} light is added on top of ${list}. If the bake saw it, it counts twice (a loaded file does not say which lights it saw). Fix: lower it where the bake takes over, or bake without it.`;
|
|
41
|
+
return `${what} light is added on top of ${list}, which the bake already saw, so it counts twice. Fix: lower it where the bake takes over, or bake without it.`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** True only when every baked light came from a bake made in this session (engine.bakeProbes): it saw this scene's lights. A loaded file or a lightmap carries no record of them */
|
|
45
|
+
export const bakeSeenScene = e => !e._lightmap && [...(e._probeSets ?? [])].every(s => s.source === 'bake');
|
|
21
46
|
|
|
22
47
|
const FORMAT = 'threedog-probes', VERSION = 2, MAX_PROBES = 4096, SH = 27;
|
|
23
48
|
const CHUNK = 8; // probes baked per turn of the event loop, so the page keeps drawing during a long bake
|
package/render/shaderErrors.js
CHANGED
|
@@ -157,7 +157,7 @@ function explainBuildError(message) {
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
let consoleHooked = false;
|
|
160
|
-
/** Wrap three's console function once per page: three's message
|
|
160
|
+
/** Wrap three's console function once per page: three's own message first, then the explanation for a pipeline failure */
|
|
161
161
|
function hookThreeConsole() {
|
|
162
162
|
if (consoleHooked) return;
|
|
163
163
|
consoleHooked = true;
|
package/render/shadows.js
CHANGED
|
@@ -14,7 +14,6 @@ import { warnOnce, fmt } from '../core/base/validate.js';
|
|
|
14
14
|
import { readParams } from '../core/base/params.js';
|
|
15
15
|
import { defineOwned, dropOwned, ownedRow } from '../core/ops/owned.js';
|
|
16
16
|
import { isWebGPU, onRendererSwap, setShadowUpdate, shadowsOn, webgpuPart } from './backend.js';
|
|
17
|
-
import { onTierChange } from '../core/scene/tier.js';
|
|
18
17
|
import { CASCADE_DEFAULTS, CASCADE_SPLITS, createCascades, dropCascades, includeInCascades } from './cascades.js';
|
|
19
18
|
|
|
20
19
|
const WHERE = 'engine.shadows.cascades';
|
|
@@ -202,7 +201,6 @@ function ownBudget(e, light, first) {
|
|
|
202
201
|
function switchShadows(e, on) {
|
|
203
202
|
e.renderer.shadowMap.enabled = on;
|
|
204
203
|
e.scene.traverse(o => { if (o.material) [].concat(o.material).forEach(m => { m.needsUpdate = true; }); });
|
|
205
|
-
e.events.emit('settings:shadows', on);
|
|
206
204
|
}
|
|
207
205
|
|
|
208
206
|
/** The running handle's cascades. The WebGL half keeps what the game wrote apart from the placement; see the header */
|
|
@@ -257,7 +255,7 @@ function ownCascades(e, light, first, gameExtent = () => undefined) {
|
|
|
257
255
|
};
|
|
258
256
|
sync(); // first, so a request that throws (a bad split callback) returns no handle and leaves no listener behind
|
|
259
257
|
const swap = onRendererSwap(e, () => { if (c?.isCascadeNode) { off(); sync(); } }); // fallback 'webgl': the shadow node has no meaning on the new renderer
|
|
260
|
-
const tier =
|
|
258
|
+
const tier = e.stacks.get('tier').watch(sync); // the map count reads engine.tier: a preset switched while running rebuilds once (sync's key skips the rest)
|
|
261
259
|
return {
|
|
262
260
|
frame() {
|
|
263
261
|
box?.frame();
|
package/types/core.d.ts
CHANGED
|
@@ -82,10 +82,10 @@ export interface EventMap extends GameEvents {
|
|
|
82
82
|
'ui:open': [id: string];
|
|
83
83
|
/** A window was closed */
|
|
84
84
|
'ui:close': [id: string];
|
|
85
|
-
/** Shadows were toggled */
|
|
86
|
-
'settings:shadows': [on: boolean];
|
|
87
85
|
/** A value in the settings menu changed (the argument is all setting values) */
|
|
88
86
|
'settings:change': [values: Record<string, any>];
|
|
87
|
+
/** engine.tier changed (device found at start, a preset, a write): resize what was sized from it */
|
|
88
|
+
'tier:change': [{ tier: 'low' | 'high' }];
|
|
89
89
|
/** A post effect was added (its name) */
|
|
90
90
|
'post:add': [name: string];
|
|
91
91
|
/** A water body was added */
|
|
@@ -189,7 +189,7 @@ export interface EventMap extends GameEvents {
|
|
|
189
189
|
/**
|
|
190
190
|
* rigid: newGame / a load rebuilt the physics world (a fresh page for physics) and the engine's bodies are back (entry.body is the rebuilt Rapier
|
|
191
191
|
* body; bodies maps the ids given to addBox / addBall / addHull / addWheeled). The old world's joints were freed with it: re-create the game's
|
|
192
|
-
* joints here (recipes/11-
|
|
192
|
+
* joints here (recipes/11-physics.md, Joints). Not emitted while a vehicle exists (the world is kept then, joints included)
|
|
193
193
|
*/
|
|
194
194
|
'rigid:rebuilt': [{ world: any; player: any; bodies: Record<string, any> }];
|
|
195
195
|
/** terrain({ shape }): the player or a moving rigid body dropped below engine.terrain.voidY (once per fall). The engine does not respawn: the game decides */
|
|
@@ -234,7 +234,7 @@ export interface EventMap extends GameEvents {
|
|
|
234
234
|
'engine:error': [EngineError];
|
|
235
235
|
/** A picture or ui module errored and was disabled (the game continues) */
|
|
236
236
|
'module:disabled': [{ name: string; message: string }];
|
|
237
|
-
'module:
|
|
237
|
+
'module:fresh': [{ modules: any[] }];
|
|
238
238
|
/** An atomic op failed and its parts were put back (its own events already went out and stay): read derived state again. Not sent for a load's rollback (that ends in state:replaced) */
|
|
239
239
|
'op:rolledBack': [{ op: string; parts: number }];
|
|
240
240
|
/** @internal The state was replaced by something other than a step, from any door (core/saves/stateReplace.js); undone: a failed load put the old state back */
|
|
@@ -1051,7 +1051,7 @@ export interface ModuleCtx {
|
|
|
1051
1051
|
/** engine.budget.metric, owned */
|
|
1052
1052
|
budget: { metric(name: string, read: () => number, opts?: { limit?: number }): Handle };
|
|
1053
1053
|
/** Where engine.thing finds this module's records, and what engine.explain({ thing }) adds; owned */
|
|
1054
|
-
things: { addSource(source: any): Handle; explainWith(fn: (e: Engine, thing: any, out: any) => void): Handle };
|
|
1054
|
+
things: { addSource(source: any): Handle; explainWith(fn: (e: Engine, thing: any, out: any) => void): Handle; recordsLoaded(info: { count: number }): void };
|
|
1055
1055
|
/**
|
|
1056
1056
|
* Give the ground. provides must name 'ground' (terrain and level hold it too, so two providers are refused at use()); when the module goes the flat ground comes back.
|
|
1057
1057
|
* addColliders: more static colliders in engine.ground.forEachCollider, whoever gives the ground.
|
|
@@ -1144,8 +1144,15 @@ export interface ModuleDef<Api = any> {
|
|
|
1144
1144
|
content?: Record<string, ContentSection>;
|
|
1145
1145
|
/** The loading screen waits until this returns true before disappearing (the hook is called isReady; in the engine ready is always a boolean property) */
|
|
1146
1146
|
isReady?(e: Engine): boolean;
|
|
1147
|
-
/**
|
|
1147
|
+
/** Session reset, step 1 (core/saves/session.js): a playthrough ends (newGame / load / quit), before anything is replaced. Stop what belongs to it (a cutscene, the music); start nothing.
|
|
1148
|
+
* Every reset step runs in engine.moduleOrder (stage, before / after), before the matching event (session:end) reaches the game */
|
|
1149
|
+
sessionEnd?(e: Engine): void;
|
|
1150
|
+
/** Session reset, step 2: the world's records were replaced wholesale (any load, new game included), before 'world:load'. Rebuild what is derived from the records */
|
|
1151
|
+
worldLoad?(e: Engine, info: { count: number }): void;
|
|
1152
|
+
/** Session reset, step 3: after a save loaded: rebuild what the loaded state needs nearby; gameplay waits frozen until the returned Promise resolves. turn: as SaveProvider.load */
|
|
1148
1153
|
afterLoad?(e: Engine, turn: SaveTurn): void | Promise<void>;
|
|
1154
|
+
/** Session reset, step 4: a new playthrough began (not after a quick load), before 'session:start' */
|
|
1155
|
+
sessionStart?(e: Engine, info: { kind: 'new' | 'load'; slot?: string }): void;
|
|
1149
1156
|
/** Fixed step (60 times per second); dt is in seconds */
|
|
1150
1157
|
fixed?(dt: number, e: Engine): void;
|
|
1151
1158
|
/** Once per frame; dt is in seconds */
|
|
@@ -1722,7 +1729,7 @@ export declare class Engine {
|
|
|
1722
1729
|
validate: boolean;
|
|
1723
1730
|
/** three.js renderer: WebGLRenderer, or WebGPURenderer on the WebGPU route (EngineRenderer) */
|
|
1724
1731
|
renderer: EngineRenderer;
|
|
1725
|
-
/** The one quality value, what everything that scales by quality reads: the device's tier, 'low' (phones, integrated graphics) | 'high', unless the player's preset says otherwise (shared point 'tier'). A headless page takes the device's from ?threedog-tier=low|high (threedog shot / gallery / capture pass high, shot --tier low checks the low tier) */
|
|
1732
|
+
/** The one quality value, what everything that scales by quality reads: the device's tier, 'low' (phones, integrated graphics) | 'high', unless the player's preset says otherwise (shared point 'tier'). Changes fire 'tier:change'. A headless page takes the device's from ?threedog-tier=low|high (threedog shot / gallery / capture pass high, shot --tier low checks the low tier) */
|
|
1726
1733
|
tier: 'low' | 'high';
|
|
1727
1734
|
/** three.js scene */
|
|
1728
1735
|
scene: import('three').Scene;
|
|
@@ -1988,7 +1995,7 @@ export declare class Engine {
|
|
|
1988
1995
|
dialogue?: Dialogue;
|
|
1989
1996
|
/** Inventory (inventory() module). Items, counts and containers, saved with the game. Install: engine.use(inventory()); undefined until installed. add() answers { ok }, read .ok */
|
|
1990
1997
|
inventory?: Inventory;
|
|
1991
|
-
/** pickups(). Things on the ground that go in the bag. Install: engine.use(
|
|
1998
|
+
/** pickups(). Things on the ground that go in the bag. Install: engine.use(world(), inventory(), interactions(), pickups()) (pickups are world records); undefined until installed. A full bag leaves the item on the ground */
|
|
1992
1999
|
pickups?: Pickups;
|
|
1993
2000
|
/** Quests (quests() module) */
|
|
1994
2001
|
quests?: Quests;
|
|
@@ -2155,7 +2162,7 @@ export declare class Engine {
|
|
|
2155
2162
|
loadLightmap(file: string | ArrayBuffer, opts?: { owner?: string }): Promise<Lightmap>;
|
|
2156
2163
|
|
|
2157
2164
|
// ---------- Settings ----------
|
|
2158
|
-
/** Render resolution, and the top adaptive resolution climbs back to. Throws while pixelSize is on */
|
|
2165
|
+
/** Render resolution, and the top adaptive resolution climbs back to. A ratio the player chose in settings below the device default caps it. Throws while pixelSize is on */
|
|
2159
2166
|
setPixelRatio(p: number): void;
|
|
2160
2167
|
/**
|
|
2161
2168
|
* One art pixel becomes k real screen pixels (createEngine({ pixelSize }) at runtime). While on, adaptive resolution stops, engine.setPixelRatio throws and a photo keeps
|
package/types/gameplay.d.ts
CHANGED
|
@@ -253,7 +253,7 @@ export interface Triggers {
|
|
|
253
253
|
|
|
254
254
|
/** Particle effect parameters (define(), and each entry of particles({ effects, default })). All optional */
|
|
255
255
|
export interface ParticleOptions {
|
|
256
|
-
/** Maximum alive at once, default 120 (60
|
|
256
|
+
/** Maximum alive at once, default 120 (60 while engine.tier is 'low'; a number the game gives stands) */
|
|
257
257
|
max?: number;
|
|
258
258
|
/** Seconds each particle lives [min, max] */
|
|
259
259
|
lifetime?: Range;
|
|
@@ -1703,8 +1703,13 @@ export interface Photo {
|
|
|
1703
1703
|
// Ambience (engine.ambience) is generated from the JSDoc in modules/ambience/Ambience.js (npm run map); only the type is re-exported here
|
|
1704
1704
|
import type { Ambience } from './generated/modules/ambience/Ambience';
|
|
1705
1705
|
export type { Ambience };
|
|
1706
|
-
/** ambience() options
|
|
1707
|
-
export interface AmbienceOptions {
|
|
1706
|
+
/** ambience() options */
|
|
1707
|
+
export interface AmbienceOptions {
|
|
1708
|
+
/** Rules added after the ones in createEngine({ audio: { ambience } }) */
|
|
1709
|
+
rules?: import('./core').AmbienceRule[];
|
|
1710
|
+
/** Seconds between rule checks, default 0.25 */
|
|
1711
|
+
interval?: number;
|
|
1712
|
+
}
|
|
1708
1713
|
// DebugPanel (engine.debug) is generated from the JSDoc in modules/debug/DebugPanel.js (npm run map); only the type is re-exported here
|
|
1709
1714
|
import type { DebugPanel } from './generated/modules/debug/DebugPanel';
|
|
1710
1715
|
export type { DebugPanel };
|
|
@@ -43,12 +43,12 @@ export class Sky {
|
|
|
43
43
|
};
|
|
44
44
|
/**
|
|
45
45
|
* The day's colors, live: rows [time, zenith, horizon, sunColor, ambient] sorted from 0 to 1 (the same rows as sky({ keyframes })).
|
|
46
|
-
* Throws, changing nothing, on rows that are not sorted from 0 to 1.
|
|
46
|
+
* Throws, changing nothing, on rows that are not sorted from 0 to 1. No argument: a copy of the rows in use (a picture gives them back on leaving).
|
|
47
47
|
* @example engine.sky.keyframes([[0, 0x101828, 0x202838, 0x8090b0, 0.3], [0.5, 0x4080c0, 0xc0d8e8, 0xffffff, 1.2], [1, 0x101828, 0x202838, 0x8090b0, 0.3]]);
|
|
48
|
-
* @param {any[][]} rows
|
|
49
|
-
* @returns {
|
|
48
|
+
* @param {any[][]} [rows]
|
|
49
|
+
* @returns {any[][]} the rows in use
|
|
50
50
|
*/
|
|
51
|
-
keyframes(rows
|
|
51
|
+
keyframes(rows?: any[][]): any[][];
|
|
52
52
|
set sunDir(v: THREE.Vector3);
|
|
53
53
|
/**
|
|
54
54
|
* Sun direction (unit vector toward the sun): the same vector as engine.uniforms.uSunDir. Computed each frame from the time and orbit until a game writes either,
|
|
@@ -44,7 +44,7 @@ export class PostFX {
|
|
|
44
44
|
* The one way to add a post effect. x is a three.js Pass (WebGL), a TSL node function (input, ctx) => node (WebGPU), or an effect
|
|
45
45
|
* { name, create | node | fuse, slot, order, params, needsDepth, needsBuffers, backend, skipOnLowTier, cheaper, facts } (both renderers when it gives create and node, or a fuse). A wrong shape throws with nothing added.
|
|
46
46
|
* needsDepth, needsBuffers ('normal' | 'diffuse' | 'velocity' | 'metalRough', WebGPU), backend ('webgpu': not on the WebGL2 backend), skipOnLowTier (held when engine.tier is 'low') and facts (shown by describe().render.post) are explained on PostEffect.
|
|
47
|
-
* A Pass that draws engine.scene takes the 'scene' slot, FXAA / SMAA
|
|
47
|
+
* A Pass that draws engine.scene (RenderPass family, SSAA / TAA, RenderPixelatedPass; your own: `{ slot: 'scene' }`) takes the 'scene' slot, FXAA / SMAA 'final', any other 'hdr' after the effects already there, or 'ldr' once an
|
|
48
48
|
* OutputPass was added. A RenderPass of engine.scene and an OutputPass are the engine's own stages: skipped and said once (an OutputPass still marks where display color starts).
|
|
49
49
|
* @example const glow = engine.post.add(new UnrealBloomPass(size, 0.6, 0.4, 0.85), { name: 'glow' }); glow.enabled = false;
|
|
50
50
|
* @example engine.post.add({ name: 'dim', fuse: { glsl: 'color.rgb *= 0.9;' }, slot: 'ldr' });
|
|
@@ -145,7 +145,7 @@ export type PostFuse = {
|
|
|
145
145
|
};
|
|
146
146
|
/**
|
|
147
147
|
* WebGPU only. scenePass: the scene's pass() node (.getTextureNode('depth'), getViewZNode() ...); buffer(name): a needsBuffers output as a texture node
|
|
148
|
-
* ('normal' | 'diffuse' | 'velocity' | 'metalRough', the last as .x metalness, .y roughness: it may share velocity's target, so read it here, not from scenePass); tsl: three/tsl; display: three's display nodes (bloom, ao from three/addons/tsl/display) plus
|
|
148
|
+
* ('normal' | 'diffuse' | 'velocity' | 'metalRough', the last as .x metalness, .y roughness: it may share velocity's target, so read it here, not from scenePass); tsl: three/tsl; display: three's display nodes (bloom, ao, denoise from three/addons/tsl/display) plus
|
|
149
149
|
* pass (an extra scene render), texture (the color so far as a texture to sample at other uvs) and own (a node the effect made itself, disposed with the chain),
|
|
150
150
|
* handed in so the main entry of an effect package never imports three/webgpu (its /tsl subpath may, a WebGL game never loads that) and so the nodes they make are disposed with the chain;
|
|
151
151
|
* fx: the threedog/tsl functions (noise, hash ...), handed in for the same reason;
|
|
@@ -44,11 +44,12 @@ export function worldToScreen(engine: Engine, pos: PositionLike): ScreenPoint;
|
|
|
44
44
|
* fadeScreen(engine, 1, 0.5) throws in dev: fadeScreen(engine, 1, { seconds: 0.5 })
|
|
45
45
|
* @param {Engine} engine
|
|
46
46
|
* @param {number} to 0 clear ... 1 fully covered
|
|
47
|
-
* @param {{ seconds?: number }} [opts]
|
|
47
|
+
* @param {{ seconds?: number, owner?: string }} [opts] owner: who holds this cover (default 'game'); a transition or a cutscene does not clear a cover another owner holds
|
|
48
48
|
* @returns {Promise<void>}
|
|
49
49
|
*/
|
|
50
50
|
export function fadeScreen(engine: Engine, to: number, opts?: {
|
|
51
51
|
seconds?: number;
|
|
52
|
+
owner?: string;
|
|
52
53
|
}): Promise<void>;
|
|
53
54
|
export function iconHTML(def: any): string;
|
|
54
55
|
import type { Engine } from '../../core';
|
package/types/physics.d.ts
CHANGED
|
@@ -264,7 +264,7 @@ export interface RigidBodies {
|
|
|
264
264
|
* Record<string, RagdollPart> for any other body, a function (facts: { character, root, mesh }, engine) => one of those, or false for no ragdoll (returns null). @experimental
|
|
265
265
|
*/
|
|
266
266
|
ragdoll(who: any, opts?: RagdollOptions): Ragdoll | null;
|
|
267
|
-
/** Give it a push: impulse vector impulse (Vector3 / [x, y, z] / { x, y, z }), e.g. impulse(ball, [0, 3, 5]) */
|
|
267
|
+
/** Give it a push: impulse vector impulse (Vector3 / [x, y, z] / { x, y, z }), e.g. impulse(ball, [0, 3, 5]). Wakes a sleeping body first (an explosion: recipe 11 §3c) */
|
|
268
268
|
impulse(entry: RigidEntry, impulse: Vec3Like): void;
|
|
269
269
|
/** Teleport to position (velocity is zeroed) */
|
|
270
270
|
setPosition(entry: RigidEntry, position: PositionLike): void;
|
package/types/world.d.ts
CHANGED
|
@@ -535,8 +535,10 @@ export interface SkyPictureOptions {
|
|
|
535
535
|
sunGlow?: number;
|
|
536
536
|
/** Sun brightness, default 6 @experimental */
|
|
537
537
|
sunBrightness?: number;
|
|
538
|
-
/** @experimental */
|
|
539
|
-
|
|
538
|
+
/** Color of the moon disk drawn at night, default 0xdcdcdc @experimental */
|
|
539
|
+
moonColor?: ColorLike;
|
|
540
|
+
/** Brightness of the moon disk drawn at night, default 3 @experimental */
|
|
541
|
+
moonBrightness?: number;
|
|
540
542
|
/** Share of the sky grid cells (0-1) that hold a star at night, default 0.0025 (0 = no stars). A probability, not a brightness: near 1 every cell is lit and the upper sky turns into a white sheet. */
|
|
541
543
|
starDensity?: number;
|
|
542
544
|
/**
|
package/ui/UI.js
CHANGED
|
@@ -11,7 +11,7 @@ import { injectUICSS } from './theme.js';
|
|
|
11
11
|
import { codedError } from '../core/base/errorHints.js';
|
|
12
12
|
import { uiAfter } from '../core/time/uiClock.js';
|
|
13
13
|
import { readParams, keysSchema } from '../core/base/params.js';
|
|
14
|
-
const FADE_SCREEN_KEYS = ['seconds'];
|
|
14
|
+
const FADE_SCREEN_KEYS = ['seconds', 'owner'];
|
|
15
15
|
/** @import { Engine } from '../types/core' */
|
|
16
16
|
/** @import { PositionLike, Object3D } from '../types/common' */
|
|
17
17
|
/** @import { UIWindow, WindowOptions, ScreenPoint } from '../types/gameplay' */
|
|
@@ -142,36 +142,40 @@ export function placeAt(el, x, y) {
|
|
|
142
142
|
if (el.style.top !== top) el.style.top = top;
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
const fades = new WeakMap(); // engine → { el, value, from, to, t, d, done }
|
|
146
|
-
// color --threedog-fade-bg. Follows engine frames (step() advances it too; stops while the loop is halted). A new fade
|
|
145
|
+
const fades = new WeakMap(); // engine → { el, by: Map<owner, { owner, value, from, to, t, d, done }> }
|
|
146
|
+
// color --threedog-fade-bg. Follows engine frames (step() advances it too; stops while the loop is halted). Each owner has its own cover; the screen shows the darkest. A new fade by the same owner interrupts its own old one (that Promise resolves at once).
|
|
147
147
|
// Scene transitions use engine.flow.transition and cutscenes use the timeline's { fade: seconds, to } step; both go through here.
|
|
148
148
|
/**
|
|
149
149
|
* Fade the whole screen to `to` (0 clear ... 1 fully covered) over `seconds` (default 0.5); the Promise resolves when the fade ends.
|
|
150
150
|
* fadeScreen(engine, 1, 0.5) throws in dev: fadeScreen(engine, 1, { seconds: 0.5 })
|
|
151
151
|
* @param {Engine} engine
|
|
152
152
|
* @param {number} to 0 clear ... 1 fully covered
|
|
153
|
-
* @param {{ seconds?: number }} [opts]
|
|
153
|
+
* @param {{ seconds?: number, owner?: string }} [opts] owner: who holds this cover (default 'game'); a transition or a cutscene does not clear a cover another owner holds
|
|
154
154
|
* @returns {Promise<void>}
|
|
155
155
|
*/
|
|
156
156
|
export function fadeScreen(engine, to, opts) {
|
|
157
|
-
const { seconds = 0.5 } = readParams('fadeScreen()', keysSchema(FADE_SCREEN_KEYS), opts);
|
|
157
|
+
const { seconds = 0.5, owner = 'game' } = readParams('fadeScreen()', keysSchema(FADE_SCREEN_KEYS), opts);
|
|
158
158
|
injectUICSS();
|
|
159
|
-
let
|
|
160
|
-
if (!
|
|
159
|
+
let s = fades.get(engine);
|
|
160
|
+
if (!s) {
|
|
161
161
|
const el = document.createElement('div'); el.className = 'threedog-fade'; engine.uiRoot.appendChild(el);
|
|
162
|
-
|
|
163
|
-
fades.set(engine,
|
|
164
|
-
engine.onFrame(dt => { if (f.done) { f.t += dt; set(f, f.t >= f.d ? 1 : f.t / f.d); } });
|
|
162
|
+
s = { el, by: new Map() };
|
|
163
|
+
fades.set(engine, s);
|
|
164
|
+
engine.onFrame(dt => { for (const f of [...s.by.values()]) if (f.done) { f.t += dt; set(s, f, f.t >= f.d ? 1 : f.t / f.d); } });
|
|
165
165
|
}
|
|
166
|
+
let f = s.by.get(owner);
|
|
167
|
+
if (!f) s.by.set(owner, f = { owner, value: 0, from: 0, to: 0, t: 0, d: 0, done: null });
|
|
166
168
|
f.done?.();
|
|
167
169
|
Object.assign(f, { from: f.value, to, t: 0, d: seconds, done: null });
|
|
168
170
|
const p = new Promise(res => { f.done = () => { f.done = null; res(); }; });
|
|
169
|
-
if (seconds <= 0) set(f, 1);
|
|
171
|
+
if (seconds <= 0) set(s, f, 1);
|
|
170
172
|
return p;
|
|
171
173
|
}
|
|
172
|
-
function set(f, k) {
|
|
174
|
+
function set(s, f, k) {
|
|
173
175
|
f.value = f.from + (f.to - f.from) * k;
|
|
174
|
-
f.
|
|
175
|
-
|
|
176
|
+
if (k >= 1 && f.value <= 0) s.by.delete(f.owner); // a cleared owner holds nothing
|
|
177
|
+
const top = Math.max(0, ...[...s.by.values()].map(x => x.value));
|
|
178
|
+
s.el.style.setProperty('--threedog-fade', top);
|
|
179
|
+
s.el.classList.toggle('is-on', top > 0.01);
|
|
176
180
|
if (k >= 1) f.done?.();
|
|
177
181
|
}
|
package/ui/cursor.js
CHANGED
|
@@ -12,13 +12,13 @@ const DIRS = { uiUp: [0, -1], uiDown: [0, 1], uiLeft: [-1, 0], uiRight: [1, 0] }
|
|
|
12
12
|
const STICK = 0.5, REPEAT_FIRST = 0.4, REPEAT = 0.15; // stick: half tilt counts, held it repeats like a key (first after 0.4 s, then every 0.15 s)
|
|
13
13
|
|
|
14
14
|
/** Visible controls inside root, in DOM order (hidden ones have no client rects) @internal */
|
|
15
|
-
|
|
15
|
+
function navItems(root) {
|
|
16
16
|
if (!root || root.hidden) return [];
|
|
17
17
|
return [...root.querySelectorAll(SEL)].filter(el => el.getClientRects().length > 0);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/** The direction pressed this frame ([dx, dy], screen y down) from the menu keys or the stick (edge + repeat), or null @internal */
|
|
21
|
-
|
|
21
|
+
function readDir(input, st, dt) {
|
|
22
22
|
for (const [a, d] of Object.entries(DIRS)) if (input.actions.has(a) && input.pressedRaw(a)) return d;
|
|
23
23
|
const s = input.padStick, x = Math.abs(s.x) >= STICK ? Math.sign(s.x) : 0, y = Math.abs(s.y) >= STICK ? -Math.sign(s.y) : 0; // padStick.y is up-positive
|
|
24
24
|
const d = Math.abs(s.x) > Math.abs(s.y) ? (x ? [x, 0] : null) : (y ? [0, y] : null);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":1,"files":{"content/actions.js":{"kind":"actions","mtime":1794404132033.9805,"size":481,"from":0,"count":4,"indexIds":0,"positional":[]},"content/audio.js":{"kind":"audio","mtime":1794404132035.9958,"size":430,"from":0,"count":1,"indexIds":0,"positional":[]},"content/items.js":{"kind":"items","mtime":1794404132040.0073,"size":204,"from":0,"count":1,"indexIds":0,"positional":[]},"content/places.js":{"kind":"places","mtime":1794404132042.007,"size":209,"from":0,"count":1,"indexIds":0,"positional":[]},"content/props.js":{"kind":"props","mtime":1794404132043.01,"size":707,"from":0,"count":8,"indexIds":0,"positional":[]},"content/templates.js":{"kind":"templates","mtime":1794404132046.5588,"size":835,"from":0,"count":4,"indexIds":0,"positional":[]},"content/views.js":{"kind":"views","mtime":1794404132049.1821,"size":539,"from":0,"count":2,"indexIds":0,"positional":[]}},"ids":{"attack":[{"file":"content/actions.js","kind":"actions","line":4,"placed":false}],"retry":[{"file":"content/actions.js","kind":"actions","line":5,"placed":false}],"save":[{"file":"content/actions.js","kind":"actions","line":6,"placed":false}],"load":[{"file":"content/actions.js","kind":"actions","line":7,"placed":false}],"sounds":[{"file":"content/audio.js","kind":"audio","line":4,"placed":false}],"gem":[{"file":"content/items.js","kind":"items","line":3,"placed":false}],"room":[{"file":"content/places.js","kind":"places","line":3,"placed":false}],"floor":[{"file":"content/props.js","kind":"props","line":3,"placed":true},{"file":"content/templates.js","kind":"templates","line":4,"placed":false}],"wall-n":[{"file":"content/props.js","kind":"props","line":4,"placed":true}],"wall-s":[{"file":"content/props.js","kind":"props","line":5,"placed":true}],"wall-w":[{"file":"content/props.js","kind":"props","line":6,"placed":true}],"wall-e":[{"file":"content/props.js","kind":"props","line":7,"placed":true}],"pillar-1":[{"file":"content/props.js","kind":"props","line":8,"placed":true}],"pillar-2":[{"file":"content/props.js","kind":"props","line":9,"placed":true}],"slime-1":[{"file":"content/props.js","kind":"props","line":10,"placed":true}],"wall":[{"file":"content/templates.js","kind":"templates","line":5,"placed":false}],"pillar":[{"file":"content/templates.js","kind":"templates","line":6,"placed":false}],"slime":[{"file":"content/templates.js","kind":"templates","line":9,"placed":false}],"corner":[{"file":"content/views.js","kind":"views","line":4,"placed":false}],"door":[{"file":"content/views.js","kind":"views","line":5,"placed":false}]}}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":1,"files":{"content/props.js":{"kind":"props","mtime":1794404132069.7053,"size":1370,"from":0,"count":15,"indexIds":0,"positional":[]},"content/templates.js":{"kind":"templates","mtime":1794404132071.7058,"size":232,"from":0,"count":2,"indexIds":0,"positional":[]},"content/vegetation.js":{"kind":"vegetation","mtime":1794404132073.7058,"size":522,"from":0,"count":1,"indexIds":0,"positional":[]}},"ids":{"tree-1":[{"file":"content/props.js","kind":"props","line":4,"placed":true}],"tree-2":[{"file":"content/props.js","kind":"props","line":5,"placed":true}],"tree-3":[{"file":"content/props.js","kind":"props","line":6,"placed":true}],"tree-4":[{"file":"content/props.js","kind":"props","line":7,"placed":true}],"tree-5":[{"file":"content/props.js","kind":"props","line":8,"placed":true}],"tree-6":[{"file":"content/props.js","kind":"props","line":9,"placed":true}],"tree-7":[{"file":"content/props.js","kind":"props","line":10,"placed":true}],"sheep-1":[{"file":"content/props.js","kind":"props","line":11,"placed":true}],"sheep-2":[{"file":"content/props.js","kind":"props","line":12,"placed":true}],"sheep-3":[{"file":"content/props.js","kind":"props","line":13,"placed":true}],"sheep-4":[{"file":"content/props.js","kind":"props","line":14,"placed":true}],"sheep-5":[{"file":"content/props.js","kind":"props","line":15,"placed":true}],"sheep-6":[{"file":"content/props.js","kind":"props","line":16,"placed":true}],"sheep-7":[{"file":"content/props.js","kind":"props","line":17,"placed":true}],"sheep-8":[{"file":"content/props.js","kind":"props","line":18,"placed":true}],"tree":[{"file":"content/templates.js","kind":"templates","line":3,"placed":false}],"sheep":[{"file":"content/templates.js","kind":"templates","line":4,"placed":false}],"wheat":[{"file":"content/vegetation.js","kind":"vegetation","line":6,"placed":false}]}}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":1,"files":{},"ids":{}}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":1,"files":{},"ids":{}}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":1,"files":{"content/items.js":{"kind":"items","mtime":1794404132140.8713,"size":471,"from":0,"count":3,"indexIds":0,"positional":[]},"content/npcs.js":{"kind":"npcs","mtime":1794404132141.8728,"size":352,"from":0,"count":1,"indexIds":0,"positional":[]},"content/places.js":{"kind":"places","mtime":1794404132144.3772,"size":345,"from":0,"count":2,"indexIds":0,"positional":[]},"content/props.js":{"kind":"props","mtime":1794404132145.3877,"size":1208,"from":0,"count":12,"indexIds":0,"positional":[]},"content/templates.js":{"kind":"templates","mtime":1794404132148.3994,"size":394,"from":0,"count":6,"indexIds":0,"positional":[]},"content/vegetation.js":{"kind":"vegetation","mtime":1794404132150.5015,"size":1840,"from":0,"count":5,"indexIds":0,"positional":[]}},"ids":{"apple":[{"file":"content/items.js","kind":"items","line":3,"placed":false}],"key":[{"file":"content/items.js","kind":"items","line":4,"placed":false}],"wood":[{"file":"content/items.js","kind":"items","line":5,"placed":false},{"file":"content/props.js","kind":"props","line":10,"placed":true}],"guide":[{"file":"content/npcs.js","kind":"npcs","line":3,"placed":false}],"stage":[{"file":"content/places.js","kind":"places","line":3,"placed":false}],"water":[{"file":"content/places.js","kind":"places","line":4,"placed":false}],"pine":[{"file":"content/props.js","kind":"props","line":4,"placed":true}],"round-tree":[{"file":"content/props.js","kind":"props","line":5,"placed":true}],"rock":[{"file":"content/props.js","kind":"props","line":6,"placed":true}],"flower-a":[{"file":"content/props.js","kind":"props","line":7,"placed":true}],"flower-b":[{"file":"content/props.js","kind":"props","line":8,"placed":true}],"flower-c":[{"file":"content/props.js","kind":"props","line":9,"placed":true}],"stone":[{"file":"content/props.js","kind":"props","line":11,"placed":true}],"metal":[{"file":"content/props.js","kind":"props","line":12,"placed":true}],"glass":[{"file":"content/props.js","kind":"props","line":13,"placed":true}],"shadow-stage":[{"file":"content/props.js","kind":"props","line":14,"placed":true}],"room":[{"file":"content/props.js","kind":"props","line":15,"placed":true},{"file":"content/templates.js","kind":"templates","line":8,"placed":false}],"woodBlock":[{"file":"content/templates.js","kind":"templates","line":3,"placed":false}],"stoneBlock":[{"file":"content/templates.js","kind":"templates","line":4,"placed":false}],"metalBall":[{"file":"content/templates.js","kind":"templates","line":5,"placed":false}],"glassPanes":[{"file":"content/templates.js","kind":"templates","line":6,"placed":false}],"shadowStage":[{"file":"content/templates.js","kind":"templates","line":7,"placed":false}],"松树":[{"file":"content/vegetation.js","kind":"vegetation","line":4,"placed":false}],"圆树":[{"file":"content/vegetation.js","kind":"vegetation","line":10,"placed":false}],"石头":[{"file":"content/vegetation.js","kind":"vegetation","line":16,"placed":false}],"草":[{"file":"content/vegetation.js","kind":"vegetation","line":20,"placed":false}],"野花":[{"file":"content/vegetation.js","kind":"vegetation","line":25,"placed":false}]}}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":1,"files":{},"ids":{}}
|