3D mouse: optional orbit while a sketch is open (#2227) (#9406)

* claim: #2227

* 3D mouse: optional orbit while a sketch is open (#2227)

A new Navigation preference, "Turn sketches with the 3D mouse"
(space_mouse_sketch_orbit, off by default), lets the cap and a device
app turn the view while a sketch is open and seen square on, as the
mouse already can. Off keeps today's behaviour: pan and zoom until the
view is tilted away from the sketch (#6687). Restore defaults on the
3D mouse section resets it.

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

* 3D mouse: keep the settings list in order after the rebase

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: bherbruck <brennen.herbruck@gmail.com>
This commit is contained in:
PaddleStroke
2026-10-30 19:22:58 +00:00
committed by GitHub
parent cdffdcbbef
commit a99c57ffc7
5 changed files with 104 additions and 15 deletions
@@ -0,0 +1,34 @@
{
"en": {
"ui.3d_mouse_sketch_orbit": "Turn sketches with the 3D mouse",
"ui.3d_mouse_sketch_orbit_tip": "The 3D mouse also turns the view while a sketch is open and seen square on, as the mouse can. Off: it pans and zooms the sketch until you tilt the view."
},
"ar": {
"ui.3d_mouse_sketch_orbit": "تدوير الرسومات بالفأرة ثلاثية الأبعاد",
"ui.3d_mouse_sketch_orbit_tip": "تدير الفأرة ثلاثية الأبعاد العرض أيضًا أثناء فتح رسم ورؤيته من الأمام مباشرة، كما تفعل الفأرة. عند الإيقاف: تحرّك الرسم وتكبّره فقط حتى تميل العرض."
},
"de": {
"ui.3d_mouse_sketch_orbit": "Skizzen mit der 3D-Maus drehen",
"ui.3d_mouse_sketch_orbit_tip": "Die 3D-Maus dreht die Ansicht auch, solange eine Skizze offen ist und frontal gesehen wird, wie es die Maus kann. Aus: Sie verschiebt und zoomt die Skizze, bis Sie die Ansicht neigen."
},
"fr": {
"ui.3d_mouse_sketch_orbit": "Faire pivoter les esquisses avec la souris 3D",
"ui.3d_mouse_sketch_orbit_tip": "La souris 3D fait aussi pivoter la vue quand une esquisse est ouverte et vue de face, comme la souris. Désactivé : elle déplace et zoome l'esquisse jusqu'à ce que vous incliniez la vue."
},
"he": {
"ui.3d_mouse_sketch_orbit": "סיבוב סקיצות בעכבר התלת־ממדי",
"ui.3d_mouse_sketch_orbit_tip": "העכבר התלת־ממדי מסובב את התצוגה גם כשסקיצה פתוחה ונראית חזיתית, כמו שהעכבר יכול. כבוי: הוא מזיז ומגדיל את הסקיצה עד שתטה את התצוגה."
},
"ja": {
"ui.3d_mouse_sketch_orbit": "3D マウスでスケッチを回転",
"ui.3d_mouse_sketch_orbit_tip": "スケッチを開いて正面から見ているときも、マウスと同じように 3D マウスでビューを回転します。オフ: ビューを傾けるまで、スケッチのパンとズームのみ行います。"
},
"vi": {
"ui.3d_mouse_sketch_orbit": "Xoay bản phác thảo bằng chuột 3D",
"ui.3d_mouse_sketch_orbit_tip": "Chuột 3D cũng xoay khung nhìn khi bản phác thảo đang mở và được nhìn thẳng, như chuột thường. Tắt: chỉ di chuyển và thu phóng bản phác thảo cho đến khi bạn nghiêng khung nhìn."
},
"zh": {
"ui.3d_mouse_sketch_orbit": "用 3D 鼠标旋转草图",
"ui.3d_mouse_sketch_orbit_tip": "草图打开并正对视图时,3D 鼠标也能旋转视图,与鼠标一样。关闭:在你倾斜视图之前,只平移和缩放草图。"
}
}
+55 -12
View File
@@ -844,22 +844,26 @@ pub(crate) fn handle(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect, resp: &e
/// The 3D mouse's motion this frame (#1336), on a page `rect` whose camera may do `caps`: the cap
/// pans and zooms every page, and turns the view where the page may orbit. In a sketch, turning
/// stays off while the camera is in its initial sketch orientation. [`handle`] calls it for its page; the 3D
/// mouse only reads the device and queues the motion ([`crate::space_mouse::navigate_frame`]).
/// stays off while the camera is in its initial sketch orientation, unless the user lets the 3D
/// mouse turn sketches (`space_mouse_sketch_orbit`, #2227), as the mouse can. [`handle`] calls it
/// for its page; the 3D mouse only reads the device and queues the motion
/// ([`crate::space_mouse::navigate_frame`]).
pub(crate) fn device(app: &mut SolveApp, rect: Rect, caps: NavCaps) {
if app.viewport.device_motion.is_none() && app.viewport.bridge_motion.is_none() {
return;
}
let sketch_view_is_initial = solidcraft_engine::view::open_sketch_plane(&app.session).is_some_and(|plane| {
let normal = plane.normal();
let mut initial = app.cam.looking_from(normal);
if normal.z.abs() > 0.999 {
initial.yaw = if normal.z > 0.0 { (-plane.x.y).atan2(plane.x.x) } else { plane.x.y.atan2(plane.x.x) };
}
let (right, up, back) = app.cam.basis();
let (initial_right, initial_up, initial_back) = initial.basis();
right.dot(initial_right) > 0.999 && up.dot(initial_up) > 0.999 && back.dot(initial_back) > 0.999
});
let sketch_turns = app.preferences.space_mouse_sketch_orbit;
let sketch_view_is_initial = !sketch_turns
&& solidcraft_engine::view::open_sketch_plane(&app.session).is_some_and(|plane| {
let normal = plane.normal();
let mut initial = app.cam.looking_from(normal);
if normal.z.abs() > 0.999 {
initial.yaw = if normal.z > 0.0 { (-plane.x.y).atan2(plane.x.x) } else { plane.x.y.atan2(plane.x.x) };
}
let (right, up, back) = app.cam.basis();
let (initial_right, initial_up, initial_back) = initial.basis();
right.dot(initial_right) > 0.999 && up.dot(initial_up) > 0.999 && back.dot(initial_back) > 0.999
});
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).
@@ -2317,6 +2321,45 @@ mod tests {
super::device(&mut app, page, super::NavCaps::MODEL);
assert_eq!(app.cam, still);
}
/// With "3D mouse turns sketches" on (#2227), the cap and a device app turn a sketch seen square
/// on, as the mouse does; pages that may not orbit still only pan.
#[test]
fn the_3d_mouse_turns_a_square_on_sketch_when_the_preference_allows_it() {
use crate::space_mouse::{BridgeMotion, DeviceMotion, Motion};
use solidcraft_engine::render::Camera;
let mut s = solidcraft_engine::Session::default();
s.execute("sketch.create", &serde_json::json!({"plane": "XY"})).unwrap();
let mut app = crate::SolveApp::new(s, crate::Services::default());
assert!(!app.preferences.space_mouse_sketch_orbit, "off by default");
app.preferences.space_mouse_sketch_orbit = true;
let square_on = Camera { yaw: 0.0, pitch: std::f64::consts::FRAC_PI_2, ..Camera::default() };
let page = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(800.0, 600.0));
let turn = |c: &Camera| (c.yaw, c.pitch, c.roll);
app.cam = square_on;
app.viewport.device_motion = Some(DeviceMotion { motion: Motion { translation: [0.0; 3], rotation: [0.3, 0.3, 0.0] }, seconds: 0.05 });
super::device(&mut app, page, super::NavCaps::MODEL);
assert_ne!(turn(&app.cam), turn(&square_on), "the cap turns the square-on sketch");
app.cam = square_on;
app.viewport.bridge_motion = Some(BridgeMotion { orbit: [6.0, 6.0], ..Default::default() });
super::device(&mut app, page, super::NavCaps::MODEL);
assert_ne!(turn(&app.cam), turn(&square_on), "a device app turns it too");
// A page that may not orbit keeps its orientation whatever the preference.
app.cam = square_on;
app.viewport.device_motion = Some(DeviceMotion { motion: Motion { translation: [0.0; 3], rotation: [0.3, 0.3, 0.3] }, seconds: 0.05 });
super::device(&mut app, page, super::NavCaps { orbit: false, ..super::NavCaps::MODEL });
assert_eq!(turn(&app.cam), turn(&square_on));
// Off again: the square-on sketch keeps its orientation, as before.
app.preferences.space_mouse_sketch_orbit = false;
app.cam = square_on;
app.viewport.device_motion = Some(DeviceMotion { motion: Motion { translation: [0.0; 3], rotation: [0.3, 0.3, 0.3] }, seconds: 0.05 });
super::device(&mut app, page, super::NavCaps::MODEL);
assert_eq!(turn(&app.cam), turn(&square_on));
}
}
#[cfg(test)]
+10 -1
View File
@@ -919,6 +919,10 @@ preference_settings! {
/// 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;
/// Whether the 3D mouse also turns the view while a sketch is edited and still seen square on
/// (#2227), as the mouse can. Off (the default): the cap pans and zooms a square-on sketch and
/// turns it only after the view is tilted away from it.
space_mouse_sketch_orbit: bool = false, PAGE_NAVIGATION => check_id("ui.3d_mouse_sketch_orbit");
/// 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
@@ -2519,6 +2523,9 @@ fn space_mouse_rows(app: &mut SolveApp, ui: &mut egui::Ui) {
});
ui.allocate_ui_with_layout(egui::vec2(width, 0.0), egui::Layout::top_down(egui::Align::Min), |ui| {
setting::space_mouse_in_view(app, ui).on_hover_text(crate::i18n::tr("ui.3d_mouse_show_in_view_tip"));
ui.add_enabled_ui(app.preferences.space_mouse_enabled, |ui| {
setting::space_mouse_sketch_orbit(app, ui).on_hover_text(crate::i18n::tr("ui.3d_mouse_sketch_orbit_tip"));
});
});
});
// Where the picture goes, a choice that waits on the checkbox above.
@@ -2870,6 +2877,7 @@ pub fn restore_space_mouse_defaults(app: &mut SolveApp) {
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;
p.space_mouse_sketch_orbit = d.space_mouse_sketch_orbit;
}
/// The device's picture with the coordinate circles under it, and a box with a small model that
@@ -4268,6 +4276,7 @@ mod tests {
p.space_mouse_ghost_position = SpaceMouseGhost::LeftWindow;
p.space_mouse_in_view = true;
p.space_mouse_model_pivot = true;
p.space_mouse_sketch_orbit = true;
let before = h.app.preferences.clone();
let camera = h.app.cam;
restore_space_mouse_defaults(&mut h.app);
@@ -4279,7 +4288,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);
assert_eq!((p.space_mouse_model_pivot, p.space_mouse_sketch_orbit), (d.space_mouse_model_pivot, d.space_mouse_sketch_orbit));
// 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);
+4 -2
View File
@@ -17,7 +17,9 @@ versions. Two preferences opt into holding the model:
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 you
adjust the view with the navigation cube, the cap can rotate it too. The Navigation
adjust the view with the navigation cube, the cap can rotate it too. Turn on **Turn sketches with
the 3D mouse** (`space_mouse_sketch_orbit: true`) to let the cap rotate a sketch seen square on as
well, as the mouse can. The Navigation
page in Preferences has an on/off switch, a speed control and, for each of the cap's six axes, an
invert switch and a speed for the 3D mouse. The cap's zoom direction comes from its own invert
switch; **Reverse zoom direction** under Wheel and trackpad reverses the wheel only (#8993). The web app reads
@@ -84,7 +86,7 @@ know, is ignored:
| Message | Meaning |
|---|---|
| `{"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":"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 and seen square on, unless **Turn sketches with the 3D mouse** is on; 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. 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. |
+1
View File
@@ -462,6 +462,7 @@ One setting per line, sorted by name. A change that adds a setting adds its own
- `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)
- `space_mouse_sketch_orbit` (default false: the 3D mouse and navigation bridge pan and zoom a sketch seen square on and turn it only after the view is tilted; true lets them turn it too, as the mouse can)
- `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 and Don't ask again as the handles `stand_up:stand` and `stand_up:never`, and its close (×) as `toast:stand_up:close` (also `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)