mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-17 13:08:32 +00:00
3D (Classic): the Black Overprint shading color shades with overprinting black over the fill
Extrude & Bevel (Classic), Revolve (Classic) and Rotate (Classic) take shadingColor blackOverprint. Each face keeps its paint unchanged, and a face that darkens gets black over it, as strong as the darkening of the shading color Black: a fill multiplied and overprinting, and a seam stroke overprinting with Darken. The black is on the black plate in Separations Preview and is written to PDF as overprinting fills. The Plastic highlight is not drawn with it. Preserve Spot Colors draws its black with the same helper, so its seam stroke no longer multiplies the black a second time along face edges. The dialogs list the choice, with catalog rows next to Shading Color. Params text, docs/mcp.md, docs/three-d.md and docs/effects-parity.md describe it.
This commit is contained in:
@@ -210,21 +210,21 @@ pub fn effect_catalog() -> Vec<EffectInfo> {
|
||||
CLASSIC_EXTRUDE,
|
||||
"Extrude & Bevel (Classic)…",
|
||||
&["Effect", "3D and Materials", "3D (Classic)"],
|
||||
"{depth: pt (0..2000, 50), cap: bool (true: solid; false: hollow), bevel: none|classic|rounded|cove|step|ogee (none), bevelHeight: pt (1..100, 4; the bevel is as wide as it is tall), bevelInside: bool (false: added around the shape; true: carved into it), 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), surface: wireframe|none|diffuse|plastic (plastic; wireframe draws the edges of every face, hidden ones included, and fills none; none keeps the paint unlit; diffuse lights the faces softly; plastic adds a glossy highlight), lights: null or array of 1..10 objects (intensity: % 0..100, rotation: degrees -180..180, height: degrees 0..90, behind: bool; overrides the single-light fields; the lights add up; color and softness are not used), 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, 100), ambient: % (0..100, 50; Ambient Light, every face whichever way it faces), highlightIntensity: % (0..100, 60; plastic only), highlightSize: % (0..100, 90; 100 broad, 0 a small spot; plastic only), blendSteps: integer (1..256, 25; how many levels the shading and the highlight are rounded to), shadingColor: black|custom|none (black; the color the faces darken toward; none keeps the paint and adds only the highlight), shadingCustom: #rrggbb (#000000; the color shadingColor custom darkens toward), preserveSpotColors: bool (false; a color linked to a spot or global swatch stays a tint of that swatch, lighter where the highlight is, with black multiplied and overprinting where the faces darken, so a spot color keeps its plate; it does nothing while shadingColor is custom), drawHiddenFaces: bool (false; also draws the faces turned away, behind the others)}. The front face is the art, extruded backwards about the center of its bounds; a solid is built for the top fill and for each stroke, each in its own paint. The defaults are VectorCraft's own.",
|
||||
"{depth: pt (0..2000, 50), cap: bool (true: solid; false: hollow), bevel: none|classic|rounded|cove|step|ogee (none), bevelHeight: pt (1..100, 4; the bevel is as wide as it is tall), bevelInside: bool (false: added around the shape; true: carved into it), 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), surface: wireframe|none|diffuse|plastic (plastic; wireframe draws the edges of every face, hidden ones included, and fills none; none keeps the paint unlit; diffuse lights the faces softly; plastic adds a glossy highlight), lights: null or array of 1..10 objects (intensity: % 0..100, rotation: degrees -180..180, height: degrees 0..90, behind: bool; overrides the single-light fields; the lights add up; color and softness are not used), 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, 100), ambient: % (0..100, 50; Ambient Light, every face whichever way it faces), highlightIntensity: % (0..100, 60; plastic only), highlightSize: % (0..100, 90; 100 broad, 0 a small spot; plastic only), blendSteps: integer (1..256, 25; how many levels the shading and the highlight are rounded to), shadingColor: black|custom|none|blackOverprint (black; the color the faces darken toward; none keeps the paint and adds only the highlight; blackOverprint keeps the paint and draws the shading over it as overprinting black, on the black plate, with no highlight), shadingCustom: #rrggbb (#000000; the color shadingColor custom darkens toward), preserveSpotColors: bool (false; a color linked to a spot or global swatch stays a tint of that swatch, lighter where the highlight is, with black multiplied and overprinting where the faces darken, so a spot color keeps its plate; it does nothing while shadingColor is custom), drawHiddenFaces: bool (false; also draws the faces turned away, behind the others)}. The front face is the art, extruded backwards about the center of its bounds; a solid is built for the top fill and for each stroke, each in its own paint. The defaults are VectorCraft's own.",
|
||||
json!({"depth":50.0,"cap":true,"bevel":"none","bevelHeight":4.0,"bevelInside":false,"rotationX":-21.88,"rotationY":-23.4,"rotationZ":9.06,"perspectiveAngle":0.0,"surface":"plastic","lights":null,"lightRotation":125.26438968275465,"lightHeight":30.0,"lightBehind":false,"lightIntensity":100.0,"ambient":50.0,"highlightIntensity":60.0,"highlightSize":90.0,"blendSteps":25,"shadingColor":"black","shadingCustom":"#000000","preserveSpotColors":false,"drawHiddenFaces":false}),
|
||||
),
|
||||
g(
|
||||
CLASSIC_REVOLVE,
|
||||
"Revolve (Classic)…",
|
||||
&["Effect", "3D and Materials", "3D (Classic)"],
|
||||
"{angle: degrees (0..360, 360; how far the profile sweeps round the axis), cap: bool (true: solid, the open ends closed; false: hollow), offset: pt (0..1000, 0; the axis's distance from the profile, a ring past 0), edge: left|right (left; the axis is at the left or the right edge of the profile's bounds), 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), surface: wireframe|none|diffuse|plastic (plastic; wireframe draws the edges of every face and fills none; none keeps the paint unlit; diffuse lights the faces softly; plastic adds a glossy highlight), lights: null or array of 1..10 objects (intensity: % 0..100, rotation: degrees -180..180, height: degrees 0..90, behind: bool; overrides the single-light fields; the lights add up; color and softness are not used), 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, 100), ambient: % (0..100, 50; Ambient Light, every face whichever way it faces), highlightIntensity: % (0..100, 60; plastic only), highlightSize: % (0..100, 90; 100 broad, 0 a small spot; plastic only), blendSteps: integer (1..256, 25; how many levels the shading and the highlight are rounded to), shadingColor: black|custom|none (black; the color the faces darken toward; none keeps the paint and adds only the highlight), shadingCustom: #rrggbb (#000000; the color shadingColor custom darkens toward), preserveSpotColors: bool (false; a color linked to a spot or global swatch stays a tint of that swatch, lighter where the highlight is, with black multiplied and overprinting where the faces darken, so a spot color keeps its plate; it does nothing while shadingColor is custom)}. The profile sweeps round a vertical axis, as Revolve's does, painted with the top fill (else the top stroke); every face is drawn, back to front. The defaults are VectorCraft's own.",
|
||||
"{angle: degrees (0..360, 360; how far the profile sweeps round the axis), cap: bool (true: solid, the open ends closed; false: hollow), offset: pt (0..1000, 0; the axis's distance from the profile, a ring past 0), edge: left|right (left; the axis is at the left or the right edge of the profile's bounds), 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), surface: wireframe|none|diffuse|plastic (plastic; wireframe draws the edges of every face and fills none; none keeps the paint unlit; diffuse lights the faces softly; plastic adds a glossy highlight), lights: null or array of 1..10 objects (intensity: % 0..100, rotation: degrees -180..180, height: degrees 0..90, behind: bool; overrides the single-light fields; the lights add up; color and softness are not used), 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, 100), ambient: % (0..100, 50; Ambient Light, every face whichever way it faces), highlightIntensity: % (0..100, 60; plastic only), highlightSize: % (0..100, 90; 100 broad, 0 a small spot; plastic only), blendSteps: integer (1..256, 25; how many levels the shading and the highlight are rounded to), shadingColor: black|custom|none|blackOverprint (black; the color the faces darken toward; none keeps the paint and adds only the highlight; blackOverprint keeps the paint and draws the shading over it as overprinting black, on the black plate, with no highlight), shadingCustom: #rrggbb (#000000; the color shadingColor custom darkens toward), preserveSpotColors: bool (false; a color linked to a spot or global swatch stays a tint of that swatch, lighter where the highlight is, with black multiplied and overprinting where the faces darken, so a spot color keeps its plate; it does nothing while shadingColor is custom)}. The profile sweeps round a vertical axis, as Revolve's does, painted with the top fill (else the top stroke); every face is drawn, back to front. The defaults are VectorCraft's own.",
|
||||
json!({"angle":360.0,"cap":true,"offset":0.0,"edge":"left","rotationX":-21.88,"rotationY":-23.4,"rotationZ":9.06,"perspectiveAngle":0.0,"surface":"plastic","lights":null,"lightRotation":125.26438968275465,"lightHeight":30.0,"lightBehind":false,"lightIntensity":100.0,"ambient":50.0,"highlightIntensity":60.0,"highlightSize":90.0,"blendSteps":25,"shadingColor":"black","shadingCustom":"#000000","preserveSpotColors":false}),
|
||||
),
|
||||
g(
|
||||
CLASSIC_ROTATE,
|
||||
"Rotate (Classic)…",
|
||||
&["Effect", "3D and Materials", "3D (Classic)"],
|
||||
"{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), surface: none|diffuse (diffuse; none keeps the paint unlit; diffuse lights the art softly), lights: null or array of 1..10 objects (intensity: % 0..100, rotation: degrees -180..180, height: degrees 0..90, behind: bool; overrides the single-light fields; the lights add up; color and softness are not used), 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, 100), ambient: % (0..100, 50; Ambient Light, the art whichever way it faces), blendSteps: integer (1..256, 25; how many levels the shading is rounded to), shadingColor: black|custom|none (black; the color the art darkens toward; none keeps the paint), shadingCustom: #rrggbb (#000000; the color shadingColor custom darkens toward), preserveSpotColors: bool (false; a color linked to a spot or global swatch stays a tint of that swatch, with black multiplied and overprinting where the art darkens, so a spot color keeps its plate; it does nothing while shadingColor is custom)}. Every fill and stroke turns as one flat plane about the center of the object's bounds, as Rotate's do, each in its own paint, and is seen from either side. The defaults are VectorCraft's own.",
|
||||
"{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), surface: none|diffuse (diffuse; none keeps the paint unlit; diffuse lights the art softly), lights: null or array of 1..10 objects (intensity: % 0..100, rotation: degrees -180..180, height: degrees 0..90, behind: bool; overrides the single-light fields; the lights add up; color and softness are not used), 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, 100), ambient: % (0..100, 50; Ambient Light, the art whichever way it faces), blendSteps: integer (1..256, 25; how many levels the shading is rounded to), shadingColor: black|custom|none|blackOverprint (black; the color the art darkens toward; none keeps the paint; blackOverprint keeps the paint and draws the shading over it as overprinting black, on the black plate), shadingCustom: #rrggbb (#000000; the color shadingColor custom darkens toward), preserveSpotColors: bool (false; a color linked to a spot or global swatch stays a tint of that swatch, with black multiplied and overprinting where the art darkens, so a spot color keeps its plate; it does nothing while shadingColor is custom)}. Every fill and stroke turns as one flat plane about the center of the object's bounds, as Rotate's do, each in its own paint, and is seen from either side. The defaults are VectorCraft's own.",
|
||||
json!({"rotationX":-21.88,"rotationY":-23.4,"rotationZ":9.06,"perspectiveAngle":0.0,"surface":"diffuse","lights":null,"lightRotation":125.26438968275465,"lightHeight":30.0,"lightBehind":false,"lightIntensity":100.0,"ambient":50.0,"blendSteps":25,"shadingColor":"black","shadingCustom":"#000000","preserveSpotColors":false}),
|
||||
),
|
||||
g(
|
||||
|
||||
@@ -164,6 +164,41 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// With Black Overprint every face keeps the blue, and the faces that darken get black over it,
|
||||
/// overprinting, as strong as the darkening of the shading color Black.
|
||||
#[test]
|
||||
fn black_overprint_keeps_the_blue_under_overprinting_black() {
|
||||
let darkened = revolved(json!({"surface": "diffuse"}));
|
||||
let art = revolved(json!({"surface": "diffuse", "shadingColor": "blackOverprint"}));
|
||||
let (darkened, drawn) = (faces(&darkened), faces(&art));
|
||||
assert_eq!(darkened.len(), drawn.len());
|
||||
let mut shaded = 0;
|
||||
for (face, black) in drawn.iter().zip(&darkened) {
|
||||
let fills: Vec<&vectorcraft_doc::FillLayer> = face
|
||||
.appearance
|
||||
.items
|
||||
.iter()
|
||||
.filter_map(|i| match i {
|
||||
AppearanceItem::Fill(f) => Some(f),
|
||||
AppearanceItem::Stroke(_) => None,
|
||||
})
|
||||
.collect();
|
||||
assert_eq!((fills[0].paint.color(), fills[0].overprint), (Some(BLUE), false));
|
||||
let k = match fills.get(1) {
|
||||
Some(shadow) => {
|
||||
let Some(Color::Gray { k }) = shadow.paint.color() else { panic!("black shading: {:?}", shadow.paint) };
|
||||
assert_eq!((shadow.blend, shadow.overprint), (vectorcraft_doc::color::BlendMode::Multiply, true));
|
||||
shaded += 1;
|
||||
k
|
||||
}
|
||||
None => 0.0,
|
||||
};
|
||||
let b = fill(black).unwrap().to_rgb()[2];
|
||||
assert!((b - 0.8 * (1.0 - k)).abs() < 1e-3, "black at {k} matches the darkened blue {b}");
|
||||
}
|
||||
assert!(shaded > 0, "faces turned from the light get black");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn angle_offset_edge_and_cap_shape_the_surface() {
|
||||
let full = revolved(json!({"rotationX": 0, "rotationY": 0, "rotationZ": 0})).visual_bounds().unwrap();
|
||||
|
||||
@@ -20,8 +20,8 @@ pub const ROTATE_SURFACES: [&str; 2] = ["none", "diffuse"];
|
||||
/// The width of a Wireframe edge, in points.
|
||||
const WIRE: f64 = 0.5;
|
||||
|
||||
/// The Shading Color choices: black, a custom color, or none.
|
||||
pub const SHADING_COLORS: [&str; 3] = ["black", "custom", "none"];
|
||||
/// The Shading Color choices: black, a custom color, none, or black overprinting the paint.
|
||||
pub const SHADING_COLORS: [&str; 4] = ["black", "custom", "none", "blackOverprint"];
|
||||
|
||||
/// The surface settings of Extrude & Bevel (Classic)'s parameters.
|
||||
pub fn classic_shading(p: &Value) -> ClassicShading {
|
||||
@@ -55,8 +55,8 @@ pub fn classic_extrude_options(p: &Value) -> Extrude {
|
||||
}
|
||||
}
|
||||
|
||||
/// The color faces darken toward: black, the custom color, or none (faces keep their paint and only
|
||||
/// the highlight lightens them).
|
||||
/// The color faces darken toward: black (for Black Overprint too), the custom color, or none (faces
|
||||
/// keep their paint and only the highlight lightens them).
|
||||
fn shading_color(p: &Value) -> Option<Color> {
|
||||
match text(p, "shadingColor", "black") {
|
||||
"none" => None,
|
||||
@@ -200,27 +200,54 @@ fn preserves_spot_colors(p: &Value) -> bool {
|
||||
|
||||
/// A face of `paint`, a color linked to a swatch, with Preserve Spot Colors: the swatch at a lower
|
||||
/// tint for the highlight `spec`, its link kept so a spot color stays on its own plate, and, where
|
||||
/// tone `tone` is below full light and the faces darken (`shade`), black over it at `1 - tone`,
|
||||
/// multiplied and overprinting, so it prints on the black plate. `seam` is the width of the seam
|
||||
/// tone `tone` is below full light and the faces darken (`shade`), black over it as
|
||||
/// [`overprinting_black`] draws it, so it prints on the black plate. `seam` is the width of the seam
|
||||
/// stroke each layer draws around the face.
|
||||
fn linked_face(paint: &Paint, tone: f64, spec: f64, shade: Option<Color>, seam: f64) -> Vec<AppearanceItem> {
|
||||
let Paint::Solid { color, swatch, tint } = paint else { return vec![] };
|
||||
let keep = (1.0 - spec).clamp(0.0, 1.0) as f32;
|
||||
let fill = Paint::Solid { color: color.tinted(keep), swatch: swatch.clone(), tint: tint * keep };
|
||||
let mut items = vec![AppearanceItem::Fill(FillLayer::new(fill.clone())), AppearanceItem::Stroke(crate::lighting::seam_stroke(fill, seam))];
|
||||
if shade.is_some() && tone < 1.0 {
|
||||
let black = Paint::solid(Color::gray((1.0 - tone).clamp(0.0, 1.0) as f32));
|
||||
let mut layer = FillLayer::new(black.clone());
|
||||
layer.blend = BlendMode::Multiply;
|
||||
layer.overprint = true;
|
||||
let mut edge = crate::lighting::seam_stroke(black, seam);
|
||||
edge.blend = BlendMode::Multiply;
|
||||
edge.overprint = true;
|
||||
items.extend([AppearanceItem::Fill(layer), AppearanceItem::Stroke(edge)]);
|
||||
if shade.is_some() {
|
||||
items.extend(overprinting_black(tone, seam));
|
||||
}
|
||||
items
|
||||
}
|
||||
|
||||
/// The black that shades a face at tone `tone` on the black plate, when the tone is below full
|
||||
/// light: a fill of black at `1 - tone`, multiplied and overprinting, and its seam stroke `seam`
|
||||
/// wide, overprinting with Darken, so where the stroke lies over the face's own black, or over a
|
||||
/// neighbor's, the face is not darkened twice.
|
||||
fn overprinting_black(tone: f64, seam: f64) -> Vec<AppearanceItem> {
|
||||
if tone >= 1.0 {
|
||||
return vec![];
|
||||
}
|
||||
let black = Paint::solid(Color::gray((1.0 - tone).clamp(0.0, 1.0) as f32));
|
||||
let mut layer = FillLayer::new(black.clone());
|
||||
layer.blend = BlendMode::Multiply;
|
||||
layer.overprint = true;
|
||||
let mut edge = crate::lighting::seam_stroke(black, seam);
|
||||
edge.blend = BlendMode::Darken;
|
||||
edge.overprint = true;
|
||||
vec![AppearanceItem::Fill(layer), AppearanceItem::Stroke(edge)]
|
||||
}
|
||||
|
||||
/// Whether the shading color of parameters `p` is Black Overprint.
|
||||
fn black_overprint(p: &Value) -> bool {
|
||||
text(p, "shadingColor", "black") == "blackOverprint"
|
||||
}
|
||||
|
||||
/// A face of `paint` with Black Overprint: the paint unchanged, and where tone `tone` is below full
|
||||
/// light, black over it as [`overprinting_black`] draws it, so the paint's own inks print as they
|
||||
/// are and the shading prints on the black plate. The highlight is not drawn. `seam` is the width of
|
||||
/// the seam stroke each layer draws around the face.
|
||||
fn overprinted_face(paint: &Paint, tone: f64, seam: f64) -> Vec<AppearanceItem> {
|
||||
let mut items =
|
||||
vec![AppearanceItem::Fill(FillLayer::new(paint.clone())), AppearanceItem::Stroke(crate::lighting::seam_stroke(paint.clone(), seam))];
|
||||
items.extend(overprinting_black(tone, seam));
|
||||
items
|
||||
}
|
||||
|
||||
/// The width of the stroke [`surface`] draws around `face` with parameters `p`: a wire edge on
|
||||
/// Wireframe, else the seam between faces.
|
||||
pub(crate) fn stroke_width(face: &Facet, p: &Value) -> f64 {
|
||||
@@ -229,14 +256,16 @@ pub(crate) fn stroke_width(face: &Facet, p: &Value) -> f64 {
|
||||
|
||||
/// One solid's faces in paint `paint`, as a group with the paint's opacity and blend mode, one child
|
||||
/// for each facet: the edges of the faces on Wireframe, else each face filled in its paint shaded by
|
||||
/// its tone and highlight (with Preserve Spot Colors, a color linked to a swatch as [`linked_face`]
|
||||
/// draws it). A gradient with transparent stops is shaded opaque and then masked by
|
||||
/// its own transparency, so the shading follows the gradient's coverage.
|
||||
/// its tone and highlight (with Black Overprint, as [`overprinted_face`] draws it; with Preserve Spot
|
||||
/// Colors, a color linked to a swatch as [`linked_face`] draws it). A gradient with transparent stops
|
||||
/// is shaded opaque and then masked by its own transparency, so the shading follows the gradient's
|
||||
/// coverage.
|
||||
pub(crate) fn surface(n: &Node, facets: Vec<Facet>, source: &Paint, opacity: f32, blend: BlendMode, p: &Value) -> Node {
|
||||
let shading = classic_shading(p);
|
||||
let lights = lights(p);
|
||||
let shade = shading_color(p);
|
||||
let preserve = preserves_spot_colors(p);
|
||||
let overprint = black_overprint(p);
|
||||
let wire = shading.surface == ClassicSurface::Wireframe;
|
||||
let (paint, mask) = if wire { (source.clone(), None) } else { crate::lighting::opaque_paint(source) };
|
||||
let paint = &paint;
|
||||
@@ -251,6 +280,10 @@ pub(crate) fn surface(n: &Node, facets: Vec<Facet>, source: &Paint, opacity: f32
|
||||
let (tone, spec) = shading.tone(face.normal, &lights);
|
||||
// A narrow stroke of the face's own paint closes the hairline seams between faces.
|
||||
let seam = super::seam_width(&face);
|
||||
if overprint {
|
||||
let items = overprinted_face(paint, tone, seam);
|
||||
return Arc::new(Node::path(n.id, face.path(), Appearance { items, ..Default::default() }));
|
||||
}
|
||||
let items = match paint.color() {
|
||||
// Unshaded (No Shading, no shading color, or a face in full light) with no
|
||||
// highlight: the paint itself, its color space and swatch kept.
|
||||
|
||||
@@ -1902,6 +1902,89 @@ fn classic_shading_color_blend_steps_and_lights() {
|
||||
assert_eq!(with(json!({"drawHiddenFaces": true})).len(), 6);
|
||||
}
|
||||
|
||||
/// The fills, then the strokes, of face `face`.
|
||||
fn layers_of(face: &Node) -> (Vec<&vectorcraft_doc::FillLayer>, Vec<&StrokeLayer>) {
|
||||
let fills = face.appearance.items.iter().filter_map(|i| if let AppearanceItem::Fill(f) = i { Some(f) } else { None }).collect();
|
||||
let strokes = face.appearance.items.iter().filter_map(|i| if let AppearanceItem::Stroke(s) = i { Some(s) } else { None }).collect();
|
||||
(fills, strokes)
|
||||
}
|
||||
|
||||
/// The black over face `face` with Black Overprint, checked to be opaque and overprinting in
|
||||
/// both its fill (multiplied) and its seam stroke (Darken, so it does not darken the face twice);
|
||||
/// `None` when the face has none.
|
||||
fn overprinted_black(face: &Node) -> Option<f32> {
|
||||
let (fills, strokes) = layers_of(face);
|
||||
assert_eq!(fills.len(), strokes.len(), "each fill has its seam stroke");
|
||||
let shadow = fills.get(1)?;
|
||||
let Some(Color::Gray { k }) = shadow.paint.color() else { panic!("black shading: {:?}", shadow.paint) };
|
||||
assert_eq!((shadow.blend, shadow.overprint, shadow.opacity), (BlendMode::Multiply, true, 1.0));
|
||||
assert_eq!((strokes[1].paint.clone(), strokes[1].blend, strokes[1].overprint), (shadow.paint.clone(), BlendMode::Darken, true));
|
||||
assert!(!fills[0].overprint && !strokes[0].overprint, "the paint itself knocks out");
|
||||
Some(k)
|
||||
}
|
||||
|
||||
/// Black Overprint keeps the paint on every face and draws the shading over it as black,
|
||||
/// overprinting, as strong as the darkening of the shading color Black; the
|
||||
/// highlight is not drawn, and No Shading adds no black.
|
||||
#[test]
|
||||
fn classic_black_overprint_keeps_the_paint_under_overprinting_black() {
|
||||
let diffuse = json!({"surface": "diffuse", "ambient": 20});
|
||||
let mut over = diffuse.clone();
|
||||
over["shadingColor"] = json!("blackOverprint");
|
||||
let darkened: Vec<[f32; 3]> = classic_faces(diffuse).iter().map(fill_rgb).collect();
|
||||
let faces = classic_faces(over);
|
||||
assert_eq!(faces.len(), darkened.len());
|
||||
let mut shaded = 0;
|
||||
for (face, rgb) in faces.iter().zip(&darkened) {
|
||||
assert_eq!(layers_of(face).0[0].paint, Paint::solid(RED), "the paint is kept");
|
||||
let k = overprinted_black(face).unwrap_or(0.0);
|
||||
assert!((rgb[0] - 0.8 * (1.0 - k)).abs() < 1e-3, "black at {k} matches the darkened {rgb:?}");
|
||||
shaded += usize::from(k > 0.0);
|
||||
}
|
||||
assert!(shaded > 0, "faces turned from the light get black");
|
||||
// Plastic: no white layer for the highlight.
|
||||
let shiny = json!({"shadingColor": "blackOverprint", "highlightIntensity": 100, "highlightSize": 100, "lightHeight": 60});
|
||||
for face in classic_faces(shiny) {
|
||||
let (fills, _) = layers_of(&face);
|
||||
assert_eq!(fills[0].paint, Paint::solid(RED));
|
||||
assert!(fills.len() <= 2 && overprinted_black(&face).is_none_or(|k| k > 0.0), "{fills:?}");
|
||||
}
|
||||
// No Shading: the paint alone.
|
||||
for face in classic_faces(json!({"surface": "none", "shadingColor": "blackOverprint"})) {
|
||||
assert_eq!(overprinted_black(&face), None);
|
||||
assert_eq!(layers_of(&face).0[0].paint, Paint::solid(RED));
|
||||
}
|
||||
}
|
||||
|
||||
/// Black Overprint keeps a gradient fill on every face, with the black over it, and Rotate
|
||||
/// (Classic) draws its plane the same way.
|
||||
#[test]
|
||||
fn classic_black_overprint_keeps_gradients_and_shades_rotate() {
|
||||
use vectorcraft_doc::color::{Gradient, GradientKind, GradientPaint};
|
||||
let gradient = Paint::Gradient(Box::new(GradientPaint::new(Gradient::new(
|
||||
GradientKind::Linear,
|
||||
vec![vectorcraft_doc::color::GradientStop::new(0.0, RED), vectorcraft_doc::color::GradientStop::new(1.0, BLUE)],
|
||||
))));
|
||||
let mut n = classic(json!({"shadingColor": "blackOverprint", "surface": "diffuse"}));
|
||||
if let Some(AppearanceItem::Fill(f)) = n.appearance.items.first_mut() {
|
||||
f.paint = gradient.clone();
|
||||
}
|
||||
let art = solid_art(&n).unwrap();
|
||||
let mut shaded = 0;
|
||||
for face in faces(&art) {
|
||||
assert_eq!(layers_of(face).0[0].paint, gradient);
|
||||
shaded += usize::from(overprinted_black(face).is_some());
|
||||
}
|
||||
assert!(shaded > 0);
|
||||
// Rotate (Classic), turned from the light: red with black over it; facing it: red alone.
|
||||
let turned = classic_rotate(json!({"rotationX": 0, "rotationY": 70, "rotationZ": 0, "lightHeight": 90, "shadingColor": "blackOverprint"}));
|
||||
let face = &turned[0].children().unwrap()[0];
|
||||
assert_eq!(layers_of(face).0[0].paint, Paint::solid(RED));
|
||||
assert!(overprinted_black(face).is_some_and(|k| k > 0.05));
|
||||
let lit = classic_rotate(json!({"rotationX": 0, "rotationY": 0, "rotationZ": 0, "lightHeight": 90, "shadingColor": "blackOverprint"}));
|
||||
assert_eq!(overprinted_black(&lit[0].children().unwrap()[0]), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn classic_bevel_height_extent_and_cap_shape_the_solid() {
|
||||
let bounds = |p: Value| solid_art(&classic(p)).unwrap().visual_bounds().unwrap();
|
||||
@@ -2077,9 +2160,12 @@ fn classic_parameters_are_checked() {
|
||||
let check = |p: Value| validate_solid(&n, CLASSIC_EXTRUDE, &crate::merged_params(CLASSIC_EXTRUDE, &p));
|
||||
assert!(check(json!({})).is_ok());
|
||||
assert!(check(json!({"surface": "wireframe", "shadingColor": "custom", "shadingCustom": "#12aBcd", "blendSteps": 256, "bevel": "ogee"})).is_ok());
|
||||
assert!(check(json!({"shadingColor": "blackOverprint"})).is_ok());
|
||||
for (p, says) in [
|
||||
(json!({"surface": "glossy"}), "`surface` must be one of wireframe, none, diffuse, plastic"),
|
||||
(json!({"shadingColor": "red"}), "`shadingColor` must be one of black, custom, none"),
|
||||
(json!({"shadingColor": "red"}), "`shadingColor` must be one of black, custom, none, blackOverprint"),
|
||||
(json!({"shadingColor": "blackoverprint"}), "`shadingColor` must be one of"),
|
||||
(json!({"shadingColor": true}), "`shadingColor` must be one of"),
|
||||
(json!({"shadingCustom": "blue"}), "`shadingCustom` must be a #rrggbb color"),
|
||||
(json!({"shadingCustom": "#fff"}), "`shadingCustom` must be a #rrggbb color"),
|
||||
(json!({"depth": 2001}), "`depth` must be between 0 and 2000 (got 2001)"),
|
||||
@@ -2156,11 +2242,12 @@ fn classic_rotate_parameters_are_checked() {
|
||||
let check = |p: Value| validate_solid(&n, CLASSIC_ROTATE, &crate::merged_params(CLASSIC_ROTATE, &p));
|
||||
assert!(check(json!({})).is_ok());
|
||||
assert!(check(json!({"surface": "none", "shadingColor": "custom", "shadingCustom": "#12aBcd", "blendSteps": 1})).is_ok());
|
||||
assert!(check(json!({"shadingColor": "blackOverprint"})).is_ok());
|
||||
for (p, says) in [
|
||||
(json!({"surface": "plastic"}), "`surface` must be one of none, diffuse"),
|
||||
(json!({"surface": "wireframe"}), "`surface` must be one of none, diffuse"),
|
||||
(json!({"surface": 2}), "`surface` must be one of"),
|
||||
(json!({"shadingColor": "red"}), "`shadingColor` must be one of black, custom, none"),
|
||||
(json!({"shadingColor": "red"}), "`shadingColor` must be one of black, custom, none, blackOverprint"),
|
||||
(json!({"shadingCustom": "#fff"}), "`shadingCustom` must be a #rrggbb color"),
|
||||
(json!({"rotationX": 181}), "`rotationX` must be between -180 and 180 (got 181)"),
|
||||
(json!({"perspectiveAngle": 161}), "`perspectiveAngle` must be between 0 and 160 (got 161)"),
|
||||
|
||||
@@ -276,3 +276,61 @@ fn overprint_black_covers_type_gradients_spots_and_groups() {
|
||||
s.execute("edit.colors.overprintBlack", &json!({"includeCmyBlacks": true, "includeSpotBlacks": true})).unwrap();
|
||||
assert!(fill(&s, g) && fill(&s, spot));
|
||||
}
|
||||
|
||||
/// The plate `plate` of `doc`, drawn as Separations Preview draws one plate, as one gray value per
|
||||
/// pixel (0 full ink, 255 none).
|
||||
fn plate(doc: &Document, plate: &str) -> Vec<u8> {
|
||||
let mut r = Renderer::new();
|
||||
r.threads = 0;
|
||||
let seps = vectorcraft_render::proof::ProofSetup { separations: Some(vec![plate.into()]), ..Default::default() };
|
||||
let opts = RenderOptions { background: Some([255, 255, 255, 255]), proof: Some(seps), ..Default::default() };
|
||||
let image = r.render(doc, 100, 100, Affine::IDENTITY, &opts);
|
||||
(0..100 * 100).map(|i| image.pixel(i % 100, i / 100)[0]).collect()
|
||||
}
|
||||
|
||||
/// 3D (Classic) with the shading color Black Overprint puts the shading on the black plate, shows
|
||||
/// it as the cyan darkened, and writes it to PDF as overprinting fills.
|
||||
#[test]
|
||||
fn classic_3d_black_overprint_shades_on_the_black_plate() {
|
||||
let doc = |params: Value| {
|
||||
let mut s = session();
|
||||
rect(&mut s, [30.0, 30.0, 40.0, 40.0], cyan_ink(), None, 0.0);
|
||||
s.execute("effect.apply", &json!({"effect": "threeD.classicExtrude", "item": null, "params": params})).unwrap();
|
||||
s
|
||||
};
|
||||
let over = doc(json!({"surface": "diffuse", "depth": 20, "shadingColor": "blackOverprint"}));
|
||||
let flat = doc(json!({"surface": "none", "depth": 20, "shadingColor": "blackOverprint"}));
|
||||
let black = doc(json!({"surface": "diffuse", "depth": 20}));
|
||||
let (over_doc, flat_doc) = (&over.doc().unwrap().doc, &flat.doc().unwrap().doc);
|
||||
let inked = |p: &[u8]| p.iter().filter(|v| **v < 250).count();
|
||||
assert!(inked(&plate(over_doc, "Cyan")) > 1000, "the solid is drawn");
|
||||
assert!(inked(&plate(over_doc, "Black")) > 100, "the shading is on the black plate");
|
||||
assert_eq!(inked(&plate(flat_doc, "Black")), 0, "No Shading adds no black");
|
||||
// On screen a shaded face is the cyan darkened, not gray: the black multiplies the cyan.
|
||||
let image = |d: &Document| {
|
||||
let mut r = Renderer::new();
|
||||
r.threads = 0;
|
||||
let opts = RenderOptions { background: Some([255, 255, 255, 255]), ..Default::default() };
|
||||
r.render(d, 100, 100, Affine::IDENTITY, &opts)
|
||||
};
|
||||
let (shaded, unshaded) = (image(over_doc), image(flat_doc));
|
||||
let mut darker = 0;
|
||||
for (x, y) in (0..100u32).flat_map(|y| (0..100u32).map(move |x| (x, y))) {
|
||||
let (s, u) = (shaded.pixel(x, y), unshaded.pixel(x, y));
|
||||
// Inside the solid (no white mixed in at an antialiased edge) where the shading darkens it.
|
||||
if u[0] < 30 && (s[1] as i32) + 20 < u[1] as i32 {
|
||||
darker += 1;
|
||||
assert!(s[2] as i32 > s[0] as i32 + 20, "a shaded face keeps its cyan at ({x}, {y}): {s:?}");
|
||||
}
|
||||
}
|
||||
assert!(darker > 100, "the faces turned from the light are darker");
|
||||
|
||||
let pdf_overprints = |s: &mut Session| {
|
||||
let v = s.execute("document.exportPdf", &json!({"compression": {"compressText": false}, "preserveEditing": false})).unwrap();
|
||||
let bytes = vectorcraft_format::base64_decode(v["dataBase64"].as_str().unwrap()).unwrap();
|
||||
String::from_utf8_lossy(&bytes).matches("/OP true/op true/OPM 1").count()
|
||||
};
|
||||
let (mut over, mut black) = (over, black);
|
||||
assert!(pdf_overprints(&mut over) > 0, "the black is written overprinting");
|
||||
assert_eq!(pdf_overprints(&mut black), 0);
|
||||
}
|
||||
|
||||
@@ -542,7 +542,7 @@ pub(super) fn own_choices(effect: &str, key: &str, cmyk: bool) -> Option<Vec<(&'
|
||||
}
|
||||
(vectorcraft_effects::CLASSIC_ROTATE, "surface") => vec![(tl!("No Shading"), "none"), (tl!("Diffuse"), "diffuse")],
|
||||
(vectorcraft_effects::CLASSIC_EXTRUDE | vectorcraft_effects::CLASSIC_REVOLVE | vectorcraft_effects::CLASSIC_ROTATE, "shadingColor") => {
|
||||
vec![(tl!("Black"), "black"), (tl!("Custom"), "custom"), (tl!("None"), "none")]
|
||||
vec![(tl!("Black"), "black"), (tl!("Custom"), "custom"), (tl!("None"), "none"), (tl!("Black Overprint"), "blackOverprint")]
|
||||
}
|
||||
(vectorcraft_effects::EXTRUDE | vectorcraft_effects::CLASSIC_EXTRUDE, "bevel") => vec, #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, Render Settings › Wireframe, which draws the live effect as the edges of its faces, 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 |
|
||||
| 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)); Preserve Spot Colors in all three, unavailable with a Custom Shading Color ([Preserve Spot Color](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=260)); Map Art: none |
|
||||
| 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, Black Overprint or no Shading Color ([Black Overprint](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=188)), 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)); Preserve Spot Colors in all three, unavailable with a Custom Shading Color ([Preserve Spot Color](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=260)); 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)) |
|
||||
|
||||
|
||||
+12
-4
@@ -4359,16 +4359,24 @@ is tall), `bevelInside` (false adds the bevel around the shape, true carves it i
|
||||
`softness` are not used). `ambient` (0..100%, default 50) lights every face.
|
||||
- `highlightIntensity` (0..100%, default 60) and `highlightSize` (0..100%, default 90; 100 is broad) shape the Plastic
|
||||
highlight. `blendSteps` (whole number, 1..256, default 25) is how many levels the shading is rounded to.
|
||||
- `shadingColor`: `black` (the default), `custom` (darkens toward `shadingCustom`, a `#rrggbb` color) or `none` (the
|
||||
paint is kept and only the highlight lightens it). `drawHiddenFaces` also draws the faces turned away from the
|
||||
viewer, behind the others.
|
||||
- `shadingColor`: `black` (the default), `custom` (darkens toward `shadingCustom`, a `#rrggbb` color), `none` (the
|
||||
paint is kept and only the highlight lightens it) or `blackOverprint`. With `blackOverprint` every face keeps the
|
||||
paint unchanged, and each face that darkens gets overprinting black over it, as strong as `black` would darken it.
|
||||
The paint's own inks print as they are and the shading prints on the black plate. On screen the black is multiplied
|
||||
over the paint, Separations Preview shows it on the Black plate, and `document.exportPdf` writes it as overprinting
|
||||
fills
|
||||
([Shading Color options](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=188)).
|
||||
The highlight is not drawn with `blackOverprint`; that rule is VectorCraft's own. On a pattern face the black covers
|
||||
the whole face, transparent pattern cells included, as the shading of the other shading colors does.
|
||||
`drawHiddenFaces` also draws the faces turned away from the viewer, behind the others.
|
||||
- `preserveSpotColors` (default false) is the Lighting tab's Preserve Spot Colors checkbox. When it is on, a fill or
|
||||
stroke linked to a spot or global swatch stays linked on every face, so a spot color prints on its own plate in
|
||||
separations and PDF. The highlight lowers the swatch's tint, and a face that darkens gets black at the shade's
|
||||
strength over the swatch, multiplied and overprinting. These rules for drawing the shading are VectorCraft's own. The
|
||||
option does nothing while `shadingColor` is `custom`, since a custom shading color cannot keep a spot color
|
||||
([Preserve Spot Color](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=260)).
|
||||
Unlinked colors, gradients, patterns and the Wireframe surface draw as they do with it off.
|
||||
Unlinked colors, gradients, patterns and the Wireframe surface draw as they do with it off. With `blackOverprint`
|
||||
every face keeps its paint, swatch link included, whether the option is on or off.
|
||||
|
||||
The defaults are VectorCraft's own. An unknown parameter, a number out of range, a flag that is not true or false, or
|
||||
an unknown surface or shading color is refused with an error and the document is not changed.
|
||||
|
||||
+4
-2
@@ -553,8 +553,10 @@ out, perspective). No Adobe software, assets, presets or bevel shapes were used.
|
||||
face that darkens gets black over it, multiplied and overprinting, so a spot color stays on its own plate. The
|
||||
checkbox is unavailable while Shading Color is Custom
|
||||
([Preserve Spot Color](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=260)); how
|
||||
the faces are shaded with it is VectorCraft's own. The track cube, map art, Turntable and 3D export are separate,
|
||||
unbuilt items.
|
||||
the faces are shaded with it is VectorCraft's own. The Black Overprint shading color keeps each face's paint and
|
||||
draws the shading over it as overprinting black, without the highlight. The shading is on the black plate in
|
||||
Separations Preview and PDF output. The track cube, map art, Turntable and 3D export are
|
||||
separate, unbuilt items.
|
||||
|
||||
Release measurements and a repeatable CLI scene are in [3D lighting performance](3d-lighting-performance.md).
|
||||
|
||||
|
||||
Reference in New Issue
Block a user