Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added commands for object transforming (translate, rotate and scale) #441

Merged
merged 13 commits into from
Jan 8, 2025
Merged
14 changes: 14 additions & 0 deletions modeling-cmds/src/def_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ define_modeling_cmd_enum! {
length_unit::LengthUnit,
shared::{
Angle,
ComponentTransform,
CutType,
CameraMovement,
ExtrudedFaceInfo,
Expand Down Expand Up @@ -1473,6 +1474,19 @@ define_modeling_cmd_enum! {
_fix_ts_rs: (),
}

///Set the transform of an object.
#[derive(
Clone, Debug, Deserialize, PartialEq, JsonSchema, Serialize, ModelingCmdVariant,
)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub struct SetObjectTransform
{
/// Id of the object whose transform is to be set.
pub object_id: Uuid,
/// List of transforms to be applied to the object.
pub transforms: Vec<ComponentTransform>,
}
/// Make a new path by offsetting an object by a given distance.
/// The new path's ID will be the ID of this command.
#[derive(Clone, Debug, PartialEq, Deserialize, JsonSchema, Serialize, ModelingCmdVariant)]
Expand Down
29 changes: 2 additions & 27 deletions modeling-cmds/src/format/fbx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,7 @@ use serde::{Deserialize, Serialize};
pub mod import {
use super::*;
/// Options for importing FBX.
#[derive(
Clone,
Debug,
Default,
Eq,
Hash,
PartialEq,
Serialize,
Deserialize,
JsonSchema,
Display,
FromStr,

)]
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
#[display("")]
#[serde(rename = "FbxImportOptions")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
Expand Down Expand Up @@ -68,19 +55,7 @@ pub mod export {

/// Describes the storage format of an FBX file.
#[derive(
Default,
Clone,
Copy,
Debug,
Eq,
Hash,
PartialEq,
Serialize,
Deserialize,
JsonSchema,
Display,
FromStr,

Default, Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr,
)]
#[display(style = "snake_case")]
#[serde(rename = "FbxStorage", rename_all = "snake_case")]
Expand Down
16 changes: 1 addition & 15 deletions modeling-cmds/src/format/gltf.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use parse_display::{Display, FromStr};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand All @@ -8,20 +7,7 @@ pub mod import {
use super::*;

/// Options for importing glTF 2.0.
#[derive(
Clone,
Debug,
Default,
Eq,
Hash,
PartialEq,
Serialize,
Deserialize,
JsonSchema,
Display,
FromStr,

)]
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
#[display("")]
#[serde(rename = "GltfImportOptions")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
Expand Down
5 changes: 1 addition & 4 deletions modeling-cmds/src/format/obj.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use parse_display::{Display, FromStr};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand All @@ -10,9 +9,7 @@ pub mod import {
use super::*;

/// Options for importing OBJ.
#[derive(
Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr,
)]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
#[display("coords: {coords}, units: {units}")]
#[serde(rename = "ObjImportOptions")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
Expand Down
5 changes: 1 addition & 4 deletions modeling-cmds/src/format/ply.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use parse_display::{Display, FromStr};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand All @@ -10,9 +9,7 @@ pub mod import {
use super::*;

/// Options for importing PLY.
#[derive(
Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr,
)]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
#[display("coords: {coords}, units: {units}")]
#[serde(rename = "PlyImportOptions")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
Expand Down
17 changes: 2 additions & 15 deletions modeling-cmds/src/format/sldprt.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
/// Import functionality.
pub mod import {

use parse_display::{Display, FromStr};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

/// Options for importing SolidWorks parts.
#[derive(
Clone,
Debug,
Default,
Eq,
Hash,
PartialEq,
Serialize,
Deserialize,
JsonSchema,
Display,
FromStr,

)]
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
#[display("split_closed_faces: {split_closed_faces}")]
#[serde(default, rename = "SldprtImportOptions")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
Expand Down
15 changes: 1 addition & 14 deletions modeling-cmds/src/format/step.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use parse_display::{Display, FromStr};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand All @@ -10,19 +9,7 @@ pub mod import {
use super::*;

/// Options for importing STEP format.
#[derive(
Clone,
Debug,
Default,
Eq,
Hash,
PartialEq,
Serialize,
Deserialize,
JsonSchema,
Display,
FromStr,
)]
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
#[display("split_closed_faces: {split_closed_faces}")]
#[serde(default, rename = "StepImportOptions")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
Expand Down
5 changes: 1 addition & 4 deletions modeling-cmds/src/format/stl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use parse_display::{Display, FromStr};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand All @@ -10,9 +9,7 @@ pub mod import {
use super::*;

/// Options for importing STL.
#[derive(
Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr,
)]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
#[display("coords: {coords}, units: {units}")]
#[serde(rename = "StlImportOptions")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
Expand Down
4 changes: 4 additions & 0 deletions modeling-cmds/src/ok_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,10 @@ define_ok_modeling_cmd_response_enum! {
pub entity_ids: Vec<Uuid>,
}

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

/// The response from the `AddHoleFromOffset` command.
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, ModelingCmdOutput)]
pub struct AddHoleFromOffset {
Expand Down
54 changes: 54 additions & 0 deletions modeling-cmds/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -969,3 +969,57 @@ mod tests {
assert!(c >= a);
}
}

/// How a property of an object should be transformed.
#[derive(Clone, Debug, PartialEq, Deserialize, JsonSchema, Serialize)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub struct TransformByPoint3d {
/// The scale, or rotation, or translation.
pub property: Point3d,
/// If true, overwrite the previous value with this.
/// If false, the previous value will be modified.
/// E.g. when translating, `set=true` will set a new location,
/// and `set=false` will translate the current location by the given X/Y/Z.
pub set: bool,
/// If true, the transform is applied in local space.
/// If false, the transform is applied in global space.
pub is_local: bool,
}

/// How a property of an object should be transformed.
/// This is a 4D version of the `TransformByPoint3d` (Used when wanting to specify a rotation with
/// an angle and axis instead of roll pitch yaw).
#[derive(Clone, Debug, PartialEq, Deserialize, JsonSchema, Serialize)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub struct TransformByPoint4d {
/// The scale, or rotation, or translation.
pub property: Point4d,
/// If true, overwrite the previous value with this.
/// If false, the previous value will be modified.
/// E.g. when translating, `set=true` will set a new location,
/// and `set=false` will translate the current location by the given X/Y/Z.
pub set: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this not the same as relative? If it is then should we not call this relative for consistency?

Copy link
Contributor

Choose a reason for hiding this comment

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

Having said that, if the intention is for relative to be the default then maybe absolute is a better name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

relative, absolute, override. There are many ways of describing this

/// If true, the transform is applied in local space.
/// If false, the transform is applied in global space.
pub is_local: bool,
}

/// Container that holds a translate, rotate and scale.
#[derive(Clone, Debug, PartialEq, Deserialize, JsonSchema, Serialize)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub struct ComponentTransform {
/// Translate component of the transform.
pub translate: Option<TransformByPoint3d>,
/// Rotate component of the transform.
/// The rotation is specified as a roll, pitch, yaw.
pub rotate_rpy: Option<TransformByPoint3d>,
/// Rotate component of the transform.
/// The rotation is specified as an axis and an angle (xyz are the components of the axis, w is
/// the angle in degrees).
pub rotate_angle_axis: Option<TransformByPoint4d>,
/// Scale component of the transform.
pub scale: Option<TransformByPoint3d>,
}
Loading