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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions modeling-cmds/src/def_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,43 @@ define_modeling_cmd_enum! {
Clone, Debug, Deserialize, JsonSchema, Serialize, ModelingCmdVariant,
)]
pub struct GetNumObjects;

///Set the parent object of an object
#[derive(
Clone, Debug, Deserialize, JsonSchema, Serialize, ModelingCmdVariantEmpty,
)]
pub struct SetObjectParent
{
///The object (child) whose parent will be set
pub object_id: Uuid,
/// Id of the new parent, if null will unset any parent of object_id
pub parent_id: Option<Uuid>
}

#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)]
struct TransformBy<T> {
/// The scale, or rotation, or translation.
property: T,
/// If true, overwrite the previous value with this.
/// If false, the object will be scaled, or translated, or rotated, etc.
set: bool,
}

///Set the transform of an object.
#[derive(
Clone, Debug, Deserialize, JsonSchema, Serialize, ModelingCmdVariantEmpty,
)]
pub struct SetObjectTransform
{
///Id of the object whose transform is to be set
pub object_id: Uuid,
#[serde(default)]
translate: Option<TransformBy<Point3d>>,
#[serde(default)]
rotate: Option<TransformBy<Point3d>>,
#[serde(default)]
scale: Option<TransformBy<Point3d>>,
}
Copy link
Contributor

@lf94 lf94 Aug 8, 2024

Choose a reason for hiding this comment

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

The following is just a suggestion/idea. We can further reduce bandwidth by instead sending a list of transforms. Otherwise looks great!

Suggested change
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)]
struct TransformBy<T> {
/// The scale, or rotation, or translation.
property: T,
/// If true, overwrite the previous value with this.
/// If false, the object will be scaled, or translated, or rotated, etc.
set: bool,
}
///Set the transform of an object.
#[derive(
Clone, Debug, Deserialize, JsonSchema, Serialize, ModelingCmdVariantEmpty,
)]
pub struct SetObjectTransform
{
///Id of the object whose transform is to be set
pub object_id: Uuid,
#[serde(default)]
translate: Option<TransformBy<Point3d>>,
#[serde(default)]
rotate: Option<TransformBy<Point3d>>,
#[serde(default)]
scale: Option<TransformBy<Point3d>>,
}
enum TransformOperation {
Translate,
Rotate,
Scale
}
struct Transform<T> {
operation: TransformOperation,
value: T,
set: bool,
}
///Set the transform of an object.
#[derive(
Clone, Debug, Deserialize, JsonSchema, Serialize, ModelingCmdVariantEmpty,
)]
pub struct SetObjectTransform
{
///Id of the object whose transform is to be set
pub object_id: Uuid,
transforms: Vec<Transform<Point3D>>
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought about this, but this allows you to send multiple transforms that overwrite each other, e.g. [(Translate, <0,0,0>), (Translate, <1,1,1>)]. So I think the current approach is better -- it limits you to sending at most one transform for a given property and the given project.

Copy link
Contributor

@lf94 lf94 Aug 8, 2024

Choose a reason for hiding this comment

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

It could be desirable from a programmer or mathematician point of view to compose transforms in various ways, ways I cannot imagine - for example [(Translate, <0,0,0>), (Translate, <1,1,1>)] could be desirable if they are composing (have set: false). Otherwise I agree with you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are knocking on the door of a transform stack here. Which is where you specify a chain of transforms one after the other that get applied in that order. Typically comes along with the ability to push and pop transforms to a stack that lets you get pretty flexible

Copy link
Collaborator

Choose a reason for hiding this comment

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

We're now agreed that Transform endpoint should take a list of transforms.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So these transforms will get applied one by one if more than one is provided? Is it up to the user to handle the complexity of the list? E.g. if two translates are side by side that could have just been one aggregate transform.

}
}

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")]
pub struct Options {}
Expand Down Expand Up @@ -64,19 +51,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")]
pub struct Options {}
Expand Down
5 changes: 1 addition & 4 deletions modeling-cmds/src/format/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use parse_display_derive::{Display, FromStr};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -53,9 +52,7 @@ pub enum OutputFormat {
}

/// Input format specifier.
#[derive(
Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr,
)]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
#[serde(tag = "type", rename_all = "snake_case")]
#[display(style = "snake_case")]
pub enum InputFormat {
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")]
pub struct Options {
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")]
pub struct Options {
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")]
pub struct Options {
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")]
pub struct Options {
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")]
pub struct Options {
Expand Down
1 change: 0 additions & 1 deletion modeling-cmds/src/units.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use kittycad_unit_conversion_derive::UnitConversion;
use parse_display_derive::{Display, FromStr};
use schemars::JsonSchema;
Expand Down