View cube and axis gizmo: a standard view centres and fits the model (#10091) (#10092)

* claim: #10091

* View cube and axis gizmo: a standard view centres and fits the model (#10091)

A new Navigation preference, "Fit the model after a navigator view change"
(`navigator_fit`, off by default): with it on, a face, corner or arrow of
the view cube and an axis tip of the gizmo look at the middle of the model
from the one distance that fits its bounding sphere, so Home, an opened
design and every view chosen on a navigator share one zoom and one centre
and only the direction changes. Off, both navigators turn in place as
before.

"Home and Fit size" (`home_fit_size`, 10–100 %, default 100 %) is how much
of the view between the panels and the controls the model fills when Home,
Fit, an opened design or a navigator view change frames it; 100 % is the
framing as before.

`view.navigate` takes an optional `fit: true` with a direction or a turn,
so programmatic callers get the same framing.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
froglemonade2
2026-10-31 18:34:13 +00:00
committed by GitHub
parent 6541a4e980
commit 441d67f9ff
10 changed files with 356 additions and 23 deletions
+50
View File
@@ -0,0 +1,50 @@
{
"en": {
"prefs.navigator_fit": "Fit the model after a navigator view change",
"prefs.navigator_fit_note": "A face, corner or arrow of the view cube, or an axis of the gizmo, also looks at the middle of the model from the one distance that fits it from every side (its bounding sphere). Home uses the same zoom and centre while this is on, so views chosen after it only turn. Off: the view turns in place, keeping its target and zoom.",
"prefs.home_fit_size": "Home and Fit size",
"prefs.home_fit_size_note": "How much of the view the model fills when Home, Fit, an opened design or a navigator view change frames it, whether or not the setting below is on. 100 %: fills the view between the panels, the compass and the navigation bar."
},
"de": {
"prefs.navigator_fit": "Modell nach einem Ansichtswechsel am Navigator einpassen",
"prefs.navigator_fit_note": "Eine Fläche, Ecke oder ein Pfeil des Würfels oder eine Achse des Gizmos blickt auch auf die Mitte des Modells, aus dem einen Abstand, der es von jeder Seite einpasst (seine Hüllkugel). Home nutzt denselben Zoom und dieselbe Mitte, solange dies an ist, sodass danach gewählte Ansichten sich nur drehen. Aus: Die Ansicht dreht sich an Ort und Stelle und behält Ziel und Zoom.",
"prefs.home_fit_size": "Größe bei Home und Einpassen",
"prefs.home_fit_size_note": "Wie viel der Ansicht das Modell füllt, wenn Home, Einpassen, ein geöffnetes Design oder ein Ansichtswechsel am Navigator es einrahmt, unabhängig von der Einstellung darunter. 100 %: füllt die Ansicht zwischen den Leisten, dem Kompass und der Navigationsleiste."
},
"ja": {
"prefs.navigator_fit": "ナビゲーターでの視点変更後にモデルを全体表示",
"prefs.navigator_fit_note": "キューブの面・角・矢印やギズモの軸をクリックすると、どの方向からでも全体が収まる一定の距離(外接球)からモデルの中心を見ます。オンの間はホームビューも同じズームと中心を使うため、その後に選んだ視点は向きだけが変わります。オフ: 視点はその場で回転し、注視点とズームを保ちます。",
"prefs.home_fit_size": "ホームと全体表示の大きさ",
"prefs.home_fit_size_note": "ホーム、全体表示、開いたデザイン、ナビゲーターでの視点変更がモデルを画面に収めるときに、モデルがビューに占める割合。下の設定のオン・オフにかかわらず適用されます。100 %: パネル、コンパス、ナビゲーションバーの間のビューをいっぱいに使います。"
},
"ko": {
"prefs.navigator_fit": "뷰 탐색기로 뷰를 바꾼 뒤 모델 맞춤",
"prefs.navigator_fit_note": "큐브의 면, 모서리, 화살표나 기즈모의 축을 클릭하면 어느 방향에서든 전체가 들어가는 한 거리(경계 구)에서 모델의 중심을 바라봅니다. 켜져 있는 동안 홈 뷰도 같은 확대/축소와 중심을 쓰므로 그 뒤에 고른 뷰는 방향만 바뀝니다. 끄면 뷰가 제자리에서 회전하며 대상과 확대/축소를 유지합니다.",
"prefs.home_fit_size": "홈·맞춤 크기",
"prefs.home_fit_size_note": "홈, 맞춤, 연 디자인 또는 뷰 탐색기의 뷰 변경으로 모델을 화면에 맞출 때 모델이 뷰에서 차지하는 비율. 아래 설정과 관계없이 적용됩니다. 100 %: 패널, 나침반, 내비게이션 바 사이의 뷰를 가득 채웁니다."
},
"zh": {
"prefs.navigator_fit": "视图导航器切换视图后适配模型",
"prefs.navigator_fit_note": "点击立方体的面、角或箭头,或坐标轴指示器的轴时,也会从各个方向都能容纳模型的同一距离(其包围球)注视模型中心。开启期间主视图使用相同的缩放和中心,因此之后选择的视图只改变方向。关闭:视图原地旋转,保持目标点和缩放。",
"prefs.home_fit_size": "主视图与适配大小",
"prefs.home_fit_size_note": "主视图、适配、打开的设计或视图导航器切换视图框住模型时,模型占视图的比例,与下方设置是否开启无关。100 %:填满面板、罗盘和导航栏之间的视图。"
},
"ar": {
"prefs.navigator_fit": "ملاءمة النموذج بعد تغيير العرض من متصفح العرض",
"prefs.navigator_fit_note": "النقر على وجه أو ركن أو سهم في المكعب، أو على محور في أداة المحاور، ينظر أيضاً إلى منتصف النموذج من المسافة الواحدة التي تُظهره كاملاً من كل جهة (كرته المحيطة). يستخدم العرض الرئيسي التكبير والمركز نفسيهما ما دام هذا مفعّلاً، فلا تغيّر العروض المختارة بعده سوى الاتجاه. عند الإيقاف: يدور العرض في مكانه محتفظاً بالهدف والتكبير.",
"prefs.home_fit_size": "حجم العرض الرئيسي والملاءمة",
"prefs.home_fit_size_note": "مقدار ما يملؤه النموذج من العرض عندما يُظهره العرض الرئيسي أو الملاءمة أو تصميم مفتوح أو تغيير العرض من متصفح العرض، سواء كان الإعداد أدناه مفعّلاً أم لا. 100 %: يملأ العرض بين اللوحات والبوصلة وشريط التنقل."
},
"he": {
"prefs.navigator_fit": "התאמת המודל לאחר שינוי תצוגה בניווט התצוגה",
"prefs.navigator_fit_note": "לחיצה על פאה, פינה או חץ בקובייה, או על ציר בגיזמו, גם מביטה אל מרכז המודל מהמרחק האחד שמכיל אותו מכל צד (הכדור החוסם שלו). תצוגת בית משתמשת באותו זום ובאותו מרכז כל עוד זה פעיל, כך שתצוגות שנבחרות אחריה רק מסתובבות. כבוי: התצוגה מסתובבת במקומה ושומרת על היעד ועל הזום.",
"prefs.home_fit_size": "גודל בתצוגת בית ובהתאמה",
"prefs.home_fit_size_note": "כמה מהתצוגה המודל ממלא כשתצוגת בית, התאמה, עיצוב שנפתח או שינוי תצוגה בניווט ממסגרים אותו, בין אם ההגדרה שלמטה פעילה ובין אם לא. 100 %: ממלא את התצוגה שבין הלוחות, המצפן וסרגל הניווט."
},
"vi": {
"prefs.navigator_fit": "Khớp mô hình sau khi đổi góc nhìn bằng khối điều hướng",
"prefs.navigator_fit_note": "Nhấp vào một mặt, góc hoặc mũi tên của khối lập phương, hoặc một trục của gizmo, cũng nhìn vào tâm mô hình từ một khoảng cách duy nhất chứa trọn nó từ mọi phía (khối cầu bao). Khi bật, góc nhìn chuẩn (Home) dùng cùng mức thu phóng và tâm đó, nên các góc nhìn chọn sau chỉ xoay. Tắt: góc nhìn xoay tại chỗ, giữ nguyên điểm nhìn và mức thu phóng.",
"prefs.home_fit_size": "Cỡ Home và Khớp",
"prefs.home_fit_size_note": "Mô hình chiếm bao nhiêu phần khung nhìn khi Home, Khớp, một thiết kế vừa mở hoặc đổi góc nhìn bằng khối điều hướng đưa nó vào khung hình, dù tùy chọn bên dưới bật hay tắt. 100 %: lấp đầy khung nhìn giữa các bảng, la bàn và thanh điều hướng."
}
}
+39 -2
View File
@@ -106,7 +106,7 @@ CommandSpec::new("view.navigate", "Navigate View", navigate)
.icon("orbit")
.noundo()
.doc_only()
.params("camera: Camera; direction?: [x,y,z] in the camera's up-axis frame; or action: left|right|up|down|clockwise|counterclockwise|home|fit, degrees?: 0..180 (how far left|right|up|down turn; default 90); or motion: pan|orbit|zoom, delta?: [dx,dy] (pixels, each ±10000), free_orbit?: bool (orbit through poles, default false), viewport?: [width,height] (1..1000000, required for pan or pivot), pivot?: [x,y,z], factor?: 0.05..20 (required for zoom), anchor?: [x,y,z] → camera, fit, continuous?"),
.params("camera: Camera; direction?: [x,y,z] in the camera's up-axis frame; or action: left|right|up|down|clockwise|counterclockwise|home|fit, degrees?: 0..180 (how far left|right|up|down turn; default 90), fit?: bool (frame the whole model from the new direction as well, as home does; default false); or motion: pan|orbit|zoom, delta?: [dx,dy] (pixels, each ±10000), free_orbit?: bool (orbit through poles, default false), viewport?: [width,height] (1..1000000, required for pan or pivot), pivot?: [x,y,z], factor?: 0.05..20 (required for zoom), anchor?: [x,y,z] → camera, fit, continuous?"),
CommandSpec::new("view.normal_to", "Normal to Selection", normal_to)
.icon("camera")
.noundo()
@@ -436,10 +436,19 @@ fn navigate(_s: &mut Session, p: &Value) -> Result<Value> {
{
return Err(bad(cmd, "invalid camera"));
}
// A turn may ask the window to frame the whole model from the new direction, as `home` does
// (the navigators' Fit preference, #10091).
let framed = match p.get("fit") {
None => false,
Some(value) => value.as_bool().ok_or_else(|| bad(cmd, "fit must be a boolean"))?,
};
if p.get("motion").is_some() {
if framed {
return Err(bad(cmd, "fit does not apply to a motion"));
}
return continuous(cam, p);
}
let mut fit = false;
let mut fit = framed;
if let Some(value) = p.get("direction") {
let dir = vec3(value)
.filter(|v| v.is_finite() && v.len() <= 2.0)
@@ -752,6 +761,34 @@ mod tests {
}
}
/// #10091: a turn asked to frame the model reports `fit`, as home does; a motion can't.
#[test]
fn a_turn_with_fit_asks_the_window_to_frame_the_model() {
let mut s = Session::default();
let before = s.doc.to_json();
let cam = Camera { distance: 100.0, ..Default::default() };
for params in
[json!({"camera": cam, "direction": [0, 0, 1]}), json!({"camera": cam, "action": "right"}), json!({"camera": cam, "action": "clockwise"})]
{
let plain = s.execute("view.navigate", &params).unwrap();
assert_eq!(plain["fit"], false, "{params}");
let mut framed = params.clone();
framed["fit"] = json!(true);
let result = s.execute("view.navigate", &framed).unwrap();
assert_eq!(result["fit"], true, "{params}");
assert_eq!(result["camera"], plain["camera"], "fit asks for the framing, the turn is the same");
framed["fit"] = json!(false);
assert_eq!(s.execute("view.navigate", &framed).unwrap(), plain);
}
assert_eq!(s.execute("view.navigate", &json!({"camera": cam, "action": "home", "fit": false})).unwrap()["fit"], true, "home frames anyway");
for value in [json!(1), json!("yes"), Value::Null, json!([true])] {
assert!(s.execute("view.navigate", &json!({"camera": cam, "action": "right", "fit": value})).is_err(), "{value}");
}
assert!(s.execute("view.navigate", &json!({"camera": cam, "motion": "zoom", "factor": 2.0, "fit": true})).is_err());
assert!(s.execute("view.navigate", &json!({"camera": cam, "motion": "zoom", "factor": 2.0, "fit": false})).is_ok());
assert_eq!(s.doc.to_json(), before);
}
#[test]
fn continuous_navigation_moves_the_camera_without_editing_the_design() {
let mut s = Session::default();
+78 -16
View File
@@ -715,7 +715,9 @@ pub struct SolveApp {
shot_token: u64,
styled: bool,
fitted: bool,
pending_fit: Option<(Camera, solidcraft_engine::geom::Aabb3, bool)>,
/// A framing to settle once the viewport's layout is known: the camera to frame from, the
/// bounds, whether to glide there, and whether it is the navigators' shared-zoom framing.
pending_fit: Option<(Camera, solidcraft_engine::geom::Aabb3, bool, bool)>,
/// Frames a pending fit has waited for a layout that can frame it (`resolve_fit`).
fit_waits: u32,
/// The sheet metal flat pattern's own pan and zoom.
@@ -1373,9 +1375,7 @@ impl SolveApp {
self.cancel_view_animation();
self.cam = to;
} else if v.get("fit").and_then(Value::as_bool).unwrap_or(false) {
let bounds = solidcraft_engine::view::bounds(&self.session);
self.animate_to(self.fitted(to));
self.pending_fit = Some((to, bounds, true));
self.animate_to_fitted(to);
} else {
self.animate_to(to);
}
@@ -2402,16 +2402,19 @@ impl SolveApp {
self.cam_anim = None;
self.viewport.orbit_free = None;
let bounds = viewport::view_bounds(self);
self.pending_fit = Some((self.cam, bounds, false));
// Framed as the Home button frames: with the navigators' Fit on, that is their shared
// zoom and centre, so a design opens the way Home shows it (#10091).
let shared = self.preferences.navigator_fit;
self.pending_fit = Some((self.cam, bounds, false, shared));
self.fit_waits = 0;
self.cam = self.fitted(self.cam);
self.cam = if shared { self.navigator_fitted(self.cam) } else { self.fitted(self.cam) };
}
/// Frame `bounds` at once, keeping the view direction (programmatic use).
pub fn fit_bounds(&mut self, bounds: solidcraft_engine::geom::Aabb3) {
self.cancel_view_animation();
self.viewport.orbit_free = None;
self.pending_fit = Some((self.cam, bounds, false));
self.pending_fit = Some((self.cam, bounds, false, false));
self.fit_waits = 0;
self.cam = self.fitted_bounds(self.cam, &bounds);
}
@@ -2436,7 +2439,36 @@ impl SolveApp {
if render_workspace::active(self) {
return viewport_layout::fit_product_bounds(cam, bounds, &render_workspace::picture_layout(self, layout));
}
viewport_layout::fit_bounds(cam, bounds, layout, self.view_fov())
viewport_layout::fit_bounds_sized(cam, bounds, layout, self.view_fov(), f64::from(self.preferences.home_fit_size))
}
/// `cam` framing the whole model the navigators' way (#10091): looking at the middle of the
/// model from the distance that fits its bounding sphere in the free part of the view, at
/// the Fit size. The sphere looks the same from every side, so Home and every face,
/// corner, arrow or axis clicked after it keep one zoom and one centre; only the direction
/// changes.
fn navigator_fitted(&self, cam: Camera) -> Camera {
let bounds = viewport::view_bounds(self);
self.navigator_fitted_bounds(cam, &bounds).unwrap_or_else(|| self.fitted(cam))
}
/// [`Self::navigator_fitted`] for `bounds`, or `None` when the layout can't frame it yet.
fn navigator_fitted_bounds(&self, mut cam: Camera, bounds: &solidcraft_engine::geom::Aabb3) -> Option<Camera> {
if bounds.is_empty() || !bounds.min.is_finite() || !bounds.max.is_finite() {
return None;
}
let centre = bounds.center();
let radius = (bounds.diagonal() * 0.5).max(0.5);
// A cube around the sphere, seen square-on from any axis, projects to the sphere's own
// square, so the layout fit of that cube is the sphere's.
let offset = solidcraft_engine::geom::Vec3::new(radius, radius, radius);
let sphere = solidcraft_engine::geom::Aabb3 { min: centre - offset, max: centre + offset };
let mut probe = Camera::default();
probe.set_view(StandardView::Front);
let framed = self.try_fitted_bounds(probe, &sphere)?;
cam.target = centre;
cam.distance = framed.distance;
cam.is_valid().then_some(cam)
}
fn fitted_bounds(&self, mut cam: Camera, bounds: &solidcraft_engine::geom::Aabb3) -> Camera {
@@ -2454,11 +2486,17 @@ impl SolveApp {
fn resolve_fit(&mut self, ctx: &egui::Context) {
viewport::refresh_layout(self, ctx);
if self.viewport.layout.is_some()
&& let Some((cam, bounds, animate)) = self.pending_fit.take()
&& let Some((cam, bounds, animate, shared)) = self.pending_fit.take()
{
// Nothing to frame: the camera goes to the empty design's own distance.
let want = if bounds.is_empty() { viewport::view_bounds(self) } else { bounds };
let to = if want.is_empty() { Some(self.fitted(cam)) } else { self.try_fitted_bounds(cam, &want) };
let to = if want.is_empty() {
Some(self.fitted(cam))
} else if shared {
self.navigator_fitted_bounds(cam, &want)
} else {
self.try_fitted_bounds(cam, &want)
};
let Some(to) = to else {
// The viewport hasn't been drawn since the fit was asked for (the Home screen was
// over it, as when a sample or a file is opened from it), so framing it now would
@@ -2467,7 +2505,7 @@ impl SolveApp {
// viewport is drawn; give up only if that never comes.
if self.fit_waits < Self::FIT_WAITS {
self.fit_waits += 1;
self.pending_fit = Some((cam, bounds, animate));
self.pending_fit = Some((cam, bounds, animate, shared));
} else {
self.fit_waits = 0;
self.cam = self.fitted_bounds(cam, &want);
@@ -2523,12 +2561,33 @@ impl SolveApp {
return;
}
self.pending_fit = None;
let request = Some((self.cam, viewport::view_bounds(self), true));
let request = Some((self.cam, viewport::view_bounds(self), true, false));
let to = self.fitted(self.cam);
self.animate_to(to);
self.pending_fit = request;
}
/// Move to `to` and frame the whole model from there at Home's zoom (animated): the
/// navigators' Home, faces, corners, arrows and axes (`navigator_fitted`).
pub fn animate_to_fitted(&mut self, to: Camera) {
let bounds = solidcraft_engine::view::bounds(&self.session);
let shared = self.preferences.navigator_fit;
let framed = if shared { self.navigator_fitted(to) } else { self.fitted(to) };
self.animate_to(framed);
self.pending_fit = Some((to, bounds, true, shared));
}
/// A view chosen on a navigator (a cube face, corner or arrow, an axis tip): the view turns
/// in place, or frames the whole model from the new direction when Preferences › Navigation
/// asks for it (`navigator_fit`, #10091).
pub fn animate_turn(&mut self, to: Camera) {
if self.preferences.navigator_fit {
self.animate_to_fitted(to);
} else {
self.animate_to(to);
}
}
/// Animated view changes for the axis view and navigation bar.
pub fn animate_view(&mut self, v: &str) {
if matches!(v, "fit" | "home") {
@@ -2563,17 +2622,20 @@ impl SolveApp {
let mut to = self.cam;
if home {
to.set_view(StandardView::Iso);
self.pending_fit = Some((to, viewport::view_bounds(self), true));
to = self.fitted(to);
// With the navigators' Fit on, Home shares their zoom, so a face clicked after it
// keeps the zoom (#10091).
let shared = self.preferences.navigator_fit;
self.pending_fit = Some((to, viewport::view_bounds(self), true, shared));
to = if shared { self.navigator_fitted(to) } else { self.fitted(to) };
} else {
// With something selected, Fit frames the selection.
match viewport::selection_bounds(self) {
Some(bounds) => {
self.pending_fit = Some((to, bounds, true));
self.pending_fit = Some((to, bounds, true, false));
to = self.fitted_bounds(to, &bounds);
}
None => {
self.pending_fit = Some((to, viewport::view_bounds(self), true));
self.pending_fit = Some((to, viewport::view_bounds(self), true, false));
to = self.fitted(to);
}
}
+59
View File
@@ -130,6 +130,10 @@ fn navigate(app: &mut SolveApp, action: Option<&str>, dir: Option<Vec3>) {
if let Some(d) = dir {
params["direction"] = json!([d.x, d.y, d.z]);
}
// Preferences › Navigation: a view chosen on the cube also frames the whole model (#10091).
if app.preferences.navigator_fit {
params["fit"] = json!(true);
}
let _ = app.run("view.navigate", params);
}
@@ -512,6 +516,61 @@ mod tests {
assert_eq!(h.app.cam.distance, cam.distance);
}
/// #10091: with Preferences › Navigation "Fit the model after a navigator view change" on, a
/// cube face, corner or arrow frames the whole model from the new direction, as Home does;
/// off (the default) the view turns in place, keeping its target and zoom.
#[test]
fn cube_views_frame_the_model_when_the_navigation_preference_asks() {
let mut h = crate::scenario::Harness::new();
h.call("ui.prefs", json!({"navigator_style":"cube", "look_at_anim":false}));
assert!(!h.app.preferences.navigator_fit, "off by default");
h.app.run("solid.box", json!({"corner":[100,0,0],"length":20,"width":20,"height":20})).unwrap();
h.settle();
let undo = h.app.session.undo.len();
let away = |h: &mut crate::scenario::Harness| {
h.call("ui.view", json!({"view":"iso"}));
h.app.cam.pan(600.0, 400.0, 500.0);
h.app.cam.distance *= 4.0;
h.frames(2);
h.app.cam
};
let from = away(&mut h);
let p = crate::scenario::handle_at("navigation_cube:front").unwrap();
h.call("ui.click", json!({"x":p.x,"y":p.y}));
h.frames(2);
assert!(h.app.cam.back().dist(-Vec3::Y) < 1e-6);
assert_eq!(h.app.cam.target, from.target, "off: the target stays");
assert_eq!(h.app.cam.distance, from.distance, "off: the zoom stays");
h.call("ui.prefs", json!({"navigator_fit":true}));
for handle in ["navigation_cube:front", "navigation_cube:top_front_right", "navigation_cube:control:right"] {
let from = away(&mut h);
let p = crate::scenario::handle_at(handle).unwrap();
h.call("ui.click", json!({"x":p.x,"y":p.y}));
h.frames(2);
if handle == "navigation_cube:front" {
assert!(h.app.cam.back().dist(-Vec3::Y) < 1e-6);
}
assert!(h.app.cam.target.dist(Vec3::new(110.0, 10.0, 10.0)) < 1e-6, "{handle}: looks at the middle of the model, {:?}", h.app.cam.target);
assert!(h.app.cam.distance < from.distance / 2.0, "{handle}: {} vs {}", h.app.cam.distance, from.distance);
}
// Home, then a face, a corner or an arrow: the zoom and the centre stay; only the
// direction changes.
let click = |h: &mut crate::scenario::Harness, handle: &str| {
let p = crate::scenario::handle_at(handle).unwrap_or_else(|| panic!("{handle} is not on the cube"));
h.call("ui.click", json!({"x":p.x,"y":p.y}));
h.frames(2);
};
click(&mut h, "navigation_cube:control:home");
let home = h.app.cam;
for handle in ["navigation_cube:front", "navigation_cube:top", "navigation_cube:top_front_right", "navigation_cube:control:right"] {
click(&mut h, "navigation_cube:control:home");
click(&mut h, handle);
assert!((h.app.cam.distance - home.distance).abs() < 1e-6, "{handle}: {} vs Home's {}", h.app.cam.distance, home.distance);
assert!(h.app.cam.target.dist(home.target) < 1e-6, "{handle}: {:?} vs Home's {:?}", h.app.cam.target, home.target);
}
assert_eq!(h.app.session.undo.len(), undo, "a view change edits nothing");
}
#[test]
fn cube_navigation_eases_through_intermediate_views_and_can_be_interrupted() {
let mut h = crate::scenario::Harness::new();
+17
View File
@@ -1248,6 +1248,14 @@ preference_settings! {
network_hosts: Vec<String> = Vec::new(), PAGE_DESIGN;
/// What a middle-button double-click in the view does: `home`, `fit` or `off`.
middle_double_click: String = "home".into(), PAGE_NAVIGATION;
/// A view chosen on the navigator (a cube face, corner or arrow, an axis tip) also frames the
/// whole model, as Home does (#10091). Off by default: the view turns in place, keeping its
/// target and zoom.
navigator_fit: bool = false, PAGE_NAVIGATION;
/// How much of the view the model fills when Home, Fit, an opened design or a navigator
/// view change frames it (0.1 to 1; #10091): 1, the default, fills the room between the
/// panels, the compass and the navigation bar, as before.
home_fit_size: f32 = 1.0, PAGE_NAVIGATION, accept(0.1..=1.0);
/// Colour vision mode (#778): `off`, `protan`, `deutan` or `tritan`.
color_vision: crate::theme::ColorVision = crate::theme::ColorVision::Off, PAGE_INTERFACE;
/// Check for updates at start and once a day (docs/updates.md).
@@ -3719,6 +3727,9 @@ pub fn migrate(mut p: Prefs) -> Prefs {
if !accepted::wheel_zoom_speed(&p) {
p.wheel_zoom_speed = Prefs::default().wheel_zoom_speed;
}
if !accepted::home_fit_size(&p) {
p.home_fit_size = Prefs::default().home_fit_size;
}
if p.orbit_cursor {
p.orbit_around = OrbitAround::Cursor;
p.orbit_cursor = false;
@@ -3854,6 +3865,9 @@ fn prepare_preferences(
if !accepted::wheel_zoom_speed(&new) {
return Err("`wheel_zoom_speed` must be 0.25…4".into());
}
if !accepted::home_fit_size(&new) {
return Err("`home_fit_size` must be 0.1…1".into());
}
let new = migrate(new);
if !UNITS.contains(&new.default_units.as_str()) {
return Err(format!("units must be one of {}", UNITS.join(", ")));
@@ -3926,6 +3940,9 @@ fn prepare_preferences(
if !accepted::print_face_highlight(&new) {
return Err("`print_face_highlight` must be 0…1".into());
}
if !accepted::home_fit_size(&new) {
return Err("`home_fit_size` must be 0.1…1".into());
}
if !accepted::perspective_fov(&new) {
return Err("`perspective_fov` must be 15°…90° in radians (0.2618…1.5708)".into());
}
+14
View File
@@ -164,6 +164,17 @@ pub(super) fn show(app: &mut SolveApp, ui: &mut egui::Ui, t: &Tokens) {
ui_kit::divider(ui, "navigation_view_controls");
ui_kit::settings_form(ui, 150.0, |ui| {
setting::wheel_zoom_speed(app, ui);
let (label, note) = (app.tr("prefs.home_fit_size").to_owned(), app.tr("prefs.home_fit_size_note").to_owned());
ui_kit::row(ui, &label, |ui| {
let response = ui_kit::slider(
ui,
&mut app.preferences.home_fit_size,
0.1..=1.0,
ui_kit::Slider { step: Some(0.05), format: |v| format!("{:.0} %", v * 100.0), ..Default::default() },
);
crate::scenario::publish_rect("prefs:home_fit_size", response.rect);
response.on_hover_text(&note)
});
ui_kit::row(ui, app.tr_label("View navigator"), |ui| {
let mut selected = usize::from(app.preferences.navigator_style == NavigatorStyle::Cube);
if ui_kit::segmented(
@@ -186,6 +197,9 @@ pub(super) fn show(app: &mut SolveApp, ui: &mut egui::Ui, t: &Tokens) {
}
}
});
let (label, note) = (app.tr("prefs.navigator_fit").to_owned(), app.tr("prefs.navigator_fit_note").to_owned());
let fit = ui_kit::checkbox(ui, &label, &mut app.preferences.navigator_fit).on_hover_text(note);
crate::scenario::publish_target("prefs:navigator_fit", fit.rect);
ui_kit::row(ui, app.tr_label("Middle double-click"), |ui| {
let current = MiddleDoubleClick::of(app);
ui_kit::settings_control_width(ui, t.form_label_width * 2.0 + t.space_24 * 2.0 + t.space_12, |ui| {
+30
View File
@@ -278,6 +278,36 @@ fn fit_and_home_json_commands_preserve_design_framing() {
assert_eq!(h.app.session.undo.len(), undo);
}
/// #10091: Preferences › Navigation "Home and Fit size" is how much of the view the model fills
/// when Home and Fit (and an opened design or a navigator view change) frame it; 100 %, the
/// default, fills the room between the panels and the controls as before.
#[test]
fn home_fit_size_scales_the_framed_model() {
let mut h = Harness::new();
h.app.preferences.look_at_anim = false;
moved_block(&mut h);
assert_eq!(h.app.preferences.home_fit_size, 1.0, "fills the room by default");
h.call("engine.execute", json!({"command":"view.home","params":{}}));
h.frames(2);
let tight = h.app.cam;
h.call("ui.prefs", json!({"home_fit_size":0.8}));
for command in ["view.home", "view.fit"] {
h.call("engine.execute", json!({"command":command,"params":{}}));
h.frames(2);
assert!((h.app.cam.distance / tight.distance - 1.25).abs() < 0.02, "{command}: {} vs {}", h.app.cam.distance, tight.distance);
assert_eq!((h.app.cam.yaw, h.app.cam.pitch), (tight.yaw, tight.pitch), "{command}: the size only zooms");
}
for bad in [1.5, 0.05, 0.0, -1.0] {
let r = h.call("ui.prefs", json!({"home_fit_size":bad}));
assert_eq!(r["ok"], false, "{bad} is outside 10 %…100 %: {r}");
}
assert!((h.app.preferences.home_fit_size - 0.8).abs() < 1e-6);
h.call("ui.prefs", json!({"open":"Navigation"}));
h.call("ui.prefs", json!({"button":"defaults"}));
assert_eq!(h.app.preferences.home_fit_size, 1.0, "Navigation defaults restore 100 %");
h.call("ui.prefs", json!({"button":"cancel"}));
}
#[test]
fn fit_json_frames_selection_while_home_frames_everything() {
let mut h = Harness::new();
+51 -1
View File
@@ -6632,7 +6632,7 @@ fn signed_axis_view(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect) {
if frame.z.abs() > 0.5 {
to.yaw = nearest_quarter_turn(app.cam.yaw);
}
app.animate_to(to);
app.animate_turn(to);
}
}
let home = Rect::from_center_size(pos2(c.x - 37.0, c.y - 37.0), vec2(18.0, 18.0));
@@ -10767,6 +10767,56 @@ mod tests {
}
}
/// #10091: an axis tip turns the view in place by default; with Preferences › Navigation
/// "Fit the model after a navigator view change" on it also frames the whole model, as Home does.
#[test]
fn axis_tips_frame_the_model_when_the_navigation_preference_asks() {
let mut h = crate::scenario::Harness::new();
h.call("ui.prefs", json!({"navigator_style":"axes", "look_at_anim":false}));
h.app.run("solid.box", json!({"corner":[100,0,0],"length":20,"width":20,"height":20})).unwrap();
h.settle();
let undo = h.app.session.undo.len();
let away = |h: &mut crate::scenario::Harness| {
h.call("ui.view", json!({"view":"iso"}));
h.app.cam.pan(300.0, 200.0, 500.0);
h.app.cam.distance *= 4.0;
h.frames(2);
h.app.cam
};
let from = away(&mut h);
let p = crate::scenario::handle_at("axis_view:-y").unwrap();
h.call("ui.click", json!({"x":p.x,"y":p.y}));
h.frames(2);
assert!(h.app.cam.back().dist(-Vec3::Y) < 1e-6);
assert_eq!(h.app.cam.target, from.target, "off by default: the target stays");
assert_eq!(h.app.cam.distance, from.distance, "off by default: the zoom stays");
h.call("ui.prefs", json!({"navigator_fit":true}));
let from = away(&mut h);
let p = crate::scenario::handle_at("axis_view:-y").unwrap();
h.call("ui.click", json!({"x":p.x,"y":p.y}));
h.frames(2);
assert!(h.app.cam.back().dist(-Vec3::Y) < 1e-6);
assert!(h.app.cam.target.dist(Vec3::new(110.0, 10.0, 10.0)) < 1e-6, "looks at the middle of the model, {:?}", h.app.cam.target);
assert!(h.app.cam.distance < from.distance / 2.0, "{} vs {}", h.app.cam.distance, from.distance);
// Home, then an axis: the zoom and the centre stay.
let home = crate::scenario::rect_of("axis_view:home").unwrap().center();
h.call("ui.click", json!({"x":home.x,"y":home.y}));
h.frames(2);
let framed = h.app.cam;
for axis in ["axis_view:-y", "axis_view:z"] {
let p = crate::scenario::handle_at(axis).unwrap();
h.call("ui.click", json!({"x":p.x,"y":p.y}));
h.frames(2);
assert!((h.app.cam.distance - framed.distance).abs() < 1e-6, "{axis}: {} vs Home's {}", h.app.cam.distance, framed.distance);
assert!(h.app.cam.target.dist(framed.target) < 1e-6, "{axis}: {:?} vs Home's {:?}", h.app.cam.target, framed.target);
}
h.call("ui.prefs", json!({"open":"Navigation"}));
h.call("ui.prefs", json!({"button":"defaults"}));
assert!(!h.app.preferences.navigator_fit, "Navigation defaults restore the in-place turn");
h.call("ui.prefs", json!({"button":"cancel"}));
assert_eq!(h.app.session.undo.len(), undo, "a view change edits nothing");
}
#[test]
fn view_axis_drag_owns_navigation_and_keeps_the_view_centre() {
for mode in [crate::shell::LayoutMode::Floating, crate::shell::LayoutMode::Docked] {
+10 -2
View File
@@ -185,11 +185,19 @@ pub(crate) fn fit_product_bounds(cam: Camera, bounds: &Aabb3, layout: &Layout) -
fit_bounds(cam, bounds, layout, cam.fov)
}
pub(crate) fn fit_bounds(mut cam: Camera, bounds: &Aabb3, layout: &Layout, fov: f64) -> Option<Camera> {
pub(crate) fn fit_bounds(cam: Camera, bounds: &Aabb3, layout: &Layout, fov: f64) -> Option<Camera> {
fit_bounds_sized(cam, bounds, layout, fov, 1.0)
}
/// [`fit_bounds`] with the model filling `share` (0.1 to 1) of the room between the panels, the
/// compass and the navigation bar instead of all of it: the Navigation preference "Home and Fit
/// size" (#10091). The model stays clear of what covers the view at every size.
pub(crate) fn fit_bounds_sized(mut cam: Camera, bounds: &Aabb3, layout: &Layout, fov: f64, share: f64) -> Option<Camera> {
let perspective = fov > 0.0;
if !fov.is_finite() || !(0.0..std::f64::consts::PI).contains(&fov) {
return None;
}
let share = if share.is_finite() { share.clamp(0.1, 1.0) } else { 1.0 };
if bounds.is_empty()
|| !bounds.min.is_finite()
|| !bounds.max.is_finite()
@@ -237,7 +245,7 @@ pub(crate) fn fit_bounds(mut cam: Camera, bounds: &Aabb3, layout: &Layout, fov:
if !room.is_positive() || !room.is_finite() {
return None;
}
let hh = (hx * h / f64::from(room.width())).max(hy * h / f64::from(room.height())).max(0.5);
let hh = (hx * h / f64::from(room.width())).max(hy * h / f64::from(room.height())).max(0.5) / share;
let offset = room.center() - layout.viewport.center();
let tangent = if perspective { (fov * 0.5).tan() } else { 0.4 };
cam.distance = hh / tangent + if perspective { depth } else { 0.0 };
+8 -2
View File
@@ -442,6 +442,7 @@ One setting per line, sorted by name. A change that adds a setting adds its own
- `history_sketches` (`in_order` (default), `under_feature`: the History at the left lists a sketch under the first feature built from it, #6489; the timeline at the bottom keeps the creation order)
- `hole_moves` (default false: a placed Single hole has a drag handle (`hole:<n>`), and a pick on a face that has a hole moves it there)
- `hole_snaps` (default false: a Single hole snaps to its face's middle and round edges' centres)
- `home_fit_size` (0.1…1, default 1: how much of the view the model fills when Home, Fit, an opened design or a navigator view change frames it, with `navigator_fit` on or off; 1 fills the room between the panels, the compass and the navigation bar, as before; #10091)
- `joint_rotation_coarse` (default 10°): coarse Assembly Move rotation step, in 0.001…180°.
- `joint_rotation_fine` (default 0.1°): fine Assembly Move rotation step, in 0.001…180°.
- `keep_work_on_tab_switch` (default false: each design tab keeps its open dialog or tool, with what was picked and typed in it, and its toolbar tab while another design is shown, and has them back when it is shown again; off, a switch cancels them and shows MODEL, #9360)
@@ -458,6 +459,7 @@ One setting per line, sorted by name. A change that adds a setting adds its own
- `msaa`
- `nav` (`fusion`, `solidworks`, `inventor`, `alias`, `blender`, `tinkercad`, `openscad`, `touchpad`)
- `nav_bridge_enabled` (default false) and `nav_bridge_port` (default 8765: a device's own app on this computer moves the view, [the navigation bridge](3d-mouse.md#device-apps-the-navigation-bridge))
- `navigator_fit` (default false: a view chosen on the view cube or the axis gizmo also looks at the middle of the model from the one distance that fits its bounding sphere in the free part of the view, at `home_fit_size`; Home and an opened design use the same zoom and centre while it is on, so views chosen after them only turn; #10091)
- `offer_stand_up`
- `orbit_around` (`view_centre` (default: what Pan moves and Fit frames), `origin` (the world origin stays still on screen), `cursor` (the model point under the pointer when the drag began); the older `orbit_cursor` boolean still sets `cursor` when true)
- `orbit_reverse` (default false: Shift with two-finger scrolling orbits the other way)
@@ -606,8 +608,12 @@ animated view changes is enabled (the default), at the configured animation spee
The cube runs `view.navigate` through the command engine. Programmatic callers pass `camera`
and either `direction: [x,y,z]` in the camera's up-axis frame or `action` (`left`, `right`, `up`,
`down`, `clockwise`, `counterclockwise`, `home`, `fit`). The result contains `camera` and `fit`;
UI callers apply the camera with their animation preference, without editing the design.
`down`, `clockwise`, `counterclockwise`, `home`, `fit`). `fit: true` with a `direction` or a
turn asks for the whole model to be framed from the new direction as well, as `home` does. The
result contains `camera` and `fit`; UI callers apply the camera with their animation
preference, without editing the design. The Navigation preference `navigator_fit` (off by
default) makes every view chosen on the cube or on the axis gizmo frame the model this way:
looking at its middle from the one distance that fits its bounding sphere, which Home then shares.
Shift-orbit snapping includes 45-degree edge views and isometric corner views, with a
lightly damped spring transition and a small boundary margin to prevent flicker.