diff --git a/demo/carla/README.md b/demo/carla/README.md index 07567b95cc6..1aeb78dc62e 100644 --- a/demo/carla/README.md +++ b/demo/carla/README.md @@ -225,7 +225,7 @@ A steering wheel works through the the keys it is absolute: rim angle is steering angle and pedal travel is throttle and brake. It takes over only once it moves with the throttle released, so a resting foot cannot claim control, and losing an armed wheel -cuts the throttle and brakes. Click its name in the header to calibrate an +cuts the throttle and brakes. Click its name on the map to calibrate an unfamiliar layout; the result is stored per device. ## Checks diff --git a/demo/carla/sim/tests/test_aerial.py b/demo/carla/sim/tests/test_aerial.py index e8964204675..74c9ffa11c1 100644 --- a/demo/carla/sim/tests/test_aerial.py +++ b/demo/carla/sim/tests/test_aerial.py @@ -1,6 +1,8 @@ from __future__ import annotations +import json import math +from pathlib import Path from types import SimpleNamespace from unittest.mock import Mock @@ -28,6 +30,15 @@ def test_footprint_contains_roads_and_preserves_world_axes() -> None: assert pixel == pytest.approx(expected) +def test_shipped_aerials_use_the_road_map_orientation() -> None: + maps = Path(__file__).resolve().parents[2] / "web/src/maps" + manifests = list(maps.glob("*.aerial.json")) + assert manifests + for path in manifests: + camera = json.loads(path.read_text())["camera"] + assert camera["yaw"] == -90, path.name + + def test_ground_height_changes_altitude_without_changing_footprint() -> None: baseline, footprint = calibration([0, 0, 100, 200], padding=10, fov=40) elevated, elevated_footprint = calibration([0, 0, 100, 200], padding=10, ground_z=70, fov=40) diff --git a/demo/carla/web/index.html b/demo/carla/web/index.html index 9589ec10902..09f54fee431 100644 --- a/demo/carla/web/index.html +++ b/demo/carla/web/index.html @@ -10,7 +10,7 @@ background: #0a0a0a; } moq-carla { - min-height: 100vh; + padding: 1rem; } diff --git a/demo/carla/web/src/calibration.css b/demo/carla/web/src/calibration.css index 35a506d9df4..ea86e952e47 100644 --- a/demo/carla/web/src/calibration.css +++ b/demo/carla/web/src/calibration.css @@ -1,7 +1,7 @@ #wheel-cal { position: fixed; inset: 0; - z-index: 10; + z-index: 1002; background: rgba(0, 0, 0, 0.75); display: flex; align-items: center; diff --git a/demo/carla/web/src/maps/README.md b/demo/carla/web/src/maps/README.md index 7bc01240899..43772a589c0 100644 --- a/demo/carla/web/src/maps/README.md +++ b/demo/carla/web/src/maps/README.md @@ -20,10 +20,10 @@ and says so. ## Aerial imagery -Town10HD\_Opt includes a calibrated WebP capture. Its manifest preserves the -capture metadata and image checksum alongside the player's `name`, `image`, -and `bbox` fields. The supplied image already has its horizontal flip applied; -image right is +x and image down is +y. Do not flip it again. +Town10HD\_Opt includes a calibrated WebP capture. Image right is +x and image +down is +y, which is what a nadir camera at yaw -90 sees. Other yaws need a +rotation, never a mirror: a mirrored town still looks plausible, but the roads +no longer line up. On the machine running CARLA, open a truck camera in the player to activate rendering, then run: @@ -46,11 +46,11 @@ records `name`, image `width`/`height`, `groundZ`, the camera transform and FOV, and the simulator `frame`. The PNG and manifest are a pair: ship them together. WebP is also supported using `.aerial.webp` and the matching manifest. Every visitor downloads the image, and the map fits the view to the roads -without zooming further, so ship at most 2560x1440 WebP (Town10HD\_Opt is about -350 KB) and update the manifest's size and checksum to match: +without zooming further, so ship at most 1920x1080 WebP (Town10HD\_Opt is about +180 KB) and update the manifest's size to match: ```bash -ffmpeg -i .aerial.png -vf scale=2560:1440 -c:v libwebp -quality 70 .aerial.webp +ffmpeg -i .aerial.png -vf scale=1920:1080 -c:v libwebp -quality 60 .aerial.webp ``` Run `just fix` afterwards so the manifests match the repository's formatting. diff --git a/demo/carla/web/src/maps/Town10HD_Opt.aerial.json b/demo/carla/web/src/maps/Town10HD_Opt.aerial.json index 7eb811dc812..4d7c2320e61 100644 --- a/demo/carla/web/src/maps/Town10HD_Opt.aerial.json +++ b/demo/carla/web/src/maps/Town10HD_Opt.aerial.json @@ -1,54 +1,16 @@ { - "version": 1, - "map": "Carla/Maps/Town10HD_Opt", + "name": "Town10HD_Opt", "image": "Town10HD_Opt.aerial.webp", - "image_sha256": "a131ed672676660a9146a638ea4b40acbbc09f234d4c9d147dc83fbab5b1ec96", - "units": "metres", - "image_size": { - "width": 2560, - "height": 1440 - }, + "bbox": [-222.51113226996526, -87.62369926452635, 217.8976679144965, 160.10625083923338], + "width": 1920, + "height": 1080, + "groundZ": 0.0, "camera": { - "location": { - "x": -2.306732177734375, - "y": 36.241275787353516, - "z": 381.4052090099687 - }, - "rotation_degrees": { - "pitch": -90.0, - "yaw": 90.0, - "roll": 0.0 - }, - "horizontal_fov_degrees": 60.0 - }, - "projection": { - "type": "nadir_pinhole_ground_plane", - "ground_z": 0.0, - "world_bounds_at_image_edges": { - "min_x": -222.51113226996526, - "min_y": -87.62369926452635, - "max_x": 217.8976679144965, - "max_y": 160.10625083923338 - }, - "image_axes": { - "left_to_right": "carla_x_increasing", - "top_to_bottom": "carla_y_increasing" - }, - "normalized_mapping": { - "left": "(x - min_x) / (max_x - min_x)", - "top": "(y - min_y) / (max_y - min_y)" - } - }, - "capture": { - "road_bounds": { - "min_x": -114.59522247314453, - "min_y": -68.72904205322266, - "max_x": 109.98175811767578, - "max_y": 141.2115936279297 - }, - "padding_fraction": 0.18, - "horizontal_flip_applied": true - }, - "name": "Town10HD_Opt", - "bbox": [-222.51113226996526, -87.62369926452635, 217.8976679144965, 160.10625083923338] + "x": -2.306732177734375, + "y": 36.241275787353516, + "z": 381.4052090099687, + "pitch": -90.0, + "yaw": -90.0, + "fov": 60.0 + } } diff --git a/demo/carla/web/src/maps/Town10HD_Opt.aerial.webp b/demo/carla/web/src/maps/Town10HD_Opt.aerial.webp index 0cf70f44cef..d1ac4102b6a 100644 Binary files a/demo/carla/web/src/maps/Town10HD_Opt.aerial.webp and b/demo/carla/web/src/maps/Town10HD_Opt.aerial.webp differ diff --git a/demo/carla/web/src/maps/index.ts b/demo/carla/web/src/maps/index.ts index 39c522b55a6..a5971ede82f 100644 --- a/demo/carla/web/src/maps/index.ts +++ b/demo/carla/web/src/maps/index.ts @@ -7,22 +7,28 @@ interface AerialManifest { bbox: [number, number, number, number]; } -const BAKED = import.meta.glob(["./*.json", "!./*.aerial.json"], { import: "default" }); -const AERIALS = import.meta.glob("./*.aerial.json", { import: "default" }); +const BAKED = import.meta.glob(["./*.json", "!./*.aerial.json"], { import: "default", eager: true }); +const AERIALS = import.meta.glob("./*.aerial.json", { import: "default", eager: true }); const IMAGES = import.meta.glob(["./*.aerial.png", "./*.aerial.webp"], { query: "?url", import: "default", eager: true, }); +/** + * Start fetching every aerial before any truck names its town, so the map can + * appear with the first truck rather than a download later. + */ +export function preloadAerials() { + for (const image of Object.values(IMAGES)) new Image().src = image; +} + /** Unknown towns fall back to positions; an unreadable aerial keeps the roads. */ export async function loadRoadMap(name: string): Promise { - const load = BAKED[`./${name}.json`]; - if (!load) return undefined; - const map = await load(); - const aerial = AERIALS[`./${name}.aerial.json`]; - if (!aerial) return map; - const manifest = await aerial(); + const map = BAKED[`./${name}.json`]; + if (!map) return undefined; + const manifest = AERIALS[`./${name}.aerial.json`]; + if (!manifest) return map; const image = IMAGES[`./${manifest.image}`]; const bbox = manifest.bbox; if ( diff --git a/demo/carla/web/src/player.html b/demo/carla/web/src/player.html index 2db3b72a7aa..46db722ad17 100644 --- a/demo/carla/web/src/player.html +++ b/demo/carla/web/src/player.html @@ -1,8 +1,3 @@ -
-

MoQ CARLA

- - Connecting… -