[Bf-blender-cvs] [c3560029a37] soc-2019-adaptive-cloth: Cloth: now reindexing the clothObject->verts to match bmesh

ishbosamiya noreply at git.blender.org
Thu Jul 4 12:47:05 CEST 2019


Commit: c3560029a3767e984b75602779418367e9b3cbb9
Author: ishbosamiya
Date:   Wed Jul 3 15:23:03 2019 +0530
Branches: soc-2019-adaptive-cloth
https://developer.blender.org/rBc3560029a3767e984b75602779418367e9b3cbb9

Cloth: now reindexing the clothObject->verts to match bmesh

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

M	source/blender/blenkernel/intern/cloth_remeshing.cpp

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

diff --git a/source/blender/blenkernel/intern/cloth_remeshing.cpp b/source/blender/blenkernel/intern/cloth_remeshing.cpp
index 415fcb9f7c2..3cc925c6ff4 100644
--- a/source/blender/blenkernel/intern/cloth_remeshing.cpp
+++ b/source/blender/blenkernel/intern/cloth_remeshing.cpp
@@ -847,11 +847,12 @@ static bool cloth_remeshing_try_edge_collapse(ClothModifierData *clmd,
   return true;
 }
 
+int count;
+
 static bool cloth_remeshing_collapse_edges(ClothModifierData *clmd,
                                            vector<ClothSizing> &sizing,
                                            vector<BMFace *> &active_faces)
 {
-  static int count = 0;
   for (int i = 0; i < active_faces.size(); i++) {
     BMFace *f = active_faces[i];
     BMEdge *e;
@@ -876,13 +877,23 @@ static bool cloth_remeshing_collapse_edges(ClothModifierData *clmd,
     }
     active_faces.erase(active_faces.begin() + i--);
     count++;
-    printf("collapse edges count: %d", count);
   }
   return false;
 }
 
 static void cloth_remeshing_reindex_cloth_vertices(Cloth *cloth, BMesh *bm)
 {
+  ClothVertex *new_verts = (ClothVertex *)MEM_mallocN(sizeof(ClothVertex) * cloth->mvert_num,
+                                                      "New ClothVertex Array");
+  BMVert *v;
+  BMIter viter;
+  int i = 0;
+  BM_ITER_MESH_INDEX (v, &viter, bm, BM_VERTS_OF_MESH, i) {
+    new_verts[i] = *cloth_remeshing_find_cloth_vertex(v, cloth->verts, cloth->mvert_num);
+  }
+
+  MEM_freeN(cloth->verts);
+  cloth->verts = new_verts;
 }
 
 static void cloth_remeshing_static(ClothModifierData *clmd)
@@ -929,9 +940,11 @@ static void cloth_remeshing_static(ClothModifierData *clmd)
     active_faces.push_back(f);
   }
   int prev_mvert_num = clmd->clothObject->mvert_num;
+  count = 0;
   while (cloth_remeshing_collapse_edges(clmd, sizing, active_faces)) {
     /* empty while */
   }
+  printf("collapse edges count: %d\n", count);
   /* delete excess vertices after collpase edges */
   if (prev_mvert_num != clmd->clothObject->mvert_num) {
     clmd->clothObject->verts = (ClothVertex *)MEM_reallocN(
@@ -940,6 +953,11 @@ static void cloth_remeshing_static(ClothModifierData *clmd)
 
 #endif
 
+  /**
+   * Reindex clmd->clothObject->verts to match clmd->clothObject->bm
+   */
+  cloth_remeshing_reindex_cloth_vertices(clmd->clothObject, clmd->clothObject->bm);
+
   /**
    * Delete sizing
    */



More information about the Bf-blender-cvs mailing list