From 48a708dc0ffa56018396a054898806d5e62f776b Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 18:53:09 -0800 Subject: [PATCH] 3D: Inflate faces that carry graphics keep their colored-light underlay Under colored lights with smooth shading, a face of Inflate's front or back that carries part of a mapped graphic is drawn as a group of the face and those parts. The underlay that closes the seams between faces did not take such a group, so the whole run was drawn without it and hairline gaps could show between triangles. Such a face now takes its facet's underlay and stays in the order with its parts. --- crates/effects/src/lighting.rs | 13 +++++++++++-- crates/effects/src/solids/tests.rs | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/crates/effects/src/lighting.rs b/crates/effects/src/lighting.rs index e62e34b55e..7f7f1099e3 100644 --- a/crates/effects/src/lighting.rs +++ b/crates/effects/src/lighting.rs @@ -173,11 +173,20 @@ pub(crate) fn footprint(path: &vectorcraft_geom::BezPath, seam: f64) -> vectorcr /// footprints. Where two facets' antialiased edges meet, the underlay fills what they leave /// uncovered with the neighbors' own colors, so the background does not show through. `None` unless /// every face is a facet a surface draws: a path filled and stroked by its seam, or a facet composed -/// in a clip of its footprint, neither with an opacity mask. +/// in a clip of its footprint, neither with an opacity mask. A face drawn with the parts of Inflate's +/// graphics on it, a group of the facet and those parts, takes its facet's underlay and stays in the +/// order with its parts, which are cut to the facet's outline, so the clip keeps them. pub(crate) fn sealed(id: vectorcraft_doc::NodeId, faces: &[std::sync::Arc]) -> Option { use std::sync::Arc; use vectorcraft_doc::{Node, NodeKind}; - let (clip, mut underlay) = underlay(id, faces)?; + let facets: Vec> = faces + .iter() + .map(|face| match &face.kind { + NodeKind::Group { children, clip: false } if face.extras().mask.is_none() => children.first().cloned(), + _ => Some(face.clone()), + }) + .collect::>()?; + let (clip, mut underlay) = underlay(id, &facets)?; underlay.extend(faces.iter().cloned()); Some(Node::new(id, NodeKind::Group { children: vec![Arc::new(clip), Arc::new(Node::group(id, underlay))], clip: true })) } diff --git a/crates/effects/src/solids/tests.rs b/crates/effects/src/solids/tests.rs index d2ad2cb0cc..c4a33a76a2 100644 --- a/crates/effects/src/solids/tests.rs +++ b/crates/effects/src/solids/tests.rs @@ -587,6 +587,30 @@ fn drawn_face_bounds(f: &Node) -> Rect { } } +/// Under a colored light, an Inflate in a solid color with a graphic on its front lies over an +/// underlay of its faces, the faces that carry parts of the graphic included. +#[test] +fn a_colored_inflate_with_a_graphic_lies_over_an_underlay_of_its_faces() { + let mut d = Document::new(1000.0, 1000.0); + let mark = Node::path( + NodeId(0), + vectorcraft_geom::shapes::rectangle(Rect::new(500.0, 500.0, 510.0, 510.0)), + Appearance::basic(Paint::solid(BLUE), Paint::None, 0.0), + ); + d.symbols.push(vectorcraft_doc::Symbol { dynamic: false, name: "Mark".into(), art: Arc::new(mark) }); + let square = vectorcraft_geom::shapes::rectangle(Rect::new(0.0, 0.0, 100.0, 100.0)); + let mut n = Node::path(NodeId(7), square, Appearance::basic(Paint::solid(RED), Paint::None, 0.0)); + let p = json!({"rotationX": -20, "rotationY": -30, "rotationZ": 0, "lights": [{"color": "#ff8080"}], "graphics": [{"symbol": "Mark", "scale": 300.0}]}); + n.appearance.effects.push(fx(INFLATE, p)); + let art = solid_art_in(Some(&d), &n).unwrap(); + let order = art.children().unwrap()[0].children().unwrap(); + let faces: Vec> = order.iter().flat_map(unsealed).collect(); + assert!(faces.len() > order.len(), "the faces lie over an underlay"); + let carrying = faces.iter().filter(|f| matches!(f.kind, NodeKind::Group { clip: false, .. })).count(); + assert!(carrying > 0, "faces carry parts of the graphic"); + assert!(order.iter().all(|run| !Arc::ptr_eq(&unsealed(run)[0], run)), "every face is in a sealed run"); +} + /// Under a light that is not white, a solid-color fill and a solid-color stroke, plain, dashed or /// with a width profile, draw their faces in one order, the faces of both solids in the order of /// their depths where they overlap, in Inflate and in Extrude & Bevel, with and without perspective