WIP: working Solid3dGetExtrusionFaceInfo for loft
This commit is contained in:
		| @ -84,6 +84,11 @@ | ||||
|     "title": "Hex nut", | ||||
|     "description": "A hex nut is a type of fastener with a threaded hole and a hexagonal outer shape, used in a wide variety of applications to secure parts together. The hexagonal shape allows for a greater torque to be applied with wrenches or tools, making it one of the most common nut types in hardware." | ||||
|   }, | ||||
|   { | ||||
|     "file": "i-beam.kcl", | ||||
|     "title": "I-beam", | ||||
|     "description": "A structural metal beam with an I shaped cross section. Often used in construction" | ||||
|   }, | ||||
|   { | ||||
|     "file": "kitt.kcl", | ||||
|     "title": "Kitt", | ||||
|  | ||||
| @ -373,32 +373,49 @@ export function getArtifactsToUpdate({ | ||||
|         }) | ||||
|     } | ||||
|     return returnArr | ||||
|   } else if ( | ||||
|     cmd.type === 'extrude' || | ||||
|     cmd.type === 'revolve' || | ||||
|     cmd.type === 'loft' | ||||
|   ) { | ||||
|   } else if (cmd.type === 'extrude' || cmd.type === 'revolve') { | ||||
|     const subType = cmd.type === 'extrude' ? 'extrusion' : cmd.type | ||||
|     const extrudeOrRevolve = cmd.type === 'extrude' || cmd.type === 'revolve' | ||||
|     console.log('Solid3dGetExtrusionFaceInfo response.data', response.data) | ||||
|     returnArr.push({ | ||||
|       id, | ||||
|       artifact: { | ||||
|         type: 'sweep', | ||||
|         subType: subType, | ||||
|         id, | ||||
|         // TODO: check what is needed here with target for loft | ||||
|         pathId: extrudeOrRevolve ? cmd.target : cmd.section_ids[0], | ||||
|         pathId: cmd.target, | ||||
|         surfaceIds: [], | ||||
|         edgeIds: [], | ||||
|         codeRef: { range, pathToNode }, | ||||
|       }, | ||||
|     }) | ||||
|     if (extrudeOrRevolve) { | ||||
|       const path = getArtifact(cmd.target) | ||||
|     const path = getArtifact(cmd.target) | ||||
|     if (path?.type === 'path') | ||||
|       returnArr.push({ | ||||
|         id: cmd.target, | ||||
|         artifact: { ...path, sweepId: id }, | ||||
|       }) | ||||
|     return returnArr | ||||
|   } else if ( | ||||
|     cmd.type === 'loft' && | ||||
|     response.type === 'modeling' && | ||||
|     response.data.modeling_response.type === 'loft' | ||||
|   ) { | ||||
|     returnArr.push({ | ||||
|       id, | ||||
|       artifact: { | ||||
|         type: 'sweep', | ||||
|         subType: 'loft', | ||||
|         id, | ||||
|         pathId: response.data.modeling_response.data.solid_id, | ||||
|         surfaceIds: [], | ||||
|         edgeIds: [], | ||||
|         codeRef: { range, pathToNode }, | ||||
|       }, | ||||
|     }) | ||||
|     for (const sectionId of cmd.section_ids) { | ||||
|       const path = getArtifact(sectionId) | ||||
|       if (path?.type === 'path') | ||||
|         returnArr.push({ | ||||
|           id: cmd.target, | ||||
|           id: sectionId, | ||||
|           artifact: { ...path, sweepId: id }, | ||||
|         }) | ||||
|     } | ||||
|  | ||||
| @ -125,7 +125,7 @@ async fn inner_extrude( | ||||
|             ModelingCmd::SketchModeDisable(mcmd::SketchModeDisable {}), | ||||
|         ) | ||||
|         .await?; | ||||
|         solids.push(do_post_extrude(sketch.clone(), length, exec_state, args.clone()).await?); | ||||
|         solids.push(do_post_extrude(sketch.clone(), length, exec_state, args.clone(), None).await?); | ||||
|     } | ||||
|  | ||||
|     Ok(solids.into()) | ||||
| @ -136,6 +136,7 @@ pub(crate) async fn do_post_extrude( | ||||
|     length: f64, | ||||
|     exec_state: &mut ExecState, | ||||
|     args: Args, | ||||
|     force_object_id: Option<Uuid>, | ||||
| ) -> Result<Box<Solid>, KclError> { | ||||
|     // Bring the object to the front of the scene. | ||||
|     // See: https://github.com/KittyCAD/modeling-app/issues/806 | ||||
| @ -163,14 +164,16 @@ pub(crate) async fn do_post_extrude( | ||||
|         sketch.id = face.solid.sketch.id; | ||||
|     } | ||||
|  | ||||
|     let object_id = force_object_id.unwrap_or(sketch.id); | ||||
|  | ||||
|     #[cfg(target_arch = "wasm32")] | ||||
|     web_sys::console::log_1(&format!("Rust Solid3dGetExtrusionFaceInfo cmd edge_id={:?} object_id={:?}", any_edge_id, sketch.id).into()); | ||||
|     web_sys::console::log_1(&format!("Rust Solid3dGetExtrusionFaceInfo cmd edge_id={:?} object_id={:?}", any_edge_id, object_id).into()); | ||||
|     let solid3d_info = args | ||||
|         .send_modeling_cmd( | ||||
|             exec_state.next_uuid(), | ||||
|             ModelingCmd::from(mcmd::Solid3dGetExtrusionFaceInfo { | ||||
|                 edge_id: any_edge_id, | ||||
|                 object_id: sketch.id, | ||||
|                 object_id: object_id, | ||||
|             }), | ||||
|         ) | ||||
|         .await?; | ||||
|  | ||||
| @ -4,7 +4,10 @@ use std::num::NonZeroU32; | ||||
|  | ||||
| use anyhow::Result; | ||||
| use derive_docs::stdlib; | ||||
| use kcmc::{each_cmd as mcmd, length_unit::LengthUnit, ModelingCmd}; | ||||
| use kcmc::{ | ||||
|     each_cmd as mcmd, length_unit::LengthUnit, ok_response::OkModelingCmdResponse, websocket::OkWebSocketResponseData, | ||||
|     ModelingCmd, | ||||
| }; | ||||
| use kittycad_modeling_cmds as kcmc; | ||||
|  | ||||
| use crate::{ | ||||
| @ -142,19 +145,32 @@ async fn inner_loft( | ||||
|         })); | ||||
|     } | ||||
|  | ||||
|     let id = exec_state.next_uuid(); | ||||
|     args.batch_modeling_cmd( | ||||
|         id, | ||||
|         ModelingCmd::from(mcmd::Loft { | ||||
|             section_ids: sketches.iter().map(|group| group.id).collect(), | ||||
|             base_curve_index, | ||||
|             bez_approximate_rational, | ||||
|             tolerance: LengthUnit(tolerance.unwrap_or(default_tolerance(&args.ctx.settings.units))), | ||||
|             v_degree, | ||||
|         }), | ||||
|     ) | ||||
|     .await?; | ||||
|     let id: uuid::Uuid = exec_state.next_uuid(); | ||||
|     let resp = args | ||||
|         .send_modeling_cmd( | ||||
|             id, | ||||
|             ModelingCmd::from(mcmd::Loft { | ||||
|                 section_ids: sketches.iter().map(|group| group.id).collect(), | ||||
|                 base_curve_index, | ||||
|                 bez_approximate_rational, | ||||
|                 tolerance: LengthUnit(tolerance.unwrap_or(default_tolerance(&args.ctx.settings.units))), | ||||
|                 v_degree, | ||||
|             }), | ||||
|         ) | ||||
|         .await?; | ||||
|     let OkWebSocketResponseData::Modeling { | ||||
|         modeling_response: OkModelingCmdResponse::Loft(data), | ||||
|     } = &resp | ||||
|     else { | ||||
|         return Err(KclError::Engine(KclErrorDetails { | ||||
|             message: format!("mcmd::Loft response was not as expected: {:?}", resp), | ||||
|             source_ranges: vec![args.source_range], | ||||
|         })); | ||||
|     }; | ||||
|  | ||||
|     #[cfg(target_arch = "wasm32")] | ||||
|     web_sys::console::log_1(&format!("Rust Loft solid_id={:?}", data.solid_id).into()); | ||||
|  | ||||
|     // Using the first sketch as the base curve, idk we might want to change this later. | ||||
|     do_post_extrude(sketches[0].clone(), 0.0, exec_state, args).await | ||||
|     do_post_extrude(sketches[0].clone(), 0.0, exec_state, args, Some(data.solid_id)).await | ||||
| } | ||||
|  | ||||
| @ -296,7 +296,7 @@ async fn inner_revolve( | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     do_post_extrude(sketch, 0.0, exec_state, args).await | ||||
|     do_post_extrude(sketch, 0.0, exec_state, args, None).await | ||||
| } | ||||
|  | ||||
| #[cfg(test)] | ||||
|  | ||||
| @ -99,5 +99,5 @@ async fn inner_sweep( | ||||
|     ) | ||||
|     .await?; | ||||
|  | ||||
|     do_post_extrude(sketch, 0.0, exec_state, args).await | ||||
|     do_post_extrude(sketch, 0.0, exec_state, args, None).await | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user