From c00ee3d924992d586e5bda1af24fe049b9864ec1 Mon Sep 17 00:00:00 2001 From: Hakan Seven Date: Tue, 11 Aug 2026 10:17:22 +0300 Subject: [PATCH] fix(acis): use source fit tolerance --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/scene/convert/acis_kernel.rs | 20 +++++++++++++++----- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a38224977..2a5171fa5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -890,7 +890,7 @@ checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" [[package]] name = "cadkernel" version = "0.1.0" -source = "git+https://github.com/HakanSeven12/cadkernel.git?rev=71e2af6#71e2af6bff7adeb115368cc665842ee51a058014" +source = "git+https://github.com/HakanSeven12/cadkernel.git?rev=584695a#584695a37dfd420e1e2d4502233c5dfd99fba472" dependencies = [ "acadrust", "cavalier_contours", diff --git a/Cargo.toml b/Cargo.toml index 225eb50bf..348ecacc2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,7 @@ rfd = "0.17" clap = { version = "4", features = ["derive"] } env_logger = "0.11" acadrust = { git = "https://github.com/HakanSeven12/cadcodec.git", rev = "7e2fa8c", features = ["serde"] } -cadkernel = { git = "https://github.com/HakanSeven12/cadkernel.git", rev = "71e2af6", features = ["acis", "offset"] } +cadkernel = { git = "https://github.com/HakanSeven12/cadkernel.git", rev = "584695a", features = ["acis", "offset"] } acadifc = { git = "https://github.com/OpenAEC-Foundation/acadifc.git", rev = "47b5603", optional = true } dwg-thumbnailer = { path = "crates/dwg-thumbnailer" } flate2 = "1" diff --git a/src/scene/convert/acis_kernel.rs b/src/scene/convert/acis_kernel.rs index 8a5cfb645..5e5acf6ba 100644 --- a/src/scene/convert/acis_kernel.rs +++ b/src/scene/convert/acis_kernel.rs @@ -15,8 +15,7 @@ use cadkernel::brep; use crate::scene::convert::solid3d_tess::{body_transform, finalize_mesh}; use crate::scene::model::mesh_model::{CurvedGen, MeshLodSet}; -/// ACIS topology fit tolerance. -const TOL: f64 = 1e-6; +const DEFAULT_FIT_TOLERANCE: f64 = 1e-6; /// Tessellate an ACIS document through the kernel. pub fn tessellate_sat( @@ -34,6 +33,7 @@ pub fn tessellate_sat( for body in bodies { let source = body.provenance.source()?; let transform = body_transform(document, source.index() as usize).ok()?; + let placement_scale = transform.map_or(1.0, |(_, _, scale)| scale.abs()); let placed = if let Some((matrix, translation, scale)) = transform { let placement = brep::Placement { x_axis: [scale * matrix[0], scale * matrix[1], scale * matrix[2]], @@ -45,7 +45,7 @@ pub fn tessellate_sat( } else { body }; - placed_bodies.push(placed); + placed_bodies.push((placed, placement_scale)); } let bodies = placed_bodies; let resolution = if facet_res.is_finite() && facet_res > 0.0 { @@ -98,9 +98,19 @@ pub fn tessellate_sat( // parameters leaves a hole, the same as one that never lifted — so both // are counted before calling the mesh whole. let mut undrawn = 0usize; - let tolerance = brep::mesh::TessellationTolerance::new(max_angle, TOL) + let source_fit = if document.header.spatial_resolution.is_finite() + && document.header.spatial_resolution > 0.0 + { + document.header.spatial_resolution + } else { + DEFAULT_FIT_TOLERANCE + }; + for (body, placement_scale) in &bodies { + let tolerance = brep::mesh::TessellationTolerance::new( + max_angle, + source_fit * placement_scale, + ) .with_isolines(isolines); - for body in &bodies { let tessellation = brep::mesh::tessellate(body, tolerance); undrawn += tessellation.missing_faces.len(); for face in &tessellation.triangle_faces {