[Bf-blender-cvs] [8fda93a4058] master: Cleanup: Change BLI_bitmap for BLI_edgeset for internal springs

Sebastian Parborg noreply at git.blender.org
Mon Aug 17 12:39:44 CEST 2020


Commit: 8fda93a4058ac4437d53279c909a44f8eb5b881c
Author: Sebastian Parborg
Date:   Mon Aug 17 12:33:05 2020 +0200
Branches: master
https://developer.blender.org/rB8fda93a4058ac4437d53279c909a44f8eb5b881c

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).

===================================================================

M	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);



More information about the Bf-blender-cvs mailing list