@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.
Files changed (84) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE.md +15 -0
  3. package/README.md +91 -0
  4. package/dist/capture/THIRD-PARTY-NOTICES.md +223 -0
  5. package/dist/capture/basis/LICENSE.txt +55 -0
  6. package/dist/capture/basis/basis_transcoder.js +19 -0
  7. package/dist/capture/basis/basis_transcoder.wasm +0 -0
  8. package/dist/capture/capture.html +15 -0
  9. package/dist/capture/harness.js +4671 -0
  10. package/dist/capture/worldgen-preview.html +15 -0
  11. package/dist/capture/worldgen-preview.js +4617 -0
  12. package/dist/cli.d.mts +1 -0
  13. package/dist/cli.mjs +1276 -0
  14. package/dist/docs-src/guide/3d-art-guidelines.md +157 -0
  15. package/dist/docs-src/guide/3d-model-assets.md +286 -0
  16. package/dist/docs-src/guide/adaptive-performance.md +89 -0
  17. package/dist/docs-src/guide/agent-loop.md +156 -0
  18. package/dist/docs-src/guide/aircraft.md +225 -0
  19. package/dist/docs-src/guide/browser-mount.md +185 -0
  20. package/dist/docs-src/guide/building-interiors.md +175 -0
  21. package/dist/docs-src/guide/capability-authoring.md +69 -0
  22. package/dist/docs-src/guide/determinism.md +285 -0
  23. package/dist/docs-src/guide/entities.md +47 -0
  24. package/dist/docs-src/guide/examples.md +58 -0
  25. package/dist/docs-src/guide/experience-playback.md +57 -0
  26. package/dist/docs-src/guide/figures.md +164 -0
  27. package/dist/docs-src/guide/game-samples.md +100 -0
  28. package/dist/docs-src/guide/graphics-performance.md +167 -0
  29. package/dist/docs-src/guide/input.md +205 -0
  30. package/dist/docs-src/guide/materials.md +125 -0
  31. package/dist/docs-src/guide/project.md +157 -0
  32. package/dist/docs-src/guide/quickstart.md +63 -0
  33. package/dist/docs-src/guide/recognizable-places.md +158 -0
  34. package/dist/docs-src/guide/rendering-backends.md +231 -0
  35. package/dist/docs-src/guide/scripting.md +330 -0
  36. package/dist/docs-src/guide/sky.md +192 -0
  37. package/dist/docs-src/guide/source-bundles.md +42 -0
  38. package/dist/docs-src/guide/structure-library.md +114 -0
  39. package/dist/docs-src/guide/surface-rendering.md +203 -0
  40. package/dist/docs-src/guide/terrain.md +389 -0
  41. package/dist/docs-src/guide/three-surface.md +70 -0
  42. package/dist/docs-src/guide/vehicle-interiors.md +126 -0
  43. package/dist/docs-src/guide/vehicles.md +110 -0
  44. package/dist/docs-src/guide/weather.md +123 -0
  45. package/dist/docs-src/guide/worldgen.md +434 -0
  46. package/dist/docs-src/llms.txt +129 -0
  47. package/dist/docs-src/schemas/README.md +36 -0
  48. package/dist/docs-src/schemas/archstyle.md +2340 -0
  49. package/dist/docs-src/schemas/assert.md +169 -0
  50. package/dist/docs-src/schemas/asset.md +543 -0
  51. package/dist/docs-src/schemas/business-catalog.md +162 -0
  52. package/dist/docs-src/schemas/cameratrack.md +132 -0
  53. package/dist/docs-src/schemas/command.md +112 -0
  54. package/dist/docs-src/schemas/components.md +5826 -0
  55. package/dist/docs-src/schemas/delta.md +204 -0
  56. package/dist/docs-src/schemas/experience-play.md +452 -0
  57. package/dist/docs-src/schemas/figure.md +290 -0
  58. package/dist/docs-src/schemas/interior-catalog.md +230 -0
  59. package/dist/docs-src/schemas/keyframe.md +314 -0
  60. package/dist/docs-src/schemas/landmark-catalog.md +56 -0
  61. package/dist/docs-src/schemas/landmark.md +293 -0
  62. package/dist/docs-src/schemas/matgraph.md +1163 -0
  63. package/dist/docs-src/schemas/pack-index.md +82 -0
  64. package/dist/docs-src/schemas/pack-source.md +139 -0
  65. package/dist/docs-src/schemas/pack.md +225 -0
  66. package/dist/docs-src/schemas/pixelgrid.md +108 -0
  67. package/dist/docs-src/schemas/prefab.md +106 -0
  68. package/dist/docs-src/schemas/project.md +271 -0
  69. package/dist/docs-src/schemas/region-atlas.md +612 -0
  70. package/dist/docs-src/schemas/replay.md +807 -0
  71. package/dist/docs-src/schemas/scatter.md +541 -0
  72. package/dist/docs-src/schemas/scene.md +1152 -0
  73. package/dist/docs-src/schemas/source-bundle.md +266 -0
  74. package/dist/docs-src/schemas/stylepack.md +420 -0
  75. package/dist/docs-src/schemas/terrain-package.md +731 -0
  76. package/dist/docs-src/schemas/terrain.md +313 -0
  77. package/dist/docs-src/schemas/types.md +218 -0
  78. package/dist/docs-src/schemas/uvpaint.md +149 -0
  79. package/dist/docs-src/schemas/worldgen-batch.md +743 -0
  80. package/dist/index.d.mts +1271 -0
  81. package/dist/index.mjs +78 -0
  82. package/dist/mcp-BFnCWrg0.mjs +796 -0
  83. package/dist/ops-BGxhSP6w.mjs +7246 -0
  84. package/package.json +96 -0
@@ -0,0 +1,157 @@
1
+ # 3D art guidelines
2
+
3
+ Molen's baseline is a readable polygonal world: strong silhouettes, restrained palettes, clear
4
+ material blocks, and modest surface detail. A building or prop should remain recognizable when
5
+ textures are disabled. Textures add material character such as brick courses; they do not carry
6
+ the entire identity.
7
+
8
+ These guidelines apply to imported static GLBs, built-in instanced props, and parameterized
9
+ worldgen buildings. They are authoring targets, not new runtime hard limits. Use the existing
10
+ [model asset workflow](3d-model-assets.md) for import, validation, hashes, hosting, and captures.
11
+
12
+ ## Recognition and shape
13
+
14
+ Work from large to small: footprint and height, roof and massing, entrance and facade rhythm,
15
+ then sign and surface detail. For a mapped business, use a generic category wordmark, an
16
+ initial-based emblem, a controlled accent color, and an entrance treatment. Source-inspired
17
+ palettes may distinguish descriptor variants, but model IDs, filenames, displayed names and
18
+ emblem geometry stay generic.
19
+
20
+ Keep mapped footprints, courtyards, height, and minimum height when supplied. Missing height is
21
+ unknown: the category recipe supplies a conservative default. An identified tenant does not
22
+ own an entire strip mall. Apply its facade locally and retain other tenants.
23
+
24
+ Flat or gently faceted surfaces are the default. Use hard normals on architecture and metal
25
+ edges; smooth normals only on deliberately round shapes. Curved identity marks should still
26
+ read at low polygon counts. Avoid tiny bevels, microdisplacement, alpha-card foliage and surface
27
+ noise that shimmer at street-view distance. Signs face +Z in their own frame and must read from
28
+ the street; never mirror text to compensate for an incorrectly oriented facade.
29
+
30
+ ## Scale and pivots
31
+
32
+ Use meters, +Y up, and transforms near unit scale. Ground-standing props have their base at
33
+ Y=0. Wall-mounted signs have a documented attachment plane. Record front direction and native
34
+ dimensions alongside each model.
35
+
36
+ | Reference | Baseline |
37
+ | --- | --- |
38
+ | Adult scale reference | 1.75 m |
39
+ | Child figure | 1.1–1.4 m |
40
+ | Dog at the shoulder | 0.5–0.7 m |
41
+ | Horse at the withers | 1.5–1.7 m |
42
+ | Ordinary door | 0.9–1.1 m wide, 2.1–2.4 m high |
43
+ | Commercial double entrance | 1.6–2.2 m wide, up to 2.6 m high |
44
+ | Bench | About 1.8 m wide; seat about 0.48 m high |
45
+ | Bicycle hoop | About 0.85 m high |
46
+ | Street lamp | About 7 m; use a mapped height when present |
47
+ | Charging pedestal | About 1.8 m |
48
+ | Canonical facade sign | 4 × 1.35 m; base Y=0, front +Z |
49
+
50
+ Check scale beside a person, a door, and a road. Make signs readable through proportions and
51
+ contrast before increasing their size. Do not stretch a mark independently in X and Y.
52
+ Mapped tree height and crown diameter scale normalized tree models independently in height
53
+ and horizontal diameter; missing species remains an estimate.
54
+
55
+ ## Fidelity and geometry budgets
56
+
57
+ Use the lowest detail that survives the intended view. These targets describe one reusable
58
+ model; scene and tile budgets still control total instances and building vertices.
59
+
60
+ | Asset | Near target | Medium/distant treatment |
61
+ | --- | --- | --- |
62
+ | Identity sign | Under 650 triangles, one material | Remove small lettering first; retain symbol and color |
63
+ | Bench, rack, charger, lamp | 50–500 triangles | Merge slats/cables; retain silhouette |
64
+ | Ordinary tree | 300–2,000 triangles | Fewer crown clusters, then a faceted crown/cone |
65
+ | Small static building | 1,000–8,000 triangles | Remove furniture and small facade details |
66
+ | Procedural building | Budgeted per outline | Keep measured envelope, main roof and identity where feasible |
67
+ | Figure (human or animal) | 1,000–4,000 triangles, one vertex-color material | 600–900 medium tier; 100–300 rigid distant tier |
68
+
69
+ Higher budgets need a visible reason and a distance fallback. Repeated street furniture and signs
70
+ should be instanced by model reference. Prefer a shared vertex-color material; do not allocate
71
+ one material or texture per store. Never put an unlimited number of signs on a complex outline:
72
+ the current frontage contract admits at most twelve per generated building.
73
+
74
+ The sign library preserves exact geometry between instances. Source business identity controls
75
+ matching; stable feature identity controls placement and variation. Do not use wall-clock time,
76
+ unseeded randomness, or locale-dependent sorting to generate geometry.
77
+
78
+ ## Figures
79
+
80
+ Figures ([guide](figures.md)) stay left of the uncanny valley on purpose: a head about one
81
+ sixth of the height for adults and closer to a quarter for children, mitten hands, block shoes or
82
+ hooves, disc eyes and brows with no mouth, nose or teeth, hair as a solid shell, and clothing as
83
+ vertex-color blocks with hard edges at cuffs, hems and collars. Segments are smooth within
84
+ themselves and low in ring count (eight to twelve sides), joints share rings with two bone
85
+ influences, and each figure uses three to five intentional colors from its palette. Animals
86
+ follow the same rules: a barrel body, cone ears, a snout, hooves or paws, and one marking color.
87
+ Review every preset from the front, three-quarter, rear and gameplay distance
88
+ (`molen figure preview --angles review`) beside a door and a bench before accepting a look.
89
+
90
+ ## Color, light and material response
91
+
92
+ Use muted wall/ground colors and reserve saturated accents for identity and wayfinding.
93
+ Limit each object to roughly three to five intentional colors, excluding small surface variation.
94
+ Roof and foundation values should separate from the wall without outlining every edge.
95
+
96
+ Author with neutral daylight, real cast shadows and a shadow-receiving ground. Base color must
97
+ not contain baked directional shadows or highlights. Prefer rough matte paint, brick, concrete,
98
+ wood, and coated metal; glass should read as glazing without becoming a mirror everywhere.
99
+ Use material variation to explain construction, not to disguise missing geometry.
100
+
101
+ For GLB PBR assets, base color/emissive are sRGB; normal, roughness, metalness and occlusion are
102
+ linear data. Existing worldgen palette helpers and three.js color inputs have different conversion
103
+ paths: compare rendered swatches when transferring colors between static and procedural assets,
104
+ rather than copying a linear buffer value into an sRGB authoring field.
105
+
106
+ ## Canonical material library
107
+
108
+ Reuse the default pack's stable material IDs before adding another texture. The library already
109
+ contains brick, stucco, concrete, siding, stone, roofing and glazing; the
110
+ [material catalog](../../content/worldgen/materials/README.md) records intended
111
+ uses and physical repeat sizes.
112
+
113
+ Use 256² or 512² seamless procedural maps for common repeated surfaces. Larger textures belong
114
+ to a visibly close hero asset and must fit its memory budget. Start at 64–128 texels per meter
115
+ at the closest ordinary view and check mipmapped distance views. Specify physical UV repeat size:
116
+ a two-meter facade should not accidentally contain two-meter bricks.
117
+
118
+ Patterns should have subdued contrast. Prefer a small shared base-color/roughness set over
119
+ unique store textures. Normal maps should describe mortar or subtle grain, not change the
120
+ silhouette. Pack bitmap GLB textures to KTX2 with mipmaps for shipping, per the asset workflow.
121
+ Runtime matgraph textures remain small and shared; they do not pass through asset packing.
122
+
123
+ ## Persisting reusable models
124
+
125
+ Store individual sign and furniture definitions in the default pack's
126
+ [landmark manifests](../../content/worldgen/landmarks/README.md), with stable IDs,
127
+ versioned parameters and shared generators. Keep source-ID/name matching in the Earth business
128
+ catalog. Reuse architectural styles and material graphs instead of copying their rules into each
129
+ mapped-business descriptor. A new store palette or an existing sign-symbol variation should be a
130
+ data edit.
131
+
132
+ ## Static and procedural parity
133
+
134
+ A static asset and its procedural counterpart must agree on scale, pivot, front direction,
135
+ palette, and intended detail tier. The identity and furniture generators are exported through
136
+ the worldgen kernel. Their buffers can be exported with encodeGlb; import the resulting GLB
137
+ through the normal asset workflow when a project needs a standalone static asset.
138
+
139
+ Procedural building bakes currently include the building mesh; attached sign/furniture instances
140
+ remain separate placements. To preserve a mapped-business treatment in a static scene, retain those
141
+ placements or explicitly assemble and import the complete model. Do not silently ship the bare
142
+ shell as an equivalent bake.
143
+
144
+ ## Review before adding to the library
145
+
146
+ Capture front, three-quarter, rear, and a normal gameplay-distance view. Include a neutral
147
+ ground, a scale reference, and a texture-disabled view. Verify outward normals, legible unmirrored
148
+ signs, ground contact, and believable shadows. Test at least two scales and a rotated placement.
149
+ For storefronts, include one shared building and a footprint with a courtyard or seam.
150
+
151
+ Compare near and distant representations for popping, silhouette drift and floating pivots.
152
+ Record triangles, material groups, model reference, texture sizes, source hashes for imported
153
+ assets, and the generator/catalog version. Keep a repeatable scene or batch fixture and a
154
+ reviewed visual regression. A successful build without inspected images is not visual approval.
155
+
156
+ The [recognizable places guide](recognizable-places.md) explains how to extend the first identity
157
+ library and use the art-review showcase.
@@ -0,0 +1,286 @@
1
+ # 3D model assets
2
+
3
+ This is the shipped, agent-facing workflow for turning a prompt or supplied model into a textured
4
+ Molen asset. It covers the current engine. Proposed pipeline improvements live in
5
+ [`../../docs/11-3d-model-assets.md`](../../docs/11-3d-model-assets.md).
6
+
7
+ ## What “done” means
8
+
9
+ A finished model asset has all of the following:
10
+
11
+ - a valid glTF 2.0 `.glb` or `.gltf` source;
12
+ - an imported `molen/asset@1` sidecar and canonical `model.glb`;
13
+ - a stable asset id registered in `project.json`;
14
+ - meter-scale bounds, useful node/material names, and collision data appropriate to its use;
15
+ - textures stored in the project or embedded in the GLB with correct PBR semantics;
16
+ - successful asset hash verification, scene validation, and headless simulation;
17
+ - inspected turntable images and at least one screenshot of the asset inside a lit Molen scene.
18
+
19
+ The model-generation tool is deliberately not prescribed. Molen consumes glTF; the only shipped organic generator is
20
+ the figures capability ([figures.md](figures.md): stylized humans and animals from a descriptor). A deterministic script is often best for simple props,
21
+ buildings, and other parametric hard-surface assets. Use an available DCC or model-generation
22
+ capability for shapes that genuinely need sculpting, retopology, rigging, or complex UV work.
23
+
24
+ For shared polygonal style, fidelity targets and canonical materials, follow [3D art guidelines](3d-art-guidelines.md).
25
+
26
+ ## 1. Convert the prompt into an asset brief
27
+
28
+ Before making geometry, decide the points that affect the runtime result:
29
+
30
+ - identity and silhouette: what must make the asset recognizable;
31
+ - dimensions in meters and where the origin should sit (usually centered at ground level);
32
+ - camera-facing details and which views must hold up;
33
+ - realistic, stylized, or low-poly treatment;
34
+ - static versus animated, and required animation clip names;
35
+ - collision: convex hulls for most moving props, optional trimesh for static concave geometry;
36
+ - triangle, material, texture, and download-size budgets;
37
+ - stable asset id and owning project. Reserve its namespace first if the id is dotted.
38
+
39
+ Do not invent requirements that materially change the prompt. Record reasonable assumptions in
40
+ the asset README or build report.
41
+
42
+ ## 2. Keep source and runtime artifacts separate
43
+
44
+ A practical project-local layout follows the [logical source bundle](source-bundles.md) contract:
45
+
46
+ ```text
47
+ source/<category>/<asset-name>/
48
+ source.json # molen/source-bundle@1; inventories every owned source file
49
+ README.md
50
+ models/
51
+ source.glb # or editable source + export script
52
+ scripts/ # deterministic generation/conversion, when useful
53
+ textures/
54
+ material-basecolor.png
55
+ material-normal.png
56
+ material-roughness.png
57
+ assets/
58
+ <asset-id path>/
59
+ asset.json # written by molen asset import (+ updated by asset pack)
60
+ model.glb # canonical design-time model (PNG/JPEG textures, no decoders)
61
+ model.ktx2.glb # packed runtime variant: KTX2 textures + mipmaps (molen asset pack)
62
+ shots/
63
+ <asset-name>/ # turntable and in-scene QA images
64
+ ```
65
+
66
+ `assets/` is the runtime contract. `source/` is provenance and reproducibility; Molen does not
67
+ serve it. Do not hand-edit an imported sidecar to disguise a stale hash—re-import instead.
68
+
69
+ For repo examples that should be ready to edit and play, keep both the unoptimized editing master
70
+ and imported runtime GLB. Keep any native authoring files and original textures too. In Vite
71
+ examples, `public/assets/` is the runtime directory: it is served in development and copied into
72
+ `dist/` during normal app builds. Asset generation/import should be an explicit authoring step,
73
+ never a requirement for launching a checked-out example. JS bundles in `dist/` remain disposable.
74
+
75
+ Generators should preserve hand edits before writing any outputs. Record generator baseline
76
+ hashes separately from the current imported source hash so an artist can edit and re-import a
77
+ master without rewriting its provenance. Verify the current source/runtime relationship with
78
+ Node checks; keep Python/DCC reproducibility checks in the optional authoring workflow. The
79
+ [Lantern Vault example contract](../../examples/ASSETS.md) implements both paths.
80
+
81
+ ## 3. Author geometry for glTF
82
+
83
+ Use glTF 2.0 conventions and these Molen authoring expectations:
84
+
85
+ - +Y is up and dimensions are in meters;
86
+ - keep the transform scale close to `[1,1,1]` at the intended world size;
87
+ - place a ground-standing asset's lowest point near Y=0;
88
+ - supply normals and non-degenerate triangle geometry;
89
+ - supply UV0 for every material that uses textures;
90
+ - give important nodes, meshes, materials, and animation clips stable names;
91
+ - prefer a self-contained GLB for reliable serving and capture;
92
+ - avoid extensions unless the client has the required decoder configuration.
93
+
94
+ The importer decodes supported input, then deduplicates, prunes, welds, and quantizes by default.
95
+ Use `--no-optimize` only to diagnose a transformation issue. Repeating UVs outside `[0,1]` are
96
+ valid, but the optimizer currently leaves those UV accessors unquantized and reports that choice.
97
+
98
+ ## 4. Author textures as material data
99
+
100
+ For a bitmap generated from a text prompt, ask for an orthographic, seamless surface with flat,
101
+ neutral illumination. Explicitly exclude cast shadows, directional highlights, perspective,
102
+ vignettes, frames, text, and scenery. Scene lighting should create the shadows; the base-color
103
+ texture should not contain them.
104
+
105
+ Use the standard glTF material meanings:
106
+
107
+ | Slot | Meaning | Color space / channels |
108
+ | --- | --- | --- |
109
+ | base color | surface color and opacity | sRGB RGBA |
110
+ | normal | tangent-space surface direction | linear RGB; neutral is approximately `[128,128,255]` |
111
+ | metallic-roughness | material response | linear; roughness in G, metalness in B |
112
+ | occlusion | indirect-light attenuation | linear; occlusion in R |
113
+ | emissive | self-lit color | sRGB RGB |
114
+
115
+ Image generation is well suited to base color or a reference pass. Generate or derive data maps
116
+ deterministically when possible; image models do not reliably preserve tangent-space normal or
117
+ channel-packing semantics. Prefer power-of-two runtime dimensions such as 1024² for ordinary props
118
+ and 2048² for hero assets, subject to the project's texel-density and download budgets. Inspect
119
+ seams and mipmapped distance views, not only the source PNG.
120
+
121
+ For procedural Molen materials and UV paint-by-numbers, see [materials.md](materials.md). Those
122
+ tools complement GLB-embedded PBR textures; they do not generate model geometry.
123
+
124
+ ## 5. Import through the project
125
+
126
+ Build the repository once before using the local CLI. From inside the asset's Molen project, run:
127
+
128
+ ```sh
129
+ molen asset import asset-src/red-barn/model-source.glb --id barn.weathered
130
+ molen asset inspect barn.weathered --verify
131
+ molen asset list
132
+ ```
133
+
134
+ In a project that installs `@bendyline/molen-tooling`, run these as `npx molen …`; from a clone of
135
+ the repository, `node <repo>/packages/tooling/dist/cli.mjs`. The importer writes
136
+ `assets/<id with dots as path>/model.glb`, creates `asset.json`, extracts per-node convex hulls,
137
+ and registers the sidecar in the surrounding `project.json`. Add `--trimesh` only when static,
138
+ concave collision justifies its extra size. Use `--project <project.json>` when project discovery
139
+ from the current directory would be ambiguous.
140
+
141
+ `asset inspect --verify` must pass before the asset is placed in a scene. Review its bounds,
142
+ triangle/vertex counts, material slots, textures, animation clips, extensions, and collision hulls;
143
+ “readable GLB” is not enough.
144
+
145
+ ## 6. Pack a runtime variant (KTX2 + mipmaps)
146
+
147
+ The imported `model.glb` is the **design-time** contract: PNG/JPEG textures that every tool can
148
+ open and that render with no decoder hosting. It is not what a shipped game should serve. A PNG
149
+ is decoded to uncompressed RGBA8 before upload, so one 2048² texture with mips costs ~21 MB of
150
+ GPU memory; the same texture as ASTC/BC7 costs ~5.6 MB. On an iOS or Android webview, where the
151
+ page's memory budget is a fraction of a native app's, that 4–8x is what decides whether a scene
152
+ fits. `molen asset pack` derives the **runtime** variant:
153
+
154
+ ```sh
155
+ molen asset pack barn.weathered # -> assets/barn/weathered/model.ktx2.glb
156
+ molen asset pack --all # every registered asset
157
+ molen asset inspect barn.weathered # files.variants.ktx2 now listed
158
+ ```
159
+
160
+ Per texture it resizes to a power of two (longest side ≤ `--max-size`, default 2048), encodes
161
+ KTX2 (Basis Universal) **with a full mip chain** (the GPU cannot generate mips for compressed
162
+ textures), and picks the codec from the material slot: sRGB color maps (baseColor, emissive) use
163
+ ETC1S for the smallest download; normal, roughness/metalness, and occlusion maps use UASTC so
164
+ data stays near-lossless. `--mode etc1s|uastc` forces one codec; `--no-pot` keeps sizes as
165
+ multiples of four instead. The KTX2 file transcodes on the device to ASTC (iOS/Android), BC7/BC1
166
+ (desktop), or ETC2, so one file serves every platform.
167
+
168
+ The variant is recorded in the sidecar (`files.variants.ktx2`); `model.glb` and its hash are
169
+ untouched, so `asset inspect --verify` still passes and design-time tools keep working. Packing
170
+ is a ship-time step: re-run it after re-importing. Encoding is slow (seconds per 2K texture), so
171
+ keep it out of the inner loop.
172
+
173
+ Verify the packed variant with the same headless captures, which serve the Basis transcoder
174
+ automatically:
175
+
176
+ ```sh
177
+ molen asset shot barn.weathered --out-dir shots/barn-ktx2 --variant ktx2
178
+ molen shot scenes/main.scene.json --out shot.png --variant ktx2
179
+ ```
180
+
181
+ Procedural materials (`matgraph:` / `pixelgrid:` refs) are baked at runtime into RGBA8 data
182
+ textures and never pass through a file, so packing does not reach them; keep them small.
183
+
184
+ ## 7. Render the asset twice
185
+
186
+ First capture neutral turntable views:
187
+
188
+ ```sh
189
+ molen asset shot barn.weathered --out-dir shots/red-barn --angles 4
190
+ ```
191
+
192
+ Then test actual scene integration. Add an entity with a GLTF renderable:
193
+
194
+ ```json
195
+ {
196
+ "id": "barn",
197
+ "components": {
198
+ "transform": { "pos": [0, 0, 0], "rot": [0, 0, 0, 1] },
199
+ "renderable": {
200
+ "kind": "gltf",
201
+ "ref": "barn.weathered",
202
+ "shadows": { "cast": true, "receive": true }
203
+ }
204
+ }
205
+ }
206
+ ```
207
+
208
+ Include an `environment` entity with a shadow-casting sun and non-off shadow tier, plus a ground
209
+ primitive with `shadows.receive: true`. Set an explicit camera, then run:
210
+
211
+ ```sh
212
+ molen validate scene.json
213
+ molen sim run scene.json --ticks 30 --assert checks.json --hash
214
+ molen shot scene.json --ticks 30 --size 1280x720 --out shots/red-barn-in-molen.png
215
+ ```
216
+
217
+ Look at every PNG. Check silhouette, scale, origin, camera clipping, UV seams, material response,
218
+ normal direction, texture repetition, transparent edges, light balance, and cast/contact shadows.
219
+ Iterate until the screenshot—not merely the command exit code—matches the brief.
220
+
221
+ ## 8. Host in a browser experience
222
+
223
+ The default URL provider maps an id like `barn.weathered` to
224
+ `assets/barn/weathered/model.glb` beneath the configured base URL. Serve or copy the imported
225
+ `assets/` directory without renaming its contents, then enable assets on the client:
226
+
227
+ ```ts
228
+ const client = await createClient(link, {
229
+ assets: { baseUrl: new URL('./', location.href).href },
230
+ });
231
+ ```
232
+
233
+ For custom hosting paths, pass an explicit id-to-model URL index:
234
+
235
+ ```ts
236
+ const client = await createClient(link, {
237
+ assets: {
238
+ baseUrl: new URL('./', location.href).href,
239
+ index: { 'barn.weathered': 'static/models/barn/model.glb' },
240
+ },
241
+ });
242
+ ```
243
+
244
+ Await `client.ready()` before deterministic captures or tests. `molen shot` builds its asset
245
+ index from `project.json` automatically.
246
+
247
+ To serve the packed runtime variants, host three's Basis transcoder (two files from
248
+ `three/examples/jsm/libs/basis/`) and tell the client which variant to prefer:
249
+
250
+ ```ts
251
+ const client = await createClient(link, {
252
+ assets: { baseUrl: new URL('./', location.href).href, variant: 'ktx2' },
253
+ decoders: { ktx2TranscoderPath: new URL('./decoders/basis/', location.href).href },
254
+ });
255
+ ```
256
+
257
+ With `variant`, a convention-resolved id fetches `model.ktx2.glb` first and falls back to
258
+ `model.glb` when an asset was never packed. Configure `dracoDecoderPath` only when a served asset
259
+ uses Draco; canonical imported assets never do.
260
+
261
+ `molen asset stage` produces the runtime bundle in one step — every registered asset's runtime
262
+ files copied under an output directory (same relative layout, so the convention still resolves)
263
+ plus `assets.index.json` for the client's `index` option:
264
+
265
+ ```sh
266
+ molen asset stage --out-dir public --variant ktx2 --require-variant
267
+ ```
268
+
269
+ Staging verifies every sidecar hash first (a stale asset fails the build), ships the packed GLB
270
+ in place of the design-time one, and rewrites the staged `asset.json` to describe it, so
271
+ `asset inspect --verify` passes on the bundle. Validate, pack, stage is the asset half of a
272
+ release build; the app half is the normal Vite build.
273
+
274
+ ## 9. Record evidence
275
+
276
+ Keep a concise README or machine-readable build report next to the source. Record:
277
+
278
+ - the original asset prompt and all material-generation prompts;
279
+ - geometry and texture generation methods;
280
+ - source and imported model hashes;
281
+ - triangle, vertex, primitive, material, texture, and animation counts;
282
+ - exact import/inspect/validate/sim/shot commands and their outcomes;
283
+ - visible QA notes, known compromises, and the final screenshot path.
284
+
285
+ The runnable library asset at [`../../assets/structures/red-barn/`](../../assets/structures/red-barn/) demonstrates
286
+ this complete path with three embedded PBR textures and real-time Molen shadows.
@@ -0,0 +1,89 @@
1
+ # Adaptive rendering performance
2
+
3
+ The world explorer defaults to **Auto (device)** quality. It measures frame cadence, CPU frame
4
+ work, and asynchronous GPU time when the WebGL extension is available. Six rendering tiers
5
+ target 60 FPS without changing simulation state. Manual Economy, Balanced, and High remain
6
+ available and can be selected without reloading or moving the camera.
7
+
8
+ ## Feedback and budgets
9
+
10
+ `AdaptiveQualityController` from `@bendyline/molen-client` returns a new integer tier when the
11
+ host should change its budgets. It evaluates one-second windows, uses trimmed frame averages
12
+ and slow-frame/p90 statistics, and waits for warmup and sustained overload before lowering detail.
13
+ Memory pressure can also lower detail. Recovery requires stable headroom, no pending streaming,
14
+ and memory margin in displayed content; failed upward probes increase the recovery delay. Hidden intervals and
15
+ isolated long pauses reset or bypass measurements instead of being mistaken for normal rendering.
16
+
17
+ The explorer applies each tier to drawing-buffer resolution, terrain screen-space error and
18
+ range, selected/resident tile limits, terrain and semantic request concurrency, worldgen cache
19
+ bytes, object LOD error, and surface decoration budgets. Pixel limits include high-DPI and
20
+ ultrawide displays. CPU caches and resident geometry have separate limits:
21
+
22
+ | Tier | Maximum rendered pixels | Terrain error | Selected tiles | Resident buffer budget | Worldgen cache |
23
+ | --- | ---: | ---: | ---: | ---: | ---: |
24
+ | Minimum | 450,000 | 10 px | 16 | 96 MiB | 24 MiB |
25
+ | Low | 700,000 | 7 px | 24 | 144 MiB | 32 MiB |
26
+ | Medium | 1,100,000 | 5 px | 40 | 208 MiB | 48 MiB |
27
+ | Balanced | 1,800,000 | 3.5 px | 64 | 288 MiB | 64 MiB |
28
+ | High | 2,800,000 | 2.4 px | 96 | 400 MiB | 96 MiB |
29
+ | Ultra | 4,000,000 | 1.75 px | 128 | 544 MiB | 128 MiB |
30
+
31
+ Resident byte estimates count retained height arrays, geometry attributes/indices and instance
32
+ buffers, deduplicating shared backing storage within each object. They exclude textures, archive
33
+ caches and GPU copies, so they are not total device memory measurements. The resident cap is soft:
34
+ visible ground remains until a replacement is loaded. The controller uses `displayedByteRatio`
35
+ for feedback so a full, reclaimable warm cache does not prevent recovery. Total resident bytes
36
+ still control eviction. After asynchronous surface replacements settle, `refreshMemoryUsage()`
37
+ updates the cached estimates. Existing surface grids keep their resolution
38
+ to preserve drape alignment; newly admitted terrain uses the current cap.
39
+
40
+ ## Object detail and visibility
41
+
42
+ `ScreenSpaceLod` and `ScreenSpaceLodPolicy` from `@bendyline/molen-worldgen/client` use rendered
43
+ viewport height, camera field of view/zoom, conservative spatial bounds and a configurable pixel
44
+ error. The same mutable policy updates resident objects without generation or instance uploads.
45
+ Perspective and orthographic cameras are supported, including parent scale and floating origins.
46
+ Transitions have 15% hysteresis.
47
+
48
+ Builtin vegetation uses three shared models in spatial cells; the far fir/conifer is 12 triangles
49
+ and the far broadleaf crown is 20. Building cells use authored materials nearby, a single
50
+ vertex-color material farther away, then remove window/door/trim faces while retaining walls,
51
+ roof shapes and foundations. Cell bounds let frustum culling reject offscreen batches.
52
+ These are conservative authored detail tolerances, not measured mesh-simplification error bounds.
53
+
54
+ Terrain selection also culls by horizontal view direction. Mesh frustum culling and the GPU
55
+ depth buffer are active. There is no hierarchical depth/terrain occlusion culling; objects behind
56
+ hills may still submit vertices. Custom GLBs retain their authored geometry until lower-detail
57
+ assets or a simplification path are supplied.
58
+
59
+ ## Background work and instrumentation
60
+
61
+ World generation, land-cover draping, and road/parking/junction construction use separate workers
62
+ in the explorer. They transfer typed buffers, skip obsolete queued work and retain the current
63
+ surface while a replacement is generated. Surface quality changes are bucketed to avoid repeated
64
+ rebuilds. Archive decoding, terrain mesh construction, scene assembly and GPU uploads still use
65
+ the main thread; streaming selection runs at 10 Hz.
66
+
67
+ `createGpuFrameTimer(renderer.three.getContext())` returns an optional timer. Call `poll()`
68
+ before a frame, `begin()` before rendering, and `end()` afterward. Pass only new completed GPU
69
+ samples to the controller. It samples one frame in four by default, has a bounded query queue,
70
+ never waits for a result, discards disjoint measurements, and handles context loss/restoration.
71
+ Call `dispose()` when the renderer is destroyed. Frame-time adaptation works without the extension.
72
+
73
+ The separate performance HUD shows Auto's active tier/change reason, frame average/max/p90,
74
+ CPU/GPU timing, actual draw/triangle counts, drawing-buffer dimensions and resident buffer budget.
75
+ These measurements are distinct from cumulative generation counters. Use `?quality=auto` for
76
+ adaptation; explicit `quality=economy|balanced|high` fixes a preset. `?worker=0` and
77
+ `?surfaceWorker=0` are diagnostic fallbacks. Fixed-grid `?level=N` uses manual quality.
78
+
79
+ The approach follows screen-space refinement and memory budgeting described in
80
+ [Cesium's tileset API](https://cesium.com/learn/cesiumjs/ref-doc/Cesium3DTileset.html), Three.js
81
+ [LOD hysteresis](https://threejs.org/docs/pages/LOD.html), and the
82
+ [Khronos asynchronous GPU timer specification](https://registry.khronos.org/webgl/extensions/EXT_disjoint_timer_query_webgl2/).
83
+ These mechanisms need representative hardware profiling; they do not guarantee 60 FPS on every
84
+ device or eliminate download latency.
85
+
86
+ Driving and walking share a nearby collision tree. Its bounding-volume hierarchy stores each
87
+ rendered triangle once, including overlapping roads, walls and interior portal covers. Rebuilding
88
+ as the player moves therefore avoids the recursive triangle duplication of spatial octree cells;
89
+ ray, capsule and vehicle-body queries still test the original surfaces.