Commit: 10109fd1b230688793e38568ce59593163ac9577
Author: Howard Trickey
Date:   Wed Aug 5 09:25:25 2020 -0400
Branches: newboolean
https://developer.blender.org/rB10109fd1b230688793e38568ce59593163ac9577

Fix union of two disjoint meshes.

Also added unit test for that.

===================================================================

M       source/blender/blenlib/intern/boolean.cc
M       tests/gtests/blenlib/BLI_boolean_test.cc

===================================================================

diff --git a/source/blender/blenlib/intern/boolean.cc 
b/source/blender/blenlib/intern/boolean.cc
index fa8eb3e3e1d..123733a61c9 100644
--- a/source/blender/blenlib/intern/boolean.cc
+++ b/source/blender/blenlib/intern/boolean.cc
@@ -1648,6 +1648,7 @@ static void finish_patch_cell_graph(const Mesh &tm,
       std::cout << "\n";
     }
   }
+  /* For nested components, merge their ambient cell with the nearest 
containing cell. */
   Vector<int> outer_components;
   for (int comp : comp_cont.index_range()) {
     if (comp_cont[comp].size() == 0) {
@@ -1669,6 +1670,7 @@ static void finish_patch_cell_graph(const Mesh &tm,
       merge_cells(cont_cell, comp_ambient, cinfo, pinfo);
     }
   }
+  /* For outer components (not nested in any other component), merge their 
ambient cells. */
   if (outer_components.size() > 1) {
     int merged_ambient = ambient_cell[outer_components[0]];
     for (int i = 1; i < outer_components.size(); ++i) {
@@ -1677,7 +1679,7 @@ static void finish_patch_cell_graph(const Mesh &tm,
                   << "'s ambient cell=" << ambient_cell[outer_components[i]] 
<< " to cell "
                   << merged_ambient << "\n";
       }
-      merge_cells(merged_ambient, outer_components[i], cinfo, pinfo);
+      merge_cells(merged_ambient, ambient_cell[outer_components[i]], cinfo, 
pinfo);
     }
   }
   if (dbg_level > 0) {
diff --git a/tests/gtests/blenlib/BLI_boolean_test.cc 
b/tests/gtests/blenlib/BLI_boolean_test.cc
index ccd0d6d85fb..f4c43bcd84e 100644
--- a/tests/gtests/blenlib/BLI_boolean_test.cc
+++ b/tests/gtests/blenlib/BLI_boolean_test.cc
@@ -328,6 +328,38 @@ TEST(boolean_trimesh, TetInsideTetTrimesh)
   }
 }
 
+TEST(boolean_trimesh, TetBesideTetTrimesh)
+{
+  const char *spec = R"(8 8
+  0 0 0
+  2 0 0
+  1 2 0
+  1 1 2
+  3 0 0
+  5 0 0
+  4 2 0
+  4 1 2
+  0 2 1
+  0 1 3
+  1 2 3
+  2 0 3
+  4 6 5
+  4 5 7
+  5 6 7
+  6 4 7
+  )";
+
+  MeshBuilder mb(spec);
+  Mesh out = boolean_trimesh(
+      mb.mesh, BOOLEAN_UNION, 1, [](int) { return 0; }, true, &mb.arena);
+  out.populate_vert();
+  EXPECT_EQ(out.vert_size(), 8);
+  EXPECT_EQ(out.face_size(), 8);
+  if (DO_OBJ) {
+    write_obj_mesh(out, "tetbesidetet_tm");
+  }
+}
+
 TEST(boolean_polymesh, TetTet)
 {
   const char *spec = R"(8 8

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to