From fa739ef0562e6588d0bbf053d3b2b6c57c7c5df8 Mon Sep 17 00:00:00 2001 From: benjamaan476 Date: Wed, 15 Jan 2025 11:51:38 +0000 Subject: [PATCH 1/9] Change TransformByPoint3d to use LengthUnit --- modeling-cmds/src/shared.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modeling-cmds/src/shared.rs b/modeling-cmds/src/shared.rs index df72b98c..6cfad05b 100644 --- a/modeling-cmds/src/shared.rs +++ b/modeling-cmds/src/shared.rs @@ -971,7 +971,7 @@ mod tests { #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))] pub struct TransformByPoint3d { /// The scale, or rotation, or translation. - pub property: Point3d, + 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, From c52f2b1ea22e58d029f2f42947708f68f13ccd89 Mon Sep 17 00:00:00 2001 From: benjamaan476 Date: Thu, 16 Jan 2025 12:51:50 +0000 Subject: [PATCH 2/9] Attempt generic again --- modeling-cmds/src/shared.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modeling-cmds/src/shared.rs b/modeling-cmds/src/shared.rs index 6cfad05b..270f8110 100644 --- a/modeling-cmds/src/shared.rs +++ b/modeling-cmds/src/shared.rs @@ -969,9 +969,9 @@ mod tests { #[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 { +pub struct TransformBy { /// The scale, or rotation, or translation. - pub property: Point3d, + 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, @@ -1007,14 +1007,14 @@ pub struct TransformByPoint4d { #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))] pub struct ComponentTransform { /// Translate component of the transform. - pub translate: Option, + pub translate: Option>, /// Rotate component of the transform. /// The rotation is specified as a roll, pitch, yaw. - pub rotate_rpy: Option, + pub rotate_rpy: Option>, /// 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, /// Scale component of the transform. - pub scale: Option, + pub scale: Option>, } From 088be8911decc1c376b6c5cfc05ce7a7a6f52d5f Mon Sep 17 00:00:00 2001 From: benjamaan476 Date: Thu, 16 Jan 2025 13:02:56 +0000 Subject: [PATCH 3/9] Use the generic properly --- modeling-cmds/src/shared.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modeling-cmds/src/shared.rs b/modeling-cmds/src/shared.rs index 270f8110..10e8bbec 100644 --- a/modeling-cmds/src/shared.rs +++ b/modeling-cmds/src/shared.rs @@ -971,7 +971,7 @@ mod tests { #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))] pub struct TransformBy { /// The scale, or rotation, or translation. - pub property: Point3d, + pub property: T, /// 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, From a3d60735164b95b6a9d3eeea04e23fe2de2ef794 Mon Sep 17 00:00:00 2001 From: benjamaan476 Date: Thu, 16 Jan 2025 13:05:00 +0000 Subject: [PATCH 4/9] Actually use it properly --- modeling-cmds/src/shared.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modeling-cmds/src/shared.rs b/modeling-cmds/src/shared.rs index 10e8bbec..dff14f4d 100644 --- a/modeling-cmds/src/shared.rs +++ b/modeling-cmds/src/shared.rs @@ -1007,14 +1007,14 @@ pub struct TransformByPoint4d { #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))] pub struct ComponentTransform { /// Translate component of the transform. - pub translate: Option>, + pub translate: Option>>, /// Rotate component of the transform. /// The rotation is specified as a roll, pitch, yaw. - pub rotate_rpy: Option>, + pub rotate_rpy: Option>>, /// 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, /// Scale component of the transform. - pub scale: Option>, + pub scale: Option>>, } From c3dd8f78cfb4c19acc9e53047fe840df2f9df000 Mon Sep 17 00:00:00 2001 From: benjamaan476 Date: Thu, 16 Jan 2025 13:32:19 +0000 Subject: [PATCH 5/9] Prevent camel case line error --- modeling-cmds/src/shared.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/modeling-cmds/src/shared.rs b/modeling-cmds/src/shared.rs index dff14f4d..e1bc6bbc 100644 --- a/modeling-cmds/src/shared.rs +++ b/modeling-cmds/src/shared.rs @@ -969,6 +969,7 @@ mod tests { #[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"))] +#[allow(non_camel_case_types)] pub struct TransformBy { /// The scale, or rotation, or translation. pub property: T, From e12c6b350da09af0109ab98e85eb3e0b577d26c1 Mon Sep 17 00:00:00 2001 From: benjamaan476 Date: Thu, 16 Jan 2025 13:56:03 +0000 Subject: [PATCH 6/9] Try force PascalCase --- modeling-cmds/src/shared.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modeling-cmds/src/shared.rs b/modeling-cmds/src/shared.rs index e1bc6bbc..b0aae51e 100644 --- a/modeling-cmds/src/shared.rs +++ b/modeling-cmds/src/shared.rs @@ -969,7 +969,7 @@ mod tests { #[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"))] -#[allow(non_camel_case_types)] +#[serde(rename_all="PascalCase")] pub struct TransformBy { /// The scale, or rotation, or translation. pub property: T, From 94ae9d6ea3b0501128f9bc648cda2a6d812c1a6f Mon Sep 17 00:00:00 2001 From: benjamaan476 Date: Thu, 16 Jan 2025 14:29:36 +0000 Subject: [PATCH 7/9] Change name to avoid issue --- modeling-cmds/src/shared.rs | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/modeling-cmds/src/shared.rs b/modeling-cmds/src/shared.rs index b0aae51e..caa90758 100644 --- a/modeling-cmds/src/shared.rs +++ b/modeling-cmds/src/shared.rs @@ -969,7 +969,7 @@ mod tests { #[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"))] -#[serde(rename_all="PascalCase")] +#[serde(rename = "TransformBy")] pub struct TransformBy { /// The scale, or rotation, or translation. pub property: T, @@ -983,25 +983,6 @@ pub struct TransformBy { 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, - /// 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))] @@ -1015,7 +996,7 @@ pub struct ComponentTransform { /// 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, + pub rotate_angle_axis: Option>, /// Scale component of the transform. pub scale: Option>>, } From 53ee92d6f74daa31380e87de5d8b17261d9e923b Mon Sep 17 00:00:00 2001 From: benjamaan476 Date: Thu, 16 Jan 2025 16:20:01 +0000 Subject: [PATCH 8/9] Implement custom JsonSchema --- modeling-cmds/src/shared.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/modeling-cmds/src/shared.rs b/modeling-cmds/src/shared.rs index caa90758..49ebbb9b 100644 --- a/modeling-cmds/src/shared.rs +++ b/modeling-cmds/src/shared.rs @@ -1,6 +1,6 @@ use enum_iterator::Sequence; use parse_display_derive::{Display, FromStr}; -use schemars::JsonSchema; +use schemars::{schema::SchemaObject, JsonSchema}; use serde::{Deserialize, Serialize}; use uuid::Uuid; @@ -966,10 +966,9 @@ mod tests { } /// How a property of an object should be transformed. -#[derive(Clone, Debug, PartialEq, Deserialize, JsonSchema, Serialize)] +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))] #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))] -#[serde(rename = "TransformBy")] pub struct TransformBy { /// The scale, or rotation, or translation. pub property: T, @@ -983,6 +982,24 @@ pub struct TransformBy { pub is_local: bool, } +impl JsonSchema for TransformBy { + fn schema_name() -> String { + format!("TransformByFor{}", T::schema_name()) + } + + fn schema_id() -> std::borrow::Cow<'static, str> { + std::borrow::Cow::Owned(format!("{}::TransformBy<{}>", module_path!(), T::schema_id())) + } + + fn json_schema(_: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { + SchemaObject { + instance_type: Some(schemars::schema::InstanceType::String.into()), + ..Default::default() + } + .into() + } +} + /// Container that holds a translate, rotate and scale. #[derive(Clone, Debug, PartialEq, Deserialize, JsonSchema, Serialize)] #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))] From 65becad72d27e0166c223d3e20b39b48b787d421 Mon Sep 17 00:00:00 2001 From: benjamaan476 Date: Thu, 16 Jan 2025 16:58:30 +0000 Subject: [PATCH 9/9] Change f32 to f64 for Transforms --- modeling-cmds/src/shared.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modeling-cmds/src/shared.rs b/modeling-cmds/src/shared.rs index 49ebbb9b..bdf0fced 100644 --- a/modeling-cmds/src/shared.rs +++ b/modeling-cmds/src/shared.rs @@ -1009,11 +1009,11 @@ pub struct ComponentTransform { pub translate: Option>>, /// Rotate component of the transform. /// The rotation is specified as a roll, pitch, yaw. - pub rotate_rpy: Option>>, + pub rotate_rpy: Option>>, /// 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>, + pub rotate_angle_axis: Option>>, /// Scale component of the transform. - pub scale: Option>>, + pub scale: Option>>, }