Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Section Analysis: a Hatch option (#4563) (#4565)

SS-EN769dfff1a5c5
diff --git a/assets/locales/cs.json b/assets/locales/cs.json
index 5073d3d268..e77abd223c 100644
--- a/assets/locales/cs.json
+++ b/assets/locales/cs.json
@@ -1503,6 +1503,7 @@
"ui.grid_follows_view_hint": "Boční pohledy zobrazí mřížku na svislé rovině, která je k nim přivrácená, místo na zemi",
"ui.ground_shadow": "Stín na podložce",
"ui.groupSelected": "Seskupit vybrané",
+ "ui.hatch": "Šrafování",
"ui.heading_add_ins": "DOPLŇKY",
"ui.heading_assemble": "SESTAVA",
"ui.heading_box": "KVÁDR",
diff --git a/assets/locales/da.json b/assets/locales/da.json
index f26f270754..eb3fd8e10c 100644
--- a/assets/locales/da.json
+++ b/assets/locales/da.json
@@ -1503,6 +1503,7 @@
"ui.grid_follows_view_hint": "Sidevisninger viser gitteret på det lodrette plan, der vender mod dem, i stedet for grundplanet",
"ui.ground_shadow": "Skygge på grundplan",
"ui.groupSelected": "Gruppér valgte",
+ "ui.hatch": "Skravering",
"ui.heading_add_ins": "ADD-INS",
"ui.heading_assemble": "SAMLING",
"ui.heading_box": "BOKS",
diff --git a/assets/locales/de.json b/assets/locales/de.json
index c6a0e90448..8ab6ba1def 100644
--- a/assets/locales/de.json
+++ b/assets/locales/de.json
@@ -1627,6 +1627,7 @@
"ui.grid_follows_view_hint": "Seitenansichten zeigen das Raster auf der aufrechten Ebene, die ihnen zugewandt ist, statt auf dem Boden",
"ui.ground_shadow": "Bodenschatten",
"ui.groupSelected": "Auswahl gruppieren",
+ "ui.hatch": "Schraffur",
"ui.heading_add_ins": "ADD-INS",
"ui.heading_assemble": "ZUSAMMENBAU",
"ui.heading_box": "BLOCK",
diff --git a/assets/locales/en.json b/assets/locales/en.json
index 7cc72175af..49037d934b 100644
--- a/assets/locales/en.json
+++ b/assets/locales/en.json
@@ -1815,6 +1815,7 @@
"ui.grid_follows_view_hint": "Side views show the grid on the upright plane facing them instead of the ground",
"ui.ground_shadow": "Ground shadow",
"ui.groupSelected": "Group Selected",
+ "ui.hatch": "Hatch",
"ui.heading_add_ins": "ADD-INS",
"ui.heading_assemble": "ASSEMBLE",
"ui.heading_box": "BOX",
diff --git a/assets/locales/es.json b/assets/locales/es.json
index a09457309e..5efd56a26d 100644
--- a/assets/locales/es.json
+++ b/assets/locales/es.json
@@ -1503,6 +1503,7 @@
"ui.grid_follows_view_hint": "Las vistas laterales muestran la cuadrícula en el plano vertical que tienen enfrente, en lugar del suelo",
"ui.ground_shadow": "Sombra en el suelo",
"ui.groupSelected": "Agrupar selección",
+ "ui.hatch": "Rayado",
"ui.heading_add_ins": "COMPLEMENTOS",
"ui.heading_assemble": "ENSAMBLAR",
"ui.heading_box": "CAJA",
diff --git a/assets/locales/fr.json b/assets/locales/fr.json
index b7ff8f6b53..adb61a4f63 100644
--- a/assets/locales/fr.json
+++ b/assets/locales/fr.json
@@ -1509,6 +1509,7 @@
"ui.grid_follows_view_hint": "Dans les vues de côté, la grille s'affiche sur le plan vertical qui leur fait face plutôt que sur le sol",
"ui.ground_shadow": "Ombre au sol",
"ui.groupSelected": "Grouper la sélection",
+ "ui.hatch": "Hachures",
"ui.heading_add_ins": "COMPLÉMENTS",
"ui.heading_assemble": "ASSEMBLER",
"ui.heading_box": "BOÎTE",
diff --git a/assets/locales/gl.json b/assets/locales/gl.json
index 63984ade89..f4eeceb1df 100644
--- a/assets/locales/gl.json
+++ b/assets/locales/gl.json
@@ -1503,6 +1503,7 @@
"ui.grid_follows_view_hint": "As vistas laterais mostran a grella no plano vertical que ten diante en vez do chan",
"ui.ground_shadow": "Sombra no chan",
"ui.groupSelected": "Agrupar a selección",
+ "ui.hatch": "Raiado",
"ui.heading_add_ins": "COMPLEMENTOS",
"ui.heading_assemble": "ENSAMBLAR",
"ui.heading_box": "CAIXA",
diff --git a/assets/locales/hu.json b/assets/locales/hu.json
index 9951a111f0..c89d9d0bb8 100644
--- a/assets/locales/hu.json
+++ b/assets/locales/hu.json
@@ -1502,6 +1502,7 @@
"ui.grid_follows_view_hint": "Az oldalnézetek a talaj helyett a feléjük néző függőleges síkon mutatják a rácsot",
"ui.ground_shadow": "Talajárnyék",
"ui.groupSelected": "Kijelöltek csoportosítása",
+ "ui.hatch": "Sraffozás",
"ui.heading_add_ins": "BŐVÍTMÉNYEK",
"ui.heading_assemble": "ÖSSZESZERELÉS",
"ui.heading_box": "DOBOZ",
diff --git a/assets/locales/id.json b/assets/locales/id.json
index cb6b37dc58..0773a42a70 100644
--- a/assets/locales/id.json
+++ b/assets/locales/id.json
@@ -1502,6 +1502,7 @@
"ui.grid_follows_view_hint": "Tampilan samping menampilkan grid pada bidang tegak yang menghadapnya, bukan pada dasar",
"ui.ground_shadow": "Bayangan dasar",
"ui.groupSelected": "Kelompokkan yang Dipilih",
+ "ui.hatch": "Arsir",
"ui.heading_add_ins": "ADD-IN",
"ui.heading_assemble": "RAKIT",
"ui.heading_box": "KOTAK",
diff --git a/assets/locales/it.json b/assets/locales/it.json
index 540bd066ef..92bca1f1f2 100644
--- a/assets/locales/it.json
+++ b/assets/locales/it.json
@@ -1506,6 +1506,7 @@
"ui.grid_follows_view_hint": "Le viste laterali mostrano la griglia sul piano verticale rivolto verso di esse anziché sul piano di appoggio",
"ui.ground_shadow": "Ombra sul piano di appoggio",
"ui.groupSelected": "Raggruppa selezionati",
+ "ui.hatch": "Tratteggio",
"ui.heading_add_ins": "COMPONENTI AGGIUNTIVI",
"ui.heading_assemble": "ASSEMBLA",
"ui.heading_box": "PARALLELEPIPEDO",
diff --git a/assets/locales/ja.json b/assets/locales/ja.json
index 51cb6e5d0c..773d5427c9 100644
--- a/assets/locales/ja.json
+++ b/assets/locales/ja.json
@@ -1815,6 +1815,7 @@
"ui.grid_follows_view_hint": "側面ビューでは、グリッドを地面ではなく、そのビューに向いた垂直平面に表示します",
"ui.ground_shadow": "地面の影",
"ui.groupSelected": "選択をグループ化",
+ "ui.hatch": "ハッチング",
"ui.heading_add_ins": "アドイン",
"ui.heading_assemble": "アセンブリ",
"ui.heading_box": "直方体",
diff --git a/assets/locales/ko.json b/assets/locales/ko.json
index f496d32400..828a598f10 100644
--- a/assets/locales/ko.json
+++ b/assets/locales/ko.json
@@ -1507,6 +1507,7 @@
"ui.grid_follows_view_hint": "측면 뷰에서는 지면 대신 마주 보는 수직 평면에 격자를 표시합니다",
"ui.ground_shadow": "바닥 그림자",
"ui.groupSelected": "선택 항목 그룹화",
+ "ui.hatch": "해칭",
"ui.heading_add_ins": "애드인",
"ui.heading_assemble": "조립",
"ui.heading_box": "박스",
diff --git a/assets/locales/ms.json b/assets/locales/ms.json
index 3b17efc58c..5a13055b11 100644
--- a/assets/locales/ms.json
+++ b/assets/locales/ms.json
@@ -1503,6 +1503,7 @@
"ui.grid_follows_view_hint": "Pandangan sisi guna grid satah tegak yang menghadapnya, bukan satah tanah",
"ui.ground_shadow": "Bayang tanah",
"ui.groupSelected": "Kumpulkan Pilihan",
+ "ui.hatch": "Lorek",
"ui.heading_add_ins": "TAMBAHAN",
"ui.heading_assemble": "PASANG",
"ui.heading_box": "KOTAK",
diff --git a/assets/locales/nl.json b/assets/locales/nl.json
index b85477f28e..32b410e597 100644
--- a/assets/locales/nl.json
+++ b/assets/locales/nl.json
@@ -1502,6 +1502,7 @@
"ui.grid_follows_view_hint": "Zijaanzichten tonen het raster op het rechtopstaande vlak dat naar hen toe gericht is in plaats van op de grond",
"ui.ground_shadow": "Grondschaduw",
"ui.groupSelected": "Selectie groeperen",
+ "ui.hatch": "Arcering",
"ui.heading_add_ins": "INVOEGMODULES",
"ui.heading_assemble": "SAMENSTELLEN",
"ui.heading_box": "KUB",
diff --git a/assets/locales/pl.json b/assets/locales/pl.json
index 430a22933a..1ef280a400 100644
--- a/assets/locales/pl.json
+++ b/assets/locales/pl.json
@@ -1687,6 +1687,7 @@
"ui.grid_follows_view_hint": "Widoki boczne pokazują siatkę na pionowej płaszczyźnie zwróconej do nich zamiast na podłożu",
"ui.ground_shadow": "Cień na podłożu",
"ui.groupSelected": "Grupuj zaznaczone",
+ "ui.hatch": "Kreskowanie",
"ui.heading_add_ins": "DODATKI",
"ui.heading_assemble": "ZŁOŻENIE",
"ui.heading_box": "PROSTOPADŁOŚCIAN",
diff --git a/assets/locales/pt-BR.json b/assets/locales/pt-BR.json
index 6590da7385..092683499b 100644
--- a/assets/locales/pt-BR.json
+++ b/assets/locales/pt-BR.json
@@ -1503,6 +1503,7 @@
"ui.grid_follows_view_hint": "As vistas laterais mostram a grade no plano vertical voltado para elas, em vez do solo",
"ui.ground_shadow": "Sombra no chão",
"ui.groupSelected": "Agrupar seleção",
+ "ui.hatch": "Hachura",
"ui.heading_add_ins": "COMPLEMENTOS",
"ui.heading_assemble": "MONTAR",
"ui.heading_box": "CAIXA",
diff --git a/assets/locales/ro.json b/assets/locales/ro.json
index 6b6b76a35a..2834558456 100644
--- a/assets/locales/ro.json
+++ b/assets/locales/ro.json
@@ -1502,6 +1502,7 @@
"ui.grid_follows_view_hint": "Vederile laterale afișează grila pe planul vertical orientat spre ele, în loc de sol",
"ui.ground_shadow": "Umbra la sol",
"ui.groupSelected": "Grupează selecția",
+ "ui.hatch": "Hașură",
"ui.heading_add_ins": "EXTENSII",
"ui.heading_assemble": "ASAMBLARE",
"ui.heading_box": "CUTIE",
diff --git a/assets/locales/ru.json b/assets/locales/ru.json
index 1eafd7a6a9..c193ff6478 100644
--- a/assets/locales/ru.json
+++ b/assets/locales/ru.json
@@ -1502,6 +1502,7 @@
"ui.grid_follows_view_hint": "На боковых видах сетка показывается на вертикальной плоскости, обращённой к вам, а не на земле",
"ui.ground_shadow": "Тень на земле",
"ui.groupSelected": "Группировать выбранное",
+ "ui.hatch": "Штриховка",
"ui.heading_add_ins": "НАДСТРОЙКИ",
"ui.heading_assemble": "СБОРКА",
"ui.heading_box": "БОКС",
diff --git a/assets/locales/sv.json b/assets/locales/sv.json
index 3d1370a0d7..ca4ae65212 100644
--- a/assets/locales/sv.json
+++ b/assets/locales/sv.json
@@ -1502,6 +1502,7 @@
"ui.grid_follows_view_hint": "Sidovyer visar rutnätet på det upprätta planet som vetter mot dem istället för marken",
"ui.ground_shadow": "Markskugga",
"ui.groupSelected": "Gruppera markerade",
+ "ui.hatch": "Skraffering",
"ui.heading_add_ins": "TILLÄGG",
"ui.heading_assemble": "MONTERA",
"ui.heading_box": "LÅDA",
diff --git a/assets/locales/tr.json b/assets/locales/tr.json
index a98e9b1afe..3667efbbea 100644
--- a/assets/locales/tr.json
+++ b/assets/locales/tr.json
@@ -1502,6 +1502,7 @@
"ui.grid_follows_view_hint": "Yan görünümlerde ızgara, zemin yerine onlara bakan dik düzlemde gösterilir",
"ui.ground_shadow": "Zemin gölgesi",
"ui.groupSelected": "Seçimi grupla",
+ "ui.hatch": "Tarama",
"ui.heading_add_ins": "EKLENTİLER",
"ui.heading_assemble": "MONTAJ",
"ui.heading_box": "KUTU",
diff --git a/assets/locales/uk.json b/assets/locales/uk.json
index d73c8965cb..b42b8ae64f 100644
--- a/assets/locales/uk.json
+++ b/assets/locales/uk.json
@@ -1503,6 +1503,7 @@
"ui.grid_follows_view_hint": "Бічні види показують сітку на вертикальній площині, повернутій до них, а не на землі",
"ui.ground_shadow": "Тінь на землі",
"ui.groupSelected": "Згрупувати виділене",
+ "ui.hatch": "Штрихування",
"ui.heading_add_ins": "НАДБУДОВИ",
"ui.heading_assemble": "СКЛАДАННЯ",
"ui.heading_box": "КУБ",
diff --git a/assets/locales/vi.json b/assets/locales/vi.json
index c40db60844..2b9b225181 100644
--- a/assets/locales/vi.json
+++ b/assets/locales/vi.json
@@ -1503,6 +1503,7 @@
"ui.grid_follows_view_hint": "Các góc nhìn cạnh hiển thị lưới trên mặt phẳng thẳng đứng hướng về phía camera thay vì trên mặt sàn",
"ui.ground_shadow": "Bóng đổ mặt sàn",
"ui.groupSelected": "Gộp nhóm vùng chọn",
+ "ui.hatch": "Gạch mặt cắt",
"ui.heading_add_ins": "TIỆN ÍCH MỞ RỘNG",
"ui.heading_assemble": "LẮP RÁP",
"ui.heading_box": "KHỐI HỘP",
diff --git a/assets/locales/zh-TW.json b/assets/locales/zh-TW.json
index dcfcd5b3f8..abe0c3e19a 100644
--- a/assets/locales/zh-TW.json
+++ b/assets/locales/zh-TW.json
@@ -1502,6 +1502,7 @@
"ui.grid_follows_view_hint": "在側檢視中,將網格顯示在朝向該檢視的豎直平面上,而不是地面上",
"ui.ground_shadow": "地面陰影",
"ui.groupSelected": "群組所選",
+ "ui.hatch": "剖面線",
"ui.heading_add_ins": "增益集",
"ui.heading_assemble": "組裝",
"ui.heading_box": "長方體",
diff --git a/assets/locales/zh.json b/assets/locales/zh.json
index 75ed0d74e6..5f29371b69 100644
--- a/assets/locales/zh.json
+++ b/assets/locales/zh.json
@@ -1815,6 +1815,7 @@
"ui.grid_follows_view_hint": "在侧视图中,将网格显示在朝向该视图的竖直平面上,而不是地面上",
"ui.ground_shadow": "地面阴影",
"ui.groupSelected": "将所选编组",
+ "ui.hatch": "剖面线",
"ui.heading_add_ins": "加载项",
"ui.heading_assemble": "装配",
"ui.heading_box": "长方体",
diff --git a/assets/shaders/viewport.wgsl b/assets/shaders/viewport.wgsl
index 6884ad8562..5911918800 100644
--- a/assets/shaders/viewport.wgsl
+++ b/assets/shaders/viewport.wgsl
@@ -253,7 +253,9 @@ fn solid(i: TOut, front: bool) -> vec4<f32> {
if (clipped(i.wp)) { discard; }
if (!front && length(u.clip.xyz) > 0.5) {
// The cut face in its body's colour ("from component" colouring), tinted toward the
- // cap colour so it reads as a cut, hatched at 45 degrees on screen.
+ // cap colour so it reads as a cut, hatched at 45 degrees on screen; with the hatch off
+ // (`u.cap.a` 0), plain in the body's own colour.
+ if (u.cap.a < 0.5) { return out_color(vec4<f32>(i.c.rgb, 1.0)); }
let base = mix(i.c.rgb, u.cap.rgb, 0.35);
let h = fract((i.pos.x + i.pos.y) / 9.0);
return out_color(vec4<f32>(select(base, base * 0.6, h < 0.22), 1.0));
diff --git a/crates/engine/src/cmd/section.rs b/crates/engine/src/cmd/section.rs
index 60e136286e..dae02beef0 100644
--- a/crates/engine/src/cmd/section.rs
+++ b/crates/engine/src/cmd/section.rs
@@ -12,7 +12,7 @@ pub static COMMANDS: &[CommandSpec] =
&[CommandSpec::new("inspect.section", "Section Analysis", section).at("SOLID", "INSPECT").icon("section").noundo().params(
"plane: XY|XZ|YZ | construction plane name or id | {origin, normal}; offset?: expr along the plane's normal (XY: +Z, XZ: +Y, YZ: +X); \
at?: expr, the cut's world coordinate on the named plane's axis (XY: Z, XZ: Y, YZ: X), instead of offset; \
- flip?: bool; or clear: true. Returns the cut's origin and normal, and for a named plane its axis and at",
+ flip?: bool; hatch?: bool (hatch the cut faces, in each body's colour; default true); or clear: true. Returns the cut's origin and normal, and for a named plane its axis and at",
)];
fn section(s: &mut Session, p: &Value) -> Result<Value> {
@@ -72,8 +72,9 @@ fn section(s: &mut Session, p: &Value) -> Result<Value> {
let normal = if bool_(p, "flip").unwrap_or(false) { -normal } else { normal };
let origin = origin + normal * offset * if bool_(p, "flip").unwrap_or(false) { -1.0 } else { 1.0 };
s.section = Some((origin, normal));
+ s.section_hatch = bool_(p, "hatch").unwrap_or(true);
s.revision += 1;
- let mut section = json!({"origin": origin, "normal": normal});
+ let mut section = json!({"origin": origin, "normal": normal, "hatch": s.section_hatch});
if let Some(i) = axis {
section["axis"] = json!(["X", "Y", "Z"].get(i).copied().unwrap_or("?"));
section["at"] = json!(axis_component(origin, i));
diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs
index 1e82cdf186..baf93456ca 100644
--- a/crates/engine/src/lib.rs
+++ b/crates/engine/src/lib.rs
@@ -282,6 +282,8 @@ pub struct Session {
pub sketch_clipboard: Option<cmd::sketch_clipboard::SketchClip>,
/// Section Analysis: a view cut by a plane (origin, unit normal; the normal side is hidden).
pub section: Option<(Vec3, Vec3)>,
+ /// Whether the section's cut faces are hatched (`inspect.section`'s `hatch`; on by default).
+ pub section_hatch: bool,
/// Surface analysis shading the model (zebra, draft, curvature map).
pub analysis: Option<SurfaceAnalysis>,
/// The seams `inspect.continuity` last measured, for the viewport to shade. View state: not
@@ -436,6 +438,7 @@ impl Session {
clipboard: Vec::new(),
sketch_clipboard: None,
section: None,
+ section_hatch: true,
analysis: None,
continuity: Vec::new(),
checkpoints: Vec::new(),
@@ -993,6 +996,7 @@ impl Session {
clipboard: self.clipboard.clone(),
sketch_clipboard: self.sketch_clipboard.clone(),
section: None,
+ section_hatch: true,
analysis: None,
continuity: Vec::new(),
checkpoints: Vec::new(),
diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs
index e543ae9288..7f1f58e459 100644
--- a/crates/engine/src/tests.rs
+++ b/crates/engine/src/tests.rs
@@ -1523,9 +1523,15 @@ fn section_analysis() {
let mut s = Session::default();
run(&mut s, "solid.box", json!({"length": 40, "width": 30, "height": 20}));
let (doc, undo) = (s.doc.clone(), s.undo.len());
- run(&mut s, "inspect.section", json!({"plane": "XZ", "offset": 15}));
+ let r = run(&mut s, "inspect.section", json!({"plane": "XZ", "offset": 15}));
let (o, n) = s.section.unwrap();
assert!((o - n * 15.0).len() < 1e-12 && (n.y.abs() - 1.0).abs() < 1e-12);
+ // The cut faces are hatched unless `hatch` says otherwise.
+ assert!(s.section_hatch && r["section"]["hatch"] == true, "{r}");
+ let r = run(&mut s, "inspect.section", json!({"plane": "XZ", "offset": 15, "hatch": false}));
+ assert!(!s.section_hatch && r["section"]["hatch"] == false, "{r}");
+ run(&mut s, "inspect.section", json!({"plane": "XZ", "offset": 15}));
+ assert!(s.section_hatch);
run(&mut s, "inspect.section", json!({"plane": {"origin": [0, 0, 5], "normal": [0, 0, 2]}, "flip": true}));
let (o, n) = s.section.unwrap();
assert!((o.z - 5.0).abs() < 1e-12 && (n.z + 1.0).abs() < 1e-12);
diff --git a/crates/engine/src/view.rs b/crates/engine/src/view.rs
index c45f30fd80..1a4e669476 100644
--- a/crates/engine/src/view.rs
+++ b/crates/engine/src/view.rs
@@ -453,6 +453,7 @@ fn build_scene(
background: Some(p.background),
clip: section.map(|(o, n)| (n, n.dot(o))),
cap: Some(p.cap),
+ plain_cap: !s.section_hatch,
analysis: s.analysis.map(|a| SceneAnalysis { mode: a.mode(), colors: p.analysis }),
..Default::default()
};
@@ -902,6 +903,28 @@ mod tests {
assert!(cap > 500, "fov {fov}: cap pixels {cap}");
}
}
+
+ /// The cut faces are hatched (stripes over the body's colour tinted toward the cap colour)
+ /// unless the section's `hatch` is off; then the cut is the body's own solid colour.
+ #[test]
+ fn cpu_picture_section_hatch_is_optional() {
+ let mut s = Session::default();
+ s.execute("solid.box", &json!({"length": 40, "width": 30, "height": 20})).unwrap();
+ s.execute("appearance.assign", &json!({"bodies": ["Body1"], "color": [40, 160, 90]})).unwrap();
+ let cam = home_camera(&s);
+ let mut picture = |hatch: bool| {
+ let plane = json!({"origin": [0, 15, 0], "normal": [0, -1, 0]});
+ s.execute("inspect.section", &json!({"plane": plane, "hatch": hatch})).unwrap();
+ solidcraft_render::render(&scene(&s, &cam), &cam, 300, 220).rgba
+ };
+ // Pixels in the body's exact colour: only a plain cut has them (lit faces are shaded).
+ let solid = |img: &[u8]| img.chunks(4).filter(|p| p[..3] == [40, 160, 90]).count();
+ let (hatched, plain) = (picture(true), picture(false));
+ assert!(solid(&plain) > 500, "plain cut: {} pixels in the body's colour", solid(&plain));
+ assert_eq!(solid(&hatched), 0, "the hatched cut is tinted");
+ let shades = |img: &[u8]| img.chunks(4).map(|p| [p[0], p[1], p[2]]).collect::<std::collections::BTreeSet<_>>().len();
+ assert!(shades(&hatched) > shades(&plain), "the hatch adds its stripes' shades");
+ }
}
#[cfg(test)]
diff --git a/crates/gpu/src/capture.rs b/crates/gpu/src/capture.rs
index 50ae63cad8..903aebe808 100644
--- a/crates/gpu/src/capture.rs
+++ b/crates/gpu/src/capture.rs
@@ -374,7 +374,7 @@ fn frame(scene: &Scene, cam: &Camera, [width, height]: [u32; 2], key: u64, acces
back: cam.back().to_f32(),
size_px: [width as f32, height as f32],
clip: scene.clip.map_or([0.0; 4], |(n, d)| [n.x as f32, n.y as f32, n.z as f32, d as f32]),
- cap: [f32::from(cap.0) / 255.0, f32::from(cap.1) / 255.0, f32::from(cap.2) / 255.0, 1.0],
+ cap: [f32::from(cap.0) / 255.0, f32::from(cap.1) / 255.0, f32::from(cap.2) / 255.0, if scene.plain_cap { 0.0 } else { 1.0 }],
images: Vec::new(),
analysis: analysis_uniform(mode, access.as_ref()),
analysis_colors: scene.analysis.map_or([0.0; 36], |a| analysis_colors(&a.colors)),
diff --git a/crates/gpu/src/view.rs b/crates/gpu/src/view.rs
index 07a0acd8ff..c243cd8273 100644
--- a/crates/gpu/src/view.rs
+++ b/crates/gpu/src/view.rs
@@ -470,7 +470,7 @@ pub struct Frame {
pub size_px: [f32; 2],
/// Section cut: (normal, d); fragments with normal·p > d are hidden. A zero normal: none.
pub clip: [f32; 4],
- /// Colour of the inside of cut bodies (straight sRGBA, 0..1).
+ /// Colour of the inside of cut bodies (straight sRGB, 0..1); alpha 1 hatches it, 0 leaves it plain in the body's colour.
pub cap: [f32; 4],
/// Canvases and decals.
pub images: Vec<GpuImage>,
diff --git a/crates/gpu/tests/capture.rs b/crates/gpu/tests/capture.rs
index fd544f7a08..218bdfb8ef 100644
--- a/crates/gpu/tests/capture.rs
+++ b/crates/gpu/tests/capture.rs
@@ -147,6 +147,26 @@ fn pictures_show_the_section_and_its_cap() {
}
}
+/// With the section's hatch off, the cut shows plain in its body's own colour, as the CPU
+/// rasterizer draws it; hatched, it is tinted and striped.
+#[test]
+fn pictures_show_a_plain_cut_without_the_hatch() {
+ let Some(c) = capturer() else { return };
+ let mut s = session(&[
+ ("solid.box", json!({"length": 40, "width": 30, "height": 20})),
+ ("appearance.assign", json!({"bodies": ["Body1"], "color": [40, 160, 90]})),
+ ]);
+ let cam = view::home_camera(&s);
+ let mut picture = |hatch: bool| {
+ s.execute("inspect.section", &json!({"plane": {"origin": [0, 15, 0], "normal": [0, -1, 0]}, "hatch": hatch})).unwrap();
+ c.rgba(&view::scene(&s, &cam), &cam, 300, 220).unwrap()
+ };
+ let solid = |img: &[u8]| pixels(img).filter(|p| p[..3].iter().zip([40u8, 160, 90]).all(|(a, b)| a.abs_diff(b) <= 3)).count();
+ let (hatched, plain) = (picture(true), picture(false));
+ assert!(solid(&plain) > 500, "plain cut: {} pixels in the body's colour", solid(&plain));
+ assert!(solid(&hatched) < 50, "the hatched cut is tinted: {}", solid(&hatched));
+}
+
/// Surface analysis shades headless pictures as it shades the viewport: a box's flat faces in
/// the curvature map's flat colour, zebra stripes in black and white, the accessibility analysis
/// in reachable and blocked colours.
diff --git a/crates/render/src/raster.rs b/crates/render/src/raster.rs
index 01ac16f5ab..606e6fa859 100644
--- a/crates/render/src/raster.rs
+++ b/crates/render/src/raster.rs
@@ -195,7 +195,12 @@ pub fn render(scene: &Scene, cam: &Camera, w: usize, h: usize) -> Canvas {
}
if cut {
// The cut: the body's colour tinted toward the cap colour, hatched
- // at 45 degrees (as the viewport draws it).
+ // at 45 degrees (as the viewport draws it); a plain cap is the
+ // body's own colour.
+ if scene.plain_cap {
+ c.put(x, y, base, 1.0);
+ continue;
+ }
let tinted: [f64; 3] = std::array::from_fn(|k| base[k] + (cap_tint[k] - base[k]) * 0.35);
let k = if ((x + y) / SS) % 9 < 2 { 0.6 } else { 1.0 };
c.put(x, y, tinted.map(|v| v * k), 1.0);
diff --git a/crates/render/src/scene.rs b/crates/render/src/scene.rs
index f7934b8944..7b1e62f55d 100644
--- a/crates/render/src/scene.rs
+++ b/crates/render/src/scene.rs
@@ -79,6 +79,8 @@ pub struct Scene {
pub clip: Option<(Vec3, f64)>,
/// The colour the section cap is tinted toward (default: [`SECTION_CAP`]).
pub cap: Option<Rgb>,
+ /// The section cap without its hatch: plain, in the body's own colour.
+ pub plain_cap: bool,
/// A surface analysis shading the meshes (zebra, draft, curvature map, ...).
pub analysis: Option<SceneAnalysis>,
}
diff --git a/crates/ui-egui/src/browser.rs b/crates/ui-egui/src/browser.rs
index 880786578e..09d72b82e3 100644
--- a/crates/ui-egui/src/browser.rs
+++ b/crates/ui-egui/src/browser.rs
@@ -1444,7 +1444,7 @@ pub fn set_section_visible(app: &mut SolveApp, visible: bool) {
if visible {
if let Some((origin, normal)) = app.tree.hidden_section {
let plane = json!({"origin": [origin.x, origin.y, origin.z], "normal": [normal.x, normal.y, normal.z]});
- if app.run("inspect.section", json!({ "plane": plane })).is_ok() {
+ if app.run("inspect.section", json!({"plane": plane, "hatch": app.session.section_hatch})).is_ok() {
app.tree.hidden_section = None;
}
}
diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs
index 058815d7fa..fcc8076490 100644
--- a/crates/ui-egui/src/control.rs
+++ b/crates/ui-egui/src/control.rs
@@ -212,14 +212,16 @@ pub fn request_scope(app: &SolveApp, params: &Value) -> Result<Option<vfs::PathS
/// mode, the section the viewport shows: an open Section Analysis dialog's preview, a sketch's
/// Slice), with the grid and the origin's axes as `guides` says.
pub(crate) fn view_scene(app: &SolveApp, guides: solidcraft_engine::view::Guides) -> solidcraft_engine::render::Scene {
- solidcraft_engine::view::scene_with_palette_and_guides(
+ let mut scene = solidcraft_engine::view::scene_with_palette_and_guides(
&app.session,
&app.cam,
crate::viewport::section_plane(app),
solidcraft_engine::view::world_curve_parts,
&crate::viewport::scene_palette(app.ui.dark, app.preferences.color_vision),
guides,
- )
+ );
+ scene.plain_cap = !crate::viewport::section_hatch(app);
+ scene
}
/// The grid and the origin's axes as the window shows them (the Grid and Origin switches).
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index a296c36752..ff349bd76a 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -278,6 +278,8 @@ crate::dialog_descriptor::dialog_descriptors! {
Section {
offset: String,
flip: bool,
+ /// Hatch the cut faces.
+ hatch: bool,
},
/// Measure one or two picked items (vertices, edges, faces): the result of the last
/// measurement and the items it was for.
@@ -698,9 +700,10 @@ impl Dialog {
vec![SelInput::new("Cylindrical face", FACES, false)],
),
"material.assign" => Dialog::new(Kind::Material { index: 1 }, vec![SelInput::new("Bodies", BODIES, true)]),
- "inspect.section" => {
- Dialog::new(Kind::Section { offset: "0 mm".into(), flip: false }, vec![SelInput::new("Plane", PLANES | PLANAR_FACES, false)])
- }
+ "inspect.section" => Dialog::new(
+ Kind::Section { offset: "0 mm".into(), flip: false, hatch: true },
+ vec![SelInput::new("Plane", PLANES | PLANAR_FACES, false)],
+ ),
"inspect.measure" => Dialog::new(
Kind::Measure { result: None, of: Vec::new(), show: None },
vec![SelInput::new("Items", FACES | EDGES | selection::VERTICES | selection::CURVES | PROFILES, true)],
@@ -2965,10 +2968,10 @@ pub(crate) fn run_dialog(app: &mut SolveApp, d: &Dialog) -> Result<(), String> {
}
}
}
- if let Kind::Section { offset, flip } = &d.kind
+ if let Kind::Section { offset, flip, hatch } = &d.kind
&& let Some(cut) = app.session.section
{
- app.tree.section_dialog = Some(SectionDraft { offset: offset.clone(), flip: *flip, plane: sels(d, 0).to_vec(), cut });
+ app.tree.section_dialog = Some(SectionDraft { offset: offset.clone(), flip: *flip, hatch: *hatch, plane: sels(d, 0).to_vec(), cut });
}
Ok(())
}
@@ -2981,7 +2984,7 @@ pub fn edit_section(app: &mut SolveApp) {
let cut = app.session.section.or(app.tree.hidden_section);
let Some(last) = app.tree.section_dialog.clone().filter(|last| cut.is_some_and(|c| same_cut(c, last.cut))) else { return };
if let Some(d) = app.dialog.as_mut().filter(|d| matches!(d.kind, Kind::Section { .. })) {
- d.kind = Kind::Section { offset: last.offset, flip: last.flip };
+ d.kind = Kind::Section { offset: last.offset, flip: last.flip, hatch: last.hatch };
if let Some(plane) = d.inputs.first_mut() {
plane.items = last.plane;
}
@@ -2994,6 +2997,7 @@ pub fn edit_section(app: &mut SolveApp) {
pub struct SectionDraft {
pub offset: String,
pub flip: bool,
+ pub hatch: bool,
pub plane: Vec<Sel>,
pub cut: (Vec3, Vec3),
}
@@ -3583,7 +3587,7 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S
let name = s.doc.material_names().get(*index).cloned().unwrap_or_else(|| solidcraft_engine::doc::DEFAULT_MATERIAL.into());
("material.assign", json!({"bodies": sels(d, 0).body_names(), "material": name}))
}
- Kind::Section { offset, flip } => {
+ Kind::Section { offset, flip, hatch } => {
need(0, "a plane or planar face")?;
let plane = match sels(d, 0).first() {
Some(Sel::Plane { name }) if matches!(name.as_str(), "XY" | "XZ" | "YZ") => json!(name),
@@ -3601,7 +3605,7 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S
}
_ => return Err("pick a plane or a planar face".into()),
};
- ("inspect.section", json!({"plane": plane, "offset": offset, "flip": flip}))
+ ("inspect.section", json!({"plane": plane, "offset": offset, "flip": flip, "hatch": hatch}))
}
Kind::Move { .. } => return Ok(vec![("solid.move".into(), crate::dialogs_move::params(app, d)?)]),
Kind::Hole { diameter, depth, kind, cb_diameter, cb_depth, cs_diameter, cs_angle, opts } => {
diff --git a/crates/ui-egui/src/dialogs_all_tests.rs b/crates/ui-egui/src/dialogs_all_tests.rs
index da457bc986..4a50f8b7d9 100644
--- a/crates/ui-egui/src/dialogs_all_tests.rs
+++ b/crates/ui-egui/src/dialogs_all_tests.rs
@@ -134,7 +134,8 @@ fn check_form(command: &str, labels: &[&str]) {
}
let checks: &[&str] = match command {
"solid.shell" => &["Tangent Chain"],
- "solid.rib" | "solid.web" | "solid.align" | "inspect.section" | "sheet.flange" | "sheet.hem" | "sheet.fold" | "joint.create" => &["Flip"],
+ "solid.rib" | "solid.web" | "solid.align" | "sheet.flange" | "sheet.hem" | "sheet.fold" | "joint.create" => &["Flip"],
+ "inspect.section" => &["Flip", "Hatch"],
"solid.move" => &["Create Copy"],
"solid.combine" => &["Keep Tools", "New Component"],
"solid.thread" => &["Modeled", "Full Length", "Automatic size"],
diff --git a/crates/ui-egui/src/dialogs_dense.rs b/crates/ui-egui/src/dialogs_dense.rs
index a58e1d5110..50467ffd40 100644
--- a/crates/ui-egui/src/dialogs_dense.rs
+++ b/crates/ui-egui/src/dialogs_dense.rs
@@ -786,9 +786,9 @@ fn additional_rows(app: &mut SolveApp, d: &mut Dialog, ui: &mut egui::Ui) -> boo
Kind::Plastic(k) => enter |= crate::dialogs_plastic::rows(app, ui, k, &d.inputs),
Kind::Assembly(k) => enter |= crate::dialogs_assembly::rows(app, ui, k, &mut d.inputs, &mut d.active),
Kind::Measure { result, show, .. } => measure_rows(app, ui, result.as_ref(), show),
- Kind::Section { offset, flip } => {
+ Kind::Section { offset, flip, hatch } => {
enter |= expr_row(ui, "Distance", offset);
- ui_kit::options(ui, "feature_options", &mut [("Flip", flip)]);
+ ui_kit::options(ui, "feature_options", &mut [("Flip", flip), ("Hatch", hatch)]);
}
Kind::Rename { name, .. } => {
form_row(ui, "Name", |ui| {
diff --git a/crates/ui-egui/src/section_browser_tests.rs b/crates/ui-egui/src/section_browser_tests.rs
index ac1982a890..746a2187c3 100644
--- a/crates/ui-egui/src/section_browser_tests.rs
+++ b/crates/ui-egui/src/section_browser_tests.rs
@@ -89,7 +89,7 @@ fn edit_opens_the_section_dialog() {
fn section_dialog(h: &Harness) -> (String, bool, Vec<solidcraft_engine::Sel>) {
let d = h.app.dialog.as_ref().expect("the Section Analysis dialog");
- let crate::dialogs::Kind::Section { offset, flip } = &d.kind else { panic!("not the section dialog: {:?}", d.kind) };
+ let crate::dialogs::Kind::Section { offset, flip, .. } = &d.kind else { panic!("not the section dialog: {:?}", d.kind) };
(offset.clone(), *flip, d.inputs.first().map(|i| i.items.clone()).unwrap_or_default())
}
@@ -148,3 +148,28 @@ fn edit_starts_from_the_section_as_it_was_left() {
assert_eq!(offset, "0 mm");
assert!(plane.is_empty());
}
+
+/// The dialog's Hatch option: the preview follows it, OK makes the section with it, and the
+/// section keeps it when hidden and shown again or edited.
+#[test]
+fn the_hatch_option_carries_through_the_section() {
+ let mut h = harness();
+ h.app.run("solid.box", json!({"length":40,"width":30,"height":20})).unwrap();
+ h.app.session.selection = vec![solidcraft_engine::Sel::Plane { name: "XY".into() }];
+ h.app.start("inspect.section");
+ assert!(crate::viewport::section_hatch(&h.app), "a new section is hatched");
+ if let Some(crate::dialogs::Kind::Section { hatch, .. }) = h.app.dialog.as_mut().map(|d| &mut d.kind) {
+ *hatch = false;
+ }
+ h.frames(2);
+ assert!(!crate::viewport::section_hatch(&h.app), "the preview follows the option");
+ ok(&mut h);
+ assert!(h.app.session.section.is_some() && !h.app.session.section_hatch);
+
+ click(&mut h, "eye:Section Analysis");
+ click(&mut h, "eye:Section Analysis");
+ assert!(h.app.session.section.is_some() && !h.app.session.section_hatch, "shown again, still plain");
+ menu(&mut h, "Edit Section Analysis");
+ let d = h.app.dialog.as_ref().map(|d| &d.kind);
+ assert!(matches!(d, Some(crate::dialogs::Kind::Section { hatch: false, .. })), "{d:?}");
+}
diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rs
index fe4e62a201..3fe6eddbbb 100644
--- a/crates/ui-egui/src/viewport.rs
+++ b/crates/ui-egui/src/viewport.rs
@@ -1701,6 +1701,15 @@ pub fn section_plane(app: &SolveApp) -> Option<(Vec3, Vec3)> {
app.session.section
}
+/// Whether the section [`section_plane`] shows has hatched cut faces: an open Section Analysis
+/// dialog's Hatch option, else the section's own.
+pub fn section_hatch(app: &SolveApp) -> bool {
+ match app.dialog.as_ref().map(|d| &d.kind) {
+ Some(crate::dialogs::Kind::Section { hatch, .. }) => *hatch,
+ _ => app.session.section_hatch,
+ }
+}
+
/// Visible geometry belonging to a timeline feature. Body creators retain their whole-body
/// feedback; modifiers use persistent face names, which survive later edits and placement.
/// Do not expand these faces into surface patches: neighbouring faces can belong to another
@@ -2705,7 +2714,10 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui) {
pv_slot: app.preview.slot.clone(),
pv_hide: app.preview.rolled_back,
clip: section_clip(app),
- cap: t.section_cap.to_normalized_gamma_f32(),
+ cap: {
+ let [r, g, b, _] = t.section_cap.to_normalized_gamma_f32();
+ [r, g, b, if section_hatch(app) { 1.0 } else { 0.0 }]
+ },
view_proj: proj.vp.to_f32(),
back: proj.cam.back().to_f32(),
size_px,