From d83fa66454a34bb1f00098ad2f0dd05f1b86cd51 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 5 Dec 2026 16:24:16 -0800 Subject: [PATCH] =?UTF-8?q?3D=20and=20Materials:=20Raster=20Settings=20?= =?UTF-8?q?=E2=80=BA=20Color=20makes=20the=20rendered=20image=20RGB,=20gra?= =?UTF-8?q?yscale=20or=20bitmap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The 3D effects' `render` object takes `colorModel` (`document`, the default, `grayscale` or `bitmap`). Grayscale gives each pixel of the rendered image the Rec. 709 luma of its color, and Bitmap makes it black or white, after the background and with each pixel's transparency kept, as Effect › Rasterize does with the same model ids. Edge pixels are mapped from their straight color before the coverage is rounded. Grayscale and Bitmap images are stored as gray PNGs, and the model is part of the rendered image's cache key. Any other value is refused with an error and leaves the object and the undo history unchanged. The setting is saved with the effect. Render Settings › Raster Settings… gets a Color row (RGB, Grayscale, Bitmap). It opens blank for a selection that holds different models, and OK sets the picked model on every selected object in one undo step. Docs: docs/three-d.md, docs/mcp.md, docs/target-app-parity.md, params text. --- crates/effects/src/catalog.rs | 8 +- crates/effects/src/solids/rendered.rs | 49 +++++++++-- crates/effects/src/solids/rendered/tests.rs | 90 +++++++++++++++++++- crates/effects/src/solids/wireframe.rs | 26 ++++-- crates/effects/src/solids/wireframe/tests.rs | 14 ++- crates/engine/src/tests/effectedit.rs | 61 +++++++++++++ crates/ui-egui/src/panels/tests_three_d.rs | 69 +++++++++++++++ crates/ui-egui/src/panels/three_d.rs | 1 + crates/ui-egui/src/panels/three_d/raster.rs | 59 ++++++++++--- docs/mcp.md | 12 ++- docs/target-app-parity.md | 1 + docs/three-d.md | 13 ++- 12 files changed, 360 insertions(+), 43 deletions(-) diff --git a/crates/effects/src/catalog.rs b/crates/effects/src/catalog.rs index 7a6663b603..387cfca9f4 100644 --- a/crates/effects/src/catalog.rs +++ b/crates/effects/src/catalog.rs @@ -241,28 +241,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, and how much it blurs the shadow), ambient: % (0..200, 25; Ambient Light), lightAzimuth: degrees (the earlier form: with lightElevation, read as the lightRotation, lightHeight and lightBehind of the same light), lightElevation: degrees (the earlier form, with lightAzimuth), shadow: bool (false; in the shaded faces the first light casts a shadow, black at 50% times the art's opacity, hard-edged at the first light's softness 0 and blurred above it; with render mode rendered, every light with an intensity above 0 casts shadows in the image), shadowPosition: behind|below (behind; behind: on a plane square to the view, below: on the floor under the object, turned with it), shadowDistance: % (0..100, 0; how far the plane is from the object, as a share of its largest size), shadowBounds: % (10..400, 100; how far the plane reaches: at 100 it is four times the object's largest size across), cap: bool (true: solid, closing circular ends of open profiles and a partial sweep's cut sides; false: hollow), 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), material: object ({roughness: 1, metallic: 0}; the 3D and Materials panel's Materials › Properties: roughness: 0..1 (1; lower values give a smaller, brighter highlight), metallic: 0..1 (0; higher values tint the reflected light with the paint and darken the diffuse light); a key left out keeps its default, and any other key or value is an error; the default draws as before), render: object ({mode: shaded}; mode: shaded|wireframe|rendered, wireframe draws the edges of the faces the effect draws, each once, stroked 0.5 pt black with round joins, with no fill, shadow or graphics, whatever the opacity of the fills, strokes and group members, while the effect stays live; the stroke is VectorCraft's own; rendered draws the solid as one image with a depth buffer, lit by every light; with shadow on, every light with an intensity above 0 casts shadows on the solid and on the shadow plane in the image, and with it off none does; it draws the shaded faces when the image can't be made or a later geometry effect reshapes paths but leaves images unchanged; quality: low|medium|high (medium; 1, 2 x 2 or 3 x 3 samples a pixel, VectorCraft's own), resolution: null or ppi 1..2400 (null: Document Raster Effects Settings), background: transparent|white (transparent); any other key or value is an error)}. 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; in the shaded faces the first light casts a shadow, black at 50% times the art's opacity, hard-edged at the first light's softness 0 and blurred above it; with render mode rendered, every light with an intensity above 0 casts shadows in the image), shadowPosition: behind|below (behind; behind: on a plane square to the view, below: on the floor under the object, turned with it), shadowDistance: % (0..100, 0; how far the plane is from the object, as a share of its largest size), shadowBounds: % (10..400, 100; how far the plane reaches: at 100 it is four times the object's largest size across), cap: bool (true: solid, closing circular ends of open profiles and a partial sweep's cut sides; false: hollow), 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), material: object ({roughness: 1, metallic: 0}; the 3D and Materials panel's Materials › Properties: roughness: 0..1 (1; lower values give a smaller, brighter highlight), metallic: 0..1 (0; higher values tint the reflected light with the paint and darken the diffuse light); a key left out keeps its default, and any other key or value is an error; the default draws as before), render: object ({mode: shaded}; mode: shaded|wireframe|rendered, wireframe draws the edges of the faces the effect draws, each once, stroked 0.5 pt black with round joins, with no fill, shadow or graphics, whatever the opacity of the fills, strokes and group members, while the effect stays live; the stroke is VectorCraft's own; rendered draws the solid as one image with a depth buffer, lit by every light; with shadow on, every light with an intensity above 0 casts shadows on the solid and on the shadow plane in the image, and with it off none does; it draws the shaded faces when the image can't be made or a later geometry effect reshapes paths but leaves images unchanged; quality: low|medium|high (medium; 1, 2 x 2 or 3 x 3 samples a pixel, VectorCraft's own), resolution: null or ppi 1..2400 (null: Document Raster Effects Settings), background: transparent|white (transparent), colorModel: document|grayscale|bitmap (document: RGB pixels in every document, which a CMYK document's PDF export converts as it converts raster effect images; grayscale: the Rec. 709 luma of each pixel; bitmap: black and white pixels only, as Rasterize makes them; applied after the background); any other key or value is an error)}. 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":[],"material":{"roughness":1.0,"metallic":0.0},"render":{"mode":"shaded"}}), ), 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; or custom, a bevel of the user's own drawn by bevelProfile), 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), bevelName: string (a custom bevel's name), bevelProfile: [[x, y], …] (a custom bevel's 2 to 64 points, shares 0..1 of the width and height from [0, 0] at the cap's edge to [1, 1] at the side wall, joined by straight lines; effect.apply and effect.setParams also take bevel {custom: name}, a bevel of the bevels file (threeD.bevels.list), and store it as bevel custom with its bevelName and bevelProfile), rotationX: degrees (-180..180, -21.88), rotationY: degrees (-180..180, -23.4), rotationZ: degrees (-180..180, 9.06; the defaults are the Off-Axis Front position), perspectiveAngle: degrees (0..160, 0; 0 is none, wider brings the eye nearer), perspective: % (0..100; the earlier form, read as the perspectiveAngle that shows the same view), shade: bool (true), lightColor: #rrggbb (white, #ffffff; legacy directional light color), lights: null or array of 1..10 objects (color: #rrggbb, intensity: % 0..100, rotation: degrees -180..180, height: degrees 0..90, softness: % 0..100, behind: bool; overrides the single-light fields; ambient is shared), lightRotation: degrees (-180..180, 125.26; round the object on the page, 0 on its right, counterclockwise), lightHeight: degrees (0..90, 30; 0 beside the object, 90 straight in front), lightBehind: bool (false; true lights it from behind), lightIntensity: % (0..100, 80), lightSoftness: % (0..100, 0; how far round the object the light reaches, and how much it blurs the shadow), ambient: % (0..200, 25; Ambient Light), lightAzimuth: degrees (the earlier form: with lightElevation, read as the lightRotation, lightHeight and lightBehind of the same light), lightElevation: degrees (the earlier form, with lightAzimuth), shadow: bool (false; in the shaded faces the first light casts a shadow, black at 50% times the art's opacity, hard-edged at the first light's softness 0 and blurred above it; with render mode rendered, every light with an intensity above 0 casts shadows in the image), shadowPosition: behind|below (behind; behind: on a plane square to the view, below: on the floor under the object, turned with it), shadowDistance: % (0..100, 0; how far the plane is from the object, as a share of its largest size), shadowBounds: % (10..400, 100; how far the plane reaches: at 100 it is four times the object's largest size across), graphics: array of 0..64 objects ([]; the 3D and Materials panel's Graphics on the caps and the side, see threeD.mapGraphic: symbol: name of a document symbol, face: front|back|side (front; the back reads left to right as seen from behind; side is the walls and bevels), x: pt (0; the offset of the graphic's center from the center of the object's bounds, in the face's own plane; on the side from the middle of the side unrolled flat, along the outline, clockwise from its top), y: pt (0; on the side from the front toward the back), scale: % (1..10000, 100; of the symbol's own size), rotation: degrees (-360..360, 0; counterclockwise); drawn turned, foreshortened and shaded with the face and clipped to it: on a cap of a solid object only, and on the side of a solid or hollow object wrapped around it and drawn only where its outside faces the viewer), material: object ({roughness: 1, metallic: 0}; as Revolve's), render: object ({mode: shaded}; mode: shaded|wireframe|rendered, quality, resolution and background, as Revolve's)}. 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; or custom, a bevel of the user's own drawn by bevelProfile), 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), bevelName: string (a custom bevel's name), bevelProfile: [[x, y], …] (a custom bevel's 2 to 64 points, shares 0..1 of the width and height from [0, 0] at the cap's edge to [1, 1] at the side wall, joined by straight lines; effect.apply and effect.setParams also take bevel {custom: name}, a bevel of the bevels file (threeD.bevels.list), and store it as bevel custom with its bevelName and bevelProfile), rotationX: degrees (-180..180, -21.88), rotationY: degrees (-180..180, -23.4), rotationZ: degrees (-180..180, 9.06; the defaults are the Off-Axis Front position), perspectiveAngle: degrees (0..160, 0; 0 is none, wider brings the eye nearer), perspective: % (0..100; the earlier form, read as the perspectiveAngle that shows the same view), shade: bool (true), lightColor: #rrggbb (white, #ffffff; legacy directional light color), lights: null or array of 1..10 objects (color: #rrggbb, intensity: % 0..100, rotation: degrees -180..180, height: degrees 0..90, softness: % 0..100, behind: bool; overrides the single-light fields; ambient is shared), lightRotation: degrees (-180..180, 125.26; round the object on the page, 0 on its right, counterclockwise), lightHeight: degrees (0..90, 30; 0 beside the object, 90 straight in front), lightBehind: bool (false; true lights it from behind), lightIntensity: % (0..100, 80), lightSoftness: % (0..100, 0; how far round the object the light reaches, and how much it blurs the shadow), ambient: % (0..200, 25; Ambient Light), lightAzimuth: degrees (the earlier form: with lightElevation, read as the lightRotation, lightHeight and lightBehind of the same light), lightElevation: degrees (the earlier form, with lightAzimuth), shadow: bool (false; in the shaded faces the first light casts a shadow, black at 50% times the art's opacity, hard-edged at the first light's softness 0 and blurred above it; with render mode rendered, every light with an intensity above 0 casts shadows in the image), shadowPosition: behind|below (behind; behind: on a plane square to the view, below: on the floor under the object, turned with it), shadowDistance: % (0..100, 0; how far the plane is from the object, as a share of its largest size), shadowBounds: % (10..400, 100; how far the plane reaches: at 100 it is four times the object's largest size across), graphics: array of 0..64 objects ([]; the 3D and Materials panel's Graphics on the caps and the side, see threeD.mapGraphic: symbol: name of a document symbol, face: front|back|side (front; the back reads left to right as seen from behind; side is the walls and bevels), x: pt (0; the offset of the graphic's center from the center of the object's bounds, in the face's own plane; on the side from the middle of the side unrolled flat, along the outline, clockwise from its top), y: pt (0; on the side from the front toward the back), scale: % (1..10000, 100; of the symbol's own size), rotation: degrees (-360..360, 0; counterclockwise); drawn turned, foreshortened and shaded with the face and clipped to it: on a cap of a solid object only, and on the side of a solid or hollow object wrapped around it and drawn only where its outside faces the viewer), material: object ({roughness: 1, metallic: 0}; as Revolve's), render: object ({mode: shaded}; mode: shaded|wireframe|rendered, quality, resolution, background and colorModel, as Revolve's)}. 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":[],"material":{"roughness":1.0,"metallic":0.0},"render":{"mode":"shaded"}}), ), 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, and how much it blurs the shadow), ambient: % (0..200, 25; Ambient Light), lightAzimuth: degrees (the earlier form: with lightElevation, read as the lightRotation, lightHeight and lightBehind of the same light), lightElevation: degrees (the earlier form, with lightAzimuth), shadow: bool (false; in the shaded faces the first light casts a shadow, black at 50% times the art's opacity, hard-edged at the first light's softness 0 and blurred above it; with render mode rendered, every light with an intensity above 0 casts shadows in the image), shadowPosition: behind|below (behind; behind: on a plane square to the view, below: on the floor under the object, turned with it), shadowDistance: % (0..100, 0; how far the plane is from the object, as a share of its largest size), shadowBounds: % (10..400, 100; how far the plane reaches: at 100 it is four times the object's largest size across), graphics: array of 0..64 objects ([]; the 3D and Materials panel's Graphics on the puffed front and back, see threeD.mapGraphic: symbol: name of a document symbol, face: front|back (front; the back reads left to right as seen from behind and takes graphics with bothSides and cap on), x: pt (0; the offset of the graphic's center from the center of the object's bounds, in the art's plane), y: pt (0), scale: % (1..10000, 100; of the symbol's own size), rotation: degrees (-360..360, 0; counterclockwise); carried straight out from the art's plane onto the puffed face, twist and taper turning and shrinking the back's with it, shaded with the surface and drawn only where its outside faces the viewer), material: object ({roughness: 1, metallic: 0}; as Revolve's), render: object ({mode: shaded}; mode: shaded|wireframe|rendered, quality, resolution and background, as Revolve's)}. 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; in the shaded faces the first light casts a shadow, black at 50% times the art's opacity, hard-edged at the first light's softness 0 and blurred above it; with render mode rendered, every light with an intensity above 0 casts shadows in the image), shadowPosition: behind|below (behind; behind: on a plane square to the view, below: on the floor under the object, turned with it), shadowDistance: % (0..100, 0; how far the plane is from the object, as a share of its largest size), shadowBounds: % (10..400, 100; how far the plane reaches: at 100 it is four times the object's largest size across), graphics: array of 0..64 objects ([]; the 3D and Materials panel's Graphics on the puffed front and back, see threeD.mapGraphic: symbol: name of a document symbol, face: front|back (front; the back reads left to right as seen from behind and takes graphics with bothSides and cap on), x: pt (0; the offset of the graphic's center from the center of the object's bounds, in the art's plane), y: pt (0), scale: % (1..10000, 100; of the symbol's own size), rotation: degrees (-360..360, 0; counterclockwise); carried straight out from the art's plane onto the puffed face, twist and taper turning and shrinking the back's with it, shaded with the surface and drawn only where its outside faces the viewer), material: object ({roughness: 1, metallic: 0}; as Revolve's), render: object ({mode: shaded}; mode: shaded|wireframe|rendered, quality, resolution, background and colorModel, as Revolve's)}. 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,"graphics":[],"material":{"roughness":1.0,"metallic":0.0},"render":{"mode":"shaded"}}), ), 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, and how much it blurs the shadow), ambient: % (0..200, 25; Ambient Light), lightAzimuth: degrees (the earlier form: with lightElevation, read as the lightRotation, lightHeight and lightBehind of the same light), lightElevation: degrees (the earlier form, with lightAzimuth), shadow: bool (false; in the shaded faces the first light casts a shadow, black at 50% times the art's opacity, hard-edged at the first light's softness 0 and blurred above it; with render mode rendered, every light with an intensity above 0 casts shadows in the image), shadowPosition: behind|below (behind; behind: on a plane square to the view, below: on the floor under the object, turned with it), shadowDistance: % (0..100, 0; how far the plane is from the object, as a share of its largest size), shadowBounds: % (10..400, 100; how far the plane reaches: at 100 it is four times the object's largest size across), graphics: array of 0..64 objects ([]; the 3D and Materials panel's Graphics on the plane, as Extrude & Bevel's, with face front only), material: object ({roughness: 1, metallic: 0}; as Revolve's), render: object ({mode: shaded}; mode: shaded|wireframe|rendered, quality, resolution and background, as Revolve's; rendered mode checks the paint of every fill and stroke)}. Turns the flat art in 3D about the centre of its bounds; every fill and stroke keeps its paint, shaded as one plane.", + "{rotationX: degrees (-180..180, -21.88), rotationY: degrees (-180..180, -23.4), rotationZ: degrees (-180..180, 9.06; the defaults are the Off-Axis Front position), perspectiveAngle: degrees (0..160, 0; 0 is none, wider brings the eye nearer), perspective: % (0..100; the earlier form, read as the perspectiveAngle that shows the same view), shade: bool (true), lightColor: #rrggbb (white, #ffffff; legacy directional light color), lights: null or array of 1..10 objects (color: #rrggbb, intensity: % 0..100, rotation: degrees -180..180, height: degrees 0..90, softness: % 0..100, behind: bool; overrides the single-light fields; ambient is shared), lightRotation: degrees (-180..180, 125.26; round the object on the page, 0 on its right, counterclockwise), lightHeight: degrees (0..90, 30; 0 beside the object, 90 straight in front), lightBehind: bool (false; true lights it from behind), lightIntensity: % (0..100, 80), lightSoftness: % (0..100, 0; how far round the object the light reaches, and how much it blurs the shadow), ambient: % (0..200, 25; Ambient Light), lightAzimuth: degrees (the earlier form: with lightElevation, read as the lightRotation, lightHeight and lightBehind of the same light), lightElevation: degrees (the earlier form, with lightAzimuth), shadow: bool (false; in the shaded faces the first light casts a shadow, black at 50% times the art's opacity, hard-edged at the first light's softness 0 and blurred above it; with render mode rendered, every light with an intensity above 0 casts shadows in the image), shadowPosition: behind|below (behind; behind: on a plane square to the view, below: on the floor under the object, turned with it), shadowDistance: % (0..100, 0; how far the plane is from the object, as a share of its largest size), shadowBounds: % (10..400, 100; how far the plane reaches: at 100 it is four times the object's largest size across), graphics: array of 0..64 objects ([]; the 3D and Materials panel's Graphics on the plane, as Extrude & Bevel's, with face front only), material: object ({roughness: 1, metallic: 0}; as Revolve's), render: object ({mode: shaded}; mode: shaded|wireframe|rendered, quality, resolution, background and colorModel, as Revolve's; rendered mode checks the paint of every fill and stroke)}. Turns the flat art in 3D about the centre of its bounds; every fill and stroke keeps its paint, shaded as one plane.", json!({"rotationX":-21.88,"rotationY":-23.4,"rotationZ":9.06,"perspectiveAngle":0.0,"shade":true,"lightColor":"#ffffff","lights":null,"lightRotation":125.26438968275465,"lightHeight":30.0,"lightBehind":false,"lightIntensity":80.0,"lightSoftness":0.0,"ambient":25.0,"shadow":false,"shadowPosition":"behind","shadowDistance":0.0,"shadowBounds":100.0,"graphics":[],"material":{"roughness":1.0,"metallic":0.0},"render":{"mode":"shaded"}}), ), g( diff --git a/crates/effects/src/solids/rendered.rs b/crates/effects/src/solids/rendered.rs index a21ccbbba2..203aae9c51 100644 --- a/crates/effects/src/solids/rendered.rs +++ b/crates/effects/src/solids/rendered.rs @@ -7,7 +7,7 @@ use std::io::Cursor; use std::sync::Arc; use craft_raster3d::{Limits, Scene, Vertex, srgb_to_linear, try_encode, try_render_cpu, try_shadow_maps}; -use vectorcraft_doc::{ImageBlob, ImageObject, Node, NodeId, NodeKind}; +use vectorcraft_doc::{ImageBlob, ImageObject, Node, NodeId, NodeKind, RasterColorModel}; use vectorcraft_geom::{Affine, Rect}; use vectorcraft_three_d::{Light, MeshProjection}; @@ -149,7 +149,8 @@ pub(crate) fn with_receiver( } /// A rendered image: `cols` × `rows` straight-alpha sRGB RGBA8 pixels covering `rect` on the page, -/// made with `samples` × `samples` samples a pixel. +/// made with `samples` × `samples` samples a pixel. `gray` when the color model is Grayscale or +/// Bitmap: every pixel's red, green and blue are equal, and the image is stored as a gray PNG. #[derive(Clone, Debug, PartialEq)] pub struct Rendered { pub rect: Rect, @@ -157,6 +158,7 @@ pub struct Rendered { pub rows: u32, pub samples: u32, pub pixels: Vec, + pub gray: bool, } /// The margin, as a share of the depth range, the solids' nearest and farthest points keep from the @@ -197,12 +199,28 @@ pub fn render( .iter() .flat_map(|p| { let p = if settings.white { [p[0] + 1.0 - p[3], p[1] + 1.0 - p[3], p[2] + 1.0 - p[3], 1.0] } else { *p }; - let a = p[3].clamp(0.0, 1.0); - let straight = |c: f32| if a > 0.0 { (c / a).clamp(0.0, 1.0) } else { 0.0 }; - [straight(p[0]), straight(p[1]), straight(p[2]), a].map(|c| (c * 255.0).round() as u8) + color_model_pixel(p, settings.color_model) }) .collect(); - Ok(Rendered { rect, cols, rows, samples: k, pixels }) + Ok(Rendered { rect, cols, rows, samples: k, pixels, gray: settings.color_model != RasterColorModel::Document }) +} + +/// Premultiplied sRGB float pixel `p` as a straight RGBA8 pixel in color model `model`. Grayscale +/// and Bitmap map the straight color before the coverage is rounded, so an edge pixel takes the +/// gray or the black or white of the surface it covers. +fn color_model_pixel(p: [f32; 4], model: RasterColorModel) -> [u8; 4] { + let a = p[3].clamp(0.0, 1.0); + let straight = |c: f32| if a > 0.0 { (c / a).clamp(0.0, 1.0) } else { 0.0 }; + if model == RasterColorModel::Document { + return [straight(p[0]), straight(p[1]), straight(p[2]), a].map(|c| (c * 255.0).round() as u8); + } + let alpha = (a * 255.0).round() as u8; + if alpha == 0 { + return [0; 4]; + } + let luma = 0.2126 * straight(p[0]) + 0.7152 * straight(p[1]) + 0.0722 * straight(p[2]); + let gray = if model == RasterColorModel::Bitmap { if luma < 0.5 { 0 } else { 255 } } else { (luma * 255.0).round() as u8 }; + [gray, gray, gray, alpha] } #[cfg(test)] @@ -585,11 +603,23 @@ pub fn image_node(id: NodeId, image: &Rendered) -> Option> { Some(Arc::new(Node::new(id, NodeKind::Image(Box::new(image_object(image)?))))) } -/// `image` as an image object holding its pixels as a PNG; `None` when it can't be encoded. +/// `image` as an image object holding its pixels as a PNG: RGBA, or for a [`Rendered::gray`] image +/// gray, with alpha unless every pixel is opaque. `None` when it can't be encoded. fn image_object(image: &Rendered) -> Option { - let raw = image::RgbaImage::from_raw(image.cols, image.rows, image.pixels.clone())?; let mut png = vec![]; - raw.write_to(&mut Cursor::new(&mut png), image::ImageFormat::Png).ok()?; + let mut out = Cursor::new(&mut png); + if image.gray { + let pixels = image.pixels.as_chunks::<4>().0; + if pixels.iter().all(|p| p[3] == 255) { + let levels = pixels.iter().map(|p| p[0]).collect(); + image::GrayImage::from_raw(image.cols, image.rows, levels)?.write_to(&mut out, image::ImageFormat::Png).ok()?; + } else { + let gray_alpha = pixels.iter().flat_map(|p| [p[0], p[3]]).collect(); + image::GrayAlphaImage::from_raw(image.cols, image.rows, gray_alpha)?.write_to(&mut out, image::ImageFormat::Png).ok()?; + } + } else { + image::RgbaImage::from_raw(image.cols, image.rows, image.pixels.clone())?.write_to(&mut out, image::ImageFormat::Png).ok()?; + } let blob = ImageBlob::png(png); let cell = image.rect.width() / f64::from(image.cols); Some(ImageObject { @@ -728,6 +758,7 @@ fn image_key(meshes: &[SolidMesh], lighting: &Lighting, settings: RenderSettings .into_iter() .for_each(&mut f); [settings.quality as f64, settings.resolution.unwrap_or(f64::NAN), f64::from(u8::from(settings.white)), ppi].into_iter().for_each(&mut f); + settings.color_model.id().hash(&mut h); for m in meshes { m.mesh.triangles.hash(&mut h); } diff --git a/crates/effects/src/solids/rendered/tests.rs b/crates/effects/src/solids/rendered/tests.rs index 59633f835f..be9b1fb3ea 100644 --- a/crates/effects/src/solids/rendered/tests.rs +++ b/crates/effects/src/solids/rendered/tests.rs @@ -62,7 +62,8 @@ fn scene_of(n: &Node) -> (Vec, Lighting) { (crate::three_d_meshes(n).unwrap(), lighting(&fx.id, &p)) } -const MEDIUM: RenderSettings = RenderSettings { quality: 1, resolution: None, white: false }; +const MEDIUM: RenderSettings = + RenderSettings { quality: 1, resolution: None, white: false, color_model: vectorcraft_doc::RasterColorModel::Document }; const FOUR: [&str; 4] = [super::super::EXTRUDE, crate::REVOLVE, super::super::INFLATE, super::super::ROTATE]; @@ -447,6 +448,89 @@ fn the_background_is_white_or_clear() { assert!(corners(&white).contains(&[255; 4]), "{:?}", corners(&white)); } +#[test] +fn color_model_maps_straight_color_before_rounding_coverage() { + let dark = 127.0 / 255.0; + let edge = [dark * 0.25, dark * 0.25, dark * 0.25, 0.25]; + assert_eq!(color_model_pixel(edge, RasterColorModel::Bitmap), [0, 0, 0, 64]); + assert_eq!(color_model_pixel(edge, RasterColorModel::Grayscale), [127, 127, 127, 64]); + assert_eq!(color_model_pixel([0.125, 0.125, 0.125, 0.25], RasterColorModel::Bitmap), [255, 255, 255, 64]); + for model in [RasterColorModel::Grayscale, RasterColorModel::Bitmap] { + assert_eq!(color_model_pixel([0.0; 4], model), [0; 4]); + for rgb in [[127, 127, 127], [128, 128, 128], [255, 0, 0], [0, 255, 0], [0, 0, 255]] { + let mut expected = [rgb[0], rgb[1], rgb[2], 255]; + vectorcraft_doc::RasterEffectsSettings { color_model: model, ..Default::default() }.finish_pixels(&mut expected); + let p = [f32::from(rgb[0]) / 255.0, f32::from(rgb[1]) / 255.0, f32::from(rgb[2]) / 255.0, 1.0]; + assert_eq!(color_model_pixel(p, model), expected, "{model:?}: {rgb:?}"); + } + } +} + +/// Grayscale gives each pixel the Rec. 709 luma of the pixel the document's color mode gives, and +/// Bitmap makes each pixel black or white, after the background, with the same coverage. The +/// effect's `colorModel` sets the model, and a new model makes a new image. +#[test] +fn the_color_model_makes_gray_or_black_and_white_pixels() { + use vectorcraft_doc::RasterColorModel; + let n = solid_square(super::super::EXTRUDE, Color::rgb(0.2, 0.5, 0.8), json!({})); + let (meshes, lighting) = scene_of(&n); + let at = |color_model, white| { + render(&meshes, &lighting, RenderSettings { color_model, white, ..MEDIUM }, 72.0, false, &Limits::default()).unwrap().pixels + }; + for white in [false, true] { + let (color, gray, bitmap) = + (at(RasterColorModel::Document, white), at(RasterColorModel::Grayscale, white), at(RasterColorModel::Bitmap, white)); + assert_eq!((color.len(), gray.len(), bitmap.len()), (color.len(), color.len(), color.len())); + let (mut colored, mut blacks, mut whites) = (0, 0, 0); + for ((c, g), b) in color.chunks(4).zip(gray.chunks(4)).zip(bitmap.chunks(4)) { + assert_eq!((g[3], b[3]), (c[3], c[3]), "white {white}: the color model keeps each pixel's coverage"); + assert!(g[0] == g[1] && g[1] == g[2], "white {white}: grayscale pixel {g:?}"); + if c[3] == 255 { + let luma = 0.2126 * f64::from(c[0]) + 0.7152 * f64::from(c[1]) + 0.0722 * f64::from(c[2]); + assert!((f64::from(g[0]) - luma).abs() <= 1.0, "white {white}: gray {g:?} for {c:?}, luma {luma}"); + assert!(b[..3] == [0; 3] || b[..3] == [255; 3], "white {white}: bitmap pixel {b:?}"); + blacks += usize::from(b[0] == 0); + whites += usize::from(b[0] == 255); + } + colored += usize::from(c[0] != c[1] || c[1] != c[2]); + } + assert!(colored > 0, "white {white}: the document's color mode keeps the paint's color"); + // Over white, the background is white and the blue solid has dark pixels. + assert!(blacks > 0 && (whites > 0 || !white), "white {white}: bitmap gives {blacks} black and {whites} white pixels"); + } + // Grayscale and Bitmap images are stored as gray PNGs, and the document's color mode as RGBA. + for (color_model, kinds) in [ + (RasterColorModel::Document, [image::ColorType::Rgba8, image::ColorType::Rgba8]), + (RasterColorModel::Grayscale, [image::ColorType::La8, image::ColorType::L8]), + (RasterColorModel::Bitmap, [image::ColorType::La8, image::ColorType::L8]), + ] { + for (white, kind) in [false, true].into_iter().zip(kinds) { + let image = render(&meshes, &lighting, RenderSettings { color_model, white, ..MEDIUM }, 72.0, false, &Limits::default()).unwrap(); + let object = image_object(&image).unwrap(); + let blob = object.pixels.unwrap(); + let decoded = image::load_from_memory(&blob.bytes).unwrap(); + assert_eq!(decoded.color(), kind, "{color_model:?}, white {white}"); + assert_eq!(decoded.to_rgba8().into_raw(), image.pixels, "{color_model:?}, white {white}: the PNG holds the pixels"); + } + } + let settings = |model: &str| crate::render_settings(super::super::EXTRUDE, &json!({"render": {"mode": "rendered", "colorModel": model}})); + assert_eq!(settings("bitmap").map(|s| s.color_model), Some(RasterColorModel::Bitmap)); + assert_eq!(settings("grayscale").map(|s| s.color_model), Some(RasterColorModel::Grayscale)); + assert_eq!(settings("document").map(|s| s.color_model), Some(RasterColorModel::Document)); + let default = crate::render_settings(super::super::EXTRUDE, &json!({"render": {"mode": "rendered"}})); + assert_eq!(default.map(|s| s.color_model), Some(RasterColorModel::Document), "the document's color mode is the default"); + assert_eq!(settings("rgb"), None, "a model outside the three draws shaded"); + let count = || RASTERIZATIONS.with(|count| count.get()); + let doc = vectorcraft_doc::Document::new(400.0, 400.0); + let mut lit = solid_square(super::super::EXTRUDE, Color::rgb(0.2, 0.5, 0.8), json!({"render": {"mode": "rendered", "quality": "low"}})); + let draw = |n: &Node| images(&super::super::solid_art_drawn_in(Some(&doc), n).unwrap()).len(); + assert_eq!(draw(&lit), 1); + let start = count(); + lit.appearance.effects[0].params["render"]["colorModel"] = json!("grayscale"); + assert_eq!(draw(&lit), 1); + assert_eq!(count(), start + 1, "a new color model makes a new image"); +} + /// A mesh without a projection, or meshes with different ones, can't be placed: the image is refused. #[test] fn meshes_without_one_projection_are_refused() { @@ -1203,7 +1287,7 @@ fn a_medium_render_stays_within_its_work_bound() { let mut n = Node::path(NodeId(1), PathData::from_bezpath(&b), Appearance::basic(Paint::solid(Color::rgb(0.2, 0.5, 0.8)), Paint::None, 0.0)); n.appearance.effects.push(crate::new_effect(super::super::EXTRUDE, &json!({"render": {"mode": "rendered", "resolution": 300}})).unwrap()); let (meshes, lighting) = scene_of(&n); - let settings = RenderSettings { quality: 1, resolution: Some(300.0), white: false }; + let settings = RenderSettings { quality: 1, resolution: Some(300.0), ..MEDIUM }; let m = measure(&meshes, &lighting, settings, 72.0, false, &Limits::default()).unwrap(); assert_eq!(m.samples, 2); let samples = u64::from(m.cols) * u64::from(m.rows) * 4; @@ -1245,7 +1329,7 @@ fn edge_values_render_or_are_refused() { meshes[0].mesh.triangles.push([first[0], first[0], first[1]]); assert!(render(&meshes, &lighting, MEDIUM, 72.0, false, &Limits::default()).is_ok(), "zero-area triangle"); for resolution in [1.0, 2400.0] { - let settings = RenderSettings { quality: 0, resolution: Some(resolution), white: false }; + let settings = RenderSettings { quality: 0, resolution: Some(resolution), ..MEDIUM }; let image = render(&meshes, &lighting, settings, 72.0, false, &Limits::default()).unwrap(); assert!(image.cols >= 1 && image.rows >= 1, "{resolution} ppi"); } diff --git a/crates/effects/src/solids/wireframe.rs b/crates/effects/src/solids/wireframe.rs index 9ad0597c5c..5fe9416ffd 100644 --- a/crates/effects/src/solids/wireframe.rs +++ b/crates/effects/src/solids/wireframe.rs @@ -6,7 +6,7 @@ use std::sync::Arc; use serde_json::Value; use vectorcraft_doc::color::{Color, Paint}; -use vectorcraft_doc::{Appearance, AppearanceItem, Document, Effect, FillLayer, LineJoin, Node, NodeId, StrokeLayer}; +use vectorcraft_doc::{Appearance, AppearanceItem, Document, Effect, FillLayer, LineJoin, Node, NodeId, RasterColorModel, StrokeLayer}; use vectorcraft_geom::{Anchor, CubicBez, PathData, Point, SubPath}; use vectorcraft_three_d::Facet; @@ -21,8 +21,8 @@ use crate::{GeomContext, is_geometry}; pub(crate) const MAX_WIRE_EDGES: usize = 1_000_000; /// The parameter that holds a 3D effect's render settings: an object whose `mode` is one of -/// [`RENDER_MODES`], with the rendered image's `quality` ([`RENDER_QUALITIES`]), `resolution` and -/// `background` ([`RENDER_BACKGROUNDS`]). +/// [`RENDER_MODES`], with the rendered image's `quality` ([`RENDER_QUALITIES`]), `resolution`, +/// `background` ([`RENDER_BACKGROUNDS`]) and `colorModel` ([`RENDER_COLOR_MODELS`]). pub const RENDER: &str = "render"; /// The render modes of a 3D effect: `shaded` draws the lit faces, `wireframe` the edges of every @@ -37,6 +37,10 @@ pub const RENDER_QUALITIES: [&str; 3] = ["low", "medium", "high"]; /// What the rendered image shows where no surface is: nothing, or white. pub const RENDER_BACKGROUNDS: [&str; 2] = ["transparent", "white"]; +/// The color models of the rendered image, the ids of [`RasterColorModel`]: RGB pixels in every +/// document, grayscale, or black and white pixels only, as Effect › Rasterize makes them. +pub const RENDER_COLOR_MODELS: [&str; 3] = ["document", "grayscale", "bitmap"]; + /// The index in [`RENDER_QUALITIES`] of the quality a `render` without one takes (VectorCraft's own /// default). const DEFAULT_QUALITY: usize = 1; @@ -51,6 +55,8 @@ pub struct RenderSettings { /// A white background, which makes the image opaque; otherwise it is transparent where no /// surface or shadow is. pub white: bool, + /// The image's color model, applied after the background. + pub color_model: RasterColorModel, } impl RenderSettings { @@ -73,6 +79,11 @@ pub fn render_settings(id: &str, p: &Value) -> Option { quality: quality.unwrap_or(DEFAULT_QUALITY), resolution: render.get("resolution").and_then(Value::as_f64), white: render.get("background").and_then(Value::as_str) == Some("white"), + color_model: render + .get("colorModel") + .and_then(Value::as_str) + .and_then(|m| RasterColorModel::ALL.into_iter().find(|c| c.id() == m)) + .unwrap_or_default(), }) } @@ -83,7 +94,8 @@ pub fn renders_image(fx: &Effect) -> bool { /// The message a `render` that breaks the rules of [`validate_render`] is refused with. const RENDER_RULES: &str = "`render` must be an object holding only mode (shaded, wireframe or rendered), quality (low, medium or high), \ - resolution (null or a number from 1 to 2400) and background (transparent or white)"; + resolution (null or a number from 1 to 2400), background (transparent or white) and colorModel \ + (document, grayscale or bitmap)"; /// Check one `render` value against [`RENDER_RULES`]. fn check_render(render: &Value) -> Result<(), String> { @@ -93,6 +105,7 @@ fn check_render(render: &Value) -> Result<(), String> { "mode" => one_of(value, &RENDER_MODES), "quality" => one_of(value, &RENDER_QUALITIES), "background" => one_of(value, &RENDER_BACKGROUNDS), + "colorModel" => one_of(value, &RENDER_COLOR_MODELS), "resolution" => value.is_null() || value.as_f64().is_some_and(|r| (1.0..=2400.0).contains(&r)), _ => false, }) @@ -124,8 +137,9 @@ pub(crate) fn wireframe_params(id: &str, p: &Value) -> bool { /// Check the render settings in 3D effect `id`'s parameters `p`: `render`, when given to one of the /// effects in [`TAKES_RENDER`], is an object that holds only `mode` (one of [`RENDER_MODES`]), /// `quality` (one of [`RENDER_QUALITIES`]), `resolution` (`null`, or a number from 1 to 2400 pixels -/// per inch) and `background` (one of [`RENDER_BACKGROUNDS`]). A key left out takes its default: -/// `shaded`, `medium`, the document's raster effects resolution and `transparent`. The 3D (Classic) +/// per inch), `background` (one of [`RENDER_BACKGROUNDS`]) and `colorModel` (one of +/// [`RENDER_COLOR_MODELS`]). A key left out takes its default: `shaded`, `medium`, the document's +/// raster effects resolution, `transparent` and `document`. The 3D (Classic) /// effects refuse it as a parameter they do not take. pub(crate) fn validate_render(id: &str, p: &Value) -> Result<(), String> { let Some(render) = p.get(RENDER).filter(|_| TAKES_RENDER.contains(&id)) else { return Ok(()) }; diff --git a/crates/effects/src/solids/wireframe/tests.rs b/crates/effects/src/solids/wireframe/tests.rs index f99be96a94..31238b08b8 100644 --- a/crates/effects/src/solids/wireframe/tests.rs +++ b/crates/effects/src/solids/wireframe/tests.rs @@ -419,8 +419,9 @@ fn expanding_a_revolve_in_wireframe_mode_gives_the_edges() { } /// `render` is checked before an edit: an object holding only `mode` (shaded, wireframe or -/// rendered), `quality` (low, medium or high), `resolution` (null or 1 to 2400) and `background` -/// (transparent or white), and only on the panel's four effects. +/// rendered), `quality` (low, medium or high), `resolution` (null or 1 to 2400), `background` +/// (transparent or white) and `colorModel` (document, grayscale or bitmap), and only on the panel's +/// four effects. #[test] fn render_settings_are_validated() { for id in WIRE { @@ -434,6 +435,9 @@ fn render_settings_are_validated() { json!({"render": {"mode": "rendered", "quality": "low", "resolution": null, "background": "transparent"}}), json!({"render": {"resolution": 1}}), json!({"render": {"resolution": 2400}}), + json!({"render": {"mode": "rendered", "colorModel": "document"}}), + json!({"render": {"mode": "rendered", "colorModel": "grayscale"}}), + json!({"render": {"colorModel": "bitmap"}}), ] { assert_eq!(crate::validate_three_d_params(id, &good), Ok(()), "{id} {good}"); } @@ -448,12 +452,16 @@ fn render_settings_are_validated() { json!({"render": {"mode": "rendered", "resolution": "300"}}), json!({"render": {"mode": "rendered", "background": "black"}}), json!({"render": {"mode": "rendered", "samples": 4}}), + json!({"render": {"mode": "rendered", "colorModel": "rgb"}}), + json!({"render": {"mode": "rendered", "colorModel": "Grayscale"}}), + json!({"render": {"mode": "rendered", "colorModel": null}}), + json!({"render": {"mode": "rendered", "colorModel": 1}}), ] { let e = crate::validate_three_d_params(id, &bad).unwrap_err(); assert_eq!( e, "`render` must be an object holding only mode (shaded, wireframe or rendered), quality (low, medium or high), resolution (null \ - or a number from 1 to 2400) and background (transparent or white)", + or a number from 1 to 2400), background (transparent or white) and colorModel (document, grayscale or bitmap)", "{id} {bad}" ); } diff --git a/crates/engine/src/tests/effectedit.rs b/crates/engine/src/tests/effectedit.rs index 23f703af6a..b3ed23ee3e 100644 --- a/crates/engine/src/tests/effectedit.rs +++ b/crates/engine/src/tests/effectedit.rs @@ -284,6 +284,67 @@ fn image_widths(bytes: &[u8]) -> Vec { out } +/// `render.colorModel` outside document, grayscale and bitmap is refused before the document +/// changes. A valid one is saved with the effect and read back, and Grayscale gives the image +/// Expand Appearance leaves gray pixels, stored as a gray PNG. +#[test] +fn a_rendered_3d_color_model_is_checked_saved_and_drawn() { + let mut s = rendered_square(&[]); + let object = |s: &Session| { + let mut found = None; + for l in &s.doc().unwrap().doc.layers { + l.walk(&mut |n| { + if n.appearance.effects.iter().any(|e| e.id == "threeD.extrude") { + found = Some(n.clone()); + } + }); + } + found.unwrap() + }; + let before = object(&s); + let undo = s.doc().unwrap().history.undo.len(); + for bad in [json!("sepia"), json!("rgb"), json!(null), json!(2)] { + let params = json!({"index": 0, "item": null, "params": {"render": {"mode": "rendered", "colorModel": bad}}}); + let e = s.execute("effect.setParams", ¶ms).unwrap_err().to_string(); + assert!(e.contains("colorModel (document, grayscale or bitmap)"), "{bad}: {e}"); + } + assert_eq!(object(&s), before, "a refused color model leaves the object unchanged"); + assert_eq!(s.doc().unwrap().history.undo.len(), undo); + run( + &mut s, + "effect.setParams", + json!({"index": 0, "item": null, "params": {"render": {"mode": "rendered", "quality": "low", "colorModel": "grayscale"}}}), + ); + let back = vectorcraft_format::load(&vectorcraft_format::save(&s.doc().unwrap().doc, false)).unwrap(); + let mut models = vec![]; + for l in &back.layers { + l.walk(&mut |n| { + for e in n.appearance.effects.iter().filter(|e| e.id == "threeD.extrude") { + models.push(vectorcraft_render::effects::render_settings(&e.id, &e.params).map(|r| r.color_model)); + } + }); + } + assert_eq!(models, vec![Some(vectorcraft_doc::RasterColorModel::Grayscale)], "the saved file keeps the color model"); + run(&mut s, "effect.expandAppearance", json!({})); + let doc = &s.doc().unwrap().doc; + let mut keys = vec![]; + for l in &doc.layers { + l.walk(&mut |n| { + if let vectorcraft_doc::NodeKind::Image(im) = &n.kind { + keys.push(im.key.clone()); + } + }); + } + assert_eq!(keys.len(), 1, "{keys:?}"); + let decoded = image::load_from_memory(&doc.images[&keys[0]].bytes).unwrap(); + assert!(matches!(decoded.color(), image::ColorType::L8 | image::ColorType::La8), "a gray image is stored gray: {:?}", decoded.color()); + let pixels = decoded.to_rgba8(); + let opaque = pixels.pixels().filter(|p| p[3] == 255).count(); + assert!(opaque > 0, "the image covers the solid"); + let colored: Vec<_> = pixels.pixels().filter(|p| p[3] > 0 && !(p[0] == p[1] && p[1] == p[2])).take(4).collect(); + assert!(colored.is_empty(), "pixels with color in a grayscale image: {colored:?}"); +} + /// PDF and SVG export write one image for a rendered 3D object, and Expand Appearance leaves one /// embedded image of the same size in pixels that covers the object. #[test] diff --git a/crates/ui-egui/src/panels/tests_three_d.rs b/crates/ui-egui/src/panels/tests_three_d.rs index dbb058c0c7..85e2d1c0eb 100644 --- a/crates/ui-egui/src/panels/tests_three_d.rs +++ b/crates/ui-egui/src/panels/tests_three_d.rs @@ -2169,3 +2169,72 @@ fn raster_settings_sets_resolution_and_background() { assert_eq!(render_of(&panel.app(), id)["resolution"], Value::Null, "{id}"); } } + +/// Raster Settings… shows Color as RGB (in a CMYK document too, since the image is made in RGB), +/// Grayscale or Bitmap. OK sets the picked model on every object in one undo step; a model the +/// objects hold differently opens blank and stays as each object has it. +#[test] +fn raster_settings_sets_the_color_model() { + use craft::ui::contract::Role; + use craft::ui::dialog::dialog_id; + use craft::ui::patterns::form_dialogs::HostedParamDialog; + + use crate::tests::panel_harness::Panel; + + let (app, a, b) = two_renders(); + let mut panel = Panel::new(app, show_with_dialogs); + panel.frame(); + let (id, ctx) = (dialog_id(super::raster::KIND), panel.ctx().clone()); + let is_open = |panel: &Panel| panel.app().dialogs().is_some_and(|d| d.with(|host| host.get_mut_by_id::(id).is_some())); + let set = |panel: &Panel, key: &str, value: Value| panel.app().dialogs().unwrap().with(|host| host.set_json_field(&ctx, id, key, value)).unwrap(); + let ok = |panel: &mut Panel| { + panel.app().dialogs().unwrap().with(|host| host.confirm_by_id(&ctx, id)); + panel.frame(); + panel.frame(); + }; + let open = |panel: &mut Panel| { + panel.click("Render Settings"); + panel.click("Raster Settings…"); + panel.frame(); + assert!(is_open(panel)); + }; + open(&mut panel); + assert_eq!(panel.value_role("Color", Role::COMBO_BOX).as_deref(), Some("RGB"), "both objects take the document's color mode"); + let history = undo_len(&panel.app()); + set(&panel, "colorModel", json!("grayscale")); + ok(&mut panel); + assert!(!is_open(&panel)); + assert_eq!(undo_len(&panel.app()), history + 1, "OK is one undo step for the selection"); + for id in [a, b] { + assert_eq!(render_of(&panel.app(), id)["colorModel"], "grayscale", "{id}"); + } + open(&mut panel); + assert_eq!(panel.value_role("Color", Role::COMBO_BOX).as_deref(), Some("Grayscale")); + ok(&mut panel); + assert_eq!(undo_len(&panel.app()), history + 1, "OK with what every object holds records no undo step"); + panel.app().run("select.set", json!({"ids": [b]})).unwrap(); + let mut bitmap = render_of(&panel.app(), b); + bitmap["colorModel"] = json!("bitmap"); + panel.app().run("effect.setParams", json!({"index": 0, "item": null, "params": {"render": bitmap}})).unwrap(); + panel.app().run("select.set", json!({"ids": [b, a]})).unwrap(); + panel.frame(); + open(&mut panel); + let shown = panel.value_role("Color", Role::COMBO_BOX).unwrap_or_default(); + assert!(!["RGB", "Grayscale", "Bitmap"].contains(&shown.as_str()), "a mixed color model shows {shown:?}"); + let history = undo_len(&panel.app()); + set(&panel, "background", json!("transparent")); + ok(&mut panel); + assert_eq!(undo_len(&panel.app()), history + 1); + assert_eq!(render_of(&panel.app(), a)["colorModel"], "grayscale", "a blank color model stays as each object has it"); + assert_eq!(render_of(&panel.app(), b)["colorModel"], "bitmap"); + panel.app().run("file.documentColorMode", json!({"mode": "cmyk"})).unwrap(); + panel.frame(); + open(&mut panel); + set(&panel, "colorModel", json!("document")); + panel.frame(); + assert_eq!(panel.value_role("Color", Role::COMBO_BOX).as_deref(), Some("RGB"), "the image is made in RGB in a CMYK document"); + ok(&mut panel); + for id in [a, b] { + assert_eq!(render_of(&panel.app(), id)["colorModel"], "document", "{id}"); + } +} diff --git a/crates/ui-egui/src/panels/three_d.rs b/crates/ui-egui/src/panels/three_d.rs index 51a26d533c..30a985473a 100644 --- a/crates/ui-egui/src/panels/three_d.rs +++ b/crates/ui-egui/src/panels/three_d.rs @@ -550,6 +550,7 @@ fn render_value(render: &Map, key: &str) -> Value { "mode" => json!("shaded"), "quality" => json!("medium"), "background" => json!("transparent"), + "colorModel" => json!("document"), _ => Value::Null, }) } diff --git a/crates/ui-egui/src/panels/three_d/raster.rs b/crates/ui-egui/src/panels/three_d/raster.rs index 1e0ef2e86c..10a057bd81 100644 --- a/crates/ui-egui/src/panels/three_d/raster.rs +++ b/crates/ui-egui/src/panels/three_d/raster.rs @@ -1,9 +1,10 @@ -//! Render Settings › Raster Settings…: the resolution and background of the rendered image of each -//! selected object's 3D effect. +//! Render Settings › Raster Settings…: the resolution, background and color model of the rendered +//! image of each selected object's 3D effect. //! -//! Fields: `document` (Use Document Raster Effects Resolution), `resolution` (1 to 2400 ppi) and -//! `background` (`transparent` or `white`). A field the selected objects hold differently opens -//! blank, and OK leaves it as each object has it. OK runs one `effect.setParams` over the objects +//! Fields: `document` (Use Document Raster Effects Resolution), `resolution` (1 to 2400 ppi), +//! `background` (`transparent` or `white`) and `colorModel` (`document`, shown as RGB, the image it +//! makes in every document; `grayscale` or `bitmap`). A field the selected objects hold differently +//! opens blank, and OK leaves it as each object has it. OK runs one `effect.setParams` over the objects //! selected when the dialog opened, one undo step, which records none when every object already //! holds what it sets. While another document is the active one, or after the document was //! reverted or had an Undo, Redo or canceled edit, OK keeps the dialog open with the reason. @@ -54,6 +55,11 @@ pub(crate) fn open(app: &mut VectorcraftApp) -> Result<(), String> { Some(b) => fields.set("background", FieldValue::Text(b.clone())), None => fields.set_mixed("background"), } + let color_model = shared_render(&renders, "colorModel").as_ref().and_then(Value::as_str).map(str::to_owned); + match &color_model { + Some(m) => fields.set("colorModel", FieldValue::Text(m.clone())), + None => fields.set_mixed("colorModel"), + } let ctx = app.ui_ctx.clone().ok_or("no window")?; let dialog = HostedParamDialog::new(&ctx, KIND, fields, |fields| dialog().values(Bind::bound(fields))); let (doc, targets) = app @@ -71,7 +77,7 @@ pub(crate) fn open(app: &mut VectorcraftApp) -> Result<(), String> { (Some((st.uid, st.reverts, st.history_restores)), targets) }) .unwrap_or_default(); - let opened = Opened { document, resolution: opening, background, doc, targets }; + let opened = Opened { document, resolution: opening, background, color_model, doc, targets }; open_held(app, dialog, move |app, answer| ok(app, answer, &opened)).ok_or("no window")?; Ok(()) } @@ -84,12 +90,19 @@ fn opening_resolution(resolutions: &[Option], ppi: f64) -> Option { effective.all(|r| r == first).then_some(first) } -/// The dialog over its rows. +/// The dialog over its rows. Color's `document` shows as RGB in every document: the image is made in +/// RGB, and a CMYK document's PDF export converts it as it converts raster effect images. fn dialog<'a>() -> ParamDialog<'a> { let backgrounds = vec![("transparent".to_owned(), tl!("Transparent").into()), ("white".to_owned(), tl!("White").into())]; + let models = vec![ + ("document".to_owned(), tl!("RGB").into()), + ("grayscale".to_owned(), tl!("Grayscale").into()), + ("bitmap".to_owned(), tl!("Bitmap").into()), + ]; let params = vec![ Param::new("document", tl!("Use Document Raster Effects Resolution"), ParamKind::bool(true)), Param::number("resolution", tl!("Resolution (ppi):"), 72.0, 1.0, 0).bounds(Some(1.0), Some(2400.0)).enabled_when("document", false), + Param::new("colorModel", tl!("Color:"), ParamKind::choice(models, None)), Param::new("background", tl!("Background:"), ParamKind::radio(backgrounds, None)), ]; ParamDialog::new(KIND, tl!("Raster Settings"), params) @@ -101,6 +114,7 @@ struct Opened { document: Option, resolution: Option, background: Option, + color_model: Option, /// The document the dialog opened on: its uid, and its revert count and history restore count (Undo, Redo or a canceled edit) then. doc: Option<(u64, u64, u64)>, /// The selected objects whose render settings the dialog opened on, as they were then: OK sets @@ -135,6 +149,9 @@ fn edited(f: &DialogFields, opened: &Opened) -> Result, Strin if let Some(background) = f.text("background").filter(|b| opened.background.as_deref() != Some(*b)) { render.insert("background".into(), json!(background)); } + if let Some(model) = f.text("colorModel").filter(|m| opened.color_model.as_deref() != Some(*m)) { + render.insert("colorModel".into(), json!(model)); + } Ok(render) } @@ -226,12 +243,12 @@ mod tests { /// resolution sets nothing and a changed one sets it. #[test] fn ok_needs_a_resolution_and_keeps_blank_fields() { - let on = Opened { document: Some(true), resolution: Some(72.0), background: Some("transparent".into()), doc: None, targets: vec![] }; + let on = Opened { document: Some(true), resolution: Some(72.0), background: Some("transparent".into()), ..opened() }; assert_eq!(edited(&fields(&[("document", FieldValue::Bool(false))]), &on), Err(NO_RESOLUTION.to_string())); - let own = Opened { document: Some(false), resolution: None, background: Some("transparent".into()), doc: None, targets: vec![] }; + let own = Opened { document: Some(false), resolution: None, background: Some("transparent".into()), ..opened() }; let kept = edited(&fields(&[("document", FieldValue::Bool(false)), ("background", FieldValue::Text("white".into()))]), &own).unwrap(); assert_eq!(kept, Map::from_iter([("background".to_string(), json!("white"))])); - let mixed = Opened { document: None, resolution: Some(150.0), background: None, doc: None, targets: vec![] }; + let mixed = Opened { document: None, resolution: Some(150.0), ..opened() }; assert_eq!(edited(&fields(&[("resolution", FieldValue::Number(150.0))]), &mixed), Ok(Map::new())); let changed = edited(&fields(&[("resolution", FieldValue::Number(200.0))]), &mixed).unwrap(); assert_eq!(changed.get("resolution").and_then(Value::as_f64), Some(200.0)); @@ -243,14 +260,21 @@ mod tests { /// mixed one sets it. #[test] fn ok_on_unchanged_values_sets_nothing() { - let on = Opened { document: Some(true), resolution: Some(72.0), background: Some("transparent".into()), doc: None, targets: vec![] }; + let on = Opened { + document: Some(true), + resolution: Some(72.0), + background: Some("transparent".into()), + color_model: Some("document".into()), + ..opened() + }; let unchanged = fields(&[ ("document", FieldValue::Bool(true)), ("resolution", FieldValue::Number(72.0)), ("background", FieldValue::Text("transparent".into())), + ("colorModel", FieldValue::Text("document".into())), ]); assert_eq!(edited(&unchanged, &on), Ok(Map::new())); - let own = Opened { document: Some(false), resolution: Some(150.0), background: Some("transparent".into()), doc: None, targets: vec![] }; + let own = Opened { document: Some(false), resolution: Some(150.0), background: Some("transparent".into()), ..opened() }; let kept = fields(&[("document", FieldValue::Bool(false)), ("resolution", FieldValue::Number(150.0))]); assert_eq!(edited(&kept, &own), Ok(Map::new())); let raised = edited(&fields(&[("document", FieldValue::Bool(false)), ("resolution", FieldValue::Number(200.0))]), &own).unwrap(); @@ -259,8 +283,17 @@ mod tests { assert_eq!(switched, Map::from_iter([("resolution".to_string(), Value::Null)])); let white = edited(&fields(&[("background", FieldValue::Text("white".into()))]), &on).unwrap(); assert_eq!(white, Map::from_iter([("background".to_string(), json!("white"))])); - let mixed = Opened { document: Some(true), resolution: Some(72.0), background: None, doc: None, targets: vec![] }; + let mixed = Opened { document: Some(true), resolution: Some(72.0), ..opened() }; let picked = edited(&fields(&[("background", FieldValue::Text("transparent".into()))]), &mixed).unwrap(); assert_eq!(picked, Map::from_iter([("background".to_string(), json!("transparent"))])); + let gray = edited(&fields(&[("colorModel", FieldValue::Text("grayscale".into()))]), &on).unwrap(); + assert_eq!(gray, Map::from_iter([("colorModel".to_string(), json!("grayscale"))])); + let model = edited(&fields(&[("colorModel", FieldValue::Text("document".into()))]), &mixed).unwrap(); + assert_eq!(model, Map::from_iter([("colorModel".to_string(), json!("document"))]), "a model picked over a mixed one sets it"); + } + + /// The values a dialog opened blank on, with no document or objects. + fn opened() -> Opened { + Opened { document: None, resolution: None, background: None, color_model: None, doc: None, targets: vec![] } } } diff --git a/docs/mcp.md b/docs/mcp.md index 8ba81f20ad..73bea99c51 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -7637,8 +7637,13 @@ it is for a solid past its limits. In rendered mode the effect draws its solid a by every light. With `shadow` and `shade` both on, every light with an intensity above 0 casts shadows on the solid and on the effect's shadow plane, drawn in the image; with either off, none does. `render` then also takes `quality` (`"low"`, `"medium"` or `"high"`: 1, 2 × 2 or 3 × 3 samples a pixel, default `"medium"`, VectorCraft's own -values), `resolution` (`null` for Document Raster Effects Settings › Resolution, the default, or 1..2400 ppi) and -`background` (`"transparent"`, the default, or `"white"`). A quality whose samples would pass 16,777,216 pixels +values), `resolution` (`null` for Document Raster Effects Settings › Resolution, the default, or 1..2400 ppi), +`background` (`"transparent"`, the default, or `"white"`) and `colorModel` (`"document"`, the default, for RGB +pixels in every document; `"grayscale"` for the Rec. 709 luma of each pixel; or `"bitmap"` for black and white +pixels only). The color model applies after the background, in the same way as Effect › Rasterize's `colorModel`, +and leaves each pixel's transparency as it is. In a CMYK document the `"document"` image is made in RGB and is +converted as raster effect images are when a PDF export converts colors; Grayscale and Bitmap images are stored as +gray images. A quality whose samples would pass 16,777,216 pixels takes fewer, and an image past that limit at one sample a pixel draws the shaded faces. The shaded faces are also drawn for a scene past the renderer's limits on triangles, vertices, lights or work, for a mesh point at or behind the eye, for solids painted with a gradient, a pattern, graphics, an @@ -7656,9 +7661,10 @@ limits, so art too complex for the shaded surface does not refuse the wireframe. ```json {"name":"run_command","arguments":{"command":"effect.setParams","params":{"index":0,"item":null,"params":{"render":{"mode":"wireframe"}}}}} {"name":"run_command","arguments":{"command":"effect.setParams","params":{"index":0,"item":null,"params":{"render":{"mode":"rendered","quality":"high","background":"white"}}}}} +{"name":"run_command","arguments":{"command":"effect.setParams","params":{"index":0,"item":null,"params":{"render":{"mode":"rendered","colorModel":"grayscale"}}}}} ``` -The 3D and Materials panel's Render Settings › Raster Settings dialog sets resolution and background on the objects +The 3D and Materials panel's Render Settings › Raster Settings dialog sets resolution, color model and background on the objects selected when the dialog opened. OK applies the changes in one undo step and records nothing when nothing changes. When there are changes to apply, OK keeps the dialog open with the reason while its document is not active, after it was reverted or had an Undo, a Redo or a canceled edit that put back an earlier state, if one of those objects was changed, deleted, locked or hidden, or while another edit is in progress. diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 4f0ae8fc24..1e869b6638 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -745,6 +745,7 @@ since 2026-10-01. - 3D and Materials › Render Settings › Rendered: `render: {mode: "rendered"}` with `quality`, `resolution` and `background` draws the solid of Extrude & Bevel, Revolve, Inflate and Rotate as one depth-buffered image lit by every light (Revolve on a group draws every member's surface in one image, and Revolve on a fill or stroke draws that surface's own image), with shadow maps while Shading and Shadows are both on; solids painted with a gradient, a pattern, graphics, an opacity below 100% or a blending mode other than Normal, a later geometry effect that reshapes paths only, and an image past the renderer's limits draw the shaded faces instead, with a warning ([three-d.md](three-d.md#3d-and-materials-panel)); `crates/effects/src/solids/rendered/tests.rs` and `crates/ui-egui/src/panels/tests_three_d.rs` cover it. Scores and hours unchanged. - 3D and Materials › Materials › Properties: Roughness and Metallic sliders set `material: {roughness, metallic}` on Extrude & Bevel, Revolve, Inflate and Rotate; with Shading on and outside Wireframe mode, any material other than the default (1 and 0) is shaded with craft-pbr's glTF 2.0 metallic-roughness BRDF, its highlight screened over each face; in every mode glTF exports write both factors, and USD exports write roughness and write metallic only when it is not the default 0 ([three-d.md](three-d.md#material-properties)); `crates/three-d/src/material.rs`, `crates/effects/src/solids/tests_material.rs`, `crates/engine/src/cmd/fileio/mesh3d/tests.rs` and `crates/ui-egui/src/panels/tests_three_d.rs` cover it. Scores and hours unchanged. - 3D and Materials › Export 3D Object: the panel's button adds the selected objects that have a 3D effect to Asset Export as 3D assets (`assets.add3D`), one undo step and none when each is an asset already, selects their assets and shows the Asset Export panel ([three-d.md](three-d.md#3d-and-materials-panel)); `panels::three_d::tests::{export_3d_object_adds_the_selected_3d_objects_to_asset_export, export_3d_object_leaves_out_a_3d_object_inside_another}` cover it. Scores and hours unchanged. +- 3D and Materials › Render Settings › Raster Settings › Color: `render.colorModel` (`document`, `grayscale` or `bitmap`) on Extrude & Bevel, Revolve, Inflate and Rotate makes the rendered image in RGB, in gray or in black and white pixels, after the background, as Effect › Rasterize does; any other value is refused, the setting is saved with the effect, and the Raster Settings dialog's Color row sets it on every selected object in one undo step ([three-d.md](three-d.md#3d-and-materials-panel)); `the_color_model_makes_gray_or_black_and_white_pixels`, `render_settings_are_validated`, `a_rendered_3d_color_model_is_checked_saved_and_drawn` and `raster_settings_sets_the_color_model` 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. - 3D effects, images a clip hides: an image in a clipping group is left out of the solid when its transformed frame lies wholly outside the area every clipping path around it fills together, holes included, instead of when only the boxes miss; an image the clips show part of is still refused ([the help page](https://helpx.adobe.com/illustrator/using/clipping-masks.html) on clipping paths hiding everything outside their shape; the omission rule is VectorCraft's own). `solids::tests_sources::an_image_inside_a_clips_box_but_outside_its_shape_is_left_out` covers it. Scores and estimates unchanged. diff --git a/docs/three-d.md b/docs/three-d.md index ca4ab76973..49a37d3c13 100644 --- a/docs/three-d.md +++ b/docs/three-d.md @@ -68,11 +68,20 @@ pages describe it. off, no light casts a shadow. Low takes one sample a pixel, Medium 2 × 2 and High 3 × 3 (VectorCraft's own values), at the effect's `resolution` or, without one, at Document Raster Effects Settings › Resolution. **Render Settings › Raster Settings…** sets Use Document Raster Effects Resolution, Resolution (1 to 2400 ppi) and - Background (Transparent or White). OK sets the objects selected when the dialog opened in one undo step. + Background (Transparent or White), and Color: RGB, Grayscale or Bitmap (`colorModel`: `document`, the default, + `grayscale` or `bitmap`). Grayscale gives each pixel the Rec. 709 luma of its color, and Bitmap makes each pixel + black or white; both apply after the background, as Effect › Rasterize applies its color model, and keep each + pixel's transparency. RGB is shown in every document because the image is made in RGB: in a CMYK document, PDF + export converts it as it converts raster effect images, keeping RGB or converting to CMYK by the export's color + conversion, and Expand Appearance embeds it in RGB. Grayscale and Bitmap images are stored as gray images. OK sets + the objects selected when the dialog opened in one undo step. When nothing changed, OK closes the dialog and records nothing. When there are changes to apply, OK keeps the dialog open with the reason while its document is not active, after it was reverted or had an Undo, a Redo or a canceled edit that put back an earlier state, if one of those objects was changed, deleted, locked or hidden, or while another edit is in progress. - The Render 3D vector artwork page describes Raster Settings changing the resolution and background. A setting + The Render 3D vector artwork page describes Raster Settings changing the resolution, color and background, and + the public + [Rasterization options](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/apply-filter-effects/rasterization-options.html) + page lists the color models of a rasterized image as the document's RGB or CMYK, Grayscale and Bitmap. A setting the selected objects hold differently opens blank and is left as each object has it; Rendered and the qualities show unchecked for such a selection. The selection box, Use Preview Bounds, Align, hit testing and snapping measure the shaded faces, and the image is