@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,158 @@
|
|
|
1
|
+
# Recognizable places and mapped props
|
|
2
|
+
|
|
3
|
+
The Protomaps profile can decode the `pois` MVT layer into renderer-neutral `TerrainPoiFeature`
|
|
4
|
+
records. Include `"poi"` in a terrain package's `features.layers`; the bundled Sammamish package
|
|
5
|
+
does so. POI names, categories, details, IDs and optional enriched brand/measurement fields survive
|
|
6
|
+
decoding. Label `min_zoom` is not a semantic filter: useful points marked 16–18 already exist in
|
|
7
|
+
the archive's zoom-15 tiles.
|
|
8
|
+
|
|
9
|
+
## Identity library
|
|
10
|
+
|
|
11
|
+
The Earth catalog recognizes **44 mapped source businesses** by exact aliases and verified source
|
|
12
|
+
IDs. Each match selects a generic descriptor model rather than a source-business sign: for example,
|
|
13
|
+
Walmart maps to `sign.mart_store`, Taco Bell maps to `sign.taco_place`, Best Buy maps to
|
|
14
|
+
`sign.electronics_store`, and The Home Depot maps to `sign.hardware_store`. The
|
|
15
|
+
[retail catalog](../../content/earth/businesses/README.md) documents the
|
|
16
|
+
source data and mapping policy.
|
|
17
|
+
|
|
18
|
+
Nine generic treatments cover grocery, restaurant, cafe, pharmacy, shop, department store, shopping
|
|
19
|
+
mall, outlet center and strip mall. These also support unnamed points with known categories.
|
|
20
|
+
Unknown identities keep the normal architectural fallback. This is a stylized descriptor library,
|
|
21
|
+
not a complete global business database.
|
|
22
|
+
|
|
23
|
+
Matching lives in
|
|
24
|
+
[the Earth business catalog](../../content/earth/businesses/catalog.json).
|
|
25
|
+
A stable canonical ID selects an appearance; aliases and verified brand:wikidata IDs map source
|
|
26
|
+
records onto it. Explicit source IDs take precedence. An explicit conflicting ID blocks name-based
|
|
27
|
+
guesses. Name aliases must match exactly after punctuation/spacing normalization and pass category
|
|
28
|
+
checks. McDonald's Book Exchange remains a bookshop. Localized aliases can be added without
|
|
29
|
+
duplicating models.
|
|
30
|
+
|
|
31
|
+
The catalog's initial identifiers were verified against the
|
|
32
|
+
[OpenStreetMap Name Suggestion Index](https://github.com/osmlab/name-suggestion-index).
|
|
33
|
+
Names without explicit IDs are inferred matches; generic names can collide across countries, so
|
|
34
|
+
prefer source IDs and conservative alias additions.
|
|
35
|
+
|
|
36
|
+
At the finest detail level, using unmerged footprints (Protomaps zoom 15+), matching source IDs plus containment associate businesses with their
|
|
37
|
+
footprints; otherwise containment is used, including courtyard holes. No unbounded nearest-building
|
|
38
|
+
guess is made. Shared buildings retain independent storefronts, with stable nonoverlapping facade
|
|
39
|
+
bays. A directly identified supermarket can absorb its internal cafe/pharmacy signage. These are
|
|
40
|
+
conservative tenancy heuristics, not surveyed lease boundaries.
|
|
41
|
+
|
|
42
|
+
A single business directly identified by its footprint can color the whole shell. Containment-only
|
|
43
|
+
matches and shared tenants color only their own fascia,
|
|
44
|
+
canopy and entry accents. Existing residential/civic/tall-building styles and floor counts survive
|
|
45
|
+
when a shop is a ground-floor tenant. Measured footprints/heights remain authoritative. Frontage is estimated
|
|
46
|
+
from the POI and nearby access lines; exact entrance location, sign location and tenant width are
|
|
47
|
+
generally absent from the archive.
|
|
48
|
+
|
|
49
|
+
## External model manifests
|
|
50
|
+
|
|
51
|
+
The reusable definitions are JSON content, not package code. The landmarks ship in the
|
|
52
|
+
`molen.worldgen.default` content pack (role `landmarks`) and the business catalog in the
|
|
53
|
+
`molen.earth` pack (role `businesses`); their sources are in the repository's `content/`:
|
|
54
|
+
|
|
55
|
+
| What to edit | Source |
|
|
56
|
+
| --- | --- |
|
|
57
|
+
| Model index and file paths | [Landmark catalog](../../content/worldgen/landmarks/catalog.json) |
|
|
58
|
+
| Burger-restaurant descriptor, source-inspired palette and frontage | [burger_restaurant.landmark.json](../../content/worldgen/landmarks/burger_restaurant.landmark.json) |
|
|
59
|
+
| Unbranded grocery treatment | [grocery.landmark.json](../../content/worldgen/landmarks/grocery.landmark.json) |
|
|
60
|
+
| Store aliases, source IDs and category matching | [Business catalog](../../content/earth/businesses/catalog.json) |
|
|
61
|
+
| Lamp, bench, rack and charger geometry recipes | [Landmark library](../../content/worldgen/landmarks/README.md) |
|
|
62
|
+
| Base building proportions and architectural rules | [Generic store style](../../content/worldgen/styles/generic/store.archstyle.json) |
|
|
63
|
+
| Shared surface patterns | [Material library](../../content/worldgen/materials/README.md) |
|
|
64
|
+
|
|
65
|
+
A `molen/landmark@1` sign manifest contains its stable model ID, text, initial-based emblem, palette,
|
|
66
|
+
wall/accent appearance and default standalone/shared storefront widths. Its optional
|
|
67
|
+
`storefront.style` selects a preferred building envelope when the business directly identifies a
|
|
68
|
+
low-rise host and the active pack contains that style. Shared tenants cannot select host massing.
|
|
69
|
+
The seven additional styles distinguish big-box retail, warehouse clubs, restaurants, department
|
|
70
|
+
stores, enclosed malls, strip malls and outlet centers. Broad frontages raise and enlarge their
|
|
71
|
+
fascia to remain readable on taller shells; source heights and floor counts still win. The building
|
|
72
|
+
generator adapts that treatment to a measured footprint; this is not a fixed building mesh.
|
|
73
|
+
Mapped-business descriptors use `symbol: "letters"` with initials derived from their generic
|
|
74
|
+
titles. Source recognition stays in the Earth catalog; model-facing names and emblems stay generic.
|
|
75
|
+
Furniture uses `generator: "boxes"` with ordered
|
|
76
|
+
metric parts and optional detail tiers (0 near, 1 medium, 2 distant).
|
|
77
|
+
|
|
78
|
+
A host reads the documents from the packs and builds the libraries once, synchronously:
|
|
79
|
+
`createPlacesContent({ landmarks: { catalog, models }, businesses })` from
|
|
80
|
+
`@bendyline/molen-worldgen-earth/kernel` validates both and cross-checks every sign. Pass the
|
|
81
|
+
result as `places` to `semanticTileToBatch`, `createInThreadWorldgenGenerator` and
|
|
82
|
+
`createWorldgenSemanticRenderers`; a worker bridge takes the same content as plain documents, so
|
|
83
|
+
only data crosses the Worker boundary. Without `places`, mapped businesses are not recognized and
|
|
84
|
+
no street furniture is placed. Rendering cache keys include both content hashes, so palette and
|
|
85
|
+
recipe changes invalidate cached terrain render output.
|
|
86
|
+
|
|
87
|
+
Landmarks alone are `createLandmarkLibrary({ catalog, models })` from
|
|
88
|
+
`@bendyline/molen-worldgen/kernel`, or `resolveLandmarkCatalogDocuments(catalog, readDocument)` for
|
|
89
|
+
just the definitions; pass definitions to `generateLandmarkModel(id, definitions, tier)` or
|
|
90
|
+
`new ModelLibrary(assetLoader, definitions)`. A `ModelLibrary` without definitions serves no
|
|
91
|
+
landmark models. In the repository, edit the sources and rebuild the packs (the world explorer
|
|
92
|
+
does it before `dev`); editing is not runtime hot reload.
|
|
93
|
+
|
|
94
|
+
## Extending the library
|
|
95
|
+
|
|
96
|
+
1. Copy the nearest `.landmark.json`, assign a stable ID, and edit its parameters.
|
|
97
|
+
Add the ID and relative file path to the landmark catalog. Adding a design that uses an
|
|
98
|
+
existing generator needs no manual TypeScript registration.
|
|
99
|
+
2. For a new business identity, add its canonical ID, allowed source categories, exact aliases,
|
|
100
|
+
verified source IDs and landmark reference to the Earth business catalog. To change a
|
|
101
|
+
generic treatment, edit its landmark or category mapping.
|
|
102
|
+
3. For a mapped-business descriptor, use `symbol: "letters"` and derive `letters` from the generic
|
|
103
|
+
title. Reserve other geometric marks for non-business category signs and props. A new silhouette
|
|
104
|
+
needs a bounded generator implementation and schema update.
|
|
105
|
+
4. Increment the edited document version to record the revision. Run `molen validate <file>`
|
|
106
|
+
for structural validation, then `pnpm -r build` to validate catalog cross-references.
|
|
107
|
+
Content hashes handle cache invalidation independently of manual version bumps.
|
|
108
|
+
5. For behavioral or visual changes, add positive and misleading-name cases, a standalone and
|
|
109
|
+
shared-building example, and inspect near/distant captures. Follow the
|
|
110
|
+
[3D art guidelines](3d-art-guidelines.md).
|
|
111
|
+
|
|
112
|
+
The engine uses generic `BuildingRequest.appearance` and `storefronts` fields; geographic names
|
|
113
|
+
and category matching stay in the Earth adapter. Custom scenes can supply those same fields through
|
|
114
|
+
`worldgenBuilding`. Each storefront supplies an identity, local anchor, accent, model reference,
|
|
115
|
+
optional native sign size, and desired width. Canonical signs are 4 × 1.35 m, front +Z, base Y=0.
|
|
116
|
+
Signs and outdoor objects use shared instanced geometry and a shared vertex-color material.
|
|
117
|
+
|
|
118
|
+
## Mapped outdoor objects
|
|
119
|
+
|
|
120
|
+
The adapter places mapped street lamps, benches, bicycle parking, charging stations and trees.
|
|
121
|
+
Human mode owns furniture; Land classes mode owns trees. A point in the half-open tile rectangle
|
|
122
|
+
[0,1) × [0,1) owns its placement; buffered copies do not create duplicates. Finest-level points
|
|
123
|
+
are ground-fitted, deduplicated and budgeted before procedural scatter.
|
|
124
|
+
|
|
125
|
+
When the source supplies them, tree height/crown diameter/leaf type, lamp height, numeric direction,
|
|
126
|
+
and bike-parking capacity influence the model. Missing dimensions use conservative defaults.
|
|
127
|
+
A charging POI denotes a station, so the renderer places a representative pedestal rather than
|
|
128
|
+
inventing a surveyed bank of connectors. The library includes a red/white fast-charger variant.
|
|
129
|
+
|
|
130
|
+
Mapped crowns reserve space from procedural scatter. Surface renderers can opt into
|
|
131
|
+
`details.preferMappedProps` to suppress inferred lamps near mapped ones; the explorer enables
|
|
132
|
+
this when its worldgen library is active. Synthetic and unmapped areas keep procedural fallbacks.
|
|
133
|
+
The ordinary Protomaps extract usually supplies position/category, not detailed species or dimensions.
|
|
134
|
+
|
|
135
|
+
## Repeatable visual review
|
|
136
|
+
|
|
137
|
+
Build the repository and run the world explorer with `?synthetic=1&stores=1&style=default`
|
|
138
|
+
to inspect all 44 mapped descriptor variants, four additional retail-center treatments, mixed tenants and outdoor
|
|
139
|
+
props. The original eight stores and interior walkthrough coordinates remain in place; the new
|
|
140
|
+
chains occupy the southern blocks and the retail centers flank them.
|
|
141
|
+
The [store-library batch fixture](../../packages/worldgen-earth/test/fixtures/store-library.batch.json)
|
|
142
|
+
supports deterministic close views:
|
|
143
|
+
|
|
144
|
+
```sh
|
|
145
|
+
molen worldgen preview --batch packages/worldgen-earth/test/fixtures/store-library.batch.json --out .artifacts/store-library.png --angles 4
|
|
146
|
+
```
|
|
147
|
+
The [U.S. retail batch](../../packages/worldgen-earth/test/fixtures/us-retail-library.batch.json)
|
|
148
|
+
includes all 40 additions plus Target, including a courtyard mall and independent mixed tenants:
|
|
149
|
+
|
|
150
|
+
```sh
|
|
151
|
+
molen worldgen preview --batch packages/worldgen-earth/test/fixtures/us-retail-library.batch.json --out .artifacts/us-retail.png --angles 8
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Raw model buffers are available through `generateLandmarkModel` and `generateSignModel`;
|
|
155
|
+
`encodeGlb` exports the same geometry for the static asset workflow.
|
|
156
|
+
|
|
157
|
+
The data and shapes are intentionally stylized. Mapping accuracy, coverage and source freshness
|
|
158
|
+
bound recognition. A sign treatment must not be interpreted as recovered photographic appearance.
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
# WebGPU and WebGL rendering
|
|
2
|
+
|
|
3
|
+
Molen renders through Three.js WebGPU or the Three.js `WebGLRenderer`. Selecting one is a
|
|
4
|
+
`backend` option, not a choice of function: every client factory is asynchronous because picking
|
|
5
|
+
a backend is, and `backend` defaults to `'auto'`, which probes WebGPU and falls back to WebGL.
|
|
6
|
+
So a page that does nothing special gets WebGPU where the browser has it.
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { mountExperience } from '@bendyline/molen-client';
|
|
10
|
+
|
|
11
|
+
const { client, dispose } = await mountExperience({
|
|
12
|
+
link: worker,
|
|
13
|
+
scene: manifest,
|
|
14
|
+
canvas,
|
|
15
|
+
}); // backend: 'auto' is the default
|
|
16
|
+
|
|
17
|
+
console.log(client.renderer.backend); // 'webgpu' or 'webgl'
|
|
18
|
+
console.log(client.renderer.fallbackReason); // explains an automatic WebGL fallback
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`createClient(link, options)`, `createSnapshotViewer(keyframe, options)`, `createViewer(options)`
|
|
22
|
+
and the low-level `Renderer.create(options)` take the same option and return the same promise;
|
|
23
|
+
`createViewer` is the one for terrain viewers and other hosts without a simulation Worker.
|
|
24
|
+
Awaiting the factory *is* awaiting initialization, so the client you get back is ready for
|
|
25
|
+
backend-specific materials and the first frame. `createClientCore` stays synchronous — it has no
|
|
26
|
+
renderer to initialize.
|
|
27
|
+
|
|
28
|
+
| `backend` | Behavior |
|
|
29
|
+
| --- | --- |
|
|
30
|
+
| `'auto'` (default) | Initialize WebGPU when available; otherwise initialize the legacy Three.js WebGL renderer and expose the reason. |
|
|
31
|
+
| `'webgpu'` | Require WebGPU. Initialization rejects if it cannot be used; this is useful for testing that WebGPU actually executes. |
|
|
32
|
+
| `'webgl'` | Use the legacy Three.js WebGL renderer directly, skipping the WebGPU probe. |
|
|
33
|
+
|
|
34
|
+
Pin `'webgl'` when the pixels have to be reproducible rather than fast: a golden frame must not
|
|
35
|
+
depend on which backend a runner happened to offer. The CLI capture harness and the worldgen
|
|
36
|
+
preview page both pass `backend: 'webgl'` explicitly for that reason.
|
|
37
|
+
|
|
38
|
+
WebGPU requires a supporting browser, GPU adapter, and secure context (HTTPS or localhost).
|
|
39
|
+
Its availability can vary with browser policy, graphics drivers and execution environment.
|
|
40
|
+
The browser exposing `navigator.gpu` alone does not establish that device initialization works.
|
|
41
|
+
An automatic fallback uses `THREE.WebGLRenderer`, preserving existing GLSL materials and the
|
|
42
|
+
legacy rendering path, rather than Three's alternate WebGL implementation inside
|
|
43
|
+
`WebGPURenderer`.
|
|
44
|
+
|
|
45
|
+
Automatic fallback covers initialization. A device lost after startup cannot switch the
|
|
46
|
+
same canvas into a WebGL context safely; use `onDeviceLost(reason)` to show recovery UI and
|
|
47
|
+
reload with `backend: 'webgl'`. The world explorer stops its frame loop and displays this
|
|
48
|
+
recovery instruction. Reconstructing the GPU world after a runtime loss is not automatic.
|
|
49
|
+
|
|
50
|
+
## What WebGPU costs your bundle
|
|
51
|
+
|
|
52
|
+
`three/webgpu` is a second Three.js build, so the WebGPU backend is real bytes: bundled, it is
|
|
53
|
+
about **530 KB** beyond the WebGL core. Molen keeps it behind a dynamic import, and the engine only
|
|
54
|
+
reaches that import after `navigator.gpu.requestAdapter()` hands back an adapter. Two consequences
|
|
55
|
+
worth knowing:
|
|
56
|
+
|
|
57
|
+
- **A device without WebGPU never downloads it.** A page served to headless Chromium with software
|
|
58
|
+
rendering requests only the app and worker chunks; the WebGPU chunk is not fetched. Falling back
|
|
59
|
+
costs one adapter request, not a download.
|
|
60
|
+
- **Your bundler still emits the chunk.** It is in the module graph, so a production build contains
|
|
61
|
+
it whether or not your users have WebGPU. That is the price of supporting both backends from one
|
|
62
|
+
package, and it is lazy rather than wasted.
|
|
63
|
+
|
|
64
|
+
`backend: 'webgl'` skips the probe at runtime but does not remove the chunk from a build. A
|
|
65
|
+
deployment that will never use WebGPU can drop it by pointing the specifier at a stub. The client
|
|
66
|
+
takes exactly four runtime names from `three/webgpu`, so the stub is short:
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
// webgpu-stub.js
|
|
70
|
+
const missing = () => {
|
|
71
|
+
throw new Error('three/webgpu was stubbed out at build time');
|
|
72
|
+
};
|
|
73
|
+
export const WebGPURenderer = missing;
|
|
74
|
+
export const WebGPUBackend = missing;
|
|
75
|
+
export const CanvasTarget = missing;
|
|
76
|
+
export const BundleGroup = missing;
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
```js
|
|
80
|
+
// vite.config.js
|
|
81
|
+
export default { resolve: { alias: { 'three/webgpu': '/webgpu-stub.js' } } };
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Measured over the published client entry, that removes 532 KB and one chunk. Pair it with
|
|
85
|
+
`backend: 'webgl'` so nothing ever reaches the stub; if something does, the throw is caught and
|
|
86
|
+
`'auto'` falls back to WebGL with the reason on `renderer.fallbackReason`.
|
|
87
|
+
|
|
88
|
+
## Materials and existing hosts
|
|
89
|
+
|
|
90
|
+
Standard Three materials, geometry, textures, instancing, lighting and Molen's camera APIs are
|
|
91
|
+
shared between the backends. Custom `ShaderMaterial`, `RawShaderMaterial`, and GLSL
|
|
92
|
+
`onBeforeCompile` hooks need node-material/TSL equivalents for WebGPU. Select the material
|
|
93
|
+
from the **actual** `renderer.backend`, since an `auto` request may have fallen back.
|
|
94
|
+
|
|
95
|
+
The world explorer includes both atmosphere implementations: `Sky` for WebGL and the
|
|
96
|
+
node-based `SkyMesh` for WebGPU. Atmospheric parameters, sun direction and depth settings are
|
|
97
|
+
aligned, and SkyMesh's default clouds are disabled to preserve the existing clear sky.
|
|
98
|
+
Both keep the sky outside the world's floating-origin group.
|
|
99
|
+
The sky depth-tests against the correct far plane, including reverse depth, so cached terrain
|
|
100
|
+
commands can execute before the sky without being covered by it.
|
|
101
|
+
|
|
102
|
+
Generated building and landmark uploads align packed RGB vertex colors to a four-byte stride
|
|
103
|
+
for WebGPU. The color attribute remains a normalized RGB triplet, preserving its WebGL
|
|
104
|
+
appearance and the kernel/worker buffer format.
|
|
105
|
+
|
|
106
|
+
For terrain water, use terrain's own asynchronous material factory when supporting both
|
|
107
|
+
backends:
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import {
|
|
111
|
+
createTerrainWaterMaterialAsync,
|
|
112
|
+
setTerrainWaterTime,
|
|
113
|
+
} from '@bendyline/molen-terrain/client';
|
|
114
|
+
|
|
115
|
+
const water = await createTerrainWaterMaterialAsync(
|
|
116
|
+
{ color: '#286d83', waveScale: 0.028, waveStrength: 0.045 },
|
|
117
|
+
client.renderer.backend,
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
// Each frame: compensate for origin rebasing so wave patterns remain world-anchored.
|
|
121
|
+
const origin = client.renderer.getWorldOrigin();
|
|
122
|
+
setTerrainWaterTime(water, seconds, [origin[0], origin[2]]);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Terrain keeps a synchronous `createTerrainWaterMaterial()` that returns the existing WebGL
|
|
126
|
+
material. WebGPU-specific code and shader modules are loaded on demand by the asynchronous path.
|
|
127
|
+
Code directly using `renderer.three` should check `renderer.backend` before accessing APIs
|
|
128
|
+
specific to one backend, such as a WebGL context.
|
|
129
|
+
|
|
130
|
+
`preserveDrawingBuffer` is a WebGL option. For WebGPU canvas readback, render immediately
|
|
131
|
+
before capturing in the same task, or use a render target and explicit readback. CLI reference
|
|
132
|
+
captures stay on WebGL by pinning `backend: 'webgl'`.
|
|
133
|
+
|
|
134
|
+
## WebGPU performance
|
|
135
|
+
|
|
136
|
+
`backend: 'auto'` prefers WebGPU. WebGPU optimization is enabled by default too;
|
|
137
|
+
pass `optimizeWebGpu: false` to disable the instance-upload and command-cache optimizations
|
|
138
|
+
for a controlled comparison. This does not change backend selection, resolution or detail.
|
|
139
|
+
|
|
140
|
+
Small instance sets use Three's uniform-buffer shaders. Molen avoids uploading unchanged
|
|
141
|
+
instance matrices again, using the attribute's `version` rather than comparing matrix contents.
|
|
142
|
+
After `setMatrixAt` or direct array edits, set `mesh.instanceMatrix.needsUpdate = true`, as
|
|
143
|
+
required by Three. Shared LOD attributes retain their identity. A local adapter for Three's
|
|
144
|
+
WebGPU backend (r184–r186, the supported peer range) applies this check only to recognized
|
|
145
|
+
instance-matrix buffers; camera, material, animation and other uniforms continue updating
|
|
146
|
+
normally. Revalidate this adapter before widening the three peer range. Large instance buffers retain Three's vertex-attribute path.
|
|
147
|
+
|
|
148
|
+
Use `renderer.createRenderGroup()` for independent opaque terrain/content chunks. It returns
|
|
149
|
+
a managed WebGPU `BundleGroup`, or a normal Three `Group` on WebGL. The pyramid terrain stream
|
|
150
|
+
accepts `createTileGroup: () => renderer.createRenderGroup()`; World Explorer already uses it.
|
|
151
|
+
The renderer checks command state on every frame, updating LOD and re-recording when the
|
|
152
|
+
camera, hierarchy, visibility, transforms, draw counts, geometry, materials or lighting change.
|
|
153
|
+
During camera motion it uses normal draw submission and skips command snapshots, retaining
|
|
154
|
+
Three's frustum and LOD decisions without rebuilding bundles on every frame. Caching resumes
|
|
155
|
+
when the view settles.
|
|
156
|
+
Statistics include draws executed from cached bundles, not just newly recorded commands.
|
|
157
|
+
The pinned renderer also refreshes every instance's material observer even in a static bundle.
|
|
158
|
+
Molen skips that refresh only for an initialized, verified unchanged render object without
|
|
159
|
+
node animation; changed frames, new objects and animated materials retain normal updates.
|
|
160
|
+
|
|
161
|
+
These chunks must be independent in draw order. Do not put content requiring ordering across
|
|
162
|
+
chunks (such as coplanar overlays) into separate render groups. Transparent materials, disabled
|
|
163
|
+
depth testing/writing, skinning, video textures, custom draw callbacks, clipping, XR, shadows and
|
|
164
|
+
scene overrides use ordinary rendering instead of command caching. Nested managed groups disable
|
|
165
|
+
the outer cache.
|
|
166
|
+
Time-based node materials still receive Three's per-frame node updates.
|
|
167
|
+
|
|
168
|
+
The world explorer also accepts `gpuOptimizations=0` for an uncached WebGPU comparison.
|
|
169
|
+
|
|
170
|
+
## Testing the world explorer
|
|
171
|
+
|
|
172
|
+
Run the example with `pnpm --filter @bendyline/molen-examples-world-explorer dev`, then compare
|
|
173
|
+
the same location and settings using `?backend=webgpu` and `?backend=webgl`. Omitting the
|
|
174
|
+
parameter, or using `?backend=auto`, enables automatic selection. The performance HUD displays
|
|
175
|
+
the backend that actually rendered and any automatic fallback reason; its
|
|
176
|
+
`#performance-status` element also exposes `data-backend` and `data-fallback-reason` for tests.
|
|
177
|
+
|
|
178
|
+
For comparisons, keep `quality`, viewport dimensions, device-pixel ratio, camera position,
|
|
179
|
+
layer mode and loaded assets the same. A manual quality such as `quality=balanced` prevents
|
|
180
|
+
the adaptive controller from choosing different detail during a comparison. `freeze` freezes
|
|
181
|
+
the water animation for screenshots. World Explorer requests multisample antialiasing by default
|
|
182
|
+
(4x MSAA on WebGPU; context antialiasing on WebGL); pass `antialias=0` only when measuring its
|
|
183
|
+
cost. Allow tiles, assets and shader pipelines to warm up
|
|
184
|
+
before collecting frame statistics; record startup separately.
|
|
185
|
+
|
|
186
|
+
Use `renderer.createGpuTimer()` for optional asynchronous GPU timing. It returns `undefined`
|
|
187
|
+
when the backend or device lacks usable timestamps. Unavailable timestamps are not zero GPU
|
|
188
|
+
cost; CPU/frame timings remain useful. The world explorer already integrates this timer into
|
|
189
|
+
its adaptive-quality controller.
|
|
190
|
+
|
|
191
|
+
WebGPU is an additional rendering backend, not a guaranteed frame-rate improvement. Backend
|
|
192
|
+
comparisons require the same workload on real GPU hardware. Software adapters are useful for
|
|
193
|
+
API/shader correctness and fallback testing, but their timings do not predict hardware gains.
|
|
194
|
+
Keep WebGL reference screenshots pinned to `backend=webgl`; test WebGPU separately rather than
|
|
195
|
+
silently regenerating a backend's visual baseline from another renderer.
|
|
196
|
+
|
|
197
|
+
After building, `pnpm -r test:golden` runs browser regression coverage, including the backend
|
|
198
|
+
suite. That suite's default launch uses explicit SwiftShader flags for portable software
|
|
199
|
+
execution; WebGPU cases report a skip if Chromium cannot create an adapter/device, while the
|
|
200
|
+
WebGL and fallback cases still run. Require WebGPU and use the browser's normal hardware
|
|
201
|
+
selection with these PowerShell commands:
|
|
202
|
+
|
|
203
|
+
```powershell
|
|
204
|
+
pnpm -r build
|
|
205
|
+
$env:MOLEN_REQUIRE_WEBGPU = '1'
|
|
206
|
+
$env:MOLEN_WEBGPU_ARGS = '[]'
|
|
207
|
+
$env:MOLEN_WEBGPU_CHANNEL = 'chrome'
|
|
208
|
+
pnpm --filter @bendyline/molen-tooling exec vitest run --config vitest.golden.config.ts test/golden/webgpu.golden.test.ts
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
`MOLEN_REQUIRE_WEBGPU=1` makes an unavailable adapter/device fail the suite and also defaults
|
|
212
|
+
to normal browser arguments. `MOLEN_WEBGPU_CHANNEL=chrome` selects installed Google Chrome;
|
|
213
|
+
omit it to use Playwright's bundled Chromium. Browser builds can have different GPU support,
|
|
214
|
+
so an unavailable adapter in bundled Chromium does not establish that installed Chrome lacks
|
|
215
|
+
WebGPU. `MOLEN_WEBGPU_ARGS` accepts a JSON array that overrides launch
|
|
216
|
+
flags; `[]` explicitly selects normal browser behavior. To require execution through a
|
|
217
|
+
software WebGPU adapter, supply
|
|
218
|
+
`["--enable-unsafe-webgpu","--use-webgpu-adapter=swiftshader","--use-angle=swiftshader","--enable-unsafe-swiftshader"]`
|
|
219
|
+
instead. The suite writes capability diagnostics with browser version, launch flags and
|
|
220
|
+
adapter information, so a passing run can be identified as hardware or software execution.
|
|
221
|
+
|
|
222
|
+
`MOLEN_SKIP_WEBGPU=1` does the opposite: every golden suite treats WebGPU as unavailable, so
|
|
223
|
+
WebGPU cases report a skip while the WebGL, fallback and node-WebGL cases still run. CI's golden
|
|
224
|
+
job sets it. Its CPU-only runners expose a SwiftShader WebGPU adapter but lose the device on the
|
|
225
|
+
world explorer's scenes, which leaves a blank canvas and "Instance dropped" errors. WebGPU coverage
|
|
226
|
+
therefore comes from local runs and from GPU runners with `MOLEN_REQUIRE_WEBGPU=1`. The two
|
|
227
|
+
switches contradict each other; with both set, the suites fail.
|
|
228
|
+
|
|
229
|
+
This backend integration does not add GPU-driven terrain selection, compute culling, indirect
|
|
230
|
+
draws or a new lighting pipeline. Those are separate optimizations to evaluate after measuring
|
|
231
|
+
the shared rendering path.
|