[Bf-blender-cvs] [869c50d] hair_system: Reimplemented debug drawing for the hair bending vectors.

Lukas Tönne noreply at git.blender.org
Wed Aug 20 16:10:57 CEST 2014


Commit: 869c50d1bb50b5b26c91546aef7ba1294404889a
Author: Lukas Tönne
Date:   Wed Aug 20 16:08:12 2014 +0200
Branches: hair_system
https://developer.blender.org/rB869c50d1bb50b5b26c91546aef7ba1294404889a

Reimplemented debug drawing for the hair bending vectors.

Currently the bending forces are buggy, this should help fixing it.

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

M	release/scripts/startup/bl_ui/properties_physics_hair.py
M	source/blender/editors/space_view3d/drawhair.c
M	source/blender/hair/HAIR_capi.cpp
M	source/blender/hair/HAIR_debug_types.h
M	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/makesrna/intern/rna_modifier.c

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

diff --git a/release/scripts/startup/bl_ui/properties_physics_hair.py b/release/scripts/startup/bl_ui/properties_physics_hair.py
index 98b63c8..60ede18 100644
--- a/release/scripts/startup/bl_ui/properties_physics_hair.py
+++ b/release/scripts/startup/bl_ui/properties_physics_hair.py
@@ -161,6 +161,7 @@ class PHYSICS_PT_hair_debug(PhysicButtonsPanel, Panel):
         col.prop(md, "show_debug_size")
         col.prop(md, "show_debug_roots")
         col.prop(md, "show_debug_frames")
+        col.prop(md, "show_debug_bending")
         col.prop(md, "show_debug_smoothing")
 
 
diff --git a/source/blender/editors/space_view3d/drawhair.c b/source/blender/editors/space_view3d/drawhair.c
index 617b187..ef23930 100644
--- a/source/blender/editors/space_view3d/drawhair.c
+++ b/source/blender/editors/space_view3d/drawhair.c
@@ -461,6 +461,7 @@ bool draw_hair_system(Scene *UNUSED(scene), View3D *UNUSED(v3d), ARegion *ar, Ba
 #define SHOW_FRAMES
 //#define SHOW_SMOOTHING
 #define SHOW_CONTACTS
+#define SHOW_BENDING
 
 static void draw_hair_debug_points(HairSystem *hsys, HAIR_SolverDebugPoint *dpoints, int dtotpoints)
 {
@@ -554,13 +555,13 @@ static void draw_hair_debug_frames(HairSystem *hsys, HAIR_SolverDebugPoint *dpoi
 	for (i = 0; i < hsys->totcurves; ++i) {
 		HairCurve *hair = hsys->curves + i;
 		for (k = 0; k < hair->totpoints; ++k, ++ktot) {
-			HairPoint *point = hair->points + k;
+//			HairPoint *point = hair->points + k;
 			
 			if (ktot < dtotpoints) {
 				HAIR_SolverDebugPoint *dpoint = dpoints + ktot;
 				float co[3], nor[3], tan[3], cotan[3];
 				
-				copy_v3_v3(co, point->co);
+				copy_v3_v3(co, dpoint->co);
 				madd_v3_v3v3fl(nor, co, dpoint->frame[0], scale);
 				madd_v3_v3v3fl(tan, co, dpoint->frame[1], scale);
 				madd_v3_v3v3fl(cotan, co, dpoint->frame[2], scale);
@@ -586,6 +587,46 @@ static void draw_hair_debug_frames(HairSystem *hsys, HAIR_SolverDebugPoint *dpoi
 #endif
 }
 
+static void draw_hair_debug_bending(HairSystem *hsys, HAIR_SolverDebugPoint *dpoints, int dtotpoints)
+{
+#ifdef SHOW_BENDING
+	int i, k, ktot;
+	
+	glBegin(GL_LINES);
+	
+	ktot = 0;
+	for (i = 0; i < hsys->totcurves; ++i) {
+		HairCurve *hair = hsys->curves + i;
+		for (k = 0; k < hair->totpoints; ++k, ++ktot) {
+//			HairPoint *point = hair->points + k;
+			
+			if (ktot < dtotpoints) {
+				HAIR_SolverDebugPoint *dpoint = dpoints + ktot;
+				float co[3], bend[3];
+				
+				copy_v3_v3(co, dpoint->co);
+				
+				add_v3_v3v3(bend, co, dpoint->bend);
+				glColor3f(0.4f, 0.25f, 0.55f);
+				glVertex3fv(co);
+				glVertex3fv(bend);
+				
+				add_v3_v3v3(bend, co, dpoint->rest_bend);
+				glColor3f(0.15f, 0.55f, 0.55f);
+				glVertex3fv(co);
+				glVertex3fv(bend);
+			}
+		}
+	}
+	
+	glEnd();
+#else
+	(void)hsys;
+	(void)dpoints;
+	(void)dtotpoints;
+#endif
+}
+
 #if 0
 static void draw_hair_curve_debug_frames(HairSystem *hsys, HairCurve *hair)
 {
@@ -731,6 +772,8 @@ 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);
diff --git a/source/blender/hair/HAIR_capi.cpp b/source/blender/hair/HAIR_capi.cpp
index 2a63b8f..e2d8dc7 100644
--- a/source/blender/hair/HAIR_capi.cpp
+++ b/source/blender/hair/HAIR_capi.cpp
@@ -148,6 +148,7 @@ void HAIR_solver_step_debug(struct HAIR_Solver *csolver, float time, float times
 				/* transform to object space for display */
 				mul_m4_v3(ob_imat, p.co);
 				mul_mat3_m4_v3(ob_imat, p.bend);
+				mul_mat3_m4_v3(ob_imat, p.rest_bend);
 				mul_mat3_m4_v3(ob_imat, p.frame[0]);
 				mul_mat3_m4_v3(ob_imat, p.frame[1]);
 				mul_mat3_m4_v3(ob_imat, p.frame[2]);
diff --git a/source/blender/hair/HAIR_debug_types.h b/source/blender/hair/HAIR_debug_types.h
index 988c966..514e74e 100644
--- a/source/blender/hair/HAIR_debug_types.h
+++ b/source/blender/hair/HAIR_debug_types.h
@@ -42,6 +42,7 @@ typedef struct HAIR_SolverDebugContact {
 typedef struct HAIR_SolverDebugPoint {
 	int index;
 	float co[3];
+	float rest_bend[3];
 	float bend[3];
 	float frame[3][3];
 } HAIR_SolverDebugPoint;
diff --git a/source/blender/hair/intern/HAIR_debug.h b/source/blender/hair/intern/HAIR_debug.h
index 2fea6cd..c27e041 100644
--- a/source/blender/hair/intern/HAIR_debug.h
+++ b/source/blender/hair/intern/HAIR_debug.h
@@ -56,13 +56,15 @@ struct DebugThreadData
 
 struct Debug {
 	
-	static void point(DebugThreadData *data, int index, const float3 &co, const float3 &bend, const Frame &frame)
+	static void point(DebugThreadData *data, int index, const float3 &co,
+	                  const float3 &rest_bend, const float3 &bend, const Frame &frame)
 	{
 #ifdef HAIR_DEBUG
 		if (data) {
 			HAIR_SolverDebugPoint p;
 			p.index = index;
 			copy_v3_v3(p.co, co.data());
+			copy_v3_v3(p.rest_bend, rest_bend.data());
 			copy_v3_v3(p.bend, bend.data());
 			copy_v3_v3(p.frame[0], frame.normal.data());
 			copy_v3_v3(p.frame[1], frame.tangent.data());
diff --git a/source/blender/hair/intern/HAIR_solver.cpp b/source/blender/hair/intern/HAIR_solver.cpp
index c91d440..0adcb6f 100644
--- a/source/blender/hair/intern/HAIR_solver.cpp
+++ b/source/blender/hair/intern/HAIR_solver.cpp
@@ -383,7 +383,7 @@ static void calc_forces(const HairParams &params, const SolverForces &forces, fl
 			accum_internal_forces(params, forces, time, timestep, point, point_next, frame_iter.frame(), intern_force, intern_force_next);
 			accum_external_forces(params, forces, time, timestep, point, point_next, frame_iter.frame(), extern_force);
 			
-			Debug::point(data.debug_data, k, point->cur.co, point->rest_bend, frame_iter.frame());
+			Debug::point(data.debug_data, k, point->cur.co, point->rest_bend, bend_target(frame_iter.frame(), point), frame_iter.frame());
 			
 			frame_iter.next();
 			acc_prev = intern_force_next;
@@ -393,18 +393,17 @@ static void calc_forces(const HairParams &params, const SolverForces &forces, fl
 		}
 		
 		/* Integrate free points */
-		for (; k < numpoints; ++k, ++point) {
+		for (; k < numpoints; ++k, ++point, ++k_tot) {
 			Point *point_next = k < numpoints-1 ? point+1 : NULL;
 			accum_internal_forces(params, forces, time, timestep, point, point_next, frame_iter.frame(), intern_force, intern_force_next);
 			accum_external_forces(params, forces, time, timestep, point, point_next, frame_iter.frame(), extern_force);
 			
 			point->force_accum = point->force_accum + intern_force + extern_force + acc_prev;
 			
-			Debug::point(data.debug_data, k_tot, point->cur.co, point->rest_bend, frame_iter.frame());
+			Debug::point(data.debug_data, k_tot, point->cur.co, point->rest_bend, bend_target(frame_iter.frame(), point), frame_iter.frame());
 			
 			frame_iter.next();
 			acc_prev = intern_force_next;
-			k_tot++;
 		}
 		
 	}
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index fd23dc2..f482acc 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1391,6 +1391,7 @@ enum {
 	MOD_HAIR_DEBUG_ROOTS        = (1 << 3),
 	MOD_HAIR_DEBUG_SMOOTHING    = (1 << 4),
 	MOD_HAIR_DEBUG_FRAMES       = (1 << 5),
+	MOD_HAIR_DEBUG_BENDING      = (1 << 6),
 };
 
 
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index fabe444..c45200b 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -3724,6 +3724,11 @@ static void rna_def_modifier_hair(BlenderRNA *brna)
 	RNA_def_property_boolean_sdna(prop, NULL, "debug_flag", MOD_HAIR_DEBUG_SMOOTHING);
 	RNA_def_property_ui_text(prop, "Show Smoothing", "");
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+	prop = RNA_def_property(srna, "show_debug_bending", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "debug_flag", MOD_HAIR_DEBUG_BENDING);
+	RNA_def_property_ui_text(prop, "Show Bending", "");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 }
 
 void RNA_def_modifier(BlenderRNA *brna)




More information about the Bf-blender-cvs mailing list