@bendyline/molen-tooling 0.0.14 → 0.0.16

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 (46) hide show
  1. package/dist/capture/harness.js +736 -400
  2. package/dist/capture/worldgen-preview.js +409 -298
  3. package/dist/docs-src/guide/3d-art-guidelines.md +5 -2
  4. package/dist/docs-src/guide/adaptive-performance.md +50 -23
  5. package/dist/docs-src/guide/aircraft.md +275 -31
  6. package/dist/docs-src/guide/ambient-life.md +36 -9
  7. package/dist/docs-src/guide/building-interiors.md +92 -8
  8. package/dist/docs-src/guide/determinism.md +1 -1
  9. package/dist/docs-src/guide/dioramas.md +7 -0
  10. package/dist/docs-src/guide/earth-view.md +198 -16
  11. package/dist/docs-src/guide/entities.md +38 -7
  12. package/dist/docs-src/guide/figures.md +32 -4
  13. package/dist/docs-src/guide/graphics-performance.md +62 -19
  14. package/dist/docs-src/guide/livery-catalog.md +137 -1
  15. package/dist/docs-src/guide/livery-gallery.md +136 -1
  16. package/dist/docs-src/guide/medium-fi.md +194 -10
  17. package/dist/docs-src/guide/night-lighting.md +10 -0
  18. package/dist/docs-src/guide/regional-fleets.md +27 -5
  19. package/dist/docs-src/guide/regional-world.md +19 -1
  20. package/dist/docs-src/guide/rendering-backends.md +23 -2
  21. package/dist/docs-src/guide/sky.md +28 -2
  22. package/dist/docs-src/guide/snow.md +231 -0
  23. package/dist/docs-src/guide/surface-rendering.md +324 -9
  24. package/dist/docs-src/guide/terrain.md +84 -9
  25. package/dist/docs-src/guide/vehicle-interiors.md +6 -0
  26. package/dist/docs-src/guide/vehicles.md +368 -45
  27. package/dist/docs-src/guide/weather.md +7 -1
  28. package/dist/docs-src/guide/worldgen.md +82 -3
  29. package/dist/docs-src/llms.txt +3 -2
  30. package/dist/docs-src/schemas/README.md +1 -0
  31. package/dist/docs-src/schemas/components.md +749 -12
  32. package/dist/docs-src/schemas/figure.md +30 -4
  33. package/dist/docs-src/schemas/interior-catalog.md +56 -3
  34. package/dist/docs-src/schemas/map-overrides.md +658 -0
  35. package/dist/docs-src/schemas/structure-placement-data.md +195 -0
  36. package/dist/docs-src/schemas/structure-placements.md +195 -0
  37. package/dist/docs-src/schemas/worldgen-batch.md +54 -0
  38. package/dist/templates/city-courier/gen/molen-types.ts +113 -4
  39. package/dist/templates/city-courier/scripts/molen-scripts.d.ts +112 -3
  40. package/dist/templates/figures-gallery/test/headless.test.ts +3 -2
  41. package/dist/templates/index.json +17 -17
  42. package/dist/templates/skybound/gen/molen-types.ts +113 -4
  43. package/dist/templates/skybound/scripts/molen-scripts.d.ts +112 -3
  44. package/dist/templates/top-down-arena/scripts/molen-scripts.d.ts +112 -3
  45. package/dist/templates/top-down-arena/src/gen/molen-types.ts +113 -4
  46. package/package.json +12 -12
@@ -0,0 +1,231 @@
1
+ # Snow cover
2
+
3
+ Snow lying on the ground is part of the [weather](weather.md): a `snowCover` block on the
4
+ singleton `weather` component names a snow line, and everything above it is under snow. The
5
+ ground whitens, roofs and trees take a dusting, people wade, cars lose their grip and bog down,
6
+ and skis, a snowboard and a snowmobile come into their own. One value drives the simulation and
7
+ the picture, so they agree.
8
+
9
+ ```json
10
+ {
11
+ "id": "conditions",
12
+ "components": {
13
+ "weather": {
14
+ "snowCover": { "level": 1000 }
15
+ }
16
+ }
17
+ }
18
+ ```
19
+
20
+ Lying snow is independent of falling snow. `precipitation.kind: "snow"` draws flakes in the air;
21
+ `snowCover` is what is on the ground, on a clear day as much as in a storm. Leave `snowCover`
22
+ out and the ground is bare.
23
+
24
+ ## The snow line and the depth
25
+
26
+ | Field | Meaning |
27
+ | --- | --- |
28
+ | `level` | The snow line: absolute world Y in meters where lying snow begins. In an Earth view world Y is meters above sea level. Required. |
29
+ | `transition` | Height above the line over which cover builds from none to complete; default 150 m. Zero is a hard line. |
30
+ | `depth` | Depth where cover becomes complete, at the top of the transition; default 0.15 m. |
31
+ | `depthGain` | Extra depth for each 1000 m of height above that; default 0.6 m. |
32
+ | `maxDepth` | Greatest depth at any height; default 1.5 m. |
33
+
34
+ With the defaults and a line at 1000 m, ground at 1075 m is half covered and 7 cm deep, ground
35
+ at 1150 m is covered 15 cm deep, and at 2150 m the snow is 75 cm deep. A line below the lowest
36
+ ground with `transition: 0` covers everything evenly.
37
+
38
+ `snowCoverAt(cover, altitude)` from `@bendyline/molen-schema` returns `{ coverage, depth }` at a
39
+ height, `resolveSnowCover` fills in the defaults, and `resolveWeather(data).snowCover` is present
40
+ only while snow lies. The function uses arithmetic alone, so the kernel, a script and a renderer
41
+ get the same answer bit for bit:
42
+
43
+ ```ts
44
+ import { snowCoverAt } from '@bendyline/molen-schema';
45
+
46
+ const { coverage, depth } = snowCoverAt({ level: 1000 }, 1400);
47
+ // coverage 1, depth 0.3
48
+ ```
49
+
50
+ A script changes it like any weather: `molen.patch('conditions', 'weather', { snowCover: { level: 600 } })`.
51
+ It is in state hashes, checkpoints and replays with the rest of the component.
52
+
53
+ ## What it does to movement
54
+
55
+ ### On foot
56
+
57
+ `snowWalkingPace(depth)` is the share of a person's pace left in snow that deep: all of it up
58
+ to boot-sole depth, about 70% at 30 cm, 40% from 60 cm on. `WalkController.paceAt` takes
59
+ a function of the feet's position and applies it to walking and running (never swimming):
60
+
61
+ ```ts
62
+ import { snowCoverAt, snowWalkingPace } from '@bendyline/molen-schema';
63
+
64
+ walker.paceAt = (_x, y) => snowWalkingPace(snowCoverAt(weather.snowCover, y).depth);
65
+ ```
66
+
67
+ [Ambient pedestrians](ambient-life.md) slow the same way from the world's weather, on half the
68
+ depth: a footway is trodden down. In an Earth view the walker and the host's actors are wired
69
+ already (see [below](#in-an-earth-view)).
70
+
71
+ ### On wheels
72
+
73
+ `installVehicles` reads the world's weather, so a car needs nothing more. Under snow:
74
+
75
+ - **Grip** falls toward the `snow` surface's 0.35 of dry pavement as cover builds (`looseSurfaceGrip`
76
+ wins some back). Snow falling onto lying snow costs at most 15% more.
77
+ - **Depth drags.** Within a few centimeters it is the rolling resistance of any soft ground.
78
+ Deeper, the wheels plough and the floor drags: the drag grows with the square of the depth
79
+ against the wheel's size, about 3 m/s² where the snow reaches 60% of the wheel's radius.
80
+ `snowDrag(depth, wheelRadius, tread)` returns both parts.
81
+ - **A car can be stuck.** Below a crawl, what the tires and the slope give has to beat the whole
82
+ of that drag, or the car stays where it is: `vehicleState.stuck` is true while the driver is
83
+ asking for drive and getting none. On untouched snow the stock sedan is held at 13 cm, the
84
+ all-wheel-drive SUV at 22 cm and the off-roader on its tread at 33 cm; on a ploughed road the
85
+ sedan keeps going until the snow beside it is 40 cm deep. A car that leaves the road at speed
86
+ ploughs on for a few lengths first.
87
+ - **Roads are ploughed.** A [surface](vehicles.md#surfaces) may say how much of the snow it
88
+ keeps: `VehicleSurface.snow`, 0.3 for the paved stock surfaces (`asphalt`, `concrete`, `paved`,
89
+ `stone`, `wood`, `metal`) and 1 for open ground and for a world with no surface callback.
90
+
91
+ `vehicleState.snowDepth` is the depth under the vehicle, absent on bare ground, and
92
+ `vehicleState.surfaceGrip` reports the grip whether or not a host names surfaces.
93
+
94
+ ### On runners
95
+
96
+ `vehicle.spec.runners` is for what slides: skis, a snowboard, a snowmobile's skis and track.
97
+
98
+ ```json
99
+ "runners": { "friction": 0.05, "bareDrag": 3.5, "pushSpeed": 4.5, "flat": true }
100
+ ```
101
+
102
+ | Field | Meaning |
103
+ | --- | --- |
104
+ | `friction` | Sliding friction coefficient on snow; it resists as `friction` × g. About 0.05 for waxed skis, 0.12 for a snowmobile's track. |
105
+ | `bareDrag` | Resistance in m/s² off the snow, where runners scrape bare ground; default 3. |
106
+ | `pushSpeed` | Fastest the rider's own pushing drives it; gravity may take it on to `maxSpeed`. Absent, `engineForce` works up to `maxSpeed`. |
107
+ | `flat` | A cycle whose runners stay flat on the snow in a turn (a pair of skis) instead of banking as one plank (a snowboard). The lean stays in `vehicleState.bodyRoll` for the rider's pose. |
108
+
109
+ On lying snow a vehicle with runners keeps its full `grip` (edges and paddles bite), floats over
110
+ any depth, and is never stuck. Friction is Coulomb friction: it holds the vehicle on a slope too
111
+ gentle to beat it (about 3° for skis) and lets go on a steeper one, so skis pointed downhill
112
+ start by themselves unless the brake is on, accelerate under gravity along the slope, and settle
113
+ at the speed where air drag and friction balance it. Across the slope the edges hold a traverse.
114
+ Off the snow, runners scrape to a stop.
115
+
116
+ A cycle on runners also lies on the slope across it, where a wheeled cycle balances upright on
117
+ its tire line: `vehicleState.roll` follows the ground under the skis, and the standing rider's
118
+ pose stays plumb over them.
119
+
120
+ ## The three rides
121
+
122
+ The `molen.entities` pack carries three types, drivable through `installVehicles` like any
123
+ [vehicle](vehicles.md):
124
+
125
+ | Type | What it is | Controls |
126
+ | --- | --- | --- |
127
+ | `molen.entities.cycle.skis` | A pair of 1.70 m all-mountain skis with bindings and two poles. The rider stands over them with a hand on each pole. | Point downhill to slide. Steering carves. Brake, or back on the throttle, stops on the edges. Throttle poles along the flat to 4.5 m/s. |
128
+ | `molen.entities.cycle.snowboard` | A 1.56 m twin-tip board with strap bindings. The rider stands across it, left foot forward. | As skis; the board banks into its turns, and throttle skates it along the flat to 3.5 m/s. |
129
+ | `molen.entities.vehicle.snowmobile` | A two-up trail sled: a lugged track, two steered skis, handlebars, a headlamp. | Throttle and brake as a car, reverse included. It floats over snow a car is stuck in, and drags on bare ground. |
130
+
131
+ On a 25° slope the skis reach about 105 km/h; their hard limit is `maxSpeed`, 38 m/s. The poles
132
+ stand planted at rest and swing back in the hands once moving. None of the three joins traffic
133
+ or parks on streets.
134
+
135
+ ## Rendering
136
+
137
+ The renderer needs only the weather. `renderer.setWeather(data)` (the normal client mirrors the
138
+ component by itself) hands the snow line to every material that takes snow, on WebGL and WebGPU,
139
+ and changing or clearing it never rebuilds a shader.
140
+
141
+ - **Marked materials** take a dusting on what faces the sky: `enableSnowCover(material, amount,
142
+ facing)` from `@bendyline/molen-client/snow` marks a lit material once. `amount` (0–1) thins
143
+ the dusting, and `facing` is the range of the surface normal's up component over which a
144
+ face goes from bare to dusted: by default `[0.3, 0.75]`, so flat roofs are white and walls
145
+ stay clean. The `@bendyline/molen-worldgen` material sets mark generated buildings (roofs,
146
+ ledges and sills whiten, glass does not), landmark models, and the scatter material for
147
+ trees, shrubs and props, where the dusting is thinner so foliage still shows and reaches
148
+ down steeper faces (`[-0.05, 0.55]`), so a conifer's tiers carry snow. Parked cars and the
149
+ painted shell of a car you drive are marked too. Mark your own models the same way; leave
150
+ out anything that moves through the weather, such as an aircraft or a person.
151
+ - **Terrain ground and paving** draw their own snow. `setTerrainGroundSnow(material, snowCover,
152
+ worldOriginY)` from `@bendyline/molen-terrain/client` works on the materials from
153
+ `createTerrainGroundMaterialAsync` and `createTerrainPavementMaterialAsync`: open ground
154
+ whitens in patches through the transition and completely above it, faces steeper than about
155
+ 58° shed it and show rock, and roads keep worn, greyer snow with the paving showing through.
156
+ Up close the snow surface has wind drifts a few meters long, which the sun and the sky's
157
+ light model: crests bright, hollows a little bluer.
158
+
159
+ The line is one function of world position on every surface, so a roof and the ground under it
160
+ agree on where the snow begins. It wanders by up to a third of the transition with broad noise,
161
+ so it does not follow a contour like a tide mark; the simulation uses the smooth line.
162
+
163
+ Trees do not stop at the snow line; they stop at the tree line. The Earth tile adapter thins
164
+ mountain forest out over the last 350 m below a latitude-dependent alpine tree line (about
165
+ 2,250 m at Mount Rainier, 3,900 m in the tropics, lower in the southern hemisphere), so glaciers
166
+ and summits are bare whatever the snow level. See [regional world content](regional-world.md).
167
+
168
+ ## In an Earth view
169
+
170
+ `mountEarthView` takes the weather at mount and changes it at once:
171
+
172
+ ```ts
173
+ const view = await mountEarthView({
174
+ canvas,
175
+ terrain,
176
+ baseUrl,
177
+ content,
178
+ weather: { snowCover: { level: 2000 } },
179
+ });
180
+
181
+ view.setWeather({ ...view.weather, snowCover: { level: 500 } }); // a winter storm reaches town
182
+ view.setWeather(undefined); // clear skies, bare ground
183
+ ```
184
+
185
+ That one call reaches the sky, the view's simulation (so cars slip and bog down and runners
186
+ glide), its ground and paving materials, the walker's pace and the pace of the host's
187
+ [actors](earth-view.md#actors-companions-and-npcs). On mapped roads and footways the walker and
188
+ cars meet the ploughed depth; off them, and where the map is empty, the full depth.
189
+ `view.vehicleStatus()` adds `snowDepth` and `stuck` for a car, and `EarthVehicles.snow` reports
190
+ the same for a host composing its own view, where `createSnowPace` builds the walker's
191
+ `paceAt`.
192
+
193
+ Put the viewer on skis as on any ride:
194
+
195
+ ```ts
196
+ view.setMode('drive', { vehicle: 'molen.entities.cycle.skis', force: true });
197
+ ```
198
+
199
+ ## World explorer
200
+
201
+ The Weather panel has a **Snow level** list: no snow, everywhere, sea level, and lines from
202
+ 250 m to 4,000 m. `?snow=1500` sets a line in meters, `?snow=all` covers everything and
203
+ `?snow=off` clears it. Each region can open on a line of its own: the Seattle region, which
204
+ reaches east over the Cascade crest and south past Mount Rainier (4,392 m), opens with snow
205
+ above 2,000 m, as the mountain's glaciers keep it all year.
206
+
207
+ On foot on lying snow, **P** takes skis, then a snowboard, then a snowmobile from the bag (on
208
+ bare ground it is still the skateboard and scooter). `?ride=skis` starts on them, so this link
209
+ drops you onto the Muir Snowfield pointed downhill:
210
+
211
+ ```text
212
+ https://molen.dev/play/world-explorer/?lat=46.822&lon=-121.728&yaw=1.57&navigation=walk&ride=skis&mode=human&weather=sunny
213
+ ```
214
+
215
+ The status line shows the snow depth under the ride and says when a car is stuck.
216
+
217
+ ## Limits
218
+
219
+ - Snow does not fall and build up, melt, drift or avalanche. The cover is authored: move the
220
+ line to change it.
221
+ - The depth depends on height alone. Aspect, wind and forest shelter do not change it, and
222
+ only the surface under a vehicle or walker tells a ploughed road from open ground.
223
+ - A stuck car stays stuck: step out and walk, or bring a snowmobile. There is no digging out,
224
+ no chains and no winter tires beyond `looseSurfaceGrip`.
225
+ - Lakes do not freeze, and no tracks are left in the snow.
226
+ - The dusting on marked materials follows the surface's facing, not what overhangs it: a
227
+ covered porch floor whitens with the roof above it.
228
+ - Skiing is a grounded glide: no jumps, falls, moguls or lifts. Ambient traffic drives on at
229
+ its usual pace.
230
+ - World Explorer draws no rider (it has no avatar), so its skis run without a skier in the
231
+ chase view; an Earth view with a walker avatar draws one.
@@ -107,10 +107,14 @@ setTerrainGroundOrigin(pavement, [worldOrigin[0], worldOrigin[2]]);
107
107
 
108
108
  The material reads a `surfaceDetail` attribute the surface builder writes on every road, sidewalk,
109
109
  curb, marking and lot: meters along the band, meters across it from its edge, the surface kind
110
- and band width, and a road's lane width. Roads and lots get asphalt aggregate (within a few meters,
111
- crisp pale chips and dark pits a few centimeters across), blotchy wear, polished wheel
112
- tracks and an oil line in each lane, grit in the gutters, storm-drain grates, manhole covers and
113
- the odd darker repaired section; asphalt and concrete both get hairline cracks; lots get oil
110
+ and band width, and a road's lane width and wear grade. Roads and lots get asphalt aggregate
111
+ (within a few meters, crisp pale chips and dark pits a few centimeters across), blotchy wear,
112
+ polished wheel tracks and an oil line in each lane, grit in the gutters, storm-drain grates,
113
+ manhole covers and the odd darker repaired section; asphalt and concrete both get hairline cracks.
114
+ Worn roads also get potholes in the wheel tracks, each with a ragged lip and a halo of alligator
115
+ cracking, plus more patches and cracks: none on freeways, trunk and primary roads (grade 0), a few
116
+ on secondary and tertiary roads (1), more on residential streets (2) and most on service roads and
117
+ alleys (3). A band sets its grade with `wear` beside `lanes`; lots get oil
114
118
  stains; sidewalks and footways get 1.5 m saw-cut slabs and curbs 3 m ones, each slab its own
115
119
  tone, weathered with water stains and, close up, the odd spot of gum; plazas and pedestrian areas get a half-meter paver grid; markings wear through to the
116
120
  asphalt. Detail fades to the plain swatch with distance, so it never shimmers, and each layer's
@@ -159,6 +163,45 @@ Curbs are a step, not a stripe: a 15 cm vertical face drops from the curb's road
159
163
  asphalt, split finer than the ground grid so it follows the draped ground, and jointed like the curb top.
160
164
  Any draped band can have one with `riser` (meters) on its `TerrainLineBand`.
161
165
 
166
+ Markings follow US practice (MUTCD), with center lines yellow where the sign profile's countries
167
+ use yellow (the Americas and Korea) and white elsewhere. Lines are about 11 cm wide (edge lines
168
+ 15 cm), and broken lines are 3 m of paint in every 12 m.
169
+
170
+ - **Center lines:** residential streets have none unless mapped with `lanes`. Multilane roads and
171
+ city arterials get a double solid line. A two-lane country road gets a broken line where passing
172
+ is allowed, and a double line round curves (more than about 11° of turn over 90 m), within 60 m
173
+ of a junction, on bridges, and in passing zones too short to use (under about 120 m). Roads with
174
+ an odd lane count get a two-way left-turn lane down the middle: each edge is solid on the
175
+ outside and broken toward the turn lane.
176
+ - **Lane and edge lines:** white broken lines separate lanes going the same way, turning solid over
177
+ the last 30 m into a signal. Lane counts match the traffic simulation's. Edge lines run along
178
+ freeways and ramps (yellow on a one-way carriageway's left), country roads, and city arterials at
179
+ least 8 m wide.
180
+ - **Junctions:** marked crosswalks (high-visibility bars, laddered with transverse lines at
181
+ signals) cross every arm of a signal. At stop or yield signs they appear only where an arterial
182
+ meets the junction or at a mapped all-way stop. Where two quiet streets meet, the corner stays
183
+ unmarked. Stop lines stand about 1.2 m short of a crosswalk, yield lines are rows of triangles,
184
+ and signal approaches with two or more lanes get lane arrows. Lines run up to the stop line or
185
+ crosswalk, or to the crossing road's edge. A road with the right of way past side streets that
186
+ join from one side only (a tee) keeps its center line across their mouths, and its edge line
187
+ breaks only where each side street meets it. Where a track crosses a road, a crossing panel
188
+ carries the rails across it (see [Railways](#railways)).
189
+
190
+ Sidewalks follow built-up frontage, not every street. Stations every 10 m along a street look for
191
+ buildings within about 70 m (five for an arterial, eight otherwise) or mapped commercial or retail
192
+ land. A sidewalk then runs about 40 m past the last house, bridges gaps under about 120 m, and
193
+ skips stretches shorter than about 80 m. A tile without building footprints reads mapped
194
+ residential land as built up, and a tile with no land data at all keeps sidewalks on every street.
195
+ Where a sidewalk mapped as its own footway runs alongside a street, the inferred one on that side
196
+ is left out (the curb stays). Streetlights, poles, hydrants and mailboxes stand only where there is
197
+ a sidewalk. Living streets have none.
198
+
199
+ Where a road continues into another feature (for example where its tags change at a bridge's
200
+ end), the two lines' ends share a miter (`TerrainLinePath.startJoin` and `endJoin`), so their
201
+ bands meet on one seam instead of leaving a wedge on the outside of the bend. Paint is drawn a few
202
+ centimeters above the asphalt and is marked `walkIgnore`, so walkers and cars do not collide with
203
+ it.
204
+
162
205
  Styles with streetlights also furnish their blocks: utility poles every 38 m on one side of each
163
206
  street with sidewalks, set back behind the sidewalk with a crossarm and a pair of sagging lines
164
207
  between neighbors, and a hydrant at the other curb about every 100 m. Residential streets that
@@ -253,9 +296,10 @@ The decoder preserves road `subclass`, `service`, `link` (including Protomaps `i
253
296
  and explicit `width`. Properties absent from the source use class-based defaults. Tunnel roads are
254
297
  excluded from the ground painter; Earth views add separate underground bores as described below.
255
298
  Bridges and differing layers do not form surface junctions. Tagged bridges receive inferred
256
- decks, slabs, barriers and supports. Motorway spans retain clearance through their ends;
257
- connected approaches ease back to terrain over the surrounding road fragments, with retaining
258
- sides below raised pavement. Curved profiles follow distance along the mapped road. Barriers
299
+ decks, slabs, barriers and supports, at heights that clear whatever they cross (see
300
+ [Road grading](#road-grading)). A deck that reaches its end still raised hands the rest of the
301
+ descent to the roads joined to it there, which climb on retaining walls with a parapet along
302
+ any drop of a meter or more. Curved profiles follow distance along the mapped road. Barriers
259
303
  sit outside paved shoulders and open at merges where the adjoining carriageway is at the same
260
304
  height; edge paint also clears these openings. Traffic uses the same grading samples.
261
305
  Surveyed deck heights and authored bridge connections take precedence. Inferred grades depend
@@ -310,6 +354,9 @@ this change does not add a full-stop/dwell simulation for the decorative signs.
310
354
  Ground surfaces render at all available semantic levels. Fine markings and fixtures default to
311
355
  the finest pyramid level; `detailLevelsBelowMax` extends them to coarser levels. Fixture/car and
312
356
  detail-work budgets bound each tile. A portion of the detail budget is reserved for parking.
357
+ `maxDetailElements` counts the quads drawn for sidewalks, curbs and paint (dash gaps cost
358
+ nothing), and roads are furnished in order of importance: freeways and arterials first, so on a
359
+ tile that runs out the side streets go without, not the main roads.
313
360
  Geometry is batched by surface role, broad land-cover meshes share indexed vertices, and fixture/car parts are instanced. Stats cover resident
314
361
  surface tiles, including temporarily hidden tiles.
315
362
 
@@ -327,6 +374,151 @@ Protomaps deliberately includes a subset of OSM features. Its documented `landus
327
374
  kinds do not currently include parking, while roads may carry `parking_aisle` detail.
328
375
  See the [Protomaps layer reference](https://docs.protomaps.com/basemaps/layers).
329
376
 
377
+ ### Parking garages
378
+
379
+ The same archive identifies multi-storey car parks, though it drops `building=parking` and
380
+ `parking=multi-storey`. A `parking` POI keeps the source id of its OSM element, so a footprint that
381
+ shares its id is one element tagged both `building=*` and `amenity=parking`. Failing that, a POI
382
+ inside exactly one footprint counts if its name claims a structure ("garage", "car park",
383
+ "Parkhaus", "立体駐車場"), since an unnamed one is as likely a tower's basement. Footprints under
384
+ 450 m² or over 48 m tall are left alone: small roofed lots, and towers with parking in them.
385
+
386
+ Height gives the number of decks: Protomaps derives a missing height as `3 × levels + 2`, so
387
+ `(height - 2) / 3` recovers `building:levels`. An unmapped height is assumed to be three decks.
388
+ `parking_entrance` POIs within 6 m of the walls place the doors. `applyParkingStructure` then
389
+ requests the `molen.worldgen.use.parking_garage` style and modeled decks, ramps and cars; see
390
+ [Inferred building interiors](building-interiors.md#car-parks). A style pack without that style
391
+ keeps its usual architecture.
392
+
393
+ ## Building use
394
+
395
+ Stock Protomaps footprints say only `building`. `kind_detail` is empty on all of them, and in the
396
+ regional archives between 3% and 22% carry a height. So the use of a building is argued from what
397
+ surrounds it, strongest evidence first:
398
+
399
+ 1. A POI with the footprint's source id is the same OSM element, so the building is that thing: a
400
+ `hotel`, `school`, `place_of_worship`, `fire_station` and so on.
401
+ 2. A POI inside exactly one footprint names it when it is an institution (`hotel`, `hospital`,
402
+ `school`, `mall`, `library`, `museum`). A cinema or a chapel inside a tower does not.
403
+ 3. Eight or more shops and restaurants in a footprint of 5,000 m² or more make a mall.
404
+ 4. The land use under it: `school`, `university`, `college` and `hospital` land.
405
+ 5. Its shape on that land: at 15 m or more on `commercial` land it is offices, at 12 m or more on
406
+ `residential` land it is flats, at 45 m or more a tower, and at 60 m or more on anything but
407
+ residential land a skyscraper.
408
+
409
+ `associateBuildingUses` returns the use and which of these decided it, and `applyBuildingUse` puts
410
+ the use ahead of any tenant in the interior's labels, so a cafe in the lobby does not make the tower
411
+ a cafe. It also requests a matching style from the `molen.worldgen.use.*` family, and a style pack
412
+ without one keeps its usual architecture. Styles in that family are chosen by a building's use, so
413
+ they are not part of the [structure library](structure-library.md).
414
+
415
+ Everything else, most buildings by far, stays with the style rules. Use
416
+ `?synthetic=1&uses=1` in world explorer for a street with one of each.
417
+
418
+ ## Road grading
419
+
420
+ A digital elevation model is sampled every ten meters or so and knows nothing of roads, and
421
+ many basemaps keep neither a bridge's height nor the OpenStreetMap `layer` tag that says which
422
+ of two crossing bridges is on top. Draped as mapped, a street tilts with every hillside it runs
423
+ along and ripples with the samples, and every bridge of an interchange stands at one height,
424
+ through the others. Two passes put that right. World explorer and `mountEarthView` run both by
425
+ default; compare with `?roadGrading=0` (neither) or `?earthworks=0` (bridges only).
426
+
427
+ ### Leveled ground
428
+
429
+ The ground is graded for roads the way it is for an airfield, before the terrain is meshed, so
430
+ the terrain, everything draped on it and everything that drives on it agree:
431
+
432
+ - **Profile.** A road's height at a point is the elevation averaged 30 m either way along the
433
+ road's own direction, weighted toward the point: bumps shorter than a block go, the hill
434
+ stays. It is read from one elevation level, two below the finest (about the resolution
435
+ elevation is surveyed at), so every tile and every level of detail gets the same answer.
436
+ - **Cross-section.** The road is level from edge to edge at that height: the carriageway with
437
+ its curbs and sidewalks, a freeway with its shoulders, a track with its ballast.
438
+ - **Bench.** A road draped on the ground grid is only as level as the grid vertices around
439
+ it, so the level ground reaches 1.25 grid cells past the road's edge. Beyond that it blends
440
+ back to the surveyed ground over 1.6 cells (at least 8 m). At High detail that is about 16 m
441
+ and 21 m; at Ultra, half as much.
442
+ - **Between roads** the nearest one decides. Two streets on one slope each keep their own
443
+ bench and the block between them takes up the difference, as a graded city block does.
444
+ - Bridges and tunnels are not graded for (the ground under a deck is the river's or the lower
445
+ road's), nor are footpaths, which take the ground as they find it. Mapped water keeps its
446
+ bed beside a road. No point moves more than 12 m.
447
+
448
+ Grading runs for the two finest feature levels, where the rendered grid is no coarser than
449
+ 28 m between vertices; coarser tiles are seen from too far to tell. Adjacent tiles agree on
450
+ their shared edge exactly: each reads the roads of the eight tiles around it as well as its
451
+ own.
452
+
453
+ ### Clearance
454
+
455
+ Every inferred bridge gets a height profile, and so does every road that has to climb to one:
456
+
457
+ - A deck meets the roads at its ends where they stand and spans straight between them. Over
458
+ ground with nothing mapped beneath it (water, mostly) it rises toward 6 m, 3 m for a
459
+ footbridge, no faster than its class of road climbs.
460
+ - Where it crosses another way without sharing a vertex, it clears that way's surface by a
461
+ clear height plus 1.4 m of girder and slab: **6.5 m over a road** (5.1 m clear, the 16 ft
462
+ 9 in of US practice and well over the 14 ft legal minimum), **8.4 m over a railway** (7 m
463
+ clear, for double-stack trains and wires) and **4.4 m over a footpath**. The height holds
464
+ across the lower way's whole width.
465
+ - Two bridges that cross are stacked. The mapped `layer` decides which is on top when the
466
+ source keeps it. Otherwise: the deck whose span already stands 3 m or more above the
467
+ other's (a bridge between two hilltops is over a ramp in the valley); else by what they
468
+ carry (ramps over streets, streets over freeway carriageways and railways); else the one
469
+ farther along its structure from where it lands; else the one running more nearly north
470
+ and south. Only the two structures near the crossing enter into it, so every tile that
471
+ sees the crossing decides alike.
472
+ - A deck falls away from a crossing no faster than its class allows: 5% for a freeway, 7% for
473
+ its ramps, 6 to 8% for streets, 10% for service roads and footpaths, 3% for heavy rail and
474
+ as stairs do for steps. Breaks in grade are rounded over about 20 m.
475
+ - A road climbing to a structure lies on the ground wherever that same structure passes over
476
+ it: an approach never lifts what its own bridge has to clear. Lift passes down the ranks
477
+ only, so a footbridge's steps come down to the street and the street does not rise to the
478
+ footbridge; a footpath beside a climbing road rides on its embankment.
479
+ - Decks side by side (twin carriageways, a sidewalk mapped along a road bridge) stand level
480
+ with each other.
481
+
482
+ A vertex shared by a bridge and a road beneath it is taken for a junction or a mapper's tie,
483
+ never a flyover, and a way's end lying on another way is joined to it even where the tile
484
+ dropped the shared vertex. Surveyed deck heights and authored bridge connections are left
485
+ alone. The stacking order where nothing is mapped is an inference that produces a buildable
486
+ interchange, not a survey of the real one.
487
+
488
+ ### Using it
489
+
490
+ `createTerrainPackageSemanticLayers` wires both passes with one option and hands back the
491
+ ground transform for the stream:
492
+
493
+ ```ts
494
+ const semantic = await createProfiledTerrainPackageSemanticLayers(pkg, {
495
+ roadGrading: { heights: elevationSource }, // the stream's elevation source
496
+ featuresLayer: { renderer },
497
+ });
498
+ const stream = await createTerrainPackagePyramidStream(pkg, {
499
+ layers: semantic.layers,
500
+ ...(semantic.roadGrading
501
+ ? { transformHeightfield: semantic.roadGrading.transformHeightfield }
502
+ : {}),
503
+ });
504
+ ```
505
+
506
+ Pass `earthworks: false` to keep the ground as surveyed, and `maxSpacing` to change the
507
+ coarsest grid that is leveled. A host with its own transform (an airport's leveling) applies
508
+ the road grading first; `composeEarthGroundGrading(roads, airports)` from
509
+ `@bendyline/molen-earth/client` does that. The pieces are public for custom hosts:
510
+ `createTerrainRoadGrading` and `withTerrainRoadGrading` (client), and the pure
511
+ `gradeRoadEarthworks`, `roadProfileHeight` and `gradeTransportSeparations` (kernel), which need
512
+ neither three.js nor a tile stream.
513
+
514
+ Without the option, each tile's bridges are still graded from that tile alone, with the same
515
+ clearances. A bridge cut by a tile edge then cannot see what it crosses in the next tile and
516
+ assumes a free clearance at the cut.
517
+
518
+ Both passes run on the main thread in slices of about 2 ms, so a tile arriving under a fast
519
+ camera does not hold a frame. A town tile's earthworks take 3 to 10 ms in all; an
520
+ interchange and its surroundings, 15 to 35 ms.
521
+
330
522
  ## Tunnels
331
523
 
332
524
  World explorer and `mountEarthView` render mapped `tunnel: true` corridors in Human mode.
@@ -363,6 +555,129 @@ returns a visible bore's floor and ceiling in the root's coordinate frame. Obser
363
555
  ceiling continue using the surface height. Static hosts can use `createTerrainTunnelObject`
364
556
  with complete route lines and a ground sampler that covers both portals.
365
557
 
558
+ ## Railways
559
+
560
+ Railway lines in the transportation layer (a `class`, `subclass` or `service` that names rail,
561
+ tram or train) are drawn as track rather than as roads, by the same surface renderer and worker.
562
+ Everything below is inferred from the map's classes and points and placed by fixed rules, so a
563
+ tile draws the same railway on every load and neighboring tiles agree.
564
+
565
+ - **Track beds.** Each track is a ballast band as wide as its sleepers plus a shoulder each side:
566
+ about 3.6 m on a main line, 3.3 m on a siding and 3 m on yard, spur and crossover tracks. Main
567
+ lines and sidings in the open stand on a prism whose shoulders slope about a meter down to the
568
+ ground wherever no other track runs alongside. Yard ballast is darker and browner, and mapped
569
+ railway land (the `railway` land use of yards and corridors) is ballast grey rather than lawn.
570
+ - **Sleepers and rails in the pavement material.** A track band is `TERRAIN_SURFACE_KIND.track`.
571
+ With the pavement material (see [Pavement material](#pavement-material)) it draws sleepers and a
572
+ pair of rails across the band's middle: concrete sleepers every 0.6 m on main lines and light
573
+ rail, timber every 0.52 m on sidings, yards, spurs, heritage and disused track, and rails at the
574
+ track's gauge with a polished head over a rusty web and foot. Both are box-filtered, so they stay
575
+ antialiased at every distance and settle, as they shrink below a pixel, to the averaged dark
576
+ stripe a track makes in an aerial photograph: a yard reads from the air as many parallel tracks
577
+ on grey ballast. Track is standard gauge unless the style's `railGauge` gives the region's
578
+ main-line gauge (1.067 m for Japan's conventional lines, 1.676 m for India's); light rail,
579
+ trams, subways and lines named as Shinkansen stay standard gauge, and lines mapped as
580
+ `narrow_gauge` are 1 m.
581
+ - **Rails in 3D.** On the finest tiles each rail is also modeled: a 72 mm polished steel head on a
582
+ rusty web 0.17 m deep, its head `TERRAIN_RAIL_HEIGHT` (0.21 m) above the ballast top. Rails run
583
+ on unbroken through level crossings and over bridges and stay out of walking and driving
584
+ collision. They are `TERRAIN_SURFACE_KIND.rail`: the pavement material polishes the heads and
585
+ drops a rail wherever it would be under about a pixel and a half wide, where the track's drawn
586
+ rails beneath it take over, so a yard seen from a plane never sparkles with broken rails. Rails
587
+ and wires also stop drawing for tiles more than 260 m (rails) or 200 m (wires) away, counting
588
+ the camera's height above the ground as well as its distance.
589
+ - **Level crossings.** Where a road crosses tracks on the same layer, neither on a bridge nor in a
590
+ tunnel, a concrete panel level with the rail heads covers the crossing, with short ramps down to
591
+ the road; tracks within 30 m of each other along one road share one crossing. A main line or
592
+ siding crossing a public road gets active warning: a crossbuck (R15-1) with a plate counting the
593
+ tracks (R15-2P) when there is more than one, a pair of flashing lights (dark until a train
594
+ comes), a raised gate arm on roads at least 5 m wide, and an equipment house beside the track.
595
+ Yard, spur and service-road crossings get crossbucks only, and disused track nothing. Each
596
+ approach also gets an advance warning sign 45 to 75 m up the road: the round yellow W10-1 in the
597
+ United States, Canada and Mexico, a red-bordered triangle elsewhere. Signs stand on the side the region's sign profile
598
+ drives on, and a one-way carriageway has a single approach.
599
+ - **Turnouts.** Where a track's end meets another track's side at a shallow angle, where three or
600
+ more track ends meet, and at mapped `switch` points, a turnout gets a powered switch machine on a
601
+ main line or a hand-thrown stand with its target and lamp elsewhere, beside the points and
602
+ opposite the diverging track. Mapped `buffer_stop` and `derail` points get a buffer stop across
603
+ the track's end and a yellow derail on its rail.
604
+ - **Signals.** Mapped `signal` points become color-light signals: a mast with three lenses on main
605
+ lines, a dwarf signal beside yard, siding and tram tracks, and a signal bridge where three or
606
+ more stand abreast over parallel tracks. Map data keeps no direction, so a signal faces the
607
+ trains heading toward the nearest turnout it stands short of, or governs the trains it is mapped
608
+ to the driving side of. Aspects are mostly green, yellow approaching a junction, and the odd red.
609
+ Each lit lens is a self-lit lamp in one instanced draw per tile; `object.userData.railLamps`
610
+ lists them.
611
+ - **Lineside signs.** Whistle posts ("W") stand 400 m ahead of crossings with active warning on
612
+ main lines, unless another crossing comes first. Mileposts stand at mapped `milestone` points
613
+ and, where none is mapped nearby, wherever a main line crosses a north-south line of a world grid
614
+ a mile apart. "YARD LIMIT" boards stand on a main line about 150 m outside each stretch it runs
615
+ beside yard tracks. Like road signs, they need fonts for their lettering.
616
+ - **Overhead catenary.** `railElectrification` on the surface style (or in `details`, which
617
+ overrides it) decides which tracks are wired: `'light'`, the default, wires light rail, trams
618
+ and subways in the open; `'all'` also wires heavy rail, for regions whose main lines are
619
+ electrified (Japan, India, much of Europe, Sydney's suburban network); `'none'` draws no wires.
620
+ Masts stand about every 60 m on heavy rail, 50 m on light rail and 35 m beside trams, at
621
+ stations fixed in the world so wires run on across tile edges, and on the outside of a pair of
622
+ tracks. Each mast's arms carry a messenger wire sagging between masts, droppers every 5.5 m and
623
+ a level contact wire 5.2 to 5.6 m up, staggered from side to side; street trams carry a single
624
+ contact wire. With WebGL, each wire segment also stops drawing beyond 140 m, where it would be
625
+ far thinner than a pixel.
626
+ - **Platforms.** Mapped `platform` land is a raised slab with walls down to the ground: 0.36 m
627
+ beside light rail and trams, 1 m beside subways, 0.4 m beside heavy rail in North America and
628
+ 0.9 m elsewhere, and curb height with no track within 40 m. Edges that face a track get a yellow
629
+ tactile strip. Platforms on viaducts are left to the viaduct.
630
+ - **Disused lines** keep their track, with rusted rails, weeds through the ballast and the odd
631
+ missing sleeper, but get no signals, crossing equipment or wires.
632
+ - **Rolling stock in yards.** With `details.railCars` (rail vehicle types: specs with a `rail`
633
+ block), yard, siding and spur tracks hold cuts of coupled cars. Freight cars and the odd idle
634
+ locomotive stand on heavy rail, and light-rail cars stand in light-rail yards. A cut is a unit
635
+ train's cars of one kind and paint, or a mixed manifest in blocks. Cuts keep 32 m clear of each
636
+ turnout's points and 14 m clear of road crossings. Tracks are split into blocks at stations fixed
637
+ in the world, about 75 m apart. That way neighbouring tiles, and the coarser tile one level up
638
+ (yards are filled that far out, for the view from the air), agree on which blocks hold cars and
639
+ what they hold. `railCarOccupancy` scales how full they are (default 1: about three yard blocks
640
+ in four, half of the sidings). The cars are ordinary parked-vehicle placements (`kind`, `spec`,
641
+ `color`, standing on the rail heads), drawn with the parked cars when `parkedCars` is on. Far off
642
+ each stands in as a silhouette of its `spec.rail.profile` (`railVehicleProxyGeometry` in
643
+ `@bendyline/molen-client/vehicles`), and a host makes the near ones entities as it does a
644
+ street's.
645
+
646
+ `railEquipment: false` (on the style or in `details`) keeps the beds and rails and drops the
647
+ equipment: signals, switch stands, crossing signs, lights and gates, lineside signs and catenary.
648
+ The Simple surfaces style turns it off.
649
+
650
+ ```ts
651
+ import {
652
+ createTerrainSurfaceRenderer,
653
+ TERRAIN_SURFACE_STYLES,
654
+ } from '@bendyline/molen-terrain/client';
655
+
656
+ // A region whose main lines are electrified and on 1,067 mm gauge.
657
+ const surfaces = createTerrainSurfaceRenderer({
658
+ style: { ...TERRAIN_SURFACE_STYLES.modern, railElectrification: 'all', railGauge: 1.067 },
659
+ });
660
+ // Later: tracks only, no equipment.
661
+ await surfaces.setOptions({ details: { railEquipment: false } });
662
+ ```
663
+
664
+ Equipment has budgets of its own, scaled by `maxFixturesPerTile`: 25 boxes per fixture for
665
+ signals, stands, crossing gear and masts, as many again for wire segments, and up to 48 lineside
666
+ signs a tile. Rails in 3D take up to three quarters of `maxDetailElements`, in segments a few
667
+ meters long. Tracks are furnished most important first: main lines, then light rail, sidings,
668
+ trams, yards and spurs, then disused track. `stats()` counts `railTracks`, `railCrossings`,
669
+ `railSwitches` and `railSignals`. `placeTerrainYardCars` is the yard placement on its own.
670
+ `terrainRailTrack(feature, countries)` (a line's mode, service,
671
+ gauge and sleepers) and `TERRAIN_RAIL_HEIGHT` are exported from `@bendyline/molen-terrain/kernel`
672
+ as well, for anything that must run on the rails the renderer draws.
673
+
674
+ The [Protomaps layer reference](https://docs.protomaps.com/basemaps/layers) keeps a railway's
675
+ `kind_detail` (`rail`, `light_rail`, `tram`, `subway`, `disused` and others) and `service`
676
+ (`yard`, `siding`, `spur`, `crossover`), and its points layer keeps railway nodes: `switch`,
677
+ `signal`, `level_crossing`, `railway_crossing`, `buffer_stop`, `derail` and `milestone`. It keeps
678
+ no electrification, voltage, gauge, signal direction or aspect; those are inferred as described
679
+ above, not surveyed.
680
+
366
681
  ## Lines beyond roads
367
682
 
368
683
  `createTerrainLinearObject(lines, context, profile)` is independent of road semantics. Lines use
@@ -396,8 +711,8 @@ For a utility corridor, use narrow elevated bands and widely spaced pole repeate
396
711
  width across the route, height, and length along it. Band `dash: [length, gap]` and `phase` use
397
712
  world units along the path; callers can carry phase across tile fragments when their source
398
713
  provides route chainage. `terrainLinePath` and `sampleTerrainLine` are exported for custom
399
- attachment/model placement. Railway switches, wire sag and route-level cross-tile topology are
400
- separate consumers of this foundation, and traffic simulation is [ambient life](ambient-life.md).
714
+ attachment/model placement. The surface renderer's [railways](#railways) are built on it, and
715
+ traffic simulation is [ambient life](ambient-life.md).
401
716
 
402
717
  ## Road sign fonts
403
718