@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,156 @@
|
|
|
1
|
+
# The headless agent dev loop
|
|
2
|
+
|
|
3
|
+
You can build and verify a complete experience with no human and no browser window, using only
|
|
4
|
+
the `molen` CLI (the MCP server exposes the same operations). Every step returns structured,
|
|
5
|
+
fixable text.
|
|
6
|
+
|
|
7
|
+
## 1. Author
|
|
8
|
+
|
|
9
|
+
Write a scene manifest as JSON. Minimal example (`scene.json`):
|
|
10
|
+
|
|
11
|
+
```json
|
|
12
|
+
{
|
|
13
|
+
"format": "molen/scene@3",
|
|
14
|
+
"name": "demo",
|
|
15
|
+
"seed": "demo-1",
|
|
16
|
+
"tickRate": 30,
|
|
17
|
+
"entities": [
|
|
18
|
+
{ "id": "a", "components": {
|
|
19
|
+
"transform": { "pos": [0, 0, 0], "rot": [0, 0, 0, 1] },
|
|
20
|
+
"renderable": { "kind": "primitive", "ref": "box", "materialRef": "palette:#4363d8" }
|
|
21
|
+
} }
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Entities can also instantiate project-registry types (`"type": "train.locomotive"`) — see
|
|
27
|
+
[project.md](project.md). A scene that takes input declares its `commands` (optionally with a
|
|
28
|
+
JSON Schema payload) and an `input` block; scripts handle them with `molen.onCommand`.
|
|
29
|
+
|
|
30
|
+
Add game logic as **scene-data `scripts`** right in the manifest (deterministic, no
|
|
31
|
+
build step — see [scripting.md](scripting.md)); a **setup module** (`export function
|
|
32
|
+
setup(world, manifest) { … }` or a `defineExperience({...})` result) adds ECS systems in other
|
|
33
|
+
phases. With `"setup"` in project.json every op loads it automatically. The fastest start is `molen new <name>`, which scaffolds a full
|
|
34
|
+
project (project.json + scene + type registry + setup + `cmds.json`/`checks.json`). Ops accept
|
|
35
|
+
project scene names too: `molen sim run main --ticks 30`.
|
|
36
|
+
|
|
37
|
+
## 2. Validate (the inner loop — cheap, do it constantly)
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
molen validate scene.json
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
On failure you get the exact JSON Pointer, what was expected, what was found, and often a
|
|
44
|
+
did-you-mean. Fix and repeat until clean.
|
|
45
|
+
|
|
46
|
+
## 3. Simulate N ticks headlessly
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
molen sim run scene.json --ticks 300 --setup ./setup.mjs --hash
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Runs the kernel in-process in Node (no Worker), printing the final tick, a deterministic state
|
|
53
|
+
hash, and the event count. The hash is identical across runs of the same build; how far it travels
|
|
54
|
+
across machines depends on which subsystems the scene uses, and the command prints the level for
|
|
55
|
+
the scene's physics engine on the last line. See [determinism.md](determinism.md).
|
|
56
|
+
|
|
57
|
+
## 4. Assert on world state
|
|
58
|
+
|
|
59
|
+
Author an assertion document (`checks.json`) and pass `--assert`:
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{ "format": "molen/assert@1", "assertions": [
|
|
63
|
+
{ "select": "has:renderable", "op": "count", "value": 1 },
|
|
64
|
+
{ "select": "#a .transform.pos[1]", "op": "approx", "value": 0, "tol": 0.01 }
|
|
65
|
+
] }
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
molen sim run scene.json --ticks 300 --setup ./setup.mjs --assert checks.json
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Selectors: `#id`, `tag:name`, `has:component`, space-separated conjunction, and value paths
|
|
73
|
+
like `.health.hp` or `.transform.pos[1]`. The command exits non-zero if any assertion fails.
|
|
74
|
+
|
|
75
|
+
## 5. Screenshot (then look at it)
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
molen shot scene.json --ticks 300 --setup ./setup.mjs --camera 0,6,24 --look 0,0,0 --size 1280x720 --out shot.png
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Renders one deterministic frame in headless Chromium and writes a PNG plus a stats block
|
|
82
|
+
(entities rendered, draw calls, triangles). The stats alone often tell you whether the scene is
|
|
83
|
+
right; read the PNG when you need to judge appearance.
|
|
84
|
+
|
|
85
|
+
## 6. PLAY it (drive: commands in, frames out)
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
molen drive scene.json --actions actions.json --out-dir shots/ --assert checks.json
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`actions.json` is a tick-ordered array: `[{ "at": 0, "screenshot": "start" },
|
|
92
|
+
{ "at": 1, "command": { "type": "move", "payload": { "dir": [1, 0] } } },
|
|
93
|
+
{ "at": 60, "screenshot": "after" }]`. One deterministic pass: same seed + same actions =
|
|
94
|
+
identical frames and hash, so a played session doubles as a scenario regression test. Over MCP
|
|
95
|
+
(`drive_scene`) the frames come back as **images** — look at what you did. Assets get the same
|
|
96
|
+
treatment: `molen asset shot <id> --out-dir d` renders turntable angles of an imported model
|
|
97
|
+
(`screenshot_asset` over MCP), and `molen types test` smoke-tests every registry type
|
|
98
|
+
standalone (validates, spawns, simulates).
|
|
99
|
+
|
|
100
|
+
## 7. Iterate
|
|
101
|
+
|
|
102
|
+
Edit the JSON or setup module and go back to step 2 — or keep
|
|
103
|
+
`molen sim watch scene.json --ticks 300 --assert checks.json` running: it reruns on every file
|
|
104
|
+
change and reports what moved (hash flip, event delta, assertion transitions). The same
|
|
105
|
+
commands run in CI, so local green equals CI green.
|
|
106
|
+
|
|
107
|
+
For full browser experiences whose behavior includes pointer input, wall-clock rendering, or
|
|
108
|
+
streamed content, use `molen play` after the headless checks. Its declarative scenario holds keys,
|
|
109
|
+
drags the render surface, waits for visible telemetry to settle, and emits screenshots plus a run
|
|
110
|
+
manifest. See [experience-playback.md](experience-playback.md).
|
|
111
|
+
|
|
112
|
+
## Debugging determinism
|
|
113
|
+
|
|
114
|
+
Determinism is the engine's headline guarantee, and it has its own feedback surface. The contract
|
|
115
|
+
itself — what reproduces at which level, what breaks it, and what is not promised — is in
|
|
116
|
+
[determinism.md](determinism.md). To debug a specific run, record a `*.replay.json` fixture
|
|
117
|
+
(scene + command log), then:
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
molen replay demo.replay.json --setup ./setup.mjs # ✓ matches, or localizes divergence
|
|
121
|
+
molen replay demo.replay.json --setup ./setup.mjs --record # (re)record expected hashes
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
On a mismatch you don't get "hash differs" — you get one of:
|
|
125
|
+
|
|
126
|
+
- **non-deterministic**: "state first diverges at tick N" with a component-level diff. Cause is
|
|
127
|
+
almost always `Math.random`, `Date`/`performance`, or Set/Map iteration order in your code.
|
|
128
|
+
Route randomness through `molen.rng` / the world RNG and math through `molen.math` (dmath).
|
|
129
|
+
- **behavior-drift**: the build is deterministic but differs from the recording (an intentional
|
|
130
|
+
engine/content change, or a regression). Re-record with `--record` if intended.
|
|
131
|
+
|
|
132
|
+
`molen diff a.keyframe.json b.keyframe.json` gives a component-level diff between two snapshots.
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
## Checkpoints and continuation hashes
|
|
136
|
+
|
|
137
|
+
Keyframes now include `entityOrder` and `commands` (accepted future commands, source sequence
|
|
138
|
+
cursors, and late-command policy). Older keyframes without these optional fields still parse:
|
|
139
|
+
order falls back to object keys and the command queue is empty. Restore into the same
|
|
140
|
+
`STATE_FORMAT` and tick rate, with the same systems, type vocabulary, script ids, and plugin
|
|
141
|
+
providers. The package version is metadata that rides along in the keyframe and is never compared,
|
|
142
|
+
so an upgrade that did not change simulation semantics keeps your keyframes and recorded replays
|
|
143
|
+
valid — see [Upgrades and save files](determinism.md#upgrades-and-save-files). See
|
|
144
|
+
[scripting](scripting.md#state-that-survives-saveload-and-replay) for script state requirements.
|
|
145
|
+
|
|
146
|
+
`stateHash` version 2 covers entity creation order, tick rate, queued commands and deduplication,
|
|
147
|
+
RNG, allocator, components, and plugin snapshots, including physics state. Equal hashes assume
|
|
148
|
+
identical systems and host configuration. Re-record replay expectations with
|
|
149
|
+
`molen replay <fixture> --record` whenever `STATE_FORMAT` is bumped or the behaviour changes on
|
|
150
|
+
purpose; pinned hashes intentionally differ then. A changed future command can now diverge
|
|
151
|
+
immediately, before its effect becomes visible. `molen diff` reports continuation differences under
|
|
152
|
+
the reserved `$world` pseudo-entity as well as ordinary component differences.
|
|
153
|
+
|
|
154
|
+
`molen replay` uses the surrounding project's `setup` by default, just like simulation and
|
|
155
|
+
capture; an explicit `--setup` overrides it. The installed tooling package includes the guide
|
|
156
|
+
bundle, so `molen docs search` works from projects outside the engine checkout.
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# Aircraft in the world explorer
|
|
2
|
+
|
|
3
|
+
See [Vehicle interiors and instruments](vehicle-interiors.md) for cockpit source files,
|
|
4
|
+
per-model instrument bindings and the shared exterior/seated GLB contract.
|
|
5
|
+
|
|
6
|
+
The world explorer includes a P-51D Mustang and OH-6 interpretation, each with an editable
|
|
7
|
+
GLB, reusable entity type, flight physics, an instrumented cockpit and a chase camera. Use the
|
|
8
|
+
**P-51 Mustang** or **OH-6** buttons to visit the practice airfield, then press **E** to board.
|
|
9
|
+
The aircraft buttons also work from the example hub's world view. A direct link can use
|
|
10
|
+
`?aircraft=p51d` or `?aircraft=oh6`.
|
|
11
|
+
|
|
12
|
+
The practice airfield is a raised 900-meter runway and helipad near the initial camera position.
|
|
13
|
+
Its foundation clears streamed buildings; it is a fictional practice location, not a mapped airport.
|
|
14
|
+
Both aircraft stay in the ECS and retain their position throughout the session, across terrain
|
|
15
|
+
streaming and floating-origin changes. Reloading starts a fresh session.
|
|
16
|
+
|
|
17
|
+
## Controls
|
|
18
|
+
|
|
19
|
+
| Control | Action |
|
|
20
|
+
| --- | --- |
|
|
21
|
+
| E | Board, or exit after landing, stopping and engine shutdown |
|
|
22
|
+
| I | Start/stop engine; allow the propeller or rotor to spool |
|
|
23
|
+
| Shift / Ctrl | Increase/decrease throttle (Mustang) or collective (OH-6); holds its setting on release |
|
|
24
|
+
| W / S | Nose down / nose up |
|
|
25
|
+
| A / D | Bank left / right; helicopter cyclic |
|
|
26
|
+
| Q / Z | Left / right rudder or anti-torque pedals; ground steering in the Mustang |
|
|
27
|
+
| Space | Wheel brakes |
|
|
28
|
+
| G | Retract/extend Mustang gear while airborne |
|
|
29
|
+
| F | Toggle Mustang flaps |
|
|
30
|
+
| V | Cockpit / chase |
|
|
31
|
+
| Mouse | Look around the cockpit |
|
|
32
|
+
| R | Recover at the airfield after an impact |
|
|
33
|
+
|
|
34
|
+
Mustang: start the engine, set flaps, hold the brake while raising throttle, then release the brake.
|
|
35
|
+
Rotate gently around 85–100 knots and release the pitch key once the nose is about 10 degrees up.
|
|
36
|
+
Retract gear and flaps after climbing. Reduce throttle on approach, lower gear and flaps, and land
|
|
37
|
+
with wings level and a gentle descent. Gear-up and hard landings register an impact.
|
|
38
|
+
To accelerate, ease the nose down toward level flight after cleaning up; holding the takeoff
|
|
39
|
+
attitude spends engine power on climbing. During a stall, lower the nose, add power and gently
|
|
40
|
+
level the wings. Let airspeed rebuild before pulling out; hauling back immediately can stall
|
|
41
|
+
the wing again. A stall recovery requires altitude.
|
|
42
|
+
|
|
43
|
+
OH-6: start the engine and allow roughly six simulation seconds to reach full rotor speed. Raise
|
|
44
|
+
collective gradually toward 50%; exact hover power varies with altitude and ground effect. Small
|
|
45
|
+
cyclic inputs tilt rotor thrust to travel. Lower collective gently to land. Switch off the engine
|
|
46
|
+
and wait for the rotor to stop before exiting. An aircraft cannot be exited or switched to free
|
|
47
|
+
flight while airborne. After an impact, R resets its aircraft state and places it on the airfield.
|
|
48
|
+
|
|
49
|
+
Cockpit needles show airspeed, altitude, heading, vertical speed and RPM; the artificial horizon
|
|
50
|
+
banks with the aircraft. The HUD supplies precise knot/feet/feet-per-minute readings, AGL height,
|
|
51
|
+
power, engine/gear/flap state, stall alerts and terrain waiting status. Propellers, both helicopter
|
|
52
|
+
rotors, controls, gear, flaps and ailerons animate from simulation state.
|
|
53
|
+
|
|
54
|
+
## Reuse in another experience
|
|
55
|
+
|
|
56
|
+
Both aircraft ship in the `molen.entities` content pack (source: `content/entities`), with their
|
|
57
|
+
type documents and models. List the pack in your project.json `packs` and the CLI resolves the
|
|
58
|
+
types; in a browser, open it with `openPack` from `@bendyline/molen-pack` and pass
|
|
59
|
+
`createPackSet([pack]).assetProvider()` as the client's asset provider. The entity type IDs and
|
|
60
|
+
glTF refs are `molen.entities.aircraft.p51d` and `molen.entities.aircraft.oh6`. The world
|
|
61
|
+
explorer builds the pack into `public/packs` before dev and build, so authoring tools are not
|
|
62
|
+
required to launch it.
|
|
63
|
+
|
|
64
|
+
These are not kernel presets. Each type document contains the concrete aircraft's mass and center
|
|
65
|
+
of gravity, engine and thrust geometry, wing or rotor geometry, control response, lift/drag or
|
|
66
|
+
rotor-force coefficients, landing limits, collision probes, GLB reference, animation-node bindings,
|
|
67
|
+
seats, and behavior scripts. Molen supplies only the generic `airplane` and `helicopter` algorithms.
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
import { installAircraft, flyAircraft } from '@bendyline/molen-kernel/aircraft';
|
|
71
|
+
import { mountEntity, unmountEntity } from '@bendyline/molen-kernel/vehicles';
|
|
72
|
+
|
|
73
|
+
export function setup(world) {
|
|
74
|
+
const ground = { groundHeight: (x, z) => 0 };
|
|
75
|
+
installAircraft(world, ground);
|
|
76
|
+
world.registerCommand('board', () => mountEntity(world, 'pilot', 'mustang'));
|
|
77
|
+
world.registerCommand('fly', (_w, command) => flyAircraft(world, 'pilot', command.payload));
|
|
78
|
+
world.registerCommand('exit', () => unmountEntity(world, 'pilot', ground));
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Declare the commands and spawn the pilot and aircraft in your scene, using the type registry.
|
|
83
|
+
`Aircraft`, `AircraftInput`, `AircraftState`, `aircraftMounts`, `initialAircraftState` and
|
|
84
|
+
`stepAircraft` are exported by `kernel/aircraft`; serializable spec shapes are in schema, while
|
|
85
|
+
concrete values live in the external type documents.
|
|
86
|
+
The aircraft capability installs the same seat follower as cars, once per world. Mounted actors
|
|
87
|
+
bypass walking physics. Only the occupied pilot seat can submit flight intent.
|
|
88
|
+
|
|
89
|
+
The render half is `@bendyline/molen-client/aircraft`: `createAircraftVisual(loadedGlb, spec)` takes
|
|
90
|
+
ownership of a loaded GLB and animates the nodes named by `spec.visual` from aircraft state, and
|
|
91
|
+
`aircraftCameraPose(transform, spec, options)` returns the cockpit or chase pose from the same
|
|
92
|
+
`VehicleCameraOptions` that `@bendyline/molen-client/vehicles` exports.
|
|
93
|
+
|
|
94
|
+
The deterministic solver uses lift, induced/profile/gear/flap drag, propeller thrust, air density,
|
|
95
|
+
wind-relative airspeed, gravity, ground friction, damped control response and a progressive stall
|
|
96
|
+
envelope for the plane. Stall depends on wing incidence, including camber, rather than a fixed
|
|
97
|
+
true-airspeed cutoff. Separated flow progressively loses lift and control authority, adds drag,
|
|
98
|
+
and unloads the nose toward attached flow for both positive and negative incidence. Lift remains
|
|
99
|
+
perpendicular to airflow. Turn assistance follows the lift actually produced; fin stability
|
|
100
|
+
aligns the aircraft with the relative wind instead of forcing a level-flight turn during a stall.
|
|
101
|
+
Elevator and rudder retain limited propwash authority at low speed. Throttle controls shaft power
|
|
102
|
+
with a transient RPM spool limit, avoiding a second steady power penalty from RPM.
|
|
103
|
+
|
|
104
|
+
`airplane.stallTransitionAngle` sets the separation transition width (radians, default `0.12`),
|
|
105
|
+
and `airplane.yawStability` sets sideslip restoring response (1/s at reference airspeed, default
|
|
106
|
+
`1`). `stallDrag` is the broadside separated-flow coefficient, scaled by separation and
|
|
107
|
+
`sin(alpha)^2`. The legacy `stallSpeed` tuning reference no longer triggers aerodynamic stall.
|
|
108
|
+
The authored engine thrust axis is respected. Engine positions relative to the center of mass
|
|
109
|
+
produce thrust-induced yaw; wing position remains metadata rather than a distributed lift model.
|
|
110
|
+
|
|
111
|
+
## Multiple engines and engine failures
|
|
112
|
+
|
|
113
|
+
An airplane can keep the existing `spec.engine` (implicitly named `main`), or replace it with a
|
|
114
|
+
nonempty `spec.engines` array. Supply exactly one form. Every engine has a unique `id`, local
|
|
115
|
+
`position`, `thrustAxis`, shaft `power` in watts, and its own RPM/spool configuration. Power and
|
|
116
|
+
thrust limits are **per engine**; splitting one engine into two without changing total power or
|
|
117
|
+
static thrust means halving each engine's power and thrust cap. Optional engine `propellerEfficiency`, `maxThrust` and
|
|
118
|
+
`minPropellerSpeed` override the shared `airplane` values.
|
|
119
|
+
|
|
120
|
+
For example, derive a synthetic twin from an existing single-engine airplane spec:
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
const { engine, ...airframe } = singleEngineSpec;
|
|
124
|
+
if (!engine || !airframe.airplane) throw new Error('Expected a single-engine airplane');
|
|
125
|
+
const twinSpec = {
|
|
126
|
+
...airframe,
|
|
127
|
+
engines: [
|
|
128
|
+
{ ...engine, id: 'left', position: [2.5, 1, 1], power: engine.power / 2,
|
|
129
|
+
maxThrust: airframe.airplane.maxThrust / 2 },
|
|
130
|
+
{ ...engine, id: 'right', position: [-2.5, 1, 1], power: engine.power / 2,
|
|
131
|
+
maxThrust: airframe.airplane.maxThrust / 2 },
|
|
132
|
+
],
|
|
133
|
+
visual: {
|
|
134
|
+
...airframe.visual,
|
|
135
|
+
rotors: [
|
|
136
|
+
{ node: 'left-propeller', engine: 'left', axis: 'z', multiplier: 1 },
|
|
137
|
+
{ node: 'right-propeller', engine: 'right', axis: 'z', multiplier: 1 },
|
|
138
|
+
],
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Positions are meters from the aircraft's landing-contact origin, with +Z forward, +Y up and
|
|
144
|
+
**+X to the pilot's left**. The solver sums each engine's force and computes its yaw moment from
|
|
145
|
+
`(position - centerOfMass) × thrust`. A failed left engine therefore leaves the right engine
|
|
146
|
+
yawing the nose left. Rudder can counter the yaw; cutting the remaining engine removes the
|
|
147
|
+
powered asymmetry. Greater lateral separation produces a larger moment. `airplane.yawInertia`
|
|
148
|
+
sets yaw inertia in kg m² (default `mass * (span² + length²) / 12`), while `thrustYawDamping`
|
|
149
|
+
sets the thrust-induced yaw-rate damping in 1/s at reference airspeed (default `1.2`). Damping
|
|
150
|
+
scales with airspeed, with a 20% floor; ground tracking adds damping while on the wheels.
|
|
151
|
+
|
|
152
|
+
The normal throttle and engine switch still control the whole bank. Optional
|
|
153
|
+
`aircraftInput.engines` entries override individual throttles or switches; omitted fields inherit
|
|
154
|
+
the common controls. The common `engine: false` always shuts every engine down. In a host setup:
|
|
155
|
+
|
|
156
|
+
```js
|
|
157
|
+
import { flyAircraft, setAircraftEngineFailed } from '@bendyline/molen-kernel/aircraft';
|
|
158
|
+
|
|
159
|
+
flyAircraft(world, 'pilot', {
|
|
160
|
+
power: 0.8, engine: true, pitch: 0, roll: 0, yaw: 0,
|
|
161
|
+
gear: false, flaps: false, brake: false,
|
|
162
|
+
engines: { left: { power: 0.6 }, right: { enabled: true } },
|
|
163
|
+
});
|
|
164
|
+
setAircraftEngineFailed(world, 'twin', 'left'); // latch a failure
|
|
165
|
+
setAircraftEngineFailed(world, 'twin', 'left', false); // explicit repair
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
`setAircraftEngineFailed` returns false for an unknown aircraft or engine. A failure immediately
|
|
169
|
+
removes powered thrust and lets that propeller spool down; pilot throttle/switch input cannot
|
|
170
|
+
repair it. Failure triggers belong to the experience (for example a damage or training command).
|
|
171
|
+
The shipped world explorer still has its two single-engine aircraft and common controls; this
|
|
172
|
+
API does not add a twin-engine model, failure key or automatic random failures.
|
|
173
|
+
|
|
174
|
+
`aircraftState.engines[id]` stores `rpm`, `rotorAngle`, `failed` and current `thrust` in newtons.
|
|
175
|
+
The solver initializes missing engine state from the legacy RPM/phase, then the per-engine state
|
|
176
|
+
is authoritative. The aggregate `rpm` is the maximum across engines, and aggregate `rotorAngle`
|
|
177
|
+
follows the first engine. Set `visual.rotors[].engine` to animate independent propellers; omitted
|
|
178
|
+
bindings retain the common phase. `thrustYawRate`, all engine state and input overrides survive
|
|
179
|
+
keyframes/replay and pause at terrain gaps. Boarding and exit checks consider every engine.
|
|
180
|
+
|
|
181
|
+
This extension models propeller aircraft thrust imbalance within the assisted flight solver.
|
|
182
|
+
It does not add roll/pitch thrust moments, propeller reaction torque, P-factor, feathering,
|
|
183
|
+
windmilling drag or a calibrated minimum-control-speed envelope. Helicopters continue to use
|
|
184
|
+
one `engine` driving the shared rotor; multiple turbines feeding a common gearbox require a
|
|
185
|
+
different shaft-power model and are not represented by independent propeller engines.
|
|
186
|
+
|
|
187
|
+
Helicopter forces include rotor spool, collective lift, cyclic tilt, ground effect,
|
|
188
|
+
translational lift, air drag and assisted yaw. State includes velocity, attitude/rates, rotor phase
|
|
189
|
+
and controls for checkpoint/replay. Translational lift uses air-relative horizontal speed, so
|
|
190
|
+
wind and forward motion give consistent results. Collision sampling is at least 120 Hz and at most one meter
|
|
191
|
+
of translation per substep. Unknown terrain pauses at the last known position and resumes when
|
|
192
|
+
support is available.
|
|
193
|
+
|
|
194
|
+
Hosts can supply `groundHeight`, `wind` and `canOccupy(transform, spec, entity)`. The world view
|
|
195
|
+
checks nearby resident geometry, the airfield, cars and other aircraft. Cars and exits also check
|
|
196
|
+
conservative aircraft bounds. Imported collision hulls are
|
|
197
|
+
available for hosts that need a different collision solver. Without `canOccupy`, the kernel only
|
|
198
|
+
collides with terrain. Do not add a second physics body that also writes the aircraft transform.
|
|
199
|
+
|
|
200
|
+
This is an assisted game flight model with recognizable polygonal aircraft, not a full aircraft
|
|
201
|
+
systems simulation. Pitch and bank are bounded; aerobatic loops, spin recovery, rotor blade-element
|
|
202
|
+
aerodynamics, autorotation, vortex-ring state, fuel, automatic engine damage, detailed avionics and weapons
|
|
203
|
+
are outside this implementation. Cockpit switches and pedals are visual details; the listed input
|
|
204
|
+
controls operate the simulated systems. Collision uses coarse airframe probes and resident world
|
|
205
|
+
geometry; it does not model deformation or distant unloaded obstacles.
|
|
206
|
+
|
|
207
|
+
## Reproducible review
|
|
208
|
+
|
|
209
|
+
The source brief, generator, provenance and verification notes are in
|
|
210
|
+
the copyable [P-51 source bundle](../../content/entities/source/aircraft/p-51/README.md) and
|
|
211
|
+
[OH-6 source bundle](../../content/entities/source/aircraft/oh-6/README.md).
|
|
212
|
+
`content/entities/scenes/aircraft.scene.json` is the neutral apron scene. The browser flight
|
|
213
|
+
scenario is `examples/world-explorer/test/visual/aircraft.play.json`.
|
|
214
|
+
|
|
215
|
+
`packages/kernel/test/aircraft-performance.test.ts` exercises level acceleration, part-throttle
|
|
216
|
+
power, configuration drag, stall recovery from either bank direction, coordinated turns,
|
|
217
|
+
unpowered energy loss, wind equivalence and 30/60/120 Hz consistency. In calm air at 1,000 m,
|
|
218
|
+
starting at 60 m/s and using a test pilot to hold altitude for 120 seconds, the tuned Mustang
|
|
219
|
+
reaches approximately 311 knots at full throttle, 262 knots at 65% throttle, and 203 knots with
|
|
220
|
+
gear and flaps extended. These are simulation regression targets, not a certified performance
|
|
221
|
+
chart or an altitude-hold feature available to the player.
|
|
222
|
+
|
|
223
|
+
`packages/kernel/test/aircraft-engines.test.ts` covers symmetric two/four-engine layouts,
|
|
224
|
+
mirrored engine failures, counter-rudder, thrust moment arms, independent switches/spool,
|
|
225
|
+
explicit repair, terrain rollback, exit safety, keyframe restoration and 30/60/120 Hz consistency.
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# Mounting an experience in a browser page
|
|
2
|
+
|
|
3
|
+
The headless loop proves a scene; the browser plays it. The same manifest drives both: the
|
|
4
|
+
kernel runs in a Web Worker built with `buildWorld` (which installs the scene's scripts), and
|
|
5
|
+
the page mounts a client on that Worker with one call.
|
|
6
|
+
|
|
7
|
+
## worker.ts (the kernel)
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
/// <reference lib="webworker" />
|
|
11
|
+
import { startKernelWorker } from '@bendyline/molen-kernel';
|
|
12
|
+
import { project } from './project';
|
|
13
|
+
|
|
14
|
+
// Builds the world (scripts, commands and physics all from data) and serves it on this Worker's
|
|
15
|
+
// own port. Returns `{ world, host }` if you want to step or dispose it yourself.
|
|
16
|
+
startKernelWorker({ ...project() });
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`startKernelWorker` takes `keyframeInterval` from the scene, so the page gets its first keyframe
|
|
20
|
+
promptly. Everything `buildWorld` accepts — `setup`, `physics`, `terrain`, `capabilities` — passes
|
|
21
|
+
straight through, and `host` carries `KernelHost` options such as `startPaused`.
|
|
22
|
+
|
|
23
|
+
## project.ts (the manifest, scripts inlined)
|
|
24
|
+
|
|
25
|
+
Tooling reads `scripts[].path` files from disk; a bundler does it with raw imports:
|
|
26
|
+
|
|
27
|
+
Scene scripts are read as text here too. Register the `molenScripts()` plugin in
|
|
28
|
+
`vite.config.ts` so a `.ts` script is type-stripped when Vite loads it raw — the browser never
|
|
29
|
+
sees TypeScript, and nothing is transpiled at runtime:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
// vite.config.ts
|
|
33
|
+
import { molenScripts } from '@bendyline/molen-client/vite';
|
|
34
|
+
import { defineConfig } from 'vite';
|
|
35
|
+
|
|
36
|
+
export default defineConfig({
|
|
37
|
+
plugins: [molenScripts()],
|
|
38
|
+
// Worker bundles have their own plugin pipeline in Vite, and the kernel runs in the Worker.
|
|
39
|
+
worker: { format: 'es', plugins: () => [molenScripts()] },
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { loadProject } from '@bendyline/molen-kernel';
|
|
45
|
+
import sceneDoc from '../scene.json';
|
|
46
|
+
import typesDoc from '../types/main.types.json'; // omit when the scene declares no `type` refs
|
|
47
|
+
|
|
48
|
+
const scripts = import.meta.glob('../scripts/*.ts', { query: '?raw', import: 'default', eager: true });
|
|
49
|
+
|
|
50
|
+
export function project() {
|
|
51
|
+
return loadProject({ scene: sceneDoc, types: typesDoc, scripts });
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`loadProject` validates both documents, resolves the type registry, and inlines each script by
|
|
56
|
+
matching the glob's keys to the `path` the scene declares — so the glob's own prefix never has to
|
|
57
|
+
be stripped by hand. A bad document throws the validator's formatted message, the same text
|
|
58
|
+
`molen validate` prints; a script with no matching source names the keys it did have.
|
|
59
|
+
|
|
60
|
+
(Scenes whose scripts are all inline `code` still go through `loadProject` for the validation; the
|
|
61
|
+
`scripts` option is simply omitted.)
|
|
62
|
+
|
|
63
|
+
## main.ts (the page)
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { mountExperience } from '@bendyline/molen-client';
|
|
67
|
+
import { scene } from './scene';
|
|
68
|
+
|
|
69
|
+
const canvas = document.getElementById('view') as HTMLCanvasElement;
|
|
70
|
+
const worker = new Worker(new URL('./worker.ts', import.meta.url), { type: 'module' });
|
|
71
|
+
|
|
72
|
+
const { client } = await mountExperience({ link: worker, scene: scene(), canvas, clearColor: '#11131a' });
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`mountExperience` creates the client, applies the scene's `camera` block (fixed / free-fly /
|
|
76
|
+
top-down-ortho / follow), wires the `input` block (bindings + `emit` rules: `press`, `release`, `axis2d`)
|
|
77
|
+
to `client.command`, and keeps the renderer sized to the canvas (ortho framing refits on resize).
|
|
78
|
+
It returns `{ client, input, dispose }`.
|
|
79
|
+
|
|
80
|
+
The call is asynchronous because it picks a graphics backend: `backend` defaults to `'auto'`,
|
|
81
|
+
which probes WebGPU and falls back to the existing Three.js WebGL renderer, so this page gets
|
|
82
|
+
WebGPU wherever the browser has it. Pass `backend: 'webgl'` to skip the probe — pinning a
|
|
83
|
+
backend is what makes a captured frame reproducible. `client.renderer.backend` reports the one
|
|
84
|
+
that actually initialized, and `client.renderer.fallbackReason` explains a fallback. See
|
|
85
|
+
[rendering backends](rendering-backends.md) for strict selection, material compatibility and
|
|
86
|
+
diagnostics.
|
|
87
|
+
|
|
88
|
+
## Feedback from the simulation
|
|
89
|
+
|
|
90
|
+
The client exposes what a HUD, sound, or win screen needs — no wire-protocol parsing:
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
client.onEvent('collision', (e, tick) => flash());
|
|
94
|
+
client.onEvent('*', (e) => log(e.type));
|
|
95
|
+
client.onDiag((d) => console.warn(d.code, d.detail)); // rejected commands, tick overruns
|
|
96
|
+
client.onError((e) => showStopped(e.message)); // the kernel died, or a frame threw
|
|
97
|
+
const hp = client.get('player', 'health'); // a detached copy of the component
|
|
98
|
+
client.entities(); // every mirrored entity id
|
|
99
|
+
client.tick; // the latest applied kernel tick
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Wire `onError` in every experience. It is the only signal for the two failures the simulation
|
|
103
|
+
cannot report about itself: the Worker throwing (its scheduler stops and the world faults, which
|
|
104
|
+
arrives as the `tick-failed` diagnostic and, when the Worker dies outright, as `link-error`), and
|
|
105
|
+
an exception escaping the client's own render frame (`frame-error`). Without it a broken kernel
|
|
106
|
+
looks exactly like a paused one — the last frame keeps rendering and nothing is logged.
|
|
107
|
+
|
|
108
|
+
Events arrive with their tick: on a delta's tick, or on the keyframe's tick when the kernel sent
|
|
109
|
+
a keyframe instead of a delta. Periodic keyframes keep the interpolation ring, so motion stays
|
|
110
|
+
smooth across keyframe boundaries.
|
|
111
|
+
|
|
112
|
+
## Holding the world until assets are in
|
|
113
|
+
|
|
114
|
+
A `KernelHost` starts ticking the moment it is constructed, so a scene with models to fetch
|
|
115
|
+
simulates through its own loading screen — enemies close in, timers run down, and the player
|
|
116
|
+
cannot act yet. Boot the worker paused and let the page start it:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
// worker.ts
|
|
120
|
+
startKernelWorker({
|
|
121
|
+
...project(),
|
|
122
|
+
host: { startPaused: true }, // the initial keyframe still posts, so the page renders
|
|
123
|
+
}); // tick 0 while it loads
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
// main.ts
|
|
128
|
+
await client.ready(); // every pending asset load has settled
|
|
129
|
+
client.control({ action: 'resume' });
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
`client.control` carries the rest of the scheduler surface too — `pause`, `step` for a fixed
|
|
133
|
+
number of ticks, `set-rate` to change playback speed (not the sim's `tickRate`), and
|
|
134
|
+
`request-keyframe`:
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
client.control({ action: 'pause' });
|
|
138
|
+
client.control({ action: 'step', ticks: 30 }); // advance exactly one second at 30Hz
|
|
139
|
+
client.control({ action: 'set-rate', hz: 15 }); // half-speed playback for a debug view
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Stepping is what makes a browser test independent of machine speed: pause, send input, step a
|
|
143
|
+
known number of ticks, assert. A test that instead waits on wall-clock time is racing the
|
|
144
|
+
renderer, and on a software rasterizer it will lose.
|
|
145
|
+
|
|
146
|
+
## Manual frame loop
|
|
147
|
+
|
|
148
|
+
Pass `frameLoop: 'manual'` to drive rendering yourself (machinima camera tracks, custom timing):
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
const { client } = await mountExperience({ link: worker, scene: scene(), canvas, frameLoop: 'manual' });
|
|
152
|
+
function loop(now: number) {
|
|
153
|
+
client.setCamera(evaluateCameraTrack(track, tick(now)));
|
|
154
|
+
client.renderFrame(now);
|
|
155
|
+
requestAnimationFrame(loop);
|
|
156
|
+
}
|
|
157
|
+
requestAnimationFrame(loop);
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## The escape hatch
|
|
161
|
+
|
|
162
|
+
`client.renderer` is the three.js wrapper (`scene`, `worldRoot`, `camera`, `setCamera`,
|
|
163
|
+
`setTopDownOrtho`, `setSize`), and `client.getObject(id)` hands back the three.js object bound to
|
|
164
|
+
an entity — take it from there rather than searching `worldRoot`, because that is what releases a
|
|
165
|
+
statically batched entity into its own object:
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
const player = client.getObject('player'); // or client.backend for the whole surface
|
|
169
|
+
player?.add(myParticleSystem);
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
`mountExperience` is built from public pieces you can use directly: `await createClient(link, opts)`,
|
|
173
|
+
`applySceneCamera(camera, renderer)`, `applyInputRules(input, inputMap, emit)`,
|
|
174
|
+
`createClientCore({ link, backend })` (renderer-free and synchronous, for tests and custom
|
|
175
|
+
backends). See
|
|
176
|
+
[three-surface.md](three-surface.md).
|
|
177
|
+
|
|
178
|
+
Entity-follow cameras use scene data and the renderer interpolation buffer; see
|
|
179
|
+
[game samples](game-samples.md#follow-cameras) for overhead, first-person, and side-scroll configurations.
|
|
180
|
+
|
|
181
|
+
## Controller profiles and remapping
|
|
182
|
+
|
|
183
|
+
The mounted `input` supports keyboard, joystick/gamepad axes and buttons, named profiles, and
|
|
184
|
+
runtime rebinding. See [Input profiles and joysticks](input.md) for scene declarations and the
|
|
185
|
+
optional React remapping editor. Hosts can build their own UI with the same API.
|