3D and Materials: Expand as Wireframes keeps a layer's path guides and cuts Revolve's art for Revolve

A layer expanded to its edges keeps the paths made into guides inside it, as it keeps its ruler
guides. A clipping group with Revolve and Rotate is cut for Revolve, the effect the canvas draws,
so its fills go in one piece and art with more fills than a 3D effect takes still expands.
This commit is contained in:
dotCooCoo
2026-11-12 09:47:53 -08:00
parent 714d72971c
commit 556123e691
5 changed files with 65 additions and 19 deletions
+8 -6
View File
@@ -10,7 +10,7 @@ use vectorcraft_three_d::Facet;
use super::{
INFLATE, Profile, ROTATE, facets, geometry, has_solid, inflate_options, is_container, is_plane, is_three_d, label_of, members, object_profile,
region, reshape_members, resolve, solid, solid_paints, solid_parts, union_bounds, view_options,
region, reshape_members, resolve, resolve_for, solid, solid_paints, solid_parts, union_bounds, view_options,
};
use crate::{GeomContext, is_geometry};
@@ -41,16 +41,18 @@ pub fn three_d_wireframe_in(doc: Option<&Document>, n: &Node) -> Result<Vec<Path
// is no surface to expand.
let revolve = crate::has_revolve(n) && crate::revolve_art_in(doc, n).is_some();
if !revolve && !(has_solid(n) && super::solid_art_in(doc, n).is_some()) {
let n = &*resolve(doc, n, label)?;
// The builders' own error says why, when there is one.
// The builders' own error says why, when there is one. Revolve's art is cut for Revolve,
// as the canvas cuts it.
if crate::has_revolve(n) {
crate::revolve::revolve_face_paths(doc, n)?;
crate::revolve::revolve_face_paths(doc, &*resolve_for(doc, n, label, false)?)?;
} else {
solid_face_paths(doc, n)?;
solid_face_paths(doc, &*resolve(doc, n, label)?)?;
}
return Err(format!("{label} draws the source art for this object instead of its 3D surface"));
}
let n = &*resolve(doc, n, label)?;
// Revolve's art is cut for Revolve whatever other 3D effect the object carries, as the canvas
// cuts it ([`crate::revolve_art_in`]).
let n = &*if revolve { resolve_for(doc, n, label, false)? } else { resolve(doc, n, label)? };
let faces = if revolve { crate::revolve::revolve_face_paths(doc, n)? } else { solid_face_paths(doc, n)? };
let faces = after_geometry(doc, n, faces, revolve);
let wire = edges(&faces)?;
@@ -204,6 +204,27 @@ fn a_geometry_effect_before_the_drawn_3d_effect_is_not_applied_again() {
assert!((both.x0 - alone.x0).abs() < 1e-6 && (both.x1 - alone.x1).abs() < 1e-6, "{alone:?} {both:?}");
}
/// A clipping group with Revolve and Rotate draws Revolve, which cuts the art's fills as one piece
/// in the top fill's place. Its wireframe is cut the same way, so art with more fills than a 3D
/// effect takes members still expands, to the edges of Revolve alone.
#[test]
fn a_clipping_group_with_revolve_and_rotate_expands_the_art_revolve_cuts() {
let mut art = Node::path(NodeId(3), square(100.0, 100.0, 100.0), Appearance::basic(Paint::solid(Color::BLACK), Paint::None, 0.0));
let fill = art.appearance.items.iter().find(|i| matches!(i, AppearanceItem::Fill(_))).cloned().unwrap();
art.appearance.items = vec![fill; super::super::MAX_MEMBERS + 4];
let mut clip = Node::path(NodeId(2), square(100.0, 100.0, 50.0), Appearance::default());
if let vectorcraft_doc::NodeKind::Path { clipping, .. } = &mut clip.kind {
*clipping = true;
}
let mut n = Node::new(NodeId(1), vectorcraft_doc::NodeKind::Group { children: vec![Arc::new(clip), Arc::new(art)], clip: true });
n.appearance.effects.push(crate::new_effect(crate::REVOLVE, &json!({})).unwrap());
let alone = segments(&three_d_wireframe_in(None, &n).unwrap());
n.appearance.effects.push(crate::new_effect(ROTATE, &json!({})).unwrap());
assert!(crate::revolve_art_in(None, &n).is_some(), "the canvas draws Revolve");
let both = segments(&three_d_wireframe_in(None, &n).unwrap());
assert_eq!(both, alone);
}
#[test]
fn an_object_without_a_visible_3d_effect_is_an_error() {
let mut n = solid_square(super::super::EXTRUDE, json!({}));
+12 -12
View File
@@ -25,7 +25,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Expand as Wireframes",
[],
None,
"{ids?: [..] (default: the selected objects)} replace each object that has a visible 3D effect (Extrude & Bevel, Revolve, Inflate, Rotate or one of their 3D (Classic) forms, on the object or on its fills and strokes) with a group of paths: the edges of the faces the effect draws, as the object is turned and projected now, each edge once (edges that meet end to end make one path, closed where it comes back to its start; curved edges stay curves; geometry effects after the 3D effect, on the object or on a fill or stroke, reshape them too), stroked 0.5 pt black with round joins and no fill (VectorCraft's own); the group takes the object's place, id, name, opacity, blending mode, opacity mask, attributes, slice and text wrap and is selected (a layer stays a layer holding the edges, which are selected, and its ruler guides); objects without a visible 3D effect are left as they are; one undo step. An error, with nothing changed, when no object is selected or given, when none has a visible 3D effect, when an object's solid can't be built or the canvas draws its source art in its place, or when one object's wireframe has more than 1,000,000 edges → {ids}",
"{ids?: [..] (default: the selected objects)} replace each object that has a visible 3D effect (Extrude & Bevel, Revolve, Inflate, Rotate or one of their 3D (Classic) forms, on the object or on its fills and strokes) with a group of paths: the edges of the faces the effect draws, as the object is turned and projected now, each edge once (edges that meet end to end make one path, closed where it comes back to its start; curved edges stay curves; geometry effects after the 3D effect, on the object or on a fill or stroke, reshape them too), stroked 0.5 pt black with round joins and no fill (VectorCraft's own); the group takes the object's place, id, name, opacity, blending mode, opacity mask, attributes, slice and text wrap and is selected (a layer stays a layer holding the edges, which are selected, and its ruler guides and paths made into guides); objects without a visible 3D effect are left as they are; one undo step. An error, with nothing changed, when no object is selected or given, when none has a visible 3D effect, when an object's solid can't be built or the canvas draws its source art in its place, or when one object's wireframe has more than 1,000,000 edges → {ids}",
has_doc,
expand_as_wireframes
)]
@@ -38,12 +38,12 @@ fn wire_appearance() -> Appearance {
Appearance { items: vec![AppearanceItem::Stroke(stroke)], ..Default::default() }
}
/// The ruler guides of layer `n` and then those of the sublayers inside it, in order, added to
/// `out`. A guide from a hidden or locked sublayer, or from one inside a hidden or locked group or
/// sublayer, is hidden or locked itself.
fn ruler_guides(n: &Node, hidden: bool, locked: bool, out: &mut Vec<Arc<Node>>) {
/// The guides (ruler guides and paths made into guides) of layer `n` and then those of the groups
/// and sublayers inside it, in order, added to `out`. A guide from a hidden or locked sublayer, or
/// from one inside a hidden or locked group or sublayer, is hidden or locked itself.
fn guides(n: &Node, hidden: bool, locked: bool, out: &mut Vec<Arc<Node>>) {
let Some(children) = n.children() else { return };
for c in children.iter().filter(|c| c.is_ruler_guide()) {
for c in children.iter().filter(|c| c.is_guide()) {
let mut g = c.clone();
if hidden || locked {
let g = Arc::make_mut(&mut g);
@@ -52,8 +52,8 @@ fn ruler_guides(n: &Node, hidden: bool, locked: bool, out: &mut Vec<Arc<Node>>)
}
out.push(g);
}
for c in children.iter().filter(|c| !c.is_ruler_guide()) {
ruler_guides(c, hidden || !c.visible, locked || c.locked, out);
for c in children.iter().filter(|c| !c.is_guide()) {
guides(c, hidden || !c.visible, locked || c.locked, out);
}
}
@@ -89,13 +89,13 @@ fn expand_as_wireframes(s: &mut Session, p: &Value) -> Result<Value> {
let Some(source) = d.node(id) else { continue };
if matches!(source.kind, NodeKind::Layer { .. }) {
// A layer stays a layer: its members become the edges, and its 3D effect is removed.
// Its ruler guides and those of its sublayers are not art: they stay, after the edges.
// Its guides and those of its sublayers are not art: they stay, after the edges.
let mut layer = source.clone();
let mut guides = vec![];
ruler_guides(source, false, false, &mut guides);
let mut kept = vec![];
guides(source, false, false, &mut kept);
let mut children: Vec<Arc<Node>> = wire.into_iter().map(|path| Arc::new(Node::path(d.alloc_id(), path, wire_appearance()))).collect();
selected.extend(children.iter().map(|c| c.id));
children.extend(guides);
children.extend(kept);
if let Some(members) = layer.children_mut() {
*members = children;
}
+23
View File
@@ -112,6 +112,29 @@ fn a_layer_keeps_its_ruler_guides() {
assert!(!st.selection.objects.is_empty() && st.selection.objects.iter().all(|id| !before.contains(id)));
}
/// A path made into a guide is not art either: it stays on the layer, after the edges, and is not
/// selected.
#[test]
fn a_layer_keeps_its_path_guides() {
let (mut s, id) = setup(None);
let layer = s.doc().unwrap().doc.layers[0].id;
s.execute("path.create", &json!({"d":"M0 300L300 300"})).unwrap();
s.execute("view.guides.make", &json!({})).unwrap();
let guides = |s: &Session| -> Vec<NodeId> {
s.doc().unwrap().doc.node(layer).unwrap().children().unwrap().iter().filter(|c| c.is_guide()).map(|c| c.id).collect()
};
let before = guides(&s);
assert_eq!(before.len(), 1);
assert_ne!(before[0], id);
s.execute("effect.apply", &json!({"ids":[layer.0],"effect":"threeD.extrude","item":null,"params":{}})).unwrap();
run(&mut s, json!({"ids":[layer.0]})).unwrap();
assert_eq!(guides(&s), before);
let st = s.doc().unwrap();
let children = st.doc.node(layer).unwrap().children().unwrap();
assert!(children.len() > 1 && children.last().is_some_and(|c| c.is_guide()));
assert!(!st.selection.objects.is_empty() && st.selection.objects.iter().all(|i| !before.contains(i)));
}
/// The number of segments in the wireframe group `id`.
fn segments(s: &Session, id: NodeId) -> usize {
let st = s.doc().unwrap();
+1 -1
View File
@@ -3237,7 +3237,7 @@ on the object or on a fill or stroke, reshape its edges as they reshape the draw
black stroke with round joins and no fill (VectorCraft's own choice). The group keeps the object's place, id, name,
visibility, lock, opacity, blending mode, knockout, opacity mask, attributes, slice and text wrap, and the groups
are selected.
A layer in `ids` stays a layer: its members are replaced by the edges, which are selected, and its ruler guides stay. Objects without a visible 3D effect do not change. It is one undo step and
A layer in `ids` stays a layer: its members are replaced by the edges, which are selected, and its ruler guides and paths made into guides stay. Objects without a visible 3D effect do not change. It is one undo step and
returns `{ids}`, the groups. It is an error, and nothing changes, when nothing is selected or given, when no object
has a visible 3D effect, when an object's solid can't be built or the canvas draws its source art in its place, or when one object's wireframe has more than
1,000,000 edges.