mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-16 12:03:31 +00:00
Merge pull request #7883 from dotCooCoo/feat/3d-bevel-reset
3D and Materials: the Bevel section's Reset restores only the bevel settings
This commit is contained in:
@@ -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<String, Value> {
|
||||
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<String, Value>) -> 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, and the
|
||||
/// classic 3D effects, which have the track cube below the presets.
|
||||
fn view_controls(ui: &mut egui::Ui, d: &mut Dialog) {
|
||||
|
||||
@@ -578,6 +578,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] {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -601,6 +601,7 @@ since 2026-10-01.
|
||||
- 3D shadows: a command that applies or edits Extrude & Bevel, Inflate or Rotate with Shadows on checks the shadow from the faces kept by the builds that check the solids, as drawing casts it, so it builds each solid once instead of building it again for the shadow. A stroke whose solid is left out of the art past its own limits casts no shadow. Evidence: `solids::tests::the_check_builds_each_drawn_solid_once`, `solids::tests_shadow::a_stroke_left_out_of_the_art_casts_no_shadow`, `solids::tests_shadow::the_check_accepts_the_shadowed_objects_that_draw`. 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 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.
|
||||
|
||||
@@ -110,6 +110,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
|
||||
|
||||
Reference in New Issue
Block a user