@bendyline/molen-tooling 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -4
- package/dist/cli.mjs +26 -4
- package/dist/docs-src/guide/3d-art-guidelines.md +2 -2
- package/dist/docs-src/guide/3d-model-assets.md +15 -11
- package/dist/docs-src/guide/aircraft.md +9 -10
- package/dist/docs-src/guide/browser-mount.md +14 -0
- package/dist/docs-src/guide/building-interiors.md +2 -1
- package/dist/docs-src/guide/determinism.md +16 -11
- package/dist/docs-src/guide/entities.md +16 -5
- package/dist/docs-src/guide/examples.md +38 -23
- package/dist/docs-src/guide/experience-playback.md +2 -3
- package/dist/docs-src/guide/game-samples.md +30 -18
- package/dist/docs-src/guide/project.md +22 -2
- package/dist/docs-src/guide/quickstart.md +37 -28
- package/dist/docs-src/guide/recognizable-places.md +21 -15
- package/dist/docs-src/guide/rendering-backends.md +5 -4
- package/dist/docs-src/guide/scripting.md +4 -2
- package/dist/docs-src/guide/sky.md +10 -9
- package/dist/docs-src/guide/structure-library.md +18 -8
- package/dist/docs-src/guide/terrain.md +6 -4
- package/dist/docs-src/guide/vehicles.md +9 -5
- package/dist/docs-src/guide/worldgen.md +31 -21
- package/dist/docs-src/llms.txt +26 -15
- package/dist/docs-src/schemas/README.md +1 -1
- package/dist/index.d.mts +26 -2
- package/dist/index.mjs +2 -2
- package/dist/{mcp-BFnCWrg0.mjs → mcp-AOfIp89b.mjs} +12 -2
- package/dist/{ops-BGxhSP6w.mjs → ops-C4BvDgP-.mjs} +267 -33
- package/dist/templates/city-courier/README.md +53 -0
- package/dist/templates/city-courier/checks.json +20 -0
- package/dist/templates/city-courier/commands.json +32 -0
- package/dist/templates/city-courier/delivery-run.replay.json +214 -0
- package/dist/templates/city-courier/gen/molen-types.ts +878 -0
- package/dist/templates/city-courier/index.html +2 -0
- package/dist/templates/city-courier/package.json +25 -0
- package/dist/templates/city-courier/project.json +8 -0
- package/dist/templates/city-courier/scene.json +3395 -0
- package/dist/templates/city-courier/scripts/game.ts +127 -0
- package/dist/templates/city-courier/scripts/molen-scripts.d.ts +1125 -0
- package/dist/templates/city-courier/scripts/tsconfig.json +16 -0
- package/dist/templates/city-courier/src/game-shell.css +309 -0
- package/dist/templates/city-courier/src/main.ts +81 -0
- package/dist/templates/city-courier/src/scene.ts +17 -0
- package/dist/templates/city-courier/src/vite-env.d.ts +1 -0
- package/dist/templates/city-courier/src/worker.ts +5 -0
- package/dist/templates/city-courier/test/headless.test.ts +95 -0
- package/dist/templates/city-courier/test/playthrough.test.js +52 -0
- package/dist/templates/city-courier/test/replay.test.ts +22 -0
- package/dist/templates/city-courier/tsconfig.json +17 -0
- package/dist/templates/city-courier/vite.config.ts +19 -0
- package/dist/templates/cubes/README.md +51 -0
- package/dist/templates/cubes/index.html +16 -0
- package/dist/templates/cubes/package.json +24 -0
- package/dist/templates/cubes/scene.json +15 -0
- package/dist/templates/cubes/src/cubes.ts +100 -0
- package/dist/templates/cubes/src/main.ts +21 -0
- package/dist/templates/cubes/src/worker.ts +15 -0
- package/dist/templates/cubes/test/headless.test.ts +98 -0
- package/dist/templates/cubes/tsconfig.json +17 -0
- package/dist/templates/cubes/vite.config.ts +17 -0
- package/dist/templates/data-viz/README.md +47 -0
- package/dist/templates/data-viz/camera-track.json +12 -0
- package/dist/templates/data-viz/data.json +9 -0
- package/dist/templates/data-viz/index.html +16 -0
- package/dist/templates/data-viz/package.json +25 -0
- package/dist/templates/data-viz/scene.json +7 -0
- package/dist/templates/data-viz/src/main.ts +39 -0
- package/dist/templates/data-viz/src/viz.ts +91 -0
- package/dist/templates/data-viz/src/worker.ts +12 -0
- package/dist/templates/data-viz/test/headless.test.ts +75 -0
- package/dist/templates/data-viz/tsconfig.json +17 -0
- package/dist/templates/data-viz/vite.config.ts +16 -0
- package/dist/templates/figures-gallery/README.md +46 -0
- package/dist/templates/figures-gallery/index.html +16 -0
- package/dist/templates/figures-gallery/package.json +25 -0
- package/dist/templates/figures-gallery/scene.json +276 -0
- package/dist/templates/figures-gallery/src/main.ts +44 -0
- package/dist/templates/figures-gallery/src/worker.ts +17 -0
- package/dist/templates/figures-gallery/test/headless.test.ts +90 -0
- package/dist/templates/figures-gallery/tsconfig.json +17 -0
- package/dist/templates/figures-gallery/vite.config.ts +17 -0
- package/dist/templates/index.json +188 -0
- package/dist/templates/skybound/README.md +53 -0
- package/dist/templates/skybound/checks.json +24 -0
- package/dist/templates/skybound/commands.json +32 -0
- package/dist/templates/skybound/first-leap.replay.json +224 -0
- package/dist/templates/skybound/gen/molen-types.ts +878 -0
- package/dist/templates/skybound/index.html +2 -0
- package/dist/templates/skybound/package.json +25 -0
- package/dist/templates/skybound/project.json +8 -0
- package/dist/templates/skybound/scene.json +1737 -0
- package/dist/templates/skybound/scripts/game.ts +119 -0
- package/dist/templates/skybound/scripts/molen-scripts.d.ts +1125 -0
- package/dist/templates/skybound/scripts/tsconfig.json +16 -0
- package/dist/templates/skybound/src/game-shell.css +309 -0
- package/dist/templates/skybound/src/main.ts +60 -0
- package/dist/templates/skybound/src/scene.ts +17 -0
- package/dist/templates/skybound/src/vite-env.d.ts +1 -0
- package/dist/templates/skybound/src/worker.ts +5 -0
- package/dist/templates/skybound/test/headless.test.ts +124 -0
- package/dist/templates/skybound/test/playthrough.test.js +38 -0
- package/dist/templates/skybound/test/replay.test.ts +22 -0
- package/dist/templates/skybound/tsconfig.json +17 -0
- package/dist/templates/skybound/vite.config.ts +19 -0
- package/dist/templates/terrain-flyover/README.md +46 -0
- package/dist/templates/terrain-flyover/index.html +16 -0
- package/dist/templates/terrain-flyover/package.json +26 -0
- package/dist/templates/terrain-flyover/src/flyover.ts +23 -0
- package/dist/templates/terrain-flyover/src/main.ts +93 -0
- package/dist/templates/terrain-flyover/terrain.json +15 -0
- package/dist/templates/terrain-flyover/test/headless.test.ts +72 -0
- package/dist/templates/terrain-flyover/tsconfig.json +17 -0
- package/dist/templates/terrain-flyover/vite.config.ts +15 -0
- package/dist/templates/top-down-arena/README.md +52 -0
- package/dist/templates/top-down-arena/arena-skirmish.replay.json +204 -0
- package/dist/templates/top-down-arena/index.html +16 -0
- package/dist/templates/top-down-arena/package.json +25 -0
- package/dist/templates/top-down-arena/project.json +10 -0
- package/dist/templates/top-down-arena/scene.json +162 -0
- package/dist/templates/top-down-arena/scripts/chase.ts +17 -0
- package/dist/templates/top-down-arena/scripts/combat.ts +12 -0
- package/dist/templates/top-down-arena/scripts/control.ts +8 -0
- package/dist/templates/top-down-arena/scripts/molen-scripts.d.ts +1095 -0
- package/dist/templates/top-down-arena/scripts/spawner.ts +11 -0
- package/dist/templates/top-down-arena/scripts/tsconfig.json +16 -0
- package/dist/templates/top-down-arena/src/arena.ts +8 -0
- package/dist/templates/top-down-arena/src/gen/molen-types.ts +882 -0
- package/dist/templates/top-down-arena/src/main.ts +31 -0
- package/dist/templates/top-down-arena/src/scene.ts +24 -0
- package/dist/templates/top-down-arena/src/vite-env.d.ts +1 -0
- package/dist/templates/top-down-arena/src/worker.ts +7 -0
- package/dist/templates/top-down-arena/test/headless.test.ts +87 -0
- package/dist/templates/top-down-arena/test/replay.test.ts +22 -0
- package/dist/templates/top-down-arena/tsconfig.json +17 -0
- package/dist/templates/top-down-arena/types/arena.types.json +54 -0
- package/dist/templates/top-down-arena/vite.config.ts +21 -0
- package/package.json +14 -14
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type CameraTrackDoc,
|
|
3
|
+
evaluateCameraTrack,
|
|
4
|
+
registerCameraTrackSchema,
|
|
5
|
+
} from '@bendyline/molen-client/camera-track';
|
|
6
|
+
import { buildWorld, defineComponent, type World } from '@bendyline/molen-kernel';
|
|
7
|
+
import { runHeadless } from '@bendyline/molen-kernel/testing';
|
|
8
|
+
import { validate, validateByKind } from '@bendyline/molen-schema';
|
|
9
|
+
import { describe, expect, it } from 'vitest';
|
|
10
|
+
import trackDoc from '../camera-track.json';
|
|
11
|
+
import sceneDoc from '../scene.json';
|
|
12
|
+
import { DATA, setup } from '../src/viz';
|
|
13
|
+
|
|
14
|
+
registerCameraTrackSchema();
|
|
15
|
+
|
|
16
|
+
const Bar = defineComponent<{ target: number; t: number }>('bar');
|
|
17
|
+
const Transform = defineComponent<{
|
|
18
|
+
pos: [number, number, number];
|
|
19
|
+
scale?: [number, number, number];
|
|
20
|
+
}>('transform');
|
|
21
|
+
|
|
22
|
+
function build(): World {
|
|
23
|
+
const r = validate('scene', sceneDoc);
|
|
24
|
+
if (!r.ok) throw new Error(r.formatted);
|
|
25
|
+
return buildWorld(r.value, setup);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe('data-viz (headless)', () => {
|
|
29
|
+
it('binds the dataset to one bar per datum', () => {
|
|
30
|
+
const w = build();
|
|
31
|
+
expect(w.query(Bar).count()).toBe(DATA.length);
|
|
32
|
+
expect(w.exists('bar-0')).toBe(true);
|
|
33
|
+
expect(w.get('bar-3', Bar)?.target).toBe(DATA[3]?.value);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('bars grow from the ground over time', () => {
|
|
37
|
+
const w = build();
|
|
38
|
+
const startH = w.get('bar-5', Transform)?.scale?.[1] ?? 0;
|
|
39
|
+
w.stepN(40);
|
|
40
|
+
const grownH = w.get('bar-5', Transform)?.scale?.[1] ?? 0;
|
|
41
|
+
expect(grownH).toBeGreaterThan(startH);
|
|
42
|
+
// reaches its target height (value * heightScale) once the animation completes
|
|
43
|
+
expect(grownH).toBeCloseTo((DATA[5]?.value ?? 0) * 0.9, 1);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('bar height encodes the data value (taller = bigger)', () => {
|
|
47
|
+
const w = build();
|
|
48
|
+
w.stepN(60);
|
|
49
|
+
const hJun = w.get('bar-5', Transform)?.scale?.[1] ?? 0; // value 11 (max)
|
|
50
|
+
const hJan = w.get('bar-0', Transform)?.scale?.[1] ?? 0; // value 4
|
|
51
|
+
expect(hJun).toBeGreaterThan(hJan);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Pinned: run-to-run equality cannot notice a databinding or easing change that moves both.
|
|
55
|
+
it('matches the pinned state hash across engine versions', () => {
|
|
56
|
+
expect(runHeadless(build, { ticks: 60 }).finalHash).toBe(
|
|
57
|
+
'sha256:e0c4277d900fd86e892894c77a31cae5fbb0898140f72794de2294f14da58e30',
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('is deterministic', () => {
|
|
62
|
+
const a = runHeadless(build, { ticks: 60 });
|
|
63
|
+
const b = runHeadless(build, { ticks: 60 });
|
|
64
|
+
expect(a.finalHash).toBe(b.finalHash);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('the camera track validates and orbits the chart', () => {
|
|
68
|
+
const r = validateByKind('cameratrack', trackDoc);
|
|
69
|
+
expect(r.ok).toBe(true);
|
|
70
|
+
const track = trackDoc as CameraTrackDoc;
|
|
71
|
+
const p0 = evaluateCameraTrack(track, 0).position;
|
|
72
|
+
const p60 = evaluateCameraTrack(track, 60).position;
|
|
73
|
+
expect(p0).not.toEqual(p60); // camera moved
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"lib": ["ES2023", "DOM", "DOM.Iterable", "WebWorker"],
|
|
7
|
+
"types": [],
|
|
8
|
+
"strict": true,
|
|
9
|
+
"noUncheckedIndexedAccess": true,
|
|
10
|
+
"verbatimModuleSyntax": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
"noEmit": true,
|
|
14
|
+
"resolveJsonModule": true
|
|
15
|
+
},
|
|
16
|
+
"include": ["src", "test"]
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
// Relative asset URLs, so one production build plays from any directory (molen.dev/play hosts
|
|
5
|
+
// the samples beneath subdirectories).
|
|
6
|
+
base: './',
|
|
7
|
+
worker: { format: 'es' },
|
|
8
|
+
build: {
|
|
9
|
+
target: 'es2022',
|
|
10
|
+
// main.ts mounts with a top-level `await`, and the client lazy-loads its WebGPU driver. By
|
|
11
|
+
// default Rollup puts three.js and the client in the entry chunk, so the lazy chunk imports
|
|
12
|
+
// the entry while the entry is still suspended at that `await`: the import never settles and
|
|
13
|
+
// the page stays blank in every browser with a WebGPU adapter. Their own chunk breaks the cycle.
|
|
14
|
+
rollupOptions: { output: { manualChunks: { vendor: ['three', '@bendyline/molen-client'] } } },
|
|
15
|
+
},
|
|
16
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Figures gallery
|
|
2
|
+
|
|
3
|
+
Every shipped figure preset rendered side by side: three human ages, six quadrupeds, a rider seated on a horse, a hat on a head socket, a pack on a back socket, and a five-step body-type sweep. Seventeen figures, all as scene data. This is the reference for the figures capability — descriptors, canonical rigs, sockets and attachments, and the deterministic gaits.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
## Run
|
|
8
|
+
|
|
9
|
+
Play it in the browser at [molen.dev/play/figures-gallery](https://molen.dev/play/figures-gallery/). To run and change
|
|
10
|
+
your own copy, make one from the npm packages (no clone of the engine repository needed):
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npx @bendyline/molen-tooling new my-figures-gallery --template figures-gallery
|
|
14
|
+
cd my-figures-gallery
|
|
15
|
+
npm install
|
|
16
|
+
npm run dev
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
1: idle (clears the override). 2: walk in place. 3: run in place. `?walk=1` or `?run=1` sets the gait on load. The keys are the scene's own bindings (`Digit1`/`Digit2`/`Digit3` emitting `gait_idle`/`gait_walk`/`gait_run`); `set_gait` with `{ mode }` does the same from a test or the CLI.
|
|
20
|
+
|
|
21
|
+
## Authoring map
|
|
22
|
+
|
|
23
|
+
- `scene.json`: the entire gallery. The `figure` prefab, seventeen figure entities, an `environment` entity (hemisphere ambient plus a shadow-casting sun), the socketed hat and pack (`figureAttachment` + `parent`), the `mountable` horse with its `mounted` rider, the four gait commands with a payload schema on `set_gait`, and one inline `gaits` script that sets or removes `figureIntent` on every unmounted figure.
|
|
24
|
+
- `src/worker.ts`: the only capability wiring in the sample — `installFigures(world)` plus `figuresScriptApi` passed to `buildWorld` as a capability, so scripts can reach it.
|
|
25
|
+
- `src/main.ts`: `mountExperience` with `kinds: [figureKind()]`, the client half of the capability, and the `?walk=` / `?run=` query params.
|
|
26
|
+
|
|
27
|
+
Bodies are authored, not modelled: `height`, `build`, `features` (`hair`, `sleeves`) and `palette` overrides on a figure component reshape a preset in place — that is what the `sweep-*` row and the `slim` / `heavy` pair demonstrate. `npx molen figure presets` lists the nine presets that ship, and `npx molen figure preview` renders them without a scene.
|
|
28
|
+
|
|
29
|
+
## Verify
|
|
30
|
+
|
|
31
|
+
From this directory:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
npx molen validate scene.json
|
|
35
|
+
npx molen sim run scene.json --ticks 240 --hash
|
|
36
|
+
npx molen shot scene.json --ticks 45 --camera 0,4.6,9.4 --look 0,1,0.9 --out figures.png
|
|
37
|
+
npm test
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`test/headless.test.ts` is the only test file. It pins the **state hash** at 240 ticks — the same hash `sim run --hash` prints, so a rig, gait or pose-evaluation change has to be an intentional edit there — and adds run-to-run equality plus two `molen/assert@1` scenarios: every one of the seventeen figures gets a `figureState`, the rider's mode is `sit`, both attachments resolved to a `localTransform`, no `figures-error` event ever fires, and a `set_gait` walk-then-run sequence lands as `run` with `prevMode` `walk` before returning to idle.
|
|
41
|
+
|
|
42
|
+
No golden image and no replay fixture. The bodies are generated procedurally on the client, so the regression that matters lives in kernel state, not in pixels.
|
|
43
|
+
|
|
44
|
+
In the engine repository this sample lives in `examples/figures-gallery/`. The same commands run from
|
|
45
|
+
that directory, and `pnpm --filter @bendyline/molen-examples-figures-gallery test:unit` runs its tests from the
|
|
46
|
+
root.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>molen - figures gallery</title>
|
|
7
|
+
<style>
|
|
8
|
+
html, body { margin: 0; height: 100%; overflow: hidden; background: #1b2130; }
|
|
9
|
+
#view { display: block; width: 100vw; height: 100vh; }
|
|
10
|
+
</style>
|
|
11
|
+
</head>
|
|
12
|
+
<body>
|
|
13
|
+
<canvas id="view"></canvas>
|
|
14
|
+
<script type="module" src="/src/main.ts"></script>
|
|
15
|
+
</body>
|
|
16
|
+
</html>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"private": true,
|
|
3
|
+
"type": "module",
|
|
4
|
+
"scripts": {
|
|
5
|
+
"dev": "vite --port 5225",
|
|
6
|
+
"build": "vite build",
|
|
7
|
+
"preview": "vite preview",
|
|
8
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
9
|
+
"test": "vitest run"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@bendyline/molen-client": "workspace:*",
|
|
13
|
+
"@bendyline/molen-figures": "workspace:*",
|
|
14
|
+
"@bendyline/molen-kernel": "workspace:*",
|
|
15
|
+
"@bendyline/molen-schema": "workspace:*",
|
|
16
|
+
"three": "0.184.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@bendyline/molen-tooling": "workspace:*",
|
|
20
|
+
"@types/three": "0.184.0",
|
|
21
|
+
"typescript": "^6.0.3",
|
|
22
|
+
"vite": "^6.4.0",
|
|
23
|
+
"vitest": "^5.0.1"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
{
|
|
2
|
+
"format": "molen/scene@3",
|
|
3
|
+
"name": "figures-gallery",
|
|
4
|
+
"seed": "figures-gallery",
|
|
5
|
+
"tickRate": 60,
|
|
6
|
+
"keyframeInterval": 120,
|
|
7
|
+
"camera": { "mode": "fixed", "position": [0, 3.4, 15], "lookAt": [0, 0.9, 0] },
|
|
8
|
+
"input": {
|
|
9
|
+
"bindings": { "Digit1": "idle", "Digit2": "walk", "Digit3": "run" },
|
|
10
|
+
"emit": [
|
|
11
|
+
{ "kind": "press", "action": "idle", "command": "gait_idle" },
|
|
12
|
+
{ "kind": "press", "action": "walk", "command": "gait_walk" },
|
|
13
|
+
{ "kind": "press", "action": "run", "command": "gait_run" }
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
"commands": {
|
|
17
|
+
"set_gait": {
|
|
18
|
+
"doc": "Force every standing figure into a gait (idle clears the override).",
|
|
19
|
+
"payload": {
|
|
20
|
+
"type": "object",
|
|
21
|
+
"properties": { "mode": { "type": "string", "enum": ["idle", "walk", "run"] } },
|
|
22
|
+
"required": ["mode"],
|
|
23
|
+
"additionalProperties": false
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"gait_idle": { "doc": "Clear the forced gait (key 1)." },
|
|
27
|
+
"gait_walk": { "doc": "Walk in place (key 2)." },
|
|
28
|
+
"gait_run": { "doc": "Run in place (key 3)." }
|
|
29
|
+
},
|
|
30
|
+
"scripts": [
|
|
31
|
+
{
|
|
32
|
+
"id": "gaits",
|
|
33
|
+
"code": "function apply(mode) { for (const id of molen.query('figure').without('mounted').ids()) { if (mode === 'idle') { if (molen.has(id, 'figureIntent')) molen.remove(id, 'figureIntent'); } else { molen.set(id, 'figureIntent', { mode }); } } }\nmolen.onCommand('set_gait', (p) => apply(p.mode));\nmolen.onCommand('gait_idle', () => apply('idle'));\nmolen.onCommand('gait_walk', () => apply('walk'));\nmolen.onCommand('gait_run', () => apply('run'));"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"prefabs": {
|
|
37
|
+
"figure": {
|
|
38
|
+
"components": {
|
|
39
|
+
"transform": { "pos": [0, 0, 0], "rot": [0, 0, 0, 1] },
|
|
40
|
+
"renderable": {
|
|
41
|
+
"kind": "figure",
|
|
42
|
+
"ref": "procedural",
|
|
43
|
+
"shadows": { "cast": true, "receive": true }
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"entities": [
|
|
49
|
+
{
|
|
50
|
+
"id": "sky",
|
|
51
|
+
"components": {
|
|
52
|
+
"environment": {
|
|
53
|
+
"ambient": { "sky": "#dfe7ff", "ground": "#4a5240", "intensity": 1.0 },
|
|
54
|
+
"sun": {
|
|
55
|
+
"direction": [6, 12, 5],
|
|
56
|
+
"color": "#fff4e0",
|
|
57
|
+
"intensity": 1.6,
|
|
58
|
+
"castShadow": true
|
|
59
|
+
},
|
|
60
|
+
"shadows": "medium"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"id": "ground",
|
|
66
|
+
"components": {
|
|
67
|
+
"transform": { "pos": [0, -0.05, 0], "rot": [0, 0, 0, 1] },
|
|
68
|
+
"renderable": {
|
|
69
|
+
"kind": "primitive",
|
|
70
|
+
"ref": "box",
|
|
71
|
+
"materialRef": "palette:#6b7f5a",
|
|
72
|
+
"primitive": { "size": [30, 0.1, 18] },
|
|
73
|
+
"shadows": { "receive": true }
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
{
|
|
79
|
+
"id": "child",
|
|
80
|
+
"prefab": "figure",
|
|
81
|
+
"components": {
|
|
82
|
+
"transform": { "pos": [-6.5, 0, 1.5] },
|
|
83
|
+
"figure": { "preset": "human.child" }
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"id": "adult",
|
|
88
|
+
"prefab": "figure",
|
|
89
|
+
"components": {
|
|
90
|
+
"transform": { "pos": [-4.6, 0, 1.5] },
|
|
91
|
+
"figure": { "preset": "human.adult" }
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"id": "adult-hat",
|
|
96
|
+
"components": {
|
|
97
|
+
"transform": { "pos": [0, 0, 0], "rot": [0, 0, 0, 1] },
|
|
98
|
+
"renderable": {
|
|
99
|
+
"kind": "primitive",
|
|
100
|
+
"ref": "cylinder",
|
|
101
|
+
"materialRef": "palette:#39747d",
|
|
102
|
+
"primitive": { "size": [0.32, 0.12, 0.32] },
|
|
103
|
+
"shadows": { "cast": true }
|
|
104
|
+
},
|
|
105
|
+
"parent": { "id": "adult" },
|
|
106
|
+
"figureAttachment": { "socket": "head.top", "offset": { "pos": [0, 0.06, 0] } }
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"id": "slim",
|
|
111
|
+
"prefab": "figure",
|
|
112
|
+
"components": {
|
|
113
|
+
"transform": { "pos": [-2.8, 0, 1.5] },
|
|
114
|
+
"figure": {
|
|
115
|
+
"preset": "human.adult",
|
|
116
|
+
"height": 1.62,
|
|
117
|
+
"build": -0.6,
|
|
118
|
+
"features": { "hair": "long" },
|
|
119
|
+
"palette": { "top": "#8c3b5a", "bottom": "#2b2b33", "hair": "#e6c27a" }
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"id": "heavy",
|
|
125
|
+
"prefab": "figure",
|
|
126
|
+
"components": {
|
|
127
|
+
"transform": { "pos": [-1.0, 0, 1.5] },
|
|
128
|
+
"figure": {
|
|
129
|
+
"preset": "human.adult",
|
|
130
|
+
"height": 1.88,
|
|
131
|
+
"build": 0.8,
|
|
132
|
+
"features": { "hair": "none", "sleeves": "short" },
|
|
133
|
+
"palette": { "top": "#2f5f3a", "bottom": "#4b4b52", "skin": "#8d5a3c" }
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"id": "heavy-pack",
|
|
139
|
+
"components": {
|
|
140
|
+
"transform": { "pos": [0, 0, 0], "rot": [0, 0, 0, 1] },
|
|
141
|
+
"renderable": {
|
|
142
|
+
"kind": "primitive",
|
|
143
|
+
"ref": "box",
|
|
144
|
+
"materialRef": "palette:#7a4a2a",
|
|
145
|
+
"primitive": { "size": [0.34, 0.42, 0.18] },
|
|
146
|
+
"shadows": { "cast": true }
|
|
147
|
+
},
|
|
148
|
+
"parent": { "id": "heavy" },
|
|
149
|
+
"figureAttachment": { "socket": "back", "offset": { "pos": [0, 0, 0.11] } }
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
"id": "elder",
|
|
154
|
+
"prefab": "figure",
|
|
155
|
+
"components": { "transform": { "pos": [0.8, 0, 1.5] }, "figure": { "preset": "human.elder" } }
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"id": "dog",
|
|
159
|
+
"prefab": "figure",
|
|
160
|
+
"components": { "transform": { "pos": [2.6, 0, 1.5] }, "figure": { "preset": "dog" } }
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"id": "cat",
|
|
164
|
+
"prefab": "figure",
|
|
165
|
+
"components": { "transform": { "pos": [4.0, 0, 1.5] }, "figure": { "preset": "cat" } }
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
"id": "sheep",
|
|
169
|
+
"prefab": "figure",
|
|
170
|
+
"components": { "transform": { "pos": [5.6, 0, 1.5] }, "figure": { "preset": "sheep" } }
|
|
171
|
+
},
|
|
172
|
+
|
|
173
|
+
{
|
|
174
|
+
"id": "horse",
|
|
175
|
+
"prefab": "figure",
|
|
176
|
+
"components": {
|
|
177
|
+
"transform": { "pos": [-4.5, 0, -2.5] },
|
|
178
|
+
"figure": { "preset": "horse" },
|
|
179
|
+
"mountable": {
|
|
180
|
+
"seats": [{ "id": "saddle", "role": "passenger", "position": [0, 1.45, 0] }],
|
|
181
|
+
"exits": [[1.3, 0, 0], [-1.3, 0, 0], [0, 0, -1.8]],
|
|
182
|
+
"reach": 2.5
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
"id": "rider",
|
|
188
|
+
"prefab": "figure",
|
|
189
|
+
"components": {
|
|
190
|
+
"transform": { "pos": [-4.5, 1.45, -2.5] },
|
|
191
|
+
"figure": {
|
|
192
|
+
"preset": "human.adult",
|
|
193
|
+
"height": 1.7,
|
|
194
|
+
"palette": { "top": "#b3332c", "bottom": "#2b2b33" }
|
|
195
|
+
},
|
|
196
|
+
"mounted": { "vehicle": "horse", "seat": "saddle" }
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
"id": "deer",
|
|
201
|
+
"prefab": "figure",
|
|
202
|
+
"components": { "transform": { "pos": [-1.0, 0, -2.5] }, "figure": { "preset": "deer" } }
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
"id": "cow",
|
|
206
|
+
"prefab": "figure",
|
|
207
|
+
"components": { "transform": { "pos": [2.2, 0, -2.5] }, "figure": { "preset": "cow" } }
|
|
208
|
+
},
|
|
209
|
+
|
|
210
|
+
{
|
|
211
|
+
"id": "sweep-0",
|
|
212
|
+
"prefab": "figure",
|
|
213
|
+
"components": {
|
|
214
|
+
"transform": { "pos": [-4.0, 0, 4.8] },
|
|
215
|
+
"figure": {
|
|
216
|
+
"preset": "human.adult",
|
|
217
|
+
"height": 1.55,
|
|
218
|
+
"build": -0.8,
|
|
219
|
+
"palette": { "top": "#4d6d9a" }
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
"id": "sweep-1",
|
|
225
|
+
"prefab": "figure",
|
|
226
|
+
"components": {
|
|
227
|
+
"transform": { "pos": [-2.0, 0, 4.8] },
|
|
228
|
+
"figure": {
|
|
229
|
+
"preset": "human.adult",
|
|
230
|
+
"height": 1.65,
|
|
231
|
+
"build": -0.4,
|
|
232
|
+
"palette": { "top": "#5d8a6a" }
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
"id": "sweep-2",
|
|
238
|
+
"prefab": "figure",
|
|
239
|
+
"components": {
|
|
240
|
+
"transform": { "pos": [0.0, 0, 4.8] },
|
|
241
|
+
"figure": {
|
|
242
|
+
"preset": "human.adult",
|
|
243
|
+
"height": 1.75,
|
|
244
|
+
"build": 0,
|
|
245
|
+
"palette": { "top": "#a8783c" }
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
"id": "sweep-3",
|
|
251
|
+
"prefab": "figure",
|
|
252
|
+
"components": {
|
|
253
|
+
"transform": { "pos": [2.0, 0, 4.8] },
|
|
254
|
+
"figure": {
|
|
255
|
+
"preset": "human.adult",
|
|
256
|
+
"height": 1.82,
|
|
257
|
+
"build": 0.4,
|
|
258
|
+
"palette": { "top": "#8c3b5a" }
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
"id": "sweep-4",
|
|
264
|
+
"prefab": "figure",
|
|
265
|
+
"components": {
|
|
266
|
+
"transform": { "pos": [4.0, 0, 4.8] },
|
|
267
|
+
"figure": {
|
|
268
|
+
"preset": "human.adult",
|
|
269
|
+
"height": 1.9,
|
|
270
|
+
"build": 0.8,
|
|
271
|
+
"palette": { "top": "#4b4b52" }
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
]
|
|
276
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { mountExperience } from '@bendyline/molen-client';
|
|
2
|
+
import { figureKind } from '@bendyline/molen-figures/client';
|
|
3
|
+
import { validate } from '@bendyline/molen-schema';
|
|
4
|
+
import sceneDoc from '../scene.json';
|
|
5
|
+
|
|
6
|
+
// Browser entry: the kernel runs in a Worker (worker.ts); this side mounts the client with the
|
|
7
|
+
// figure renderable kind. Keys 1/2/3 (or ?walk=1 / ?run=1) send the scene's `set_gait` command.
|
|
8
|
+
const scene = validate('scene', sceneDoc);
|
|
9
|
+
if (!scene.ok) throw new Error(scene.formatted);
|
|
10
|
+
|
|
11
|
+
const canvas = document.getElementById('view') as HTMLCanvasElement;
|
|
12
|
+
const worker = new Worker(new URL('./worker.ts', import.meta.url), { type: 'module' });
|
|
13
|
+
|
|
14
|
+
const { client } = await mountExperience({
|
|
15
|
+
link: worker,
|
|
16
|
+
scene: scene.value,
|
|
17
|
+
canvas,
|
|
18
|
+
clearColor: '#1b2130',
|
|
19
|
+
kinds: [figureKind()],
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Status for headless checks: the kernel tick, the mirrored entity count, and asset readiness.
|
|
23
|
+
const status = setInterval(() => {
|
|
24
|
+
if (client.tick === undefined) return;
|
|
25
|
+
canvas.dataset.tick = String(client.tick);
|
|
26
|
+
canvas.dataset.entities = String(client.entities().length);
|
|
27
|
+
}, 100);
|
|
28
|
+
void client.ready().then(() => {
|
|
29
|
+
canvas.dataset.ready = 'true';
|
|
30
|
+
});
|
|
31
|
+
window.addEventListener('beforeunload', () => clearInterval(status));
|
|
32
|
+
|
|
33
|
+
const params = new URLSearchParams(location.search);
|
|
34
|
+
const initial = params.get('run') === '1' ? 'run' : params.get('walk') === '1' ? 'walk' : undefined;
|
|
35
|
+
if (initial !== undefined) {
|
|
36
|
+
// The first keyframe lands asynchronously; the command is queued for the next tick.
|
|
37
|
+
setTimeout(() => client.command('set_gait', { mode: initial }), 300);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const hint = document.createElement('div');
|
|
41
|
+
hint.textContent = 'press 1 (idle), 2 (walk) or 3 (run)';
|
|
42
|
+
hint.style.cssText =
|
|
43
|
+
'position:fixed;left:12px;bottom:10px;font:13px system-ui;color:#9aa;pointer-events:none';
|
|
44
|
+
document.body.appendChild(hint);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference lib="webworker" />
|
|
2
|
+
import { figuresScriptApi, installFigures } from '@bendyline/molen-figures/kernel';
|
|
3
|
+
import { buildWorld, KernelHost } from '@bendyline/molen-kernel';
|
|
4
|
+
import { type MessageLink, validate } from '@bendyline/molen-schema';
|
|
5
|
+
import sceneDoc from '../scene.json';
|
|
6
|
+
|
|
7
|
+
// The Worker entry: the scene is pure data (figures, a hat, a rider, one script), so the only
|
|
8
|
+
// code here installs the figures capability and hosts the world.
|
|
9
|
+
const scene = validate('scene', sceneDoc);
|
|
10
|
+
if (!scene.ok) throw new Error(scene.formatted);
|
|
11
|
+
|
|
12
|
+
const world = buildWorld(scene.value, undefined, {
|
|
13
|
+
capabilities: [(w) => ({ figures: figuresScriptApi(installFigures(w)) })],
|
|
14
|
+
});
|
|
15
|
+
new KernelHost(world, self as unknown as MessageLink, {
|
|
16
|
+
keyframeInterval: scene.value.keyframeInterval,
|
|
17
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { Command, SceneManifest } from '@bendyline/molen-schema';
|
|
2
|
+
import { validate } from '@bendyline/molen-schema';
|
|
3
|
+
import { runSimulation } from '@bendyline/molen-tooling';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
import sceneDoc from '../scene.json';
|
|
6
|
+
|
|
7
|
+
function scene(): SceneManifest {
|
|
8
|
+
const r = validate('scene', sceneDoc);
|
|
9
|
+
if (!r.ok) throw new Error(r.formatted);
|
|
10
|
+
return r.value;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const FIGURES = 17;
|
|
14
|
+
|
|
15
|
+
function gait(mode: 'idle' | 'walk' | 'run', tick: number, seq = 0): Command {
|
|
16
|
+
return {
|
|
17
|
+
kind: 'command',
|
|
18
|
+
seq,
|
|
19
|
+
source: 'local',
|
|
20
|
+
tick,
|
|
21
|
+
tickExecuted: tick,
|
|
22
|
+
type: 'set_gait',
|
|
23
|
+
payload: { mode },
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
describe('figures gallery headless', () => {
|
|
28
|
+
// Pinned, so a rig, gait or pose-evaluation change has to be an intentional edit here.
|
|
29
|
+
it('matches the pinned state hash across engine versions', async () => {
|
|
30
|
+
const r = await runSimulation({ scene: scene(), ticks: 240 });
|
|
31
|
+
expect(r.stateHash).toBe(
|
|
32
|
+
'sha256:f2565a0cba6e85f16c44ec40a5dbede0c6d7cd4ef704174854a81c69a05f4ab2',
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('runs 240 ticks deterministically (identical hash across runs)', async () => {
|
|
37
|
+
const a = await runSimulation({ scene: scene(), ticks: 240 });
|
|
38
|
+
const b = await runSimulation({ scene: scene(), ticks: 240 });
|
|
39
|
+
expect(a.tick).toBe(240);
|
|
40
|
+
expect(a.stateHash).toBe(b.stateHash);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('gives every figure a locomotion state, seats the rider, and resolves every socket', async () => {
|
|
44
|
+
const r = await runSimulation({
|
|
45
|
+
scene: scene(),
|
|
46
|
+
ticks: 30,
|
|
47
|
+
assertDoc: {
|
|
48
|
+
format: 'molen/assert@1',
|
|
49
|
+
assertions: [
|
|
50
|
+
{ select: 'has:figure', op: 'count', value: FIGURES },
|
|
51
|
+
{ select: 'has:figureState', op: 'count', value: FIGURES },
|
|
52
|
+
{ select: '#rider .figureState.mode', op: 'eq', value: 'sit' },
|
|
53
|
+
{ select: '#adult .figureState.mode', op: 'eq', value: 'idle' },
|
|
54
|
+
{ select: '#adult-hat .localTransform', op: 'exists' },
|
|
55
|
+
{ select: '#heavy-pack .localTransform', op: 'exists' },
|
|
56
|
+
{ event: 'figures-error', op: 'never' },
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
expect(r.ok, r.assertionsFormatted ?? r.error).toBe(true);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('walks and runs in place on the set_gait command and returns to idle', async () => {
|
|
64
|
+
const r = await runSimulation({
|
|
65
|
+
scene: scene(),
|
|
66
|
+
ticks: 90,
|
|
67
|
+
commands: [gait('walk', 5, 0), gait('run', 40, 1)],
|
|
68
|
+
assertDoc: {
|
|
69
|
+
format: 'molen/assert@1',
|
|
70
|
+
assertions: [
|
|
71
|
+
{ select: '#adult .figureState.mode', op: 'eq', value: 'run' },
|
|
72
|
+
{ select: '#adult .figureState.prevMode', op: 'eq', value: 'walk' },
|
|
73
|
+
{ select: '#horse .figureState.mode', op: 'eq', value: 'run' },
|
|
74
|
+
{ select: '#rider .figureState.mode', op: 'eq', value: 'sit' },
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
expect(r.ok, r.assertionsFormatted ?? r.error).toBe(true);
|
|
79
|
+
const back = await runSimulation({
|
|
80
|
+
scene: scene(),
|
|
81
|
+
ticks: 60,
|
|
82
|
+
commands: [gait('walk', 5, 0), gait('idle', 30, 1)],
|
|
83
|
+
assertDoc: {
|
|
84
|
+
format: 'molen/assert@1',
|
|
85
|
+
assertions: [{ select: '#adult .figureState.mode', op: 'eq', value: 'idle' }],
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
expect(back.ok, back.assertionsFormatted ?? back.error).toBe(true);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"lib": ["ES2023", "DOM", "DOM.Iterable", "WebWorker"],
|
|
7
|
+
"types": [],
|
|
8
|
+
"strict": true,
|
|
9
|
+
"noUncheckedIndexedAccess": true,
|
|
10
|
+
"verbatimModuleSyntax": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
"noEmit": true,
|
|
14
|
+
"resolveJsonModule": true
|
|
15
|
+
},
|
|
16
|
+
"include": ["src", "test"]
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
// Relative asset URLs, so one production build plays from any directory (molen.dev/play hosts
|
|
5
|
+
// the samples beneath subdirectories).
|
|
6
|
+
base: './',
|
|
7
|
+
// The kernel Worker is an ES module, bundled like the page.
|
|
8
|
+
worker: { format: 'es' },
|
|
9
|
+
build: {
|
|
10
|
+
target: 'es2022',
|
|
11
|
+
// main.ts mounts with a top-level `await`, and the client lazy-loads its WebGPU driver. By
|
|
12
|
+
// default Rollup puts three.js and the client in the entry chunk, so the lazy chunk imports
|
|
13
|
+
// the entry while the entry is still suspended at that `await`: the import never settles and
|
|
14
|
+
// the page stays blank in every browser with a WebGPU adapter. Their own chunk breaks the cycle.
|
|
15
|
+
rollupOptions: { output: { manualChunks: { vendor: ['three', '@bendyline/molen-client'] } } },
|
|
16
|
+
},
|
|
17
|
+
});
|