Skip to content

Commit e96c408

Browse files
Save/restore camera views (#782)
* Add new commands and shared types * Fix enum casing * Apply suggestions from code review Co-authored-by: Adam Chalmers <adam.chalmers@zoo.dev> --------- Co-authored-by: Adam Chalmers <adam.chalmers@zoo.dev>
1 parent 96ad246 commit e96c408

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

modeling-cmds/src/def_enum.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ define_modeling_cmd_enum! {
1515
use schemars::JsonSchema;
1616
use serde::{Deserialize, Serialize};
1717
use uuid::Uuid;
18+
use crate::shared::CameraViewState;
1819

1920
use crate::{
2021
format::{OutputFormat2d, OutputFormat3d},
@@ -273,6 +274,21 @@ define_modeling_cmd_enum! {
273274
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
274275
pub struct DefaultCameraGetSettings {}
275276

277+
/// Gets the default camera's view state
278+
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant)]
279+
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
280+
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
281+
pub struct DefaultCameraGetView {}
282+
283+
/// Sets the default camera's view state
284+
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant)]
285+
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
286+
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
287+
pub struct DefaultCameraSetView {
288+
/// Camera view state
289+
pub view: CameraViewState,
290+
}
291+
276292
/// Change what the default camera is looking at.
277293
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant)]
278294
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]

modeling-cmds/src/ok_response.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ define_ok_modeling_cmd_response_enum! {
1212
use serde::{Deserialize, Serialize};
1313
use uuid::Uuid;
1414
use crate::shared::CameraSettings;
15+
use crate::shared::CameraViewState;
1516

1617
use crate::{self as kittycad_modeling_cmds};
1718
use crate::{
@@ -397,6 +398,17 @@ define_ok_modeling_cmd_response_enum! {
397398
pub settings: CameraSettings
398399
}
399400

401+
/// The response from the `DefaultCameraGetView` command.
402+
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, ModelingCmdOutput)]
403+
pub struct DefaultCameraGetView {
404+
/// Camera view state
405+
pub view: CameraViewState
406+
}
407+
408+
/// The response from the `DefaultCameraSetView` command.
409+
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, ModelingCmdOutput)]
410+
pub struct DefaultCameraSetView {}
411+
400412
/// The response from the `DefaultCameraZoom` command.
401413
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, ModelingCmdOutput)]
402414
pub struct DefaultCameraZoom {

modeling-cmds/src/shared.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,55 @@ pub struct CameraSettings {
739739
pub ortho: bool,
740740
}
741741

742+
#[allow(missing_docs)]
743+
#[repr(u8)]
744+
#[derive(Default, Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
745+
#[serde(rename_all = "snake_case")]
746+
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
747+
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
748+
pub enum WorldCoordinateSystem {
749+
#[default]
750+
RightHandedUpZ,
751+
RightHandedUpY,
752+
}
753+
754+
#[allow(missing_docs)]
755+
#[repr(C)]
756+
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
757+
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
758+
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
759+
pub struct CameraViewState {
760+
pub pivot_rotation: [f32; 4],
761+
pub pivot_position: [f32; 3],
762+
pub eye_offset: f32,
763+
pub fov_y: f32,
764+
pub ortho_scale_factor: f32,
765+
pub is_ortho: bool,
766+
pub ortho_scale_enabled: bool,
767+
pub world_coord_system: WorldCoordinateSystem,
768+
}
769+
770+
impl Default for CameraViewState {
771+
fn default() -> Self {
772+
CameraViewState {
773+
pivot_rotation: [0.0, 0.0, 0.0, 1.0],
774+
pivot_position: Default::default(),
775+
eye_offset: 10.0,
776+
fov_y: 45.0,
777+
ortho_scale_factor: 1.6,
778+
is_ortho: false,
779+
ortho_scale_enabled: true,
780+
world_coord_system: WorldCoordinateSystem::default(),
781+
}
782+
}
783+
}
784+
785+
#[cfg(feature = "cxx")]
786+
impl_extern_type! {
787+
[Trivial]
788+
CameraViewState = "Endpoints::CameraViewState"
789+
}
790+
742791
impl From<CameraSettings> for crate::output::DefaultCameraZoom {
743792
fn from(settings: CameraSettings) -> Self {
744793
Self { settings }

0 commit comments

Comments
 (0)