[Bf-blender-cvs] [160791c] hair_system: Hair debug cleanup: Nicer organization of drawing elements and a dedicated Debug class for solver info.

Lukas Tönne noreply at git.blender.org
Fri Aug 1 11:36:37 CEST 2014


Commit: 160791c4b43acbd30d4ecc1824ff733a2da77514
Author: Lukas Tönne
Date:   Fri Aug 1 11:35:00 2014 +0200
Branches: hair_system
https://developer.blender.org/rB160791c4b43acbd30d4ecc1824ff733a2da77514

Hair debug cleanup: Nicer organization of drawing elements and a
dedicated Debug class for solver info.

The debug code uses preprocessor conditions to avoid all overhead in
non-debug modes or when not using debug output. The only extra info at
this point is for collision contact points, which will be imported from
the Bullet collision world (not yet implemented).

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

M	source/blender/blenkernel/intern/object.c
M	source/blender/editors/space_view3d/drawhair.c
M	source/blender/editors/space_view3d/drawobject.c
M	source/blender/editors/space_view3d/view3d_intern.h
M	source/blender/hair/CMakeLists.txt
M	source/blender/hair/HAIR_capi.cpp
M	source/blender/hair/HAIR_capi.h
A	source/blender/hair/intern/HAIR_debug.cpp
A	source/blender/hair/intern/HAIR_debug.h
M	source/blender/hair/intern/HAIR_solver.cpp
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/modifiers/intern/MOD_hair.c

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

diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index b844795..271e55d 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -3120,7 +3120,14 @@ void BKE_object_sim_tick(Scene *UNUSED(scene), Object *ob, float ctime, float ti
 	for (md = ob->modifiers.first; md; md = md->next) {
 		if (md->type == eModifierType_Hair) {
 			HairModifierData *hmd = (HairModifierData*) md;
+			
+#if 0
 			HAIR_solver_step(hmd->solver, ctime, timestep);
+#else
+			if (hmd->debug_contacts)
+				MEM_freeN(hmd->debug_contacts);
+			HAIR_solver_step_debug(hmd->solver, ctime, timestep, &hmd->debug_contacts, &hmd->debug_totcontacts);
+#endif
 		}
 	}
 }
diff --git a/source/blender/editors/space_view3d/drawhair.c b/source/blender/editors/space_view3d/drawhair.c
index 72389fc..8d9855e 100644
--- a/source/blender/editors/space_view3d/drawhair.c
+++ b/source/blender/editors/space_view3d/drawhair.c
@@ -81,18 +81,110 @@ static void draw_hair_curve(HairSystem *UNUSED(hsys), HairCurve *hair)
 	}
 	glEnd();
 	glPointSize(1.0f);
+}
+
+/* called from drawobject.c, return true if nothing was drawn */
+bool draw_hair_system(Scene *UNUSED(scene), View3D *UNUSED(v3d), ARegion *ar, Base *base, HairSystem *hsys)
+{
+	RegionView3D *rv3d = ar->regiondata;
+	Object *ob = base->object;
+	struct DerivedMesh *dm = ob->derivedFinal;
+	HairCurve *hair;
+	int i;
+	bool retval = true;
 	
-#if 0
-	/* frames */
-	{
-		struct HAIR_FrameIterator *iter;
-		float co[3], nor[3], tan[3], cotan[3];
-		int k = 0;
-		const float scale = 0.1f;
-		
+	glLoadMatrixf(rv3d->viewmat);
+	glMultMatrixf(ob->obmat);
+	
+	/* hair roots */
+	if (dm) {
+		glPointSize(3.0f);
+		glColor3f(1.0f, 1.0f, 0.0f);
 		glBegin(GL_LINES);
-		iter = HAIR_frame_iter_new(hair, 1.0f / hair->totpoints, hsys->smooth, nor, tan, cotan);
-		copy_v3_v3(co, hair->points[0].co);
+		for (hair = hsys->curves, i = 0; i < hsys->totcurves; ++hair, ++i) {
+			float loc[3], nor[3];
+			if (BKE_mesh_sample_eval(dm, &hair->root, loc, nor)) {
+				glVertex3f(loc[0], loc[1], loc[2]);
+				madd_v3_v3fl(loc, nor, 0.1f);
+				glVertex3f(loc[0], loc[1], loc[2]);
+			}
+		}
+		glEnd();
+	}
+	
+	for (hair = hsys->curves, i = 0; i < hsys->totcurves; ++hair, ++i) {
+		draw_hair_curve(hsys, hair);
+	}
+	
+	return retval;
+}
+
+/* ---------------- debug drawing ---------------- */
+
+//#define SHOW_ROOTS
+//#define SHOW_FRAMES
+//#define SHOW_SMOOTHING
+#define SHOW_CONTACTS
+
+static void draw_hair_debug_roots(HairSystem *hsys, struct DerivedMesh *dm)
+{
+#ifdef SHOW_ROOTS
+	HairCurve *hair;
+	int i;
+	
+	/* hair roots */
+	if (dm) {
+		glPointSize(3.0f);
+		glColor3f(1.0f, 1.0f, 0.0f);
+		glBegin(GL_LINES);
+		for (hair = hsys->curves, i = 0; i < hsys->totcurves; ++hair, ++i) {
+			float loc[3], nor[3];
+			if (BKE_mesh_sample_eval(dm, &hair->root, loc, nor)) {
+				glVertex3f(loc[0], loc[1], loc[2]);
+				madd_v3_v3fl(loc, nor, 0.1f);
+				glVertex3f(loc[0], loc[1], loc[2]);
+			}
+		}
+		glEnd();
+	}
+#else
+	(void)hsys;
+	(void)dm;
+#endif
+}
+
+static void draw_hair_curve_debug_frames(HairSystem *hsys, HairCurve *hair)
+{
+#ifdef SHOW_FRAMES
+	struct HAIR_FrameIterator *iter;
+	float co[3], nor[3], tan[3], cotan[3];
+	int k = 0;
+	const float scale = 0.1f;
+	
+	glBegin(GL_LINES);
+	iter = HAIR_frame_iter_new(hair, 1.0f / hair->totpoints, hsys->smooth, nor, tan, cotan);
+	copy_v3_v3(co, hair->points[0].co);
+	mul_v3_fl(nor, scale);
+	mul_v3_fl(tan, scale);
+	mul_v3_fl(cotan, scale);
+	add_v3_v3(nor, co);
+	add_v3_v3(tan, co);
+	add_v3_v3(cotan, co);
+	++k;
+	
+	glColor3f(1.0f, 0.0f, 0.0f);
+	glVertex3fv(co);
+	glVertex3fv(nor);
+	glColor3f(0.0f, 1.0f, 0.0f);
+	glVertex3fv(co);
+	glVertex3fv(tan);
+	glColor3f(0.0f, 0.0f, 1.0f);
+	glVertex3fv(co);
+	glVertex3fv(cotan);
+	
+	while (HAIR_frame_iter_valid(hair, iter)) {
+		HAIR_frame_iter_next(hair, iter, nor, tan, cotan);
+		copy_v3_v3(co, hair->points[k].co);
 		mul_v3_fl(nor, scale);
 		mul_v3_fl(tan, scale);
 		mul_v3_fl(cotan, scale);
@@ -110,102 +202,96 @@ static void draw_hair_curve(HairSystem *UNUSED(hsys), HairCurve *hair)
 		glColor3f(0.0f, 0.0f, 1.0f);
 		glVertex3fv(co);
 		glVertex3fv(cotan);
-		
-		while (HAIR_frame_iter_valid(hair, iter)) {
-			HAIR_frame_iter_next(hair, iter, nor, tan, cotan);
-			copy_v3_v3(co, hair->points[k].co);
-			mul_v3_fl(nor, scale);
-			mul_v3_fl(tan, scale);
-			mul_v3_fl(cotan, scale);
-			add_v3_v3(nor, co);
-			add_v3_v3(tan, co);
-			add_v3_v3(cotan, co);
-			++k;
-			
-			glColor3f(1.0f, 0.0f, 0.0f);
-			glVertex3fv(co);
-			glVertex3fv(nor);
-			glColor3f(0.0f, 1.0f, 0.0f);
-			glVertex3fv(co);
-			glVertex3fv(tan);
-			glColor3f(0.0f, 0.0f, 1.0f);
-			glVertex3fv(co);
-			glVertex3fv(cotan);
-		}
-		HAIR_frame_iter_free(iter);
-		glEnd();
 	}
+	HAIR_frame_iter_free(iter);
+	glEnd();
+#else
+	(void)hsys;
+	(void)hair;
 #endif
+}
+
+static void draw_hair_curve_debug_smoothing(HairSystem *hsys, HairCurve *hair)
+{
+#ifdef SHOW_SMOOTHING
+	struct HAIR_SmoothingIteratorFloat3 *iter;
+	float smooth_co[3];
 	
-#if 0
-	/* smoothed curve */
-	if (hair->totpoints >= 2) {
-		struct HAIR_SmoothingIteratorFloat3 *iter;
-		float smooth_co[3];
-		
-		glColor3f(0.5f, 1.0f, 0.1f);
-		
-		glBegin(GL_LINE_STRIP);
-		iter = HAIR_smoothing_iter_new(hair, 1.0f / hair->totpoints, hsys->smooth, smooth_co);
+	if (hair->totpoints < 2)
+		return;
+	
+	glColor3f(0.5f, 1.0f, 0.1f);
+	
+	glBegin(GL_LINE_STRIP);
+	iter = HAIR_smoothing_iter_new(hair, 1.0f / hair->totpoints, hsys->smooth, smooth_co);
+	glVertex3fv(smooth_co);
+	while (HAIR_smoothing_iter_valid(hair, iter)) {
+		HAIR_smoothing_iter_next(hair, iter, smooth_co);
 		glVertex3fv(smooth_co);
-		while (HAIR_smoothing_iter_valid(hair, iter)) {
-			HAIR_smoothing_iter_next(hair, iter, smooth_co);
-			glVertex3fv(smooth_co);
-		}
-		HAIR_smoothing_iter_end(hair, iter, smooth_co);
+	}
+	HAIR_smoothing_iter_end(hair, iter, smooth_co);
+	glVertex3fv(smooth_co);
+	HAIR_smoothing_iter_free(iter);
+	glEnd();
+	
+	glPointSize(2.5f);
+	glBegin(GL_POINTS);
+	iter = HAIR_smoothing_iter_new(hair, 1.0f / hair->totpoints, hsys->smooth, smooth_co);
+	glVertex3fv(smooth_co);
+	while (HAIR_smoothing_iter_valid(hair, iter)) {
+		HAIR_smoothing_iter_next(hair, iter, smooth_co);
 		glVertex3fv(smooth_co);
-		HAIR_smoothing_iter_free(iter);
-		glEnd();
+	}
+	HAIR_smoothing_iter_end(hair, iter, smooth_co);
+	glVertex3fv(smooth_co);
+	HAIR_smoothing_iter_free(iter);
+	glEnd();
+	glPointSize(1.0f);
+#else
+	(void)hsys;
+	(void)hair;
+#endif
+}
+
+static void draw_hair_debug_contacts(HAIR_SolverContact *contacts, int totcontacts)
+{
+#ifdef SHOW_CONTACTS
+	int i;
+	
+	glColor3f(1.0f, 0.1f, 0.0f);
+	
+	glPointSize(3.0f);
+	glBegin(GL_POINTS);
+	for (i = 0; i < totcontacts; ++i) {
+		HAIR_SolverContact *c = contacts + i;
 		
-		glPointSize(2.5f);
-		glBegin(GL_POINTS);
-		iter = HAIR_smoothing_iter_new(hair, 1.0f / hair->totpoints, hsys->smooth, smooth_co);
-		glVertex3fv(smooth_co);
-		while (HAIR_smoothing_iter_valid(hair, iter)) {
-			HAIR_smoothing_iter_next(hair, iter, smooth_co);
-			glVertex3fv(smooth_co);
-		}
-		HAIR_smoothing_iter_end(hair, iter, smooth_co);
-		glVertex3fv(smooth_co);
-		HAIR_smoothing_iter_free(iter);
-		glEnd();
-		glPointSize(1.0f);
+		glVertex3f(c->co[0], c->co[1], c->co[2]);
 	}
+	glEnd();
+	glPointSize(1.0f);
+#else
+	(void)contacts;
+	(void)totcontacts;
 #endif
 }
 
-/* called from drawobject.c, return true if nothing was drawn */
-bool draw_hair_system(Scene *UNUSED(scene), View3D *UNUSED(v3d), ARegion *ar, Base *base, HairSystem *hsys)
+void draw_hair_debug_info(Scene *UNUSED(scene), View3D *UNUSED(v3d), ARegion *ar, Base *base, HairModifierData *hmd)
 {
 	RegionView3D *rv3d = ar->regiondata;
 	Object *ob = base->object;
-	struct DerivedMesh *dm = ob->derivedFinal;
+	HairSystem *hsys = hmd->hairsys;
 	HairCurve *hair;
 	int i;
-	bool retval = true;
 	
 	glLoadMatrixf(rv3d->viewmat);
 	glMultMatrixf(ob->obmat);
 	
-	/* hair roots */
-	if (dm) {
-		glPointSize(3.0f);
-		glColor3f(1.0f, 1.0f, 0.0f);
-		glBegin(GL_LINES);
-		for (hair = hsys->curves, i = 0; i < hsys->totcurves; ++hair, ++i) {
-			float loc[3], nor[3];
-			if (BKE_mesh_sample_eval(dm, &hair->root, loc, nor)) {
-				glVertex3f(loc[0], loc[1], loc[2]);
-				madd_v3_v3fl(loc, nor, 0.1f);
-				glVertex3f(loc[0], loc[1], loc[2]);
-			}
-		}
-		glEnd();
-	}
+	draw_hair_debug_roots(hsys, ob->derivedFinal);
 	
 	for (hair = hsys->curves, i = 0; i < hsys->totcurves; ++hair, ++i) {
-		draw_hair_curve(hsys, hair);
+		draw_hair_curve_debug_frames(hsys, hair);
+		draw_hair_curve_debug_smoothing(hsys, hair);
 	}
 	
-	return retval;
+	draw_hair_debug_contacts(hmd->debug_contacts, hmd->debug_totcontacts);
 }
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index 13fc59d..abfee79 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -7649,6 +7649,9 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short
 		HairModifierData *hmd = (HairModifierData *)modifiers_findByType(ob, eModifierType_Hair);
 		if (hmd) {
 			draw_hair_system(scene, v3d, ar, base, hmd->hairsys);
+#ifndef NDEBUG
+			draw_hair_debug_info(scene, v3d, ar, base, hmd);
+#endif
 		}
 	}
 
diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h
index e26ffc3..fee9cc1 100644
--- a/source/blender/editors/space_view3d/view3d_intern.h
+++ b/source/blender/editors/space_view3d/view3d_intern.h
@@ -39,6 +39,7 @@ struct ARegion;
 struct ARegionType;
 struct BoundBox;
 struct DerivedMesh;
+struct HairModifierData;
 struct HairSystem;
 struct Object;
 struct SmokeDomainSettings;
@@ -132,8 +133,8 @@ void draw_motion_path_instance(Scene *scene,
 void draw_motion_paths_cleanup(View3D *v3d);
 
 /* drawhair.c */
-bool draw_hair_system(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
-               struct HairSystem *hsys);
+bool draw_hair_system(Scene *scene, View3D *v3d, ARegion *ar, Base *base, struct HairSystem *hsys);
+void draw_hair_debug_info(Scene *scene, View3D *v3d, ARegion *ar, Base *base, struct HairModifi

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list