[Bf-blender-cvs] [f5e098dd113] soc-2019-adaptive-cloth: Cloth: added derivative and compression metric support
ishbosamiya
noreply at git.blender.org
Fri Jul 19 11:16:20 CEST 2019
Commit: f5e098dd113b6f2eba67135a970a953c50cc61f5
Author: ishbosamiya
Date: Thu Jul 18 19:36:48 2019 +0530
Branches: soc-2019-adaptive-cloth
https://developer.blender.org/rBf5e098dd113b6f2eba67135a970a953c50cc61f5
Cloth: added derivative and compression metric support
===================================================================
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 e3223135d99..dbb212758bd 100644
--- a/source/blender/blenkernel/intern/cloth_remeshing.cpp
+++ b/source/blender/blenkernel/intern/cloth_remeshing.cpp
@@ -130,6 +130,7 @@ static void cloth_remeshing_update_active_faces(vector<BMFace *> &active_faces,
BMesh *bm,
BMEdge *e);
static ClothSizing cloth_remeshing_find_average_sizing(ClothSizing &size_01, ClothSizing &size_02);
+static void mul_m2_m2m2(float r[2][2], float a[2][2], float b[2][2]);
static CustomData_MeshMasks cloth_remeshing_get_cd_mesh_masks(void)
{
@@ -520,7 +521,6 @@ static void cloth_remeshing_flip_edges(BMesh *bm,
/* BM_EDGEROT_CHECK_SPLICE sets it up for BM_CREATE_NO_DOUBLE */
BMEdge *new_edge = BM_edge_rotate(bm, edge, true, BM_EDGEROT_CHECK_SPLICE);
BLI_assert(new_edge != NULL);
- /* TODO(Ish): need to update active_faces */
cloth_remeshing_update_active_faces(active_faces, bm, new_edge);
}
}
@@ -1597,6 +1597,18 @@ static void cloth_remeshing_dynamic(ClothModifierData *clmd)
#endif
}
+static void cloth_remeshing_face_data(BMesh *bm, BMFace *f, float r_mat[2][2])
+{
+ BMVert *v[3];
+ float uv[3][2];
+ BM_face_as_array_vert_tri(f, v);
+ for (int i = 0; i < 3; i++) {
+ cloth_remeshing_uv_of_vert_in_face(bm, f, v[i], uv[i]);
+ }
+ sub_v2_v2v2(r_mat[0], uv[1], uv[0]);
+ sub_v2_v2v2(r_mat[1], uv[2], uv[0]);
+}
+
static float cloth_remeshing_calc_area(BMesh *bm, BMFace *f)
{
/* TODO(Ish): Area calculation might be with respect to World Space, need
@@ -1660,6 +1672,35 @@ static void cloth_remeshing_eigen_decomposition(float mat[2][2], float r_mat[2][
}
}
+static void diag_m2_v2(float r[2][2], float a[2])
+{
+ zero_m2(r);
+ for (int i = 0; i < 2; i++) {
+ r[i][i] = a[i];
+ }
+}
+
+static void cloth_remeshing_compression_metric(float mat[2][2], float r_mat[2][2])
+{
+ float l[2];
+ float q[2][2];
+
+ cloth_remeshing_eigen_decomposition(mat, q, l);
+ float q_t[2][2];
+ copy_m2_m2(q_t, q);
+ transpose_m2(q_t);
+
+ for (int i = 0; i < 2; i++) {
+ l[i] = max(1 - sqrtf(l[i]), 0.0f);
+ }
+
+ float temp_mat[2][2];
+ float diag_l[2][2];
+ diag_m2_v2(diag_l, l);
+ mul_m2_m2m2(temp_mat, q, diag_l);
+ mul_m2_m2m2(r_mat, temp_mat, q_t);
+}
+
#define NEXT(x) ((x) < 2 ? (x) + 1 : (x)-2)
#define PREV(x) ((x) > 0 ? (x)-1 : (x) + 2)
@@ -1729,13 +1770,55 @@ static void cloth_remeshing_curvature(BMesh *bm, BMFace *f, float r_mat[2][2])
mul_m2_fl(r_mat, 1.0f / cloth_remeshing_calc_area(bm, f));
}
+static void transpose_m32_m23(float r_mat[3][2], float mat[2][3])
+{
+ r_mat[0][0] = mat[0][0];
+ r_mat[0][1] = mat[1][0];
+
+ r_mat[1][0] = mat[0][1];
+ r_mat[1][1] = mat[1][1];
+
+ r_mat[2][0] = mat[0][2];
+ r_mat[2][1] = mat[1][2];
+}
+
+static void zero_m32(float r[3][2])
+{
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 2; j++) {
+ r[i][j] = 0.0f;
+ }
+ }
+}
+
+static void mul_m32_m32m22(float r[3][2], float a[3][2], float b[2][2])
+{
+ zero_m32(r);
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 2; j++) {
+ for (int k = 0; k < 2; k++) {
+ r[i][j] += a[i][k] * b[k][j];
+ }
+ }
+ }
+}
+
static void cloth_remeshing_derivative(
- float m_01[3], float m_02[3], float m_03[3], BMFace *f, float r_mat[3][2])
+ BMesh *bm, float m_01[3], float m_02[3], float m_03[3], BMFace *f, float r_mat[3][2])
{
- /* TODO(Ish) */
+ float mat[2][3];
+ sub_v3_v3v3(mat[0], m_02, m_01);
+ sub_v3_v3v3(mat[1], m_03, m_01);
+ float mat_t[3][2];
+ transpose_m32_m23(mat_t, mat);
+
+ float face_dm_inv[2][2];
+ cloth_remeshing_face_data(bm, f, face_dm_inv);
+ transpose_m2(face_dm_inv);
+ mul_m32_m32m22(r_mat, mat_t, face_dm_inv);
}
-static void transpose_m32(float r_mat[2][3], float mat[3][2])
+static void transpose_m23_m32(float r_mat[2][3], float mat[3][2])
{
r_mat[0][0] = mat[0][0];
r_mat[0][1] = mat[1][0];
@@ -1785,22 +1868,25 @@ static ClothSizing cloth_remeshing_compute_face_sizing(ClothModifierData *clmd,
float sizing_s[2][2];
cloth_remeshing_curvature(bm, f, sizing_s);
float sizing_f[3][2];
- cloth_remeshing_derivative(cv[0]->x, cv[1]->x, cv[2]->x, f, sizing_f);
+ cloth_remeshing_derivative(bm, cv[0]->x, cv[1]->x, cv[2]->x, f, sizing_f);
float sizing_v[3][2];
- cloth_remeshing_derivative(cv[0]->v, cv[1]->v, cv[2]->v, f, sizing_v);
+ cloth_remeshing_derivative(bm, cv[0]->v, cv[1]->v, cv[2]->v, f, sizing_v);
float sizing_s_t[2][2];
copy_m2_m2(sizing_s_t, sizing_s);
transpose_m2(sizing_s_t);
+ float sizing_f_t[2][3];
+ transpose_m23_m32(sizing_f_t, sizing_f);
float sizing_v_t[2][3];
- transpose_m32(sizing_v_t, sizing_v);
+ transpose_m23_m32(sizing_v_t, sizing_v);
float curv[2][2];
mul_m2_m2m2(curv, sizing_s_t, sizing_s);
- /* TODO(Ish): compression metric */
float comp[2][2];
- zero_m2(comp);
+ float f_x_ft[2][2];
+ mul_m2_m23m32(f_x_ft, sizing_f_t, sizing_f);
+ cloth_remeshing_compression_metric(f_x_ft, comp);
float dvel[2][2];
mul_m2_m23m32(dvel, sizing_v_t, sizing_v);
@@ -1844,10 +1930,7 @@ static ClothSizing cloth_remeshing_compute_face_sizing(ClothModifierData *clmd,
float result[2][2];
float temp_result[2][2];
float diag_l[2][2];
- zero_m2(diag_l);
- for (int i = 0; i < 2; i++) {
- diag_l[i][i] = l[i];
- }
+ diag_m2_v2(diag_l, l);
float q_t[2][2];
copy_m2_m2(q_t, q);
transpose_m2(q_t);
More information about the Bf-blender-cvs
mailing list