3D (Classic): the lighting sphere moves, adds and deletes lights on the Lighting tab

The Lighting tab of Extrude & Bevel (Classic), Revolve (Classic) and
Rotate (Classic) now shows the lighting sphere, in the 3D and Materials
panel and in the options dialog, while the surface is Diffuse or
Plastic. A light drags to a new Rotation and Height, a press selects
it, and the button below the sphere moves it behind or in front of the
object. Add Light places a new light at the front center and Delete
Light keeps at least one light. The classic effects shade without light
color, so their suns are drawn white.
This commit is contained in:
dotCooCoo
2026-11-15 06:55:20 -08:00
parent 3075889f0c
commit 6d87660fd0
6 changed files with 149 additions and 28 deletions
+32 -13
View File
@@ -52,6 +52,22 @@ impl Harness {
}
}
/// Scrolls the dialog's body to its end with the wheel over `text`, and lets the scroll finish.
fn scroll_to_end(&mut self, text: &str) {
let p = self.rect(text).center();
let wheel = Event::MouseWheel {
unit: egui::MouseWheelUnit::Point,
delta: vec2(0.0, -4000.0),
phase: egui::TouchPhase::Move,
modifiers: Default::default(),
source: egui::MouseWheelSource::Unknown,
};
self.frame(vec![Event::PointerMoved(p), wheel]);
for _ in 0..60 {
self.frame(vec![]);
}
}
fn rect(&self, text: &str) -> Rect {
self.texts.iter().find(|(s, _)| s == text).map(|(_, r)| *r).unwrap_or_else(|| panic!("missing text {text:?}"))
}
@@ -338,17 +354,12 @@ fn classic_extrude_bevel_shows_its_options_and_applies_as_one_step() {
}
h.click(h.rect("Lighting").center());
h.settle();
for text in [
"Surface",
"Plastic",
"Light Intensity",
"Ambient Light",
"Highlight Intensity",
"Highlight Size",
"Blend Steps",
"Shading Color",
"Draw Hidden Faces",
] {
for text in ["Surface", "Plastic", "Move Light to Back", "Light Intensity"] {
h.rect(text);
}
// The lighting sphere makes the tab taller than the dialog's body, which scrolls.
h.scroll_to_end("Light Intensity");
for text in ["Ambient Light", "Highlight Intensity", "Highlight Size", "Blend Steps", "Shading Color", "Draw Hidden Faces"] {
h.rect(text);
}
assert!(h.ctx.read_response(Id::unique(("revolve-reset", "highlightSize"))).unwrap().enabled());
@@ -399,7 +410,11 @@ fn classic_revolve_shows_its_options_and_applies_as_one_step() {
}
h.click(h.rect("Lighting").center());
h.settle();
for text in ["Surface", "Plastic", "Light Intensity", "Ambient Light", "Highlight Size", "Blend Steps", "Shading Color"] {
for text in ["Surface", "Plastic", "Move Light to Back", "Light Intensity"] {
h.rect(text);
}
h.scroll_to_end("Light Intensity");
for text in ["Ambient Light", "Highlight Size", "Blend Steps", "Shading Color"] {
h.rect(text);
}
assert!(!h.texts.iter().any(|(t, _)| t == "Draw Hidden Faces"), "every face is drawn");
@@ -437,7 +452,11 @@ fn classic_rotate_shows_its_options_and_applies_as_one_step() {
assert!(!h.texts.iter().any(|(t, _)| t == "Object" || t == "Depth" || t == "Angle"), "no Object tab");
h.click(h.rect("Lighting").center());
h.settle();
for text in ["Surface", "Diffuse", "Light Intensity", "Ambient Light", "Blend Steps", "Shading Color"] {
for text in ["Surface", "Diffuse", "Move Light to Back", "Light Intensity"] {
h.rect(text);
}
h.scroll_to_end("Light Intensity");
for text in ["Ambient Light", "Blend Steps", "Shading Color"] {
h.rect(text);
}
assert!(
+14 -5
View File
@@ -1,6 +1,8 @@
//! The lighting widget on the 3D and Materials panel's Lighting tab for Extrude & Bevel, Revolve,
//! Inflate and Rotate: a sphere that shows each of the effect's lights
//! Inflate and Rotate, and on the Lighting tab of the 3D (Classic) effects in both the panel and the
//! options dialog: a sphere that shows each of the effect's lights
//! at its Rotation and Height, a filled sun in front of the object and a hollow one behind it.
//! The 3D (Classic) effects' lights have no color, so their suns are white.
//! Dragging a light moves it on its side of the object, a press selects it in the list of lights,
//! and the button below the sphere moves the selected light to the back or the front of the object.
//! Each light takes the keyboard focus, where the arrow keys move it, and has a name for screen
@@ -82,15 +84,20 @@ fn round(n: f64) -> f64 {
}
/// The effect's lights: each light of its list, or its single light, with the effect's defaults for
/// the settings a light leaves out or the selected effects hold with different values (null).
/// the settings a light leaves out or the selected effects hold with different values (null). A 3D
/// (Classic) effect's lights are white whatever color a list light carries, since it shades
/// without light color.
pub(crate) fn lights(d: &Dialog) -> Vec<Light> {
let defaults = vectorcraft_effects::default_params(&d.str("__effect")).unwrap_or(json!({}));
let effect = d.str("__effect");
let colored = !vectorcraft_effects::is_classic_three_d(&effect);
let defaults = vectorcraft_effects::default_params(&effect).unwrap_or(json!({}));
let list = explicit_lights(d).cloned().unwrap_or_else(|| vec![light_record(d)]);
list.iter()
.map(|light| {
let value =
|key: &str, field: &str| light.get(key).filter(|v| !v.is_null()).or_else(|| defaults.get(field)).cloned().unwrap_or(Value::Null);
let [r, g, b] = value("color", "lightColor")
let color = if colored { value("color", "lightColor") } else { Value::Null };
let [r, g, b] = color
.as_str()
.filter(|s| s.len() == 7 && s.starts_with('#'))
.and_then(vectorcraft_color::Color::from_hex)
@@ -143,10 +150,12 @@ pub(super) fn show(ui: &mut egui::Ui, d: &mut Dialog) {
let order = (0..lights.len()).filter(|&i| i != current).chain([current]);
let mut moved = None;
let enabled = ui.is_enabled();
// The panel and a 3D (Classic) options dialog can both show the sphere at once.
let panel = d.bool("__panel");
for index in order {
let light = lights.get(index).copied().unwrap_or(first);
let at = center + light.offset() * radius;
let id = Id::unique(("three-d-lighting-widget", index));
let id = Id::unique(("three-d-lighting-widget", panel, index));
let response = ui.interact(Rect::from_center_size(at, Vec2::splat((SUN + 4.0) * 2.0)), id, Sense::click_and_drag());
response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Slider, enabled, light.name(index)));
// A light the pointer took, or that the keyboard focus reached, becomes the selected light and
@@ -1,7 +1,7 @@
//! The own controls of Extrude & Bevel (Classic), Revolve (Classic) and Rotate (Classic) in the
//! compact 3D dialog: the extrude and bevel options, or the revolve options, on the Object tab
//! (Rotate (Classic) has none), and the surface with its lights, highlight, blend steps, shading
//! color and Preserve Spot Colors on the Lighting tab. Position (presets, rotation, perspective) is the Rotation tab every 3D
//! (Rotate (Classic) has none), and the surface with its lighting sphere, lights, highlight, blend
//! steps, shading color and Preserve Spot Colors on the Lighting tab. Position (presets, rotation, perspective) is the Rotation tab every 3D
//! effect shares.
use serde_json::{Value, json};
@@ -40,16 +40,18 @@ pub(super) fn revolve_controls(ui: &mut egui::Ui, d: &mut Dialog, unit: Unit) {
choice(ui, d, "edge", tl!("Axis side"), &sides);
}
/// The surface, then for Diffuse and Plastic the lights, Ambient Light, the highlight (Plastic
/// only, and not for Rotate (Classic), which has no Plastic surface), Blend Steps, Shading Color and
/// Preserve Spot Colors (unavailable while Shading Color is Custom); Draw Hidden Faces last, for Extrude & Bevel (Classic) (Revolve (Classic) draws every face, and
/// Rotate (Classic)'s plane is seen from either side).
/// The surface, then for Diffuse and Plastic the lighting sphere, the lights, Ambient Light, the
/// highlight (Plastic only, and not for Rotate (Classic), which has no Plastic surface), Blend Steps,
/// Shading Color and Preserve Spot Colors (unavailable while Shading Color is Custom); Draw Hidden
/// Faces last, for Extrude & Bevel (Classic) (Revolve (Classic) draws every face, and Rotate
/// (Classic)'s plane is seen from either side). The sphere shows in the dialog as well as in the panel.
pub(super) fn surface_controls(ui: &mut egui::Ui, d: &mut Dialog) {
let id = d.str("__effect");
let effect = if id == CLASSIC_ROTATE { CLASSIC_ROTATE } else { CLASSIC_EXTRUDE };
choice(ui, d, "surface", tl!("Surface"), &options_of(effect, "surface"));
let surface = d.str("surface");
ui.add_enabled_ui(surface == "diffuse" || surface == "plastic", |ui| {
super::revolve_lights::show(ui, d);
light_list(ui, d);
let mut selected = selected_light(d);
let before = light_record(&selected);
+85 -1
View File
@@ -839,9 +839,15 @@ fn quick_actions_show_on_the_object_tab_only() {
/// An app with an Extrude & Bevel square given `params`, and the panel on its Lighting tab with the
/// accessibility tree on.
fn lighting_app(params: Value) -> (VectorcraftApp, egui::Context) {
lighting_app_of("threeD.extrude", params)
}
/// An app with a square given 3D effect `effect` with `params`, and the panel on its Lighting tab
/// with the accessibility tree on.
fn lighting_app_of(effect: &str, params: Value) -> (VectorcraftApp, egui::Context) {
use crate::panels::tests_appearance::{click, frame_events, text_rect};
let mut app = app();
app.run("effect.apply", json!({"effect": "threeD.extrude", "item": null, "params": params})).unwrap();
app.run("effect.apply", json!({"effect": effect, "item": null, "params": params})).unwrap();
let ctx = egui::Context::default();
crate::theme::install_fonts(&ctx);
ctx.enable_accesskit();
@@ -1026,6 +1032,84 @@ fn the_arrow_keys_move_the_light_pressed_last() {
assert_eq!(rotations, [json!(0.0), json!(-179.0)]);
}
/// The Lighting tab of Extrude & Bevel (Classic) has the lighting sphere: dragging its light is one
/// undo step, the button below it moves the light behind the object, Add Light adds a light at the
/// front center of the sphere, and Delete Light removes the selected light but never the last one.
#[test]
fn the_classic_lighting_tab_has_the_lighting_sphere() {
use crate::dialogs::revolve_lights::RADIUS;
use crate::panels::tests_appearance::{click, frame_events, text_rect};
use vectorcraft_effects::CLASSIC_EXTRUDE;
let (mut app, ctx) = lighting_app_of(CLASSIC_EXTRUDE, json!({}));
let (name, from) = light_node(&mut app, &ctx, 1);
assert_eq!(name, "Light 1: Rotation 125.3°, Height 30.0°");
let light = crate::dialogs::revolve_lights::lights(&crate::state::Dialog::new(
"x",
json!({"__effect": CLASSIC_EXTRUDE, "lightRotation": vectorcraft_three_d::DEFAULT_LIGHT.0, "lightHeight": 30.0}),
))[0];
let center = from - light.offset() * RADIUS;
let history = undo_len(&app);
let rim = center + egui::vec2(RADIUS, 0.0);
for event in [pointer(from, None), pointer(from, Some(true)), pointer(rim, None)] {
frame_events(&ctx, &mut app, vec![event], show);
}
assert_eq!(merged_light(&app), (0.0, 0.0), "the light follows the pointer while it is down");
assert_eq!(undo_len(&app), history);
frame_events(&ctx, &mut app, vec![pointer(rim, Some(false))], show);
frame_events(&ctx, &mut app, vec![], show);
assert_eq!(undo_len(&app), history + 1);
let texts = frame_events(&ctx, &mut app, vec![], show);
click(&ctx, &mut app, text_rect(&texts, "Move Light to Back").center(), show);
assert_eq!(undo_len(&app), history + 2);
assert_eq!(effect(&app).1["lightBehind"], json!(true));
let texts = frame_events(&ctx, &mut app, vec![], show);
click(&ctx, &mut app, text_rect(&texts, "Add Light").center(), show);
assert_eq!(undo_len(&app), history + 3);
let (name, _) = light_node(&mut app, &ctx, 2);
assert_eq!(name, "Light 2: Rotation 0.0°, Height 90.0°", "a new light is at the front center");
let count = |app: &VectorcraftApp| effect(app).1["lights"].as_array().map_or(1, Vec::len);
assert_eq!(count(&app), 2);
let texts = frame_events(&ctx, &mut app, vec![], show);
click(&ctx, &mut app, text_rect(&texts, "Delete Light").center(), show);
assert_eq!(count(&app), 1);
assert_eq!(undo_len(&app), history + 4);
let (name, _) = light_node(&mut app, &ctx, 1);
assert_eq!(name, "Light 1: Rotation 0.0°, Height 0.0°, Light behind the object", "the selected light was deleted");
// One light stays: Delete Light does nothing then.
let texts = frame_events(&ctx, &mut app, vec![], show);
click(&ctx, &mut app, text_rect(&texts, "Delete Light").center(), show);
assert_eq!(count(&app), 1);
assert_eq!(undo_len(&app), history + 4);
}
/// The 3D (Classic) options dialog shows the lighting sphere on its Lighting tab too, and the
/// sphere draws a 3D (Classic) effect's lights white, since those effects shade without light color.
#[test]
fn the_classic_options_dialog_has_the_lighting_sphere_with_white_lights() {
use crate::panels::tests_appearance::frame_events;
use vectorcraft_effects::{CLASSIC_REVOLVE, EXTRUDE};
let mut app = app();
app.run("effect.dialog", json!({"effect": CLASSIC_REVOLVE, "item": null})).unwrap();
app.ui.dialog.as_mut().unwrap().fields.insert("__gizmo".into(), json!("light"));
let ctx = egui::Context::default();
crate::theme::install_fonts(&ctx);
ctx.enable_accesskit();
let dialog = |app: &mut VectorcraftApp, ui: &mut egui::Ui| crate::dialogs::show(app, ui.ctx());
frame_events(&ctx, &mut app, vec![], dialog);
let mut out = ctx.run_ui(egui::RawInput::default(), |ui| dialog(&mut app, ui));
out.textures_delta.clear();
let nodes: Vec<_> = out.platform_output.accesskit_update.map(|u| u.nodes.into_iter().map(|(_, n)| n).collect()).unwrap_or_default();
assert!(
nodes.iter().any(|n| n.role() == egui::accesskit::Role::Slider && n.label() == Some("Light 1: Rotation 125.3°, Height 30.0°")),
"the dialog shows the sphere"
);
let red = json!([{"color": "#ff0000", "rotation": 0.0, "height": 30.0}]);
let color =
|effect: &str| crate::dialogs::revolve_lights::lights(&crate::state::Dialog::new("x", json!({"__effect": effect, "lights": red})))[0].color;
assert_eq!(color(CLASSIC_REVOLVE), egui::Color32::WHITE);
assert_eq!(color(EXTRUDE), egui::Color32::from_rgb(255, 0, 0));
}
#[test]
fn changed_settings_lists_only_new_values() {
let before = json!({"depth": 50.0, "cap": true, "bevel": "none"});
+1 -1
View File
@@ -181,7 +181,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, smooth vector shading and round seam joins, overlapping faces drawn in the order of their depths where they overlap, SVG/PDF output, Expand Appearance ([revolve.md](revolve.md), #846) |
| Extrude & Bevel, Inflate, Rotate | initial: live, round seam joins, depth, twist, taper, solid or hollow caps, five original bevel shapes, Inflate volume, both sides, twist, taper and cap, Rotate of every fill and stroke, groups and layers turned about one shared axis (#4506), contours that cross, touch or overlap merged first ([three-d.md](three-d.md)), Position presets, rotation and light gizmos, SVG/PDF output, Expand Appearance ([three-d.md](three-d.md)) |
| Materials panel, lighting, ray-traced render | Window › 3D and Materials panel with the object types (Plane, Extrude, Revolve, Inflate) and the Object, Rotation and Lighting settings of the applied effect, Render Settings › Wireframe, which draws the live effect as the edges of its faces, and Quick Actions › Expand as Wireframes ([three-d.md](three-d.md#3d-and-materials-panel)); one to ten directional lights with per-light Color (opaque RGB, white by default), Intensity, Rotation, Height, Softness and neutral Ambient Light, Revolve and colored Inflate use smooth vector shading; Extrude & Bevel and Rotate retain planar shading; original Standard, Diffuse, Top Left and Right lighting rigs; hard-edged shadows behind or below the object from the first light ([three-d.md](three-d.md#shadows)); the Materials tab's Graphics, document symbols mapped onto Extrude & Bevel's caps and onto a plane, moved with an artboard handle, and wrapped around Revolve's side ([three-d.md](three-d.md#graphics)); no base materials, graphics on Inflate or on Extrude & Bevel's walls and bevels, soft shadows or ray tracing |
| 3D (Classic): Extrude & Bevel, Revolve, Rotate | Extrude & Bevel (Classic) initial: live, round seam joins, Extrude Depth, Cap, five original bevel shapes with Height and Bevel Extent In or Out, Position presets and rotation gizmo, Perspective, Wireframe, No Shading, Diffuse and Plastic surfaces with one to ten lights, Light Intensity, Ambient Light, Highlight Intensity and Size, Blend Steps, Black, Custom or no Shading Color, Draw Hidden Faces ([create 3D objects](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/create-3d-graphics/create-3d-objects.html)); Revolve (Classic) initial: live, round seam joins, Angle, Cap, Offset from the left or right edge, Position presets and rotation gizmo, Perspective, the same four surfaces, lights, highlight, Blend Steps and Shading Color, groups and layers revolved about one shared axis (same page); Rotate (Classic) initial: live, round seam joins, every fill and stroke turned as one plane, Position presets and rotation gizmo, Perspective, No Shading and Diffuse surfaces with lights, Ambient Light, Blend Steps and Shading Color ([rotate objects in 3D](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/create-3d-graphics/rotate-objects-in-3d.html)); Preserve Spot Colors in all three, unavailable with a Custom Shading Color ([Preserve Spot Color](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=260)); Map Art: none |
| 3D (Classic): Extrude & Bevel, Revolve, Rotate | Extrude & Bevel (Classic) initial: live, round seam joins, Extrude Depth, Cap, five original bevel shapes with Height and Bevel Extent In or Out, Position presets and rotation gizmo, Perspective, Wireframe, No Shading, Diffuse and Plastic surfaces with one to ten lights, Light Intensity, Ambient Light, Highlight Intensity and Size, Blend Steps, Black, Custom or no Shading Color, Draw Hidden Faces ([create 3D objects](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/create-3d-graphics/create-3d-objects.html)); Revolve (Classic) initial: live, round seam joins, Angle, Cap, Offset from the left or right edge, Position presets and rotation gizmo, Perspective, the same four surfaces, lights, highlight, Blend Steps and Shading Color, groups and layers revolved about one shared axis (same page); Rotate (Classic) initial: live, round seam joins, every fill and stroke turned as one plane, Position presets and rotation gizmo, Perspective, No Shading and Diffuse surfaces with lights, Ambient Light, Blend Steps and Shading Color ([rotate objects in 3D](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/create-3d-graphics/rotate-objects-in-3d.html)); Preserve Spot Colors in all three, unavailable with a Custom Shading Color ([Preserve Spot Color](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=260)); 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)); Map Art: none |
| Turntable (30.0 beta) | none |
| Export 3D objects (OBJ, USDA, glTF) | initial: Asset Export's Export 3D Object collects an object with Extrude & Bevel, Revolve, Inflate or Rotate as a 3D asset, and Export writes its solids as a USDA (the default), USDZ, glTF or OBJ mesh with a material in each solid's paint color (`assets.add3D`, `assets.set3DFormat`, `assets.export3D`); no textures, map art or shading ([3D export help](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/create-3d-graphics/export-3d-vector-artwork.html)) |
+9 -2
View File
@@ -342,8 +342,15 @@ is drawn larger, above the others.
The widget sends the same settings as the Rotation, Height and Light behind the object controls
(`effect.setParams`); there is no command of its own. The sphere's look, the 0.1° rounding and the arrow keys
are VectorCraft's own. The options dialogs keep the light rings on the artboard instead, and the Lighting tab
of Extrude & Bevel (Classic), Revolve (Classic) and Rotate (Classic) has no lighting widget.
are VectorCraft's own. The options dialogs of Extrude & Bevel, Revolve, Inflate and Rotate keep the light rings
on the artboard instead.
The Lighting tab of Extrude & Bevel (Classic), Revolve (Classic) and Rotate (Classic) has the same sphere, in
the options dialog as well as in the panel, while the surface is Diffuse or Plastic, as the archived
[lighting options](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=272) of
the classic 3D dialogs describe. Their lights have no color, so every sun is white. The light rings on the
artboard stay available in the dialog. **Add Light** adds a light at the front center of the sphere (Rotation
0°, Height 90°), and **Delete Light** removes the selected light and is unavailable while one light is left.
### Light settings