Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions modeling-cmds/src/def_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use crate::shared::CameraViewState;

use crate::{
format::{OutputFormat2d, OutputFormat3d},
Expand Down Expand Up @@ -273,6 +274,21 @@
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub struct DefaultCameraGetSettings {}

/// Gets the default camera's view state
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]

Check warning on line 279 in modeling-cmds/src/def_enum.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/def_enum.rs#L278-L279

Added lines #L278 - L279 were not covered by tests
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub struct DefaultCameraGetView {}

/// Sets the default camera's view state
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]

Check warning on line 285 in modeling-cmds/src/def_enum.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/def_enum.rs#L284-L285

Added lines #L284 - L285 were not covered by tests
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub struct DefaultCameraSetView {
/// Camera view state
pub view: CameraViewState,
}

/// Change what the default camera is looking at.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
Expand Down
12 changes: 12 additions & 0 deletions modeling-cmds/src/ok_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ define_ok_modeling_cmd_response_enum! {
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use crate::shared::CameraSettings;
use crate::shared::CameraViewState;

use crate::{self as kittycad_modeling_cmds};
use crate::{
Expand Down Expand Up @@ -397,6 +398,17 @@ define_ok_modeling_cmd_response_enum! {
pub settings: CameraSettings
}

/// The response from the `DefaultCameraGetView` command.
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, ModelingCmdOutput)]
pub struct DefaultCameraGetView {
/// Camera view state
pub view: CameraViewState
}

/// The response from the `DefaultCameraSetView` command.
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, ModelingCmdOutput)]
pub struct DefaultCameraSetView {}

/// The response from the `DefaultCameraZoom` command.
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, ModelingCmdOutput)]
pub struct DefaultCameraZoom {
Expand Down
49 changes: 49 additions & 0 deletions modeling-cmds/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,55 @@
pub ortho: bool,
}

#[allow(missing_docs)]
#[repr(u8)]
#[derive(Default, Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]

Check warning on line 746 in modeling-cmds/src/shared.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/shared.rs#L746

Added line #L746 was not covered by tests
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub enum WorldCoordinateSystem {
#[default]
RightHandedUpZ,
RightHandedUpY,
}

#[allow(missing_docs)]
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]

Check warning on line 757 in modeling-cmds/src/shared.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/shared.rs#L757

Added line #L757 was not covered by tests
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub struct CameraViewState {
pub pivot_rotation: [f32; 4],
pub pivot_position: [f32; 3],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should use our dedicated Point type, because it's not just 3 arbitrary number, it represents a specific point in space, right?

Suggested change
pub pivot_position: [f32; 3],
pub pivot_position: Point3d<f32>,

Copy link
Contributor Author

@davreev davreev Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was avoiding it here since this type passes through an FFI boundary and Point3d isn't repr(C).

I might be erring on the side of caution unnecessarily though - is it ok to have non repr(C) fields in a repr(C) struct? Will follow up with another PR if so.

pub eye_offset: f32,
pub fov_y: f32,
pub ortho_scale_factor: f32,
pub is_ortho: bool,
pub ortho_scale_enabled: bool,
pub world_coord_system: WorldCoordinateSystem,
}

impl Default for CameraViewState {
fn default() -> Self {
CameraViewState {
pivot_rotation: [0.0, 0.0, 0.0, 1.0],
pivot_position: [0.0, 0.0, 0.0],
eye_offset: 10.0,
fov_y: 45.0,
ortho_scale_factor: 1.6,
is_ortho: false,
ortho_scale_enabled: true,
world_coord_system: WorldCoordinateSystem::default(),
}
}

Check warning on line 782 in modeling-cmds/src/shared.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/shared.rs#L771-L782

Added lines #L771 - L782 were not covered by tests
}

#[cfg(feature = "cxx")]
impl_extern_type! {
[Trivial]
CameraViewState = "Endpoints::CameraViewState"
}

impl From<CameraSettings> for crate::output::DefaultCameraZoom {
fn from(settings: CameraSettings) -> Self {
Self { settings }
Expand Down