diff options
author | Sebastian Parborg <darkdefende@gmail.com> | 2020-08-17 13:33:05 +0300 |
---|---|---|
committer | Sebastian Parborg <darkdefende@gmail.com> | 2020-08-17 13:39:40 +0300 |
commit | 8fda93a4058ac4437d53279c909a44f8eb5b881c (patch) | |
tree | 68f760e486d0d4c6c13cc2f50cb258f8e2953124 /source/blender/blenkernel | |
parent | b2d9020aa5d9a6a98cc89a8b5fbd69b12e99d8c5 (diff) |
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).
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/intern/cloth.c | 13 |
1 files changed, 6 insertions, 7 deletions
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); |