From e3458a4733df876d84d4c644bce6766882e64c37 Mon Sep 17 00:00:00 2001 From: Jess Frazelle Date: Thu, 12 Sep 2024 13:51:40 -0700 Subject: [PATCH] updates Signed-off-by: Jess Frazelle --- src/wasm-lib/kcl/src/std/patterns.rs | 50 +++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/wasm-lib/kcl/src/std/patterns.rs b/src/wasm-lib/kcl/src/std/patterns.rs index ccc49d3d66..33c6bb8394 100644 --- a/src/wasm-lib/kcl/src/std/patterns.rs +++ b/src/wasm-lib/kcl/src/std/patterns.rs @@ -10,7 +10,7 @@ use crate::{ errors::{KclError, KclErrorDetails}, executor::{ ExtrudeGroup, ExtrudeGroupSet, Geometries, Geometry, KclValue, Point3d, SketchGroup, SketchGroupSet, - SourceRange, UserVal, + SketchSurface, SourceRange, UserVal, }, function_param::FunctionParam, std::{types::Uint, Args}, @@ -475,6 +475,26 @@ async fn inner_pattern_linear_3d( let mut extrude_groups = Vec::new(); for extrude_group in starting_extrude_groups.iter() { + // Before we pattern, we need to enable the sketch mode. + // We do this so if the user is patterning a sketch on a face, + // it patterns correctly. + args.batch_modeling_cmd( + uuid::Uuid::new_v4(), + kittycad::types::ModelingCmd::EnableSketchMode { + animated: false, + ortho: false, + entity_id: extrude_group.sketch_group.on.id(), + adjust_camera: false, + planar_normal: if let SketchSurface::Plane(plane) = &extrude_group.sketch_group.on { + // We pass in the normal for the plane here. + Some(plane.z_axis.into()) + } else { + None + }, + }, + ) + .await?; + let geometries = pattern_linear( LinearPattern::ThreeD(data.clone()), Geometry::ExtrudeGroup(extrude_group.clone()), @@ -482,6 +502,10 @@ async fn inner_pattern_linear_3d( ) .await?; + // Disable the sketch mode. + args.batch_modeling_cmd(uuid::Uuid::new_v4(), kittycad::types::ModelingCmd::SketchModeDisable {}) + .await?; + let Geometries::ExtrudeGroups(new_extrude_groups) = geometries else { return Err(KclError::Semantic(KclErrorDetails { message: "Expected a vec of extrude groups".to_string(), @@ -798,6 +822,26 @@ async fn inner_pattern_circular_3d( let mut extrude_groups = Vec::new(); for extrude_group in starting_extrude_groups.iter() { + // Before we pattern, we need to enable the sketch mode. + // We do this so if the user is patterning a sketch on a face, + // it patterns correctly. + args.batch_modeling_cmd( + uuid::Uuid::new_v4(), + kittycad::types::ModelingCmd::EnableSketchMode { + animated: false, + ortho: false, + entity_id: extrude_group.sketch_group.on.id(), + adjust_camera: false, + planar_normal: if let SketchSurface::Plane(plane) = &extrude_group.sketch_group.on { + // We pass in the normal for the plane here. + Some(plane.z_axis.into()) + } else { + None + }, + }, + ) + .await?; + let geometries = pattern_circular( CircularPattern::ThreeD(data.clone()), Geometry::ExtrudeGroup(extrude_group.clone()), @@ -805,6 +849,10 @@ async fn inner_pattern_circular_3d( ) .await?; + // Disable the sketch mode. + args.batch_modeling_cmd(uuid::Uuid::new_v4(), kittycad::types::ModelingCmd::SketchModeDisable {}) + .await?; + let Geometries::ExtrudeGroups(new_extrude_groups) = geometries else { return Err(KclError::Semantic(KclErrorDetails { message: "Expected a vec of extrude groups".to_string(),