threedog 1.4.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +48 -0
- package/README.md +13 -7
- package/bin/threedog.mjs +42 -0
- package/core/assets/assetEntry.js +1 -1
- package/core/assets/assetPart.js +1 -1
- package/core/base/Events.js +7 -1
- package/core/base/errorCodes.js +1 -1
- package/core/base/events.generated.js +2 -2
- package/core/engine/Engine.js +11 -7
- package/core/engine/copies.js +1 -1
- package/core/engine/moduleTypes.js +1 -1
- package/core/engine/modules.js +23 -6
- package/core/engine/page.js +1 -0
- package/core/engine/services.js +5 -3
- package/core/engine/startup.js +4 -1
- package/core/inspect/DebugOverrides.js +2 -2
- package/core/inspect/InspectPerf.js +1 -1
- package/core/inspect/describeRender.js +0 -7
- package/core/inspect/metadata.generated.js +139 -50
- package/core/inspect/pictureChecks.js +2 -27
- package/core/ops/control.js +3 -3
- package/core/ops/holds.js +8 -3
- package/core/ops/sharedPoint.js +11 -2
- package/core/saves/saveApply.js +3 -3
- package/core/saves/session.js +20 -4
- package/core/scene/adaptive.js +5 -2
- package/core/scene/pixelRatio.js +39 -17
- package/core/scene/sceneMethods.js +1 -1
- package/core/scene/things.js +3 -2
- package/core/scene/tier.js +2 -16
- package/core/scene/view.js +14 -0
- package/core/time/skip.js +1 -1
- package/docs/AI.md +2 -2
- package/docs/CODEMAP.md +8 -8
- package/docs/COMMANDS.md +2 -2
- package/docs/CONVENTIONS.md +1 -0
- package/docs/THREE.md +1 -1
- package/docs/api/ambience.md +2 -2
- package/docs/api/cameraRig.md +7 -0
- package/docs/api/engine.md +6 -3
- package/docs/api/events.md +3 -3
- package/docs/api/particles.md +1 -1
- package/docs/api/photo.md +5 -0
- package/docs/api/pickups.md +1 -1
- package/docs/api/post.md +1 -1
- package/docs/api/rigid.md +1 -1
- package/docs/api/sky.md +11 -1
- package/docs/api/terrain.md +19 -0
- package/docs/api/tools.md +1 -1
- package/docs/recipes/01-new-game.md +1 -1
- package/docs/recipes/03-items-pickups.md +1 -1
- package/docs/recipes/05-props-bake.md +1 -1
- package/docs/recipes/06-clock-events.md +3 -10
- package/docs/recipes/07-flow-scenes-pause.md +3 -4
- package/docs/recipes/09-materials-lights-models.md +1 -1
- package/docs/recipes/10-blender-level.md +2 -2
- package/docs/recipes/{11-vehicles.md → 11-physics.md} +13 -5
- package/docs/recipes/12-navmesh.md +3 -3
- package/docs/recipes/14-custom-module.md +6 -5
- package/docs/recipes/15-perf.md +1 -1
- package/docs/recipes/16-dev-bridge.md +1 -1
- package/docs/recipes/18-world.md +1 -1
- package/docs/recipes/20-content-actions-save.md +0 -1
- package/docs/recipes/21-camera.md +11 -1
- package/docs/recipes/26-ui-parts.md +2 -2
- package/docs/recipes/27-net.md +1 -1
- package/docs/recipes/29-grid.md +1 -1
- package/docs/recipes/34-environment-lighting.md +5 -3
- package/docs/recipes/40-scene.md +1 -1
- package/docs/recipes/44-water-weather-hooks.md +1 -1
- package/docs/recipes/45-cascaded-shadows.md +6 -3
- package/docs/recipes/51-capability-catalog.md +1 -1
- package/docs/recipes/52-around-the-picture.md +8 -8
- package/docs/recipes/53-ground-up-close.md +2 -2
- package/docs/recipes/55-mods-time-wrap.md +6 -8
- package/docs/recipes/57-control.md +1 -1
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +7 -7
- package/docs/recipes/62-picture-code.md +13 -17
- package/examples/action/GAMEMAP.md +4 -2
- package/examples/action/picture/lights.js +3 -2
- package/examples/perf-island/GAMEMAP.md +2 -1
- package/examples/perf-island/picture/lights.js +3 -2
- package/examples/styletest/GAMEMAP.md +2 -2
- package/examples/styletest/picture/env.js +1 -2
- package/examples/techniques/contact-shadows/README.md +1 -1
- package/examples/techniques/day-night-grade/picture/lights.js +3 -1
- package/examples/techniques/interior-light/README.md +1 -1
- package/examples/techniques/interior-light/picture/lights.js +4 -2
- package/examples/techniques/modular-building/picture/lights.js +3 -2
- package/examples/techniques/night-lights/README.md +1 -1
- package/examples/techniques/night-lights/picture/lights.js +3 -1
- package/examples/techniques/night-lights/picture/post.js +2 -2
- package/examples/techniques/outlines-and-rim/README.md +1 -1
- package/examples/techniques/outlines-and-rim/picture/lights.js +3 -2
- package/examples/techniques/procedural-animation/README.md +1 -1
- package/examples/techniques/procedural-animation/picture/lights.js +3 -1
- package/examples/techniques/procedural-surface/README.md +1 -1
- package/examples/techniques/procedural-surface/picture/lights.js +3 -1
- package/examples/techniques/stylized-shading/picture/lights.js +3 -1
- package/examples/techniques/wet-road/README.md +1 -1
- package/examples/techniques/wet-road/picture/lights.js +3 -1
- package/examples/webgpu-tsl/GAMEMAP.md +4 -2
- package/examples/webgpu-tsl/picture/lights.js +3 -1
- package/examples/world/GAMEMAP.md +4 -3
- package/examples/world/picture/lights.js +3 -1
- package/examples/world/picture/post.js +2 -2
- package/llms.txt +33 -7
- package/modules/camera/common.js +22 -20
- package/modules/camera/contract.js +1 -1
- package/modules/characters/Character.js +2 -2
- package/modules/characters/NPC.js +7 -8
- package/modules/characters/index.js +8 -8
- package/modules/characters/mover.contract.js +1 -1
- package/modules/characters/movers/rapier.js +7 -9
- package/modules/characters/npcAvoid.js +2 -2
- package/modules/characters/player.js +11 -15
- package/modules/characters/playerStrings.js +1 -2
- package/modules/characters/seat.js +1 -1
- package/modules/collision/Collision.js +1 -1
- package/modules/collision/grid.js +1 -1
- package/modules/content/index.js +4 -3
- package/modules/content/models.js +1 -1
- package/modules/content/templates.js +3 -2
- package/modules/flow/index.js +8 -8
- package/modules/gameplay/Dialogue.js +1 -1
- package/modules/gameplay/Inventory.js +3 -3
- package/modules/gameplay/Quests.js +1 -0
- package/modules/gameplay/inventory.contract.js +1 -1
- package/modules/gameplay/pickups.js +1 -1
- package/modules/gameplay/questLog.js +0 -1
- package/modules/grid/index.js +1 -1
- package/modules/grid/tiles.js +6 -3
- package/modules/hud/index.js +2 -2
- package/modules/level/contract.js +2 -2
- package/modules/level/index.js +1 -1
- package/modules/music/Music.js +1 -1
- package/modules/nav/index.js +1 -1
- package/modules/net/sync.js +1 -1
- package/modules/particles/Particles.js +12 -5
- package/modules/particles/effect.js +17 -3
- package/modules/photo/pathTrace.js +1 -1
- package/modules/rigid/RigidBodies.js +23 -9
- package/modules/rigid/ragdoll.js +1 -1
- package/modules/rigid/sync.js +14 -0
- package/modules/settings/Settings.js +3 -2
- package/modules/settings/apply.js +4 -3
- package/modules/settings/sections.js +1 -1
- package/modules/sky/Sky.js +9 -4
- package/modules/sky/environment.js +5 -3
- package/modules/terrain/index.js +1 -2
- package/modules/timeline/Timeline.js +9 -6
- package/modules/vegetation/Vegetation.js +1 -1
- package/modules/vegetation/index.js +1 -1
- package/modules/weather/weatherDraw.js +1 -2
- package/modules/world/World.js +1 -0
- package/modules/world/index.js +1 -0
- package/modules/world/persist.js +1 -1
- package/package.json +6 -2
- package/render/PostFX.js +17 -12
- package/render/fx/postWebGPU.tsl.js +2 -1
- package/render/lightmap.js +1 -1
- package/render/lights.js +1 -2
- package/render/neutral.js +1 -1
- package/render/patches.js +3 -3
- package/render/probes.js +27 -2
- package/render/shaderErrors.js +1 -1
- package/render/shadows.js +1 -3
- package/types/core.d.ts +16 -9
- package/types/gameplay.d.ts +8 -3
- package/types/generated/modules/sky/Sky.d.ts +4 -4
- package/types/generated/render/PostFX.d.ts +2 -2
- package/types/generated/ui/UI.d.ts +2 -1
- package/types/physics.d.ts +1 -1
- package/types/world.d.ts +4 -2
- package/ui/UI.js +18 -14
- package/ui/cursor.js +2 -2
- package/examples/action/.threedog/content-index.json +0 -1
- package/examples/perf-island/.threedog/content-index.json +0 -1
- package/examples/plain-picture/.threedog/content-index.json +0 -1
- package/examples/rc2d/.threedog/content-index.json +0 -1
- package/examples/styletest/.threedog/content-index.json +0 -1
- package/examples/webgpu-tsl/.threedog/content-index.json +0 -1
- package/examples/world/.threedog/content-index.json +0 -1
|
@@ -36,15 +36,15 @@ shadow. `threedog examples pull sun-and-key-light` shows three routes side by si
|
|
|
36
36
|
| Ambient / hemisphere, environment | the fill: how bright and what color the shaded side is | shadows are as deep as the style wants and still show shape; up-facing and down-facing faces differ; metals have something to reflect | your `picture/` code writes the hemisphere light and `scene.environment`, `scene.environmentIntensity` ([34](34-environment-lighting.md), [08 brightness](08-weather-sky.md#3-changing-sky-colors-sun-stars-the-day-and-night-sky)) |
|
|
37
37
|
| Shadow softness | hard or blurred shadow edges | edges match the light (crisp under a clear sun, soft under cloud or for a gentle style); no stair-steps or speckle | `renderer.shadowMap.type`, `light.shadow.radius` ([45](45-cascaded-shadows.md)) |
|
|
38
38
|
| Shadow distance, detail | how far shadows reach and how sharp small ones are | the area the player looks at has shadows; small props keep theirs; objects touch the ground (no gap under a foot) | `engine.shadows.box(sun, { extent })`, `engine.shadows.cascades(sun, { count, maxFar })`, `light.shadow.bias`, `mapSize` ([45](45-cascaded-shadows.md)) |
|
|
39
|
-
| Bloom | light bleeding around bright pixels | the bright things you meant (sun, lamps, magic) glow and nothing else does; the picture does not turn milky | `engine.post.add(bloom())` from `@threedog/post-effects`, or three's `UnrealBloomPass` through `engine.post.add(pass)` ([52 Post chain](52-around-the-picture.md#post-effect-chain)) |
|
|
39
|
+
| Bloom | light bleeding around bright pixels | the bright things you meant (sun, lamps, magic) glow and nothing else does; the picture does not turn milky | `engine.post.add(bloom())` from `@threedog/post-effects`, or three's `UnrealBloomPass` through `engine.post.add(pass)` ([52 Post chain](52-around-the-picture.md#post-effect-chain-your-own-pass-extra-render-passes)) |
|
|
40
40
|
| Light glow / halo | lamps, windows, signs that read as lit | a glowing object keeps its hue at the center (it is not a white block), has a halo where bloom is on, and lights its surroundings if it should | `material.emissive`, `engine.uniforms.uNight` ([09 §1b](09-materials-lights-models.md#night-glow-emissive-that-follows-daylight)); many lamps: `lightPool` ([09 §1b](09-materials-lights-models.md#1b-lights-and-stalls)) |
|
|
41
41
|
| Water, sea | color with depth, waves, foam, what it reflects | shallow and deep read differently, the far sea meets the sky without a seam, foam sits where waves break | `engine.water.shader({ depthColor, foam })`, `engine.water.uniforms.uWave` ([44](44-water-weather-hooks.md)); own: three/addons `Water`, a `ShaderMaterial` ([44 own material](44-water-weather-hooks.md#water-your-own-material-reflections-refraction)) |
|
|
42
42
|
| Wet ground | streets and stone after rain | wet is darker and glossier together, gloss shows reflections of something bright, puddles have soft edges | no engine picture: read `engine.uniforms.uRain`, then write `material.color`, `material.roughness` ([08 §7](08-weather-sky.md#7-wet-roads-and-puddles-after-rain)) |
|
|
43
|
-
| Color grading | contrast, saturation and warm / cool shift of the whole frame | the frame has the mood you named; skin, foliage and the player's colors still read | `engine.post.add(lut())` from `@threedog/post-effects`, or `new LUTPass({ lut })` ([52 Post chain](52-around-the-picture.md#post-effect-chain)) |
|
|
43
|
+
| Color grading | contrast, saturation and warm / cool shift of the whole frame | the frame has the mood you named; skin, foliage and the player's colors still read | `engine.post.add(lut())` from `@threedog/post-effects`, or `new LUTPass({ lut })` ([52 Post chain](52-around-the-picture.md#post-effect-chain-your-own-pass-extra-render-passes)) |
|
|
44
44
|
| Cloud shadow | moving dark patches on the ground | the patches drift slowly enough to read as clouds, are as dark as the sky is cloudy, and do not hide gameplay | `engine.uniforms.uCloudShadow`, `uCloudShadowScale`, `uCloudShadowSpeed`; clouds in the sky: `uCloudCover`, `uSkyCloudScale`, `uSkyCloudSpeed` on the dome ([08](08-weather-sky.md)); your own: `engine.shaderTerms.cloudShadow(spec)` ([52](52-around-the-picture.md)) |
|
|
45
|
-
| Grain, vignette | film noise; darker frame corners | you notice the mood, not the effect; text and the HUD stay clean | `engine.post.add(grain())`, `engine.post.add(vignette())`; a pixel snippet: `engine.post.add({ name, fuse: { glsl }, slot: 'ldr' })` ([52 Post chain](52-around-the-picture.md#post-effect-chain)) |
|
|
46
|
-
| Ambient occlusion | darker creases and contact corners | objects sit on the ground and corners have weight; no dark halo around thin things | `engine.post.add(ao())` ([52 Post chain](52-around-the-picture.md#post-effect-chain)) |
|
|
47
|
-
| Outline | lines around shapes | lines help read shapes at play distance and match the style's line weight | `engine.post.add(outline())` ([52 Post chain](52-around-the-picture.md#post-effect-chain)), or three/addons `OutlinePass` |
|
|
45
|
+
| Grain, vignette | film noise; darker frame corners | you notice the mood, not the effect; text and the HUD stay clean | `engine.post.add(grain())`, `engine.post.add(vignette())`; a pixel snippet: `engine.post.add({ name, fuse: { glsl }, slot: 'ldr' })` ([52 Post chain](52-around-the-picture.md#post-effect-chain-your-own-pass-extra-render-passes)) |
|
|
46
|
+
| Ambient occlusion | darker creases and contact corners | objects sit on the ground and corners have weight; no dark halo around thin things | `engine.post.add(ao())` ([52 Post chain](52-around-the-picture.md#post-effect-chain-your-own-pass-extra-render-passes)) |
|
|
47
|
+
| Outline | lines around shapes | lines help read shapes at play distance and match the style's line weight | `engine.post.add(outline())` ([52 Post chain](52-around-the-picture.md#post-effect-chain-your-own-pass-extra-render-passes)), or three/addons `OutlinePass` |
|
|
48
48
|
| Surface shading | how light falls across a surface (smooth, banded, flat) | materials that should differ (wood, stone, metal, cloth) differ in response, not only in color | `new THREE.MeshToonMaterial({ gradientMap })` or any material of yours; `applyEffects(mat, { lighting })`, `rampTexture` ([43](43-shader-patches-surfaces.md), [09](09-materials-lights-models.md)) |
|
|
49
49
|
| God rays, volumetric fog | light shafts, fog thick in the air | shafts come from where the light is and fade when it leaves the screen | `lightShaft`, `sunShafts`, `lightVolumes` ([34](34-environment-lighting.md)); haze by depth ([59](59-depth-post-effects.md)) |
|
|
50
50
|
|
|
@@ -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);
|
|
@@ -103,4 +103,4 @@ Rules (correctness):
|
|
|
103
103
|
Sources: written for this repository, no code copied. Background: three.js `RectAreaLight` and `LightProbe` docs and examples (0.187), general
|
|
104
104
|
architectural-visualization and game-lighting writing on window light, bounce and eye adaptation.
|
|
105
105
|
|
|
106
|
-
This example is written in GLSL: it is the WebGL route (`threedog new-game --webgl`).
|
|
106
|
+
This example is written in GLSL: it is the WebGL route (`threedog new-game --webgl`). TSL version: recipe 56.
|
|
@@ -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;
|
|
@@ -92,4 +92,4 @@ Rules (correctness):
|
|
|
92
92
|
Sources: written for this example; no code copied. Light units and falloff as documented for three.js physically based lights; the bloom pass
|
|
93
93
|
is three's `UnrealBloomPass` through `@threedog/post-effects`.
|
|
94
94
|
|
|
95
|
-
This example is written in GLSL: it is the WebGL route (`threedog new-game --webgl`).
|
|
95
|
+
This example is written in GLSL: it is the WebGL route (`threedog new-game --webgl`). TSL version: recipe 56.
|
|
@@ -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
|
}
|
|
@@ -38,7 +38,7 @@ How to judge it: a shot at the real camera, with the busiest background the game
|
|
|
38
38
|
- **Selection highlight**: a colored hull or `OutlinePass` on the selected object only.
|
|
39
39
|
|
|
40
40
|
## The engine helper (optional convenience)
|
|
41
|
-
Copy `outlines.js` into a game; `main.js`
|
|
41
|
+
Copy `outlines.js` into a game; only the demo around it is not part of the tool (`main.js` shapes; `picture/` has the lights, materials by name and the post pass). It gives `trackResolution(engine)` (the drawing-buffer size for screen-unit hulls),
|
|
42
42
|
`addHull(mesh, { thickness, units: 'world' | 'screen', color })`, and `rimPatch({ color, strength, power, shadowSide })`.
|
|
43
43
|
|
|
44
44
|
| route | how | width | cost |
|
|
@@ -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
|
}
|
|
@@ -76,4 +76,4 @@ Sources: written for this example; no code copied. Background: distance-driven g
|
|
|
76
76
|
stretch are common practice (David Rosen, "An Indie Approach to Procedural Animation", GDC 2014; the squash-and-stretch principle from
|
|
77
77
|
Thomas and Johnston, *The Illusion of Life*, 1981).
|
|
78
78
|
|
|
79
|
-
This example is written in GLSL: it is the WebGL route (`threedog new-game --webgl`).
|
|
79
|
+
This example is written in GLSL: it is the WebGL route (`threedog new-game --webgl`). TSL version: recipe 56.
|
|
@@ -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 });
|
|
@@ -66,4 +66,4 @@ Rules (correctness):
|
|
|
66
66
|
Sources: triplanar mapping as commonly described (Ben Golus, "Normal Mapping for a Triplanar Shader", 2017); vertex AO and edge wear as
|
|
67
67
|
standard game-art practice. Code written for this engine; nothing copied.
|
|
68
68
|
|
|
69
|
-
This example is written in GLSL: it is the WebGL route (`threedog new-game --webgl`).
|
|
69
|
+
This example is written in GLSL: it is the WebGL route (`threedog new-game --webgl`). TSL version: recipe 56.
|
|
@@ -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);
|
|
@@ -99,4 +99,4 @@ Sources: written for this example; no code copied. Background: the mirror-image
|
|
|
99
99
|
the common darken + lower-roughness approach discussed in Sébastien Lagarde, "Water drop 2a / 2b – Dynamic rain and its effects" (2013);
|
|
100
100
|
`Reflector` and SSR as found in the three.js examples (`webgl_mirror`, `webgl_postprocessing_ssr`).
|
|
101
101
|
|
|
102
|
-
This example is written in GLSL: it is the WebGL route (`threedog new-game --webgl`).
|
|
102
|
+
This example is written in GLSL: it is the WebGL route (`threedog new-game --webgl`). TSL version: recipe 56.
|
|
@@ -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
|