3e70ad9876
* View navigator: a custom body as the navigator, and a right-click menu to switch types A right-click anywhere on the view navigator opens a menu with its three types: Axes, Cube and Custom. Custom opens the Custom View Navigator panel (a feature panel with OK and Cancel): pick a body in the view, its texture (Themed: the cube's colours; Modeled: the body's own appearance and the view's edge colour), and whether the cube's rotation arrows and Home button go around it. The navigator previews the panel's choices while it is open; Cancel leaves it as it was. The custom navigator draws the body at the cube's size through a small depth-buffered raster, so hidden faces stay hidden; hovering a face highlights it, a click looks straight at it (and frames the model with navigator_fit on), a drag orbits. Until a body is chosen it draws the cube. The body is kept as a packed snapshot (16-bit, base64) with the preferences and in settings profiles, so it stays across runs and designs and travels with an exported profile. Bodies over 10,000 triangles, and long or flat ones (thinnest width under a fifth of the widest), are refused. New command view.navigator (style, body, texture, arrows, home) does the same without opening anything; new preferences navigator_texture, navigator_arrows and navigator_home, and a Custom choice for navigator_style. Defaults are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Custom view navigator: a hovered face in Modeled takes the view's selection colours In the Modeled texture the face under the pointer is filled and outlined the way the view selects a face of the model (sel_face, sel_edge), not in the cube's hover blue and accent, which Themed keeps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Custom view navigator: a hovered face in Modeled lights up as the view's mouse-over does The face under the pointer keeps its own colour, a little lighter (hover_face_lift) and still shaded, with its edges in the view's mouse-over edge colour (hover_edge), as the 3D view shows a face under the pointer; not the selection colours. Themed keeps the cube's hover blue and accent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Custom view navigator: rotation arrows and Home on by default navigator_arrows and navigator_home start on, so a new custom navigator has the cube's arrows and Home button around it; the Custom View Navigator panel turns either off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Custom view navigator: the strings in every complete language, and test fixes - The new messages in Arabic, Hebrew and Vietnamese (complete catalogs, like Japanese and Chinese). - The navigator's raster goes through one colour helper, listed with its reason among the files allowed colour literals (the design's appearance shaded into pixels). - nav_settings joins the requested-icon manifest (the view.navigator command's icon). - A visible edge piece is kept only when the stretch seen with it, across the edge's segments, is at least two samples long: a hidden edge no longer shows a sliver at a silhouette corner. - The navigator layout test treats Custom without a body as the cube it draws; the panel and size tests no longer assume an empty undo list, the style before opening, or a coarse sphere. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Custom view navigator: profiles carry its texture, arrows and Home Settings profiles keep a fixed set of preference keys (#9907), which the custom navigator's newer settings are not part of. They travel in the profile's own `view_navigator` entry, next to its body (`view_gizmo`): captured, checked (a value this version can't read is left out) and applied, leaving the fixed key set unchanged. The cube's arrow inversion (#10286) applies to the custom navigator's arrows too, through the shared arrows(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Custom view navigator: follow main's Vec3 move and fallible world_state Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Custom view navigator: list view.navigator in the rig's EXEMPT, refuse a stored body that can't save again, right-click without a widget over the navigator Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Custom view navigator: keep the body unless picked again, save only a profile that reads back, no navigator menu through a popup Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Custom view navigator: refuse a stored body with a triangle past its points Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Custom view navigator: a stored body meets the triangle and aspect limits a picked one does Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Custom view navigator: a body at the 5:1 limit stays inside it once packed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
284 lines
11 KiB
Rust
284 lines
11 KiB
Rust
//! Render shell requests. The UI applies validated echoes without design edits.
|
|
use schemars::{JsonSchema, Schema, SchemaGenerator, json_schema};
|
|
use serde::{Deserialize, Deserializer, Serialize};
|
|
use serde_json::Value;
|
|
use std::borrow::Cow;
|
|
|
|
use super::types::{CameraParam, present};
|
|
|
|
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct RenderDock {
|
|
pub panel: RenderPanel,
|
|
pub side: DockSide,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
|
|
#[serde(rename_all = "lowercase")]
|
|
pub enum RenderPanel {
|
|
Inspector,
|
|
Browser,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
|
|
#[serde(rename_all = "lowercase")]
|
|
pub enum DockSide {
|
|
Left,
|
|
Right,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct RenderFocus {
|
|
/// Hide the Render docks while retaining their layout and the current camera.
|
|
pub on: bool,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct RenderBrowser {
|
|
/// Open the floating Browser card in a narrow Render window.
|
|
pub open: bool,
|
|
}
|
|
|
|
/// Empty input for the read-only viewport effect query.
|
|
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct StatusItemsParams {}
|
|
|
|
/// 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>,
|
|
}
|
|
|
|
/// Turn the view to the command's standard orientation (front, back, left, right, top, bottom
|
|
/// or isometric), as the view cube does, keeping the camera's target, distance, projection and
|
|
/// up axis. Display only: the design isn't changed and nothing is added to undo.
|
|
#[derive(Debug, Deserialize, JsonSchema)]
|
|
#[schemars(deny_unknown_fields)]
|
|
pub struct StandardViewParams {
|
|
/// The camera to turn. Default: the session's camera, or the home view when there is none.
|
|
#[serde(default, deserialize_with = "present", skip_serializing_if = "Option::is_none")]
|
|
#[schemars(with = "CameraParam")]
|
|
pub camera: Option<CameraParam>,
|
|
}
|
|
|
|
/// Look straight at the first selected planar face or plane, centred on the point it was picked
|
|
/// at (a plane: its origin); asked again while already facing it, look from the other side.
|
|
/// Keeps the camera's distance, projection and up axis. Needs a planar face or plane in the
|
|
/// selection. Display only: the design isn't changed and nothing is added to undo.
|
|
#[derive(Debug, Deserialize, JsonSchema)]
|
|
#[schemars(deny_unknown_fields)]
|
|
pub struct NormalToParams {
|
|
/// The camera to turn. Default: the session's camera, or the home view when there is none.
|
|
/// Its yaw and roll must also be within ±1e6 and its pitch within ±π/2.
|
|
#[serde(default, deserialize_with = "present", skip_serializing_if = "Option::is_none")]
|
|
#[schemars(with = "CameraParam")]
|
|
pub camera: Option<CameraParam>,
|
|
}
|
|
|
|
/// What the standard views and `view.normal_to` return: the camera after the turn, which the
|
|
/// session keeps as its view.
|
|
#[derive(Debug, Serialize, JsonSchema)]
|
|
pub struct CameraReply {
|
|
/// The camera now.
|
|
#[schemars(with = "CameraParam")]
|
|
pub camera: solidcraft_render::Camera,
|
|
/// 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>,
|
|
}
|
|
|
|
/// `view.next_tab` and `view.previous_tab` take no parameters (#8565).
|
|
#[derive(Debug, Deserialize, JsonSchema)]
|
|
#[schemars(deny_unknown_fields)]
|
|
pub struct TabStepParams {}
|
|
|
|
/// What `view.next_tab` and `view.previous_tab` return. The window shows the design tab `step`
|
|
/// places along the strip, going round at either end; the design is not changed and nothing is
|
|
/// added to undo.
|
|
#[derive(Debug, Serialize, JsonSchema)]
|
|
pub struct TabStep {
|
|
/// 1: the tab to the right; -1: the tab to the left.
|
|
pub step: i8,
|
|
/// 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>,
|
|
}
|
|
|
|
/// Validated request and echoed result of `view.render_select`.
|
|
#[derive(Debug, Serialize)]
|
|
pub struct RenderSelect {
|
|
pub kind: String,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub id: Option<String>,
|
|
}
|
|
|
|
impl<'de> Deserialize<'de> for RenderSelect {
|
|
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
|
|
#[derive(Deserialize)]
|
|
#[serde(deny_unknown_fields)]
|
|
struct Request {
|
|
kind: String,
|
|
id: Option<String>,
|
|
}
|
|
let request = Request::deserialize(d)?;
|
|
let identified = matches!(request.kind.as_str(), "light" | "shot");
|
|
if !matches!(
|
|
request.kind.as_str(),
|
|
"nothing" | "environment" | "lighting" | "light" | "shot" | "output" | "wear" | "sampling" | "effects" | "check"
|
|
) || identified != request.id.is_some()
|
|
|| request.id.as_ref().is_some_and(|id| id.trim().is_empty() || id.len() > 1024)
|
|
{
|
|
return Err(serde::de::Error::custom("expected a Browser kind and an id only for light or shot"));
|
|
}
|
|
Ok(Self { kind: request.kind, id: request.id })
|
|
}
|
|
}
|
|
|
|
impl JsonSchema for RenderSelect {
|
|
fn schema_name() -> Cow<'static, str> {
|
|
"RenderSelect".into()
|
|
}
|
|
fn json_schema(_: &mut SchemaGenerator) -> Schema {
|
|
json_schema!({
|
|
"oneOf": [
|
|
{
|
|
"type": "object",
|
|
"properties": {
|
|
"kind": {"type": "string", "enum": ["nothing", "environment", "lighting", "output", "wear", "sampling", "effects", "check"]},
|
|
"id": {"type": "null"}
|
|
},
|
|
"required": ["kind"],
|
|
"additionalProperties": false
|
|
},
|
|
{
|
|
"type": "object",
|
|
"properties": {
|
|
"kind": {"type": "string", "enum": ["light", "shot"]},
|
|
"id": {"type": "string", "minLength": 1, "maxLength": 1024, "pattern": super::types::not_blank_pattern(),
|
|
"description": "A nonblank identity, at most 1024 UTF-8 bytes."}
|
|
},
|
|
"required": ["kind", "id"],
|
|
"additionalProperties": false
|
|
}
|
|
]
|
|
})
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, Deserialize, Serialize, JsonSchema)]
|
|
pub enum FrameAspect {
|
|
#[serde(rename = "16:9")]
|
|
Wide,
|
|
#[serde(rename = "3:2")]
|
|
Photo,
|
|
#[serde(rename = "1:1")]
|
|
Square,
|
|
#[serde(rename = "4:5")]
|
|
Portrait,
|
|
#[serde(rename = "9:16")]
|
|
Tall,
|
|
#[serde(rename = "custom")]
|
|
Custom,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct RenderFrame {
|
|
/// Overlay aspect selection only; output dimensions require render.settings.set.
|
|
#[serde(default, deserialize_with = "super::types::present", skip_serializing_if = "Option::is_none")]
|
|
#[schemars(with = "FrameAspect")]
|
|
pub aspect: Option<FrameAspect>,
|
|
#[serde(default, deserialize_with = "super::types::present", skip_serializing_if = "Option::is_none")]
|
|
#[schemars(with = "bool")]
|
|
pub thirds: Option<bool>,
|
|
#[serde(default, deserialize_with = "super::types::present", skip_serializing_if = "Option::is_none")]
|
|
#[schemars(with = "bool")]
|
|
pub safe_area: Option<bool>,
|
|
#[serde(default, deserialize_with = "super::types::present", skip_serializing_if = "Option::is_none")]
|
|
#[schemars(with = "bool")]
|
|
pub centre_mark: Option<bool>,
|
|
}
|
|
|
|
/// Set the view navigator at the view's corner: its type, and for the custom one the body it
|
|
/// draws, its texture and the controls around it. The navigator is the app's, kept with the
|
|
/// preferences and settings profiles, never in the design; without an app the call only checks
|
|
/// its parameters. Never opens a dialog.
|
|
#[derive(Debug, Default, Deserialize, Serialize, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct NavigatorParams {
|
|
/// The navigator: signed axes, the cube, or a custom body (the cube until a body is
|
|
/// chosen). Default: unchanged.
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
pub style: Option<NavigatorStyle>,
|
|
/// A body of the open design for the custom navigator to draw; the app keeps a snapshot of
|
|
/// it, so it stays when the design closes. `null`: no body (the cube again). A body over
|
|
/// 10,000 triangles, or whose thinnest width is under a fifth of its widest, is refused.
|
|
/// Default: unchanged.
|
|
#[serde(default, deserialize_with = "nullable", skip_serializing_if = "Option::is_none")]
|
|
#[schemars(with = "Option<String>")]
|
|
pub body: Option<Option<String>>,
|
|
/// The custom navigator's colours: the cube's (`themed`) or the body's own appearance and
|
|
/// edge colour (`modeled`). Default: unchanged.
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
pub texture: Option<NavigatorTexture>,
|
|
/// The cube's orbit and roll arrows around the custom navigator. Default: unchanged.
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
pub arrows: Option<bool>,
|
|
/// The cube's Home button beside the custom navigator. Default: unchanged.
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
pub home: Option<bool>,
|
|
}
|
|
|
|
/// A view navigator type.
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize, JsonSchema)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum NavigatorStyle {
|
|
Axes,
|
|
Cube,
|
|
Custom,
|
|
}
|
|
|
|
/// How the custom view navigator colours its body.
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize, JsonSchema)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum NavigatorTexture {
|
|
Themed,
|
|
Modeled,
|
|
}
|
|
|
|
/// A key that may be given as `null` (`Some(None)`), apart from absent (`None`).
|
|
fn nullable<'de, D: Deserializer<'de>>(d: D) -> Result<Option<Option<String>>, D::Error> {
|
|
Option::<String>::deserialize(d).map(Some)
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "view_navigation_tests.rs"]
|
|
mod tests;
|