diff --git a/crates/three-d/src/material.rs b/crates/three-d/src/material.rs index f12b53750f..fef547d017 100644 --- a/crates/three-d/src/material.rs +++ b/crates/three-d/src/material.rs @@ -11,6 +11,11 @@ //! which is screened over the shaded paint. The diffuse light is the softened Lambert term of the //! lights, scaled by `(1 − F) (1 − metallic)` with the Fresnel term `F` of the 0.04 dielectric //! reflectance, and Ambient Light scaled by `1 − metallic`. +//! +//! The effects draw `paint` as a color layer that multiplies the paint, so each channel of `paint` is +//! clamped to 0..1 where it is drawn (`Shading::of`). Where a bright light or a low Roughness +//! makes `paint` greater than 1, the drawn face stops at that limit. The highlight `h` is also +//! drawn with Screen, so the drawn color is `p + h − p × h` for the shaded paint `p`, not `p + h`. use std::sync::OnceLock; diff --git a/crates/ui-egui/src/panels/tests_three_d.rs b/crates/ui-egui/src/panels/tests_three_d.rs index 867ce33747..5f99fdf05e 100644 --- a/crates/ui-egui/src/panels/tests_three_d.rs +++ b/crates/ui-egui/src/panels/tests_three_d.rs @@ -1455,6 +1455,48 @@ fn the_materials_tab_sets_roughness_and_metallic_in_one_undo_step() { assert_eq!(effect(&app).1["material"], json!({"roughness": 0.3, "metallic": 0.6})); } +/// A drag that goes back to the value it began with previews that value again, and its release leaves the effect +/// as it was without an undo step. +#[test] +fn a_drag_back_to_its_start_value_restores_it() { + let (mut app, _) = materials_app(); + let history = undo_len(&app); + let start = effect(&app).1; + let before = begin(&mut app, GESTURE); + update(&mut app, GESTURE, &[("material", json!({"roughness": 1.0, "metallic": 0.5}))]); + assert_eq!(effect(&app).1["material"]["metallic"], 0.5); + update(&mut app, GESTURE, &[("material", json!({"roughness": 1.0, "metallic": 0.0}))]); + assert_eq!(effect(&app).1["material"]["metallic"].as_f64().unwrap_or(0.0), 0.0, "the preview follows the slider back"); + commit(&mut app, GESTURE, before); + assert_eq!(effect(&app).1, start); + assert_eq!(undo_len(&app), history); + assert!(!app.session.in_interaction()); +} + +/// A Metallic slider dragged away and back on an effect whose `material` leaves Metallic out keeps the effect as it +/// was and records no undo step. +#[test] +fn a_metallic_drag_back_to_its_start_keeps_a_partial_material() { + use crate::tests::panel_harness::Panel; + use craft::ui::contract::Role; + + let (mut app, _) = materials_app(); + app.run("effect.setParams", json!({"index": 0, "item": null, "params": {"material": {"roughness": 0.3}}})).unwrap(); + let mut panel = Panel::new(app, show); + let start = effect(&panel.app()).1; + let history = undo_len(&panel.app()); + let slider = panel.rect_role("Metallic", Role::SLIDER); + panel.drag_hold_role("Metallic", Role::SLIDER, egui::vec2(10.0, 0.0)); + panel.frame_with(vec![egui::Event::PointerMoved(slider.center() + egui::vec2(30.0, 0.0))]); + assert!(effect(&panel.app()).1["material"]["metallic"].as_f64().unwrap() > 0.0); + // Past the slider's left end, Metallic is back at 0. + panel.frame_with(vec![egui::Event::PointerMoved(slider.left_center() - egui::vec2(20.0, 0.0))]); + assert_eq!(effect(&panel.app()).1, start, "the held drag shows the effect as it began"); + panel.release(); + assert_eq!(effect(&panel.app()).1, start); + assert_eq!(undo_len(&panel.app()), history); +} + fn selected_materials(app: &VectorcraftApp) -> Vec { let st = app.session.active().unwrap(); st.selection diff --git a/crates/ui-egui/src/panels/three_d.rs b/crates/ui-egui/src/panels/three_d.rs index 16b300b010..cacaef0ec8 100644 --- a/crates/ui-egui/src/panels/three_d.rs +++ b/crates/ui-egui/src/panels/three_d.rs @@ -265,6 +265,9 @@ pub(crate) fn apply(app: &mut VectorcraftApp, params: &[Param], input: &DialogFi let mut settings = form::json_of(params, fields); for (field, _, _) in materials::MATERIAL_KEYS { if let Some(value) = fields.number(field) { + // The Properties fields stand for `material`: an object that only writes out a + // default it left out is not a change. + settings.remove(vectorcraft_effects::MATERIAL); settings.insert(field.into(), json!(value)); } } @@ -283,11 +286,26 @@ pub(crate) fn apply(app: &mut VectorcraftApp, params: &[Param], input: &DialogFi } EditEvent::Update { value, .. } => { let changed = changed_settings(&app.three_d.before, &settings(value)); - send(app, changed, Live::Dragging); + if changed.is_empty() && !app.three_d.pending.is_empty() && !selection_moved(app) { + // Back where it began: the document returns to its state before the preview, and the + // gesture goes on. + app.three_d.pending.clear(); + app.session.cancel_interaction().ok(); + app.sync_views(); + } else { + let changed = returned(app, changed); + send(app, changed, Live::Dragging); + } } EditEvent::Commit { after, .. } => { let changed = changed_settings(&app.three_d.before, &settings(after)); - send(app, changed, Live::Released); + if changed.is_empty() && !selection_moved(app) { + // Back where it began: the preview is rolled back and no undo step is recorded. + rollback(app); + } else { + let changed = returned(app, changed); + send(app, changed, Live::Released); + } } EditEvent::Set { after, .. } => set = Some(after), EditEvent::Cancel { reason, .. } => { @@ -618,6 +636,23 @@ pub(crate) fn mark_mixed(app: &VectorcraftApp, fields: &mut DialogFields) { } } +/// Whether the selection is no longer the one the gesture in progress started with. +fn selection_moved(app: &VectorcraftApp) -> bool { + let selection: Vec = app.session.active().map(|st| st.selection.objects.iter().map(|id| id.0).collect()).unwrap_or_default(); + app.three_d.plan.as_ref().is_some_and(|p| p.selection != selection) +} + +/// Drops from the gesture's previewed settings each one that `changed` no longer holds (it is back at +/// its value from when the gesture began), so the next preview, which starts again from the document +/// as it was, leaves it as it was stored. A selection that moved keeps them: the gesture's objects are +/// committed first with what they previewed. Returns `changed`. +fn returned(app: &mut VectorcraftApp, changed: Map) -> Map { + if !selection_moved(app) { + app.three_d.pending.retain(|key, _| changed.contains_key(key)); + } + changed +} + /// The settings whose values differ between `before` and `after`, with their values in `after`. /// A change to a custom bevel (`bevel` `"custom"`, its name or its points) sends all three, so an /// effect of a mixed selection that had none takes the whole bevel. diff --git a/docs/effects-parity.md b/docs/effects-parity.md index 317868dcd7..8d617537e6 100644 --- a/docs/effects-parity.md +++ b/docs/effects-parity.md @@ -180,7 +180,7 @@ VectorCraft choices; an original approximation, never compared with another appl |---|---| | Revolve | initial: live, editable profile, rotation and light gizmos, default-on Cap with continuous curved rims that also closes a partial sweep's cut sides, smooth vector shading and round seam joins, overlapping faces drawn in the order of their depths where they overlap, a ring of them broken at one of its own faces, SVG/PDF output, Expand Appearance ([revolve.md](revolve.md), #846) | | Extrude & Bevel, Inflate, Rotate | initial: live, round seam joins, a ring of overlapping faces broken at one of its own faces (Extrude & Bevel and Inflate), depth, twist, taper, solid or hollow caps, five original bevel shapes and custom bevels drawn as open paths in the bevels file ([add custom bevel paths](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/create-3d-graphics/add-custom-bevel-paths.html), [three-d.md](three-d.md#custom-bevels)), 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; shadows behind or below the object from the first light, blurred by its Softness ([three-d.md](three-d.md#shadows)); the Materials tab's Graphics, document symbols mapped onto Extrude & Bevel's caps and onto a plane, moved with an artboard handle, and wrapped around Extrude & Bevel's walls and bevels and around Revolve's side, and carried onto Inflate's puffed front and back ([three-d.md](three-d.md#graphics)); the Materials tab's Properties, Roughness and Metallic from 0 to 1, shaded with glTF 2.0's metallic-roughness BRDF and written into glTF and USD exports ([three-d.md](three-d.md#material-properties)); no base materials or ray tracing | +| Materials panel, lighting, ray-traced render | Window › 3D and Materials panel with the object types (Plane, Extrude, Revolve, Inflate) and the Object, Rotation and Lighting settings of the applied effect, 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; shadows behind or below the object from the first light, blurred by its Softness ([three-d.md](three-d.md#shadows)); the Materials tab's Graphics, document symbols mapped onto Extrude & Bevel's caps and onto a plane, moved with an artboard handle, and wrapped around Extrude & Bevel's walls and bevels and around Revolve's side, and carried onto Inflate's puffed front and back ([three-d.md](three-d.md#graphics)); the Materials tab's Properties, Roughness and Metallic from 0 to 1, shaded with glTF 2.0's metallic-roughness BRDF and written into glTF and USD exports ([three-d.md](three-d.md#material-properties)); no base-material library or ray tracing | | 3D (Classic): Extrude & Bevel, Revolve, Rotate | Extrude & Bevel (Classic) initial: live, round seam joins, Extrude Depth, Cap, five original bevel shapes and the custom bevels 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)); all three: a lighting sphere on the Lighting tab whose lights drag, move to the back or front, and are added at the front center or deleted down to one ([lighting options](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=272)); all three: the track cube (face, edge, Shift and ring drags, keyboard steps; [three-d.md](three-d.md#track-cube)); Map Art for Extrude & Bevel (Classic) and Revolve (Classic): one document symbol on each numbered surface, surface navigation with visible and hidden marks and a red outline on the artboard, move, scale and rotate on the surface laid out flat, Scale to Fit, Clear, Clear All, Shade Artwork, Invisible Geometry, kept by Expand Appearance and exports, `threeD.mapArt` ([map artwork to a 3D object](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=189)) | | Turntable (30.0 beta) | none | | Export 3D objects (OBJ, USDA, glTF) | initial: Asset Export's Export 3D Object, and the 3D and Materials panel's Export 3D Object button (which then shows Asset Export with the new assets selected, [three-d.md](three-d.md#3d-and-materials-panel)), collect 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`); graphics mapped onto a plane or Extrude & Bevel's caps are exported as PNG textures of those faces, flat and unlit, and the graphics on Revolve's side as a texture of the side unrolled; every corner carries texture coordinates and a normal, smoothed across a curved bevel and over Inflate's puff ([three-d.md](three-d.md#3d-meshes)); glTF and USD carry each solid's Roughness and Metallic as its roughness and metallic factors ([three-d.md](three-d.md#material-properties)); no other materials and no lighting ([3D export help](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/create-3d-graphics/export-3d-vector-artwork.html)) | diff --git a/docs/mcp.md b/docs/mcp.md index 7f39ec7d82..e2ffe5008b 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -6475,9 +6475,10 @@ limits, so art too complex for the shaded surface does not refuse the wireframe. Revolve, Extrude & Bevel, Inflate and Rotate take `material`, an object with `roughness` (0..1, default 1) and `metallic` (0..1, default 0), the Roughness and Metallic of **Window › 3D and Materials** › Materials › Properties, set with `effect.apply` or `effect.setParams` in one undo step. A key left out takes its default. The default -material draws the surface as it was drawn before materials existed; any other material shades it with glTF 2.0's -metallic-roughness BRDF and screens the reflected light over each face. Export 3D Object writes the two values as -glTF's `roughnessFactor` and `metallicFactor` and USD's `inputs:roughness` and `inputs:metallic`. A `material` that +material draws the surface as it was drawn before materials existed; in shaded rendering (`shade` true, not +Wireframe) any other material shades it with glTF 2.0's metallic-roughness BRDF and screens the reflected light +over each face. Export 3D Object writes the two values as glTF's `roughnessFactor` and `metallicFactor` and USD's +`inputs:roughness`, and writes USD's `inputs:metallic` only when Metallic is not 0 (USD reads a missing value as 0). A `material` that is not an object, a key other than `roughness` and `metallic`, a value that is not a number from 0 to 1, and `material` on Extrude & Bevel (Classic), Revolve (Classic) or Rotate (Classic) are refused before the document changes. See [three-d.md](three-d.md#material-properties). diff --git a/docs/three-d.md b/docs/three-d.md index f30b170747..ff01d818ef 100644 --- a/docs/three-d.md +++ b/docs/three-d.md @@ -76,7 +76,7 @@ pages describe it. and ranges, showing the 3D effect of the first selected object (its own effects first, then those of its fills and strokes). A changed setting goes to the 3D effect of each selected object whose effect takes that setting; other effects and objects without a 3D effect do not change. A setting the selected 3D effects hold with - different values shows its default with its reset dot filled; a checkbox shows a dash instead, and a mixed + different values has its reset dot filled; a number is shown blank, a checkbox shows a dash, and a mixed Shading leaves the light settings available. Its reset dot, a choice from its menu or a click on its checkbox (which turns a mixed one on) sets it on all of them; a typed or dragged number sets it when it differs from the default shown. Other changes leave it as each effect has it.