From de0dc9e3b0babd84589642798794050fc855bc70 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 14 Nov 2026 22:03:37 -0800 Subject: [PATCH 1/3] 3D and Materials: the shadow is blurred by the first light's Softness The first light's Softness now softens the shadow of Revolve, Extrude & Bevel, Inflate and Rotate. At 0% the shadow stays the hard-edged path. Above it the path carries a Gaussian Blur of radius Softness x the object's largest size x (5% + 20% x Distance from Object), at most 1,000 pt, VectorCraft's own mapping. The blur draws, counts in the bounds and exports as a Gaussian Blur effect does, a fill's or stroke's own 3D effect keeps it below its later effects, and Expand Appearance turns a blurred shadow into an image. --- crates/effects/src/catalog.rs | 8 ++-- crates/effects/src/revolve.rs | 3 +- crates/effects/src/solids.rs | 6 ++- crates/effects/src/solids/shadow.rs | 25 +++++++---- crates/effects/src/solids/tests_shadow.rs | 54 +++++++++++++++++++++++ crates/engine/src/cmd/effectcmd.rs | 24 ++++++++++ crates/engine/src/cmd/effectcmd/tests.rs | 43 ++++++++++++++++++ crates/three-d/src/shadow.rs | 40 ++++++++++++++--- crates/three-d/src/shadow/tests.rs | 31 +++++++++++++ docs/effects-parity.md | 2 +- docs/mcp.md | 7 ++- docs/target-app-parity.md | 1 + docs/three-d.md | 19 +++++--- 13 files changed, 234 insertions(+), 29 deletions(-) diff --git a/crates/effects/src/catalog.rs b/crates/effects/src/catalog.rs index 1c1ca96d9f..42d7d2c283 100644 --- a/crates/effects/src/catalog.rs +++ b/crates/effects/src/catalog.rs @@ -182,28 +182,28 @@ pub fn effect_catalog() -> Vec { REVOLVE, "Revolve…", &["Effect", "3D and Materials"], - "{angle: degrees (0..360, 360), offset: pt (0..100000, 0), edge: left|right, rotationX: degrees (0), rotationY: degrees (0), rotationZ: degrees (0), 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), segments: integer (8..128, 64), 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), 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; the first light casts a hard-edged shadow, black at 50% times the art's opacity), 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), cap: bool (true, close circular ends of open profiles; partial-sweep cut sides stay open), expandVisibleOnly: bool (true, trim covered opaque solid surfaces only on Expand Appearance; surfaces with graphics keep every face), graphics: array of 0..64 objects ([]; the 3D and Materials panel's Graphics on the swept side, see threeD.mapGraphic: symbol: name of a document symbol, face: front (the side), x: pt (0; the offset of the graphic's center from the middle of the side, around the axis: the angle times the profile's distance from the axis at that point), y: pt (0; along the profile, toward its lower end), scale: % (1..10000, 100), rotation: degrees (-360..360, 0; counterclockwise); wrapped around the side at its own size, so it reaches farther around where the profile comes nearer the axis, shaded with it and drawn only where the side's outside faces the viewer; a full turn cuts it at the back; nothing on the caps)}. Shaded surfaces use smooth vector gradients automatically; intersecting profiles use approximate painter visibility.", + "{angle: degrees (0..360, 360), offset: pt (0..100000, 0), edge: left|right, rotationX: degrees (0), rotationY: degrees (0), rotationZ: degrees (0), 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), segments: integer (8..128, 64), 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; 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), 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), cap: bool (true, close circular ends of open profiles; partial-sweep cut sides stay open), expandVisibleOnly: bool (true, trim covered opaque solid surfaces only on Expand Appearance; surfaces with graphics keep every face), graphics: array of 0..64 objects ([]; the 3D and Materials panel's Graphics on the swept side, see threeD.mapGraphic: symbol: name of a document symbol, face: front (the side), x: pt (0; the offset of the graphic's center from the middle of the side, around the axis: the angle times the profile's distance from the axis at that point), y: pt (0; along the profile, toward its lower end), scale: % (1..10000, 100), rotation: degrees (-360..360, 0; counterclockwise); wrapped around the side at its own size, so it reaches farther around where the profile comes nearer the axis, shaded with it and drawn only where the side's outside faces the viewer; a full turn cuts it at the back; nothing on the caps)}. Shaded surfaces use smooth vector gradients automatically; intersecting profiles use approximate painter visibility.", json!({"angle":360.0,"offset":0.0,"edge":"left","rotationX":0.0,"rotationY":0.0,"rotationZ":0.0,"perspectiveAngle":0.0,"segments":64,"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,"cap":true,"expandVisibleOnly":true,"graphics":[]}), ), g( EXTRUDE, "Extrude & Bevel…", &["Effect", "3D and Materials"], - "{depth: pt (0..2000, 50), twist: degrees (0..360, 0; the back turned against the front), taper: % (1..100, 100; the back's size), cap: bool (true: solid; false: hollow), bevel: none|classic|rounded|cove|step|ogee (none), bevelWidth: pt (0..1000, 4), bevelHeight: pt (0..1000, 4), bevelRepeat: integer (1..32, 1), bevelSpace: % (0..90, 0; flat between repeats), bevelInside: bool (false: added around the shape; true: carved into it), bevelBothSides: bool (false), 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), 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; the first light casts a hard-edged shadow, black at 50% times the art's opacity), 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 caps, see threeD.mapGraphic: symbol: name of a document symbol, face: front|back (front; the back reads left to right as seen from behind), x: pt (0; the offset of the graphic's center from the center of the object's bounds, in the face's own plane), y: pt (0), scale: % (1..10000, 100; of the symbol's own size), rotation: degrees (-360..360, 0; counterclockwise); drawn turned, foreshortened and shaded with the cap and clipped to it, on a solid cap only)}. The front face is the art, extruded backwards about the centre of its bounds; painted with the top fill (else the top stroke).", + "{depth: pt (0..2000, 50), twist: degrees (0..360, 0; the back turned against the front), taper: % (1..100, 100; the back's size), cap: bool (true: solid; false: hollow), bevel: none|classic|rounded|cove|step|ogee (none), bevelWidth: pt (0..1000, 4), bevelHeight: pt (0..1000, 4), bevelRepeat: integer (1..32, 1), bevelSpace: % (0..90, 0; flat between repeats), bevelInside: bool (false: added around the shape; true: carved into it), bevelBothSides: bool (false), 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; 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), 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 caps, see threeD.mapGraphic: symbol: name of a document symbol, face: front|back (front; the back reads left to right as seen from behind), x: pt (0; the offset of the graphic's center from the center of the object's bounds, in the face's own plane), y: pt (0), scale: % (1..10000, 100; of the symbol's own size), rotation: degrees (-360..360, 0; counterclockwise); drawn turned, foreshortened and shaded with the cap and clipped to it, on a solid cap only)}. The front face is the art, extruded backwards about the centre of its bounds; painted with the top fill (else the top stroke).", json!({"depth":50.0,"twist":0.0,"taper":100.0,"cap":true,"bevel":"none","bevelWidth":4.0,"bevelHeight":4.0,"bevelRepeat":1,"bevelSpace":0.0,"bevelInside":false,"bevelBothSides":false,"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":[]}), ), g( INFLATE, "Inflate…", &["Effect", "3D and Materials"], - "{depth: pt (0..2000, 0; flat depth between front and back), twist: degrees (0..360, 0; the back turned against the front), taper: % (1..100, 100; the back's size), cap: bool (true: solid; false: no back, a shell open behind), volume: % (0..100, 50; 50 rounds the edge like a half sphere), bothSides: bool (false: flat back), 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), 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; the first light casts a hard-edged shadow, black at 50% times the art's opacity), 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)}. Painted with the top fill (else the top stroke).", + "{depth: pt (0..2000, 0; flat depth between front and back), twist: degrees (0..360, 0; the back turned against the front), taper: % (1..100, 100; the back's size), cap: bool (true: solid; false: no back, a shell open behind), volume: % (0..100, 50; 50 rounds the edge like a half sphere), bothSides: bool (false: flat back), 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; 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), 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)}. Painted with the top fill (else the top stroke).", json!({"depth":0.0,"twist":0.0,"taper":100.0,"cap":true,"volume":50.0,"bothSides":false,"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}), ), g( 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), 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; the first light casts a hard-edged shadow, black at 50% times the art's opacity), 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)}. 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; 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), 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)}. 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":[]}), ), g( diff --git a/crates/effects/src/revolve.rs b/crates/effects/src/revolve.rs index a9c9482d1d..ea891c0ca4 100644 --- a/crates/effects/src/revolve.rs +++ b/crates/effects/src/revolve.rs @@ -855,7 +855,8 @@ fn art(doc: Option<&Document>, n: &Node, expand: bool) -> Option { if let Some(b) = p.bounds() && let Some(mut shadow) = shadow_of(n.id, fx, &p, item, b, fx_options(fx), kept).ok()? { - shadow.appearance.effects = art.appearance.effects.clone(); + // The shadow keeps its own blur (the light's Softness) below the later effects. + shadow.appearance.effects.extend(art.appearance.effects.iter().cloned()); shadows.push(Arc::new(shadow)); } children.push(Arc::new(art)); diff --git a/crates/effects/src/solids.rs b/crates/effects/src/solids.rs index c0d44947d7..d8948d5322 100644 --- a/crates/effects/src/solids.rs +++ b/crates/effects/src/solids.rs @@ -2123,7 +2123,11 @@ pub fn solid_art_in(doc: Option<&Document>, n: &Node) -> Option { Arc::make_mut(&mut art).appearance.effects = later.clone(); art }; - shadows.extend(shadow.into_iter().map(with_later)); + // A shadow keeps its own blur (the light's Softness) below the later effects. + shadows.extend(shadow.into_iter().map(|mut art| { + Arc::make_mut(&mut art).appearance.effects.extend(later.iter().cloned()); + art + })); children.extend(surfaces.into_iter().map(with_later)); } else { let flat = Appearance { items: vec![item.clone()], ..Default::default() }; diff --git a/crates/effects/src/solids/shadow.rs b/crates/effects/src/solids/shadow.rs index 3906ac2d3c..57fa323a11 100644 --- a/crates/effects/src/solids/shadow.rs +++ b/crates/effects/src/solids/shadow.rs @@ -1,12 +1,12 @@ //! The shadow of the 3D and Materials effects (Extrude & Bevel, Inflate, Rotate and Revolve): the //! `shadow` switch with `shadowPosition`, `shadowDistance` and `shadowBounds`, and the shape it -//! draws behind the solids. +//! draws behind the solids, blurred by the first light's Softness. use std::ops::Range; use std::sync::Arc; -use serde_json::Value; +use serde_json::{Value, json}; use vectorcraft_doc::color::{BlendMode, Color, Paint}; -use vectorcraft_doc::{Appearance, AppearanceItem, FillLayer, Node, NodeId}; +use vectorcraft_doc::{Appearance, AppearanceItem, Effect, FillLayer, Node, NodeId}; use vectorcraft_three_d::{Shadow, ShadowCaster, ShadowPlane, ShadowPosition}; use super::Scope; @@ -15,15 +15,21 @@ use crate::util::{flag, num, text}; /// The shadow's paint: black at this opacity. VectorCraft's own values. const SHADOW_OPACITY: f32 = 0.5; +/// Blur radii below this, in points, leave the shadow hard-edged. +const MIN_BLUR: f64 = 0.01; + /// The shadow `p` asks for, or `None` with the switch off or when the first light lights nothing -/// (Shading is off or its intensity is 0), so that no shadow is built. +/// (Shading is off or its intensity is 0), so that no shadow is built. Its softness is the first +/// light's. pub(crate) fn options(p: &Value) -> Option { - let intensity = crate::lighting::lights(p).and_then(|l| l.iter().next().map(|l| l.intensity)).unwrap_or_else(|| num(p, "lightIntensity", 80.0)); + let first = crate::lighting::lights(p).and_then(|l| l.iter().next().copied()); + let intensity = first.map_or_else(|| num(p, "lightIntensity", 80.0), |l| l.intensity); let lit = flag(p, "shade", true) && intensity > 0.0; (lit && flag(p, "shadow", false)).then(|| Shadow { position: ShadowPosition::parse(text(p, "shadowPosition", "behind")).unwrap_or_default(), distance: num(p, "shadowDistance", 0.0) / 100.0, bounds: num(p, "shadowBounds", 100.0) / 100.0, + softness: first.map_or_else(|| num(p, "lightSoftness", 0.0) / 100.0, |l| l.softness), }) } @@ -51,8 +57,9 @@ pub(crate) struct Ink { } /// The shadow of the faces in `caster` as a path of object `id`, cast by art in `ink`: filled -/// black at [`SHADOW_OPACITY`] times its opacity, in its blending mode, with the nonzero rule; -/// `None` when it casts nothing. +/// black at [`SHADOW_OPACITY`] times its opacity, in its blending mode, with the nonzero rule, and +/// with the light's Softness a Gaussian Blur of the plane's radius ([`ShadowPlane::blur`]), which +/// is drawn, measured, exported and expanded as that effect is; `None` when it casts nothing. pub(crate) fn art(id: NodeId, caster: &ShadowCaster, shadow: Shadow, ink: Ink) -> Option { let all = 0..caster.len(); let all = std::slice::from_ref(&all); @@ -65,7 +72,9 @@ fn piece(id: NodeId, caster: &ShadowCaster, plane: &ShadowPlane, faces: &[Range< let mut fill = FillLayer::new(Paint::solid(Color::BLACK)); fill.opacity = SHADOW_OPACITY * ink.opacity.clamp(0.0, 1.0); fill.blend = ink.blend; - Some(Node::path(id, path, Appearance { items: vec![AppearanceItem::Fill(fill)], ..Default::default() })) + let blur = plane.blur(); + let effects = if blur >= MIN_BLUR { vec![Effect { id: "blur.gaussian".into(), params: json!({"radius": blur}), visible: true }] } else { vec![] }; + Some(Node::path(id, path, Appearance { items: vec![AppearanceItem::Fill(fill)], effects, ..Default::default() })) } /// Whether `a` and `b` are the same objects' scopes (each member holds its own copies). diff --git a/crates/effects/src/solids/tests_shadow.rs b/crates/effects/src/solids/tests_shadow.rs index 4d62961612..9f8a597014 100644 --- a/crates/effects/src/solids/tests_shadow.rs +++ b/crates/effects/src/solids/tests_shadow.rs @@ -87,6 +87,40 @@ fn the_shadow_moves_with_its_settings() { } } +/// The radius of the Gaussian Blur on shadow `n`; `None` without one. +fn shadow_blur(n: &Node) -> Option { + match n.appearance.effects.as_slice() { + [] => None, + [e] if e.id == "blur.gaussian" && e.visible => e.params["radius"].as_f64(), + other => panic!("unexpected effects on the shadow: {other:?}"), + } +} + +/// The first light's Softness blurs the shadow, more with Softness and with Distance from Object; +/// at 0 % it stays the hard-edged path. A list of lights takes the first light's Softness. +#[test] +fn the_first_lights_softness_blurs_the_shadow() { + for id in CASTING { + let blur = |params: Value| { + let mut n = square_node(1, 0.0); + n.appearance.effects.push(crate::new_effect(id, ¶ms).unwrap()); + let lit = art(&n, id).unwrap(); + let shadow = &lit.children().unwrap()[0]; + assert!(is_shadow(shadow), "{id} {params}"); + shadow_blur(shadow) + }; + assert_eq!(blur(json!({"shadow": true})), None, "{id}: hard at 0 %"); + let soft = blur(json!({"shadow": true, "lightSoftness": 50})).unwrap_or_else(|| panic!("{id}")); + let softer = blur(json!({"shadow": true, "lightSoftness": 100})).unwrap(); + let far = blur(json!({"shadow": true, "lightSoftness": 100, "shadowDistance": 100})).unwrap(); + assert!(soft > 0.0 && softer > soft && far > softer, "{id}: {soft} {softer} {far}"); + let first = json!({"shadow": true, "lightSoftness": 0, "lights": [{"softness": 100}, {"softness": 0}]}); + assert_eq!(blur(first), Some(softer), "{id}: the first light's"); + let second = json!({"shadow": true, "lightSoftness": 100, "lights": [{"softness": 0}, {"softness": 100}]}); + assert_eq!(blur(second), None, "{id}: only the first light casts"); + } +} + #[test] fn shadow_settings_out_of_range_or_of_the_wrong_kind_are_refused() { for id in CASTING { @@ -203,6 +237,26 @@ fn the_shadows_of_every_fill_go_behind_every_fill_s_solid() { } } +/// A fill's own 3D effect blurs its shadow by the light's Softness too, and the effects after it +/// in the fill's list follow the blur. +#[test] +fn a_fills_own_3d_effect_keeps_the_blur_below_its_later_effects() { + for id in CASTING { + for later in [None, Some(crate::new_effect("distort.roughen", &json!({})).unwrap())] { + let mut n = square_node(1, 0.0); + let fill = n.appearance.items.iter_mut().find(|i| matches!(i, AppearanceItem::Fill(_))).unwrap(); + fill.effects_mut().push(crate::new_effect(id, &json!({"shadow": true, "lightSoftness": 100})).unwrap()); + fill.effects_mut().extend(later.clone()); + let lit = art(&n, id).unwrap_or_else(|| panic!("{id}")); + let shadow = &lit.children().unwrap()[0]; + assert!(is_shadow(shadow), "{id}"); + let ids: Vec<&str> = shadow.appearance.effects.iter().map(|e| e.id.as_str()).collect(); + let want: Vec<&str> = std::iter::once("blur.gaussian").chain(later.as_ref().map(|e| e.id.as_str())).collect(); + assert_eq!(ids, want, "{id}"); + } + } +} + #[test] fn expand_appearance_keeps_the_shadow_as_a_path() { for id in CASTING { diff --git a/crates/engine/src/cmd/effectcmd.rs b/crates/engine/src/cmd/effectcmd.rs index 118773cfc8..b9726361fa 100644 --- a/crates/engine/src/cmd/effectcmd.rs +++ b/crates/engine/src/cmd/effectcmd.rs @@ -1014,6 +1014,27 @@ fn expand_pieces( expanded } +/// `m`, the art a 3D effect expanded into, with each object in it that has effects of its own (a +/// shadow blurred by the light's Softness) expanded as Expand Appearance expands it on its own: +/// a blurred shadow becomes an image. Groups in `m` without effects that hold such an object are +/// looked into; the rest are left as they are. +fn expand_raster_pieces(d: &mut Document, mut m: Node, brushes: &[vectorcraft_brush::Brush]) -> Node { + for c in m.children_mut().into_iter().flatten() { + if !c.appearance.effects.is_empty() { + if let Some(e) = expanded_node(d, (**c).clone(), brushes, &mut vec![]) { + *c = Arc::new(e); + } + } else if c.children().is_some() { + let mut holds = false; + c.walk(&mut |n| holds |= !n.appearance.effects.is_empty()); + if holds { + *c = Arc::new(expand_raster_pieces(d, (**c).clone(), brushes)); + } + } + } + m +} + /// Replace each symbol instance in `m`, art an instance placed (`depth` instances deep), whose /// active fill or stroke has a geometry effect ([`effects::has_item_geometry`]) by its art as /// [`effects::expand_outlined`] makes it, and the instances in that art in turn, so @@ -1207,6 +1228,9 @@ fn expanded_node(d: &mut Document, mut n: Node, brushes: &[vectorcraft_brush::Br m }) }; + // A 3D effect's shadow blurred by the light's Softness keeps its blur in the art: it + // expands in turn, to an image. + let m = if effects::has_solid(&v) || effects::has_revolve(&v) { m.map(|m| expand_raster_pieces(d, m, brushes)) } else { m }; match image { Some((image, _)) => { let mut m = m.unwrap_or(v); diff --git a/crates/engine/src/cmd/effectcmd/tests.rs b/crates/engine/src/cmd/effectcmd/tests.rs index b3389e190d..0045cfe7fe 100644 --- a/crates/engine/src/cmd/effectcmd/tests.rs +++ b/crates/engine/src/cmd/effectcmd/tests.rs @@ -1017,6 +1017,49 @@ fn a_3d_shadow_is_one_undo_step_saved_exported_and_expanded() { assert_eq!(shadows, 1); } +/// With the light's Softness, the 3D shadow is blurred: the canvas paints past the hard shadow's +/// edge, the object's bounds take the blur in, SVG export blurs it as it does a Gaussian Blur +/// effect, and Expand Appearance keeps it as an image with no live effect left. +#[test] +fn a_soft_3d_shadow_is_drawn_measured_exported_and_expanded_blurred() { + let (mut s, id) = session_with_rect(); + s.execute("effect.apply", &json!({"effect": effects::EXTRUDE, "ids": [id.0], "item": null})).unwrap(); + let set = |s: &mut Session, params: serde_json::Value| { + s.execute("effect.setParams", &json!({"ids": [id.0], "index": 0, "item": null, "params": params})).unwrap(); + }; + let draw = |s: &Session| { + vectorcraft_render::Renderer::new().render(&s.doc().unwrap().doc, 400, 400, vectorcraft_geom::Affine::IDENTITY, &Default::default()).pixels + }; + let bounds = |s: &Session| { + let doc = &s.doc().unwrap().doc; + vectorcraft_render::effect_bounds(&doc.symbol_boxes(), doc.node(id).unwrap()).unwrap() + }; + let blurs = |s: &mut Session| { + let svg = s.execute("document.serialize", &json!({"format": "svg"})).unwrap(); + let svg = svg["data"].as_str().or_else(|| svg["text"].as_str()).map(str::to_string).unwrap_or_else(|| svg.to_string()); + svg.matches(" 100, "{spread}"); + assert!(soft_bounds.contains_rect(hard_bounds) && soft_bounds.area() > hard_bounds.area(), "{hard_bounds:?} {soft_bounds:?}"); + assert_eq!(blurs(&mut s), hard_blurs + 1, "SVG export blurs the shadow as a Gaussian Blur effect"); + s.execute("effect.expandAppearance", &json!({"ids": [id.0]})).unwrap(); + let (mut live, mut pictures) = (0, 0); + s.doc().unwrap().doc.walk(|n| { + live += usize::from(!n.appearance.effects.is_empty() || n.appearance.items.iter().any(|i| !i.effects().is_empty())); + pictures += usize::from(matches!(n.kind, NodeKind::Image(_))); + }); + assert_eq!((live, pictures), (0, 1), "the blurred shadow expands to an image"); +} + /// Radial Blur's Blur Center: stored as given, drawn about that point of the object's bounds, and /// a value outside 0 to 1 (or not a number) is refused with nothing changed and no undo step. #[test] diff --git a/crates/three-d/src/shadow.rs b/crates/three-d/src/shadow.rs index b580ddcd5f..b12f7be8c9 100644 --- a/crates/three-d/src/shadow.rs +++ b/crates/three-d/src/shadow.rs @@ -1,6 +1,7 @@ //! The shadow a 3D effect's solid casts: its faces projected along the first light onto a plane //! behind the object (square to the view) or below it (under the object's own vertical axis, turned -//! with it), as one hard-edged vector shape. +//! with it), as one vector shape. The light's Softness gives the shape a blur radius +//! ([`ShadowPlane::blur`]); at 0 the shape stays hard-edged. //! //! Every face is projected whole, so the shape is the union of the projected faces: each contour is //! turned so that its face winds the same way, and the shape is filled with the nonzero rule. The @@ -48,20 +49,36 @@ pub struct Shadow { /// How far the plane reaches, as a share (0.1..4): at 1 the plane is a square four times the /// object's largest size across. pub bounds: f64, + /// The casting light's Softness (0..1): at 0 the shadow is hard-edged, above it blurred + /// ([`ShadowPlane::blur`]). + pub softness: f64, } impl Default for Shadow { fn default() -> Self { - Self { position: ShadowPosition::Behind, distance: 0.0, bounds: 1.0 } + Self { position: ShadowPosition::Behind, distance: 0.0, bounds: 1.0, softness: 0.0 } } } impl Shadow { fn sanitized(self) -> Self { - Self { distance: finite(self.distance, 0.0, 0.0, 1.0), bounds: finite(self.bounds, 1.0, 0.1, 4.0), ..self } + Self { + distance: finite(self.distance, 0.0, 0.0, 1.0), + bounds: finite(self.bounds, 1.0, 0.1, 4.0), + softness: finite(self.softness, 0.0, 0.0, 1.0), + ..self + } } } +/// The blur radius at full Softness on a plane that touches the object, as a share of the object's +/// largest size, and what each share of Distance from Object adds to it. VectorCraft's own values. +const BLUR_NEAR: f64 = 0.05; +const BLUR_PER_DISTANCE: f64 = 0.2; + +/// Most blur radius a shadow takes, in points (the Gaussian Blur effect's own limit). +pub const MAX_SHADOW_BLUR: f64 = 1000.0; + /// The rotation and projection a solid is drawn with. #[derive(Clone, Copy, Debug, PartialEq)] pub(crate) struct Projection { @@ -119,6 +136,17 @@ pub struct ShadowPlane { foot: V3, /// Half the side of the square the plane ends at. half: f64, + /// The blur radius of the shadow on the plane, in points ([`ShadowPlane::blur`]). + blur: f64, +} + +impl ShadowPlane { + /// The radius, in points, of the blur that softens the edges of the shadow on this plane: 0 at + /// Softness 0, and with Softness a share of the object's largest size that grows with the + /// plane's distance from the object (VectorCraft's own mapping), at most [`MAX_SHADOW_BLUR`]. + pub fn blur(&self) -> f64 { + self.blur + } } /// The faces of one object's solids, gathered to cast one shadow. The solids of one object share @@ -254,13 +282,15 @@ impl ShadowCaster { let level = corners().map(|v| n.dot(*v)).fold(f64::INFINITY, f64::min) - s.distance * size; let centre = V3((lo.0 + hi.0) / 2.0, (lo.1 + hi.1) / 2.0, (lo.2 + hi.2) / 2.0); let foot = add(centre, scale(n, level - n.dot(centre))); - Some(ShadowPlane { projection: p, light, reach, n, u, w, level, foot, half: 2.0 * s.bounds * size }) + let blur = (s.softness * size * (BLUR_NEAR + BLUR_PER_DISTANCE * s.distance)).min(MAX_SHADOW_BLUR); + let blur = if blur.is_finite() { blur } else { 0.0 }; + Some(ShadowPlane { projection: p, light, reach, n, u, w, level, foot, half: 2.0 * s.bounds * size, blur }) } /// The shadow the faces in the ranges `faces` cast on `plane`, on the page, filled with the /// nonzero rule; `None` when nothing of it falls within the plane. pub fn path_on(&self, plane: &ShadowPlane, faces: &[Range]) -> Option { - let &ShadowPlane { projection: p, light, reach, n, u, w, level, foot, half } = plane; + let &ShadowPlane { projection: p, light, reach, n, u, w, level, foot, half, .. } = plane; // A corner's shadow, in the plane's axes about the foot. let cast = |v: V3| { let q = add(v, scale(light, -(n.dot(v) - level) / reach)); diff --git a/crates/three-d/src/shadow/tests.rs b/crates/three-d/src/shadow/tests.rs index 1e3f5c437b..2d80c2ea61 100644 --- a/crates/three-d/src/shadow/tests.rs +++ b/crates/three-d/src/shadow/tests.rs @@ -127,10 +127,41 @@ fn bad_settings_are_sanitized_and_an_empty_caster_casts_nothing() { let wild = Shadow { distance: f64::NAN, bounds: f64::INFINITY, ..Shadow::default() }; assert_eq!(wild.sanitized(), Shadow { bounds: 1.0, ..Shadow::default() }); assert_eq!(Shadow { distance: -3.0, bounds: 99.0, ..Shadow::default() }.sanitized(), Shadow { bounds: 4.0, ..Shadow::default() }); + assert_eq!(Shadow { softness: f64::NAN, ..Shadow::default() }.sanitized(), Shadow::default()); + assert_eq!(Shadow { softness: 7.0, ..Shadow::default() }.sanitized(), Shadow { softness: 1.0, ..Shadow::default() }); assert_eq!(ShadowPosition::parse("below"), Some(ShadowPosition::Below)); assert_eq!(ShadowPosition::parse("under"), None); } +/// Softness blurs the shadow by a radius that grows with Softness and with the plane's distance +/// from the object, and scales with the object; at 0 the shadow keeps its hard edge. The outline +/// itself does not change. +#[test] +fn softness_blurs_the_shadow_more_the_farther_the_plane_is() { + let blur = |s: f64, shadow: Shadow| { + let path = square(100.0, 100.0, s); + let mut caster = ShadowCaster::new(); + caster.extrude(&path, FillRule::NonZero, Rect::new(100.0, 100.0, 100.0 + s, 100.0 + s), Extrude::default(), front()).unwrap(); + let all = 0..caster.len(); + let all = std::slice::from_ref(&all); + let plane = caster.shadow_plane(shadow, all).unwrap(); + (plane.blur(), caster.path_on(&plane, all).unwrap()) + }; + let (hard, hard_path) = blur(100.0, Shadow::default()); + assert_eq!(hard, 0.0); + let (half, half_path) = blur(100.0, Shadow { softness: 0.5, ..Shadow::default() }); + let (full, _) = blur(100.0, Shadow { softness: 1.0, ..Shadow::default() }); + let (far, _) = blur(100.0, Shadow { softness: 1.0, distance: 1.0, ..Shadow::default() }); + assert!(half > 0.0 && full > half && far > full, "{half} {full} {far}"); + assert_eq!(half_path, hard_path, "the outline stays"); + // Twice the object, twice the blur. + let (twice, _) = blur(200.0, Shadow { softness: 1.0, ..Shadow::default() }); + assert!((twice - 2.0 * full).abs() < 1e-9, "{twice} {full}"); + // A huge object's blur stops at the Gaussian Blur effect's limit. + let (huge, _) = blur(1.0e7, Shadow { softness: 1.0, distance: 1.0, ..Shadow::default() }); + assert_eq!(huge, MAX_SHADOW_BLUR); +} + #[test] fn the_faces_one_shadow_is_cast_from_are_bounded() { // An open profile of 500 points revolves into about 64,000 faces at 128 segments: five fit, diff --git a/docs/effects-parity.md b/docs/effects-parity.md index 342a5171b6..e9e5b5696b 100644 --- a/docs/effects-parity.md +++ b/docs/effects-parity.md @@ -180,7 +180,7 @@ VectorCraft choices; an original approximation, never compared with another appl |---|---| | Revolve | initial: live, editable profile, rotation and light gizmos, default-on Cap with continuous curved rims, smooth vector shading and round seam joins, overlapping faces drawn in the order of their depths where they overlap, SVG/PDF output, Expand Appearance ([revolve.md](revolve.md), #846) | | Extrude & Bevel, Inflate, Rotate | initial: live, round seam joins, depth, twist, taper, solid or hollow caps, five original bevel shapes, Inflate volume, both sides, twist, taper and cap, Rotate of every fill and stroke, groups and layers turned about one shared axis (#4506), contours that cross, touch or overlap merged first ([three-d.md](three-d.md)), Position presets, rotation and light gizmos, SVG/PDF output, Expand Appearance ([three-d.md](three-d.md)) | -| Materials panel, lighting, ray-traced render | Window › 3D and Materials panel with the object types (Plane, Extrude, Revolve, Inflate) and the Object, Rotation and Lighting settings of the applied effect, and Quick Actions › Expand as Wireframes ([three-d.md](three-d.md#3d-and-materials-panel)); one to ten directional lights with per-light Color (opaque RGB, white by default), Intensity, Rotation, Height, Softness and neutral Ambient Light, Revolve and colored Inflate use smooth vector shading; Extrude & Bevel and Rotate retain planar shading; original Standard, Diffuse, Top Left and Right lighting rigs; hard-edged shadows behind or below the object from the first light ([three-d.md](three-d.md#shadows)); the Materials tab's Graphics, document symbols mapped onto Extrude & Bevel's caps and onto a plane, moved with an artboard handle, and wrapped around Revolve's side ([three-d.md](three-d.md#graphics)); no base materials, graphics on Inflate or on Extrude & Bevel's walls and bevels, soft shadows or ray tracing | +| Materials panel, lighting, ray-traced render | Window › 3D and Materials panel with the object types (Plane, Extrude, Revolve, Inflate) and the Object, Rotation and Lighting settings of the applied effect, and Quick Actions › Expand as Wireframes ([three-d.md](three-d.md#3d-and-materials-panel)); one to ten directional lights with per-light Color (opaque RGB, white by default), Intensity, Rotation, Height, Softness and neutral Ambient Light, Revolve and colored Inflate use smooth vector shading; Extrude & Bevel and Rotate retain planar shading; original Standard, Diffuse, Top Left and Right lighting rigs; shadows behind or below the object from the first light, blurred by its Softness ([three-d.md](three-d.md#shadows)); the Materials tab's Graphics, document symbols mapped onto Extrude & Bevel's caps and onto a plane, moved with an artboard handle, and wrapped around Revolve's side ([three-d.md](three-d.md#graphics)); no base materials, graphics on Inflate or on Extrude & Bevel's walls and bevels, or ray tracing | | 3D (Classic): Extrude & Bevel, Revolve, Rotate | Extrude & Bevel (Classic) initial: live, round seam joins, Extrude Depth, Cap, five original bevel shapes with Height and Bevel Extent In or Out, Position presets and rotation gizmo, Perspective, Wireframe, No Shading, Diffuse and Plastic surfaces with one to ten lights, Light Intensity, Ambient Light, Highlight Intensity and Size, Blend Steps, Black, Custom or no Shading Color, Draw Hidden Faces ([create 3D objects](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/create-3d-graphics/create-3d-objects.html)); Revolve (Classic) initial: live, round seam joins, Angle, Cap, Offset from the left or right edge, Position presets and rotation gizmo, Perspective, the same four surfaces, lights, highlight, Blend Steps and Shading Color, groups and layers revolved about one shared axis (same page); Rotate (Classic) initial: live, round seam joins, every fill and stroke turned as one plane, Position presets and rotation gizmo, Perspective, No Shading and Diffuse surfaces with lights, Ambient Light, Blend Steps and Shading Color ([rotate objects in 3D](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/create-3d-graphics/rotate-objects-in-3d.html)); Map Art: none | | Turntable (30.0 beta) | none | | Export 3D objects (OBJ, USDA, glTF) | initial: Asset Export's Export 3D Object collects an object with Extrude & Bevel, Revolve, Inflate or Rotate as a 3D asset, and Export writes its solids as a USDA (the default), USDZ, glTF or OBJ mesh with a material in each solid's paint color (`assets.add3D`, `assets.set3DFormat`, `assets.export3D`); no textures, map art or shading ([3D export help](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/create-3d-graphics/export-3d-vector-artwork.html)) | diff --git a/docs/mcp.md b/docs/mcp.md index 8ca4121032..cb8294d8ff 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -4066,8 +4066,11 @@ The document stores their numeric settings; manual edits remain possible through Revolve, Extrude & Bevel, Inflate and Rotate take `shadow` (boolean, default false), `shadowPosition` (`"behind"` or `"below"`, default `"behind"`), `shadowDistance` (0..100%, default 0) and `shadowBounds` (10..400%, default 100), set with `effect.apply` or `effect.setParams` in one undo step. With `shadow` on, the first light casts a -hard-edged shadow of the solid, drawn behind the solid as one path filled black at 50% opacity times the opacity -of the art that casts it, in that art's blending mode. `"behind"` puts it +shadow of the solid, drawn behind the solid as one path filled black at 50% opacity times the opacity +of the art that casts it, in that art's blending mode. At the first light's `softness` (or `lightSoftness`) 0 the +path is hard-edged; above 0 it carries a Gaussian Blur of radius softness × the object's largest size × (5% + 20% × +`shadowDistance`), at most 1,000 pt (VectorCraft's own mapping), drawn, measured, exported and expanded (to an +image) as that effect is. `"behind"` puts it on a plane square to the view behind the object; `"below"` puts it on the floor under the object, square to the object's own vertical axis and turned with it, so with no X rotation the floor is seen edge-on and draws nothing. `shadowDistance` moves the plane away from the object by that share of the object's largest size. `shadowBounds` diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index f4424700be..8456ef461f 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -588,6 +588,7 @@ since 2026-10-01. - 3D lighting presets: `crates/effects/src/lighting_presets.rs`, `crates/engine/src/cmd/effectcmd/lighting_presets_tests.rs` and the pointer tests in `crates/ui-egui/src/dialogs/revolve/tests.rs` cover recognition, atomic targeting, native round trips, preview, Cancel, reset and Undo. - 3D shadows: Revolve, Extrude & Bevel, Inflate and Rotate take a Shadows switch with Position (Behind Object or Below Object), Distance from Object (0–100 %) and Shadow Bounds (10–400 %) on the Lighting tab ([three-d.md](three-d.md#shadows)); the first light casts one hard-edged vector shadow, drawn behind the solids, in exports and kept by Expand Appearance. Evidence: `crates/three-d/src/shadow/tests.rs`, `crates/effects/src/solids/tests_shadow.rs`, `effectcmd::tests::a_3d_shadow_is_one_undo_step_saved_exported_and_expanded`. Softness and the shadows of lights after the first are not built. Scores unchanged. - 3D shadows: with Shadows on, Revolve, Extrude & Bevel, Inflate and Rotate cast the shadow from the faces kept by the build that draws each solid, so drawing an object builds each of its solids once. The art and the shadow are unchanged. Evidence: `crates/three-d/src/shadow/tests.rs` (`a_solid_and_its_shadow_are_built_once` and the tests that compare each solid and its shadow with the two built apart), `solids::tests_shadow::a_shadowed_3d_object_builds_each_solid_once`, `solids::tests_shadow::the_shadow_cast_from_the_solids_drawn_is_the_shadow_of_solids_built_for_it`, `revolve::tests::the_shadow_cast_from_the_surfaces_drawn_is_the_shadow_of_surfaces_swept_for_it`. Scores unchanged. +- 3D shadows: the first light's Softness blurs the shadow of Revolve, Extrude & Bevel, Inflate and Rotate with a Gaussian Blur whose radius grows with Softness and Distance from Object and scales with the object (VectorCraft's own mapping; at 0 % the shadow stays hard-edged), on the canvas, in the art's bounds and in exports, and Expand Appearance keeps it as an image ([three-d.md](three-d.md#shadows)). Evidence: `shadow::tests::softness_blurs_the_shadow_more_the_farther_the_plane_is` (three-d), `solids::tests_shadow::the_first_lights_softness_blurs_the_shadow`, `solids::tests_shadow::a_fills_own_3d_effect_keeps_the_blur_below_its_later_effects`, `effectcmd::tests::a_soft_3d_shadow_is_drawn_measured_exported_and_expanded_blurred`. Scores unchanged. - Window › 3D and Materials panel: `crates/ui-egui/src/panels/three_d.rs` applies a 3D effect by object type (Plane, Extrude, Revolve, Inflate), changes an applied one in place (`effect.setParams` `threeDType`) and edits it with the options dialog's Object, Rotation and Lighting controls, one undo step per change; `crates/engine/src/cmd/effectcmd/three_d_type_tests.rs` and `crates/ui-egui/src/panels/tests_three_d.rs` cover it. No Materials tab. - 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 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 f12ca4675c..38b7e8f0b1 100644 --- a/docs/three-d.md +++ b/docs/three-d.md @@ -334,7 +334,7 @@ Inflate and Rotate has a **Shadows** switch with those three settings below it. | Option | | |---|---| -| Shadows | Off by default. On, the first light casts a hard-edged shadow of the solid, drawn behind it. | +| Shadows | Off by default. On, the first light casts a shadow of the solid, drawn behind it: hard-edged at the light's Softness 0 %, blurred above it. | | Position | **Behind Object** (the default): on a plane square to the view, behind the object. **Below Object**: on the floor under the object, square to its own vertical axis and turned with it. | | Distance from Object | 0–100 %, default 0 %: how far the plane is from the object, as a share of the object's largest size. | | Shadow Bounds | 10–400 %, default 100 %: how far the plane reaches. At 100 % it is a square four times the object's largest size across, about the foot of the object's center; the shadow is cut at its edges. | @@ -351,12 +351,17 @@ Our reading: Intensity is 0 %, or when it does not reach the plane: a light behind the object casts none behind it, and a light from under the floor casts none below it. A fill, stroke or group member at 0 % opacity casts none. With no X rotation the floor is seen edge-on, so a shadow below draws nothing until the object is tilted (the default Off-Axis Front position shows it). -- Softness is not applied to the shadow, and only the first light casts one. +- The first light's Softness blurs the shadow with a Gaussian Blur: at 0 % it stays the hard-edged path, and above + it the blur radius is Softness × the object's largest size × (5 % + 20 % × Distance from Object), at most + 1,000 pt. At 100 % Softness a 100 pt object casts a shadow blurred by 5 pt on a plane that touches it and by + 25 pt at 100 % Distance. This mapping is our own. The blur scales with the object, and it draws, takes room and + exports as a Gaussian Blur effect does. Only the first light casts a + shadow. - A shadow is cast from at most 327,680 faces, the solids of one object together (our own limit). Past it, a command is refused with "The 3D shadow is too complex; turn Shadows off or simplify the art", and a loaded file draws the source path. -- Canvas, SVG and PDF exports draw the shadow, the art's bounds take it in, and Expand Appearance keeps it as a - path below the faces. Extrude & Bevel (Classic), Revolve (Classic) and Rotate (Classic) have no shadow. +- Canvas, SVG and PDF exports draw the shadow, the art's bounds take it in (with its blur), and Expand Appearance + keeps it below the faces: a hard shadow as a path, a blurred one as an image. Extrude & Bevel (Classic), Revolve (Classic) and Rotate (Classic) have no shadow. ## Graphics @@ -459,10 +464,10 @@ and [Create 3D objects](https://helpx.adobe.com/illustrator/desktop/special-effe pages, and the archived Extrude & Bevel option list (depth 0–2,000, cap on/off, bevel height, bevel extent in or out, perspective). No Adobe software, assets, presets or bevel shapes were used. -- **Materials** (base and Adobe Substance), graphics on Inflate and on Extrude & Bevel's walls and bevels, soft - shadows, shadows of lights after the first, and **ray-traced rendering** are not built: shading uses directional +- **Materials** (base and Adobe Substance), graphics on Inflate and on Extrude & Bevel's walls and bevels, + shadows of lights after the first, and **ray-traced rendering** are not built: shading uses directional lights, in the paint of the fill or stroke the solid is built for ([Fills and strokes](#fills-and-strokes)), and - the shadow is hard-edged ([Shadows](#shadows)). Graphics map onto planar faces and Revolve's side only + only the first light casts a shadow ([Shadows](#shadows)). Graphics map onto planar faces and Revolve's side only ([Graphics](#graphics)). - The bevel shapes and their names are our own; custom bevel paths are not supported. - Visibility is a painter's algorithm: faces of a closed solid turned away are left out, and the rest are drawn From 38bc30128ae1c31b5f338e04031c647a7f07cd2e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 06:55:53 -0800 Subject: [PATCH 2/3] Docs: the 3D shadow entry no longer lists Softness as not built The earlier 3D shadows entry in docs/target-app-parity.md said Softness was not built. The first light's Softness now blurs the shadow, as the next entry describes, so only the shadows of lights after the first remain unbuilt. --- docs/target-app-parity.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 91749e12b6..13cb824cbd 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -590,7 +590,7 @@ since 2026-10-01. - 3D lighting presets: `crates/effects/src/lighting_presets.rs`, `crates/engine/src/cmd/effectcmd/lighting_presets_tests.rs` and the pointer tests in `crates/ui-egui/src/dialogs/revolve/tests.rs` cover recognition, atomic targeting, native round trips, preview, Cancel, reset and Undo. - 3D lighting widget: the Lighting tab of the 3D and Materials panel shows every light on a sphere at its Rotation and Height; a drag moves a light in one undo step, a press selects it, Move Light to Back and Move Light to Front change its side, and the arrow keys move the focused light ([three-d.md](three-d.md#lighting-widget)). `crates/ui-egui/src/panels/tests_three_d.rs` covers the drag, selection, side and keyboard. -- 3D shadows: Revolve, Extrude & Bevel, Inflate and Rotate take a Shadows switch with Position (Behind Object or Below Object), Distance from Object (0–100 %) and Shadow Bounds (10–400 %) on the Lighting tab ([three-d.md](three-d.md#shadows)); the first light casts one hard-edged vector shadow, drawn behind the solids, in exports and kept by Expand Appearance. Evidence: `crates/three-d/src/shadow/tests.rs`, `crates/effects/src/solids/tests_shadow.rs`, `effectcmd::tests::a_3d_shadow_is_one_undo_step_saved_exported_and_expanded`. Softness and the shadows of lights after the first are not built. Scores unchanged. +- 3D shadows: Revolve, Extrude & Bevel, Inflate and Rotate take a Shadows switch with Position (Behind Object or Below Object), Distance from Object (0–100 %) and Shadow Bounds (10–400 %) on the Lighting tab ([three-d.md](three-d.md#shadows)); the first light casts one hard-edged vector shadow, drawn behind the solids, in exports and kept by Expand Appearance. Evidence: `crates/three-d/src/shadow/tests.rs`, `crates/effects/src/solids/tests_shadow.rs`, `effectcmd::tests::a_3d_shadow_is_one_undo_step_saved_exported_and_expanded`. The shadows of lights after the first are not built; the first light's Softness blurs the shadow (next entry). Scores unchanged. - 3D shadows: with Shadows on, Revolve, Extrude & Bevel, Inflate and Rotate cast the shadow from the faces kept by the build that draws each solid, so drawing an object builds each of its solids once. The art and the shadow are unchanged. Evidence: `crates/three-d/src/shadow/tests.rs` (`a_solid_and_its_shadow_are_built_once` and the tests that compare each solid and its shadow with the two built apart), `solids::tests_shadow::a_shadowed_3d_object_builds_each_solid_once`, `solids::tests_shadow::the_shadow_cast_from_the_solids_drawn_is_the_shadow_of_solids_built_for_it`, `revolve::tests::the_shadow_cast_from_the_surfaces_drawn_is_the_shadow_of_surfaces_swept_for_it`. Scores unchanged. - 3D shadows: the first light's Softness blurs the shadow of Revolve, Extrude & Bevel, Inflate and Rotate with a Gaussian Blur whose radius grows with Softness and Distance from Object and scales with the object (VectorCraft's own mapping; at 0 % the shadow stays hard-edged), on the canvas, in the art's bounds and in exports, and Expand Appearance keeps it as an image ([three-d.md](three-d.md#shadows)). Evidence: `shadow::tests::softness_blurs_the_shadow_more_the_farther_the_plane_is` (three-d), `solids::tests_shadow::the_first_lights_softness_blurs_the_shadow`, `solids::tests_shadow::a_fills_own_3d_effect_keeps_the_blur_below_its_later_effects`, `effectcmd::tests::a_soft_3d_shadow_is_drawn_measured_exported_and_expanded_blurred`. Scores unchanged. - 3D shadows: in Revolve, Extrude & Bevel, Inflate and Rotate, a fill, stroke or member whose opacity is NaN or infinite casts no part of the shadow, as one at 0 % does, whether the shadow is cast from the solids drawn or from solids built for it alone; the art beside it still casts. This is VectorCraft's own rule. Evidence: `solids::tests_shadow::art_whose_opacity_is_not_a_finite_number_casts_no_shadow`, `revolve::tests::a_surface_whose_opacity_is_not_a_finite_number_casts_no_shadow`. Scores unchanged. From a20b45193f931ddf67a8fe9ef7f267f52c00c4ed Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 14:07:05 -0800 Subject: [PATCH 3/3] 3D and Materials: pass the skip list to the blurred shadow's expansion main added a list of objects to leave unexpanded to expanded_node, and the expansion of a 3D effect's blurred shadow did not pass it, so the branch stopped compiling after the merge of main. --- crates/engine/src/cmd/effectcmd.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/engine/src/cmd/effectcmd.rs b/crates/engine/src/cmd/effectcmd.rs index bef2e7ab58..15fa875847 100644 --- a/crates/engine/src/cmd/effectcmd.rs +++ b/crates/engine/src/cmd/effectcmd.rs @@ -1032,18 +1032,18 @@ fn expand_pieces( /// `m`, the art a 3D effect expanded into, with each object in it that has effects of its own (a /// shadow blurred by the light's Softness) expanded as Expand Appearance expands it on its own: /// a blurred shadow becomes an image. Groups in `m` without effects that hold such an object are -/// looked into; the rest are left as they are. -fn expand_raster_pieces(d: &mut Document, mut m: Node, brushes: &[vectorcraft_brush::Brush]) -> Node { +/// looked into; the rest are left as they are. The objects `skip` lists are not expanded. +fn expand_raster_pieces(d: &mut Document, mut m: Node, brushes: &[vectorcraft_brush::Brush], skip: &[NodeId]) -> Node { for c in m.children_mut().into_iter().flatten() { if !c.appearance.effects.is_empty() { - if let Some(e) = expanded_node(d, (**c).clone(), brushes, &mut vec![]) { + if let Some(e) = expanded_node(d, (**c).clone(), brushes, skip, &mut vec![]) { *c = Arc::new(e); } } else if c.children().is_some() { let mut holds = false; c.walk(&mut |n| holds |= !n.appearance.effects.is_empty()); if holds { - *c = Arc::new(expand_raster_pieces(d, (**c).clone(), brushes)); + *c = Arc::new(expand_raster_pieces(d, (**c).clone(), brushes, skip)); } } } @@ -1254,7 +1254,7 @@ fn expanded_node(d: &mut Document, mut n: Node, brushes: &[vectorcraft_brush::Br }; // A 3D effect's shadow blurred by the light's Softness keeps its blur in the art: it // expands in turn, to an image. - let m = if effects::has_solid(&v) || effects::has_revolve(&v) { m.map(|m| expand_raster_pieces(d, m, brushes)) } else { m }; + let m = if effects::has_solid(&v) || effects::has_revolve(&v) { m.map(|m| expand_raster_pieces(d, m, brushes, skip)) } else { m }; match image { Some((image, _)) => { let mut m = m.unwrap_or(v);