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/core/scene/adaptive.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// Frames that compiled shaders (ApplyCost.rendered reports them) and the first GRACE seconds after ready are not judged: startup hitches are
|
|
8
8
|
// one-off costs that lowering cannot fix, and a step that rebuilds the post chain must not judge its own compile.
|
|
9
9
|
//
|
|
10
|
-
// The ladder (engine.adaptive.steps; docs/plans/2026-11-09-quality-ladder.md): the game says what may be lowered and in which order. Default, cheapest
|
|
10
|
+
// The ladder (engine.adaptive.steps; docs/plans/done/2026-11-09-quality-ladder.md): the game says what may be lowered and in which order. Default, cheapest
|
|
11
11
|
// to see first (Unity's Adaptive Performance lowers low-visual-impact scalers first): each post effect's own `cheaper` params (live uniforms: no
|
|
12
12
|
// recompile), then the resolution, then the effects that declare skipOnLowTier held off (a chain rebuild and a compile: last, and never back and forth,
|
|
13
13
|
// see FLAP). No list of expensive effects lives here: an effect declares cheaper / skipOnLowTier itself, the engine follows. Only downward: nothing is
|
|
@@ -58,7 +58,8 @@ function checkSteps(v) {
|
|
|
58
58
|
const keyOf = s => (typeof s === 'string' ? s : `game.${s.name}`);
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
|
-
* The engine.adaptive state object: the public fields (on, target, min, max, base, lowered, from, steps;
|
|
61
|
+
* The engine.adaptive state object: the public fields (on, target, min, max, base, lowered, from, steps; max follows the shared value render.pixelRatio and base mirrors its base,
|
|
62
|
+
* the device default the settings presets take shares of) plus the
|
|
62
63
|
* controller's own counters. on is an accessor because every reader (the loop's GPU timer, describe, settings) must see false under pixelSize; what was asked for stays and returns with setPixelSize(null).
|
|
63
64
|
* held: what the ladder lowers now besides the resolution, key -> { text, undo }; the resolution needs no entry (renderer ratio against max says it).
|
|
64
65
|
* @param {{ on: boolean, target: number, max: number, held: () => boolean }} o held: pixelSize decides the ratio now
|
|
@@ -222,5 +223,7 @@ export class GpuTimer {
|
|
|
222
223
|
this.free.push(q);
|
|
223
224
|
}
|
|
224
225
|
}
|
|
226
|
+
/** A restored context: the queries were the lost one's (never answer, so timing stopped) and ms was measured under the pressure that lost it */
|
|
227
|
+
reset() { this.pending = []; this.free = []; this.active = null; this.ms = null; this.ext = this.gl?.getExtension?.('EXT_disjoint_timer_query_webgl2') ?? null; }
|
|
225
228
|
dispose() { if (!this.ext || this.gl.isContextLost()) return; for (const q of [...this.pending, ...this.free]) this.gl.deleteQuery(q); this.pending = []; this.free = []; }
|
|
226
229
|
}
|
package/core/scene/pixelRatio.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
// The renderer's pixel ratio has one owner, this file: every engine write goes through it,
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// borrowed ratio.
|
|
1
|
+
// The renderer's pixel ratio has one owner, this file: every engine write goes through it, so no two entries fight by "who wrote last". Two modes:
|
|
2
|
+
// ratio (the default) the shared value render.pixelRatio is the ceiling: base the tier's default, the game's engine.setPixelRatio, the player's settings
|
|
3
|
+
// choice capping it (so their order never matters). Adaptive resolution writes under it, a photo borrows a ratio; writeRatio is the one write.
|
|
5
4
|
// pixelSize (createEngine({ pixelSize }), engine.setPixelSize) one art pixel is k real screen pixels: the ratio is devicePixelRatio / k and fitPixelSize
|
|
6
5
|
// alone sets the drawing buffer. Everything else asking for a ratio is held off, refused or kept for later: adaptive stops (engine.adaptive.on
|
|
7
|
-
// reads false), the
|
|
6
|
+
// reads false), the ceiling only updates what comes back when pixelSize ends, a photo keeps the art pixels, engine.setPixelRatio throws.
|
|
8
7
|
// A direct renderer.setPixelRatio by the game is not refused (hard rule 4): the engine yields in both modes (view.pixelRatio in core/ops/owned.js).
|
|
9
8
|
// tests/specs/pixel-size.mjs guards that no other file calls renderer.setPixelRatio.
|
|
10
9
|
import { DEV, warnOnce } from '../base/validate.js';
|
|
@@ -31,26 +30,49 @@ export function writeRatio(e, p) {
|
|
|
31
30
|
e._oPixelRatio.mark();
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
/** The ceiling at its top again: adaptive resolution starts over from it (the ceiling moved, or the player turned adaptive off) @param {any} e */
|
|
34
|
+
export function topRatio(e) {
|
|
35
|
+
if (e._pixelSize != null) return;
|
|
36
|
+
writeRatio(e, e.adaptive.max);
|
|
37
|
+
Object.assign(e.adaptive, { lowered: false, from: null, good: 0 });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** render.pixelRatio, made with engine.adaptive: its max follows the value (under pixelSize only that, for when pixelSize ends) @param {any} e */
|
|
41
|
+
export function defineRatio(e) {
|
|
42
|
+
const point = e.stacks.define('render.pixelRatio', { base: e.renderer.getPixelRatio(), save: false,
|
|
43
|
+
manual: "the settings entry is the player's ceiling: the game's ratio stays under it while the player keeps that choice" });
|
|
44
|
+
point.watch(() => { e.adaptive.max = point.value(); topRatio(e); });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** engine.setPixelRatio, a game-layer set: written even when the game took the ratio (the named entry stays where the raw three.js call is) @param {any} e @param {number} p */
|
|
39
48
|
export function askRatio(e, p) {
|
|
40
49
|
if (e._pixelSize != null) throw codedError('pixel-conflict', `engine.setPixelRatio(${p}): pixelSize ${e._pixelSize} decides the ratio now. Keep pixelSize and drop this call, or call engine.setPixelSize(null) first`);
|
|
41
|
-
|
|
42
|
-
|
|
50
|
+
e.stacks.get('render.pixelRatio').take({ owner: 'game', set: p });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The player's settings choice; null hands the ratio back to the game (settings.reset). It stands in for the device default (engine layer: the player may
|
|
55
|
+
* pick above it). Under the default it is also a ceiling on the game (settings layer, which only restricts); at or above it (a 'high' preset is a share of 1)
|
|
56
|
+
* it limits nothing, so a full-quality choice never pulls the game's higher ratio down. Two entries, so their order does not change the result.
|
|
57
|
+
* @param {any} e @param {number | null} p
|
|
58
|
+
*/
|
|
59
|
+
export function chooseRatio(e, p) {
|
|
60
|
+
const point = e.stacks.get('render.pixelRatio');
|
|
61
|
+
if (p == null || p >= e.adaptive.base) point.release('settings');
|
|
62
|
+
else point.take({ owner: 'settings', layer: 'settings', clamp: { max: p } });
|
|
63
|
+
if (p == null) point.release('settings.default');
|
|
64
|
+
else point.take({ owner: 'settings.default', layer: 'engine', set: p });
|
|
43
65
|
}
|
|
44
66
|
|
|
45
67
|
/**
|
|
46
|
-
* The
|
|
47
|
-
*
|
|
48
|
-
* @param {any} e @param {string} tier
|
|
68
|
+
* The device became known in start(): its default is the new base (the entries stay on top), unless the game chose one at creation or owns the renderer.
|
|
69
|
+
* engine.adaptive.base is only a mirror of that base, kept for readers (the settings presets' shares). @param {any} e @param {string} tier
|
|
49
70
|
*/
|
|
50
71
|
export function tierRatio(e, tier) {
|
|
51
72
|
if (!e._ownsRenderer || e._createParams.pixelRatio != null) return;
|
|
52
|
-
const p =
|
|
53
|
-
|
|
73
|
+
const p = defaultPixelRatio(dpr(), tier);
|
|
74
|
+
e.stacks.get('render.pixelRatio').setBase(p);
|
|
75
|
+
e.adaptive.base = p;
|
|
54
76
|
}
|
|
55
77
|
|
|
56
78
|
/**
|
|
@@ -111,7 +111,7 @@ export const sceneMethods = {
|
|
|
111
111
|
drawOnce(this.renderer, this.scene, camera, target);
|
|
112
112
|
} finally { if (own) own.inside--; }
|
|
113
113
|
},
|
|
114
|
-
/** Render resolution, and the top adaptive resolution climbs back to. Throws while pixelSize is on (core/scene/pixelRatio.js) @param {number} p */
|
|
114
|
+
/** 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 (core/scene/pixelRatio.js) @param {number} p */
|
|
115
115
|
setPixelRatio(p) { askRatio(this, p); },
|
|
116
116
|
/**
|
|
117
117
|
* One art pixel becomes k real screen pixels, every one the same width at any display scale, and it stays so through a page zoom or a move to another display.
|
package/core/scene/things.js
CHANGED
|
@@ -86,15 +86,16 @@ export class Things {
|
|
|
86
86
|
this.byId = new Map(); // id -> WeakRef(root)
|
|
87
87
|
this.n = 0; // session ids obj#n
|
|
88
88
|
this.stacks = 0;
|
|
89
|
-
this.setup = false; // true inside session:start listeners: what they add is rebuilt by code every playthrough
|
|
89
|
+
this.setup = false; // true inside sessionStart hooks and session:start listeners: what they add is rebuilt by code every playthrough
|
|
90
90
|
this.over = new Map(); // stable id -> { orig, cur }: thing.set overrides (orig = the code-built transform, for load / newGame / undo)
|
|
91
91
|
this.removed = new Set(); // stable ids removed with thing.remove (saved)
|
|
92
92
|
this.gone = new Map(); // id -> { obj, parent }: removed with thing.remove, detached and held so undo or a load can put it back
|
|
93
93
|
this.pending = { set: {}, removed: new Set() }; // from a loaded save, objects not registered yet (orphans if they never come)
|
|
94
94
|
this.unsaved = new Set(); // WeakRefs of session-tier objects someone expected to keep (save: true, or made inside an op)
|
|
95
95
|
this.conflicts = []; // dev: "two systems manage one object" findings, newest last
|
|
96
|
-
e.events.on('session:start', () => { this.setup = true; queueMicrotask(() => { this.setup = false; }); });
|
|
97
96
|
}
|
|
97
|
+
/** @internal step 4 of the session reset (session.js), before the modules' sessionStart hooks and the 'session:start' listeners: what they add is setup */
|
|
98
|
+
setupTurn() { this.setup = true; queueMicrotask(() => { this.setup = false; }); }
|
|
98
99
|
/**
|
|
99
100
|
* A store of records that share the id space with engine.add objects (the world module registers itself at install). The shape core uses:
|
|
100
101
|
* { has(id), get(id) -> { position, ... }, ids(), idOf(obj) -> id | null (model -> record), view(id) -> Object3D | null,
|
package/core/scene/tier.js
CHANGED
|
@@ -11,21 +11,6 @@ export function forcedTier(search = typeof location === 'undefined' ? '' : locat
|
|
|
11
11
|
return TIERS.includes(t) ? t : null;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
/** @type {WeakMap<any, Set<() => void>>} per engine: the parts that rebuild when engine.tier changes */
|
|
15
|
-
const FOLLOWERS = new WeakMap();
|
|
16
|
-
/**
|
|
17
|
-
* Follow engine.tier while running: fn runs once after every change (a preset, the device found at start). Why one notice: the post chain followed
|
|
18
|
-
* the tier and the cascades read it only when made, so a preset changed one and not the other (GPT review l2-render 2). Pixel ratio does not follow
|
|
19
|
-
* here: a settings preset writes its own ratio, and a second writer would undo the player's. @param {any} e @param {() => void} fn @returns {{ remove(): void }}
|
|
20
|
-
*/
|
|
21
|
-
export function onTierChange(e, fn) {
|
|
22
|
-
if (!FOLLOWERS.has(e)) FOLLOWERS.set(e, new Set());
|
|
23
|
-
FOLLOWERS.get(e).add(fn);
|
|
24
|
-
return { remove: () => { FOLLOWERS.get(e)?.delete(fn); } };
|
|
25
|
-
}
|
|
26
|
-
/** The tier stack's onChange (core/engine/services.js) @param {any} e */
|
|
27
|
-
export function tierChanged(e) { for (const fn of [...(FOLLOWERS.get(e) ?? [])]) fn(); }
|
|
28
|
-
|
|
29
14
|
/** The name under engine.saves.storageKey of a player's MSAA choice */
|
|
30
15
|
export const MSAA_KEY = 'msaa';
|
|
31
16
|
/**
|
|
@@ -38,7 +23,8 @@ export function storedMsaa(saveKey) {
|
|
|
38
23
|
|
|
39
24
|
/**
|
|
40
25
|
* Default render scale. High tier: the display scale up to 1.5. Low tier: at least 0.75 x display scale (1.5 on a 2x screen; a fixed 1 there
|
|
41
|
-
* would be an upscaled blurry picture), never above 1.5 or the display scale.
|
|
26
|
+
* would be an upscaled blurry picture), never above 1.5 or the display scale. It is the base of render.pixelRatio (core/scene/pixelRatio.js), set from the
|
|
27
|
+
* device, not from tier changes while running: a preset's ratio is already a share of it.
|
|
42
28
|
* @param {number} dpr @param {string} tier
|
|
43
29
|
*/
|
|
44
30
|
export function defaultPixelRatio(dpr, tier) {
|
package/core/scene/view.js
CHANGED
|
@@ -121,6 +121,20 @@ export function setProjection(e, projection = 'perspective', size = 20) {
|
|
|
121
121
|
swapCamera(e, e._ortho.camera);
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
/**
|
|
125
|
+
* engine.renderer.toneMapping as one owned value.
|
|
126
|
+
* @param {any} e
|
|
127
|
+
* @param {{ owned: boolean }} o owned: false when the game passed its own renderer
|
|
128
|
+
*/
|
|
129
|
+
export function defineTone(e, { owned }) {
|
|
130
|
+
// who writes tone mapping now is one owned record like every other picture value (core/ops/owned.js),
|
|
131
|
+
// not a comparison against a remembered creation value here: a direct renderer.toneMapping write yields it ('three (engine yielded)'), quietly (once),
|
|
132
|
+
// because that write is the documented way to change the curve. A game-supplied renderer (owned false) starts manual: the engine never wrote it
|
|
133
|
+
e._oTone = defineOwned(e, { id: 'toneMapping', part: 'tone', key: 'toneMapping', read: () => e.renderer.toneMapping, objects: [e.renderer], once: true,
|
|
134
|
+
write: v => { e.renderer.toneMapping = v; }, levels: { manual: 'engine.renderer.toneMapping = THREE.AgXToneMapping' } });
|
|
135
|
+
if (owned) e._oTone.mark(); else e._oTone.manual(true, 'game renderer');
|
|
136
|
+
}
|
|
137
|
+
|
|
124
138
|
/** @param {any} e */
|
|
125
139
|
export function defineView(e) {
|
|
126
140
|
const cam = () => e.camera;
|
package/core/time/skip.js
CHANGED
|
@@ -115,7 +115,7 @@ export const skipMethods = {
|
|
|
115
115
|
const end = () => { this._skipping = false; ctx.remove(); fz.remove(); off.remove(); };
|
|
116
116
|
if (!(fade > 0)) { try { go(); } finally { end(); } return Promise.resolve(out); }
|
|
117
117
|
const run = this.flow ? this.flow.transition(go, { fade, autosave: false, music: false })
|
|
118
|
-
: (async () => { try { await fadeScreen(this, 1, { seconds: fade }); go(); } finally { await fadeScreen(this, 0, { seconds: fade }); } })();
|
|
118
|
+
: (async () => { try { await fadeScreen(this, 1, { seconds: fade, owner: 'skip' }); go(); } finally { await fadeScreen(this, 0, { seconds: fade, owner: 'skip' }); } })();
|
|
119
119
|
return run.finally(end).then(() => out);
|
|
120
120
|
},
|
|
121
121
|
};
|
package/docs/AI.md
CHANGED
|
@@ -77,7 +77,7 @@ A row or `threedog how` -> recipe -> `api/<module>.md`. Also: `CONVENTIONS.md`,
|
|
|
77
77
|
| Pixel art | `pixelSize`, `pixelSnap` | 62-picture-code.md §4b |
|
|
78
78
|
| Skeletal animation, IK | `engine.assets.animate`, `anim.addAim`, `.addFeet`, `engine.hlod` | 13-animation.md §3, 15-perf.md |
|
|
79
79
|
| Pathfinding, navmesh, NPC jumps and gaps, gates | `engine.characters.findPath`, `engine.nav` | 12-navmesh.md §2 |
|
|
80
|
-
| Physics, ragdoll, collision, vehicles | `engine.collision`, `engine.rigid`, `engine.collider3d` | 11-
|
|
80
|
+
| Physics, ragdoll, collision, vehicles | `engine.collision`, `engine.rigid`, `engine.collider3d` | 11-physics.md §3 |
|
|
81
81
|
| Ray / mouse picking, shooting, lock-on | `engine.rays` | 19-shooting-picking.md §1 |
|
|
82
82
|
| Prompts, trigger zones | `engine.interactions`, `engine.triggers` | 20-content-actions-save.md §3 |
|
|
83
83
|
| Press E on a mesh | `interactions.add(mesh, { once, counter })` | 03-items-pickups.md |
|
|
@@ -119,7 +119,7 @@ A row or `threedog how` -> recipe -> `api/<module>.md`. Also: `CONVENTIONS.md`,
|
|
|
119
119
|
| To do | Use | Recipe |
|
|
120
120
|
|---|---|---|
|
|
121
121
|
| Own ground or plant drawing, keep collision | `engine.terrain.view`, `engine.terrainDraw`, `engine.vegetationDraw` | 28-terrain.md §6 |
|
|
122
|
-
| Worker results, far records' models, raw navmesh or physics, content sections, own mover | `ctx.commits`, `world.present`, `nav.query`, `rigid.world`, module `content`, `characters.kit` | 15-perf.md, 18-world.md, 12-navmesh.md, 11-
|
|
122
|
+
| Worker results, far records' models, raw navmesh or physics, content sections, own mover | `ctx.commits`, `world.present`, `nav.query`, `rigid.world`, module `content`, `characters.kit` | 15-perf.md, 18-world.md, 12-navmesh.md, 11-physics.md, 14-custom-module.md, 57-control.md |
|
|
123
123
|
|
|
124
124
|
### Troubleshooting and speed
|
|
125
125
|
| To do | Use | Recipe |
|
package/docs/CODEMAP.md
CHANGED
|
@@ -66,7 +66,7 @@ Type = what the module may own (core/engine/moduleTypes.js): world, picture, act
|
|
|
66
66
|
- inspect/ Generated by npm run map, do not edit by hand — Budget.js, DebugOverrides.js, Describe.js, Inspect.js, InspectMaterials.js, InspectPerf.js, InspectScene.js, MaterialInfo.js, UrlState.js, catalog.js, checks.js, debugView.js, describeRender.js, describeText.js, geometryWatch.js, lightWatch.js, metadata.generated.js, pictureChecks.js, pictureMenu.js, pictureWriters.js, shaderCost.js, textureBytes.js, toolDoor.js, valueHistory.js
|
|
67
67
|
- ops/ Shared points: the ONE way several owners change a shared t… — Ops.js, actor.js, control.js, holds.js, opsAtomic.js, opsCheck.js, opsFail.js, opsGuard.js, opsHistory.js, opsRun.js, owned.js, sharedPoint.js, stackFrames.js, stacks.js, wrap.js
|
|
68
68
|
- saves/ Saves: each module registers "how to save and load", and sa… — SaveStore.js, Saves.js, saveApply.js, saveFiles.js, saveIds.js, saveVersions.js, session.js, stateReplace.js
|
|
69
|
-
- scene/
|
|
69
|
+
- scene/ Adaptive quality by frame cost: one controller, one ladder … — Rays.js, Views.js, adaptive.js, canvasBox.js, compositeGround.js, drawOnly.js, floor.js, gameLights.js, grayMap.js, grid.js, gridLoad.js, ground.contract.js, ground.js, movement.js, pictureSlots.js, pixel.js, pixelRatio.js, sceneDelta.js, sceneMethods.js, screenToGround.js, stepPoses.js, targeting.js, thingExplain.js, thingOps.js, things.js, threePatches.js, tier.js, view.js
|
|
70
70
|
- stream/ Automatic batching, engine.batching: the same static model … — Batching.js, Stream.js, batchGroups.js, cells.js, chunkStream.js, prepare.js, scatter.js, streamCells.js, streamSources.js
|
|
71
71
|
- threads/ engine.threads: a small worker pool — Commits.js, Jobs.js, Threads.js, pureWorker.js, threadPure.js, threadServe.js
|
|
72
72
|
- time/ engine.time: the one time source — Clock.js, dayTime.js, skip.js, time.js, uiClock.js
|
|
@@ -179,7 +179,7 @@ Type = what the module may own (core/engine/moduleTypes.js): world, picture, act
|
|
|
179
179
|
| engine:ready | core/engine/startup.js | content, flow, rigid |
|
|
180
180
|
| flow:change | flow | — |
|
|
181
181
|
| flow:transition | flow | — |
|
|
182
|
-
| ground:change | terrain | characters, rigid |
|
|
182
|
+
| ground:change | terrain | characters, grid, rigid |
|
|
183
183
|
| i18n:change | core/base/I18n.js | core/input/inputTouch.js, gameplay, hud, settings, timeline, ui/UI.js |
|
|
184
184
|
| input:context | core/input/inputContext.js | — |
|
|
185
185
|
| input:rebind | core/input/Input.js | gameplay, timeline, ui/UI.js |
|
|
@@ -194,7 +194,7 @@ Type = what the module may own (core/engine/moduleTypes.js): world, picture, act
|
|
|
194
194
|
| link:enter | characters | — |
|
|
195
195
|
| link:exit | characters | — |
|
|
196
196
|
| module:disabled | core/base/errors.js | — |
|
|
197
|
-
| module:
|
|
197
|
+
| module:fresh | core/engine/modules.js | content |
|
|
198
198
|
| music:change | music | — |
|
|
199
199
|
| music:stinger | music | — |
|
|
200
200
|
| net:close | net | — |
|
|
@@ -220,20 +220,20 @@ Type = what the module may own (core/engine/moduleTypes.js): world, picture, act
|
|
|
220
220
|
| quest:unpaid | gameplay | — |
|
|
221
221
|
| rigid:rebuilt | rigid | rigid |
|
|
222
222
|
| save:imported | core/saves/saveFiles.js | photo |
|
|
223
|
-
| save:loaded | core/saves/saveApply.js |
|
|
223
|
+
| save:loaded | core/saves/saveApply.js | core/ops/control.js |
|
|
224
224
|
| save:written | core/saves/Saves.js | — |
|
|
225
225
|
| season:change | calendar | calendar |
|
|
226
|
-
| session:end | core/saves/session.js | core/time/skip.js
|
|
226
|
+
| session:end | core/saves/session.js | core/time/skip.js |
|
|
227
227
|
| session:failed | core/saves/saveApply.js, core/saves/session.js | flow, rigid |
|
|
228
|
-
| session:start | core/saves/session.js |
|
|
228
|
+
| session:start | core/saves/session.js | — |
|
|
229
229
|
| settings:change | settings | — |
|
|
230
|
-
| settings:shadows | render/shadows.js | vegetation |
|
|
231
230
|
| state:applied | core/inspect/UrlState.js | — |
|
|
232
231
|
| state:placed | core/inspect/UrlState.js | camera |
|
|
233
232
|
| state:replaced | core/engine/startup.js, core/saves/stateReplace.js | calendar |
|
|
234
233
|
| template:stage | content | — |
|
|
235
234
|
| terrain:chunkFailed | terrain | — |
|
|
236
235
|
| terrain:void | rigid, terrain | — |
|
|
236
|
+
| tier:change | core/engine/services.js | — |
|
|
237
237
|
| time:skip | core/time/skip.js | — |
|
|
238
238
|
| timeline:end | timeline | — |
|
|
239
239
|
| timeline:start | timeline | — |
|
|
@@ -251,7 +251,7 @@ Type = what the module may own (core/engine/moduleTypes.js): world, picture, act
|
|
|
251
251
|
| weather:lightning | weather | weather |
|
|
252
252
|
| world:add | world | gameplay, grid |
|
|
253
253
|
| world:change | world | gameplay, grid |
|
|
254
|
-
| world:load |
|
|
254
|
+
| world:load | core/engine/modules.js | — |
|
|
255
255
|
| world:remove | world | core/ops/control.js, core/ops/stacks.js, characters, gameplay, grid |
|
|
256
256
|
|
|
257
257
|
## Input actions (engine.input)
|
package/docs/COMMANDS.md
CHANGED
|
@@ -35,7 +35,7 @@ export const specs = [{
|
|
|
35
35
|
A spec whose run() reads pixels (`page.screenshot`) moves to software rendering, which is much slower; `software: false` on the spec keeps it on the GPU for a real picture. Frame times measured beside other pages read several times too high: give such a spec `serial: true`, or run with `--jobs 1`. A spec file and what it imports run in Node. Importing `threedog` there works, but a file that touches `document` or `window` at its top level fails: move that code into a function, move plain data into a file of its own, or read the value in the page through `ev`.
|
|
36
36
|
A test that steers: `frames(n)` and `wait(ms)` follow the machine; hold the loop with `engine.haltLoop('my-test')` and advance game time yourself, `await page.keyboard.down('KeyW'); await ev(() => engine.step(0.25));`: the same steps give the same path on any machine.
|
|
37
37
|
- New game: `npm run new-game -- name [--open-world | --pixel] [--webgl]` (the blank and `--open-world` starts: `recipes/01-new-game.md`; `--pixel` starts a sprite character in a pixel-snapped orthographic view with input, interaction, dialogue and saves wired, gray placeholders, not together with `--open-world`; the game runs on WebGPU and writes shaders in TSL, `--webgl` on WebGL with GLSL).
|
|
38
|
-
- Game in your own folder (outside this repo):
|
|
38
|
+
- Game in your own folder (outside this repo): the steps are README.md "Start here"; `threedog init [folder] [--open-world] [--webgl]` (folder: the one to create, default the current folder): it copies the new-game template without overwriting anything, merges package.json and writes `.mcp.json`, so Claude Code opened in that folder starts the threedog MCP server by itself.
|
|
39
39
|
|
|
40
40
|
> Git Bash (MSYS) rewrites arguments that start with `/` into a path under the Git install (`/` turns into `C:/Program Files/Git/`). Page arguments (`shot`, `capture`, `--page`) undo that by themselves, through `npm run` too (npm still echoes `> threedog shot C:/...`; shot then prints the page it really opens); if the Git folder cannot be found the error says so: then write `shot styletest`, set `MSYS_NO_PATHCONV=1`, or use PowerShell.
|
|
41
41
|
|
|
@@ -76,7 +76,7 @@ export const specs = [{
|
|
|
76
76
|
| `npm run bake` | Before release, or to take code-generated models into Blender: exports public/models/baked/*.glb (`-- -w game`) |
|
|
77
77
|
| `npm run assets -- check [glb or folder] [--json] [--strict]` | Inspect models without building (default art/models/; a game with no such folder has nothing to check and passes, and only models are read: sprite and texture PNGs are never looked at): the level manifest (spawns, col_ colliders, trigger_ zones, npcs, markers, template / id nodes, missing templates, duplicate ids), material and color-space suspicions (data texture in a color slot, BLEND, texture without UV, oversized texture), statistics. `--json` for tools, exit 1 on errors (`--strict`: on warnings too). `npm run check` also reads the level glbs for content validation |
|
|
78
78
|
| `threedog assets optimize [-w game] [--dry] [--force] [--budget MB] [--strict] [--lod [--lod-shares 0.5,0.2]]` (`npm run assets -- optimize`) | Game-ready copies of art/models/ into public/optimized/, originals untouched: Meshopt geometry, KTX2 textures by slot (data maps linear UASTC, color maps sRGB ETC1S; each read back and checked). Writes `assets.optimized.js` and imports it in assets.js, so the names point at the results; a rerun handles only changed files. Per file: size before / after, estimated GPU memory and problems (over `--budget` MB, color space, missing UVs). `--dry` reports the estimate only; `--lod` also writes lower-detail levels (recipe 15 §4a). Needs `@gltf-transform/cli`; textures go through `ktx` (KTX-Software 4.3+) when it is on PATH, else the WebAssembly encoder of `ktx2-encoder` that comes with the tools. Baked lightmaps are left as baked. Report: `.threedog/optimize-report.json` |
|
|
79
|
-
| `npm run perf` | Performance comparison (plain three.js vs engine vs per-module cost in openWorld). Prints the renderer first. `threedog perf -w my-game [
|
|
79
|
+
| `npm run perf` | Performance comparison (plain three.js vs engine vs per-module cost in openWorld). Prints the renderer first. `threedog perf -w my-game [--seconds N]`: your game's page in play, standing still: avg FPS, 1% low, spikes, heap start -> end (3 runs of N s, default 4); frame ms, JS ms, draw calls, memory |
|
|
80
80
|
| `threedog stress [-w game] [--only a,b] [--frames 30] [--json]` | At what load this game drops: from a game folder (or `-w`) the load ramps go on top of the game's own scene on its own renderer in system Chrome, one axis at a time (extra meshes, triangles, instances, point lights), after a line with the game alone; then the load that fits 16.7 and 33 ms per axis. A WebGPU game on a browser without real WebGPU is refused. In the engine repo with no game it runs the neutral page `tests/stress/` for the engine's own measurements, and says so |
|
|
81
81
|
| `--gpu` · `--software` · `THREEDOG_RENDER=gpu` or `software` | Renderer of the headless browser. `shot`, the dev bridge's headless page, `gallery --shots`, `perf` and `stress` prefer the hardware GPU (ANGLE d3d11 / metal / vulkan), check the renderer string after launch and fall back to SwiftShader with one note line; tests that read rendered pixels (`software: true` on the spec; unmarked ones are caught at the end of a GPU run) start on SwiftShader (same pixels everywhere), the others on the GPU when it is reachable |
|
|
82
82
|
| `threedog content ids [-w game \| folder] [--write]` | Stateful content entries that rely on their index id: prints the id each has now as `-`/`+` lines (dry run); `--write` writes them in. Recipe 30, "Writing the ids, renaming them" | <!-- r18-ignore-line -->
|
package/docs/CONVENTIONS.md
CHANGED
|
@@ -141,6 +141,7 @@ into, or a convenience for after.
|
|
|
141
141
|
| Load far parts of a big map only when near | `engine.stream` (recipe 33) | |
|
|
142
142
|
| Heavy work in a web worker | `engine.threads` (recipe 15) | bit by bit on the main thread: `engine.jobs` |
|
|
143
143
|
| How many seconds passed in the game | `engine.time.now()` (recipe 06) | |
|
|
144
|
+
| Hit stop, bullet time | `engine.mod('time.world', { owner, set: 0, layer: 'system', for: 0.06 })`; `for` is real seconds (or `clock: '<channel>'`) | not `clock.rate` (the calendar) |
|
|
144
145
|
| Remember a flag or a count, a door was opened | `engine.vars` (recipe 20) | |
|
|
145
146
|
| A named fixed view, a second camera to show | `engine.views` (recipe 46) | |
|
|
146
147
|
| Load a model, texture or sound file | `engine.assets` (recipe 05) | a format it does not read: a three.js loader |
|
package/docs/THREE.md
CHANGED
|
@@ -33,7 +33,7 @@ systems share a value (recipe 55); `engine.autoView.manual(key)` takes a value w
|
|
|
33
33
|
|---|---|---|---|
|
|
34
34
|
| `renderer.toneMapping` | Just set it: `engine.renderer.toneMapping = THREE.ACESFilmicToneMapping` (any three mapping). A curve of your own: a post stage in the `'tone'` slot, `engine.post.add({ name, slot: 'tone', create, node })`, which runs on both renderers (a `ShaderChunk` edit is page-wide and reaches only WebGLRenderer) | Never: three's default (none) stands until you write it | Nothing to take: `describe().render.toneMapping.writer` then says `game` |
|
|
35
35
|
| `renderer.outputColorSpace` | Leave it at `SRGBColorSpace` (three's default) | No | Changing it makes every color wrong; `assets.report` flags it |
|
|
36
|
-
| `renderer.shadowMap` | On at start on a renderer the engine built; the switch is `engine.shadows.enabled`; `type` is yours | `enabled` when the switch changes | `createEngine({ renderer })` and run your own |
|
|
36
|
+
| `renderer.shadowMap` | On at start on a renderer the engine built; the switch is `engine.shadows.enabled`; `type` is yours (three 0.187 has no `PCFSoftShadowMap`: blur the edge with `PCFShadowMap` + `light.shadow.radius`, recipe 45 "Filter, bias, softness") | `enabled` when the switch changes | `createEngine({ renderer })` and run your own |
|
|
37
37
|
| `scene.environment` | None by default. The sky as a map: `engine.sky.environment({ into: engine.scene })` | Only after that call; a map you write stays | Write it; recipe 34 |
|
|
38
38
|
| `scene.background` | Starts neutral gray; assign yours, or `engine.sky.replace(name \| Texture \| Object3D)` with a sky | The sky dome draws over it; a backdrop / skybox writes it every frame | Assign it: the dome hides and the sky stops writing it |
|
|
39
39
|
| Your own sky (three/addons `Sky`, a ShaderMaterial dome, a skybox) | `engine.sky.replace(mySky)`; feed it from `engine.uniforms` (`uSunDir`, `uDaylight`, `uTimeOfDay`, `uWind`, `uWeatherCloud`) | Never: the engine only hides its dome and adds `mySky` to the scene when it has no parent; time, lights, fog and weather keep running | `engine.sky.replace(null)` gives the dome back. Per key instead of whole: write `engine.sky.top` and friends in your frame code |
|
package/docs/api/ambience.md
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Ambience (ambience() module)
|
|
4
4
|
|
|
5
5
|
- Options `AmbienceOptions`:
|
|
6
|
-
- `rules?: import('./core').AmbienceRule[]`
|
|
7
|
-
- `interval?: number`
|
|
6
|
+
- `rules?: import('./core').AmbienceRule[]` Rules added after the ones in createEngine({ audio: { ambience } })
|
|
7
|
+
- `interval?: number` Seconds between rule checks, default 0.25
|
|
8
8
|
|
|
9
9
|
## Methods and properties
|
|
10
10
|
- `ambience.add(rule: AmbienceRule) → { remove(): void }` — Add one rule; returns a handle whose remove() fades the sound out and drops the rule. Example: `const h = engine.ambience.add({ sound: 'storm-wind', when: { weather: 'storm' }, volume: 0.5 });`
|
package/docs/api/cameraRig.md
CHANGED
|
@@ -56,6 +56,13 @@ Current camera (one of followCamera / firstPersonCamera / fixedCamera / rtsCamer
|
|
|
56
56
|
- `trackSmoothing?: number` (experimental) Head-follow smoothing
|
|
57
57
|
- `holdDirection?: boolean` (experimental) Keep the direction when switching shots until the direction key is released
|
|
58
58
|
- `ease?: Ease` Transition easing
|
|
59
|
+
- `position?: Vec3Like` Camera position
|
|
60
|
+
- `lookAt?: Vec3Like` Fixed point to look at (if omitted, it turns its head with the player)
|
|
61
|
+
- `track?: boolean` Turn its head with the player
|
|
62
|
+
- `fov?: number` Field of view (degrees)
|
|
63
|
+
- `at?: Vec3Like` Position used to judge the "nearest shot", defaults to position
|
|
64
|
+
- `projection?: 'perspective' | 'orthographic'` 'orthographic' draws this shot without perspective (isometric / 2.5D); default 'perspective'
|
|
65
|
+
- `size?: number` With projection 'orthographic' (required there): world units of view height; the width follows the aspect
|
|
59
66
|
- rtsCamera options `RtsCameraOptions`:
|
|
60
67
|
- `height?: number` Camera height above the focus (meters), default 30
|
|
61
68
|
- `minHeight?: number` Zoom range (meters)
|
package/docs/api/engine.md
CHANGED
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
- `engine.bakeProbes(opts: { bounds, spacing, resolution?, include?, owner? }) → Promise<ProbeSet>` — (experimental) Bake a grid of light probes from the scene as it is now: three's probe grid renders a cube at every grid point and keeps spherical harmonics, and every lit pixel inside the grid then takes its own interpolated light, on WebGL and WebGPU alike. The grid adds to whatever ambient light the scene has (hemi, environment), which the bake also saw: lower those where the probes take over (a warning and describe().render.probes say so). Outside the grid there is no probe light. A load-time cost, not per frame: 6 renders per probe, a few probes per task so the page keeps drawing; ship the result with `toJSON()` + `engine.loadProbes(json)` instead of baking at every start. Adding a grid recompiles the lit materials once: bake at start-up, not mid-play. Example: `const probes = await engine.bakeProbes({ bounds: { min: [-20, 0, -20], max: [20, 6, 20] }, spacing: 4, include: o => !o.userData.moving }); saveFile('probes.json', JSON.stringify(probes.toJSON()));`
|
|
61
61
|
- `engine.loadProbes(json: ProbeData, opts?: { owner?: string }) → ProbeSet` — (experimental) A probe set from a file made by `handle.toJSON()` (no baking), on either renderer whichever one baked it. A wrong shape is refused with code `probes-data` and nothing is added. Example: `const probes = engine.loadProbes(await (await fetch('probes.json')).json());`
|
|
62
62
|
- `engine.loadLightmap(file: string | ArrayBuffer, opts?: { owner?: string }) → Promise<Lightmap>` — (experimental) Put a baked lightmap on the scene: `threedog bake light` wrote the file from the meshes the game marked `userData.static = true`; this rebuilds each with its second UV set and sets plain `material.lightMap`, on WebGL and WebGPU alike. Call it once the level is built, with its lights as they will be played. Nothing runs per frame. Keep the sun real-time; the ambient light the bake saw (hemisphere, environment) has to go, or it counts twice. A wrong file is refused with code `lightmap-data` and nothing is changed. `material.lightMapIntensity` is yours. describe().render.lightmap says what was skipped, moved or doubled. Example: `const light = await engine.loadLightmap('light/level.lightmap');`
|
|
63
|
-
- `engine.setPixelRatio(p: number)` — Render resolution, and the top adaptive resolution climbs back to. Throws while pixelSize is on
|
|
63
|
+
- `engine.setPixelRatio(p: number)` — 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
|
|
64
64
|
- `engine.setPixelSize(k: number | null)` — One art pixel becomes k real screen pixels (createEngine({ pixelSize }) at runtime). While on, adaptive resolution stops, engine.setPixelRatio throws and a photo keeps the art pixels. null turns it off and brings the ratio from before back. Example: `engine.setPixelSize(3);`
|
|
65
65
|
- `engine.raycast(origin: Vec3Like, dir: Vec3Like, opts?: RaycastOptions) → RayHit | null` — Ray: shoot from origin along dir, returns the nearest hit or null (by default only registered static objects are hit)
|
|
66
66
|
- `engine.pick(ndcX: number, ndcY: number, opts?: RaycastOptions) → RayHit | null` — Shoot a ray through the camera from screen coordinates (-1..1, e.g. input.pointer.ndcX/ndcY). The ray comes from the camera as last drawn: a rig.yaw / rig.pitch write reaches it on the next drawn step, so several shots in one step with recoil between them cast from the rig's angles with engine.raycast (recipe 19)
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
## engine properties (module properties are on each module page)
|
|
84
84
|
- `validate: boolean` False when createEngine({ validate: false }) turned the development checks off for this engine
|
|
85
85
|
- `renderer: EngineRenderer` three.js renderer: WebGLRenderer, or WebGPURenderer on the WebGPU route (EngineRenderer)
|
|
86
|
-
- `tier: 'low' | 'high'` 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').
|
|
86
|
+
- `tier: 'low' | 'high'` 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'.
|
|
87
87
|
- `scene: import('three').Scene` three.js scene
|
|
88
88
|
- `lights: { sun, hemi }` Placeholder lights: neutral and still, nothing moves them (the sky only gives signals). createEngine({ lights: false }) leaves them out of the scene
|
|
89
89
|
- `camera: import('three').Perspec… | import('three').Orthogr…` The camera the engine draws with, a plain THREE.PerspectiveCamera to begin with. Assign a real THREE.PerspectiveCamera or THREE.OrthographicCamera to draw through it; any other class is refused [camera-option].
|
|
@@ -172,7 +172,10 @@
|
|
|
172
172
|
- `install(e: Engine, ctx: ModuleCtx) → Api` — Install: create and return the object the game uses (engine.name). Register listeners / timers through ctx.track so they leave with the module (a use() batch that rolls back, a failed init, engine.dispose). Example: `install(e, ctx) { ctx.track(e.events.on('item:add', onAdd)); return api; }`
|
|
173
173
|
- `init(e: Engine, ctx: ModuleCtx) → void | Promise<void>` — Called at startup (download things, wait for assets); may be async. ctx is the same as install's
|
|
174
174
|
- `isReady(e: Engine) → boolean` — The loading screen waits until this returns true before disappearing (the hook is called isReady; in the engine ready is always a boolean property)
|
|
175
|
-
- `
|
|
175
|
+
- `sessionEnd(e: Engine)` — 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. Every reset step runs in engine.moduleOrder (stage, before / after), before the matching event (session:end) reaches the game
|
|
176
|
+
- `worldLoad(e: Engine, info: { count: number })` — 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
|
|
177
|
+
- `afterLoad(e: Engine, turn: SaveTurn) → void | Promise<void>` — 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
|
|
178
|
+
- `sessionStart(e: Engine, info: { kind, slot? })` — Session reset, step 4: a new playthrough began (not after a quick load), before 'session:start'
|
|
176
179
|
- `fixed(dt: number, e: Engine)` — Fixed step (60 times per second); dt is in seconds
|
|
177
180
|
- `frame(dt: number, e: Engine)` — Once per frame; dt is in seconds
|
|
178
181
|
- `afterRender(dt: number, e: Engine)` — After rendering
|
package/docs/api/events.md
CHANGED
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
- `save:loaded` [slot: string] A save was loaded onto the running playthrough (saves.load / session.load); the argument is the slot name
|
|
23
23
|
- `ui:open` [id: string] A window was opened (the argument is the window id, e.g. 'inventory')
|
|
24
24
|
- `ui:close` [id: string] A window was closed
|
|
25
|
-
- `settings:shadows` [on: boolean] Shadows were toggled
|
|
26
25
|
- `settings:change` [values: Record<string, any>] A value in the settings menu changed (the argument is all setting values)
|
|
26
|
+
- `tier:change` [{ tier: 'low' | 'high' }] engine.tier changed (device found at start, a preset, a write): resize what was sized from it
|
|
27
27
|
- `post:add` [name: string] A post effect was added (its name)
|
|
28
28
|
- `water:add` [body: WaterBody] A water body was added
|
|
29
29
|
- `water:remove` [body: WaterBody] A water body was removed
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
- `timeline:end` [{ id: number; ending: 'finished' | 'skipped' | 'dropped' | 'failed';… A cutscene ended; ending says how, error why it failed
|
|
75
75
|
- `template:stage` [TemplateStageEvent] A content template instance entered a new stage by growing (templates with stages)
|
|
76
76
|
- `ground:change` [{ x0: number; z0: number; x1: number; z1: number }] The ground's shape or type changed in this world-space box (engine.terrain.edit): cached ground samples (path rasters) inside it are stale
|
|
77
|
-
- `rigid:rebuilt` [{ world: any; player: any; bodies: Record<string, any> }] 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 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 joints here (recipes/11-
|
|
77
|
+
- `rigid:rebuilt` [{ world: any; player: any; bodies: Record<string, any> }] 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 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 joints here (recipes/11-physics.md, Joints). Not emitted while a vehicle exists (the world is kept then, joints included)
|
|
78
78
|
- `terrain:void` [{ who: any; position: { x: number; y: number; z: number } }] 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
|
|
79
79
|
- `terrain:chunkFailed` [{ cx: number; cz: number; error: any }] A terrain chunk job failed every try (usually the game's height / groundType / placement rule throws there): the chunk stays empty and the error is reported. engine.terrain.retry() sends failed chunks again
|
|
80
80
|
- `vegetation:remove` [VegetationRemoveEvent] A vegetation instance was chopped / removed
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
- `net:result` [{ seq: number; name: string; ok: boolean; code: string | null; value… Client (net): the host's answer to an op request (seq from ops.run's return value; tick is the host's), sent after the state it caused
|
|
97
97
|
- `engine:error` [EngineError] A gameplay error: in development / testing gameplay is frozen; a release build keeps running and sends it once per site (engine.error holds the first; error severity levels, see engine.error)
|
|
98
98
|
- `module:disabled` [{ name: string; message: string }] A picture or ui module errored and was disabled (the game continues)
|
|
99
|
-
- `module:
|
|
99
|
+
- `module:fresh` [{ modules: any[] }]
|
|
100
100
|
- `op:rolledBack` [{ op: string; parts: number }] 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)
|
|
101
101
|
- `vehicle:enter` [{ character: Character; vehicle: Rideable }] A character boarded a vehicle
|
|
102
102
|
- `vehicle:exit` [{ character: Character; vehicle: Rideable }] A character exited a vehicle
|
package/docs/api/particles.md
CHANGED
|
@@ -18,7 +18,7 @@ Particles (particles() module)
|
|
|
18
18
|
|
|
19
19
|
## Data structures
|
|
20
20
|
- **ParticleOptions** Particle effect parameters (define(), and each entry of particles({ effects, default })). All optional
|
|
21
|
-
- `max?: number` Maximum alive at once, default 120 (60
|
|
21
|
+
- `max?: number` Maximum alive at once, default 120 (60 while engine.tier is 'low'; a number the game gives stands)
|
|
22
22
|
- `lifetime?: Range` Seconds each particle lives [min, max]
|
|
23
23
|
- `rate?: number` Default particles per second for attach
|
|
24
24
|
- `speed?: Range` Initial speed (m/s) [min, max]
|
package/docs/api/photo.md
CHANGED
|
@@ -5,6 +5,11 @@ Photo mode (photo() module)
|
|
|
5
5
|
- Options `PhotoOptions` (also includes the fields of PhotoTakeOptions):
|
|
6
6
|
- `maxAlbum?: number` (experimental) How many photos the album keeps at most, default 50
|
|
7
7
|
- `pathTracer?: (() => Promise<any>) | null` (experimental) The game's import of its optional path tracer, called on the first photo.trace(): () => import('three-gpu-pathtracer/webgpu')
|
|
8
|
+
- `scale?: number` Resolution multiplier, default 1.6
|
|
9
|
+
- `shadowMapSize?: number` Shadow resolution (pixels), default 4096
|
|
10
|
+
- `bloom?: boolean | null` Bloom for the shot: null (default) keeps what the game's post has; true / false forces it for that shot only
|
|
11
|
+
- `quality?: number` Image quality 0–1
|
|
12
|
+
- `format?: string` Image format, e.g. 'image/jpeg'
|
|
8
13
|
|
|
9
14
|
## Methods and properties
|
|
10
15
|
- `photo.take(opts?: PhotoTakeOptions) → PhotoShot` — Capture a photo now without checks. Gameplay takes photos through the op: engine.ops.run('photo.take') (checks canTake, logged)
|
package/docs/api/pickups.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# engine.pickups — pickups(opts?: PickupsOptions)
|
|
2
2
|
|
|
3
|
-
pickups(). Things on the ground that go in the bag. Install: engine.use(
|
|
3
|
+
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
|
|
4
4
|
|
|
5
5
|
- Options `PickupsOptions`:
|
|
6
6
|
- `radius?: number` Reach of pickups that do not set their own radius (meters), default 2
|
package/docs/api/post.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
- `post.object() → any` — (experimental) What the chain runs in, for reading, or null while no post work has run yet (built the first time an effect is on; it is not built here, so asking never costs a render target). WebGLRenderer: the three.js EffectComposer (pass list, sizes, its targets). WebGPURenderer: { pipeline, scenePass }, three's RenderPipeline and the scene's pass() node. Read-only by rule, not by lock: the engine owns it, rebuilds the chain whenever the list changes and disposes it with the engine. To add a pass use post.add, to own the whole chain post.own() (recipe 52). Why public: a game reading the chain had to dig into an internal field (review 2026-11-03)
|
|
4
4
|
- `post.targets() → { renderTarget1, renderTarget2, readBuffer, writeBuffer } | null | …` — (experimental) The composer's render targets, for reading (sample the last frame's color or depth in a game pass, check formats / samples), or null while there is no composer, and always on WebGPURenderer (its pass nodes own their targets: post.object().scenePass). renderTarget1 / renderTarget2 are the ping-pong pair. During the chain readBuffer is a pass's input and writeBuffer its output; EffectComposer swaps them after every pass with needsSwap (most passes; the scene RenderPass does not). The last pass draws to the canvas and still swaps, so after the frame (engine.onRender(fn, { when: 'after' })) neither target holds the final picture: writeBuffer holds the input of that last pass (readBuffer when the last pass does not swap) and readBuffer is stale. For the final image, render into a target of your own.
|
|
5
|
-
- `post.add(x: any, o?: { name?, slot?, order? }) → PostHandle` — 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 { 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. 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. A Pass that draws engine.scene takes the 'scene' slot, FXAA / SMAA
|
|
5
|
+
- `post.add(x: any, o?: { name?, slot?, order? }) → PostHandle` — 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 { 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. 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. 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 OutputPass was added. Example: `const glow = engine.post.add(new UnrealBloomPass(size, 0.6, 0.4, 0.85), { name: 'glow' }); glow.enabled = false;`
|
|
6
6
|
- `post.get(name: string) → PostHandle | undefined` — An added effect's handle (as add() returns it), or undefined. Example: `engine.post.get('bloom').set({ strength: 0.6 });`
|
|
7
7
|
- `post.byRole(role: string, name?: string) → PostHandle[]` — (experimental) The added effects that declare this role in about.acts ('glow', 'ao', 'exposure'): found by what they do, never by name; the settings rows and photo follow every one of them. Only when NO effect declares the role does the effect named `name` stand in (a game's own 'bloom' written before roles existed); with no `name` that case gives [].
|
|
8
8
|
- `post.own(on?: boolean)` — (experimental) Hand the built chain to the game: the engine stops rebuilding it, so the composer's passes (post.object().passes) or the WebGPU pipeline's outputNode are the game's to edit. own(false) gives it back and rebuilds from the list. describe().owned shows who has it. Example: `engine.post.own(); engine.post.object().passes.reverse();`
|
package/docs/api/rigid.md
CHANGED
|
@@ -20,7 +20,7 @@ Real physics, Rapier (rigid() module, needs collision)
|
|
|
20
20
|
- `rigid.addBall(mesh: Object3D, opts?: RigidBallOptions) → RigidEntry | null` — (experimental) Add a ball; null only as in addBox: a release build, called before physics is ready
|
|
21
21
|
- `rigid.addHull(mesh: Object3D, opts?: RigidBodyOptions) → RigidEntry | null` — (experimental) Add a convex hull (irregular objects such as rocks and barrels); null only as in addBox: a release build, called before physics is ready
|
|
22
22
|
- `rigid.ragdoll(who: any, opts?: RagdollOptions) → Ragdoll | null` — (experimental) Turn a skinned character limp in one call; rd.remove() returns it to animation. who: a Character, an NPC handle, a character id or a skinned Object3D. Its mover, animator, capsule and camera yield until then; calling again on the same one pushes it again and returns the same ragdoll. Not saved: any load ends it. A skeleton it cannot read throws, naming the missing parts. The rule 'ragdoll.graph' (per character id) gives the parts: 'humanoid' (default), Record<string, RagdollPart> for any other body, a function (facts: { character, root, mesh }, engine) => one of those, or false for no ragdoll (returns null).
|
|
23
|
-
- `rigid.impulse(entry: RigidEntry, impulse: Vec3Like)` — Give it a push: impulse vector impulse (Vector3 / [x, y, z] / { x, y, z }), e.g. impulse(ball, [0, 3, 5])
|
|
23
|
+
- `rigid.impulse(entry: RigidEntry, impulse: Vec3Like)` — 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)
|
|
24
24
|
- `rigid.setPosition(entry: RigidEntry, position: PositionLike)` — Teleport to position (velocity is zeroed)
|
|
25
25
|
- `rigid.addWheeled(mesh: Object3D, opts: VehicleOptions) → Vehicle | null` — Turn a model into a wheeled vehicle (Rapier ray-cast vehicle controller: cars, karts, carts); remove it with vehicle.remove() (anyone inside gets out first). Before physics is ready it throws in development (release: warns, null), like addBox. Boats, mounts and mechs are the game's own objects with the same seat interface
|
|
26
26
|
- Properties:
|
package/docs/api/sky.md
CHANGED
|
@@ -4,9 +4,19 @@ Sky dome and the sun / daylight / sky-color signals, from the calendar's time; i
|
|
|
4
4
|
|
|
5
5
|
- Options `SkyOptions` (also includes the fields of Pick<SkyPictureOptions, 'clouds' | 'backdrop' | 'keyframes' | 'sunSize' | 'sunGlow' | 'sunBrightness' | 'moonColor' | 'moonBrightness' | 'starDensity' | 'dim'>):
|
|
6
6
|
- `time?: string | number` The fixed time of day drawn while no calendar() is installed: 'HH:MM' or 0–1 (0.5 noon), default 0.33 (a sunset arena: sky({ time: '18:30' })). With calendar() the sky draws engine.calendar.timeOfDay and this option throws (start the day with calendar({ time }))
|
|
7
|
+
- `clouds?: SkyCloudOptions` Clouds in the sky (cloud cover follows the weather); see SkyCloudOptions
|
|
8
|
+
- `backdrop?: ColorLike` A flat background color in place of the dome (no gradient, horizon line, sun / moon disk, stars or clouds). Drawn as written (no tone mapping); a fog asked for in the default horizon color takes it (a fog.color of your own still wins). Leave out for the dome. recipes/08. Example: `backdrop: 0xefebe4`
|
|
9
|
+
- `keyframes?: SkyKeyframe[]` Rows [time, zenith, horizon, sunColor, ambient]. time: share of the day (0 = 00:00, 0.5 = noon), sorted, first row 0, last 1 (midnight again: same values as 0). They color the dome and the signals uSkyTop / uSkyHorizon, and light nothing: sunColor is the sun disk and the signal uSunColor, ambient dims a skybox and the weather's sky tint (recipe 08). Example: `[[0, 0x0b1030, 0x1c2440, 0x8090c0, 0.25], [0.5, 0x5a8fd0, 0xbcd4ea, 0xfff4e0, 1.1], [1, 0x0b1030, 0x1c2440, 0x8090c0, 0.25]]`
|
|
10
|
+
- `sunSize?: number` Sharpness exponent of the sun disk, default 900 (about 2 deg); larger = smaller. Not a size in degrees: 10 is ~20 deg, under ~3 the "disk" washes most of the sky toward the sun color
|
|
11
|
+
- `sunGlow?: number` Sun glow, default 0.18
|
|
12
|
+
- `sunBrightness?: number` (experimental) Sun brightness, default 6
|
|
13
|
+
- `moonColor?: ColorLike` (experimental) Color of the moon disk drawn at night, default 0xdcdcdc
|
|
14
|
+
- `moonBrightness?: number` (experimental) Brightness of the moon disk drawn at night, default 3
|
|
15
|
+
- `starDensity?: number` 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.
|
|
16
|
+
- `dim?: { tint?: boolean; stars?: boolean }` What the sky dims for every game unless the style says no (each default true; false turns that one off, the rest stay). The one place these picture decisions are switched: - tint: a sky.tint color (weather grey, a cave tint) dims with the sky's own light, so a grey rain tint stays dark at night. Example: `sky({ dim: { stars: false } }) // live: engine.sky.dim.tint = false`
|
|
7
17
|
|
|
8
18
|
## Methods and properties
|
|
9
|
-
- `sky.keyframes(rows
|
|
19
|
+
- `sky.keyframes(rows?: any[][]) → any[][]` — The day's colors, live: rows [time, zenith, horizon, sunColor, ambient] sorted from 0 to 1 (the same rows as sky({ keyframes })). 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). Example: `engine.sky.keyframes([[0, 0x101828, 0x202838, 0x8090b0, 0.3], [0.5, 0x4080c0, 0xc0d8e8, 0xffffff, 1.2], [1, 0x101828, 0x202838, 0x8090b0, 0.3]]);`
|
|
10
20
|
- `sky.clouds(spec: string | { glsl?, tsl?, uniforms? } | null)` — Your own cloud function on the dome: glsl defines `vec4 threedogClouds(vec3 dir, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cover)`, tsl is its WebGPURenderer form (ctx) => vec4 node; each renderer needs its own form (modules/sky/clouds.js). null gives the built-in kind back. Recompiles the dome once: a scene change, not every frame. Example: `engine.sky.clouds({ glsl: 'vec4 threedogClouds(vec3 d, float t, vec3 s, float night, vec3 lit, vec3 shade, float cover){ return vec4(lit, step(0.5, threedogNoise(d.xz * 4.0)) * cover); }' });`
|
|
11
21
|
- `sky.layer(name: string, spec: string | { glsl?, tsl?, uniforms?, order?, blend? } | null | …)` — Add, change or remove (null) a named dome layer drawn after the clouds and stars: glsl defines `vec4 threedogSkyLayer(vec3 dir, float time, vec3 sunDir, float night)` returning (rgb, amount), tsl is its WebGPURenderer form (modules/sky/domeLayers.js). Recompiles the dome once. Example: `engine.sky.layer('aurora', { glsl: 'vec4 threedogSkyLayer(vec3 d, float t, vec3 s, float n){ return vec4(0.2, 1.0, 0.5, n * smoothstep(0.1, 0.6, d.y) * 0.4); }', blend: 'add' });`
|
|
12
22
|
- `sky.replace(sky: string | import("three").Texture | THREE.Object3D | …)` — Replace or hide the dome: a skybox asset name (equirectangular panorama), a THREE.Texture / CubeTexture, or your own THREE.Object3D sky; null gives the dome back, false draws no sky (the scene shows its base background, the signals keep running). The engine never writes your object: it hides the dome, adds your object to the scene only when it has no parent, puts a plain texture's panorama mapping on a clone, and keeps feeding engine.uniforms (uSunDir, uWind ...). Example: `engine.sky.replace(new SkyMesh());`
|
package/docs/api/terrain.md
CHANGED
|
@@ -11,6 +11,25 @@ Procedural terrain, data part (terrain() module: chunks, heights, edits, collisi
|
|
|
11
11
|
- `effects?: boolean` With material: false = draw it exactly as given, no cloud shadow / season / detail patch
|
|
12
12
|
- `detail?: MaterialDetail | null` Detail layer over the ground: a noise, a texture asset name or your own glsl; defaults scale 0.25, strength 0.35, top-down world projection, multiply. Change it with engine.terrain.recolor({ detail })
|
|
13
13
|
- `variation?: TerrainVariation` Ground color noise, baked into the chunks
|
|
14
|
+
- `seed?: number` Random seed; the same seed gives the same terrain
|
|
15
|
+
- `chunkSize?: number` Chunk edge length (meters), default 64
|
|
16
|
+
- `resolution?: number` Cells per chunk; smaller is more "low poly", default 16
|
|
17
|
+
- `waterLevel?: number` Water level (meters), default -Infinity = no water (terrainPreset() from
|
|
18
|
+
- `flatten?: FlattenZone[]` Flattened plots
|
|
19
|
+
- `biomeColors?: Record<string, string[]>` Ground type → palette color names (two are blended by noise); a type left out is neutral gray
|
|
20
|
+
- `steep?: SteepRule[]` Steep-slope color rule
|
|
21
|
+
- `heightmap?: { url?, size?, min?, max?, center?, outside?, … } | null` Heightmap (used when there is no height function): url grayscale image, size [width m, length m], min/max height (meters), center [x, z]
|
|
22
|
+
- `height?: ((x, z, n) => number) | string | null` Height generator: (x, z, n) => meters. Without one (and without a heightmap) the ground is flat at y = 0, a placeholder (dev warning). Runs in workers, so it must be pure (only its parameters and globals like Math); an outside variable throws at terrain() naming it. n = { fbm(x, z, octaves?), noise(x, z), hash(x, z, salt?), seed, waterLevel, params }. Example: `terrain({ height: (x, z, n) => 4 + 12 * n.fbm(x * 0.01, z * 0.01) })`
|
|
23
|
+
- `groundType?: ((x, z, h, slope, n) => string | null) | string | null` Ground type: (x, z, h, slope, n) => type name (null = 'default'). Pure, like height. Colors come from biomeColors[type]; vegetation rules and footsteps match by name. Example: `terrain({ groundType: (x, z, h, slope) => slope > 0.7 ? 'rock' : h < 2 ? 'beach' : 'grass' })`
|
|
24
|
+
- `params?: Record<string, any> | null` Plain data handed to height / groundType as n.params (a preset's settings); must be serializable
|
|
25
|
+
- `shading?: 'flat' | 'smooth' | 'texture'` How the ground gets its color: 'smooth' (default) blended per grid point / 'flat' one color and normal per triangle (low poly) / 'texture' per-chunk color map sampled per pixel, so color borders (a river bank) are not confined to triangle edges and the mesh can stay coarse. See recipes/53-ground-up-close.md.
|
|
26
|
+
- `colorResolution?: number` Texture shading: color map pixels per chunk edge (default 128, 64 on low-tier devices; independent of `resolution`)
|
|
27
|
+
- `normals?: 'smooth' | 'flat' | null` Texture shading only: lighting normals 'smooth' (default) / 'flat'
|
|
28
|
+
- `normalFn?: ((i, j, h, cell) => number[]) | string | null` Replace the smooth normal at grid point (i, j): (i, j, h, cell) => [nx, ny, nz] (any length; the engine normalizes). h(i, j) is a grid-point height, cell the grid spacing in meters. Pure, like height (workers get its source). Default: central difference of the neighbors. Example: `terrain({ normalFn: (i, j, h, cell) => [(h(i - 1, j) - h(i + 1, j)) / (2 * cell), 2, (h(i, j - 1) - h(i, j + 1)) / (2 * cell)] }) // flatter lighting`
|
|
29
|
+
- `diagonal?: 'fixed' | 'adaptive' | 'alternate'` How each cell is cut into two triangles: 'fixed' (default, the same diagonal everywhere) / 'adaptive' (along the diagonal with the smaller height difference, fewer zigzag ridges on slopes) / 'alternate' (flips every other cell). It is shape: engine.surface follows it
|
|
30
|
+
- `boundsPad?: { up?: number; radius?: number }` Chunk bounding sphere margin in meters (default { up: 3, radius: 8 }): center raised by `up`, radius grown by `radius`. Raise it when a shader moves vertices far
|
|
31
|
+
- `shape?: TerrainShape | null` World outline (default null = ground everywhere): an island, a floating rock, a coastline that ends
|
|
32
|
+
- `colors?: Record<string, ColorLike>` Palette: color name → color
|
|
14
33
|
|
|
15
34
|
## Methods and properties
|
|
16
35
|
- `terrain.recolor(o?: TerrainRecolor)` — Change at run time what terrain({...}) baked in. colors, biomeColors, steep, variation, shading, normals rebuild every chunk (edits stay); detail only patches the engine's material. Throws under a draw part that replaced 'terrain-draw'. Example: `engine.terrain.recolor({ colors: { grass: 0x6a8a3a }, biomeColors: { meadow: ['grass'] } });`
|
package/docs/api/tools.md
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
- `toast(engine: Engine, text: string, { kind, ms }?: { kind?: string; ms?: number })` — Show a short message through the 'toast' UI part (default: top of the screen, gone after ms). A game restyles it, filters it by kind or turns it off with createEngine({ ui: { toast: false } }). kind says where it came from: 'info' (default), 'quest', 'item', 'save', 'error'.
|
|
26
26
|
- `makeWindow(engine: Engine, opts: WindowOptions) → UIWindow` — A toggleable window
|
|
27
27
|
- `worldToScreen(engine: Engine, pos: PositionLike) → ScreenPoint` — World coordinates (position or object) -> pixels from the canvas's top-left corner { x, y, onScreen, behind } (the UI root covers the canvas, so these place UI elements directly)
|
|
28
|
-
- `fadeScreen(engine: Engine, to: number, opts?: { seconds?: number }) → Promise<void>` — Fade the whole screen to `to` (0 clear ... 1 fully covered) over `seconds` (default 0.5); the Promise resolves when the fade ends. fadeScreen(engine, 1, 0.5) throws in dev: fadeScreen(engine, 1, { seconds: 0.5 })
|
|
28
|
+
- `fadeScreen(engine: Engine, to: number, opts?: { seconds?: number; owner?: string }) → Promise<void>` — Fade the whole screen to `to` (0 clear ... 1 fully covered) over `seconds` (default 0.5); the Promise resolves when the fade ends. fadeScreen(engine, 1, 0.5) throws in dev: fadeScreen(engine, 1, { seconds: 0.5 })
|
|
29
29
|
- `uiFocus(engine: Engine) → UIFocus` — (experimental) UI focus stack: windows, dialogue and cutscenes push in open order; the back key (Esc) goes to the top only; an empty stack hands it to the settings menu
|
|
30
30
|
- `toggleOnKey(engine: Engine, win: { open, toggle }, action: string)` — (experimental) Window toggle key: call once per frame in a frame hook; opens on the action when closed, closes on another press when open
|
|
31
31
|
- `parseClock(clock: string | number, hoursPerDay?: number) → number` — Clock time -> fraction of the day: parseClock('18:30') = 0.77; a number or numeric string ('0.25') is converted as is. hoursPerDay is hours per day, default 24
|
|
@@ -22,7 +22,7 @@ The name may only contain lowercase letters, digits and dashes; an existing dire
|
|
|
22
22
|
2. Creates the `node_modules/my-game` link (the path npm gives a workspace named `my-game`). It builds nothing and leaves `package-lock.json` alone; it runs `npm install` only when a dependency of the template is not installed yet, and says so.
|
|
23
23
|
3. Runs `map` (generates GAMEMAP.md) and `check`. Any failing step stops and says why. The smoke test (`threedog test -w games/my-game`) builds, so it is left to you.
|
|
24
24
|
|
|
25
|
-
The default game has no genre: `world()` + `content()`, what nearly every game needs (a start screen with Continue / Start, autosave, Esc = pause + settings menu; delete a line if the game does not want it), a plain `THREE.PerspectiveCamera` placed by hand and
|
|
25
|
+
The default game has no genre: `world()` + `content()`, what nearly every game needs (a start screen with Continue / Start, autosave, Esc = pause + settings menu; delete a line if the game does not want it), a plain `THREE.PerspectiveCamera` placed by hand and a neutral, lit starting picture (recipe 62). No ground, sky, player or camera rig: a card table, a puzzle room, a side-scroller and an open world start differently (a character walking around a place you built: recipe 63, about twenty lines).
|
|
26
26
|
Content files start empty, a comment in each saying what goes there, except `props.js`, whose `marker-1` shows the shape. `picture/` (`index.js` wiring, `palette.js`, `lights.js`, `materials.js`) is plain three.js, yours to change or replace (recipe 62).
|
|
27
27
|
`--open-world` swaps `main.js` for `openWorld` (generated terrain from `@threedog/terrain-noise`, vegetation, a day/night sky, weather, water, collision, a
|
|
28
28
|
follow camera) and a player at a flat spot, with `sky()` giving the signals and `picture/` writing the lights; it adds `@threedog/terrain-noise` to `package.json`. `spawn` and `places` take any `{ x, z }` (or `{ x, y, z }`); `findSpawn` is only for generated terrain.
|