[Bf-blender-cvs] [5da5856] hair_system: New debug drawing system for the hair solver.

Lukas Tönne noreply at git.blender.org
Fri Aug 22 12:17:50 CEST 2014


Commit: 5da5856d367efbc2f62c5f13237559fc24efe022
Author: Lukas Tönne
Date:   Fri Aug 22 11:51:02 2014 +0200
Branches: hair_system
https://developer.blender.org/rB5da5856d367efbc2f62c5f13237559fc24efe022

New debug drawing system for the hair solver.

Now storing anonymous "elements" (dots, lines, etc) instead of explicit
elements of the simulation. This makes it much easier to quickly add
debug information where needed without going through all stages of data
conversion. Could add tagging to associate elements with the
various debug settings again.

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

M	source/blender/blenkernel/BKE_hair.h
M	source/blender/blenkernel/intern/hair.c
M	source/blender/blenkernel/intern/object.c
M	source/blender/editors/space_view3d/drawhair.c
M	source/blender/hair/CMakeLists.txt
M	source/blender/hair/HAIR_capi.cpp
M	source/blender/hair/HAIR_capi.h
M	source/blender/hair/HAIR_debug_types.h
M	source/blender/hair/intern/HAIR_debug.cpp
M	source/blender/hair/intern/HAIR_debug.h
M	source/blender/hair/intern/HAIR_solver.cpp
A	source/blender/hair/intern/HAIR_util_hash.h
M	source/blender/makesdna/DNA_hair_types.h

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

diff --git a/source/blender/blenkernel/BKE_hair.h b/source/blender/blenkernel/BKE_hair.h
index 06e577a..7037c13 100644
--- a/source/blender/blenkernel/BKE_hair.h
+++ b/source/blender/blenkernel/BKE_hair.h
@@ -36,6 +36,7 @@ struct HairCurve;
 struct HairPoint;
 struct HairDebugData;
 struct HairParams;
+struct HAIR_SolverDebugElement;
 
 struct HairSystem *BKE_hairsys_new(void);
 void BKE_hairsys_free(struct HairSystem *hsys);
@@ -58,6 +59,9 @@ void BKE_hair_point_remove_position(struct HairSystem *hsys, struct HairCurve *h
 
 void BKE_hair_calculate_rest(struct HairSystem *hsys);
 
+struct HairDebugData *BKE_hair_debug_data_new(void);
+void BKE_hair_debug_data_insert(struct HairDebugData *debug_data, struct HAIR_SolverDebugElement *elem);
+void BKE_hair_debug_data_clear(struct HairDebugData *debug_data);
 void BKE_hair_debug_data_free(struct HairDebugData *debug_data);
 
 /* cached per-hair data */
diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.c
index 8eda84b..c0da7c8 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.c
@@ -36,6 +36,7 @@
 #include "BLI_math.h"
 #include "BLI_rand.h"
 #include "BLI_utildefines.h"
+#include "BLI_ghash.h"
 
 #include "DNA_hair_types.h"
 
@@ -43,6 +44,7 @@
 #include "BKE_mesh_sample.h"
 
 #include "HAIR_capi.h"
+#include "HAIR_debug_types.h"
 
 void BKE_hairparams_init(HairParams *params)
 {
@@ -244,15 +246,65 @@ void BKE_hair_calculate_rest(HairSystem *hsys)
 	}
 }
 
-void BKE_hair_debug_data_free(HairDebugData *debug_data)
+
+static unsigned int debug_element_hash(const void *key)
 {
-	if (debug_data) {
-		if (debug_data->points)
-			MEM_freeN(debug_data->points);
-		if (debug_data->contacts)
-			MEM_freeN(debug_data->contacts);
-		MEM_freeN(debug_data);
+	const HAIR_SolverDebugElement *elem = key;
+	return elem->hash;
+}
+
+static int debug_element_compare(const void *a, const void *b)
+{
+	const HAIR_SolverDebugElement *elem1 = a;
+	const HAIR_SolverDebugElement *elem2 = b;
+
+	if (elem1->hash == elem2->hash) {
+		return 0;
 	}
+	return 1;
+}
+
+static void debug_element_free(void *val)
+{
+	HAIR_SolverDebugElement *elem = val;
+	MEM_freeN(elem);
+}
+
+HairDebugData *BKE_hair_debug_data_new(void)
+{
+	HairDebugData *debug_data = MEM_callocN(sizeof(HairDebugData), "hair debug data");
+	debug_data->gh = BLI_ghash_new(debug_element_hash, debug_element_compare, "hair debug element hash");
+	return debug_data;
+}
+
+void BKE_hair_debug_data_insert(HairDebugData *debug_data, HAIR_SolverDebugElement *elem)
+{
+	HAIR_SolverDebugElement *old_elem = BLI_ghash_lookup(debug_data->gh, elem);
+	if (old_elem) {
+		*old_elem = *elem;
+		MEM_freeN(elem);
+	}
+	else
+		BLI_ghash_insert(debug_data->gh, elem, elem);
+}
+
+void BKE_hair_debug_data_clear(HairDebugData *debug_data)
+{
+	if (!debug_data)
+		return;
+	
+	if (debug_data->gh)
+		BLI_ghash_clear(debug_data->gh, NULL, debug_element_free);
+}
+
+void BKE_hair_debug_data_free(HairDebugData *debug_data)
+{
+	if (!debug_data)
+		return;
+	
+	if (debug_data->gh)
+		BLI_ghash_free(debug_data->gh, NULL, debug_element_free);
+	MEM_freeN(debug_data);
 }
 
 
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 3882d06..ee6d623 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -3173,24 +3173,21 @@ void BKE_object_sim_tick(Scene *UNUSED(scene), Object *ob, float ctime, float ti
 			HairModifierData *hmd = (HairModifierData*) md;
 			
 			if (!(hmd->debug_flag & MOD_HAIR_DEBUG_SHOW)) {
+				if (hmd->debug_data) {
+					BKE_hair_debug_data_free(hmd->debug_data);
+					hmd->debug_data = NULL;
+				}
+				
 				HAIR_solver_step(hmd->solver, ctime, timestep);
 			}
 			else {
 				float imat[4][4];
-				
 				invert_m4_m4(imat, ob->obmat);
 				
-				if (hmd->debug_data) {
-					if (hmd->debug_data->points)
-						MEM_freeN(hmd->debug_data->points);
-					if (hmd->debug_data->contacts)
-						MEM_freeN(hmd->debug_data->contacts);
-				}
-				else {
-					hmd->debug_data = MEM_callocN(sizeof(HairDebugData), "hair debug data");
-				}
+				if (!hmd->debug_data)
+					hmd->debug_data = BKE_hair_debug_data_new();
 				
-				HAIR_solver_step_debug(hmd->solver, ctime, timestep, imat, &hmd->debug_data->points, &hmd->debug_data->totpoints, &hmd->debug_data->contacts, &hmd->debug_data->totcontacts);
+				HAIR_solver_step_debug(hmd->solver, ctime, timestep, imat, hmd->debug_data);
 			}
 		}
 	}
diff --git a/source/blender/editors/space_view3d/drawhair.c b/source/blender/editors/space_view3d/drawhair.c
index 7b657a2..3071df8 100644
--- a/source/blender/editors/space_view3d/drawhair.c
+++ b/source/blender/editors/space_view3d/drawhair.c
@@ -40,6 +40,7 @@
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
+#include "BLI_ghash.h"
 
 #include "BKE_global.h"
 #include "BKE_hair.h"
@@ -780,6 +781,67 @@ static void draw_hair_debug_contacts(HairSystem *UNUSED(hsys), HAIR_SolverDebugC
 #endif
 }
 
+static void draw_hair_debug_elements(HairSystem *UNUSED(hsys), HairDebugData *debug_data)
+{
+	GHashIterator iter;
+	
+	/**** dots ****/
+	
+	glPointSize(3.0f);
+	glBegin(GL_POINT);
+	for (BLI_ghashIterator_init(&iter, debug_data->gh); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) {
+		HAIR_SolverDebugElement *elem = BLI_ghashIterator_getValue(&iter);
+		if (elem->type != HAIR_DEBUG_ELEM_DOT)
+			continue;
+		
+		glColor3f(elem->color[0], elem->color[1], elem->color[2]);
+		glVertex3f(elem->a[0], elem->a[1], elem->a[2]);
+	}
+	glEnd();
+	glPointSize(1.0f);
+	
+	/**** lines ****/
+	
+	glBegin(GL_LINES);
+	for (BLI_ghashIterator_init(&iter, debug_data->gh); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) {
+		HAIR_SolverDebugElement *elem = BLI_ghashIterator_getValue(&iter);
+		if (elem->type != HAIR_DEBUG_ELEM_LINE)
+			continue;
+		
+		glColor3f(elem->color[0], elem->color[1], elem->color[2]);
+		glVertex3f(elem->a[0], elem->a[1], elem->a[2]);
+		glVertex3f(elem->b[0], elem->b[1], elem->b[2]);
+	}
+	glEnd();
+	
+	/**** vectors ****/
+	
+	glPointSize(2.0f);
+	glBegin(GL_POINT);
+	for (BLI_ghashIterator_init(&iter, debug_data->gh); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) {
+		HAIR_SolverDebugElement *elem = BLI_ghashIterator_getValue(&iter);
+		if (elem->type != HAIR_DEBUG_ELEM_VECTOR)
+			continue;
+		
+		glColor3f(elem->color[0], elem->color[1], elem->color[2]);
+		glVertex3f(elem->a[0], elem->a[1], elem->a[2]);
+	}
+	glEnd();
+	glPointSize(1.0f);
+	
+	glBegin(GL_LINES);
+	for (BLI_ghashIterator_init(&iter, debug_data->gh); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) {
+		HAIR_SolverDebugElement *elem = BLI_ghashIterator_getValue(&iter);
+		if (elem->type != HAIR_DEBUG_ELEM_VECTOR)
+			continue;
+		
+		glColor3f(elem->color[0], elem->color[1], elem->color[2]);
+		glVertex3f(elem->a[0], elem->a[1], elem->a[2]);
+		glVertex3f(elem->b[0], elem->b[1], elem->b[2]);
+	}
+	glEnd();
+}
+
 void draw_hair_debug_info(Scene *UNUSED(scene), View3D *UNUSED(v3d), ARegion *ar, Base *base, HairModifierData *hmd)
 {
 	RegionView3D *rv3d = ar->regiondata;
@@ -806,14 +868,15 @@ void draw_hair_debug_info(Scene *UNUSED(scene), View3D *UNUSED(v3d), ARegion *ar
 	}
 	
 	if (hmd->debug_data) {
-		if (debug_flag & MOD_HAIR_DEBUG_FRAMES)
-			draw_hair_debug_frames(hsys, hmd->debug_data->points, hmd->debug_data->totpoints);
-		if (debug_flag & MOD_HAIR_DEBUG_BENDING)
-			draw_hair_debug_bending(hsys, hmd->debug_data->points, hmd->debug_data->totpoints);
-//		draw_hair_debug_points(hsys, hmd->debug_data->points, hmd->debug_data->totpoints);
-		if (debug_flag & MOD_HAIR_DEBUG_CONTACTS)
-			draw_hair_debug_contacts(hsys, hmd->debug_data->contacts, hmd->debug_data->totcontacts);
-		if (debug_flag & MOD_HAIR_DEBUG_FORCES)
-			draw_hair_debug_forces(hsys, hmd->debug_flag_forces, hmd->debug_data->points, hmd->debug_data->totpoints);
+//		if (debug_flag & MOD_HAIR_DEBUG_FRAMES)
+//			draw_hair_debug_frames(hsys, hmd->debug_data->points, hmd->debug_data->totpoints);
+//		if (debug_flag & MOD_HAIR_DEBUG_BENDING)
+//			draw_hair_debug_bending(hsys, hmd->debug_data->points, hmd->debug_data->totpoints);
+//		if (debug_flag & MOD_HAIR_DEBUG_CONTACTS)
+//			draw_hair_debug_contacts(hsys, hmd->debug_data->contacts, hmd->debug_data->totcontacts);
+//		if (debug_flag & MOD_HAIR_DEBUG_FORCES)
+//			draw_hair_debug_forces(hsys, hmd->debug_flag_forces, hmd->debug_data->points, hmd->debug_data->totpoints);
+		
+		draw_hair_debug_elements(hsys, hmd->debug_data);
 	}
 }
diff --git a/source/blender/hair/CMakeLists.txt b/source/blender/hair/CMakeLists.txt
index 5a97154..121c860 100644
--- a/source/blender/hair/CMakeLists.txt
+++ b/source/blender/hair/CMakeLists.txt
@@ -57,6 +57,7 @@ set(SRC
 	intern/HAIR_collision.cpp
 	intern/HAIR_types.h
 	intern/HAIR_types.cpp
+intern/HAIR_util_hash.h
 )
 
 add_definitions(
diff --git a/source/blender/hair/HAIR_capi.cpp b/source/blender/hair/HAIR_capi.cpp
index b26362d..8728a93 100644
--- a/source/blender/hair/HAIR_capi.cpp
+++ b/source/blender/hair/HAIR_capi.cpp
@@ -141,15 +141,26 @@ void HAIR_solver_step(struct HAIR_Solver *csolver, float time, float timestep)
 }
 
 void HAIR_solver_step_debug(struct HAIR_Solver *csolver, float time, float timestep,
-                            float ob_imat[4][4],
-                            HAIR_SolverDebugPoint **points, int *totpoints,
-                            HAIR_SolverDebugContact **contacts, int *totcontacts)
+                            float ob_imat[4][4], HairDebugData *debug_data)
 {
 	Solver *solver = (Solver *)csolver;
 	
+	Debug::init();
+	
 	DebugThreadDataVector thread_data_list;
 	solver->step_threaded(time, timestep, &thread_data_list);
 	
+	if (debug_data) {
+		int i, tot = Debug::elements.size();
+		for (i = 0; i < tot; ++i) {
+			HAIR_SolverDebugElement *elem = (HAIR_SolverDebugElement *)MEM_mallocN(sizeof(HAIR_SolverDebugElement), "hair debug element");
+			*elem = Debug::elements[i];
+			
+			BKE_hair_debug_data_insert(debug_data, elem);
+		}
+	}
+	
+#if 0
 	if (points && totpoints) {
 		int tot = solver->data()->totpoints;
 		*totpoints = tot;
@@ -200,6 +211,9 @@ void 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list