View angles: an optional readout under the orientation gizmo and a command to set them (#6032) (#6249)

* claim: #6032

* View angles: an optional readout under the orientation gizmo and a command to set them (#6032)

View > View angles (also Preferences > Graphics, or view.angle_readout) shows the
view's pitch, yaw and roll in degrees and Ortho/Persp under the axis view or cube,
updated live; off by default. Clicking the readout opens a small card to type
exact angles, which runs view.apply.

The angles are the camera's own (Camera::view_angles / with_view_angles), about
the up axis: yaw is the heading of the line of sight (Front 0, Left 90, Right -90,
Back 180), pitch the eye's elevation (Top 90, Bottom -90), and a positive roll
turns the model clockwise. view.apply documents this convention and now refuses a
pitch past +/-pi/2.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
HiroKenEz
2026-10-28 14:49:47 +00:00
committed by GitHub
parent 31d6873f7d
commit 4fa051c9fc
19 changed files with 666 additions and 4 deletions
@@ -1,6 +1,7 @@
//! Render shell requests. The UI applies validated echoes without design edits.
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::Value;
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
#[serde(deny_unknown_fields)]
@@ -36,3 +37,37 @@ pub struct RenderBrowser {
/// Open the floating Browser card in a narrow Render window.
pub open: bool,
}
/// Show or hide the View angles readout under the orientation gizmo (#6032): the view's pitch, yaw
/// and roll in degrees (the angles of `view.apply`'s camera, which takes them in radians) and Ortho
/// or Persp for the projection. A display setting the app keeps: not saved with the design, not an
/// undo step, and it never opens a dialog.
#[derive(Debug, Deserialize, JsonSchema)]
#[schemars(deny_unknown_fields)]
pub struct AngleReadoutParams {
/// True shows the readout, false hides it.
#[serde(deserialize_with = "enabled_flag")]
pub enabled: bool,
}
/// A boolean, with the `view.angle_readout` handler's message for anything else.
fn enabled_flag<'de, D: serde::Deserializer<'de>>(d: D) -> Result<bool, D::Error> {
match Value::deserialize(d)? {
Value::Bool(b) => Ok(b),
_ => Err(serde::de::Error::custom("must be a boolean")),
}
}
/// What `view.angle_readout` returns.
#[derive(Debug, Serialize, JsonSchema)]
pub struct AngleReadoutResult {
/// Whether the readout is shown now.
pub enabled: bool,
/// In the warn parameter-check mode: what the call's parameters got wrong.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub param_warnings: Vec<String>,
}
#[cfg(test)]
#[path = "view_navigation_tests.rs"]
mod tests;
@@ -0,0 +1,35 @@
use serde_json::{Value, json};
use super::AngleReadoutParams;
use crate::Session;
use crate::schema::tests::{assert_keys, assert_strict_keeps_todays_errors, conforms};
use crate::schema::{ParamCheck, input_schema_for, output_schema_for};
#[test]
fn schemas_and_the_key_check_agree() {
assert_keys(input_schema_for::<AngleReadoutParams>(), &["enabled"]);
}
#[test]
fn strict_keeps_todays_errors() {
assert_strict_keeps_todays_errors(&[
("view.angle_readout", json!({"enabled": 1})),
("view.angle_readout", json!({"enabled": "true"})),
("view.angle_readout", json!({"enabled": null})),
]);
}
#[test]
fn angle_readout_replies_match_the_output_schema() {
let schema = output_schema_for::<super::AngleReadoutResult>();
let schema = schema.as_value();
let mut s = Session { param_check: ParamCheck::Warn, ..Session::default() };
for enabled in [true, false] {
let r = s.execute("view.angle_readout", &json!({"enabled": enabled})).unwrap_or_else(|e| panic!("{e}"));
assert!(conforms(schema, schema, &r), "{r} doesn't match {schema}");
assert_eq!(r.get("param_warnings"), None, "{r}");
assert_eq!(r["enabled"], Value::Bool(enabled));
}
assert!(!conforms(schema, schema, &json!({"enabled": "yes"})));
assert!(!conforms(schema, schema, &json!({})));
}