Commit: c6e48575d6ebd83b4dd660f020b7c200c04b288b Author: ishbosamiya Date: Fri Jul 26 02:07:04 2019 +0530 Branches: soc-2019-adaptive-cloth https://developer.blender.org/rBc6e48575d6ebd83b4dd660f020b7c200c04b288b
Cloth: nearly completed transition to using ClothVertMap =================================================================== 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 d641fcbeb67..4a2d7fc2ae5 100644 --- a/source/blender/blenkernel/intern/cloth_remeshing.cpp +++ b/source/blender/blenkernel/intern/cloth_remeshing.cpp @@ -78,7 +78,7 @@ using namespace std; * reference http://graphics.berkeley.edu/papers/Narain-AAR-2012-11/index.html ******************************************************************************/ -typedef map<BMVert *, ClothVertex> VertMap; +typedef map<BMVert *, ClothVertex> ClothVertMap; #define COLLAPSE_EDGES_DEBUG 1 #define NEXT(x) ((x) < 2 ? (x) + 1 : (x)-2) @@ -110,7 +110,7 @@ static bool cloth_remeshing_vert_on_seam_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 float cloth_remeshing_wedge(float v_01[2], float v_02[2]); static float cloth_remeshing_edge_size_with_vert( - BMesh *bm, BMVert *v1, BMVert *v2, BMVert *v, map<BMVert *, ClothSizing> &sizing); + BMesh *bm, BMVert *v1, BMVert *v2, BMVert *v, ClothVertMap &cvm); static void cloth_remeshing_update_active_faces(vector<BMFace *> &active_faces, BMesh *bm, BMVert *v); @@ -137,7 +137,10 @@ static CustomData_MeshMasks cloth_remeshing_get_cd_mesh_masks(void) return cddata_masks; } -static void cloth_remeshing_init_bmesh(Object *ob, ClothModifierData *clmd, Mesh *mesh) +static void cloth_remeshing_init_bmesh(Object *ob, + ClothModifierData *clmd, + Mesh *mesh, + ClothVertMap &cvm) { if (clmd->sim_parms->remeshing_reset || !clmd->clothObject->bm_prev) { cloth_to_mesh(ob, clmd, mesh); @@ -159,7 +162,10 @@ static void cloth_remeshing_init_bmesh(Object *ob, ClothModifierData *clmd, Mesh int i = 0; BM_ITER_MESH_INDEX (v, &viter, clmd->clothObject->bm_prev, BM_VERTS_OF_MESH, i) { copy_v3_v3(v->co, clmd->clothObject->verts[i].x); + cvm[v] = clmd->clothObject->verts[i]; } + /* TODO(Ish): delete the existing clmd->clothObject->verts because + * it is duplicated into cvm */ BM_mesh_normals_update(clmd->clothObject->bm_prev); @@ -178,11 +184,17 @@ static void cloth_remeshing_init_bmesh(Object *ob, ClothModifierData *clmd, Mesh BMIter viter; int i = 0; BM_ITER_MESH_INDEX (v, &viter, clmd->clothObject->bm_prev, BM_VERTS_OF_MESH, i) { - copy_v3_v3(v->co, clmd->clothObject->verts[i].x); + copy_v3_v3(v->co, cvm[v].x); } } clmd->clothObject->mvert_num_prev = clmd->clothObject->mvert_num; clmd->clothObject->bm = clmd->clothObject->bm_prev; + + if (clmd->clothObject->verts != NULL) { + MEM_freeN(clmd->clothObject->verts); + clmd->clothObject->verts = NULL; + } + clmd->clothObject->mvert_num = 0; } static ClothVertex cloth_remeshing_mean_cloth_vert(ClothVertex *v1, ClothVertex *v2) @@ -240,21 +252,40 @@ static ClothVertex cloth_remeshing_mean_cloth_vert(ClothVertex *v1, ClothVertex return new_vert; } -static Mesh *cloth_remeshing_update_cloth_object_bmesh(Object *ob, ClothModifierData *clmd) +static Mesh *cloth_remeshing_update_cloth_object_bmesh(Object *ob, + ClothModifierData *clmd, + ClothVertMap &cvm) { Mesh *mesh_result = NULL; + Cloth *cloth = clmd->clothObject; CustomData_MeshMasks cddata_masks = cloth_remeshing_get_cd_mesh_masks(); mesh_result = BKE_mesh_from_bmesh_for_eval_nomain(clmd->clothObject->bm, &cddata_masks); + /* Allocate our vertices since they were removed before the + * remeshing step */ + const unsigned int mvert_num = mesh_result->totvert; + clmd->clothObject->mvert_num = mvert_num; + clmd->clothObject->verts = (ClothVertex *)MEM_callocN( + sizeof(ClothVertex) * clmd->clothObject->mvert_num, "clothVertex"); + if (clmd->clothObject->verts == NULL) { + cloth_free_modifier(clmd); + modifier_setError(&(clmd->modifier), "Out of memory on allocating clmd->clothObject->verts"); + printf("cloth_free_modifier clmd->clothObject->verts\n"); + return NULL; + } + BMVert *v; + BMIter viter; + int v_index = 0; + BM_ITER_MESH_INDEX (v, &viter, clmd->clothObject->bm, BM_VERTS_OF_MESH, v_index) { + cloth->verts[v_index] = cvm[v]; + } + if (clmd->clothObject->mvert_num_prev == clmd->clothObject->mvert_num) { clmd->clothObject->bm_prev = BM_mesh_copy(clmd->clothObject->bm); BM_mesh_free(clmd->clothObject->bm); clmd->clothObject->bm = NULL; return mesh_result; } - /* cloth_remeshing_update_cloth_object_mesh(clmd, mesh_result); */ - /**/ - Cloth *cloth = clmd->clothObject; // Free the springs. if (cloth->springs != NULL) { LinkNode *search = cloth->springs; @@ -382,7 +413,7 @@ static pair<BMVert *, BMVert *> cloth_remeshing_edge_side_verts(BMEdge *e) /* from Bossen and Heckbert 1996 */ #define CLOTH_REMESHING_EDGE_FLIP_THRESHOLD 0.001f -static bool cloth_remeshing_should_flip(BMesh *bm, BMEdge *e, map<BMVert *, ClothSizing> &sizing) +static bool cloth_remeshing_should_flip(BMesh *bm, BMEdge *e, ClothVertMap &cvm) { BMVert *v1, *v2, *v3, *v4; float x[2], y[2], z[2], w[2]; @@ -392,9 +423,8 @@ static bool cloth_remeshing_should_flip(BMesh *bm, BMEdge *e, map<BMVert *, Clot v4 = cloth_remeshing_edge_opposite_vert(bm, e, 1, y); float m[2][2]; - /* TODO(Ish): need to fix this when sizing is improved */ - ClothSizing size_temp_01 = cloth_remeshing_find_average_sizing(sizing[v1], sizing[v2]); - ClothSizing size_temp_02 = cloth_remeshing_find_average_sizing(sizing[v3], sizing[v4]); + ClothSizing size_temp_01 = cloth_remeshing_find_average_sizing(*cvm[v1].sizing, *cvm[v2].sizing); + ClothSizing size_temp_02 = cloth_remeshing_find_average_sizing(*cvm[v3].sizing, *cvm[v4].sizing); ClothSizing size_temp = cloth_remeshing_find_average_sizing(size_temp_01, size_temp_02); copy_m2_m2(m, size_temp.m); @@ -414,7 +444,7 @@ static bool cloth_remeshing_should_flip(BMesh *bm, BMEdge *e, map<BMVert *, Clot } static bool cloth_remeshing_should_flip( - BMesh *bm, BMVert *v1, BMVert *v2, BMVert *v3, BMVert *v4, map<BMVert *, ClothSizing> &sizing) + BMesh *bm, BMVert *v1, BMVert *v2, BMVert *v3, BMVert *v4, ClothVertMap &cvm) { BMFace *f1, *f2; cloth_remeshing_edge_face_pair(BM_edge_exists(v1, v2), &f1, &f2); @@ -425,9 +455,8 @@ static bool cloth_remeshing_should_flip( cloth_remeshing_uv_of_vert_in_face(bm, f1, v3, w); float m[2][2]; - /* TODO(Ish): need to fix this when sizing is improved */ - ClothSizing size_temp_01 = cloth_remeshing_find_average_sizing(sizing[v1], sizing[v2]); - ClothSizing size_temp_02 = cloth_remeshing_find_average_sizing(sizing[v3], sizing[v4]); + ClothSizing size_temp_01 = cloth_remeshing_find_average_sizing(*cvm[v1].sizing, *cvm[v2].sizing); + ClothSizing size_temp_02 = cloth_remeshing_find_average_sizing(*cvm[v3].sizing, *cvm[v4].sizing); ClothSizing size_temp = cloth_remeshing_find_average_sizing(size_temp_01, size_temp_02); copy_m2_m2(m, size_temp.m); @@ -505,7 +534,7 @@ static bool cloth_remeshing_vert_on_seam_or_boundary_test(BMesh *bm, BMVert *v) #if 1 static vector<BMEdge *> cloth_remeshing_find_edges_to_flip(BMesh *bm, - map<BMVert *, ClothSizing> &sizing, + ClothVertMap &cvm, vector<BMFace *> &active_faces) { vector<BMEdge *> edges; @@ -522,7 +551,7 @@ static vector<BMEdge *> cloth_remeshing_find_edges_to_flip(BMesh *bm, if (cloth_remeshing_edge_on_seam_or_boundary_test(bm, e)) { continue; } - if (!cloth_remeshing_should_flip(bm, e, sizing)) { + if (!cloth_remeshing_should_flip(bm, e, cvm)) { continue; } fedges.push_back(e); @@ -531,7 +560,7 @@ static vector<BMEdge *> cloth_remeshing_find_edges_to_flip(BMesh *bm, } #else static vector<BMEdge *> cloth_remeshing_find_edges_to_flip(BMesh *bm, - map<BMVert *, ClothSizing> &sizing, + ClothVertMap &cvm, vector<BMFace *> &active_faces) { vector<BMEdge *> edges; @@ -575,11 +604,11 @@ static vector<BMEdge *> cloth_remeshing_find_edges_to_flip(BMesh *bm, continue; } - if (cloth_remeshing_edge_size_with_vert(bm, v3, v4, e->v1, sizing) > 1.0f) { + if (cloth_remeshing_edge_size_with_vert(bm, v3, v4, e->v1, cvm) > 1.0f) { continue; } - if (!cloth_remeshing_should_flip(bm, v1, v2, v3, v4, sizing)) { + if (!cloth_remeshing_should_flip(bm, v1, v2, v3, v4, cvm)) { continue; } @@ -614,11 +643,11 @@ static vector<BMEdge *> cloth_remeshing_find_independent_edges(vector<BMEdge *> } static bool cloth_remeshing_flip_edges(BMesh *bm, - map<BMVert *, ClothSizing> &sizing, + ClothVertMap &cvm, vector<BMFace *> &active_faces) { static int prev_num_independent_edges = 0; - vector<BMEdge *> flipable_edges = cloth_remeshing_find_edges_to_flip(bm, sizing, active_faces); + vector<BMEdge *> flipable_edges = cloth_remeshing_find_edges_to_flip(bm, cvm, active_faces); vector<BMEdge *> independent_edges = cloth_remeshing_find_independent_edges(flipable_edges); if (independent_edges.size() == prev_num_independent_edges) { return false; @@ -636,12 +665,10 @@ static bool cloth_remeshing_flip_edges(BMesh *bm, return true; } -static bool cloth_remeshing_fix_mesh(BMesh *bm, - map<BMVert *, ClothSizing> &sizing, - vector<BMFace *> active_faces) +static bool cloth_remeshing_fix_mesh(BMesh *bm, ClothVertMap &cvm, vector<BMFace *> active_fa @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list [email protected] https://lists.blender.org/mailman/listinfo/bf-blender-cvs
