[Bf-blender-cvs] [88a57a6ac53] soc-2019-adaptive-cloth: Cloth: remeshing parameters added

ishbosamiya noreply at git.blender.org
Thu Jun 6 11:11:16 CEST 2019


Commit: 88a57a6ac5353f54e817a4dd79b5ad84d2070b85
Author: ishbosamiya
Date:   Thu Jun 6 12:48:33 2019 +0530
Branches: soc-2019-adaptive-cloth
https://developer.blender.org/rB88a57a6ac5353f54e817a4dd79b5ad84d2070b85

Cloth: remeshing parameters added

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

M	source/blender/blenkernel/BKE_cloth.h
M	source/blender/blenkernel/intern/cloth.c
M	source/blender/blenlib/BLI_math_matrix.h
M	source/blender/blenlib/intern/math_matrix.c
M	source/blender/makesdna/DNA_cloth_types.h

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

diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h
index 8280563cea5..e19dc0e54a0 100644
--- a/source/blender/blenkernel/BKE_cloth.h
+++ b/source/blender/blenkernel/BKE_cloth.h
@@ -122,6 +122,13 @@ typedef struct ClothVertex {
   float shrink_factor; /* how much to shrink this cloth */
 } ClothVertex;
 
+/**
+ *The definition of sizing used for remeshing
+ */
+typedef struct ClothSizing {
+  float m[2][2];
+} ClothSizing;
+
 /**
  * The definition of a spring.
  */
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index 6be1e342030..4981669b35c 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -152,6 +152,16 @@ void cloth_init(ClothModifierData *clmd)
 
   clmd->sim_parms->bending_model = CLOTH_BENDING_ANGULAR;
 
+  /**
+   *remeshing parameters
+   */
+  clmd->sim_parms->refine_angle = 0.3f;
+  clmd->sim_parms->refine_compression = 0.005f;
+  clmd->sim_parms->refine_velocity = 0.5f;
+  clmd->sim_parms->size_min = 10e-3f;
+  clmd->sim_parms->size_max = 200e-3f;
+  clmd->sim_parms->aspect_min = 0.2f;
+
   if (!clmd->sim_parms->effector_weights) {
     clmd->sim_parms->effector_weights = BKE_effector_add_weights(NULL);
   }
@@ -419,16 +429,9 @@ static void cloth_remeshing_init_bmesh(Object *ob, ClothModifierData *clmd, Mesh
     printf("remeshing_reset has been set to true or bm_prev does not exist\n");
   }
   clmd->clothObject->bm = clmd->clothObject->bm_prev;
-
-  /* BMesh *bm = clmd->clothObject->bm; */
-  /* BM_mesh_elem_table_init(bm, BM_FACE); */
-  /* if (bm->totface > 1) { */
-  /*   BMFace *face = BM_face_at_index(bm, 0); */
-  /*   BM_face_kill_loose(bm, face); */
-  /* } */
 }
 
-static Mesh *cloth_remeshing_update_cloth_object(Object *ob, ClothModifierData *clmd)
+static Mesh *cloth_remeshing_update_cloth_object_bmesh(Object *ob, ClothModifierData *clmd)
 {
   Mesh *mesh_result = NULL;
   CustomData_MeshMasks cddata_masks = cloth_remeshing_get_cd_mesh_masks();
@@ -440,11 +443,44 @@ static Mesh *cloth_remeshing_update_cloth_object(Object *ob, ClothModifierData *
   return mesh_result;
 }
 
+static void cloth_remeshing_static(ClothModifierData *clmd)
+{
+  int numVerts = clmd->clothObject->bm->totvert;
+  ClothSizing *sizing = MEM_mallocN(numVerts * sizeof(ClothSizing), "ClothSizing");
+
+  /**
+   * Define sizing staticly
+   */
+  for (int i = 0; i < numVerts; i++) {
+    unit_m2(sizing[i].m);
+    mul_m2_fl(sizing[i].m, 1.0f / clmd->sim_parms->size_min);
+  }
+
+  /**
+   * Split edges
+   */
+
+  /**
+   * Collapse edges
+   */
+
+  /**
+   * Split edges
+   */
+
+  /**
+   * Delete sizing
+   */
+  MEM_freeN(sizing);
+}
+
 Mesh *cloth_remeshing_step(Object *ob, ClothModifierData *clmd, Mesh *mesh)
 {
   cloth_remeshing_init_bmesh(ob, clmd, mesh);
 
-  return cloth_remeshing_update_cloth_object(ob, clmd);
+  cloth_remeshing_static(clmd);
+
+  return cloth_remeshing_update_cloth_object_bmesh(ob, clmd);
 }
 
 /************************************************
diff --git a/source/blender/blenlib/BLI_math_matrix.h b/source/blender/blenlib/BLI_math_matrix.h
index 52d976daa2d..b4286e3112a 100644
--- a/source/blender/blenlib/BLI_math_matrix.h
+++ b/source/blender/blenlib/BLI_math_matrix.h
@@ -194,6 +194,7 @@ void mul_transposed_m3_v3(const float M[3][3], float r[3]);
 void mul_transposed_mat3_m4_v3(const float M[4][4], float r[3]);
 void mul_m3_v3_double(const float M[3][3], double r[3]);
 
+void mul_m2_fl(float R[2][2], float f);
 void mul_m3_fl(float R[3][3], float f);
 void mul_m4_fl(float R[4][4], float f);
 void mul_mat3_m4_fl(float R[4][4], float f);
diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c
index 71655084b2b..ae557e046db 100644
--- a/source/blender/blenlib/intern/math_matrix.c
+++ b/source/blender/blenlib/intern/math_matrix.c
@@ -782,6 +782,17 @@ void mul_transposed_mat3_m4_v3(const float mat[4][4], float vec[3])
   vec[2] = x * mat[2][0] + y * mat[2][1] + mat[2][2] * vec[2];
 }
 
+void mul_m2_fl(float m[2][2], float f)
+{
+  int i, j;
+
+  for (i = 0; i < 2; i++) {
+    for (j = 0; j < 2; j++) {
+      m[i][j] *= f;
+    }
+  }
+}
+
 void mul_m3_fl(float m[3][3], float f)
 {
   int i, j;
diff --git a/source/blender/makesdna/DNA_cloth_types.h b/source/blender/makesdna/DNA_cloth_types.h
index f9158409cfa..0437bc24308 100644
--- a/source/blender/makesdna/DNA_cloth_types.h
+++ b/source/blender/makesdna/DNA_cloth_types.h
@@ -148,6 +148,14 @@ typedef struct ClothSimSettings {
   float compression_damp;
   /** Mechanical damping of shear springs. */
   float shear_damp;
+
+  /** Remeshing parameters **/
+  float refine_angle;
+  float refine_compression;
+  float refine_velocity;
+  float size_min;
+  float size_max;
+  float aspect_min;
 } ClothSimSettings;
 
 typedef struct ClothCollSettings {



More information about the Bf-blender-cvs mailing list