SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Sketch on a face: project from the model's own body, not a copy that meshes it again (#3981)
bherbruck08eff4f9dd55
diff --git a/crates/doc/src/anchor_frame.rs b/crates/doc/src/anchor_frame.rsindex 9b7e7b682c..e58fda5c22 100644--- a/crates/doc/src/anchor_frame.rs+++ b/crates/doc/src/anchor_frame.rs@@ -7,8 +7,13 @@ pub fn state_in_face_anchor_frame<'a>(doc: &Document, state: &'a ModelState, anclet raw = state.body(&anchor.target.body).ok_or_else(|| DocError::Unknown(format!("anchored body `{}`", anchor.target.body)))?;let relative = anchor.source_to_author(doc, author, raw)?;let mut output = crate::state_in_frame_at(doc, state, author, frame).into_owned();- let shape = if crate::is_identity(&relative) { raw.body.clone() } else { solidcraft_kernel::transform_matrix(&raw.body, relative)? };- let mut body = ModelBody::new(raw.name.clone(), shape, raw.feature);+ // In place, the body is the model's own, display mesh included: a sketch projecting the+ // face's edges meshes it once for the features after it too, rather than a copy.+ let mut body = if crate::is_identity(&relative) {+ raw.clone()+ } else {+ ModelBody::new(raw.name.clone(), solidcraft_kernel::transform_matrix(&raw.body, relative)?, raw.feature)+ };body.component = raw.component;body.transferred = raw.transferred;body.source_name = raw.source_name.clone();diff --git a/crates/engine/src/cmd/sketch_face_tests.rs b/crates/engine/src/cmd/sketch_face_tests.rsindex 23ee3ee471..c21ba0739f 100644--- a/crates/engine/src/cmd/sketch_face_tests.rs+++ b/crates/engine/src/cmd/sketch_face_tests.rs@@ -723,3 +723,17 @@ fn a_custom_plane_origin_that_is_not_numbers_is_refused_not_zeroed() {assert_eq!(origin_of(&mut s, json!({"origin": [20, 0, 0], "x_dir": [0, 1, 0], "y_dir": [0, 0, 1]})), json!([20.0, 0.0, 0.0]));assert_eq!(origin_of(&mut s, json!({"x_dir": [0, 1, 0], "y_dir": [0, 0, 1]})), json!([0.0, 0.0, 0.0]));}+/// A sketch on a body's face projects that face's edges from the body's display mesh. The body+/// it projects from is the model's own, not a copy that meshes it again: on a body whose curved+/// edges are slow to mesh, the copy's mesh was thrown away and the next feature meshed the body+/// a second time, which made a sketch on a face as slow as a cut.+#[test]+fn a_sketch_on_a_face_meshes_its_body_once() {+ let mut s = Session::default();+ run(&mut s, "solid.box", json!({"length":10,"width":10,"height":10,"body_name":"Base","name":"BaseFeature"}));+ assert!(s.model.state().body("Base").unwrap().cached_mesh().is_none());+ let pick = top_pick(&s, "Base");+ run(&mut s, "sketch.create", json!({"name":"Attached","plane":pick}));+ run(&mut s, "sketch.finish", json!({}));+ assert!(s.model.state().body("Base").unwrap().cached_mesh().is_some(), "the sketch's projection meshed a copy of the body");+}