threedog 0.2.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/Assets.js +12 -0
- package/core/Engine.js +13 -4
- package/core/describeRender.js +7 -1
- package/core/grid.js +127 -0
- package/core/gridLoad.js +19 -0
- package/core/loop.js +7 -2
- package/core/renamed.js +1 -0
- package/core/styleParts.js +9 -7
- package/docs/AI.md +28 -23
- package/docs/API.md +3 -3
- package/docs/CODEMAP.md +5 -3
- package/docs/COMMANDS.md +5 -3
- package/docs/CONVENTIONS.md +6 -6
- package/docs/api/assets.md +1 -0
- package/docs/api/characters.md +3 -2
- package/docs/api/engine.md +3 -3
- package/docs/api/style.md +7 -7
- package/docs/api/tools.md +3 -2
- package/docs/api/vegetation.md +1 -0
- package/docs/recipes/01-new-game.md +41 -43
- package/docs/recipes/02-npc.md +24 -24
- 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/07-flow-scenes-pause.md +2 -2
- package/docs/recipes/08-weather-sky.md +5 -5
- package/docs/recipes/09-style-pack.md +35 -100
- package/docs/recipes/13-animation.md +22 -6
- package/docs/recipes/14-custom-module.md +6 -7
- package/docs/recipes/15-perf.md +8 -0
- package/docs/recipes/16-dev-bridge.md +7 -7
- 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/22-shop-gold.md +16 -16
- package/docs/recipes/23-ops.md +2 -2
- package/docs/recipes/27-net.md +2 -2
- package/docs/recipes/28-terrain.md +2 -2
- package/docs/recipes/29-grid.md +47 -27
- package/docs/recipes/34-environment-lighting.md +2 -2
- 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 +47 -42
- package/docs/recipes/42-terrain-shape.md +1 -1
- package/docs/recipes/43-shader-patches-surface-looks.md +35 -20
- package/docs/recipes/44-water-weather-look-hooks.md +5 -5
- package/docs/recipes/45-cascaded-shadows.md +1 -1
- package/docs/recipes/46-blender-art-route.md +4 -4
- package/docs/recipes/47-island-snow-backdrop.md +4 -3
- package/docs/recipes/48-make-material.md +2 -2
- package/docs/recipes/49-game-module-contract.md +25 -25
- package/docs/recipes/51-capability-catalog.md +2 -2
- package/docs/recipes/52-look.md +43 -5
- package/docs/recipes/53-ground-up-close.md +58 -0
- package/examples/action/GAMEMAP.md +2 -2
- package/examples/action/main.js +3 -2
- package/examples/sheepisland/GAMEMAP.md +1 -1
- package/examples/styletest/content/npcs.js +1 -1
- package/examples/styletest/main.js +1 -1
- package/examples/world/content/npcs.js +1 -1
- package/examples/world/main.js +1 -1
- package/index.d.ts +8 -2
- package/index.js +3 -2
- package/llms.txt +9 -8
- package/modules/characters/Character.js +21 -19
- package/modules/characters/assetModel.js +35 -7
- package/modules/characters/proceduralRig.js +45 -10
- package/modules/content/index.js +1 -1
- package/modules/gameplay/pickups.js +1 -1
- package/modules/vegetation/Vegetation.js +15 -3
- package/modules/vegetation/index.js +1 -1
- package/modules/vegetation/nearFade.js +39 -0
- package/package.json +2 -1
- package/render/detail.js +39 -15
- package/types/core.d.ts +7 -5
- package/types/gameplay.d.ts +12 -6
- package/types/style.d.ts +20 -15
- package/types/world.d.ts +7 -1
|
@@ -62,15 +62,15 @@ are not core keys either: they come from the game (`presets.player.*`, `interact
|
|
|
62
62
|
```js
|
|
63
63
|
// content/actions.js
|
|
64
64
|
export default {
|
|
65
|
-
kick: { keys: ['KeyF'], label: '
|
|
66
|
-
save: { keys: ['KeyK'], label: '
|
|
67
|
-
load: { keys: ['KeyL'], label: '
|
|
65
|
+
kick: { keys: ['KeyF'], label: 'Push / kick' },
|
|
66
|
+
save: { keys: ['KeyK'], label: 'Save' },
|
|
67
|
+
load: { keys: ['KeyL'], label: 'Load' },
|
|
68
68
|
};
|
|
69
69
|
```
|
|
70
70
|
Don't forget to add it to the exports in `content/index.js` (`export default { ..., actions }`), otherwise `engine.content.load(data)` will not load
|
|
71
71
|
it (it calls `engine.input.define(name, keys, label)`). What happens on press is written in main.js, read inside a fixed step so it lands on a tick:
|
|
72
72
|
`engine.onFixed(() => { if (engine.input.pressed('kick')) engine.ops.run('ball.kick', {}, { source: 'player' }); })` (a gameplay action is an op,
|
|
73
|
-
recipes/23-ops.md). A game that does not use content calls `engine.input.define('kick', 'KeyF', '
|
|
73
|
+
recipes/23-ops.md). A game that does not use content calls `engine.input.define('kick', 'KeyF', 'Push / kick')` directly.
|
|
74
74
|
|
|
75
75
|
**The engine does not perform the `save` / `load` actions for you**: they only register the keys; after the press you call the engine yourself in
|
|
76
76
|
main.js. Saving and loading are async (`Promise<boolean>`): await them, and say "saved" only on `true` (on `false` the engine already showed why).
|
|
@@ -78,8 +78,8 @@ Loading a slot to keep playing from it is `engine.session.load`, which leaves no
|
|
|
78
78
|
```js
|
|
79
79
|
import { toast } from 'threedog';
|
|
80
80
|
engine.onFixed(() => { // read keys in the fixed step like every gameplay key; the async work runs after it
|
|
81
|
-
if (engine.input.pressed('save')) engine.saves.save('slot1').then(ok => ok && toast(engine, '
|
|
82
|
-
if (engine.input.pressed('load')) engine.session.load('slot1').then(ok => !ok && toast(engine, '
|
|
81
|
+
if (engine.input.pressed('save')) engine.saves.save('slot1').then(ok => ok && toast(engine, 'Saved'));
|
|
82
|
+
if (engine.input.pressed('load')) engine.session.load('slot1').then(ok => !ok && toast(engine, 'No save yet'));
|
|
83
83
|
});
|
|
84
84
|
engine.saves.autosave(3); // autosave to 'auto' every 3 minutes of play (waits while paused, on the title screen and during newGame / load)
|
|
85
85
|
```
|
|
@@ -97,9 +97,9 @@ engine.interactions.pickMode = 'aim'; // switch at runtime (enter
|
|
|
97
97
|
One object with two verbs = two interactions with different key actions; each key picks among its own action, and `engine.interactions.options` lists
|
|
98
98
|
one `{ action, id, label }` per key for a prompt that shows both:
|
|
99
99
|
```js
|
|
100
|
-
engine.input.define('
|
|
101
|
-
engine.interactions.add(
|
|
102
|
-
engine.interactions.add(
|
|
100
|
+
engine.input.define('take', 'KeyF', 'Take');
|
|
101
|
+
engine.interactions.add(thing, { label: 'Inspect', onUse: inspect }); // E
|
|
102
|
+
engine.interactions.add(thing, { label: 'Take', action: 'take', enabled: () => ready, onUse: take }); // F
|
|
103
103
|
```
|
|
104
104
|
**Who acts** is `engine.actor` (a world record id, default `'player'`). Interactions, trigger zones, objective-marker distances, the world simulation
|
|
105
105
|
center and the default `ctx.actor` of ops all measure from `engine.actorPosition()`. To let the user drive a boat or switch squad members, set
|
|
@@ -163,7 +163,7 @@ A save is one envelope; `engine.saves.collect()` returns it and `export` / `expo
|
|
|
163
163
|
it loads, together with the owed time, container goods and fields that name them; only ids the counter could have made are touched (own kind, `n` up
|
|
164
164
|
to the saved counter, each `n` once), so an authored `crate-2` stays as it is. A migrate step that needs another part gets the whole save as its
|
|
165
165
|
second argument: `migrate: { 1: (data, save) => … }`. <!-- r18-ignore-line -->
|
|
166
|
-
- **Grid layers diff too**: cells authored in `content/grids.js` (`
|
|
166
|
+
- **Grid layers diff too**: cells authored in `content/grids.js` (`plot: { …, layers: { soil: [[i, j, { tilled: true }]] } }`) are the baseline;
|
|
167
167
|
the <!-- r18-ignore-line -->
|
|
168
168
|
`grids` part (version 2) stores only changed cells (`set`) and emptied authored ones (`clear`), and keeps a diff for a grid the run does not
|
|
169
169
|
have. <!-- r18-ignore-line -->
|
|
@@ -16,15 +16,15 @@ The rest is written for A.
|
|
|
16
16
|
`content/items.js`:
|
|
17
17
|
```js
|
|
18
18
|
export default {
|
|
19
|
-
gold: { name: '
|
|
20
|
-
|
|
19
|
+
gold: { name: 'Gold', icon: '🪙', stack: 99999 }, // currency: one slot however much
|
|
20
|
+
medkit: { name: 'Medkit', price: 5 }, // price: read by the shop ops below
|
|
21
21
|
};
|
|
22
22
|
export const startItems = { gold: 12 };
|
|
23
23
|
```
|
|
24
24
|
`content/containers.js` (the shelf. `items` is the initial stock, placed only the first time; a shelf that was emptied by looting / selling stays
|
|
25
25
|
empty after loading, see recipe 03):
|
|
26
26
|
```js
|
|
27
|
-
export default { 'shop-
|
|
27
|
+
export default { 'shop-trader': { capacity: 6, items: { medkit: 3 } } };
|
|
28
28
|
```
|
|
29
29
|
Import it in `content/index.js` and put it in the exported object (`containers`).
|
|
30
30
|
|
|
@@ -63,38 +63,38 @@ engine.ops.define('shop.sell', {
|
|
|
63
63
|
In the dialogue, `if: { can: [...] }` shows a choice only when the op would succeed, and `do: { op: [...] }` runs it:
|
|
64
64
|
```js
|
|
65
65
|
// content/dialogues.js
|
|
66
|
-
const
|
|
67
|
-
const
|
|
66
|
+
const buyKit = ['shop.buy', { shop: 'shop-trader', item: 'medkit' }];
|
|
67
|
+
const sellKit = ['shop.sell', { shop: 'shop-trader', item: 'medkit' }];
|
|
68
68
|
export default {
|
|
69
|
-
|
|
70
|
-
speaker: '
|
|
69
|
+
trader: {
|
|
70
|
+
speaker: 'Trader',
|
|
71
71
|
nodes: {
|
|
72
72
|
start: {
|
|
73
|
-
text: '
|
|
73
|
+
text: 'What do you need?',
|
|
74
74
|
choices: [
|
|
75
|
-
{ text: '
|
|
76
|
-
{ text: '
|
|
77
|
-
{ text: '
|
|
75
|
+
{ text: 'Buy a medkit (5 gold)', next: 'start', if: { can: buyKit }, do: { op: buyKit } },
|
|
76
|
+
{ text: 'Sell a medkit (3 gold)', next: 'start', if: { can: sellKit }, do: { op: sellKit } },
|
|
77
|
+
{ text: 'Bye', next: 'end' },
|
|
78
78
|
],
|
|
79
79
|
},
|
|
80
80
|
},
|
|
81
81
|
},
|
|
82
82
|
};
|
|
83
83
|
```
|
|
84
|
-
- The shelf id (`'shop-
|
|
84
|
+
- The shelf id (`'shop-trader'`: a market stall, a ship's store, a vending machine) is any string, and the shelf contents are saved. A "shop window" is your own UI drawn from `shelf.list()`; its
|
|
85
85
|
buttons call `engine.ops.run('shop.buy', { shop, item })` and grey out with `engine.ops.can(...)`.
|
|
86
|
-
- Prices live on the item (`price` in items.js above), read with `e.inventory.item('
|
|
86
|
+
- Prices live on the item (`price` in items.js above), read with `e.inventory.item('medkit').price`; an item without one costs 1 here.
|
|
87
87
|
- Items with their own data (a used sword with `durability`, recipe 03): pass the entry key as `item` (`'sword#3'`, from `shelf.list()[i].key`);
|
|
88
88
|
`transfer` moves exactly that piece with its data, and `e.inventory.container(shop).get(item)` reads the data for a price
|
|
89
89
|
(`def.price * data.durability / 100`).
|
|
90
|
-
- Show a failure reason to the player through your own i18n string (`e.t('shop.' + r.
|
|
91
|
-
- `npx threedog ops` lists what can be bought right now if you add `offers` (see recipe 23); `npx threedog op shop.buy shop=shop-
|
|
90
|
+
- Show a failure reason to the player through your own i18n string (`e.t('shop.' + r.code)`); the engine shows nothing itself.
|
|
91
|
+
- `npx threedog ops` lists what can be bought right now if you add `offers` (see recipe 23); `npx threedog op shop.buy shop=shop-trader item=medkit`
|
|
92
92
|
buys from the terminal.
|
|
93
93
|
|
|
94
94
|
## 4. Gold HUD
|
|
95
95
|
Calling `hud.counter` again with the same id = update, and it leaves the DOM alone when the value is unchanged, so calling it every frame is cheap:
|
|
96
96
|
```js
|
|
97
|
-
engine.onFrame(() => engine.hud.counter('gold', { icon: '🪙', label: '
|
|
97
|
+
engine.onFrame(() => engine.hud.counter('gold', { icon: '🪙', label: 'Gold', value: engine.inventory.count('gold') }));
|
|
98
98
|
```
|
|
99
99
|
Loading a save replaces the whole inventory, and refreshing every frame follows naturally; no event listener is needed.
|
|
100
100
|
|
package/docs/recipes/23-ops.md
CHANGED
|
@@ -39,7 +39,7 @@ Rules that keep ops replayable and network-ready:
|
|
|
39
39
|
- **All "may I" checks live in `can`**, so `run` never stops halfway. A failure always has a reason (camelCase English). Show it to the player through
|
|
40
40
|
i18n (`e.t('op.shop.buy.' + r.code)`); the engine shows nothing itself.
|
|
41
41
|
- An op may call another op inside `run` (logged with `depth`); `can` must not call `run` or change state.
|
|
42
|
-
- Name ops `noun.verb`. A dot means "asking to do"; events (`noun:action`) mean "already happened". `run`
|
|
42
|
+
- Name ops `noun.verb`. A dot means "asking to do"; events (`noun:action`) mean "already happened". `run` emits your own domain events itself.
|
|
43
43
|
|
|
44
44
|
## 2. Who calls it, and when
|
|
45
45
|
| Caller | How | History `phase` / `source` |
|
|
@@ -172,4 +172,4 @@ What atomic covers, honestly: it copies the save parts that declared `saves.regi
|
|
|
172
172
|
|
|
173
173
|
Causal trace (`events.traceSize > 0`, recipe 06): failed ops are noted as `op:<name>` with their `code`; `collision.lineClear(a, b, { who })` as `sight` (blocked lines always, clear ones for the focused object only); NPC state changes as `npc:state`. A game's behavior notes its own mode switch with `engine.events.note('npc:mode', { obj: rec.id, data: { from: 'patrol', to: 'investigate' } })`; `events.traceFocus('guard-1')` makes one object verbose.
|
|
174
174
|
|
|
175
|
-
Atomic details: a rolled-back run still bumps `ops.revision` (it only goes up, never back to an old number) and its committed nested ops show in `ops.recent()` as `ok: false` with code `rolledBack`. `after` hooks run in commit order (nested first, then the outer op) once the outermost atomic op ends. The rollback does not run `afterLoad` and mutes the events its loads would emit, so atomic state must be plain data. `reason
|
|
175
|
+
Atomic details: a rolled-back run still bumps `ops.revision` (it only goes up, never back to an old number) and its committed nested ops show in `ops.recent()` as `ok: false` with code `rolledBack`. `after` hooks run in commit order (nested first, then the outer op) once the outermost atomic op ends. The rollback does not run `afterLoad` and mutes the events its loads would emit, so atomic state must be plain data. Failed results have no `reason`: reading it throws `renamed-api` and points to `code`.
|
package/docs/recipes/27-net.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Co-op multiplayer: net() (host authority + state sync)
|
|
2
2
|
|
|
3
|
-
**What it is**: an optional module for slow, cooperative games (
|
|
3
|
+
**What it is**: an optional module for slow, cooperative games (a shared base or farm, a co-op puzzle, a turn-based board, trading). One player's browser is the **host** and
|
|
4
4
|
owns the game state; friends are **clients** that mirror it and ask for changes through ops. Not installed = no cost.
|
|
5
5
|
**What it is not (yet)**: action netcode. There is no client prediction or rollback, so a client's attack / roll / shot waits one round trip.
|
|
6
6
|
Souls-like and shooter games need that later step; the rules below (ops with self-contained args, state only changed in fixed steps and ops,
|
|
@@ -11,7 +11,7 @@ The same game code runs on every machine; only `role` and the transport differ.
|
|
|
11
11
|
```js
|
|
12
12
|
import { net, webSocket } from 'threedog';
|
|
13
13
|
|
|
14
|
-
const room = 'ws://192.168.1.5:8787/
|
|
14
|
+
const room = 'ws://192.168.1.5:8787/my-game';
|
|
15
15
|
const hosting = new URLSearchParams(location.search).has('host');
|
|
16
16
|
engine.use(net(hosting
|
|
17
17
|
? { role: 'host', transport: webSocket(room, { host: true }) }
|
|
@@ -16,7 +16,7 @@ engine.use(openWorld({ camera: 'follow', seed: 7, terrain: terrainPreset({ shape
|
|
|
16
16
|
const preview = createTerrain({ seed: 7, ...terrainPreset() }); // same heights before the engine starts
|
|
17
17
|
const dry = (x, z) => riverAt(x, z, preview.noise) === 0;
|
|
18
18
|
```
|
|
19
|
-
Its ground types are `beach snow rock riverbank wetland savanna forest highland meadow`;
|
|
19
|
+
Its ground types are `beach snow rock riverbank wetland savanna forest highland meadow`; a style pack colors them (`terrain.colors`)
|
|
20
20
|
(`style.terrain.biomeColors`), and `terrainStrings` names them for `describe()`. Other options:
|
|
21
21
|
`heightScale mountains rivers riverWidth biomes noise island canyon` (types in the package's `index.d.ts`).
|
|
22
22
|
|
|
@@ -72,7 +72,7 @@ engine.ops.define('path.sand', { args: { at: 'position' }, // a sandy path; a
|
|
|
72
72
|
Read the ground with `engine.surface(x, z)` (also `slope`, `groundType`, `waterAt`) and put an object on it with `engine.snapToGround(obj)`. Don't
|
|
73
73
|
raycast the terrain for this: the height function is exact and works before the chunk has a mesh.
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
Crisp ground color borders, triangle cut, normals, bounds margin, height from a grid: `37-terrain-look-hooks.md`.
|
|
76
76
|
|
|
77
77
|
## 5. Where the ground ends: `shape`
|
|
78
78
|
|
package/docs/recipes/29-grid.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
# Grid placement:
|
|
1
|
+
# Grid placement: towers, furniture, buildings, crops
|
|
2
2
|
|
|
3
3
|
Requires module `grids()` and `world()` (`openWorld()` includes world; grids is opt-in and costs nothing when not installed). The API list is in
|
|
4
4
|
`../api/grids.md`.
|
|
5
5
|
A grid turns world positions into cells. Things placed on it are ordinary `engine.world` records; per-cell state that is not a thing (tilled soil, wet
|
|
6
|
-
soil, a painted floor) lives in **layers**.
|
|
6
|
+
soil, creep on a board, a painted floor) lives in **layers**. Per-cell gameplay state always goes here; `terrain.edit({ paint })` is only for landscape ground types (roads, sand),
|
|
7
7
|
see `28-terrain.md`.
|
|
8
8
|
Works on any ground: procedural terrain, a Blender level, an indoor floor. Heights come from `engine.surface`, ground types from `engine.groundType`.
|
|
9
9
|
|
|
@@ -11,77 +11,97 @@ Works on any ground: procedural terrain, a Blender level, an indoor floor. Heigh
|
|
|
11
11
|
```js
|
|
12
12
|
import { grids, toast } from 'threedog';
|
|
13
13
|
engine.use(grids());
|
|
14
|
-
const
|
|
15
|
-
const room = engine.grids.add('room', { cell: 0.5, origin: [-3, -3], size: [12, 12], zone: 'house' });
|
|
14
|
+
const board = engine.grids.add('board', { cell: 1, origin: [0, 0], size: [16, 12] }); // several grids may exist: a tower-defense board,
|
|
15
|
+
const room = engine.grids.add('room', { cell: 0.5, origin: [-3, -3], size: [12, 12], zone: 'house' }); // a dungeon or house room,
|
|
16
|
+
const plot = engine.grids.add('plot', { cell: 1, origin: [20, 0], size: [8, 8] }); // a garden plot
|
|
16
17
|
|
|
18
|
+
engine.grids.define('tower', { size: [2, 2], kind: 'tower', fields: { level: 1 } }); // 2x2 cells on the board
|
|
17
19
|
engine.grids.define('crop', { layer: { soil: 'tilled' }, fields: { plantedAt: 0 } }); // only on cells whose soil layer has tilled
|
|
18
20
|
engine.grids.define('bed', { size: [2, 1], kind: 'furniture', fields: { model: 'bed' } }); // 2x1 cells; world record kind 'furniture'
|
|
19
21
|
engine.grids.define('shed', { size: [3, 2], ground: ['grass', 'dirt'], flat: 0.2 }); // engine.groundType must match; max 0.2 m height difference
|
|
20
22
|
engine.grids.define('crate', { size: [1, 1], can: (e, { cell }) => (cell[1] > 2 ? true : 'tooCloseToRoad') }); // your own rule
|
|
21
23
|
```
|
|
22
|
-
Coordinates: `
|
|
23
|
-
`
|
|
24
|
+
Coordinates: `board.toCell(pos)` -> `[i, j]`, `board.toWorld(cell, size?, rotation?)` -> footprint center on the ground, `board.snap(pos)`,
|
|
25
|
+
`board.inside(cell)`, `board.footprint(cell, size, rotation)`.
|
|
24
26
|
Cell `[0, 0]` starts at `origin`. A footprint is anchored at its min corner; `rotation` is quarter turns (0-3), odd turns swap width and depth.
|
|
25
27
|
|
|
26
28
|
## 2. Place, pick up, move: always ops
|
|
27
29
|
```js
|
|
28
|
-
engine.ops.run('grid.place', { grid: '
|
|
30
|
+
engine.ops.run('grid.place', { grid: 'room', item: 'bed', cell: [4, 4], rotation: 1 }); // { ok, value: record id } or { ok: false, code, facts, nextActions }
|
|
29
31
|
engine.ops.run('grid.move', { id: 'furniture-3', cell: [6, 2], rotation: 0 }); // its own cells do not block it; grid: 'room' moves it to another grid
|
|
30
32
|
engine.ops.run('grid.remove', { id: 'furniture-3' }); // value { item, kind }: put it back in the bag yourself
|
|
31
|
-
|
|
33
|
+
board.can('tower', [3, 5]); // ask only: true or a reason string
|
|
32
34
|
```
|
|
33
|
-
|
|
35
|
+
Failure codes: `outOfBounds` `occupied` `wrongGround` `notFlat` `not<Field>` (from a layer rule: `notTilled`) `noGrid` `idTaken` `unknown` `notPlaced`, or
|
|
34
36
|
your `can` reason.
|
|
35
|
-
Show them through i18n (`engine.t('grid.' + r.
|
|
37
|
+
Show them through i18n (`engine.t('grid.' + r.code)`; `grid.can()` returns the same names as a plain string); `engine.explain({ grid: { grid: 'room', item: 'bed', cell: [4, 4] } }).text` says which cell
|
|
36
38
|
and which record is in the way.
|
|
37
|
-
A placed record looks like `{ id, kind, position, rot, ...fields, grid: { id: '
|
|
39
|
+
A placed record looks like `{ id, kind, position, rot, ...fields, grid: { id: 'room', cell: [4, 4], size: [2, 1], rotation: 1, item: 'bed' } }`. Give
|
|
38
40
|
it a look with `world.present(kind, ...)` as usual (`rot` is the yaw in radians).
|
|
39
41
|
To build several things at once, call `grid.place` from your own op (`build.wall`), so each placement is still checked.
|
|
40
42
|
|
|
41
|
-
**Occupancy is not saved separately.** `
|
|
43
|
+
**Occupancy is not saved separately.** `room.at(cell)` / `room.area(cell, size)` read an index built from the world records' `grid` field, so a save
|
|
42
44
|
holds every placed thing once and can never disagree with itself.
|
|
43
45
|
**Don't go around it** (dev): the `grid` field of a placed record is frozen (editing it in place throws); `world.set / add` outside an op trigger the
|
|
44
46
|
ops guard; a record added by hand that overlaps another is reported and the cell stays with the first.
|
|
45
47
|
|
|
46
|
-
## 3. Layers: per-cell state (
|
|
48
|
+
## 3. Layers: per-cell state (soil, creep, paint)
|
|
47
49
|
```js
|
|
48
|
-
const soil =
|
|
49
|
-
engine.ops.define('
|
|
50
|
-
can: (e, { cell }) => (!
|
|
50
|
+
const soil = plot.layer('soil'); // created on first use; saved with the game (only cells that differ from content)
|
|
51
|
+
engine.ops.define('plot.till', { args: { cell: 'any' },
|
|
52
|
+
can: (e, { cell }) => (!plot.inside(cell) ? 'outOfBounds' : plot.at(cell) ? 'occupied' : true),
|
|
51
53
|
run: (e, { cell }) => soil.set(cell, { tilled: true }) });
|
|
52
|
-
engine.ops.define('
|
|
54
|
+
engine.ops.define('plot.water', { args: { cell: 'any' },
|
|
53
55
|
can: (e, { cell }) => (soil.get(cell)?.tilled ? true : 'notTilled'),
|
|
54
56
|
run: (e, { cell }) => soil.set(cell, { watered: true }) });
|
|
55
|
-
engine.ops.define('
|
|
56
|
-
engine.sky.at('06:00', () => engine.ops.run('
|
|
57
|
+
engine.ops.define('plot.dry', { run: () => soil.updateAll(d => { delete d.watered; }) }); // bulk change; return null from fn to clear a cell
|
|
58
|
+
engine.sky.at('06:00', () => engine.ops.run('plot.dry')); // daily reset is the game's job
|
|
57
59
|
```
|
|
58
60
|
`get(cell)`, `set(cell, patch)` (merge; a field set to null is deleted), `clear(cell)`, `query(cell?, size?)` -> `[{ cell, data }]`, `updateAll(fn)`, `count`.
|
|
59
61
|
Writes are saved gameplay state: do them inside an op or a fixed step (the guard reports anything else). Data must be plain values.
|
|
60
62
|
Cells that exist from the start go in content: `content/grids.js` <!-- r18-ignore-line -->
|
|
61
|
-
`
|
|
63
|
+
`plot: { cell: 1, origin: [20, 0], size: [8, 8], layers: { soil: [[3, 5, { tilled: true }]] } }` <!-- r18-ignore-line -->
|
|
62
64
|
(or `grids.add(name, { layers })`). They are the baseline: a save keeps only cells changed from it, so editing the content later still reaches old saves.
|
|
63
65
|
|
|
64
|
-
**Tiles.** The game gives a layer its colors: `
|
|
66
|
+
**Tiles.** The game gives a layer its colors: `plot.layer('soil', { tiles: { look: d => d.watered ? 0x5b3d2a : d.tilled ? 0x8a6243 : null } })`
|
|
65
67
|
(what the data means is gameplay, so no style pack ships these). A layer with tiles shows crisp per-cell quads just above the ground, following its
|
|
66
68
|
height (slopes, ramps, level meshes).
|
|
67
|
-
`tiles: { colors: { watered: 0x5b3d2a, tilled: 0x8a6243 } }` is the same as `look` from a table (first truthy field wins) and wins over a style pack's `style.grid.tiles`; `
|
|
69
|
+
`tiles: { colors: { watered: 0x5b3d2a, tilled: 0x8a6243 } }` is the same as `look` from a table (first truthy field wins) and wins over a style pack's `style.grid.tiles`; `plot.layer('soil', { tiles: false })` turns them off; `{ tiles: true }` draws every non-empty cell gray; `lift` raises them; `{ tiles:
|
|
68
70
|
(engine, layer) => ({ update(cells), dispose() }) }` is your own view. Options are read when the layer is first created.
|
|
69
71
|
|
|
70
72
|
## 4. Preview
|
|
71
73
|
```js
|
|
72
74
|
engine.input.define('place', ['Mouse0'], 'Place'); // gameplay reads input actions, not pointer.clicked (recipe 26)
|
|
73
|
-
const pv = engine.grids.preview({ grid: '
|
|
75
|
+
const pv = engine.grids.preview({ grid: 'board', item: 'tower', ...presets.keys.gridRotate }); // under the pointer; from: 'front' = the cell in front of the player
|
|
74
76
|
engine.onFrame(() => {
|
|
75
|
-
if (engine.input.pressed('place')) { const r = pv.place(); if (!r.ok) toast(engine, engine.t('grid.' + r.reason)); }
|
|
77
|
+
if (engine.input.pressed('place')) { const r = pv.place(); if (!r.ok) toast(engine, engine.t('grid.' + (r.code ?? r.reason))); } // reason only for 'noTarget'
|
|
76
78
|
});
|
|
77
79
|
pv.remove(); // leave build mode
|
|
78
80
|
```
|
|
79
81
|
The engine binds no key: `...presets.keys.gridRotate` (or `rotateKeys: ['KeyR']`) defines the action `rotate` on R, or bind that action yourself with
|
|
80
82
|
`input.define`; pass `rotate: 'myAction'` to read another one, `false` for none. Without a binding the preview warns once and only `pv.rotate()` turns
|
|
81
|
-
it. `pv.cell`, `pv.rotation`, `pv.ok`, `pv.reason`
|
|
83
|
+
it. `pv.cell`, `pv.rotation`, `pv.ok`, `pv.reason` (the `can` answer)
|
|
82
84
|
are readable every frame.
|
|
83
85
|
Colors come from `style.grid.ok / bad / previewOpacity`. `look: false` hides the default box; `look: (engine) => ({ update(view), hide(), dispose()
|
|
84
86
|
})` draws your own (`view = { cells, center, size, rotation, ok, reason }`).
|
|
85
87
|
|
|
86
|
-
## 5.
|
|
87
|
-
|
|
88
|
+
## 5. Baked data vs state the player changes
|
|
89
|
+
Anything the player can change in play must be runtime state, never baked into generated height or ground-type data: a tilled plot (farming), a dug or mined
|
|
90
|
+
tile (survival), a road or placed floor (city builder), a painted tile (puzzle), a breakable wall (action). Bake only what never changes: the landform (hills,
|
|
91
|
+
valleys, coast). Runtime state is a grid cell (`layer`), a `terrain.edit` (lower / raise / paint a ground type) or a world record (`grid.place`); all three are
|
|
92
|
+
saved, while a baked version cannot be changed in game and is not saved. A save keeps only what differs from the generated base.
|
|
93
|
+
```js
|
|
94
|
+
engine.use(terrain({ height: (x, z) => 3 + Math.sin(x * 0.05) * 2 }), world(), grids()); // generated: the landform only
|
|
95
|
+
engine.grids.add('plots', { cell: 4, origin: [8, 16], size: [4, 4] });
|
|
96
|
+
engine.ops.define('plot.dig', { args: { cell: 'any' },
|
|
97
|
+
can: (e, { cell }) => (e.grids.get('plots').inside(cell) ? true : 'outOfBounds'),
|
|
98
|
+
run: (e, { cell }) => {
|
|
99
|
+
const [x, z] = [8 + cell[0] * 4 + 2, 16 + cell[1] * 4 + 2]; // cell centre
|
|
100
|
+
e.terrain.edit({ x, z }, { shape: 'square', radius: 2, lower: 0.5, paint: 'dug' }); // ground shape and type
|
|
101
|
+
e.grids.get('plots').layer('state').set(cell, { dug: true }); // per-cell game state
|
|
102
|
+
} });
|
|
103
|
+
```
|
|
104
|
+
Undo with `paint: null` and `raise`. The test "player-changed ground" (`tests/specs/terrain-edit.mjs`) runs this pattern: save, then load into a fresh engine.
|
|
105
|
+
|
|
106
|
+
## 6. Verify
|
|
107
|
+
`engine.describe().grids` -> `{ room: { occupied, items: { bed: 1 }, layers: {} }, plot: { ..., layers: { soil: 30 } } }`. Tests: `npx threedog test "grid:"`.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Environment lighting
|
|
2
2
|
|
|
3
|
-
The engine gives the mechanism and sets nothing: `scene.environment` is `null` until a style pack or the game asks for one, so the
|
|
4
|
-
|
|
3
|
+
The engine gives the mechanism and sets nothing: `scene.environment` is `null` until a style pack or the game asks for one, so the default look
|
|
4
|
+
(lit by the sun and hemisphere lights only) is unchanged. The background (the sky dome or `sky.skybox`) and the environment lighting are two separate fields.
|
|
5
5
|
|
|
6
6
|
```js
|
|
7
7
|
engine.look.env.replace('sky'); // lit by the procedural sky; follows the time of day
|
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
# Making a new look from a reference picture
|
|
2
2
|
|
|
3
|
-
For an AI that is given one picture ("make it look like this") and has to turn it into a style pack.
|
|
4
|
-
`
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
For an AI that is given one picture ("make it look like this") and has to turn it into a style pack. The tools keep the work measurable: `threedog style palette`
|
|
4
|
+
and `style compare` measure pictures, `npm run new-style` makes the pack, `threedog style check` finds mistakes before you look at pixels. They never say which
|
|
5
|
+
colors are right; the taste is yours. What a style is and the composing rules are in `09-style-pack.md`; this page is the order of work.
|
|
6
|
+
|
|
7
|
+
## The loop (every round, in this order)
|
|
8
|
+
Looping "edit, screenshot, read the image" costs the most tokens and fixes the least. Numbers come first, pictures last.
|
|
9
|
+
1. **Measure the reference once** (step 2 below): `style palette <ref> --average`, then `style compare <ref> <your shot>`.
|
|
10
|
+
2. **Change one family of values** (colors, then materials, then post).
|
|
11
|
+
3. **Shoot small and compare to the previous shot**: `threedog shot styletest --view overview --size 480x270 --keep --compare <previous.png>`. It prints the
|
|
12
|
+
pixel diff and the look differences. Through MCP the `snap` tool is 480 px wide by default; `style_compare` gives the numbers.
|
|
13
|
+
4. **Read the numbers first, then at most one image per round.** Name the biggest remaining difference and fix only that.
|
|
14
|
+
5. **Wrong in a way the numbers do not explain?** Diagnose before guessing: `engine.debug.view('albedo' | 'lighting' | 'shadow' | 'normals')` shows which
|
|
15
|
+
layer is off, `engine.describe().look` shows who set each value and where (recipe 52). Nothing drawn: `threedog scene --hidden` (reasons per mesh).
|
|
16
|
+
6. **After two rounds without reaching the reference, take the next exit** and tell the user which and why: `look.surface.patch('detail' | 'lighting', glsl)`
|
|
17
|
+
-> painted textures (`map`, `normalMap`) -> `look.materials.replace` -> plain three.js (recipe 40 section 8). Never call it "close" to stop tuning.
|
|
18
|
+
7. **Every few rounds show the user the shot and the numbers.**
|
|
19
|
+
|
|
20
|
+
The loop is the same for every art direction; only what you measure and which value you move differ: flat (palette share, hard edges, no shading), painterly
|
|
21
|
+
(soft edges, texture, low contrast), low-poly (few flat colors, faceted light), realistic (exposure, tone mapping, lighting, material roughness). None is the default.
|
|
7
22
|
|
|
8
23
|
## What a style can change, and what it cannot
|
|
9
24
|
Can change (all in the style pack): colors (`palette`, `terrain.colors`, `background`, `water.color`, season tints), material types per role
|
|
@@ -18,57 +33,37 @@ world (a canyon instead of hills), say so instead of faking it with colors.
|
|
|
18
33
|
|
|
19
34
|
## Steps
|
|
20
35
|
1. **Keep the picture.** Put it in the game's `art/reference/` (one file per look, with a few lines of notes beside it on what to copy:
|
|
21
|
-
palette, mood, line work, light direction).
|
|
22
|
-
2. **Measure it.** `threedog style palette art/reference/ref.png --n 8` prints JSON (colors with share, hue, saturation,
|
|
23
|
-
largest block = ground / environment candidate, brightest = highlight / sky candidate, most saturated = accent candidate,
|
|
24
|
-
outline candidate) and one summary line such as `warm colors, mostly sand, low saturation, medium brightness, weak light/dark contrast`.
|
|
25
|
-
reads pixels in a headless browser (png, jpg, webp, gif, svg).
|
|
26
|
-
|
|
27
|
-
`--ignore-ui` (cuts a flat frame around the picture) or `--region x,y,w,h` (only that rectangle), `--crop cut.png` to save exactly what was
|
|
28
|
-
measured and open it, and `--average` for the overall mean color (HSL). The output says what area was measured.
|
|
36
|
+
palette, mood, line work, light direction). Use the highest-resolution picture you have: a small or compressed one gives wrong detail and brightness numbers.
|
|
37
|
+
2. **Measure it.** `threedog style palette art/reference/ref.png --n 8 --average` (MCP: `style_palette`) prints JSON (colors with share, hue, saturation,
|
|
38
|
+
brightness, and role hints: largest block = ground / environment candidate, brightest = highlight / sky candidate, most saturated = accent candidate,
|
|
39
|
+
darkest = shadow or outline candidate) and one summary line such as `warm colors, mostly sand, low saturation, medium brightness, weak light/dark contrast`.
|
|
40
|
+
It reads pixels in a headless browser (png, jpg, webp, gif, svg). The overall mean (`--average`) sets exposure and tint; the clusters pick the named
|
|
41
|
+
palette entries. A phone screenshot with a dark UI frame needs `--ignore-ui` or `--region x,y,w,h`; `--crop cut.png` saves exactly what was measured.
|
|
29
42
|
3. **Make the pack.** `npm run new-style sand-dune` creates `packages/styles/sand-dune` from a clean template (gray neutral materials, a sky, one
|
|
30
43
|
palette, no post effects, one palette-colored example model) and links it as `@threedog/style-sand-dune`. Import it in the game:
|
|
31
44
|
`import style, { assets } from '@threedog/style-sand-dune'`, `createEngine({ canvas, style })`, `engine.assets.manifest(assets)`.
|
|
32
|
-
To start from another pack's strengths instead, compose: `style: [
|
|
45
|
+
To start from another pack's strengths instead, compose: `style: [basePack, sandDune]` (later parts win key by key).
|
|
33
46
|
4. **Fill it in, in this order** (each step changes the picture most for the least work): `sky` and `background` (light and mood), `exposure` and
|
|
34
|
-
`toneMapping`, `palette` and `terrain.colors` / `biomeColors` (the measured colors, snapped to a few named ones
|
|
35
|
-
|
|
36
|
-
|
|
47
|
+
`toneMapping`, `palette` and `terrain.colors` / `biomeColors` (the measured colors, snapped to a few named ones; a reference usually has 5 to 8 that
|
|
48
|
+
matter), `materials` (`lambert` matte, `toon` banded, `phong` shiny, `standard` PBR, `basic` unlit), `post`, then `ui`. The first frame should already be close:
|
|
49
|
+
if it is far from the reference, fix sky, exposure, palette and material type before adding anything.
|
|
37
50
|
5. **Check.** `threedog style check sand-dune` (or the folder / file of a game's own style). It checks the final merged style, not each part:
|
|
38
51
|
unknown fields (with "did you mean"), world-state fields, palette keys a model reads but the style does not define, color formats (`'ff8800'`
|
|
39
52
|
without `#`, a float, a string `'0xff8800'`), post-effect conflicts (same name twice, two `scene` effects, a depth reader after a buffer-swapping
|
|
40
53
|
effect, `dof` ordered after `outline`), misspelled material roles and types, and asset names the pack does not register. `--json` gives the same list for
|
|
41
54
|
tools, `--assets file.js` adds another pack's names. Exit code 1 on errors. It is static: it cannot prove a pack holds no gameplay logic, only
|
|
42
55
|
the patterns R34 can see (`npm run check` runs R34).
|
|
43
|
-
6. **Look.** Take pictures with the same arguments every round so only the style differs
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
score (there is deliberately no "similarity %"); it turns "looks dirty / fragmented / too dark" into something you can change and re-measure.
|
|
51
|
-
7. **Iterate.** Change one family of values per round (colors, then materials, then post), re-run `style check`, shoot again. Stop when the
|
|
52
|
-
biggest remaining difference is a silhouette or a world rule: that is the asset pack or the game, not the style.
|
|
53
|
-
|
|
54
|
-
## Method lessons (from matching a reference picture)
|
|
55
|
-
- **Measure first, then build.** Run `style palette --average` and `style compare` before touching values; guessing by eye and getting "close" rejected
|
|
56
|
-
several times costs more than ten minutes of measuring.
|
|
57
|
-
- **Take the overall average, not clustered colors.** The tone of a picture is its mean (`--average`), not the 8 colors a median cut finds; a few
|
|
58
|
-
bright accents can dominate the clusters and say little about the look. Use clusters for picking named palette entries, the mean for exposure and tint.
|
|
59
|
-
- **Use the highest-resolution reference you have**, and crop away phone UI (`--ignore-ui` / `--region`). A small, compressed or UI-framed picture
|
|
60
|
-
gives wrong fine-detail and brightness numbers.
|
|
61
|
-
- **Restraint: an effect the reference does not show is not added.** Smudge filters, AO and tone changes stacked together made a picture worse with every
|
|
62
|
-
layer. Start with no post effects, add one only for a visible difference you named, and measure again after each one. `style check` warns when more than 2 are on.
|
|
63
|
-
- **The first frame should already be close.** Get sky, exposure, palette and material type right in the first round; if the first screenshot is far
|
|
64
|
-
from the reference, fix that (one family of values at a time) before adding anything.
|
|
65
|
-
- **Quantify "dirty / fragmented / dark".** Dirty = lower saturation or an off hue (average color), fragmented = fine detail ratio well above 1,
|
|
66
|
-
dark or flat = brightness and contrast. Change one thing, run `style compare` again, keep it if the number moved toward the reference and the picture looks better.
|
|
67
|
-
- **Nothing drawn?** Do not bisect with screenshots: `threedog scene --hidden` lists every mesh that exists but is not drawn and why (hidden parent, layers, scale 0,
|
|
68
|
-
empty geometry, behind the camera...). A mesh that is drawn but far too small is not an error there, but its position and bounding radius are listed:
|
|
69
|
-
compare them with what you meant (`scene` without `--hidden`).
|
|
56
|
+
6. **Look: the loop above.** Take pictures with the same arguments every round so only the style differs, and use the style test page's named camera
|
|
57
|
+
views (below), not free `--pos` shots. `threedog style compare art/reference/ref.png .threedog/shots/styletest.png [--region x,y,w,h]` prints brightness,
|
|
58
|
+
saturation, contrast, fine detail, average and main color of both and one sentence such as "the screenshot is 18% darker and 2.3x more broken up". There is
|
|
59
|
+
deliberately no "similarity %": the numbers turn "looks dirty / fragmented / too dark" into something you can change and re-measure. Dirty = lower
|
|
60
|
+
saturation or an off hue, fragmented = fine detail ratio well above 1, dark or flat = brightness and contrast. Keep a change if its number moved toward
|
|
61
|
+
the reference and the picture looks better. A phone UI frame in the screenshot skews the numbers: compare a `--region`.
|
|
62
|
+
7. **Stop** when the biggest remaining difference is a silhouette or a world rule: that is the asset pack or the game, not the style.
|
|
70
63
|
|
|
71
64
|
## Guard rails
|
|
65
|
+
- Restraint: an effect the reference does not show is not added. Start with no post effects, add one only for a visible difference you named, and measure
|
|
66
|
+
again after each one. `style check` warns when more than 2 are on.
|
|
72
67
|
- Never put gameplay or world values in the pack to match a picture; `style check` reports them as errors.
|
|
73
68
|
- Fonts and textures are asset-pack entries; the style names them (`ui.fonts: ['pixel']`, `terrain.detail.texture`), it does not carry files.
|
|
74
69
|
- Keep `npm run check` at 0 errors; a new pack adds no warnings.
|
|
@@ -78,12 +73,12 @@ world (a canyon instead of hills), say so instead of faking it with colors.
|
|
|
78
73
|
a shadow receiver, wood / stone / metal surfaces, a lit room (outside and inside) and the UI parts. Same arguments, same picture, so only the style differs.
|
|
79
74
|
- `threedog shot styletest --view <name> [--time day|dusk|night] [--weather clear|rain|snow]`; the same words work as URL parameters
|
|
80
75
|
(`?view=room&time=dusk&weather=rain`; also `style=none` for the engine's gray placeholders, `env=1` for environment lighting from the sky).
|
|
81
|
-
- Views: `overview` (everything
|
|
76
|
+
- Views: `overview` (everything: overall brightness, ground color, shadow darkness), `character` (close-up: character colors, outline, shadow on
|
|
82
77
|
the ground), `water` (water color, shore, fog at distance), `room` (the lamp and window light against the dark corners: ambient level, `ao`, bloom),
|
|
83
78
|
`path` (the camera moves along a fixed line at 2.5 m/s: with `--wait 4` the shot is the same frame every time; in a browser look for grass blades
|
|
84
79
|
and shadow edges that flicker or crawl), `ui` (HUD, dialogue line, bag window: the `ui` colors).
|
|
85
|
-
- Per round: shoot `overview`, `room` at `--time dusk`, and `character
|
|
80
|
+
- Per round: shoot `overview`, `room` at `--time dusk`, and `character`.
|
|
86
81
|
- `?panel=1` opens the workbench (needs the dev package `tweakpane`, installed with the repository's `npm install`; without it the page says so).
|
|
87
82
|
Live sliders change exposure, sky time, environment lighting, water color, post effects and UI colors at once; palette, terrain and wave values
|
|
88
83
|
are marked "needs rebuild" and only apply after "apply and rebuild". "export overrides" prints an object literal to paste into
|
|
89
|
-
`style: [
|
|
84
|
+
`style: [yourPack, { ... }]`; the original pack is never written, so the paste is the one place the change becomes real.
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
For an AI turning a reference picture into a style pack and hitting "the engine draws it this way". Colors and materials are in `09-style-pack.md`, the
|
|
4
4
|
order of work in `35-style-from-reference.md`. This page lists the places where the *shape* of a look was fixed in engine code and is now a style
|
|
5
|
-
setting.
|
|
5
|
+
setting. Each table lists the engine default; a style that sets nothing here gets those defaults. Style packs hold looks only
|
|
6
6
|
(rule R34): none of these settings move a hill, a river or a species list.
|
|
7
7
|
|
|
8
8
|
## Sky clouds: `style.sky.clouds`
|
|
9
9
|
| Key | Meaning | Default |
|
|
10
10
|
|---|---|---|
|
|
11
|
-
| `color`, `shade`, `coverage`, `scale`, `speed` |
|
|
11
|
+
| `color`, `shade`, `coverage`, `scale`, `speed` | lit color, shaded color, cover (multiplies the weather's cloud amount), size, drift speed | |
|
|
12
12
|
| `kind` | `'plane'` cheap, 3 noise samples. `'cumulus'` billowy, 8 noise samples per cloudy sky pixel, flatter projection (clouds fill the whole sky instead of crowding at the horizon), the sun side of each cloud is lit and the underside shaded | `'plane'` |
|
|
13
13
|
| `horizon` | added to `dir.y` before projecting; smaller = clouds shrink and crowd more towards the horizon | plane 0.08, cumulus 0.5 |
|
|
14
14
|
| `fade` | `[from, to]` in `dir.y`: invisible below `from`, full above `to` | plane `[0, 0.18]`, cumulus `[0, 0.12]` |
|
|
@@ -37,14 +37,14 @@ vec4 threedogClouds(vec3 dir, float time, vec3 sunDir, float night, vec3 lit, ve
|
|
|
37
37
|
```
|
|
38
38
|
In scope: the GLSL noise helpers `float threedogHash(vec2 p)` and `float threedogNoise(vec2 p)`, the built-in cloud uniforms (`uCloudScale`, `uCloudSpeed`, `uCloudHorizon`, `uCloudFade`...) and
|
|
39
39
|
your `clouds.uniforms` (declared for you; number, `THREE.Color`, `THREE.Vector2/3/4`, array of 2-4 numbers, or `THREE.Texture`). Change one later
|
|
40
|
-
with `engine.sky.dome.material.uniforms.
|
|
41
|
-
|
|
40
|
+
with `engine.sky.dome.material.uniforms.uEdge.value = 0.1`. A bad `kind`, a `glsl` without the function, or an unsupported uniform value throws with the fix.
|
|
41
|
+
Flat painted cloud blobs with a hard edge, multiplied by a texture:
|
|
42
42
|
```js
|
|
43
43
|
clouds: { color: 0xfff1dc, shade: 0x9aa8c4, uniforms: { uPaper: paperTexture, uEdge: 0.06 }, // paperTexture: any THREE.Texture, repeat wrapping
|
|
44
44
|
glsl: `vec4 threedogClouds(vec3 d, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cover){
|
|
45
45
|
vec2 p = d.xz / (d.y + 0.5) * 0.4 + vec2(0.004, 0.002) * time;
|
|
46
46
|
float n = threedogNoise(p) * 0.65 + threedogNoise(p * 2.3 + 5.0) * 0.35;
|
|
47
|
-
float a = smoothstep(1.0 - cover, 1.0 - cover + uEdge, n); // hard
|
|
47
|
+
float a = smoothstep(1.0 - cover, 1.0 - cover + uEdge, n); // hard edge
|
|
48
48
|
float up = clamp(0.5 + (n - threedogNoise(p + sunDir.xz * 0.1)) * 6.0, 0.0, 1.0); // sun side
|
|
49
49
|
vec3 c = mix(shade, lit, up) * texture2D(uPaper, p * 3.0).rgb * (0.35 + 0.65 * (1.0 - night));
|
|
50
50
|
return vec4(c, a * smoothstep(0.0, 0.1, d.y));
|
|
@@ -52,36 +52,38 @@ clouds: { color: 0xfff1dc, shade: 0x9aa8c4, uniforms: { uPaper: paperTexture, uE
|
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
## Ground color: `style.terrain.variation`
|
|
55
|
-
Terrain colors are baked
|
|
56
|
-
|
|
55
|
+
Terrain colors are baked by the (worker) generator from the palette: two palette colors blended by a noise, a small brightness grain, and an
|
|
56
|
+
optional layer of large patches. The defaults are shown (plain data, so it travels to the workers; unknown keys throw):
|
|
57
57
|
```js
|
|
58
58
|
terrain: { colors: { ... }, biomeColors: { ... },
|
|
59
59
|
variation: {
|
|
60
60
|
blend: { size: 33, strength: 1 }, // wavelength in m of the two-color noise; strength > 1 = harder contrast, < 1 = flatter
|
|
61
61
|
jitter: { size: 0.33, min: 0.92, range: 0.12 }, // grain cell in m; darkest multiplier; how much brighter it can get (0 range = no grain)
|
|
62
|
-
patches: { size: 90, strength: 0.15, levels: 0, tint: 0xb59a5a }, // optional second, large layer
|
|
62
|
+
patches: { size: 90, strength: 0.15, levels: 0, tint: 0xb59a5a }, // optional (example values): a second, large layer of color blocks
|
|
63
63
|
} }
|
|
64
64
|
```
|
|
65
|
-
`patches` is off unless given. It is a noise much larger than `blend`; `levels: 4` snaps it to 4 flat steps (
|
|
66
|
-
|
|
67
|
-
interpolate across a chunk cell (4 m at the default resolution), so blocks smaller than that blur; for crisp
|
|
65
|
+
`patches` is off unless given. It is a noise much larger than `blend`; `levels: 4` snaps it to 4 flat steps (hard-edged color blocks instead of a
|
|
66
|
+
soft blend); without `tint` it lightens and darkens the ground, with `tint` it pulls the color towards the tint where the noise is high. Vertex colors
|
|
67
|
+
interpolate across a chunk cell (4 m at the default resolution), so blocks smaller than that blur; for crisp blocks use `shading: 'texture'`
|
|
68
|
+
(recipe 37) or a texture (next). Which combination fits which look, and ground that looks wrong up close: recipe 53.
|
|
68
69
|
|
|
69
|
-
###
|
|
70
|
+
### Your own ground material
|
|
70
71
|
`style.terrain.material` (a Material or `(engine) => Material`) replaces the ground material. Chunk geometry has `uv = world xz / chunk size`, continuous
|
|
71
72
|
across chunk borders (checked by `tests/specs/appearance.mjs`), so a repeating texture is seamless whatever chunk it lands in; cloud shadows and
|
|
72
73
|
season tint are added to your material. `texture.repeat.set(8, 8)` = 8 tiles per chunk. Without UVs (steep sides stretch a top-down map), project
|
|
73
74
|
from the world position in a patch instead (`needs.patches: ['world']` gives `vThreedogWorld`):
|
|
74
75
|
```js
|
|
75
76
|
material: engine => applyEffects(new THREE.MeshLambertMaterial({ vertexColors: true }), { clouds: false, patches: [{
|
|
76
|
-
name: 'triplanar', needs: { patches: ['world'] }, uniforms: {
|
|
77
|
-
glsl: { fragment: { pars: 'uniform sampler2D
|
|
77
|
+
name: 'triplanar', needs: { patches: ['world'] }, uniforms: { uTex: { value: groundTexture }, uTexScale: { value: 0.1 } }, // groundTexture: repeat wrapping
|
|
78
|
+
glsl: { fragment: { pars: 'uniform sampler2D uTex; uniform float uTexScale;',
|
|
78
79
|
color_fragment: `vec3 n = abs(normalize(cross(dFdx(vThreedogWorld), dFdy(vThreedogWorld)))); n /= n.x + n.y + n.z;
|
|
79
|
-
diffuseColor.rgb *= texture2D(
|
|
80
|
-
+ texture2D(
|
|
80
|
+
diffuseColor.rgb *= texture2D(uTex, vThreedogWorld.zy * uTexScale).rgb * n.x + texture2D(uTex, vThreedogWorld.xz * uTexScale).rgb * n.y
|
|
81
|
+
+ texture2D(uTex, vThreedogWorld.xy * uTexScale).rgb * n.z;` } } }] })
|
|
81
82
|
```
|
|
82
83
|
A procedural noise texture is a `THREE.DataTexture` filled in a loop (`wrapS = wrapT = THREE.RepeatWrapping`, `colorSpace = THREE.SRGBColorSpace`,
|
|
83
|
-
`needsUpdate = true`)
|
|
84
|
-
`detail`
|
|
84
|
+
`needsUpdate = true`). The lighter alternative is a detail layer, `style.terrain.detail` / `look.ground.set({ detail })`: the same object as a
|
|
85
|
+
material spec's `detail` (`noise: 'grain' | 'paper' | 'stroke' | 'dabs'`, or `texture: 'name'`, or your own `glsl`; `scale`, `strength`, `fade`
|
|
86
|
+
...; keys in recipe 43), with no material of your own. Which to pick: recipe 53.
|
|
85
87
|
|
|
86
88
|
## Plants and wind
|
|
87
89
|
Audit of what the vegetation code fixes, split into mechanism (stays) and look (made a setting):
|
|
@@ -92,11 +94,11 @@ Audit of what the vegetation code fixes, split into mechanism (stays) and look (
|
|
|
92
94
|
| `GroundChunks`, `Vegetation.levelOf` | one InstancedMesh per species per chunk; rings decide LOD swap, draw distance, shadow distance; 3 ms placement budget; collision lag | mechanism, stays |
|
|
93
95
|
| wind sway shape | two sines (speed `1.2 + 0.6*uWind` and `2.9`, spatial phase from the instance origin), height-weighted, lean with wind strength | look: **`style.wind.glsl`** replaces it |
|
|
94
96
|
| wind speed | `uWindFreq` | already `style.wind.frequency` |
|
|
95
|
-
| season tint | `diffuseColor.rgb *= tint` (default) or a blend towards the tint; colors from `style.seasons` | look, both settings: `style.seasons.mode: 'multiply' \| 'mix'` (+ `strength`); see recipe
|
|
97
|
+
| season tint | `diffuseColor.rgb *= tint` (default) or a blend towards the tint; colors from `style.seasons` | look, both settings: `style.seasons.mode: 'multiply' \| 'mix'` (+ `strength`); see recipe 43 |
|
|
96
98
|
| defaults | `castShadow` = not `nearOnly`, `shadowRing` 1, `lodRing` 1 | per-species options, set them in the species |
|
|
97
99
|
|
|
98
100
|
```js
|
|
99
|
-
wind: { frequency: 1, uniforms: { uSteps: 3 }, //
|
|
101
|
+
wind: { frequency: 1, uniforms: { uSteps: 3 }, // stepped sway: plants snap between 3 poses instead of a smooth sine
|
|
100
102
|
glsl: `void threedogWind(inout vec3 transformed, vec3 ip, vec3 position){
|
|
101
103
|
float s = floor(sin(uTime * uWindFreq + ip.x * 0.3 + ip.z * 0.2) * uSteps) / uSteps;
|
|
102
104
|
transformed.x += s * max(position.y, 0.0) * THREEDOG_WIND_AMP * uWind;
|