Skip to content

cvcGL: mirror viewports — alternate cameras over a shared scene (minimap) - #386

Merged
transfix merged 1 commit into
masterfrom
feat/cvcgl-viewport-mirror
Sep 21, 2026
Merged

transfix merged 1 commit into
masterfrom
feat/cvcgl-viewport-mirror

Conversation

@transfix

@transfix transfix commented Sep 21, 2026 •

Copy link
Copy Markdown
Owner

cvcGL: mirror viewports — alternate cameras over a shared scene (minimap)

Second half of the picture-in-picture story, on top of the merged
ViewportManager core (#384). (Supersedes #385, which GitHub auto-closed when its
stacked base branch was deleted on merge; this is the same commit rebased onto
master.)

Why

#384 gave us N viewports over separate scenes and made a second
setRenderer over one scene a loud error. The other half the demos want is a
minimap: a second view of the same scene from a different camera —
which addSceneViewport now (correctly) refuses.

What

  • ViewportManager::addMirrorViewport(name, sourceViewport, region, layer=2)
    — a viewport flagged mirror, pointed at the source viewport's renderer. It
    does not attach the scene again (so the source keeps its actors) and is
    not tracked in attachedScenes. Each render() copies the source renderer's
    props into the mirror's renderer (shared by reference — one geometry drawn
    twice
    ), so the mirror always shows the live scene from its own camera; a
    node added or re-meshed in the source scene appears in the mirror next frame
    with no extra bookkeeping.
  • Viewport::mirrorSource() (the source renderer, or nullptr) alongside
    isMirror(), plus a manager-only setMirrorSource().

Tests

cvcgl_viewport extended (offscreen, headless): a mirror of the primary over
the same mainScene

  • draws the shared geometry (its rect shows the scene, not just its own
    background — luma > 0.18);
  • is live — a large quad added to the source scene shows up in the mirror
    rect with the mirror camera left untouched (per-frame prop sync);
  • throws when the named source viewport does not exist.

Full cvcgl suite (28 tests) green locally on Windows/MSVC.

Not yet (the remaining follow-ups)

Input router (FindPokedRenderer, in progress), state layout, SceneRenderer→
facade, promoting the nav-city minimap demo, and the SWIG bindings + Python
ChaseCamera shim. Lights for a mirror currently fall back to a headlight
following the mirror camera (explicit StageLighting rigs are not yet mirrored)
— fine for a minimap, noted for the demo pass.

…map)

The true DBG minimap, generalised: a viewport that shows a scene ANOTHER
viewport already draws, from its own camera, without re-attaching the scene
(which SceneGraph::setRenderer would do — blanking the source view, the trap
the previous commit made loud).

ViewportManager::addMirrorViewport(name, sourceViewport, region, layer) adds a
Viewport flagged mirror, pointing at the source viewport's renderer. It does
NOT attach the scene a second time and is not tracked in attachedScenes;
instead render() copies the source renderer's props into the mirror's renderer
each frame (shared by reference — one geometry drawn twice), so the mirror
always shows the live scene from its own viewpoint. A node added or re-meshed
in the source scene appears in the mirror the next frame with no extra work.

Viewport gains isMirror()'s companion mirrorSource() (the source renderer, or
nullptr) and a manager-only setMirrorSource().

cvcgl_viewport extended: a mirror of the primary over the same mainScene draws
the shared geometry (its rect shows the scene, not just its background), a
large quad added to the source scene shows up in the mirror rect (live prop
sync, camera untouched), and mirroring an unknown source throws. Full cvcgl
suite (28 tests) green locally.

Stacked on the ViewportManager core PR.
@transfix
transfix merged commit 28b3a60 into master Sep 21, 2026
13 checks passed
@transfix
transfix deleted the feat/cvcgl-viewport-mirror branch September 21, 2026 02:41
transfix added a commit that referenced this pull request Sep 21, 2026
…p analysis (#389)

Concrete defects a gap-analysis pass found in the merged PiP stack (#384/#386/
#387), fixed before the minimap demo exercises them:

  * Mirror double-drew 2-D overlays: syncMirrorProps copied EVERY prop, so a
    mirror of a scene with FpsHud/ScreenTextHud drew the HUD a second time on the
    inset. It now skips vtkActor2D (a window-space overlay, not scene geometry) —
    matching the shipping wasm PiP.
  * Mirror rendered flat: syncMirrorProps copied view props but not lights, so a
    mirror of a StageLighting-rigged scene lost its lighting. It now copies the
    source's lights (world-space, correct from the mirror's own camera); with
    none, the mirror falls back to VTK's automatic headlight.
  * MB::Right was not the no-op the header claims: its button-down latched a drag
    target and called setActiveViewport, so a right-click silently stole keyboard
    focus and released the prior viewport's held keys. routeMouseButton now
    returns immediately for Right.
  * CameraController::viewportAspect preferred the WINDOW size over the renderer's
    for the Map/ortho fit, so a PiP inset in Map mode framed to the wrong aspect;
    it now prefers the viewport (renderer) size, matching the pan scaling, and
    falls back to the window before the first frame.
  * Fixed the stale "addMirrorViewport, a follow-up" comment (it shipped in #386).

Tests: cvcgl_viewport gains a check that a 2-D actor on the source does NOT reach
the mirror while a source light DOES; cvcgl_viewport_input gains a Right-button
no-op check (no focus steal, no camera motion). Full cvcgl suite (29) green
locally.
transfix added a commit that referenced this pull request Sep 21, 2026
…ython (#390)

Closes the largest gap the PiP work left: the whole ViewportManager/Viewport/
input-router surface (cvcGL #384/#386/#387) was C++-only, so volrover3 and
grl-snam — both Python — could not build multi-viewport or minimap layouts. This
wraps it, so the Python API mirrors C++:

    vm = pycvc_gl.ViewportManager(scene, 1024, 768, False, "main")
    inset = vm.addSceneViewport("inset", scene2, (0.62, 0.05, 0.97, 0.42), 1)
    mini  = vm.addMirrorViewport("mini", "main", (0.62, 0.58, 0.97, 0.95), 2)
    inset.camera().setMode(pycvc_gl.CameraController.Mode_Fly)  # per-viewport
    vm.routeMouseButton(pycvc_gl.ViewportManager.MouseButton_Left, True, x, y)
    vp = vm.viewportAt(x, y)          # None over the gutter
    frame = vm.frameRGB()            # bytes

Binding details, following the existing pycvc_gl patterns:
  * frameRGB() -> bytes (a scoped typemap, like SceneRenderer's — the SceneRenderer
    one does not apply to ViewportManager).
  * region as a Python 4-sequence in (addSceneViewport/addMirrorViewport) and a
    4-tuple out (Viewport.region()), via in/argout typemaps.
  * Viewport has a private ctor -> %nodefaultctor; it is only ever handed out by
    the manager. renderer()/renderWindow()/mirrorSource() reuse the existing
    vtkRenderer*/vtkRenderWindow* -> live vtkmodules typemaps.
  * KEEPALIVE chain mirrors C++ ownership so a live child pins its parent: the
    manager keeps its scene(s); every handed-out Viewport (primary/viewport/
    viewportAt/activeViewport/add*Viewport) keeps the manager; a Viewport's
    camera() keeps the Viewport.
  * MouseButton enum -> ViewportManager.MouseButton_Left/Middle/Right.

New test_pycvc_gl_viewport.py exercises the surface end to end: auto primary,
addSceneViewport over a second scene + addMirrorViewport, viewportAt (layer/
visibility/inputEnabled/gutter), focus-follows-click into cvc::state, the
per-viewport camera (its state under the viewer tree), region tuples, and
frameRGB bytes — self-skipping without a GL driver, hard-exiting past cvcGL's
static-teardown race like the other pycvc_gl tests.

Validated locally by SWIG generation (all 24 ViewportManager + 15 Viewport
methods, the MouseButton enum, and both typemaps wrap cleanly); the compiled
.pyd + this test run in the cvcpkg pycvc-gl recipe, which builds against the
python-enabled VTK the module needs.
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