threedog 1.3.0 → 2.0.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 +40 -0
- package/README.md +13 -7
- package/bin/threedog.mjs +42 -0
- package/core/base/Events.js +7 -1
- package/core/base/errorCodes.js +1 -1
- package/core/base/events.generated.js +1 -0
- package/core/engine/Engine.js +2 -2
- package/core/engine/copies.js +1 -1
- package/core/engine/moduleTypes.js +1 -1
- package/core/engine/modules.js +19 -2
- package/core/engine/page.js +1 -0
- package/core/engine/services.js +2 -1
- package/core/engine/startup.js +4 -1
- package/core/inspect/InspectPerf.js +1 -1
- package/core/inspect/metadata.generated.js +33 -14
- package/core/ops/control.js +3 -3
- package/core/ops/holds.js +8 -3
- package/core/saves/saveApply.js +2 -2
- package/core/saves/session.js +20 -4
- package/core/scene/adaptive.js +2 -0
- package/core/scene/things.js +3 -2
- package/core/scene/tier.js +19 -2
- package/docs/AI.md +3 -3
- package/docs/CODEMAP.md +5 -5
- package/docs/COMMANDS.md +3 -2
- package/docs/CONVENTIONS.md +1 -0
- package/docs/THREE.md +1 -1
- package/docs/api/engine.md +5 -2
- package/docs/api/events.md +2 -1
- package/docs/api/particles.md +1 -1
- 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 +1 -1
- package/docs/recipes/01-new-game.md +1 -1
- package/docs/recipes/03-items-pickups.md +1 -1
- package/docs/recipes/06-clock-events.md +3 -10
- package/docs/recipes/07-flow-scenes-pause.md +0 -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 +5 -4
- package/docs/recipes/20-content-actions-save.md +0 -1
- package/docs/recipes/21-camera.md +11 -1
- 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/44-water-weather-hooks.md +1 -1
- package/docs/recipes/45-cascaded-shadows.md +6 -3
- package/docs/recipes/52-around-the-picture.md +6 -6
- package/docs/recipes/53-ground-up-close.md +2 -2
- package/docs/recipes/55-mods-time-wrap.md +3 -5
- package/docs/recipes/60-judge-the-picture.md +2 -2
- 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/picture/lights.js +4 -2
- package/examples/techniques/modular-building/picture/lights.js +3 -2
- 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/picture/lights.js +3 -2
- package/examples/techniques/procedural-animation/picture/lights.js +3 -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/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/characters/Character.js +2 -2
- package/modules/characters/NPC.js +7 -8
- package/modules/characters/index.js +8 -8
- package/modules/characters/npcAvoid.js +2 -2
- package/modules/characters/player.js +10 -14
- package/modules/characters/playerStrings.js +1 -2
- package/modules/characters/seat.js +1 -1
- package/modules/content/index.js +2 -1
- package/modules/content/templates.js +3 -2
- package/modules/flow/index.js +5 -5
- package/modules/gameplay/Dialogue.js +1 -1
- package/modules/gameplay/Inventory.js +3 -3
- package/modules/gameplay/Quests.js +1 -0
- package/modules/gameplay/pickups.js +1 -1
- package/modules/gameplay/questLog.js +0 -1
- package/modules/grid/index.js +1 -1
- package/modules/hud/index.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 +13 -5
- package/modules/particles/effect.js +17 -3
- package/modules/rigid/RigidBodies.js +10 -9
- package/modules/rigid/sync.js +14 -0
- package/modules/sky/Sky.js +9 -4
- package/modules/sky/environment.js +4 -2
- package/modules/timeline/Timeline.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 +10 -5
- package/render/fx/postWebGPU.tsl.js +2 -1
- package/types/core.d.ts +14 -5
- package/types/gameplay.d.ts +1 -1
- package/types/generated/modules/sky/Sky.d.ts +4 -4
- package/types/generated/render/PostFX.d.ts +2 -2
- package/types/physics.d.ts +1 -1
|
@@ -21,7 +21,7 @@ import { vec3, xzOf } from '../../core/base/math.js';
|
|
|
21
21
|
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
22
22
|
import { cellsChanged } from '../../core/stream/streamCells.js';
|
|
23
23
|
import { createVehicle, VEHICLE_KEYS, STRINGS } from './Vehicles.js';
|
|
24
|
-
import { syncTerrain, syncTrees, treesChanged, syncGroundTrees, syncStatics, restandStatics, syncLevel, syncFloor, dropChunks, wantsFloor, recordLocks, carryBody, carryCollider } from './sync.js';
|
|
24
|
+
import { syncTerrain, syncTrees, treesChanged, syncGroundTrees, syncStatics, restandStatics, syncLevel, syncFloor, dropChunks, wantsFloor, recordLocks, carryBody, carryCollider, carryWorld } from './sync.js';
|
|
25
25
|
import { refreshQueries } from './refresh.js';
|
|
26
26
|
import { Ragdolls } from './ragdoll.js';
|
|
27
27
|
import { codedError, coded } from '../../core/base/errorHints.js';
|
|
@@ -186,7 +186,7 @@ export class RigidBodies {
|
|
|
186
186
|
* crate pushed the same way after newGame landed a few millimetres off the fresh-page result (durability audit). The world is rebuilt: the
|
|
187
187
|
* player capsule first, every body still here (bodies of world records were already removed by the load and come back with their views) at its
|
|
188
188
|
* pose with no velocity, and terrain / tree / static colliders on the next step, the order a fresh page builds them in. What the game wrote on a
|
|
189
|
-
* body or collider itself (gravityScale, axis locks, ccd, dominance, sensor, groups, enabled) is carried onto the rebuilt one (carryBody / carryCollider in sync.js). Joints are not carried: Rapier has no getters for a joint's
|
|
189
|
+
* body or collider itself (gravityScale, axis locks, ccd, dominance, sensor, groups, enabled) is carried onto the rebuilt one (carryBody / carryCollider in sync.js), and so are the world's solver settings (carryWorld). Joints are not carried: Rapier has no getters for a joint's
|
|
190
190
|
* whole description (rope length, motor settings), and copying one would mean patching Rapier. The game re-creates its own joints on rigid:rebuilt,
|
|
191
191
|
* emitted once the bodies are back (the coordination point); a dev warning names a game whose joints vanished with no re-creation. Movers'
|
|
192
192
|
* character controllers are freed with the old world (World.free frees them; movers/rapier.js sees another world object and builds new ones).
|
|
@@ -201,6 +201,7 @@ export class RigidBodies {
|
|
|
201
201
|
}
|
|
202
202
|
const old = this.world, R = this.rapier, hadJoints = old.impulseJoints.len();
|
|
203
203
|
this._newWorld();
|
|
204
|
+
carryWorld(old.integrationParameters, this.world.integrationParameters); // solver settings are the game's, like what it wrote on a body
|
|
204
205
|
this.terrain.clear(); this.trees.clear(); this.groundTrees.clear(); this._statics?.clear(); this._onGround.clear(); this._layered.clear();
|
|
205
206
|
this._level.reset(); this._levelColliders = [];
|
|
206
207
|
this._srcMemo = null; this._srcPending = false; this._syncT = 0; this._anchors = []; this._treeMemo = [];
|
|
@@ -417,7 +418,7 @@ export class RigidBodies {
|
|
|
417
418
|
* @internal What a save keeps of each body with an id (addBox / addBall / addHull({ id }), vehicles always): pose, velocities, asleep. Without it a
|
|
418
419
|
* load put a toppling crate back upright and at rest wherever its record was, so the game after the load was not the game that was saved. A template
|
|
419
420
|
* body carries its record id, and atRest (content/templates.js): while it stands where content put it, content is its state and it stays out of the save.
|
|
420
|
-
* Bodies not built yet keep their loaded state (it is still the saved game). Not kept: Rapier's contact / warm-start caches (docs/recipes/11-
|
|
421
|
+
* Bodies not built yet keep their loaded state (it is still the saved game). Not kept: Rapier's contact / warm-start caches (docs/recipes/11-physics.md, section 3).
|
|
421
422
|
*/
|
|
422
423
|
_saveState() {
|
|
423
424
|
const out = {};
|
|
@@ -477,7 +478,7 @@ export class RigidBodies {
|
|
|
477
478
|
}
|
|
478
479
|
this._upkeep();
|
|
479
480
|
if (this._jointsGone) { // dev only (set in _fresh): the old world had the game's joints and nothing re-created one since the rebuild
|
|
480
|
-
if (!this.world.impulseJoints.len()) warnOnce(coded('rigid-misuse', `rigid: ${this._jointsGone} joint(s) were freed with the old physics world by newGame / load and none was re-created. The engine rebuilds the world and does not copy joints: re-create them in a rigid:rebuilt listener ({ world }), between entry.body of the rebuilt bodies (recipes/11-
|
|
481
|
+
if (!this.world.impulseJoints.len()) warnOnce(coded('rigid-misuse', `rigid: ${this._jointsGone} joint(s) were freed with the old physics world by newGame / load and none was re-created. The engine rebuilds the world and does not copy joints: re-create them in a rigid:rebuilt listener ({ world }), between entry.body of the rebuilt bodies (recipes/11-physics.md, Joints)`));
|
|
481
482
|
this._jointsGone = 0;
|
|
482
483
|
}
|
|
483
484
|
// player capsule follows the player (the rapier mover computes collision and writes the position itself); turned off while driving to avoid colliding with
|
|
@@ -573,17 +574,17 @@ export function rigid(opts = {}) {
|
|
|
573
574
|
ctx.budget.metric('rigidBodies', () => r.bodies.length);
|
|
574
575
|
ctx.stream.addReadyCheck('rigid', s => !s.physics || r.ready && r.readyAt(s)); // a physics stream source waits for the collider under it
|
|
575
576
|
ctx.track(e.rays.addProvider((o, d, far) => r._raycast(o, d, far))); // engine.raycast(..., { targets: 'all' }) includes rigid bodies
|
|
576
|
-
// a new playthrough / a load is a fresh page for physics too (_fresh), rebuilt once per load: session:end only marks it due. With the world
|
|
577
|
-
// module the rebuild runs on world:load, after the load removed the records' bodies, so the rebuilt world gets them back in view order; without
|
|
578
|
-
// it, afterLoad (newGame / load / quit all apply a save) runs it. Rebuilding on both events built the world twice per new game.
|
|
579
577
|
// A refused load (session:failed) leaves the game as it was, physics included: no afterLoad runs after a rollback, so the state its rigid part read back is claimed here.
|
|
580
578
|
ctx.track(e.events.on('ground:change', b => { r._srcPending = true; restandStatics(r, b); })); // dug or raised ground: colliders follow on the next step, not at the half-second check a body could fall through
|
|
581
|
-
ctx.track(e.events.on('session:end', () => { r._freshDue = true; }));
|
|
582
579
|
ctx.track(e.events.on('session:failed', () => { r._freshDue = false; r._claimSaved(); }));
|
|
583
|
-
ctx.track(e.events.on('world:load', () => r._fresh()));
|
|
584
580
|
ctx.saves.define('rigid', { notAtomic: 'the physics world is stepped, not written: a load cannot rewind what the bodies did', save: () => r._saveState(), load: d => r._loadState(d) });
|
|
585
581
|
return r;
|
|
586
582
|
},
|
|
583
|
+
// a new playthrough / a load is a fresh page for physics too (_fresh), rebuilt once per load: sessionEnd only marks it due. With the world
|
|
584
|
+
// module the rebuild runs in worldLoad, after the load removed the records' bodies, so the rebuilt world gets them back in view order; without
|
|
585
|
+
// it, afterLoad (newGame / load / quit all apply a save) runs it. Rebuilding in both steps built the world twice per new game.
|
|
586
|
+
sessionEnd() { r._freshDue = true; },
|
|
587
|
+
worldLoad() { r._fresh(); },
|
|
587
588
|
afterLoad() { if (r._freshDue) r._fresh(); r._claimSaved(); }, // after every part loaded and _fresh rebuilt the world (world:load is emitted inside the world part's load)
|
|
588
589
|
async init(e, ctx) { await r.init(ctx.signal); ctx.whileCompiling(() => warmRapier(r.rapier)); },
|
|
589
590
|
counts() { return r.bodies.length; }, // engine.counts().rigid
|
package/modules/rigid/sync.js
CHANGED
|
@@ -224,6 +224,20 @@ export function carryBody(entry, o, n) {
|
|
|
224
224
|
if (!o.isEnabled()) n.setEnabled(false);
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
+
/** @internal Copy the solver settings a game wrote on the old world (numSolverIterations, maxCcdSubsteps, contact_natural_frequency...) onto the rebuilt one.
|
|
228
|
+
* Every Rapier setter with a getter but dt (the engine writes the timestep each step), read from the prototype so a setting a Rapier update adds is carried too.
|
|
229
|
+
* contact_natural_frequency has no getter in rapier3d-compat 0.21: it is read back from contact_erp (erp = a·f / (a·f + c), a = 2π·dt, c Rapier's
|
|
230
|
+
* hidden damping term), with c measured on the new world by setting a known frequency there, so no Rapier constant is copied here */
|
|
231
|
+
export function carryWorld(o, n) {
|
|
232
|
+
const proto = Object.getPrototypeOf(o), d = k => Object.getOwnPropertyDescriptor(proto, k);
|
|
233
|
+
for (const k of Object.getOwnPropertyNames(proto)) if (k !== 'dt' && d(k).set && d(k).get && o[k] !== n[k]) n[k] = o[k];
|
|
234
|
+
if (!d('contact_natural_frequency')?.set || !d('contact_erp')?.get) return;
|
|
235
|
+
const a0 = 2 * Math.PI * o.dt, a1 = 2 * Math.PI * n.dt, f1 = 30;
|
|
236
|
+
n.contact_natural_frequency = f1;
|
|
237
|
+
const e0 = o.contact_erp, e1 = n.contact_erp, c = a1 * f1 * (1 - e1) / e1;
|
|
238
|
+
if (e0 > 0 && e0 < 1) n.contact_natural_frequency = c * e0 / ((1 - e0) * a0);
|
|
239
|
+
}
|
|
240
|
+
|
|
227
241
|
/** @internal Copy game-set collider state from the old collider onto the one rebuilt from the entry's desc */
|
|
228
242
|
export function carryCollider(o, n) {
|
|
229
243
|
const pairs = [['isSensor', 'setSensor'], ['collisionGroups', 'setCollisionGroups'], ['solverGroups', 'setSolverGroups'], ['friction', 'setFriction'],
|
package/modules/sky/Sky.js
CHANGED
|
@@ -99,6 +99,7 @@ export class Sky {
|
|
|
99
99
|
|
|
100
100
|
/** The day's rows as colors (start, keyframes()) @internal */
|
|
101
101
|
_setKeyframes(rows) {
|
|
102
|
+
/** @internal the rows as given, for keyframes() with no argument (copied, so a later edit of the caller's array changes nothing here) */ this._rows = rows.map(r => [...r]);
|
|
102
103
|
/** @internal */ this.kf = rows.map(k => [k[0], new THREE.Color(k[1]), new THREE.Color(k[2]), new THREE.Color(k[3]), k[4]]);
|
|
103
104
|
// brightest row of the sky's ambient light (ambient column x the hemi color's brightness, frame.js skyLight): the sky's light now / this is
|
|
104
105
|
// the 0-1 scale the sky.tint color (weather grey) follows
|
|
@@ -108,12 +109,16 @@ export class Sky {
|
|
|
108
109
|
|
|
109
110
|
/**
|
|
110
111
|
* The day's colors, live: rows [time, zenith, horizon, sunColor, ambient] sorted from 0 to 1 (the same rows as sky({ keyframes })).
|
|
111
|
-
* Throws, changing nothing, on rows that are not sorted from 0 to 1.
|
|
112
|
+
* 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).
|
|
112
113
|
* @example engine.sky.keyframes([[0, 0x101828, 0x202838, 0x8090b0, 0.3], [0.5, 0x4080c0, 0xc0d8e8, 0xffffff, 1.2], [1, 0x101828, 0x202838, 0x8090b0, 0.3]]);
|
|
113
|
-
* @param {any[][]} rows
|
|
114
|
-
* @returns {
|
|
114
|
+
* @param {any[][]} [rows]
|
|
115
|
+
* @returns {any[][]} the rows in use
|
|
115
116
|
*/
|
|
116
|
-
keyframes(rows) {
|
|
117
|
+
keyframes(rows) {
|
|
118
|
+
if (rows === undefined) return this._rows.map(r => [...r]); // a copy: editing it changes nothing until it is passed back
|
|
119
|
+
checkKeyframes(rows); this._setKeyframes(rows);
|
|
120
|
+
return rows;
|
|
121
|
+
}
|
|
117
122
|
|
|
118
123
|
/**
|
|
119
124
|
* 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,
|
|
@@ -78,10 +78,12 @@ export const environmentMethods = {
|
|
|
78
78
|
this._envScene.add(copy);
|
|
79
79
|
}
|
|
80
80
|
/** @type {any} */ (this._envScene.children[0]).material = this.dome.material; // a game may have set engine.sky.dome.material
|
|
81
|
-
|
|
81
|
+
// WebGPU: the rebuild refills the same target. A new texture there made every material that reads the environment build again: a stall of 100 ms
|
|
82
|
+
// to seconds at each rebuild, measured on the open-world start. three 0.187's WebGL generator has no renderTarget option and returns a new one, which costs nothing there
|
|
83
|
+
const old = e.target, next = this._pmrem.fromScene(this._envScene, 0, 0.1, 100, { size: 256, renderTarget: old });
|
|
82
84
|
// a map the game wrote there is the game's: the owned check (frame.js) has yielded, and the sky writes it no more
|
|
83
85
|
if (e.into && this._oEnv.on) { e.into.environment = next.texture; this._oEnv.mark(); }
|
|
84
|
-
|
|
86
|
+
if (old !== next) old?.dispose(); e.target = next;
|
|
85
87
|
e.builds++; e.key = skyKey(this);
|
|
86
88
|
},
|
|
87
89
|
|
|
@@ -321,11 +321,10 @@ export function timeline(opts = {}) {
|
|
|
321
321
|
name: 'timeline', skipKind: 'none', type: 'rules', params: TIMELINE_PARAMS, options: opts, label: 'Timeline', stage: 'control', before: ['cameraRig'], optional: ['dialogue'], // before the camera, so the takeover applies on the same frame
|
|
322
322
|
install(e, ctx) {
|
|
323
323
|
e.i18n.add(STRINGS); t = new Timeline(e, ctx);
|
|
324
|
-
// a running cutscene ends with its playthrough (session waits one macrotask for its steps to settle)
|
|
325
|
-
ctx.track(e.events.on('session:end', () => t._drop()));
|
|
326
324
|
return t;
|
|
327
325
|
},
|
|
328
326
|
frame(dt) { t.frame(dt); },
|
|
327
|
+
sessionEnd() { t._drop(); }, // a running cutscene ends with its playthrough (session waits one macrotask for its steps to settle)
|
|
329
328
|
afterLoad() { t._drop(r => r.duringLoad); },
|
|
330
329
|
// unloaded mid-cutscene: every run ends through its finally (camera, focus, actors go back); nothing else would, the frame hook is gone
|
|
331
330
|
dispose() { t._drop(); t._tweener.cancelAll(); }, // also the tweens started with timeline.tween(): no run owns them
|
package/modules/world/World.js
CHANGED
|
@@ -28,6 +28,7 @@ export class World {
|
|
|
28
28
|
constructor(engine, opts = {}) {
|
|
29
29
|
const { cellSize = 32, radius = 60, farEvery = 1, farMaxPerTick = 500, buildPerFrame = 8 } = opts;
|
|
30
30
|
/** @internal */ this.engine = engine;
|
|
31
|
+
/** @internal ctx.things.recordsLoaded, set at install (index.js): the worldLoad reset step and 'world:load' after a wholesale replace (persist.js) @type {(info: { count: number }) => void} */ this._recordsLoaded = () => {};
|
|
31
32
|
initState(this, cellSize);
|
|
32
33
|
/** All records: id → record (read-only; use set to change fields, move to change position) @type {Map<string, WorldRecord>} @experimental */
|
|
33
34
|
this.records = new Map();
|
package/modules/world/index.js
CHANGED
|
@@ -50,6 +50,7 @@ export function world(opts = {}) {
|
|
|
50
50
|
ctx.track(e.onFixed(() => w._v.pull(), { phase: 'late' }));
|
|
51
51
|
ctx.track(e.time.onMove(() => w._s.moved()));
|
|
52
52
|
ctx.saves.define('world', { atomic: true, version: 5, migrate: WORLD_MIGRATE, save: () => w.toJSON(), load: d => w.fromJSON(d), checkNewGame: codePlaced });
|
|
53
|
+
w._recordsLoaded = ctx.things.recordsLoaded;
|
|
53
54
|
ctx.things.addSource(recordSource(w)); // engine.thing / thing.set / the shared id space reach the records through this
|
|
54
55
|
ctx.things.explainWith(worldExplain);
|
|
55
56
|
ctx.budget.metric('worldRecords', () => w.records.size);
|
package/modules/world/persist.js
CHANGED
|
@@ -209,7 +209,7 @@ export function loadWorld(w, d) {
|
|
|
209
209
|
for (const [id, base] of w._base) if (!w._removed.has(id)) w._insert(w._fromBase(id, base));
|
|
210
210
|
for (const [id, r] of Object.entries(d?.records || {})) w._insert({ id, ...r });
|
|
211
211
|
if (built) w._v.keepSame(built);
|
|
212
|
-
w.
|
|
212
|
+
w._recordsLoaded({ count: w.records.size }); // ctx.things.recordsLoaded: the modules' worldLoad step, then 'world:load' (core/saves/session.js step 2)
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "threedog",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Web 3D game engine on three.js:
|
|
3
|
+
"version": "2.0.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
|
@@ -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;
|
|
@@ -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' });
|
|
@@ -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/types/core.d.ts
CHANGED
|
@@ -86,6 +86,8 @@ export interface EventMap extends GameEvents {
|
|
|
86
86
|
'settings:shadows': [on: boolean];
|
|
87
87
|
/** A value in the settings menu changed (the argument is all setting values) */
|
|
88
88
|
'settings:change': [values: Record<string, any>];
|
|
89
|
+
/** engine.tier changed (device found at start, a preset, a write): resize what was sized from it */
|
|
90
|
+
'tier:change': [{ tier: 'low' | 'high' }];
|
|
89
91
|
/** A post effect was added (its name) */
|
|
90
92
|
'post:add': [name: string];
|
|
91
93
|
/** A water body was added */
|
|
@@ -189,7 +191,7 @@ export interface EventMap extends GameEvents {
|
|
|
189
191
|
/**
|
|
190
192
|
* 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
193
|
* 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-
|
|
194
|
+
* joints here (recipes/11-physics.md, Joints). Not emitted while a vehicle exists (the world is kept then, joints included)
|
|
193
195
|
*/
|
|
194
196
|
'rigid:rebuilt': [{ world: any; player: any; bodies: Record<string, any> }];
|
|
195
197
|
/** 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 */
|
|
@@ -1051,7 +1053,7 @@ export interface ModuleCtx {
|
|
|
1051
1053
|
/** engine.budget.metric, owned */
|
|
1052
1054
|
budget: { metric(name: string, read: () => number, opts?: { limit?: number }): Handle };
|
|
1053
1055
|
/** 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 };
|
|
1056
|
+
things: { addSource(source: any): Handle; explainWith(fn: (e: Engine, thing: any, out: any) => void): Handle; recordsLoaded(info: { count: number }): void };
|
|
1055
1057
|
/**
|
|
1056
1058
|
* 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
1059
|
* addColliders: more static colliders in engine.ground.forEachCollider, whoever gives the ground.
|
|
@@ -1144,8 +1146,15 @@ export interface ModuleDef<Api = any> {
|
|
|
1144
1146
|
content?: Record<string, ContentSection>;
|
|
1145
1147
|
/** 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
1148
|
isReady?(e: Engine): boolean;
|
|
1147
|
-
/**
|
|
1149
|
+
/** 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.
|
|
1150
|
+
* Every reset step runs in engine.moduleOrder (stage, before / after), before the matching event (session:end) reaches the game */
|
|
1151
|
+
sessionEnd?(e: Engine): void;
|
|
1152
|
+
/** 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 */
|
|
1153
|
+
worldLoad?(e: Engine, info: { count: number }): void;
|
|
1154
|
+
/** 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
1155
|
afterLoad?(e: Engine, turn: SaveTurn): void | Promise<void>;
|
|
1156
|
+
/** Session reset, step 4: a new playthrough began (not after a quick load), before 'session:start' */
|
|
1157
|
+
sessionStart?(e: Engine, info: { kind: 'new' | 'load'; slot?: string }): void;
|
|
1149
1158
|
/** Fixed step (60 times per second); dt is in seconds */
|
|
1150
1159
|
fixed?(dt: number, e: Engine): void;
|
|
1151
1160
|
/** Once per frame; dt is in seconds */
|
|
@@ -1722,7 +1731,7 @@ export declare class Engine {
|
|
|
1722
1731
|
validate: boolean;
|
|
1723
1732
|
/** three.js renderer: WebGLRenderer, or WebGPURenderer on the WebGPU route (EngineRenderer) */
|
|
1724
1733
|
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) */
|
|
1734
|
+
/** 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
1735
|
tier: 'low' | 'high';
|
|
1727
1736
|
/** three.js scene */
|
|
1728
1737
|
scene: import('three').Scene;
|
|
@@ -1988,7 +1997,7 @@ export declare class Engine {
|
|
|
1988
1997
|
dialogue?: Dialogue;
|
|
1989
1998
|
/** Inventory (inventory() module). Items, counts and containers, saved with the game. Install: engine.use(inventory()); undefined until installed. add() answers { ok }, read .ok */
|
|
1990
1999
|
inventory?: Inventory;
|
|
1991
|
-
/** pickups(). Things on the ground that go in the bag. Install: engine.use(
|
|
2000
|
+
/** 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
2001
|
pickups?: Pickups;
|
|
1993
2002
|
/** Quests (quests() module) */
|
|
1994
2003
|
quests?: Quests;
|
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;
|
|
@@ -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;
|
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;
|