diff --git a/crates/ui-egui/src/dialogs/revolve.rs b/crates/ui-egui/src/dialogs/revolve.rs index 8978805ac8..885135bf18 100644 --- a/crates/ui-egui/src/dialogs/revolve.rs +++ b/crates/ui-egui/src/dialogs/revolve.rs @@ -248,7 +248,7 @@ fn extrude_controls(ui: &mut egui::Ui, d: &mut Dialog, unit: Unit) { number(ui, d, "taper", tl!("Taper"), (1.0, 100.0), "%", 1, None); choice(ui, d, "cap", c3("Cap"), &[(json!(true), c3("Solid")), (json!(false), c3("Hollow"))]); ui.add_space(10.0); - heading(ui, c3("Bevel")); + bevel_heading(ui, d); let shapes: Vec<(Value, &str)> = super::effect::own_choices(EXTRUDE, "bevel", false).unwrap_or_default().into_iter().map(|(label, value)| (json!(value), label)).collect(); choice(ui, d, "bevel", tl!("Bevel Shape"), &shapes); @@ -262,6 +262,53 @@ fn extrude_controls(ui: &mut egui::Ui, d: &mut Dialog, unit: Unit) { }); } +/// Extrude & Bevel's bevel settings (every parameter named `bevel…`) with their defaults. +fn bevel_defaults() -> serde_json::Map { + match vectorcraft_effects::default_params(EXTRUDE) { + Some(Value::Object(m)) => m.into_iter().filter(|(k, _)| k.starts_with("bevel")).collect(), + _ => serde_json::Map::new(), + } +} + +/// Does any setting in `defaults` differ from its default in `d`? A setting the 3D and Materials +/// panel's selected effects hold with different values (null) counts as changed. +fn differs_from(d: &Dialog, defaults: &serde_json::Map) -> bool { + defaults.iter().any(|(k, v)| match (d.fields.get(k), v.as_f64()) { + (Some(Value::Null), _) => true, + (_, Some(default)) => (d.f64(k, default) - default).abs() > 1e-6, + (field, None) => field.is_some_and(|f| f != v), + }) +} + +/// The Bevel heading with its Reset button, which puts every bevel setting back to its default and +/// leaves the other settings as they are. The button is off while every bevel setting is at its +/// default. +fn bevel_heading(ui: &mut egui::Ui, d: &mut Dialog) { + let defaults = bevel_defaults(); + let changed = differs_from(d, &defaults); + let mut reset = false; + ui.horizontal(|ui| { + heading(ui, c3("Bevel")); + ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { + ui.add_enabled_ui(changed, |ui| { + let t = Tokens::get(ui.ctx()); + let (r, _) = ui.allocate_exact_size(vec2(56.0, 20.0), Sense::hover()); + let response = ui.interact(r, Id::unique("revolve-reset-bevel"), Sense::click()); + response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, ui.is_enabled(), tl!("Reset"))); + if response.hovered() { + ui.painter().rect_filled(r, 3.0, t.hover); + } + let color = if ui.is_enabled() { t.text } else { t.text_disabled }; + ui.painter().text(r.right_center() - vec2(4.0, 0.0), Align2::RIGHT_CENTER, tl!("Reset"), FontId::proportional(11.5), color); + reset = response.clicked(); + }); + }); + }); + if reset { + d.fields.extend(defaults); + } +} + /// Rotation presets, rotation and perspective for Extrude & Bevel, Inflate and Rotate. fn view_controls(ui: &mut egui::Ui, d: &mut Dialog) { heading(ui, tl!("Rotation")); diff --git a/crates/ui-egui/src/dialogs/revolve/tests.rs b/crates/ui-egui/src/dialogs/revolve/tests.rs index fd802f83f0..1a879f2618 100644 --- a/crates/ui-egui/src/dialogs/revolve/tests.rs +++ b/crates/ui-egui/src/dialogs/revolve/tests.rs @@ -472,6 +472,42 @@ fn extrude_bevel_options_enable_with_a_bevel_shape() { assert_eq!(h.response(("revolve-reset", "bevelWidth")), width); } +#[test] +fn the_bevel_reset_restores_the_bevel_settings_and_keeps_the_others() { + let mut h = Harness::with("M100 100 L200 100 L200 200 L100 200 Z", vectorcraft_effects::EXTRUDE, vec2(1400.0, 1000.0)); + let before = h.app.session.doc().unwrap().doc.clone(); + h.settle(); + let enabled = |h: &Harness| h.ctx.read_response(Id::unique("revolve-reset-bevel")).unwrap().enabled(); + assert!(!enabled(&h), "every bevel setting at its default: Reset is off"); + let changed = json!({"bevel": "step", "bevelWidth": 12.0, "bevelHeight": 3.0, "bevelRepeat": 4, "bevelSpace": 30.0, "bevelInside": true, "bevelBothSides": true, "depth": 90.0, "twist": 45.0, "rotationX": 10.0}); + h.app.ui.dialog.as_mut().unwrap().fields.extend(changed.as_object().unwrap().clone()); + h.settle(); + assert!(enabled(&h)); + h.click(h.response("revolve-reset-bevel").center()); + let defaults = vectorcraft_effects::default_params(vectorcraft_effects::EXTRUDE).unwrap(); + let dialog = h.app.ui.dialog.as_ref().unwrap(); + for key in ["bevel", "bevelWidth", "bevelHeight", "bevelRepeat", "bevelSpace", "bevelInside", "bevelBothSides"] { + assert_eq!(dialog.fields.get(key), defaults.get(key), "reset: {key}"); + } + for key in ["depth", "twist", "rotationX"] { + assert_eq!(dialog.fields.get(key), changed.get(key), "kept: {key}"); + } + assert!(!enabled(&h), "Reset turns itself off"); + // One bevel setting off its default is enough to turn Reset on again. + h.app.ui.dialog.as_mut().unwrap().fields.insert("bevelBothSides".into(), json!(true)); + h.settle(); + assert!(enabled(&h)); + dialogs::confirm(&mut h.app).unwrap(); + let state = h.app.session.doc().unwrap(); + let params = vectorcraft_effects::merged_params( + vectorcraft_effects::EXTRUDE, + &state.doc.node(state.selection.objects[0]).unwrap().appearance.effects[0].params, + ); + assert_eq!((params["depth"].clone(), params["bevelBothSides"].clone(), params["bevel"].clone()), (json!(90.0), json!(true), json!("none"))); + h.app.run("edit.undo", json!({})).unwrap(); + assert_eq!(h.app.session.doc().unwrap().doc, before); +} + #[test] fn cap_checkbox_previews_resets_and_respects_cancel_and_one_step_undo() { for confirm in [false, true] { diff --git a/crates/ui-egui/src/panels/tests_three_d.rs b/crates/ui-egui/src/panels/tests_three_d.rs index 6146bc4852..b5e08663e7 100644 --- a/crates/ui-egui/src/panels/tests_three_d.rs +++ b/crates/ui-egui/src/panels/tests_three_d.rs @@ -426,6 +426,49 @@ fn a_mixed_checkbox_shows_a_dash_and_another_change_keeps_each_effects_value() { assert!(named(&controls(&mut app, &ctx), "Add Light").is_disabled()); } +/// The Bevel heading's Reset sets every bevel setting back to its default on each selected Extrude & +/// Bevel, as one undo step, and leaves Depth and the rotation as each effect has them. With every +/// bevel setting at its default it is off and records nothing. +#[test] +fn the_bevel_reset_restores_only_the_bevel_settings_of_each_selected_effect() { + use crate::panels::tests_appearance::click; + let mut app = app(); + let bevelled = json!({"bevel": "rounded", "bevelWidth": 9.0, "bevelHeight": 6.0, "bevelRepeat": 3, "bevelSpace": 20.0, "bevelInside": true, "bevelBothSides": true, "depth": 70.0, "rotationX": 15.0}); + app.run("effect.apply", json!({"effect": "threeD.extrude", "item": null, "params": bevelled})).unwrap(); + let a = app.session.active().unwrap().selection.objects[0].0; + let b = app.run("shape.rectangle", json!({"x": 250, "y": 100, "width": 100, "height": 100})).unwrap()["id"].as_u64().unwrap(); + app.run("effect.apply", json!({"effect": "threeD.extrude", "item": null, "params": {"bevel": "cove", "bevelWidth": 2.0, "depth": 30.0}})) + .unwrap(); + app.run("select.set", json!({"ids": [a, b]})).unwrap(); + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + ctx.enable_accesskit(); + let nodes = controls(&mut app, &ctx); + let reset = named(&nodes, "Reset"); + assert!(!reset.is_disabled(), "changed bevel settings turn Reset on"); + let at = reset.bounds().map(|r| egui::pos2(((r.x0 + r.x1) / 2.0) as f32, ((r.y0 + r.y1) / 2.0) as f32)).unwrap(); + let history = undo_len(&app); + click(&ctx, &mut app, at, show); + assert_eq!(undo_len(&app), history + 1, "one undo step for both objects"); + let defaults = vectorcraft_effects::default_params("threeD.extrude").unwrap(); + let merged = |app: &VectorcraftApp, id: u64| { + let params = app.session.active().unwrap().doc.node(vectorcraft_doc::NodeId(id)).unwrap().appearance.effects[0].params.clone(); + vectorcraft_effects::merged_params("threeD.extrude", ¶ms) + }; + for id in [a, b] { + for key in ["bevel", "bevelWidth", "bevelHeight", "bevelRepeat", "bevelSpace", "bevelInside", "bevelBothSides"] { + assert_eq!(merged(&app, id)[key], defaults[key], "{key} of {id}"); + } + } + assert_eq!((merged(&app, a)["depth"].clone(), merged(&app, b)["depth"].clone()), (json!(70.0), json!(30.0))); + assert_eq!(merged(&app, a)["rotationX"], 15.0); + let nodes = controls(&mut app, &ctx); + assert!(named(&nodes, "Reset").is_disabled(), "every bevel setting at its default: Reset is off"); + let history = undo_len(&app); + click(&ctx, &mut app, at, show); + assert_eq!(undo_len(&app), history, "an unavailable Reset records nothing"); +} + /// Revolve's Cap checkbox shows a dash when the selected effects disagree on it. #[test] fn a_mixed_revolve_cap_shows_a_dash() { diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 72de21a43c..ee77be41e0 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -594,6 +594,7 @@ since 2026-10-01. - 3D shadows: with Shadows on, Revolve, Extrude & Bevel, Inflate and Rotate cast the shadow from the faces kept by the build that draws each solid, so drawing an object builds each of its solids once. The art and the shadow are unchanged. Evidence: `crates/three-d/src/shadow/tests.rs` (`a_solid_and_its_shadow_are_built_once` and the tests that compare each solid and its shadow with the two built apart), `solids::tests_shadow::a_shadowed_3d_object_builds_each_solid_once`, `solids::tests_shadow::the_shadow_cast_from_the_solids_drawn_is_the_shadow_of_solids_built_for_it`, `revolve::tests::the_shadow_cast_from_the_surfaces_drawn_is_the_shadow_of_surfaces_swept_for_it`. Scores unchanged. - 3D shadows: in Revolve, Extrude & Bevel, Inflate and Rotate, a fill, stroke or member whose opacity is NaN or infinite casts no part of the shadow, as one at 0 % does, whether the shadow is cast from the solids drawn or from solids built for it alone; the art beside it still casts. This is VectorCraft's own rule. Evidence: `solids::tests_shadow::art_whose_opacity_is_not_a_finite_number_casts_no_shadow`, `revolve::tests::a_surface_whose_opacity_is_not_a_finite_number_casts_no_shadow`. Scores unchanged. - Window › 3D and Materials panel: `crates/ui-egui/src/panels/three_d.rs` applies a 3D effect by object type (Plane, Extrude, Revolve, Inflate), changes an applied one in place (`effect.setParams` `threeDType`) and edits it with the options dialog's Object, Rotation and Lighting controls, one undo step per change; `crates/engine/src/cmd/effectcmd/three_d_type_tests.rs` and `crates/ui-egui/src/panels/tests_three_d.rs` cover it. No Materials tab. +- 3D and Materials › Object › Bevel › Reset: the button next to Extrude & Bevel's Bevel heading, in the options dialog and the panel, sets Bevel Shape, Width, Height, Repeat, Space, Bevel Inside and Bevel both sides back to their defaults and leaves the other settings as they are, as one undo step in the panel; it is unavailable while every bevel setting is at its default ([three-d.md](three-d.md#extrude--bevel)); `crates/ui-egui/src/dialogs/revolve/tests.rs` and `crates/ui-egui/src/panels/tests_three_d.rs` cover it. Scores and hours unchanged. - 3D and Materials › Quick Actions › Expand as Wireframes (#6354): `effect.expandAsWireframes` replaces each selected 3D object with a group of 0.5 pt black stroked paths, the edges of the faces its effect draws, each edge once and joined end to end, curves kept, in one undo step ([three-d.md](three-d.md#3d-and-materials-panel)); `crates/effects/src/solids/wireframe/tests.rs`, `crates/engine/src/cmd/wireframe/tests.rs` and `crates/ui-egui/src/panels/tests_three_d.rs` cover it. Scores and hours unchanged. - 3D and Materials › Render Settings › Wireframe: `render: {mode: "wireframe"}` on Extrude & Bevel, Revolve, Inflate and Rotate draws the live effect as the edges of its faces, 0.5 pt black strokes with no shadow, in every output and in Expand Appearance ([three-d.md](three-d.md#3d-and-materials-panel)); `crates/effects/src/solids/wireframe/tests.rs` and `crates/ui-egui/src/panels/tests_three_d.rs` cover it. Scores and hours unchanged. - 3D effects on clipping groups, blends and symbol instances (#6140, #5725): every 3D type builds from the art the object shows (the art inside the clipping path, the blend's keys and steps, the symbol's art where the instance places it), alone or in a group, on the canvas, in exports, Object › Rasterize and `assets.add3D`; an image is refused with a pointer to Object › Image Trace › Make. `crates/effects/src/solids/tests_sources.rs`, `crates/engine/src/cmd/effectcmd/three_d_source_tests.rs` and `fx::tests::a_symbol_instance_a_blend_and_a_clipping_group_draw_their_solids` cover it. Scores and estimates unchanged. diff --git a/docs/three-d.md b/docs/three-d.md index 2861bee0b7..37693c6e0a 100644 --- a/docs/three-d.md +++ b/docs/three-d.md @@ -100,6 +100,7 @@ object is where the art was. | Repeat, Space | The cross-section repeated 1–32 times across the width, with a share (0–90 %) of the width flat between repeats. | | Bevel Inside | The bevel carved into the shape (the front face shrinks) instead of added around it (the walls stand outside the art). | | Bevel both sides | The back is bevelled too. | +| Reset | Next to the Bevel heading, in the dialog and the panel. It sets every bevel setting above back to its default (Bevel Shape None, Width and Height 4 pt, Repeat 1, Space 0 %, both checkboxes off) and leaves Depth, Twist, Taper, Cap, the rotation, the lights and the graphics as they are, as the public [3D and Materials panel options](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/create-3d-graphics/3d-materials-panel-options.html) page describes. In the panel it sets them on each selected Extrude & Bevel as one undo step. It is unavailable while every bevel setting is at its default. | Holes stay holes, with walls of their own. Bevels move each corner along its bisector. A corner the bevel opens (a sharp point with the bevel outside, a narrow notch with it inside) whose miter would reach past four times the width is