From 3ad5a360f27e246908cfb663ffecb582bd5ff67d Mon Sep 17 00:00:00 2001 From: Jackson Oursland Date: Tue, 27 Oct 2026 03:40:29 +0000 Subject: [PATCH] Engine: keep the model and placed world across appearance-only edits (#7396) Evaluation and placement never read appearances, yet an appearance edit re-evaluated the model and placed every occurrence again. A whole-document proof that only appearances changed now takes the existing render-only refresh, which keeps the model and retargets the world-placement cache. Co-authored-by: Claude Opus 5.5 (1M context) --- crates/doc/src/appearance.rs | 15 +++++++++++++++ crates/doc/src/document.rs | 12 ++++++++++++ crates/engine/src/lib.rs | 8 +++++--- crates/engine/src/world_placement_cache_tests.rs | 11 ++++++++--- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/crates/doc/src/appearance.rs b/crates/doc/src/appearance.rs index 9298178a0..756913ad8 100644 --- a/crates/doc/src/appearance.rs +++ b/crates/doc/src/appearance.rs @@ -324,6 +324,21 @@ pub(crate) fn closest_on_triangle(p: Vec3, a: Vec3, b: Vec3, c: Vec3) -> Vec3 { mod tests { use super::*; + /// Only an appearance change is appearance-only: with any other field changed too, or with + /// nothing changed, the model must be evaluated as usual. + #[test] + fn appearance_only_changes_are_proved_on_the_whole_document() { + let before = crate::Document::default(); + let mut painted = before.clone(); + painted.appearances.bodies.insert("Body1".into(), Look::custom([255, 0, 0], 0.5)); + assert!(painted.differs_only_in_appearance(&before)); + assert!(before.differs_only_in_appearance(&painted), "clearing it too"); + assert!(!before.differs_only_in_appearance(&before.clone()), "nothing changed"); + let mut mixed = painted.clone(); + mixed.materials.insert("Body1".into(), "Steel".into()); + assert!(!mixed.differs_only_in_appearance(&before), "a material change is not appearance-only"); + } + #[test] fn library_and_materials() { assert_eq!(library("abs - red").map(|l| l.color), Some([196, 40, 40])); diff --git a/crates/doc/src/document.rs b/crates/doc/src/document.rs index 9004f3cf4..f04a25b06 100644 --- a/crates/doc/src/document.rs +++ b/crates/doc/src/document.rs @@ -3104,6 +3104,18 @@ impl Document { Some(out) } + /// Only appearances (body, face and component looks) changed: evaluation never reads them, so + /// the model and its placed world stay valid. The same whole-Document proof as + /// [`Document::differs_only_in_render`]. + pub fn differs_only_in_appearance(&self, previous: &Document) -> bool { + if self.appearances == previous.appearances { + return false; + } + let mut normalized = previous.clone(); + normalized.appearances = self.appearances.clone(); + *self == normalized + } + /// The colour a body is shown and exported in (sRGB as 0–1 fractions): its appearance, /// else its component's, else its material's look, else the colour it was imported with. /// (Faces may have their own: `face_looks`.) diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index e9824c440..a80d69d2a 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -994,12 +994,14 @@ impl Session { } } - /// Only persistent render intent, or only part properties, changed. Never evaluate or clear - /// a stale model here. + /// Only persistent render intent, part properties or appearances changed. Never evaluate or + /// clear a stale model here. fn render_only_change(&self, before: &Snapshot) -> bool { self.active_sketch == before.active_sketch && self.pending_moves == before.pending_moves - && (self.doc.differs_only_in_render(&before.doc) || self.doc.differs_only_in_part_properties(&before.doc)) + && (self.doc.differs_only_in_render(&before.doc) + || self.doc.differs_only_in_part_properties(&before.doc) + || self.doc.differs_only_in_appearance(&before.doc)) } /// Only what is hidden or shown changed (`browser.visibility`): the document and the model diff --git a/crates/engine/src/world_placement_cache_tests.rs b/crates/engine/src/world_placement_cache_tests.rs index 5c6457cfc..9c736b7fb 100644 --- a/crates/engine/src/world_placement_cache_tests.rs +++ b/crates/engine/src/world_placement_cache_tests.rs @@ -116,16 +116,21 @@ fn world_cache_requires_exact_design_model_pending_and_author_context() { assert!(!Arc::ptr_eq(&authored, &scratch_world)); assert!(scratch_world.sketch(sketch).unwrap().plane.origin.dist(Vec3::ZERO) < 1e-9); assert!(Arc::ptr_eq(&authored, &session.world_state()), "scratch context must not replace the source cache"); + // Evaluation and placement never read appearances: an appearance edit, its undo and its redo + // keep the evaluated model and the placed world (the cache follows the new document). + let model = session.model.state(); run(&mut session, "appearance.assign", json!({"bodies":["Block"],"color":"#ff0000"})); let painted = session.world_state(); - assert!(!Arc::ptr_eq(&authored, &painted)); + assert!(Arc::ptr_eq(&authored, &painted), "an appearance edit keeps the placed world"); + assert!(Arc::ptr_eq(&model, &session.model.state()), "and the evaluated model"); assert_ne!(session.doc.model_body_look(painted.body("Block").unwrap()), None); run(&mut session, "edit.undo", json!({})); let undone = session.world_state(); - assert!(!Arc::ptr_eq(&painted, &undone)); + assert!(Arc::ptr_eq(&painted, &undone), "undoing it too"); + assert_eq!(session.doc.model_body_look(undone.body("Block").unwrap()), None); run(&mut session, "edit.redo", json!({})); let redone = session.world_state(); - assert!(!Arc::ptr_eq(&undone, &redone)); + assert!(Arc::ptr_eq(&undone, &redone), "and redoing it"); assert!(session.doc.model_body_look(redone.body("Block").unwrap()).is_some()); let before_edit = session.world_state(); run(&mut session, "solid.box", json!({"length":5,"width":6,"height":7,"body_name":"Other","operation":"new"}));