ifcviewer: add Focus-on-Object and View-All camera shortcuts

F (no modifier) re-aims the orbit camera at the selected object's
world AABB centroid and dollies camera_distance_ so the bounding
sphere fits the current viewport.  Home does the same for the union
of all finalized models.  Both preserve yaw/pitch so the user keeps
their orientation; both no-op in FPS mode.

Scene AABB prefers the per-model BVH root when available and falls
back to walking InstanceCpu world AABBs.  Object AABB unions every
matching instance.  Distance accounts for portrait windows by using
the tighter of the horizontal and vertical FOV constraints.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Dion Moult
2026-04-30 11:34:35 +10:00
parent 1ca2e12f92
commit a06e5ecdf5
2 changed files with 135 additions and 0 deletions
+19
View File
@@ -176,6 +176,14 @@ public:
void setBenchmarkFrames(int n);
QString cameraString() const;
// Move camera_target_ to the selected object's world-AABB centroid and
// dolly camera_distance_ so the object's bounding sphere fits the
// current viewport. Yaw/pitch are preserved. No-op if no object is
// selected or its AABB is unknown.
void focusOnSelectedObject();
// Frame the union of all finalized models. No-op if the scene is empty.
void viewAll();
struct CameraState {
QVector3D target;
float distance;
@@ -237,6 +245,17 @@ private:
void renderAxisGizmo();
void renderPivotIndicator();
void updateCamera();
// Geometry queries used by focusOnSelectedObject() / viewAll(). Both
// return false when nothing matched (caller should leave the camera
// alone). Bounds are world-space AABBs.
bool computeObjectAabb(uint32_t object_id, QVector3D& mn, QVector3D& mx) const;
bool computeSceneAabb(QVector3D& mn, QVector3D& mx) const;
// Re-aim the orbit camera so the bounding sphere of [mn, mx] just fits
// vertically and horizontally within the current FOV, with `padding`
// headroom (1.0 = tight). Yaw/pitch are preserved; only target and
// distance change.
void frameAabb(const QVector3D& mn, const QVector3D& mx, float padding);
void buildShaders();
void buildAxisGizmo();
void buildPivotIndicator();