Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Preview: new surface is tinted whatever its size, and the tints can be turned off (#9111) (#9112)

N3MI-DG38ae728538f5
diff --git a/assets/locales/pending/preview-tints.json b/assets/locales/pending/preview-tints.json
new file mode 100644
index 0000000000..86db8893b1
--- /dev/null
+++ b/assets/locales/pending/preview-tints.json
@@ -0,0 +1,50 @@
+{
+ "ar": {
+ "prefs.cut_preview_tint": "إظهار المادة المُزالة باللون الأحمر",
+ "prefs.cut_preview_tint_help": "تملأ المعاينة المادة التي تزيلها الميزة، والشكل الذي تستبدله، بطيف أحمر شبه شفاف. عند الإيقاف تكون هذه التعبئة شفافة تمامًا ولا تُرسم سوى مخططاتها.",
+ "prefs.preview_tint_new_faces": "تلوين السطح الجديد في المعاينة",
+ "prefs.preview_tint_new_faces_help": "يمكن لمعاينة ميزة تغيّر جسمًا أن ترسم السطح المضاف بلون المعاينة. عند الإيقاف يُرسم الجسم بلونه الأصلي."
+ },
+ "de": {
+ "prefs.cut_preview_tint": "Entferntes Material rot anzeigen",
+ "prefs.cut_preview_tint_help": "Eine Vorschau füllt das Material, das ein Feature entfernt, sowie die ersetzte Form mit einem roten, durchscheinenden Geist. Wenn deaktiviert, sind diese Füllungen völlig transparent und es werden nur ihre Umrisse gezeichnet.",
+ "prefs.preview_tint_new_faces": "Neue Fläche in der Vorschau einfärben",
+ "prefs.preview_tint_new_faces_help": "Eine Vorschau eines Features, das einen Körper ändert, kann die hinzugefügte Fläche in der Vorschaufarbe zeichnen. Wenn deaktiviert, wird der Körper wie er ist gezeichnet."
+ },
+ "en": {
+ "prefs.cut_preview_tint": "Show removed material in red",
+ "prefs.cut_preview_tint_help": "A preview fills the material a feature removes, and the shape it replaces, with a red see-through ghost. When off, those fills are fully transparent and only their outlines are drawn.",
+ "prefs.preview_tint_new_faces": "Tint new surface in a preview",
+ "prefs.preview_tint_new_faces_help": "A preview of a feature that changes a body can draw the surface it adds in the preview colour. When off, the body is drawn as itself."
+ },
+ "he": {
+ "prefs.cut_preview_tint": "הצגת חומר שהוסר באדום",
+ "prefs.cut_preview_tint_help": "תצוגה מקדימה ממלאת את החומר שהפעולה מסירה, ואת הצורה שהיא מחליפה, ברוח אדומה שקופה. כשהאפשרות כבויה המילויים האלה שקופים לחלוטין ומצוירים רק קווי המתאר שלהם.",
+ "prefs.preview_tint_new_faces": "צביעת משטח חדש בתצוגה מקדימה",
+ "prefs.preview_tint_new_faces_help": "תצוגה מקדימה של פעולה שמשנה גוף יכולה לצבוע את המשטח שנוסף בצבע התצוגה המקדימה. כשהאפשרות כבויה הגוף מצויר בצבעו שלו."
+ },
+ "ja": {
+ "prefs.cut_preview_tint": "除去される材料を赤で表示",
+ "prefs.cut_preview_tint_help": "プレビューでは、フィーチャーが除去する材料と置き換えられる形状を、赤い透過ゴーストで塗りつぶします。オフにすると、この塗りつぶしは完全に透明になり、輪郭のみが描画されます。",
+ "prefs.preview_tint_new_faces": "プレビューで新しい面に色を付ける",
+ "prefs.preview_tint_new_faces_help": "ボディを変更するフィーチャーのプレビューで、追加される面をプレビュー色で描画できます。オフにすると、ボディはそのままの色で描画されます。"
+ },
+ "ko": {
+ "prefs.cut_preview_tint": "제거되는 재료를 빨간색으로 표시",
+ "prefs.cut_preview_tint_help": "미리 보기는 피처가 제거하는 재료와 대체되는 형상을 빨간색 반투명 고스트로 채웁니다. 끄면 이 채움이 완전히 투명해지고 윤곽선만 그려집니다.",
+ "prefs.preview_tint_new_faces": "미리 보기에서 새 면에 색 입히기",
+ "prefs.preview_tint_new_faces_help": "바디를 변경하는 피처의 미리 보기에서 추가되는 면을 미리 보기 색으로 그릴 수 있습니다. 끄면 바디가 원래 색으로 그려집니다."
+ },
+ "vi": {
+ "prefs.cut_preview_tint": "Hiển thị vật liệu bị loại bỏ bằng màu đỏ",
+ "prefs.cut_preview_tint_help": "Bản xem trước tô vật liệu mà đặc trưng loại bỏ, và hình dạng mà nó thay thế, bằng một bóng mờ màu đỏ. Khi tắt, các phần tô này hoàn toàn trong suốt và chỉ vẽ đường viền của chúng.",
+ "prefs.preview_tint_new_faces": "Tô màu bề mặt mới trong bản xem trước",
+ "prefs.preview_tint_new_faces_help": "Bản xem trước của một đặc trưng làm thay đổi một khối có thể vẽ bề mặt được thêm vào bằng màu xem trước. Khi tắt, khối được vẽ bằng màu của chính nó."
+ },
+ "zh": {
+ "prefs.cut_preview_tint": "以红色显示被移除的材料",
+ "prefs.cut_preview_tint_help": "预览会用红色半透明幻影填充特征所移除的材料以及被替换的形状。关闭时,这些填充完全透明,仅绘制其轮廓。",
+ "prefs.preview_tint_new_faces": "在预览中为新表面着色",
+ "prefs.preview_tint_new_faces_help": "更改实体的特征,其预览可以用预览颜色绘制新增的表面。关闭时,实体按自身颜色绘制。"
+ }
+}
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index b97a244ea7..838c26b050 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -6774,7 +6774,16 @@ mod refused_ok_tests {
let preview = crate::preview::compute(
&app.session,
&commands,
- crate::preview::Colors { body: [1; 4], added: [2; 4], new_body: [3; 4], removed: [4; 4], edge: [5; 4], ghost: false },
+ crate::preview::Colors {
+ body: [1; 4],
+ added: [2; 4],
+ new_body: [3; 4],
+ removed: [4; 4],
+ edge: [5; 4],
+ ghost: false,
+ tint_new: true,
+ cut_tint: true,
+ },
)
.expect("the angled plane previews");
diff --git a/crates/ui-egui/src/dialogs_assembly_tests.rs b/crates/ui-egui/src/dialogs_assembly_tests.rs
index 07feadc53a..3931c4b6de 100644
--- a/crates/ui-egui/src/dialogs_assembly_tests.rs
+++ b/crates/ui-egui/src/dialogs_assembly_tests.rs
@@ -167,6 +167,8 @@ fn joint_and_drive_preview_on_the_placed_model() {
removed: [3, 3, 3, 100],
edge: [0, 0, 0, 255],
ghost: true,
+ tint_new: true,
+ cut_tint: true,
};
let cmds = preview_commands(&app, &d).unwrap();
let b = world_preview(&app.session, &cmds, colors).unwrap().unwrap();
@@ -871,6 +873,8 @@ fn drive_says_where_a_loop_stopped_it() {
removed: [3, 3, 3, 100],
edge: [0, 0, 0, 255],
ghost: true,
+ tint_new: true,
+ cut_tint: true,
};
let rocker = app.session.doc.assembly.joints.iter().position(|j| j.name == "Rocker").unwrap();
let mut d = drive_joint(&app, app.session.doc.assembly.joints[rocker].id).unwrap();
@@ -931,6 +935,8 @@ fn drive_says_when_its_joint_is_joined_to_nothing_grounded() {
removed: [3, 3, 3, 100],
edge: [0, 0, 0, 255],
ghost: true,
+ tint_new: true,
+ cut_tint: true,
};
let b = world_preview(&app.session, &apply_commands(&app, &d).unwrap(), colors).unwrap().unwrap();
let why = b.stopped.as_ref().and_then(drive_stop).unwrap();
diff --git a/crates/ui-egui/src/extrude_preview.rs b/crates/ui-egui/src/extrude_preview.rs
index 227daa4bbe..e21182941d 100644
--- a/crates/ui-egui/src/extrude_preview.rs
+++ b/crates/ui-egui/src/extrude_preview.rs
@@ -115,6 +115,10 @@ impl StraightPreview {
let color = scene.color(color);
let cut_edge = scene.color(cut_edge);
let triangle = |scene: &mut GpuScene, points: [Vec3; 3], normal: Vec3| {
+ // Removed material the preference leaves fully transparent: only the cut's outline.
+ if operation == "cut" && !colors.cut_tint {
+ return;
+ }
for point in points {
if matches!(operation, "cut" | "intersect") {
scene.xray_tri(point.to_f32(), normal.to_f32(), color);
diff --git a/crates/ui-egui/src/move_preview.rs b/crates/ui-egui/src/move_preview.rs
index f66ba782dd..76a8ac2a64 100644
--- a/crates/ui-egui/src/move_preview.rs
+++ b/crates/ui-egui/src/move_preview.rs
@@ -95,7 +95,7 @@ impl MovePreview {
let mut bounds = Aabb3::EMPTY;
for mesh in &cache.meshes {
draw(&mut scene, mesh, &m, colors, &mut bounds);
- if !copy {
+ if !copy && colors.cut_tint {
// Where the body was, as the scratch-design preview shows a body moved away.
for t in &mesh.triangles {
for k in t {
@@ -119,9 +119,11 @@ impl MovePreview {
}
}
-/// `mesh` moved by `m`, in the colour of geometry the feature adds, with its shaded edges.
+/// `mesh` moved by `m`, in the colour of geometry the feature adds, or the body's own where
+/// the preference leaves new surface untinted (a move makes none either way), with its shaded
+/// edges.
fn draw(scene: &mut GpuScene, mesh: &Mesh, m: &Mat, colors: Colors, bounds: &mut Aabb3) {
- let added = scene.color(colors.added);
+ let added = scene.color(if colors.tint_new { colors.added } else { colors.body });
for t in &mesh.triangles {
for k in t {
let i = *k as usize;
diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs
index b8efe27b9c..d64c99ee9a 100644
--- a/crates/ui-egui/src/prefs.rs
+++ b/crates/ui-egui/src/prefs.rs
@@ -1102,6 +1102,13 @@ preference_settings! {
/// A small dot at every vertex wherever edges are drawn (#7834). Off by default: the viewport
/// draws edges only, as it always has.
vertex_markers: bool = false => check("Vertex markers", "Show a small dot at every vertex wherever edges are drawn");
+ /// A preview of a feature that changes a body draws the surface it adds in the preview
+ /// colour, working out face by face which surface that is. Off: the body is drawn as itself
+ /// and nothing is worked out (`preview::Colors::tint_new`).
+ preview_tint_new_faces: bool = true, PAGE_GRAPHICS => check_id("prefs.preview_tint_new_faces");
+ /// A preview that removes material shows the removed shape as a red see-through ghost. Off:
+ /// the ghost is fully transparent and only its outline is drawn (`preview::Colors::cut_tint`).
+ cut_preview_tint: bool = true, PAGE_GRAPHICS => check_id("prefs.cut_preview_tint");
/// Restore the previous platform-specific fixed Render preview geometry budget.
render_previous_geometry_budget: bool = false, PAGE_GRAPHICS => check_id("prefs.render_previous_geometry_budget");
/// How finely the viewport tessellates curved faces and edges: `coarse`, `normal`, `fine` or
diff --git a/crates/ui-egui/src/prefs/graphics.rs b/crates/ui-egui/src/prefs/graphics.rs
index d4d42d4361..5b551dda1c 100644
--- a/crates/ui-egui/src/prefs/graphics.rs
+++ b/crates/ui-egui/src/prefs/graphics.rs
@@ -181,6 +181,10 @@ pub(super) fn show(app: &mut SolveApp, ui: &mut egui::Ui) {
});
crate::prefs::view_angles_checkbox(app, left);
setting::reference_geometry_through_bodies(app, left).on_hover_text(app.tr("settings.reference_geometry_through_bodies_help"));
+ let tint_new = setting::preview_tint_new_faces(app, left).on_hover_text(app.tr("prefs.preview_tint_new_faces_help"));
+ crate::scenario::publish_target("prefs:preview_tint_new_faces", tint_new.rect);
+ let cut_tint = setting::cut_preview_tint(app, left).on_hover_text(app.tr("prefs.cut_preview_tint_help"));
+ crate::scenario::publish_target("prefs:cut_preview_tint", cut_tint.rect);
setting::sketch_halo(app, left);
setting::vertex_markers(app, left);
}
diff --git a/crates/ui-egui/src/preview.rs b/crates/ui-egui/src/preview.rs
index be5ffd4076..7ff05ada13 100644
--- a/crates/ui-egui/src/preview.rs
+++ b/crates/ui-egui/src/preview.rs
@@ -1,9 +1,10 @@
//! Live operation previews. While a feature dialog is open, its commands are evaluated on a
//! scratch copy of the session ([`solidcraft_engine::Session::preview`]), off the UI thread
//! where threads exist, and the result is drawn in place of the bodies it changes: new surface
-//! tinted, removed material as a translucent ghost. The last good preview stays up while the
-//! next one computes; once the current inputs make the feature fail, nothing is previewed and
-//! the error shows in the dialog (#3254).
+//! tinted (unless Graphics' Tint new surface in a preview is off, when a changed body is drawn
+//! as itself), removed material as a translucent ghost. The last good preview stays up while
+//! the next one computes; once the current inputs make the feature fail, nothing is previewed
+//! and the error shows in the dialog (#3254).
//! Nothing here touches the document or the undo history.
//!
//! A feature that adds or removes a tool body (join, cut, intersect) shows only its tool. That
@@ -19,6 +20,7 @@ use solidcraft_engine::Session;
use solidcraft_engine::doc::ModelState;
use solidcraft_engine::doc::progress::Progress;
use solidcraft_engine::geom::{Aabb3, Mesh, Ring, Vec3};
+use solidcraft_engine::kernel::history::Change;
use crate::SolveApp;
use crate::gpu::{GpuScene, SceneSlot};
@@ -28,6 +30,8 @@ use crate::theme::Tokens;
#[derive(Clone, Copy, Debug)]
pub struct Colors {
pub body: [u8; 4],
+ /// The tool a join, cut or intersect adds, a datum plane a preview creates, and, where the
+ /// preference asks for it (`tint_new`), the surface a feature adds to a body it changes.
pub added: [u8; 4],
/// A body the preview creates (New Body), so it doesn't look like a join.
pub new_body: [u8; 4],
@@ -35,12 +39,29 @@ pub struct Colors {
pub edge: [u8; 4],
/// Whether a moved component's old place is drawn as a ghost (Drive Joints' Show ghost).
pub ghost: bool,
+ /// Whether the surface a feature adds to a body it changes is drawn in the added colour
+ /// (Graphics' Tint new surface in a preview). Off: that body is drawn as itself, and which
+ /// of its faces are new is never worked out.
+ pub tint_new: bool,
+ /// Whether removed material is filled in the cut colour (Graphics' Show removed material in
+ /// red): the see-through cut and the ghost of the shape a feature replaces. Off: those fills
+ /// are left out altogether, so they are fully transparent and only outlines are drawn.
+ pub cut_tint: bool,
}
impl Colors {
pub fn from_tokens(t: &Tokens) -> Colors {
let c = |c: egui::Color32| c.to_srgba_unmultiplied();
- Colors { body: c(t.body), added: c(t.preview_add), new_body: c(t.preview_new), removed: c(t.preview_cut), edge: c(t.body_edge), ghost: true }
+ Colors {
+ body: c(t.body),
+ added: c(t.preview_add),
+ new_body: c(t.preview_new),
+ removed: c(t.preview_cut),
+ edge: c(t.body_edge),
+ ghost: true,
+ tint_new: true,
+ cut_tint: true,
+ }
}
fn for_tool(t: &Tokens, tab: &str, active: bool) -> Colors {
@@ -366,6 +387,8 @@ pub fn update(app: &mut SolveApp, ctx: &egui::Context) {
if app.dialog.as_ref().is_some_and(|d| matches!(d.kind, crate::dialogs::Kind::Assembly(crate::dialogs_assembly::Asm::Drive { .. }))) {
colors.ghost = app.preferences.drive_joints_ghost;
}
+ colors.tint_new = app.preferences.preview_tint_new_faces;
+ colors.cut_tint = app.preferences.cut_preview_tint;
let key = job_key(&cmds, app.session.revision, colors);
let stream_key = stream_key(&cmds, app.session.revision, colors);
let tool = as_new_body(&cmds).is_some();
@@ -577,6 +600,7 @@ fn build_tool(before: &ModelState, after: &ModelState, c: Colors, op: &str) -> B
let i = *k as usize;
if let (Some(p), Some(n)) = (m.positions.get(i), m.normals.get(i)) {
match op {
+ "cut" if !c.cut_tint => {}
"cut" => sc.xray_tri(p.to_f32(), n.to_f32(), removed),
"intersect" => sc.xray_tri(p.to_f32(), n.to_f32(), intersect),
_ => sc.tri(p.to_f32(), n.to_f32(), added),
@@ -665,26 +689,43 @@ pub fn build(before: &ModelState, after: &ModelState, c: Colors) -> Built {
if old.as_ref().is_some_and(|bm| same(bm, &am)) {
continue;
}
- let nf = am.tri_face.iter().max().map_or(0, |m| *m as usize + 1);
- let added: Vec<bool> = match &old {
- Some(bm) => new_faces(&am, nf, bm),
- None => vec![true; nf],
- };
// Material removed from a body (a hole, a pocket): its new faces also show through the
// body in the cut colour, so the cut is seen from any side.
- let cut = old.as_ref().is_some_and(|bm| am.measure().volume < bm.measure().volume - 1e-6);
+ let cut = c.cut_tint && old.as_ref().is_some_and(|bm| am.measure().volume < bm.measure().volume - 1e-6);
+ // Which of the body's faces the feature made, asked only when something is drawn from
+ // the answer: the cut above, and the tint the preference offers. A changed body is
+ // otherwise drawn as itself, so a preview looks like the model and nothing has to be
+ // worked out face by face.
+ let new_face: Vec<bool> = match &old {
+ Some(bm) if cut || c.tint_new => {
+ let mut new = new_faces(&am, am.tri_face.iter().max().map_or(0, |m| *m as usize + 1), bm);
+ // The kernel recorded which faces the operation that made this body generated,
+ // i.e. has no face of an input under it. The two answers are taken together
+ // because each misses something on its own: geometry cannot see a round small
+ // beside the part, which lies within its tolerance of the faces it is tangent
+ // to all along both of its sides, while the record may be of a later operation
+ // than the one previewed (a parameter change re-evaluates the design, and a
+ // body keeps the history of whatever last made it), so the record only ever
+ // adds faces to the answer.
+ if let Some(history) = a.body.history() {
+ for (is_new, face) in new.iter_mut().zip(&history.faces) {
+ *is_new |= face.change == Change::Generated;
+ }
+ }
+ new
+ }
+ _ => Vec::new(),
+ };
+ let kept = if old.is_some() { body_color } else { new_body };
for (t, f) in am.triangles.iter().zip(&am.tri_face) {
- let new = added.get(*f as usize).copied().unwrap_or(true);
- let col = match (new, old.is_some()) {
- (false, _) => body_color,
- (true, true) => added_color,
- (true, false) => new_body,
- };
+ let new = new_face.get(*f as usize).copied().unwrap_or(false);
+ let col = if new && c.tint_new { added_color } else { kept };
+ let through = cut && new;
for k in t {
let i = *k as usize;
if let (Some(p), Some(n)) = (am.positions.get(i), am.normals.get(i)) {
sc.tri(p.to_f32(), n.to_f32(), col);
- if new && cut {
+ if through {
sc.xray_tri(p.to_f32(), n.to_f32(), removed);
}
}
@@ -708,11 +749,13 @@ pub fn build(before: &ModelState, after: &ModelState, c: Colors) -> Built {
continue;
}
let m = b.mesh();
- for t in &m.triangles {
- for k in t {
- let i = *k as usize;
- if let (Some(p), Some(n)) = (m.positions.get(i), m.normals.get(i)) {
- sc.ghost_tri(p.to_f32(), n.to_f32(), removed);
+ if c.cut_tint {
+ for t in &m.triangles {
+ for k in t {
+ let i = *k as usize;
+ if let (Some(p), Some(n)) = (m.positions.get(i), m.normals.get(i)) {
+ sc.ghost_tri(p.to_f32(), n.to_f32(), removed);
+ }
}
}
}
@@ -755,6 +798,12 @@ pub fn build(before: &ModelState, after: &ModelState, c: Colors) -> Built {
Built { scene: sc, sketches, replaced, error: None, bounds: Aabb3::EMPTY, applied: None, tapered: Vec::new(), stopped: None }
}
+/// Points of one face the vote in [`new_faces`] asks about: every centroid of a face with no
+/// more than this many triangles, so its answer doesn't ride on where that face's rows of
+/// facets happen to fall, and a spread sample of a larger one. The lookups per face stay
+/// bounded, so a modeled thread's thousands of faces still cost little.
+const FACE_SAMPLES: usize = 24;
+
/// Which of the `nf` faces of `m` are new surface, i.e. not on the old mesh? Each is decided by
/// a vote of points on it (triangle centroids spread over the face). One pass over `m`'s
/// triangles gathers the centroids, and the old mesh is indexed once, so the cost stays
@@ -774,10 +823,23 @@ fn new_faces(m: &Mesh, nf: usize, old: &Mesh) -> Vec<bool> {
if cents.is_empty() {
return true;
}
- let step = cents.len().div_ceil(9);
- let samples: Vec<&Vec3> = cents.iter().step_by(step.max(1)).collect();
+ let samples: Vec<&Vec3> = if cents.len() <= FACE_SAMPLES {
+ cents.iter().collect()
+ } else {
+ // Spread by the golden ratio rather than at a fixed step: a face's triangles
+ // come in rows across its curve, and a step that divides the row length would
+ // ask about the same place in every row (a blend's tangent sides, say), so two
+ // alike faces could be told apart by nothing but how long they are.
+ let len = cents.len() as f64;
+ (0..FACE_SAMPLES).filter_map(|i| cents.get(((i as f64 * 0.618_033_988_75).fract() * len) as usize)).collect()
+ };
let off = samples.iter().filter(|p| !index.contains(***p)).count();
- off * 3 > samples.len()
+ // More than an eighth of the face off the old surface is new surface. A blend meets
+ // the faces it rounds tangentially, so the rows of facets along both of its sides
+ // lie within the tolerance of the old surface and only the band through its middle
+ // is clearly off: a small round on a large part never reaches the third the vote
+ // asked for before, and was drawn as if it had always been there.
+ off * 8 > samples.len()
})
.collect()
}
@@ -933,7 +995,16 @@ mod tests {
}
fn colors() -> Colors {
- Colors { body: [1, 1, 1, 255], added: [2, 2, 2, 255], new_body: [4, 4, 4, 255], removed: [3, 3, 3, 100], edge: [0, 0, 0, 255], ghost: true }
+ Colors {
+ body: [1, 1, 1, 255],
+ added: [2, 2, 2, 255],
+ new_body: [4, 4, 4, 255],
+ removed: [3, 3, 3, 100],
+ edge: [0, 0, 0, 255],
+ ghost: true,
+ tint_new: true,
+ cut_tint: true,
+ }
}
#[test]
@@ -1205,6 +1276,32 @@ mod tests {
assert_eq!(count(&b.scene, &b.scene.xray, 28, colors().removed), 0);
}
+ /// Graphics' Show removed material in red, off: the cut and the ghost of the shape the
+ /// feature replaces are left out, and the body itself is still drawn.
+ #[test]
+ fn removed_material_can_be_left_fully_transparent() {
+ let mut s = solidcraft_engine::Session::default();
+ s.execute("solid.box", &json!({"length": 40, "width": 30, "height": 20})).unwrap();
+ let cmds = [("solid.hole".to_string(), json!({"position": [20, 15, 20], "diameter": 5, "depth": 10}))];
+ let p = s.preview(&cmds).unwrap();
+ let plain = colors();
+ let b = build(&p.before, &p.after, plain);
+ assert!(count(&b.scene, &b.scene.ghost, 28, plain.removed) > 0, "the replaced shape is ghosted while the tint is on");
+ let quiet = Colors { cut_tint: false, ..plain };
+ let b = build(&p.before, &p.after, quiet);
+ assert_eq!(count(&b.scene, &b.scene.xray, 28, quiet.removed), 0, "no see-through cut");
+ assert_eq!(count(&b.scene, &b.scene.ghost, 28, quiet.removed), 0, "no ghost of the old shape");
+ assert!(count(&b.scene, &b.scene.tris, 28, quiet.body) > 0, "the body is still drawn");
+ // The tool of a cut is left out too, its outline alone showing where it goes.
+ let cmds = [("solid.box".to_string(), json!({"length": 10, "width": 10, "height": 30, "operation": "new"}))];
+ let p = s.preview(&cmds).unwrap();
+ let shown = build_tool(&p.before, &p.after, plain, "cut");
+ assert!(count(&shown.scene, &shown.scene.xray, 28, plain.removed) > 0, "the tool is see-through red while the tint is on");
+ let b = build_tool(&p.before, &p.after, quiet, "cut");
+ assert_eq!(count(&b.scene, &b.scene.xray, 28, quiet.removed), 0, "no see-through tool");
+ assert!(!b.scene.overlay.is_empty(), "the tool's outline still shows where the cut goes");
+ }
+
fn plate() -> Session {
let mut s = Session::default();
for (id, p) in [
@@ -1345,6 +1442,42 @@ mod tests {
assert_eq!(s.undo.len(), undo);
}
+ /// Graphics' Tint new surface in a preview, off: the changed body is drawn as itself, and
+ /// no face of it is worked out.
+ #[test]
+ fn the_tint_on_new_surface_can_be_turned_off() {
+ let s = plate();
+ let cmds = [("solid.fillet".to_string(), json!({"edges": [[0, 0, 10]], "radius": 3}))];
+ let plain = Colors { tint_new: false, ..colors() };
+ let b = compute(&s, &cmds, plain).unwrap();
+ assert_eq!(count(&b.scene, &b.scene.tris, crate::gpu::TRI_SIZE, plain.added), 0, "nothing is tinted");
+ assert!(count(&b.scene, &b.scene.tris, crate::gpu::TRI_SIZE, plain.body) > 0, "the body is drawn as itself");
+ }
+
+ /// With the tint on, a round far smaller than the part is new surface too. Every facet of
+ /// this one lies within the preview's tolerance (half a millimetre here) of the faces it is
+ /// tangent to, so no point on it is off the old body and only the kernel's record of what
+ /// the fillet generated can tell.
+ #[test]
+ fn a_small_round_on_a_large_part_is_tinted_as_new() {
+ let mut s = Session::default();
+ for (id, p) in [
+ ("sketch.create", json!({"plane": "XY"})),
+ ("sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [200, 150]})),
+ ("sketch.finish", json!({})),
+ ("solid.extrude", json!({"distance": 10})),
+ ] {
+ s.execute(id, &p).unwrap();
+ }
+ // The plate's diagonal is 250 mm, so a point counts as on the old surface within half a
+ // millimetre: a 0.5 mm round never leaves it, bulging 0.15 mm at the most.
+ let tinted = Colors { tint_new: true, ..colors() };
+ let b = compute(&s, &[("solid.fillet".into(), json!({"edges": [[100, 0, 10]], "radius": 0.5}))], tinted).unwrap();
+ let added = count(&b.scene, &b.scene.tris, crate::gpu::TRI_SIZE, tinted.added);
+ assert!(added > 0, "the round is drawn as new surface, not as part of the old body");
+ assert!(count(&b.scene, &b.scene.tris, crate::gpu::TRI_SIZE, tinted.body) > 0, "the rest of the plate is kept");
+ }
+
/// A cut shows its tool see-through and replaces nothing.
#[test]
fn cut_preview_scene() {
diff --git a/crates/ui-egui/src/preview_drag_tests.rs b/crates/ui-egui/src/preview_drag_tests.rs
index 3167b3156e..22e96f8198 100644
--- a/crates/ui-egui/src/preview_drag_tests.rs
+++ b/crates/ui-egui/src/preview_drag_tests.rs
@@ -3,7 +3,16 @@ use super::*;
use serde_json::json;
fn colors() -> Colors {
- Colors { body: [1, 1, 1, 255], added: [2, 2, 2, 255], new_body: [2, 2, 2, 255], removed: [3, 3, 3, 100], edge: [0, 0, 0, 255], ghost: true }
+ Colors {
+ body: [1, 1, 1, 255],
+ added: [2, 2, 2, 255],
+ new_body: [2, 2, 2, 255],
+ removed: [3, 3, 3, 100],
+ edge: [0, 0, 0, 255],
+ ghost: true,
+ tint_new: true,
+ cut_tint: true,
+ }
}
fn fixture() -> Session {