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:
1 parent
31d6873f7d
commit
4fa051c9fc
19 files changed
+666
-4
No files matched your search
@@ -0,0 +1,98 @@
|
||||
{
|
||||
"en": {
|
||||
"cmd.view_angle_readout": "View Angles",
|
||||
"ui.view_angles": "View angles",
|
||||
"ui.view_angles_convention": "Degrees about the up axis. Yaw 0° is the Front view, 90° Left, −90° Right, 180° Back; pitch 90° is the Top view; a positive roll turns the model clockwise.",
|
||||
"ui.view_angles_help": "Shows the view's pitch, yaw and roll in degrees and its projection under the orientation gizmo. Click the readout to type exact angles.",
|
||||
"ui.view_angles_ortho": "Ortho",
|
||||
"ui.view_angles_persp": "Persp",
|
||||
"ui.view_angles_pitch": "Pitch",
|
||||
"ui.view_angles_readout": "Pitch {pitch} · Yaw {yaw} · Roll {roll}",
|
||||
"ui.view_angles_roll": "Roll",
|
||||
"ui.view_angles_yaw": "Yaw"
|
||||
},
|
||||
"ar": {
|
||||
"cmd.view_angle_readout": "زوايا العرض",
|
||||
"ui.view_angles": "زوايا العرض",
|
||||
"ui.view_angles_convention": "درجات حول المحور العلوي. الانعراج 0° هو العرض الأمامي، و90° الأيسر، و−90° الأيمن، و180° الخلفي؛ الانحدار 90° هو العرض العلوي؛ والدوران الموجب يدير النموذج على الشاشة باتجاه عقارب الساعة.",
|
||||
"ui.view_angles_help": "يعرض زوايا الانحدار والانعراج والدوران للعرض بالدرجات ونوع الإسقاط أسفل أداة الاتجاه. انقر على القراءة لكتابة زوايا دقيقة.",
|
||||
"ui.view_angles_ortho": "متعامد",
|
||||
"ui.view_angles_persp": "منظور",
|
||||
"ui.view_angles_pitch": "الانحدار",
|
||||
"ui.view_angles_readout": "الانحدار {pitch} · الانعراج {yaw} · الدوران {roll}",
|
||||
"ui.view_angles_roll": "الدوران",
|
||||
"ui.view_angles_yaw": "الانعراج"
|
||||
},
|
||||
"de": {
|
||||
"cmd.view_angle_readout": "Ansichtswinkel",
|
||||
"ui.view_angles": "Ansichtswinkel",
|
||||
"ui.view_angles_convention": "Grad um die Hochachse. Gieren 0° ist die Vorderansicht, 90° links, −90° rechts, 180° die Rückansicht; Nicken 90° ist die Draufsicht; ein positives Rollen dreht das Modell im Uhrzeigersinn.",
|
||||
"ui.view_angles_help": "Zeigt Nick-, Gier- und Rollwinkel der Ansicht in Grad sowie die Projektion unter dem Orientierungs-Gizmo. Klicken Sie auf die Anzeige, um genaue Winkel einzugeben.",
|
||||
"ui.view_angles_ortho": "Ortho",
|
||||
"ui.view_angles_persp": "Persp",
|
||||
"ui.view_angles_pitch": "Nicken",
|
||||
"ui.view_angles_readout": "Nicken {pitch} · Gieren {yaw} · Rollen {roll}",
|
||||
"ui.view_angles_roll": "Rollen",
|
||||
"ui.view_angles_yaw": "Gieren"
|
||||
},
|
||||
"he": {
|
||||
"cmd.view_angle_readout": "זוויות תצוגה",
|
||||
"ui.view_angles": "זוויות תצוגה",
|
||||
"ui.view_angles_convention": "מעלות סביב הציר העליון. סבסוב 0° הוא התצוגה הקדמית, 90° שמאלית, −90° ימנית, 180° אחורית; עלרוד 90° הוא התצוגה העליונה; גלגול חיובי מסובב את המודל על המסך עם כיוון השעון.",
|
||||
"ui.view_angles_help": "מציג מתחת לגיזמו הכיוון את זוויות העלרוד, הסבסוב והגלגול של התצוגה במעלות ואת סוג ההטלה. לחצו על התצוגה כדי להקליד זוויות מדויקות.",
|
||||
"ui.view_angles_ortho": "אורתוגרפי",
|
||||
"ui.view_angles_persp": "פרספקטיבה",
|
||||
"ui.view_angles_pitch": "עלרוד",
|
||||
"ui.view_angles_readout": "עלרוד {pitch} · סבסוב {yaw} · גלגול {roll}",
|
||||
"ui.view_angles_roll": "גלגול",
|
||||
"ui.view_angles_yaw": "סבסוב"
|
||||
},
|
||||
"ja": {
|
||||
"cmd.view_angle_readout": "ビュー角度",
|
||||
"ui.view_angles": "ビュー角度",
|
||||
"ui.view_angles_convention": "上方向の軸まわりの角度(度)。ヨー 0° が正面ビュー、90° が左、−90° が右、180° が背面です。ピッチ 90° が上面ビューです。ロールが正のとき、モデルは画面上で時計回りに回ります。",
|
||||
"ui.view_angles_help": "方向ギズモの下に、ビューのピッチ、ヨー、ロール(度)と投影法を表示します。表示をクリックすると正確な角度を入力できます。",
|
||||
"ui.view_angles_ortho": "平行投影",
|
||||
"ui.view_angles_persp": "透視投影",
|
||||
"ui.view_angles_pitch": "ピッチ",
|
||||
"ui.view_angles_readout": "ピッチ {pitch} · ヨー {yaw} · ロール {roll}",
|
||||
"ui.view_angles_roll": "ロール",
|
||||
"ui.view_angles_yaw": "ヨー"
|
||||
},
|
||||
"ko": {
|
||||
"cmd.view_angle_readout": "뷰 각도",
|
||||
"ui.view_angles": "뷰 각도",
|
||||
"ui.view_angles_convention": "위쪽 축을 기준으로 한 각도(도)입니다. 요 0°는 정면 뷰, 90°는 왼쪽, −90°는 오른쪽, 180°는 뒷면이고, 피치 90°는 평면 뷰입니다. 롤이 양수이면 모델이 화면에서 시계 방향으로 회전합니다.",
|
||||
"ui.view_angles_help": "방향 기즈모 아래에 뷰의 피치, 요, 롤(도)과 투영 방식을 표시합니다. 표시를 클릭하면 정확한 각도를 입력할 수 있습니다.",
|
||||
"ui.view_angles_ortho": "직교",
|
||||
"ui.view_angles_persp": "원근",
|
||||
"ui.view_angles_pitch": "피치",
|
||||
"ui.view_angles_readout": "피치 {pitch} · 요 {yaw} · 롤 {roll}",
|
||||
"ui.view_angles_roll": "롤",
|
||||
"ui.view_angles_yaw": "요"
|
||||
},
|
||||
"vi": {
|
||||
"cmd.view_angle_readout": "Góc hướng nhìn",
|
||||
"ui.view_angles": "Góc hướng nhìn",
|
||||
"ui.view_angles_convention": "Độ quanh trục hướng lên. Lệch 0° là góc nhìn phía trước, 90° bên trái, −90° bên phải, 180° phía sau; chúc 90° là góc nhìn từ trên; nghiêng dương xoay mô hình trên màn hình theo chiều kim đồng hồ.",
|
||||
"ui.view_angles_help": "Hiển thị góc chúc, góc lệch và góc nghiêng của góc nhìn theo độ cùng kiểu chiếu, bên dưới gizmo định hướng. Bấm vào phần hiển thị để nhập góc chính xác.",
|
||||
"ui.view_angles_ortho": "Trực giao",
|
||||
"ui.view_angles_persp": "Phối cảnh",
|
||||
"ui.view_angles_pitch": "Chúc",
|
||||
"ui.view_angles_readout": "Chúc {pitch} · Lệch {yaw} · Nghiêng {roll}",
|
||||
"ui.view_angles_roll": "Nghiêng",
|
||||
"ui.view_angles_yaw": "Lệch"
|
||||
},
|
||||
"zh": {
|
||||
"cmd.view_angle_readout": "视图角度",
|
||||
"ui.view_angles": "视图角度",
|
||||
"ui.view_angles_convention": "绕向上轴的角度(度)。偏航 0° 为前视图,90° 为左视图,−90° 为右视图,180° 为后视图;俯仰 90° 为俯视图;滚转为正时,模型在屏幕上顺时针旋转。",
|
||||
"ui.view_angles_help": "在方向小部件下方显示视图的俯仰、偏航和滚转角(度)以及投影方式。单击读数可输入精确角度。",
|
||||
"ui.view_angles_ortho": "正交",
|
||||
"ui.view_angles_persp": "透视",
|
||||
"ui.view_angles_pitch": "俯仰",
|
||||
"ui.view_angles_readout": "俯仰 {pitch} · 偏航 {yaw} · 滚转 {roll}",
|
||||
"ui.view_angles_roll": "滚转",
|
||||
"ui.view_angles_yaw": "偏航"
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ pub static COMMANDS: &[CommandSpec] = &[
|
||||
CommandSpec::new("view.delete", "Delete Named View", view_delete).icon("delete").params("view: name"),
|
||||
CommandSpec::new("view.list", "List Named Views", view_list).icon("list").noundo().doc_only(),
|
||||
CommandSpec::new("view.apply", "Restore Named View", view_apply).icon("camera").noundo().params(
|
||||
"view?: front|back|top|bottom|left|right|iso|home (frames the model) | a named view's name; or camera?: {target: [x,y,z], yaw, pitch, distance, fov?, roll?} (radians, mm; roll defaults to 0, must be finite and is clamped to ±π; up is refused: the up axis comes from the design settings) → camera. The viewport (and the MCP screenshot) moves there. View state: not saved, not an undo step",
|
||||
"view?: front|back|top|bottom|left|right|iso|home (frames the model) | a named view's name; or camera?: {target: [x,y,z], yaw, pitch, distance, fov?, roll?} (radians, mm, about the up axis; yaw: heading of the line of sight, 0 along +Y (Front), π/2 along +X (Left), π (Back), −π/2 (Right); pitch: the eye's elevation, within ±π/2, π/2 = Top; roll defaults to 0, turns the picture clockwise, must be finite and is clamped to ±π; the View angles readout shows these in degrees; up is refused: the up axis comes from the design settings) → camera. The viewport (and the MCP screenshot) moves there. View state: not saved, not an undo step",
|
||||
),
|
||||
CommandSpec::new("browser.order", "Order Browser Items", order).icon("reorder").params("folder, component?, order: [keys] (the folder's items in display order)"),
|
||||
CommandSpec::new("browser.visibility", "Show/Hide", visibility).icon("eye").params(
|
||||
@@ -751,6 +751,10 @@ fn view_apply(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
None => 0.0,
|
||||
};
|
||||
let v: solidcraft_doc::NamedView = serde_json::from_value(c.clone()).map_err(|e| bad(cmd, format!("bad camera: {e}")))?;
|
||||
// Past a pole the same view has other angles; the orbit would snap it back (#6032).
|
||||
if !(v.pitch.abs() <= std::f64::consts::FRAC_PI_2 + 1e-9) {
|
||||
return Err(bad(cmd, "camera `pitch` must be within ±π/2 radians (±90°)"));
|
||||
}
|
||||
crate::render::Camera { roll: roll.clamp(-std::f64::consts::PI, std::f64::consts::PI), ..camera_of(&v) }
|
||||
}
|
||||
// Standard view names come first, as in the browser's Named Views folder.
|
||||
@@ -1581,6 +1585,43 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// The View angles popup (#6032) sets the view through `view.apply`: the readout's degrees are
|
||||
/// the camera's radians, named views read round numbers, and hostile angles never leave a
|
||||
/// camera past a pole or a NaN behind.
|
||||
#[test]
|
||||
fn applying_a_camera_by_view_angles_reads_back_and_refuses_hostile_pitch() {
|
||||
use crate::render::ViewAngles;
|
||||
let mut s = Session::default();
|
||||
for (view, (yaw, pitch)) in
|
||||
[("front", (0.0, 0.0)), ("left", (90.0, 0.0)), ("right", (-90.0, 0.0)), ("back", (180.0, 0.0)), ("top", (0.0, 90.0))]
|
||||
{
|
||||
run(&mut s, "view.apply", json!({"view": view}));
|
||||
let a = s.camera.expect("a camera for the standard view").view_angles();
|
||||
assert!((a.yaw - yaw).abs() < 1e-3 && (a.pitch - pitch).abs() < 1e-3 && a.roll == 0.0, "{view}: {a:?}");
|
||||
}
|
||||
let typed = ViewAngles { yaw: -30.0, pitch: 15.0, roll: 5.0 };
|
||||
let cam = crate::render::Camera::default().with_view_angles(typed).expect("finite angles");
|
||||
let p = json!({"camera": {"target": [0, 0, 0], "yaw": cam.yaw, "pitch": cam.pitch, "roll": cam.roll, "distance": 80}});
|
||||
run(&mut s, "view.apply", p);
|
||||
let a = s.camera.expect("the typed camera").view_angles();
|
||||
assert!((a.yaw - typed.yaw).abs() < 1e-9 && (a.pitch - typed.pitch).abs() < 1e-9 && (a.roll - typed.roll).abs() < 1e-9, "{a:?}");
|
||||
// Straight down is allowed (90° in radians may round a hair past π/2).
|
||||
run(&mut s, "view.apply", json!({"camera": {"target": [0, 0, 0], "yaw": 0, "pitch": 90.0_f64.to_radians(), "distance": 80}}));
|
||||
// Many turns of yaw are the same heading; the readout brings it into range.
|
||||
run(&mut s, "view.apply", json!({"camera": {"target": [0, 0, 0], "yaw": 1e300, "pitch": 0, "distance": 80}}));
|
||||
let a = s.camera.expect("a camera").view_angles();
|
||||
assert!(a.yaw.is_finite() && (-180.0..=180.0).contains(&a.yaw), "{a:?}");
|
||||
let before = serde_json::to_value(s.camera).unwrap();
|
||||
for pitch in [json!(2.0), json!(-1.6), json!(1e300), json!(-f64::MAX), json!(f64::NAN), json!("90"), json!(null)] {
|
||||
let err = s.execute("view.apply", &json!({"camera": {"target": [0, 0, 0], "yaw": 0, "pitch": pitch, "distance": 80}})).unwrap_err();
|
||||
assert!(err.to_string().contains("camera"), "{pitch}: {err}");
|
||||
assert_eq!(serde_json::to_value(s.camera).unwrap(), before, "a refused camera leaves the view alone");
|
||||
}
|
||||
for yaw in [json!(f64::NAN), json!(f64::INFINITY), json!("0")] {
|
||||
assert!(s.execute("view.apply", &json!({"camera": {"target": [0, 0, 0], "yaw": yaw, "pitch": 0, "distance": 80}})).is_err(), "{yaw}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn named_views_are_saved_renamed_and_deleted() {
|
||||
let mut s = Session::default();
|
||||
|
||||
@@ -79,6 +79,8 @@ CommandSpec::new("view.ambient_occlusion", "Ambient Occlusion", ambient_occlusio
|
||||
.icon("settings").noundo().doc_only().params("enabled: bool → enabled; apply soft contact shading in the GPU viewport"),
|
||||
CommandSpec::new("view.perspective", "Perspective view", perspective)
|
||||
.icon("perspective").noundo().doc_only().params("enabled: bool → enabled; draw the view in perspective, or orthographic when false; a sketch being edited is always shown orthographic"),
|
||||
CommandSpec::new("view.angle_readout", "View Angles", crate::checked!("view.angle_readout", angle_readout))
|
||||
.icon("camera").noundo().doc_only().contract(&ANGLE_READOUT_CONTRACT).output(crate::schema::output_schema_for::<crate::schema::view_navigation::AngleReadoutResult>).params("enabled: bool → enabled; show the view's pitch, yaw and roll (degrees, as view.apply's camera in radians) and Ortho or Persp under the orientation gizmo; display only, never opens a dialog"),
|
||||
CommandSpec::new("view.navigate", "Navigate View", navigate)
|
||||
.icon("orbit")
|
||||
.noundo()
|
||||
@@ -871,9 +873,33 @@ fn perspective(_s: &mut Session, p: &Value) -> Result<Value> {
|
||||
Ok(json!({"enabled": enabled}))
|
||||
}
|
||||
|
||||
const ANGLE_READOUT_CONTRACT: crate::schema::TypedContract<crate::schema::view_navigation::AngleReadoutParams> = crate::schema::TypedContract::new();
|
||||
|
||||
/// The View angles readout under the orientation gizmo (#6032): a display setting the UI keeps.
|
||||
fn angle_readout(_s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let enabled = p.get("enabled").and_then(Value::as_bool).ok_or_else(|| bad("view.angle_readout", "`enabled` must be a boolean"))?;
|
||||
let reply = crate::schema::view_navigation::AngleReadoutResult { enabled, param_warnings: Vec::new() };
|
||||
serde_json::to_value(reply).map_err(|e| crate::EngineError::Other(e.to_string()))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod ambient_occlusion_tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn angle_readout_validates_display_setting_without_editing_design_or_history() {
|
||||
let mut s = Session::default();
|
||||
let before = s.doc.to_json();
|
||||
for enabled in [true, false] {
|
||||
assert_eq!(s.execute("view.angle_readout", &json!({"enabled": enabled})).unwrap(), json!({"enabled": enabled}));
|
||||
}
|
||||
for p in [json!({}), json!({"enabled": 1}), json!({"enabled": "true"}), json!({"enabled": null}), json!({"enabled": f64::NAN})] {
|
||||
assert!(s.execute("view.angle_readout", &p).is_err(), "{p}");
|
||||
}
|
||||
assert_eq!(s.doc.to_json(), before);
|
||||
assert!(s.undo.is_empty());
|
||||
assert!(s.camera.is_none(), "a display setting leaves the view where it is");
|
||||
}
|
||||
#[test]
|
||||
fn validates_display_setting_without_editing_design_or_history() {
|
||||
let mut s = Session::default();
|
||||
|
||||
@@ -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!({})));
|
||||
}
|
||||
@@ -553,6 +553,64 @@ impl Camera {
|
||||
&& self.distance.is_finite()
|
||||
&& self.distance > 0.0
|
||||
}
|
||||
/// The view's orientation in degrees, as the viewport's View angles readout shows it (#6032).
|
||||
/// These are the camera's own angles: yaw in (−180, 180], pitch in [−90, 90], roll in
|
||||
/// (−180, 180]. A camera whose pitch passed a pole is read from its basis, as the same view
|
||||
/// with the angles in range; there, straight up or down, yaw and roll turn the image the same
|
||||
/// way, so roll reads 0 and yaw carries the turn. An invalid camera reads all zeros.
|
||||
pub fn view_angles(&self) -> ViewAngles {
|
||||
use std::f64::consts::FRAC_PI_2;
|
||||
let angles = if !self.is_valid() {
|
||||
(0.0, 0.0, 0.0)
|
||||
} else if self.pitch.abs() <= FRAC_PI_2 {
|
||||
(wrap_half_turn(self.yaw), self.pitch, wrap_half_turn(self.roll))
|
||||
} else {
|
||||
let (right, _, back) = self.basis();
|
||||
let (right, back) = (self.up.to_frame(right), self.up.to_frame(back));
|
||||
let pitch = back.z.clamp(-1.0, 1.0).asin();
|
||||
if back.x.hypot(back.y) < 1e-9 {
|
||||
// Straight up or down: the camera's right vector lies in the ground plane.
|
||||
((-right.y).atan2(right.x), pitch, 0.0)
|
||||
} else {
|
||||
let yaw = (-back.x).atan2(-back.y);
|
||||
let base_right = Vec3::new(yaw.cos(), -yaw.sin(), 0.0);
|
||||
let base_up = back.cross(base_right).normalized().unwrap_or(Vec3::Z);
|
||||
(yaw, pitch, right.dot(base_up).atan2(right.dot(base_right)))
|
||||
}
|
||||
};
|
||||
let degrees = |a: f64| if a.is_finite() { a.to_degrees() + 0.0 } else { 0.0 };
|
||||
ViewAngles { yaw: degrees(wrap_half_turn(angles.0)), pitch: degrees(angles.1).clamp(-90.0, 90.0), roll: degrees(wrap_half_turn(angles.2)) }
|
||||
}
|
||||
/// The same camera turned to `angles` (degrees, as [`Camera::view_angles`] reads them):
|
||||
/// target, distance, projection and up axis are kept. Yaw and roll may be any number of
|
||||
/// turns; pitch is held to ±90°. `None` when an angle is not finite.
|
||||
pub fn with_view_angles(&self, angles: ViewAngles) -> Option<Camera> {
|
||||
let ViewAngles { yaw, pitch, roll } = angles;
|
||||
if !(yaw.is_finite() && pitch.is_finite() && roll.is_finite()) {
|
||||
return None;
|
||||
}
|
||||
let radians = |a: f64| wrap_half_turn(a.to_radians());
|
||||
Some(Camera { yaw: radians(yaw), pitch: pitch.clamp(-90.0, 90.0).to_radians(), roll: radians(roll), ..*self })
|
||||
}
|
||||
}
|
||||
|
||||
/// A view's orientation in degrees about the up axis (#6032). Yaw is the heading of the line of
|
||||
/// sight: 0 looks along +Y (Front), 90 along +X (Left), 180 along −Y (Back), −90 along −X
|
||||
/// (Right). Pitch is the eye's elevation above the ground plane: 90 looks straight down (Top),
|
||||
/// −90 straight up (Bottom). Roll turns the image about the line of sight; positive turns the
|
||||
/// model clockwise on screen. With Y up the same angles turn about Y, the front view looking
|
||||
/// along −Z.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ViewAngles {
|
||||
pub yaw: f64,
|
||||
pub pitch: f64,
|
||||
pub roll: f64,
|
||||
}
|
||||
|
||||
/// An angle in radians brought into (−π, π]; any finite angle, however many turns.
|
||||
fn wrap_half_turn(a: f64) -> f64 {
|
||||
use std::f64::consts::{PI, TAU};
|
||||
if a.is_finite() { PI - (PI - a).rem_euclid(TAU) } else { 0.0 }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -900,4 +958,102 @@ mod tests {
|
||||
let v = Vec3::new(1.0, 2.0, 3.0);
|
||||
assert!(UpAxis::Y.from_frame(UpAxis::Y.to_frame(v)).dist(v) < 1e-12);
|
||||
}
|
||||
|
||||
fn same_view(a: &Camera, b: &Camera) -> bool {
|
||||
let ((ar, au, ab), (br, bu, bb)) = (a.basis(), b.basis());
|
||||
ar.dist(br) < 1e-9 && au.dist(bu) < 1e-9 && ab.dist(bb) < 1e-9
|
||||
}
|
||||
|
||||
/// The View angles readout (#6032): the named views read round numbers, with Front 0/0/0,
|
||||
/// in both up frames.
|
||||
#[test]
|
||||
fn named_views_read_round_view_angles() {
|
||||
let iso_pitch = (1.0_f64 / 3.0_f64.sqrt()).asin().to_degrees();
|
||||
for up in [UpAxis::Z, UpAxis::Y] {
|
||||
for (view, expected) in [
|
||||
(StandardView::Front, (0.0, 0.0, 0.0)),
|
||||
(StandardView::Back, (180.0, 0.0, 0.0)),
|
||||
(StandardView::Left, (90.0, 0.0, 0.0)),
|
||||
(StandardView::Right, (-90.0, 0.0, 0.0)),
|
||||
(StandardView::Top, (0.0, 90.0, 0.0)),
|
||||
(StandardView::Bottom, (0.0, -90.0, 0.0)),
|
||||
(StandardView::Iso, (-45.0, iso_pitch, 0.0)),
|
||||
] {
|
||||
let mut cam = Camera { up, roll: 0.7, ..Default::default() };
|
||||
cam.set_view(view);
|
||||
let a = cam.view_angles();
|
||||
assert!(
|
||||
(a.yaw - expected.0).abs() < 1e-3 && (a.pitch - expected.1).abs() < 1e-3 && (a.roll - expected.2).abs() < 1e-9,
|
||||
"{up:?} {view:?}: {a:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
// Yaw is the heading of the line of sight; positive roll turns the model clockwise.
|
||||
let cam = Camera::default().with_view_angles(ViewAngles { yaw: 90.0, pitch: 0.0, roll: 0.0 }).unwrap();
|
||||
assert!(cam.back().dist(-Vec3::X) < 1e-12, "yaw 90 looks along +X: {:?}", cam.back());
|
||||
let cam = Camera::default().with_view_angles(ViewAngles { yaw: 0.0, pitch: 0.0, roll: 30.0 }).unwrap();
|
||||
let (x, y, _) = cam.to_screen(cam.target + Vec3::X * 10.0, 800.0, 600.0, 50.0).unwrap();
|
||||
assert!(x > 400.0 && y > 300.0, "+X turned clockwise, below the centre: {x}, {y}");
|
||||
}
|
||||
|
||||
/// Angles read from a camera turn a camera to the same view, and set angles read back, for
|
||||
/// any orientation, including straight up and down and cameras whose stored pitch passed a pole.
|
||||
#[test]
|
||||
fn view_angles_round_trip_without_nan_at_the_poles() {
|
||||
use std::f64::consts::{FRAC_PI_2, TAU};
|
||||
for up in [UpAxis::Z, UpAxis::Y] {
|
||||
let base = Camera { up, target: Vec3::new(1.0, -2.0, 3.0), distance: 80.0, fov: 0.6, ..Default::default() };
|
||||
for yaw in [-180.0, -135.0, -90.0, -12.5, 0.0, 45.0, 90.0, 179.0, 180.0] {
|
||||
for pitch in [-90.0, -89.9, -35.0, 0.0, 15.0, 89.9, 90.0] {
|
||||
for roll in [-170.0, -90.0, 0.0, 30.0, 180.0] {
|
||||
let set = ViewAngles { yaw, pitch, roll };
|
||||
let cam = base.with_view_angles(set).unwrap();
|
||||
assert_eq!((cam.target, cam.distance, cam.fov, cam.up), (base.target, base.distance, base.fov, base.up));
|
||||
let read = cam.view_angles();
|
||||
let turn = |a: f64, b: f64| ((a - b + 540.0).rem_euclid(360.0) - 180.0).abs();
|
||||
assert!(
|
||||
turn(read.yaw, yaw) < 1e-9 && (read.pitch - pitch).abs() < 1e-9 && turn(read.roll, roll) < 1e-9,
|
||||
"{set:?} -> {read:?}"
|
||||
);
|
||||
assert!(same_view(&cam, &cam.with_view_angles(read).unwrap()));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Stored angles out of range (a pitch over a pole, many turns) read in range as the same view.
|
||||
for (yaw, pitch, roll) in [
|
||||
(0.3, 2.0, 0.2),
|
||||
(-1.0, -3.0, 1.0),
|
||||
(7.0 * TAU + 0.5, 0.4, -9.0 * TAU),
|
||||
(0.8, FRAC_PI_2 + TAU, 0.3),
|
||||
(-0.6, -FRAC_PI_2 - TAU, 1.1),
|
||||
(1e6, 1e6, -1e6),
|
||||
] {
|
||||
let cam = Camera { yaw, pitch, roll, ..base };
|
||||
let a = cam.view_angles();
|
||||
assert!(a.yaw.is_finite() && a.pitch.is_finite() && a.roll.is_finite(), "{cam:?}: {a:?}");
|
||||
assert!((-180.0..=180.0).contains(&a.yaw) && (-90.0..=90.0).contains(&a.pitch) && (-180.0..=180.0).contains(&a.roll));
|
||||
assert!(same_view(&cam, &cam.with_view_angles(a).unwrap()), "{cam:?}: {a:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hostile_view_angles_are_refused_or_held_in_range() {
|
||||
let cam = Camera::default();
|
||||
for bad in [f64::NAN, f64::INFINITY, f64::NEG_INFINITY] {
|
||||
for a in [
|
||||
ViewAngles { yaw: bad, ..Default::default() },
|
||||
ViewAngles { pitch: bad, ..Default::default() },
|
||||
ViewAngles { roll: bad, ..Default::default() },
|
||||
] {
|
||||
assert_eq!(cam.with_view_angles(a), None);
|
||||
}
|
||||
assert_eq!(Camera { yaw: bad, ..cam }.view_angles(), ViewAngles::default());
|
||||
assert_eq!(Camera { pitch: bad, ..cam }.view_angles(), ViewAngles::default());
|
||||
}
|
||||
let huge = cam.with_view_angles(ViewAngles { yaw: f64::MAX, pitch: f64::MAX, roll: -f64::MAX }).unwrap();
|
||||
assert!(huge.is_valid() && (huge.pitch - std::f64::consts::FRAC_PI_2).abs() < 1e-12, "{huge:?}");
|
||||
let a = huge.view_angles();
|
||||
assert!(a.yaw.is_finite() && a.roll.is_finite() && a.pitch == 90.0, "{a:?}");
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ pub use backend::{
|
||||
RenderMode, RenderOperation, RenderPolicy, RenderProfile, RenderRequest, ResolveError, ResolvedRequest, ScratchLayout, builtin_backend,
|
||||
resolve_request,
|
||||
};
|
||||
pub use camera::{Camera, CameraAnim, Mat4, Quat, StandardView, UpAxis, ease_in_out};
|
||||
pub use camera::{Camera, CameraAnim, Mat4, Quat, StandardView, UpAxis, ViewAngles, ease_in_out};
|
||||
pub use curve_display::{PixelCurveView, SampledPath, SamplingBudget, SamplingQuality, sample_segment, sample_segment_unclipped};
|
||||
pub use gif::gif;
|
||||
pub use product::{FaceAppearance, ProductMesh, ProductScene};
|
||||
|
||||
@@ -238,6 +238,7 @@ fn execute(app: &mut SolveApp, id: &str, params: Value) -> Result<Value, String>
|
||||
| "view.navigate"
|
||||
| "view.ambient_occlusion"
|
||||
| "view.perspective"
|
||||
| "view.angle_readout"
|
||||
| "view.graphics_preset"
|
||||
| "view.history_layout"
|
||||
| "browser.expand_all"
|
||||
|
||||
@@ -284,6 +284,7 @@ pub mod ui_kit;
|
||||
mod ui_kit_guard_tests;
|
||||
pub mod update;
|
||||
mod value_step;
|
||||
pub(crate) mod view_angles;
|
||||
mod view_confirm;
|
||||
pub mod view_pick;
|
||||
pub mod viewport;
|
||||
@@ -1139,6 +1140,9 @@ impl SolveApp {
|
||||
{
|
||||
self.ui.perspective = perspective;
|
||||
}
|
||||
if id == "view.angle_readout" {
|
||||
self.preferences.show_view_angles = v.get("enabled").and_then(Value::as_bool).unwrap_or(false);
|
||||
}
|
||||
if matches!(id, "view.ambient_occlusion" | "view.graphics_preset") {
|
||||
self.preferences.ambient_occlusion = v.get("enabled").and_then(Value::as_bool).unwrap_or(false);
|
||||
if id == "view.graphics_preset" {
|
||||
@@ -1375,6 +1379,10 @@ impl SolveApp {
|
||||
let _ = self.run(id, json!({"enabled": !self.ui.perspective}));
|
||||
return;
|
||||
}
|
||||
if id == "view.angle_readout" {
|
||||
let _ = self.run(id, json!({"enabled": !self.preferences.show_view_angles}));
|
||||
return;
|
||||
}
|
||||
// Another command ends Edit Text (its dialog is not a feature edit to keep).
|
||||
sketch_text_move::cancel_drag(self);
|
||||
if sketch_text::editing(self) || self.dialog.as_ref().is_some_and(|d| matches!(d.kind, dialogs::Kind::TextMove(_))) {
|
||||
|
||||
@@ -470,11 +470,16 @@ pub(crate) fn handle(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect, resp: &e
|
||||
let secondary_down = secondary_down && app.viewport.context_menu.is_none();
|
||||
// The axis view handles its own clicks; the model underneath must not see them.
|
||||
let axes = if caps.orbit { axis_rect(app, rect) } else { Rect::NOTHING };
|
||||
// So is the View angles readout under it (#6032).
|
||||
let readout = crate::view_angles::readout_rect(ui.ctx(), rect).filter(|_| caps.orbit && app.preferences.show_view_angles);
|
||||
// Floating windows and menus own input over the model, including wheel navigation. egui's
|
||||
// hit test also counts the model as under the pointer a few points past its own edge and
|
||||
// inside a window's or a list's edge (#678), so the pointer must be in the viewport too,
|
||||
// with no window or menu above it.
|
||||
let inside = ui.is_enabled() && resp.contains_pointer() && ui.rect_contains_pointer(rect) && hover.is_some_and(|p| !axes.contains(p));
|
||||
let inside = ui.is_enabled()
|
||||
&& resp.contains_pointer()
|
||||
&& ui.rect_contains_pointer(rect)
|
||||
&& hover.is_some_and(|p| !axes.contains(p) && !readout.is_some_and(|r| r.contains(p)));
|
||||
app.viewport.mouse = hover.filter(|_| inside);
|
||||
// Sketch snap suppression is set once in `viewport::show` from preferences.
|
||||
middle_double_click(app, ui, inside);
|
||||
|
||||
@@ -538,6 +538,14 @@ fn display_menu(app: &mut SolveApp, ui: &mut egui::Ui) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// The View angles readout under the orientation gizmo (#6032).
|
||||
let mut angles = NavigationMenuRow::new("view_angles", app.tr("ui.view_angles"), "select");
|
||||
angles.selected = app.preferences.show_view_angles;
|
||||
let response = angles.show(ui).on_hover_text(app.tr("ui.view_angles_help"));
|
||||
crate::scenario::publish_target("view:view_angles", response.rect);
|
||||
if response.clicked() {
|
||||
let _ = app.run("view.angle_readout", json!({"enabled": !app.preferences.show_view_angles}));
|
||||
}
|
||||
separator(ui);
|
||||
heading(ui, app.tr("navbar.assistant"));
|
||||
let mut cursor = NavigationMenuRow::new("agent_cursor", app.tr("navbar.agent_cursor"), "select");
|
||||
|
||||
@@ -812,6 +812,9 @@ preference_settings! {
|
||||
frame_rate_details: bool = false, PAGE_GRAPHICS;
|
||||
/// Draw a wider rim under finished sketch curves to improve contrast on shaded faces.
|
||||
sketch_halo: bool = false, PAGE_GRAPHICS => check("Halo under sketch curves");
|
||||
/// Show the view's pitch, yaw and roll and its projection under the orientation gizmo (#6032).
|
||||
/// Off by default; View ▸ View angles and `view.angle_readout` turn it on.
|
||||
show_view_angles: bool = false, PAGE_GRAPHICS;
|
||||
/// Show world X/Y/Z component dimensions beside the total distance in Measure.
|
||||
measure_axis_distances: bool = true, PAGE_GRAPHICS => check_id("settings.measure_axis_distances");
|
||||
/// Decimals shown for lengths and angles.
|
||||
@@ -5809,6 +5812,16 @@ mod ui_scale_regression_tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// View ▸ View angles and Preferences ▸ Graphics run the same command (#6032).
|
||||
pub(crate) fn view_angles_checkbox(app: &mut SolveApp, ui: &mut egui::Ui) {
|
||||
let mut enabled = app.preferences.show_view_angles;
|
||||
let response = ui_kit::checkbox(ui, crate::i18n::tr("ui.view_angles"), &mut enabled).on_hover_text(crate::i18n::tr("ui.view_angles_help"));
|
||||
crate::scenario::publish_handle("view:view_angles", response.rect.center());
|
||||
if response.changed() {
|
||||
let _ = app.run("view.angle_readout", json!({"enabled": enabled}));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod ambient_occlusion_tests {
|
||||
use super::*;
|
||||
|
||||
@@ -163,6 +163,7 @@ pub(super) fn show(app: &mut SolveApp, ui: &mut egui::Ui) {
|
||||
ui_kit::checkbox(ui, app.tr("ui.frame_rate_details"), &mut app.preferences.frame_rate_details)
|
||||
.on_hover_text(app.tr("settings.frame_rate_details_note"));
|
||||
});
|
||||
crate::prefs::view_angles_checkbox(app, left);
|
||||
setting::reference_geometry_through_bodies(app, left).on_hover_text(app.tr("settings.reference_geometry_through_bodies_help"));
|
||||
setting::sketch_halo(app, left);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
//! The View angles readout under the orientation gizmo (#6032): the view's pitch, yaw and roll in
|
||||
//! degrees and its projection, shown while View ▸ View angles is on (`view.angle_readout`). A
|
||||
//! click on it opens a small card to type exact angles; its Apply runs `view.apply`.
|
||||
//!
|
||||
//! The angles are the camera's own (`Camera::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 on screen.
|
||||
|
||||
use egui::{Align2, FontId, Rect, Sense, pos2, vec2};
|
||||
use serde_json::json;
|
||||
use solidcraft_engine::render::ViewAngles;
|
||||
|
||||
use crate::SolveApp;
|
||||
use crate::fonts::RichTextExt as _;
|
||||
use crate::theme::Tokens;
|
||||
use crate::ui_kit::{self, Container, Surface};
|
||||
|
||||
/// The angles typed in the card while it is open; no entry while it is closed.
|
||||
pub(crate) fn draft_id() -> egui::Id {
|
||||
egui::Id::new("sc_view_angles_draft")
|
||||
}
|
||||
|
||||
/// Where the readout was drawn last frame over the viewport `viewport`, so a click on it never
|
||||
/// reaches the model below.
|
||||
pub(crate) fn readout_rect(ctx: &egui::Context, viewport: Rect) -> Option<Rect> {
|
||||
ctx.data(|d| d.get_temp::<(Rect, Rect)>(egui::Id::new("sc_view_angles_readout"))).filter(|(v, _)| *v == viewport).map(|(_, r)| r)
|
||||
}
|
||||
|
||||
fn set_readout_rect(ui: &egui::Ui, viewport: Rect, rect: Option<Rect>) {
|
||||
let id = egui::Id::new("sc_view_angles_readout");
|
||||
ui.data_mut(|d| match rect {
|
||||
Some(r) => {
|
||||
d.insert_temp(id, (viewport, r));
|
||||
}
|
||||
None => {
|
||||
d.remove::<(Rect, Rect)>(id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// An angle as the readout prints it: Preferences' angle decimals, and never "-0".
|
||||
pub(crate) fn degrees(value: f64, decimals: u8) -> String {
|
||||
let decimals = usize::from(decimals.min(6));
|
||||
let k = 10f64.powi(i32::try_from(decimals).unwrap_or(6));
|
||||
let rounded = if value.is_finite() { (value * k).round() / k + 0.0 } else { 0.0 };
|
||||
format!("{rounded:.decimals$}°")
|
||||
}
|
||||
|
||||
/// The readout's two lines: the angles, then the projection the view is drawn with.
|
||||
pub(crate) fn lines(app: &SolveApp) -> (String, String) {
|
||||
let a = app.cam.view_angles();
|
||||
let d = app.preferences.angle_decimals;
|
||||
let angles =
|
||||
crate::i18n::format("ui.view_angles_readout", &[("pitch", °rees(a.pitch, d)), ("yaw", °rees(a.yaw, d)), ("roll", °rees(a.roll, d))]);
|
||||
let projection = if app.perspective_view() { "ui.view_angles_persp" } else { "ui.view_angles_ortho" };
|
||||
(angles, crate::i18n::tr(projection).to_string())
|
||||
}
|
||||
|
||||
/// Turn the view to typed angles through `view.apply`, keeping its target, distance and projection.
|
||||
pub(crate) fn apply(app: &mut SolveApp, angles: ViewAngles) {
|
||||
let Some(cam) = app.cam.with_view_angles(angles) else { return };
|
||||
let camera = json!({"target": cam.target, "yaw": cam.yaw, "pitch": cam.pitch, "roll": cam.roll, "distance": cam.distance, "fov": cam.fov});
|
||||
if app.run("view.apply", json!({ "camera": camera })).is_ok() {
|
||||
app.follow_view_request(true);
|
||||
}
|
||||
}
|
||||
|
||||
/// Paint the readout under the gizmo of the viewport `rect`, and the card when it is open.
|
||||
pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let axis = crate::viewport::axis_rect(app, rect);
|
||||
if !app.preferences.show_view_angles || !axis.is_positive() || !axis.is_finite() {
|
||||
ui.data_mut(|d| d.remove::<ViewAngles>(draft_id()));
|
||||
set_readout_rect(ui, rect, None);
|
||||
return;
|
||||
}
|
||||
let t = Tokens::get();
|
||||
let (angles, projection) = lines(app);
|
||||
let painter = ui.painter_at(rect);
|
||||
let font = FontId::proportional(t.font_caption);
|
||||
let first = painter.layout_no_wrap(angles.clone(), font.clone(), t.text);
|
||||
let second = painter.layout_no_wrap(projection.clone(), font, t.text_dim);
|
||||
let gap = 2.0;
|
||||
let size = vec2(first.size().x.max(second.size().x), first.size().y + gap + second.size().y) + vec2(12.0, 6.0);
|
||||
let chip = Rect::from_min_size(pos2(axis.right() - 4.0 - size.x, axis.bottom() + 2.0), size);
|
||||
if !rect.contains_rect(chip) {
|
||||
ui.data_mut(|d| d.remove::<ViewAngles>(draft_id()));
|
||||
set_readout_rect(ui, rect, None);
|
||||
return;
|
||||
}
|
||||
set_readout_rect(ui, rect, Some(chip));
|
||||
let mut draft = ui.data(|d| d.get_temp::<ViewAngles>(draft_id()));
|
||||
painter.rect(chip, t.radius_sm, t.overlay, t.control_border_stroke(if draft.is_some() { t.accent } else { t.border }), egui::StrokeKind::Inside);
|
||||
let right = chip.right() - 6.0;
|
||||
painter.galley(pos2(right - first.size().x, chip.top() + 3.0), first, t.text);
|
||||
painter.galley(pos2(right - second.size().x, chip.bottom() - 3.0 - second.size().y), second, t.text_dim);
|
||||
crate::scenario::publish_target("view_angles:readout", chip);
|
||||
let label = format!("{angles} · {projection}");
|
||||
let response = ui.interact(chip, ui.id().with("view_angles_readout"), Sense::click());
|
||||
response.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, &label));
|
||||
if response.hovered() {
|
||||
ui.ctx().set_cursor_icon(egui::CursorIcon::PointingHand);
|
||||
}
|
||||
let response = response.on_hover_text(crate::i18n::tr("ui.view_angles_help"));
|
||||
if response.clicked() {
|
||||
draft = if draft.is_some() { None } else { Some(app.cam.view_angles()) };
|
||||
}
|
||||
let Some(mut typed) = draft else {
|
||||
ui.data_mut(|d| d.remove::<ViewAngles>(draft_id()));
|
||||
return;
|
||||
};
|
||||
let area = Container::new(ui.ctx(), Surface::Popup)
|
||||
.area(egui::Id::new("sc_view_angles_card"))
|
||||
.order(egui::Order::Foreground)
|
||||
.pivot(Align2::RIGHT_TOP)
|
||||
.fixed_pos(chip.right_bottom() + vec2(0.0, 4.0));
|
||||
let mut applied = false;
|
||||
let card = area.show(ui.ctx(), |ui| {
|
||||
Container::popup_frame(ui.style()).show(ui, |ui| {
|
||||
ui.set_width(200.0);
|
||||
ui.label(egui::RichText::new(crate::i18n::tr("ui.view_angles")).semibold().color(t.text).size(t.font_caption));
|
||||
for (id, value) in
|
||||
[("ui.view_angles_pitch", &mut typed.pitch), ("ui.view_angles_yaw", &mut typed.yaw), ("ui.view_angles_roll", &mut typed.roll)]
|
||||
{
|
||||
ui_kit::row(ui, crate::i18n::tr(id), |ui| ui_kit::angle_field(ui, value));
|
||||
}
|
||||
ui_kit::text(ui, crate::i18n::tr("ui.view_angles_convention"), ui_kit::Text::Hint("view_angles"));
|
||||
applied = ui_kit::primary_button(ui, "Apply").clicked();
|
||||
});
|
||||
});
|
||||
crate::scenario::publish_rect("view_angles:card", card.response.rect);
|
||||
if applied {
|
||||
apply(app, typed);
|
||||
}
|
||||
let clicked_out = ui.input(|i| i.pointer.any_pressed())
|
||||
&& ui.input(|i| i.pointer.interact_pos()).is_some_and(|p| !card.response.rect.contains(p) && !chip.contains(p));
|
||||
let escape = ui.input(|i| i.key_pressed(egui::Key::Escape));
|
||||
ui.data_mut(|d| {
|
||||
if clicked_out || escape {
|
||||
d.remove::<ViewAngles>(draft_id());
|
||||
} else {
|
||||
d.insert_temp(draft_id(), typed);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -4493,6 +4493,7 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui) {
|
||||
crate::sketch_dims::show(app, ui, &proj);
|
||||
crate::select_other::show(app, ui.ctx());
|
||||
axis_view(app, ui, rect);
|
||||
crate::view_angles::show(app, ui, rect);
|
||||
crate::navigation_bar_view::show(app, ui, rect);
|
||||
// The notices and the agent chip first, so the 3D mouse picture can keep clear of them.
|
||||
let toasts = transient_messages(app, ui, rect);
|
||||
|
||||
@@ -607,3 +607,70 @@ fn frame_rate_readout_stays_beside_a_right_pane() {
|
||||
in_corner(&h);
|
||||
}
|
||||
}
|
||||
|
||||
/// The View angles readout (#6032) sits under the orientation gizmo only while View ▸ View angles
|
||||
/// is on, follows the view live with its projection, and its card turns the view to typed angles
|
||||
/// through `view.apply`, without touching the design or its history.
|
||||
#[test]
|
||||
fn view_angles_readout_shows_only_when_on_and_applies_typed_angles() {
|
||||
use solidcraft_engine::render::ViewAngles;
|
||||
for style in ["axes", "cube"] {
|
||||
let mut h = Harness::new();
|
||||
h.call("ui.prefs", json!({"navigator_style": style}));
|
||||
h.app.preferences.look_at_anim = false;
|
||||
h.settle();
|
||||
let design = h.app.session.doc.to_json();
|
||||
assert!(!h.app.preferences.show_view_angles, "off by default");
|
||||
assert!(crate::scenario::rect_of("view_angles:readout").is_none());
|
||||
// View ▸ View angles runs view.angle_readout.
|
||||
let view = crate::scenario::handle_at("nav:view").unwrap();
|
||||
h.call("ui.click", json!({"x": view.x, "y": view.y}));
|
||||
let check = crate::scenario::handle_at("view:view_angles").unwrap();
|
||||
h.call("ui.click", json!({"x": check.x, "y": check.y}));
|
||||
assert!(h.app.preferences.show_view_angles);
|
||||
h.call("ui.click", json!({"x": view.x, "y": view.y}));
|
||||
h.call("ui.view", json!({"view": "front"}));
|
||||
h.settle();
|
||||
let readout = crate::scenario::rect_of("view_angles:readout").expect("the readout shows once it is on");
|
||||
let axis = crate::scenario::rect_of("axis_view:outer").unwrap();
|
||||
assert!(
|
||||
readout.top() >= axis.bottom() && readout.right() <= axis.right() && readout.right() > axis.center().x,
|
||||
"{style}: {readout:?} under {axis:?}"
|
||||
);
|
||||
let lines = |h: &Harness| crate::view_angles::lines(&h.app);
|
||||
assert_eq!(lines(&h), ("Pitch 0.0° · Yaw 0.0° · Roll 0.0°".to_string(), "Ortho".to_string()));
|
||||
h.call("ui.view", json!({"view": "right"}));
|
||||
h.app.ui.perspective = true;
|
||||
h.settle();
|
||||
assert_eq!(lines(&h), ("Pitch 0.0° · Yaw -90.0° · Roll 0.0°".to_string(), "Persp".to_string()));
|
||||
h.call("ui.view", json!({"view": "top"}));
|
||||
h.settle();
|
||||
assert_eq!(lines(&h).0, "Pitch 90.0° · Yaw 0.0° · Roll 0.0°");
|
||||
// A click on the readout opens the card with the current angles; Apply turns the view.
|
||||
let camera = h.app.cam;
|
||||
h.call("ui.click", json!({"x": readout.center().x, "y": readout.center().y}));
|
||||
assert_eq!(h.app.cam, camera, "the click opens the card, it does not move the view");
|
||||
assert!(crate::scenario::rect_of("view_angles:card").is_some());
|
||||
let draft = h.ctx.data(|d| d.get_temp::<ViewAngles>(crate::view_angles::draft_id())).expect("the card holds the typed angles");
|
||||
assert!((draft.pitch - 90.0).abs() < 1e-3 && draft.yaw == 0.0 && draft.roll == 0.0, "{draft:?}");
|
||||
h.ctx.data_mut(|d| d.insert_temp(crate::view_angles::draft_id(), ViewAngles { yaw: 30.0, pitch: 15.0, roll: -10.0 }));
|
||||
h.frame();
|
||||
let apply = crate::scenario::handle_at("dialog:button:Apply").unwrap();
|
||||
h.call("ui.click", json!({"x": apply.x, "y": apply.y}));
|
||||
h.settle();
|
||||
let a = h.app.cam.view_angles();
|
||||
assert!((a.yaw - 30.0).abs() < 1e-9 && (a.pitch - 15.0).abs() < 1e-9 && (a.roll + 10.0).abs() < 1e-9, "{a:?}");
|
||||
assert_eq!((h.app.cam.target, h.app.cam.distance), (camera.target, camera.distance), "only the orientation changes");
|
||||
assert_eq!(lines(&h).0, "Pitch 15.0° · Yaw 30.0° · Roll -10.0°");
|
||||
// A click elsewhere closes the card; the command turns the readout off again.
|
||||
let centre = h.app.viewport.rect.unwrap().center();
|
||||
h.call("ui.click", json!({"x": centre.x, "y": centre.y}));
|
||||
assert!(crate::scenario::rect_of("view_angles:card").is_none());
|
||||
h.call("engine.execute", json!({"command": "view.angle_readout", "params": {"enabled": false}}));
|
||||
h.settle();
|
||||
assert!(!h.app.preferences.show_view_angles);
|
||||
assert!(crate::scenario::rect_of("view_angles:readout").is_none());
|
||||
assert_eq!(h.app.session.doc.to_json(), design);
|
||||
assert!(h.app.session.undo.is_empty());
|
||||
}
|
||||
}
|
||||
@@ -80,6 +80,13 @@
|
||||
top right while a dialog or a sketch is open, and moves the axis view or cube down below them.
|
||||
With a dialog open they do what its OK and Cancel do (the check is grey whenever OK is); in a
|
||||
sketch without a dialog they are Finish Sketch and Cancel Sketch.
|
||||
**View angles** in the navigation bar's View menu (or Preferences › Graphics, or the
|
||||
`view.angle_readout` command) shows the view's pitch, yaw and roll in degrees under the axis
|
||||
view, with **Ortho** or **Persp** for the projection; it is off by default and updates as the
|
||||
view turns. The angles turn about the up axis: yaw 0° is the Front view, 90° Left, −90° Right
|
||||
and 180° Back; pitch 90° is the Top view and −90° the Bottom; a positive roll turns the model
|
||||
clockwise on screen. Click the readout to type exact angles; **Apply** turns the view there
|
||||
(it keeps the view's centre and zoom). Scripts set the same angles in radians with `view.apply`.
|
||||
Right-click for the marking menu: eight commands around the cursor, plus a
|
||||
menu for whatever is under it. Near the window's bottom or right edge a menu opens above or
|
||||
to the left of the cursor, so it stays in view.
|
||||
|
||||
@@ -366,6 +366,22 @@ The ordered list of a design's features, which SolidCraft computes from first to
|
||||
- **Elsewhere:** timeline, history, feature tree.
|
||||
- **For translators:** not the undo history.
|
||||
|
||||
### view angles
|
||||
|
||||
The yaw, pitch and roll, in degrees, that give the direction a view looks along and how its
|
||||
picture is turned.
|
||||
|
||||
Yaw is the heading of the line of sight about the up axis (Front view 0°, Left 90°, Right −90°,
|
||||
Back 180°); pitch is how far the eye is above the ground plane (Top view 90°, Bottom −90°); a
|
||||
positive roll turns the picture clockwise. They are the camera's own angles, which `view.apply`
|
||||
and the MCP camera take in radians.
|
||||
|
||||
- **In SolidCraft:** `view.angle_readout` and the View angles readout under the orientation
|
||||
gizmo; the `yaw`, `pitch` and `roll` of `view.apply`'s `camera`.
|
||||
- **Don't use:** camera angles, view rotation.
|
||||
- **Elsewhere:** view orientation, azimuth and elevation.
|
||||
- **For translators:** the view's pitch is a tilt, not a thread's or a pattern's pitch.
|
||||
|
||||
### web browser
|
||||
|
||||
A program that shows web pages, such as the one that runs SolidCraft's web build.
|
||||
|
||||
+1
-1
@@ -364,7 +364,7 @@ the batch added to the undo history.)
|
||||
|
||||
## Camera and close-up recipe
|
||||
|
||||
The `camera` of `screenshot` (the object `view.apply`, `view.save` and `solidcraft-cli snapshot --camera` take too) is an orbit camera, `{target, yaw, pitch, distance, fov?}`, in millimetres and **radians**. Unlike the `angle` of `solid.move`, a bare number is not degrees here. The eye is at `target + distance * (-sin(yaw) * cos(pitch), -cos(yaw) * cos(pitch), sin(pitch))`, looking at `target` with Z up on the screen. So `yaw: 0, pitch: 0` is the front view: the eye at -Y, looking along +Y, with +X to the right. A yaw of π/2 looks from -X, π from +Y and -π/2 from +X. The pitch is the elevation angle up from the XY plane, and π/2 looks straight down with +X to the right and +Y up. `fov` is the vertical field of view in radians. `0`, or no `fov`, is an orthographic view whose visible half-height is 0.4 × `distance`; with a perspective `fov` the half-height at the target is `distance * tan(fov / 2)`. `inspect.section` removes what lies on the side its normal points to: it keeps the points `p` with `n · p < d`, where `d = n · origin` (`flip: true` keeps the other side). To look into the cut, put the eye on the removed side.
|
||||
The `camera` of `screenshot` (the object `view.apply`, `view.save` and `solidcraft-cli snapshot --camera` take too) is an orbit camera, `{target, yaw, pitch, distance, fov?}`, in millimetres and **radians**. Unlike the `angle` of `solid.move`, a bare number is not degrees here. The eye is at `target + distance * (-sin(yaw) * cos(pitch), -cos(yaw) * cos(pitch), sin(pitch))`, looking at `target` with Z up on the screen. So `yaw: 0, pitch: 0` is the front view: the eye at -Y, looking along +Y, with +X to the right. A yaw of π/2 looks from -X, π from +Y and -π/2 from +X. The pitch is the elevation angle up from the XY plane, and π/2 looks straight down with +X to the right and +Y up; `view.apply` refuses a pitch past ±π/2. A positive `roll` turns the picture clockwise. The app's View angles readout (`view.angle_readout`) shows the same yaw, pitch and roll in degrees. `fov` is the vertical field of view in radians. `0`, or no `fov`, is an orthographic view whose visible half-height is 0.4 × `distance`; with a perspective `fov` the half-height at the target is `distance * tan(fov / 2)`. `inspect.section` removes what lies on the side its normal points to: it keeps the points `p` with `n · p < d`, where `d = n · origin` (`flip: true` keeps the other side). To look into the cut, put the eye on the removed side.
|
||||
|
||||
To look closely at one part of a large model, such as a STEP assembly, work in a headless session. These steps change only the open design in memory:
|
||||
|
||||
|
||||
Reference in new issue
Block a user