From 08eff4f9dd55a65c7cdbf2c1913f9a2dea805a92 Mon Sep 17 00:00:00 2001 From: bherbruck Date: Tue, 20 Oct 2026 23:02:22 -0400 Subject: [PATCH] Sketch on a face: project from the model's own body, not a copy that meshes it again (#3981) A sketch attached to a face is evaluated in the face's frame. When that frame is the body's own, the body was still rebuilt as a new ModelBody with empty mesh cells, so projecting the face's edges display-meshed a throwaway copy and the next cut or join meshed the same body a second time. On a body whose cut edges are slow to mesh this added about a second to each feature after a sketch on a face. In place, the anchored body is now the model's own clone and shares its mesh. Co-authored-by: Claude Opus 5.5 --- crates/doc/src/anchor_frame.rs | 9 +++++++-- crates/engine/src/cmd/sketch_face_tests.rs | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/crates/doc/src/anchor_frame.rs b/crates/doc/src/anchor_frame.rs index 9b7e7b682..e58fda5c2 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, anc let 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.rs index 23ee3ee47..c21ba0739 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"); +}