@bendyline/molen-tooling 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/NOTICE.md +15 -0
- package/README.md +91 -0
- package/dist/capture/THIRD-PARTY-NOTICES.md +223 -0
- package/dist/capture/basis/LICENSE.txt +55 -0
- package/dist/capture/basis/basis_transcoder.js +19 -0
- package/dist/capture/basis/basis_transcoder.wasm +0 -0
- package/dist/capture/capture.html +15 -0
- package/dist/capture/harness.js +4671 -0
- package/dist/capture/worldgen-preview.html +15 -0
- package/dist/capture/worldgen-preview.js +4617 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +1276 -0
- package/dist/docs-src/guide/3d-art-guidelines.md +157 -0
- package/dist/docs-src/guide/3d-model-assets.md +286 -0
- package/dist/docs-src/guide/adaptive-performance.md +89 -0
- package/dist/docs-src/guide/agent-loop.md +156 -0
- package/dist/docs-src/guide/aircraft.md +225 -0
- package/dist/docs-src/guide/browser-mount.md +185 -0
- package/dist/docs-src/guide/building-interiors.md +175 -0
- package/dist/docs-src/guide/capability-authoring.md +69 -0
- package/dist/docs-src/guide/determinism.md +285 -0
- package/dist/docs-src/guide/entities.md +47 -0
- package/dist/docs-src/guide/examples.md +58 -0
- package/dist/docs-src/guide/experience-playback.md +57 -0
- package/dist/docs-src/guide/figures.md +164 -0
- package/dist/docs-src/guide/game-samples.md +100 -0
- package/dist/docs-src/guide/graphics-performance.md +167 -0
- package/dist/docs-src/guide/input.md +205 -0
- package/dist/docs-src/guide/materials.md +125 -0
- package/dist/docs-src/guide/project.md +157 -0
- package/dist/docs-src/guide/quickstart.md +63 -0
- package/dist/docs-src/guide/recognizable-places.md +158 -0
- package/dist/docs-src/guide/rendering-backends.md +231 -0
- package/dist/docs-src/guide/scripting.md +330 -0
- package/dist/docs-src/guide/sky.md +192 -0
- package/dist/docs-src/guide/source-bundles.md +42 -0
- package/dist/docs-src/guide/structure-library.md +114 -0
- package/dist/docs-src/guide/surface-rendering.md +203 -0
- package/dist/docs-src/guide/terrain.md +389 -0
- package/dist/docs-src/guide/three-surface.md +70 -0
- package/dist/docs-src/guide/vehicle-interiors.md +126 -0
- package/dist/docs-src/guide/vehicles.md +110 -0
- package/dist/docs-src/guide/weather.md +123 -0
- package/dist/docs-src/guide/worldgen.md +434 -0
- package/dist/docs-src/llms.txt +129 -0
- package/dist/docs-src/schemas/README.md +36 -0
- package/dist/docs-src/schemas/archstyle.md +2340 -0
- package/dist/docs-src/schemas/assert.md +169 -0
- package/dist/docs-src/schemas/asset.md +543 -0
- package/dist/docs-src/schemas/business-catalog.md +162 -0
- package/dist/docs-src/schemas/cameratrack.md +132 -0
- package/dist/docs-src/schemas/command.md +112 -0
- package/dist/docs-src/schemas/components.md +5826 -0
- package/dist/docs-src/schemas/delta.md +204 -0
- package/dist/docs-src/schemas/experience-play.md +452 -0
- package/dist/docs-src/schemas/figure.md +290 -0
- package/dist/docs-src/schemas/interior-catalog.md +230 -0
- package/dist/docs-src/schemas/keyframe.md +314 -0
- package/dist/docs-src/schemas/landmark-catalog.md +56 -0
- package/dist/docs-src/schemas/landmark.md +293 -0
- package/dist/docs-src/schemas/matgraph.md +1163 -0
- package/dist/docs-src/schemas/pack-index.md +82 -0
- package/dist/docs-src/schemas/pack-source.md +139 -0
- package/dist/docs-src/schemas/pack.md +225 -0
- package/dist/docs-src/schemas/pixelgrid.md +108 -0
- package/dist/docs-src/schemas/prefab.md +106 -0
- package/dist/docs-src/schemas/project.md +271 -0
- package/dist/docs-src/schemas/region-atlas.md +612 -0
- package/dist/docs-src/schemas/replay.md +807 -0
- package/dist/docs-src/schemas/scatter.md +541 -0
- package/dist/docs-src/schemas/scene.md +1152 -0
- package/dist/docs-src/schemas/source-bundle.md +266 -0
- package/dist/docs-src/schemas/stylepack.md +420 -0
- package/dist/docs-src/schemas/terrain-package.md +731 -0
- package/dist/docs-src/schemas/terrain.md +313 -0
- package/dist/docs-src/schemas/types.md +218 -0
- package/dist/docs-src/schemas/uvpaint.md +149 -0
- package/dist/docs-src/schemas/worldgen-batch.md +743 -0
- package/dist/index.d.mts +1271 -0
- package/dist/index.mjs +78 -0
- package/dist/mcp-BFnCWrg0.mjs +796 -0
- package/dist/ops-BGxhSP6w.mjs +7246 -0
- package/package.json +96 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# Inferred building interiors
|
|
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
|
|
7
|
+
stores; `test/visual/interiors.play.json` walks into and out of its fast-food restaurant and grocery store.
|
|
8
|
+
Use `?synthetic=1&houses=1` for a residential block with two-storey houses and a bungalow.
|
|
9
|
+
`test/visual/houses.play.json` walks through its entrance, climbs the stairs, and enters a bedroom.
|
|
10
|
+
|
|
11
|
+
These layouts are plausible procedural interpretations of building use, **not surveyed floor
|
|
12
|
+
plans**. Confirmed occupant categories take precedence over building labels, then surrounding
|
|
13
|
+
use. The selected exterior style supplies a final fallback hint, so weakly labeled homes receive
|
|
14
|
+
a domestic layout. Unrecognized uses receive a generic furnished hall. A multi-tenant building currently uses
|
|
15
|
+
one inferred ground-floor program; it does not infer individual leased premises.
|
|
16
|
+
|
|
17
|
+
## Reusable generation platform
|
|
18
|
+
|
|
19
|
+
The implementation lives in `@bendyline/molen-worldgen/kernel` and knows only metric polygons,
|
|
20
|
+
opaque identities and use labels. The Earth adapter supplies those labels from mapped businesses
|
|
21
|
+
without changing the exterior classification of towers. Source feature identities, or the
|
|
22
|
+
existing quantized location identity when absent, stabilize the result.
|
|
23
|
+
|
|
24
|
+
The interior catalog is content: the style pack names it (`"interiors"` in `stylepack.json`) and
|
|
25
|
+
the resolved pack carries it as `pack.interiors`. A pack without one generates no interiors.
|
|
26
|
+
|
|
27
|
+
1. `generateBuilding({ ..., interiors: catalog }, builder)` cuts a real entrance and frontage
|
|
28
|
+
windows into the exterior. Homes also have bounded side/rear and upper-storey apertures. Its `record.interior` is an `InteriorSite`:
|
|
29
|
+
canonical outline and courtyard holes, floor and ceiling, door/window apertures, access ramp,
|
|
30
|
+
available storey heights, labels and identity. This stage generates **no floor plan or furniture**.
|
|
31
|
+
2. `generateInteriorPlan(site, { catalog })` returns a data-only `InteriorPlan`: rooms, fixtures,
|
|
32
|
+
storeys, stair runs, reserved circulation strips, seed and work statistics.
|
|
33
|
+
3. `generateInteriorGeometry(plan, catalog)` produces structure, furniture, glass, visible
|
|
34
|
+
stair-step and smooth stair-collision buffers. Structure includes floors, ceiling, interior-facing shell walls, room partitions
|
|
35
|
+
with doorways, and an entrance ramp. Furniture is a merged vertex-color batch of structured
|
|
36
|
+
low-poly models: stocked shelving, racks, counters/registers, tables/chairs, beds, desks,
|
|
37
|
+
sofas and benches, plus fitted kitchens, bathroom fixtures, wardrobes, dressers, bookcases,
|
|
38
|
+
rugs, coffee tables and plants.
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import {
|
|
42
|
+
generateInteriorPlan, generateInteriorGeometry, validateInteriorCatalog,
|
|
43
|
+
} from '@bendyline/molen-worldgen/kernel';
|
|
44
|
+
|
|
45
|
+
const catalog = pack.interiors ?? validateInteriorCatalog(myCatalogJson);
|
|
46
|
+
const plan = generateInteriorPlan(site, { catalog, maxFixtures: 160, maxCandidates: 1024 });
|
|
47
|
+
const buffers = generateInteriorGeometry(plan, catalog);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Both generation passes have `*Steps` variants that yield repeatedly. They run without a DOM or
|
|
51
|
+
three.js and can also be driven by a worker host. The shipped client drives these iterators
|
|
52
|
+
cooperatively on the main thread; exterior generation continues through the existing worker.
|
|
53
|
+
|
|
54
|
+
## Data-driven profiles and algorithms
|
|
55
|
+
|
|
56
|
+
`molen/interior-catalog@1` is a registered JSON format. Validate it with
|
|
57
|
+
`molen validate catalog.json`; discover its fields with `molen schema get interior-catalog`.
|
|
58
|
+
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
|
+
|
|
61
|
+
| Program | Algorithm and furnishings |
|
|
62
|
+
| --- | --- |
|
|
63
|
+
| Grocery | Long stocked shelf rows, 2.4 m aisles, front checkout |
|
|
64
|
+
| Fast food, restaurant, cafe | Tables and chairs with an entrance-side service counter |
|
|
65
|
+
| Pharmacy, retail, library | Smaller shelving modules and generous access strips |
|
|
66
|
+
| House | Connected hallway, living room, kitchen, bathrooms, bedrooms, and stairs to an upper floor when it fits |
|
|
67
|
+
| Apartments/hotel | Repeated room pods off circulation spaces |
|
|
68
|
+
| Office | Desk and chair modules with clear routes |
|
|
69
|
+
| School | Larger room pods with desks |
|
|
70
|
+
| Clinic | Room pods with beds |
|
|
71
|
+
| Warehouse | Tall storage racks and 3 m handling aisles |
|
|
72
|
+
| Assembly | Bench rows with a central aisle |
|
|
73
|
+
| Generic | Furnished hall with seating |
|
|
74
|
+
|
|
75
|
+
Each profile supplies an id/version, ordered label matches, algorithm family, furniture type,
|
|
76
|
+
module dimensions, aisle width, placement density and floor/wall/wood/accent colors. Catalog
|
|
77
|
+
validation rejects duplicate ids, missing fallbacks, invalid colors and unsafe metric ranges.
|
|
78
|
+
The seven reusable layout families are `aisles`, `dining`, `rooms`, `workplace`, `storage`,
|
|
79
|
+
`hall`, and `residential`.
|
|
80
|
+
Add or tune a profile in JSON to vary these families; extend the typed algorithm union and
|
|
81
|
+
generator when a new topology is necessary. The optional `residential` profile settings control
|
|
82
|
+
whether upstairs is allowed, clear stair width, run per meter of rise, and minimum room width.
|
|
83
|
+
|
|
84
|
+
The seed is `interior1|<identity>|<profile.id>@<profile.version>`. Named coordinate draws make
|
|
85
|
+
placements independent of request order, frame timing, floating-origin shifts and unrelated
|
|
86
|
+
profile edits. Smaller fixture caps preserve the prefix of the full layout. A profile version
|
|
87
|
+
bump intentionally rerolls that profile. No global random state is consumed.
|
|
88
|
+
|
|
89
|
+
Placement reserves the entrance spine, front circulation and cross aisles before furnishing.
|
|
90
|
+
Whole-rectangle tests include polygon edges and enclosed courtyard holes, so checking only
|
|
91
|
+
corners cannot accidentally place furniture across a concavity. Room furniture sits at the
|
|
92
|
+
back, leaving the doorway and turning space clear. Conservative placement can leave irregular
|
|
93
|
+
wings sparsely furnished; the generated floor still follows the complete outline and holes.
|
|
94
|
+
|
|
95
|
+
## Residential rooms and stairs
|
|
96
|
+
|
|
97
|
+
The residential algorithm fits two banks of rooms beside an entrance-connected hallway, then
|
|
98
|
+
assigns domestic uses instead of repeating beds. Single-storey homes get living, kitchen,
|
|
99
|
+
bedroom and bathroom spaces. When the envelope and footprint fit a safe stair run and a 1.5 m
|
|
100
|
+
landing, bedrooms move upstairs. Room records carry a purpose, storey index and hall-facing
|
|
101
|
+
1.16 m doorway. Partitions include headers, door casing and skirting; fixtures reserve turning
|
|
102
|
+
space at each door. House identity determines room proportions, bedding size, upholstery and
|
|
103
|
+
decor colors. Kitchens include cupboards, worktops, a sink/faucet, hob and oven. Bathrooms have
|
|
104
|
+
a shower, toilet and vanity. Furniture remains deliberately low-poly.
|
|
105
|
+
|
|
106
|
+
This first vertical topology supports ground plus one upper floor. Stair rise is divided into
|
|
107
|
+
steps no higher than 18 cm, with a default horizontal run of 1.65 m per meter of rise. The run
|
|
108
|
+
is removed from both the lower ceiling and upper floor. Guard walls and handrail trim protect
|
|
109
|
+
the upper opening; the landing leads directly back to the hallway. Insufficient width, depth
|
|
110
|
+
or headroom produces a single usable floor, rather than inaccessible upstairs rooms. Irregular
|
|
111
|
+
wings retain conservative placement and can remain sparsely furnished.
|
|
112
|
+
|
|
113
|
+
## Streaming, rendering and collision
|
|
114
|
+
|
|
115
|
+
`InteriorStreamer` from `@bendyline/molen-worldgen/client` accepts groups of sites and a metric
|
|
116
|
+
origin. Call `register(root, sites, [originX, originZ])` after creating a region's exterior,
|
|
117
|
+
`update([cameraX, cameraY, cameraZ])` before collision, and `unregister(root)` on disposal.
|
|
118
|
+
The supplied root must be attached to a visible scene hierarchy.
|
|
119
|
+
|
|
120
|
+
`new InteriorStreamer({ catalog })` takes the same catalog. The Earth renderer wires
|
|
121
|
+
registration/disposal automatically when created with `interiors: true` or streaming options,
|
|
122
|
+
using the style pack's catalog (and generating no interiors when the pack has none). The host calls
|
|
123
|
+
`renderers.updateInteriors(cameraPosition)` each frame. Only complete buildings at the finest
|
|
124
|
+
semantic level receive sites; coarse representations retain the cheap exterior path.
|
|
125
|
+
|
|
126
|
+
Defaults are a 65 m load distance, 90 m release distance, 12 resident interiors and a 16 MiB
|
|
127
|
+
resident geometry cap. Distance is measured to the footprint (including courtyard boundaries)
|
|
128
|
+
and vertically to the available storey envelope, so a large building remains resident while you are inside
|
|
129
|
+
and a high fly camera does not request rooms underneath it. Selection checks region bounds,
|
|
130
|
+
then prioritizes nearby buildings and deduplicates source identities. Plans cap at 1,024
|
|
131
|
+
candidate modules and 160 fixtures (hard ceilings 4,096 and 512). The work budget is 3 ms and
|
|
132
|
+
64 iterator steps per frame, with at most one completed upload per frame. This is a cooperative
|
|
133
|
+
budget, not a hard deadline: triangulation and final buffer upload are indivisible operations.
|
|
134
|
+
|
|
135
|
+
One opaque portal batch covers unready entrances/windows per region. Publication attaches the
|
|
136
|
+
complete interior and removes those covers atomically. Eviction restores covers and disposes
|
|
137
|
+
owned geometry; shared materials survive until streamer disposal. Hidden layers, region
|
|
138
|
+
disposal and moving out of range cancel pending work. There is no unbounded interior cache:
|
|
139
|
+
returning regenerates the same plan. Cached exterior descriptors count toward the existing
|
|
140
|
+
tile cache budget. The HUD reports available/resident interiors, pending generation, memory
|
|
141
|
+
and failures.
|
|
142
|
+
|
|
143
|
+
Structure, furnishings and glass share materials across interiors. Four shared 256² detail maps
|
|
144
|
+
supply wood grain/boards, ceramic grout, fabric weave and plaster grain, using metric UVs and
|
|
145
|
+
mipmaps. These neutral maps combine with household vertex colors; no texture is allocated per
|
|
146
|
+
building. Their fixed shared memory is separate from the resident geometry counter. Furniture is merged instead
|
|
147
|
+
of spawning one scene object per shelf product. Ceilings use simple bright fixture geometry;
|
|
148
|
+
there are no per-building dynamic lights or additional shadow maps. The walking octree uses
|
|
149
|
+
the same published geometry, except that visible stair steps are skipped (`walkIgnore`) and
|
|
150
|
+
a closed wedge supplies smooth stair collision. The published proxy is marked
|
|
151
|
+
`walkCollisionOnly` and has rendering layers disabled. Hosts using the kernel buffers directly
|
|
152
|
+
should likewise omit `steps` from physics and add `collision` to their collision scene. Portal index changes invalidate collision, and window glass is
|
|
153
|
+
solid from either side. Doorways remain open without an interaction key or door animation.
|
|
154
|
+
|
|
155
|
+
## Current limits and next extensions
|
|
156
|
+
|
|
157
|
+
This release covers ground floors and a connected upper floor for suitable homes in complete,
|
|
158
|
+
non-elevated polygon buildings that fit the
|
|
159
|
+
exterior geometry budget and have room for human-scale access. It does not promise entry into
|
|
160
|
+
every mapped fragment: clipped footprints, elevated parts, very low/narrow structures,
|
|
161
|
+
budget-boxed and omitted buildings lack a site. Additional storeys, switchback stairs, elevators,
|
|
162
|
+
animated doors, tenant subdivision and persistent object edits remain future extensions.
|
|
163
|
+
|
|
164
|
+
Ground-floor platforms use the highest sampled perimeter height and an entrance ramp. Very
|
|
165
|
+
steep sites, terrain protruding inside a large footprint, adjacent buildings obstructing a
|
|
166
|
+
door, or missing street-access metadata can still need a site-specific access solution. Window
|
|
167
|
+
transparency applies to generated apertures; homes have upper windows where the envelope
|
|
168
|
+
allows them. An aperture above an unused storey stays backed by an opaque surface. Interior objects are viewer-local geometry, not persistent ECS
|
|
169
|
+
entities. Extend the plan contract with gameplay state before allowing movable furnishings.
|
|
170
|
+
|
|
171
|
+
Regression coverage includes every profile, deterministic regeneration, translated origins,
|
|
172
|
+
courtyard/concave containment, work/memory caps, streaming cleanup, and walking through the
|
|
173
|
+
actual shell both before and after publication, plus ascending stairs, entering an upstairs
|
|
174
|
+
bedroom, descending and exiting with the real capsule controller. The browser playback scenario checks the
|
|
175
|
+
visible world-view path alongside those headless checks.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Authoring a capability package
|
|
2
|
+
|
|
3
|
+
Capabilities extend the engine without bloating the kernel. Two shipped packages are the
|
|
4
|
+
templates:
|
|
5
|
+
|
|
6
|
+
- **`@bendyline/molen-physics-rapier`** — a **kernel-only** plugin (no client half).
|
|
7
|
+
- **`@bendyline/molen-terrain`** — a **kernel + client** capability, split into subpath exports
|
|
8
|
+
`@bendyline/molen-terrain/kernel` and `@bendyline/molen-terrain/client` (it has **no `.` export**).
|
|
9
|
+
|
|
10
|
+
## The pattern
|
|
11
|
+
|
|
12
|
+
1. **Pick your halves.** Pure simulation → kernel-only (like physics-rapier). Needs rendering →
|
|
13
|
+
add a `/client` half that depends on `@bendyline/molen-client` (like terrain). Never let the
|
|
14
|
+
kernel half import three.js or the DOM.
|
|
15
|
+
|
|
16
|
+
2. **Install onto a world.** Export an `install*(world, opts?)` that registers systems and (if
|
|
17
|
+
stateful for snapshots) a snapshot provider. Give the system a name and unregister both in
|
|
18
|
+
your `dispose()` (`world.removeSystem(name)`, `world.unregisterSnapshotProvider(name)`):
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
export function installMyThing(world: World, opts?: MyOpts): void {
|
|
22
|
+
world.addSystem((w, ctx) => { /* ... */ }, { phase: 'physics', name: 'my-thing' });
|
|
23
|
+
// Opaque state that the legible ECS can't hold (solver warm-start, etc.):
|
|
24
|
+
world.registerSnapshotProvider('my-thing', () => save(), (blob) => load(blob));
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
`installKinematics`, `installCharacterController`, and `installScripting` are concrete examples.
|
|
28
|
+
|
|
29
|
+
3. **Define components in `@bendyline/molen-schema`.** Register their data shape so `molen validate`
|
|
30
|
+
and `molen components` know about them (and typos get did-you-mean):
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { registerComponent } from '@bendyline/molen-schema';
|
|
34
|
+
import { z } from 'zod';
|
|
35
|
+
registerComponent('myBody', z.looseObject({ mass: z.number() }), {
|
|
36
|
+
description: 'My rigid body.', owner: 'my-capability', examples: [{ mass: 1 }],
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
4. **Register any file formats** with `registerSchema(kind, zod, meta)` — and add a
|
|
41
|
+
`meta.validate(data)` for cross-field checks Zod can't express (cycles, dangling refs); see how
|
|
42
|
+
`@bendyline/molen-materials` validates matgraph/pixelgrid.
|
|
43
|
+
|
|
44
|
+
5. **Keep determinism.** Kernel-side math goes through `dmath` (the `check-dmath` lint enforces it);
|
|
45
|
+
route randomness through the world RNG. WASM stays behind an `await init()` and never enters the
|
|
46
|
+
kernel core (it lives in the capability/tooling package — see physics-rapier).
|
|
47
|
+
|
|
48
|
+
6. **Reach scripts.** Export a `<thing>ScriptApi(handle): object` (a frozen bag of functions —
|
|
49
|
+
see `rapierScriptApi`, `terrainScriptApi`) and hand it to `buildWorld` through the `physics` /
|
|
50
|
+
`terrain` hooks or `scriptExtensions`; it appears as `molen.<name>.*` in every scene script.
|
|
51
|
+
Tooling wires the built-in capabilities in `prepareSceneBuilder`; your own host does the same
|
|
52
|
+
with `buildWorld(manifest, setup, { scriptExtensions: { mine: myScriptApi(handle) } })`.
|
|
53
|
+
|
|
54
|
+
7. **Ground and reads.** A capability that owns a height source registers it with
|
|
55
|
+
`installTerrain(world, field)` (any object with `sampleHeight` + `normalAt`) so the character
|
|
56
|
+
controller and kinematics find it. Component reads are frozen stored objects: compare
|
|
57
|
+
references to detect change (`w.get(id, C) !== last`), never mutate them.
|
|
58
|
+
|
|
59
|
+
8. **Surface it to agents.** If you add an operation, put the logic in `@bendyline/molen-tooling`'s
|
|
60
|
+
`src/ops/`, expose it on **both** the CLI and MCP server, and add an `OPS_CATALOG` entry so
|
|
61
|
+
`molen describe` / `describe_op` document it. Add a guide here and link it from `llms.txt`.
|
|
62
|
+
|
|
63
|
+
## Conventions checklist
|
|
64
|
+
|
|
65
|
+
- Package name `@bendyline/molen-<thing>`; kernel/client halves as **subpath exports**, no `.`
|
|
66
|
+
export if it has both halves.
|
|
67
|
+
- `isolatedDeclarations` on (every export explicitly typed); ESM-only; build with tsdown.
|
|
68
|
+
- Kernel halves run `node ../../scripts/check-dmath.mjs src` in their `lint` script.
|
|
69
|
+
- Ship a smoke test in each target environment for any WASM dep.
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
# Determinism: what is guaranteed
|
|
2
|
+
|
|
3
|
+
Determinism is molen's headline guarantee. This page is the contract: what reproduces, how
|
|
4
|
+
exactly, what breaks it, and what happens to your save files when you upgrade.
|
|
5
|
+
|
|
6
|
+
## The short version
|
|
7
|
+
|
|
8
|
+
**Same scene, same seed, same command log, same build → the same state hash, tick for tick.**
|
|
9
|
+
|
|
10
|
+
The unit of proof is `stateHash(world)`: a SHA-256 over a canonical serialization of the world's
|
|
11
|
+
continuation state — tick, tick rate, seeded RNG state, entity creation order, every component's
|
|
12
|
+
data, the queued-command state, and every registered snapshot provider's blob (`stateHash` in
|
|
13
|
+
`packages/kernel/src/snapshot.ts`). Numbers are hashed as their raw IEEE-754 bits, object keys are
|
|
14
|
+
sorted, and the SHA-256 is pure JS with no `node:crypto` — so the kernel hashes identically in
|
|
15
|
+
Node and in a Web Worker.
|
|
16
|
+
|
|
17
|
+
Two granularities are available:
|
|
18
|
+
|
|
19
|
+
| Granularity | How you get it | What it tells you |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| Final state hash | `molen sim run … --hash`, `runHeadless().finalHash` | the whole run agrees, or it does not |
|
|
22
|
+
| Per-tick hashes | `perTickHashes()`, stored in a `*.replay.json` under `expected.tickHashes` | the **first tick** that disagrees |
|
|
23
|
+
|
|
24
|
+
Everything the hash covers is simulation state. Rendering is downstream of it and is never hashed.
|
|
25
|
+
|
|
26
|
+
## The levels
|
|
27
|
+
|
|
28
|
+
Determinism is not one guarantee, it is four. Every row below is the level at which that
|
|
29
|
+
subsystem's contribution to the state hash reproduces.
|
|
30
|
+
|
|
31
|
+
| Level | Means |
|
|
32
|
+
|---|---|
|
|
33
|
+
| **Cross-platform** | any OS, any JS engine, any build at the same `STATE_FORMAT`. Only IEEE-754 `+ - * /` and `Math.sqrt` reach hashed state, and those are exactly specified. |
|
|
34
|
+
| **Same JS engine** | reproduces wherever the same JS engine runs (V8 in Node, Chromium, Electron). Transcendentals (`sin`, `cos`, `pow`, `exp`, `log`, `atan2`) reach hashed state, and the spec leaves those implementation-approximated. |
|
|
35
|
+
| **Same build + platform** | native/WASM code whose float behaviour is a property of the compiled artifact. |
|
|
36
|
+
| **Not hashed** | the output never enters the state hash at all. It has its own contract, listed in the row. |
|
|
37
|
+
|
|
38
|
+
| Subsystem | Level | What backs it |
|
|
39
|
+
|---|---|---|
|
|
40
|
+
| ECS core, seeded RNG, command queue, hashing | Cross-platform | `rng.ts` is sfc32 — four uint32s and `Math.imul`, no floats in the state; `hash.ts` is pure-JS SHA-256 over canonical bytes |
|
|
41
|
+
| `physics.engine: "kinematics"` (2.5D XZ) | Cross-platform | `kernel/src/kinematics.ts` uses only `dmath.abs/ceil/clamp/floor/hypot/max/min/sqrt`; the broad-phase grid is rebuilt every tick and bodies resolve in creation order |
|
|
42
|
+
| `physics.engine: "platformer"` (XY swept boxes) | Cross-platform | `kernel/src/platformer.ts` uses only `dmath.clamp/max` |
|
|
43
|
+
| `physics.character: true` (character controller) | Cross-platform | `kernel/src/character.ts` uses only `dmath.hypot` |
|
|
44
|
+
| Terrain **sampling** — `molen.terrain.*`, ground under kinematics/character/vehicles | Cross-platform | `kernel/src/terrain.ts` is `+ - * /` plus `dmath.floor/sqrt`; the `Heightfield` behind it is `packages/terrain/src/heightfield.ts` + `gen.ts`, the two files `check-dmath` guards, and they use only `floor`, `sqrt`, `imul`, `max` |
|
|
45
|
+
| Timers, tweens, hierarchy, lifetime (`kernel/src/gameplay.ts`) | Cross-platform | no `dmath` and no `Math` transcendentals; easings are polynomial and `quatRotateVec3` is plain arithmetic |
|
|
46
|
+
| Scene scripts | Cross-platform **until** the script calls a transcendental; then same JS engine | the Compartment's `Math` is IEEE-exact natives plus `dmath` for everything else (`kernel/src/scripting.ts`); `Math.random` is absent and `Date`/`Intl`/`Promise` are shadowed to `undefined` |
|
|
47
|
+
| Quaternion helpers that use angles — `quatSlerp`, `lookRotation`, `quatFromYaw`, `quatFromEuler`, `yawOf` | Same JS engine | `kernel/src/math3d.ts` routes these through `dmath.sin/cos/acos/atan2`, and `dmath` is currently a thin re-export of native `Math` |
|
|
48
|
+
| Vehicles and aircraft | Same JS engine | `kernel/src/vehicles.ts` and `aircraft.ts` use `dmath.sin/cos/tan/atan2/exp` |
|
|
49
|
+
| Figures (`@bendyline/molen-figures/kernel`) | Same JS engine | its locomotion system writes `figureState` and `transform.rot` into the world and registers a `figures` snapshot provider, so it **is** hashed; it reaches `dmath.atan2` and `quatFromYaw`, and `gait.ts` reaches `dmath.pow`/`sin`/`cos` |
|
|
50
|
+
| `physics.engine: "rapier"` (3D rigid bodies) | Same build + platform | `@dimforge/rapier3d-compat` WASM; the plugin hashes an opaque `takeSnapshot()` blob plus its id→handle maps |
|
|
51
|
+
| Worldgen geometry and prop placement | Not hashed | `installWorldgen` registers the index on a `WeakMap` side channel with no snapshot provider; a test asserts installing it leaves `stateHash` unchanged. Its own content hashes (`hashWorldgenOutput`) are **same JS engine**: its kernel half calls `Math.hypot` in ~33 places, which `dmath.hypot` deliberately avoids because `Math.hypot`'s intermediate scaling is engine-defined |
|
|
52
|
+
| Terrain **streaming, projection, surface rendering** | Not hashed | outside `check-dmath`'s two guarded files on purpose; `geospatial.ts` reaches `Math.cos/log/tan/atan/exp` |
|
|
53
|
+
| `@bendyline/molen-materials` (textures, matgraphs, SVG) | Not hashed | render-only, and no kernel half imports it. Its contract is byte-identical output in Node and the browser — see the caveat below |
|
|
54
|
+
| Rendering, `molen shot`, golden images | Not hashed | pixels, not state; per-build, not cross-machine |
|
|
55
|
+
|
|
56
|
+
Two rows carry a footnote worth reading before you rely on them.
|
|
57
|
+
|
|
58
|
+
**Materials.** The contract is *identical bytes in Node and in the browser*, and it is tested
|
|
59
|
+
directly: `packages/tooling/test/golden/material-cross-env.golden.test.ts` bakes the same
|
|
60
|
+
matgraph and pixelgrid documents in Node and in headless Chromium and compares the RGBA buffers
|
|
61
|
+
byte for byte, with zero tolerance. Both of those are V8. The bakers call `Math.sin`/`Math.cos`
|
|
62
|
+
(in `noise.ts` and `matgraph.ts`), so that test is evidence across environments, not a proof
|
|
63
|
+
across JS engines. The SVG and UV-paint paths are not in that test.
|
|
64
|
+
|
|
65
|
+
**Worldgen's `worldgenBuilding` component.** The component *data* an entity is authored with is
|
|
66
|
+
ordinary ECS state and is hashed like any other component. What is not hashed is the geometry
|
|
67
|
+
worldgen generates from it.
|
|
68
|
+
|
|
69
|
+
## What breaks it
|
|
70
|
+
|
|
71
|
+
### Rules an author follows
|
|
72
|
+
|
|
73
|
+
The script Compartment enforces the first three. The rest are yours to keep.
|
|
74
|
+
|
|
75
|
+
- **No `Math.random`.** The injected `Math` has no `random`. Use `molen.rng()`, which draws from
|
|
76
|
+
the seeded world RNG and is saved in every keyframe.
|
|
77
|
+
- **No `Date`, no `Intl`.** Both are shadowed to `undefined`. Use `molen.tick`.
|
|
78
|
+
- **No `Promise`.** Also shadowed: a `.then()` callback runs after the tick's hash was taken. Use
|
|
79
|
+
`molen.after` / `molen.every`, which emit events on a tick boundary.
|
|
80
|
+
- **Locale formatting is a review rule, not a guarded one.** `toLocaleString`, `toLocaleDateString`
|
|
81
|
+
and `localeCompare` live on `Number`/`String` prototypes, which the Compartment cannot remove.
|
|
82
|
+
They depend on the host's locale and ICU build. Never put their output into component state or
|
|
83
|
+
an event payload — format for display in the client.
|
|
84
|
+
- **Closure variables are not state.** Nothing serializes a JavaScript closure. Durable values
|
|
85
|
+
belong in components, in `molen.state` (with `"checkpoint": "state"` on the script entry), or in
|
|
86
|
+
a `world.registerSnapshotProvider`. See
|
|
87
|
+
[scripting.md](scripting.md#state-that-survives-saveload-and-replay).
|
|
88
|
+
- **Never mutate a read.** `molen.get` and query rows hand back the stored object, frozen in dev
|
|
89
|
+
worlds. Writing through it throws there — and with `devFreeze: false` it silently corrupts both
|
|
90
|
+
the state and the deltas the client mirrors.
|
|
91
|
+
- **No NaN or Infinity in component data.** Dev worlds reject them at the write site: they hash as
|
|
92
|
+
their IEEE bits but serialize to `null`, so a keyframe round trip would change both the state
|
|
93
|
+
and its hash.
|
|
94
|
+
- **Kernel and capability code uses `dmath`, never transcendental `Math.*`.** `scripts/check-dmath.mjs`
|
|
95
|
+
enforces it. It takes explicit roots, so coverage is per-package and deliberate: `kernel` guards
|
|
96
|
+
all of `src`; `figures`, `worldgen` and `worldgen-earth` guard `src/kernel`; `terrain` guards
|
|
97
|
+
exactly `src/heightfield.ts` and `src/gen.ts`, because a `Heightfield` is the kernel's structural
|
|
98
|
+
`GroundField` and the rest of that package is projection and streaming. The lint is lexical — it
|
|
99
|
+
cannot see a transcendental reached through an import, which is why
|
|
100
|
+
`worldgen-earth` carries its own `dmath`-based `projection.ts` instead of importing terrain's.
|
|
101
|
+
- **Systems never read a content library at tick time.** Entity types, landmark models and
|
|
102
|
+
business catalogs are content: a host loads them and hands them over as libraries
|
|
103
|
+
(`createTypeLibrary`, `createLandmarkLibrary`, `createBusinessCatalog`). Anything a tick needs
|
|
104
|
+
from them is copied into components when the entity spawns, which keeps the state hash complete
|
|
105
|
+
on its own and lets a replay run without the library.
|
|
106
|
+
|
|
107
|
+
### Ways a host breaks it from outside
|
|
108
|
+
|
|
109
|
+
The Compartment only covers scripts. A setup module, a capability package or an embedding host
|
|
110
|
+
runs as ordinary code, and nothing lints it.
|
|
111
|
+
|
|
112
|
+
- **Reading the wall clock in a system.** `World` is clock-free by construction; every real-time
|
|
113
|
+
concern lives in `Scheduler`, which is the only thing that calls `Date.now`. A system that reads
|
|
114
|
+
`Date.now()` or `performance.now()` and writes the result into a component makes the run
|
|
115
|
+
unreproducible, and the divergence report will say so.
|
|
116
|
+
- **Turning off `devFreeze`.** That disables both the freeze and the non-finite check, so mutating
|
|
117
|
+
a read stops throwing and starts corrupting.
|
|
118
|
+
- **Iteration order that is not insertion order.** `Set`/`Map` iteration is insertion-ordered in
|
|
119
|
+
JS, so the hazard is code that builds the collection in an order that varies — from an unordered
|
|
120
|
+
fetch, a directory listing, or an object keyed by something unstable.
|
|
121
|
+
- **Changing the systems while comparing hashes.** Hash equality assumes identical systems,
|
|
122
|
+
identical script sources and snapshot-safe host configuration. Two worlds built differently that
|
|
123
|
+
happen to agree at tick 30 are not the same simulation.
|
|
124
|
+
- **Rapier.** Same build and same platform only. A replay recorded on one machine may diverge on
|
|
125
|
+
another. The 2.5D kinematics layer is the cross-platform option.
|
|
126
|
+
|
|
127
|
+
## Upgrades and save files
|
|
128
|
+
|
|
129
|
+
**Upgrading molen does not invalidate your saves unless the state format changed.**
|
|
130
|
+
|
|
131
|
+
Two constants live in `packages/kernel/src/version.ts` and they do different jobs:
|
|
132
|
+
|
|
133
|
+
| Constant | Today | Role |
|
|
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.** |
|
|
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
|
+
|
|
138
|
+
So a release — even one that moves every package on the fixed version line — keeps your keyframes
|
|
139
|
+
loadable and your recorded `*.replay.json` fixtures valid, as long as it did not change simulation
|
|
140
|
+
semantics or the snapshot layout. `STATE_FORMAT` is bumped only when it did. A keyframe written
|
|
141
|
+
before the key existed is read as format 1, the layout in use when it was introduced.
|
|
142
|
+
|
|
143
|
+
**What a mismatch looks like.** Loading a keyframe whose format does not match throws:
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
keyframe state format 7 does not match 1 (written by engine 0.0.1)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
`molen replay` checks the same thing before it runs anything, and tells you the fix:
|
|
150
|
+
|
|
151
|
+
```
|
|
152
|
+
replay was recorded with state format 99; this build reads 1. Re-record it with: molen replay <fixture> --record
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**What to do about it.** For a replay fixture or a pinned test hash, re-record:
|
|
156
|
+
`molen replay <fixture> --record`. For a save file, there is nothing to run: **formats are beta,
|
|
157
|
+
and a breaking change bumps the version in the envelope (`molen/scene@3`, `molen/keyframe@1`)
|
|
158
|
+
rather than shipping a migration.** Plan for saves to be disposable until the formats stabilize.
|
|
159
|
+
|
|
160
|
+
Loading a keyframe has three more requirements beyond the format, all of which throw rather than
|
|
161
|
+
silently drift: the target world's `tickRate` must match, `entityOrder` must name every entity
|
|
162
|
+
exactly once, and any script that has not declared `"checkpoint": "state"` refuses a restore at a
|
|
163
|
+
nonzero tick — because its durable state may be sitting in closures the engine cannot serialize.
|
|
164
|
+
Restore into the same systems, component vocabulary, script ids and plugin providers.
|
|
165
|
+
|
|
166
|
+
### Content identity
|
|
167
|
+
|
|
168
|
+
A world can record which content it was built from: `buildWorld(scene, setup, { content })`, where
|
|
169
|
+
`content` names each domain with the hash of the library that loaded it and, optionally, the packs
|
|
170
|
+
it came from (`{ types: { hash: typeLibrary.hash, packs: ['molen.entities@0.0.1'] } }`). The
|
|
171
|
+
identity is recorded **next to** the state hash, never inside it: keyframes carry it under the
|
|
172
|
+
reserved `plugins.$content` key, and a replay fixture records it as `content`. Content that affects
|
|
173
|
+
the simulation already reaches the hash through the components written at spawn; folding pack
|
|
174
|
+
hashes in as well would make a hash depend on content no tick read.
|
|
175
|
+
|
|
176
|
+
What the identity buys is a named error instead of a divergence at tick 0. Loading a keyframe into
|
|
177
|
+
a world built from different content throws before any state changes:
|
|
178
|
+
|
|
179
|
+
```
|
|
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
|
+
```
|
|
182
|
+
|
|
183
|
+
`applyKeyframeTo(world, keyframe, { allowContentDrift: true })` loads anyway. `molen replay` checks
|
|
184
|
+
a fixture's `content` before it runs and suggests `--record`, which writes the identity the build
|
|
185
|
+
ran against. Only domains both sides name are compared, so a fixture recorded before a domain
|
|
186
|
+
existed, or a host that loads extra content, is not a mismatch. `worldFromKeyframe` restores the
|
|
187
|
+
identity the keyframe recorded.
|
|
188
|
+
|
|
189
|
+
## How to check it yourself
|
|
190
|
+
|
|
191
|
+
**One run, one hash.**
|
|
192
|
+
|
|
193
|
+
```
|
|
194
|
+
molen sim run examples/skybound/scene.json --ticks 30 --hash
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
```
|
|
198
|
+
tick: 30
|
|
199
|
+
hash: sha256:ba22126aec5915b2de74b445cce75077e859ed5f1837cc3f13d4508c7222ccb9
|
|
200
|
+
events: 30
|
|
201
|
+
physics: platformer (cross-platform deterministic)
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
The last line is the CLI naming the level for you. A `rapier` scene prints
|
|
205
|
+
`physics: rapier (deterministic same-build/same-platform only)` instead. It reports the **physics
|
|
206
|
+
engine's** level, not the scene's: a kinematics scene that also drives vehicles or figures is
|
|
207
|
+
same-JS-engine overall. Use the table above for the whole scene.
|
|
208
|
+
|
|
209
|
+
**A recorded run, localized on failure.** A `*.replay.json` fixture holds the scene reference, the
|
|
210
|
+
command log, and `expected.stateHash` plus `expected.tickHashes`.
|
|
211
|
+
|
|
212
|
+
```
|
|
213
|
+
molen replay examples/skybound/first-leap.replay.json
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
```
|
|
217
|
+
✓ replay matches (150 ticks, hash sha256:ede1d58b…, 128 events)
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
On a mismatch you do not get "hash differs". `molen replay` re-runs the build against itself and
|
|
221
|
+
classifies what it finds:
|
|
222
|
+
|
|
223
|
+
- **`non-deterministic`** — the build diverged from *itself*. You get the first divergent tick and
|
|
224
|
+
a component-level diff of what differed there, plus the usual causes (`Math.random`,
|
|
225
|
+
`Date`/`performance`, iteration order). Fix the code.
|
|
226
|
+
- **`behavior-drift`** — the build is deterministic but no longer matches the recording. If the
|
|
227
|
+
per-tick hashes are recorded, you get the first tick that differs:
|
|
228
|
+
|
|
229
|
+
```
|
|
230
|
+
✖ replay diverged from the recording (the build is deterministic):
|
|
231
|
+
expected: sha256:deadbeef
|
|
232
|
+
actual: sha256:ede1d58b…
|
|
233
|
+
first differs at tick 40
|
|
234
|
+
→ if the change was intentional, re-record with: molen replay <fixture> --record
|
|
235
|
+
```
|
|
236
|
+
|
|
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
|
|
239
|
+
only proves reproducibility, so that literal is what catches a refactor that quietly moved the
|
|
240
|
+
whole simulation. The committed `*.replay.json` beside the scene freezes the command log and the
|
|
241
|
+
per-tick hashes, so a failure names the tick. Keep both.
|
|
242
|
+
|
|
243
|
+
**Other tools.** `molen diff a.keyframe.json b.keyframe.json` gives a component-level diff between
|
|
244
|
+
two snapshots, including continuation differences under the reserved `$world` pseudo-entity.
|
|
245
|
+
`molen sim watch scene.json --ticks N` reruns on every file change and reports hash flips, event
|
|
246
|
+
deltas and assertion transitions.
|
|
247
|
+
|
|
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.
|
|
254
|
+
|
|
255
|
+
## What is not promised
|
|
256
|
+
|
|
257
|
+
Read this list before you build something that depends on a guarantee it does not make.
|
|
258
|
+
|
|
259
|
+
- **Golden images are deterministic per build, not across machines.** The software rasterizer
|
|
260
|
+
agrees with itself for a given Chromium build; it does not agree across Chromium versions or
|
|
261
|
+
operating systems. That is why goldens are recorded in one pinned container and compared with a
|
|
262
|
+
tolerance, and why DOM text overlays are kept out of captured frames.
|
|
263
|
+
- **Rapier is not cross-platform.** Same build, same platform. Measured run-to-run in its own
|
|
264
|
+
tests; not claimed beyond that.
|
|
265
|
+
- **Transcendentals are not proven across JS engines.** `dmath` exists so that the swap to
|
|
266
|
+
polynomial approximations is a one-file change. Today its transcendentals are thin re-exports of
|
|
267
|
+
native `Math`, so every "same JS engine" row above stays same-JS-engine until that swap happens.
|
|
268
|
+
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,
|
|
270
|
+
the browser goldens, the materials cross-environment test — runs V8. No claim in this repo has
|
|
271
|
+
been checked against JavaScriptCore or SpiderMonkey.
|
|
272
|
+
- **Worldgen's content hashes are same-engine.** They are cache keys and regression signals, and
|
|
273
|
+
its kernel half reaches `Math.hypot`, whose intermediate scaling is engine-defined.
|
|
274
|
+
- **Equal hashes are not proof of equivalent future behaviour.** `stateHash` compares serialized
|
|
275
|
+
continuation state. Mutable host and script closure state is outside the contract, and two
|
|
276
|
+
worlds that agree for 300 ticks can still diverge at tick 301 if their systems differ.
|
|
277
|
+
- **Nothing here survives a change to the inputs.** A different `tickRate`, a different seed, an
|
|
278
|
+
edited script, an added system, or a reordered command log is a different simulation, and it is
|
|
279
|
+
supposed to hash differently.
|
|
280
|
+
|
|
281
|
+
## Where to go next
|
|
282
|
+
|
|
283
|
+
- [Scripting](scripting.md) — the verb set, the determinism rules in context, and `hardenScripts()`.
|
|
284
|
+
- [The agent loop](agent-loop.md) — where `sim run`, `replay` and `diff` sit in the dev loop.
|
|
285
|
+
- [Scene manifest](../schemas/scene.md) — the `physics.engine` field and what each value means.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Reusable entities
|
|
2
|
+
|
|
3
|
+
The `molen.entities` content pack is molen's curated entity collection. It builds on the existing
|
|
4
|
+
`renderable.kind: "gltf"`, `molen/asset@1`, `molen/types@1`, and `molen/project@1` contracts;
|
|
5
|
+
there is no second entity or asset runtime.
|
|
6
|
+
|
|
7
|
+
The initial nature collection contains pine, fir, oak, birch, shrub, and boulder models under the
|
|
8
|
+
stable `molen.entities.*` namespace. Every model is a deterministic texture-free GLB with a
|
|
9
|
+
hash-verified sidecar, meter-scale bounds, a conservative collision hull, and a type definition.
|
|
10
|
+
Its source is `content/entities/` in the repository; the npm package
|
|
11
|
+
`@bendyline/molen-entities` carries only the id lists and helpers, no models or type documents. The
|
|
12
|
+
gallery scene is both an example and a headless render check.
|
|
13
|
+
|
|
14
|
+
Every concrete thing is authored as a [logical source bundle](source-bundles.md) under
|
|
15
|
+
`content/entities/source/<category>/<thing>/`. Its local `source.json` inventories the definition,
|
|
16
|
+
model master or recipe, scripts, textures, sounds, and documentation. The package generator builds
|
|
17
|
+
the aggregate registry and gallery from those bundles; the aggregate files are compatibility and
|
|
18
|
+
runtime outputs, not a second authoring authority.
|
|
19
|
+
|
|
20
|
+
Bind the pack to a browser client through its asset provider:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { createClient } from '@bendyline/molen-client';
|
|
24
|
+
import { createPackSet, openPack } from '@bendyline/molen-pack';
|
|
25
|
+
|
|
26
|
+
// Wherever the app hosts the pack. Models are range-read only when a scene uses them.
|
|
27
|
+
const entities = await openPack('/packs/molen.entities.zip');
|
|
28
|
+
const client = await createClient(link, {
|
|
29
|
+
assets: { provider: createPackSet([entities]).assetProvider() },
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The entity type id and renderable asset ref are identical, such as
|
|
34
|
+
`molen.entities.tree.conifer.pine`. For the type definitions, list the pack in the project's
|
|
35
|
+
`packs` (see [Projects & types](project.md)); the CLI then resolves every `molen.entities.*` type.
|
|
36
|
+
In code, read the documents the manifest `provides` as `types` and pass them to
|
|
37
|
+
`createTypeLibrary` from `@bendyline/molen-kernel/content`.
|
|
38
|
+
|
|
39
|
+
From the repository, run `molen asset list` in `content/entities`, `molen types check --project
|
|
40
|
+
content/entities/project.json`, or render `content/entities/scenes/gallery.scene.json` with
|
|
41
|
+
`molen shot`. The package generator is deterministic and its build fails when a checked-in GLB,
|
|
42
|
+
sidecar, types document, project, or gallery scene is stale.
|
|
43
|
+
## Aircraft collection
|
|
44
|
+
|
|
45
|
+
`molen.entities.aircraft.p51d` and `molen.entities.aircraft.oh6` add the Mustang and OH-6
|
|
46
|
+
helicopter, including GLBs, flight components and pilot seats. The pack's asset provider
|
|
47
|
+
serves them like any other model. See [Aircraft](aircraft.md) for world-view controls, physics and integration.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Examples gallery
|
|
2
|
+
|
|
3
|
+
Run `npm run dev` from the repository root to open the gallery and serve every browser example
|
|
4
|
+
from one local URL. The individual workspace commands below remain available when you only want
|
|
5
|
+
one demo.
|
|
6
|
+
|
|
7
|
+
Each example is a private workspace package that is simultaneously a browser demo and a headless
|
|
8
|
+
regression test. Run a demo with `pnpm --filter <pkg> dev`; run its headless test with
|
|
9
|
+
`pnpm --filter <pkg> test:unit`. They are the best copy-and-modify starting points.
|
|
10
|
+
|
|
11
|
+
| Example | Package | Shows | Run the demo |
|
|
12
|
+
|---|---|---|---|
|
|
13
|
+
| Cubes | `@bendyline/molen-examples-cubes` | ~50 spinning/drifting cubes; a `spawn_cube` command; determinism across runs | `pnpm --filter @bendyline/molen-examples-cubes dev` |
|
|
14
|
+
| Data viz | `@bendyline/molen-examples-data-viz` | data-driven entities (one per row) + a camera track; golden image | `pnpm --filter @bendyline/molen-examples-data-viz dev` |
|
|
15
|
+
| Terrain flyover | `@bendyline/molen-examples-terrain-flyover` | chunked LOD terrain from a descriptor + deterministic 16-bit heightmap | `pnpm --filter @bendyline/molen-examples-terrain-flyover dev` |
|
|
16
|
+
| World explorer | `@bendyline/molen-examples-world-explorer` | streamed Web Mercator terrain with adaptive package LOD, bare / land-classification / human-feature modes, and styled buildings from the default worldgen pack (`?style=`, `?synthetic=1&lineup=1`) | `pnpm --filter @bendyline/molen-examples-world-explorer dev` |
|
|
17
|
+
| Figures gallery | `@bendyline/molen-examples-figures-gallery` | a lineup of every figure preset, a body-type sweep, a hat on a head socket and a rider on a horse; `?walk=1` (or the `set_gait` command) animates the gaits in place | `pnpm --filter @bendyline/molen-examples-figures-gallery dev` |
|
|
18
|
+
| Top-down arena | `@bendyline/molen-examples-top-down-arena` | a complete small game as **pure data**: `scene.json` declares kinematics, the `move` command + WASD input, and four scripts (control/spawner/chaser/combat); no setup module | `pnpm --filter @bendyline/molen-examples-top-down-arena dev` |
|
|
19
|
+
|
|
20
|
+
## Playable game samples
|
|
21
|
+
|
|
22
|
+
[Three complete games, one authoring path](game-samples.md) explains the shared infrastructure.
|
|
23
|
+
|
|
24
|
+
| Game | Run | Demonstrates |
|
|
25
|
+
|---|---|---|
|
|
26
|
+
| City Courier | `pnpm dev:driving` | Arcade driving, traffic, five deliveries, damage, a time limit and restart |
|
|
27
|
+
| The Lantern Vault | `pnpm dev:dungeon` | First-person exploration, melee rolls, inventory, a locked gate and victory |
|
|
28
|
+
| Skybound | `pnpm dev:platformer` | Side-scrolling jumps, one-way ledges, seeds, stomps, hazards and checkpoints |
|
|
29
|
+
|
|
30
|
+
Each includes a command-only victory regression and a real-browser gameplay test.
|
|
31
|
+
|
|
32
|
+
## Capability layers used
|
|
33
|
+
|
|
34
|
+
- **Kinematics** (`@bendyline/molen-kernel/kinematics`): 2.5D circle/AABB collision, `raycast`,
|
|
35
|
+
`overlapCircle` (arena).
|
|
36
|
+
- **Platformer** (`@bendyline/molen-kernel/platformer`): swept XY box movement against static
|
|
37
|
+
solids, jump buffering, coyote grace, and short hops (Skybound).
|
|
38
|
+
- **Character controller** (`@bendyline/molen-kernel/character`): gravity + jump + planar movement
|
|
39
|
+
from a `moveIntent` component.
|
|
40
|
+
- **Pathfinding** (`@bendyline/molen-pathfinding`): flow-field navigation over a grid.
|
|
41
|
+
- **Physics (Rapier)** (`@bendyline/molen-physics-rapier`): opt-in rigid-body plugin (WASM).
|
|
42
|
+
Colliders apply a positive uniform `transform.scale`, including offsets, asset geometry and
|
|
43
|
+
heightfields, and a scale change rebuilds the collider while keeping the body and its velocity.
|
|
44
|
+
Nonuniform, zero or negative scale on a physical entity fails with a diagnostic; bake it into
|
|
45
|
+
the collision geometry. Purely visual entities keep per-axis scale.
|
|
46
|
+
- **Terrain** (`@bendyline/molen-terrain`): `/kernel` heightfield queries + `/client` LOD meshes.
|
|
47
|
+
- **Worldgen** (`@bendyline/molen-worldgen`): `/kernel` outline → styled building and labeled
|
|
48
|
+
polygon → prop generation; `/client` buffer uploads and style packs.
|
|
49
|
+
- **Worldgen Earth binding** (`@bendyline/molen-worldgen-earth`): `/kernel` terrain-semantics
|
|
50
|
+
adapter and region atlas; `/client` terrain tile renderers.
|
|
51
|
+
- **Figures** (`@bendyline/molen-figures`): `/kernel` descriptors, rigs, gaits, `figureState`,
|
|
52
|
+
sockets and attachments; `/client` the `figure` renderable kind (procedural skinned bodies).
|
|
53
|
+
|
|
54
|
+
## Start from scratch
|
|
55
|
+
|
|
56
|
+
`molen new <name>` scaffolds a runnable experience (scene with camera/input/commands + scripts +
|
|
57
|
+
setup + commands + checks + a Vite browser app) that already runs the [agent loop](agent-loop.md)
|
|
58
|
+
and mounts in a page ([browser-mount.md](browser-mount.md)). Then iterate.
|