diff options
author | Germano Cavalcante <germano.costa@ig.com.br> | 2020-07-06 20:44:30 +0300 |
---|---|---|
committer | Germano Cavalcante <germano.costa@ig.com.br> | 2020-07-06 20:44:30 +0300 |
commit | 12817083ec615f9d3e3f0261d5d4247b81bfbbf8 (patch) | |
tree | c9fc06e39d36453bb702ceb5cee93e1e05a21629 /source/blender/blenkernel | |
parent | a856de700b4274ebc1735aa349f7425c7c23cbfc (diff) |
Cleanup: Use the BLI_edgehash API in the sewing simulation of cloths
Also remove the code in the ghash that is no longer used.
This change simplifies the existing code.
Differential Revision: https://developer.blender.org/D8219
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_cloth.h | 8 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/cloth.c | 26 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/collision.c | 14 |
3 files changed, 12 insertions, 36 deletions
diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h index f25482570b1..cd78746a3f0 100644 --- a/source/blender/blenkernel/BKE_cloth.h +++ b/source/blender/blenkernel/BKE_cloth.h @@ -93,10 +93,10 @@ typedef struct Cloth { struct Implicit_Data *implicit; /* our implicit solver connects to this pointer */ struct EdgeSet *edgeset; /* used for selfcollisions */ int last_frame; - float initial_mesh_volume; /* Initial volume of the mesh. Used for pressure */ - float average_acceleration[3]; /* Moving average of overall acceleration. */ - struct MEdge *edges; /* Used for hair collisions. */ - struct GHash *sew_edge_graph; /* Sewing edges represented using a GHash */ + float initial_mesh_volume; /* Initial volume of the mesh. Used for pressure */ + float average_acceleration[3]; /* Moving average of overall acceleration. */ + struct MEdge *edges; /* Used for hair collisions. */ + struct EdgeSet *sew_edge_graph; /* Sewing edges represented using a GHash */ } Cloth; /** diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index 6b25095a87a..7c8c1cf6653 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -30,7 +30,6 @@ #include "DNA_scene_types.h" #include "BLI_edgehash.h" -#include "BLI_ghash.h" #include "BLI_linklist.h" #include "BLI_math.h" #include "BLI_rand.h" @@ -587,7 +586,7 @@ void cloth_free_modifier(ClothModifierData *clmd) } if (cloth->sew_edge_graph) { - BLI_ghash_free(cloth->sew_edge_graph, MEM_freeN, NULL); + BLI_edgeset_free(cloth->sew_edge_graph); cloth->sew_edge_graph = NULL; } @@ -669,7 +668,7 @@ void cloth_free_modifier_extern(ClothModifierData *clmd) } if (cloth->sew_edge_graph) { - BLI_ghash_free(cloth->sew_edge_graph, MEM_freeN, NULL); + BLI_edgeset_free(cloth->sew_edge_graph); cloth->sew_edge_graph = NULL; } @@ -1557,9 +1556,8 @@ static bool find_internal_spring_target_vertex(BVHTreeFromMesh *treedata, *r_tar_v_idx = vert_idx; return true; } - - return false; - + + return false; } static int cloth_build_springs(ClothModifierData *clmd, Mesh *mesh) @@ -1693,8 +1691,7 @@ static int cloth_build_springs(ClothModifierData *clmd, Mesh *mesh) if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SEW) { /* cloth->sew_edge_graph should not exist before this */ BLI_assert(cloth->sew_edge_graph == NULL); - cloth->sew_edge_graph = BLI_ghash_new( - BLI_ghashutil_inthash_v2_p, BLI_ghashutil_inthash_v2_cmp, "cloth_sewing_edges_graph"); + cloth->sew_edge_graph = BLI_edgeset_new("cloth_sewing_edges_graph"); } /* Structural springs. */ @@ -1709,18 +1706,7 @@ static int cloth_build_springs(ClothModifierData *clmd, Mesh *mesh) spring->lin_stiffness = 1.0f; spring->type = CLOTH_SPRING_TYPE_SEWING; - /* set indices of verts of the sewing edge symmetrically in sew_edge_graph */ - unsigned int *vertex_index_pair = MEM_mallocN(sizeof(unsigned int) * 2, - "sewing_edge_index_pair_01"); - if (medge[i].v1 < medge[i].v2) { - vertex_index_pair[0] = medge[i].v1; - vertex_index_pair[1] = medge[i].v2; - } - else { - vertex_index_pair[0] = medge[i].v2; - vertex_index_pair[1] = medge[i].v1; - } - BLI_ghash_insert(cloth->sew_edge_graph, vertex_index_pair, NULL); + BLI_edgeset_insert(cloth->sew_edge_graph, medge[i].v1, medge[i].v2); } else { shrink_factor = cloth_shrink_factor(clmd, cloth->verts, spring->ij, spring->kl); diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c index daf1602319f..31d49dd4508 100644 --- a/source/blender/blenkernel/intern/collision.c +++ b/source/blender/blenkernel/intern/collision.c @@ -32,7 +32,7 @@ #include "DNA_scene_types.h" #include "BLI_blenlib.h" -#include "BLI_ghash.h" +#include "BLI_edgehash.h" #include "BLI_linklist.h" #include "BLI_math.h" #include "BLI_task.h" @@ -1153,17 +1153,7 @@ static bool cloth_bvh_selfcollision_is_active(const Cloth *cloth, } if (sewing_active) { - unsigned int vertex_index_pair[2]; - /* The indices pair are ordered, thus must ensure the same here as well */ - if (tri_a->tri[i] < tri_b->tri[j]) { - vertex_index_pair[0] = tri_a->tri[i]; - vertex_index_pair[1] = tri_b->tri[j]; - } - else { - vertex_index_pair[0] = tri_b->tri[j]; - vertex_index_pair[1] = tri_a->tri[i]; - } - if (BLI_ghash_haskey(cloth->sew_edge_graph, vertex_index_pair)) { + if (BLI_edgeset_haskey(cloth->sew_edge_graph, tri_a->tri[i], tri_b->tri[j])) { return false; } } |