@bendyline/molen-tooling 0.0.1 → 0.0.3

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 (158) hide show
  1. package/README.md +22 -4
  2. package/dist/capture/harness.js +216 -216
  3. package/dist/capture/worldgen-preview.js +288 -288
  4. package/dist/cli.mjs +134 -12
  5. package/dist/docs-src/guide/3d-art-guidelines.md +2 -2
  6. package/dist/docs-src/guide/3d-model-assets.md +49 -13
  7. package/dist/docs-src/guide/adaptive-performance.md +4 -0
  8. package/dist/docs-src/guide/agent-loop.md +6 -6
  9. package/dist/docs-src/guide/aircraft.md +25 -17
  10. package/dist/docs-src/guide/audio.md +247 -0
  11. package/dist/docs-src/guide/browser-mount.md +17 -1
  12. package/dist/docs-src/guide/building-interiors.md +7 -5
  13. package/dist/docs-src/guide/determinism.md +27 -22
  14. package/dist/docs-src/guide/earth-view.md +444 -0
  15. package/dist/docs-src/guide/entities.md +17 -6
  16. package/dist/docs-src/guide/examples.md +39 -23
  17. package/dist/docs-src/guide/experience-playback.md +2 -3
  18. package/dist/docs-src/guide/game-samples.md +50 -21
  19. package/dist/docs-src/guide/graphics-performance.md +40 -8
  20. package/dist/docs-src/guide/input.md +9 -0
  21. package/dist/docs-src/guide/markers.md +52 -0
  22. package/dist/docs-src/guide/materials.md +10 -3
  23. package/dist/docs-src/guide/navigation.md +144 -0
  24. package/dist/docs-src/guide/project.md +23 -3
  25. package/dist/docs-src/guide/quickstart.md +39 -30
  26. package/dist/docs-src/guide/recognizable-places.md +24 -17
  27. package/dist/docs-src/guide/rendering-backends.md +5 -4
  28. package/dist/docs-src/guide/scripting.md +8 -4
  29. package/dist/docs-src/guide/sky.md +26 -9
  30. package/dist/docs-src/guide/source-bundles.md +0 -1
  31. package/dist/docs-src/guide/structure-library.md +20 -10
  32. package/dist/docs-src/guide/terrain.md +51 -6
  33. package/dist/docs-src/guide/vehicles.md +27 -14
  34. package/dist/docs-src/guide/worldgen.md +34 -24
  35. package/dist/docs-src/llms.txt +35 -18
  36. package/dist/docs-src/schemas/README.md +4 -1
  37. package/dist/docs-src/schemas/archive-set.md +175 -0
  38. package/dist/docs-src/schemas/components.md +1104 -1
  39. package/dist/docs-src/schemas/matgraph.md +6 -0
  40. package/dist/docs-src/schemas/soundbank.md +251 -0
  41. package/dist/docs-src/schemas/structure-placements.md +496 -0
  42. package/dist/docs-src/schemas/terrain-package.md +120 -0
  43. package/dist/index.d.mts +31 -3
  44. package/dist/index.mjs +2 -2
  45. package/dist/{mcp-BFnCWrg0.mjs → mcp-BTVwVKFb.mjs} +78 -4
  46. package/dist/{ops-BGxhSP6w.mjs → ops-BPdHodFR.mjs} +1181 -61
  47. package/dist/templates/city-courier/README.md +66 -0
  48. package/dist/templates/city-courier/checks.json +20 -0
  49. package/dist/templates/city-courier/commands.json +32 -0
  50. package/dist/templates/city-courier/delivery-run.replay.json +214 -0
  51. package/dist/templates/city-courier/gen/molen-types.ts +1016 -0
  52. package/dist/templates/city-courier/index.html +2 -0
  53. package/dist/templates/city-courier/package.json +26 -0
  54. package/dist/templates/city-courier/project.json +8 -0
  55. package/dist/templates/city-courier/scene.json +3474 -0
  56. package/dist/templates/city-courier/scripts/game.ts +131 -0
  57. package/dist/templates/city-courier/scripts/molen-scripts.d.ts +1288 -0
  58. package/dist/templates/city-courier/scripts/tsconfig.json +16 -0
  59. package/dist/templates/city-courier/src/audio.ts +96 -0
  60. package/dist/templates/city-courier/src/game-shell.css +317 -0
  61. package/dist/templates/city-courier/src/main.ts +84 -0
  62. package/dist/templates/city-courier/src/scene.ts +17 -0
  63. package/dist/templates/city-courier/src/vite-env.d.ts +1 -0
  64. package/dist/templates/city-courier/src/worker.ts +5 -0
  65. package/dist/templates/city-courier/test/headless.test.ts +95 -0
  66. package/dist/templates/city-courier/test/playthrough.test.js +52 -0
  67. package/dist/templates/city-courier/test/replay.test.ts +22 -0
  68. package/dist/templates/city-courier/tsconfig.json +17 -0
  69. package/dist/templates/city-courier/vite.config.ts +19 -0
  70. package/dist/templates/cubes/README.md +51 -0
  71. package/dist/templates/cubes/index.html +16 -0
  72. package/dist/templates/cubes/package.json +24 -0
  73. package/dist/templates/cubes/scene.json +15 -0
  74. package/dist/templates/cubes/src/cubes.ts +100 -0
  75. package/dist/templates/cubes/src/main.ts +21 -0
  76. package/dist/templates/cubes/src/worker.ts +15 -0
  77. package/dist/templates/cubes/test/headless.test.ts +98 -0
  78. package/dist/templates/cubes/tsconfig.json +17 -0
  79. package/dist/templates/cubes/vite.config.ts +17 -0
  80. package/dist/templates/data-viz/README.md +47 -0
  81. package/dist/templates/data-viz/camera-track.json +12 -0
  82. package/dist/templates/data-viz/data.json +9 -0
  83. package/dist/templates/data-viz/index.html +16 -0
  84. package/dist/templates/data-viz/package.json +25 -0
  85. package/dist/templates/data-viz/scene.json +7 -0
  86. package/dist/templates/data-viz/src/main.ts +39 -0
  87. package/dist/templates/data-viz/src/viz.ts +91 -0
  88. package/dist/templates/data-viz/src/worker.ts +12 -0
  89. package/dist/templates/data-viz/test/headless.test.ts +75 -0
  90. package/dist/templates/data-viz/tsconfig.json +17 -0
  91. package/dist/templates/data-viz/vite.config.ts +16 -0
  92. package/dist/templates/figures-gallery/README.md +46 -0
  93. package/dist/templates/figures-gallery/index.html +16 -0
  94. package/dist/templates/figures-gallery/package.json +25 -0
  95. package/dist/templates/figures-gallery/scene.json +276 -0
  96. package/dist/templates/figures-gallery/src/main.ts +44 -0
  97. package/dist/templates/figures-gallery/src/worker.ts +17 -0
  98. package/dist/templates/figures-gallery/test/headless.test.ts +90 -0
  99. package/dist/templates/figures-gallery/tsconfig.json +17 -0
  100. package/dist/templates/figures-gallery/vite.config.ts +17 -0
  101. package/dist/templates/index.json +191 -0
  102. package/dist/templates/skybound/README.md +66 -0
  103. package/dist/templates/skybound/checks.json +24 -0
  104. package/dist/templates/skybound/commands.json +32 -0
  105. package/dist/templates/skybound/first-leap.replay.json +224 -0
  106. package/dist/templates/skybound/gen/molen-types.ts +1016 -0
  107. package/dist/templates/skybound/index.html +2 -0
  108. package/dist/templates/skybound/package.json +26 -0
  109. package/dist/templates/skybound/project.json +8 -0
  110. package/dist/templates/skybound/scene.json +1777 -0
  111. package/dist/templates/skybound/scripts/game.ts +122 -0
  112. package/dist/templates/skybound/scripts/molen-scripts.d.ts +1288 -0
  113. package/dist/templates/skybound/scripts/tsconfig.json +16 -0
  114. package/dist/templates/skybound/src/audio.ts +96 -0
  115. package/dist/templates/skybound/src/game-shell.css +317 -0
  116. package/dist/templates/skybound/src/main.ts +63 -0
  117. package/dist/templates/skybound/src/scene.ts +17 -0
  118. package/dist/templates/skybound/src/vite-env.d.ts +1 -0
  119. package/dist/templates/skybound/src/worker.ts +5 -0
  120. package/dist/templates/skybound/test/headless.test.ts +124 -0
  121. package/dist/templates/skybound/test/playthrough.test.js +38 -0
  122. package/dist/templates/skybound/test/replay.test.ts +22 -0
  123. package/dist/templates/skybound/tsconfig.json +17 -0
  124. package/dist/templates/skybound/vite.config.ts +19 -0
  125. package/dist/templates/terrain-flyover/README.md +46 -0
  126. package/dist/templates/terrain-flyover/index.html +16 -0
  127. package/dist/templates/terrain-flyover/package.json +26 -0
  128. package/dist/templates/terrain-flyover/src/flyover.ts +23 -0
  129. package/dist/templates/terrain-flyover/src/main.ts +93 -0
  130. package/dist/templates/terrain-flyover/terrain.json +15 -0
  131. package/dist/templates/terrain-flyover/test/headless.test.ts +72 -0
  132. package/dist/templates/terrain-flyover/tsconfig.json +17 -0
  133. package/dist/templates/terrain-flyover/vite.config.ts +15 -0
  134. package/dist/templates/top-down-arena/README.md +65 -0
  135. package/dist/templates/top-down-arena/arena-skirmish.replay.json +204 -0
  136. package/dist/templates/top-down-arena/index.html +16 -0
  137. package/dist/templates/top-down-arena/package.json +26 -0
  138. package/dist/templates/top-down-arena/project.json +10 -0
  139. package/dist/templates/top-down-arena/scene.json +182 -0
  140. package/dist/templates/top-down-arena/scripts/chase.ts +17 -0
  141. package/dist/templates/top-down-arena/scripts/combat.ts +13 -0
  142. package/dist/templates/top-down-arena/scripts/control.ts +8 -0
  143. package/dist/templates/top-down-arena/scripts/molen-scripts.d.ts +1258 -0
  144. package/dist/templates/top-down-arena/scripts/spawner.ts +11 -0
  145. package/dist/templates/top-down-arena/scripts/tsconfig.json +16 -0
  146. package/dist/templates/top-down-arena/src/arena.ts +8 -0
  147. package/dist/templates/top-down-arena/src/audio.ts +96 -0
  148. package/dist/templates/top-down-arena/src/gen/molen-types.ts +1020 -0
  149. package/dist/templates/top-down-arena/src/main.ts +34 -0
  150. package/dist/templates/top-down-arena/src/scene.ts +24 -0
  151. package/dist/templates/top-down-arena/src/vite-env.d.ts +1 -0
  152. package/dist/templates/top-down-arena/src/worker.ts +7 -0
  153. package/dist/templates/top-down-arena/test/headless.test.ts +87 -0
  154. package/dist/templates/top-down-arena/test/replay.test.ts +22 -0
  155. package/dist/templates/top-down-arena/tsconfig.json +17 -0
  156. package/dist/templates/top-down-arena/types/arena.types.json +54 -0
  157. package/dist/templates/top-down-arena/vite.config.ts +21 -0
  158. package/package.json +14 -14
@@ -0,0 +1,247 @@
1
+ # Sound and music
2
+
3
+ Sound in Molen is data. A sound bank names the clips, three components say when and where they
4
+ play, and scripts can fire one-shots with `molen.audio.play`. The client's audio director reads
5
+ all of it every frame and plays the result through Web Audio. Nothing about playback touches the
6
+ simulation, so sound never changes a state hash, and `molen audio plan` shows what a scene would
7
+ play without opening a browser.
8
+
9
+ ## The pieces
10
+
11
+ | Piece | Where it lives | What it does |
12
+ | --- | --- | --- |
13
+ | `molen/soundbank@1` | a content pack (`provides.soundbank`) or a file beside the scene | Sound ids → clip files, loop points, gain, pitch range, bus, spatial defaults and provenance |
14
+ | `audioEnvironment` | one entity in the scene | Ambience layers, music playlist, event → sound mappings, footsteps, bus gains |
15
+ | `audioSource` | any entity | An emitter: loops follow the entity, pitch and gain follow signals, one-shots fire on triggers |
16
+ | `audioZone` | any entity | Area ambience that fades in as the listener approaches a sphere or box |
17
+ | `molen.audio.*` | scene scripts | `play`, `stop` and `music`, emitted as `audio.*` events |
18
+ | `@bendyline/molen-client/audio` | the page | `createAudioLayer` loads banks and plays what the rules ask for |
19
+
20
+ The `molen.sounds` content pack carries 63 CC0 sounds (ambience, vehicles, footsteps, impacts,
21
+ foley, UI, stings and six music tracks). Fetch it into a project with:
22
+
23
+ ```sh
24
+ npx molen pack fetch https://molen.dev/packs/index.json molen.sounds --out-dir public/packs
25
+ ```
26
+
27
+ That writes `public/packs/index.json` and pins the pack in `project.json`, so CLI ops such as
28
+ `molen audio plan` find the bank without flags.
29
+
30
+ ## Annotate a scene
31
+
32
+ Add one entity with an `audioEnvironment`. This one plays rain while it rains, birds on sunny
33
+ days, music throughout, and a crash sound on the `crash` event your script emits:
34
+
35
+ ```json
36
+ {
37
+ "id": "audio",
38
+ "components": {
39
+ "audioEnvironment": {
40
+ "buses": { "music": 0.5 },
41
+ "ambience": [
42
+ {
43
+ "sound": "ambience.rain",
44
+ "when": { "weather.precipitation.kind": "rain" },
45
+ "gainFrom": { "signal": "weather.precipitation.intensity", "curve": [[0, 0], [1, 1]] }
46
+ },
47
+ { "sound": "ambience.birds", "when": { "sky.daylight": { "min": 0.35 } }, "fadeS": 4 }
48
+ ],
49
+ "music": { "playlist": ["music.ambient.first-light", "music.ambient.lifewave"], "mode": "shuffle" },
50
+ "events": { "crash": { "sound": "impact.metal.heavy" } }
51
+ }
52
+ }
53
+ }
54
+ ```
55
+
56
+ Give a moving thing its own voice with `audioSource`. The engine below follows the car, and its
57
+ pitch and loudness follow the car's state:
58
+
59
+ ```json
60
+ {
61
+ "id": "player",
62
+ "components": {
63
+ "transform": { "pos": [0, 0.5, 0] },
64
+ "audioSource": {
65
+ "sound": "vehicle.engine.car",
66
+ "pitchFrom": { "signal": "vehicleState.speed", "curve": [[0, 0.8], [30, 1.7]] },
67
+ "gainFrom": { "signal": "vehicleInput.throttle", "curve": [[0, 0.5], [1, 1]] }
68
+ }
69
+ }
70
+ }
71
+ ```
72
+
73
+ Put the `audioSource` on an entity type and every instance gets it. The `molen.entities` vehicles
74
+ and aircraft carry their engines this way: cars run `vehicle.engine.car` or
75
+ `vehicle.engine.diesel` only while someone drives them (`"when": { "self.occupied": true }`), with
76
+ pitch from `vehicleState.speed` and gain from `vehicleInput.throttle`. The P-51 (a Merlin) and the
77
+ OH-6 take pitch and gain from `aircraftState.rpm`, so they are silent until the engine starts and
78
+ spool up and down with it. A loop whose gain is zero holds no voice.
79
+
80
+ Fire one-shots from a script when something happens that no component describes:
81
+
82
+ ```ts
83
+ molen.onCommand('attack', () => {
84
+ molen.audio.play('weapon.slash');
85
+ });
86
+ if (delivered === total) molen.audio.play('sting.win');
87
+ const alarm = molen.audio.play('ui.error', { entity: 'door', loop: true });
88
+ molen.audio.stop(alarm, 0.5);
89
+ molen.audio.music('music.dungeon');
90
+ ```
91
+
92
+ `molen.emit` works too: any event type listed under `audioEnvironment.events` plays its sound, at
93
+ the entity or position the payload names (`payload.entity`, `payload.position`, or `payload.a` for
94
+ collisions), or at the listener.
95
+
96
+ ## Rules
97
+
98
+ Every rule is a small piece of data the director re-evaluates each frame.
99
+
100
+ | Field | Meaning |
101
+ | --- | --- |
102
+ | `when` | All conditions must hold. A value means equality, a list means any of, `{ "min", "max" }` is an inclusive range, `{ "exists": true }` tests presence |
103
+ | `gainFrom`, `pitchFrom` | `{ signal, curve, smoothS? }`: a piecewise-linear curve of `[input, output]` points, clamped at both ends. A list of them multiplies, so a sound can fade with height and with distance at once |
104
+ | `triggerFrom` | `{ signal, every?, onChange?, sound? }`: a one-shot each time the signal advances by `every` (footsteps by distance) or changes |
105
+ | `startTick` | Play once at that tick; changing it plays again |
106
+ | `fadeS` | Fade time for ambience layers (default 1.5 s) |
107
+
108
+ Sounds that come from the ground, such as birds in the trees or traffic on the roads, should get
109
+ quieter as the listener rises. List one curve for height and another for distance to the source:
110
+
111
+ ```json
112
+ {
113
+ "sound": "ambience.city.traffic",
114
+ "gainFrom": [
115
+ { "signal": "listener.heightAboveGround", "curve": [[3, 1], [30, 0.7], [100, 0.3], [300, 0.08], [500, 0]] },
116
+ { "signal": "host.streetDistance", "curve": [[0, 1], [40, 0.55], [120, 0.2], [250, 0]] }
117
+ ]
118
+ }
119
+ ```
120
+
121
+ A layer turns on after its condition has held for 0.25 s and off after it has failed for 1 s, and
122
+ numeric ranges widen by 5% while a layer plays. A signal hovering at a threshold therefore never
123
+ makes a sound flicker.
124
+
125
+ ## Signals
126
+
127
+ | Signal | Value |
128
+ | --- | --- |
129
+ | `<component>.<field>` | A field of a component on the source's entity, e.g. `vehicleState.speed`, `aircraftState.rpm`, `transform.pos.1`. In `audioEnvironment` rules it reads the `listenerEntity` |
130
+ | `self.speed`, `self.distance`, `self.x/y/z` | The source entity's measured speed (m/s), distance travelled (m) and position |
131
+ | `self.occupied` | true while someone rides the source entity (an entity's `mounted` component names it) |
132
+ | `listener.speed`, `listener.distance`, `listener.x/y/z`, `listener.altitude` | The listener's speed, odometer and position |
133
+ | `listener.heightAboveGround` | What the host reports as the listener's height above the terrain (m); 0 when it reports nothing |
134
+ | `listener.mode`, `listener.grounded`, `listener.surface`, `listener.indoors` | What the host reports: walk, drive, fly, pilot or orbit; on the ground; the surface underfoot; inside a building |
135
+ | `weather.precipitation.kind`, `weather.precipitation.intensity`, `weather.windSpeed`, `weather.visibility`, `weather.clouds.coverage` | The scene's weather; a scene without weather reads as clear and calm |
136
+ | `sky.daylight`, `sky.starVisibility`, `sky.sunElevation` | The sky; a scene without a sky reads as day |
137
+ | `time.seconds` | Seconds since the audio layer started |
138
+ | `host.<name>` | Anything the page passes in, e.g. `host.urban` |
139
+
140
+ An unknown built-in signal is reported with a did-you-mean suggestion by `molen audio plan` and
141
+ in the browser console.
142
+
143
+ ## Check it headlessly
144
+
145
+ `molen audio plan` runs the scene for N ticks, feeds the director, and prints what would play:
146
+
147
+ ```sh
148
+ npx molen audio plan scene.json --ticks 300 --commands commands.json
149
+ ```
150
+
151
+ ```text
152
+ 300 ticks at 30 Hz, banks: molen.sounds@1.0.0:sounds.soundbank.json
153
+ loops:
154
+ [0 → end] music.racing bus music peak 0.80 pitch 1.00
155
+ [0 → end] vehicle.engine.car @player bus sfx peak 0.61 pitch 0.75–1.36
156
+ one-shots (1):
157
+ t=115 impact.metal.heavy (sfx)
158
+ ```
159
+
160
+ It reports unknown sound ids with a suggestion, and exits non-zero when it finds one. Pass
161
+ `--weather rain`, `--daylight 0.1`, `--mode walk` or `--listener <entity>` to hear other
162
+ conditions. `--json` prints the full report, and the `plan_audio` MCP tool returns the same.
163
+ Script sounds are ordinary events, so assertions work on them too:
164
+
165
+ ```json
166
+ { "format": "molen/assert@1", "assertions": [{ "event": "audio.play", "op": "occurred" }] }
167
+ ```
168
+
169
+ ## Play it in the browser
170
+
171
+ A page with a Worker kernel creates one layer, attaches it to the client, and updates it each
172
+ frame. Sound starts on the first click or key press, as browsers require.
173
+
174
+ ```ts
175
+ import { mountExperience } from '@bendyline/molen-client';
176
+ import {
177
+ attachAutoplayUnlock,
178
+ createAudioLayer,
179
+ loadPackSoundbanks,
180
+ } from '@bendyline/molen-client/audio';
181
+ import { createPackSet, openPack } from '@bendyline/molen-pack';
182
+
183
+ const { client } = await mountExperience({ link: worker, scene, canvas });
184
+ const index = await (await fetch('packs/index.json')).json();
185
+ const entry = index.packs['molen.sounds'];
186
+ const packs = createPackSet([await openPack(new URL(entry.file, new URL('packs/', location.href)).href)]);
187
+ const audio = createAudioLayer({
188
+ banks: await loadPackSoundbanks(packs),
189
+ provider: packs.assetProvider(),
190
+ renderer: client.renderer, // the camera is the listener; weather and sky come from here too
191
+ });
192
+ audio.attachClient(client);
193
+ attachAutoplayUnlock(audio);
194
+ requestAnimationFrame(function frame(now) {
195
+ audio.update(now);
196
+ requestAnimationFrame(frame);
197
+ });
198
+ ```
199
+
200
+ Every game sample does exactly this in its `src/audio.ts`. Hosts without a Worker kernel use
201
+ `audio.attachWorld(world)` for a main-thread `World`, or no source at all and pass the listener to
202
+ `update(now, { position, forward, mode, grounded, heightAboveGround })`. `setVolume`, `setMuted` and
203
+ `setBusGain('music', 0)` drive a settings menu.
204
+
205
+ `mountEarthView` plays the Earth soundscape on its own when its content includes the
206
+ `molen.sounds` pack: weather and time-of-day ambience, footsteps in walk mode, traffic near
207
+ streets, and engines on the cars and aircraft you board. Birds, crickets and traffic fade with
208
+ height above the terrain, and traffic also fades with distance from the nearest street. Pass `audio: false` to turn it off, and
209
+ use `view.audio` for volume. See [Earth view](earth-view.md).
210
+
211
+ ## Make your own sounds
212
+
213
+ A sound bank is a JSON file beside its clips. Add clips with `molen audio import`, which copies the
214
+ file, hashes it, reads its duration, and records where it came from:
215
+
216
+ ```sh
217
+ npx molen audio import rain.mp3 --id ambience.rain --bank sounds/sounds.soundbank.json \
218
+ --license CC0-1.0 --source https://freesound.org/s/000000/ --loop \
219
+ --description "Steady rain on leaves"
220
+ npx molen audio import step-2.mp3 --id footstep.wood --bank sounds/sounds.soundbank.json \
221
+ --license CC0-1.0 --append
222
+ npx molen audio check sounds/sounds.soundbank.json
223
+ ```
224
+
225
+ A bank with a later position in `banks` overrides sounds with the same id, so a project can
226
+ re-skin `molen.sounds` by shipping only the sounds it changes. Every entry records its license.
227
+ A bank with `"license": "CC0-1.0"` rejects anything else, which is how `molen.sounds` stays public
228
+ domain.
229
+
230
+ > [!TIP]
231
+ > MP3 plays in every browser. Ogg Vorbis does not decode in older Safari. Keep one-shots mono so
232
+ > they pan cleanly, and set `loopStart`/`loopEnd` a few milliseconds inside a loop so encoder
233
+ > padding never plays.
234
+
235
+ Good places to find sounds:
236
+
237
+ - **[Freesound](https://freesound.org)** — the largest library; filter to Creative Commons 0.
238
+ - **[Kenney](https://kenney.nl/assets/category:Audio)** — CC0 packs of UI, impacts, footsteps and
239
+ jingles.
240
+ - **[OpenGameArt](https://opengameart.org/art-search-advanced)** — filter by license, then check
241
+ each page, since many items are CC-BY or GPL.
242
+ - **Generated clips** (ElevenLabs sound effects, Stable Audio Open) — record the prompt and the
243
+ generator in the entry's `source`, and check the service's terms for your use.
244
+
245
+ CC-BY sounds and music (Kevin MacLeod's, for example) are fine in your own bank if you show the
246
+ credit they require. Avoid the BBC Sound Effects archive (non-commercial licence) and libraries
247
+ that forbid redistribution.
@@ -37,6 +37,10 @@ export default defineConfig({
37
37
  plugins: [molenScripts()],
38
38
  // Worker bundles have their own plugin pipeline in Vite, and the kernel runs in the Worker.
39
39
  worker: { format: 'es', plugins: () => [molenScripts()] },
40
+ build: {
41
+ // Keep three.js and the client out of the entry chunk; see "Production builds" below.
42
+ rollupOptions: { output: { manualChunks: { vendor: ['three', '@bendyline/molen-client'] } } },
43
+ },
40
44
  });
41
45
  ```
42
46
 
@@ -85,9 +89,21 @@ that actually initialized, and `client.renderer.fallbackReason` explains a fallb
85
89
  [rendering backends](rendering-backends.md) for strict selection, material compatibility and
86
90
  diagnostics.
87
91
 
92
+ ### Production builds
93
+
94
+ A page that mounts with a top-level `await`, as above, needs three.js and
95
+ `@bendyline/molen-client` in a chunk of their own (the `manualChunks` line in the Vite config
96
+ above). The client lazy-loads its WebGPU driver. If the bundler leaves three.js and the client in
97
+ the entry chunk, that lazy chunk imports the entry while the entry is still suspended at the
98
+ `await`, the import never settles, and the built page stays blank in every browser with WebGPU,
99
+ with no error. The dev server does not bundle, so only the production build shows it. `molen new`
100
+ and every sample template already carry the setting.
101
+
88
102
  ## Feedback from the simulation
89
103
 
90
- The client exposes what a HUD, sound, or win screen needs — no wire-protocol parsing:
104
+ The client exposes what a HUD, sound, or win screen needs — no wire-protocol parsing. For sound,
105
+ `createAudioLayer(...).attachClient(client)` from `@bendyline/molen-client/audio` plays a scene's
106
+ audio rules and `molen.audio.*` events; see [Sound and music](audio.md).
91
107
 
92
108
  ```ts
93
109
  client.onEvent('collision', (e, tick) => flash());
@@ -1,9 +1,10 @@
1
1
  # Inferred building interiors
2
2
 
3
- World explorer enables lazy interiors in the styled **Human** layer. Choose
4
- **Walk**, approach a building, and walk through its framed entrance. Near the entrance, the
5
- windows become transparent and reveal the same interior you can enter. `?interiors=0`
6
- disables this capability. `?synthetic=1&stores=1` provides a repeatable block of recognizable
3
+ World explorer enables lazy interiors in the styled **Human** layer: choose **Walk**, approach
4
+ a building, and walk through its framed entrance. Near the entrance, the windows become
5
+ transparent and reveal the same interior you can enter.
6
+
7
+ `?interiors=0` disables this capability. `?synthetic=1&stores=1` provides a repeatable block of recognizable
7
8
  stores; `test/visual/interiors.play.json` walks into and out of its fast-food restaurant and grocery store.
8
9
  Use `?synthetic=1&houses=1` for a residential block with two-storey houses and a bungalow.
9
10
  `test/visual/houses.play.json` walks through its entrance, climbs the stairs, and enters a bedroom.
@@ -56,7 +57,8 @@ cooperatively on the main thread; exterior generation continues through the exis
56
57
  `molen/interior-catalog@1` is a registered JSON format. Validate it with
57
58
  `molen validate catalog.json`; discover its fields with `molen schema get interior-catalog`.
58
59
  The default style pack's `interiors/catalog.json` (in the `molen.worldgen.default` content pack,
59
- source `content/worldgen/interiors/`) is a complete editable starting catalog with 15 profiles:
60
+ source [`content/worldgen/interiors/`](https://github.com/bendyline/molen/tree/main/content/worldgen/interiors)) is a complete
61
+ editable starting catalog with 15 profiles:
60
62
 
61
63
  | Program | Algorithm and furnishings |
62
64
  | --- | --- |
@@ -1,6 +1,6 @@
1
1
  # Determinism: what is guaranteed
2
2
 
3
- Determinism is molen's headline guarantee. This page is the contract: what reproduces, how
3
+ Determinism is Molen's headline guarantee. This page is the contract: what reproduces, how
4
4
  exactly, what breaks it, and what happens to your save files when you upgrade.
5
5
 
6
6
  ## The short version
@@ -126,13 +126,13 @@ runs as ordinary code, and nothing lints it.
126
126
 
127
127
  ## Upgrades and save files
128
128
 
129
- **Upgrading molen does not invalidate your saves unless the state format changed.**
129
+ **Upgrading Molen does not invalidate your saves unless the state format changed.**
130
130
 
131
131
  Two constants live in `packages/kernel/src/version.ts` and they do different jobs:
132
132
 
133
133
  | Constant | Today | Role |
134
134
  |---|---|---|
135
- | `ENGINE_VERSION` | `0.0.1` | metadata. Written into a keyframe's `engine` field so a save says which build wrote it. **Never compared on load, never hashed.** |
135
+ | `ENGINE_VERSION` | `0.0.3` | metadata. Written into a keyframe's `engine` field so a save says which build wrote it. **Never compared on load, never hashed.** |
136
136
  | `STATE_FORMAT` | `1` | the gate. Written into a keyframe under the reserved `plugins.$format` key, compared by `applyKeyframeTo`, and folded into `stateHash` as `stateFormat`. |
137
137
 
138
138
  So a release — even one that moves every package on the fixed version line — keeps your keyframes
@@ -142,13 +142,13 @@ before the key existed is read as format 1, the layout in use when it was introd
142
142
 
143
143
  **What a mismatch looks like.** Loading a keyframe whose format does not match throws:
144
144
 
145
- ```
145
+ ```text
146
146
  keyframe state format 7 does not match 1 (written by engine 0.0.1)
147
147
  ```
148
148
 
149
149
  `molen replay` checks the same thing before it runs anything, and tells you the fix:
150
150
 
151
- ```
151
+ ```text
152
152
  replay was recorded with state format 99; this build reads 1. Re-record it with: molen replay <fixture> --record
153
153
  ```
154
154
 
@@ -176,7 +176,7 @@ hashes in as well would make a hash depend on content no tick read.
176
176
  What the identity buys is a named error instead of a divergence at tick 0. Loading a keyframe into
177
177
  a world built from different content throws before any state changes:
178
178
 
179
- ```
179
+ ```text
180
180
  keyframe was saved with different content: content "types" was sha256:ab… (molen.entities@0.0.1) but the loaded content is sha256:cd… (molen.entities@0.0.2)
181
181
  ```
182
182
 
@@ -188,13 +188,16 @@ identity the keyframe recorded.
188
188
 
189
189
  ## How to check it yourself
190
190
 
191
+ The commands below run in a copy of the Skybound sample, made from the npm packages with
192
+ `npx @bendyline/molen-tooling new skybound --template skybound` (then `cd skybound && npm install`).
193
+
191
194
  **One run, one hash.**
192
195
 
193
- ```
194
- molen sim run examples/skybound/scene.json --ticks 30 --hash
196
+ ```sh
197
+ npx molen sim run scene.json --ticks 30 --hash
195
198
  ```
196
199
 
197
- ```
200
+ ```text
198
201
  tick: 30
199
202
  hash: sha256:ba22126aec5915b2de74b445cce75077e859ed5f1837cc3f13d4508c7222ccb9
200
203
  events: 30
@@ -209,11 +212,11 @@ same-JS-engine overall. Use the table above for the whole scene.
209
212
  **A recorded run, localized on failure.** A `*.replay.json` fixture holds the scene reference, the
210
213
  command log, and `expected.stateHash` plus `expected.tickHashes`.
211
214
 
212
- ```
213
- molen replay examples/skybound/first-leap.replay.json
215
+ ```sh
216
+ npx molen replay first-leap.replay.json
214
217
  ```
215
218
 
216
- ```
219
+ ```text
217
220
  ✓ replay matches (150 ticks, hash sha256:ede1d58b…, 128 events)
218
221
  ```
219
222
 
@@ -226,7 +229,7 @@ classifies what it finds:
226
229
  - **`behavior-drift`** — the build is deterministic but no longer matches the recording. If the
227
230
  per-tick hashes are recorded, you get the first tick that differs:
228
231
 
229
- ```
232
+ ```text
230
233
  ✖ replay diverged from the recording (the build is deterministic):
231
234
  expected: sha256:deadbeef
232
235
  actual: sha256:ede1d58b…
@@ -234,8 +237,8 @@ classifies what it finds:
234
237
  → if the change was intentional, re-record with: molen replay <fixture> --record
235
238
  ```
236
239
 
237
- **Two regression artifacts per example, doing different jobs.** A pinned `stateHash` literal in an
238
- example's `test/headless.test.ts` freezes one run of the current build; a run compared with itself
240
+ **Two regression artifacts per sample, doing different jobs.** A pinned `stateHash` literal in a
241
+ sample's `test/headless.test.ts` freezes one run of the current build; a run compared with itself
239
242
  only proves reproducibility, so that literal is what catches a refactor that quietly moved the
240
243
  whole simulation. The committed `*.replay.json` beside the scene freezes the command log and the
241
244
  per-tick hashes, so a failure names the tick. Keep both.
@@ -245,12 +248,14 @@ two snapshots, including continuation differences under the reserved `$world` ps
245
248
  `molen sim watch scene.json --ticks N` reruns on every file change and reports hash flips, event
246
249
  deltas and assertion transitions.
247
250
 
248
- **Golden images** are a different mechanism with a different guarantee. `pnpm -r test:golden`
249
- renders in a pinned headless Chromium on a software rasterizer and compares against a committed
250
- PNG with a perceptual tolerance (per-pixel threshold 0.1, at most 0.3% differing pixels). A
251
- missing golden **fails** rather than adopting the candidate. Record with `UPDATE_GOLDENS=1`;
252
- locally that produces a candidate only, and the authoritative refresh is the `update-goldens`
253
- workflow, which records on the same Ubuntu 24.04 runner as the CI golden job.
251
+ **Golden images** are a different mechanism with a different guarantee. `compareGolden` from
252
+ `@bendyline/molen-tooling` compares a render (from `molen shot`, or `screenshotScene` in a test)
253
+ against a committed PNG with a perceptual tolerance (per-pixel threshold 0.1, at most 0.3%
254
+ differing pixels by default). A missing golden **fails** rather than adopting the candidate.
255
+ Record with `UPDATE_GOLDENS=1`. The engine's own golden suites (`pnpm -r test:golden` in the
256
+ engine repository) render in a pinned headless Chromium on a software rasterizer, and their
257
+ authoritative refresh is the `update-goldens` workflow, which records on the same Ubuntu 24.04
258
+ runner as the CI golden job. Record your own goldens on one pinned machine for the same reason.
254
259
 
255
260
  ## What is not promised
256
261
 
@@ -266,7 +271,7 @@ Read this list before you build something that depends on a guarantee it does no
266
271
  polynomial approximations is a one-file change. Today its transcendentals are thin re-exports of
267
272
  native `Math`, so every "same JS engine" row above stays same-JS-engine until that swap happens.
268
273
  Routing through `dmath` buys you the swap point, not the result.
269
- - **There is no cross-JS-engine CI.** Every environment molen tests in — Node, headless Chromium,
274
+ - **There is no cross-JS-engine CI.** Every environment Molen tests in — Node, headless Chromium,
270
275
  the browser goldens, the materials cross-environment test — runs V8. No claim in this repo has
271
276
  been checked against JavaScriptCore or SpiderMonkey.
272
277
  - **Worldgen's content hashes are same-engine.** They are cache keys and regression signals, and