[Bf-blender-cvs] [829b1b2] hair_system: A bunch of fixes for the frame propagation method for calculating bend forces between hair segments.

Lukas Tönne noreply at git.blender.org
Thu Aug 7 12:26:21 CEST 2014


Commit: 829b1b20d647d1776a5ecfc7ea2548cc85ced128
Author: Lukas Tönne
Date:   Thu Aug 7 11:21:22 2014 +0200
Branches: hair_system
https://developer.blender.org/rB829b1b20d647d1776a5ecfc7ea2548cc85ced128

A bunch of fixes for the frame propagation method for calculating bend
forces between hair segments.

This is still not quite ready, in particular first/last hair segments
are a bit problematic.

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

M	source/blender/blenkernel/intern/object.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/space_view3d/drawhair.c
M	source/blender/hair/HAIR_capi.cpp
M	source/blender/hair/HAIR_capi.h
M	source/blender/hair/intern/HAIR_debug.cpp
M	source/blender/hair/intern/HAIR_debug.h
M	source/blender/hair/intern/HAIR_math.h
M	source/blender/hair/intern/HAIR_scene.cpp
M	source/blender/hair/intern/HAIR_smoothing.h
M	source/blender/hair/intern/HAIR_solver.cpp
M	source/blender/hair/intern/HAIR_solver.h
M	source/blender/makesdna/DNA_hair_types.h
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 da3ff6c..70513cb 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -3121,23 +3121,24 @@ void BKE_object_sim_tick(Scene *UNUSED(scene), Object *ob, float ctime, float ti
 		if (md->type == eModifierType_Hair) {
 			HairModifierData *hmd = (HairModifierData*) md;
 			
-#if 0
+#if 0 /* debugging? */
 			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);
-			/* transform to object space */
-			{
-				float imat[4][4];
-				int i;
-				invert_m4_m4(imat, ob->obmat);
-				for (i = 0; i < hmd->debug_totcontacts; ++i) {
-					HAIR_SolverContact *c = hmd->debug_contacts + i;
-					mul_m4_v3(imat, c->coA);
-					mul_m4_v3(imat, c->coB);
-				}
+			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");
 			}
+			
+			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);
 #endif
 		}
 	}
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 2e8a348..f76246a 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4865,8 +4865,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
 
 			hmd->solver = NULL;
 
-			hmd->debug_contacts = NULL;
-			hmd->debug_totcontacts = 0;
+			hmd->debug_data = NULL;
 		}
 	}
 }
diff --git a/source/blender/editors/space_view3d/drawhair.c b/source/blender/editors/space_view3d/drawhair.c
index 715cad0..6f9bda9 100644
--- a/source/blender/editors/space_view3d/drawhair.c
+++ b/source/blender/editors/space_view3d/drawhair.c
@@ -104,11 +104,44 @@ bool draw_hair_system(Scene *UNUSED(scene), View3D *UNUSED(v3d), ARegion *ar, Ba
 
 /* ---------------- debug drawing ---------------- */
 
+#define SHOW_POINTS
 //#define SHOW_ROOTS
 #define SHOW_FRAMES
 //#define SHOW_SMOOTHING
-#define SHOW_CYLINDERS
-#define SHOW_CONTACTS
+//#define SHOW_CYLINDERS
+//#define SHOW_CONTACTS
+
+static void draw_hair_debug_points(HairSystem *hsys, HAIR_SolverDebugPoint *dpoints, int dtotpoints)
+{
+#ifdef SHOW_POINTS
+	int i, k, ktot = 0;
+	
+	glColor3f(0.8f, 1.0f, 1.0f);
+	glBegin(GL_LINES);
+	
+	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 loc[3];
+				
+				glVertex3fv(point->co);
+				add_v3_v3v3(loc, point->co, dpoint->bend);
+				glVertex3fv(loc);
+			}
+		}
+	}
+	
+	glEnd();
+#else
+	(void)hsys;
+	(void)dpoints;
+	(void)dtotpoints;
+#endif
+}
 
 static void draw_hair_debug_roots(HairSystem *hsys, struct DerivedMesh *dm)
 {
@@ -137,6 +170,52 @@ static void draw_hair_debug_roots(HairSystem *hsys, struct DerivedMesh *dm)
 #endif
 }
 
+static void draw_hair_debug_frames(HairSystem *hsys, HAIR_SolverDebugPoint *dpoints, int dtotpoints)
+{
+#ifdef SHOW_FRAMES
+	const float scale = 0.2f;
+	int i, k, ktot;
+	
+	glColor3f(0.8f, 1.0f, 1.0f);
+	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], nor[3], tan[3], cotan[3];
+				
+				copy_v3_v3(co, point->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);
+				
+				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);
+			}
+		}
+	}
+	
+	glEnd();
+#else
+	(void)hsys;
+	(void)dpoints;
+	(void)dtotpoints;
+#endif
+}
+
+#if 0
 static void draw_hair_curve_debug_frames(HairSystem *hsys, HairCurve *hair)
 {
 #ifdef SHOW_FRAMES
@@ -147,24 +226,6 @@ static void draw_hair_curve_debug_frames(HairSystem *hsys, HairCurve *hair)
 	
 	glBegin(GL_LINES);
 	iter = HAIR_frame_iter_new(hair, 1.0f / hair->totpoints, hsys->smooth);
-//	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(iter)) {
 		HAIR_frame_iter_get(iter, nor, tan, cotan);
@@ -196,6 +257,7 @@ static void draw_hair_curve_debug_frames(HairSystem *hsys, HairCurve *hair)
 	(void)hair;
 #endif
 }
+#endif
 
 static void draw_hair_curve_debug_smoothing(HairSystem *hsys, HairCurve *hair)
 {
@@ -237,7 +299,7 @@ static void draw_hair_curve_debug_smoothing(HairSystem *hsys, HairCurve *hair)
 #endif
 }
 
-static void draw_hair_debug_contacts(HAIR_SolverContact *contacts, int totcontacts)
+static void draw_hair_debug_contacts(HairSystem *UNUSED(hsys), HAIR_SolverDebugContact *contacts, int totcontacts)
 {
 #ifdef SHOW_CONTACTS
 	int i;
@@ -245,7 +307,7 @@ static void draw_hair_debug_contacts(HAIR_SolverContact *contacts, int totcontac
 	glBegin(GL_LINES);
 	glColor3f(0.7f, 0.7f, 0.9f);
 	for (i = 0; i < totcontacts; ++i) {
-		HAIR_SolverContact *c = contacts + i;
+		HAIR_SolverDebugContact *c = contacts + i;
 		
 		glVertex3f(c->coA[0], c->coA[1], c->coA[2]);
 		glVertex3f(c->coB[0], c->coB[1], c->coB[2]);
@@ -255,7 +317,7 @@ static void draw_hair_debug_contacts(HAIR_SolverContact *contacts, int totcontac
 	glPointSize(3.0f);
 	glBegin(GL_POINTS);
 	for (i = 0; i < totcontacts; ++i) {
-		HAIR_SolverContact *c = contacts + i;
+		HAIR_SolverDebugContact *c = contacts + i;
 		
 		glColor3f(1.0f, 0.1f, 0.0f);
 		glVertex3f(c->coA[0], c->coA[1], c->coA[2]);
@@ -466,7 +528,6 @@ void draw_hair_debug_info(Scene *UNUSED(scene), View3D *UNUSED(v3d), ARegion *ar
 	draw_hair_debug_roots(hsys, ob->derivedFinal);
 	
 	for (hair = hsys->curves, i = 0; i < hsys->totcurves; ++hair, ++i) {
-		draw_hair_curve_debug_frames(hsys, hair);
 		draw_hair_curve_debug_smoothing(hsys, hair);
 		if (hair->totpoints > 1) {
 			tot_points += hair->totpoints;
@@ -475,5 +536,10 @@ void draw_hair_debug_info(Scene *UNUSED(scene), View3D *UNUSED(v3d), ARegion *ar
 	}
 	
 	draw_hair_debug_cylinders(hsys, tot_points, valid_points);
-	draw_hair_debug_contacts(hmd->debug_contacts, hmd->debug_totcontacts);
+	
+	if (hmd->debug_data) {
+		draw_hair_debug_frames(hsys, hmd->debug_data->points, hmd->debug_data->totpoints);
+		draw_hair_debug_points(hsys, hmd->debug_data->points, hmd->debug_data->totpoints);
+		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 daf5597..d6464d7 100644
--- a/source/blender/hair/HAIR_capi.cpp
+++ b/source/blender/hair/HAIR_capi.cpp
@@ -105,22 +105,48 @@ void HAIR_solver_step(struct HAIR_Solver *csolver, float time, float timestep)
 	solver->step_threaded(time, timestep);
 }
 
-void HAIR_solver_step_debug(struct HAIR_Solver *csolver, float time, float timestep, HAIR_SolverContact **contacts, int *totcontacts)
+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)
 {
 	Solver *solver = (Solver *)csolver;
+	Transform itfm(ob_imat);
 	
+	Debug::Points dbg_points;
+	Debug::set_points(&dbg_points);
 	Debug::CollisionContacts dbg_contacts;
 	Debug::set_collision_contacts(&dbg_contacts);
 	
 	solver->step_threaded(time, timestep);
 	
+	Debug::set_points(NULL);
+	if (points && totpoints) {
+		int tot = solver->data()->totpoints;
+		*totpoints = tot;
+		*points = (HAIR_SolverDebugPoint *)MEM_mallocN(sizeof(HAIR_SolverDebugPoint) * tot, "hair solver point debug data");
+		for (int i = 0; i < dbg_points.size(); ++i) {
+			const Debug::Point &dbg_point = dbg_points[i];
+			if (dbg_point.index < 0 || dbg_point.index >= tot)
+				continue;
+			
+			HAIR_SolverDebugPoint *p = (*points) + dbg_point.index;
+			copy_v3_v3(p->bend, transform_direction(itfm, dbg_point.bend).data());
+			copy_v3_v3(p->frame[0], transform_direction(itfm, dbg_point.frame.normal).data());
+			copy_v3_v3(p->frame[1], transform_direction(itfm, dbg_point.frame.tangent).data());
+			copy_v3_v3(p->frame[2], transform_direction(itfm, dbg_point.frame.cotangent).data());
+		}
+	}
+	
 	Debug::set_collision_contacts(NULL);
-	*totcontacts = dbg_contacts.size();
-	*contacts = (HAIR_SolverContact *)MEM_mallocN(sizeof(HAIR_SolverContact) * dbg_contacts.size(), "hair solver contact debug data");
-	for (int i = 0; i < dbg_contacts.size(); ++i) {
-		HAIR_SolverContact *c = (*contacts) + i;
-		copy_v3_v3(c->coA, dbg_contacts[i].coA.data());
-		copy_v3_v3(c->coB, dbg_contacts[i].coB.data());
+	if (contacts && totcontacts) {
+		*totcontacts = dbg_contacts.size();
+		*contacts = (HAIR_SolverDebugContact *)MEM_mallocN(sizeof(HAIR_SolverDebugContact) * dbg_contacts.size(), "hair solver contact debug data");
+		for (int i = 0; i < dbg_contacts.size(); ++i) {
+			HAIR_SolverDebugContact *c = (*contacts) + i;
+			copy_v3_v3(c->coA, transform_point(itfm, dbg_contact

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list