From 8fda93a4058ac4437d53279c909a44f8eb5b881c Mon Sep 17 00:00:00 2001 From: Sebastian Parborg Date: Mon, 17 Aug 2020 12:33:05 +0200 Subject: Cleanup: Change BLI_bitmap for BLI_edgeset for internal springs The BLI_bitmap had the potential to eat a lot of memory as it was a dense map between all the vertices in the mesh. Now we instead use BLI_edgeset so that we only store data when needed (creating a spare map instead of a dense). --- source/blender/blenkernel/intern/cloth.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'source/blender/blenkernel/intern/cloth.c') diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index 027761335b0..24b4b85d0d4 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -1611,7 +1611,6 @@ static int cloth_build_springs(ClothModifierData *clmd, Mesh *mesh) if (use_internal_springs && numpolys > 0) { BVHTreeFromMesh treedata = {NULL}; unsigned int tar_v_idx; - BLI_bitmap *verts_used = NULL; Mesh *tmp_mesh = NULL; RNG *rng; @@ -1622,7 +1621,7 @@ static int cloth_build_springs(ClothModifierData *clmd, Mesh *mesh) BKE_mesh_calc_normals(tmp_mesh); } - verts_used = BLI_BITMAP_NEW(mvert_num * mvert_num, __func__); + EdgeSet *existing_vert_pairs = BLI_edgeset_new("cloth_sewing_edges_graph"); BKE_bvhtree_from_mesh_get(&treedata, tmp_mesh ? tmp_mesh : mesh, BVHTREE_FROM_LOOPTRI, 2); rng = BLI_rng_new_srandom(0); @@ -1635,12 +1634,12 @@ static int cloth_build_springs(ClothModifierData *clmd, Mesh *mesh) clmd->sim_parms->internal_spring_max_diversion, (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_INTERNAL_SPRINGS_NORMAL), &tar_v_idx)) { - if (BLI_BITMAP_TEST_BOOL(verts_used, i * mvert_num + tar_v_idx)) { + if (BLI_edgeset_haskey(existing_vert_pairs, i, tar_v_idx)) { + /* We have already created a spring between these verts! */ continue; } - BLI_BITMAP_ENABLE(verts_used, i * mvert_num + tar_v_idx); - BLI_BITMAP_ENABLE(verts_used, tar_v_idx * mvert_num + i); + BLI_edgeset_insert(existing_vert_pairs, i, tar_v_idx); spring = (ClothSpring *)MEM_callocN(sizeof(ClothSpring), "cloth spring"); @@ -1666,7 +1665,7 @@ static int cloth_build_springs(ClothModifierData *clmd, Mesh *mesh) } else { cloth_free_errorsprings(cloth, edgelist, spring_ref); - MEM_freeN(verts_used); + BLI_edgeset_free(existing_vert_pairs); free_bvhtree_from_mesh(&treedata); if (tmp_mesh) { BKE_mesh_free(tmp_mesh); @@ -1675,7 +1674,7 @@ static int cloth_build_springs(ClothModifierData *clmd, Mesh *mesh) } } } - MEM_freeN(verts_used); + BLI_edgeset_free(existing_vert_pairs); free_bvhtree_from_mesh(&treedata); if (tmp_mesh) { BKE_mesh_free(tmp_mesh); -- cgit v1.2.3