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.
Files changed (244) hide show
  1. package/README.md +4 -4
  2. package/core/Animator.js +1 -0
  3. package/core/Assets.js +28 -0
  4. package/core/DebugOverrides.js +143 -0
  5. package/core/Describe.js +14 -3
  6. package/core/Engine.js +44 -72
  7. package/core/Events.js +59 -1
  8. package/core/I18n.js +2 -2
  9. package/core/Inspect.js +12 -32
  10. package/core/InspectScene.js +7 -3
  11. package/core/MaterialInfo.js +32 -0
  12. package/core/Ops.js +43 -59
  13. package/core/Saves.js +5 -4
  14. package/core/UrlState.js +3 -2
  15. package/core/Vars.js +1 -0
  16. package/core/Views.js +49 -0
  17. package/core/actor.js +2 -2
  18. package/core/assetReport.js +83 -0
  19. package/core/catalog.js +169 -0
  20. package/core/checks.js +67 -0
  21. package/core/claims.js +51 -0
  22. package/core/debugView.js +76 -0
  23. package/core/describeRender.js +51 -0
  24. package/core/describeText.js +11 -4
  25. package/core/errorCodes.js +33 -0
  26. package/core/errorHints.js +6 -1
  27. package/core/grid.js +127 -0
  28. package/core/gridLoad.js +19 -0
  29. package/core/holds.js +106 -0
  30. package/core/lifecycle.js +1 -0
  31. package/core/lightWatch.js +23 -3
  32. package/core/look/coreParts.js +112 -0
  33. package/core/look/layers.js +136 -0
  34. package/core/look/part.js +173 -0
  35. package/core/look/report.js +79 -0
  36. package/core/look/write.js +86 -0
  37. package/core/loop.js +22 -16
  38. package/core/modules.js +19 -5
  39. package/core/opsAtomic.js +31 -0
  40. package/core/opsCheck.js +25 -14
  41. package/core/opsFail.js +20 -0
  42. package/core/opsHistory.js +6 -6
  43. package/core/opsRun.js +77 -0
  44. package/core/params.js +132 -0
  45. package/core/renamed.js +22 -0
  46. package/core/saveApply.js +2 -2
  47. package/core/sceneMethods.js +9 -34
  48. package/core/services.js +73 -0
  49. package/core/startup.js +3 -1
  50. package/core/styleParts.js +11 -9
  51. package/core/thingExplain.js +68 -0
  52. package/core/thingOps.js +35 -24
  53. package/core/things.js +15 -1
  54. package/core/util.js +11 -0
  55. package/core/validate.js +23 -7
  56. package/docs/AI.md +93 -114
  57. package/docs/API.md +8 -9
  58. package/docs/CODEMAP.md +67 -53
  59. package/docs/COMMANDS.md +21 -7
  60. package/docs/CONVENTIONS.md +22 -11
  61. package/docs/THREE.md +3 -3
  62. package/docs/api/assets.md +3 -0
  63. package/docs/api/characters.md +5 -2
  64. package/docs/api/collision.md +4 -0
  65. package/docs/api/content.md +1 -0
  66. package/docs/api/engine.md +23 -14
  67. package/docs/api/events.md +5 -1
  68. package/docs/api/post.md +5 -4
  69. package/docs/api/saves.md +2 -1
  70. package/docs/api/sky.md +3 -3
  71. package/docs/api/style.md +8 -8
  72. package/docs/api/tools.md +5 -2
  73. package/docs/api/vegetation.md +1 -0
  74. package/docs/api/weather.md +1 -1
  75. package/docs/recipes/01-new-game.md +41 -43
  76. package/docs/recipes/02-npc.md +38 -22
  77. package/docs/recipes/03-items-pickups.md +4 -4
  78. package/docs/recipes/04-quests.md +23 -23
  79. package/docs/recipes/05-props-bake.md +5 -5
  80. package/docs/recipes/06-clock-events.md +13 -0
  81. package/docs/recipes/07-flow-scenes-pause.md +6 -2
  82. package/docs/recipes/08-weather-sky.md +6 -6
  83. package/docs/recipes/09-style-pack.md +35 -100
  84. package/docs/recipes/12-navmesh.md +22 -0
  85. package/docs/recipes/13-animation.md +25 -6
  86. package/docs/recipes/14-custom-module.md +6 -7
  87. package/docs/recipes/15-perf.md +9 -1
  88. package/docs/recipes/16-dev-bridge.md +52 -18
  89. package/docs/recipes/18-world.md +5 -2
  90. package/docs/recipes/19-shooting-picking.md +9 -8
  91. package/docs/recipes/20-content-actions-save.md +10 -10
  92. package/docs/recipes/21-camera.md +51 -2
  93. package/docs/recipes/22-shop-gold.md +16 -16
  94. package/docs/recipes/23-ops.md +46 -10
  95. package/docs/recipes/27-net.md +3 -3
  96. package/docs/recipes/28-terrain.md +2 -2
  97. package/docs/recipes/29-grid.md +47 -27
  98. package/docs/recipes/34-environment-lighting.md +11 -10
  99. package/docs/recipes/35-style-from-reference.md +41 -46
  100. package/docs/recipes/36-sky-ground-plant-looks.md +22 -20
  101. package/docs/recipes/37-terrain-look-hooks.md +34 -13
  102. package/docs/recipes/38-environment-look-hooks.md +49 -42
  103. package/docs/recipes/40-scene.md +29 -0
  104. package/docs/recipes/41-thing-registry.md +29 -0
  105. package/docs/recipes/42-terrain-shape.md +1 -1
  106. package/docs/recipes/43-shader-patches-surface-looks.md +37 -20
  107. package/docs/recipes/44-water-weather-look-hooks.md +11 -9
  108. package/docs/recipes/45-cascaded-shadows.md +2 -2
  109. package/docs/recipes/46-blender-art-route.md +26 -4
  110. package/docs/recipes/47-island-snow-backdrop.md +4 -3
  111. package/docs/recipes/48-make-material.md +70 -0
  112. package/docs/recipes/49-game-module-contract.md +71 -0
  113. package/docs/recipes/50-own-renderer.md +12 -0
  114. package/docs/recipes/51-capability-catalog.md +63 -0
  115. package/docs/recipes/52-look.md +146 -0
  116. package/docs/recipes/53-ground-up-close.md +58 -0
  117. package/examples/action/GAMEMAP.md +7 -7
  118. package/examples/action/content/index.js +2 -1
  119. package/examples/action/content/views.js +6 -0
  120. package/examples/action/main.js +3 -2
  121. package/examples/sheepisland/GAMEMAP.md +3 -4
  122. package/examples/styletest/GAMEMAP.md +3 -3
  123. package/examples/styletest/content/npcs.js +1 -1
  124. package/examples/styletest/main.js +2 -2
  125. package/examples/styletest/panel.js +3 -3
  126. package/examples/world/GAMEMAP.md +3 -3
  127. package/examples/world/content/npcs.js +1 -1
  128. package/examples/world/main.js +1 -1
  129. package/index.d.ts +35 -2
  130. package/index.js +6 -3
  131. package/llms.txt +13 -7
  132. package/modules/ambience/Ambience.js +5 -2
  133. package/modules/camera/FirstPersonCamera.js +3 -5
  134. package/modules/camera/FixedCamera.js +19 -12
  135. package/modules/camera/FollowCamera.js +14 -8
  136. package/modules/camera/RtsCamera.js +3 -5
  137. package/modules/camera/common.js +40 -10
  138. package/modules/camera/index.js +1 -1
  139. package/modules/camera/projection.js +34 -0
  140. package/modules/characters/Character.js +45 -31
  141. package/modules/characters/assetModel.js +35 -7
  142. package/modules/characters/astar.js +14 -7
  143. package/modules/characters/index.js +6 -3
  144. package/modules/characters/movers/simple.js +6 -1
  145. package/modules/characters/npcSim.js +8 -2
  146. package/modules/characters/pathAsync.js +12 -6
  147. package/modules/characters/pathJob.js +2 -1
  148. package/modules/characters/proceduralRig.js +50 -11
  149. package/modules/characters/useModel.js +22 -0
  150. package/modules/characters/walkTo.js +58 -0
  151. package/modules/collision/Collision.js +102 -4
  152. package/modules/content/explain.js +13 -0
  153. package/modules/content/index.js +3 -1
  154. package/modules/content/loader.js +3 -0
  155. package/modules/content/rules.js +1 -0
  156. package/modules/debug/DebugPanel.js +11 -5
  157. package/modules/entities/Entities.js +6 -2
  158. package/modules/flow/index.js +5 -2
  159. package/modules/gameplay/Dialogue.js +5 -2
  160. package/modules/gameplay/Interactions.js +12 -2
  161. package/modules/gameplay/Inventory.js +21 -11
  162. package/modules/gameplay/Quests.js +13 -3
  163. package/modules/gameplay/pickups.js +6 -4
  164. package/modules/grid/Layer.js +1 -1
  165. package/modules/grid/index.js +1 -1
  166. package/modules/grid/tiles.js +9 -5
  167. package/modules/hlod/index.js +5 -2
  168. package/modules/hud/index.js +5 -2
  169. package/modules/level/index.js +5 -3
  170. package/modules/lights/index.js +5 -2
  171. package/modules/music/Music.js +6 -2
  172. package/modules/nav/index.js +5 -3
  173. package/modules/net/Client.js +4 -3
  174. package/modules/net/Host.js +2 -2
  175. package/modules/net/index.js +5 -3
  176. package/modules/particles/Particles.js +1 -1
  177. package/modules/photo/Photo.js +10 -7
  178. package/modules/rigid/RigidBodies.js +5 -2
  179. package/modules/settings/Settings.js +6 -3
  180. package/modules/settings/apply.js +2 -1
  181. package/modules/sky/Sky.js +21 -19
  182. package/modules/sky/cascades.js +6 -6
  183. package/modules/sky/domeLayers.js +1 -1
  184. package/modules/sky/environment.js +39 -13
  185. package/modules/sky/fog.js +9 -6
  186. package/modules/sky/frame.js +4 -3
  187. package/modules/sky/look.js +3 -2
  188. package/modules/sky/lookFog.js +80 -0
  189. package/modules/sky/lookShadow.js +50 -0
  190. package/modules/sky/lookSky.js +108 -0
  191. package/modules/sky/shader.js +2 -2
  192. package/modules/sky/shadow.js +4 -10
  193. package/modules/sky/skyModule.js +4 -3
  194. package/modules/terrain/ChunkManager.js +2 -33
  195. package/modules/terrain/chunkLevels.js +40 -0
  196. package/modules/terrain/index.js +10 -2
  197. package/modules/terrain/lookGround.js +61 -0
  198. package/modules/timeline/Timeline.js +7 -3
  199. package/modules/timeline/Tween.js +3 -7
  200. package/modules/timeline/shots.js +6 -4
  201. package/modules/triggers/index.js +9 -2
  202. package/modules/vegetation/Vegetation.js +17 -4
  203. package/modules/vegetation/index.js +7 -4
  204. package/modules/vegetation/lookWind.js +37 -0
  205. package/modules/vegetation/nearFade.js +39 -0
  206. package/modules/water/Water.js +19 -3
  207. package/modules/water/look.js +80 -0
  208. package/modules/weather/Weather.js +22 -31
  209. package/modules/weather/look.js +75 -0
  210. package/modules/weather/particles.js +1 -1
  211. package/modules/weather/strings.js +15 -0
  212. package/modules/world/explain.js +11 -0
  213. package/modules/world/index.js +11 -4
  214. package/modules/world/thingSource.js +44 -0
  215. package/package.json +2 -1
  216. package/render/PostFX.js +48 -51
  217. package/render/detail.js +39 -15
  218. package/render/effects.js +4 -2
  219. package/render/fuse.js +12 -0
  220. package/render/lights.js +4 -2
  221. package/render/lookSurface.js +161 -0
  222. package/render/materials.js +27 -10
  223. package/render/postLook.js +86 -0
  224. package/render/surface.js +3 -1
  225. package/types/core.d.ts +223 -29
  226. package/types/gameplay.d.ts +22 -6
  227. package/types/generated/core/DebugOverrides.d.ts +52 -0
  228. package/types/generated/core/Events.d.ts +43 -0
  229. package/types/generated/core/Ops.d.ts +62 -21
  230. package/types/generated/core/Saves.d.ts +1 -0
  231. package/types/generated/core/Views.d.ts +33 -0
  232. package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
  233. package/types/generated/modules/grid/Layer.d.ts +1 -0
  234. package/types/generated/modules/sky/Sky.d.ts +10 -17
  235. package/types/generated/modules/weather/Weather.d.ts +5 -15
  236. package/types/generated/render/PostFX.d.ts +20 -23
  237. package/types/generated/render/materials.d.ts +10 -0
  238. package/types/physics.d.ts +8 -0
  239. package/types/style.d.ts +35 -20
  240. package/types/world.d.ts +7 -1
  241. package/ui/Parts.js +6 -2
  242. package/ui/UI.js +1 -1
  243. package/ui/defaults.js +1 -1
  244. package/docs/api/debug.md +0 -10
@@ -1,9 +1,9 @@
1
- # Terrain look open points: shading, color map, triangle cut, normals
1
+ # Crisp ground color borders, terrain normals, height from a grid
2
2
 
3
3
  For an AI that wants the ground to look a way the defaults do not: crisp color borders (a river bank, a path edge), a coarse low-poly mesh with
4
- fine color, a different triangle cut, custom lighting normals. Terrain basics are in `28-terrain.md`, ground color noise in
5
- `36-sky-ground-plant-looks.md`. Every default below is the original look, bit for bit (checked against hashes of the old output in
6
- `tests/specs/terrain-look.mjs`). Each knob has three exits: a parameter, a small pure function, or replacing the whole ground material.
4
+ fine color, a different triangle cut, custom lighting normals, height read from a grid or image. Terrain basics are in `28-terrain.md`, ground
5
+ color noise in `36-sky-ground-plant-looks.md`, the ground up close (detail, variation, symptoms) in `53-ground-up-close.md`. Each knob names its
6
+ default (`tests/specs/terrain-look.mjs` pins them). Each knob has three exits: a parameter, a small pure function, or replacing the whole ground material.
7
7
 
8
8
  ## Why the bank is jagged: color lived on the mesh
9
9
  With `shading: 'smooth'` or `'flat'` a color is computed at a grid point (or triangle center) and blended across the triangle. At the default
@@ -11,9 +11,6 @@ With `shading: 'smooth'` or `'flat'` a color is computed at a grid point (or tri
11
11
  Raising `resolution` fixes it at the price of triangles (and collision, and edit granularity). `shading: 'texture'` cuts the link: color is
12
12
  computed per pixel into a per-chunk image, the mesh stays as coarse as you like.
13
13
 
14
- Material roles (`makeMaterial('role')`) are free labels: a role the style does not list uses `materials.default`, and the engine warns only on a name
15
- that looks like a typo of a known one (`09-style-pack.md`). A style that wants a special ground surface adds its own role and ground material.
16
-
17
14
  ## 1. `shading: 'texture'` (and `colorResolution`)
18
15
  ```js
19
16
  engine.use(terrain({ ...terrainPreset(), shading: 'texture', colorResolution: 128 }));
@@ -64,21 +61,20 @@ terrain({ normalFn: (i, j, h, cell) => [(h(i - 1, j) - h(i + 1, j)) / cell, 4, (
64
61
  ```js
65
62
  terrain({ diagonal: 'adaptive' }) // 'fixed' (default) | 'adaptive' | 'alternate'
66
63
  ```
67
- `fixed` cuts every cell the same way (the original mesh). `adaptive` cuts along the diagonal with the smaller height difference, which removes
64
+ `fixed` cuts every cell the same way. `adaptive` cuts along the diagonal with the smaller height difference, which removes
68
65
  the zigzag ridges a fixed cut leaves on a slope; `alternate` flips every other cell (no directional bias on flat low-poly facets). `engine.surface`,
69
66
  collision and vegetation heights follow the chosen cut, so nothing floats. Because it changes the walkable shape, it belongs to the game's
70
67
  `terrain({...})`, not to a style (rule R34 and `style check` accept `shading`, `colorResolution`, `normals`, `normalFn` in `style.terrain.config`
71
68
  and flag `diagonal`).
72
69
 
73
70
  ## 4. `boundsPad`: the chunk bounding sphere margin
74
- `boundsPad: { up: 3, radius: 8 }` (meters, the original values) is the margin of the culling sphere: the center is raised by `up`, the radius grows
71
+ `boundsPad: { up: 3, radius: 8 }` (meters, the defaults) is the margin of the culling sphere: the center is raised by `up`, the radius grows
75
72
  by `radius`. Raise it if a shader moves vertices far (wind on tall ground cover, a vertex-displacement patch) and chunks pop out at the screen edge.
76
73
 
77
74
  ## 5. Relation to `style.terrain.variation`
78
- `variation` shapes *what* color a point gets (blend size, grain, patches); `shading` decides *where* that color is evaluated. They compose:
79
- in texture mode the grain (`jitter.size`, default 0.33 m) is sampled by pixel, so with `colorResolution: 128` (0.5 m pixels) it is coarser than the
80
- vertex version; set `jitter.size` near the pixel size or use `patches` for the painterly look. In vertex modes the mesh limited every one of these to
81
- cell size; in texture mode `patches: { size: 20, levels: 4 }` shows real hard-edged strokes.
75
+ `variation` shapes *what* color a point gets; `shading` decides *where* it is evaluated. In vertex modes every variation is limited to cell size; in
76
+ texture mode it is sampled per pixel, so `patches: { size: 20, levels: 4 }` gives hard-edged color blocks, and a `jitter.size` below the pixel size
77
+ (0.5 m at `colorResolution: 128`) comes out as one grain per pixel, coarser than asked. Choosing a combination, and ground that looks wrong up close: recipe 53.
82
78
 
83
79
  ## 6. Example: a river bank
84
80
  ```js
@@ -92,6 +88,31 @@ engine.use(terrain({
92
88
  ```
93
89
  Using a preset (`riverAt` of `@threedog/terrain-noise`) the same switch gives crisp banks without more triangles: `terrain({ ...terrainPreset(), shading: 'texture' })`.
94
90
 
91
+ ## 7. Height from a grid or image
92
+ `sampleGrid(data, { width, height, size | cellSize, origin, interp })` turns numbers laid out on a regular grid into a function `(x, z) => value`;
93
+ `await engine.assets.gridFromImage(nameOrUrl, { channel, range, bits })` reads such a grid from an image (PNG at full 8 or 16 bits, jpg/webp at 8;
94
+ `channel` is `'r'`/`'g'`/`'b'`/`'a'`; `range: [min, max]` maps the pixel values to world units, default `[0, 1]`). Samples sit on the grid nodes, so
95
+ `width` samples span `width - 1` cells; outside the grid the edge value is used, or `outside: v`. The grid is just a field: height, moisture, a
96
+ ground-type weight, spawn density, a walkable mask, danger, travel cost.
97
+
98
+ `interp` is the look between nodes; none of them is the right one:
99
+ - `'nearest'`: flat steps, one value per cell. Terraces, blocky or voxel-like ground, tile masks, numbers that are ids.
100
+ - `'linear'` (default): plain bilinear blend; smooth enough for most fields, never leaves the range of its four corners.
101
+ - `'cubic'`: smooth slopes without cell creases (rolling hills, soft gradients). It can overshoot beside a sharp step; `clamp: true` keeps the
102
+ result inside the four corner values.
103
+
104
+ ```js
105
+ const g = await engine.assets.gridFromImage('/maps/height16.png', { range: [-5, 60] }); // meters, 16-bit file
106
+ const heightAt = sampleGrid(g.data, { ...g, size: [512, 512], origin: [-256, -256], interp: 'cubic', clamp: true });
107
+ heightAt(10, 20); // gameplay side: where to put a camp, a mine, a lighthouse
108
+ const wet = sampleGrid(moisture, { width: 32, height: 32, cellSize: 8 }); // a hand-made field: wetter ground grows reeds, rice, moss
109
+ const walk = sampleGrid(mask, { width: 64, height: 64, cellSize: 1, interp: 'nearest', outside: 0 }); // 0 / 1 per tile; off the map: not walkable
110
+ ```
111
+ A terrain `height` function is recompiled in a worker and cannot capture `heightAt`, so the terrain reads the same image through its own
112
+ `heightmap` (bilinear, centered on `center`): `terrain({ heightmap: { ...g, size: [512, 512], min: -5, max: 60 } })` with `g` from `gridFromImage`
113
+ using the default `range` (it expects 0-1 values; `min`/`max` scale them). Use `sampleGrid` for everything outside the terrain module; when you need
114
+ a look the terrain's bilinear read does not give (terraces: `nearest`), bake it into the data first or write the step in a `height` function.
115
+
95
116
  ## Whole replacement
96
117
  Anything beyond this: `terrain({ material })` (or `style.terrain.material`) swaps the ground material and `engine.terrain.T.buildChunk(cx, cz)` returns the
97
118
  raw arrays (`pos`, `nor`, `col`, `uv`, and `tex: { data, size }` in texture mode) if you build chunk meshes yourself.
@@ -1,69 +1,76 @@
1
- # Environment look open points: lights, fog, exposure, sky layers
1
+ # Owning lights, fog and exposure yourself
2
2
 
3
- For an AI that wants lighting, fog or the sky to look a way the defaults do not. Sky basics are in `08-weather-sky.md`, clouds and ground color in
4
- `36-sky-ground-plant-looks.md`, environment lighting in `34-environment-lighting.md`. Every default below draws exactly what it drew before
5
- (checked pixel by pixel in `tests/specs/appearance-env.mjs`). Each knob has three exits: a parameter, a GLSL function you replace, or turning the
6
- engine's part off and bringing your own three.js objects.
3
+ The normal way to change lights, fog, exposure and the sky is `engine.look.<part>.set` / `patch` ([recipe 52](52-look.md)): the sky keeps
4
+ driving them over the day, and your values sit on top. This page is the next step, for when that is not enough: your own fog math, exposure over
5
+ the day, extra sky layers, and taking a light or the fog away from the sky entirely. Sky basics are in `08-weather-sky.md`, clouds and ground color in
6
+ `36-sky-ground-plant-looks.md`, environment lighting in `34-environment-lighting.md`. Each section starts with the `look` call and ends with the exit.
7
7
 
8
- ## Lights: let the sky drive them, drive them yourself, or switch them off
8
+ ## Lights: override, take over, or switch off
9
9
  The engine has one directional light (`engine.lights.sun`, also `engine.sky.sun`; moonlight at night, the shadows live on it) and one hemisphere
10
10
  ambient (`engine.lights.hemi` = `engine.sky.hemi`). The sky module rewrites their color and intensity every frame from `style.sky.keyframes`,
11
- so editing them directly is overwritten (a dev warning says so). Choose per light:
11
+ so editing the three.js objects directly is overwritten (a dev warning says so). **Without the sky module** both lights are a bright placeholder
12
+ (hemi 1.2, white sun 2 at (40, 80, 30), no shadows).
12
13
 
13
14
  ```js
14
- engine.use(sky({ sun: 'manual' })); // the sky still aims the sun along the time of day and moves the shadow box
15
+ engine.look.lights.set({ sun: { color: '#ffd0a0', intensity: 1.4 }, hemi: { intensity: 0.5 } }, { owner: 'dusk' }); // 1. override, any hour
16
+ engine.sky.modify('cave', { sun: 0.3, ambient: 0.4 }); // or a multiplier on top of the day cycle (recipe 52)
17
+
18
+ engine.use(sky({ sun: 'manual' })); // 2. take over: the sky still aims the sun along the time of day and moves the shadow box
15
19
  engine.sky.sun.color.set(0xffd0a0); engine.sky.sun.intensity = 1.4; // yours now, never overwritten
16
20
 
17
- engine.use(sky({ sun: false, hemisphere: false })); // a dungeon: both hidden, never touched; the dome still shows sun and moon
21
+ engine.use(sky({ sun: false, hemisphere: false })); // 3. switch off (a dungeon): both hidden, never touched; the dome still shows sun and moon
18
22
  const torch = new THREE.PointLight(0xffa040, 6, 12); engine.add(torch); // add your own lights before engine.start()
19
23
  ```
20
24
 
21
- - Default `true`: the sky drives everything (as before). `'manual'`: color and intensity are the game's; the sun keeps its direction and shadow box.
22
- `false`: `visible = false`, no shadows, never touched (lightning no longer flashes the ambient either).
23
- - Shadows: only the engine sun's shadow is managed (size, bias, snapping via `engine.sky.setShadow`). Your own `castShadow` lights work as in
24
- three.js, each costing its own shadow pass; `engine.setShadows(false)` turns theirs off too and restores them after.
25
- - Add or remove lights before `engine.start()`: a light count that changes mid-play recompiles every material (one long frame). Many torches:
26
- `lightPool()`. Brightness tweaks without giving up the keyframes: `engine.sky.modify('cave', { sun: 0.3, ambient: 0.4 })`.
27
-
28
- ## Fog: kind, color, density, or your own math
29
- `style.sky.fog` (a look; `sky({ fog })` overrides it):
25
+ - `sky({ sun, hemisphere })`: `true` (default) the sky drives everything; `'manual'` color and intensity are the game's, the sun keeps its
26
+ direction and shadow box; `false` `visible = false`, no shadows, never touched (lightning no longer flashes the ambient either).
27
+ - `createEngine({ lights: false })` goes one step further: the default sun and hemisphere are never put in the scene, `engine.lights.sun` / `hemi`
28
+ stay as detached objects so nothing reads `undefined`. Use it for a scene lit entirely by your own lights.
29
+ - Shadows: only the engine sun's shadow is managed (`engine.look.shadow.set`). Your own `castShadow` lights work as in three.js, each costing its
30
+ own shadow pass; `engine.setShadows(false)` turns theirs off too and restores them after.
31
+ - Add or remove lights before `engine.start()`: a light count that changes mid-play recompiles every material (one long frame). Many lamps or
32
+ torches: `lightPool({ point: 6 })` keeps a fixed number of real lights and moves them to the nearest sources (recipe 09, "Lights and stalls").
30
33
 
34
+ ## Fog: kind, color, density, your own math, or your own fog
31
35
  ```js
32
- fog: { kind: 'exp2' } // three's FogExp2, density derived so it reaches as far as the linear fog did
33
- fog: { kind: 'height', height: 2, falloff: 0.08, density: 0.03 } // valley mist: thick below y = 2, thinning 8% per meter above
34
- fog: { kind: 'exp', color: 0xb8c4d0 } // own color: the dome's lower band fades to it, so the horizon line never shows
35
- fog: { color: sky => sky.isDay ? 0xc8d0d8 : 0x10141c } // a function, evaluated each frame
36
- fog: { kind: 'exp', glsl: `vec4 threedogFog(vec3 c, float depth, vec3 p){
36
+ engine.look.fog.set({ far: 220, color: '#9bb' }); // live: color, density, near, far, enabled, linear <-> exp2
37
+ engine.look.fog.set({ kind: 'height', height: 2, falloff: 0.08, density: 0.03 }); // valley mist; before the first frame (below)
38
+ engine.look.fog.patch('fog', `vec4 threedogFog(vec3 c, float depth, vec3 p){
37
39
  float f = 1.0 - exp(-fogDensity * depth);
38
- return vec4(mix(c, vec3(1.0, 0.85, 0.7), f * 0.3), f); }` } // warm far haze
40
+ return vec4(mix(c, vec3(1.0, 0.85, 0.7), f * 0.3), f); }`); // warm far haze
41
+ engine.look.fog.replace('manual'); // the exit: the sky stops writing scene.fog (or pass a THREE.Fog)
39
42
  ```
43
+ The same keys are the style layer `style.sky.fog` (or `sky({ fog })`), e.g. `fog: { kind: 'exp', color: 0xb8c4d0 }` or
44
+ `fog: { color: sky => sky.isDay ? 0xc8d0d8 : 0x10141c }` (a function, evaluated each frame).
40
45
 
41
- - `kind`: `'linear'` (default, near = 0.3 x far) | `'exp'` | `'exp2'` | `'height'`. `color`: `'horizon'` (default) | color | `(sky) => color`.
42
- `density` per meter (default derived from `engine.fogFar`); weather fog divides it, `engine.setFogFar` still moves the derived one.
43
- - `glsl` replaces the fog math in every material, built-in or yours: `vec4 threedogFog(vec3 color, float depth, vec3 worldPos)` returns
46
+ - `kind`: `'linear'` (default, near = 0.3 x far) | `'exp'` | `'exp2'` | `'height'`. `color`: `'horizon'` (default; the dome's lower band fades to
47
+ the fog color, so the horizon line never shows) | color | `(sky) => color`. `density` per meter (default derived from the fog distance);
48
+ weather fog divides it, `engine.setFogFar` still moves the derived one.
49
+ - The `fog` hook replaces the fog math in every material, built-in or yours: `vec4 threedogFog(vec3 color, float depth, vec3 worldPos)` returns
44
50
  (fog rgb, amount 0..1). In scope: `fogColor`, `cameraPosition`, `fogNear` / `fogFar` (linear) or `fogDensity` (other kinds),
45
51
  `THREEDOG_FOG_HEIGHT`, `THREEDOG_FOG_FALLOFF`.
46
- - How it works and its limits: `'exp'`, `'height'` and `glsl` replace three's `fog_*` shader chunks once at install (three caches programs by
47
- material settings, not by source, so the fog model cannot change mid-play; color and density stay live). No custom uniforms (three copies fog
48
- uniforms into each material when it compiles); write constants. Materials with `fog: false` (the dome) are not fogged; the dome follows the
49
- fog color as above. A ShaderMaterial of your own gets the same fog when it sets `fog: true` and includes the fog chunks.
50
- - Whole replacement: `sky({ fog: 'manual' })` creates `scene.fog` once and never writes it (set its color / near / far, or assign your own
51
- object); `sky({ fog: false })` sets `scene.fog = null` (leave fog out of your materials with `fog: false` and fog in a post pass). Default
52
- `true` = the sky drives it. This is a sky() option, not a style key.
53
- - Two engines on one page share three's fog chunks: the same custom `kind` / `height` / `falloff` / `glsl` is fine (reference counted, the
54
- originals return when the last one is disposed); a different custom setting throws. Plain `linear` / `exp2` do not touch the chunks.
52
+ - Limits: `'exp'`, `'height'` and the hook replace three's `fog_*` shader chunks once (three caches programs by material settings, not by
53
+ source), so they only work before the first frame (style, `sky({ fog })`, or right after `createEngine`); later they throw. Color and density
54
+ stay live. No custom uniforms (three copies fog uniforms into each material when it compiles); write constants. Materials with `fog: false`
55
+ (the dome) are not fogged. A ShaderMaterial of your own gets the same fog when it sets `fog: true` and includes the fog chunks.
56
+ - Your own fog: `look.fog.replace('manual')` or `sky({ fog: 'manual' })` creates `scene.fog` once and never writes it (set its color / near /
57
+ far, or assign your own object); `sky({ fog: false })` sets `scene.fog = null` (leave fog out of your materials with `fog: false` and fog in a
58
+ post pass).
59
+ - Two engines on one page share three's fog chunks: the same custom `kind` / `height` / `falloff` / hook is fine (reference counted); a different
60
+ custom setting throws. Plain `linear` / `exp2` do not touch the chunks.
55
61
 
56
62
  ## Exposure and tone mapping over time
57
63
  ```js
58
64
  exposure: [[0, 1.6], [0.3, 1], [0.75, 1.1]] // style: per time of day (0-1), wraps across midnight
59
65
  exposure: sky => sky.isDay ? 1 : 1.5 // or a function, evaluated by the sky module every frame
60
- engine.setExposure(1.3); // at run time: number, keyframes or function (replaces the style's)
61
- engine.setToneMapping('agx'); // 'aces' | 'agx' | 'neutral' | 'none'; materials recompile on their next draw
66
+ engine.look.tone.set({ exposure: 1.3 }); // at run time: number, keyframes or function (replaces the style's)
67
+ engine.look.tone.set({ mapping: 'agx' }); // 'aces' | 'agx' | 'neutral' | 'none'; materials recompile on their next draw
62
68
  ```
63
- A plain number behaves as before (set once, no per-frame work). Keyframes and functions need the sky module (it knows the time of day).
69
+ A plain number is set once (no per-frame work). Keyframes and functions need the sky module (it knows the time of day).
64
70
 
65
- ## Extra sky layers: rainbow, aurora, painted bands
66
- `style.sky.layers` (or `sky({ layers })`), drawn on the dome after clouds and stars; none by default (the dome shader text is then unchanged):
71
+ ## Extra sky layers: rainbow, aurora, color bands
72
+ `style.sky.layers` (or `sky({ layers })`; at run time `engine.look.sky.patch('layer:aurora', { glsl, blend })`, recipe 52), drawn on the dome
73
+ after clouds and stars; none by default:
67
74
 
68
75
  ```js
69
76
  layers: [{ blend: 'add', uniforms: { uAurora: [0.2, 1, 0.6] }, glsl: `vec4 threedogSkyLayer(vec3 d, float time, vec3 sunDir, float night){
@@ -78,4 +85,4 @@ hide `engine.sky.dome` and add your own background.
78
85
 
79
86
  ## Water and weather particles
80
87
  Water depth color, crest foam, wave / surface GLSL, reflections; rain and snow shape, size, density and shaders, the lightning look, and
81
- particles for the game's own weather (`engine.weather.define`): `44-water-weather-look-hooks.md`.
88
+ particles for the game's own weather (`engine.look.weather.replace`): `44-water-weather-look-hooks.md`.
@@ -77,3 +77,32 @@ write a template, add a placement with an id. Delete the `engine.add` line. Noth
77
77
  ## 6. Verify
78
78
  `threedog check` flags the startup calls above; `engine.world.origin(id)` and `engine.pick(x, y).thing` say where a record came from (`30-templates.md`
79
79
  §5); `engine.world.query({ kind: 'windmill' })` lists the records a save would hold.
80
+
81
+ ## 7. Why is this mesh this colour? (material provenance)
82
+
83
+ `engine.inspect.scene()` / `npx threedog scene` list, for each mesh, one `material:` line and the renderer line (tone mapping, exposure; the same text as `describe().render`). Diagnostics only: nothing about the look changes.
84
+
85
+ ```
86
+ renderer: ACES (style) exposure 1.1 (style) shadows soft (engine)
87
+ ✓ roof [Mesh] (4, 3, 0) r=2 · MeshLambertMaterial/roof
88
+ material: roof from pack-spec [color] · MeshLambertMaterial #3b5168 · map x color #3b5168 (vertexColors off) · map (base colour)
89
+ note: map already carries colour and color #3b5168 is not white: the result is map x color (fine when it is a tint)
90
+ ```
91
+
92
+ - `from` is `pack-spec | pack-instance | pack-function | call-params | default`, `keys` the params the call passed; both come from `userData.materialSource`, which `makeMaterial` records (a material made by hand shows `unknown`).
93
+ - `--json` carries `material.info[]` per mesh: role, from, keys, type, color, maps (base colour vs detail), vertexColors, side, transparent, opacity, colorPath, notes.
94
+ - The tint note is not an error: a map times a non-white colour is how tinting works.
95
+
96
+ ## 8. When to write plain three.js directly, and which integrations you lose
97
+
98
+ Plain three.js is always allowed (`engine.scene`, `engine.renderer`, `engine.camera` are the real objects; `engine.add(obj, { id })` keeps it saveable). Write it directly for a one-off effect, a special mesh, a shader nothing else shares. What you give up depends on how the material or pass was made:
99
+
100
+ | You wrote | Not applied to it |
101
+ |---|---|
102
+ | `new THREE.MeshStandardMaterial(...)` (not `makeMaterial` / a look material) | wind sway, snow and season cover, cloud shadows, the engine fog hook, cascaded shadows, `look.surface` lighting and detail, `look.materials` roles, `debug.view` modes |
103
+ | your own `EffectComposer` / render call | `engine.post` effects, `look.post`, adaptive resolution, photo mode, `describe().render.post` |
104
+ | `renderer.toneMappingExposure = x`, `scene.fog = ...` | the owner record and the debug layer (`describe().look` tags it `three`); the sky keeps writing fog unless `look.fog.replace('manual')` |
105
+
106
+ Keep the integrations by going through the engine: `engine.makeMaterial('role', {...})` for the material, `look.materials.patch(name, { glsl }, { roles })` to add GLSL to a role, `look.post.patch(name, { glsl, slot })` or `look.post.replace([...])` for a screen effect.
107
+
108
+ `patch` vs `replace`: `patch(hook, glsl)` swaps one registered hook (`threedogWind`, `threedogFog`, `threedogLighting`, the water `wave`) and the rest of the engine's shader stays, so the integrations above still work. `replace(impl)` hands over the whole part (the ground material, the water surface, the whole post chain): everything that part did is now yours, including the fog, shadow and season hooks inside it. Prefer `patch`; use `replace` when the hook is too small. `engine.catalog('look.<part>')` lists the hooks and what each `replace` loses.
@@ -62,3 +62,32 @@ the override applies the moment `engine.add(obj, { id })` runs. One that never c
62
62
  - Rule R33 (`npm run check`) flags the static half: startup calls that create things saved whole, and code writing `world.view()` models.
63
63
  - Cost: a release build pays two table writes per `engine.add` (about 2 µs per add in `tests/specs/things.mjs`); dev builds also take a short stack
64
64
  for `at`, at most 2000 per session (`describe().scene.atCapped` after that).
65
+
66
+ ## 6. One id, everything: explain() and the three kinds of change
67
+ ```js
68
+ engine.thing('chest-home').explain(); // CLI: npx threedog thing chest-home (MCP: thing); the same JSON
69
+ // { id, kind, owner, definition: { at: 'content/props.js:14', template, templateAt, level?, node?, spawned? }, model, materials: [{ role, name, from, keys }],
70
+ // state, rules: { blocksMovement, pickable, interact, height }, ops: [{ op, desc, args }], saved: { tier, keeps, loses }, change: {…}, overrides? }
71
+ ```
72
+ `ops` lists the ops whose definition names this id, kind or template in the optional `targets` field (`engine.ops.define('chest.toggle', { targets: 'chest', … })`;
73
+ `'*'` = any thing, which `thing.set` / `thing.remove` use). `definition.at` is null in release builds and for code run without a file (page `eval`).
74
+ `thing.explain()` (type `ThingExplanation`) is not `engine.explain({ op | quest | … })`: that one takes a question and answers `{ ok, text }` about why an op or quest cannot run now (recipe 23); this one takes no question and returns the facts about one id. `rules.blocksMovement` is the template's / prop's `collide` shape; the engine does not model blocking sight. Pick the kind of change first:
75
+
76
+ | Kind | How | Lasts |
77
+ |---|---|---|
78
+ | Game state (a chest opens, a door moves) | an op: `ops.run('chest.toggle', { id })`, `thing.set`, `thing.remove` (section 3) | by the thing's save tier |
79
+ | Permanent edit (another model, place, material role) | content entry: `npx threedog content set <id> <field> <json>` (below); template or `engine.add` line: edit the file:line `explain().change.permanent` prints; then reload | forever |
80
+ | Diagnostic override ("show me without it") | `engine.debug.override(owner, id, { visible: false, material: 'flat' \| 'wire', apply })` | until `handle.remove()` / `engine.debug.clear(owner)`; never saved |
81
+
82
+ ```js
83
+ const h = engine.debug.override('ai-session', 'windmill', { material: 'flat' }); // unlit base colour: is the colour wrong, or the light?
84
+ engine.debug.override('ai-session', 'fence', { visible: false });
85
+ engine.describe().scene.overrides; // [{ owner, target, material: 'flat' }, …]: the screen differs from the real state while this is non-empty
86
+ h.remove(); engine.debug.clear('ai-session'); // clear removes every override of that owner (and its debug.view) and nothing else
87
+ ```
88
+ `apply(obj)` may return its undo function: any other look (a view mode) uses the same owner mechanism. Overrides do not touch game state, ops or saves.
89
+
90
+ `npx threedog content set cabin x=12 z=3 place=home --in props` sets several fields in one call (one write, one check, all or nothing; a bare word is a string). `npx threedog content set cabin x 12 --in props` writes a permanent change into the content entry (`-w game` or `--dir folder` picks the game; `--dry` only shows it). It edits just that
91
+ value in place (comments and spacing stay), adds the field when missing, runs the content check (reverting if it fails) and tells you to reload. Fields are the content file's names
92
+ (`x`, `z`, `y`, `rot`, `scale`, `template`, `place`, `model`), not the record's `position`; the value is JSON (`'"home"'` for a string). It refuses, and says why, for an entry built
93
+ by code (loop, spread, computed value) or an id matching several entries (`--in props`). A placed entry wins over a template or npc of the same name.
@@ -1,6 +1,6 @@
1
1
  # Terrain outline: islands, floating rocks, a world that ends
2
2
 
3
- `terrain({ shape })` decides where there is ground at all. Without it the ground goes on forever, exactly as before. With it, ground exists only
3
+ `terrain({ shape })` decides where there is ground at all. Without it (the default) the ground goes on forever. With it, ground exists only
4
4
  where `mask > 0`; the rim is cut through the cells in straight lines, walls hang down from it, and an optional underside closes it.
5
5
 
6
6
  ## 1. A floating island with a ragged rim (copy this)
@@ -6,13 +6,14 @@ material** (a function or instance). Use the first that does the job.
6
6
 
7
7
  ## Material roles are open
8
8
  `style.materials` maps a role name to a material. The engine asks for `default terrain vegetation character water pickup prop`; **any other
9
- name is fine** (`wool`, `bark`, `lantern`): code asks for it with `engine.makeMaterial('wool', { color })`, an unlisted role uses `materials.default`.
9
+ name is fine** (`cloth`, `metal`, `glass`): code asks for it with `engine.makeMaterial('cloth', { color })`, an unlisted role uses `materials.default`.
10
10
  Only a name very close to an existing one (`props`, `charcter`) warns, as a probable typo.
11
11
 
12
12
  ```js
13
13
  materials: {
14
14
  default: { type: 'lambert' },
15
- wool: { type: 'standard', roughness: 1, detail: { noise: 'grain', projection: 'triplanar', scale: 3, normal: 0.01 } },
15
+ cloth: { type: 'standard', roughness: 1, detail: { noise: 'grain', projection: 'triplanar', scale: 3, normal: 0.01 } },
16
+ glass: { type: 'physical', transmission: 1, roughness: 0.05, thickness: 0.2 },
16
17
  rock: { type: 'standard', map: 'rock.png', normalMap: 'rock_n.png', roughnessMap: 'rock_r.png', repeat: 4 },
17
18
  prop: (params, purpose, engine) => new THREE.MeshMatcapMaterial({ matcap: texture, color: params.color }), // any Material
18
19
  }
@@ -22,18 +23,17 @@ three.js Material. A **spec** is plain data (`type: lambert | phong | standard |
22
23
  `materials.default` when that is a spec too; keys the material has are set, spec keys below are handled by the engine.
23
24
 
24
25
  ## Exit 1: parameters in the spec
25
- **Texture names.** A texture slot may be an asset name (`map`, `emissiveMap` are sRGB; `normalMap roughnessMap metalnessMap aoMap bumpMap alphaMap
26
- displacementMap specularMap...` are linear). The engine loads it with `engine.assets.texture`, sets anisotropy, wrap and `repeat` (a number or `[x, y]`;
27
- `wrap: 'repeat' | 'clamp' | 'mirror'`), and a neutral stand-in (flat normal, white) sits in the slot until the image arrives. A texture object works too.
28
- A key the type lacks (`roughnessMap` on `lambert`) warns once with the type to use; a misspelled slot (`normalmap`) throws with the near name.
29
- `style check` verifies the names against the asset pack (`materials.*.map` and the other slots, `materials.*.detail.texture`).
26
+ The accepted spec keys, texture slots, `repeat` / `wrap` and who wins between pack and call: recipe 48. How texture names load: the engine
27
+ fetches the asset with `engine.assets.texture` (`map`, `emissiveMap` sRGB, the other slots linear), sets anisotropy, wrap and repeat, and a neutral
28
+ stand-in (flat normal, white) sits in the slot until the image arrives. `style check` verifies the names against the asset pack. This page
29
+ covers the keys that add shader code: `detail`, `lighting`, toon `ramp`, seasons.
30
30
 
31
- **`detail`**: grain, paper or strokes over the surface, in world space (needs no UVs). Off unless written; every number is a uniform, so
31
+ **`detail`**: a noise pattern, a texture or your own GLSL laid over the surface in world space (needs no UVs). Off unless written; every number is a uniform, so
32
32
  100 materials with different `scale` / `strength` / `direction` compile **one** program (tested: 8 variants, +0 programs).
33
33
 
34
34
  | key | meaning |
35
35
  |---|---|
36
- | `noise` | `'grain'` (default) `'paper'` `'stroke'`; or `texture: 'name'` (asset name or a Texture), or `glsl` (below) |
36
+ | `noise` | `'grain'` (default) `'paper'` `'stroke'` `'dabs'` (soft oval dabs, no direction); or `texture: 'name'` (asset name or a Texture), or `glsl` (below) |
37
37
  | `projection` | `'world'` top-down (default, fine for ground) or `'triplanar'` (walls, rocks, characters) |
38
38
  | `scale` `strength` | repeats per meter (0.25), color effect 0-1 (0.35) |
39
39
  | `mode` `tint` | `'multiply'` (default) `'add'` `'mix'`; tint colors the sample |
@@ -41,9 +41,10 @@ A key the type lacks (`roughnessMap` on `lambert`) warns once with the type to u
41
41
  | `octaves` | 1-4 noise layers (2) |
42
42
  | `normal` | relief height in meters (bumps the normal; 0 = off) |
43
43
  | `roughness` | amount the sample moves roughness (`standard` / `physical`) |
44
+ | `fade` | default `true`: the effect fades out where its pattern is smaller than a pixel (far, grazing), so it does not shimmer; `false` keeps it |
44
45
 
45
46
  Which channels (color, normal, roughness) are on is fixed when the material is made (it is part of the program); the numbers can change any time.
46
- `style.terrain.detail` (`{ texture, scale, strength }`) is the same patch for the ground.
47
+ The ground takes the same object as `style.terrain.detail` / `look.ground.set({ detail })`; which detail suits which ground: recipe 53.
47
48
 
48
49
  **`lighting`** shapes the light after it is summed. three has no "shadow color": a shadow only removes the sun's light. The patch reads the first
49
50
  directional light (the sun; three sorts shadow casters first) and its shadow value for the pixel:
@@ -63,7 +64,7 @@ orange-on-green muddy; `mix` moves the surface `strength` of the way to the colo
63
64
 
64
65
  ## Exit 2: your own GLSL
65
66
  `detail.glsl` replaces the noise: `vec4 threedogDetailSample(vec2 p)` returns `vec4(color, height 0-1)`; `p` is already scaled, turned, stretched;
66
- `uniforms: { uCells: 6 }` (numbers, colors, arrays, textures) are in scope. `lighting.glsl` replaces the three light effects:
67
+ `uniforms: { uCells: 6 }` (numbers, colors, arrays, textures) are in scope; `threedogDetailFootprint` is one pixel in pattern units (`fade` uses it; read it to fade your own sample). `lighting.glsl` replaces the three light effects:
67
68
  `void threedogLighting(inout ReflectedLight light, vec3 normal, vec3 viewDir, vec3 sunDir, float sunShadow, vec3 albedo)` (view space; `sunShadow` 1 lit,
68
69
  0 shadowed; change `light.directDiffuse` / `indirectDiffuse`, the lights are already summed).
69
70
 
@@ -78,6 +79,21 @@ For anything else write a **named patch** and add it with `applyEffects(material
78
79
  glsl: { fragment: { pars: 'uniform float uFuzz;', // pars = declarations at the top
79
80
  color_fragment: 'diffuseColor.rgb *= 1.0 - uFuzz * 0.5;' } } } // chunk name -> code placed after `#include <chunk>`
80
81
  ```
82
+ Patches on one material must agree. Each patch declares what it relies on, and a bad combination throws when it is added (or logs once at compile):
83
+
84
+ | Field | Meaning | Checked |
85
+ |---|---|---|
86
+ | `needs.data` | Program inputs the code reads: `'instancing'`, `'instancingColor'`, `'vertexColors'`, `'skinning'`, `'batching'` | when the program compiles (console.error once per material) |
87
+ | `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 |
88
+ | `conflicts` | Patch names it cannot share a material with | when added, both ways |
89
+ | `uniforms` | A uniform name belongs to one patch; share `engine.uniforms` (`uTime`, `uWind`, `uCloud`...) instead of making your own `uTime` | when added |
90
+ | `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 | - |
91
+ | `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 |
92
+ ```js
93
+ applyEffects(mat, { wind: 0.03, season: 'foliage', patches: [{ name: 'ripple', needs: { patches: ['world'] }, conflicts: ['wind'],
94
+ glsl: { fragment: { color_fragment: 'diffuseColor.rgb *= 0.9 + 0.1 * sin(vThreedogWorld.x);' } } }] }); // throws: 'wind' and 'ripple' cannot be combined
95
+ ```
96
+
81
97
  A chunk value may be `{ before, after }`. A missing chunk throws when the patch is added (`strict`), not as a silent no-op. Chunk names in three **0.187**
82
98
  (read from `three/src/renderers/shaders`), in main-body order:
83
99
 
@@ -101,18 +117,19 @@ A `materials` entry that is a Material instance (cloned per use, its patches kep
101
117
  lit materials returned by it. Nothing else is applied: textures, `detail` and `lighting` keys are only read on specs, so call `applyEffects(material,
102
118
  { detail, patches })` yourself.
103
119
 
104
- ## Three complete looks
120
+ ## Three complete looks (different directions, same mechanism)
105
121
  ```js
106
122
  const looks = {
107
- // wool: rough, fuzzy, soft light, a warm rim; one fine grain seen from every side
108
- wool: { type: 'standard', roughness: 1, detail: { noise: 'grain', projection: 'triplanar', scale: 4, octaves: 3, strength: 0.25, normal: 0.01 },
109
- lighting: { wrap: 0.5, rim: { color: 0xffd9a8, strength: 0.35, power: 2.5 } } },
110
- // leaves: toon bands, brush strokes along the wind, cool shade, a bit of transmitted light on the side away from the sun
123
+ // metal, realistic PBR: a texture set does the work; a fine world-space grain moves only the roughness (smudges), not the color
124
+ metal: { type: 'standard', metalness: 1, roughness: 0.35, map: 'steel.png', normalMap: 'steel_n.png', roughnessMap: 'steel_r.png', repeat: 2,
125
+ detail: { noise: 'grain', projection: 'triplanar', scale: 6, strength: 0, roughness: 0.25 } },
126
+ // poster, flat and unlit: no light or shadow, the color is exactly the given one; a faint grain keeps large areas from looking empty
127
+ poster: { type: 'basic', detail: { noise: 'paper', scale: 2, strength: 0.12 } },
128
+ // leaf, stylized: toon bands, directional strokes along the wind, cool shade, a rim on the side away from the sun
111
129
  leaf: { type: 'toon', ramp: [0.45, 0.8, 1], soften: 0.25, detail: { noise: 'stroke', direction: 35, scale: 1.2, strength: 0.3, mode: 'add' },
112
130
  lighting: { shadowTint: { color: 0x5a6fb0, strength: 0.7 }, rim: { color: 0xb8e08a, strength: 0.3, shadowSide: 1 } } },
113
- // rock: a real texture set, plus a world-space grain that also roughens it
114
- rock: { type: 'standard', map: 'rock.png', normalMap: 'rock_n.png', roughnessMap: 'rock_r.png', repeat: 3,
115
- detail: { noise: 'paper', projection: 'triplanar', scale: 0.8, strength: 0.2, normal: 0.02, roughness: 0.3 } },
116
131
  };
117
132
  ```
118
- Fetch them with `engine.makeMaterial('wool')`. Check a pack with `threedog style check`; the pixel and program-count guarantees are in `tests/specs/surface.mjs`.
133
+ Fetch them with `engine.makeMaterial('metal')`. Check a pack with `threedog style check`; the pixel and program-count guarantees are in `tests/specs/surface.mjs`.
134
+
135
+ To change these from code at run time (`materials`, `surface`, `ground`, `wind` look parts), see recipe 52.
@@ -1,9 +1,9 @@
1
- # Water and weather look open points: depth color, foam, reflections, rain and snow, lightning, own particles
1
+ # Water and rain/snow looks: depth color, foam, reflections, particles, lightning
2
2
 
3
3
  For an AI that wants water or weather particles to look a way the defaults do not. Water basics are the `water()` module and `style.water` (color, opacity, waves,
4
- fresnel, normal map); lights, fog and the sky are in `38-environment-look-hooks.md`. Every default below draws exactly what it drew before
5
- (checked pixel by pixel against the old shaders in `tests/specs/appearance-water.mjs`), and a style that writes none of the new keys gets the same
6
- shader text, so it pays nothing. Three exits: a parameter, a GLSL function you replace, or your own material.
4
+ fresnel, normal map); lights, fog and the sky are in `38-environment-look-hooks.md`. A style that writes none of the keys below keeps the built-in
5
+ shaders and pays nothing for them (`tests/specs/appearance-water.mjs`). Three exits: a parameter, a GLSL function you replace, or your own material.
6
+ At run time the same keys go through `engine.look.water` / `engine.look.weather` (recipe 52).
7
7
 
8
8
  ## Water: depth color and crest foam (parameters)
9
9
  ```js
@@ -78,7 +78,7 @@ water: { material: () => {
78
78
  - Tested: `tests/specs/appearance-water.mjs` renders this exact example and finds the reflected box in the mirror texture.
79
79
 
80
80
  ## Weather particles: rain and snow parameters
81
- `style.weather.rain` / `snow` (left-out keys keep the built-in look; the defaults are pixel for pixel the old ones):
81
+ `style.weather.rain` / `snow` (left-out keys keep the built-in look):
82
82
 
83
83
  ```js
84
84
  weather: {
@@ -118,16 +118,18 @@ engine.events.on('weather:lightning', () => spawnBolt()); // when it st
118
118
  ```
119
119
 
120
120
  ## Particles of the game's own weather
121
- A field of the game's own weather table (`ash`, `petals`, `sparks`) gets particles with `engine.weather.define(field, spec)`; the amount is
121
+ A field of the game's own weather table (`ash`, `petals`, `sparks`) gets particles with `engine.look.weather.replace({ [field]: spec })`; the amount is
122
122
  `engine.weather.current[field]`, so they fade in and out with the weather. The spec takes the rain / snow keys above (default: drifting
123
123
  round sprites), or `create` for a system of your own:
124
124
 
125
125
  ```js
126
126
  engine.use(sky(), weather({ types: { clear: {}, ashfall: { ash: 1, grey: 0.5, sun: 0.6 } } }));
127
- engine.weather.define('ash', { shape: 'soft', color: 0x555555, size: 14, speed: 0.8, sway: 3 });
128
- engine.weather.define('rain', { create: (engine, { area, count }) => { // the same call replaces rain or snow
127
+ engine.look.weather.replace({ ash: { shape: 'soft', color: 0x555555, size: 14, speed: 0.8, sway: 3 } });
128
+ engine.look.weather.replace({ rain: { create: (engine, { area, count }) => { // the same call replaces rain or snow
129
129
  const drops = new THREE.InstancedMesh(new THREE.SphereGeometry(0.03), new THREE.MeshBasicMaterial({ color: 0x99bbff }), count);
130
130
  return { object: drops, update(amount, { camera, time, wind }) { /* move the instances; shown while amount > 0.02 */ } };
131
- } });
131
+ } } });
132
132
  ```
133
133
  A field no type has throws with the table's fields. Rain and snow are built only when a type rains or snows, so a desert pays nothing.
134
+
135
+ > Water and weather are also look parts (`engine.look.water`, `engine.look.weather`): recipes/52-look.md, "Water, weather, post".
@@ -1,12 +1,12 @@
1
1
  # Cascaded shadows
2
2
 
3
- Off by default: the sun casts one shadow map around the focus (`extent`, default 70 m), exactly as before. Cascades split the sun's shadow
3
+ Off by default: the sun casts one shadow map around the focus (`extent`, default 70 m). Cascades split the sun's shadow
4
4
  along the view into 2-4 maps (three's CSM addon): sharp near the camera, coarse far away. Use them when near shadows look blocky and the
5
5
  world is bigger than one map covers well.
6
6
 
7
7
  ```js
8
8
  engine.use(sky({ shadow: { cascades: 3 } })); // or the style pack: style.sky.shadow.cascades
9
- engine.sky.setShadow({ cascades: 3, maxFar: 150 }); // at run time; { cascades: 1 } switches back
9
+ engine.look.shadow.set({ cascades: 3, maxFar: 150 }); // at run time; { cascades: 1 } switches back
10
10
  ```
11
11
 
12
12
  | field | default | meaning |
@@ -1,4 +1,4 @@
1
- # Hand-painted art route: from Blender to the game
1
+ # Blender to game (GLB) route
2
2
 
3
3
  Code-built geometry (`models.js`, recipe 05) is good for blockout, props and variations, but it cannot reach the finish of hand-made art: painted
4
4
  textures, baked shadows, sculpted edges. That finish comes from Blender. This page is the whole path, in order. The level naming rules live in
@@ -32,6 +32,13 @@ Do not join meshes or decimate a level: node names are its interface.
32
32
  threedog assets check art/models/town.glb # inspect only: spawns, col_ colliders, trigger_ zones, template / id nodes, material suspicions
33
33
  threedog assets # compress art/models/*.glb into public/models/ (add -w my-game for a game)
34
34
  ```
35
+ `assets check` also lists materials, textures with the color space three gives them (by slot), normal maps, clips, `col_` colliders and template / id nodes.
36
+ After loading, `engine.assets.report('hero')` (or `.reportText`; pass a copy from `model()` to check what the game shows) lists the same from the scene and
37
+ flags what the file has but the scene lost: `normal-map-lost`, `material-replaced` (a style role took over), `clip-lost`, `clip-unmapped` (an animation
38
+ state names a clip the file lacks), `node-lost`, and wrong color spaces. The engine never recomputes normals or drops a normal map on a GLB; only code
39
+ that swaps materials as in section 5 does.
40
+ Swapping an export for a new one: `threedog assets check new.glb --against old.glb` lists what the old file had and the new one lacks (errors: `col_`
41
+ colliders, template / id nodes, spawn / trigger_ / npc_ / marker_ points; warnings: clips, materials, points moved over 0.5 m, a bounding box that changed over 15%).
35
42
  `assets check` exits 1 on errors (`--strict`: on warnings too; `--json` for tools). It changes no file.
36
43
  `assets` keeps names, hierarchy and materials and only compresses:
37
44
  | Step | What it does | When it matters |
@@ -42,6 +49,21 @@ threedog assets # compress art/models/*.glb into pub
42
49
 
43
50
  It needs `@gltf-transform/cli` (`npm i -D @gltf-transform/cli`). Unchanged files are skipped; `--force` redoes everything.
44
51
 
52
+ ### The same shot again, before and after
53
+ Declare fixed views once: `engine.views.define('gate', { position: [10, 4, 12], target: [0, 1, 0], fov: 50 })` (`views.show(name)` also works in code). Then
54
+ `npm run shot -- -w my-game --view gate --keep` takes the picture from there in any game (the page's own `?view=` still wins where a page handles it, as
55
+ in the style test). After a change, `npm run shot -- -w my-game --view gate --compare .threedog/shots/<before>.png` prints both file names, one pixel-diff
56
+ number (0 = identical) and the brightness / saturation / contrast / detail differences. A view holds the camera (`engine.takeCamera`) until `views.release()` or the handle `show()` returns is removed; a cutscene that held it before gets it back.
57
+ Views can also be content: `content/views.js` = `{ gate: { position: [10, 4, 12], target: [0, 1, 0], fov: 50 } }` is defined by `engine.content.load` (checked by `npm run check`; example: `examples/action/content/views.js`, `npm run shot -- action --view corner`).
58
+ `describe render` also shows the renderer output color space and warns when it is not srgb; `assets.report` flags color maps that are not srgb and data maps that are.
59
+
60
+ ### Looking at one part of the render
61
+ `engine.debug.view('albedo')` shows only the base color and texture (unlit), `'lighting'` plain white clay under the scene lights, `'shadow'` the same with
62
+ ambient and hemisphere light hidden so shadows read black, `'normals'` the normals as color (a normal map shows here); `'off'` restores everything.
63
+ A view is temporary and owner-scoped (`{ owner }`; another owner needs `force: true` to clear it), never saved, and `describe().render` / `describe render`
64
+ start with a DEBUG VIEW line while one is on, so a screenshot of clay is not taken for the real look. Meshes added after the call are not covered: call it again.
65
+ It needs the debug module (`engine.use(debug())`).
66
+
45
67
  ## 4. Use it
46
68
  Register the compressed file in the asset pack and refer to it by name everywhere else:
47
69
  ```js
@@ -57,11 +79,11 @@ A whole level is `level({ url: '/models/town.glb' })` (recipe 10). Animation cli
57
79
 
58
80
  ## 5. The GLB's own materials and the style
59
81
  **The GLB keeps its own materials.** The engine loads them as they are (textures, colors, roughness) and does not swap them for style roles;
60
- that is what lets a hand-painted texture show. `style.materials` (recipe 43) applies only to what code builds through `engine.makeMaterial(role, ...)`
61
- (terrain, vegetation, procedural models, pickups). One scene can mix painted GLB props and styled code-built things.
82
+ that is what lets a painted or baked texture show. `style.materials` (recipe 43) applies only to what code builds through `engine.makeMaterial(role, ...)`
83
+ (terrain, vegetation, procedural models, pickups). One scene can mix GLB props and styled code-built things.
62
84
 
63
85
  There is no automatic mapping from a GLB material name to a style role and no flag for it. To make a GLB follow the style anyway, do it in your
64
- game code, per model: name the material in Blender after the role (`wool`, `bark`) and look it up:
86
+ game code, per model: name the material in Blender after the role (`cloth`, `metal`, `glass`) and look it up:
65
87
  ```js
66
88
  const m = await engine.assets.model('hat');
67
89
  m.traverse(o => { if (o.isMesh) o.material = engine.makeMaterial(o.material.name, { color: o.material.color.getHex() }); });
@@ -1,7 +1,8 @@
1
- # Floating island look: round rim, snow that settles, flat backdrop
1
+ # Snow cover, flat backdrop, rounded terrain rim
2
2
 
3
- A floating island scene (recipe 42 for the outline) usually wants three more things: a soft rim, trees and ground that turn white while
4
- it snows, and a plain background with no horizon. All three are style or scenario settings; none needs a shader of your own.
3
+ Three independent settings, each for its own situation: a **rounded rim** for terrain with a visible edge (an island, a diorama board, a floating
4
+ level; recipe 42 for the outline), **snow cover** for any outdoor scene where it snows, and a **flat backdrop** for a scene that should have no
5
+ horizon (a menu stage, a board game, a diorama). All are style or scenario settings; none needs a shader of your own.
5
6
 
6
7
  ## Round rim
7
8
  `terrain({ shape: { edge: { round: 1.2 } } })` bends the top down by up to 1.2 m toward the rim. The side wall follows every bend of the