Skip to content

cvcGL examples: GRL-SNAM navigation demos (city swarm, fog ghost, Austin finale) - #203

Merged
transfix merged 11 commits into
masterfrom
feat/cvcgl-nav-demos
Aug 20, 2026
Merged

transfix merged 11 commits into
masterfrom
feat/cvcgl-nav-demos

Conversation

@transfix

Copy link
Copy Markdown
Owner

Three runnable C++ cvcGL demos of the GRL-SNAM navigation scenarios — the payoff of
the torch-free cvc::nav port: the identical sim_world / sim_thread runtime driving
agents inside the cvcGL scene graph, no Python, no libtorch.

demo what it shows views
nav_city_swarm N vehicles navigate a procedural city_scene, coloured by belief group; one merged glyph mesh streamed per frame (verified to 2000 agents) 3-D + --ortho 2-D
nav_fog_ghost the belief-vs-truth "ghost": a stale phantom wall dissolves as the agent senses through it; live belief heatmap 3-D + --ortho 2-D
nav_finale 8 vehicles rendezvous → pursue 4 moving targets on the real Austin bundle, private belief 3-D + 2-D PiP minimap

New reusable code in src/cvcGL/examples/nav_common.{h,cpp}:

  • AgentGlyphs — one merged arrow mesh for all agents, streamed via
    GeometryNode::updateVertices (the path that scales; per-node actors die at ~63).
  • occupancy_to_walls, ground_quad, add_border, orbit_camera, set_ortho_topdown.
  • occupancy_from_model — the C++ analog of GRL-SNAM's building_occupancy: CPU
    scan-conversion of a mesh footprint (e.g. buildings.glb) into the nav occupancy grid.
  • A one-line sim_world::agent_planes() accessor so a renderer can colour agents by group.

The Finale loads a scene bundle (terrain.json + buildings.glb) at runtime via
--bundle; assets are never vendored into the repo. Falls back to a synthetic city with
no bundle.

Examples are opt-in (-DCVC_BUILD_CVCGL=ON -DCVC_BUILD_EXAMPLES=ON), so default CI is
unaffected. See src/cvcGL/examples/NAV_DEMOS.md.

The first of the C++ cvcGL demos of the GRL-SNAM navigation scenarios: N vehicles
reactively navigate a procedural "city" (the same cvc::nav::city_scene the trainer
uses), rendered with no Python and no libtorch — the exact sim_world / sim_thread
runtime driving agents inside the cvcGL scene graph. This is the swarm's first
visual (the Python Swarm only ever had bench numbers).

- nav_common.{h,cpp}: shared demo helpers — occupancy_to_walls (grid -> merged
  blocky buildings), AgentGlyphs (ONE merged arrow mesh for all agents, streamed
  per frame via GeometryNode::updateVertices — the path that scales to thousands;
  per-node actors die at ~63), and orbit_camera (scripted capture orbit).
- nav_city_swarm.cpp: city_scene occupancy -> sim_world::from_occupancy with
  --belief shared|grouped|private (agents coloured by belief group), run on a
  sim_thread off the render thread; walls + ground + agent glyphs under two
  directional lights + a shadow map; interactive window or offscreen orbit/fly
  capture -> PNG -> mp4. Verified offscreen at up to 2000 agents.
- sim_world: add agent_planes() so a renderer can colour agents by belief group.
- NAV_DEMOS.md: build/run + the headless mesa-GLX note.

Bind-pose gotcha baked into AgentGlyphs: the glyph mesh must start as a real
(non-degenerate) triangle so ensureNormals gets a valid +z normal — updateVertices
leaves normals at bind pose, and every packed glyph stays coplanar, so a degenerate
bind pose renders the agents unlit/black.
…ground

Address demo-review feedback:
- add_border() stamps a wall around the occupancy so the reactive swarm can't
  drive off city_scene's open edge (agents were leaking out of bounds).
- --ortho: a fixed top-down orthographic camera (set_ortho_topdown) for a
  matplotlib-style 2-D map, alongside the default 3-D perspective — one codebase,
  both 2-D and 3-D. Ortho forces shadows off for a clean flat read.
- Raise the ground's ambient so the shadow-map coverage boundary on the big flat
  plane stops reading as a hard dark/light line.
The belief-vs-truth scenario that defines GRL-SNAM, rendered natively. One vehicle
starts with a STALE belief (a phantom vertical wall the prior map has but reality
doesn't); it sets off detouring around the ghost, its ray sensor sweeps the space,
the belief clears, and it drives straight through — all on cvc::nav's sim_world
with sensing on (freeze_sense=false), no Python, no libtorch.

- The agent's planning field (sim_world::field_data, plane-0 SDF) is drawn as a
  live ground heatmap via a zero-copy cvc::image texture updated in place each
  frame (setTexture + texture_modified): red = believed wall, blue = open. You
  watch the phantom wall dissolve as the sensor ring sweeps it. Colourmap clip is
  measured once from the field (the SDF range is a small few, scene-dependent).
- --ortho gives the top-down 2-D "matplotlib" belief map; default is 3-D.
- Reuses nav_common (occupancy_to_walls border, AgentGlyphs, ortho camera); adds a
  LINES sensor ring that tracks the agent.
…iP minimap)

The flagship GRL-SNAM demo on the REAL Austin bundle, rendered natively (no Python,
no libtorch). 8 vehicles enter blind from the west and rendezvous on a staging line
(Act 1), then split into pursuit packs chasing 4 moving targets via per-tick
sim_world::retarget (Act 2), each on its own private belief.

- occupancy_from_model (nav_common): the C++ analog of GRL-SNAM's building_occupancy
  — CPU scan-conversion of a mesh's XY footprint into the nav occupancy grid, with
  optional dilation. Rasterizes buildings.glb (verified: 978K tris, bbox +/-1500)
  straight into the grid the vehicles navigate. Internally consistent with the
  rendered mesh + sim_world's cell mapping; a rough IoU cross-check vs Python's
  cached .occ.npy is printed (differs by the grid-node vs pixel sampling convention).
- Loads the bundle (terrain.json bounds + buildings.glb via cvc::read_model) at
  runtime from --bundle; NEVER vendored into the repo. Synthetic-city fallback when
  no bundle is given.
- 2-D picture-in-picture minimap composited into each frame (frameRGB -> cvc::image
  -> cvc::write_image): the occupancy raster + every agent's position + the line to
  the target it is chasing.

3-D only (the 2-D view is the PiP). Verified end-to-end on the Austin bundle.
…+ minimap

Load satellite.png from the bundle and texture the ground quad with it (the quad's
[min,max]->[0,1] UVs + setTexture's V flip land the north-up aerial correctly), so the
3-D buildings sit on their real satellite footprints instead of flat grey. The PiP
minimap uses the same aerial (downsampled) as its base, and agent/target dots got a
dark halo + larger radius so they read on the imagery. Falls back to grey ground +
occupancy minimap when no bundle/satellite is present.
…oating)

The vehicle params are normalized, and Austin's normalized extent is ~±1 (vs the
city_scene's ±5), so the previous values were ~5x too large — reach_tol=1.2 meant
"arrived" spanned the whole map (the vehicles parked immediately) and the radius /
barrier were street-swallowing. Rescale: rr ~9 m, d_hat ~30 m barrier, reach_tol
~90 m, vmax 0.35; give them the known city map (freeze_sense=true, prior==truth) so
the reactive drive threads the streets. Also drop the glyphs to ~18 m off the ground
(they were floating at 60 m). The 8 vehicles now spread out and navigate the real
downtown instead of bunching at the start.
…* routing

Fix a heap-overflow crash and harden/extend the finale.

CRASH FIX + TESTS (the reported crash): the finale's 2-D PiP minimap composited
straight into the frame buffer with unchecked indices, so a minimap larger than the
frame (e.g. rendering at 200x150 with a 180-px minimap) or an off-map agent dot wrote
past the buffer -> heap corruption -> SIGSEGV in the next allocation. Extract
bounds-safe blit_clamped() + plot_disc() into nav_common (every write clipped to the
destination) and route all minimap drawing through them. nav_common_test.cpp
(GoogleTest, built only when tests are enabled; no GL needed) reproduces the exact
overflow with a sentinel-fenced buffer and proves nothing writes out of bounds — plus
negative/offscreen origins, huge radii, and occupancy_from_model edge cases.

HUMVEE MODEL: AgentGlyphs gains build_template() to instance an arbitrary mesh per
agent (streamed the same way as the arrow). nav_finale loads the bundle's Humvee.glb
(--vehicle, default <bundle>/../../shared/Humvee.glb), canonicalised to forward +x /
up +z / resting on the ground; falls back to the arrow.

A* ROUTING: the vehicles now follow an A* route spine (cvc::nav::astar + simplify over
a lightly-inflated occupancy) to their goal, advancing waypoints on arrival, replanned
to the moving targets in Act 2; the reactive drive does local avoidance between
waypoints. The minimap draws each vehicle's remaining route.

OCCUPANCY TUNE: occupancy_from_model rasterizes with a tight cell-centre test (the
earlier conservative fatten sealed dense downtown so A* couldn't route and the drive
was repelled everywhere).
…aypoint-change

The vehicles were frozen (spd -> 0) for two reasons, both fixed:
- SCALE MISMATCH: the finale used a custom world->normalized scale (1/1500) while
  keeping sim_world's vehicle constants (wheelbase L, a_max, a_lat_max, ...) at the
  city_scene defaults, which are normalized and tuned for scale 0.05. Mis-sized, the
  drive governor clamped speed to ~0. Use scale 0.05 (1 unit = 20 m) like the working
  city demo + its proven veh params (rr ~3 m, barrier ~7 m, arrive ~16 m); the drive
  now produces motion.
- RETARGET THRASH: retargeting every frame reset the carrot FSM's escape/tracking
  state each tick. Retarget only when the waypoint index changes (force it after an
  Act-2 replan). Widen the waypoint-advance radius to 0.03*span.

Vehicles now move and follow their A* routes. Known remaining tuning: they can circle
a waypoint that lands next to a building, and Act-2's periodic replan restarts the
route — smooth full-map convoy traversal on dense real Austin needs more tuning.
Explain the reactive brain the demos actually run, in every demo header and in
NAV_DEMOS.md (a new "How the GRL-SNAM nav model works" section): per agent, per
tick — sample the SDF clearance field phi -> a small CoefMLP emits
(alpha,beta,gamma) = wall-barrier / goal-spring / damping -> a kinematic bicycle
steers toward a carrot on the goal bearing, deflected by the barrier, with a
bug-style wall-follow escape on a stall (the carrot FSM). Belief is M log-odds
occupancy planes (shared/grouped/private via map_id); the SDF rebuild on a belief
flip IS the replan.

Fix doc inaccuracies the audit caught:
- nav_finale: the 8 vehicles hold the KNOWN city map (freeze_sense) — they do not
  "enter blind"; private belief is configured but inert without sensing.
- nav_fog_ghost: the ground heatmap is the SDF clearance field phi, not the raw
  log-odds belief grid; note this is the reactive core only (no A* planner, unlike
  GRL-SNAM's BeliefRoutePlanner).
- belief modes only diverge in behaviour under --fog; without it every plane equals
  the known map and grouped/private merely recolour the same trajectories.

examples/CMakeLists.txt: install() the example binaries with an $ORIGIN/../lib
RPATH so a cvcpkg recipe can package them without LD_LIBRARY_PATH, and link
cvc::cvcGL (works in-tree and standalone). nav_fog_ghost: size_t loop counter to
silence -Waggressive-loop-optimizations.

The cvcgl-examples cvcpkg recipe is owned by PR #204 (feat/cvcgl-wasm), which
already carries the single recipe with a linux+wasm platform matrix (wasm is a
matrix entry, not a separate -wasm recipe); the three nav demos join that one
recipe rather than a duplicate here.
# Conflicts:
#	src/cvcGL/examples/CMakeLists.txt
Now that #204's cvcgl-examples recipe is on master, extend it to also ship the
nav_city_swarm / nav_fog_ghost / nav_finale binaries alongside lsystem_forest.
build.sh builds every example and installs the cvcgl-examples component via
cmake --install (using examples/CMakeLists.txt's install() rules — the
$ORIGIN-rpath'd bins only, not the cvcGL SDK), replacing the by-hand staging.
package.files gains the three nav bins; cvc_revision 1 -> 2 to republish.

Wasm stays lsystem_forest-only for now; the nav demos' browser builds are a
follow-up.
@transfix
transfix merged commit a7d6176 into master Aug 20, 2026
12 checks passed
@transfix
transfix deleted the feat/cvcgl-nav-demos branch August 20, 2026 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant