[Bf-blender-cvs] [0b546f15d69] soc-2019-adaptive-cloth: Cloth: fix derivative function

ishbosamiya noreply at git.blender.org
Fri Jul 19 18:55:40 CEST 2019


Commit: 0b546f15d690feb919dae2d177d2ea9cd17f9724
Author: ishbosamiya
Date:   Fri Jul 19 20:40:07 2019 +0530
Branches: soc-2019-adaptive-cloth
https://developer.blender.org/rB0b546f15d690feb919dae2d177d2ea9cd17f9724

Cloth: fix derivative function

The matrix was being transposed instead of inversing.

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

M	source/blender/blenkernel/intern/cloth_remeshing.cpp
M	source/blender/blenlib/BLI_math_matrix.h
M	source/blender/blenlib/intern/math_matrix.c

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

diff --git a/source/blender/blenkernel/intern/cloth_remeshing.cpp b/source/blender/blenkernel/intern/cloth_remeshing.cpp
index a550ddefb91..d5304041de3 100644
--- a/source/blender/blenkernel/intern/cloth_remeshing.cpp
+++ b/source/blender/blenkernel/intern/cloth_remeshing.cpp
@@ -1818,9 +1818,10 @@ static void cloth_remeshing_derivative(
   float mat_t[3][2];
   transpose_m32_m23(mat_t, mat);
 
+  float face_dm[2][2];
   float face_dm_inv[2][2];
-  cloth_remeshing_face_data(bm, f, face_dm_inv);
-  transpose_m2(face_dm_inv);
+  cloth_remeshing_face_data(bm, f, face_dm);
+  invert_m2_m2(face_dm_inv, face_dm);
   mul_m32_m32m22(r_mat, mat_t, face_dm_inv);
 }
 
@@ -2075,7 +2076,7 @@ Mesh *cloth_remeshing_step(Object *ob, ClothModifierData *clmd, Mesh *mesh)
 {
   cloth_remeshing_init_bmesh(ob, clmd, mesh);
 
-  if (true) {
+  if (false) {
     cloth_remeshing_static(clmd);
   }
   else {
diff --git a/source/blender/blenlib/BLI_math_matrix.h b/source/blender/blenlib/BLI_math_matrix.h
index b54a58bab21..7f38c5bec2c 100644
--- a/source/blender/blenlib/BLI_math_matrix.h
+++ b/source/blender/blenlib/BLI_math_matrix.h
@@ -208,6 +208,7 @@ void negate_m4(float R[4][4]);
 bool invert_m3_ex(float m[3][3], const float epsilon);
 bool invert_m3_m3_ex(float m1[3][3], const float m2[3][3], const float epsilon);
 
+bool invert_m2_m2(float r[2][2], float m[2][2]);
 bool invert_m3(float R[3][3]);
 bool invert_m3_m3(float R[3][3], const float A[3][3]);
 bool invert_m4(float R[4][4]);
diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c
index 1eba3645a79..7f5db8d7a6b 100644
--- a/source/blender/blenlib/intern/math_matrix.c
+++ b/source/blender/blenlib/intern/math_matrix.c
@@ -971,6 +971,21 @@ float determinant_m4_mat3_array(const float m[4][4])
           m[2][0] * (m[0][1] * m[1][2] - m[0][2] * m[1][1]));
 }
 
+bool invert_m2_m2(float r[2][2], float m[2][2])
+{
+  float det = determinant_m2(m[0][0], m[0][1], m[1][0], m[1][1]);
+  if (det == 0) {
+    return false;
+  }
+  r[0][0] = m[1][1];
+  r[0][1] = -m[0][1];
+
+  r[1][0] = -m[1][0];
+  r[1][1] = m[0][0];
+  mul_m2_fl(r, 1.0f / det);
+  return true;
+}
+
 bool invert_m3_ex(float m[3][3], const float epsilon)
 {
   float tmp[3][3];



More information about the Bf-blender-cvs mailing list