Commit: 07e365dbaab8157ae3749787ce72750cd68955e8 Author: ishbosamiya Date: Thu Aug 1 19:47:46 2019 +0530 Branches: soc-2019-adaptive-cloth https://developer.blender.org/rB07e365dbaab8157ae3749787ce72750cd68955e8
Cloth: optimization: uv offset calculated only every frame =================================================================== 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 ee78ede007f..e847ec8be44 100644 --- a/source/blender/blenkernel/intern/cloth_remeshing.cpp +++ b/source/blender/blenkernel/intern/cloth_remeshing.cpp @@ -86,7 +86,7 @@ class ClothPlane { }; #define REMESHING_DATA_DEBUG 0 /* split and collapse edge count */ -#define COLLAPSE_EDGES_DEBUG 1 +#define COLLAPSE_EDGES_DEBUG 0 #define FACE_SIZING_DEBUG 0 #define FACE_SIZING_DEBUG_COMP 0 #define FACE_SIZING_DEBUG_OBS 0 @@ -145,10 +145,13 @@ ClothSizing ClothSizing::operator*(float value) static bool cloth_remeshing_boundary_test(BMVert *v); static bool cloth_remeshing_boundary_test(BMEdge *e); -static bool cloth_remeshing_edge_on_seam_test(BMesh *bm, BMEdge *e); -static bool cloth_remeshing_vert_on_seam_test(BMesh *bm, BMVert *v); -static bool cloth_remeshing_vert_on_seam_or_boundary_test(BMesh *bm, BMVert *v); -static void cloth_remeshing_uv_of_vert_in_face(BMesh *bm, BMFace *f, BMVert *v, float r_uv[2]); +static bool cloth_remeshing_edge_on_seam_test(BMesh *bm, BMEdge *e, const int cd_loop_uv_offset); +static bool cloth_remeshing_vert_on_seam_test(BMesh *bm, BMVert *v, const int cd_loop_uv_offset); +static bool cloth_remeshing_vert_on_seam_or_boundary_test(BMesh *bm, + BMVert *v, + const int cd_loop_uv_offset); +static void cloth_remeshing_uv_of_vert_in_face( + BMesh *bm, BMFace *f, BMVert *v, const int cd_loop_uv_offset, float r_uv[2]); static float cloth_remeshing_wedge(float v_01[2], float v_02[2]); static void cloth_remeshing_update_active_faces(vector<BMFace *> &active_faces, vector<BMFace *> &remove_faces, @@ -163,7 +166,8 @@ static ClothSizing cloth_remeshing_find_average_sizing(ClothSizing &size_01, Clo static void mul_m2_m2m2(float r[2][2], float a[2][2], float b[2][2]); static BMVert *cloth_remeshing_edge_vert(BMEdge *e, int which); static BMVert *cloth_remeshing_edge_vert(BMesh *bm, BMEdge *e, int side, int i, float r_uv[2]); -static BMVert *cloth_remeshing_edge_opposite_vert(BMesh *bm, BMEdge *e, int side, float r_uv[2]); +static BMVert *cloth_remeshing_edge_opposite_vert( + BMesh *bm, BMEdge *e, int side, const int cd_loop_uv_offset, float r_uv[2]); static void cloth_remeshing_edge_face_pair(BMEdge *e, BMFace **r_f1, BMFace **r_f2); static void cloth_remeshing_uv_of_vert_in_edge(BMesh *bm, BMEdge *e, BMVert *v, float r_uv[2]); static bool cloth_remeshing_edge_label_test(BMEdge *e); @@ -202,6 +206,8 @@ static void cloth_remeshing_init_bmesh(Object *ob, BMVert *v; BMIter viter; int i = 0; + const int cd_loop_uv_offset = CustomData_get_offset(&clmd->clothObject->bm_prev->ldata, + CD_MLOOPUV); BM_ITER_MESH_INDEX (v, &viter, clmd->clothObject->bm_prev, BM_VERTS_OF_MESH, i) { mul_m4_v3(ob->obmat, v->co); if (!equals_v3v3(v->co, clmd->clothObject->verts[i].x)) { @@ -215,7 +221,8 @@ static void cloth_remeshing_init_bmesh(Object *ob, copy_v3_v3(v->co, clmd->clothObject->verts[i].x); } cvm[v] = clmd->clothObject->verts[i]; - if (cloth_remeshing_vert_on_seam_or_boundary_test(clmd->clothObject->bm_prev, v)) { + if (cloth_remeshing_vert_on_seam_or_boundary_test( + clmd->clothObject->bm_prev, v, cd_loop_uv_offset)) { cvm[v].flags |= CLOTH_VERT_FLAG_PRESERVE; } } @@ -428,14 +435,17 @@ static Mesh *cloth_remeshing_update_cloth_object_bmesh(Object *ob, ClothModifier /* from Bossen and Heckbert 1996 */ #define CLOTH_REMESHING_EDGE_FLIP_THRESHOLD 0.001f -static bool cloth_remeshing_should_flip(BMesh *bm, BMEdge *e, ClothVertMap &cvm) +static bool cloth_remeshing_should_flip(BMesh *bm, + BMEdge *e, + ClothVertMap &cvm, + const int cd_loop_uv_offset) { BMVert *v1, *v2, *v3, *v4; float x[2], y[2], z[2], w[2]; v1 = cloth_remeshing_edge_vert(bm, e, 0, 0, x); v2 = cloth_remeshing_edge_vert(bm, e, 0, 1, z); - v3 = cloth_remeshing_edge_opposite_vert(bm, e, 0, w); - v4 = cloth_remeshing_edge_opposite_vert(bm, e, 1, y); + v3 = cloth_remeshing_edge_opposite_vert(bm, e, 0, cd_loop_uv_offset, w); + v4 = cloth_remeshing_edge_opposite_vert(bm, e, 1, cd_loop_uv_offset, y); float m[2][2]; ClothSizing size_temp_01 = cloth_remeshing_find_average_sizing(*cvm[v1].sizing, *cvm[v2].sizing); @@ -458,7 +468,9 @@ static bool cloth_remeshing_should_flip(BMesh *bm, BMEdge *e, ClothVertMap &cvm) (cloth_remeshing_wedge(zy, xy) + cloth_remeshing_wedge(xw, zw)); } -static bool cloth_remeshing_edge_on_seam_or_boundary_test(BMesh *bm, BMEdge *e) +static bool cloth_remeshing_edge_on_seam_or_boundary_test(BMesh *bm, + BMEdge *e, + const int cd_loop_uv_offset) { #if 0 BMFace *f1, *f2; @@ -475,22 +487,24 @@ static bool cloth_remeshing_edge_on_seam_or_boundary_test(BMesh *bm, BMEdge *e) return true; } float uv_f1_v1[2], uv_f1_v2[2], uv_f2_v1[2], uv_f2_v2[2]; - cloth_remeshing_uv_of_vert_in_face(bm, f1, e->v1, uv_f1_v1); - cloth_remeshing_uv_of_vert_in_face(bm, f1, e->v2, uv_f1_v2); - cloth_remeshing_uv_of_vert_in_face(bm, f2, e->v1, uv_f2_v1); - cloth_remeshing_uv_of_vert_in_face(bm, f2, e->v2, uv_f2_v2); + cloth_remeshing_uv_of_vert_in_face(bm, f1, e->v1, cd_loop_uv_offset, uv_f1_v1); + cloth_remeshing_uv_of_vert_in_face(bm, f1, e->v2, cd_loop_uv_offset, uv_f1_v2); + cloth_remeshing_uv_of_vert_in_face(bm, f2, e->v1, cd_loop_uv_offset, uv_f2_v1); + cloth_remeshing_uv_of_vert_in_face(bm, f2, e->v2, cd_loop_uv_offset, uv_f2_v2); return (!equals_v2v2(uv_f1_v1, uv_f2_v1) || !equals_v2v2(uv_f1_v2, uv_f2_v2)); #endif } -static bool cloth_remeshing_vert_on_seam_or_boundary_test(BMesh *bm, BMVert *v) +static bool cloth_remeshing_vert_on_seam_or_boundary_test(BMesh *bm, + BMVert *v, + const int cd_loop_uv_offset) { BMEdge *e; BMIter eiter; BM_ITER_ELEM (e, &eiter, v, BM_EDGES_OF_VERT) { - if (cloth_remeshing_edge_on_seam_or_boundary_test(bm, e)) { + if (cloth_remeshing_edge_on_seam_or_boundary_test(bm, e, cd_loop_uv_offset)) { return true; } } @@ -504,7 +518,8 @@ static bool cloth_remeshing_edge_label_test(BMEdge *e) static vector<BMEdge *> cloth_remeshing_find_edges_to_flip(BMesh *bm, ClothVertMap &cvm, - vector<BMFace *> &active_faces) + vector<BMFace *> &active_faces, + const int cd_loop_uv_offset) { vector<BMEdge *> edges; for (int i = 0; i < active_faces.size(); i++) { @@ -517,13 +532,13 @@ static vector<BMEdge *> cloth_remeshing_find_edges_to_flip(BMesh *bm, vector<BMEdge *> fedges; for (int i = 0; i < edges.size(); i++) { BMEdge *e = edges[i]; - if (cloth_remeshing_edge_on_seam_or_boundary_test(bm, e)) { + if (cloth_remeshing_edge_on_seam_or_boundary_test(bm, e, cd_loop_uv_offset)) { continue; } if (cloth_remeshing_edge_label_test(e)) { continue; } - if (!cloth_remeshing_should_flip(bm, e, cvm)) { + if (!cloth_remeshing_should_flip(bm, e, cvm, cd_loop_uv_offset)) { continue; } fedges.push_back(e); @@ -555,10 +570,12 @@ static vector<BMEdge *> cloth_remeshing_find_independent_edges(vector<BMEdge *> static bool cloth_remeshing_flip_edges(BMesh *bm, ClothVertMap &cvm, - vector<BMFace *> &active_faces) + vector<BMFace *> &active_faces, + const int cd_loop_uv_offset) { static int prev_num_independent_edges = 0; - vector<BMEdge *> flipable_edges = cloth_remeshing_find_edges_to_flip(bm, cvm, active_faces); + vector<BMEdge *> flipable_edges = cloth_remeshing_find_edges_to_flip( + bm, cvm, active_faces, cd_loop_uv_offset); vector<BMEdge *> independent_edges = cloth_remeshing_find_independent_edges(flipable_edges); if (independent_edges.size() == prev_num_independent_edges) { return false; @@ -598,10 +615,13 @@ static bool cloth_remeshing_flip_edges(BMesh *bm, return true; } -static bool cloth_remeshing_fix_mesh(BMesh *bm, ClothVertMap &cvm, vector<BMFace *> active_faces) +static bool cloth_remeshing_fix_mesh(BMesh *bm, + ClothVertMap &cvm, + vector<BMFace *> active_faces, + const int cd_loop_uv_offset) { for (int i = 0; i < bm->totvert * 3; i++) { - if (cloth_remeshing_flip_edges(bm, cvm, active_faces) == false) { + if (cloth_remeshing_flip_edges(bm, cvm, active_faces, cd_loop_uv_offset) == false) { break; } } @@ -1016,7 +1036,9 @@ static BMEdge *cloth_remeshing_fix_sewing_verts( } } -static bool cloth_remeshing_split_edges(ClothModifierData *clmd, ClothVertMap &cvm) +static bool cloth_remeshing_split_edges(ClothModifierData *clmd, + ClothVertMap &cvm, + const int cd_loop_uv_offset) { BMesh *bm = clmd->clothObject->bm; static int prev_num_bad_edges = 0; @@ -1052,7 +1074,7 @@ static bool cloth_remeshing_split_edges(ClothModifierData *clmd, ClothVertMap &c BM_ITER_ELEM (af, &afiter, new_vert, BM_FACES_OF_VERT) { active_faces.push_back(af); } - cloth_remeshing_fix_mesh(bm, cvm, active_faces); + cloth_remeshing_fix_mesh(bm, cvm, active_faces, cd_loop_uv_offset); if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SEW) { if (cloth_remeshing_find_next_loo @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs