Skip to content

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

Section Analysis: bodies behind the cut no longer colour the cap (#6328) (#6728)

bherbruck5012f33c85fb
diff --git a/crates/gpu/src/view.rs b/crates/gpu/src/view.rs
index 42a1059a77..ea1efe07a6 100644
--- a/crates/gpu/src/view.rs
+++ b/crates/gpu/src/view.rs
@@ -1780,7 +1780,8 @@ impl Renderer {
let built = [Some(tri_layout())];
let evaluated = [Some(planned_layout()), Some(color_layout())];
let placed = [Some(shared_layout()), Some(instance_layout())];
- let solid = |label: &str, fs: &str, cull: Option<wgpu::Face>, ds: Option<wgpu::DepthStencilState>, source: TriSource| {
+ // `colour`: whether the pipeline writes colour (the cap's depth pass writes none).
+ let solid_writes = |label: &str, fs: &str, cull: Option<wgpu::Face>, ds: Option<wgpu::DepthStencilState>, source: TriSource, colour: bool| {
let fs = source.fragment(fs);
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: Some(label),
@@ -1801,13 +1802,20 @@ impl Renderer {
fragment: Some(wgpu::FragmentState {
module: &module,
entry_point: Some(&fs),
- targets: &[Some(wgpu::ColorTargetState { format: t.format, blend: None, write_mask: wgpu::ColorWrites::ALL })],
+ targets: &[Some(wgpu::ColorTargetState {
+ format: t.format,
+ blend: None,
+ write_mask: if colour { wgpu::ColorWrites::ALL } else { wgpu::ColorWrites::empty() },
+ })],
compilation_options: Default::default(),
}),
multiview_mask: None,
cache: None,
})
};
+ let solid = |label: &str, fs: &str, cull: Option<wgpu::Face>, ds: Option<wgpu::DepthStencilState>, source: TriSource| {
+ solid_writes(label, fs, cull, ds, source, true)
+ };
// While a section is shown: the stencil marking and the cap (see `Renderer::tri_cut`).
let cut = |source: TriSource| {
t.depth.filter(|f| f.has_stencil_aspect()).map(|format| {
@@ -1844,7 +1852,11 @@ impl Renderer {
(
solid("sc_tris_mark", "fs_solid", None, Some(mark), source),
solid("sc_tris_mark_back", "fs_solid", Some(wgpu::Face::Front), Some(mark_back), source),
- solid("sc_tris_cap", "fs_solid_cut", Some(wgpu::Face::Front), Some(cap), source),
+ // Depth only: every back face behind a marked pixel draws here, so writing
+ // colour let the last one drawn paint the cut, other bodies behind it
+ // included (their colours and outlines showed through it, #6328). The
+ // marking passes already drew the nearest back face's colour.
+ solid_writes("sc_tris_cap", "fs_solid_cut", Some(wgpu::Face::Front), Some(cap), source, false),
)
})
};
diff --git a/crates/gpu/tests/capture.rs b/crates/gpu/tests/capture.rs
index 9f7258e2f7..2967ed6bef 100644
--- a/crates/gpu/tests/capture.rs
+++ b/crates/gpu/tests/capture.rs
@@ -192,6 +192,40 @@ fn pictures_show_a_plain_cut_without_the_hatch() {
assert!(solid(&hatched) < 50, "the hatched cut is tinted: {}", solid(&hatched));
}
+/// A body inside another's hollow, behind the cut, leaves no trace on the cap (#6328): the cap
+/// used to be painted by every face behind it, last drawn last, so the inner body's colour and
+/// outline showed through the cut like an X-ray. Hatched and plain, orthographic and
+/// perspective, the picture is the same with the inner body as without it.
+#[test]
+fn a_body_behind_the_cut_does_not_colour_the_cap() {
+ let Some(c) = capturer() else { return };
+ let outer = [
+ ("solid.box", json!({"length": 40, "width": 40, "height": 30, "body_name": "outer"})),
+ ("solid.box", json!({"length": 20, "width": 20, "height": 16, "corner": [10, 10, 7], "operation": "cut"})),
+ ("appearance.assign", json!({"bodies": ["outer"], "color": [40, 160, 90]})),
+ ];
+ let inner = [
+ ("solid.box", json!({"length": 8, "width": 8, "height": 6, "corner": [16, 16, 12], "operation": "new_body", "body_name": "inner"})),
+ ("appearance.assign", json!({"bodies": ["inner"], "color": [220, 30, 30]})),
+ ];
+ let mut alone = session(&outer);
+ let mut with = session(&[outer[0].clone(), outer[1].clone(), outer[2].clone(), inner[0].clone(), inner[1].clone()]);
+ for hatch in [true, false] {
+ // Cut away y < 6: the hollow (and the inner body) lie 4 mm behind the cut face.
+ for s in [&mut alone, &mut with] {
+ s.execute("inspect.section", &json!({"plane": {"origin": [0, 6, 0], "normal": [0, -1, 0]}, "hatch": hatch})).unwrap();
+ }
+ for fov in [0.0, 0.6] {
+ let mut cam = view::home_camera(&alone);
+ cam.fov = fov;
+ let picture = |s: &Session| c.rgba(&view::scene(s, &cam), &cam, 300, 220).unwrap();
+ let (a, b) = (picture(&alone), picture(&with));
+ let differ = pixels(&a).zip(pixels(&b)).filter(|(p, q)| p.iter().zip(q).any(|(x, y)| x.abs_diff(*y) > 8)).count();
+ assert_eq!(differ, 0, "hatch {hatch}, fov {fov}: the inner body shows through the cap in {differ} pixels");
+ }
+ }
+}
+
/// 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.