From 76cbd16361022674b13844a454862666f61e4efe Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 4 Dec 2026 11:31:35 -0800 Subject: [PATCH] 3D: Rotate in rendered mode checks every fill it draws Rotate draws a plane for every fill and stroke, but rendered mode only checked the top fill and the strokes before drawing the image. A gradient fill below a solid top fill was drawn as a flat color in the rendered image instead of falling back to shaded faces with the warning. Extrude & Bevel and Inflate still check only the top fill and strokes they build solids from. --- crates/effects/src/catalog.rs | 2 +- crates/effects/src/solids.rs | 8 ++++++- crates/effects/src/solids/rendered/tests.rs | 24 ++++++++++++++++++++- docs/mcp.md | 3 ++- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/crates/effects/src/catalog.rs b/crates/effects/src/catalog.rs index b6131adb53..7a6663b603 100644 --- a/crates/effects/src/catalog.rs +++ b/crates/effects/src/catalog.rs @@ -262,7 +262,7 @@ pub fn effect_catalog() -> Vec { ROTATE, "Rotate…", &["Effect", "3D and Materials"], - "{rotationX: degrees (-180..180, -21.88), rotationY: degrees (-180..180, -23.4), rotationZ: degrees (-180..180, 9.06; the defaults are the Off-Axis Front position), perspectiveAngle: degrees (0..160, 0; 0 is none, wider brings the eye nearer), perspective: % (0..100; the earlier form, read as the perspectiveAngle that shows the same view), shade: bool (true), lightColor: #rrggbb (white, #ffffff; legacy directional light color), lights: null or array of 1..10 objects (color: #rrggbb, intensity: % 0..100, rotation: degrees -180..180, height: degrees 0..90, softness: % 0..100, behind: bool; overrides the single-light fields; ambient is shared), lightRotation: degrees (-180..180, 125.26; round the object on the page, 0 on its right, counterclockwise), lightHeight: degrees (0..90, 30; 0 beside the object, 90 straight in front), lightBehind: bool (false; true lights it from behind), lightIntensity: % (0..100, 80), lightSoftness: % (0..100, 0; how far round the object the light reaches, and how much it blurs the shadow), ambient: % (0..200, 25; Ambient Light), lightAzimuth: degrees (the earlier form: with lightElevation, read as the lightRotation, lightHeight and lightBehind of the same light), lightElevation: degrees (the earlier form, with lightAzimuth), shadow: bool (false; in the shaded faces the first light casts a shadow, black at 50% times the art's opacity, hard-edged at the first light's softness 0 and blurred above it; with render mode rendered, every light with an intensity above 0 casts shadows in the image), shadowPosition: behind|below (behind; behind: on a plane square to the view, below: on the floor under the object, turned with it), shadowDistance: % (0..100, 0; how far the plane is from the object, as a share of its largest size), shadowBounds: % (10..400, 100; how far the plane reaches: at 100 it is four times the object's largest size across), graphics: array of 0..64 objects ([]; the 3D and Materials panel's Graphics on the plane, as Extrude & Bevel's, with face front only), material: object ({roughness: 1, metallic: 0}; as Revolve's), render: object ({mode: shaded}; mode: shaded|wireframe|rendered, quality, resolution and background, as Revolve's)}. Turns the flat art in 3D about the centre of its bounds; every fill and stroke keeps its paint, shaded as one plane.", + "{rotationX: degrees (-180..180, -21.88), rotationY: degrees (-180..180, -23.4), rotationZ: degrees (-180..180, 9.06; the defaults are the Off-Axis Front position), perspectiveAngle: degrees (0..160, 0; 0 is none, wider brings the eye nearer), perspective: % (0..100; the earlier form, read as the perspectiveAngle that shows the same view), shade: bool (true), lightColor: #rrggbb (white, #ffffff; legacy directional light color), lights: null or array of 1..10 objects (color: #rrggbb, intensity: % 0..100, rotation: degrees -180..180, height: degrees 0..90, softness: % 0..100, behind: bool; overrides the single-light fields; ambient is shared), lightRotation: degrees (-180..180, 125.26; round the object on the page, 0 on its right, counterclockwise), lightHeight: degrees (0..90, 30; 0 beside the object, 90 straight in front), lightBehind: bool (false; true lights it from behind), lightIntensity: % (0..100, 80), lightSoftness: % (0..100, 0; how far round the object the light reaches, and how much it blurs the shadow), ambient: % (0..200, 25; Ambient Light), lightAzimuth: degrees (the earlier form: with lightElevation, read as the lightRotation, lightHeight and lightBehind of the same light), lightElevation: degrees (the earlier form, with lightAzimuth), shadow: bool (false; in the shaded faces the first light casts a shadow, black at 50% times the art's opacity, hard-edged at the first light's softness 0 and blurred above it; with render mode rendered, every light with an intensity above 0 casts shadows in the image), shadowPosition: behind|below (behind; behind: on a plane square to the view, below: on the floor under the object, turned with it), shadowDistance: % (0..100, 0; how far the plane is from the object, as a share of its largest size), shadowBounds: % (10..400, 100; how far the plane reaches: at 100 it is four times the object's largest size across), graphics: array of 0..64 objects ([]; the 3D and Materials panel's Graphics on the plane, as Extrude & Bevel's, with face front only), material: object ({roughness: 1, metallic: 0}; as Revolve's), render: object ({mode: shaded}; mode: shaded|wireframe|rendered, quality, resolution and background, as Revolve's; rendered mode checks the paint of every fill and stroke)}. Turns the flat art in 3D about the centre of its bounds; every fill and stroke keeps its paint, shaded as one plane.", json!({"rotationX":-21.88,"rotationY":-23.4,"rotationZ":9.06,"perspectiveAngle":0.0,"shade":true,"lightColor":"#ffffff","lights":null,"lightRotation":125.26438968275465,"lightHeight":30.0,"lightBehind":false,"lightIntensity":80.0,"lightSoftness":0.0,"ambient":25.0,"shadow":false,"shadowPosition":"behind","shadowDistance":0.0,"shadowBounds":100.0,"graphics":[],"material":{"roughness":1.0,"metallic":0.0},"render":{"mode":"shaded"}}), ), g( diff --git a/crates/effects/src/solids.rs b/crates/effects/src/solids.rs index 883366a97f..6a9ddfbbff 100644 --- a/crates/effects/src/solids.rs +++ b/crates/effects/src/solids.rs @@ -1013,6 +1013,12 @@ fn solid_items(shape: &Profile) -> impl Iterator { shape.items.iter().enumerate().filter(move |(k, i)| Some(*k) == top_fill || matches!(i, AppearanceItem::Stroke(_))).map(|(_, i)| i) } +/// The fills and strokes 3D effect `id` draws for `shapes`: every one for Rotate, which draws a +/// plane for each ([`meshes_for`]), and [`solid_items`] for the other effects. +fn drawn_items<'a>(id: &str, shapes: &'a [Profile]) -> Box + 'a> { + if is_plane(id) { Box::new(shapes.iter().flat_map(|s| s.items.iter())) } else { Box::new(shapes.iter().flat_map(solid_items)) } +} + /// The parts Extrude & Bevel and Inflate build solids from: each shape's top fill and its strokes, /// a group's members from the back up, each with its shape's opacity, the region it paints and its /// shape's scopes. The solids share the bounds of all their parts (`fallback` when none has any): @@ -2086,7 +2092,7 @@ fn art_for( { let image = if rendered::reshapes_paths_only(later) { Err(rendered::PATHS_ONLY.into()) - } else if mapped_graphics(&p).is_empty() && rendered::takes(shapes.iter().flat_map(solid_items), has_masks(shapes)) { + } else if mapped_graphics(&p).is_empty() && rendered::takes(drawn_items(&fx.id, shapes), has_masks(shapes)) { meshes_for(fx, shapes, &mut 0, MAX_MESH_TRIANGLES).and_then(|meshes| { let lighting = rendered::lighting(&fx.id, &p); let lighting = match cast_shadow_with(&fx.id, &p, shapes, rendered::plane_settings(&p, &lighting))? { diff --git a/crates/effects/src/solids/rendered/tests.rs b/crates/effects/src/solids/rendered/tests.rs index 275a747edc..403991b6ca 100644 --- a/crates/effects/src/solids/rendered/tests.rs +++ b/crates/effects/src/solids/rendered/tests.rs @@ -70,7 +70,7 @@ const FOUR: [&str; 4] = [super::super::EXTRUDE, crate::REVOLVE, super::super::IN fn rendered_eligibility_ignores_fills_below_the_top_fill() { use vectorcraft_doc::color::{Gradient, GradientKind, GradientPaint, GradientStop}; let doc = vectorcraft_doc::Document::new(400.0, 400.0); - for id in [super::super::EXTRUDE, super::super::INFLATE, super::super::ROTATE] { + for id in [super::super::EXTRUDE, super::super::INFLATE] { let mut n = solid_square(id, Color::BLACK, json!({"render": {"mode": "rendered", "quality": "low"}})); let stops = vec![GradientStop::new(0.0, Color::BLACK), GradientStop::new(1.0, Color::WHITE)]; let lower = vectorcraft_doc::AppearanceItem::Fill(vectorcraft_doc::FillLayer::new(Paint::Gradient(Box::new(GradientPaint::new( @@ -85,6 +85,28 @@ fn rendered_eligibility_ignores_fills_below_the_top_fill() { } } +/// Rotate draws a plane for every fill and stroke, so a gradient fill below the top fill keeps it +/// from rendering, as a gradient top fill does. +#[test] +fn rotate_rendered_eligibility_checks_every_fill() { + use vectorcraft_doc::color::{Gradient, GradientKind, GradientPaint, GradientStop}; + let doc = vectorcraft_doc::Document::new(400.0, 400.0); + let n = solid_square(super::super::ROTATE, Color::BLACK, json!({"render": {"mode": "rendered", "quality": "low"}})); + assert_eq!(crate::rendered_warning(&doc, &n), None); + assert_eq!(images(&drawn(&n)).len(), 1); + let stops = vec![GradientStop::new(0.0, Color::BLACK), GradientStop::new(1.0, Color::WHITE)]; + let lower = vectorcraft_doc::AppearanceItem::Fill(vectorcraft_doc::FillLayer::new(Paint::Gradient(Box::new(GradientPaint::new(Gradient::new( + GradientKind::Linear, + stops, + )))))); + for at in [0, 1] { + let mut n = n.clone(); + n.appearance.items.insert(at, lower.clone()); + assert_eq!(crate::rendered_warning(&doc, &n).as_deref(), Some(OPAQUE_ONLY), "gradient fill at {at}"); + assert!(images(&drawn(&n)).is_empty(), "gradient fill at {at}"); + } +} + #[test] fn later_pathfinder_uses_shaded_faces_and_reports_the_fallback() { let doc = vectorcraft_doc::Document::new(400.0, 400.0); diff --git a/docs/mcp.md b/docs/mcp.md index ee2d767223..a1180a2980 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -7351,7 +7351,8 @@ takes fewer, and an image past that limit at one sample a pixel draws the shaded 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 opacity below 100% or a blending mode other than Normal, and for a later geometry effect that reshapes paths but -leaves images unchanged. The status bar and +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 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