wgpu backend: per-element visibility + H/Shift+H/I hotkeys

Closes the interactive selection loop. After this commit you can:
  - LMB-click an object  → highlight (selection)
  - Press H              → hide all selected
  - Press Shift+H        → show all (clear hidden set)
  - Press I              → isolate selected (hide everything else)

WgpuVisibilityState (new header) is a plain unordered_set<uint32_t> of
hidden object_ids — mirrors src/ifcviewer/Visibility.h's shape but
stays Qt-free for the ifcviewer-core extract later.

cullModelCpuCompute consults visibility_.isHidden(inst.object_id)
before the frustum test — hidden instances cost nothing on every axis
(no draw, no depth contribution, no pick hit). The CPU vector is
read concurrently by the parallel cull workers, which is safe because
mutations only happen between renders (handlers requestUpdate after
mutating; render reads).

Hiding deselects (matches GL behaviour: H clears the now-invisible
selection rather than leaving phantom selected-but-invisible ids).

Stage 5's last piece — clip planes — is deferred. Adding the uniform
array + WGSL discard is mechanical, but the section-tool UI that
drives them isn't ported yet (minimal viewer has no way to place a
clip plane), so it'd ship as empty plumbing. Will land alongside the
section-tool port.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Dion Moult
2026-05-27 20:28:07 +10:00
parent 54fa7d8379
commit 4dfe27e251
3 changed files with 119 additions and 0 deletions
+51
View File
@@ -1941,6 +1941,9 @@ uint32_t WgpuViewportWindow::cullModelCpuCompute(WgpuModelGpuData& m,
for (uint32_t i = 0; i < uint32_t(m.instances.size()); ++i) {
const auto& inst = m.instances[i];
if (inst.mesh_id >= m.meshes.size()) continue;
// Cheapest possible cull first: explicit user-hidden flag. Skips
// every downstream cost (frustum / HiZ / draw / pick).
if (visibility_.isHidden(inst.object_id)) continue;
if (!aabbInFrustum(inst.world_aabb_min, inst.world_aabb_max, planes)) continue;
const MeshInfo& mesh = m.meshes[inst.mesh_id];
@@ -2972,6 +2975,54 @@ void WgpuViewportWindow::mouseMoveEvent(QMouseEvent* event) {
}
}
void WgpuViewportWindow::keyPressEvent(QKeyEvent* event) {
// Visibility shortcuts, modelled on the GL viewer:
// H — hide selected
// Shift+H — show all (clear hidden set)
// I — isolate selected (hide everything not currently selected)
// None of these are useful without a selection (except show-all), so we
// skip silently rather than burning a cull on an empty mutation.
const auto mods = event->modifiers();
const int key = event->key();
if (key == Qt::Key_H && (mods & Qt::ShiftModifier)) {
if (visibility_.hiddenCount() == 0) return;
visibility_.clear();
qInfo() << "[wgpu] show all";
requestUpdate();
return;
}
if (key == Qt::Key_H) {
if (selection_.count() == 0) return;
for (uint32_t id : selection_.ids()) visibility_.hide(id);
const size_t n = selection_.count();
selection_.clear(); // hiding deselects, matching GL behaviour
qInfo().noquote().nospace() << "[wgpu] hid " << n << " selected";
requestUpdate();
return;
}
if (key == Qt::Key_I) {
if (selection_.count() == 0) return;
// Walk every instance across all models; hide those NOT in selection.
size_t hidden_now = 0;
for (auto& [mid, m] : models_gpu_) {
for (const auto& inst : m.instances) {
if (selection_.contains(inst.object_id)) continue;
if (!visibility_.isHidden(inst.object_id)) {
visibility_.hide(inst.object_id);
++hidden_now;
}
}
}
qInfo().noquote().nospace() << "[wgpu] isolated " << selection_.count()
<< " (hid " << hidden_now << " others)";
requestUpdate();
return;
}
QWindow::keyPressEvent(event);
}
void WgpuViewportWindow::wheelEvent(QWheelEvent* event) {
// 120 = one notch on a typical mouse. Each notch zooms ~12% in/out;
// sign matches conventional "wheel up = zoom in".