Hair debugging: use "categories" (strings) for grouping debug elements

and support clearing for categories.
This commit is contained in:
2014-09-02 14:10:28 +02:00
parent 70df8f8dd6
commit d43f760892
4 changed files with 44 additions and 19 deletions

View File

@@ -139,8 +139,10 @@ int get_effector_data(struct EffectorCache *eff, struct EffectorData *efd, struc
/* ======== Simulation Debugging ======== */
typedef struct SimDebugElement {
int type;
int category_hash;
int hash;
int type;
float color[3];
float v1[3], v2[3];
@@ -157,11 +159,12 @@ typedef struct SimDebugData {
} SimDebugData;
struct SimDebugData *BKE_sim_debug_data_new(void);
void BKE_sim_debug_data_add_dot(struct SimDebugData *debug_data, const float p[3], float r, float g, float b, int hash);
void BKE_sim_debug_data_add_line(struct SimDebugData *debug_data, const float p1[3], const float p2[3], float r, float g, float b, int hash);
void BKE_sim_debug_data_add_vector(struct SimDebugData *debug_data, const float p[3], const float d[3], float r, float g, float b, int hash);
void BKE_sim_debug_data_add_dot(struct SimDebugData *debug_data, const float p[3], float r, float g, float b, const char *category, int hash);
void BKE_sim_debug_data_add_line(struct SimDebugData *debug_data, const float p1[3], const float p2[3], float r, float g, float b, const char *category, int hash);
void BKE_sim_debug_data_add_vector(struct SimDebugData *debug_data, const float p[3], const float d[3], float r, float g, float b, const char *category, int hash);
void BKE_sim_debug_data_remove(struct SimDebugData *debug_data, int hash);
void BKE_sim_debug_data_clear(struct SimDebugData *debug_data);
void BKE_sim_debug_data_clear_category(struct SimDebugData *debug_data, const char *category);
void BKE_sim_debug_data_free(struct SimDebugData *debug_data);
#endif

View File

@@ -1010,10 +1010,10 @@ static bool cloth_points_collision_response_static(ClothModifierData *clmd, Coll
/**** DEBUG ****/
if (clmd->debug_data) {
BKE_sim_debug_data_add_dot(clmd->debug_data, collpair->pa, 0.9, 0.2, 0.2, hash_collpair(833, collpair));
BKE_sim_debug_data_add_dot(clmd->debug_data, collpair->pb, 0.2, 0.9, 0.2, hash_collpair(834, collpair));
BKE_sim_debug_data_add_line(clmd->debug_data, collpair->pa, collpair->pb, 0.8, 0.8, 0.8, hash_collpair(835, collpair));
BKE_sim_debug_data_add_vector(clmd->debug_data, collpair->pa, collpair->normal, 1.0, 1.0, 0.0, hash_collpair(836, collpair));
BKE_sim_debug_data_add_dot(clmd->debug_data, collpair->pa, 0.9, 0.2, 0.2, "collision", hash_collpair(833, collpair));
BKE_sim_debug_data_add_dot(clmd->debug_data, collpair->pb, 0.2, 0.9, 0.2, "collision", hash_collpair(834, collpair));
BKE_sim_debug_data_add_line(clmd->debug_data, collpair->pa, collpair->pb, 0.8, 0.8, 0.8, "collision", hash_collpair(835, collpair));
// BKE_sim_debug_data_add_vector(clmd->debug_data, collpair->pa, collpair->normal, 1.0, 1.0, 0.0, "collision", hash_collpair(836, collpair));
}
/********/
@@ -1046,16 +1046,10 @@ static bool cloth_points_collision_response_static(ClothModifierData *clmd, Coll
copy_v3_v3(impulse, repulse);
}
cloth1->verts[collpair->ap1].impulse_count++;
BKE_sim_debug_data_add_vector(clmd->debug_data, collpair->pa, impulse, 0.0, 1.0, 0.6, hash_collpair(873, collpair));
BKE_sim_debug_data_add_vector(clmd->debug_data, collpair->pa, impulse, 0.0, 1.0, 0.6, "collision", hash_collpair(873, collpair));
result = true;
}
else {
BKE_sim_debug_data_remove(clmd->debug_data, hash_collpair(833, collpair));
BKE_sim_debug_data_remove(clmd->debug_data, hash_collpair(834, collpair));
BKE_sim_debug_data_remove(clmd->debug_data, hash_collpair(835, collpair));
BKE_sim_debug_data_remove(clmd->debug_data, hash_collpair(873, collpair));
}
if (result) {
int i = 0;

View File

@@ -1070,14 +1070,16 @@ static void debug_data_insert(SimDebugData *debug_data, SimDebugElement *elem)
BLI_ghash_insert(debug_data->gh, elem, elem);
}
void BKE_sim_debug_data_add_dot(struct SimDebugData *debug_data, const float p[3], float r, float g, float b, int hash)
void BKE_sim_debug_data_add_dot(struct SimDebugData *debug_data, const float p[3], float r, float g, float b, const char *category, int hash)
{
int category_hash = (int)BLI_ghashutil_strhash_p(category);
SimDebugElement *elem;
if (!debug_data)
return;
elem = MEM_callocN(sizeof(SimDebugElement), "sim debug data element");
elem->type = SIM_DEBUG_ELEM_DOT;
elem->category_hash = category_hash;
elem->hash = hash;
elem->color[0] = r;
elem->color[1] = g;
@@ -1087,14 +1089,16 @@ void BKE_sim_debug_data_add_dot(struct SimDebugData *debug_data, const float p[3
debug_data_insert(debug_data, elem);
}
void BKE_sim_debug_data_add_line(struct SimDebugData *debug_data, const float p1[3], const float p2[3], float r, float g, float b, int hash)
void BKE_sim_debug_data_add_line(struct SimDebugData *debug_data, const float p1[3], const float p2[3], float r, float g, float b, const char *category, int hash)
{
int category_hash = (int)BLI_ghashutil_strhash_p(category);
SimDebugElement *elem;
if (!debug_data)
return;
elem = MEM_callocN(sizeof(SimDebugElement), "sim debug data element");
elem->type = SIM_DEBUG_ELEM_LINE;
elem->category_hash = category_hash;
elem->hash = hash;
elem->color[0] = r;
elem->color[1] = g;
@@ -1105,14 +1109,16 @@ void BKE_sim_debug_data_add_line(struct SimDebugData *debug_data, const float p1
debug_data_insert(debug_data, elem);
}
void BKE_sim_debug_data_add_vector(struct SimDebugData *debug_data, const float p[3], const float d[3], float r, float g, float b, int hash)
void BKE_sim_debug_data_add_vector(struct SimDebugData *debug_data, const float p[3], const float d[3], float r, float g, float b, const char *category, int hash)
{
int category_hash = (int)BLI_ghashutil_strhash_p(category);
SimDebugElement *elem;
if (!debug_data)
return;
elem = MEM_callocN(sizeof(SimDebugElement), "sim debug data element");
elem->type = SIM_DEBUG_ELEM_VECTOR;
elem->category_hash = category_hash;
elem->hash = hash;
elem->color[0] = r;
elem->color[1] = g;
@@ -1142,6 +1148,26 @@ void BKE_sim_debug_data_clear(SimDebugData *debug_data)
BLI_ghash_clear(debug_data->gh, NULL, debug_element_free);
}
void BKE_sim_debug_data_clear_category(SimDebugData *debug_data, const char *category)
{
int category_hash = (int)BLI_ghashutil_strhash_p(category);
if (!debug_data)
return;
if (debug_data->gh) {
GHashIterator iter;
BLI_ghashIterator_init(&iter, debug_data->gh);
while(!BLI_ghashIterator_done(&iter)) {
SimDebugElement *elem = BLI_ghashIterator_getValue(&iter);
BLI_ghashIterator_step(&iter); /* removing invalidates the current iterator, so step before removing */
if (elem->category_hash == category_hash)
BLI_ghash_remove(debug_data->gh, elem, NULL, debug_element_free);
}
}
}
void BKE_sim_debug_data_free(SimDebugData *debug_data)
{
if (!debug_data)

View File

@@ -1959,6 +1959,8 @@ int implicit_solver(Object *ob, float frame, ClothModifierData *clmd, ListBase *
/*float (*initial_cos)[3] = MEM_callocN(sizeof(float)*3*cloth->numverts, "initial_cos implicit.c");*/ /* UNUSED */
Implicit_Data *id = cloth->implicit;
BKE_sim_debug_data_clear_category(clmd->debug_data, "collision");
if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL) { /* do goal stuff */
/* Update vertex constraints for pinned vertices */
@@ -1975,7 +1977,7 @@ int implicit_solver(Object *ob, float frame, ClothModifierData *clmd, ListBase *
if (clmd->debug_data) {
for (i = 0; i < numverts; i++) {
BKE_sim_debug_data_add_dot(clmd->debug_data, verts[i].x, 1.0f, 0.1f, 1.0f, hash_vertex(583, i));
BKE_sim_debug_data_add_dot(clmd->debug_data, verts[i].x, 1.0f, 0.1f, 1.0f, "points", hash_vertex(583, i));
}
}