SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Viewport: show reference geometry through bodies (Preferences, off by default) (#2697)
Frankb79c03d2279f
diff --git a/assets/locales/de.json b/assets/locales/de.jsonindex 8ab6ba1def..31d8bec689 100644--- a/assets/locales/de.json+++ b/assets/locales/de.json@@ -1187,6 +1187,8 @@"settings.msaa_applies_on_restart": "Die Kantenglättung wird beim nächsten Start von SolidCraft übernommen","settings.msaa_reset": "{setting}: {requested}× wird von diesem Grafikgerät nicht unterstützt; jetzt {reset}× (unterstützt: {supported}).","settings.msaa_unsupported": "Von diesem Grafikgerät nicht unterstützt",+ "settings.reference_geometry_through_bodies": "Referenzgeometrie durch Körper hindurch anzeigen",+ "settings.reference_geometry_through_bodies_help": "Konturen inaktiver Skizzen und Bezugsebenen über schattierten Körpern zeichnen","settings.reset_intro": "Diese Einstellungen funktionieren auf diesem Computer nicht und würden den Start von SolidCraft verhindern. Sie wurden daher geändert:","settings.reset_title": "Einstellungen wurden geändert","settings.supersampling_note": "Zeichnet die Ansicht in höherer Auflösung und rechnet sie herunter: glattere Kanten, Linien und Raster auf Bildschirmen unter 4K. Kostet GPU-Zeit: etwa 2,25-mal so viele Pixel bei 1,5× und 4-mal bei 2×.",diff --git a/assets/locales/en.json b/assets/locales/en.jsonindex 4d47a2a057..e1eb0b75cb 100644--- a/assets/locales/en.json+++ b/assets/locales/en.json@@ -1364,6 +1364,8 @@"settings.msaa_applies_on_restart": "Anti-aliasing applies the next time SolidCraft starts","settings.msaa_reset": "{setting}: {requested}× isn't supported by this graphics device; it is now {reset}× (supported: {supported}).","settings.msaa_unsupported": "Not supported by this graphics device",+ "settings.reference_geometry_through_bodies": "Show reference geometry through bodies",+ "settings.reference_geometry_through_bodies_help": "Draw inactive sketch contours and datum planes over shaded bodies","settings.reset_intro": "These settings don't work on this computer and would keep SolidCraft from starting, so they were changed:","settings.reset_title": "Settings were changed","settings.supersampling_note": "Draws the view at a higher resolution and filters it down: smoother edges, lines and grid on screens below 4K. It costs GPU time: about 2.25× the pixels at 1.5× and 4× at 2×.",diff --git a/assets/locales/es.json b/assets/locales/es.jsonindex 5efd56a26d..f1d4f1e9c2 100644--- a/assets/locales/es.json+++ b/assets/locales/es.json@@ -1066,6 +1066,8 @@"settings.msaa_applies_on_restart": "El suavizado de bordes se aplicará la próxima vez que se inicie SolidCraft","settings.msaa_reset": "{setting}: este dispositivo gráfico no admite {requested}×; se ha establecido {reset}× (admitidos: {supported}).","settings.msaa_unsupported": "No compatible con este dispositivo gráfico",+ "settings.reference_geometry_through_bodies": "Mostrar geometría de referencia a través de los cuerpos",+ "settings.reference_geometry_through_bodies_help": "Dibujar los contornos de bocetos inactivos y los planos de referencia sobre los cuerpos sombreados","settings.reset_intro": "Estos ajustes no funcionan en este ordenador e impedirían iniciar SolidCraft, por lo que se han cambiado:","settings.reset_title": "Se han cambiado los ajustes","settings.supersampling_note": "Dibuja la vista a mayor resolución y después la reduce: bordes, líneas y cuadrícula más suaves en pantallas inferiores a 4K. Consume recursos de GPU: unos 2,25× píxeles a 1,5× y 4× a 2×.",diff --git a/assets/locales/fr.json b/assets/locales/fr.jsonindex adb61a4f63..770b33e853 100644--- a/assets/locales/fr.json+++ b/assets/locales/fr.json@@ -1072,6 +1072,8 @@"settings.msaa_applies_on_restart": "L'anticrénelage s'appliquera au prochain démarrage de SolidCraft","settings.msaa_reset": "{setting} : {requested}× n'est pas pris en charge par ce périphérique graphique ; la valeur est désormais {reset}× (pris en charge : {supported}).","settings.msaa_unsupported": "Non pris en charge par ce périphérique graphique",+ "settings.reference_geometry_through_bodies": "Afficher la géométrie de référence à travers les corps",+ "settings.reference_geometry_through_bodies_help": "Afficher les contours des esquisses inactives et les plans de référence par-dessus les corps ombrés","settings.reset_intro": "Ces réglages ne fonctionnent pas sur cet ordinateur et empêcheraient SolidCraft de démarrer ; ils ont donc été modifiés :","settings.reset_title": "Des réglages ont été modifiés","settings.supersampling_note": "Dessine la vue à une résolution plus élevée puis la réduit : arêtes, lignes et grille plus lisses sur les écrans de définition inférieure à la 4K. Cela coûte du temps GPU : environ 2,25× plus de pixels à 1,5× et 4× plus à 2×.",diff --git a/assets/locales/ja.json b/assets/locales/ja.jsonindex 2e390d2cfb..5784877ef3 100644--- a/assets/locales/ja.json+++ b/assets/locales/ja.json@@ -1364,6 +1364,8 @@"settings.msaa_applies_on_restart": "アンチエイリアスは次回 SolidCraft を起動したときに適用されます","settings.msaa_reset": "{setting}: {requested}× はこのグラフィックスデバイスではサポートされていないため、{reset}× に変更しました(サポート: {supported})。","settings.msaa_unsupported": "このグラフィックスデバイスではサポートされていません",+ "settings.reference_geometry_through_bodies": "ボディ越しに参照ジオメトリを表示",+ "settings.reference_geometry_through_bodies_help": "非アクティブなスケッチ輪郭と基準平面をシェーディングされたボディの上に描画します","settings.reset_intro": "次の設定はこのコンピューターでは使用できず、SolidCraft が起動できなくなるため変更されました:","settings.reset_title": "設定が変更されました","settings.supersampling_note": "ビューを高い解像度で描画してから縮小します。4K 未満の画面でエッジ、線、グリッドが滑らかになります。GPU の負荷が増えます(1.5× で約 2.25 倍、2× で 4 倍のピクセル)。",diff --git a/assets/locales/ko.json b/assets/locales/ko.jsonindex 828a598f10..659de66dfe 100644--- a/assets/locales/ko.json+++ b/assets/locales/ko.json@@ -1070,6 +1070,8 @@"settings.msaa_applies_on_restart": "안티앨리어싱은 다음에 SolidCraft를 시작할 때 적용됩니다","settings.msaa_reset": "{setting}: {requested}×는 이 그래픽 장치에서 지원되지 않아 {reset}×로 변경했습니다(지원: {supported}).","settings.msaa_unsupported": "이 그래픽 장치에서 지원되지 않음",+ "settings.reference_geometry_through_bodies": "바디를 통해 참조 형상 표시",+ "settings.reference_geometry_through_bodies_help": "비활성 스케치 윤곽과 기준 평면을 음영 처리된 바디 위에 그립니다","settings.reset_intro": "다음 설정은 이 컴퓨터에서 작동하지 않아 SolidCraft를 시작할 수 없게 하므로 변경되었습니다:","settings.reset_title": "설정이 변경되었습니다","settings.supersampling_note": "뷰를 더 높은 해상도로 그린 뒤 축소합니다. 4K 미만 화면에서 모서리, 선, 그리드가 더 매끄러워집니다. GPU 시간이 듭니다: 1.5×에서 약 2.25배, 2×에서 4배의 픽셀.",diff --git a/assets/locales/pl.json b/assets/locales/pl.jsonindex 1ef280a400..90a93d4f36 100644--- a/assets/locales/pl.json+++ b/assets/locales/pl.json@@ -1245,6 +1245,8 @@"settings.msaa_applies_on_restart": "Wygładzanie krawędzi zadziała po ponownym uruchomieniu SolidCraft","settings.msaa_reset": "{setting}: {requested}× nie jest obsługiwane przez to urządzenie graficzne; ustawiono {reset}× (obsługiwane: {supported}).","settings.msaa_unsupported": "Nieobsługiwane przez to urządzenie graficzne",+ "settings.reference_geometry_through_bodies": "Pokaż geometrię odniesienia przez bryły",+ "settings.reference_geometry_through_bodies_help": "Rysuj kontury nieaktywnych szkiców i płaszczyzny odniesienia na cieniowanych bryłach","settings.reset_intro": "Te ustawienia nie działają na tym komputerze i uniemożliwiłyby uruchomienie SolidCraft, więc zostały zmienione:","settings.reset_title": "Zmieniono ustawienia","settings.supersampling_note": "Rysuje widok w wyższej rozdzielczości i go zmniejsza: gładsze krawędzie, linie i siatka na ekranach poniżej 4K. Kosztuje czas GPU: ok. 2,25× więcej pikseli przy 1,5× i 4× przy 2×.",diff --git a/assets/locales/zh.json b/assets/locales/zh.jsonindex 6717402b3d..6041fe9f79 100644--- a/assets/locales/zh.json+++ b/assets/locales/zh.json@@ -1364,6 +1364,8 @@"settings.msaa_applies_on_restart": "抗锯齿将在下次启动 SolidCraft 时生效","settings.msaa_reset": "{setting}: {requested}× 不受此图形设备支持;已重置为 {reset}× (支持: {supported})。","settings.msaa_unsupported": "此图形设备不支持",+ "settings.reference_geometry_through_bodies": "在实体后方显示参考几何体",+ "settings.reference_geometry_through_bodies_help": "将非活动草图轮廓和基准平面绘制在着色实体上方","settings.reset_intro": "这些设置在此计算机上无法正常工作,会导致 SolidCraft 无法启动,因此已更改:","settings.reset_title": "设置已更改","settings.supersampling_note": "以更高分辨率绘制视图再缩小:在低于 4K 的屏幕上边、线和网格更平滑。会消耗 GPU 时间:1.5× 时约 2.25 倍像素,2× 时 4 倍。",diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rsindex 7fdcd39f21..b851713669 100644--- a/crates/ui-egui/src/prefs.rs+++ b/crates/ui-egui/src/prefs.rs@@ -469,6 +469,9 @@ preference_settings! {/// The grid turns to the upright origin plane facing a side view (#1470). Off by default: the/// grid stays on the ground plane (XY) whatever the view.grid_follows_view: bool = false => check("Grid follows the view", "Side views show the grid on the upright plane facing them instead of the ground");+ /// Draw reference geometry such as inactive sketches and datum planes through shaded bodies.+ /// Off by default to preserve the depth-tested viewport behaviour.+ reference_geometry_through_bodies: bool = false, PAGE_GRAPHICS => check_id("settings.reference_geometry_through_bodies");/// How finely the viewport tessellates curved faces and edges: `coarse`, `normal`, `fine` or/// `ultra` (#1287). Only the display plan the viewport draws; never the design or exports.display_quality: String = "normal".into(), PAGE_GRAPHICS;diff --git a/crates/ui-egui/src/prefs/graphics.rs b/crates/ui-egui/src/prefs/graphics.rsindex 606b42754c..1ab40ec263 100644--- a/crates/ui-egui/src/prefs/graphics.rs+++ b/crates/ui-egui/src/prefs/graphics.rs@@ -123,6 +123,7 @@ pub(super) fn show(app: &mut SolveApp, ui: &mut egui::Ui) {ui_kit::checkbox(left, crate::i18n::tr_label("Grid"), &mut app.ui.show_grid);ui_kit::checkbox(left, crate::i18n::tr_label("Perspective view"), &mut app.ui.perspective);setting::show_frame_rate(app, left).on_hover_text(app.tr("settings.frame_rate_note"));+ setting::reference_geometry_through_bodies(app, left).on_hover_text(app.tr("settings.reference_geometry_through_bodies_help"));}if let Some(right) = columns.get_mut(1) {ui_kit::checkbox(right, crate::i18n::tr_label("Ground shadow"), &mut app.ui.ground_shadow);diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rsindex 1868470f97..c7341bd2f2 100644--- a/crates/ui-egui/src/viewport.rs+++ b/crates/ui-egui/src/viewport.rs@@ -353,6 +353,8 @@ fn sketch_scene_key(app: &SolveApp, proj: &Proj) -> u64 {// The grid this scene draws follows the view when the preference says so (#1470): turning it// on or off redraws even while the camera holds still.app.preferences.grid_follows_view.hash(&mut h);+ // Finished sketches are drawn over the bodies when the preference says so.+ app.preferences.reference_geometry_through_bodies.hash(&mut h);(std::sync::Arc::as_ptr(&crate::open_meshing::shown_world(app)) as usize).hash(&mut h);crate::sketch_display::projection_key(proj, app.viewport.pixels_per_point()).hash(&mut h);h.finish()@@ -1055,7 +1057,10 @@ fn build_sketch_scene(app: &SolveApp, proj: &Proj) -> GpuScene {unit,);for (a, b) in segs {- sc.line(a.to_f32(), b.to_f32(), sketch_color(&tk, col), if cons { 1.2 } else { 2.0 }, active);+ // Active sketches retain their existing through-body display. Inactive sketches+ // can opt into the same behaviour in Preferences.+ let through = active || app.preferences.reference_geometry_through_bodies;+ sc.line(a.to_f32(), b.to_f32(), sketch_color(&tk, col), if cons { 1.2 } else { 2.0 }, through);}}}@@ -2139,7 +2144,8 @@ pub(crate) fn profile_fill(sc: &mut GpuScene, app: &SolveApp, sketch: u64, index/// An origin or construction plane: reference geometry, which a section does not cut (#1229)./// A reference plane's square. `through` draws it over the model (Create Sketch: a plane inside-/// a body stays visible and pickable), else it is depth-tested like the rest of the scene.+/// a body stays visible and pickable; or the Preferences setting to show reference geometry+/// through bodies), else it is depth-tested like the rest of the scene.fn quad(sc: &mut GpuScene, q: &[Vec3; 4], fill: Color32, edge: Color32, through: bool) {let col = c4(fill);for i in [0, 1, 2, 0, 2, 3] {@@ -2153,11 +2159,17 @@ fn quad(sc: &mut GpuScene, q: &[Vec3; 4], fill: Color32, edge: Color32, through:}for i in 0..4 {let (a, b) = (q[i].to_f32(), q[(i + 1) % 4].to_f32());- if through {- sc.line(a, b, c4(edge), 1.2, true);- } else {- sc.guide_line(a, b, c4(edge), 1.2);- }+ reference_line(sc, a, b, c4(edge), 1.2, through);+ }+}++/// A reference line (plane edge, axis): over the model when `through` (as [`quad`]), else depth-tested and+/// left whole by a section.+fn reference_line(sc: &mut GpuScene, a: [f32; 3], b: [f32; 3], col: [u8; 4], width: f32, through: bool) {+ if through {+ sc.line(a, b, col, width, true);+ } else {+ sc.guide_line(a, b, col, width);}}@@ -2202,6 +2214,7 @@ fn highlight_geometry_key(app: &SolveApp) -> u64 {app.preview.rolled_back.hash(&mut h);app.origin_visible().hash(&mut h);app.picking_plane().hash(&mut h);+ app.preferences.reference_geometry_through_bodies.hash(&mut h);app.session.visibility.hidden_origin.hash(&mut h);app.session.visibility.hidden_bodies.hash(&mut h);app.session.visibility.hidden_occurrences.hash(&mut h);@@ -2368,7 +2381,7 @@ pub(crate) fn build_highlight(app: &SolveApp) -> GpuScene {};let mut planes: Vec<(String, [Vec3; 4], Color32)> = origin_planes(app).into_iter().map(|(n, _, q)| (n.to_string(), q, t.origin_plane)).collect();planes.extend(construction_quads(app).into_iter().map(|(n, _, q)| (n, q, t.construction_plane)));- let through = app.picking_plane();+ let through = app.picking_plane() || app.preferences.reference_geometry_through_bodies;for (name, q, base) in &planes {let (selected, hovered) = plane_state(name);let fill = if hovered {@@ -2389,11 +2402,11 @@ pub(crate) fn build_highlight(app: &SolveApp) -> GpuScene {};let on = sel.iter().any(|x| matches!(x, Sel::Axis { name: n } if n == name)) || matches!(hover, Some(Hit::Axis { name: n }) if n == name);let w = if on { 4.0 } else { 2.0 };- sc.guide_line([0.0; 3], (dir * size).to_f32(), c4(col), w);+ reference_line(&mut sc, [0.0; 3], (dir * size).to_f32(), c4(col), w, through);let dash = size * 0.08;let mut a = size + dash;while a < size * AXIS_LEN {- sc.guide_line((dir * a).to_f32(), (dir * (a + dash)).to_f32(), c4(col), w * 0.75);+ reference_line(&mut sc, (dir * a).to_f32(), (dir * (a + dash)).to_f32(), c4(col), w * 0.75, through);a += dash * 2.0;}}@@ -2408,7 +2421,7 @@ pub(crate) fn build_highlight(app: &SolveApp) -> GpuScene {let mut s = 0.0;while s < len {let e = (s + dash).min(len);- sc.guide_line(a.lerp(b, s / len).to_f32(), a.lerp(b, e / len).to_f32(), col, w);+ reference_line(&mut sc, a.lerp(b, s / len).to_f32(), a.lerp(b, e / len).to_f32(), col, w, through);s += dash * 1.6;}}@@ -6736,6 +6749,13 @@ mod tests {assert!(sc.trans.is_empty(), "no origin plane is drawn where the section clips");// Each origin axis: a solid part and dashes beyond, plus each plane's four edges.assert!(sc.guide_lines.len() >= (planes * 4 + 3) * crate::gpu::LINE_SIZE);+ assert!(sc.xray.is_empty(), "depth-tested unless the preference is on");+ // Shown through bodies (Preferences), they are drawn over everything, also unclipped.+ h.app.preferences.reference_geometry_through_bodies = true;+ let sc = build_highlight(&h.app).merged();+ assert_eq!(sc.xray.len(), planes * 6 * crate::gpu::TRI_SIZE);+ assert!(sc.trans.is_empty() && sc.guide_trans.is_empty() && sc.guide_lines.is_empty());+ assert!(sc.overlay.len() >= (planes * 4 + 3) * crate::gpu::LINE_SIZE);}#[test]@@ -7984,9 +8004,8 @@ mod grid_plane_tests {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.+ /// Create Sketch shows the Origin through bodies; the preference opts into that outside the+ /// tool while remaining off by default.#[test]fn create_sketch_shows_the_origin_planes_through_the_model() {let mut app = SolveApp::new(solidcraft_engine::Session::default(), crate::Services::default());@@ -8004,7 +8023,31 @@ mod grid_plane_tests {assert!(origin_planes(&app).is_empty());app.ui.show_origin = true;let sc = build_highlight(&app);- assert!(sc.xray.is_empty() && !sc.guide_trans.is_empty(), "outside Create Sketch the planes are depth-tested");+ assert!(sc.xray.is_empty(), "through-body reference geometry is off by default");+ assert_eq!(sc.guide_trans.len(), 3 * 6 * crate::gpu::TRI_SIZE, "planes use the ordinary depth-tested path by default");+ app.preferences.reference_geometry_through_bodies = true;+ let sc = build_highlight(&app);+ assert_eq!(sc.xray.len(), 3 * 6 * crate::gpu::TRI_SIZE, "the preference draws reference planes through bodies");+ assert!(sc.guide_trans.is_empty());+ }++ /// A finished sketch is depth-tested unless the preference draws reference geometry through+ /// bodies; switching it redraws the sketch scene while nothing else changes.+ #[test]+ fn the_preference_draws_finished_sketches_through_bodies() {+ 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.run("sketch.create", json!({"plane": "XY"})).unwrap();+ app.run("sketch.rectangle.two_point", json!({"p0": [-10, -10], "p1": [10, 10]})).unwrap();+ app.run("sketch.finish", json!({})).unwrap();+ let proj = projection(&app, rect);+ let off = build_sketch_scene(&app, &proj);+ assert!(!off.lines.is_empty() && off.overlay.is_empty(), "off by default: the sketch is depth-tested");+ let key = sketch_scene_key(&app, &proj);+ app.preferences.reference_geometry_through_bodies = true;+ assert_ne!(sketch_scene_key(&app, &proj), key, "the cached sketch scene is rebuilt");+ let on = build_sketch_scene(&app, &proj);+ assert!(on.lines.is_empty() && on.overlay.len() == off.lines.len(), "the sketch is drawn over the bodies");}/// #2581: a dialog waiting for a plane (here Mirror's plane) shows the origin planes in the