threedog 0.1.0 → 0.2.1
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/README.md +4 -4
- package/core/Animator.js +1 -0
- package/core/Assets.js +28 -0
- package/core/DebugOverrides.js +143 -0
- package/core/Describe.js +14 -3
- package/core/Engine.js +44 -72
- package/core/Events.js +59 -1
- package/core/I18n.js +2 -2
- package/core/Inspect.js +12 -32
- package/core/InspectScene.js +7 -3
- package/core/MaterialInfo.js +32 -0
- package/core/Ops.js +43 -59
- package/core/Saves.js +5 -4
- package/core/UrlState.js +3 -2
- package/core/Vars.js +1 -0
- package/core/Views.js +49 -0
- package/core/actor.js +2 -2
- package/core/assetReport.js +83 -0
- package/core/catalog.js +169 -0
- package/core/checks.js +67 -0
- package/core/claims.js +51 -0
- package/core/debugView.js +76 -0
- package/core/describeRender.js +51 -0
- package/core/describeText.js +11 -4
- package/core/errorCodes.js +33 -0
- package/core/errorHints.js +6 -1
- package/core/grid.js +127 -0
- package/core/gridLoad.js +19 -0
- package/core/holds.js +106 -0
- package/core/lifecycle.js +1 -0
- package/core/lightWatch.js +23 -3
- package/core/look/coreParts.js +112 -0
- package/core/look/layers.js +136 -0
- package/core/look/part.js +173 -0
- package/core/look/report.js +79 -0
- package/core/look/write.js +86 -0
- package/core/loop.js +22 -16
- package/core/modules.js +19 -5
- package/core/opsAtomic.js +31 -0
- package/core/opsCheck.js +25 -14
- package/core/opsFail.js +20 -0
- package/core/opsHistory.js +6 -6
- package/core/opsRun.js +77 -0
- package/core/params.js +132 -0
- package/core/renamed.js +22 -0
- package/core/saveApply.js +2 -2
- package/core/sceneMethods.js +9 -34
- package/core/services.js +73 -0
- package/core/startup.js +3 -1
- package/core/styleParts.js +11 -9
- package/core/thingExplain.js +68 -0
- package/core/thingOps.js +35 -24
- package/core/things.js +15 -1
- package/core/util.js +11 -0
- package/core/validate.js +23 -7
- package/docs/AI.md +93 -114
- package/docs/API.md +8 -9
- package/docs/CODEMAP.md +67 -53
- package/docs/COMMANDS.md +21 -7
- package/docs/CONVENTIONS.md +22 -11
- package/docs/THREE.md +3 -3
- package/docs/api/assets.md +3 -0
- package/docs/api/characters.md +5 -2
- package/docs/api/collision.md +4 -0
- package/docs/api/content.md +1 -0
- package/docs/api/engine.md +23 -14
- package/docs/api/events.md +5 -1
- package/docs/api/post.md +5 -4
- package/docs/api/saves.md +2 -1
- package/docs/api/sky.md +3 -3
- package/docs/api/style.md +8 -8
- package/docs/api/tools.md +5 -2
- package/docs/api/vegetation.md +1 -0
- package/docs/api/weather.md +1 -1
- package/docs/recipes/01-new-game.md +41 -43
- package/docs/recipes/02-npc.md +38 -22
- package/docs/recipes/03-items-pickups.md +4 -4
- package/docs/recipes/04-quests.md +23 -23
- package/docs/recipes/05-props-bake.md +5 -5
- package/docs/recipes/06-clock-events.md +13 -0
- package/docs/recipes/07-flow-scenes-pause.md +6 -2
- package/docs/recipes/08-weather-sky.md +6 -6
- package/docs/recipes/09-style-pack.md +35 -100
- package/docs/recipes/12-navmesh.md +22 -0
- package/docs/recipes/13-animation.md +25 -6
- package/docs/recipes/14-custom-module.md +6 -7
- package/docs/recipes/15-perf.md +9 -1
- package/docs/recipes/16-dev-bridge.md +52 -18
- package/docs/recipes/18-world.md +5 -2
- package/docs/recipes/19-shooting-picking.md +9 -8
- package/docs/recipes/20-content-actions-save.md +10 -10
- package/docs/recipes/21-camera.md +51 -2
- package/docs/recipes/22-shop-gold.md +16 -16
- package/docs/recipes/23-ops.md +46 -10
- package/docs/recipes/27-net.md +3 -3
- package/docs/recipes/28-terrain.md +2 -2
- package/docs/recipes/29-grid.md +47 -27
- package/docs/recipes/34-environment-lighting.md +11 -10
- package/docs/recipes/35-style-from-reference.md +41 -46
- package/docs/recipes/36-sky-ground-plant-looks.md +22 -20
- package/docs/recipes/37-terrain-look-hooks.md +34 -13
- package/docs/recipes/38-environment-look-hooks.md +49 -42
- package/docs/recipes/40-scene.md +29 -0
- package/docs/recipes/41-thing-registry.md +29 -0
- package/docs/recipes/42-terrain-shape.md +1 -1
- package/docs/recipes/43-shader-patches-surface-looks.md +37 -20
- package/docs/recipes/44-water-weather-look-hooks.md +11 -9
- package/docs/recipes/45-cascaded-shadows.md +2 -2
- package/docs/recipes/46-blender-art-route.md +26 -4
- package/docs/recipes/47-island-snow-backdrop.md +4 -3
- package/docs/recipes/48-make-material.md +70 -0
- package/docs/recipes/49-game-module-contract.md +71 -0
- package/docs/recipes/50-own-renderer.md +12 -0
- package/docs/recipes/51-capability-catalog.md +63 -0
- package/docs/recipes/52-look.md +146 -0
- package/docs/recipes/53-ground-up-close.md +58 -0
- package/examples/action/GAMEMAP.md +7 -7
- package/examples/action/content/index.js +2 -1
- package/examples/action/content/views.js +6 -0
- package/examples/action/main.js +3 -2
- package/examples/sheepisland/GAMEMAP.md +3 -4
- package/examples/styletest/GAMEMAP.md +3 -3
- package/examples/styletest/content/npcs.js +1 -1
- package/examples/styletest/main.js +2 -2
- package/examples/styletest/panel.js +3 -3
- package/examples/world/GAMEMAP.md +3 -3
- package/examples/world/content/npcs.js +1 -1
- package/examples/world/main.js +1 -1
- package/index.d.ts +35 -2
- package/index.js +6 -3
- package/llms.txt +13 -7
- package/modules/ambience/Ambience.js +5 -2
- package/modules/camera/FirstPersonCamera.js +3 -5
- package/modules/camera/FixedCamera.js +19 -12
- package/modules/camera/FollowCamera.js +14 -8
- package/modules/camera/RtsCamera.js +3 -5
- package/modules/camera/common.js +40 -10
- package/modules/camera/index.js +1 -1
- package/modules/camera/projection.js +34 -0
- package/modules/characters/Character.js +45 -31
- package/modules/characters/assetModel.js +35 -7
- package/modules/characters/astar.js +14 -7
- package/modules/characters/index.js +6 -3
- package/modules/characters/movers/simple.js +6 -1
- package/modules/characters/npcSim.js +8 -2
- package/modules/characters/pathAsync.js +12 -6
- package/modules/characters/pathJob.js +2 -1
- package/modules/characters/proceduralRig.js +50 -11
- package/modules/characters/useModel.js +22 -0
- package/modules/characters/walkTo.js +58 -0
- package/modules/collision/Collision.js +102 -4
- package/modules/content/explain.js +13 -0
- package/modules/content/index.js +3 -1
- package/modules/content/loader.js +3 -0
- package/modules/content/rules.js +1 -0
- package/modules/debug/DebugPanel.js +11 -5
- package/modules/entities/Entities.js +6 -2
- package/modules/flow/index.js +5 -2
- package/modules/gameplay/Dialogue.js +5 -2
- package/modules/gameplay/Interactions.js +12 -2
- package/modules/gameplay/Inventory.js +21 -11
- package/modules/gameplay/Quests.js +13 -3
- package/modules/gameplay/pickups.js +6 -4
- package/modules/grid/Layer.js +1 -1
- package/modules/grid/index.js +1 -1
- package/modules/grid/tiles.js +9 -5
- package/modules/hlod/index.js +5 -2
- package/modules/hud/index.js +5 -2
- package/modules/level/index.js +5 -3
- package/modules/lights/index.js +5 -2
- package/modules/music/Music.js +6 -2
- package/modules/nav/index.js +5 -3
- package/modules/net/Client.js +4 -3
- package/modules/net/Host.js +2 -2
- package/modules/net/index.js +5 -3
- package/modules/particles/Particles.js +1 -1
- package/modules/photo/Photo.js +10 -7
- package/modules/rigid/RigidBodies.js +5 -2
- package/modules/settings/Settings.js +6 -3
- package/modules/settings/apply.js +2 -1
- package/modules/sky/Sky.js +21 -19
- package/modules/sky/cascades.js +6 -6
- package/modules/sky/domeLayers.js +1 -1
- package/modules/sky/environment.js +39 -13
- package/modules/sky/fog.js +9 -6
- package/modules/sky/frame.js +4 -3
- package/modules/sky/look.js +3 -2
- package/modules/sky/lookFog.js +80 -0
- package/modules/sky/lookShadow.js +50 -0
- package/modules/sky/lookSky.js +108 -0
- package/modules/sky/shader.js +2 -2
- package/modules/sky/shadow.js +4 -10
- package/modules/sky/skyModule.js +4 -3
- package/modules/terrain/ChunkManager.js +2 -33
- package/modules/terrain/chunkLevels.js +40 -0
- package/modules/terrain/index.js +10 -2
- package/modules/terrain/lookGround.js +61 -0
- package/modules/timeline/Timeline.js +7 -3
- package/modules/timeline/Tween.js +3 -7
- package/modules/timeline/shots.js +6 -4
- package/modules/triggers/index.js +9 -2
- package/modules/vegetation/Vegetation.js +17 -4
- package/modules/vegetation/index.js +7 -4
- package/modules/vegetation/lookWind.js +37 -0
- package/modules/vegetation/nearFade.js +39 -0
- package/modules/water/Water.js +19 -3
- package/modules/water/look.js +80 -0
- package/modules/weather/Weather.js +22 -31
- package/modules/weather/look.js +75 -0
- package/modules/weather/particles.js +1 -1
- package/modules/weather/strings.js +15 -0
- package/modules/world/explain.js +11 -0
- package/modules/world/index.js +11 -4
- package/modules/world/thingSource.js +44 -0
- package/package.json +2 -1
- package/render/PostFX.js +48 -51
- package/render/detail.js +39 -15
- package/render/effects.js +4 -2
- package/render/fuse.js +12 -0
- package/render/lights.js +4 -2
- package/render/lookSurface.js +161 -0
- package/render/materials.js +27 -10
- package/render/postLook.js +86 -0
- package/render/surface.js +3 -1
- package/types/core.d.ts +223 -29
- package/types/gameplay.d.ts +22 -6
- package/types/generated/core/DebugOverrides.d.ts +52 -0
- package/types/generated/core/Events.d.ts +43 -0
- package/types/generated/core/Ops.d.ts +62 -21
- package/types/generated/core/Saves.d.ts +1 -0
- package/types/generated/core/Views.d.ts +33 -0
- package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
- package/types/generated/modules/grid/Layer.d.ts +1 -0
- package/types/generated/modules/sky/Sky.d.ts +10 -17
- package/types/generated/modules/weather/Weather.d.ts +5 -15
- package/types/generated/render/PostFX.d.ts +20 -23
- package/types/generated/render/materials.d.ts +10 -0
- package/types/physics.d.ts +8 -0
- package/types/style.d.ts +35 -20
- package/types/world.d.ts +7 -1
- package/ui/Parts.js +6 -2
- package/ui/UI.js +1 -1
- package/ui/defaults.js +1 -1
- package/docs/api/debug.md +0 -10
package/docs/recipes/02-npc.md
CHANGED
|
@@ -10,18 +10,18 @@ dialogue(), content())`.
|
|
|
10
10
|
`games/<game>/content/npcs.js`:
|
|
11
11
|
```js
|
|
12
12
|
export default {
|
|
13
|
-
|
|
14
|
-
name: '
|
|
13
|
+
guard: {
|
|
14
|
+
name: 'Gate guard',
|
|
15
15
|
colors: { body: 0xc89a5a, legs: 0x5b4a3a, hair: 0x3a2a1a }, // omit to use the style pack's default colors
|
|
16
16
|
start: { place: 'home', x: 6, z: -3 }, // starting position; omitted = the first stop of the schedule
|
|
17
17
|
schedule: [ // at is a clock time 'HH:MM'; at that time the NPC walks there (pathfinding is automatic)
|
|
18
18
|
{ at: '07:00', place: 'home', x: 6, z: -3 },
|
|
19
|
-
{ at: '13:00', place: '
|
|
19
|
+
{ at: '13:00', place: 'tower' },
|
|
20
20
|
{ at: '18:30', place: 'home', x: 2, z: 4 },
|
|
21
21
|
],
|
|
22
|
-
talk: '
|
|
22
|
+
talk: 'guard', // a dialogue id in dialogues.js; press E when near
|
|
23
23
|
},
|
|
24
|
-
cat: { name: '
|
|
24
|
+
cat: { name: 'Cat', start: { place: 'home' }, behavior: 'wander', mind: { radius: 6 } }, // no schedule: write behavior + start, omit schedule
|
|
25
25
|
};
|
|
26
26
|
```
|
|
27
27
|
A content NPC takes every `npcs.add` option (`speed`, `talkRadius`, `arriveDistance`, `pathStep`, `repath`, `talkLabel`, `model`...) written as a
|
|
@@ -29,35 +29,35 @@ field; a misspelt one errors with the closest name. `start` and `schedule` are t
|
|
|
29
29
|
`content/dialogues.js`:
|
|
30
30
|
```js
|
|
31
31
|
export default {
|
|
32
|
-
|
|
33
|
-
speaker: '
|
|
32
|
+
guard: {
|
|
33
|
+
speaker: 'Gate guard',
|
|
34
34
|
nodes: {
|
|
35
35
|
start: {
|
|
36
36
|
text: [ // several variants: the first whose condition holds is used
|
|
37
|
-
{ if: { flag: '
|
|
38
|
-
{ text: '
|
|
37
|
+
{ if: { flag: 'metGuard' }, text: 'Back again?' },
|
|
38
|
+
{ text: 'Halt. First time here?' },
|
|
39
39
|
],
|
|
40
|
-
do: { setFlag: '
|
|
40
|
+
do: { setFlag: 'metGuard' },
|
|
41
41
|
next: 'ask',
|
|
42
42
|
},
|
|
43
|
-
ask: { text: '
|
|
44
|
-
{ text: '
|
|
45
|
-
{ text: '
|
|
43
|
+
ask: { text: 'A pass costs one coin.', choices: [
|
|
44
|
+
{ text: 'Buy one', next: 'buy', if: { has: { coin: 1 } } },
|
|
45
|
+
{ text: 'No thanks' }, // a choice with no next = the dialogue ends; a plain node with no next waits for one more interact press, then ends
|
|
46
46
|
] },
|
|
47
|
-
buy: { text: '
|
|
47
|
+
buy: { text: 'Move along.', do: [{ take: { coin: 1 } }, { give: { pass: 1 } }], next: 'end' },
|
|
48
48
|
},
|
|
49
49
|
},
|
|
50
50
|
};
|
|
51
51
|
```
|
|
52
52
|
The words usable in conditions / effects are in the comment at the top of `modules/content/rules.js` (flag notFlag has lacks counter can / setFlag
|
|
53
53
|
give take bump startQuest toast particles marker clearMarker op).
|
|
54
|
-
The items used (coin,
|
|
55
|
-
from a level marker (such as `
|
|
54
|
+
The items used (coin, pass) must be defined in `items.js`, otherwise validation fails. A `place` name comes from `content.load(data, { places })` or
|
|
55
|
+
from a level marker (such as `npc_guard`). Add a new content file to `content/index.js`.
|
|
56
56
|
|
|
57
57
|
## 2. Add in code (temporary NPCs, dynamic schedules)
|
|
58
58
|
```js
|
|
59
|
-
engine.dialogue.define('passerby', { start: { text: '
|
|
60
|
-
const npc = engine.npcs.add({ id: 'passerby', name: '
|
|
59
|
+
engine.dialogue.define('passerby', { start: { text: 'Nice day.', speaker: 'Passerby' } });
|
|
60
|
+
const npc = engine.npcs.add({ id: 'passerby', name: 'Passerby', position: [10, 0, 5], schedule: [{ at: '08:00', position: [20, 0, 5] }], talk: 'passerby' }); // at: 'HH:MM' or 0-1; without id the name is used
|
|
61
61
|
engine.npcs.remove('passerby'); // remove by id, name or handle
|
|
62
62
|
```
|
|
63
63
|
|
|
@@ -88,7 +88,7 @@ them. Built in there is also `'wander'` (random wandering near home, using `engi
|
|
|
88
88
|
```js
|
|
89
89
|
npc.setBehavior('wander', { radius: 12 }); // home = current position, wander within 12 meters (pause: [2, 6] pause seconds, home: { x, z } sets the center)
|
|
90
90
|
npc.setBehavior('schedule'); // back to the schedule
|
|
91
|
-
engine.npcs.add({ id: 'dog', name: '
|
|
91
|
+
engine.npcs.add({ id: 'dog', name: 'Dog', position: [5, 0, 5], behavior: 'wander', mind: { radius: 8 } }); // wanders from the start
|
|
92
92
|
```
|
|
93
93
|
The behavior name and `mind` (the behavior's parameters and memory) are in the NPC data and are saved; after changing behavior or loading, the NPC
|
|
94
94
|
carries on with the new behavior. A wrong behavior name throws and lists the registered ones. NPCs in content can also write `behavior` + `mind`
|
|
@@ -138,12 +138,28 @@ engine.npcs.avoid.set(false); // turn off (ghosts, cro
|
|
|
138
138
|
- Behaviors you write are not avoided automatically: after your own `character.move`, call `engine.npcs.avoid.push(rec, npc.character, dt)` once
|
|
139
139
|
(inside `near`, before writing back to the data).
|
|
140
140
|
|
|
141
|
+
|
|
142
|
+
## A guard you build yourself (`Character` + `walkTo`)
|
|
143
|
+
|
|
144
|
+
For a one-off (guard, pet, follower) that `schedule` / `wander` do not cover: `new Character(engine, { rig })` takes a ready body
|
|
145
|
+
(`{ root, body?, head?, limbs?, joints? }`), or `{ model: 'humanoid' }` picks a body asset like any character ([13-animation](13-animation.md)); call `character.animate(dt)` each frame.
|
|
146
|
+
`character.walkTo(target, { speed, arrive, turnRate, run })` follows `characters.findPath` on fixed steps (turns at `turnRate` rad/s, skips passed
|
|
147
|
+
points, re-plans when it makes no progress for `stuckSeconds`, up to `maxRepaths`). It returns a promise of `{ status }`: `'arrived'` | `'noPath'` |
|
|
148
|
+
`'stuck'` | `'cancelled'` (never rejects), with `remove()` to cancel.
|
|
149
|
+
|
|
150
|
+
```js
|
|
151
|
+
const guard = new Character(engine, { rig: { root: myGuardMesh } }).addTo();
|
|
152
|
+
guard.placeAt(post);
|
|
153
|
+
const walk = guard.walkTo(player.position, { arrive: 1.5 });
|
|
154
|
+
if ((await walk).status === 'noPath') guard.face(player); // walk.remove() cancels
|
|
155
|
+
```
|
|
156
|
+
|
|
141
157
|
## 3. Verify
|
|
142
158
|
- `npm run check`: content validation catches "dialogue id does not exist", "bad clock-time format", "node next points to a missing node". After
|
|
143
159
|
`npm run map` it shows up in the NPC table and dialogue graph of GAMEMAP.md.
|
|
144
|
-
- State: `npm run shot -- / --time 13:10 --wait 20 --describe-only`; the "nearby" list has an entry for
|
|
145
|
-
meters (only listed within 30 meters; add `--pos x,z` to stand by the
|
|
146
|
-
- Console / tests: `engine.npcs.get('
|
|
160
|
+
- State: `npm run shot -- / --time 13:10 --wait 20 --describe-only`; the "nearby" list has an entry for `Gate guard` tagged as an NPC with its distance in
|
|
161
|
+
meters (only listed within 30 meters; add `--pos x,z` to stand by the tower).
|
|
162
|
+
- Console / tests: `engine.npcs.get('guard').position`, `.currentStop()`; during a dialogue `engine.describe().ui.dialogue` = `{ speaker, text, typing, choices: [labels], lock }` (absent when no dialogue runs; the text version prints it as a `Dialogue:` line). `describe` does NOT expose the node id or the NPC id: `speaker` is the display name; to inspect the node, read the content file or listen to `engine.events.on("dialogue:line", ({ script, node, speaker, text }) => ...)` (also `dialogue:start` / `dialogue:end`).
|
|
147
163
|
- Advancing a dialogue in a headless test (typing and "keys ignored right after opening" both run on game time): press E when near -> `engine.step(1)`
|
|
148
164
|
to finish typing -> press a number key or run `engine.ops.run('dialogue.choose', { index: i })` (while typing it completes the sentence first) ->
|
|
149
165
|
`engine.step(0.3)`. No real-time waiting.
|
|
@@ -10,8 +10,8 @@ it grows back" is data in world (needs the world module that `openWorld()` inclu
|
|
|
10
10
|
```js
|
|
11
11
|
// Items: id -> name, icon, description. stack = how many fit in one slot (default 99; more spill into further slots), weight (optional), color = color when dropped on the ground
|
|
12
12
|
export default {
|
|
13
|
-
mushroom: { name: '
|
|
14
|
-
coin: { name: '
|
|
13
|
+
mushroom: { name: 'Mushroom', icon: '🍄', desc: 'Found in the woods', color: 0xc0504d },
|
|
14
|
+
coin: { name: 'Coin', icon: '🪙', stack: 99999 }, // currency: one slot however much you carry; full buying/selling in recipe 22
|
|
15
15
|
};
|
|
16
16
|
export const startItems = { coin: 3 }; // what the inventory holds at the start (optional)
|
|
17
17
|
```
|
|
@@ -39,7 +39,7 @@ changing level and coming back they are still picked up.
|
|
|
39
39
|
|
|
40
40
|
## 2. In code (dynamic drops, custom models)
|
|
41
41
|
```js
|
|
42
|
-
engine.inventory.define('gem', { name: '
|
|
42
|
+
engine.inventory.define('gem', { name: 'Gem', icon: '💎', color: 0x66ccff }); // shape: add mesh: (item, { color, size }, e) => Object3D | geometry, or model: 'generatorName', to set it on the item (wins over style.pickup.model; spawnPickup { mesh } wins over both)
|
|
43
43
|
const gem = engine.inventory.spawnPickup('gem', engine.player.position, { count: 1, respawnSeconds: 0 }); // returns a handle; gem.remove() deletes data and model together
|
|
44
44
|
// handle: { id: item, worldId: id in world, object: current model (null when far), remove() }; opts.id lets you write a stable id (spawning again with the same id reuses the existing one)
|
|
45
45
|
engine.inventory.add('coin', 2); // give directly; returns the entry key ('coin'), false if it doesn't fit
|
|
@@ -88,7 +88,7 @@ Both act on `ctx.actor`'s container (`'player'` by default).
|
|
|
88
88
|
can be undone.
|
|
89
89
|
```js
|
|
90
90
|
const r = engine.ops.run('inventory.trade', { take: 'rusty_key', give: 'gold_key' }); // also takeN / giveN; take may be an entry key ('sword#3')
|
|
91
|
-
if (!r.ok) say(r.
|
|
91
|
+
if (!r.ok) say(r.code); // 'notEnough' (A missing) | 'full' (B does not fit even after A leaves)
|
|
92
92
|
engine.ops.undo('inventory.trade', { take: 'rusty_key', give: 'gold_key' }, r.value); // gives A back (with its data), takes B away
|
|
93
93
|
engine.inventory.trade('rusty_key', 'gold_key'); // the same from code; a container has .trade() too
|
|
94
94
|
```
|
|
@@ -10,16 +10,16 @@ may also fail. When the current step has a `target`, hud shows a marker and dist
|
|
|
10
10
|
`games/<game>/content/quests.js`:
|
|
11
11
|
```js
|
|
12
12
|
export default {
|
|
13
|
-
'
|
|
14
|
-
title: '
|
|
15
|
-
desc: '
|
|
16
|
-
startOn: 'engine:ready', // the event that starts it automatically (or use { startQuest: '
|
|
13
|
+
'restore-power': {
|
|
14
|
+
title: 'Restore power',
|
|
15
|
+
desc: 'The engineer needs three fuses to restart the relay.',
|
|
16
|
+
startOn: 'engine:ready', // the event that starts it automatically (or use { startQuest: 'restore-power' } in a dialogue)
|
|
17
17
|
steps: [
|
|
18
|
-
{ id: 'talk', text: '
|
|
19
|
-
{ id: 'gather', text: '
|
|
20
|
-
{ id: 'return', text: '
|
|
18
|
+
{ id: 'talk', text: 'Talk to the engineer', done: { flag: 'metEngineer' }, target: { npc: 'engineer' } }, // the marker follows the NPC
|
|
19
|
+
{ id: 'gather', text: 'Find 3 fuses', done: { has: { fuse: 3 } }, target: 'storage' }, // a place name
|
|
20
|
+
{ id: 'return', text: 'Fit them at the relay', done: { flag: 'relayOn' }, target: { place: 'home', x: 0, z: 3 } },
|
|
21
21
|
],
|
|
22
|
-
reward: [{ take: {
|
|
22
|
+
reward: [{ take: { fuse: 3 } }, { give: { coin: 5 } }, { toast: 'Power restored!' }],
|
|
23
23
|
},
|
|
24
24
|
};
|
|
25
25
|
```
|
|
@@ -39,18 +39,18 @@ Not every quest is a straight line. A step can hold several goals done in any or
|
|
|
39
39
|
`fail` ends the quest early:
|
|
40
40
|
```js
|
|
41
41
|
'defend-camp': {
|
|
42
|
-
title: '
|
|
42
|
+
title: 'Hold the camp',
|
|
43
43
|
startOn: 'engine:ready',
|
|
44
44
|
steps: [
|
|
45
|
-
{ text: '
|
|
46
|
-
{ all: [ // text defaults to the required goals: "
|
|
47
|
-
{ text: '
|
|
48
|
-
{ text: '
|
|
49
|
-
{ text: '
|
|
45
|
+
{ text: 'Reach the camp', done: { flag: 'atCamp' }, target: 'camp' },
|
|
46
|
+
{ all: [ // text defaults to the required goals: "Hold the north gate / Hold the south gate"
|
|
47
|
+
{ text: 'Hold the north gate', done: { counter: { northWaves: 3 } }, target: 'northGate' },
|
|
48
|
+
{ text: 'Hold the south gate', done: { counter: { southWaves: 3 } }, target: 'southGate' },
|
|
49
|
+
{ text: 'No ally hurt', done: { notFlag: 'allyHurt' }, optional: true }, // a bonus: never blocks, shown done if met in time
|
|
50
50
|
] },
|
|
51
51
|
],
|
|
52
52
|
fail: { flag: 'campBurned' }, // checked while the quest is active
|
|
53
|
-
onFail: [{ toast: '
|
|
53
|
+
onFail: [{ toast: 'The camp has fallen' }, { setFlag: 'mayRetryCamp' }],
|
|
54
54
|
reward: { give: { coin: 20 } },
|
|
55
55
|
},
|
|
56
56
|
```
|
|
@@ -60,18 +60,18 @@ Not every quest is a straight line. A step can hold several goals done in any or
|
|
|
60
60
|
|
|
61
61
|
## 2. In code (complex conditions, or when you need functions)
|
|
62
62
|
```js
|
|
63
|
-
engine.quests.define('
|
|
64
|
-
title: '
|
|
65
|
-
steps: [{ text: '
|
|
63
|
+
engine.quests.define('slimes3', {
|
|
64
|
+
title: 'Clear the cellar',
|
|
65
|
+
steps: [{ text: 'Defeat 3 slimes', done: e => e.vars.counter('slimes') >= 3, target: () => engine.npcs.get('engineer')?.position }], // the function returns a position every frame: when the NPC is far away and has no model, root is null, so read position from the data
|
|
66
66
|
reward: e => e.inventory.add('coin', 3),
|
|
67
67
|
});
|
|
68
|
-
engine.quests.start('
|
|
69
|
-
engine.vars.bump('
|
|
68
|
+
engine.quests.start('slimes3');
|
|
69
|
+
engine.vars.bump('slimes'); // each time one is defeated
|
|
70
70
|
engine.events.on('quest:done', ({ id }) => { /* quest completed */ }); // there are also quest:start, quest:step, quest:part and quest:fail
|
|
71
71
|
```
|
|
72
|
-
To turn off automatic markers: `hud({ questMarkers: false })`. To add a marker by hand: `const m = engine.hud.marker('
|
|
73
|
-
content effects can add them too: `{ marker: '
|
|
74
|
-
`engine.hud.counter('
|
|
72
|
+
To turn off automatic markers: `hud({ questMarkers: false })`. To add a marker by hand: `const m = engine.hud.marker('gate', { label: 'Gate' }); m.remove();`;
|
|
73
|
+
content effects can add them too: `{ marker: 'gate' }` / `{ clearMarker: 'gate' }`. A counter in the screen corner:
|
|
74
|
+
`engine.hud.counter('slimes', { label: 'Slimes', value: 2, max: 3 })`.
|
|
75
75
|
|
|
76
76
|
## 3. Verify
|
|
77
77
|
- `npm run check`: a wrong item / flag / place name / NPC id in a step is an error; "flag is only checked but never set" is a warning. After
|
|
@@ -10,7 +10,7 @@ Large repeated areas (forests, grass) don't use this; use `content/vegetation.js
|
|
|
10
10
|
`games/<game>/content/props.js` (a list; remember to add it to `content/index.js`):
|
|
11
11
|
```js
|
|
12
12
|
export default [
|
|
13
|
-
{ model: 'pine', place: 'home', x: -8, z: -6, scale: 1.2, collide: 'circle' }, // an asset name (here a generator
|
|
13
|
+
{ model: 'pine', place: 'home', x: -8, z: -6, scale: 1.2, collide: 'circle' }, // an asset name (here a generator from an asset pack)
|
|
14
14
|
{ model: ['flower', 0xf2d16b], place: 'home', x: 1.6, z: 3.4 }, // a generator with arguments, use an array: flower(0xf2d16b)
|
|
15
15
|
{ model: 'rock', x: 120, z: -40, rot: 0.6, scale: 0.8, collide: 'box' }, // no place = world coordinates; rot in radians
|
|
16
16
|
{ model: 'well', place: 'home', x: 4, z: -4, y: 0, collide: 'box' }, // a file asset: assets.model('well')
|
|
@@ -25,8 +25,8 @@ interaction, container and saved state (recipe 30).
|
|
|
25
25
|
A model is always an **asset name**, never a path or a function (`npm run check` reports both): register it in a manifest or asset pack first. A
|
|
26
26
|
generator entry is built through `engine.assets.cached` (params from the array), a file entry through `engine.assets.model`:
|
|
27
27
|
```js
|
|
28
|
-
import { assets
|
|
29
|
-
engine.assets.manifest(
|
|
28
|
+
import { assets } from './assets.js'; // your asset pack (or a published one)
|
|
29
|
+
engine.assets.manifest(assets); // pine, rock, ['flower', color]...
|
|
30
30
|
engine.assets.manifest({ name: 'props', models: { well: '/models/well.glb' } });
|
|
31
31
|
```
|
|
32
32
|
Props with the same model share one prototype (geometry and material are built once); each spot gets a clone.
|
|
@@ -134,11 +134,11 @@ import forest from 'forest-assets';
|
|
|
134
134
|
engine.assets.manifest(forest); // content and code now say 'oak', 'creek'
|
|
135
135
|
engine.assets.manifest({ name: 'mine', models: { oak: '/models/my-oak.glb' } }); // a later pack replaces a name it shares
|
|
136
136
|
```
|
|
137
|
-
A generator function is also an entry (`models: { pine: () => geometry }`):
|
|
137
|
+
A generator function is also an entry (`models: { pine: () => geometry }`): an asset pack exports its procedural models this way.
|
|
138
138
|
|
|
139
139
|
Fonts are entries too, and a style names them instead of holding the file (a style is looks only):
|
|
140
140
|
```js
|
|
141
|
-
const engine = createEngine({ canvas, style: [
|
|
141
|
+
const engine = createEngine({ canvas, style: [basePack, { ui: { fonts: ['pixel', 'pixelBold'], font: '"pixel", system-ui' } }] });
|
|
142
142
|
engine.assets.manifest({ name: 'ui-fonts', base: '/fonts/', fonts: { pixel: 'pixel.woff2', pixelBold: { url: 'pixel-bold.woff2', family: 'pixel', weight: 700 } } });
|
|
143
143
|
```
|
|
144
144
|
`family` defaults to the asset name; the other keys are FontFace descriptors (`weight`, `style`, `unicodeRange`, ...). `start()` loads the fonts
|
|
@@ -92,6 +92,13 @@ What catches up, and how:
|
|
|
92
92
|
- `timeScale = 0` skips as if at 1x. The jump itself is the op `time.skip { seconds }` (logged and replayable; it refuses `seconds <= 0`).
|
|
93
93
|
- A module that keeps its own time implements the hook `skip(dt, e, done)` (called once per segment; `done` on the last one).
|
|
94
94
|
|
|
95
|
+
### Order inside one frame
|
|
96
|
+
Each rendered frame runs: input poll -> the fixed steps due (`commits` applied first, then `onFixed`, module `fixed` hooks, clock timers) -> `onFrame`
|
|
97
|
+
callbacks **in the order they were registered** -> module `frame` hooks -> stream / jobs / batching -> render -> `afterRender` hooks. The animation of a model
|
|
98
|
+
from `engine.assets.animate` (and a Character's model) is itself an `onFrame` callback registered when the animator was created, so your `onFrame` runs
|
|
99
|
+
before it if you registered first (you see last frame's pose) and after it if you registered later. To read or override a pose after animation, register
|
|
100
|
+
the callback after the model is created, or use an `afterRender` hook.
|
|
101
|
+
|
|
95
102
|
## 3. Verify
|
|
96
103
|
- Without waiting real time: in a test or the console, `engine.sky.timeOfDay = parseClock('17:59'); engine.step(5)`, then look at the result (`step`
|
|
97
104
|
returns the describe).
|
|
@@ -101,4 +108,10 @@ What catches up, and how:
|
|
|
101
108
|
scale is not 1, divide by `timeScale` as well.
|
|
102
109
|
- Reproduce a scenario: `npm run shot -- / --time 17:58 --wait 10 --describe-only`, then look at the time (18:0x) and your effect (lamps, NPCs, items).
|
|
103
110
|
- After `npm run map`, the "timed events" section of GAMEMAP.md lists every `sky.at/between/daily/onSeason` and `clock.after/every`.
|
|
111
|
+
- Is skip the same as living through it? `const r = await engine.checkSkip(600)` skips 600 game seconds, rewinds, steps the same span and compares the
|
|
112
|
+
saved state: `{ ok, diffs: [{ path, a, b }] }` (refuses with `reason: 'frozen'` / `'timeScale0'` while gameplay is frozen or the clock stopped; pending background results are applied first) (a = skip, b = step; `{ ignore: ['parts.world', 'parts.random'] }` drops paths). Skip does not run near simulation (the weather module has a skip hook, so its timers do advance), so a moving player/NPC
|
|
113
|
+
always differs: ignore those parts and read the rest. It leaves the world at the stepped state, so run
|
|
114
|
+
it on a scratch playthrough or in a test. A diff usually means a module with its own time lacks a `skip` hook. `await engine.checkSave()` does the same
|
|
115
|
+
for save -> load (a diff names a save part whose `load` does not restore what `save` wrote).
|
|
116
|
+
- Why did it fire (or not)? `engine.events.traceSize = 200` records each event with the event or op that caused it: `events.trace('item:add').at(-1).chain`. Failed ops, sight queries and NPC state changes are entries too (with `code`); `events.note(name, { obj, code, data })` adds your own and `events.traceFocus(id)` makes one object verbose (the ring is bounded; size 0 costs nothing). Details: recipe 23 section 12.
|
|
104
117
|
- Related tests: `npm test -- 游戏时钟 SKIP`.
|
|
@@ -16,10 +16,10 @@ engine.flow.define('title', {
|
|
|
16
16
|
enter: (e, from) => { titleEl.hidden = false; },
|
|
17
17
|
exit: (e, to) => { titleEl.hidden = true; },
|
|
18
18
|
});
|
|
19
|
-
engine.flow.define('ending', { freeze: true, lockInput: true, enter: () => toast(engine, '
|
|
19
|
+
engine.flow.define('ending', { freeze: true, lockInput: true, enter: () => toast(engine, 'The end') });
|
|
20
20
|
startBtn.onclick = () => engine.flow.go('playing');
|
|
21
21
|
|
|
22
|
-
engine.input.define('pause', ['KeyO'], '
|
|
22
|
+
engine.input.define('pause', ['KeyO'], 'Pause'); // read by action name; Esc is the back key (see below); presets.keys / presets.interactions bind P, I, J, E (see the key table in GAMEMAP)
|
|
23
23
|
engine.onFrame(() => {
|
|
24
24
|
if (engine.input.pressedRaw('pause')) engine.flow.go(engine.flow.state === 'paused' ? 'playing' : 'paused'); // paused pushes an opaque input context, so use pressedRaw
|
|
25
25
|
});
|
|
@@ -32,6 +32,10 @@ state when the menu closes; without flow it calls `engine.freeze('settings')` di
|
|
|
32
32
|
Stopped while frozen: the fixed step (movement, physics), module `fixed`, the game clock `clock`, quest checks (they run in the fixed step), timeline
|
|
33
33
|
`wait` / tweens / camera / paths. Still running: rendering, UI, `onFrame`, the fade-to-black `fadeScreen`.
|
|
34
34
|
|
|
35
|
+
Restarting a run from a UI button (retry, "play again"): do not reset positions, health and spawns inside the click handler or an `onFrame` callback; that is
|
|
36
|
+
mid-frame and can leave half the world on the old tick. Apply it on a fixed tick: `engine.nextFixed(resetRun)`
|
|
37
|
+
(runs at the start of the next fixed step, in a stable order), or set a flag in the handler and reset in `onFixed`.
|
|
38
|
+
|
|
35
39
|
### Back key (Esc): the UI focus stack
|
|
36
40
|
Windows (inventory, quests, settings), dialogue and cutscenes are pushed onto the stack in the order they open (`uiFocus(engine)` in `ui/Focus.js`),
|
|
37
41
|
and Esc goes **only to the top one**:
|
|
@@ -28,16 +28,16 @@ Fields: `cloud` cloud cover 0-1, `sun` sunlight multiplier, `fog` fog distance m
|
|
|
28
28
|
With openWorld the weather module is already installed; pass its options through the preset: `openWorld({ camera: 'follow', weather: { types, autoPool } })`.
|
|
29
29
|
|
|
30
30
|
## 3. Changing sky colors, sun, stars (style pack)
|
|
31
|
-
`sky.keyframes` in the style pack (
|
|
31
|
+
`sky.keyframes` in the style pack (your pack's `index.js`):
|
|
32
32
|
`[time 0-1, zenith color, horizon color (= fog color), sunlight color, sunlight intensity, ambient intensity]`, interpolated by time;
|
|
33
|
-
also `sunSize sunGlow moonSize starDensity clouds skybox shadow` (see the comments in
|
|
33
|
+
also `sunSize sunGlow moonSize starDensity clouds skybox shadow` (see the comments in the style types, `types/style.d.ts`, for what they mean; `hoursPerDay` is timing, so it is a
|
|
34
34
|
`sky()` option, not a style key). The look of rain and snow is in `style.weather.rain / snow` (shape, density, shaders, the game's own particles: recipe 44).
|
|
35
35
|
|
|
36
36
|
## 4. Time and brightness (game code)
|
|
37
37
|
```js
|
|
38
38
|
engine.sky.timeOfDay = parseClock('19:30'); // jump to a time (0-1)
|
|
39
39
|
engine.clock.timeScale = 0; // sky and game seconds stop together (2 = double speed); game seconds per day: sky({ dayLength: 600 }); the three kinds of time are in recipe 06
|
|
40
|
-
engine.
|
|
40
|
+
engine.look.fog.set({ far: 300 }); // base fog distance (meters); weather scales it. engine.setFogFar(300) sets the same base value directly
|
|
41
41
|
```
|
|
42
42
|
Fixed dusk: `openWorld({ time: 18.5 / 24, ... })` (a 0-1 fraction of the day) and do not pass `sky: presets.calendar.cycle` (the template does; the cycle
|
|
43
43
|
is what moves the clock). `engine.sky.isDay` is `sunHeight > 0` with `sunHeight = sin((timeOfDay - 0.25) * 2π)`: true strictly between timeOfDay 0.25 and 0.75 (06:00 to 18:00 on the default 24-hour face; with `hoursPerDay: H` the same fractions, 0.25H to 0.75H), false at exactly 06:00 and 18:00, so 18:30 already reads as "night" in `describe().time.isDay`. `daylight` = `max(0, sunHeight)`. Keyframes only change colors, not this flip.
|
|
@@ -50,9 +50,9 @@ sky({ seasons: ['spring', 'summer', 'autumn', 'winter'], daysPerSeason: 28, dayL
|
|
|
50
50
|
sky({ seasons: [{ name: 'wet', days: 10 }, { name: 'dry', days: 20 }], dayLength: 360 }); // seasons of their own length
|
|
51
51
|
```
|
|
52
52
|
**Don't modify directly** `sky.sun.intensity / color`, `sky.hemi`, `scene.fog`: the sky recomputes them every frame and overwrites your change (the
|
|
53
|
-
console warns about it during development).
|
|
53
|
+
console warns about it during development). Use `engine.look.lights` / `look.fog` (recipe 52), or take them over yourself (recipe 38).
|
|
54
54
|
To darken or tint everything (a cave, a horror segment), write a modifier layer of your own; it stacks with the weather's 'weather' layer without
|
|
55
|
-
overwriting it:
|
|
55
|
+
overwriting it (multiplier layers vs `look.lights` overrides: [recipe 52](52-look.md#skymodify-vs-looklights)):
|
|
56
56
|
```js
|
|
57
57
|
engine.sky.modify('cave', { sun: 0.3, ambient: 0.4, fog: 0.5 }); // enter the cave: layers multiply
|
|
58
58
|
engine.sky.modify('cave', { tint: 0x402030, tintAmount: 0.5 }); // changes only the given fields (this layer's sun/ambient stay)
|
|
@@ -66,7 +66,7 @@ combined result and is read-only (changing it directly triggers a warning during
|
|
|
66
66
|
## 5. Verify
|
|
67
67
|
- Text: `npm run shot -- / --time 19:30 --weather dust --wait 2 --describe-only`, then look for "Time: 19:30..." and "Weather: dust (rain 0, snow 0, fog 0.35)".
|
|
68
68
|
`describe().weather` has `name progress rain snow fog wind cloud`; `describe().time` has `clock day season isDay dayLength timeScale`.
|
|
69
|
-
- Take a screenshot only after the look changed: `npm run shot -- / --time 19:30 --weather dust`.
|
|
69
|
+
- Take a screenshot only after the look changed: `npm run shot -- / --time 19:30 --weather dust`.
|
|
70
70
|
|
|
71
71
|
## 6. Day and night in game logic
|
|
72
72
|
Day and night come only from the sky: test `engine.sky.isDay`, and fade with `engine.sky.daylight` (0-1). Don't decide it from the clock time
|
|
@@ -4,26 +4,24 @@
|
|
|
4
4
|
plain neutral placeholder (a gray capsule for characters, a gray box for props and pickups, flat gray ground at y = 0, one white hemisphere light plus
|
|
5
5
|
one neutral directional light without shadows or tone mapping), and the console says once in dev what is missing and how to fix it.
|
|
6
6
|
|
|
7
|
-
A style pack is a plain object passed in as `createEngine({ style })`. It holds **looks only**: colors, the default
|
|
7
|
+
A style pack is a plain object passed in as `createEngine({ style })`. It holds **looks only**: colors, the default pickup shape,
|
|
8
8
|
materials and shaders, sky and lighting, post effects, UI look. Not part of it: model / texture / sound files and procedural models content names (an
|
|
9
9
|
**asset pack**, `engine.assets.manifest`, recipe 05 "Asset packs"), sounds (section 5), gameplay data and timing (a **content pack**, recipe 20;
|
|
10
10
|
`sky({ hoursPerDay })`). Which key is read by whom is in the "style pack keys" table of `../CODEMAP.md`; the field list is in `../api/style.md`. Every
|
|
11
11
|
entry can be omitted; omitted entries are the neutral placeholders above (the city example passes no style pack at all). Write it as a plain object literal, no `@type` or `as const`: fields with a fixed set of words (`shading`, `mode`, `type` …) accept any string in the types, and a wrong word is reported by `threedog style check` with the fix.
|
|
12
12
|
|
|
13
|
-
## 0.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
npm install @threedog/style-lowpoly
|
|
17
|
-
```
|
|
13
|
+
## 0. Using a style pack
|
|
14
|
+
A style pack is a plain object (or a package that exports one): yours in `style/index.js`, a folder you copy, or a published package. Any art direction fits:
|
|
15
|
+
realistic, toon, pixel, painterly, flat, noir. The engine ships none; `threedog new-style` starts an empty one (section 1).
|
|
18
16
|
```js
|
|
19
17
|
import { createEngine, presets, openWorld } from 'threedog';
|
|
20
|
-
import
|
|
21
|
-
import { terrainPreset, terrainStrings } from '@threedog/terrain-noise';
|
|
22
|
-
const engine = createEngine({ canvas, style:
|
|
23
|
-
engine.use(openWorld({ camera: 'follow', seed: 7, terrain: terrainPreset() })); // noise terrain (hills, rivers, biomes) that
|
|
18
|
+
import yourPack from './style/index.js'; // or: import yourPack from 'a-published-pack'
|
|
19
|
+
import { terrainPreset, terrainStrings } from '@threedog/terrain-noise'; // the world shape is not a look: its own package
|
|
20
|
+
const engine = createEngine({ canvas, style: yourPack, strings: terrainStrings }); // terrainStrings: names of the preset's ground types
|
|
21
|
+
engine.use(openWorld({ camera: 'follow', seed: 7, terrain: terrainPreset() })); // noise terrain (hills, rivers, biomes) that your pack colors, see recipes/28
|
|
24
22
|
```
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
A pack may also export an asset pack (procedural models: `engine.assets.manifest(assets)`). Post effects such as `bloom` / `ao` / `outline` come from
|
|
24
|
+
`@threedog/post-effects` (style packs never import each other; R34 checks). The terrain generator `terrainPreset` / `riverAt` / `BIOMES` /
|
|
27
25
|
`terrainStrings` is a separate package, `@threedog/terrain-noise`: the shape of the world is gameplay, so a style pack keeps only the colors of its
|
|
28
26
|
ground types (`terrain.colors`, `biomeColors`).
|
|
29
27
|
|
|
@@ -31,9 +29,9 @@ ground types (`terrain.colors`, `biomeColors`).
|
|
|
31
29
|
`style` may be a list of parts, deep-merged left to right into `engine.style`, so one pack's materials, another pack's sky and the game's own colors
|
|
32
30
|
mix without copying whole packs:
|
|
33
31
|
```js
|
|
34
|
-
import
|
|
32
|
+
import basePack from './style/index.js';
|
|
35
33
|
const dusk = { sky: { sunSize: 600, keyframes: myDuskKeyframes } }; // only these two sky fields change
|
|
36
|
-
const engine = createEngine({ canvas, style: [
|
|
34
|
+
const engine = createEngine({ canvas, style: [basePack, dusk, { ui: { accent: '#7fd3ff' }, post: null }] });
|
|
37
35
|
```
|
|
38
36
|
Rules (`core/styleParts.js`): plain `{ }` objects merge key by key at every depth; everything else replaces whole (arrays such as `sky.keyframes` and
|
|
39
37
|
`post`, functions, three.js objects); a key set to `null` removes it; `undefined` is ignored; nested lists flatten, so a pack can itself be a list of
|
|
@@ -43,16 +41,16 @@ parts; parts are never mutated. One object (not a list) is used as it is.
|
|
|
43
41
|
(exported by `threedog`); they are parts too:
|
|
44
42
|
```js
|
|
45
43
|
import { createEngine, postAdd, postRemove } from 'threedog';
|
|
46
|
-
import
|
|
44
|
+
import basePack from './style/index.js';
|
|
47
45
|
import { bloom } from '@threedog/post-effects';
|
|
48
|
-
createEngine({ canvas, style: [
|
|
46
|
+
createEngine({ canvas, style: [basePack, postAdd(myGrain, bloom({ strength: 0.6 })), postRemove('ao')] });
|
|
49
47
|
```
|
|
50
48
|
`postAdd(...effects)` appends; an effect whose `name` is already in the list (`'bloom'`, `'ao'`, `'outline'`) replaces that one in place.
|
|
51
49
|
`postRemove(...names)` drops effects by name. `{ post: null }` still clears the list; `{ post: [...] }` still replaces it whole.
|
|
52
50
|
|
|
53
|
-
**Retinting the procedural models.** `style.palette` holds the colors the trees, rocks, grass and flowers are built from (
|
|
54
|
-
`
|
|
55
|
-
`style: [
|
|
51
|
+
**Retinting the procedural models.** `style.palette` holds the colors the trees, rocks, grass and flowers are built from (the keys are the pack's own, e.g. `bark`, `leaf`, `rock`,
|
|
52
|
+
`grassTip`...; see `basePack.palette`). One part changes them all:
|
|
53
|
+
`style: [basePack, { palette: { leaf: 0xd98a3a } }]` (autumn); keys left out keep the pack's colors. A generator of your own written
|
|
56
54
|
with `function` (not an arrow) reads `this.palette`; the palette is part of the model cache key, so a changed palette rebuilds. `.glb` files and
|
|
57
55
|
models baked earlier keep their colors.
|
|
58
56
|
|
|
@@ -60,13 +58,14 @@ models baked earlier keep their colors.
|
|
|
60
58
|
Swapping the style must never change the map or the rules, only how they look. So these are **not** style fields, and a dev run throws an error
|
|
61
59
|
naming where each goes:
|
|
62
60
|
- water level, whether there is a sea, the water mesh size: `style.water.level / sea / size` -> `engine.use(water({ level, sea, size }))`
|
|
63
|
-
- terrain shape and size (seed, chunk size, resolution, water level, height functions): `style.terrain.config.*` -> `terrain({ ... })`. The
|
|
64
|
-
|
|
61
|
+
- terrain shape and size (seed, chunk size, resolution, water level, height functions): `style.terrain.config.*` -> `terrain({ ... })`. The looks
|
|
62
|
+
in `terrain.config` are `shading` (`'smooth'` | `'texture'` | `'flat'`), `colorResolution`, `normals` and `normalFn` (recipe 37); at run time
|
|
63
|
+
`engine.look.ground.set({ shading, colors, variation, detail })` (recipe 52)
|
|
65
64
|
Quality settings are not world state and may stay in a style (shadow `mapSize` and `low` overrides, water `segments`); players can override them in
|
|
66
65
|
settings. Packs under `packages/styles/**` are also checked by `threedog check` (R34).
|
|
67
66
|
|
|
68
67
|
## 1. Creating a new style pack
|
|
69
|
-
|
|
68
|
+
Run `threedog new-style` (or copy any pack folder into your game or a package of your own), edit the values in `index.js`, then switch to it in the game:
|
|
70
69
|
```js
|
|
71
70
|
import toon from './style/index.js';
|
|
72
71
|
const engine = createEngine({ canvas, style: toon });
|
|
@@ -80,19 +79,20 @@ Keys you will change most often:
|
|
|
80
79
|
|---|---|
|
|
81
80
|
| `materials` | The material per role. Three forms: a spec `{ default: { type: 'toon', steps: 3 }, water: { type: 'phong', shininess: 90 } }` (lambert / phong / standard / physical / toon / basic; a wrong type throws), any three.js material instance `water: new THREE.MeshMatcapMaterial({ matcap })` (cloned per use), or a function `prop: (params, role) => new THREE.ShaderMaterial({...})`. Style packs may create materials directly; games still go through `makeMaterial` |
|
|
82
81
|
| `antialias` | `false` for sharp pixel edges; omitted = on for desktop, off for phones (players can switch it in settings) |
|
|
83
|
-
| `post` | List of post effects
|
|
84
|
-
| `sky` `weather` `water` `terrain` `seasons` `clouds` | Sky keyframes (sun color and intensity over the day, fog color, shadows), rain and snow, water, terrain colors (`terrain.colors` palette, `terrain.biomeColors` ground type -> palette names, `terrain.steep` slope colors; a type with no color is gray; `terrain.config
|
|
85
|
-
| `character` |
|
|
82
|
+
| `post` | List of post effects (e.g. `[outline(), ao(), bloom()]`; `outline({ enabled: true })` draws edge lines); slots, the effects package, `fuse`, outline modes: [recipe 52](52-look.md#post-effect-chain) |
|
|
83
|
+
| `sky` `weather` `water` `terrain` `seasons` `clouds` | Sky keyframes (sun color and intensity over the day, fog color, shadows), rain and snow, water, terrain colors (`terrain.colors` palette, `terrain.biomeColors` ground type -> palette names, `terrain.steep` slope colors; a type with no color is gray; `terrain.config`: `shading` `'smooth'` (engine default) | `'texture'` (per-chunk color map) | `'flat'` (facets), `colorResolution`, `normals`, `normalFn`, recipe 37; `terrain.detail` a detail layer, recipe 53; `terrain.material` swaps the whole ground material, chunks have `uv` = world xz / chunk size; `water.material: (engine, { uniforms, waves, normalMap }) => Material` swaps the whole water surface, e.g. `applyEffects(new THREE.MeshToonMaterial({ color }), { clouds: false, patches: [waves] })` keeps the built-in waves), seasonal tints |
|
|
84
|
+
| `character` | `animation.fade`: skeletal animation transition seconds. Bodies are assets, not style: `createPlayer({ model })` with a registered model, a GLB asset name or `{ rig }`; part colors are material roles or `{ colors }` per character (recipe 13). Without a model a gray capsule |
|
|
86
85
|
| `pickup` `particles` | Items on the ground (`pickup.model(item, { color, size })` returns an Object3D or geometry; without it a plain gray box), particle presets (dust smoke leaves splash sparks...) |
|
|
87
86
|
| `triggers` `grid` | Tool colors, not art: trigger zone wireframe (`debugColor`), grid placement preview (`ok` / `bad`). The engine has neutral defaults (gray; light = can place, dark = cannot); a pack may recolor them |
|
|
88
87
|
| `ui` | UI colors, `font` (a CSS font-family list), `fonts` (font asset names to load at start, the files in an asset pack: recipes/05 §3b), extra `css`, `templates` that replace a whole UI piece |
|
|
89
88
|
|
|
90
|
-
|
|
89
|
+
## 1b. Lights and stalls
|
|
90
|
+
Every engine has `engine.lights = { sun, hemi }`, plain three.js lights. Without a style pack they are a neutral placeholder (white
|
|
91
91
|
hemisphere + neutral directional light, no shadows); the look (sun color and intensity curves, sky colors, fog, shadow softness, exposure, tone
|
|
92
|
-
mapping) comes from the style pack's `sky`, `exposure` and `toneMapping`, and the sky module drives the same two lights.
|
|
93
|
-
|
|
92
|
+
mapping) comes from the style pack's `sky`, `exposure` and `toneMapping`, and the sky module drives the same two lights. At run time:
|
|
93
|
+
`engine.look.lights.set(...)` (recipe 52); to light the world yourself: recipe 38.
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
three.js builds one shader program per material for each light setup. `engine.start()` compiles everything visible behind the
|
|
96
96
|
loading screen (`engine.startup.compileMs`), but adding or removing a light later, or toggling `visible` on one, changes the setup and compiles again:
|
|
97
97
|
a frame can freeze for hundreds of milliseconds. Keep the number of lights fixed: create them up front and fade with `intensity` (0 = off, no
|
|
98
98
|
recompile). In dev the console warns (code `light-recompile`) when programs were compiled in a frame where the lights changed.
|
|
@@ -118,7 +118,7 @@ camera. Options and handle: `../api/lightPool.md`.
|
|
|
118
118
|
Models are assets, not style keys: content names them, an asset pack maps the names to files or generators. Register a later manifest with the same
|
|
119
119
|
name to swap one:
|
|
120
120
|
```js
|
|
121
|
-
engine.assets.manifest(
|
|
121
|
+
engine.assets.manifest(yourAssets); // assets from an asset pack you have: trees, rocks, flowers... built in code
|
|
122
122
|
engine.assets.manifest({ name: 'mine', models: { pine: () => myPineGeometry(), well: '/models/well.glb' } }); // replaces pine, adds well
|
|
123
123
|
```
|
|
124
124
|
Vegetation takes a geometry (`geometry: await engine.assets.geometry('pine')`, the first mesh in the model) or a whole model with one material per
|
|
@@ -143,81 +143,16 @@ A missing `#include` anchor throws. A hand-written `ShaderMaterial` can `#includ
|
|
|
143
143
|
`render/effects.js`) with `engine.uniforms` as its uniforms.
|
|
144
144
|
`material.clone()` does not carry patches (three's `Material.copy` skips `onBeforeCompile`): a pack's Material instance in `materials` is fine
|
|
145
145
|
(`makeMaterial` keeps its patches); when you clone one yourself, apply the effects to the clone again.
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
| Field | Meaning | Checked |
|
|
149
|
-
|---|---|---|
|
|
150
|
-
| `needs.data` | Program inputs the code reads: `'instancing'`, `'instancingColor'`, `'vertexColors'`, `'skinning'`, `'batching'` | when the program compiles (console.error once per material) |
|
|
151
|
-
| `needs.patches` | Patches it builds on, e.g. `['world']` for the `vThreedogWorld` varying (world position; `applyEffects` adds `world` itself when a patch needs it) | when added |
|
|
152
|
-
| `conflicts` | Patch names it cannot share a material with | when added, both ways |
|
|
153
|
-
| `uniforms` | A uniform name belongs to one patch; share `engine.uniforms` (`uTime`, `uWind`, `uCloud`...) instead of making your own `uTime` | when added |
|
|
154
|
-
| `shadow` | Render steps: without it the color pass only; `true` also runs its vertex code in the depth (sun / spot shadows) and distance (point-light shadows) passes | - |
|
|
155
|
-
| `cacheKey` | Changes whenever the GLSL text changes (defines, branches), never for uniform values; the program key joins every patch's `name=cacheKey` in order | same name + cacheKey with different code throws |
|
|
156
|
-
```js
|
|
157
|
-
applyEffects(mat, { wind: 0.03, season: 'foliage', patches: [{ name: 'ripple', needs: { patches: ['world'] }, conflicts: ['wind'],
|
|
158
|
-
glsl: { fragment: { color_fragment: 'diffuseColor.rgb *= 0.9 + 0.1 * sin(vThreedogWorld.x);' } } }] }); // throws: 'wind' and 'ripple' cannot be combined
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
## 2c. Post effects (slots)
|
|
162
|
-
Post-processing is an ordered list of named effects. Each runs in a slot, then by `order` (low first):
|
|
163
|
-
`scene` (replaces the scene render, one at a time, e.g. pixelation) -> `hdr` (linear color: outline, AO, bloom) -> tone mapping -> `ldr` (sRGB: LUT,
|
|
164
|
-
palette, grain, vignette) -> `final` (FXAA / SMAA).
|
|
165
|
-
An effect is `{ name, slot, order, params, create(ctx) => pass, update?(pass, params) }`; under WebGL the pass is any three.js postprocessing Pass. It
|
|
166
|
-
is built the first time it is on.
|
|
167
|
-
```js
|
|
168
|
-
import { bloom, outline } from '@threedog/post-effects'; // never from another style pack: packs do not depend on each other
|
|
169
|
-
import { LUTPass } from 'three/addons/postprocessing/LUTPass.js';
|
|
170
|
-
const toon = { name: 'toon', post: [outline({ enabled: true, thickness: 1.5 }), bloom({ strength: 0.2 }),
|
|
171
|
-
{ name: 'lut', slot: 'ldr', params: { lut: myLut }, create: ({ params }) => new LUTPass({ lut: params.lut }) }] };
|
|
172
|
-
// at runtime (settings, photo mode, a game's own effect):
|
|
173
|
-
engine.post.get('bloom')?.set({ strength: 0.6 });
|
|
174
|
-
engine.post.enable('outline', false); // also engine.post.enable('antialias', false)
|
|
175
|
-
const h = engine.post.add(myVignette, { slot: 'ldr', order: 10 }); h.remove();
|
|
176
|
-
```
|
|
177
|
-
An effect that reads scene depth (`needsDepth: true`, e.g. `outline`) must run before any pass that swaps buffers (a `ShaderPass`, a scene-slot
|
|
178
|
-
`RenderPixelatedPass`, the tone-mapping output): only the buffer the scene render wrote holds scene depth. A chain that breaks this throws when the
|
|
179
|
-
effect is added or enabled, naming both effects; give the depth reader a lower `order`. `dof` copies the scene depth into its own output
|
|
180
|
-
(`pass.keepsDepth = true`, no extra pass), so `dof` and `outline` can both be on as long as `dof` has the lower `order` (default: dof 5, outline 10;
|
|
181
|
-
lines stay sharp over the blur). `threedog style check` reports the other order as an error.
|
|
182
|
-
`createEngine({ post: { bloom: false } })` overrides an effect's startup on/off; `costly: true` effects start off on low-tier devices. MSAA
|
|
183
|
-
(`antialias`) works with every effect on.
|
|
184
|
-
The settings menu shows `bloom` / `ao` toggles only when the style pack registers effects with those names.
|
|
185
|
-
|
|
186
|
-
### Optional post effects package and `fuse`
|
|
187
|
-
The engine ships no effects; `@threedog/post-effects` (install it like `@threedog/terrain-noise`, import only what you use) has `bloom`, `ao`,
|
|
188
|
-
`outline`, `dof` (all `hdr`; outline and dof read depth) and `lut` (contrast / saturation / warm-cool / optional 3D LUT), `grain`, `vignette`,
|
|
189
|
-
`chromatic` (`ldr`). A style pack lists the ones it wants in its own `post`. `lut`, `grain`, `vignette`, `chromatic`, `dof`, `ao` and `outline` are off
|
|
190
|
-
until `enabled: true`.
|
|
191
|
-
```js
|
|
192
|
-
import { vignette, grain, lut } from '@threedog/post-effects';
|
|
193
|
-
createEngine({ canvas, style: [lowpoly, postAdd(lut({ saturation: 1.1, temperature: 0.15 }), vignette(), grain({ amount: 0.04 }))] });
|
|
194
|
-
engine.post.enable('vignette', true); // photo mode, settings...
|
|
195
|
-
engine.post.get('grain')?.set({ amount: 0.1 }); // updates in place
|
|
196
|
-
```
|
|
197
|
-
`fuse` is how a light color effect avoids a fullscreen pass of its own: instead of `create()` it carries a GLSL snippet
|
|
198
|
-
`fuse: { uniforms: { uMyAmount: 'float' }, values: p => ({ uMyAmount: p.amount }), glsl: 'color.rgb *= 1.0 - uMyAmount * length(vUv - 0.5);' }`.
|
|
199
|
-
Effects with a `fuse` that are on and next to each other in one slot (never `scene`) are compiled into ONE shader and drawn in one pass, in
|
|
200
|
-
`order`; turning one off, `set()` or `remove()` recompiles or just updates the uniforms. The snippet edits `vec4 color` and may use `vUv`,
|
|
201
|
-
`tDiffuse`, `uTime`, `uResolution`, `fxHash(vec2)`; uniform names are shared by the whole group, so prefix them with the effect name. A snippet that
|
|
202
|
-
samples `tDiffuse` at other positions (blur, color fringe) sets `reads: true` and then starts a new group. Four ldr effects: 1 pass instead of 4.
|
|
203
|
-
Effects without `fuse` (bloom, outline, `dof`...) stay one pass each.
|
|
204
|
-
|
|
205
|
-
### Outline modes
|
|
206
|
-
`outline({ mode: 'depth' | 'normal' | 'both' })`: `depth` (default, silhouettes), `normal` (creases; the scene is drawn once more with normals, so
|
|
207
|
-
it is `costly` and off on low-tier devices), `both`. `fadeWithDistance: false` keeps lines at any distance; `wobble: 1.5` jitters the lines by up to 1.5
|
|
208
|
-
pixels at 8 steps a second (hand-drawn). To exempt objects: `outline({ offLayer: OUTLINE_OFF_LAYER })` and `mesh.layers.enable(OUTLINE_OFF_LAYER)`
|
|
209
|
-
(three.js layers; layer 0 stays on, so the object still renders normally; costs one extra render of just the exempt objects, nothing when
|
|
210
|
-
`offLayer` is `null`). Normal mode draws the scene with a plain override material, so wind-animated foliage lines up with its static shape.
|
|
211
|
-
|
|
212
|
-
Textures by asset name, grain / paper / strokes (`detail`), shadow tint, rim light, toon ramps and the GLSL exits are all spec keys: recipe 37.
|
|
146
|
+
What a patch declares (`needs`, `conflicts`, `shadow`, `cacheKey`) and the chunk names: recipe 43, exit 2. Textures by asset name, `detail`,
|
|
147
|
+
shadow tint, rim light and toon ramps are material spec keys: recipe 48 (keys), recipe 43 (what they do).
|
|
213
148
|
|
|
214
149
|
## 3. When the engine gets a new "look parameter"
|
|
215
|
-
Hard rule 1: a module only writes a neutral gray fallback and reads `engine.style.xxx ?? fallback`, **and the real value is added to
|
|
150
|
+
Hard rule 1: a module only writes a neutral gray fallback and reads `engine.style.xxx ?? fallback`, **and the real value is added to a style pack
|
|
216
151
|
(its `index.js`) at the same time** (with a one-line comment saying what it means),
|
|
217
152
|
and the new field gets a doc comment in `types/style.d.ts` (`docs/api/` is generated from there). Materials always go through
|
|
218
153
|
`makeMaterial('role', { color })`, leaving the surface feel to `style.materials[role]`. Whose style: `engine.makeMaterial('role', { color })` uses that
|
|
219
154
|
engine's pack; the free `makeMaterial()` uses the first engine created (fine for one engine, a dev warning when two packs run). Engine code and style packs always
|
|
220
|
-
go through the engine (`
|
|
155
|
+
go through the engine (`pickup.model(item, { color, size }, engine)`, `water.material(engine, ...)`), so two engines never share materials.
|
|
221
156
|
Look parameters only: a field that changes the world (a level, a size, a seed) goes to the module's options, not the style (section 0c).
|
|
222
157
|
|
|
223
158
|
## 4. Verify
|
|
@@ -226,7 +161,7 @@ Look parameters only: a field that changes the world (a level, a size, a seed) g
|
|
|
226
161
|
- `npm run map`: the "style pack keys" table in CODEMAP is updated.
|
|
227
162
|
- Take screenshots only when the look changed, and compare two times of day: `npm run shot -- / --time 12:00`, `npm run shot -- / --time 18:30`
|
|
228
163
|
(images go to .threedog/shots/).
|
|
229
|
-
- It must still run without a style pack: `
|
|
164
|
+
- It must still run without a style pack: start once with `createEngine({ canvas })` and no `style` (gray placeholders, one console note per missing piece).
|
|
230
165
|
|
|
231
166
|
## 5. Sounds and music (the game's, not the style pack's)
|
|
232
167
|
Sounds are game config, passed to `createEngine({ audio: { sounds, ambience, music, footsteps, levels } })` and read back as `engine.audio.config`; a
|