# `helix scene create city`

> For a Cities: Skylines II map do not run this by hand: `helix city convert cs2` ([city-convert-cs2.md](city-convert-cs2.md)) runs it with the CS2 defaults and every stage around it.

One command from a [`helix.city-source/1`](city-source.md) folder to a sealed, deterministic, perf-gated Scene v2 package that
runs in the HELIX engine (open-world lane 3.8, `SCENE-PIPELINE-DESIGN` section 3.2-3.3).

```bash
helix scene create city --source <city-source-dir> --out <package-dir>
helix scene validate <package-dir> --perf --tier desktop,mobile      # the same gate, read back from disk
```

The package folder is the Scene: `scene.helix-scene.json` (sealed, at most 4 MiB), `pin.json` (`{kind, id, revision, integrity}`,
what an engine shell loads), `scene-plan.json` (the recipe that produced it) and every bundle file at the path its resource
declares. Intermediate output (terrain source, placements, the building chunks, `scene-create-report.json` with timings) goes to
`<out>.work` (`--work`). Nothing is written into the city source except the terrain margin DEM, kept once in `<source>/terrain/margin/` (or `--margin-cache`) so a later run reads the same bytes, online or not.

## What is in it

| Layer | Source | Notes |
|---|---|---|
| Terrain | the source DEM (or its flat plane), resampled exactly onto `frame.boundsXZ`, 2 m per sample (`--terrain-mps`), 512 m tiles, carved under the roads at every LOD stride (see Roads below) | the ground splat is painted from the source's parks, water and areas and, under the roads, from the road generator's own asphalt and pavement roles (`urban` preset over `helix-terrain-materials`); the DEM is the road conform's cut and fill, so the ground sits just below the road surface |
| Terrain margin | the DEM beyond `frame.boundsXZ` (Copernicus GLO-30, fetched once and kept as `margin.json` + `margin.r16`), `--margin <m>` (default 4,096 m, 0 for none) | a low-detail ring of ground around the city so it is not a slab that stops at its bounding box: one eager GLB node, a 64 m lattice (about 66,000 triangles, 330 KiB), a skirt under the inner edge so it meets the 2 m terrain without a crack, vertex colours from slope, height and sea level (water where the DEM is at sea level). The inner row takes the city ground's own height at the edge and the ring follows the DEM out from there. `src/city/terrain/margin.ts`. Fog and aerial perspective at its far edge are the engine's |
| Sea | the source's water layer, when it holds an open sea: a body of kind `sea` over 20 km2 (the CS2 importer's `sea`: touches the edge of the map) or any `ocean` (an OSM coastline polygon) | one `water.volume` node `water.sea` (box) in `stream.root`: XZ is the terrain footprint (core, tiles and margin) plus a 4 km apron, Y runs 80 m down to the surface, and `surfaceHeight` is the largest sea body's `levelM` (0 when the source says nothing: the frame is sea level, so the CS2 sea is `y = 0`). The scene requires `helix.scene-water/1`. A source with no sea body (a lake, river or pond only, a small `sea` bay, the synthetic and OSM-slice fixtures) composes exactly as before. `src/city/assemble/sea.ts` |
| Buildings | `helix city buildings build` output: 256 m cells (near level + box-derived triangle-mesh collider), 1,024 m far clusters | the far layer is a complete HLOD v2 layer, so every building is always drawn; near cells stream by distance. A Scene holds at most 256 collision sets: when the cells would not fit, the colliders of 2 x 2 (3 x 3, ...) cells share one set and one distance group of their own (a few hundred KiB for a whole city); a city that fits keeps one set per cell, in the cell's group |
| Materials | `web.city-materials/1` and the engine's city material library (13 KTX2 textures, copied unchanged into `assets/city-materials/v1`) | identical bytes, identical CIDs: one CDN object and one GPU upload per session. A runtime without the extension draws the portable PBR fallback |
| Trees | the source's `tree` points, **street trees** along the sidewalks of ground-level streets, then a sparse jittered fill of parks and forests, clear of building footprints and streets | exact structural placements (`helix placements bake`); above 1,000 trees the distant impostor pages are baked too (P08). Prototypes: `assets/city-trees/v1` (the Granit conifers, small family). Street trees (`src/city/props/street.ts`, `vegetation.streetTrees`) are a pure function of the road graph, the buildings and the land use: a slot every 9 to 10 m per side of primary, secondary, tertiary and residential streets, kept at 75 to 85 % by class and by land use (residential 1, commercial 0.9, plaza 0.7, industrial 0.3, parking, rail, construction and parks none: parks have their own fill), never at a junction (9 m), on a roadway, under a deck, within 0.9 m of a building or within 4.5 m of another tree or a street prop. The source's own trees come first under the `maxTrees` cap (16,000), then street trees, then the fill; mostly the 9 m fir and a 10 to 14 m pine |
| Props | public Vault catalog search per street-furniture kind in the source, by the kit tags (`kit:street-props-v1`, `kind:<kind>`; [street-props-kit.md](street-props-kit.md)) | up to four Packages per kind; one structural placement per source POI, on the terrain, faced toward the nearest street, baked with the trees (category `rock`, box or cylinder collider, LODs by screen pixels). A POI mapped on the asphalt (every signal sits on its junction node; stops, hydrants and lamps on a centreline) is moved to the kerb: a corner of the junction for a node, the nearest kerb for a point on a leg, by the carriageway and sidewalk widths the road generator uses; one on a bridge deck or inside a building footprint is not placed (the report counts both under `skippedByReason`, and `adjustedByKind` counts the moves). A Package is placed only when it passes the contract (static meshopt + KTX2 web GLB, no Draco/WebP, no blended materials: the engine refuses a Scene whose placement prototype is transparent, so a glass-roofed shelter is reported, not placed). Otherwise nothing is placed and the report names what is missing. Never a placeholder. **Street life** (`props.streetLife`, default on): OpenStreetMap maps few lamps, hydrants, signs and bins, so `generateStreetProps` adds them as POIs along the ground-level streets by building density (lamps every 34 m per side on built-up arterials, hydrants every 85 m, bins every 55 m and benches every 95 m on downtown arterials, two signals at junctions of two arterials, a street-name blade at junctions of an arterial), never within 14 to 30 m of the same kind already mapped; they go through the same search and placement as mapped POIs |
| Roads | `src/city/roads` (`helix city roads build`): per 1,024 m cell one meshopt GLB (asphalt, kerb and sidewalk, markings) and a welded collider | one `road.cell.*` node per cell in its own distance group, `giContribute: false`, collider rewritten without meshopt for the engine's admission, `terrain.colliderRadiusM` 256 (P10). Paint is the restyle's real-world widths (lane and centre 0.15 m, edge 0.20 m, stop line 0.40 m) on the solid core of the atlas line tile, fresh |
| Far road layer | `roads.far` (default on), `roads.farErrorM` (default 0.3 m), `--no-far-roads`; `src/city/roads/far.ts` | the cells stream by distance, so beyond the stream radius the street network would only be painted on the terrain. The far layer is the carriageway of every cell (up-facing `road-asphalt`: no kerb, sidewalk, paint or structure), welded across the cell borders, simplified to `farErrorM`, merged into 2,048 m cells and written as one asphalt primitive each, 3 cm under the near road. One eager group `roadlod.far` (nodes `roadlod.cell.<x>.<z>`); Leonida's 14 km map: 41 cells, 58,175 triangles from 213,747, 0.43 MiB. The same `buildFarLayer` as `helix city roads restyle-cs2` |
| Terrain under the roads at every LOD | `roads.carve` (default on over a DEM); `src/cs2/restyle/terrainCarve.ts` | the conform clears a road at the field's own posting only, but the engine draws the field at strides 1, 2, 4 and 8 and the coarse layer is the stride-8 lattice. Before tiling, the corners of every lattice cell a road surface crosses are held below the surface at each stride (coarse to fine, only lowering, within 3 m of it; decks and tunnels are left out), so tiles, coarse layer and normals are cut from the carved grid and trees and props stand on it. The report's `terrain.carve` holds the share of road vertices under the terrain at each stride, before and after (Leonida: see [city-roads.md](city-roads.md)) |
| Asphalt | `materials.asphalt` `cs2` or `engine`; `assets/city-materials/cs2-asphalt` | a CS2 source (`frame.projection.kind` `cs2`) packages the Granit-calibrated asphalt albedo (darker and flatter: a CS2 map is lit by the hot Granit shell and the engine's own asphalt read twice as bright there, [city-roads-restyle-cs2.md](city-roads-restyle-cs2.md)); every other source the engine's. The plan field overrides either way. Every other texture is the engine's, byte for byte |

## Flags and the plan

Every flag has a field in `scene-plan.json` (`helix.scene-plan/1`); `--plan <file>` reads one, flags override it for the run, and
the resolved plan is written to `<out>/scene-plan.json`.

| Flag | Plan field | Default |
|---|---|---|
| `--tier desktop,mobile` | `tiers` | `desktop` |
| `--budget <MiB>`, `--mobile-budget <MiB>` | `budgetMiB.desktop/mobile` | 512 / 192 |
| `--stream-radius <m>` | `streamRadiusM` | 480 (300 when `mobile` is a gated tier) |
| `--spawn x,z` | `spawn` | the nearest street to the densest building cell |
| `--cell` (128, 256, 512 or 1024), `--far-cell` | `buildings.cellM/farCellM` | 256 / 1024 |
| `--terrain-mps 1\|2\|4` | `terrain.metresPerSample` | 2 |
| `--margin <m>`, `--margin-cache <dir>` | `terrain.marginM` | 4096 |
| (plan only) | `terrain.ground`: `natural` paints land that no area maps and that lies more than 24 m from every street as grass (shore sand below 0.8 m); `urban` leaves it paved | `urban` |
| (plan only) | `terrain.demEdgeRepair: n` (0..16): replaces a border sample of the source DEM that differs by more than 3 m from the sample `n` in; a CS2 height map carries bogus land along its border which the coarse layer's padding extrudes into a hard rectangle past the map | off |
| (plan only) | `spawn: {x, z, exact, yawDeg, faceTowards, clearM}`: with `exact` the spawn is used as given (no street snapping), facing `yawDeg` or towards `faceTowards`; trees within `clearM` (default 12 m) of the spawn are dropped | street snap |
| (plan only) | `vegetation.maxTrees`: a map with more trees than the cap keeps a thin hash-ordered sample over the whole map (Leonida's 292,028 trees under the default 16,000 read as bare from the air); raise it to the source's tree count, the distant impostor pages carry the rest (P08) | 16,000 |
| `--no-vegetation`, `--no-props`, `--no-roads` | `vegetation.enabled`, `props.enabled`, `roads.enabled` | on |
| `--no-far-roads` | `roads.far`, `roads.farErrorM` (plan only: simplifier tolerance, metres, above 0 up to 5) | on, 0.3 |
| (plan only) | `roads.carve`: carve the ground under the roads at every engine LOD stride | on |
| (plan only) | `roads.baked`: a `helix city roads bake-cs2` folder (`.../roads`); its cells, paint and colliders replace the generated roads and feed the same conform, far layer and carve | off |
| (plan only) | `materials.asphalt`: `cs2` (the Granit-calibrated albedo) or `engine` | `cs2` for a CS2 source, `engine` otherwise |
| `--id`, `--title` | `id`, `title` | `scene.<source id>` |
| `--offline` | | the Vault is not searched |
| `--skip-perf` | | the gate is skipped (publish always runs it) |

One document serves every tier it is gated for, so it commits to the tightest: the smallest budget and, for mobile, a 300 m radius.

## Files that sit beside the Scene (library functions)

Two files belong to a World built from a city source but are not part of the sealed Scene document, so they are written by library functions the pipeline calls after `create` or `compose` (neither document's integrity moves):

- `writeCityOceanFile(source, packageDir)` (`src/city/assemble/oceanFile.ts`) writes `ocean.json` + `ocean.rgba`, the format `terrain island` writes and the engine's `loadBathymetry` reads, from the source's open sea (`sea`/`ocean` water bodies) and DEM. With it the shell has `visuals.ocean.level`: fly landing refuses water, a swimmer resets to dry ground. It writes nothing for a source without an open sea, and reports (does not throw) a map wider than the format holds (2049 samples at 8 m).
- `deriveSceneVisuals(manifest, scale)` + `writeSceneVisualsFile(dir, sceneName, visuals)` (`src/city/assemble/sceneVisuals.ts`) produce `scene-visuals/<scene>.json`: latitude from a geographic projection (a mid-latitude, early-afternoon default for CS2 and synthetic maps), fog from the map extent (the far edge keeps 20% contrast), CS2 exposure lift.

## Guarantees

- **Deterministic.** The same source, plan and CLI version produce byte-identical files and the same `integrity.sha256`
  (`assemble.spec.ts` builds twice and compares every byte, impostor atlases included).
- **Sealed and valid.** The document goes through the shared Scene validator before it is written; `integrity` is over the bytes
  that ship.
- **Perf-gated.** `runScenePerf` (P01-P14) runs on the written package for the plan's tiers; a refusal exits 1 and prints the report.
  `helix world scene-source publish` already runs `enforceScenePerfGate` over the same bytes before it uploads one.

## What it does not do yet

Tunnels (the generator skips them), mesh buildings from a CS2 source (the generator already routes them; this
command composes procedural cells only), Vault props beyond the street-furniture kit (the Vault holds no vending machine, phone box or picnic table yet), water surface geometry for lakes, rivers and ponds (they are painted into the splat; only the open sea is a water volume), publishing (`helix world scene-source publish <world> <package>` also wants an `import-receipt.json`, the open-license attribution
of the source data, which this command does not author yet), and a measured mobile run (the mobile result is the static gate).
