--- name: shots description: Photograph the Cartopolis client headlessly or drive a running one — `--shot` captures, sweeps and metrics, `--expect` gates, `--flicker` z-fight checks, `--aerial-reference`, the `cargo shots` README presets and camera pictures' poses, `--shot-mode avatar`, the client's MCP server (`view`, `state`, `bun tools/mcp.ts`), and `[[patrol]]` grids that rank places by what they cost. Use whenever a change has to be seen rather than tested — "what does it look like from there?", a render bug, a visual before/after, regenerating docs/img, "find graphics or performance improvements" — and to pick which build node a capture should run on. --- # shots Answer "what does it actually look like from there?" without flying a camera by hand. Everything here is one harness, `crates/cartopolis/src/systems/dev/shot_harness.rs`: `--shot`, `cargo shots`, `cargo perf` and the MCP server's `view` all push a `ShotSpec` onto it, and it owns the only cycle that places a camera, waits for every streamer, quiesces the worker pool and then fires. ## Where to run it — decide what the capture has to prove A machine with a real GPU (a workstation, or a build node with one) draws a settled viewpoint in seconds and is evidence for everything. A build node without one renders through Mesa lavapipe on the CPU: measured over Groningen at 1600×900 on 2026-09-15, **4.1 s a frame and about six minutes a settled viewpoint**, most of it the harness rendering hundreds of frames while the map streams. That is trustworthy for **geometry, placement, culling and visibility**, and no evidence at all for **colour, exposure, bloom, lighting or frame time** (`docs/notes/headless-shots-software-renderer.md`). The real GPUs in the pool are `mac-1` and `mac-2` (Apple M5 Pro, in a VM: no Metal counters, so no per-pass GPU timings) and `deck-1` (Steam Deck, RADV). `midas take gpu` matches only nodes registered with a hardware GPU, which the Macs are not, so name a Mac when you want one. Check `midas status` for which is free. ```bash midas take --node mac-2 ssh 'cargo run -p cartopolis -- --shot /tmp/x.png --at …' ssh 'cat /tmp/x.png' > /tmp/x.png # a node's output stays on its machine ``` Fetch through plain ssh, never `scp`: on the Macs `scp` fails ("Connection closed": the node starts a Linux `sftp-server` path). PNGs have been seen landing under `$TMPDIR` rather than `/tmp` there, so look in `$TMPDIR` if it is not there. Upload the same way (`ssh mac-1 'cat > /tmp/run.sh' < run.sh`), a directory with `ssh mac-1 'cd /tmp/d && tar cf - .' | tar -C /tmp/d -xf -`, and run every ssh from the worktree that holds the node: from anywhere else midas refuses it. ## One capture, a sweep, a flythrough ```bash # one frame, straight down from 180 km cargo run -p cartopolis -- --shot /tmp/shot.png --at 53.2194,6.5665,180000 --look=-90,0 # an altitude sweep in ONE launch → /tmp/sweep_0_60000m.png, /tmp/sweep_1_1000000m.png, … cargo run -p cartopolis -- --shot /tmp/sweep.png \ --at 53.2194,6.5665,60000 --at 53.2194,6.5665,1000000 --look=-90,0 # a 24-frame flythrough between two --at, with the ramp scalars logged to CSV cargo run -p cartopolis -- --shot /tmp/fly.png \ --at 53.2194,6.5665,2000 --at 53.2194,6.5665,4000000 --frames 24 \ --look=-90,0 --csv /tmp/ramps.csv ``` - `--look pitch,yaw` in degrees pairs with `--at` by position. **Write the `=`** (`--look=-90,0`): clap reads a leading `-90` as a flag otherwise. - **The yaw turns counter-clockwise** (90 looks west), so a compass heading is its negation. The comment on `ShotSpec` said otherwise until 2026-10-15. - `--look-at lat,lng` aims at a place instead, recomputed each frame from where the camera actually ended up — use it for shallow angles (a sunken road, a viaduct), where three metres of altitude moves a fixed aim thirty. - Runs are **headless**: no window at all (`WinitPlugin` off, `ScheduleRunnerPlugin` drives frames), the camera renders offscreen, nothing can occlude and blacken a capture, and it works over ssh or in CI with no `DISPLAY`. Scripted runs are always **offline** and never read or write `data/user.json`. - Each capture waits for the streams to go quiet (`--settle`, capped by `--wait`) rather than sleeping. Both count *virtual* seconds clamped at 0.25 s a frame, so on a slow renderer they run ~6× longer than they read. - The interface is in the picture (the HUD documents the shot); `--hide-ui` drops it. `--ui a,b` opens panels and states — the vocabulary is `shot_harness::UI_ELEMENTS` (`dev`, `layers`, `route` seeds a demo route, `driver`, `sit`, `fire`, `building`, `inside`, `chat`, `settings`, `all`, …); an unknown name is logged as ignored, not refused. - Environment: `--size WxH`, `--time HOURS`, `--date YYYY-MM-DD`, `--fog D`, `--clouds C`, `--rain R`, `--weather-live`. A/B the lighting curves with `--time 6` (dawn) and tell a washed-out sky from a washed-out fog with `--time 18 --fog 0`. - Layers that a headless run has no panel to tick: `--aerial`, `--sewers`, `--underground geotop,gasfield|all`, `--satellites`. ## Avatars: `--shot-mode avatar` `--shot-mode free|earth|avatar`. In free and earth mode the camera sits at `--at` while the avatar stands at the map anchor — they rarely coincide, so the avatar is simply off screen, which has caused a lot of "the avatar isn't rendering" confusion when it was fine and elsewhere. In **avatar** mode the follow camera is put on the avatar: `--at`'s altitude is the follow distance and `--look` is (elevation°, azimuth°). Two things make it work although every scripted run is offline (where there is no avatar and no Follow camera): `ShotHarness::wants_avatar` spawns one when the run says it is photographing one (`--shot-mode avatar`, `--ui sit`, `--ui driver`), and `hold_scripted_camera_mode` re-holds the mode every frame for the duration of the capture. Use it at scale 1.0 rather than giant-scaling an avatar to find it in a free-camera shot. ### A movie: `--video-fps` `--video-fps N` treats the `--at`/`--look` list as the frames of a movie at N fps. Everything that moves — traffic, walkers, signals, clouds, rotors, and through `globals.time` water, grass and particles — reads `systems::anim_clock`, which stands still while a frame streams and settles and steps exactly `1/N` s between captures. Without it each frame moves the world by however long it took to load (0.8 s to 20 s), and a 60 fps movie of it jumps. Frames are encoded on background threads and `--settle` drops to 0.1 s, since nothing moves while a frame waits. Give it one `--at` per frame (compute a smooth path yourself: `--frames` blends straight segments and turns at each waypoint), repeat the last one to hold a pose with the city still moving, and stitch with ffmpeg at the same rate. The avatar's own clips play on Bevy's animation player and are not on this clock yet. ### Watching an animation: `--clip` A still cannot show a foot sliding, a knee bending backwards or a pop where a loop restarts — those are differences between frames. `--clip NAME` freezes the avatar at `--clip-frames` (default 12) evenly spaced points of one cycle, captures each, and tiles them into **`_sheet.jpg`**: one block per `--at`, the cycle left to right wrapping at six columns, an orange bar under each tile filled to its phase. It implies `--shot-mode avatar`; only the first frame of each viewpoint is flown to, the rest are taken in place. Read the sheet, not the frames. ```bash # a walk cycle from the side and from the front, the whole body, no HUD cargo run -p cartopolis -- --shot /tmp/walk.png --clip walk --hide-ui --size 400x600 \ --time 12 --at 53.21855,6.56730,5 --look=0,90 --at 53.21855,6.56730,5 --look=0,0 ``` **Frame it from 5 m with a level camera.** The follow camera aims at the avatar's head, so from 4 m or a few degrees up the feet leave a portrait frame — and the feet are most of what a walk cycle is about. Stand it on solid ground: the Grote Markt above. By a canal (53.2194,6.5665) the avatar drops toward the water once the run starts, and every frame after the first shows the quay wall. Names: `idle walk run sit swim climb dangle wave interact roll punch kick faint handshake highfive throw` (`climb` steps up its own 0.37 m without a wall; `--ui ledge` and `--ui edgesit` stand and sit the avatar on a real wall it is put on, `climbing-and-edges.md`; `swim` needs water under the avatar: the Noorderhaven, 53.22005,6.5587; `handshake` and `highfive` draw a stand-in partner where the sim would stand one, so whether the hands meet shows — frame them from the side, `--look=0,90`). The clip is held still (`avatar::PinnedAnimation`), so the frames are the clip's own poses at those phases however slowly the renderer goes — but that also means a playback *rate* fault (feet sliding because the clip plays too fast for the ground speed) is not visible here: the avatar stands on a treadmill. ## Metrics: one source, three sinks Every capture measures a `ShotMetrics` — altitude, tier, the altitude-driven crossfade scalars (`space_factor`, exposure, bloom, `globe_albedo`), near/far, mesh and render counts, and many layer-specific tallies — into the `shot state` log line (always), `--csv PATH` (a row per capture) and `--dump-state PATH` (JSON: an object for one shot, an array for a sweep). They report the *actual* camera state (the altitude after the teleport snapped it), not what was asked. **A new inspectable fact is one field on `ShotMetrics`** and appears in all three at once — that is how to inspect the settled world from a shell without a recompile per question. `shot state` is also what separates "black image" from "black scene". `--frames N` (needs ≥ 2 `--at`) interpolates N viewpoints along the waypoints, altitude log-interpolated; files are index- and altitude-tagged (`fly_00_2000m.png`) so the filmstrip sorts in flight order. With `--csv`, a jump between adjacent rows of `space_factor` / `exposure` / `bloom` / `globe_albedo` is a **hard cut in a ramp** that no single still can show. ## Gates: `--expect`, `--flicker`, `--aerial-reference` **`--expect` turns a capture into a test.** `--expect 'settled==true' --expect 'globe_rendered>0'` (quote it — `>` is a redirect) asserts any `--dump-state` field on every capture and exits non-zero if one fails, logging `shot expect failed` with the measured value. Operators `>= <= == != > <`; booleans are `true`/`false`; `==` is exact, so assert floats with `>=`/`<=`. **An unknown key is a startup error** (a typo that quietly holds is worse than no assertion), as is an unknown manifest key. A failure does not abort the run, so the rest is still captured and a red job hands back the pictures that explain it. The `scene-smoke` CI job is built on this — and on a software rasteriser it may only gate geometry, placement and visibility. **`--flicker` measures depth stability.** A z-fight between coplanar surfaces is deterministic per view matrix, so no single still shows it — which is how every coplanar-flicker bug here (roads over roads, water over land, the ghost pavements of 2026-08-29) shipped past a green screenshot job. `--flicker` captures each `--at` twice ~5 cm apart and reports the flipped pixels as `flicker_px` (3×3-eroded, so silhouette crawl does not count). Gate it with `--expect 'flicker_px<=N'` in a pinned environment (`--time 12 --clouds 0 --rain 0`); traffic and pedestrians still move between the pair, so N sits above that floor, never at 0. Asserting `flicker_px` without `--flicker` is a startup error. **`--aerial-reference` is what a render of a real place is checked against.** Beside each capture it writes `.aerial.jpg`: PDOK's aerial photograph of the ground from the camera to its aim point, camera a red dot, line of sight red, aim a yellow cross (`systems::aerial_reference`; manifest key `aerial_reference = true`; the Netherlands only). Use it whenever a capture is evidence that a structure, road or the ground is *right*, not merely drawn: the unified tunnels' first renders walled a cycle path across a park by Groningen's ring (2026-09-28) while every metric was self-consistent, and only the photograph showed the path at grade. ## Finding what costs, unprompted: patrols When the task is "find graphics or performance improvements" rather than "measure this place", do not pick viewpoints by hand and do not script the MCP server stop by stop. Fly a **patrol**: a `[[patrol]]` block in a perf manifest is a grid (`area`, `step_m`, `altitudes`, `looks`) that expands into ordinary perf scenarios, and the report ranks the stops against each other (`docs/notes/performance-suite.md`, "Patrols"). ```bash # the checked-in patrol: Groningen's centre, 32 stops → /tmp/patrol.json cargo run -p cartopolis -- --perf docs/patrol.toml --perf-out /tmp/patrol.json # one stop again, three flights, to see whether its rank holds cargo run -p cartopolis -- --perf docs/patrol.toml --only centre-120m-r2c1 --repeat 3 ``` Stops are named `-m-rc` (row 0 south, column 0 west); `--only ` flies all of them. A new area is a new `[[patrol]]` block in a scratch manifest (copy `docs/patrol.toml`'s header keys); `time` is required. Read the result in this order: 1. **`patrols[].columns[]`** in the JSON, or the `perf patrol` log lines (top three per column). Each hotspot carries its pose, its value as min/median/max, and `ratio` to the patrol's median. Lead with the counts — `draws`, `tris_total`, `resident_kb`, `material_modified_per_frame`, `upload_kb` — which hold on any machine; `frame_ms_*` only on a real GPU. 2. **Discard what is not a finding**: `settled: false` or a `steady` hotspot with `quiet: false` is a world still streaming and ranks high for that alone; a range that overlaps the next stop down has not out-ranked it. 3. **Re-fly the survivor** with `--only --repeat 3`, then look at it: `view` over MCP or `--shot` at the hotspot's `at` / `look`, and switch layers off one at a time (`CARTO_NO_*`, `--hide-ui`) to name what the count is made of. 4. **Change the code, re-fly the same stop with the same `--repeat`**, and claim a win only if the median moved by more than the range. A hotspot that held up becomes a `[[scenario]]` in `docs/perf.toml`, with a description of the cost it exercises. **Which machine**, by what the question needs: | question | machine | |---|---| | counts, frame times | `mac-1` / `mac-2` — vps-1 cannot settle ground level | | `fill` (fragment invocations) | `vps-1` with `--features perf` — no Mac reports it | | GPU time per pass | the owner's Mac workstation, `--features perf`: the node Macs are VMs with no Metal counters. Hand the command over and read back the JSON | ## The README images and camera pictures: `cargo shots` `docs/shots.toml` remembers named camera positions (`at = [lat, lng, alt]`, `look = [pitch, yaw]`, and per shot `mode` / `time` / `fog` / `clouds` / `rain` / `ui` / `hide_ui`; for a view that must match a photograph, `roll` / `fov` / `date` / `on_ground` / `[shot.measured]`). ```bash cargo shots # the ungrouped set → docs/img/.png cargo shots --only globe,route # a subset cargo shots --only views # a group → docs/img/views/.png ``` `cargo shots` is `cargo run -p cartopolis -- --shots`, so every flag above still applies, and the CSV gains a `name` column. The manifest pins `tile_url`, because a scripted run never sees the server handshake that supplies one and the built-in fallback is the *raster* basemap, on which `route` renders "Routing needs a vector tile source" (`CARTO_TILE_URL` still overrides). To add a view, fly there and press the dev panel's **📋 Copy as preset**, which puts a `[[shot]]` block on the clipboard. Other manifests in `docs/` (`*-shots.toml`, `perf.toml`) use the same format; `cargo perf` flies `perf.toml` (`docs/notes/performance-suite.md`). **The README shows one contact sheet, not the presets themselves.** The six ungrouped shots are real screens with the UI open; `docs/img/readme.html` frames them mockup-style and is rendered to `docs/img/readme.jpg` — `docs/img/README.md` has the Chromium and the macOS (`tools/render-html.swift`) commands. Shot order in the manifest matters (a solved route and the demo chats' shared location outlive their shot). The scenic set the README used to carry is the `views` group. **A camera picture is a preset that came from a phone** (`systems::camera_screen`, `docs/notes/camera.md`): every picture the camera makes carries its pose in its EXIF and XMP, and one sent to the agent's chat carries it in its caption too, which `read_chat` hands over as a `[[shot]]` for `docs/photos.toml`. In Mixed mode the picture is the photograph beside Cartopolis from the same pose. ## When a capture comes back wrong - **No PNG after a minute of healthy frames, or a black scene with only the chrome, exit 0**: the tile workers and Bevy's screenshot readback share `AsyncComputeTaskPool`. The harness pauses the pool (`workers::set_paused`) between the settle verdict and the shutter; anything new spawned onto that pool can starve the readback again (`docs/notes/headless-shots-software-renderer.md`). - **The run quits silently before the first capture**: something read `Query<&Window>` and drew to a scissor rect that does not match the target. With no window, `resources::HeadlessSurface` *is* the screen (`--size`); every reader of the window must fall back to it. - **Bisect a render problem by removing one layer at a time**: `CARTO_NO_ATMOSPHERE=1`, `CARTO_NO_HAZE=1`, `CARTO_NO_ENVMAP=1`, `CARTO_NO_OCEAN=1`, `CARTO_NO_CLOUDS=1`, `CARTO_NO_SHADOWS=1`, `CARTO_NO_SPACE_RAYMARCH=1` (the list is `debug_switches.rs`), plus `CARTO_NO_GROUND_DETAIL=1`, `CARTO_NO_LOD_BLEND=1`, and `CARTO_SKY_DOME=1` to force the phone's fallback sky. - **Something looks wrong only once**: it may be a ramp seam (sweep with `--csv`) or a z-fight (`--flicker`) rather than a still-image fault. ## Driving a running client: MCP The client hosts a Model Context Protocol server (`systems::dev::mcp`, server in `crates/mcp_server`; `docs/notes/driving-the-client-from-an-ide.md`): `state` (where it looks, whether the map has settled; no picture), `view` (fly and capture) and `view_here` (re-capture without moving, for a before/after). It is **not a second screenshot path** — `view` is a `ShotSpec` on the harness above, and a live harness only differs in parking instead of quitting at the end of its list. A windowed client therefore captures its *window* (`--mcp-size` applies only headless), and the camera-mode holds run only during a capture, or an idle operator would take the camera from whoever is using the client. **On by default on Linux and macOS**, on a Unix socket only its owner can open (`$XDG_RUNTIME_DIR/cartopolis/mcp.sock`; the directory *is* the access control, no token), switched in Settings ▸ General ▸ Editor access while the app runs. A scripted capture never serves, and `--no-mcp` takes any run out. Unix desktops only — `build.rs` sets the `mcp` cfg on the same predicate `Cargo.toml` gates the crate on. ```bash cargo run -p cartopolis # already serving on the default socket cargo run -p cartopolis -- mcp # the stdio relay an editor launches (or `ssh HOST cartopolis mcp`) cargo run -p cartopolis -- --mcp-headless # no window; the shape for a VPS cargo run -p cartopolis -- --mcp-headless --connect HOST --mcp-allow jeroen # an account an agent drives bun tools/mcp.ts state # the same surface from a shell ``` **Signed in, the client is somebody an agent can be** (`systems::dev::mcp::agent`): `me`, `read_chat`, `say`, `walk_to`, `teleport`, `build`, `set_script` and the rest act as the account through the channels a person's actions use, so the server's ownership and rate checks apply unchanged. **What the agent reads is the risk**: chat reaches it only from `--mcp-allow` / Settings ▸ Editor access (empty by default), `view` drops the chat overlay while that list is narrower than everyone, and a public line counts only with an avatar behind it (`ChatLine::sender_is_account`), because `say` speaks under a prim name anyone can choose. The `viberfox` bot, with an agent of its own answering its chat, is `midas bot start --agent` (the command is in `docs/notes/driving-the-client-from-an-ide.md`, "The hosted bot").