Draw the view orthographic while a sketch is open (#1758)

Thanks @pablopeza.
This commit is contained in:
Pablo López authored and GitHub committed 2026-10-17 06:48:42 -04:00
1 parent e052d19879
commit 40bdc1132e
2 files changed
+25 -3

No files matched your search

+7 -1
View File
@@ -976,6 +976,12 @@ impl SolveApp {
self.dialog.as_ref().is_some_and(|d| matches!(d.kind, dialogs::Kind::Sketch))
}
/// Is the view drawn in perspective? The perspective preference, except while a sketch is
/// open: a sketch is drawn and measured on its plane, so the view is parallel (no foreshortening).
pub fn perspective_view(&self) -> bool {
self.ui.perspective && self.session.active_sketch.is_none()
}
pub fn set_status(&mut self, s: impl Into<String>, error: bool) {
self.status = Some((s.into(), now_ms(), error));
}
@@ -1077,7 +1083,7 @@ impl SolveApp {
fn fitted_bounds(&self, mut cam: Camera, bounds: &solidcraft_engine::geom::Aabb3) -> Camera {
if let Some(layout) = &self.viewport.layout {
return viewport_layout::fit_bounds(cam, bounds, layout, self.ui.perspective).unwrap_or(cam);
return viewport_layout::fit_bounds(cam, bounds, layout, self.perspective_view()).unwrap_or(cam);
}
let previous = cam;
cam.fit(bounds);
+18 -2
View File
@@ -267,7 +267,7 @@ pub fn scene_radius(app: &SolveApp) -> f64 {
pub fn projection(app: &SolveApp, rect: Rect) -> Proj {
let mut cam = app.cam;
cam.fov = if app.ui.perspective { 0.6 } else { 0.0 };
cam.fov = if app.perspective_view() { 0.6 } else { 0.0 };
let aspect = rect.width() as f64 / rect.height().max(1.0) as f64;
Proj { cam, vp: cam.view_proj(aspect, scene_radius(app)), rect }
}
@@ -1102,7 +1102,7 @@ pub(crate) fn pick_cached(app: &mut SolveApp, proj: &Proj, pos: Pos2) -> Vec<Hit
app.dialog.as_ref().and_then(|d| d.active_input()).map(|i| i.accept).hash(&mut h);
app.session.visibility.hidden_bodies.hash(&mut h);
app.session.visibility.hidden_occurrences.hash(&mut h);
app.ui.perspective.hash(&mut h);
app.perspective_view().hash(&mut h);
(proj.rect.width().to_bits(), proj.rect.height().to_bits()).hash(&mut h);
crate::sketch_display::projection_key(proj, app.viewport.pixels_per_point()).hash(&mut h);
let key = h.finish();
@@ -5950,6 +5950,22 @@ mod grid_plane_tests {
}
}
/// A sketch is drawn in a parallel view even when the preference asks for perspective; the
/// preference comes back when the sketch is finished.
#[test]
fn an_open_sketch_is_drawn_orthographic() {
let rect = Rect::from_min_size(Pos2::ZERO, egui::vec2(800.0, 600.0));
let mut app = SolveApp::new(solidcraft_engine::Session::default(), crate::Services::default());
app.ui.perspective = true;
assert!(projection(&app, rect).cam.fov > 0.0);
app.run("sketch.create", json!({"plane": "XZ"})).unwrap();
assert!(!app.perspective_view());
assert_eq!(projection(&app, rect).cam.fov, 0.0);
app.finish_sketch();
assert!(app.ui.perspective, "the preference is left alone");
assert!(projection(&app, rect).cam.fov > 0.0);
}
/// Create Sketch shows the Origin even when the browser hides it, and draws its planes
/// through the model so a plane inside a body can be seen and picked; closing it restores
/// the hidden, depth-tested Origin.