feat(brep): enable 7-face sphere merge by default

This commit is contained in:
hm
2026-11-08 23:44:39 +08:00
parent b4ccf3e70a
commit e111d472ee
4 changed files with 32 additions and 4 deletions
+1 -1
View File
@@ -4503,7 +4503,7 @@ static void repair_corner_after_boolean(BrepModel& result) {
const auto rep = auto_trim_corner_notch(result);
if (rep.detected) {
finalize_boolean_orientation(result);
if (std::getenv("VDE_MERGE_SPHERE") != nullptr)
if (std::getenv("VDE_NO_MERGE_SPHERE") == nullptr)
merge_spherical_patches(result);
}
}
+5 -1
View File
@@ -4775,7 +4775,11 @@ static size_t vde_stitch_tjunctions(const BrepModel& model,
vde::mesh::HalfedgeMesh BrepModel::to_mesh(double deflection) const {
// env 仅作为默认来源(VDE-1231 请求 3):无显式 options 时等价于旧行为。
return to_mesh(deflection, vde::mesh::TessellationOptions::from_environment());
auto opts = vde::mesh::TessellationOptions::from_environment();
// 裁剪曲面(尤其全球面 + p-curve)必须与 B-Rep seam 边共享采样,
// 否则跨面网格会出现大量伪边界边。
if (num_trimmed_surfaces() > 0) opts.force_shared_edge_samples = true;
return to_mesh(deflection, opts);
}
vde::mesh::HalfedgeMesh BrepModel::to_mesh(
+2 -2
View File
@@ -62,10 +62,10 @@ TEST(BooleanBenchmarkTest, BoxMinusCornerSphere_SMLibComparable) {
body.num_faces(), v.valid ? 1 : 0, v.watertightness,
std::abs(a.volume - ref) / ref, be, tris, ms);
EXPECT_EQ(body.num_faces(), 70u);
EXPECT_EQ(body.num_faces(), 7u);
EXPECT_TRUE(v.valid);
EXPECT_DOUBLE_EQ(v.watertightness, 1.0);
EXPECT_LT(std::abs(a.volume - ref) / ref, 1e-9);
EXPECT_LT(std::abs(a.volume - ref) / ref, 1e-6);
EXPECT_EQ(be, 0u);
EXPECT_LT(ms, 120000.0);
}
@@ -21,6 +21,23 @@
using namespace vde::brep;
namespace {
struct NoMergeSphere {
NoMergeSphere() {
#ifdef _WIN32
_putenv_s("VDE_NO_MERGE_SPHERE", "1");
#else
setenv("VDE_NO_MERGE_SPHERE", "1", 1);
#endif
}
~NoMergeSphere() {
#ifdef _WIN32
_putenv_s("VDE_NO_MERGE_SPHERE", "");
#else
unsetenv("VDE_NO_MERGE_SPHERE");
#endif
}
};
struct NoAutoTrim {
NoAutoTrim() {
#ifdef _WIN32
@@ -190,6 +207,7 @@ TEST(WatertightMetricsTest, KnownLimitation_StitchTJunctionsDoesNotReduce912) {
const auto base = measure_mesh(body);
vde::mesh::TessellationOptions opts;
opts.stitch_tjunctions = 1;
opts.force_shared_edge_samples = true;
const auto stitched = measure_mesh(body, 0.02, &opts);
::testing::Test::RecordProperty("base_boundary", std::to_string(base.boundary_edges));
::testing::Test::RecordProperty("stitched_boundary", std::to_string(stitched.boundary_edges));
@@ -419,6 +437,7 @@ TEST(WatertightMetricsTest, NonPlanarThreeArcCap) {
TEST(WatertightMetricsTest, SphereSeamPcurveArea) {
NoMergeSphere guard;
auto body = brep_difference(box100(), make_sphere(40.0, 32, 16));
std::vector<int> group;
Point3D center;
@@ -516,4 +535,9 @@ TEST(WatertightMetricsTest, OptInMergeSpherePatches) {
const double ref = 1000000.0 - 4.0 / 3.0 * 3.141592653589793 * 64000.0 / 8.0;
const auto a = analytic_measure(body, 0.01);
EXPECT_LT(std::abs(a.volume - ref) / ref, 1e-6);
const auto m = measure_mesh(body, 0.02);
vde::mesh::TessellationOptions opts;
opts.force_shared_edge_samples = true;
const auto m2 = measure_mesh(body, 0.02, &opts);
std::printf("merge boundary=%zu forced=%zu\n", m.boundary_edges, m2.boundary_edges);
}