fix(view): preserve projection framing

Use full 3D bounds to derive a safe perspective eye distance without changing the camera target, orientation, or field of view.

Refs #502
This commit is contained in:
Hakan Seven committed 2026-08-05 12:47:46 +03:00
1 parent 5a0c286a10
commit e07f4f959b
5 files changed
+219 -19

No files matched your search

+13 -5
View File
@@ -1575,6 +1575,10 @@ pub struct Scene {
/// preview wires, layer visibility, layout). The GPU pipeline uses this to
/// skip re-uploading unchanged geometry buffers every frame.
pub geometry_epoch: u64,
/// Geometry epoch represented by the model bounds cached on the live
/// camera. Projection switches refresh those bounds through the same
/// filtered fit path when this falls behind `geometry_epoch`.
projection_bounds_epoch: std::cell::Cell<u64>,
/// Separate epoch for the (expensive) block-definition tessellation cache.
/// Bumped together with `geometry_epoch` by `bump_geometry`, but NOT by
/// `bump_geometry_no_blocks` — so edits that provably can't change any
@@ -1953,6 +1957,7 @@ impl Scene {
interim_wire: None,
camera_generation: 0,
geometry_epoch: GEOMETRY_EPOCH.fetch_add(1, Ordering::Relaxed),
projection_bounds_epoch: std::cell::Cell::new(0),
block_epoch: GEOMETRY_EPOCH.fetch_add(1, Ordering::Relaxed),
selection_generation: 0,
wire_cache: RefCell::new(None),
@@ -9189,7 +9194,8 @@ impl Scene {
}
}
// 3D solids render as meshes, not wires, so fold their
// XY AABBs in too — otherwise ZOOM EXTENTS ignores them.
// complete 3D boxes in too — otherwise view fitting loses
// both solid-only drawings and their depth.
for (&handle, set) in &self.meshes {
if !self.mesh_entity_visible(handle)
|| !self.document.get_entity(handle).is_some_and(|entity| {
@@ -9203,8 +9209,9 @@ impl Scene {
continue;
}
let [ax, ay, bx, by] = set.world_aabb;
let lo = glam::Vec3::new(ax, ay, 0.0);
let hi = glam::Vec3::new(bx, by, 0.0);
let [az, bz] = set.z_aabb;
let lo = glam::Vec3::new(ax, ay, az);
let hi = glam::Vec3::new(bx, by, bz);
if lo.is_finite() && hi.is_finite() {
min = min.min(lo);
max = max.max(hi);
@@ -9261,8 +9268,9 @@ impl Scene {
continue;
}
let [ax, ay, bx, by] = set.world_aabb;
let lo = glam::Vec3::new(ax, ay, 0.0);
let hi = glam::Vec3::new(bx, by, 0.0);
let [az, bz] = set.z_aabb;
let lo = glam::Vec3::new(ax, ay, az);
let hi = glam::Vec3::new(bx, by, bz);
if lo.is_finite() && hi.is_finite() {
min = min.min(lo);
max = max.max(hi);