Repository navigation
nav demos: control menus everywhere + two new limited-belief scenarios (dynamic map, traffic) - #215
Merged
Merged
Conversation
Same machinery, three different ways belief and truth come apart:
ghost — the map claims a wall reality lacks (as before)
dynamic — the map starts HONEST, then the world changes: a blockage appears
mid-run (sim_world::add_obstacle writes the live planning surface,
composited on the next SENSE tick, so the agent only knows once it
senses) and it must notice and re-route
traffic — the ghost lie plus N cross-traffic vehicles sweeping THROUGH the
hero's corridor, so belief-vs-truth plays out against moving
obstacles that carve their own fog
The lie always lives in the BELIEF, never in truth — collision stays scored
against truth, which is what keeps these honest. Captions are scenario-specific
('The map is honest — for now.' -> 'THE WORLD CHANGED: the way ahead just
closed.').
Control menu (Scenario / Sim / View / Camera) + panel: switch scenario, restart,
pause, 2-D map toggle (pan+zoom only), captions, world speed (live), sensor
range and traffic count. A scenario change re-execs the demo — it decides agent
count, prior map and the whole scene graph, so a fresh process is the honest way
to guarantee no stale belief or mismatched mesh survives.
--scenario / --traffic / --range on the CLI too. Verified: traffic renders the
gold hero + cyan cross-traffic each carving fog; dynamic fires the blockage and
the agent re-routes.
…-D map Sim menu jumps straight to Act 2 (pursuit) or replays the two-act arc from the top (resetting the target markers, staging line and engagement lines with it) — no more waiting 45% of the run to see the pursuit. View toggles route spines, minimap, act cards and a live 2-D map (pan+zoom only). Camera menu carries the same state-bound sensitivity/speed sliders as the other demos. Panel reports the vehicle count, the current act, and says plainly when the city is synthetic.
A capture is a deliverable — an ImGui panel across the frame is not what you want in an mp4 or a gallery thumbnail. The overlay is now hidden automatically while capturing (and offscreen), with --no-ui to force it off interactively too.
…Gestures)
Phones have no mouse. VTK's own multi-touch cannot deliver a pinch in the
browser — its gesture recognizer is complete and enabled, but the wasm
interactor feeds it wrong in three independent ways:
1. ProcessEvent loops SetEventInformation over every touch then calls
LeftButtonPressEvent ONCE, so two fingers landing in one touchstart (how
people actually pinch) leaves PointersDownCount at 1 and RecognizeGesture
— which requires >1 — never runs: the camera orbits instead of zooming;
2. it uses the touch ARRAY INDEX as VTK's pointer slot instead of
Touch.identifier, so slots shift and leak when fingers lift out of order
(VTK ships GetPointerIndexForContact for exactly this and the Android
interactor uses it; the wasm one never calls it);
3. vtkInteractorStyle::OnPinch/OnPan are empty virtuals that only
vtkInteractorStyleMultiTouchCamera overrides.
TouchGestures sidesteps all of it: capture-phase listeners on the canvas's
PARENT handle MULTI-TOUCH ONLY and stop those events before VTK sees them,
while SINGLE touches pass through untouched — so taps on ImGui widgets and
one-finger drag keep working exactly as before. ImGui is single-touch by design,
so the two layers can never fight over a gesture. The listeners only accumulate;
update() drains them once per frame (VTK drains its own queue in rAF, so frame
time is the consistent place to apply camera changes). Pinch maps to
mouseWheel() — already 'zoom' in every camera mode — via log2 so doubling the
finger distance is a fixed zoom regardless of where the pinch began.
Also fixes (3) for real touchscreens: CvcCameraInteractorStyle now implements
OnStartPinch/OnPinch/OnEndPinch/OnPan, converting VTK's absolute gesture scale
to relative steps.
Wasm pages get a real HTML Fullscreen button — fullscreen must be requested from
a DOM gesture handler, since emscripten_request_fullscreen called from the app
runs inside rAF and fails the transient-activation check. It targets the canvas
WRAPPER and nudges a resize on fullscreenchange.
Native builds compile TouchGestures to a no-op shell. nav_common_test 7/7.
Per review: no singletons, and touch settings belong in the state tree like CameraController's. - TouchGestures is now cvc::state_object<TouchGestures>, state at '<scene prefix>.viewers.<viewer>.touch' with two-way-bound keys enabled / pinch_steps / pan_enabled / invert_pinch. Set pinch_steps from a script, a config or a replicated peer and the gesture response follows; the setters write the same state. Same viewerStatePath()/setInstanceThreading(false) shape as FpsHud and CameraController. - The DOM gesture accumulator moved from a window.__cvcglTouch GLOBAL to a property of the canvas ELEMENT, and the canvas is selected per instance — two viewers on one page no longer share one accumulator. Draining is now a single EM_JS call filling out[3] instead of three separate boundary crossings. - ImGuiBinding's per-path edit cache was a function-static std::map — a process-wide singleton shared by every viewer and every ImGui context, and it outlived both. It now lives in the ImGui CONTEXT's own storage (ImGui::GetStateStorage + ImHashStr), so it dies with the context that owns the widget and cannot collide across viewers.
The wasm build steps sim_world INLINE (no worker thread), so the restart path's sim->stop()/make_unique<sim_thread> only exist natively. Pause now works on both: the worker's set_paused natively, a simPausedEm flag around the inline step in the browser.
…aste There is no ImGui platform backend under us — VTK owns the window and exposes no clipboard API — so nothing supplied copy/paste except on Windows. ImGuiOverlay now installs Platform_Get/SetClipboardTextFn on the context it creates, so Ctrl+C / Ctrl+V in any InputText work wherever the platform allows. Per platform, honestly: - Windows: imgui core ALREADY ships a complete Win32 implementation (OpenClipboard/CF_UNICODETEXT), so we forward to it instead of maintaining a second copy. - X11: implemented here — become the CLIPBOARD selection owner on copy and answer SelectionRequest events; on paste, XConvertSelection with a BOUNDED wait (this runs on the render thread, so a dead/slow owner must not freeze the app — it returns empty instead). Note the X11 model: a selection belongs to a live client, so text copied from a cvcGL app disappears when it exits unless a clipboard manager takes ownership. That is X11, not a shortcut. - macOS: NSPasteboard hooks (Clipboard_mac.mm, when the Cocoa bits are built). - WebAssembly: COPY works (navigator.clipboard.writeText, execCommand fallback). PASTE cannot be synchronous — ImGui's getter must return immediately while the browser's readText() is async, secure-context-only and permission/gesture gated (Firefox and Safari prompt on EVERY read). So get() returns the most recent text the PAGE received from a real paste event, which the browser does deliver synchronously to a listener. A paste the app never saw returns empty rather than blocking or lying. canCopy()/canPaste() report this so a UI can grey out a Paste button instead of silently doing nothing. Verified on X11: round-trip PASS, and a SEPARATE process read what cvcGL copied (the real XConvertSelection + SelectionRequest path, not a local short-circuit).
A parallel projection's scale is a half-HEIGHT, so framing a map by height alone crops its sides on any viewport narrower than the map — which is every phone in portrait, and the demos default to the top-down map view. Half the scene simply was not on screen. frameMap() now takes an optional half-width and fits the whole rect (letterboxed rather than cropped), and CameraController re-fits when the viewport changes shape — rotating a phone, entering fullscreen, dragging a window. Once the user zooms, the framing is theirs and auto-fitting stops. Both the aspect queries ask the render WINDOW before the renderer: a renderer reports its size only after it has rendered, so at setup time it answers with a default and the fit silently degrades to the height-only crop this fixes. Verified with offscreen captures at 450x900 and 900x450: the portrait frame now shows the whole map (agent, sensor ring, ghost wall, goal, border) where it previously cut off the goal, and the landscape frame is unchanged.
…binary
The restart path called execv("/proc/self/exe") to get a clean slate. That is
not a reasonable way for a program to restart its own simulation, and in a
browser it is not even possible: wasm has no exec, so every scenario change in
the deployed demo printed "restart exec failed: Exec format error" and silently
did nothing. The menu looked like it worked.
The world, the agent roster and the meshes sized from it now live behind a
unique_ptr and a build_world() lambda, so restart_scenario() rebuilds them in
place — same process, same window, same GL context. It also resets the story
state (trail, captions, pacer, ghost-cleared time), which the exec got for free
and a partial rebuild would have leaked into the next run.
nav_city_swarm already restarted this way; this brings fog_ghost in line.
Verified in the browser, where it used to fail: clicking Apply/Restart logs
"restarted — scenario=ghost, 1 vehicle", and switching Scenario -> traffic logs
"restarted — scenario=traffic, 6 vehicles" — the 1 -> 6 roster change exercises
the agent-mesh resize — with the demo still running and no errors after.
…natively Building with -DCVC_WASM_PTHREADS=ON produced a threaded binary whose sim still ran inline on the render thread, so the flag bought nothing. The seven sim_thread guards in nav_city_swarm asked `#ifndef __EMSCRIPTEN__`, and -pthread does not undefine __EMSCRIPTEN__ — it defines __EMSCRIPTEN_PTHREADS__ alongside it. Every guard therefore took the single-threaded branch in a build made specifically to be threaded. nav_common.h now defines CVC_NAV_DEMO_SIM_WORKER (native, or wasm built -pthread) and the demo gates on that. A threaded build genuinely runs the swarm on a worker; the non-threaded browser build keeps stepping inline, which is what GitHub Pages needs since it cannot send COOP/COEP. Measured in-browser at the 800-agent default, cross-origin isolated, same scene: single-threaded 23.1 fps avg p50 16.7ms p90 200ms p99 233ms max 267ms -pthread 56.8 fps avg p50 16.7ms Both hit the vsync p50; the difference is entirely in the tail, which is the signature of the sim step blocking the frame loop. Moving it off-thread removes the stalls. (Headless software rendering, so treat the absolute numbers as indicative and the ratio as the result.)
…ws are mush The scene graph only had directional lights, and VTK bakes those with a PARALLEL shadow projection fitted to the whole scene bounding box (vtkShadowMapBakerPass::BuildCameraLight: parallelScale = max(bboxW, bboxH)/2). One shadow map is therefore smeared across everything present, so a scene that also holds a sea plane and a sky billboard spends nearly all its shadow texels on empty space and the shadows that matter get a handful. Adding scenery makes existing shadows worse — lsystem_forest already carries a scar from this, an explicit comment about a billboard "900 units away" stretching the light's depth range until the island self-shadowed to black. A SPOT light is baked with a PERSPECTIVE projection whose view angle is the light's cone, so its texels land only inside the cone. Aim a 32-degree spot at the subject and effectively the whole map is spent on the subject. So: SceneGraph gains addSpotLight/setLightPosition/setLightTarget/setLightCone (cone clamped below 90 — VTK's LightCreatesShadow() silently drops any positional light at 90+, which would mean no shadow rather than a wide one), and cvc::gl::StageLighting builds a real rig out of them: key, fill, back, an overhead wash ring, and placeable specials, with four presets. Fill and wash deliberately cast no shadow — a second shadow from a fill is the classic amateur-lighting tell, and each caster costs a whole scene depth re-render. Settings are cvc::state under "<scene prefix>.lighting", two-way bound like CameraController, and cvc::gl::ui::StageLightingPanel is the canonical control surface for them — preset-first, with the cone/shadow relationship in a tooltip where someone tuning it will actually read it.
…the camera Three things, all verified against the ImGui 1.92.9 source rather than assumed: TOUCH RELEASE LOCKED THE CAMERA OUT. A lifted finger hovers nothing, but a mouse stays where it was left, so ImGui kept the last touched widget hovered forever. That holds io.WantCaptureMouse true, and intercept() returns exactly that as VTK's abort flag — so after ONE tap on the UI, every subsequent event was aborted and the CameraController never received another. Fixed the way the Android backend does it: move the pointer off-screen on touch release (and on LeaveEvent, which was already observed but silently ignored). This depends on io.ConfigInputTrickleEventQueue staying true — with trickling off the clear collapses into the release's own frame and the tap is swallowed instead. SCALING. setUiScale() multiplies fonts and widget metrics together, defaulting to 2x on a touch device (browser: ontouchstart / maxTouchPoints). Two traps avoided: io.FontGlobalScale is obsolete in 1.92 and asserts against style.FontScaleMain, and ScaleAllSizes() multiplies IN PLACE, so calling it per frame compounds (five 2x calls give FramePadding 128 instead of 8) — the style is therefore re-derived from a pristine copy captured at construction. Also set TouchExtraPadding explicitly, since it defaults to (0,0) and scaling zero is still zero, and raise the drag threshold because fingers wobble. Text stays crisp: 1.92 re-bakes glyphs at the final size. But the default font is chosen by a size heuristic that runs on the first frame, so we were silently getting the 13px bitmap face; now we ask for the scalable one explicitly. THE UI MUST BE DISMISSABLE. A large translucent circular button sits in the bottom-right corner and hides/restores the panels. It owns a zero-padding window so it claims exactly its own circle of input and no more of the scene — a foreground draw-list would paint correctly but let taps fall through to the camera.
…y mode too Replaces the two directional lights (a warm "sun" and a cool sky fill) with a cvc::gl::StageLighting three-point rig aimed at the ISLAND. The sun was the reason the shadows were poor: VTK fits a directional light's shadow map to the whole scene bounding box, and this scene's box contains a sea plane and a sun billboard 900 units out, so nearly every shadow texel landed on empty water. The rig's stage radius is the island (120 units), deliberately not the scene. The demo now shows the LIBRARY's cvc::gl::ui::StageLightingPanel rather than demo-local lighting controls, which is the point of canonising it — the same call lights any cvcGL scene. Scene menu toggles the panel. Also fixes pinch-to-zoom in fly mode. TouchGestures routed a pinch to mouseWheel(), which zooms in Orbit (orbit distance) and Map (parallel scale) but adjusts movement SPEED in Fly — so pinching in a flying scene changed how fast WASD moved and appeared to do nothing. CameraController::dolly() steps the eye along its own view direction, which is what zoom has to mean when there is no orbit centre, and TouchGestures picks it per mode.
GIZMOS. StageLighting can now draw itself into the scene: a fixture marker where each light hangs, a line down its aim, and the light's CONE. The cone is the useful part — it is exactly the frustum VTK bakes that light's shadow map with, so the wireframe answers "why is this unshadowed?" (the subject is outside the cone) and "why is this shadow mushy?" (the cone is far wider than the subject, so the map is mostly covering nothing). Toggle: "Show lights" in the panel, or the show_gizmos state key. The gizmos are drawn just under opaque, which puts them in the translucent bucket that the opaque shadow bake skips — the same trick lsystem_forest already used for its sun billboard — so the debug overlay cannot alter the shadows it is being used to debug. They ARE scene geometry though, and a cone reaches outside the acting area, so anything that auto-fits to scene bounds pulls back while they are on. Documented in the header rather than papered over. CLOSE BUTTON. StageLightingPanel took an `open` flag and passed it to ImGui::Begin, which draws the close box and clears the flag — but does NOT skip the window next frame; the caller is supposed to. So clicking X did nothing visible. The panel now honours its own flag, which is what a library panel should do. (It was always reachable from Scene > Stage lighting; that menu item is how you bring it back.) Also: on a small viewport the panels now start CLOSED. Finger-sized widgets at 2x would otherwise bury a phone screen the moment the demo loads — the floating button is always there to bring them back.
ScreenTextHud was the one overlay deliberately left unbound; the header argued a state write per change would be overhead, because captions are driven by a table the frame loop re-evaluates every frame. That concern was real, but the fix is narrower than dropping binding: every write is now CHANGE-GATED, so setText() with the same string sixty times a second costs nothing after the first. Only a real change reaches the state tree. Text, position, font size, colour, opacity, centring and visibility now live under "<scene prefix>.viewers.<viewer>.hud.<name>", two-way bound like FpsHud. Several overlays share a viewer (caption + status + act card), so each needs a NAME or they would share state nodes — the constructor takes one, and the demos that build two now pass distinct names.
SceneGraph's shadow settings (enabled / resolution / interval) and ImGuiOverlay's UI settings (visible / scale / touch_mode / panels_open / toggle_button) were the only user-facing settings still living as plain members. Neither class is a state_object — SceneGraph owns the scene tree, ImGuiOverlay is a render hook — so rather than convert them, each now owns a small state_object (cvc::gl::ShadowSettings, cvc::gl::UiSettings) that mirrors its settings to "<prefix>.shadows" and "<prefix>.viewers.<viewer>.ui". Both carry a re-entry guard, since a state write calls the setter which would write state again. Verified with a harness (tests/state_binding_audit.cpp): every key is present with a real seeded value, and object -> state round-trips for StageLighting, ScreenTextHud and the shadow settings. TWO THINGS THE AUDIT ESTABLISHED THAT ARE WORTH KNOWING: 1. Hand-built absolute dotted paths do NOT resolve to the nodes a state_object creates — cvc::state loses the separator when a multi-segment path is walked (keys land as "audit.lightingwarm_key"; the same artifact is visible in pre-existing node paths like "...children.axisaxis_length"). Read and write through a state_object rooted at the same path instead. My first harness did the former and reported false failures across the board. 2. state -> object does NOT currently fire: an external write to a settings key updates the node but does not reach handleStateChanged, so the object does not follow. This is PRE-EXISTING, not new — CameraController, the oldest binding in the tree, behaves the same way. Almost certainly the same cause as (1): the object subscribes to childChanged on its own multi-segment node, while the write lands on a flattened key elsewhere. Worth its own fix; until then "scriptable" means the setters and the bound ImGui widgets, not arbitrary external state writes.
Checks that every cvcGL setting is present in the state tree with a real value and that object -> state round-trips. Reads/writes go through a state_object rooted at the same path as the object under test, NOT hand-built absolute dotted paths — those do not resolve to the same nodes (see the binding commit).
…bject
outside libcvc
cvc::state::SEPARATOR was `inline static const std::string SEPARATOR{"."}`.
Being an inline variable with a DYNAMIC initializer, every translation unit
outside libcvc that read it got an EMPTY string — the initializer for that copy
had not run. Minimal repro, no cvcGL involved:
Peer P(app, "aa.bb"); // any state_object
P.getState("cc").value(99);
root("aa.bb.cc").value() -> "" (before)
P.stateName("cc") -> "aa.bbcc" (before)
SEPARATOR -> "" (len 0) (before)
So stateName() computed prefix + "" + child, and EVERY state_object compiled
outside libcvc — that is all of cvcGL: CameraController, FpsHud, TouchGestures,
StageLighting, the nodes — wrote FLATTENED keys like "scene.lightingwarm_key"
while subscribing to childChanged on "scene.lighting", a SIBLING of where its
own writes landed. Two consequences, both silent:
* external state writes never drove any object (state -> object was dead), so
"scriptable" was only ever true through the C++ setters;
* absolute paths could not read a state_object's values, and the tree filled
with flattened junk keys next to the real ones.
constexpr const char* has no dynamic initialization, so every TU and every
shared object sees ".". It also keeps what the old comment wanted — no MSVC
data-member export — since a compile-time constant is materialised per TU.
Also fixes a bug this exposed in the new ShadowSettings wiring: the settings
object's constructor seeds its own defaults, which fires handleStateChanged and
calls back into the setters, so a setShadowResolution(2048) was being clobbered
back to 1024. Current values are now captured before construction, and the
re-entry guard covers construction so the callback cannot build a second
settings object while the first is still being made.
Verified: tests/state_binding_audit.cpp passes 0 failures — every setting
present, and BOTH directions work now (object -> state and state -> object) for
StageLighting, ScreenTextHud and the shadow settings. Full suite: 2327/2327.
transfix
added a commit
that referenced
this pull request
Sep 2, 2026
…cgl-examples (#312) ImGuiOverlay's whole point is that "without CVC_ENABLE_IMGUI the whole class compiles to inert stubs, so consumers never need an #ifdef" (its own file header). Of the 15 methods the header declares, 14 had a stub. attachCamera did not. The three nav demos take the class at its word and call it unguarded, so nav_city_swarm, nav_fog_ghost and nav_finale all failed to link with undefined reference to cvc::gl::ImGuiOverlay::attachCamera(cvc::gl::CameraController&) in the one configuration anybody builds without imgui: the cvcgl-examples publish lane, where nothing installs imgui and src/cvcGL/CMakeLists.txt silently settles on CVC_ENABLE_IMGUI OFF. lsystem_forest, lsystem_coast and bunny_shadow link there because they wrap their overlay blocks in #ifdef — which is the noise this class exists to remove. Not a regression: the publish step that builds these demos landed in #213 about three hours AFTER the last publish run, so the v3.3.0 tag was the first time it ever executed, and it failed on first contact. The unguarded calls arrived separately, in cb5dee0 and #215, and CI had never built them imgui-less. Fixing the stub rather than the three call sites keeps the contract the header advertises, so the next consumer — volrover3, pycvc_gl, a new demo — cannot trip the same wire. With no imgui there is no input to hand off, so the camera never needs telling about it and an empty body is the right behaviour. Verified by compiling the TU exactly as that lane does (no CVC_ENABLE_IMGUI): the symbol goes from 0 definitions on master to 1 here, matching the mangled name in the link error. Audited the rest of the block at the same time — all 15 declared methods now have stubs. Follow-up worth doing separately: the published demos currently ship with no UI at all, since imgui is simply absent from the cvcgl-examples closure. imgui 1.92.9+cvc.1 is on the catalog for linux, but adding it needs care — cvcGL links imgui by ABSOLUTE find_library path and exports that target, so letting the imgui prefix reach the earlier cvcgl step would bake a builder path into the published SDK (the trap the X11 comment in that CMakeLists documents).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds on the ImGui overlay (#214): every nav demo now has a real control menu, and the fog/belief family grows two new scenarios.
Control menus (all three demos)
Sim — pause, step, and a genuine Restart. View — live 2-D map toggle, layer visibility (trails/goals/spines/minimap/captions/act cards), shadows. Camera — look sensitivity and move speed as state-bound sliders (
cvc::gl::ui), so a script or peer moving those values moves the slider too.sim_world, so the world is reconstructed and every N-sized mesh (agent glyphs, goal pyramids, trail ring buffer) rebuilt with it, joining the sim thread first (it borrows the world).Two new limited-belief scenarios (
nav_fog_ghost --scenario)Same machinery, three ways belief and truth come apart:
sim_world::add_obstaclewrites the live planning surface, composited on the next SENSE tick, so the agent only knows once it senses) and must re-route. Caption arc: "The map is honest — for now." → "THE WORLD CHANGED: the way ahead just closed."The lie always lives in the belief, never in
truth— collision stays scored against truth, which is what keeps these honest.2-D map = pan + zoom, never rotate
CameraController::Mode::Map(from #214): parallel projection, drag pans (converted through the parallel scale so the grabbed point stays under the cursor at any zoom), wheel zooms, andtoggleMode()refuses to leave Map so Tab can't tumble a map. The swarm demo gets the same 2-D mode, with shadow mapping left on and the offset light — it does still look good top-down.A scenario change re-execs the demo: the scenario decides agent count, prior map and the whole scene graph, so a fresh process is the honest way to guarantee no stale belief or mismatched mesh survives.
Verified with offscreen captures per scenario (traffic shows the gold hero plus cyan cross-traffic carving fog; dynamic fires the blockage and re-routes; the swarm panel drives restart at new agent counts).
nav_common_test7/7.