Skip to content
Connected RailsConnected Rails

Terrain rendering

From the same DGM, content::terrain builds the terrain meshes — only within the corridor around the line and at graded resolution:

Distance from track Grid spacing Triangles per km²
up to 96 m 4 m 125,000
up to 384 m 8 m 31,000
up to 768 m 16 m 8,000
beyond 32 m 2,000

For comparison: unmodified DGM1 would be 2,000,000 triangles per km². The 4 m at the track is the default; a module may name its own terrain detail (terrain_step: in the line file, the field of the same name in the route editor’s Height data panel, 1 to 16 m) and the coarser levels follow it doubled — 1 m shows a DGM1’s ditches and embankment toes, at sixteen times the vertices in every corridor tile, in the editor as in the run. The height tiles a module carries are written at that spacing by default, so a module set to 1 m imports its DGM at 1 m. The bands above are the run’s, measured from the track, which is where the run’s camera is; the route editor builds by distance from its own camera — the finest level within 700 m per metre of grid spacing (700 m at 1 m, 2.8 km at 4 m), each coarser level twice as far, and a tile is rebuilt at its new level as the camera comes and goes, with a margin so a camera on the edge of a band does not flip it back and forth. The aerial imagery is draped at the same spacing as the mesh, whatever it is. On top of that come 512 m tiles (one entity per tile → frustum culling, plus the view distance limit), skirts at the tile edges against cracks between levels, and a cutting/embankment profile that pulls the terrain near the track up to rail level. The corridor is not the whole ground: a module lists the tiles it carries beyond it (tiles: in the line file — a new module starts with the tiles under its envelope, the route editor’s Terrain tiles tool attaches more by clicking, and the DGM import fills any of them), and a quadtree draws that ground to the horizon: the tiles themselves within the load radius, nodes of 2, 4, 8 … tiles a side above them, each 64 cells a side whatever its size, chosen every frame so that the ground is covered exactly once — a node stands whole beyond one and a half times its own size and splits nearer. The nodes read a coarse overview of the elevation data sampled once per tile, so the far side of a valley costs a few thousand triangles, not a rebuild of its tiles. It is sized like the real thing: the formation (Planum) of a single track reaches 4 m to each side, the embankment or cutting runs from its edge down to the natural ground within 12 m, and edges can be laid without a formation at all (formation: false in the line file) — bare rails on bridges, platforms or ground the builder shaped themselves, with no ballast bed, embankment or gravel strip.

The ground is textured by splatting: per-vertex weights from slope and track distance blend grass, rock and gravel — gravel full on the formation, fading out by 7 m so the embankment slopes stay grass. Trees and scenery objects are line content — every one its own entry, placed by the terrain tile it stands on and spawned as a child of it, so they stream with the ground. A tree is not a scene instance but one entity per mesh part of its model, sharing the part’s mesh and material, so Bevy batches a wood into instanced draws; _LOD nodes become distance bands, and vegetation names its own (lod_distances in the object) scaled to how big the plant is — a 30 m spruce hands from leaf geometry to its whole-tree image at 105 m and is drawn to 2.5 km, while a small blackthorn keeps full detail to at least 45 m and is gone at 700 m.

mods/trees fills them: forty-six trees, shrubs and understorey plants of Central Europe, three individually shaped individuals of each, four levels of detail, and seasonal models. They are optimised from Midge “Mantissa” Sinnaeve’s hand-modelled CC0 tree packs and Poly Haven’s CC0 fir, pine and plant models; tools/trees/import_mantissa.py retains source branches and foliage for the first two levels and bakes multi-view whole-tree impostors only for distances of at least 400 m — see tools/trees/README.md. The route editor’s forest brush mixes them by stand: any tree object tagged stand-mischwald, stand-nadelwald, stand-bahndamm and so on is a member, and a painted wood draws from all of them. tools/trees/bench_forest.mjs measures what a wood costs — the checked 20,000-tree forest over an 8 km line holds 140 fps in a debug build. Tiles are built several at a time — the builder is shared read-only, the DGM sheets keep their own short lock. Terrain, splatting, vegetation and track objects live in world-render and therefore look the same in the simulator and in the route editor.

Parametric buildings use the same streamed terrain path without replacing static scenery. Their route entry keeps an editable recipe (residential, commercial or industrial use, width, length, floor count and height, six roof shapes with overhang and dormers, facade/roof material, colour, window rhythm, shutters and shop fronts, balconies, a cross wing and an annex with their own roofs, plinth, string courses, cornice and corner pilasters, and a stable variation seed). The terrain compiler normalises and bakes that recipe into a compact placement; world-render caches one three-level LOD mesh set per distinct recipe and shares a global PBR library of plaster, red/yellow brick, clinker, sandstone, wood siding, concrete, metal panels, clay and concrete tile, slate, standing seam, corrugated sheet, bitumen and roofing membrane. Halls get a parapet, a skylight grid, solar arrays, a light band and docked loading gates on either long side. Attached bodies are cut into the main roof where it covers them, so wing and annex meet it in clean valleys. Window illumination is chosen deterministically from the seed and appears only at night. Copy/paste preserves the whole recipe and seed, while all fields remain editable in the module editor.

Fields lie on that ground: the outline and the crop are line content, and what a field looks like on the day is a function of the crop, the date and the field’s own seed — winter wheat is blue-green in April, gold in the last week of July and stubble in August, and no two neighbouring fields are cut on the same afternoon. Each terrain tile carries one surface per crop on it, draped on the tile’s own height grid and cut to the track’s formation, so a tile costs one draw call per crop and the whole line costs thirteen materials. Which way each field was worked comes out of its own long axis, and the furrows and the sprayer’s tramlines run along it — the single biggest thing the eye picks up about a field.

The fields themselves come from the state agricultural registers: every EU member state has to publish what its farmers declared, and File ▸ Import fields… in the route editor asks them for the module’s envelope. Six states give the parcel with its crop; six give the field block alone, and the crop is then drawn from the regional cropping statistics, seeded by the parcel’s id — the single field is wrong about as often as the statistics say, and the landscape is right. Rhineland-Palatinate publishes nothing at all, and a module abroad has no German register under it at all; both fall back to OpenStreetMap’s landuse=farmland, which is thinner than a register and share-alike, and the import says so. See Fields in the modding guide for the crop groups, the licences and how to correct a mapping — and cargo run -p app -- --scenario example:boerdefahrt for five kilometres across the Soester Börde with 134 real parcels beside the track, its roads out of OpenStreetMap and the state DGM1 under it. All three imports re-run headless in one command (cargo run -p content --bin import-module -- …), which is how the module is regenerated.

The delivery does not have to be fetched by hand: the route editor’s Height data panel has a Download… that reads the module’s state off its anchor and pulls exactly the DGM1 sheets its tiles need from that state’s open data (eight states hand them out by URL, the others are linked), and import-module --fetch-dgm auto does the same headless.

The app shows the terrain automatically (flat without DGM):

Terminal window
cargo run -p app -- --dgm ./dgm1_niedersachsen --epsg 25832

For a line across the 12° UTM zone boundary, repeat the pair — one elevation source per zone; the n-th --epsg belongs to the n-th --dgm:

Terminal window
cargo run -p app -- --dgm ./dgm1_west --epsg 25832 --dgm ./dgm1_ost --epsg 25833