SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Viewport: opt-in model zoom and Traced 3D mouse orbit (#7435) (#7991)
Colin Faulkingham3cdc68aaf183
diff --git a/assets/locales/pending/3d-mouse-orbit.json b/assets/locales/pending/3d-mouse-orbit.jsonnew file mode 100644index 0000000000..f954de451b--- /dev/null+++ b/assets/locales/pending/3d-mouse-orbit.json@@ -0,0 +1,50 @@+{+ "en": {+ "ui.3d_mouse_orbit": "Orbit",+ "ui.3d_mouse_orbit_classic": "Classic",+ "ui.3d_mouse_orbit_tip": "Traced: the 3D mouse turns the view around the part of the model in the middle of the view when the turn begins, marked by a faint ball. Classic: around the view's centre",+ "ui.3d_mouse_orbit_traced": "Traced"+ },+ "ar": {+ "ui.3d_mouse_orbit": "الدوران",+ "ui.3d_mouse_orbit_classic": "كلاسيكي",+ "ui.3d_mouse_orbit_tip": "متتبَّع: تُدير الفأرة ثلاثية الأبعاد العرض حول جزء النموذج الموجود في منتصف العرض عند بدء الدوران، وتُعلّمه بكرة باهتة. كلاسيكي: حول مركز العرض",+ "ui.3d_mouse_orbit_traced": "متتبَّع"+ },+ "de": {+ "ui.3d_mouse_orbit": "Orbit",+ "ui.3d_mouse_orbit_classic": "Klassisch",+ "ui.3d_mouse_orbit_tip": "Verfolgt: Die 3D-Maus dreht die Ansicht um den Teil des Modells, der zu Beginn der Drehung in der Ansichtsmitte liegt, markiert durch eine blasse Kugel. Klassisch: um die Ansichtsmitte",+ "ui.3d_mouse_orbit_traced": "Verfolgt"+ },+ "he": {+ "ui.3d_mouse_orbit": "סיבוב",+ "ui.3d_mouse_orbit_classic": "קלאסי",+ "ui.3d_mouse_orbit_tip": "במעקב: העכבר התלת־ממדי מסובב את המבט סביב החלק של המודל שבמרכז המבט כשהסיבוב מתחיל, ומסמן אותו בכדור חיוור. קלאסי: סביב מרכז המבט",+ "ui.3d_mouse_orbit_traced": "במעקב"+ },+ "ja": {+ "ui.3d_mouse_orbit": "回転",+ "ui.3d_mouse_orbit_classic": "クラシック",+ "ui.3d_mouse_orbit_tip": "トレース:3Dマウスで回転を始めたときにビューの中央にあるモデルの部分を中心にビューを回転し、その点を淡い球で示します。クラシック:ビューの中心を基準に回転します。",+ "ui.3d_mouse_orbit_traced": "トレース"+ },+ "ko": {+ "ui.3d_mouse_orbit": "궤도 회전",+ "ui.3d_mouse_orbit_classic": "클래식",+ "ui.3d_mouse_orbit_tip": "추적: 회전을 시작할 때 뷰 가운데에 있는 모델 부분을 중심으로 3D 마우스가 뷰를 회전하며, 그 점을 희미한 구로 표시합니다. 클래식: 뷰의 중심을 기준으로",+ "ui.3d_mouse_orbit_traced": "추적"+ },+ "vi": {+ "ui.3d_mouse_orbit": "Quỹ đạo",+ "ui.3d_mouse_orbit_classic": "Cổ điển",+ "ui.3d_mouse_orbit_tip": "Theo dấu: chuột 3D xoay khung nhìn quanh phần mô hình ở giữa khung nhìn lúc bắt đầu xoay, được đánh dấu bằng một quả cầu mờ. Cổ điển: quanh tâm khung nhìn",+ "ui.3d_mouse_orbit_traced": "Theo dấu"+ },+ "zh": {+ "ui.3d_mouse_orbit": "环绕",+ "ui.3d_mouse_orbit_classic": "经典",+ "ui.3d_mouse_orbit_tip": "追踪:3D 鼠标围绕开始旋转时视图中间的模型部分旋转视图,并用一个淡色小球标出该点。经典:围绕视图中心旋转",+ "ui.3d_mouse_orbit_traced": "追踪"+ }+}diff --git a/assets/locales/pending/zoom-stop-at-model.json b/assets/locales/pending/zoom-stop-at-model.jsonnew file mode 100644index 0000000000..5f46035d3f--- /dev/null+++ b/assets/locales/pending/zoom-stop-at-model.json@@ -0,0 +1,34 @@+{+ "en": {+ "prefs.zoom_stop_at_model": "Stop zoom at the model",+ "prefs.zoom_stop_at_model_tip": "The 3D mouse and device app zoom toward the surface in the middle of the view; drag-zoom holds the point where the drag began. Off: zoom can pass through the model. Wheel and pinch use Zoom to the cursor separately"+ },+ "ar": {+ "prefs.zoom_stop_at_model": "إيقاف التكبير عند النموذج",+ "prefs.zoom_stop_at_model_tip": "تُكبّر الفأرة ثلاثية الأبعاد وتطبيق الجهاز نحو السطح في منتصف العرض، ويثبّت التكبير بالسحب نقطة بدء السحب. عند الإيقاف يمكن للتكبير المرور عبر النموذج. تستخدم العجلة وإيماءة القرص إعداد التكبير نحو المؤشر بشكل مستقل"+ },+ "de": {+ "prefs.zoom_stop_at_model": "Zoom am Modell stoppen",+ "prefs.zoom_stop_at_model_tip": "3D-Maus und Geräte-App zoomen zur Oberfläche in der Ansichtsmitte; Zieh-Zoom hält den Punkt am Beginn des Ziehens fest. Aus: Zoom kann durch das Modell gehen. Mausrad und Pinch verwenden separat Zoom zum Mauszeiger"+ },+ "he": {+ "prefs.zoom_stop_at_model": "עצירת הזום במודל",+ "prefs.zoom_stop_at_model_tip": "העכבר התלת־ממדי ויישום ההתקן מקרבים את המבט אל המשטח שבמרכז התצוגה; זום בגרירה שומר על נקודת תחילת הגרירה. כשהאפשרות כבויה, אפשר לעבור דרך המודל. הגלגלת ומחוות הצביטה משתמשות בנפרד בהגדרת הזום אל הסמן"+ },+ "ja": {+ "prefs.zoom_stop_at_model": "モデルでズームを止める",+ "prefs.zoom_stop_at_model_tip": "3Dマウスとデバイスアプリはビュー中央の表面に向かってズームします。ドラッグズームはドラッグ開始点を固定します。オフの場合はモデルを通り抜けられます。ホイールとピンチは別の「カーソルへズーム」設定を使います"+ },+ "ko": {+ "prefs.zoom_stop_at_model": "모델에서 확대/축소 멈추기",+ "prefs.zoom_stop_at_model_tip": "3D 마우스와 장치 앱은 뷰 중앙의 표면을 향해 확대/축소하고, 드래그 확대/축소는 드래그 시작점을 고정합니다. 끄면 모델을 통과할 수 있습니다. 휠과 핀치는 별도의 커서로 확대/축소 설정을 사용합니다"+ },+ "vi": {+ "prefs.zoom_stop_at_model": "Dừng thu phóng tại mô hình",+ "prefs.zoom_stop_at_model_tip": "Chuột 3D và ứng dụng thiết bị thu phóng về phía bề mặt ở giữa khung nhìn; thu phóng bằng cách kéo giữ nguyên điểm bắt đầu kéo. Khi tắt, có thể thu phóng xuyên qua mô hình. Con lăn và cử chỉ chụm dùng riêng tùy chọn Thu phóng về con trỏ"+ },+ "zh": {+ "prefs.zoom_stop_at_model": "缩放到模型表面时停止",+ "prefs.zoom_stop_at_model_tip": "3D 鼠标和设备应用向视图中央的表面缩放;拖动缩放固定拖动开始时的点。关闭后可穿过模型。滚轮和捏合手势单独使用向光标缩放设置"+ }+}diff --git a/crates/ui-egui/src/navigation.rs b/crates/ui-egui/src/navigation.rsindex 656647fe5d..a339e53047 100644--- a/crates/ui-egui/src/navigation.rs+++ b/crates/ui-egui/src/navigation.rs@@ -307,7 +307,18 @@ pub(crate) fn claim_wheel(ctx: &egui::Context) {/// Zoom anchor: the model point under the cursor, else the target's depth./// Preferences › Navigation › Zoom to the cursor (off: toward the view's centre).pub(crate) fn zoom_anchor(app: &mut SolveApp, rect: egui::Rect, hover: Option<egui::Pos2>, surface: bool) -> Option<Vec3> {- hover.filter(|_| app.preferences.zoom_to_cursor).map(|p| {+ let hover = hover.filter(|_| app.preferences.zoom_to_cursor);+ zoom_point(app, rect, hover, surface)+}++/// The cap, bridge and drag-zoom keep their old behaviour unless explicitly opted in.+fn model_zoom_anchor(app: &mut SolveApp, rect: Rect, point: Option<Pos2>, surface: bool) -> Option<Vec3> {+ let point = point.filter(|_| app.preferences.zoom_stop_at_model);+ zoom_point(app, rect, point, surface)+}++fn zoom_point(app: &mut SolveApp, rect: Rect, point: Option<Pos2>, surface: bool) -> Option<Vec3> {+ point.map(|p| {let proj = projection(app, rect);// Toward the model's surface under the cursor, else the target's depth.if surface && let Some(q) = pick_cached(app, &proj, p).iter().find_map(|h| if let Hit::Face { point, .. } = h { Some(*point) } else { None })@@ -753,7 +764,13 @@ pub(crate) fn handle(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect, resp: &e}match mode {Some(NavMode::Pan) => app.cam.pan(f64::from(delta.x), f64::from(delta.y), h),- Some(NavMode::Zoom) => app.cam.zoom_at((f64::from(delta.y) * 0.01).exp(), None),+ // Opt-in drag-zoom holds the press point (#7435). Following the moving pointer+ // would slide the zoom away from what was pressed on.+ Some(NavMode::Zoom) => {+ let press = ui.input(|i| i.pointer.press_origin());+ let anchor = model_zoom_anchor(app, rect, press.or(hover), caps.orbit);+ app.cam.zoom_at((f64::from(delta.y) * 0.01).exp(), anchor);+ }_ => {}}}@@ -812,12 +829,43 @@ pub(crate) fn device(app: &mut SolveApp, rect: Rect, caps: NavCaps) {});let turn = caps.orbit && !sketch_view_is_initial;let height = f64::from(rect.height().max(1.0));+ // A device has no pointer, so opt-in zoom holds the model at the middle of the view (#7435).+ // Off by default: the cap and bridge can pass through the model, as before. The wheel and+ // pinch keep their separate "Zoom to the cursor" preference.+ let anchor = model_zoom_anchor(app, rect, Some(rect.center()), caps.orbit);+ // The view turns around the model in the middle of the view, else the middle of the bodies in+ // view, so what the user is looking at stays put. Off: around the view's centre, as before.+ // The cap keeps the point it started turning around until it is back at rest (and the view+ // shows it there); a device app sends no rest, so its turns pick it each frame.+ let pivot = (turn && app.preferences.space_mouse_model_pivot).then(|| {+ let cap = app.viewport.device_motion.is_some_and(|m| m.motion.rotation != [0.0; 3]);+ match app.viewport.device_pivot.filter(|_| cap) {+ Some(p) => p,+ None => {+ let p = crate::prefs::pivot_under(app, &projection(app, rect), rect.center());+ if cap {+ app.viewport.device_pivot = Some(p);+ }+ p+ }+ }+ });if let Some(queued) = app.viewport.device_motion.take() {- device_camera(&mut app.cam, queued.motion, queued.seconds, height, turn, app.preferences.zoom_reverse, app.preferences.free_orbit);+ device_camera(+ &mut app.cam,+ queued.motion,+ queued.seconds,+ height,+ turn,+ app.preferences.zoom_reverse,+ app.preferences.free_orbit,+ anchor,+ pivot,+ );}// A device app's motion (the navigation bridge), on the same terms.if let Some(queued) = app.viewport.bridge_motion.take() {- bridge_camera(&mut app.cam, queued, height, turn, app.preferences.zoom_reverse, app.preferences.free_orbit);+ bridge_camera(&mut app.cam, queued, height, turn, app.preferences.zoom_reverse, app.preferences.free_orbit, anchor, pivot);}}@@ -828,17 +876,32 @@ const BRIDGE_ZOOM_PER_STEP: f64 = 0.08;/// A device app's `motion` (`space_mouse::bridge_frame`) on `cam`, in a view `height` points/// tall: orbit and pan as a pointer drag of that many points, zoom by steps. With `turn` off (a/// flat page, a sketch being edited) the view keeps its orientation and the orbit motion pans-/// instead, so the device still moves the view.-pub(crate) fn bridge_camera(cam: &mut Camera, motion: BridgeMotion, height: f64, turn: bool, reverse_zoom: bool, free_orbit: bool) {+/// instead, so the device still moves the view. `anchor` is the model point the view holds while+/// it zooms, as the wheel's cursor point (none zooms through the model, #7435). `pivot` is the+/// point the view turns around and keeps still on screen (none: the view's centre).+pub(crate) fn bridge_camera(+ cam: &mut Camera,+ motion: BridgeMotion,+ height: f64,+ turn: bool,+ reverse_zoom: bool,+ free_orbit: bool,+ anchor: Option<Vec3>,+ pivot: Option<Vec3>,+) {let motion = BridgeMotion::default().plus(motion);let [mut px, mut py] = motion.pan;let [ox, oy] = motion.orbit;if turn {+ let keep = pivot.map(|p| (p, cam.frame_coords(p)));if free_orbit {cam.rotate_in_view(Vec3::new(-oy * 0.008, -ox * 0.008, 0.0));} else {cam.orbit(ox, oy);}+ if let Some((p, coords)) = keep {+ cam.place(p, coords);+ }} else {px += ox;py += oy;@@ -848,14 +911,26 @@ pub(crate) fn bridge_camera(cam: &mut Camera, motion: BridgeMotion, height: f64,}if motion.zoom != 0.0 {let zoom_sign = if reverse_zoom { -1.0 } else { 1.0 };- cam.zoom_at((-motion.zoom * zoom_sign * BRIDGE_ZOOM_PER_STEP).exp(), None);+ cam.zoom_at((-motion.zoom * zoom_sign * BRIDGE_ZOOM_PER_STEP).exp(), anchor);}}/// `seconds` of 3D mouse `motion` on `cam`, in a view `height` points tall. A full deflection/// pans about 0.6 of the view's height a second and turns about two radians a second, whatever-/// the frame rate. With `turn` off the view keeps its orientation.-pub(crate) fn device_camera(cam: &mut Camera, motion: Motion, seconds: f64, height: f64, turn: bool, reverse_zoom: bool, free_orbit: bool) {+/// the frame rate. With `turn` off the view keeps its orientation. `anchor` is the model point the+/// view holds while it zooms, as the wheel's cursor point (none zooms through the model, #7435).+/// `pivot` is the point the view turns around and keeps still on screen (none: the view's centre).+pub(crate) fn device_camera(+ cam: &mut Camera,+ motion: Motion,+ seconds: f64,+ height: f64,+ turn: bool,+ reverse_zoom: bool,+ free_orbit: bool,+ anchor: Option<Vec3>,+ pivot: Option<Vec3>,+) {if !(seconds > 0.0) || !seconds.is_finite() {return;}@@ -865,17 +940,21 @@ pub(crate) fn device_camera(cam: &mut Camera, motion: Motion, seconds: f64, heig// profile can swap the physical forward/back and up/down axes before they reach here.cam.pan(x * height * 0.6 * seconds, z * height * 0.6 * seconds, height);let zoom_sign = if reverse_zoom { -1.0 } else { 1.0 };- cam.zoom_at((-y * zoom_sign * 1.5 * seconds).exp(), None);+ cam.zoom_at((-y * zoom_sign * 1.5 * seconds).exp(), anchor);if turn {// These are logical 3DxWare coordinates after the profile mapping: Rx is Tilt, Ry is// Roll and Rz is Spin. The KMJ profile swaps physical Ry/Rz for the selected navigation// mode, so swapping them again here would make Roll behave like Spin.+ let keep = pivot.map(|p| (p, cam.frame_coords(p)));if free_orbit {cam.rotate_in_view(Vec3::new(-rx, -ry, rz) * (2.0 * seconds));} else {cam.orbit(ry * 250.0 * seconds, rx * 250.0 * seconds);cam.roll_by(rz * 2.0 * seconds);}+ if let Some((p, coords)) = keep {+ cam.place(p, coords);+ }}}@@ -1631,7 +1710,7 @@ mod tests {}// Other presets keep the existing upright camera behavior.let mut cam = Camera { yaw: 0.0, pitch: 1.5, ..Default::default() };- device_camera(&mut cam, Motion { translation: [0.0; 3], rotation: [1.0, 0.0, 0.0] }, 0.1, 600.0, true, false, false);+ device_camera(&mut cam, Motion { translation: [0.0; 3], rotation: [1.0, 0.0, 0.0] }, 0.1, 600.0, true, false, false, None, None);assert!(cam.pitch < std::f64::consts::FRAC_PI_2 && cam.pitch > 1.5);}@@ -2066,6 +2145,119 @@ mod tests {}}+ /// Surface anchoring for the cap, bridge and drag-zoom is opt-in (#7435), independent of+ /// the wheel preference. Off keeps the old target fixed and lets the eye enter the model.+ #[test]+ fn the_3d_mouse_bridge_and_drag_zoom_hold_the_view_at_the_model() {+ use super::*;+ use crate::space_mouse::{BridgeMotion, DeviceMotion, Motion};+ let rect = Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0));+ let outside = |cam: &Camera| {+ let e = cam.eye();+ e.x.abs() > 20.0 - 1e-6 || e.y.abs() > 20.0 - 1e-6 || e.z.abs() > 20.0 - 1e-6+ };+ for (stop_at_model, to_cursor) in [(false, false), (false, true), (true, false), (true, true)] {+ for cap in [true, false] {+ let mut h = crate::scenario::Harness::new();+ h.app.session.execute("solid.box", &json!({"length": 40, "width": 40, "height": 40, "corner": [-20, -20, -20]})).unwrap();+ h.app.preferences.zoom_to_cursor = to_cursor;+ h.app.preferences.zoom_stop_at_model = stop_at_model;+ h.settle();+ // The iso view looks straight at the box, as the report's sample does.+ h.app.cam = Camera::default();+ for _ in 0..60 {+ if cap {+ h.app.viewport.device_motion =+ Some(DeviceMotion { motion: Motion { translation: [0.0, 1.0, 0.0], rotation: [0.0; 3] }, seconds: 0.1 });+ } else {+ h.app.viewport.bridge_motion = Some(BridgeMotion { zoom: 1.0, ..Default::default() });+ }+ device(&mut h.app, rect, NavCaps::MODEL);+ }+ assert_eq!(outside(&h.app.cam), stop_at_model, "stop={stop_at_model} cursor={to_cursor} cap={cap}: eye {:?}", h.app.cam.eye());+ if !stop_at_model {+ assert_eq!(h.app.cam.target, Camera::default().target, "legacy zoom keeps the target fixed");+ }+ if !cap && to_cursor {+ h.step(&json!({"shot": if stop_at_model { "model-zoom-enabled" } else { "model-zoom-default" }})).unwrap();+ }+ }+ }+ // Drag-zoom: the "Zoom" navigation tool holds the model point where the drag started, so+ // that point stays under the press while the pointer moves away from it.+ for (stop_at_model, to_cursor) in [(false, false), (false, true), (true, false), (true, true)] {+ let mut h = crate::scenario::Harness::new();+ h.app.session.execute("solid.box", &json!({"length": 40, "width": 40, "height": 40, "corner": [-20, -20, -20]})).unwrap();+ h.app.preferences.zoom_to_cursor = to_cursor;+ h.app.preferences.zoom_stop_at_model = stop_at_model;+ h.app.run("view.tool", json!({"tool": "zoom"})).unwrap();+ h.settle();+ h.app.cam = Camera::default();+ let rect = h.app.viewport.rect.expect("the viewport");+ let at = projection(&h.app, rect).to_screen(Vec3::new(10.0, 0.0, 10.0)).expect("the box on screen");+ let held = model_zoom_anchor(&mut h.app, rect, Some(at), true);+ assert_eq!(held.is_some(), stop_at_model);+ assert_eq!(zoom_anchor(&mut h.app, rect, Some(at), true).is_some(), to_cursor, "wheel anchoring stays independent");+ for _ in 0..12 {+ h.call("ui.drag", json!({"x0": at.x, "y0": at.y, "x1": at.x, "y1": at.y - 160.0, "steps": 40}));+ }+ assert_eq!(outside(&h.app.cam), stop_at_model, "drag stop={stop_at_model} cursor={to_cursor}: eye {:?}", h.app.cam.eye());+ if !stop_at_model {+ assert_eq!(h.app.cam.target, Camera::default().target, "legacy drag-zoom keeps the target fixed");+ }+ if let Some(held) = held {+ let now = projection(&h.app, rect).to_screen(held).expect("the held point on screen");+ assert!((now - at).length() < 1.0, "the pressed point moved from {at:?} to {now:?}");+ }+ }+ }++ /// The 3D mouse turns the view around the model in the middle of the view, so that point stays+ /// put on screen, when Traced orbit is enabled. With Classic (the default), it+ /// turns around the view's centre and the point swings away.+ #[test]+ fn the_3d_mouse_turns_around_the_model_in_the_middle_of_the_view() {+ use super::*;+ use crate::space_mouse::{BridgeMotion, DeviceMotion, Motion};+ let rect = Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0));+ for free in [false, true] {+ for (model_pivot, cap) in [(false, false), (false, true), (true, false), (true, true)] {+ let mut h = crate::scenario::Harness::new();+ h.app.session.execute("solid.box", &json!({"length": 40, "width": 40, "height": 40, "corner": [-20, -20, -20]})).unwrap();+ h.app.preferences.space_mouse_model_pivot = model_pivot;+ h.app.preferences.free_orbit = free;+ h.settle();+ // Looking at the box from far away, so the view's centre is well behind the face.+ h.app.cam = Camera { distance: 400.0, ..Camera::default() };+ let held = crate::prefs::pivot_under(&h.app, &projection(&h.app, rect), rect.center());+ for _ in 0..10 {+ if cap {+ h.app.viewport.device_motion =+ Some(DeviceMotion { motion: Motion { translation: [0.0; 3], rotation: [0.5, 0.5, 0.0] }, seconds: 0.05 });+ } else {+ h.app.viewport.bridge_motion = Some(BridgeMotion { orbit: [6.25, 6.25], ..Default::default() });+ }+ device(&mut h.app, rect, NavCaps::MODEL);+ }+ let now = projection(&h.app, rect).to_screen(held).expect("the held point on screen");+ let still = (now - rect.center()).length() < 1.0;+ assert_eq!(still, model_pivot, "free={free} model_pivot={model_pivot}: the middle point moved to {now:?}");+ if !cap {+ assert!(h.app.viewport.device_pivot.is_none(), "the bridge picks its point each frame");+ continue;+ }+ // Panning while it turns brings other parts of the model to the middle; the turn+ // keeps the point it started with until the cap is back at rest.+ for _ in 0..10 {+ h.app.viewport.device_motion =+ Some(DeviceMotion { motion: Motion { translation: [0.5, 0.0, 0.0], rotation: [0.5, 0.5, 0.0] }, seconds: 0.05 });+ device(&mut h.app, rect, NavCaps::MODEL);+ }+ assert_eq!(h.app.viewport.device_pivot, model_pivot.then_some(held), "free={free}: the turn kept its point");+ }+ }+ }+/// While a sketch is edited the cap pans and zooms without turning a square-on view; after the/// view is tilted away from the sketch, the cap can turn it again.#[test]diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rsindex 681e49cd5e..1c575d3d2e 100644--- a/crates/ui-egui/src/prefs.rs+++ b/crates/ui-egui/src/prefs.rs@@ -878,6 +878,10 @@ preference_settings! {/// Whether a picture of the connected 3D mouse, moving as it does, sits in the 3D view's lower/// left corner. Off by default.space_mouse_in_view: bool = false, PAGE_NAVIGATION => check_id("ui.3d_mouse_show_in_view");+ /// 3D mouse orbit: traced (on) turns the view around the model in the middle of the view when+ /// the turn begins (else the middle of the bodies in view), marked by a faint ball; classic+ /// (off, the default) turns it around the view's centre, as it did before.+ space_mouse_model_pivot: bool = false, PAGE_NAVIGATION;/// Speed multiplier for 3D mouse navigation.space_mouse_speed: f32 = 1.0, PAGE_NAVIGATION;/// Per physical axis of the cap (push X, Y, Z, then tilt X, Y, Z), whether it moves the view@@ -1095,6 +1099,9 @@ preference_settings! {zoom_to_cursor: bool = true, PAGE_NAVIGATION => check("Zoom to the cursor", "The wheel zooms toward the point under the cursor (off: toward the view's centre)");/// Speed multiplier for wheel zoom, independent of the 3D mouse.wheel_zoom_speed: f32 = 1.0, PAGE_NAVIGATION, accept(0.25..=4.0) => slider("ui.wheel_zoom_speed", 0.25..=4.0, 0.05, |v| format!("{v:.2}×"), "prefs:wheel_zoom_speed");+ /// Opt-in surface anchoring for the 3D mouse, navigation bridge and drag-zoom. The wheel+ /// and pinch retain their independent `zoom_to_cursor` preference.+ zoom_stop_at_model: bool = false, PAGE_NAVIGATION => check_id("prefs.zoom_stop_at_model");/// Spread discrete wheel input across frames (off: apply each event immediately).smooth_wheel_zoom: bool = true, PAGE_NAVIGATION => check("Smooth wheel zoom", "Turn off to apply each wheel event immediately, without a smoothing tail");/// Two-finger trackpad scroll pans (off: it zooms like the wheel); pinch always zooms.@@ -2357,7 +2364,20 @@ fn space_mouse_rows(app: &mut SolveApp, ui: &mut egui::Ui) {].map(|(position, key)| (position, app.tr(key).to_owned())).into();+ let orbits = [app.tr("ui.3d_mouse_orbit_traced").to_owned(), app.tr("ui.3d_mouse_orbit_classic").to_owned()];ui_kit::settings_form(ui, FORM_LABEL_WIDTH, |ui| {+ // Traced or classic orbit: a choice between two named ways rather than a checkbox.+ ui_kit::row(ui, crate::i18n::tr("ui.3d_mouse_orbit"), |ui| {+ let mut selected = usize::from(!app.preferences.space_mouse_model_pivot);+ let response = ui.scope(|ui| ui_kit::segmented(ui, &mut selected, &orbits.each_ref().map(String::as_str), ui_kit::Segments::default()));+ if response.inner {+ app.preferences.space_mouse_model_pivot = selected == 0;+ }+ let rect = response.response.rect;+ crate::scenario::publish_handle("prefs:3d_mouse_orbit_traced", egui::pos2(rect.left() + rect.width() * 0.25, rect.center().y));+ crate::scenario::publish_handle("prefs:3d_mouse_orbit_classic", egui::pos2(rect.left() + rect.width() * 0.75, rect.center().y));+ response.response.on_hover_text(crate::i18n::tr("ui.3d_mouse_orbit_tip"));+ });ui_kit::row(ui, crate::i18n::tr("ui.3d_mouse_ghost_position"), |ui| {let (in_view, position) = (app.preferences.space_mouse_in_view, &mut app.preferences.space_mouse_ghost_position);ui.add_enabled_ui(in_view, |ui| {@@ -2671,9 +2691,9 @@ fn found_but_not_allowed(drivers: Option<crate::space_mouse::DriversPresent>) ->}/// Puts this section's settings back: the driver choice, the speed, each axis's invert and speed and-/// assignment, where the picture goes and whether it shows. Not the calibration (it has its own-/// Forget), the button mapping, the offered set, "never show again", "Navigate with the 3D mouse" or-/// the test model.+/// assignment, where the picture goes and whether it shows, and what the view turns around. Not+/// the calibration (it has its own Forget), the button mapping, the offered set, "never show+/// again", "Navigate with the 3D mouse" or the test model.pub fn restore_space_mouse_defaults(app: &mut SolveApp) {let d = Prefs::default();let p = &mut app.preferences;@@ -2684,6 +2704,7 @@ pub fn restore_space_mouse_defaults(app: &mut SolveApp) {p.space_mouse_axis_source = d.space_mouse_axis_source;p.space_mouse_ghost_position = d.space_mouse_ghost_position;p.space_mouse_in_view = d.space_mouse_in_view;+ p.space_mouse_model_pivot = d.space_mouse_model_pivot;}/// The device's picture with the coordinate circles under it, and a box with a small model that@@ -4069,6 +4090,7 @@ mod tests {p.space_mouse_axis_source = [1, 0, 2, 3, 4, 5];p.space_mouse_ghost_position = SpaceMouseGhost::LeftWindow;p.space_mouse_in_view = true;+ p.space_mouse_model_pivot = true;let before = h.app.preferences.clone();let camera = h.app.cam;restore_space_mouse_defaults(&mut h.app);@@ -4080,6 +4102,7 @@ mod tests {);assert_eq!((p.space_mouse_axis_speed, p.space_mouse_axis_source), (d.space_mouse_axis_speed, d.space_mouse_axis_source));assert_eq!((p.space_mouse_ghost_position, p.space_mouse_in_view), (d.space_mouse_ghost_position, d.space_mouse_in_view));+ assert_eq!(p.space_mouse_model_pivot, d.space_mouse_model_pivot);// Kept: the calibration (dead zone too), the buttons, the offered set, never, enabled, the rest of the page.assert_eq!(p.space_mouse_calibrations, before.space_mouse_calibrations);assert_eq!(p.space_mouse_buttons, before.space_mouse_buttons);@@ -4091,6 +4114,50 @@ mod tests {assert!(!h.app.space_mouse.restore_pending);}+ /// The 3D mouse's orbit is a choice of two: Classic turns around the view's centre, Traced+ /// around the model in the middle of the view.+ #[test]+ fn the_3d_mouse_orbit_is_traced_or_classic() {+ let mut h = changed_3d_mouse_settings(None);+ assert!(!h.app.preferences.space_mouse_model_pivot, "classic is the default");+ scroll_to_and_click(&mut h, "prefs:3d_mouse_orbit_traced");+ assert!(h.app.preferences.space_mouse_model_pivot, "traced is opt-in");+ scroll_to_and_click(&mut h, "prefs:3d_mouse_orbit_classic");+ assert!(!h.app.preferences.space_mouse_model_pivot, "classic again");+ assert!(!h.app.preferences.zoom_stop_at_model, "stop-at-model zoom is off by default");+ scroll_to_and_click(&mut h, "prefs:zoom_stop_at_model");+ assert!(h.app.preferences.zoom_stop_at_model, "stop-at-model zoom is opt-in");+ assert!(h.app.preferences.zoom_to_cursor, "the wheel preference is unchanged");+ }++ #[test]+ fn model_navigation_is_opt_in_and_persists() {+ for to_cursor in [false, true] {+ let old = serde_json::from_value::<Prefs>(json!({"zoom_to_cursor": to_cursor})).unwrap();+ assert!(!old.zoom_stop_at_model && !old.space_mouse_model_pivot, "older saved preferences keep legacy navigation");+ assert_eq!(old.zoom_to_cursor, to_cursor);+ }+ let mut app = SolveApp::new(solidcraft_engine::Session::default(), Default::default());+ assert!(!app.preferences.zoom_stop_at_model && !app.preferences.space_mouse_model_pivot);+ let enabled = json!({"open": "Navigation", "zoom_stop_at_model": true, "space_mouse_model_pivot": true});+ control(&mut app, &enabled).unwrap();+ control(&mut app, &json!({"button": "cancel"})).unwrap();+ assert!(!app.preferences.zoom_stop_at_model && !app.preferences.space_mouse_model_pivot);+ let reply = control(&mut app, &enabled).unwrap();+ assert_eq!(reply["zoom_stop_at_model"], true);+ assert_eq!(reply["space_mouse_model_pivot"], true);+ control(&mut app, &json!({"button": "apply"})).unwrap();+ let mut other = SolveApp::new(solidcraft_engine::Session::default(), Default::default());+ other.load_prefs(&app.prefs());+ assert!(other.preferences.zoom_stop_at_model && other.preferences.space_mouse_model_pivot);+ assert!(other.preferences.zoom_to_cursor, "enabling model navigation leaves wheel zoom alone");+ control(&mut app, &json!({"button": "defaults"})).unwrap();+ assert!(!app.preferences.zoom_stop_at_model && !app.preferences.space_mouse_model_pivot);+ assert!(app.preferences.zoom_to_cursor, "Navigation defaults still anchor the wheel");+ control(&mut app, &json!({"button": "cancel"})).unwrap();+ assert!(app.preferences.zoom_stop_at_model && app.preferences.space_mouse_model_pivot, "Cancel restores the last Apply");+ }+/// Opens Preferences on the Navigation page with the 3D mouse section open and these settings/// changed from their defaults, as a person who changed them would find it.fn changed_3d_mouse_settings(device: Option<&str>) -> crate::scenario::Harness {diff --git a/crates/ui-egui/src/prefs/navigation.rs b/crates/ui-egui/src/prefs/navigation.rsindex ec8ecb6935..647395f289 100644--- a/crates/ui-egui/src/prefs/navigation.rs+++ b/crates/ui-egui/src/prefs/navigation.rs@@ -90,6 +90,8 @@ pub(super) fn show(app: &mut SolveApp, ui: &mut egui::Ui, t: &Tokens) {app.tr("prefs.extra_navigation").to_owned()};ui_kit::text(ui, &help, ui_kit::Text::Hint("navigation"));+ let stop = setting::zoom_stop_at_model(app, ui).on_hover_text(crate::i18n::tr("prefs.zoom_stop_at_model_tip"));+ crate::scenario::publish_target("prefs:zoom_stop_at_model", stop.rect);});ui_kit::settings_section(ui, "orbit_pivot", app.tr_label("Orbit around"), |ui| {ui.horizontal_wrapped(|ui| {diff --git a/crates/ui-egui/src/space_mouse.rs b/crates/ui-egui/src/space_mouse.rsindex 15da52ae43..b3992e3bdf 100644--- a/crates/ui-egui/src/space_mouse.rs+++ b/crates/ui-egui/src/space_mouse.rs@@ -582,6 +582,10 @@ pub fn navigate_frame(app: &mut SolveApp, ctx: &egui::Context, mapping: DriverMa// Then the user's choice of which motion drives which axis (invert and speed then go with the// axis, not the motion). After the settle: that works on the device's own calibrated axes.let axes = reassigned(axes, app.preferences.space_mouse_axis_source);+ // Back at rest: the next push picks what the view turns around afresh.+ if !axes.moving() {+ app.viewport.device_pivot = None;+ }// Only the window with focus: with two windows open, the cap moves the one being used, not both.if !app.preferences.space_mouse_enabled || app.home.open || app.file_picker_busy() || !axes.moving() || !ctx.input(|i| i.focused) {return false;@@ -690,7 +694,7 @@ mod tests {/// The camera math the page applies the motion with (`navigation::device`): `sketch` keeps/// the orientation, as editing a sketch does.fn navigate(cam: &mut Camera, motion: Motion, seconds: f64, height: f64, sketch: bool, reverse_zoom: bool) {- crate::navigation::device_camera(cam, motion, seconds, height, !sketch, reverse_zoom, false);+ crate::navigation::device_camera(cam, motion, seconds, height, !sketch, reverse_zoom, false, None, None);}/// A window that has run a frame, with or without focus. A context that has never run one@@ -1070,6 +1074,22 @@ mod tests {assert!(raw.events.iter().any(|e| matches!(e, egui::Event::MouseWheel { modifiers, .. } if modifiers.shift)));}+ /// What the cap turns the view around is chosen when it starts turning and let go when it is+ /// back at rest.+ #[test]+ fn the_cap_lets_go_of_its_turning_point_at_rest() {+ let mut app = app();+ app.preferences.space_mouse_model_pivot = true;+ let ctx = window(true);+ app.space_mouse.device = Some("hid 046d:c62b".into());+ frame(&mut app, &ctx, DriverMapping::default(), Axes { translation: [300, 0, 0], rotation: [0; 3] }, 0.016);+ assert_eq!(app.viewport.device_pivot, None, "a pan alone turns around nothing");+ frame(&mut app, &ctx, DriverMapping::default(), Axes { translation: [300, 0, 0], rotation: [300, 0, 0] }, 0.016);+ assert!(app.viewport.device_pivot.is_some(), "a turn holds a point");+ frame(&mut app, &ctx, DriverMapping::default(), Axes::default(), 0.016);+ assert_eq!(app.viewport.device_pivot, None, "at rest it is let go");+ }+#[test]fn another_device_starts_with_no_buttons_seen_and_no_settling() {let mut app = app();diff --git a/crates/ui-egui/src/test_boat.rs b/crates/ui-egui/src/test_boat.rsindex d77b17c46b..74eaf0f614 100644--- a/crates/ui-egui/src/test_boat.rs+++ b/crates/ui-egui/src/test_boat.rs@@ -119,7 +119,7 @@ pub(crate) fn step(reverse_zoom: bool,free_orbit: bool,) {- crate::navigation::device_camera(cam, motion, seconds, height, true, reverse_zoom, free_orbit);+ crate::navigation::device_camera(cam, motion, seconds, height, true, reverse_zoom, free_orbit, None, None);cam.fov = FOV;// Zoom within limits: the nearest still shows the whole boat in the shorter side of the box.let shorter = aspect.min(1.0);diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rsindex 43dcea0446..fc813273d2 100644--- a/crates/ui-egui/src/viewport.rs+++ b/crates/ui-egui/src/viewport.rs@@ -184,6 +184,9 @@ pub struct ViewportState {/// A device app's motion since the page last took it (`space_mouse::bridge_frame`), applied/// the same way.pub bridge_motion: Option<crate::space_mouse::BridgeMotion>,+ /// The model point the 3D mouse turns the view around: chosen when the cap leaves rest and+ /// kept until it comes back (`navigation::device`, `space_mouse::navigate_frame`).+ pub device_pivot: Option<Vec3>,/// After immediate zoom, ignore egui's outstanding smoothing until the gesture ends.pub(crate) wheel_zoom_raw_until_idle: bool,/// While trackpad scrolling runs, ignore egui's smoothing tail for zoom so@@ -4818,6 +4821,7 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui) {}crate::joint_handles::show(app, ui, &painter, &proj);overlays(app, &painter, &proj);+ paint_device_pivot(app, &painter, &proj);crate::dim_view::show(app, ui, &painter, &proj);crate::sketch_text_handles::show(app, ui, &painter, &proj, hover);crate::sketch3d::show(app, &painter, &proj);@@ -5809,6 +5813,16 @@ pub(crate) fn standalone_points(app: &SolveApp) -> Vec<Vec3> {}/// Sketch points and the status of the active sketch (constraint glyphs: `sketch_tools`).+/// The point the 3D mouse is turning the view around, as a faint ball, so the user sees what the+/// turn holds still (#7435). Lighter, smaller discs stacked toward the top left give it its shading.+fn paint_device_pivot(app: &SolveApp, painter: &egui::Painter, proj: &Proj) {+ let Some(p) = app.viewport.device_pivot.and_then(|p| proj.to_screen(p)) else { return };+ let t = Tokens::get();+ painter.circle(p, 8.0, t.accent.gamma_multiply(0.18), Stroke::new(1.0, t.accent.gamma_multiply(0.5)));+ painter.circle_filled(p + vec2(-1.5, -1.5), 5.0, t.accent.gamma_multiply(0.2));+ painter.circle_filled(p + vec2(-2.5, -2.5), 2.5, t.accent.gamma_multiply(0.3));+}+fn overlays(app: &SolveApp, painter: &egui::Painter, proj: &Proj) {let t = Tokens::get();let st = crate::open_meshing::shown_world(app);diff --git a/docs/3d-mouse.md b/docs/3d-mouse.mdindex dd3981ce1b..9b7eecb10c 100644--- a/docs/3d-mouse.md+++ b/docs/3d-mouse.md@@ -3,6 +3,19 @@On Windows, macOS and Linux, SolidCraft detects a connected 3D mouse through its HID multi-axiscontroller interface: a 3Dconnexion SpaceNavigator or SpaceMouse, or a homemade device thatdeclares itself one. Move the cap to pan and zoom, and tilt or twist it to rotate the 3D view.+By default, zoom can pass through the model and orbit turns around the view's centre, as in earlier+versions. Two preferences opt into holding the model:++- Preferences › Navigation › **Stop zoom at the model** (`zoom_stop_at_model`, off by default)+ makes the cap and navigation bridge zoom toward the surface in the middle of the view and stop+ there. Drag-zoom holds the model point where the drag began. The wheel and pinch keep their+ separate **Zoom to the cursor** preference; neither setting changes the other.+- Preferences › Navigation › 3D mouse › **Orbit** defaults to **Classic**. Choose **Traced**+ (`space_mouse_model_pivot: true`) to turn around the model point in the middle of the view when+ the turn begins. A faint ball marks that point until the cap is back at rest. Over empty space,+ the pivot is the middle of the bodies in view. The navigation bridge uses the same preference,+ but picks the point each frame because device apps do not report rest.+While editing a sketch, the cap pans and zooms without changing the sketch's initial view. After youadjust the view with the navigation cube, the cap can rotate it too. The Navigationpage in Preferences has an on/off switch, a speed control and, for each of the cap's six axes, an@@ -71,7 +84,7 @@ know, is ignored:|---|---|| `{"t":"hello","server":"MAKMOUSE","device":"MAKMOUSE"}` | The program's name (shown in Preferences) and, optionally, a name in the device's USB manufacturer or product string. A 3D mouse with that name is then left to the program, so its motion doesn't reach the view twice. || `{"t":"axis","x":4.0,"y":-2.5}` | Motion since the last message, in points: it orbits as a drag of that many points would (the model follows), or pans or zooms in the current mode. Where the view can't turn (a sketch being edited, a flat page) an orbit pans. |-| `{"t":"zoom","d":1.0}` | Zoom steps (8 % of the distance each); positive zooms in, as a wheel turned forward. Reverse zoom direction applies. |+| `{"t":"zoom","d":1.0}` | Zoom steps (8 % of the distance each); positive zooms in, as a wheel turned forward. Reverse zoom direction applies. Stops at the model only when **Stop zoom at the model** is on. || `{"t":"mode","mode":"pan","on":true}` | What `axis` drives: `orbit` (the default), `pan` or `zoom` (up zooms in, 8 points a step). `"on":false` goes back to orbit. || `{"t":"view","name":"iso"}` | A standard view: `front`, `back`, `left`, `right`, `top`, `bottom`, `iso`, or `fit` to frame everything. |diff --git a/docs/control-protocol.md b/docs/control-protocol.mdindex fcd43615b5..b6946cc793 100644--- a/docs/control-protocol.md+++ b/docs/control-protocol.md@@ -422,6 +422,7 @@ One setting per line, sorted by name. A change that adds a setting adds its own- `sketch_state_icons` (default true: a sketch's icon in History and the browser takes the colour of its solve state, `sketch` under constrained, `sketch_fixed` fully constrained, `error` while its constraints conflict, and its tooltip names the state; false: every sketch row's icon and tooltip as before, #7245)- `sketch_tab_always` (default false: the SKETCH tab stays in the ribbon right after MODEL while no sketch is open; a tool in its CREATE or REFERENCE section then opens Create Sketch, on the selected plane or planar face or else on the plane picked next, and starts in the new sketch, #7904)- `smooth_wheel_zoom` (default true)+- `space_mouse_model_pivot` (default false: Classic orbit around the view's centre; true opts into Traced orbit around the model for the 3D mouse and navigation bridge)- `stand_up_unknown` (`note` (default: a file whose header names no program known to save Y up and whose bodies seem to lie on their back (their flat area across Y outweighs their flat area facing down Z) gets a small note over the view, "Did this part open the wrong way up?", with Stand it up, Don't ask again and Close as the handles `stand_up:stand`, `stand_up:never` and `stand_up:dismiss`; it goes by itself after 10 seconds and never blocks input), `ask` (the "Stand this part up?" dialog for every file from another program, SolidWorks too, without looking at how it rests, as before #7717), `off` (no offer); otherwise a SolidWorks file gets the dialog, or the note when its bodies clearly stand on Z already)- `status_bar` (default false: a thin bar along the window's bottom edge, below History, handle `status:bar`: what is being edited (`status:editing`), the open sketch's state in its colour (`status:sketch`) and the design's units (`status:units`, a click opens the Units menu, whose rows run `document.units`); the sketch's state then leaves the view's top-left corner, #7243)- `step_values` (default false: Up/Down and the wheel step a plain number in a focused value field)@@ -442,6 +443,7 @@ One setting per line, sorted by name. A change that adds a setting adds its own- `wheel_zoom_speed` (0.25 to 4, default 1: how far each wheel step zooms; the 3D mouse keeps its own speed)- `window_system` (Linux: `auto` (default: XWayland whenever there is an X display, native Wayland on niri), `wayland`, `x11`; saved in `graphics.json`, applies at the next start; `SOLIDCRAFT_WAYLAND` overrides it)- `zoom_reverse`+- `zoom_stop_at_model` (default false: the 3D mouse and navigation bridge stop zoom at the surface in the middle of the view; drag-zoom holds its press point; independent of `zoom_to_cursor`)- `zoom_to_cursor`Other `ui.prefs` parameters: