Skip to content

Commit d316d5d

Browse files
Added commands for object transforming (translate, rotate and scale) (#441)
* Added commands for object transforming (translate, rotate and scale) * Change transform commands into one command containing arguments for each transform type * forgot pub on fields * Move TransformBy into shared * update modeling api * Specify if the transform is to be applied locally or globally * fix lint issue * Rename struct to remove generic * Update modeling-cmds/src/def_enum.rs Co-authored-by: Adam Chalmers <[email protected]> --------- Co-authored-by: Adam Chalmers <[email protected]>
1 parent a185d43 commit d316d5d

File tree

10 files changed

+81
-83
lines changed

10 files changed

+81
-83
lines changed

modeling-cmds/src/def_enum.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ define_modeling_cmd_enum! {
2222
length_unit::LengthUnit,
2323
shared::{
2424
Angle,
25+
ComponentTransform,
2526
CutType,
2627
CameraMovement,
2728
ExtrudedFaceInfo,
@@ -1418,6 +1419,19 @@ define_modeling_cmd_enum! {
14181419
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
14191420
pub struct GetNumObjects {}
14201421

1422+
///Set the transform of an object.
1423+
#[derive(
1424+
Clone, Debug, Deserialize, PartialEq, JsonSchema, Serialize, ModelingCmdVariant,
1425+
)]
1426+
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1427+
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1428+
pub struct SetObjectTransform
1429+
{
1430+
/// Id of the object whose transform is to be set.
1431+
pub object_id: Uuid,
1432+
/// List of transforms to be applied to the object.
1433+
pub transforms: Vec<ComponentTransform>,
1434+
}
14211435
/// Make a new path by offsetting an object by a given distance.
14221436
/// The new path's ID will be the ID of this command.
14231437
#[derive(Clone, Debug, PartialEq, Deserialize, JsonSchema, Serialize, ModelingCmdVariant)]

modeling-cmds/src/format/fbx.rs

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,7 @@ use serde::{Deserialize, Serialize};
88
pub mod import {
99
use super::*;
1010
/// Options for importing FBX.
11-
#[derive(
12-
Clone,
13-
Debug,
14-
Default,
15-
Eq,
16-
Hash,
17-
PartialEq,
18-
Serialize,
19-
Deserialize,
20-
JsonSchema,
21-
Display,
22-
FromStr,
23-
24-
)]
11+
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
2512
#[display("")]
2613
#[serde(rename = "FbxImportOptions")]
2714
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
@@ -68,19 +55,7 @@ pub mod export {
6855

6956
/// Describes the storage format of an FBX file.
7057
#[derive(
71-
Default,
72-
Clone,
73-
Copy,
74-
Debug,
75-
Eq,
76-
Hash,
77-
PartialEq,
78-
Serialize,
79-
Deserialize,
80-
JsonSchema,
81-
Display,
82-
FromStr,
83-
58+
Default, Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr,
8459
)]
8560
#[display(style = "snake_case")]
8661
#[serde(rename = "FbxStorage", rename_all = "snake_case")]

modeling-cmds/src/format/gltf.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
use parse_display::{Display, FromStr};
32
use schemars::JsonSchema;
43
use serde::{Deserialize, Serialize};
@@ -8,20 +7,7 @@ pub mod import {
87
use super::*;
98

109
/// Options for importing glTF 2.0.
11-
#[derive(
12-
Clone,
13-
Debug,
14-
Default,
15-
Eq,
16-
Hash,
17-
PartialEq,
18-
Serialize,
19-
Deserialize,
20-
JsonSchema,
21-
Display,
22-
FromStr,
23-
24-
)]
10+
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
2511
#[display("")]
2612
#[serde(rename = "GltfImportOptions")]
2713
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]

modeling-cmds/src/format/obj.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
use parse_display::{Display, FromStr};
32
use schemars::JsonSchema;
43
use serde::{Deserialize, Serialize};
@@ -10,9 +9,7 @@ pub mod import {
109
use super::*;
1110

1211
/// Options for importing OBJ.
13-
#[derive(
14-
Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr,
15-
)]
12+
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
1613
#[display("coords: {coords}, units: {units}")]
1714
#[serde(rename = "ObjImportOptions")]
1815
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]

modeling-cmds/src/format/ply.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
use parse_display::{Display, FromStr};
32
use schemars::JsonSchema;
43
use serde::{Deserialize, Serialize};
@@ -10,9 +9,7 @@ pub mod import {
109
use super::*;
1110

1211
/// Options for importing PLY.
13-
#[derive(
14-
Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr,
15-
)]
12+
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
1613
#[display("coords: {coords}, units: {units}")]
1714
#[serde(rename = "PlyImportOptions")]
1815
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]

modeling-cmds/src/format/sldprt.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
11
/// Import functionality.
22
pub mod import {
3-
3+
44
use parse_display::{Display, FromStr};
55
use schemars::JsonSchema;
66
use serde::{Deserialize, Serialize};
77

88
/// Options for importing SolidWorks parts.
9-
#[derive(
10-
Clone,
11-
Debug,
12-
Default,
13-
Eq,
14-
Hash,
15-
PartialEq,
16-
Serialize,
17-
Deserialize,
18-
JsonSchema,
19-
Display,
20-
FromStr,
21-
22-
)]
9+
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
2310
#[display("split_closed_faces: {split_closed_faces}")]
2411
#[serde(default, rename = "SldprtImportOptions")]
2512
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]

modeling-cmds/src/format/step.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
use parse_display::{Display, FromStr};
32
use schemars::JsonSchema;
43
use serde::{Deserialize, Serialize};
@@ -10,19 +9,7 @@ pub mod import {
109
use super::*;
1110

1211
/// Options for importing STEP format.
13-
#[derive(
14-
Clone,
15-
Debug,
16-
Default,
17-
Eq,
18-
Hash,
19-
PartialEq,
20-
Serialize,
21-
Deserialize,
22-
JsonSchema,
23-
Display,
24-
FromStr,
25-
)]
12+
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
2613
#[display("split_closed_faces: {split_closed_faces}")]
2714
#[serde(default, rename = "StepImportOptions")]
2815
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]

modeling-cmds/src/format/stl.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
use parse_display::{Display, FromStr};
32
use schemars::JsonSchema;
43
use serde::{Deserialize, Serialize};
@@ -10,9 +9,7 @@ pub mod import {
109
use super::*;
1110

1211
/// Options for importing STL.
13-
#[derive(
14-
Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr,
15-
)]
12+
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
1613
#[display("coords: {coords}, units: {units}")]
1714
#[serde(rename = "StlImportOptions")]
1815
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]

modeling-cmds/src/ok_response.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,10 @@ define_ok_modeling_cmd_response_enum! {
420420
pub entity_ids: Vec<Uuid>,
421421
}
422422

423+
/// The response from the `SetObjectTransform` command.
424+
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, ModelingCmdOutput)]
425+
pub struct SetObjectTransform {}
426+
423427
/// The response from the `AddHoleFromOffset` command.
424428
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, ModelingCmdOutput)]
425429
pub struct AddHoleFromOffset {

modeling-cmds/src/shared.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,3 +964,57 @@ mod tests {
964964
assert!(c >= a);
965965
}
966966
}
967+
968+
/// How a property of an object should be transformed.
969+
#[derive(Clone, Debug, PartialEq, Deserialize, JsonSchema, Serialize)]
970+
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
971+
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
972+
pub struct TransformByPoint3d {
973+
/// The scale, or rotation, or translation.
974+
pub property: Point3d,
975+
/// If true, overwrite the previous value with this.
976+
/// If false, the previous value will be modified.
977+
/// E.g. when translating, `set=true` will set a new location,
978+
/// and `set=false` will translate the current location by the given X/Y/Z.
979+
pub set: bool,
980+
/// If true, the transform is applied in local space.
981+
/// If false, the transform is applied in global space.
982+
pub is_local: bool,
983+
}
984+
985+
/// How a property of an object should be transformed.
986+
/// This is a 4D version of the `TransformByPoint3d` (Used when wanting to specify a rotation with
987+
/// an angle and axis instead of roll pitch yaw).
988+
#[derive(Clone, Debug, PartialEq, Deserialize, JsonSchema, Serialize)]
989+
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
990+
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
991+
pub struct TransformByPoint4d {
992+
/// The scale, or rotation, or translation.
993+
pub property: Point4d,
994+
/// If true, overwrite the previous value with this.
995+
/// If false, the previous value will be modified.
996+
/// E.g. when translating, `set=true` will set a new location,
997+
/// and `set=false` will translate the current location by the given X/Y/Z.
998+
pub set: bool,
999+
/// If true, the transform is applied in local space.
1000+
/// If false, the transform is applied in global space.
1001+
pub is_local: bool,
1002+
}
1003+
1004+
/// Container that holds a translate, rotate and scale.
1005+
#[derive(Clone, Debug, PartialEq, Deserialize, JsonSchema, Serialize)]
1006+
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1007+
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1008+
pub struct ComponentTransform {
1009+
/// Translate component of the transform.
1010+
pub translate: Option<TransformByPoint3d>,
1011+
/// Rotate component of the transform.
1012+
/// The rotation is specified as a roll, pitch, yaw.
1013+
pub rotate_rpy: Option<TransformByPoint3d>,
1014+
/// Rotate component of the transform.
1015+
/// The rotation is specified as an axis and an angle (xyz are the components of the axis, w is
1016+
/// the angle in degrees).
1017+
pub rotate_angle_axis: Option<TransformByPoint4d>,
1018+
/// Scale component of the transform.
1019+
pub scale: Option<TransformByPoint3d>,
1020+
}

0 commit comments

Comments
 (0)