[Bf-blender-cvs] [cafb5b81ee9] soc-2019-adaptive-cloth: Cloth: vertex on seam test during collapse edges

ishbosamiya noreply at git.blender.org
Mon Jul 8 16:36:07 CEST 2019


Commit: cafb5b81ee923e8ad02df106b40b724bc5903eea
Author: ishbosamiya
Date:   Mon Jul 8 20:04:34 2019 +0530
Branches: soc-2019-adaptive-cloth
https://developer.blender.org/rBcafb5b81ee923e8ad02df106b40b724bc5903eea

Cloth: vertex on seam test during collapse edges

Now it ensures that vertices that are on the seam are not killed while collapse the edge.
Leads to new problem, possibly related to reindex vertices.

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

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

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

diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 296086cd175..3df342fa7f4 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -50,6 +50,7 @@ set(INC
   ../../../intern/opensubdiv
   ../../../extern/curve_fit_nd
   ../../../intern/smoke/extern
+  ../editors/include
 )
 
 set(INC_SYS
diff --git a/source/blender/blenkernel/intern/cloth_remeshing.cpp b/source/blender/blenkernel/intern/cloth_remeshing.cpp
index cc1892d72b1..7c9d60c39e9 100644
--- a/source/blender/blenkernel/intern/cloth_remeshing.cpp
+++ b/source/blender/blenkernel/intern/cloth_remeshing.cpp
@@ -48,6 +48,7 @@ extern "C" {
 #include "BKE_global.h"
 #include "BKE_mesh.h"
 #include "BKE_mesh_runtime.h"
+#include "BKE_mesh_mapping.h"
 #include "BKE_modifier.h"
 #include "BKE_library.h"
 #if USE_CLOTH_CACHE
@@ -56,6 +57,8 @@ extern "C" {
 
 #include "bmesh.h"
 #include "bmesh_tools.h"
+
+#include "ED_mesh.h"
 }
 
 #include "BKE_cloth_remeshing.h"
@@ -82,6 +85,109 @@ static CustomData_MeshMasks cloth_remeshing_get_cd_mesh_masks(void)
   return cddata_masks;
 }
 
+/* copied from uvedit_ops.c uv_seams_from_islands_exec() */
+/* TODO(Ish): it seems that it can be ported to finding it for the
+ * edge indivially, do this later to preserve user defined seams */
+static void cloth_remeshing_uv_from_islands(BMesh *bm)
+{
+  const float limit[2] = {STD_UV_CONNECT_LIMIT, STD_UV_CONNECT_LIMIT};
+  const bool mark_seams = true;
+  const bool mark_sharp = false;
+
+  UvVertMap *vmap;
+  BMEdge *editedge;
+  BMIter iter;
+
+  /* This code sets editvert->tmp.l to the index. This will be useful later on. */
+  BM_mesh_elem_table_ensure(bm, BM_FACE);
+  vmap = BM_uv_vert_map_create(bm, limit, false, false);
+
+  BM_ITER_MESH (editedge, &iter, bm, BM_EDGES_OF_MESH) {
+    /* flags to determine if we uv is separated from first editface match */
+    char separated1 = 0, separated2;
+    /* set to denote edge must be flagged as seam */
+    char faces_separated = 0;
+    /* flag to keep track if uv1 is disconnected from first editface match */
+    char v1coincident = 1;
+    /* For use with v1coincident. v1coincident will change only if we've had commonFaces */
+    int commonFaces = 0;
+
+    BMFace *efa1, *efa2;
+
+    UvMapVert *mv1, *mvinit1, *mv2, *mvinit2, *mviter;
+    /* mv2cache stores the first of the list of coincident uv's for later comparison
+     * mv2sep holds the last separator and is copied to mv2cache
+     * when a hit is first found */
+    UvMapVert *mv2cache = NULL, *mv2sep = NULL;
+
+    mvinit1 = vmap->vert[BM_elem_index_get(editedge->v1)];
+    if (mark_seams) {
+      BM_elem_flag_disable(editedge, BM_ELEM_SEAM);
+    }
+
+    for (mv1 = mvinit1; mv1 && !faces_separated; mv1 = mv1->next) {
+      if (mv1->separate && commonFaces) {
+        v1coincident = 0;
+      }
+
+      separated2 = 0;
+      efa1 = BM_face_at_index(bm, mv1->poly_index);
+      mvinit2 = vmap->vert[BM_elem_index_get(editedge->v2)];
+
+      for (mv2 = mvinit2; mv2; mv2 = mv2->next) {
+        if (mv2->separate) {
+          mv2sep = mv2;
+        }
+
+        efa2 = BM_face_at_index(bm, mv2->poly_index);
+        if (efa1 == efa2) {
+          /* if v1 is not coincident no point in comparing */
+          if (v1coincident) {
+            /* have we found previously anything? */
+            if (mv2cache) {
+              /* flag seam unless proved to be coincident with previous hit */
+              separated2 = 1;
+              for (mviter = mv2cache; mviter; mviter = mviter->next) {
+                if (mviter->separate && mviter != mv2cache) {
+                  break;
+                }
+                /* coincident with previous hit, do not flag seam */
+                if (mviter == mv2) {
+                  separated2 = 0;
+                }
+              }
+            }
+            /* First hit case, store the hit in the cache */
+            else {
+              mv2cache = mv2sep;
+              commonFaces = 1;
+            }
+          }
+          else {
+            separated1 = 1;
+          }
+
+          if (separated1 || separated2) {
+            faces_separated = 1;
+            break;
+          }
+        }
+      }
+    }
+
+    if (faces_separated) {
+      if (mark_seams) {
+        BM_elem_flag_enable(editedge, BM_ELEM_SEAM);
+      }
+      if (mark_sharp) {
+        BM_elem_flag_disable(editedge, BM_ELEM_SMOOTH);
+      }
+    }
+  }
+
+  BM_uv_vert_map_free(vmap);
+}
+
 static void cloth_remeshing_init_bmesh(Object *ob, ClothModifierData *clmd, Mesh *mesh)
 {
   if (clmd->sim_parms->remeshing_reset || !clmd->clothObject->bm_prev) {
@@ -113,6 +219,7 @@ static void cloth_remeshing_init_bmesh(Object *ob, ClothModifierData *clmd, Mesh
                         NULL,
                         NULL,
                         NULL);
+    cloth_remeshing_uv_from_islands(clmd->clothObject->bm_prev);
     printf("remeshing_reset has been set to true or bm_prev does not exist\n");
   }
   else {
@@ -834,8 +941,20 @@ static void cloth_remeshing_remove_vertex_from_cloth(Cloth *cloth, BMVert *v)
   cloth->mvert_num--;
 }
 
+static bool cloth_remeshing_vert_on_seam_test(BMVert *v)
+{
+  return BM_elem_flag_test_bool(v, BM_ELEM_SEAM);
+}
+
 static BMVert *cloth_remeshing_collapse_edge(Cloth *cloth, BMesh *bm, BMEdge *e)
 {
+  if (cloth_remeshing_vert_on_seam_test(e->v1)) {
+    printf("didn't collapse edge due to vert on seam: %f, %f, %f\n",
+           e->v1->co[0],
+           e->v1->co[1],
+           e->v1->co[2]);
+    return NULL;
+  }
   BMVert v1 = *e->v1;
   BMVert *v2 = BM_edge_collapse(bm, e, e->v1, true, true);
 
@@ -969,12 +1088,6 @@ static void cloth_remeshing_static(ClothModifierData *clmd)
   while (cloth_remeshing_split_edges(clmd, sizing)) {
     /* empty while */
   }
-  /* cloth_remeshing_split_edges(clmd, &sizing); */
-  /* static int file_no = 0; */
-  /* file_no++; */
-  /* char file_name[100]; */
-  /* sprintf(file_name, "/tmp/objs/%03d.obj", file_no); */
-  /* cloth_remeshing_export_obj(clmd->clothObject->bm, file_name); */
 
   /**
    * Collapse edges
@@ -1019,6 +1132,14 @@ static void cloth_remeshing_static(ClothModifierData *clmd)
 #if 1
   active_faces.clear();
 #endif
+
+#if 1
+  static int file_no = 0;
+  file_no++;
+  char file_name[100];
+  sprintf(file_name, "/tmp/objs/%03d.obj", file_no);
+  cloth_remeshing_export_obj(clmd->clothObject->bm, file_name);
+#endif
 }
 
 Mesh *cloth_remeshing_step(Object *ob, ClothModifierData *clmd, Mesh *mesh)



More information about the Bf-blender-cvs mailing list