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
package/core/scene/tier.js
CHANGED
|
@@ -23,8 +23,25 @@ export function onTierChange(e, fn) {
|
|
|
23
23
|
FOLLOWERS.get(e).add(fn);
|
|
24
24
|
return { remove: () => { FOLLOWERS.get(e)?.delete(fn); } };
|
|
25
25
|
}
|
|
26
|
-
/**
|
|
27
|
-
|
|
26
|
+
/** @type {WeakMap<any, string>} per engine: the tier last announced by 'tier:change' */
|
|
27
|
+
const ANNOUNCED = new WeakMap();
|
|
28
|
+
/** The tier stack was just defined (core/engine/services.js): its first value is the baseline the first 'tier:change' differs from @param {any} e */
|
|
29
|
+
export function tierDefined(e) { ANNOUNCED.set(e, e.tier); }
|
|
30
|
+
/**
|
|
31
|
+
* The tier stack's onChange (core/engine/services.js). The engine's own parts first, then the public 'tier:change' event: game code sizes what it
|
|
32
|
+
* makes from engine.tier and follows this event (a shadow map, a pool), so a preset reaches it like it reaches the post chain.
|
|
33
|
+
* The stack calls this on every take and release, also when the value stays (a preset equal to the device's tier, engine.tier written under a
|
|
34
|
+
* preset), so the event fires only when the tier differs from the last one announced. Nothing during dispose: settings, disposed first, gives
|
|
35
|
+
* its tier back then, and a follower would allocate (particles, a shadow map) on an engine being torn down. @param {any} e
|
|
36
|
+
*/
|
|
37
|
+
export function tierChanged(e) {
|
|
38
|
+
if (e.disposed) return;
|
|
39
|
+
for (const fn of [...(FOLLOWERS.get(e) ?? [])]) fn();
|
|
40
|
+
const t = e.tier;
|
|
41
|
+
if (t === ANNOUNCED.get(e)) return;
|
|
42
|
+
ANNOUNCED.set(e, t);
|
|
43
|
+
e.events?.emit('tier:change', { tier: t });
|
|
44
|
+
}
|
|
28
45
|
|
|
29
46
|
/** The name under engine.saves.storageKey of a player's MSAA choice */
|
|
30
47
|
export const MSAA_KEY = 'msaa';
|
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,13 +119,13 @@ 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 |
|
|
126
126
|
|---|---|---|
|
|
127
127
|
| Broke; describe, explain, shot: which tool | `.threedog/errors.log`, `engine.describe`, `engine.explain` | 16-dev-bridge.md §11 |
|
|
128
|
-
| Picture looks wrong: judge it | `threedog shot` | 60-judge-the-picture.md §"How to judge" |
|
|
128
|
+
| Picture looks wrong: judge it | `threedog shot` (points in `shots.json`; `threedog hub` re-shoots them) | 60-judge-the-picture.md §"How to judge" |
|
|
129
129
|
| Drive and check the live game | the dev bridge (`verify <scenario>`) | 16-dev-bridge.md §1 |
|
|
130
130
|
| Slow, low fps | `engine.jobs`, `engine.threads`, `engine.budget`, `engine.debug` | 15-perf.md §1 |
|
|
131
131
|
| Deploy | `npm run build` | 61-deploy.md |
|
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
|
|
@@ -220,12 +220,12 @@ 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
230
|
| settings:shadows | render/shadows.js | vegetation |
|
|
231
231
|
| state:applied | core/inspect/UrlState.js | — |
|
|
@@ -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 -->
|
|
@@ -88,6 +88,7 @@ export const specs = [{
|
|
|
88
88
|
| `threedog tune show [-w game]` · `threedog tune write [file] [--apply] [-w game]` | Values from `.threedog/tune.json` as one `// threedog:tune begin ... end` block of plain three.js writes (`engine.scene.fog.far = 90;`, `material.setValues` by name, UI CSS variables) in `file`. A later write merges into the block, so values the panel no longer holds stay; delete a line to drop it. Model generator params (the panel's models folder) become the `default` in that model's `params` schema where it is registered (no file needed for those). Without `--apply` it only prints the diff. `recipes/35-picture-from-reference.md` |
|
|
89
89
|
| Tuning without a mouse | Try values with `threedog js` (`engine.scene.fog.far = 90`), look with `threedog snap`, then write the result into `.threedog/tune.json` as `{ "values": { "engine.scene.fog.far": 90, "engine.scene.background": "#336699" }, "css": { "accent": "#7fd3ff" }, "materials": { "rock": { "roughness": 0.8 } }, "models": { "tree": { "height": 4 } } }` and run `threedog tune write main.js --apply`, or write the value straight into the code |
|
|
90
90
|
| `threedog gallery [-w game]` · `threedog gallery --shots [--mode …] [--light …] [--material name]` | Every registered model and texture on a turntable under three neutral light setups (tone mapping copied from the game), and the look-dev page (recipe 05 "Look-dev"). Without `--shots` it serves the game in dev and prints the `?gallery=1` URL; `--shots` writes `.threedog/gallery/` pictures, `index.html` and `index.json` headless, and `--mode` adds review pictures (silhouette, value, material channels) with measured facts and no thresholds. Options: `threedog gallery --help`. `recipes/05-props-bake.md` section 2c |
|
|
91
|
+
| `threedog hub [--port 5180] [--no-open] [--shortcut]` | Local web page: a card per game, a screenshot wall per game (points in `shots.json`, fields as `threedog shot`), re-shot 30 s after file changes; new project, add folder. `--shortcut`: desktop icon (Windows). |
|
|
91
92
|
| `npm run build` | Bundle each workspace into its own dist/ |
|
|
92
93
|
| `threedog preview [game]` (or `-w game`, as for dev and build) | Serve a workspace's built dist/ (vite preview) to open the production build in a browser. It is the shipped game, so URL keys (`?play`, `?time`…) are not read; `shot`, `test` and `dev` read them, or set `createEngine({ urlState: true })` (`?fresh` stays dev-only) |
|
|
93
94
|
| `threedog relay [port]` | The WebSocket relay for the net module (default port 8787, no dependencies). `recipes/27-net.md` |
|
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/engine.md
CHANGED
|
@@ -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
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
- `ui:close` [id: string] A window was closed
|
|
25
25
|
- `settings:shadows` [on: boolean] Shadows were toggled
|
|
26
26
|
- `settings:change` [values: Record<string, any>] A value in the settings menu changed (the argument is all setting values)
|
|
27
|
+
- `tier:change` [{ tier: 'low' | 'high' }] engine.tier changed (device found at start, a preset, a write): resize what was sized from it
|
|
27
28
|
- `post:add` [name: string] A post effect was added (its name)
|
|
28
29
|
- `water:add` [body: WaterBody] A water body was added
|
|
29
30
|
- `water:remove` [body: WaterBody] A water body was removed
|
|
@@ -74,7 +75,7 @@
|
|
|
74
75
|
- `timeline:end` [{ id: number; ending: 'finished' | 'skipped' | 'dropped' | 'failed';… A cutscene ended; ending says how, error why it failed
|
|
75
76
|
- `template:stage` [TemplateStageEvent] A content template instance entered a new stage by growing (templates with stages)
|
|
76
77
|
- `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-
|
|
78
|
+
- `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
79
|
- `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
80
|
- `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
81
|
- `vegetation:remove` [VegetationRemoveEvent] A vegetation instance was chopped / removed
|
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/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
|
@@ -6,7 +6,7 @@ Sky dome and the sun / daylight / sky-color signals, from the calendar's time; i
|
|
|
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
7
|
|
|
8
8
|
## Methods and properties
|
|
9
|
-
- `sky.keyframes(rows
|
|
9
|
+
- `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
10
|
- `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
11
|
- `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
12
|
- `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());`
|
|
@@ -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.
|
|
@@ -135,7 +135,7 @@ The shape of an item on the ground is a model name from an asset pack, built thr
|
|
|
135
135
|
else a model named `pickup:<item id>`, else one named `pickup`, else a neutral gray box. A generator that returns bare geometry is drawn with
|
|
136
136
|
`engine.pickups.material` in the item's own `color`.
|
|
137
137
|
```js
|
|
138
|
-
engine.use(pickups({ color: 0xd8c070, size: 0.3, lift: 0.5 })); // default color, placeholder box, height above the ground
|
|
138
|
+
engine.use(world(), pickups({ color: 0xd8c070, size: 0.3, lift: 0.5 })); // default color, placeholder box, height above the ground
|
|
139
139
|
engine.pickups.material = new THREE.MeshStandardMaterial({ metalness: 0.8, roughness: 0.3 }); // swaps every box and geometry-only model; used as given
|
|
140
140
|
```
|
|
141
141
|
A pickup or item with its own `color`, and a vertex-colored geometry, draw with a copy of that material carrying the color. For one object of the game's own pass
|
|
@@ -16,20 +16,13 @@ engine.onFixed(dt => moveEnemies(dt), { channel: 'enemies' }); // this dt is al
|
|
|
16
16
|
`engine.mod(target, { owner, mul | add | set | clamp, for, clock })` is the one entry for every quantity several systems share (time channels,
|
|
17
17
|
`'clock.rate'`, `'freeze'`, your own from `engine.stacks.define(name, { base })`). It returns `{ remove() }`; `remove()` ends only this owner's entry.
|
|
18
18
|
Details, only when you need them:
|
|
19
|
-
- One entry per owner
|
|
20
|
-
in any order (bullet time ending under a stopwatch never "restores" a stale value).
|
|
21
|
-
- Combine order and conflicts: `55-mods-time-wrap.md` (one layer table for every shared value; a stopwatch `set: 0, layer: 'effect'` beats any
|
|
22
|
-
slow-down; two owners `set` on one layer is an error in development).
|
|
19
|
+
- One entry per owner, layers and conflicts: `55-mods-time-wrap.md`.
|
|
23
20
|
- `for: seconds` ends it by itself, counted on `clock`: `'real'` (default; real seconds, which stop while frozen, so a pause menu does not use up a
|
|
24
|
-
bullet time) or a channel name (`clock: 'enemies'`:
|
|
21
|
+
bullet time) or a channel name (`clock: 'enemies'`: slowed by bullet time too). Each end emits `mod:end`
|
|
25
22
|
`{ target, owner, id }`. Saved with the time left; `engine.skip` ends them at the right point of the jump.
|
|
26
23
|
- One record only: `engine.mod('time.local', { owner: 'stopwatch', id: 'slime_3', set: 0, layer: 'effect' })` (its speed = channel x local).
|
|
27
24
|
`world.remove(id)` drops that record's entries.
|
|
28
|
-
- Reading: `engine.time.scale(
|
|
29
|
-
holders. Saved: entries below `'system'`; `system` / `debug` ones (menus, debug panel) are screen state and are taken again after a load.
|
|
30
|
-
- Freeze is not speed 0: a frozen engine runs no fixed step, so no channel moves, no `for` runs down and input is not read.
|
|
31
|
-
- Plain JS keeps working: your own fields and `onFixed(dt => ...)` logic need none of this. Use `engine.mod` for quantities more than one system writes.
|
|
32
|
-
- Order inside a fixed step: `onFixed(fn)` runs before the modules (player not moved yet), `onFixed(fn, { phase: 'late' })` after them. Stacks, `input.gate` and `engine.wrap` together: recipe 55.
|
|
25
|
+
- Reading: `engine.time.scale(ch, id?)`, `engine.time.now(ch)`; `describe().time.channels` lists speeds and holders. Saved: entries below `'system'`; `system` / `debug` ones (menus, debug panel) are screen state and are taken again after a load.
|
|
33
26
|
|
|
34
27
|
## The time table (the single source; other docs link here)
|
|
35
28
|
**One time source.** `engine.time` counts one thing, `engine.time.tick` (fixed steps run). Every other time is a
|
|
@@ -170,4 +170,3 @@ One place listens to window focus, tab visibility, mouse lock and the WebGL cont
|
|
|
170
170
|
`page:pointerlock { locked, byEngine }` (cameras lock again on the next click; a lock the player ended counts as Esc, because the browser keeps that key), `page:contextlost` / `page:contextrestored` (the same freeze, and the player
|
|
171
171
|
sees a message; three.js restores the context).
|
|
172
172
|
- `engine.step()` still advances while away (tests, dev bridge). Held keys are released by Input.
|
|
173
|
-
- Tests: `threedog test "Session:" "Window:"`.
|
|
@@ -24,8 +24,8 @@ hierarchy are kept; faces are not reduced. Only changed files are processed; `--
|
|
|
24
24
|
|
|
25
25
|
## 3. Putting it in the game (main.js)
|
|
26
26
|
```js fragment
|
|
27
|
-
import { presets, level, collision, followCamera, characters, interactions, dialogue, triggers, content, hlod } from 'threedog';
|
|
28
|
-
engine.use(level({ url: '/models/town.glb' }), collision(), followCamera(), characters(), interactions({ ...presets.interactions.nearest }), dialogue(), triggers(), content(), hlod());
|
|
27
|
+
import { presets, level, world, collision, followCamera, characters, interactions, dialogue, triggers, content, hlod } from 'threedog';
|
|
28
|
+
engine.use(level({ url: '/models/town.glb' }), world(), collision(), followCamera(), characters(), interactions({ ...presets.interactions.nearest }), dialogue(), triggers(), content(), hlod());
|
|
29
29
|
engine.events.once('level:loaded', () => { // once: level:loaded fires again on every level change
|
|
30
30
|
engine.characters.addPlayer({ ...presets.player.thirdPerson, spawn: engine.level.spawn });
|
|
31
31
|
engine.content.load(data); // a place in content can be a marker name directly: { place: 'npc_shopkeeper' }
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
> **Covers:** rigid bodies, pushing, joints, vehicles, boarding and driving, ragdolls.
|
|
4
4
|
> **Use when:** crates that tumble, doors on hinges, a car or a boat.
|
|
5
5
|
> **Shortest:** `engine.rigid.addBox(mesh, { id })` with `rigid()` installed (§3).
|
|
6
|
-
> **Sections:** 1 Build a car · 2 Boarding and driving · 3 Rigid bodies saves · 3b Ragdoll experimental) · 4 Verify
|
|
6
|
+
> **Sections:** 1 Build a car · 2 Boarding and driving · 3 Rigid bodies saves · 3b Ragdoll experimental) · 3c Explosions, stacks, solver · 4 Verify
|
|
7
7
|
|
|
8
8
|
Any physics body (crates the player pushes, balls, doors on hinges, ropes): §3, read it first when the game has no car. Cars and
|
|
9
9
|
boarding: §1–2.
|
|
10
10
|
|
|
11
|
-
Required modules: `collision()` + `rigid()` (Rapier
|
|
11
|
+
Required modules: `collision()` + `rigid()` (Rapier, with the vehicle controller) + `world()` + `characters()` (the player and NPCs are world records). With
|
|
12
12
|
`interactions({ ...presets.interactions.nearest })` installed, a "board/exit" prompt (E key) appears automatically near a vehicle.
|
|
13
13
|
Convention: **the front of the car faces the model's +Z**, and a wheel's `position` is relative to the body origin (meters). Rapier has to be
|
|
14
14
|
downloaded and initialized, so build the car after `engine:ready`.
|
|
@@ -59,7 +59,7 @@ This section covers every `engine.rigid` body (crates, balls, hulls, vehicles),
|
|
|
59
59
|
ahead. The mover leaves dynamic bodies out of its own collision, so a body is pushed instead of stopping the player; how hard it resists is
|
|
60
60
|
its `mass` and friction. A body that should stop the player is `{ fixed: true }` with `mover: 'rapier'` (that mover collides with fixed bodies).
|
|
61
61
|
A puzzle reads the result from the body (`entry.body.translation()` in `onFixed`, or a trigger zone) and gives the body an `id`, so a save keeps
|
|
62
|
-
where it was pushed.
|
|
62
|
+
where it was pushed.
|
|
63
63
|
|
|
64
64
|
**Far bodies freeze.** On chunked terrain only the chunks within `rigid({ terrainRing })` of the player (default 1 ring) have terrain colliders. A
|
|
65
65
|
body outside them stops (`entry.enabled` is false, `describe().rigid.frozen` counts them) instead of falling through the ground, and goes on when
|
|
@@ -93,8 +93,7 @@ stay). Removing a body removes its joints (Rapier does that).
|
|
|
93
93
|
|
|
94
94
|
**Determinism**, the one place this is stated (replay, `engine.step`, saves and net link here):
|
|
95
95
|
- Same build, same machine, same inputs and the same number of fixed steps give bit-identical bodies, in a fresh page and at any frame rate.
|
|
96
|
-
Physics only advances in fixed steps.
|
|
97
|
-
`mover: 'rapier'` player, two fresh pages, `frameEvery` 1 / 2 / 4.
|
|
96
|
+
Physics only advances in fixed steps.
|
|
98
97
|
- A load restores each saved body exactly. Rapier's contact and warm-start caches and its solver order are not saved, so the run after a load
|
|
99
98
|
is not bit-identical to the run that went on without the load: a toppling stack can end some centimetres away. Bodies at rest stay at rest.
|
|
100
99
|
- Across machines: the engine uses `@dimforge/rapier3d-compat`, which Rapier does not promise to be cross-platform deterministic (that is the
|
|
@@ -127,6 +126,15 @@ engine.clock.after(4, () => rd.remove(), { channel: 'real' }); // back to anima
|
|
|
127
126
|
Without `id` it covers every body; a function `(facts, engine) => graph` picks per body; `false` makes `ragdoll()` return null.
|
|
128
127
|
- **Left out:** partial or blended ragdoll (an arm thrown by a hit while the rest animates); `remove()` cuts to the animation.
|
|
129
128
|
|
|
129
|
+
## 3c. Explosions, stacks and solver settings (when to add bodies)
|
|
130
|
+
|
|
131
|
+
**When.** Calls that return a Rapier body (`addBox`, `addBall`, `addHull`, `addWheeled`, `ragdoll`) run after `await engine.start()`; `collider3d.addSolid` works before.
|
|
132
|
+
|
|
133
|
+
**Explosion.** Loop over `engine.rigid.bodies` and call `engine.rigid.impulse(b, dirFromBlast * falloff)`: it wakes a sleeping body first.
|
|
134
|
+
**Stacks.** The collider is exactly `size`; resting boxes overlap a little (soft contacts: ~0.7 cm a layer, ~5 cm under a body 50x heavier),
|
|
135
|
+
the same at 4, 8 or 16 solver iterations: keep touching masses close. Iterations (joint chains): `engine.rigid.world.integrationParameters.numSolverIterations`
|
|
136
|
+
(default 4), kept through newGame and a load.
|
|
137
|
+
|
|
130
138
|
## 4. Verify
|
|
131
139
|
- In a test (no real key presses): `engine.player.enter(car); engine.input.autopilot = { x: 0, y: 1 }; engine.step(3)`,
|
|
132
140
|
then `describe().player.vehicle.speed` is above 0 and the car has moved; after `engine.player.exit()`, `engine.player.vehicle` is null and the
|
|
@@ -14,8 +14,8 @@ There is a single pathfinding entry point: `engine.characters.findPath(from, to)
|
|
|
14
14
|
## 1. Install (main.js)
|
|
15
15
|
A level is a file or a `THREE.Object3D` built in code: `level({ scene: group })`, its meshes named as in `10-blender-level.md`.
|
|
16
16
|
```js fragment
|
|
17
|
-
import { level, collision, followCamera, characters, nav } from 'threedog';
|
|
18
|
-
engine.use(level({ url: '/models/town.glb' }), collision(), followCamera(), characters(),
|
|
17
|
+
import { level, world, collision, followCamera, characters, nav } from 'threedog';
|
|
18
|
+
engine.use(level({ url: '/models/town.glb' }), world(), collision(), followCamera(), characters(),
|
|
19
19
|
nav({ agentRadius: 0.4, agentHeight: 1.8, maxClimb: 0.45, maxSlope: 45, debug: false })); // debug: true draws the navmesh
|
|
20
20
|
```
|
|
21
21
|
- Mesh source: the walkable meshes in the level (naming convention in `10-blender-level.md`). Walls = the level's `col_` boxes + every
|
|
@@ -56,7 +56,7 @@ engine.characters.pathsPerStep = 64; // requests sent per fixed step (default 3
|
|
|
56
56
|
if either changes while a batch is in flight, that batch is recomputed on the main thread on the new state.
|
|
57
57
|
- With A*, ground shape (height, water, slope) is sampled on a 1 m raster cached 5 s, every floor of it, so what stands under a bridge or a storey counts as it does for `findPath` (colliders and terrain trees are tested exactly), and the search stays inside
|
|
58
58
|
the start-goal box plus a margin, so an async path can differ slightly from `findPath`'s.
|
|
59
|
-
- A save taken while a request is in flight does not keep it: the NPC asks again after loading.
|
|
59
|
+
- A save taken while a request is in flight does not keep it: the NPC asks again after loading.
|
|
60
60
|
|
|
61
61
|
## 5. One source for "can walk there"
|
|
62
62
|
`createEngine({ movement: { radius, height, maxSlope, stepHeight } })` sets it once; read it as `engine.movement`. Collision, the Rapier capsule, the
|
|
@@ -101,8 +101,8 @@ A module that does two kinds of thing is two definitions returned together (`wea
|
|
|
101
101
|
`engine.use` of the same module works; a save part's data stays in the save and goes back to the part when it registers again.
|
|
102
102
|
- Listeners and timers the module adds go through `ctx.track(...)`: `ctx.track(e.events.on('item:add', fn))`, also `onFixed` / `onFrame` /
|
|
103
103
|
`clock.after` / `audio.measure` / a `makeWindow` window, anything with `remove()`. They leave with the module: when its `engine.use(...)` batch
|
|
104
|
-
rolls back, when its `init` fails, and on `engine.dispose()` before its `dispose` hook
|
|
105
|
-
|
|
104
|
+
rolls back, when its `init` fails, and on `engine.dispose()` before its `dispose` hook.
|
|
105
|
+
A class the module builds takes `ctx` as a constructor argument. DOM listeners use
|
|
106
106
|
`addEventListener(type, fn, { signal: engine.signal })`, and UI elements attach to `engine.uiRoot` (not `document.body`); jobs and stream
|
|
107
107
|
entries are collected by `engine.dispose()`; scene GPU memory is its creator's: `engine.dispose()` does not free the meshes, materials and textures you made, so track their removal: `ctx.track({ remove: () => engine.remove(mesh) })` (`engine.remove` disposes geometry and materials, not their textures: three's `material.dispose()` leaves its maps, so dispose a texture you made when nothing uses it). The `dispose(e)`
|
|
108
108
|
hook frees the rest (Workers, the physics world, WASM objects, real-time timers), in reverse install order.
|
|
@@ -125,8 +125,9 @@ A module that does two kinds of thing is two definitions returned together (`wea
|
|
|
125
125
|
on all three paths: save, load, and new game (a new game loads the state captured when `start()` finished), so there is nothing to reset by
|
|
126
126
|
hand. What cannot be saved ends with its playthrough: a background result goes through `ctx.commits` (a load or new game drops old ones;
|
|
127
127
|
keep `ctx.commits.epoch` on a queued request and drop it when that changed), and an effect of a running playthrough (an open dialogue, a
|
|
128
|
-
running cutscene, the music playing) stops
|
|
129
|
-
|
|
128
|
+
running cutscene, the music playing) stops in `sessionEnd(e)`; derived state rebuilds in `worldLoad`, `afterLoad`, `sessionStart` (that order,
|
|
129
|
+
modules by `stage` / `before` / `after`, never install order; core/saves/session.js). Events are for game code; a rollback restores on
|
|
130
|
+
`'session:failed'`. `sessionEnd` only stops things. A module's `describe()` should show such state.
|
|
130
131
|
- When you only need a per-frame callback and no module structure: `const h = engine.onFrame(dt => ...)` / `engine.onFixed`, and `h.remove()` cancels it.
|
|
131
132
|
|
|
132
133
|
## 3. Extra steps when it goes into the engine
|
|
@@ -222,4 +222,3 @@ A save is one envelope; `engine.saves.collect()` returns it and `export` / `expo
|
|
|
222
222
|
progress by step ids (`steps: [{ id: 'talk-mayor', ... }]`, recipe 04). Content edits (a new step, a new prop) then never shift an old save.
|
|
223
223
|
- The export file wraps the envelope:
|
|
224
224
|
`{ threedog: 'save', format: 1, game, slot, savedAt, data: <envelope>, files: [{ group, id, at, meta, type, url: 'data:...' }] }`.
|
|
225
|
-
- Tests: `threedog test "Save failure"`.
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
> **Covers:** the four cameras (follow, first person, strategy, fixed), switching, framing, limits.
|
|
4
4
|
> **Use when:** choosing or tuning how the player sees the game.
|
|
5
5
|
> **Shortest:** `openWorld({ camera: 'firstPerson' })`.
|
|
6
|
-
> **Sections:** 1 Press V to · 2 What the engine · 3 Other common things · 4 Over the shoulder · 4b Looking up, ground · 4c Chase camera behind · 5 Take over the · 6 Orthographic view, and · 7 Your own camera
|
|
6
|
+
> **Sections:** 1 Press V to · 2 What the engine · 3 Other common things · 4 Over the shoulder · 4b Looking up, ground · 4c Chase camera behind · 5 Take over the · 6 Orthographic view, and · 6b Screen shake and · 7 Your own camera
|
|
7
7
|
|
|
8
8
|
Four cameras; the kind names are always: `'follow'` third-person follow · `'firstPerson'` first person · `'rts'` top-down strategy · `'fixed'` fixed shots.
|
|
9
9
|
Pick one at the start: `openWorld({ camera: 'firstPerson' })`, or by hand `engine.use(followCamera({ distance: 10 }))` /
|
|
@@ -197,6 +197,16 @@ A camera module goes on placing the camera you assigned, and one assigned during
|
|
|
197
197
|
engine.use(followCamera({ projection: 'orthographic', size: 15, yaw: 0, pitch: 0, lockPitch: true, distance: 40, ground: 'none', mouseLook: false }));
|
|
198
198
|
```
|
|
199
199
|
|
|
200
|
+
## 6b. Screen shake and other camera offsets (the camera keeps following)
|
|
201
|
+
|
|
202
|
+
A direct camera write takes the camera (recipe 52); a shake is an offset on the drawn frame only:
|
|
203
|
+
```js fragment
|
|
204
|
+
const pose = new THREE.Vector3(); let shake = 0; // yours: raise it on a hit, let it fall in onFrame
|
|
205
|
+
engine.onRender(({ camera }) => { pose.copy(camera.position); camera.position.y += (Math.random() - 0.5) * shake; });
|
|
206
|
+
engine.onRender(({ camera }) => { camera.position.copy(pose); camera.updateMatrixWorld(); }, { when: 'after' }); // back: no warning, picking sees the real pose
|
|
207
|
+
```
|
|
208
|
+
Aim that should climb (recoil) is `cameraRig.pitch` (recipe 32).
|
|
209
|
+
|
|
200
210
|
## 7. Your own camera module
|
|
201
211
|
Everything else in the engine reads only what `modules/camera/contract.js` lists from `engine.cameraRig`: `forward()` / `right()` (control: 'camera',
|
|
202
212
|
faceMode 'camera', targeting), `follow(object, opts?)` (addPlayer, getting in and out of a vehicle), `focusPoint()` (photo, where the world loads)
|
package/docs/recipes/27-net.md
CHANGED
|
@@ -75,7 +75,7 @@ engine.ops.define('cheat.gold', { args: { n: 'int' }, run: (e, { n }, ctx) => e.
|
|
|
75
75
|
The host sends a full snapshot when a client joins (or after a lost message), then diffs every `syncEvery` fixed steps (default 3, 20 per second):
|
|
76
76
|
world records, containers, `vars`, and every other save part (quests, clock, sky, weather...) except `random`, `level` and `rigid`. Choose explicitly with
|
|
77
77
|
`sync: ['world', 'containers', 'vars', 'quests']`. Physics runs on each machine and is not synced, and machines need not agree on it
|
|
78
|
-
(why: [11-
|
|
78
|
+
(why: [11-physics.md, Determinism](11-physics.md#3-rigid-bodies-saves-joints-determinism)).
|
|
79
79
|
On a client the mirror is applied at the next fixed step; `world.simulate` does not run there (the host simulates). Other players glide between
|
|
80
80
|
updates (kinds in `interpolate`, default `['player']`). The client moves its own avatar and reports its position; the host clamps it to `maxSpeed`
|
|
81
81
|
(m/s, default 15).
|
package/docs/recipes/29-grid.md
CHANGED
|
@@ -15,7 +15,7 @@ Works on any ground: procedural terrain, a Blender level, an indoor floor. Heigh
|
|
|
15
15
|
## 1. Grids and items
|
|
16
16
|
```js
|
|
17
17
|
import { grids, toast } from 'threedog';
|
|
18
|
-
engine.use(grids());
|
|
18
|
+
engine.use(world(), grids());
|
|
19
19
|
const board = engine.grids.add('board', { cell: 1, origin: [0, 0], size: [16, 12] }); // several grids may exist: a tower-defense board,
|
|
20
20
|
const room = engine.grids.add('room', { cell: 0.5, origin: [-3, -3], size: [12, 12], zone: 'house' }); // a dungeon or house room,
|
|
21
21
|
const plot = engine.grids.add('plot', { cell: 1, origin: [20, 0], size: [8, 8] }); // a garden plot
|
|
@@ -63,7 +63,7 @@ engine.renderer.toneMapping = THREE.NeutralToneMapping; // the curve; materials
|
|
|
63
63
|
```
|
|
64
64
|
The engine picks no curve: `renderer.toneMapping` stays three.js's default (`NoToneMapping`) until your code writes it. A curve of your own is a post effect in the `'tone'` slot (recipe 52).
|
|
65
65
|
|
|
66
|
-
Exposure that adapts like an eye (WebGPU): `engine.post.add(autoExposure({ min: 0.25, max: 4 }))` from `@threedog/post-effects/tsl`
|
|
66
|
+
Exposure that adapts like an eye (WebGPU): `engine.post.add(autoExposure({ min: 0.25, max: 4 }))` from `@threedog/post-effects/tsl` eases the average GPU-measured brightness toward `key`. It multiplies after everything that adds light, before tone mapping (`toneMappingExposure` still applies on top). Bloom runs before it (bright daylight glows, then darkens): raise bloom's `threshold` or give it an `order` above 800. Narrow `min` / `max` for an authored look; `speedUp` / `speedDown` (on `engine.time`); a chain rebuild keeps the adapted value. It measures a 64x64 sample: a small, very bright thing nudges it.
|
|
67
67
|
|
|
68
68
|
## Environment maps
|
|
69
69
|
`scene.environment` is plain three.js and stays `null` until your code writes it. The background (the sky dome or a skybox) and the environment lighting are two separate fields.
|
|
@@ -86,11 +86,13 @@ On `renderer: 'webgpu'` take `PMREMGenerator` from `three/webgpu`. A map you mad
|
|
|
86
86
|
- With `into`, that object's `.environment` gets the map at each rebuild. A map you write there yourself stays: the rebuilds go on, but only `handle.texture` follows them.
|
|
87
87
|
- The dome is rendered into a cube (at least 256 px a face) and prefiltered with `PMREMGenerator`, rebuilt only when sky colors, sun direction or cloud cover changed
|
|
88
88
|
AND `interval` seconds passed (default 1, 4 on a low tier; yours stands). A fixed time of day builds once; a call before the first frame waits for it. A second call replaces the first.
|
|
89
|
+
A rebuild is one cube render; no material builds again, so a moving day can light the scene with its sky.
|
|
89
90
|
- An asset map is a fixed photo: it does not dim at night. Write `scene.environmentIntensity` from your own frame code reading `engine.uniforms.uDaylight`.
|
|
90
91
|
|
|
91
92
|
### What a MeshLambertMaterial does with it (three 0.187)
|
|
92
|
-
The engine's neutral materials are Lambert:
|
|
93
|
-
|
|
93
|
+
The engine's neutral materials are Lambert: soft ambient light colored by the environment by direction, no specular (reflections need Standard / Physical).
|
|
94
|
+
Both renderers alike; a `MeshLambertNodeMaterial` you build reads only its own `envMap`.
|
|
95
|
+
A hemisphere light adds on top: lower it. The first frame with an environment recompiles every Lambert program once: do it at start-up.
|
|
94
96
|
- Toon, Basic and ShaderMaterial surfaces ignore it.
|
|
95
97
|
|
|
96
98
|
## Light probes (baked indirect light)
|
|
@@ -114,7 +114,7 @@ m.colorNode = mix(color(0x2a5a7a), mirror, 0.6); // 0 = water color, 1 = pure r
|
|
|
114
114
|
engine.water.material = m;
|
|
115
115
|
```
|
|
116
116
|
- Cost: the whole scene drawn once more per frame per water mesh at `textureWidth` x `textureHeight` (shadows are not re-rendered). Use 256-512
|
|
117
|
-
on phones; on `engine.tier
|
|
117
|
+
on phones; on `engine.tier` 'low' keep the default material instead; again on `'tier:change'`.
|
|
118
118
|
- One mirror plane: the material is shared, so water bodies at other levels need `water({ sea: false })` or their own mirror. The Reflector's
|
|
119
119
|
shader has no waves or fog; for both, copy its `fragmentShader` into a `MeshPhongMaterial` patch that samples `tDiffuse` with `textureMatrix`.
|
|
120
120
|
- three's `Refractor` addon (next to `Reflector`) reads `matrixWorld` as an XY plane too, so the same adapter applies (not covered by a test).
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
const sun = new THREE.DirectionalLight('#fff4e0', 3);
|
|
10
10
|
sun.position.set(40, 80, 30);
|
|
11
11
|
sun.castShadow = true;
|
|
12
|
-
|
|
12
|
+
const fit = () => engine.shadows.mapSize(sun, engine.tier === 'low' ? 1024 : 2048);
|
|
13
|
+
fit(); engine.events.on('tier:change', fit);
|
|
13
14
|
engine.scene.add(sun);
|
|
14
15
|
if (engine.lights.sun) engine.lights.sun.castShadow = false; // WebGL: cascades must be the only shadowing DirectionalLight (or createEngine({ lights: false }))
|
|
15
16
|
|
|
@@ -73,7 +74,7 @@ It works with and without a sky, on both renderers (WebGPU needs `import 'threed
|
|
|
73
74
|
`light.position` and `light.target` hold that placement: writes to `light.position` or a new `light.target` still set the direction, and
|
|
74
75
|
`remove()` puts both back as you left them, with the shadow camera box. A `light.target` you assigned (your player, say) is never moved.
|
|
75
76
|
- `engine.tier === 'low'` gets one map unless you pass `low: { count: 2 }`. That map covers `maxFar / count` each way, so its texels are as small as an average cascade's: the low tier
|
|
76
|
-
saves shadow passes and draws shadows less far, not blurrier
|
|
77
|
+
saves shadow passes and draws shadows less far, not blurrier, rebuilt on a tier change. On a game's light it follows the
|
|
77
78
|
camera, shifted half its size ahead of the view, and never stops at the origin; like cascades it places the light, so `engine.shadows.box` on that light is refused. On `engine.lights.sun` the
|
|
78
79
|
one map stays the engine's own box around the focus, sized the same way. `count: 1` (one map on every tier) covers all of `maxFar`. `handle.csm` is null while there is one map.
|
|
79
80
|
- An engine draws one set of cascades: a second handle throws. A box on the same light throws too, except the engine's own box on `engine.lights.sun`, which waits
|
|
@@ -174,9 +175,11 @@ engine.renderer.shadowMap.type = THREE.VSMShadowMap; // BasicShadowMap | PCFSha
|
|
|
174
175
|
const sun = new THREE.DirectionalLight(0xffffff, 2);
|
|
175
176
|
sun.shadow.radius = 3; sun.shadow.blurSamples = 8; // softness (pcf, vsm); blur quality (vsm)
|
|
176
177
|
sun.shadow.bias = -0.0001; sun.shadow.normalBias = 0.03;
|
|
177
|
-
|
|
178
|
+
engine.shadows.mapSize(sun, 2048); // any time: after the first frame it reallocates the map
|
|
178
179
|
```
|
|
179
180
|
|
|
181
|
+
Soft shadows on three 0.187: `PCFSoftShadowMap` is gone (it logs a warning and gives `PCFShadowMap`). Keep `PCFShadowMap` and widen `light.shadow.radius`; `VSMShadowMap` blurs more.
|
|
182
|
+
|
|
180
183
|
PCF's `radius` is in shadow texels, so the blur in meters is `radius x 2 x extent / mapSize`: halve the map (a low-tier size) and keep the radius, and the blur doubles. Scale them
|
|
181
184
|
together, `sun.shadow.radius = Math.max(Math.min(R, 2), R * size / 2048)` for a radius `R` tuned on the 2048 map, as the engine's own sun does (`R` = 3): under about 2 texels PCF shows the map's stair steps.
|
|
182
185
|
|