threedog 1.4.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 +34 -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 +2 -2
- package/docs/CODEMAP.md +5 -5
- package/docs/COMMANDS.md +2 -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
|
@@ -59,19 +59,19 @@ effect has a name, a handle and a row in `describe().slots` and `describe().rend
|
|
|
59
59
|
|
|
60
60
|
Each runs in a slot, then by `order` (low first): `scene` (replaces the scene render, one at a time, e.g. pixelation) -> `hdr` (linear color: outline, AO, bloom) -> `tone` (replaces the tone-mapping output, one at a time; it must output display color) -> `ldr` (sRGB: LUT, palette, grain, vignette) -> `final` (FXAA / SMAA).
|
|
61
61
|
|
|
62
|
-
A plain Pass is placed by its kind: one that renders `engine.scene` itself (`RenderPixelatedPass`, `SSAARenderPass`, `TAARenderPass`) goes in `scene` and replaces the engine's scene render (a second one throws), FXAA / SMAA
|
|
62
|
+
A plain Pass is placed by its kind: one that renders `engine.scene` itself (`RenderPixelatedPass`, `SSAARenderPass`, `TAARenderPass`) goes in `scene` and replaces the engine's scene render (a second one throws; your own Pass that draws the scene says so with `{ slot: 'scene' }`). Passes that hold `scene` and `camera` only to read the scene render (`GTAOPass`, `SAOPass`, `SSAOPass`, `SSRPass`, `BokehPass`) are ordinary `hdr` passes, FXAA / SMAA in `final`, any other in `hdr` after the effects already there (`ldr` when you added it after an OutputPass); a RenderPass of `engine.scene` and an OutputPass are skipped (the engine has them). AO, bloom and outline are `ao()`, `bloom()`, `outline()` of `@threedog/post-effects`. Without `{ name }` it is listed by class or shader name (`CopyShader#1`); its `remove()` does not dispose it.
|
|
63
63
|
|
|
64
64
|
To read the chain: `engine.post.object()` and `engine.post.targets()`; both stay the engine's (it rebuilds, resizes, disposes), so change the chain through `engine.post`, or take it over with `engine.post.own()` (`own(false)` gives it back). A game that renders the canvas itself (its own composer) takes the frame: the engine stops drawing and warns once `[own-frame]`.
|
|
65
65
|
```js fragment
|
|
66
|
-
import { bloom, outline, vignette, lut } from '@threedog/post-effects'; // shared effects come from the add-on
|
|
66
|
+
import { bloom, outline, vignette, lut, grain } from '@threedog/post-effects'; // shared effects come from the add-on
|
|
67
67
|
import { LUTPass } from 'three/addons/postprocessing/LUTPass.js';
|
|
68
68
|
const line = engine.post.add(outline({ thickness: 1.5 })); engine.post.add(vignette());
|
|
69
69
|
line.enabled = false; // pauses it in place; a settings restriction above this still holds it off
|
|
70
70
|
engine.post.get('vignette').set({ strength: 0.6 }); // params by name; an unknown name throws
|
|
71
|
-
|
|
71
|
+
engine.post.add({ ...bloom(), skipOnLowTier: true }); // held while engine.tier is 'low', following a change
|
|
72
72
|
engine.post.add({ name: 'myLut', slot: 'ldr', params: { lut: myLut }, create: ({ params }) => new LUTPass({ lut: params.lut }) });
|
|
73
|
-
// a plugin file
|
|
74
|
-
export default
|
|
73
|
+
// a plugin file adds one with no main.js line: plugins/10-grain.js (a new game adds ao and bloom in picture/post.js)
|
|
74
|
+
export default grain({ amount: 0.04 });
|
|
75
75
|
```
|
|
76
76
|
- `bloom({ strength, radius, threshold })`, defaults 0.35, 0.5, 0.85 (glow added, spread 0 to 1, brightness a pixel needs to glow). It reads linear color before the tone curve, so a
|
|
77
77
|
surface brighter than 1 glows hard however small: if the frame washes out, raise `threshold` or dim that surface before lowering `strength`. On the WebGPU route three's own `BloomNode` is also open to you through `engine.post.add({ node })`.
|
|
@@ -129,7 +129,7 @@ Each of them is registered once (`core/ops/owned.js`), and every one behaves the
|
|
|
129
129
|
| `view.far` | view | terrain view range (`terrain.viewChunks`) | `engine.autoView.manual('far')` | - |
|
|
130
130
|
| `view.fov` | view | the settings menu fov slider, camera modules (first person / rts fov, fixed shots, back to the install fov on a switch) | `engine.autoView.manual('fov')` | - |
|
|
131
131
|
| `view.pixelRatio` | view | adaptive resolution, about once a second while slow | `engine.autoView.manual('pixelRatio')` | `engine.setPixelRatio(1.5)` |
|
|
132
|
-
| `camera` (position, rotation) | view | the camera module, every frame | `const cam = engine.takeCamera('me')` (`cam.remove()` gives it back) |
|
|
132
|
+
| `camera` (position, rotation) | view | the camera module, every frame | `const cam = engine.takeCamera('me')` (`cam.remove()` gives it back) | shake / offset: recipe 21 §6b |
|
|
133
133
|
| `post.chain` | post | whenever the effect list changes (add / remove / on / off, MSAA): the engine rebuilds the composer passes (WebGL) or `pipeline.outputNode` (WebGPU) | `engine.post.own()`: the built chain stays as you left it in `engine.post.object()`; `own(false)` rebuilds it from the list. A write to `object()` without `own()` does not yield: the next chain change replaces it | `engine.post.get('bloom').set({ strength: 0.6 })` |
|
|
134
134
|
| `shadow.csm` (not a property: a list) | shadow | while cascades are on: the `csm` patch goes on every built-in lit material, yours too (else N times as bright) | - (`handle.remove()`); your ShaderMaterial is left alone until `engine.shadows.include(mat)` | - |
|
|
135
135
|
|
|
@@ -53,8 +53,8 @@ With a preset the same switch gives crisp banks without more triangles: `terrain
|
|
|
53
53
|
|
|
54
54
|
Cost: the worker time per chunk is mostly your `groundType` called once per pixel, several times that of smooth at 128; 64 costs a quarter, 256 four times that.
|
|
55
55
|
Memory is `(colorResolution + 2)^2 x 4` bytes per chunk plus mipmaps (about 90 KB at 128, 23 KB at 64). The first frames pay one shader compile and the uploads, not a cost per frame.
|
|
56
|
-
On a low tier
|
|
57
|
-
|
|
56
|
+
On a low tier the default drops to 64 unless set by `colorResolution` (follows tier). To skip the color map there,
|
|
57
|
+
choose the shading: `shading: engine.tier === 'low' ? 'smooth' : 'texture'`, read once at `terrain({})`.
|
|
58
58
|
|
|
59
59
|
`variation` shapes *what* color a point gets; `shading` decides *where* it is evaluated. In vertex modes every variation is limited to cell size; in
|
|
60
60
|
texture mode it is sampled per pixel, so `patches: { size: 20, levels: 4 }` gives hard-edged color blocks, and a `jitter.size` below the pixel size
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
A shared value is something several owners change: the game, a module, an effect. Name it, say who you are, say how you change it:
|
|
9
9
|
|
|
10
10
|
```js
|
|
11
|
-
engine.time.channel('enemies'); // a channel of your own
|
|
11
|
+
engine.time.channel('enemies'); // a channel of your own (built-in ones: recipe 06)
|
|
12
12
|
const slow = engine.mod('time.enemies', { owner: 'bullet-time', mul: 0.35, for: 2 }); // bullet time; slow.remove() ends it early
|
|
13
13
|
engine.mod('time.world', { owner: 'hitstop', set: 0, layer: 'system', for: 0.06 }); // decide on a higher layer: hides everything below
|
|
14
14
|
|
|
@@ -31,12 +31,10 @@ What to remember:
|
|
|
31
31
|
- **`replaces` to swap an engine part** that `provides` a slot; a second provider without it is the error `shared-taken`. What the old part issued goes with it: read `engine.<slot>` where you use it, and keep the issuer beside any handle so you can compare (`if (from !== engine.rigid) { from = engine.rigid; crate = from.addBox(mesh); }`). Version numbers count per module, so they cannot tell two modules apart. The engine's own props, NPCs, pickups, cars and movers do this; a rider leaves a rigid car when rigid goes. `world` is the exception: it owns every record, so install your world before the modules that need it; once they are installed, or after `start()`, `replaces: 'world'` and `unuse('world')` are refused (`module-replaces`, `module-unuse`). A factory that gives two modules goes in whole: `engine.use(terrain(o), { replaces: 'terrain' })` swaps its drawing part too. A module of your own wraps `world.present`, `world.simulate`, `rays.addProvider`, `input.touchButton` and `assets.onSwap` in `ctx.track(...)`, so they leave with it.
|
|
32
32
|
- Every handle ends with `h.remove()` (`engine.mod`, `ctx.mod`, `input.gate`, `wrap`, `freeze`, `takeCamera`); it drops only your own entry.
|
|
33
33
|
|
|
34
|
-
Only things several parties
|
|
35
|
-
|
|
36
|
-
materials and textures are plain three.js: never registered, never a conflict. Which tool to reach for: `../CONVENTIONS.md` "Customization ladder".
|
|
34
|
+
Only things several parties write are shared values (time speeds, holders, move stats, input gates, shadow and post parameters); your own
|
|
35
|
+
objects stay plain three.js. Which tool to reach for: `../CONVENTIONS.md` "Customization ladder".
|
|
37
36
|
|
|
38
37
|
```js
|
|
39
|
-
engine.mod('time.player', { owner: 'haste', mul: 1.2, for: 5 }); // haste on the player
|
|
40
38
|
const menu = engine.freeze('pause-menu'); /* ... */ menu.remove(); // pause menu: the picture, UI and ambient uTime (wind, water, clouds) keep running; { still: true } stops those too
|
|
41
39
|
engine.input.gate('jump', { owner: 'stun', for: 1.5 }); // no jumping while stunned
|
|
42
40
|
engine.wrap(engine.inventory, 'add', (next, id, n = 1, o) => // a weight rule on top of the engine's inventory
|
|
@@ -55,12 +55,12 @@ hard-edged or pitch-dark look may want exactly what was measured. All of them re
|
|
|
55
55
|
| The check says | What it measured | Where it points |
|
|
56
56
|
|---|---|---|
|
|
57
57
|
| one shadow texel covers X m | the size on the ground of one shadow map pixel, when shadows do not show | cascades: `engine.shadows.cascades(engine.lights.sun, { count })` for the engine sun, `engine.shadows.cascades(light, { count: 3 })` on your own light ([recipe 45](45-cascaded-shadows.md)) |
|
|
58
|
-
| over budget | lit point and spot lights, shadow maps, the largest map size, against `engine.budget` | many lights: `engine.lightPool` ([recipe 09](09-materials-lights-models.md)); shadows: `castShadow`, `
|
|
58
|
+
| over budget | lit point and spot lights, shadow maps, the largest map size, against `engine.budget` | many lights: `engine.lightPool` ([recipe 09](09-materials-lights-models.md)); shadows: `castShadow`, `engine.shadows.mapSize` from `engine.tier`, again on `'tier:change'` |
|
|
59
59
|
| shadows nearly black | how much the fill adds on the shadowed pixels themselves | `engine.bakeProbes` ([recipe 34](34-environment-lighting.md)) or a fill light |
|
|
60
60
|
| shadow stripes, stepped edges | the shadow alone, at canvas pixels: several thin bands side by side, or edges that move when only the shadow map's pixel grid moves | the bias, map size and shadow range it lists; stairs also the cascades above |
|
|
61
61
|
| fog covers X% | how much of the picture is fog color; printed before a line about the night, since the fog comes first | `scene.fog` |
|
|
62
62
|
|
|
63
|
-
Limits a game sets per device go through the same check: `engine.budget.enable(engine.tier === 'low' ? { lights: 4 } : { lights: 12 })`. A limit you wrote is
|
|
63
|
+
Limits a game sets per device go through the same check: `engine.budget.enable(engine.tier === 'low' ? { lights: 4 } : { lights: 12 })`, again on `'tier:change'`. A limit you wrote is
|
|
64
64
|
reported as your own intent; the engine's default line (lights 8, shadow maps 7) is only a fact.
|
|
65
65
|
|
|
66
66
|
## Same knob, different styles
|
|
@@ -10,30 +10,26 @@ passes. The engine hands it signals (time of day, weather), keeps the engineerin
|
|
|
10
10
|
Working example: `examples/plain-picture/` (page `/plain-picture.html`). Every value has one writer, a line in your code.
|
|
11
11
|
|
|
12
12
|
## 0. The `picture/` folder: where all picture code goes
|
|
13
|
-
`threedog new-game` generates it,
|
|
13
|
+
`threedog new-game` generates it: gray surfaces under correct, neutral light (no style); it is yours to change or delete. One file per job, so the picture never piles up in one place:
|
|
14
14
|
```
|
|
15
15
|
picture/
|
|
16
16
|
index.js wiring: the picture module (engine.use(createPicture()), then engine.picture): creates the parts, calls each part's update(signals) in one engine.onRender; no values here
|
|
17
|
-
palette.js colors and key values for the whole game,
|
|
18
|
-
lights.js
|
|
17
|
+
palette.js colors and key values for the whole game, each with how to judge it in a shot
|
|
18
|
+
lights.js the key light from the signals, and the environment fill (scene.environment)
|
|
19
|
+
sky.js background, and fog in the horizon color when the game has a sky()
|
|
20
|
+
post.js tone curve, exposure, AO and bloom (@threedog/post-effects; one line each)
|
|
19
21
|
materials.js materials by name; other code asks for picture.materials.wall and never builds its own
|
|
20
|
-
sky.js add when the game has its own sky or fog
|
|
21
|
-
post.js add when the game has post effects
|
|
22
22
|
shaders/ your shader code: TSL .js on WebGPU (the default), .glsl on WebGL (a saved .glsl hot-reloads)
|
|
23
23
|
areas/<name>.js a large game's overrides for one area (a cave, an interior): only what differs
|
|
24
24
|
```
|
|
25
25
|
To add a part, write a file that returns `{ update(signals) }` and call it from `index.js`, handing it the module's `ctx` so what it adds leaves with the picture:
|
|
26
26
|
```js
|
|
27
|
-
// picture/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
// picture/post.js: engine.post.add takes a three.js Pass and keeps the chain in order (recipe 52)
|
|
34
|
-
export function createPost(engine, ctx) {
|
|
35
|
-
ctx.track(engine.post.add(new ShaderPass(GrainShader), { name: 'grain' }));
|
|
36
|
-
return { update() {} };
|
|
27
|
+
// picture/grain.js: engine.post.add keeps the chain in order (recipe 52); grain() runs on both renderers
|
|
28
|
+
import { grain } from '@threedog/post-effects';
|
|
29
|
+
export function createGrain(engine, ctx) {
|
|
30
|
+
const fx = engine.post.add(grain());
|
|
31
|
+
ctx.track(fx);
|
|
32
|
+
return { update(s) { fx.set({ amount: 0.02 + 0.06 * s.uNight.value }); } };
|
|
37
33
|
}
|
|
38
34
|
```
|
|
39
35
|
Gameplay and level code use material names and signals only.
|
|
@@ -96,8 +92,8 @@ engine.onRender(() => {
|
|
|
96
92
|
```
|
|
97
93
|
- **`picture/` shaders follow the renderer.** A new game is on WebGPU and writes TSL (recipe 56); `ShaderMaterial` and `onBeforeCompile` do not run there, and a GLSL material
|
|
98
94
|
on WebGPU stops at start and names itself. A `--webgl` game writes GLSL (recipe 43).
|
|
99
|
-
- **The picture
|
|
100
|
-
|
|
95
|
+
- **The picture follows the quality tier.** `engine.tier` (`'low'` | `'high'`) changes while running (a preset), so size what costs from it, then again on
|
|
96
|
+
`'tier:change'`: shadow map (`engine.shadows.mapSize`), light count. The generated `lights.js` does this.
|
|
101
97
|
|
|
102
98
|
## 3c. Wiring `picture/` parts
|
|
103
99
|
- **One `engine.onRender`, in `picture/index.js`.** It calls each part's `update(signals)` and holds no values. A part never adds its own hook: two hooks hide the order.
|
|
@@ -59,7 +59,7 @@ content/*.js is content data: how to write it in `node_modules/threedog/docs/rec
|
|
|
59
59
|
| main.js | 136 | @ts-check Action example: one room, one player, one slime, one drop. Shows how an action game wires… |
|
|
60
60
|
| models.js | 25 | Models this example builds in code (floor, wall, pillar, enemy), registered by name through assets.… |
|
|
61
61
|
| picture/index.js | 14 | @ts-check The action room's picture: wiring only. No sky.js: the engine's dome is what shows beyond… |
|
|
62
|
-
| picture/lights.js |
|
|
62
|
+
| picture/lights.js | 39 | @ts-check Sun or moon and the ambient, from the signals. The ambient's sky half follows the engine'… |
|
|
63
63
|
| picture/materials.js | 9 | @ts-check Materials by name. Module level, because models.js is an asset generator that `npm run ch… |
|
|
64
64
|
| picture/palette.js | 34 | @ts-check The action room's palette: every color and key value of the picture, one copy; the other … |
|
|
65
65
|
|
|
@@ -118,7 +118,9 @@ Code that breaks saves or manages world models: none (rule R33).
|
|
|
118
118
|
|
|
119
119
|
## Events the game emits / listens to
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
| Event | Emitted by the game | Listened to by the game |
|
|
122
|
+
|---|---|---|
|
|
123
|
+
| tier:change | — | lights.js |
|
|
122
124
|
|
|
123
125
|
## Saves
|
|
124
126
|
|
|
@@ -10,12 +10,13 @@ export function createLights(engine) {
|
|
|
10
10
|
const fill = new THREE.AmbientLight(0xffffff, 0);
|
|
11
11
|
const sun = new THREE.DirectionalLight(0xffffff, 1);
|
|
12
12
|
sun.castShadow = true;
|
|
13
|
-
|
|
13
|
+
// sized from engine.tier, resized on 'tier:change' (a preset changes it while running); these lights live with the engine, so the listener is not removed: in a module, ctx.track(engine.events.on(...))
|
|
14
|
+
const fit = () => { const n = engine.tier === 'low' ? 1024 : 2048; engine.shadows.mapSize(sun, n); sun.shadow.radius = Math.max(Math.min(SHADOW.radius, 2), SHADOW.radius * n / 2048); };
|
|
14
15
|
Object.assign(sun.shadow.camera, { left: -SHADOW.extent, right: SHADOW.extent, top: SHADOW.extent, bottom: -SHADOW.extent, near: 1, far: SHADOW.far });
|
|
15
16
|
sun.shadow.camera.updateProjectionMatrix(); // three does not redo it for a light's shadow camera: without this line the box stays at its 10 m default
|
|
16
17
|
sun.shadow.bias = SHADOW.bias; sun.shadow.normalBias = SHADOW.normalBias;
|
|
17
18
|
// radius is in shadow texels: scaled with the map so the low tier's half-size map blurs the same meters, never under 2 texels (stair steps) unless set lower
|
|
18
|
-
|
|
19
|
+
fit(); engine.events.on('tier:change', fit);
|
|
19
20
|
scene.add(hemi, fill, sun, sun.target);
|
|
20
21
|
|
|
21
22
|
const dir = new THREE.Vector3();
|
|
@@ -52,7 +52,7 @@ content/*.js is content data: how to write it in `node_modules/threedog/docs/rec
|
|
|
52
52
|
| models.js | 49 | perf-island procedural models: a round tree, a sheep, a wheat tuft. Built in code, no files; regist… |
|
|
53
53
|
| params.js | 26 | URL parameters of the perf island page. Import this file first in main.js: it rewrites word values … |
|
|
54
54
|
| picture/index.js | 21 | @ts-check The picture of perf island: wiring only. Each part writes plain three.js from the signals… |
|
|
55
|
-
| picture/lights.js |
|
|
55
|
+
| picture/lights.js | 37 | @ts-check Sun or moon and ambient, both from the day table in palette.js. |
|
|
56
56
|
| picture/materials.js | 62 | @ts-check Materials by name. All matte Lambert with two shader additions: soft light (the wrap and … |
|
|
57
57
|
| picture/palette.js | 61 | @ts-check Perf island palette: every color and key value of the picture, one copy. A soft painted d… |
|
|
58
58
|
| picture/sky.js | 21 | @ts-check A flat painted backdrop: one color at every height, the same as the fog, so the island fl… |
|
|
@@ -101,6 +101,7 @@ Code that breaks saves or manages world models: none (rule R33).
|
|
|
101
101
|
| Event | Emitted by the game | Listened to by the game |
|
|
102
102
|
|---|---|---|
|
|
103
103
|
| engine:ready | — | main.js |
|
|
104
|
+
| tier:change | — | lights.js |
|
|
104
105
|
|
|
105
106
|
## Saves
|
|
106
107
|
|
|
@@ -9,10 +9,11 @@ export function createLights(engine) {
|
|
|
9
9
|
const hemi = new THREE.HemisphereLight(0xffffff, AMBIENT_GROUND, 1);
|
|
10
10
|
const sun = new THREE.DirectionalLight(0xffffff, 1);
|
|
11
11
|
sun.castShadow = true;
|
|
12
|
-
|
|
12
|
+
// sized from engine.tier, resized on 'tier:change' (a preset changes it while running); these lights live with the engine, so the listener is not removed: in a module, ctx.track(engine.events.on(...))
|
|
13
|
+
const fit = () => { const n = engine.tier === 'low' ? SHADOW.lowMapSize : SHADOW.mapSize; engine.shadows.mapSize(sun, n); sun.shadow.radius = Math.max(Math.min(SHADOW.radius, 2), SHADOW.radius * n / SHADOW.mapSize); };
|
|
13
14
|
Object.assign(sun.shadow.camera, { left: -SHADOW.extent, right: SHADOW.extent, top: SHADOW.extent, bottom: -SHADOW.extent, near: 1, far: 420 });
|
|
14
15
|
// radius is in shadow texels: scaled with the map so the low tier's half-size map blurs the same meters, never under 2 texels (stair steps) unless set lower
|
|
15
|
-
|
|
16
|
+
fit(); engine.events.on('tier:change', fit);
|
|
16
17
|
sun.shadow.bias = -0.00005;
|
|
17
18
|
sun.shadow.normalBias = 0.04;
|
|
18
19
|
scene.add(hemi, sun, sun.target); // the target stays at the origin: the island is the whole world
|
|
@@ -31,7 +31,7 @@ None yet, write them in `DESIGN.md` (why it is designed this way, what not to ch
|
|
|
31
31
|
- weather: `node_modules/threedog/docs/recipes/44-water-weather-hooks.md` · `node_modules/threedog/docs/api/weather.md`
|
|
32
32
|
- water: `node_modules/threedog/docs/recipes/44-water-weather-hooks.md` · `node_modules/threedog/docs/api/water.md`
|
|
33
33
|
- collision: `node_modules/threedog/docs/recipes/12-navmesh.md` · `node_modules/threedog/docs/api/collision.md`
|
|
34
|
-
- rigid: `node_modules/threedog/docs/recipes/11-
|
|
34
|
+
- rigid: `node_modules/threedog/docs/recipes/11-physics.md` · `node_modules/threedog/docs/api/rigid.md`
|
|
35
35
|
- characters: `node_modules/threedog/docs/recipes/66-common-tasks.md` · `node_modules/threedog/docs/api/characters.md`
|
|
36
36
|
- …9 more modules: their pages are in `node_modules/threedog/docs/api/`
|
|
37
37
|
|
|
@@ -59,7 +59,7 @@ content/*.js is content data: how to write it in `node_modules/threedog/docs/rec
|
|
|
59
59
|
| main.js | 87 | @ts-check This example is written in GLSL: it is the WebGL route (`threedog new-game --webgl`). On … |
|
|
60
60
|
| models.js | 88 | The exhibits that are not in the world example's art (../world/art), built in code and registered b… |
|
|
61
61
|
| params.js | 30 | URL parameters of the style test page. Import this file first in main.js: it rewrites word values i… |
|
|
62
|
-
| picture/env.js |
|
|
62
|
+
| picture/env.js | 38 | @ts-check ?env=1: soft light from the sky. A gradient of the sky's two colors over the ground color… |
|
|
63
63
|
| picture/index.js | 17 | @ts-check The picture this page judges: wiring only. The picture under test is the world example's;… |
|
|
64
64
|
| picture/lights.js | 10 | @ts-check The room's lamp. The sun and the ambient belong to the picture under test; this page only… |
|
|
65
65
|
| picture/materials.js | 29 | @ts-check The exhibits' materials by name. One surface kind each: wood and plaster are matte Lamber… |
|
|
@@ -16,14 +16,13 @@ export function createEnv(engine, ambients) {
|
|
|
16
16
|
void main(){ vec3 d = normalize(vDir); gl_FragColor = vec4(d.y < 0.0 ? uGround : mix(uHorizon, uTop, smoothstep(0.0, 0.5, d.y)), 1.0); }`,
|
|
17
17
|
})));
|
|
18
18
|
scene.environmentIntensity = ENV.intensity;
|
|
19
|
-
const every = engine.tier === 'low' ? ENV.lowInterval : ENV.interval;
|
|
20
19
|
let target = /** @type {THREE.WebGLRenderTarget | null} */ (null), built = '', last = -Infinity;
|
|
21
20
|
return {
|
|
22
21
|
/** Runs after the picture under test wrote this frame's sky and lights @param {any} s engine.uniforms */
|
|
23
22
|
update(s) {
|
|
24
23
|
for (const light of ambients) light.intensity *= ENV.hemi;
|
|
25
24
|
const now = engine.time.now('real');
|
|
26
|
-
if (now - last <
|
|
25
|
+
if (now - last < (engine.tier === 'low' ? ENV.lowInterval : ENV.interval)) return; // read each frame: a settings preset changes the tier while running
|
|
27
26
|
last = now;
|
|
28
27
|
const key = s.uSkyTop.value.getHexString() + s.uSkyHorizon.value.getHexString();
|
|
29
28
|
if (key === built) return; // a fixed sky costs one build, however long the page runs
|
|
@@ -71,7 +71,7 @@ Measured with `engine.step` + a 1 px `readPixels` per frame, median of 120 frame
|
|
|
71
71
|
camera; the far ground loses its sun shadow, which is what cascades are for (`engine.shadows.cascades(sun, { count: 3 })`, recipe 45) when the view is long.
|
|
72
72
|
- A `scene.environment` lights Standard materials on top of the hemisphere light, so a strong environment plus a strong hemi doubles the fill.
|
|
73
73
|
- Which steps where: small props on tables, a tidy room, a yard: 1-3, plus 4 for every static code-built model (free at run time).
|
|
74
|
-
Characters and moving props that must look planted close up: add 5 on desktop, keep it off on low-tier devices (read `engine.tier`).
|
|
74
|
+
Characters and moving props that must look planted close up: add 5 on desktop, keep it off on low-tier devices (read `engine.tier`, again on `'tier:change'`).
|
|
75
75
|
|
|
76
76
|
Rules (correctness):
|
|
77
77
|
- Vertex AO needs `vertexColors: true` on the material and vertices where the darkening should be; it is baked once, so only static geometry.
|
|
@@ -9,7 +9,9 @@ export function createLights(engine) {
|
|
|
9
9
|
const hemi = new THREE.HemisphereLight(0xffffff, 0x4a4a4a, 1);
|
|
10
10
|
const sun = new THREE.DirectionalLight(0xffffff, 1);
|
|
11
11
|
sun.castShadow = true;
|
|
12
|
-
|
|
12
|
+
// sized from engine.tier, resized on 'tier:change' (a preset changes it while running); these lights live with the engine, so the listener is not removed: in a module, ctx.track(engine.events.on(...))
|
|
13
|
+
const fit = () => engine.shadows.mapSize(sun, engine.tier === 'low' ? 1024 : 2048);
|
|
14
|
+
fit(); engine.events.on('tier:change', fit);
|
|
13
15
|
Object.assign(sun.shadow.camera, { left: -24, right: 24, top: 24, bottom: -24, near: 1, far: 120 });
|
|
14
16
|
sun.shadow.normalBias = 0.04;
|
|
15
17
|
scene.add(hemi, sun, sun.target);
|
|
@@ -16,12 +16,14 @@ export function createLights(engine, { night, fill, windowOpening }) {
|
|
|
16
16
|
sun.position.set(Math.sin(az) * Math.cos(el), Math.sin(el), -Math.cos(az) * Math.cos(el)).multiplyScalar(SHADOW.distance);
|
|
17
17
|
sun.castShadow = true;
|
|
18
18
|
renderer.shadowMap.type = SHADOW.type;
|
|
19
|
-
|
|
19
|
+
// sized from engine.tier, resized on 'tier:change' (a preset changes it while running); these lights live with the engine, so the listener is not removed: in a module, ctx.track(engine.events.on(...))
|
|
20
|
+
const fit = () => { const n = SHADOW.mapSize[engine.tier === 'low' ? 'low' : 'high']; engine.shadows.mapSize(sun, n); sun.shadow.radius = Math.max(Math.min(SHADOW.radius, 2), SHADOW.radius * n / SHADOW.mapSize.high); };
|
|
20
21
|
const { extent: e, distance } = SHADOW;
|
|
21
22
|
Object.assign(sun.shadow.camera, { left: -e, right: e, top: e, bottom: -e, near: 1, far: distance * 2 });
|
|
22
23
|
// three adds bias in the shadow camera's 0-1 depth, i.e. a world offset of bias x (far - near)
|
|
23
24
|
// radius is in shadow texels: scaled with the map so the low tier's half-size map blurs the same meters, never under 2 texels (stair steps) unless set lower
|
|
24
|
-
Object.assign(sun.shadow, { normalBias: SHADOW.normalBias, bias: -SHADOW.biasCm / 100 / (distance * 2 - 1)
|
|
25
|
+
Object.assign(sun.shadow, { normalBias: SHADOW.normalBias, bias: -SHADOW.biasCm / 100 / (distance * 2 - 1) });
|
|
26
|
+
fit(); engine.events.on('tier:change', fit);
|
|
25
27
|
scene.add(hemi, sun, sun.target);
|
|
26
28
|
|
|
27
29
|
if (windowOpening && !night) windowLight(engine, { ...windowOpening, ...WINDOW_LIGHT });
|
|
@@ -9,11 +9,12 @@ export function createLights(engine) {
|
|
|
9
9
|
const hemi = new THREE.HemisphereLight(ambient.sky, ambient.ground, ambient.intensity);
|
|
10
10
|
const sun = new THREE.DirectionalLight(key.color, key.intensity);
|
|
11
11
|
sun.castShadow = true;
|
|
12
|
-
|
|
12
|
+
// sized from engine.tier, resized on 'tier:change' (a preset changes it while running); these lights live with the engine, so the listener is not removed: in a module, ctx.track(engine.events.on(...))
|
|
13
|
+
const fit = () => { const n = engine.tier === 'low' ? lowMapSize : mapSize; engine.shadows.mapSize(sun, n); sun.shadow.radius = Math.max(Math.min(radius, 2), radius * n / mapSize); };
|
|
13
14
|
Object.assign(sun.shadow.camera, { left: -extent, right: extent, top: extent, bottom: -extent, near: 1, far });
|
|
14
15
|
Object.assign(sun.shadow, { bias, normalBias });
|
|
15
16
|
// radius is in shadow texels: scaled with the map so the low tier's half-size map blurs the same meters, never under 2 texels (stair steps) unless set lower
|
|
16
|
-
|
|
17
|
+
fit(); engine.events.on('tier:change', fit);
|
|
17
18
|
engine.scene.add(hemi, sun, sun.target);
|
|
18
19
|
|
|
19
20
|
const [ox, oy, oz] = key.offset;
|
|
@@ -10,7 +10,9 @@ export function createLights(engine, mat, o) {
|
|
|
10
10
|
const sun = new THREE.DirectionalLight(DAY.sun.color, DAY.sun.intensity);
|
|
11
11
|
const { center, extent, near, far, distance, normalBias, mapSize } = SHADOW;
|
|
12
12
|
sun.castShadow = true;
|
|
13
|
-
|
|
13
|
+
// sized from engine.tier, resized on 'tier:change' (a preset changes it while running); these lights live with the engine, so the listener is not removed: in a module, ctx.track(engine.events.on(...))
|
|
14
|
+
const fit = () => engine.shadows.mapSize(sun, engine.tier === 'low' ? mapSize.low : mapSize.high);
|
|
15
|
+
fit(); engine.events.on('tier:change', fit);
|
|
14
16
|
Object.assign(sun.shadow.camera, { left: -extent, right: extent, top: extent, bottom: -extent, near, far });
|
|
15
17
|
sun.shadow.normalBias = normalBias;
|
|
16
18
|
sun.target.position.fromArray(center);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
// The bloom on the lamp heads.
|
|
2
|
+
// The bloom on the lamp heads. Declared skipOnLowTier: it blurs the whole frame several times (the tier is known only at start and can change later).
|
|
3
3
|
import { bloom } from '@threedog/post-effects';
|
|
4
4
|
import { BLOOM, GLARE } from './palette.js';
|
|
5
5
|
|
|
6
6
|
/** @param {any} engine @param {{ glare: boolean }} o */
|
|
7
7
|
export function createPost(engine, o) {
|
|
8
|
-
engine.post.add(
|
|
8
|
+
engine.post.add({ ...bloom(o.glare ? GLARE.bloom : BLOOM), skipOnLowTier: true }, { name: 'bloom', slot: 'hdr' });
|
|
9
9
|
}
|
|
@@ -10,11 +10,12 @@ export function createLights(engine) {
|
|
|
10
10
|
const sun = new THREE.DirectionalLight(0xffffff, LIGHT.sunIntensity);
|
|
11
11
|
sun.position.set(LIGHT.sun[0], LIGHT.sun[1], LIGHT.sun[2]);
|
|
12
12
|
sun.castShadow = true;
|
|
13
|
-
|
|
13
|
+
// sized from engine.tier, resized on 'tier:change' (a preset changes it while running); these lights live with the engine, so the listener is not removed: in a module, ctx.track(engine.events.on(...))
|
|
14
|
+
const fit = () => { const n = engine.tier === 'low' ? 1024 : 2048; engine.shadows.mapSize(sun, n); sun.shadow.radius = Math.max(Math.min(3, 2), 3 * n / 2048); };
|
|
14
15
|
Object.assign(sun.shadow.camera, { left: -30, right: 30, top: 30, bottom: -30, near: 1, far: 250 });
|
|
15
16
|
sun.shadow.bias = -0.0001; sun.shadow.normalBias = 0.03; // the box covers the row of columns with a little margin
|
|
16
17
|
// radius is in shadow texels: scaled with the map so the low tier's half-size map blurs the same meters, never under 2 texels (stair steps) unless set lower
|
|
17
|
-
|
|
18
|
+
fit(); engine.events.on('tier:change', fit);
|
|
18
19
|
engine.scene.add(hemi, sun, sun.target);
|
|
19
20
|
return { sun, hemi };
|
|
20
21
|
}
|
|
@@ -9,7 +9,9 @@ export function createLights(engine) {
|
|
|
9
9
|
const hemi = new THREE.HemisphereLight(ambient.dayColor, ambient.dayGround, ambient.day);
|
|
10
10
|
const sun = new THREE.DirectionalLight(key.dayColor, key.day);
|
|
11
11
|
sun.castShadow = true;
|
|
12
|
-
|
|
12
|
+
// sized from engine.tier, resized on 'tier:change' (a preset changes it while running); these lights live with the engine, so the listener is not removed: in a module, ctx.track(engine.events.on(...))
|
|
13
|
+
const fit = () => engine.shadows.mapSize(sun, engine.tier === 'low' ? 1024 : 2048);
|
|
14
|
+
fit(); engine.events.on('tier:change', fit);
|
|
13
15
|
Object.assign(sun.shadow.camera, { left: -extent, right: extent, top: extent, bottom: -extent, near, far });
|
|
14
16
|
sun.shadow.camera.updateProjectionMatrix();
|
|
15
17
|
Object.assign(sun.shadow, { bias, normalBias, radius });
|
|
@@ -9,7 +9,9 @@ export function createLights(engine) {
|
|
|
9
9
|
const sun = new THREE.DirectionalLight(0xffffff, LIGHT.sunIntensity);
|
|
10
10
|
sun.position.set(LIGHT.sun[0], LIGHT.sun[1], LIGHT.sun[2]);
|
|
11
11
|
sun.castShadow = true;
|
|
12
|
-
|
|
12
|
+
// sized from engine.tier, resized on 'tier:change' (a preset changes it while running); these lights live with the engine, so the listener is not removed: in a module, ctx.track(engine.events.on(...))
|
|
13
|
+
const fit = () => engine.shadows.mapSize(sun, engine.tier === 'low' ? 1024 : 2048);
|
|
14
|
+
fit(); engine.events.on('tier:change', fit);
|
|
13
15
|
Object.assign(sun.shadow.camera, { left: -30, right: 30, top: 30, bottom: -30, near: 1, far: 250 });
|
|
14
16
|
sun.shadow.camera.updateProjectionMatrix();
|
|
15
17
|
sun.shadow.bias = -0.0001; sun.shadow.normalBias = 0.03; sun.shadow.radius = 3;
|
|
@@ -11,7 +11,9 @@ export function createLights(engine) {
|
|
|
11
11
|
const sun = new THREE.DirectionalLight(0xffffff, LIGHT.sunIntensity);
|
|
12
12
|
sun.position.set(LIGHT.sun[0], LIGHT.sun[1], LIGHT.sun[2]);
|
|
13
13
|
sun.castShadow = true; // index 0 of three's lit directional lights, which is the one shading.js bands
|
|
14
|
-
|
|
14
|
+
// sized from engine.tier, resized on 'tier:change' (a preset changes it while running); these lights live with the engine, so the listener is not removed: in a module, ctx.track(engine.events.on(...))
|
|
15
|
+
const fit = () => engine.shadows.mapSize(sun, engine.tier === 'low' ? 1024 : 2048);
|
|
16
|
+
fit(); engine.events.on('tier:change', fit);
|
|
15
17
|
Object.assign(sun.shadow.camera, { left: -30, right: 30, top: 30, bottom: -30, near: 1, far: 250 });
|
|
16
18
|
sun.shadow.bias = -0.0001; sun.shadow.normalBias = 0.03; sun.shadow.radius = 3;
|
|
17
19
|
scene.add(hemi, sun, sun.target);
|
|
@@ -9,7 +9,9 @@ export function createLights(engine) {
|
|
|
9
9
|
const hemi = new THREE.HemisphereLight(ambient.dayColor, ambient.ground, ambient.day);
|
|
10
10
|
const sun = new THREE.DirectionalLight(key.dayColor, key.day);
|
|
11
11
|
sun.castShadow = true;
|
|
12
|
-
|
|
12
|
+
// sized from engine.tier, resized on 'tier:change' (a preset changes it while running); these lights live with the engine, so the listener is not removed: in a module, ctx.track(engine.events.on(...))
|
|
13
|
+
const fit = () => engine.shadows.mapSize(sun, engine.tier === 'low' ? 1024 : 2048);
|
|
14
|
+
fit(); engine.events.on('tier:change', fit);
|
|
13
15
|
// wide enough for the whole visible street around the focus point, which sits 20 m down the road
|
|
14
16
|
Object.assign(sun.shadow.camera, { left: -70, right: 70, top: 70, bottom: -70, near: 1, far: 160 });
|
|
15
17
|
sun.shadow.normalBias = 0.04;
|
|
@@ -40,7 +40,7 @@ content/*.js is content data: how to write it in `node_modules/threedog/docs/rec
|
|
|
40
40
|
|---|---|---|
|
|
41
41
|
| main.js | 45 | @ts-check WebGPU + TSL demo (page /webgpu-tsl.html): a field with grass and a lantern, every materi… |
|
|
42
42
|
| picture/index.js | 19 | @ts-check The picture of the WebGPU + TSL demo: wiring only. Materials and post are nodes that read… |
|
|
43
|
-
| picture/lights.js |
|
|
43
|
+
| picture/lights.js | 28 | @ts-check Sun and ambient from the signals. The engine's placeholder lights are off (createEngine({… |
|
|
44
44
|
| picture/materials.js | 37 | @ts-check Materials by name, every one a three.js NodeMaterial written in TSL. The engine's shader … |
|
|
45
45
|
| picture/palette.js | 24 | @ts-check The picture's numbers: one place for colors, light levels and the tone curve. Neutral sta… |
|
|
46
46
|
| picture/post.js | 17 | @ts-check Soft scanlines. On the WebGPU route a post effect is a node function: input is the pictur… |
|
|
@@ -78,7 +78,9 @@ Code that breaks saves or manages world models: none (rule R33).
|
|
|
78
78
|
|
|
79
79
|
## Events the game emits / listens to
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
| Event | Emitted by the game | Listened to by the game |
|
|
82
|
+
|---|---|---|
|
|
83
|
+
| tier:change | — | lights.js |
|
|
82
84
|
|
|
83
85
|
## Saves
|
|
84
86
|
|
|
@@ -9,7 +9,9 @@ export function createLights(engine) {
|
|
|
9
9
|
const hemi = new THREE.HemisphereLight(A.sky, A.ground, A.day);
|
|
10
10
|
const sun = new THREE.DirectionalLight(S.color, S.intensity);
|
|
11
11
|
sun.castShadow = true;
|
|
12
|
-
|
|
12
|
+
// sized from engine.tier, resized on 'tier:change' (a preset changes it while running); these lights live with the engine, so the listener is not removed: in a module, ctx.track(engine.events.on(...))
|
|
13
|
+
const fit = () => engine.shadows.mapSize(sun, engine.tier === 'low' ? 1024 : 2048);
|
|
14
|
+
fit(); engine.events.on('tier:change', fit);
|
|
13
15
|
Object.assign(sun.shadow.camera, { left: -SHADOW_BOX, right: SHADOW_BOX, top: SHADOW_BOX, bottom: -SHADOW_BOX, near: 1, far: 120 });
|
|
14
16
|
scene.add(hemi, sun, sun.target);
|
|
15
17
|
return {
|
|
@@ -38,7 +38,7 @@ Content: actions 4 · audio 3 · containers 1 · dialogues 1 · items 4 · npcs
|
|
|
38
38
|
- weather: `node_modules/threedog/docs/recipes/44-water-weather-hooks.md` · `node_modules/threedog/docs/api/weather.md`
|
|
39
39
|
- water: `node_modules/threedog/docs/recipes/44-water-weather-hooks.md` · `node_modules/threedog/docs/api/water.md`
|
|
40
40
|
- collision: `node_modules/threedog/docs/recipes/12-navmesh.md` · `node_modules/threedog/docs/api/collision.md`
|
|
41
|
-
- rigid: `node_modules/threedog/docs/recipes/11-
|
|
41
|
+
- rigid: `node_modules/threedog/docs/recipes/11-physics.md` · `node_modules/threedog/docs/api/rigid.md`
|
|
42
42
|
- characters: `node_modules/threedog/docs/recipes/66-common-tasks.md` · `node_modules/threedog/docs/api/characters.md`
|
|
43
43
|
- …14 more modules: their pages are in `node_modules/threedog/docs/api/`
|
|
44
44
|
|
|
@@ -76,10 +76,10 @@ content/*.js is content data: how to write it in `node_modules/threedog/docs/rec
|
|
|
76
76
|
| main.js | 176 | Open-world example (slow photography life): riverside cabin + an old fisherman who walks by the clo… |
|
|
77
77
|
| models.js | 39 | Models this game builds in code: the cabin (registered by name in main.js, placed by content/props.… |
|
|
78
78
|
| picture/index.js | 21 | @ts-check The open world's picture: wiring only. Each part writes plain three.js; one onRender driv… |
|
|
79
|
-
| picture/lights.js |
|
|
79
|
+
| picture/lights.js | 44 | @ts-check Sun or moon and the ambient, from the sky of this moment (sky.js) and the weather. One sh… |
|
|
80
80
|
| picture/materials.js | 35 | @ts-check Materials by name. They live at module level, not inside createPicture, because the model… |
|
|
81
81
|
| picture/palette.js | 75 | @ts-check The open world's palette: every color and key value of the picture, one copy; the other f… |
|
|
82
|
-
| picture/post.js | 10 | @ts-check The glow on the sun, the lamp and bright water.
|
|
82
|
+
| picture/post.js | 10 | @ts-check The glow on the sun, the lamp and bright water. Declared skipOnLowTier: it blurs the whol… |
|
|
83
83
|
| picture/sky.js | 40 | @ts-check The sky and the fog. The engine's dome stays because this world shows its sun, moon, star… |
|
|
84
84
|
|
|
85
85
|
## NPCs (content/npcs.js)
|
|
@@ -167,6 +167,7 @@ Code that breaks saves or manages world models: none (rule R33).
|
|
|
167
167
|
| engine:ready | — | main.js, quests.js (starts first-light) |
|
|
168
168
|
| photo:denied | — | main.js |
|
|
169
169
|
| photo:taken | — | main.js |
|
|
170
|
+
| tier:change | — | lights.js |
|
|
170
171
|
|
|
171
172
|
## Saves
|
|
172
173
|
|
|
@@ -13,7 +13,9 @@ export function createLights(engine, sky) {
|
|
|
13
13
|
const fill = new THREE.AmbientLight(0xffffff, 0);
|
|
14
14
|
const sun = new THREE.DirectionalLight(0xffffff, 1);
|
|
15
15
|
sun.castShadow = true;
|
|
16
|
-
|
|
16
|
+
// sized from engine.tier, resized on 'tier:change' (a preset changes it while running); these lights live with the engine, so the listener is not removed: in a module, ctx.track(engine.events.on(...))
|
|
17
|
+
const fit = () => engine.shadows.mapSize(sun, engine.tier === 'low' ? 1024 : 2048);
|
|
18
|
+
fit(); engine.events.on('tier:change', fit);
|
|
17
19
|
Object.assign(sun.shadow.camera, { left: -SHADOW.extent, right: SHADOW.extent, top: SHADOW.extent, bottom: -SHADOW.extent, near: 1, far: SHADOW.far });
|
|
18
20
|
sun.shadow.camera.updateProjectionMatrix(); // three does not redo it for a light's shadow camera: without this line the box stays at its 10 m default
|
|
19
21
|
sun.shadow.bias = SHADOW.bias; sun.shadow.normalBias = SHADOW.normalBias;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
// The glow on the sun, the lamp and bright water.
|
|
2
|
+
// The glow on the sun, the lamp and bright water. Declared skipOnLowTier: it blurs the whole frame several times, and a slow machine needs that time for the world (the real tier is known only at start and can change later, so it is declared, not read here).
|
|
3
3
|
import { bloom } from '@threedog/post-effects';
|
|
4
4
|
import { BLOOM } from './palette.js';
|
|
5
5
|
|
|
6
6
|
/** @param {any} engine */
|
|
7
7
|
export function createPost(engine) {
|
|
8
|
-
engine.post.add(
|
|
8
|
+
engine.post.add({ ...bloom(BLOOM), skipOnLowTier: true }, { name: 'bloom', slot: 'hdr' });
|
|
9
9
|
}
|
package/llms.txt
CHANGED
|
@@ -2,12 +2,38 @@
|
|
|
2
2
|
|
|
3
3
|
> A web 3D game engine on three.js 0.187 (plain three.js, no React): core and modules installed with engine.use. It ships no art: each game draws its own picture (plain three.js in its picture/ folder, and assets).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Start a game (the one way, in an empty folder)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
```sh
|
|
8
|
+
npm install threedog@1 three@~0.187.0
|
|
9
|
+
npm install -D @threedog/tools@1 # the threedog commands: init, shot, check, how, dev, play, test
|
|
10
|
+
npx playwright install chromium # once per machine: the headless browser behind shot, play and test
|
|
11
|
+
npx threedog init # writes the game (main.js, picture/, content/) and its CLAUDE.md; never overwrites a file
|
|
12
|
+
npm install
|
|
13
|
+
npx threedog play # runs the game and reports it (--stop ends it); npm run dev opens it for a person
|
|
14
|
+
```
|
|
8
15
|
|
|
9
|
-
|
|
10
|
-
|
|
16
|
+
The code, in short (init writes it with index.html, vite.config.js, picture/ and content/; do not hand-write the project):
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
import 'threedog/tsl'; // WebGPU with TSL, what a new game starts on; a game started with --webgl leaves this line out and the renderer option below
|
|
20
|
+
import { createEngine, presets, openWorld } from 'threedog';
|
|
21
|
+
import { terrainPreset } from '@threedog/terrain-noise'; // the noise terrain generator (init --open-world adds it; without one the ground is flat)
|
|
22
|
+
|
|
23
|
+
const engine = createEngine({ canvas: document.getElementById('view'), renderer: 'webgpu' }); // no picture code yet: gray placeholders
|
|
24
|
+
engine.use(openWorld({ camera: 'follow', seed: 7, terrain: terrainPreset() }));
|
|
25
|
+
engine.characters.addPlayer({ ...presets.player.thirdPerson });
|
|
26
|
+
engine.start();
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Read next
|
|
30
|
+
|
|
31
|
+
1. The game's CLAUDE.md (init writes it): what the engine already has, the loop, the checklist before calling it done.
|
|
32
|
+
2. `npx threedog how "<task words>"` prints the recipe section for a task. Taking over a game: its STATUS.md first.
|
|
33
|
+
3. The picture: docs/recipes/62-picture-code.md (code), docs/recipes/60-judge-the-picture.md (judge it with `npx threedog shot`), `bloom()`, `ao()`, `lut()`, `outline()`, `dof()` of @threedog/post-effects added with `engine.post.add`. Speed: `npx threedog perf -w .` (average FPS, 1% low). shot and perf use the discrete GPU and say GPU or software.
|
|
34
|
+
4. [AI.md](docs/AI.md): entry table, commands, verification rules, conventions. [API.md](docs/API.md): one page per module in docs/api/.
|
|
35
|
+
|
|
36
|
+
The rest of this file maps tasks to recipe sections.
|
|
11
37
|
|
|
12
38
|
## Which one
|
|
13
39
|
|
|
@@ -61,7 +87,7 @@ Taking over a game: its status notes first. A new feature: docs/AI.md or threedo
|
|
|
61
87
|
- Pixel art: docs/recipes/62-picture-code.md §4b
|
|
62
88
|
- Skeletal animation, IK: docs/recipes/13-animation.md §3, 15-perf.md
|
|
63
89
|
- Pathfinding, navmesh, NPC jumps and gaps, gates: docs/recipes/12-navmesh.md §2
|
|
64
|
-
- Physics, ragdoll, collision, vehicles: docs/recipes/11-
|
|
90
|
+
- Physics, ragdoll, collision, vehicles: docs/recipes/11-physics.md §3
|
|
65
91
|
- Ray / mouse picking, shooting, lock-on: docs/recipes/19-shooting-picking.md §1
|
|
66
92
|
- Prompts, trigger zones: docs/recipes/20-content-actions-save.md §3
|
|
67
93
|
- Press E on a mesh: docs/recipes/03-items-pickups.md
|
|
@@ -100,7 +126,7 @@ Taking over a game: its status notes first. A new feature: docs/AI.md or threedo
|
|
|
100
126
|
## Advanced
|
|
101
127
|
|
|
102
128
|
- Own ground or plant drawing, keep collision: docs/recipes/28-terrain.md §6
|
|
103
|
-
- Worker results, far records' models, raw navmesh or physics, content sections, own mover: docs/recipes/15-perf.md, 18-world.md, 12-navmesh.md, 11-
|
|
129
|
+
- Worker results, far records' models, raw navmesh or physics, content sections, own mover: docs/recipes/15-perf.md, 18-world.md, 12-navmesh.md, 11-physics.md, 14-custom-module.md, 57-control.md
|
|
104
130
|
|
|
105
131
|
## Troubleshooting and speed
|
|
106
132
|
|
|
@@ -122,7 +148,7 @@ Taking over a game: its status notes first. A new feature: docs/AI.md or threedo
|
|
|
122
148
|
- [08-weather-sky](docs/recipes/08-weather-sky.md): Add weather or change the sky
|
|
123
149
|
- [09-materials-lights-models](docs/recipes/09-materials-lights-models.md): Materials, lights and models: the game's own picture
|
|
124
150
|
- [10-blender-level](docs/recipes/10-blender-level.md): Importing Blender models and levels
|
|
125
|
-
- [11-
|
|
151
|
+
- [11-physics](docs/recipes/11-physics.md): Physics: rigid bodies, pushing, joints, vehicles
|
|
126
152
|
- [12-navmesh](docs/recipes/12-navmesh.md): Navigation mesh (nav)
|
|
127
153
|
- [13-animation](docs/recipes/13-animation.md): Animation state machine (skeletal animation)
|
|
128
154
|
- [14-custom-module](docs/recipes/14-custom-module.md): Custom module
|