Extrude bug (#2986)
* fix bug Signed-off-by: Jess Frazelle <github@jessfraz.com> * images Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * docs Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> * docs Signed-off-by: Jess Frazelle <github@jessfraz.com> --------- Signed-off-by: Jess Frazelle <github@jessfraz.com>
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						@ -58,3 +58,5 @@ src/wasm-lib/grackle/stdlib_cube_partial.json
 | 
			
		||||
Mac_App_Distribution.provisionprofile
 | 
			
		||||
 | 
			
		||||
*.tsbuildinfo
 | 
			
		||||
 | 
			
		||||
venv
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										2
									
								
								src/wasm-lib/Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						@ -1385,7 +1385,7 @@ dependencies = [
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "kcl-lib"
 | 
			
		||||
version = "0.1.71"
 | 
			
		||||
version = "0.1.72"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "anyhow",
 | 
			
		||||
 "approx",
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,7 @@
 | 
			
		||||
[package]
 | 
			
		||||
name = "kcl-lib"
 | 
			
		||||
description = "KittyCAD Language implementation and tools"
 | 
			
		||||
version = "0.1.71"
 | 
			
		||||
version = "0.1.72"
 | 
			
		||||
edition = "2021"
 | 
			
		||||
license = "MIT"
 | 
			
		||||
repository = "https://github.com/KittyCAD/modeling-app"
 | 
			
		||||
 | 
			
		||||
@ -77,14 +77,24 @@ async fn inner_extrude(length: f64, sketch_group_set: SketchGroupSet, args: Args
 | 
			
		||||
    let sketch_groups: Vec<Box<SketchGroup>> = sketch_group_set.into();
 | 
			
		||||
    let mut extrude_groups = Vec::new();
 | 
			
		||||
    for sketch_group in &sketch_groups {
 | 
			
		||||
        // Make sure we exited sketch mode if sketching on a plane.
 | 
			
		||||
        if let SketchSurface::Plane(_) = sketch_group.on {
 | 
			
		||||
            // Disable the sketch mode.
 | 
			
		||||
            // This is necessary for when people don't close the sketch explicitly.
 | 
			
		||||
            // The sketch mode will mess up the extrude direction if still active.
 | 
			
		||||
            args.batch_modeling_cmd(uuid::Uuid::new_v4(), kittycad::types::ModelingCmd::SketchModeDisable {})
 | 
			
		||||
        // Before we extrude, we need to enable the sketch mode.
 | 
			
		||||
        // We do this here in case extrude is called out of order.
 | 
			
		||||
        args.batch_modeling_cmd(
 | 
			
		||||
            uuid::Uuid::new_v4(),
 | 
			
		||||
            kittycad::types::ModelingCmd::EnableSketchMode {
 | 
			
		||||
                animated: false,
 | 
			
		||||
                ortho: false,
 | 
			
		||||
                entity_id: sketch_group.on.id(),
 | 
			
		||||
                adjust_camera: false,
 | 
			
		||||
                planar_normal: if let SketchSurface::Plane(plane) = &sketch_group.on {
 | 
			
		||||
                    // We pass in the normal for the plane here.
 | 
			
		||||
                    Some(plane.z_axis.clone().into())
 | 
			
		||||
                } else {
 | 
			
		||||
                    None
 | 
			
		||||
                },
 | 
			
		||||
            },
 | 
			
		||||
        )
 | 
			
		||||
        .await?;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        args.send_modeling_cmd(
 | 
			
		||||
            id,
 | 
			
		||||
@ -95,6 +105,10 @@ async fn inner_extrude(length: f64, sketch_group_set: SketchGroupSet, args: Args
 | 
			
		||||
            },
 | 
			
		||||
        )
 | 
			
		||||
        .await?;
 | 
			
		||||
 | 
			
		||||
        // Disable the sketch mode.
 | 
			
		||||
        args.batch_modeling_cmd(uuid::Uuid::new_v4(), kittycad::types::ModelingCmd::SketchModeDisable {})
 | 
			
		||||
            .await?;
 | 
			
		||||
        extrude_groups.push(do_post_extrude(sketch_group.clone(), length, id, args.clone()).await?);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -107,13 +121,6 @@ pub(crate) async fn do_post_extrude(
 | 
			
		||||
    id: Uuid,
 | 
			
		||||
    args: Args,
 | 
			
		||||
) -> Result<Box<ExtrudeGroup>, KclError> {
 | 
			
		||||
    // We need to do this after extrude for sketch on face.
 | 
			
		||||
    if let SketchSurface::Face(_) = sketch_group.on {
 | 
			
		||||
        // Disable the sketch mode.
 | 
			
		||||
        args.batch_modeling_cmd(uuid::Uuid::new_v4(), kittycad::types::ModelingCmd::SketchModeDisable {})
 | 
			
		||||
            .await?;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Bring the object to the front of the scene.
 | 
			
		||||
    // See: https://github.com/KittyCAD/modeling-app/issues/806
 | 
			
		||||
    args.batch_modeling_cmd(
 | 
			
		||||
 | 
			
		||||
| 
		 Before Width: | Height: | Size: 114 KiB After Width: | Height: | Size: 132 KiB  | 
| 
		 Before Width: | Height: | Size: 139 KiB After Width: | Height: | Size: 139 KiB  | 
| 
		 Before Width: | Height: | Size: 167 KiB After Width: | Height: | Size: 167 KiB  | 
| 
		 Before Width: | Height: | Size: 168 KiB After Width: | Height: | Size: 168 KiB  | 
							
								
								
									
										29
									
								
								src/wasm-lib/tests/executor/inputs/extrude-custom-plane.kcl
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -0,0 +1,29 @@
 | 
			
		||||
// create a sketch with name sketch000
 | 
			
		||||
const sketch000 = startSketchOn('XY')
 | 
			
		||||
  |> startProfileAt([0.0, 0.0], %)
 | 
			
		||||
  |> line([1.0, 1.0], %, $line000)
 | 
			
		||||
  |> line([0.0, -1.0], %, $line001)
 | 
			
		||||
  |> line([-1.0, 0.0], %, $line002)
 | 
			
		||||
 | 
			
		||||
// create an extrusion with name extrude000
 | 
			
		||||
const extrude000 = extrude(1.0, sketch000)
 | 
			
		||||
 | 
			
		||||
// define a plane with name plane005
 | 
			
		||||
const plane005 = {
 | 
			
		||||
  plane: {
 | 
			
		||||
    origin: [0.0, 0.0, 1.0],
 | 
			
		||||
    x_axis: [0.707107, 0.707107, 0.0],
 | 
			
		||||
    y_axis: [-0.0, 0.0, 1.0],
 | 
			
		||||
    z_axis: [0.707107, -0.707107, 0.0]
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// create a sketch with name sketch001
 | 
			
		||||
const sketch001 = startSketchOn(plane005)
 | 
			
		||||
  |> startProfileAt([0.100000, 0.250000], %)
 | 
			
		||||
  |> line([0.075545, 0.494260], %, $line003)
 | 
			
		||||
  |> line([0.741390, -0.113317], %, $line004)
 | 
			
		||||
  |> line([-0.816935, -0.380943], %, $line005)
 | 
			
		||||
 | 
			
		||||
// create an extrusion with name extrude001
 | 
			
		||||
const extrude001 = extrude(1.0, sketch001)
 | 
			
		||||
@ -2501,3 +2501,10 @@ async fn serial_test_order_sketch_extrude_out_of_order() {
 | 
			
		||||
        0.999,
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[tokio::test(flavor = "multi_thread")]
 | 
			
		||||
async fn serial_test_extrude_custom_plane() {
 | 
			
		||||
    let code = include_str!("inputs/extrude-custom-plane.kcl");
 | 
			
		||||
    let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap();
 | 
			
		||||
    twenty_twenty::assert_image("tests/executor/outputs/extrude-custom-plane.png", &result, 0.999);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								src/wasm-lib/tests/executor/outputs/extrude-custom-plane.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 120 KiB  | 
| 
		 Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 27 KiB  | 
| 
		 Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 26 KiB  | 
| 
		 Before Width: | Height: | Size: 141 KiB After Width: | Height: | Size: 142 KiB  | 
| 
		 Before Width: | Height: | Size: 150 KiB After Width: | Height: | Size: 150 KiB  | 
| 
		 Before Width: | Height: | Size: 167 KiB After Width: | Height: | Size: 167 KiB  | 
| 
		 Before Width: | Height: | Size: 168 KiB After Width: | Height: | Size: 168 KiB  | 
| 
		 Before Width: | Height: | Size: 104 KiB After Width: | Height: | Size: 102 KiB  | 
| 
		 Before Width: | Height: | Size: 104 KiB After Width: | Height: | Size: 102 KiB  | 
| 
		 Before Width: | Height: | Size: 104 KiB After Width: | Height: | Size: 102 KiB  |