[Bf-blender-cvs] [1b5a2cf3250] soc-2021-adaptive-cloth: adaptive_cloth: Mesh: is_edge_flippable(): works with across_seams

ishbosamiya noreply at git.blender.org
Mon Jul 19 17:35:42 CEST 2021


Commit: 1b5a2cf3250229daa1458bfcae60801119d8e198
Author: ishbosamiya
Date:   Wed Jul 14 13:03:12 2021 +0530
Branches: soc-2021-adaptive-cloth
https://developer.blender.org/rB1b5a2cf3250229daa1458bfcae60801119d8e198

adaptive_cloth: Mesh: is_edge_flippable(): works with across_seams

It is useful to know if the "3D edge" is flippable or not. This is
essentially done by going over all the `Edge` formed by the `Node`s of
the `Edge` and working with all those faces as a whole. Here we also
need to ensure that the edge is not on a seam. It actually might be
possible to optimize this and remove the boundary check entirely.

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

M	source/blender/blenkernel/BKE_cloth_remesh.hh
M	source/blender/modifiers/intern/MOD_adaptive_remesh.cc

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

diff --git a/source/blender/blenkernel/BKE_cloth_remesh.hh b/source/blender/blenkernel/BKE_cloth_remesh.hh
index 47f20a4b824..be679013369 100644
--- a/source/blender/blenkernel/BKE_cloth_remesh.hh
+++ b/source/blender/blenkernel/BKE_cloth_remesh.hh
@@ -1659,6 +1659,9 @@ template<typename END, typename EVD, typename EED, typename EFD> class Mesh {
     for (const auto &edge_index : edge_indices) {
       const auto &e = this->get_checked_edge(edge_index);
       num_face += e.faces.size();
+      if (num_face >= 1) {
+        break;
+      }
     }
 
     return num_face == 1;
@@ -1679,12 +1682,42 @@ template<typename END, typename EVD, typename EED, typename EFD> class Mesh {
    */
   bool is_edge_flippable(EdgeIndex edge_index, bool across_seams) const
   {
-    /* TODO(ish): handle across_seams */
+    /* Do more expensive test only if needed */
+    if (across_seams) {
+      const auto &edge = this->get_checked_edge(edge_index);
+      if (is_edge_on_boundary(edge)) {
+        return false;
+      }
+      const auto [n1, n2] = this->get_checked_nodes_of_edge(edge, false);
+      auto edge_indices = this->get_connecting_edge_indices(n1, n2);
+
+      auto num_faces = 0;
+      for (const auto &edge_index : edge_indices) {
+        const auto &e = this->get_checked_edge(edge_index);
+        num_faces += e.faces.size();
+
+        /* ensure triangulation */
+        for (const auto &face_index : e.faces) {
+          const auto &face = this->get_checked_face(face_index);
+          if (face.verts.size() != 3) {
+            return false;
+          }
+        }
+      }
+      /* ensure only 2 faces exist for the "3D edge" */
+      if (num_faces != 2) {
+        return false;
+      }
+      return true;
+    }
+
     const auto &edge = this->get_checked_edge(edge_index);
+    /* Ensure only 2 faces exist for the edge */
     if (edge.faces.size() != 2) {
       return false;
     }
 
+    /* ensure triangulation */
     for (const auto &face_index : edge.faces) {
       const auto &face = this->get_checked_face(face_index);
       if (face.verts.size() != 3) {
diff --git a/source/blender/modifiers/intern/MOD_adaptive_remesh.cc b/source/blender/modifiers/intern/MOD_adaptive_remesh.cc
index 33d558783f3..fc1ad8ffa3e 100644
--- a/source/blender/modifiers/intern/MOD_adaptive_remesh.cc
+++ b/source/blender/modifiers/intern/MOD_adaptive_remesh.cc
@@ -65,6 +65,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *UNUSED(ctx)
               << " across_seams: " << across_seams << " mode: " << mode << std::endl;
     bool is_on_boundary = internal_mesh.is_edge_on_boundary(edge_index);
     std::cout << "is_on_boundary: " << is_on_boundary << std::endl;
+    auto flippable = internal_mesh.is_edge_flippable(edge_index, across_seams);
+    std::cout << "flippable: " << flippable << std::endl;
     if (mode == ADAPTIVE_REMESH_SPLIT_EDGE) {
       internal_mesh.split_edge_triangulate(edge_index, across_seams);
     }
@@ -72,8 +74,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *UNUSED(ctx)
       internal_mesh.collapse_edge_triangulate(edge_index, verts_swapped, across_seams);
     }
     else if (mode == ADAPTIVE_REMESH_FLIP_EDGE) {
-      auto flippable = internal_mesh.is_edge_flippable(edge_index, across_seams);
-      std::cout << "flippable: " << flippable << std::endl;
       if (flippable) {
         internal_mesh.flip_edge_triangulate(edge_index, across_seams);
       }



More information about the Bf-blender-cvs mailing list