[Bf-blender-cvs] [be8d07b3491] soc-2021-adaptive-cloth: adaptive_cloth: AdaptiveMesh: preserve vert

ishbosamiya noreply at git.blender.org
Sun Aug 22 17:23:37 CEST 2021


Commit: be8d07b34915e63c34aa800a2875513a461acd85
Author: ishbosamiya
Date:   Mon Aug 9 16:36:57 2021 +0530
Branches: soc-2021-adaptive-cloth
https://developer.blender.org/rBbe8d07b34915e63c34aa800a2875513a461acd85

adaptive_cloth: AdaptiveMesh: preserve vert

Need to mark verts that should be preserves, ones that are on seams or
boundaries at the beginning of the remeshing process so that the
initial state is not altered.

Collapse edges should not collapse a vert that should be preserved
into another vert.

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

M	source/blender/blenkernel/intern/cloth_remesh.cc

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

diff --git a/source/blender/blenkernel/intern/cloth_remesh.cc b/source/blender/blenkernel/intern/cloth_remesh.cc
index eb38620dc57..0fd6e29f59b 100644
--- a/source/blender/blenkernel/intern/cloth_remesh.cc
+++ b/source/blender/blenkernel/intern/cloth_remesh.cc
@@ -223,6 +223,7 @@ enum VertFlags {
   VERT_NONE = 0,
   VERT_SELECTED_FOR_SPLIT = 1 << 0,
   VERT_SELECTED_FOR_FLIP = 1 << 1,
+  VERT_PRESERVE = 1 << 2,
 };
 
 class VertData {
@@ -230,6 +231,10 @@ class VertData {
   int flag;
 
  public:
+  VertData() : sizing(float2x2::identity())
+  {
+  }
+
   VertData(Sizing sizing) : sizing(sizing)
   {
     this->flag = VERT_NONE;
@@ -343,6 +348,26 @@ class AdaptiveMesh : public Mesh<NodeData<END>, VertData, EdgeData, internal::Em
     }
   }
 
+  /**
+   * Marks verts which are on a seam or boundary for preserve
+   */
+  void mark_verts_for_preserve()
+  {
+    for (auto &vert : this->get_verts_mut()) {
+      if (this->is_vert_on_seam_or_boundary(vert)) {
+        auto &op_vert_data = vert.get_extra_data_mut();
+        if (op_vert_data) {
+          auto &vert_data = op_vert_data.value();
+          vert_data.get_flag_mut() |= VERT_PRESERVE;
+        }
+        else {
+          vert.set_extra_data(VertData());
+          vert.get_extra_data_mut().value().get_flag_mut() |= VERT_PRESERVE;
+        }
+      }
+    }
+  }
+
   /**
    * Flip edges of the `active_faces` if needed.
    *
@@ -778,6 +803,14 @@ class AdaptiveMesh : public Mesh<NodeData<END>, VertData, EdgeData, internal::Em
 
     const auto [v1, v2] = this->get_checked_verts_of_edge(edge, verts_swapped);
 
+    /* If v1 is supposed to be preserved, cannot collapse the edge */
+    {
+      BLI_assert(v1.get_extra_data());
+      if (v1.get_extra_data().value().get_flag() & VERT_PRESERVE) {
+        return false;
+      }
+    }
+
     /* If v1 is on a seam or boundary, v2 should also be on a seam or boundary */
     if (this->is_vert_on_seam_or_boundary(v1) == true &&
         this->is_vert_on_seam_or_boundary(v2) == false) {
@@ -1018,6 +1051,11 @@ Mesh *adaptive_remesh(const AdaptiveRemeshParams<END, ExtraData> &params,
     params.post_extra_data_to_end(extra_data);
   }
 
+  /* Important to not mess with the panel boundaries so if a vert is
+   * marked for preserve it will not be removed and this takes care of
+   * that. */
+  adaptive_mesh.mark_verts_for_preserve();
+
   /* Actual Remeshing Part */
   {
     float size_min = params.size_min;



More information about the Bf-blender-cvs mailing list