Commit: d8eac4e3e5696cadc7154e40f22c49c48b8845af
Author: Germano Cavalcante
Date:   Tue Aug 11 22:57:13 2020 -0300
Branches: cloth_collision
https://developer.blender.org/rBd8eac4e3e5696cadc7154e40f22c49c48b8845af

Cloth: Implement a new edge x edge collision system

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

M       release/scripts/startup/bl_ui/properties_physics_cloth.py
M       source/blender/blenkernel/BKE_cloth.h
M       source/blender/blenkernel/intern/cloth.c
M       source/blender/blenkernel/intern/collision.c
M       source/blender/blenloader/intern/versioning_280.c
M       source/blender/makesdna/DNA_cloth_types.h
M       source/blender/makesrna/intern/rna_cloth.c

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

diff --git a/release/scripts/startup/bl_ui/properties_physics_cloth.py 
b/release/scripts/startup/bl_ui/properties_physics_cloth.py
index 79089b7cb89..5de5563c3b5 100644
--- a/release/scripts/startup/bl_ui/properties_physics_cloth.py
+++ b/release/scripts/startup/bl_ui/properties_physics_cloth.py
@@ -326,6 +326,8 @@ class PHYSICS_PT_cloth_collision(PhysicButtonsPanel, Panel):
 
         col = flow.column()
         col.prop(cloth, "collision_quality", text="Quality")
+        col.prop(cloth, "collision_element", slider=True, text="Element")
+        col.prop(cloth, "distance_min", slider=True, text="Distance")
 
 
 class PHYSICS_PT_cloth_object_collision(PhysicButtonsPanel, Panel):
@@ -350,9 +352,6 @@ class PHYSICS_PT_cloth_object_collision(PhysicButtonsPanel, 
Panel):
 
         flow = layout.grid_flow(row_major=False, columns=0, even_columns=True, 
even_rows=False, align=True)
 
-        col = flow.column()
-        col.prop(cloth, "distance_min", slider=True, text="Distance")
-
         col = flow.column()
         col.prop(cloth, "impulse_clamp")
 
@@ -386,9 +385,6 @@ class PHYSICS_PT_cloth_self_collision(PhysicButtonsPanel, 
Panel):
         col = flow.column()
         col.prop(cloth, "self_friction", text="Friction")
 
-        col = flow.column()
-        col.prop(cloth, "self_distance_min", slider=True, text="Distance")
-
         col = flow.column()
         col.prop(cloth, "self_impulse_clamp")
 
diff --git a/source/blender/blenkernel/BKE_cloth.h 
b/source/blender/blenkernel/BKE_cloth.h
index 5af37829577..1706fbd2609 100644
--- a/source/blender/blenkernel/BKE_cloth.h
+++ b/source/blender/blenkernel/BKE_cloth.h
@@ -85,9 +85,8 @@ typedef struct Cloth {
   unsigned int primitive_num;    /* Number of triangles for cloth and edges 
for hair. */
   unsigned char old_solver_type; /* unused, only 1 solver here */
   unsigned char pad2;
-  short pad3;
-  struct BVHTree *bvhtree;     /* collision tree for this cloth object */
-  struct BVHTree *bvhselftree; /* collision tree for this cloth object */
+  short bvh_elem_type;
+  struct BVHTree *bvhtree; /* collision tree for this cloth object */
   struct MVertTri *tri;
   struct Implicit_Data *implicit; /* our implicit solver connects to this 
pointer */
   struct EdgeSet *edgeset;        /* used for selfcollisions */
@@ -292,7 +291,7 @@ void clothModifier_do(struct ClothModifierData *clmd,
 int cloth_uses_vgroup(struct ClothModifierData *clmd);
 
 // needed for collision.c
-void bvhtree_update_from_cloth(struct ClothModifierData *clmd, bool moving, 
bool self);
+void bvhtree_update_from_cloth(Cloth *cloth, bool moving);
 
 // needed for button_object.c
 void cloth_clear_cache(struct Object *ob, struct ClothModifierData *clmd, 
float framenr);
diff --git a/source/blender/blenkernel/intern/cloth.c 
b/source/blender/blenkernel/intern/cloth.c
index 027761335b0..30cbe4c72b0 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -123,7 +123,6 @@ void cloth_init(ClothModifierData *clmd)
   clmd->coll_parms->epsilon = 0.015f;
   clmd->coll_parms->flags = CLOTH_COLLSETTINGS_FLAG_ENABLED;
   clmd->coll_parms->collision_list = NULL;
-  clmd->coll_parms->selfepsilon = 0.015;
   clmd->coll_parms->vgroup_selfcol = 0;
 
   /* These defaults are copied from softbody.c's
@@ -170,38 +169,21 @@ void cloth_init(ClothModifierData *clmd)
   }
 }
 
-static BVHTree *bvhtree_build_from_cloth(ClothModifierData *clmd, float 
epsilon)
+static BVHTree *bvhtree_build_from_cloth(Cloth *cloth, const float epsilon)
 {
-  unsigned int i;
-  BVHTree *bvhtree;
-  Cloth *cloth;
-  ClothVertex *verts;
-  const MVertTri *vt;
-
-  if (!clmd) {
-    return NULL;
-  }
-
-  cloth = clmd->clothObject;
-
-  if (!cloth) {
-    return NULL;
-  }
-
-  verts = cloth->verts;
-  vt = cloth->tri;
-
   /* in the moment, return zero if no faces there */
   if (!cloth->primitive_num) {
     return NULL;
   }
 
   /* create quadtree with k=26 */
-  bvhtree = BLI_bvhtree_new(cloth->primitive_num, epsilon, 4, 26);
+  BVHTree *bvhtree = BLI_bvhtree_new(cloth->primitive_num, epsilon, 4, 26);
 
   /* fill tree */
-  if (clmd->hairdata == NULL) {
-    for (i = 0; i < cloth->primitive_num; i++, vt++) {
+  ClothVertex *verts = cloth->verts;
+  if (cloth->bvh_elem_type == COL_TRIANGLES) {
+    const MVertTri *vt = cloth->tri;
+    for (uint i = 0; i < cloth->primitive_num; i++, vt++) {
       float co[3][3];
 
       copy_v3_v3(co[0], verts[vt->tri[0]].xold);
@@ -213,8 +195,7 @@ static BVHTree *bvhtree_build_from_cloth(ClothModifierData 
*clmd, float epsilon)
   }
   else {
     MEdge *edges = cloth->edges;
-
-    for (i = 0; i < cloth->primitive_num; i++) {
+    for (uint i = 0; i < cloth->primitive_num; i++) {
       float co[2][3];
 
       copy_v3_v3(co[0], verts[edges[i].v1].xold);
@@ -230,83 +211,72 @@ static BVHTree 
*bvhtree_build_from_cloth(ClothModifierData *clmd, float epsilon)
   return bvhtree;
 }
 
-void bvhtree_update_from_cloth(ClothModifierData *clmd, bool moving, bool self)
+void bvhtree_update_from_cloth(Cloth *cloth, bool moving)
 {
-  unsigned int i = 0;
-  Cloth *cloth = clmd->clothObject;
-  BVHTree *bvhtree;
+  BVHTree *bvhtree = cloth->bvhtree;
   ClothVertex *verts = cloth->verts;
-  const MVertTri *vt;
-
-  BLI_assert(!(clmd->hairdata != NULL && self));
-
-  if (self) {
-    bvhtree = cloth->bvhselftree;
-  }
-  else {
-    bvhtree = cloth->bvhtree;
-  }
 
   if (!bvhtree) {
     return;
   }
 
-  vt = cloth->tri;
+  if (!verts) {
+    return;
+  }
 
   /* update vertex position in bvh tree */
-  if (clmd->hairdata == NULL) {
-    if (verts && vt) {
-      for (i = 0; i < cloth->primitive_num; i++, vt++) {
-        float co[3][3], co_moving[3][3];
-        bool ret;
-
-        /* copy new locations into array */
-        if (moving) {
-          copy_v3_v3(co[0], verts[vt->tri[0]].txold);
-          copy_v3_v3(co[1], verts[vt->tri[1]].txold);
-          copy_v3_v3(co[2], verts[vt->tri[2]].txold);
-
-          /* update moving positions */
-          copy_v3_v3(co_moving[0], verts[vt->tri[0]].tx);
-          copy_v3_v3(co_moving[1], verts[vt->tri[1]].tx);
-          copy_v3_v3(co_moving[2], verts[vt->tri[2]].tx);
-
-          ret = BLI_bvhtree_update_node(bvhtree, i, co[0], co_moving[0], 3);
-        }
-        else {
-          copy_v3_v3(co[0], verts[vt->tri[0]].tx);
-          copy_v3_v3(co[1], verts[vt->tri[1]].tx);
-          copy_v3_v3(co[2], verts[vt->tri[2]].tx);
-
-          ret = BLI_bvhtree_update_node(bvhtree, i, co[0], NULL, 3);
-        }
+  if (cloth->bvh_elem_type == COL_TRIANGLES) {
+    const MVertTri *vt = cloth->tri;
+    if (!vt) {
+      return;
+    }
+    for (uint i = 0; i < cloth->primitive_num; i++, vt++) {
+      float co[3][3], co_moving[3][3];
+      bool ret;
+
+      /* copy new locations into array */
+      if (moving) {
+        copy_v3_v3(co[0], verts[vt->tri[0]].txold);
+        copy_v3_v3(co[1], verts[vt->tri[1]].txold);
+        copy_v3_v3(co[2], verts[vt->tri[2]].txold);
+
+        /* update moving positions */
+        copy_v3_v3(co_moving[0], verts[vt->tri[0]].tx);
+        copy_v3_v3(co_moving[1], verts[vt->tri[1]].tx);
+        copy_v3_v3(co_moving[2], verts[vt->tri[2]].tx);
+
+        ret = BLI_bvhtree_update_node(bvhtree, i, co[0], co_moving[0], 3);
+      }
+      else {
+        copy_v3_v3(co[0], verts[vt->tri[0]].tx);
+        copy_v3_v3(co[1], verts[vt->tri[1]].tx);
+        copy_v3_v3(co[2], verts[vt->tri[2]].tx);
 
-        /* check if tree is already full */
-        if (ret == false) {
-          break;
-        }
+        ret = BLI_bvhtree_update_node(bvhtree, i, co[0], NULL, 3);
       }
 
-      BLI_bvhtree_update_tree(bvhtree);
+      /* check if tree is already full */
+      if (ret == false) {
+        break;
+      }
     }
+
+    BLI_bvhtree_update_tree(bvhtree);
   }
   else {
-    if (verts) {
-      MEdge *edges = cloth->edges;
-
-      for (i = 0; i < cloth->primitive_num; i++) {
-        float co[2][3];
+    MEdge *edges = cloth->edges;
+    for (uint i = 0; i < cloth->primitive_num; i++) {
+      float co[2][3];
 
-        copy_v3_v3(co[0], verts[edges[i].v1].tx);
-        copy_v3_v3(co[1], verts[edges[i].v2].tx);
+      copy_v3_v3(co[0], verts[edges[i].v1].tx);
+      copy_v3_v3(co[1], verts[edges[i].v2].tx);
 
-        if (!BLI_bvhtree_update_node(bvhtree, i, co[0], NULL, 2)) {
-          break;
-        }
+      if (!BLI_bvhtree_update_node(bvhtree, i, co[0], NULL, 2)) {
+        break;
       }
-
-      BLI_bvhtree_update_tree(bvhtree);
     }
+
+    BLI_bvhtree_update_tree(bvhtree);
   }
 }
 
@@ -572,10 +542,6 @@ void cloth_free_modifier(ClothModifierData *clmd)
       BLI_bvhtree_free(cloth->bvhtree);
     }
 
-    if (cloth->bvhselftree) {
-      BLI_bvhtree_free(cloth->bvhselftree);
-    }
-
     // we save our faces for collision objects
     if (cloth->tri) {
       MEM_freeN(cloth->tri);
@@ -654,10 +620,6 @@ void cloth_free_modifier_extern(ClothModifierData *clmd)
       BLI_bvhtree_free(cloth->bvhtree);
     }
 
-    if (cloth->bvhselftree) {
-      BLI_bvhtree_free(cloth->bvhselftree);
-    }
-
     // we save our faces for collision objects
     if (cloth->tri) {
       MEM_freeN(cloth->tri);
@@ -925,8 +887,8 @@ static int cloth_from_object(
     SIM_cloth_solver_set_positions(clmd);
   }
 
-  clmd->clothObject->bvhtree = bvhtree_build_from_cloth(clmd, 
clmd->coll_parms->epsilon);
-  clmd->clothObject->bvhselftree = bvhtree_build_from_cloth(clmd, 
clmd->coll_parms->selfepsilon);
+  clmd->clothObject->bvhtree = bvhtree_build_from_cloth(clmd->clothObject,
+                                                        
clmd->coll_parms->epsilon);
 
   return 1;
 }
@@ -938,6 +900,8 @@ static void cloth_from_mesh(ClothModifierData *clmd, Mesh 
*mesh)
   const unsigned int mvert_num = mesh->totvert;
   const unsigned int looptri_num = mesh->runtime.looptris.len;
 
+  clmd->clothObject->bvh_elem_type = clmd->hairdata ? COL_EDGES : 
clmd->coll_parms->elem_type;
+
   /* Allocate our vertices. */
   clmd->clothObject->mvert_num = mvert_num;
   clmd->clothObject->verts = MEM_callocN(sizeof(ClothVertex) * 
clmd->clothObject->mvert_num,
@@ -950,25 +914,26 @@ static void cloth_from_mesh(ClothModifierData *clmd, Mesh 
*mesh)
     return;
   }


@@ Diff output truncated at 10240 characters. @@

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

Reply via email to