Skip to content

cvcGL: WebAssembly build of lsystem_forest, FpsHud overlay, cvcgl-examples package - #204

Merged
transfix merged 7 commits into
masterfrom
feat/cvcgl-wasm
Aug 20, 2026
Merged

transfix merged 7 commits into
masterfrom
feat/cvcgl-wasm

Conversation

@transfix

Copy link
Copy Markdown
Owner

What

The cvcGL lsystem_forest demo now runs interactively in the browser — live at https://transfix.github.io/libcvc/ (gh-pages, deployed from this branch's build). The full scene works under WebGL2: bump-mapped island terrain, the sea + drifting cloud volumes (GPU ray-cast, scattering), the wind-posed forest, shadow maps, orbit/fly camera. Companion PR: transfix/libcvc-deps#517 (rendering-enabled wasm vtk + ESSL patch this links against).

WebAssembly port (single-threaded by default)

  • emcmake build via src/cvcGL/examples/wasm/build-wasm-demo.sh against the cvcpkg wasm channel (emsdk 5.0.7, static boost/zstd/cgal + the rendering-enabled vtk). Trimmed option set: CUDA/HDF5/IMOD/ImageMagick/FFTW/assimp/mesher/SDF/state_exec/CLI/tests off.
  • The demo keeps its native while-loop and yields per frame via Asyncify emscripten_sleep(0) — SceneRenderer already drives ProcessEvents() instead of Start(), a pattern VTK's wasm interactor explicitly supports (it self-registers its canvas callbacks on that path).
  • SetupBoost: static Boost under Emscripten; BOOST_HAS_PTHREADS globally (Boost compiles against Emscripten's single-threaded pthread stubs, matching the wasm boost bundle).
  • Boost.Asio is excluded from the wasm boost bundle: guard the include, stub get_local_ip_address() in the browser sandbox.
  • SceneGraph skips the state_publisher worker thread in single-threaded wasm (writes still enqueue bounded/coalesced; the demo drains via publisher().flush() per frame).
  • GLES3 shader fix: under Emscripten VTK swaps in vtkOpenGLES30PolyDataMapper, whose lighting local is normalizedNormalVCVSOutput — the demo's bump shaders wrote normalVCVSOutput, which there is the raw in varying: an ESSL error (NVIDIA desktop silently tolerates it) that killed the terrain/bark programs. The replacement now targets the variant's actual local via CVC_FS_NORMAL; desktop GLSL is byte-identical.
  • Host page + serve.py (COOP/COEP static server) under examples/wasm/; the build dir is directly servable.

cvc::gl::FpsHud (native + wasm)

An on-screen FPS readout drawn by VTK itself (vtkTextActor overlay). Everything is cvc::state under <scene>.viewers.<name>.hud — enabled, rebindable keys.toggle ('f'), update_hz, placement — two-way bound exactly like CameraController; the measured rate mirrors to ...hud.fps (throttled). Frames are counted with an EndEvent observer on the render window (no host-loop changes); the key is a priority-1.0 interactor observer, coexisting with the camera's interactor style. Headless state test: cvcgl_fps_hud (10 checks). lsystem_forest shows it by default, off for captures.

Threaded variant (opt-in)

-DCVC_WASM_PTHREADS=ON / build-wasm-demo.sh --pthread: real std::thread (publisher runs under __EMSCRIPTEN_PTHREADS__), -sPTHREAD_POOL_SIZE=4, deps from a CVC_WASM_THREADS=1 prefix. Verified running cross-origin isolated via serve.py.

cvcpkg/recipes/cvcgl-examples

The examples as installable commands: native bin/lsystem_forest (src/cvcGL standalone + CVC_BUILD_EXAMPLES, cvcgl-recipe pattern), a wasm matrix entry packaging the browser build under share/cvcgl-examples/web/, and bin/cvcgl-examples-web — serves the wasm demo cross-origin isolated and opens a browser. cvcpkg validate passes. The wasm entry publishes once vtk 9.5.0+cvc.3 (wasm) from libcvc-deps#517 is in the catalog.

Verification

  • Native: full build with the wasm option set compiles + links; cvcgl_fps_hud 10/10.
  • Browser (single-threaded): scene renders with zero shader errors; mouse orbit works; 'f' toggles the HUD (canvas pixel sampling: 115 text pixels → 0 → 118 across two toggles).
  • Browser (threaded): crossOriginIsolated === true, runtime up, zero errors.
  • GitHub Pages serves the exact verified binaries (sha256-identical).

Single-threaded browser build against the cvcpkg wasm channel (emsdk 5.0.7,
static boost/zstd, VTK 9.5 with rendering modules):
- SetupBoost: static Boost under Emscripten (wasm bundles are static-only),
  no BOOST_ALL_DYN_LINK there
- utility: Boost.Asio is excluded from the wasm Boost bundle; guard the
  include and stub get_local_ip_address in the browser sandbox
- SceneGraph: don't start the state_publisher worker thread under wasm;
  writers still enqueue (bounded, coalesced), embedder drains via flush()
- lsystem_forest: yield to the browser event loop every frame via
  emscripten_sleep (Asyncify) and drain the publisher at the same cadence
- global -fexceptions under Emscripten (cvc throws/catches as API surface)
- examples/wasm/: host page + reproducible build script
…sher include

Boost's config refuses to compile without -pthread; Emscripten ships the
pthread API as single-threaded stubs, so force Boost onto it with the same
define the wasm Boost bundle itself was built with. The example TU needs
state_publisher.h directly (SceneGraph.h only forward-declares it).
The writable normal at //VTK::Normal::Impl differs by mapper: desktop
vtkOpenGLPolyDataMapper declares a local normalVCVSOutput shadowing the
varying; the GLES3 mapper (Emscripten/WebGL2) declares
normalizedNormalVCVSOutput and never shadows the varying, so writing
normalVCVSOutput there is an ESSL 'can't modify an input' error and the
terrain/bark programs failed to compile in the browser. Select the
variant's actual local at C++ compile time; desktop GLSL is unchanged.
Host page now retains diagnostic stderr lines across VTK's shader dumps.
FpsHud: an on-screen FPS readout drawn by VTK itself (vtkTextActor overlay),
so it appears in the native window, offscreen captures and the wasm canvas
alike. Everything is cvc::state under <scene>.viewers.<name>.hud — enabled,
the rebindable toggle key ('f'), update rate, placement — two-way bound like
CameraController. Frames are measured with an EndEvent observer on the render
window (no host-loop changes); the toggle key is a priority-1.0 observer on
the interactor so it coexists with the camera's interactor style. Headless
state test included. lsystem_forest shows it by default (off for captures).

Threaded wasm variant: CVC_WASM_PTHREADS compiles the tree with -pthread
(deps must come from a CVC_WASM_THREADS=1 prefix), the scene publisher thread
runs for real under __EMSCRIPTEN_PTHREADS__, build-wasm-demo.sh grows a
--pthread mode, and wasm/serve.py hosts cross-origin isolated (COOP/COEP).

cvcgl-examples recipe: the examples as cvcpkg commands — native
bin/lsystem_forest (src/cvcGL standalone + CVC_BUILD_EXAMPLES, cvcgl recipe
pattern), a wasm matrix entry packaging the browser build under
share/cvcgl-examples/web/, and a bin/cvcgl-examples-web launcher that serves
it and opens a browser. cvcpkg validate passes.
…-busting

A 25 MB fetch behind a bare spinner reads as a hang on slow links, and a
cached 404 (a first visit racing a deploy) wedges silently. Fetch the wasm
directly with a live progress readout, surface HTTP failures as status text,
and key ?v= to the page's own Last-Modified so redeploys revalidate stale
caches.
VTK's wasm interactor rewrites the canvas's PARENT to
position:relative; width:100%; height:100% (initializeCanvasElement in
vtkWebAssemblyRenderWindowInteractor.js). A percentage height only resolves
against a parent with a definite height, so embedding the canvas directly in
a container whose ancestors are auto-height silently yields a 0-height
drawing buffer and a blank demo. This page's flex chain happened to satisfy
it; the hosted copy did not.

Give the canvas its own wrapper and document the constraint, so the page is
robust in either layout and consumers copying it inherit the safe structure.
@transfix
transfix merged commit 5bca94b into master Aug 20, 2026
12 checks passed
transfix added a commit that referenced this pull request Aug 20, 2026
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.
transfix added a commit that referenced this pull request Aug 20, 2026
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 added a commit that referenced this pull request Aug 21, 2026
The cvcgl-examples recipe has been in the tree since #204 but was never
wired into publish-cvcpkg.yml, so the example commands never reached the
catalog: the workflow only knew about libcvc, libcvc-cuda, cvcgl and the
pycvc columns.

Add a linux release step alongside cvcgl, plus a cvcgl_examples output on
compute-revisions so the revision is chosen the same way as every other
package (`cvcpkg next-revision`).  Nothing links the examples, so unlike
cvcgl this runs only in the pyver-311 column rather than in every column.

The step invokes the recipe's own build.sh instead of repeating its cmake
in YAML.  Duplicating it would leave two sources of truth for flags like
the -DCGAL_Boost_USE_STATIC_LIBS=OFF workaround (#207) -- and a recipe
drifting from what CI actually runs is exactly how one passes `cvcpkg
validate` while being broken.  build.sh takes its prefixes from a single
CVC_DEPS_PREFIX, and CMAKE_PREFIX_PATH is a list, so the three prefixes
this job spreads its dependencies across are handed over as one
semicolon-separated value (verified: cvc + Boost both resolve from a
multi-prefix list passed through build.sh's quoting).

The nav demos need cvc::nav, which exists only in libcvc >= the nav
kernels (#198) -- newer than the published bundle.  That resolves itself
here because the job builds and installs libcvc from this tree into
$STAGE before this step runs; publishing the examples from anywhere else
needs a libcvc republish first.

The recipe's `platform: wasm` entry (the browser build under
share/cvcgl-examples/web/) is deliberately NOT wired up: it needs emsdk,
the wasm dependency closure, and a rendering-enabled wasm vtk on the
catalog.  Left as a TODO in the step.
@transfix
transfix deleted the feat/cvcgl-wasm branch October 29, 2026 20:52
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