From 38efaa55a9aef226d232a8a3c5ee92db23f924b3 Mon Sep 17 00:00:00 2001 From: Adam Chalmers Date: Wed, 30 Oct 2024 14:08:55 -0500 Subject: [PATCH 1/2] Extrude can send IDs for the new faces When extruding a 2D shape into a 3D shape, a bunch of new faces are created. These faces need IDs. The backend currently generates these IDs randomly. Add a new option to allow the client to send the IDs. --- modeling-cmds/src/def_enum.rs | 5 ++++ modeling-cmds/src/shared.rs | 24 +++++++++++++++++++ modeling-session/examples/cube_png.rs | 1 + modeling-session/examples/cube_png_batch.rs | 1 + .../examples/lsystem_png_batch.rs | 1 + 5 files changed, 32 insertions(+) diff --git a/modeling-cmds/src/def_enum.rs b/modeling-cmds/src/def_enum.rs index d888bdcc..cd2a7164 100644 --- a/modeling-cmds/src/def_enum.rs +++ b/modeling-cmds/src/def_enum.rs @@ -24,6 +24,7 @@ define_modeling_cmd_enum! { Angle, CutType, CameraMovement, + ExtrudedFaceInfo, AnnotationOptions, AnnotationType, CameraDragInteractionType, Color, DistanceType, EntityType, PathComponentConstraintBound, PathComponentConstraintType, PathSegment, PerspectiveCameraParameters, Point2d, Point3d, SceneSelectionType, SceneToolType, @@ -99,6 +100,10 @@ define_modeling_cmd_enum! { pub target: ModelingCmdId, /// How far off the plane to extrude pub distance: LengthUnit, + /// Which IDs should the new faces have? + /// If this isn't given, the engine will generate IDs. + #[serde(default)] + pub faces: Option, } /// Command for revolving a solid 2d. diff --git a/modeling-cmds/src/shared.rs b/modeling-cmds/src/shared.rs index c475e6f3..55a44973 100644 --- a/modeling-cmds/src/shared.rs +++ b/modeling-cmds/src/shared.rs @@ -2,6 +2,7 @@ use enum_iterator::Sequence; use parse_display_derive::{Display, FromStr}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; +use uuid::Uuid; #[cfg(feature = "cxx")] use crate::impl_extern_type; @@ -606,6 +607,29 @@ impl From for http::StatusCode { } } +/// IDs for the extruded faces. +#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone)] +pub struct ExtrudedFaceInfo { + /// The face made from the original 2D shape being extruded. + /// If the solid is extruded from a shape which already has an ID + /// (e.g. extruding something which was sketched on a face), this + /// doesn't need to be sent. + pub bottom: Option, + /// Top face of the extrusion (parallel and further away from the original 2D shape being extruded). + pub top: Uuid, + /// Any intermediate sides between the top and bottom. + pub sides: Vec, +} + +/// IDs for a side face, extruded from the path of some sketch/2D shape. +#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone)] +pub struct SideFace { + /// ID of the path this face is being extruded from. + pub path_id: Uuid, + /// Desired ID for the resulting face. + pub face_id: Uuid, +} + /// Camera settings including position, center, fov etc #[derive(Debug, Serialize, Deserialize, JsonSchema, Clone)] pub struct CameraSettings { diff --git a/modeling-session/examples/cube_png.rs b/modeling-session/examples/cube_png.rs index 491afcf1..c31d3f00 100644 --- a/modeling-session/examples/cube_png.rs +++ b/modeling-session/examples/cube_png.rs @@ -107,6 +107,7 @@ async fn main() -> Result<()> { Extrude { distance: CUBE_WIDTH * 2.0, target: path, + faces: None, } .into(), ) diff --git a/modeling-session/examples/cube_png_batch.rs b/modeling-session/examples/cube_png_batch.rs index d66c4042..4fd3340f 100644 --- a/modeling-session/examples/cube_png_batch.rs +++ b/modeling-session/examples/cube_png_batch.rs @@ -98,6 +98,7 @@ async fn main() -> Result<()> { cmd: ModelingCmd::Extrude(Extrude { distance: CUBE_WIDTH * 2.0, target: path, + faces: None, }), cmd_id: random_id(), }); diff --git a/modeling-session/examples/lsystem_png_batch.rs b/modeling-session/examples/lsystem_png_batch.rs index 6ca286aa..c2a8a265 100644 --- a/modeling-session/examples/lsystem_png_batch.rs +++ b/modeling-session/examples/lsystem_png_batch.rs @@ -137,6 +137,7 @@ async fn main() -> Result<()> { cmd: ModelingCmd::Extrude(Extrude { distance: LengthUnit(1.0), target: path, + faces: None, }), cmd_id: random_id(), }); From d96cd6e6143b035740e82a00d63ebcc09ffb027a Mon Sep 17 00:00:00 2001 From: benjamaan476 Date: Mon, 16 Dec 2024 11:51:31 +0900 Subject: [PATCH 2/2] AddHoleFromOffset --- modeling-cmds/src/def_enum.rs | 9 +++++++++ modeling-cmds/src/ok_response.rs | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/modeling-cmds/src/def_enum.rs b/modeling-cmds/src/def_enum.rs index 64adf73f..90f93699 100644 --- a/modeling-cmds/src/def_enum.rs +++ b/modeling-cmds/src/def_enum.rs @@ -1190,6 +1190,15 @@ define_modeling_cmd_enum! { /// The distance to offset the path (positive for outset, negative for inset) pub offset: LengthUnit, } + + /// Add a hole to a closed path by offsetting it a uniform distance inward. + #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize, ModelingCmdVariant)] + pub struct AddHoleFromOffset { + /// The closed path to add a hole to. + pub object_id: Uuid, + /// The distance to offset the path (positive for outset, negative for inset) + pub offset: LengthUnit, + } } } diff --git a/modeling-cmds/src/ok_response.rs b/modeling-cmds/src/ok_response.rs index 659f0633..25fe3b85 100644 --- a/modeling-cmds/src/ok_response.rs +++ b/modeling-cmds/src/ok_response.rs @@ -435,6 +435,16 @@ define_ok_modeling_cmd_response_enum! { pub entity_ids: Vec, } + /// The response from the `AddHoleFromOffset` command. + #[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, ModelingCmdOutput)] + pub struct AddHoleFromOffset { + /// If the offset path splits into multiple paths, this will contain the UUIDs of the + /// new paths. + /// If the offset path remains as a single path, this will be empty, and the resulting ID + /// of the (single) new path will be the ID of the `AddHoleFromOffset` command. + pub entity_ids: Vec, + } + /// The response from the `DefaultCameraFocusOn` command. #[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, ModelingCmdOutput)] pub struct DefaultCameraFocusOn { }