From 755d28c33345358e35a2e7a7caafd663cf516764 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 4 Dec 2026 22:30:06 -0800 Subject: [PATCH] 3D: Revolve renders on groups and on fills and strokes In Render Settings > Rendered, Revolve on a group or layer drew its shaded faces and reported "Revolve renders on a single object only". Revolve on a fill or stroke did the same. Extrude & Bevel, Inflate and Rotate already draw an image in both cases. - On a group, every member's surface is swept about the shared axis into one mesh list and drawn as one image, with the shadow plane placed from every member that casts. A member that is not an opaque solid color in Normal blending, or that sits in a group with an opacity mask or a blending mode, keeps the shaded faces and reports why, as the other effects do. The painted bounds of the group are the image's rectangle. - On a fill or stroke, that paint's surface is drawn as its own image under the effects after its Revolve, as Extrude & Bevel, Inflate and Rotate draw a rendered fill or stroke. - When a group's members, or the clipping groups, blends and symbol instances in it, can't be revolved, a rendered Revolve on the group reports the reason in the status bar and the command's warning. - The object, fill and stroke paths share one helper for the image, so the eligibility checks and the shadow plane are the same in each. Docs: docs/mcp.md, docs/three-d.md, docs/target-app-parity.md. --- crates/effects/src/revolve.rs | 238 ++++++++++++++++---- crates/effects/src/solids.rs | 9 +- crates/effects/src/solids/rendered.rs | 3 - crates/effects/src/solids/rendered/tests.rs | 171 +++++++++++++- docs/mcp.md | 6 +- docs/target-app-parity.md | 2 +- docs/three-d.md | 5 +- 7 files changed, 367 insertions(+), 67 deletions(-) diff --git a/crates/effects/src/revolve.rs b/crates/effects/src/revolve.rs index 601706a0ca..8d4e448162 100644 --- a/crates/effects/src/revolve.rs +++ b/crates/effects/src/revolve.rs @@ -1072,8 +1072,23 @@ fn group_meshes(n: &Node, total: &mut usize, limit: usize) -> Result Result, String> { // The graphics go on the side of the member with the longest profile, as the canvas draws them. - let longest = if options.map_surface { graphics_member(&shapes, b, options) } else { None }; + let longest = if options.map_surface { graphics_member(shapes, b, options) } else { None }; let mut out = vec![]; for (k, s) in shapes.iter().enumerate() { let Some(item) = surface_item(&s.items) else { continue }; @@ -1099,9 +1114,18 @@ pub(crate) fn art_reporting(doc: Option<&Document>, n: &Node, expand: bool, buil if !has_revolve(n) { return None; } - let n = &*resolve_for(doc, n, "Revolve", false).ok()?; + let n = &*match resolve_for(doc, n, "Revolve", false) { + Ok(n) => n, + Err(error) => { + // Art that has to be resolved draws only the Revolve on the object itself. + if n.appearance.effects.iter().find(|e| e.visible && is_revolve(&e.id)).is_some_and(crate::renders_image) { + warning.get_or_insert(error); + } + return None; + } + }; if is_container(n) { - return group_art(doc, n, expand, check_only, warning); + return group_art(doc, n, expand, build, warning); } let (path, rule) = profile(n)?; let ctx = GeomContext::of(n); @@ -1115,37 +1139,8 @@ pub(crate) fn art_reporting(doc: Option<&Document>, n: &Node, expand: bool, buil let paints = solid_paints(n); let item = surface_item(&paints)?; let expand = expand && !n.appearance.effects.iter().skip(index + 1).any(|e| e.visible && is_geometry(&e.id)); - let p = merged_params(&fx.id, &fx.params); - // Rendered, the surface's image, with the shadows of every light on the surface and on the - // shadow plane; the shaded faces when it can't be made, and for vector measurements. - let image = crate::render_settings(&fx.id, &p).filter(|_| build != Build::Vector).and_then(|settings| { - let result = if crate::solids::rendered::reshapes_paths_only(&n.appearance.effects[index + 1..]) { - Err(crate::solids::rendered::PATHS_ONLY.into()) - } else if crate::mapped_graphics(&p).is_empty() && crate::solids::rendered::takes([item], false) { - let b = path.bounds()?; - let (paint, opacity, _) = paint_of(item); - let options = rule_options(fx, rule); - surface_meshes(&path, rule, b, fx, options, (&paint, opacity, 1.0), true).and_then(|meshes| { - let lighting = crate::solids::rendered::lighting(&fx.id, &p); - let lighting = match crate::solids::rendered::plane_settings(&p, &lighting).filter(|_| crate::solids::shadow::casts(opacity)) { - Some(shadow) => { - let mut caster = vectorcraft_three_d::ShadowCaster::new(); - let faces = cast_surface(&mut caster, &path, b, options, None)?; - crate::solids::rendered::with_receiver(lighting, &caster, shadow, &[faces]) - } - None => lighting, - }; - if build == Build::Bounds { - crate::solids::rendered::bounds_art(doc, n.id, &lighting, &meshes, settings) - } else { - crate::solids::rendered::art(doc, n.id, &lighting, &meshes, settings, check_only) - } - }) - } else { - Err(crate::solids::rendered::OPAQUE_ONLY.into()) - }; - crate::solids::rendered::reported(result, warning) - }); + let later = n.appearance.effects.get(index + 1..).unwrap_or_default(); + let image = surface_image(ImageFor { doc, id: n.id, build }, fx, later, &path, rule, item, warning); if check_only { return None; } @@ -1180,13 +1175,22 @@ pub(crate) fn art_reporting(doc: Option<&Document>, n: &Node, expand: bool, buil for (original, item) in originals.into_iter().zip(&items) { if let Some(index) = item.effects().iter().position(|e| e.visible && is_revolve(&e.id)) { let fx = item.effects().get(index)?; - if crate::renders_image(fx) { - warning.get_or_insert_with(|| crate::solids::rendered::OBJECTS_ONLY.into()); - } - if check_only { + if check_only && !crate::renders_image(fx) { continue; } let p = geometry(&path, item.effects().get(..index)?, &ctx.item(original)); + // Rendered, this fill's or stroke's surface as an image, under the effects after its + // Revolve, with the shadows in the image. + let later = item.effects().get(index + 1..).unwrap_or_default(); + let image = surface_image(ImageFor { doc, id: n.id, build }, fx, later, &p, rule, item, warning); + if check_only { + continue; + } + if let Some(mut image) = image { + Arc::make_mut(&mut image).appearance.effects = later.iter().filter(|e| !is_revolve(&e.id)).cloned().collect(); + children.push(image); + continue; + } let expand = expand && !item.effects().iter().skip(index + 1).any(|e| e.visible && is_geometry(&e.id)); if crate::solids::renders_wireframe(fx) { let mut art = wire_art(n.id, [(&p, rule)], p.bounds()?, fx, fx_options(fx))?; @@ -1218,6 +1222,126 @@ pub(crate) fn art_reporting(doc: Option<&Document>, n: &Node, expand: bool, buil Some(art) } +/// What a rendered image is made for: the object `id` it is art of, the document `doc` whose raster +/// effects resolution it takes, and the art `build` it goes in. +#[derive(Clone, Copy)] +struct ImageFor<'a> { + doc: Option<&'a Document>, + id: NodeId, + build: Build, +} + +/// The rendered image of Revolve `fx` for `to`, swept from `path` (filled under `rule`) about its +/// own bounds and painted with `item`; `later` are the effects after `fx`. `None` when `fx` draws no +/// image or `to.build` takes none, and when the image can't be made, with the reason in `warning`: +/// the caller then draws the shaded faces. +fn surface_image( + to: ImageFor, + fx: &Effect, + later: &[Effect], + path: &PathData, + rule: FillRule, + item: &AppearanceItem, + warning: &mut Option, +) -> Option> { + let p = merged_params(&fx.id, &fx.params); + let settings = crate::render_settings(&fx.id, &p).filter(|_| to.build != Build::Vector)?; + let paint = item.paint(); + let opacity = item.opacity(); + let result = if crate::solids::rendered::reshapes_paths_only(later) { + Err(crate::solids::rendered::PATHS_ONLY.into()) + } else if !crate::mapped_graphics(&p).is_empty() + || !crate::solids::rendered::takes([item], false) + || crate::solids::mesh_color(paint, opacity)[3] != 1.0 + { + Err(crate::solids::rendered::OPAQUE_ONLY.into()) + } else if let Some(b) = path.bounds() { + let options = rule_options(fx, rule); + surface_meshes(path, rule, b, fx, options, (paint, opacity, 1.0), true).and_then(|meshes| { + let lighting = crate::solids::rendered::lighting(&fx.id, &p); + let lighting = match crate::solids::rendered::plane_settings(&p, &lighting).filter(|_| crate::solids::shadow::casts(opacity)) { + Some(shadow) => { + let mut caster = vectorcraft_three_d::ShadowCaster::new(); + let faces = cast_surface(&mut caster, path, b, options, None)?; + crate::solids::rendered::with_receiver(lighting, &caster, shadow, &[faces]) + } + None => lighting, + }; + image_for(to, &lighting, &meshes, settings) + }) + } else { + Err("Revolve requires a shape with at least two anchors".into()) + }; + crate::solids::rendered::reported(result, warning) +} + +/// [`surface_image`] of the members `shapes` of a group, every member swept about the axis of `b` +/// with `options` into one image, as the shaded faces draw them in one order. The shaded faces are +/// drawn instead when a member's surface is not an opaque solid color in Normal blending, or when a +/// member, or a group it is in, has an opacity below 100%, a blending mode or an opacity mask. +fn members_image( + to: ImageFor, + fx: &Effect, + later: &[Effect], + shapes: &[Profile], + b: Rect, + options: Revolve, + warning: &mut Option, +) -> Option> { + let p = merged_params(&fx.id, &fx.params); + let settings = crate::render_settings(&fx.id, &p).filter(|_| to.build != Build::Vector)?; + let profiles = shapes.iter().filter(|s| surface_item(&s.items).is_some()); + let surfaces = profiles.clone().filter_map(|s| surface_item(&s.items)); + let result = if profiles.clone().next().is_none() { + Err("Revolve requires a group holding a shape with a fill or stroke".into()) + } else if crate::solids::rendered::reshapes_paths_only(later) { + Err(crate::solids::rendered::PATHS_ONLY.into()) + } else if crate::mapped_graphics(&p).is_empty() + && crate::solids::rendered::takes(surfaces, crate::solids::profiles_have_masks(profiles)) + && shapes.iter().all(|s| { + let Some(item) = surface_item(&s.items) else { return true }; + crate::solids::mesh_color(item.paint(), item.opacity() * s.opacity)[3] == 1.0 + }) + { + members_meshes(fx, shapes, b, options, &mut 0, crate::solids::MAX_MESH_TRIANGLES).and_then(|meshes| { + let lighting = crate::solids::rendered::lighting(&fx.id, &p); + let lighting = match crate::solids::rendered::plane_settings(&p, &lighting) { + Some(shadow) => { + let mut caster = vectorcraft_three_d::ShadowCaster::new(); + let mut faces = vec![]; + for s in shapes { + let Some((_, opacity, _)) = surface_item(&s.items).map(paint_of) else { continue }; + if crate::solids::shadow::casts(opacity * s.opacity) { + faces.push(cast_surface(&mut caster, &s.path, b, Revolve { fill_rule: s.rule, ..options }, None)?); + } + } + crate::solids::rendered::with_receiver(lighting, &caster, shadow, &faces) + } + None => lighting, + }; + image_for(to, &lighting, &meshes, settings) + }) + } else { + Err(crate::solids::rendered::OPAQUE_ONLY.into()) + }; + crate::solids::rendered::reported(result, warning) +} + +/// The rendered image of `meshes` lit by `lighting` for `to`: for [`Build::Bounds`] its rectangle +/// without pixels, for [`Build::Check`] only the check of its limits. +fn image_for( + to: ImageFor, + lighting: &crate::solids::rendered::Lighting, + meshes: &[crate::SolidMesh], + settings: crate::solids::wireframe::RenderSettings, +) -> Result>, String> { + if to.build == Build::Bounds { + crate::solids::rendered::bounds_art(to.doc, to.id, lighting, meshes, settings) + } else { + crate::solids::rendered::art(to.doc, to.id, lighting, meshes, settings, to.build == Build::Check) + } +} + /// The members' `surfaces`, or runs of their faces, in order, from the [`Scope`] at `level` of each /// one's `Profile::scopes` inward: consecutive surfaces that share a scope go in one group with its /// opacity, blending mode and opacity mask, so each applies once, to the faces it holds together. @@ -1338,19 +1462,43 @@ pub(crate) fn overlaps(a: Rect, b: Rect) -> bool { /// [`art`] of group or layer `n`: every member swept about one axis on the bounds of all of them, /// each in its own paint. Every member's faces are drawn in one back-to-front order. `None` when /// the effect is only on the group's own fills or strokes or when its members can't be revolved. -fn group_art(doc: Option<&Document>, n: &Node, expand: bool, check_only: bool, warning: &mut Option) -> Option { +fn group_art(doc: Option<&Document>, n: &Node, expand: bool, build: Build, warning: &mut Option) -> Option { + let check_only = build == Build::Check; let index = n.appearance.effects.iter().position(|e| e.visible && is_revolve(&e.id))?; let fx = n.appearance.effects.get(index)?; - if crate::renders_image(fx) { - warning.get_or_insert_with(|| crate::solids::rendered::OBJECTS_ONLY.into()); + if check_only && !crate::renders_image(fx) { + return None; } + let prepared = members(n, "Revolve").and_then(|mut shapes| { + reshape_members(n, n.appearance.effects.get(..index).unwrap_or_default(), &mut shapes); + let b = union_bounds(&shapes).ok_or("Revolve requires a group holding a shape with at least two anchors")?; + let options = shared_options(&shapes, fx_options(fx))?; + Ok((shapes, b, options)) + }); + let (shapes, b, options) = match prepared { + Ok(prepared) => prepared, + Err(e) => { + // In rendered mode the reason the members can't be revolved is reported, as the reason + // an image can't be made is; the canvas then draws the source art. + if crate::renders_image(fx) { + warning.get_or_insert(e); + } + return None; + } + }; + // Rendered, one image of every member's surface, with the shadows of every light on the + // surfaces and on the shadow plane; the shaded faces when it can't be made. + let later = n.appearance.effects.get(index + 1..).unwrap_or_default(); + let image = members_image(ImageFor { doc, id: n.id, build }, fx, later, &shapes, b, options, warning); if check_only { return None; } - let mut shapes = members(n, "").ok()?; - reshape_members(n, n.appearance.effects.get(..index)?, &mut shapes); - let b = union_bounds(&shapes)?; - let options = shared_options(&shapes, fx_options(fx)).ok()?; + if let Some(image) = image { + let mut art = n.clone(); + art.kind = NodeKind::Group { children: vec![image], clip: false }; + art.appearance = Appearance { effects: past_effect(&n.appearance.effects, index), ..Default::default() }.into(); + return Some(art); + } if crate::solids::renders_wireframe(fx) { // In wireframe mode the edges of every member's faces, with no shadow. let paths = shapes.iter().filter(|s| surface_item(&s.items).is_some()).map(|s| (&s.path, s.rule)); diff --git a/crates/effects/src/solids.rs b/crates/effects/src/solids.rs index 6a9ddfbbff..5fca519b94 100644 --- a/crates/effects/src/solids.rs +++ b/crates/effects/src/solids.rs @@ -689,7 +689,12 @@ fn masked(id: NodeId, surfaces: Vec<(&[Scope], Arc)>) -> Vec> { /// Does any of `shapes` sit in a scope with an opacity mask or a blending mode other than Normal? pub(crate) fn has_masks(shapes: &[Profile]) -> bool { - shapes.iter().any(|s| s.scopes.iter().any(composites)) + profiles_have_masks(shapes.iter()) +} + +/// Does any profile sit in a scope with an opacity mask or a blending mode other than Normal? +pub(crate) fn profiles_have_masks<'a>(mut shapes: impl Iterator) -> bool { + shapes.any(|s| s.scopes.iter().any(composites)) } /// One shape a solid is built from: its outline and fill rule, the fills and strokes that paint @@ -721,7 +726,7 @@ const MAX_MEMBERS: usize = 4096; /// The most triangles the meshes of one 3D effect hold together (about 290 MB of corners and /// normals): past it the object is too complex to export. -const MAX_MESH_TRIANGLES: usize = 2_000_000; +pub(crate) const MAX_MESH_TRIANGLES: usize = 2_000_000; /// The most facets of solid colors under colored lights that one 3D effect draws as faces of their /// own, to go in one order with other solids' faces. Each such face is about 16 nodes, a composite diff --git a/crates/effects/src/solids/rendered.rs b/crates/effects/src/solids/rendered.rs index 59b425da48..a21ccbbba2 100644 --- a/crates/effects/src/solids/rendered.rs +++ b/crates/effects/src/solids/rendered.rs @@ -35,9 +35,6 @@ pub(crate) fn reshapes_paths_only(effects: &[vectorcraft_doc::Effect]) -> bool { }) } -/// The message for Revolve on a group or on a fill or stroke, which draws its shaded faces. -pub const OBJECTS_ONLY: &str = "Revolve renders on a single object only; showing the shaded faces instead"; - /// Why a visible 3D effect in rendered mode on `n` draws shaded faces instead of an image. /// Messages are English, to be translated when displayed. `None` when no rendered effect falls back. pub fn rendered_warning(doc: &vectorcraft_doc::Document, n: &Node) -> Option { diff --git a/crates/effects/src/solids/rendered/tests.rs b/crates/effects/src/solids/rendered/tests.rs index 403991b6ca..59633f835f 100644 --- a/crates/effects/src/solids/rendered/tests.rs +++ b/crates/effects/src/solids/rendered/tests.rs @@ -796,7 +796,7 @@ fn rendered_images_are_reused_until_an_input_changes() { /// faces, which apply them; without either, the group draws the image. #[test] fn masked_or_blended_members_draw_the_shaded_faces() { - for id in [super::super::EXTRUDE, super::super::INFLATE, super::super::ROTATE] { + for id in FOUR { let group = |member: Node| { let mut g = Node::group(NodeId(10), vec![std::sync::Arc::new(member)]); g.appearance.effects.push(crate::new_effect(id, &json!({"render": {"mode": "rendered", "quality": "low"}})).unwrap()); @@ -817,23 +817,170 @@ fn masked_or_blended_members_draw_the_shaded_faces() { } } -/// Revolve on a group, or on a fill or stroke, draws the shaded faces and reports why. +/// The page rectangle image `i` covers. +fn image_rect(i: &vectorcraft_doc::ImageObject) -> Rect { + let [a, _, _, d, e, f] = i.xf.as_coeffs(); + Rect::new(e, f, e + a * f64::from(i.width), f + d * f64::from(i.height)) +} + +/// Revolve on a group draws one image of every member's surface, over the area of the shaded faces +/// of all of them, and its painted bounds are that image's rectangle; nothing is reported. #[test] -fn revolve_on_a_group_or_a_paint_reports_objects_only() { +fn revolve_on_a_group_draws_one_image_of_every_member() { + let doc = vectorcraft_doc::Document::new(600.0, 400.0); + let member = + |id: u64, x: f64, color: Color| Node::path(NodeId(id), square(x, 100.0, 100.0), Appearance::basic(Paint::solid(color), Paint::None, 0.0)); + let members = + vec![std::sync::Arc::new(member(11, 100.0, Color::rgb(0.2, 0.5, 0.8))), std::sync::Arc::new(member(12, 300.0, Color::rgb(0.8, 0.3, 0.2)))]; + let mut group = Node::group(NodeId(10), members); + group.appearance.effects.push(crate::new_effect(crate::REVOLVE, &json!({"render": {"mode": "rendered", "quality": "low"}})).unwrap()); + assert_eq!(crate::rendered_warning(&doc, &group), None, "a group's rendered Revolve reports a fallback"); + let art = crate::revolve_art_drawn_in(Some(&doc), &group).unwrap(); + let found = images(&art); + assert_eq!(found.len(), 1, "a group's Revolve draws one image of every member, not the shaded faces"); + assert!(faces_bounds(&art).is_none(), "a group's rendered Revolve draws no shaded faces"); + let shaded = faces_bounds(&crate::revolve_art_in(Some(&doc), &group).unwrap()).unwrap(); + let rect = image_rect(&found[0]); + let grown = rect.inflate(1.0, 1.0); + assert!(grown.contains(shaded.origin()) && grown.contains(Point::new(shaded.x1, shaded.y1)), "the image {rect:?} misses the faces {shaded:?}"); + let bounds = crate::three_d_bounds_art_in(Some(&doc), &group).unwrap(); + let measured = images(&bounds); + assert_eq!(measured.len(), 1, "the painted bounds of a group's rendered Revolve are its image's rectangle"); + assert_eq!(image_rect(&measured[0]), rect); +} + +/// A group's rendered Revolve draws the shaded faces, and reports why, when a member is not opaque. +#[test] +fn revolve_on_a_group_with_a_see_through_member_draws_the_shaded_faces() { + let doc = vectorcraft_doc::Document::new(400.0, 400.0); + let mut member = + Node::path(NodeId(11), square(100.0, 100.0, 100.0), Appearance::basic(Paint::solid(Color::rgb(0.2, 0.5, 0.8)), Paint::None, 0.0)); + member.opacity = 0.5; + let mut group = Node::group(NodeId(10), vec![std::sync::Arc::new(member)]); + group.appearance.effects.push(crate::new_effect(crate::REVOLVE, &json!({"render": {"mode": "rendered", "quality": "low"}})).unwrap()); + assert_eq!(crate::rendered_warning(&doc, &group).as_deref(), Some(OPAQUE_ONLY), "member at 50%"); + let art = drawn(&group); + assert!(images(&art).is_empty() && faces_bounds(&art).is_some(), "member at 50%"); +} + +/// A member with no surface paint does not prevent the group's Revolve from rendering. +#[test] +fn revolve_on_a_group_ignores_blending_on_an_unpainted_member() { + let doc = vectorcraft_doc::Document::new(400.0, 400.0); + let painted = Node::path(NodeId(11), square(100.0, 100.0, 100.0), Appearance::basic(Paint::solid(Color::rgb(0.2, 0.5, 0.8)), Paint::None, 0.0)); + let mut unpainted = Node::path(NodeId(12), square(250.0, 100.0, 100.0), Appearance::basic(Paint::None, Paint::None, 0.0)); + unpainted.blend = vectorcraft_doc::color::BlendMode::Multiply; + let mut group = Node::group(NodeId(10), vec![std::sync::Arc::new(painted), std::sync::Arc::new(unpainted)]); + group.appearance.effects.push(crate::new_effect(crate::REVOLVE, &json!({"render": {"mode": "rendered", "quality": "low"}})).unwrap()); + assert_eq!(crate::rendered_warning(&doc, &group), None); + assert_eq!(images(&drawn(&group)).len(), 1); +} + +/// A group whose members can't be revolved reports why in rendered mode. +#[test] +fn revolve_on_a_group_that_cant_be_revolved_reports_why() { + let doc = vectorcraft_doc::Document::new(400.0, 400.0); + let mut group = Node::group(NodeId(10), vec![]); + group.appearance.effects.push(crate::new_effect(crate::REVOLVE, &json!({"render": {"mode": "rendered", "quality": "low"}})).unwrap()); + let warning = crate::rendered_warning(&doc, &group); + assert!(warning.as_deref().is_some_and(|w| w.starts_with("Revolve requires")), "an empty group's rendered Revolve reports {warning:?}"); + // An image with a fill of its own inside a clipping group is refused while the clipping group + // is resolved, before the members are listed. + let mut clip = Node::path(NodeId(21), square(100.0, 100.0, 100.0), Appearance::default()); + if let NodeKind::Path { clipping, .. } = &mut clip.kind { + *clipping = true; + } + let mut image = Node::new( + NodeId(22), + NodeKind::Image(Box::new(vectorcraft_doc::ImageObject { + key: "k".into(), + width: 10, + height: 10, + xf: vectorcraft_geom::Affine::translate((150.0, 150.0)), + link: None, + placement: Default::default(), + pixels: None, + })), + ); + image.appearance = Appearance::basic(Paint::solid(Color::BLACK), Paint::None, 0.0).into(); + let clipped = Node::new(NodeId(20), NodeKind::Group { children: vec![std::sync::Arc::new(clip), std::sync::Arc::new(image)], clip: true }); + let mut group = Node::group(NodeId(10), vec![std::sync::Arc::new(clipped.clone())]); + group.appearance.effects.push(crate::new_effect(crate::REVOLVE, &json!({"render": {"mode": "rendered", "quality": "low"}})).unwrap()); + let warning = crate::rendered_warning(&doc, &group); + assert!(warning.as_deref().is_some_and(|w| w.contains("trace it first")), "a clipped image's rendered Revolve reports {warning:?}"); + // A clipping group draws no Revolve on its own fill, so that one reports nothing. + let mut on_fill = clipped; + on_fill.appearance = Appearance::basic(Paint::solid(Color::BLACK), Paint::None, 0.0).into(); + on_fill.appearance.items[0].effects_mut().push(crate::new_effect(crate::REVOLVE, &json!({"render": {"mode": "rendered"}})).unwrap()); + assert_eq!(crate::rendered_warning(&doc, &on_fill), None, "a clipping group's fill Revolve"); +} + +/// A group's rendered Revolve reports when no member has a fill or stroke. +#[test] +fn revolve_on_a_group_without_surface_paint_reports_why() { + let doc = vectorcraft_doc::Document::new(400.0, 400.0); + let member = Node::path(NodeId(11), square(100.0, 100.0, 100.0), Appearance::basic(Paint::None, Paint::None, 0.0)); + let mut group = Node::group(NodeId(10), vec![std::sync::Arc::new(member)]); + group.appearance.effects.push(crate::new_effect(crate::REVOLVE, &json!({"render": {"mode": "rendered", "quality": "low"}})).unwrap()); + assert_eq!(crate::rendered_warning(&doc, &group).as_deref(), Some("Revolve requires a group holding a shape with a fill or stroke")); +} + +/// Revolve on a fill, or on a stroke, draws an image of that paint's surface under the effects +/// after it, with nothing reported; with both, each draws its own image. A fill at 50% draws the +/// shaded faces and reports why. +#[test] +fn revolve_on_a_fill_or_a_stroke_draws_its_image() { + use vectorcraft_doc::AppearanceItem; let doc = vectorcraft_doc::Document::new(400.0, 400.0); let rendered = || crate::new_effect(crate::REVOLVE, &json!({"render": {"mode": "rendered", "quality": "low"}})).unwrap(); - let member = || Node::path(NodeId(11), square(100.0, 100.0, 100.0), Appearance::basic(Paint::solid(Color::rgb(0.2, 0.5, 0.8)), Paint::None, 0.0)); - let mut group = Node::group(NodeId(10), vec![std::sync::Arc::new(member())]); - group.appearance.effects.push(rendered()); - assert_eq!(crate::rendered_warning(&doc, &group).as_deref(), Some(OBJECTS_ONLY), "group"); - assert!(images(&drawn(&group)).is_empty(), "group"); - let mut fill = member(); - fill.appearance.items[0].effects_mut().push(rendered()); - assert_eq!(crate::rendered_warning(&doc, &fill).as_deref(), Some(OBJECTS_ONLY), "fill"); - assert!(images(&drawn(&fill)).is_empty(), "fill"); + let painted = || { + Node::path( + NodeId(11), + square(100.0, 100.0, 100.0), + Appearance::basic(Paint::solid(Color::rgb(0.2, 0.5, 0.8)), Paint::solid(Color::BLACK), 4.0), + ) + }; + let at = |n: &Node, stroke: bool| n.appearance.items.iter().position(|i| matches!(i, AppearanceItem::Stroke(_)) == stroke).unwrap(); + for stroke in [false, true] { + let mut n = painted(); + let i = at(&n, stroke); + n.appearance.items[i].effects_mut().push(rendered()); + n.appearance.items[i].effects_mut().push(crate::new_effect("stylize.dropShadow", &json!({})).unwrap()); + assert_eq!(crate::rendered_warning(&doc, &n), None, "stroke {stroke}: a paint's rendered Revolve reports a fallback"); + let art = crate::revolve_art_drawn_in(Some(&doc), &n).unwrap(); + let mut later = vec![]; + art.walk(&mut |c| { + if matches!(c.kind, NodeKind::Image(_)) { + later.push(c.appearance.effects.iter().map(|e| e.id.clone()).collect::>()); + } + }); + assert_eq!(later, [["stylize.dropShadow"]], "stroke {stroke}: Revolve on one paint draws one image under the effects after it"); + } + let mut both = painted(); + for item in &mut both.appearance.items { + item.effects_mut().push(rendered()); + } + assert_eq!(images(&crate::revolve_art_drawn_in(Some(&doc), &both).unwrap()).len(), 2, "each paint draws its own image"); + let mut faint = painted(); + let i = at(&faint, false); + faint.appearance.items[i].effects_mut().push(rendered()); + if let AppearanceItem::Fill(f) = &mut faint.appearance.items[i] { + f.opacity = 0.5; + } + assert_eq!(crate::rendered_warning(&doc, &faint).as_deref(), Some(OPAQUE_ONLY), "fill at 50%"); + assert!(images(&drawn(&faint)).is_empty(), "fill at 50%"); assert_eq!(crate::rendered_warning(&doc, &solid_square(crate::REVOLVE, Color::BLACK, json!({"render": {"mode": "rendered"}}))), None); } +/// A rendered Revolve on an empty fill profile reports why it cannot render. +#[test] +fn revolve_on_an_empty_fill_profile_reports_why() { + let doc = vectorcraft_doc::Document::new(400.0, 400.0); + let mut n = Node::path(NodeId(1), PathData::new(vec![]), Appearance::basic(Paint::solid(Color::BLACK), Paint::None, 0.0)); + n.appearance.items[0].effects_mut().push(crate::new_effect(crate::REVOLVE, &json!({"render": {"mode": "rendered", "quality": "low"}})).unwrap()); + assert_eq!(crate::rendered_warning(&doc, &n).as_deref(), Some("Revolve requires a shape with at least two anchors")); +} + /// Baking a rendered object's appearance, as an envelope with Distort Appearance does, keeps its /// image, for Revolve and the other 3D effects. #[test] diff --git a/docs/mcp.md b/docs/mcp.md index 762958f91f..16818b21de 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -7527,10 +7527,12 @@ values), `resolution` (`null` for Document Raster Effects Settings › Resolutio `background` (`"transparent"`, the default, or `"white"`). A quality whose samples would pass 16,777,216 pixels takes fewer, and an image past that limit at one sample a pixel draws the shaded faces. The shaded faces are also drawn for a scene past the renderer's limits on triangles, vertices, lights or work, for a mesh point at or behind -the eye, for Revolve on a group or on a fill or stroke, for solids painted with a gradient, a pattern, graphics, an +the eye, for solids painted with a gradient, a pattern, graphics, an opacity below 100% or a blending mode other than Normal, and for a later geometry effect that reshapes paths but leaves images unchanged. Extrude & Bevel and Inflate check the top fill and the strokes they build solids from; Rotate -checks every fill and stroke, since it draws a plane for each. The status bar and +checks every fill and stroke, since it draws a plane for each. Revolve on a group draws every member's surface in one +image and checks each member's surface fill or stroke; Revolve on a fill or stroke draws that fill's or stroke's +surface as an image under the effects after it. The status bar and the command result's `warning` field report when the shaded faces are drawn instead. A `render` that is not an object, another key, another value, and `render` on Extrude & Bevel (Classic), Revolve (Classic) or Rotate (Classic) are refused before the document changes. In wireframe mode the graphics' art is not checked against the graphics diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 10e96a36c1..c8ea8a917b 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -741,7 +741,7 @@ since 2026-10-01. - 3D and Materials › Object › Bevel › Reset: the button next to Extrude & Bevel's Bevel heading, in the options dialog and the panel, sets Bevel Shape, Width, Height, Repeat, Space, Bevel Inside and Bevel both sides back to their defaults and leaves the other settings as they are, as one undo step in the panel; it is unavailable while every bevel setting is at its default ([three-d.md](three-d.md#extrude--bevel)); `crates/ui-egui/src/dialogs/revolve/tests.rs` and `crates/ui-egui/src/panels/tests_three_d.rs` cover it. Scores and hours unchanged. - 3D and Materials › Quick Actions › Expand as Wireframes (#6354): `effect.expandAsWireframes` replaces each selected 3D object with a group of 0.5 pt black stroked paths, the edges of the faces its effect draws, each edge once and joined end to end, curves kept, in one undo step ([three-d.md](three-d.md#3d-and-materials-panel)); `crates/effects/src/solids/wireframe/tests.rs`, `crates/engine/src/cmd/wireframe/tests.rs` and `crates/ui-egui/src/panels/tests_three_d.rs` cover it. Scores and hours unchanged. - 3D and Materials › Render Settings › Wireframe: `render: {mode: "wireframe"}` on Extrude & Bevel, Revolve, Inflate and Rotate draws the live effect as the edges of its faces, 0.5 pt black strokes with no shadow, in every output and in Expand Appearance ([three-d.md](three-d.md#3d-and-materials-panel)); `crates/effects/src/solids/wireframe/tests.rs` and `crates/ui-egui/src/panels/tests_three_d.rs` cover it. Scores and hours unchanged. -- 3D and Materials › Render Settings › Rendered: `render: {mode: "rendered"}` with `quality`, `resolution` and `background` draws the solid of Extrude & Bevel, Revolve, Inflate and Rotate as one depth-buffered image lit by every light, with shadow maps while Shading and Shadows are both on; solids painted with a gradient, a pattern, graphics, an opacity below 100% or a blending mode other than Normal, a later geometry effect that reshapes paths only, Revolve on a group, fill or stroke, and an image past the renderer's limits draw the shaded faces instead, with a warning ([three-d.md](three-d.md#3d-and-materials-panel)); `crates/effects/src/solids/rendered/tests.rs` and `crates/ui-egui/src/panels/tests_three_d.rs` cover it. Scores and hours unchanged. +- 3D and Materials › Render Settings › Rendered: `render: {mode: "rendered"}` with `quality`, `resolution` and `background` draws the solid of Extrude & Bevel, Revolve, Inflate and Rotate as one depth-buffered image lit by every light (Revolve on a group draws every member's surface in one image, and Revolve on a fill or stroke draws that surface's own image), with shadow maps while Shading and Shadows are both on; solids painted with a gradient, a pattern, graphics, an opacity below 100% or a blending mode other than Normal, a later geometry effect that reshapes paths only, and an image past the renderer's limits draw the shaded faces instead, with a warning ([three-d.md](three-d.md#3d-and-materials-panel)); `crates/effects/src/solids/rendered/tests.rs` and `crates/ui-egui/src/panels/tests_three_d.rs` cover it. Scores and hours unchanged. - 3D and Materials › Materials › Properties: Roughness and Metallic sliders set `material: {roughness, metallic}` on Extrude & Bevel, Revolve, Inflate and Rotate; with Shading on and outside Wireframe mode, any material other than the default (1 and 0) is shaded with craft-pbr's glTF 2.0 metallic-roughness BRDF, its highlight screened over each face; in every mode glTF exports write both factors, and USD exports write roughness and write metallic only when it is not the default 0 ([three-d.md](three-d.md#material-properties)); `crates/three-d/src/material.rs`, `crates/effects/src/solids/tests_material.rs`, `crates/engine/src/cmd/fileio/mesh3d/tests.rs` and `crates/ui-egui/src/panels/tests_three_d.rs` cover it. Scores and hours unchanged. - 3D and Materials › Export 3D Object: the panel's button adds the selected objects that have a 3D effect to Asset Export as 3D assets (`assets.add3D`), one undo step and none when each is an asset already, selects their assets and shows the Asset Export panel ([three-d.md](three-d.md#3d-and-materials-panel)); `panels::three_d::tests::{export_3d_object_adds_the_selected_3d_objects_to_asset_export, export_3d_object_leaves_out_a_3d_object_inside_another}` cover it. Scores and hours unchanged. - 3D effects on clipping groups, blends and symbol instances (#6140, #5725): every 3D type builds from the art the object shows (the art inside the clipping path, the blend's keys and steps, the symbol's art where the instance places it), alone or in a group, on the canvas, in exports, Object › Rasterize and `assets.add3D`; an image is refused with a pointer to Object › Image Trace › Make. `crates/effects/src/solids/tests_sources.rs`, `crates/engine/src/cmd/effectcmd/three_d_source_tests.rs` and `fx::tests::a_symbol_instance_a_blend_and_a_clipping_group_draw_their_solids` cover it. Scores and estimates unchanged. diff --git a/docs/three-d.md b/docs/three-d.md index d45a826edc..2fddfee31e 100644 --- a/docs/three-d.md +++ b/docs/three-d.md @@ -77,8 +77,9 @@ pages describe it. image, the effect draws its shaded faces. The image keeps transparency where no surface is, or is white with `background: white`. The image shows opaque solid colors only: a solid painted with a gradient or a pattern, one with graphics, a paint with an opacity below 100% or in a blending mode other than Normal, and a group member whose opacity mask or blending mode - applies to its solid draw the shaded faces, as do Revolve on a group, Revolve on a fill or stroke, and a later - geometry effect that reshapes paths but leaves images unchanged. The mode + applies to its solid draw the shaded faces, as does a later geometry effect that reshapes paths but leaves images + unchanged. Revolve on a group draws every member's surface in one image, and Revolve on a fill or stroke draws an + image of that fill's or stroke's surface under the effects after it. The mode is saved with the effect. The status bar and the command result's `warning` field report when the shaded faces are drawn instead. The lighting follows the same lights as the shaded faces but in linear light, so lit areas differ from the shaded faces' colors. Ambient Light keeps its full range from 0 to 200%;