ADR-029: Geo-Anchored Prim Storage
Metadata:
- ID: ADR-029
- Status: Proposed
- Date: 2026-07-22
- Tags: [prims, coordinates, storage, protocol, precision, large-world, persistence]
- Decision Type: architecture_pattern
- Aligns with: [G-02, P-03] — a planet-scale world where authored content keeps its real-world position
- Roadmap tier: P1
- Doc resolution: R2
- Related: [ADR-002, ADR-011, ADR-017, ADR-019, ADR-020, ADR-025]
- Supersedes: []
- Superseded By: []
Context
Problem: Prim positions are stored and transmitted as a single absolute f32
Vec3 in "sim-space" metres measured from the world origin (0,0,0), at every
layer — the Prim component's Bevy Transform, PrimDto.position on the wire,
the position_x/y/z REAL columns read back into f32, and both SQLite databases
(server and offline client). Prims are spawned with only (Prim, Transform) —
no big_space GridCell, no region parenting (rendering.rs::spawn_prims) —
so they render at grid cell (0,0,0) and their world position is the raw f32.
This does not fit the world-size coordinate system the client now uses:
-
Precision. The world frame is a big_space
i64grid of 10 km cells with anf32localTransforminside each cell (ADR-019), giving ~mm precision anywhere on the planet. A lone absolutef32holds only ~7 significant digits, so a prim more than ~10–100 km from the origin degrades to decimetre/metre precision. Regions already dodge this —spawn_regionsrunsGrid::translation_to_gridand spawns them with aGridCell+ChildOf(root)— but prims do not. -
Reference frame. The world is no longer pinned to a fixed sim origin. Since the movable-OSM-anchor model (ADR-006 → ADR-020) and the planetary globe (ADR-025), the ground truth is a re-anchorable Web-Mercator frame whose origin is wherever the anchor currently sits:
MapStream::geo_anchor() -> (lat, lng, zoom), andlat_lng_to_world(anchor, clat, clng) == (0, 0). A prim stored as absolute metres-from-origin has no tie to a lat/lng, so the moment the anchor moves — the entire point of the anchor-less direction — every prim's world position silently refers to a different place on Earth, with no stored geo coordinate to re-project it from.
Requirements:
- A prim's real-world position must survive a re-anchor (the anchor is expected to move across the globe within a session).
- Placement precision must be independent of distance from the current origin (planet-wide ~mm, matching ADR-019).
- Geo placement is authoritative and anchor-independent at every layer (wire, storage, render).
Decision
Store each prim's horizontal placement as an absolute geographic coordinate
(GeoAnchor { latitude, longitude }, f64) plus an altitude carried in
position.y; derive the render-space GridCell + local Transform on the client
from the current OSM anchor, and re-derive it whenever the anchor moves.
Prims are online-only and geo-anchored: the server is the sole authority for
prim state, and every prim carries an absolute GeoAnchor.
Approach:
cartopolis_core—GeoAnchor { latitude: f64, longitude: f64 }and a mandatorygeo: GeoAnchorfield onPrimDto,CreatePrim, andUpdatePrim. Shipped as wire revision v10 (seePROTOCOL_HISTORY; the current version is derived from that log, not pinned here).cartopolis_simulator— theprimstable carrieslatitude/longitude REAL NOT NULL;db.rsround-trips them as requiredf64. The sim stores whatever geo the client authored — it never converts, having no anchor of its own.cartopolis— aPrimGeo { latitude, longitude }component mirrors the DTO field onto every prim entity.place_geo_primsconvertsgeo → lat_lng_to_world(anchor, …) → GridCell + local Transform, parents the prim to the big_space root, and re-projects all prims whenMapStream::geo_anchor()changes. The outboundCreatePrim/UpdatePrimsenders (gizmo drag, edit dialog, AI assistant) derivegeofrom the prim's world position viaprim_geo::geo_for(cell + local) orgeo_from_world. Prim authoring requires anOnlineSession.
f64 lat/lng gives sub-millimetre resolution globally; the f32 local
Transform stays cell-local (≤10 km) so it keeps mm precision — the same
guarantee regions already have.
Rationale
Primary Reasoning:
- Geo is the anchor-independent invariant. Two clients with different anchors each convert their own local frame to the same lat/lng, and a re-anchor is a pure re-projection of an unchanged stored coordinate. Nothing else in the system survives an anchor move — this does.
- It matches how regions already work. Regions carry
latitude/longitudeand are rebased into the grid viatranslation_to_grid; this makes prims first-class citizens of the same anchored frame instead of an exception that only renders correctly while everything sits near the origin. - Precision follows from cell-locality, not bigger floats. Keeping the
f32Transformcell-relative (viaGridCell) is what ADR-019 already relies on; widening prim coordinates tof64everywhere would fight big_space instead of using it. - Decouples prims from region lifetime. The anchor-less direction expects fixed sim regions to go away; an absolute geo coordinate needs no region to be placed.
Alternatives Considered:
| Alternative | Pros | Cons | Rejected Because |
|---|---|---|---|
Parent prims to their Region entity (ChildOf(region)), keep f32 region-relative | Smallest change; no protocol/schema churn; reuses region GridCell | Ties prims to region lifetime; still bound to the fixed-origin frame; breaks when regions are dropped for the movable anchor | Contradicts the anchor-less direction (ADR-020); doesn't survive re-anchor on its own |
Widen position to f64 DVec3 absolute metres | Conceptually simple; planet-wide precision | Still frameless — absolute from which origin? A re-anchor still invalidates it; doubles wire/storage width; duplicates what big_space already does with i64 cells | Solves precision but not the reference-frame problem, which is the real blocker |
Store GridCell (i64×3) + f32 local on the wire | Directly matches the render model; mm precision | Cell indices are meaningless across a re-anchor (they're relative to the current origin); leaks a client rendering concept into the persisted authority | Not anchor-independent; couples storage to the floating-origin implementation |
Consequences
Positive:
- Prims keep their real-world location across re-anchors, teleports, and the space/globe tier — placement is defined in the same frame as the imagery.
- Planet-wide ~mm placement precision, independent of distance from origin.
- Prims stop depending on regions for a reference frame (aligns with anchor-less).
- Server storage becomes geo-authoritative; no anchor knowledge needed sim-side.
Negative:
- Prims require the server. Authoring needs an
OnlineSession; offline is a map viewer, not an authoring mode. The AI assistant'screate_prim/update_prim/delete_primtools return "requires an online session" when disconnected, andupdate_primcan't change shape (noshapefield onUpdatePrim). - Altitude is
f32inposition.y. Acceptable — altitude range is small and cell-local; only the horizontal plane needs geo precision. - Authoring reconstructs world from cell + local before converting to geo.
Because
transform.translationis cell-relative, gizmo sends add the cell back in (prim_geo::geo_for); the edit-dialog / AI paths author near the origin and convert the world position directly (prim_geo::geo_from_world). Monitoring: a prim that jumps on the next re-anchor means a send site sent a stale/local coordinate — worth a round-trip test (author → snapshot → re-anchor → same lat/lng).
Related
- ADR-019: the
i64-cell floating-origin model this makes prims participate in. - ADR-020 / ADR-006: the movable-anchor frame prims are now expressed in.
- ADR-025: re-anchor on globe descent — the event that makes re-projection necessary.
- ADR-017: the
CreatePrim/UpdatePrimauthoring path extended withgeo. - ADR-011:
WorldSnapshotcarryingPrimDto. - ADR-002: the prim table extended by migration
V5.