Look At in the viewport context menu for a planar face or plane (#4105) (#4497)

* Look At in the viewport context menu for a planar face or plane

Fixes #4105

* Look At tests: turn the camera without the animation

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: bherbruck <brennen.herbruck@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
authored and GitHub committed 2026-10-25 21:37:37 +00:00
1 parent 4355d117ef
commit c7f86c7309
3 files changed
+50 -6

No files matched your search

+18 -5
View File
@@ -527,6 +527,9 @@ fn viewport_items(app: &SolveApp) -> Vec<Item> {
v.push(cmd(app, "solid.shell", "Shell"));
v.push(act("ui.editFeature", "Edit Feature", "edit").with(json!({ "feature": feature })).on(feature.is_some()));
v.push(act("ui.editSketch", "Edit Profile Sketch", "sketch").with(json!({ "sketch": sketch })).on(sketch.is_some()));
let planar =
sel.iter().any(|s| matches!(s, Sel::Face { body, index, .. } if crate::dialogs::planar_face(&app.session, body, *index).is_some()));
v.push(act("ui.lookAt", "Look At", "lookat").on(planar));
v.push(Item::sep());
v.push(act("ui.appearance", "Appearance", "appearance").key("A"));
v.push(act("ui.properties", "Properties", "measure").with(json!({ "bodies": [face] })));
@@ -561,12 +564,16 @@ fn viewport_items(app: &SolveApp) -> Vec<Item> {
v.push(cmd(app, "solid.revolve", "Revolve"));
} else {
// Empty space, or a plane: both lead with Create Sketch (#3032). On a plane it sketches
// there; on empty space it is the toolbar's, which asks for the plane or face.
// there, with Look At beside it; on empty space it is the toolbar's, which asks for the
// plane or face.
let sketch = cmd(app, "sketch.create", "Create Sketch");
v.push(match &app.menu.plane {
Some(plane) => sketch.with(json!({ "plane": plane })),
None => sketch,
});
match &app.menu.plane {
Some(plane) => {
v.push(sketch.with(json!({ "plane": plane })));
v.push(act("ui.lookAt", "Look At", "lookat").with(json!({ "plane": plane })));
}
None => v.push(sketch),
}
v.push(Item::sep());
v.push(act("ui.nav", "Pan", "pan").with(json!({ "mode": "pan" })));
v.push(act("ui.nav", "Zoom", "zoom").with(json!({ "mode": "zoom" })));
@@ -1414,6 +1421,12 @@ pub fn run_item(app: &mut SolveApp, item: &Item, at: Pos2) {
if let Some(ss) = id_of(&p, "sketch").and_then(|id| st.sketch(id)) {
let to = crate::dialogs::onto_sketch(app.cam.looking_from(ss.plane.normal()), ss);
app.animate_to(to);
} else if let Some(plane) = p.get("plane").and_then(Value::as_str).and_then(solidcraft_engine::geom::Plane::named) {
let mut to = app.cam.looking_from(crate::dialogs::facing(app, plane.normal(), true));
to.target = plane.origin;
app.animate_to(to);
} else if p.get("sketch").is_none() {
crate::viewport::look_at_selection(app);
}
}
"ui.nav" => {
+31
View File
@@ -60,3 +60,34 @@ fn an_empty_sketch_keeps_its_planes_origin() {
assert!(near(h.app.cam.target, Vec3::new(0.0, 0.0, 8.0)), "{:?}", h.app.cam.target);
assert_eq!(h.app.cam.distance, 123.0);
}
/// The viewport menu's Look At (#4105): the same turn as the navigation bar's, for the planar
/// face under the right-click and for a plane.
#[test]
fn the_viewport_menu_looks_at_a_planar_face() {
let mut h = Harness::new();
h.app.home.open = false;
h.app.preferences.look_at_anim = false;
h.app.run("solid.box", json!({"length": 40, "width": 30, "height": 10})).unwrap();
let body = h.app.session.model.state().bodies[0].clone();
let face = body.body.faces(0.01).unwrap().into_iter().find(|f| f.plane_normal.is_some_and(|n| n.z > 0.99)).unwrap();
h.app.run("select.set", json!({"items": [{"type": "face", "body": body.name, "index": face.index, "point": face.centroid}]})).unwrap();
let items = crate::context_menu::items(&h.app, &crate::context_menu::Target::Viewport);
let look = items.iter().find(|i| i.id == "ui.lookAt").cloned().expect("a face's menu has Look At");
assert!(look.enabled);
crate::context_menu::run_item(&mut h.app, &look, egui::Pos2::ZERO);
assert!((h.app.cam.back() - Vec3::new(0.0, 0.0, 1.0)).len() < 1e-6, "facing the top face: {:?}", h.app.cam.back());
}
#[test]
fn the_viewport_menu_looks_at_a_plane_under_the_cursor() {
let mut h = Harness::new();
h.app.home.open = false;
h.app.preferences.look_at_anim = false;
h.app.menu.plane = Some("XZ".to_string());
let items = crate::context_menu::items(&h.app, &crate::context_menu::Target::Viewport);
let look = items.iter().find(|i| i.id == "ui.lookAt").cloned().expect("a plane's menu has Look At");
crate::context_menu::run_item(&mut h.app, &look, egui::Pos2::ZERO);
let normal = solidcraft_engine::geom::Plane::named("XZ").unwrap().normal();
assert!((h.app.cam.back().cross(normal)).len() < 1e-6, "facing the plane along its normal: {:?}", h.app.cam.back());
}
+1 -1
View File
@@ -1028,7 +1028,7 @@ fn right_click_on_a_plane_offers_a_sketch_on_it() {
let menu = h.call("ui.menu", json!({}))["result"].clone();
let items = menu["items"].as_array().unwrap();
let labels: Vec<&str> = items.iter().filter_map(|i| i["label"].as_str()).filter(|l| !l.is_empty()).collect();
assert_eq!(labels[..3], ["Select Other…", "Create Sketch", "Pan"], "{plane}: {labels:?}");
assert_eq!(labels[..4], ["Select Other…", "Create Sketch", "Look At", "Pan"], "{plane}: {labels:?}");
let sketch = items.iter().find(|i| i["label"] == "Create Sketch").unwrap();
assert_eq!(sketch["params"], json!({"plane": plane}));
assert!(h.app.session.selection.is_empty(), "the right-click leaves the plane unselected");