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.
This commit is contained in:
dotCooCoo
2026-11-15 18:53:09 -08:00
parent f190b81896
commit 48a708dc0f
2 changed files with 35 additions and 2 deletions
+11 -2
View File
@@ -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<vectorcraft_doc::Node>]) -> Option<vectorcraft_doc::Node> {
use std::sync::Arc;
use vectorcraft_doc::{Node, NodeKind};
let (clip, mut underlay) = underlay(id, faces)?;
let facets: Vec<Arc<Node>> = 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::<Option<_>>()?;
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 }))
}
+24
View File
@@ -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<Arc<Node>> = 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