* 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:
@@ -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", ¶ms).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();
|
||||
|
||||
Reference in New Issue
Block a user