From 556123e691bdf02748f270902c616c57481f05b0 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 12 Nov 2026 09:47:53 -0800 Subject: [PATCH] 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. --- crates/effects/src/solids/wireframe.rs | 14 +++++++----- crates/effects/src/solids/wireframe/tests.rs | 21 +++++++++++++++++ crates/engine/src/cmd/wireframe.rs | 24 ++++++++++---------- crates/engine/src/cmd/wireframe/tests.rs | 23 +++++++++++++++++++ docs/mcp.md | 2 +- 5 files changed, 65 insertions(+), 19 deletions(-) diff --git a/crates/effects/src/solids/wireframe.rs b/crates/effects/src/solids/wireframe.rs index 4f93b2f41a..f1dc324679 100644 --- a/crates/effects/src/solids/wireframe.rs +++ b/crates/effects/src/solids/wireframe.rs @@ -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 { "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>) { +/// 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>) { 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>) } 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 { 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> = 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; } diff --git a/crates/engine/src/cmd/wireframe/tests.rs b/crates/engine/src/cmd/wireframe/tests.rs index 268fbcd6db..33a30975d9 100644 --- a/crates/engine/src/cmd/wireframe/tests.rs +++ b/crates/engine/src/cmd/wireframe/tests.rs @@ -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 { + 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(); diff --git a/docs/mcp.md b/docs/mcp.md index 7457e6faa3..7d344068bb 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -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.