[Bf-blender-cvs] [9c4837d] hair_system: "Render" draw mode for hair, currently just drawing the coordinate frames.

Lukas Tönne noreply at git.blender.org
Mon Aug 11 15:19:55 CEST 2014


Commit: 9c4837d8e9f03c2d04b3c6497c10bcc515c69101
Author: Lukas Tönne
Date:   Mon Aug 11 15:18:50 2014 +0200
Branches: hair_system
https://developer.blender.org/rB9c4837d8e9f03c2d04b3c6497c10bcc515c69101

"Render" draw mode for hair, currently just drawing the coordinate
frames.

The average hair segment rest length is now calculated in advance in the
DNA data, so the drawing/rendering can use it for smoothing as well.

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/blenkernel/BKE_hair.h
M	source/blender/blenkernel/intern/hair.c
M	source/blender/editors/physics/hair_ops.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_scene.cpp
M	source/blender/hair/intern/HAIR_smoothing.h
M	source/blender/hair/intern/HAIR_solver.cpp
M	source/blender/makesdna/DNA_hair_types.h
M	source/blender/makesrna/intern/rna_hair.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index e81210a..f748057 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1262,6 +1262,11 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         
         col.separator()
         
+        col.label("Render:")
+        col2.prop(params, "curl_smoothing")
+        
+        col.separator()
+        
         col.label("Display:")
         row = col.row()
         row.prop(display, "mode", expand=True)
diff --git a/source/blender/blenkernel/BKE_hair.h b/source/blender/blenkernel/BKE_hair.h
index 0cc463b..9d7e4d7 100644
--- a/source/blender/blenkernel/BKE_hair.h
+++ b/source/blender/blenkernel/BKE_hair.h
@@ -51,6 +51,8 @@ struct HairPoint *BKE_hair_point_insert_multi(struct HairSystem *hsys, struct Ha
 void BKE_hair_point_remove(struct HairSystem *hsys, struct HairCurve *hair, struct HairPoint *point);
 void BKE_hair_point_remove_position(struct HairSystem *hsys, struct HairCurve *hair, int pos);
 
+void BKE_hair_calculate_rest(struct HairSystem *hsys);
+
 void BKE_hair_debug_data_free(struct HairDebugData *debug_data);
 
 #endif
diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.c
index 3f86e84..b07775a 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.c
@@ -33,6 +33,7 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "BLI_math.h"
 #include "BLI_utildefines.h"
 
 #include "DNA_hair_types.h"
@@ -192,6 +193,25 @@ void BKE_hair_point_remove_position(HairSystem *UNUSED(hsys), HairCurve *hair, i
 	hair->totpoints = ntotpoints;
 }
 
+void BKE_hair_calculate_rest(HairSystem *hsys)
+{
+	HairCurve *hair;
+	int i;
+	
+	for (i = 0, hair = hsys->curves; i < hsys->totcurves; ++i, ++hair) {
+		HairPoint *point;
+		int k;
+		float tot_rest_length;
+		
+		tot_rest_length = 0.0f;
+		for (k = 1, point = hair->points + 1; k < hair->totpoints; ++k, ++point) {
+			tot_rest_length += len_v3v3((point-1)->rest_co, point->rest_co);
+		}
+		if (hair->totpoints > 1)
+			hair->avg_rest_length = tot_rest_length / (float)(hair->totpoints-1);
+	}
+}
+
 void BKE_hair_debug_data_free(HairDebugData *debug_data)
 {
 	if (debug_data) {
diff --git a/source/blender/editors/physics/hair_ops.c b/source/blender/editors/physics/hair_ops.c
index 9bf00c6..15a08ae 100644
--- a/source/blender/editors/physics/hair_ops.c
+++ b/source/blender/editors/physics/hair_ops.c
@@ -276,6 +276,8 @@ static int hair_copy_from_particles_exec(bContext *C, wmOperator *op)
 		hmd->flag &= ~MOD_HAIR_SOLVER_DATA_VALID;
 	}
 	
+	BKE_hair_calculate_rest(hsys);
+	
 	WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
 	return OPERATOR_FINISHED;
 }
diff --git a/source/blender/editors/space_view3d/drawhair.c b/source/blender/editors/space_view3d/drawhair.c
index f37e022..5d3bfbe 100644
--- a/source/blender/editors/space_view3d/drawhair.c
+++ b/source/blender/editors/space_view3d/drawhair.c
@@ -57,30 +57,99 @@
 
 /* TODO vertex/index buffers, etc. etc., avoid direct mode ... */
 
-static void draw_hair_curve(HairSystem *UNUSED(hsys), HairCurve *hair)
+static void draw_hair_line(HairSystem *hsys)
 {
-	HairPoint *point;
-	int k;
+	HairCurve *hair;
+	int i;
 	
-	glColor3f(0.4f, 0.7f, 1.0f);
+	for (hair = hsys->curves, i = 0; i < hsys->totcurves; ++hair, ++i) {
+		HairPoint *point;
+		int k;
+		
+		glColor3f(0.4f, 0.7f, 1.0f);
+		
+		glBegin(GL_LINE_STRIP);
+		for (point = hair->points, k = 0; k < hair->totpoints; ++point, ++k) {
+			glVertex3fv(point->co);
+		}
+		glEnd();
+		
+		glPointSize(2.5f);
+		glBegin(GL_POINTS);
+		for (point = hair->points, k = 0; k < hair->totpoints; ++point, ++k) {
+			if (k == 0)
+				glColor3f(1.0f, 0.0f, 1.0f);
+			else
+				glColor3f(0.2f, 0.0f, 1.0f);
+			glVertex3fv(point->co);
+		}
+		glEnd();
+		glPointSize(1.0f);
+	}
+}
+
+static void get_hair_root_frame(HairCurve *hair, float frame[3][3])
+{
+	const float up[3] = {0.0f, 0.0f, 1.0f};
+	float normal[3];
 	
-	glBegin(GL_LINE_STRIP);
-	for (point = hair->points, k = 0; k < hair->totpoints; ++point, ++k) {
-		glVertex3fv(point->co);
+	if (hair->totpoints >= 2) {
+		sub_v3_v3v3(normal, hair->points[1].co, hair->points[0].co);
+		normalize_v3(normal);
+		
+		copy_v3_v3(frame[0], normal);
+		madd_v3_v3v3fl(frame[1], up, normal, -dot_v3v3(up, normal));
+		normalize_v3(frame[1]);
+		cross_v3_v3v3(frame[2], frame[0], frame[1]);
 	}
-	glEnd();
+	else {
+		unit_m3(frame);
+	}
+}
+
+static void draw_hair_render(HairSystem *hsys)
+{
+	const float scale = 0.2f;
 	
-	glPointSize(2.5f);
-	glBegin(GL_POINTS);
-	for (point = hair->points, k = 0; k < hair->totpoints; ++point, ++k) {
-		if (k == 0)
-			glColor3f(1.0f, 0.0f, 1.0f);
-		else
-			glColor3f(0.2f, 0.0f, 1.0f);
-		glVertex3fv(point->co);
+	struct HAIR_FrameIterator *iter = HAIR_frame_iter_new();
+	int i;
+	
+	glBegin(GL_LINES);
+	
+	for (i = 0; i < hsys->totcurves; ++i) {
+		HairCurve *hair = hsys->curves + i;
+		float initial_frame[3][3];
+		
+		get_hair_root_frame(hair, initial_frame);
+		
+		for (HAIR_frame_iter_init(iter, hair, hair->avg_rest_length, hsys->params.curl_smoothing, initial_frame); HAIR_frame_iter_valid(iter); HAIR_frame_iter_next(iter)) {
+			HairPoint *point = hair->points + HAIR_frame_iter_index(iter);
+			float co[3], nor[3], tan[3], cotan[3];
+			
+			copy_v3_v3(co, point->co);
+			HAIR_frame_iter_get(iter, nor, tan, cotan);
+			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);
+			
+			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();
-	glPointSize(1.0f);
+	
+	HAIR_frame_iter_free(iter);
 }
 
 static void count_hairs(HairSystem *hsys, int *totpoints, int *validhairs)
@@ -285,8 +354,6 @@ bool draw_hair_system(Scene *UNUSED(scene), View3D *UNUSED(v3d), ARegion *ar, Ba
 {
 	RegionView3D *rv3d = ar->regiondata;
 	Object *ob = base->object;
-	HairCurve *hair;
-	int i;
 	bool retval = true;
 	
 	glLoadMatrixf(rv3d->viewmat);
@@ -294,12 +361,10 @@ bool draw_hair_system(Scene *UNUSED(scene), View3D *UNUSED(v3d), ARegion *ar, Ba
 	
 	switch (hsys->display.mode) {
 		case HAIR_DISPLAY_LINE:
-			for (hair = hsys->curves, i = 0; i < hsys->totcurves; ++hair, ++i) {
-				draw_hair_curve(hsys, hair);
-			}
+			draw_hair_line(hsys);
 			break;
 		case HAIR_DISPLAY_RENDER:
-			// TODO
+			draw_hair_render(hsys);
 			break;
 		case HAIR_DISPLAY_HULL:
 			draw_hair_hulls(hsys);
diff --git a/source/blender/hair/HAIR_capi.cpp b/source/blender/hair/HAIR_capi.cpp
index 81186ca..91e5030 100644
--- a/source/blender/hair/HAIR_capi.cpp
+++ b/source/blender/hair/HAIR_capi.cpp
@@ -174,6 +174,9 @@ void HAIR_solver_apply(struct HAIR_Solver *csolver, Scene *scene, Object *ob, Ha
 struct HairCurveWalker {
 	typedef float3 data_t;
 	
+	HairCurveWalker()
+	{}
+	
 	HairCurveWalker(HairCurve *curve) :
 	    curve(curve),
 	    i(0)
@@ -232,19 +235,21 @@ void HAIR_smoothing_iter_next(struct HAIR_SmoothingIteratorFloat3 *citer)
 	iter->next();
 }
 
-#if 0
-struct HAIR_FrameIterator *HAIR_frame_iter_new(HairCurve *curve, float rest_length, float amount)
+struct HAIR_FrameIterator *HAIR_frame_iter_new(void)
 {
-	HairCurveFrameIterator *iter = new HairCurveFrameIterator(HairCurveWalker(curve), rest_length, amount);
-	
-	return (struct HAIR_FrameIterator *)iter;
+	return (struct HAIR_FrameIterator *)(new HairCurveFrameIterator());
 }
 
 void HAIR_frame_iter_free(struct HAIR_FrameIterator *citer)
 {
+	delete ((HairCurveFrameIterator *)citer);
+}
+
+void HAIR_frame_iter_init(struct HAIR_FrameIterator *citer, HairCurve *curve, float rest_length, float amount, float initial_frame[3][3])
+{
 	HairCurveFrameIterator *iter = (HairCurveFrameIterator *)citer;
 	
-	delete iter;
+	*iter = HairCurveFrameIterator(HairCurveWalker(curve), rest_length, amount, Frame(initial_frame[0], initial_frame[1], initial_frame[2]));
 }
 
 bool HAIR_frame_iter_valid(struct HAIR_FrameIterator *citer)
@@ -254,6 +259,13 @@ bool HAIR_frame_iter_valid(struct HAIR_FrameIterator *citer)
 	return iter->valid();
 }
 
+int HAIR_frame_iter_index(struct HAIR_FrameIterator *citer)
+{
+	HairCurveFrameIterator *iter = (HairCurveFrameIterator *)citer;
+	
+	return iter->index();
+}
+
 void HAIR_frame_iter_get(struct HAIR_FrameIterator *citer, float cnor[3], float ctan[3], float ccotan[3])
 {
 	HairCurveFrameIterator *iter = (HairCurveFrameIterator *)citer;
@@ -269,4 +281,3 @@ void HAIR_frame_iter_next(struct HAIR_FrameIterator *citer)
 	
 	iter->next();
 }
-#endif
diff --git a/source/blender/hair/HAIR_capi.h b/source/blender/hair/HAIR_capi.h
index d419478..0037384 100644
--- a/source/blender/hair/HAIR_capi.h
+++ b/source/blender/hair/HAIR_capi.h
@@ -69,13 +69,13 @@ bool HAIR_smoothing_iter_valid(struct HAIR_SmoothingIteratorFloat3 *iter);
 void HAIR_smoothing_iter_get(struct HAIR_SmoothingIteratorFloat3 *iter, float val[3]);
 void HAIR_smoothing_iter_next(struct HAIR_SmoothingIteratorFloat3 *iter);
 
-#if 0
-struct HAIR_FrameIterator *HAIR_frame_iter_new(struct HairCurve *curve, float rest_length, float amount);
+struct HAIR_FrameIterator *HAIR_frame_iter_new(void);
 void HAIR_frame_iter_free(struct HAIR_FrameIterator *iter);
+void HAIR_frame_iter_init(struct HAIR_FrameIterator *iter, struct HairCurve *curve, float rest_length, float amount, float initial_frame[3][3]);
 bool HAIR_frame_iter_valid(struct HAIR_FrameIterator *iter);
+int HAIR_frame_iter_index(struct HAIR_FrameIterator *citer);
 void HAIR_frame_iter_get(struct HAIR_FrameIterator *iter, float nor[3], float tan[3], float cotan[3]);
 void HAIR_frame_iter_next(struct HAIR_FrameIterator *iter);
-#endif
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/hair/intern/HAIR_scene.cpp b/source/blender/hair/intern/HAIR_scene.cpp
index c837a16..ebe8135 100644
--- a/source/blender/hair/intern/HAIR_scene.cpp
+++ b/source/blender/hair/intern/HAIR_scene.cpp
@@ -92,6 +92,7 @@ SolverData *SceneConverter::bui

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list