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
This commit is contained in:
@@ -93,10 +93,10 @@ typedef struct Cloth {
|
|||||||
struct Implicit_Data *implicit; /* our implicit solver connects to this pointer */
|
struct Implicit_Data *implicit; /* our implicit solver connects to this pointer */
|
||||||
struct EdgeSet *edgeset; /* used for selfcollisions */
|
struct EdgeSet *edgeset; /* used for selfcollisions */
|
||||||
int last_frame;
|
int last_frame;
|
||||||
float initial_mesh_volume; /* Initial volume of the mesh. Used for pressure */
|
float initial_mesh_volume; /* Initial volume of the mesh. Used for pressure */
|
||||||
float average_acceleration[3]; /* Moving average of overall acceleration. */
|
float average_acceleration[3]; /* Moving average of overall acceleration. */
|
||||||
struct MEdge *edges; /* Used for hair collisions. */
|
struct MEdge *edges; /* Used for hair collisions. */
|
||||||
struct GHash *sew_edge_graph; /* Sewing edges represented using a GHash */
|
struct EdgeSet *sew_edge_graph; /* Sewing edges represented using a GHash */
|
||||||
} Cloth;
|
} Cloth;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -30,7 +30,6 @@
|
|||||||
#include "DNA_scene_types.h"
|
#include "DNA_scene_types.h"
|
||||||
|
|
||||||
#include "BLI_edgehash.h"
|
#include "BLI_edgehash.h"
|
||||||
#include "BLI_ghash.h"
|
|
||||||
#include "BLI_linklist.h"
|
#include "BLI_linklist.h"
|
||||||
#include "BLI_math.h"
|
#include "BLI_math.h"
|
||||||
#include "BLI_rand.h"
|
#include "BLI_rand.h"
|
||||||
@@ -587,7 +586,7 @@ void cloth_free_modifier(ClothModifierData *clmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cloth->sew_edge_graph) {
|
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;
|
cloth->sew_edge_graph = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -669,7 +668,7 @@ void cloth_free_modifier_extern(ClothModifierData *clmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cloth->sew_edge_graph) {
|
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;
|
cloth->sew_edge_graph = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1557,9 +1556,8 @@ static bool find_internal_spring_target_vertex(BVHTreeFromMesh *treedata,
|
|||||||
*r_tar_v_idx = vert_idx;
|
*r_tar_v_idx = vert_idx;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cloth_build_springs(ClothModifierData *clmd, Mesh *mesh)
|
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) {
|
if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SEW) {
|
||||||
/* cloth->sew_edge_graph should not exist before this */
|
/* cloth->sew_edge_graph should not exist before this */
|
||||||
BLI_assert(cloth->sew_edge_graph == NULL);
|
BLI_assert(cloth->sew_edge_graph == NULL);
|
||||||
cloth->sew_edge_graph = BLI_ghash_new(
|
cloth->sew_edge_graph = BLI_edgeset_new("cloth_sewing_edges_graph");
|
||||||
BLI_ghashutil_inthash_v2_p, BLI_ghashutil_inthash_v2_cmp, "cloth_sewing_edges_graph");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Structural springs. */
|
/* Structural springs. */
|
||||||
@@ -1709,18 +1706,7 @@ static int cloth_build_springs(ClothModifierData *clmd, Mesh *mesh)
|
|||||||
spring->lin_stiffness = 1.0f;
|
spring->lin_stiffness = 1.0f;
|
||||||
spring->type = CLOTH_SPRING_TYPE_SEWING;
|
spring->type = CLOTH_SPRING_TYPE_SEWING;
|
||||||
|
|
||||||
/* set indices of verts of the sewing edge symmetrically in sew_edge_graph */
|
BLI_edgeset_insert(cloth->sew_edge_graph, medge[i].v1, medge[i].v2);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
shrink_factor = cloth_shrink_factor(clmd, cloth->verts, spring->ij, spring->kl);
|
shrink_factor = cloth_shrink_factor(clmd, cloth->verts, spring->ij, spring->kl);
|
||||||
|
@@ -32,7 +32,7 @@
|
|||||||
#include "DNA_scene_types.h"
|
#include "DNA_scene_types.h"
|
||||||
|
|
||||||
#include "BLI_blenlib.h"
|
#include "BLI_blenlib.h"
|
||||||
#include "BLI_ghash.h"
|
#include "BLI_edgehash.h"
|
||||||
#include "BLI_linklist.h"
|
#include "BLI_linklist.h"
|
||||||
#include "BLI_math.h"
|
#include "BLI_math.h"
|
||||||
#include "BLI_task.h"
|
#include "BLI_task.h"
|
||||||
@@ -1153,17 +1153,7 @@ static bool cloth_bvh_selfcollision_is_active(const Cloth *cloth,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sewing_active) {
|
if (sewing_active) {
|
||||||
unsigned int vertex_index_pair[2];
|
if (BLI_edgeset_haskey(cloth->sew_edge_graph, tri_a->tri[i], tri_b->tri[j])) {
|
||||||
/* 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)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -371,20 +371,6 @@ unsigned int BLI_ghashutil_uinthash_v4_murmur(const unsigned int key[4]);
|
|||||||
bool BLI_ghashutil_uinthash_v4_cmp(const void *a, const void *b);
|
bool BLI_ghashutil_uinthash_v4_cmp(const void *a, const void *b);
|
||||||
#define BLI_ghashutil_inthash_v4_cmp BLI_ghashutil_uinthash_v4_cmp
|
#define BLI_ghashutil_inthash_v4_cmp BLI_ghashutil_uinthash_v4_cmp
|
||||||
|
|
||||||
unsigned int BLI_ghashutil_uinthash_v2(const unsigned int key[2]);
|
|
||||||
#define BLI_ghashutil_inthash_v2(key) \
|
|
||||||
(CHECK_TYPE_ANY(key, int *, const int *), BLI_ghashutil_uinthash_v2((const unsigned int *)key))
|
|
||||||
#define BLI_ghashutil_inthash_v2_p ((GSetHashFP)BLI_ghashutil_uinthash_v2)
|
|
||||||
#define BLI_ghashutil_uinthash_v2_p ((GSetHashFP)BLI_ghashutil_uinthash_v2)
|
|
||||||
unsigned int BLI_ghashutil_uinthash_v2_murmur(const unsigned int key[2]);
|
|
||||||
#define BLI_ghashutil_inthash_v2_murmur(key) \
|
|
||||||
(CHECK_TYPE_ANY(key, int *, const int *), \
|
|
||||||
BLI_ghashutil_uinthash_v2_murmur((const unsigned int *)key))
|
|
||||||
#define BLI_ghashutil_inthash_v2_p_murmur ((GSetHashFP)BLI_ghashutil_uinthash_v2_murmur)
|
|
||||||
#define BLI_ghashutil_uinthash_v2_p_murmur ((GSetHashFP)BLI_ghashutil_uinthash_v2_murmur)
|
|
||||||
bool BLI_ghashutil_uinthash_v2_cmp(const void *a, const void *b);
|
|
||||||
#define BLI_ghashutil_inthash_v2_cmp BLI_ghashutil_uinthash_v2_cmp
|
|
||||||
|
|
||||||
typedef struct GHashPair {
|
typedef struct GHashPair {
|
||||||
const void *first;
|
const void *first;
|
||||||
const void *second;
|
const void *second;
|
||||||
|
@@ -86,25 +86,6 @@ bool BLI_ghashutil_uinthash_v4_cmp(const void *a, const void *b)
|
|||||||
return (memcmp(a, b, sizeof(uint[4])) != 0);
|
return (memcmp(a, b, sizeof(uint[4])) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint BLI_ghashutil_uinthash_v2(const uint key[2])
|
|
||||||
{
|
|
||||||
uint hash;
|
|
||||||
hash = key[0];
|
|
||||||
hash *= 37;
|
|
||||||
hash += key[1];
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint BLI_ghashutil_uinthash_v2_murmur(const uint key[2])
|
|
||||||
{
|
|
||||||
return BLI_hash_mm2((const unsigned char *)key, sizeof(int) * 2 /* sizeof(key) */, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BLI_ghashutil_uinthash_v2_cmp(const void *a, const void *b)
|
|
||||||
{
|
|
||||||
return (memcmp(a, b, sizeof(uint[2])) != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint BLI_ghashutil_uinthash(uint key)
|
uint BLI_ghashutil_uinthash(uint key)
|
||||||
{
|
{
|
||||||
key += ~(key << 16);
|
key += ~(key << 16);
|
||||||
|
Reference in New Issue
Block a user