[Bf-blender-cvs] [71dd6e2] hair_immediate_fixes: Guide hair drawing for hair particles.

Lukas Tönne noreply at git.blender.org
Fri Oct 3 16:49:24 CEST 2014


Commit: 71dd6e2ada7eefef6cf5bef11dff8795b9bb71b4
Author: Lukas Tönne
Date:   Fri Oct 3 16:46:08 2014 +0200
Branches: hair_immediate_fixes
https://developer.blender.org/rB71dd6e2ada7eefef6cf5bef11dff8795b9bb71b4

Guide hair drawing for hair particles.

Without this the particle system only shows the actual non-simulated
hairs ("guide hairs") during edit mode. These hairs are used for goals
as well, so showing them in the regular viewport is pretty important.

Also the usual hair curves are interpolated along the entire length,
which makes it very difficult to see exact vertex positions, unless
using exact powers of 2 for the segment number and match the display
steps.

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

M	release/scripts/startup/bl_ui/properties_particle.py
M	source/blender/blenkernel/intern/particle.c
M	source/blender/editors/space_view3d/drawobject.c
M	source/blender/makesdna/DNA_particle_types.h
M	source/blender/makesrna/intern/rna_particle.c

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

diff --git a/release/scripts/startup/bl_ui/properties_particle.py b/release/scripts/startup/bl_ui/properties_particle.py
index fa6b1c5..4869500 100644
--- a/release/scripts/startup/bl_ui/properties_particle.py
+++ b/release/scripts/startup/bl_ui/properties_particle.py
@@ -1158,6 +1158,7 @@ class PARTICLE_PT_draw(ParticleButtonsPanel, Panel):
 
         row = layout.row()
         row.prop(part, "draw_method", expand=True)
+        row.prop(part, "show_guide_hairs")
 
         if part.draw_method == 'NONE' or (part.render_type == 'NONE' and part.draw_method == 'RENDER'):
             return
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index ffdeb23..02a86ce 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -3064,19 +3064,12 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra)
 
 		/*--interpolate actual path from data points--*/
 		for (k = 0, ca = cache[p]; k <= steps; k++, ca++) {
-			if (edit && shapekey) {
-				copy_v3_v3(ca->co, shapekey);
-				shapekey += 3;
-			}
-			else {
-				ParticleKey result;
-				
-				time = (float)k / (float)steps;
-				t = birthtime + time * (dietime - birthtime);
-				result.time = -t;
-				do_particle_interpolation(psys, p, pa, t, &pind, &result);
-				copy_v3_v3(ca->co, result.co);
-			}
+			ParticleKey result;
+			time = (float)k / (float)steps;
+			t = birthtime + time * (dietime - birthtime);
+			result.time = -t;
+			do_particle_interpolation(psys, p, pa, t, &pind, &result);
+			copy_v3_v3(ca->co, result.co);
 
 			/* dynamic hair is in object space */
 			/* keyed and baked are already in global space */
@@ -3087,7 +3080,24 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra)
 
 			copy_v3_v3(ca->col, col);
 		}
-		
+
+		if (part->type == PART_HAIR) {
+			HairKey *hkey;
+			
+			for (k = 0, hkey = pa->hair; k < pa->totkey; ++k, ++hkey) {
+				float co[3];
+				if (edit && shapekey) {
+					copy_v3_v3(co, shapekey);
+					shapekey += 3;
+				}
+				else {
+					copy_v3_v3(co, hkey->co);
+				}
+				
+				mul_v3_m4v3(hkey->world_co, hairmat, co);
+			}
+		}
+
 		/*--modify paths and calculate rotation & velocity--*/
 
 		if (!(psys->flag & PSYS_GLOBAL_HAIR)) {
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index 62b0c86..544ac8d 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -5159,6 +5159,34 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
 				glDrawArrays(GL_LINE_STRIP, 0, path->steps + 1);
 			}
 		}
+
+		if (part->type ==  PART_HAIR) {
+			if (part->draw & PART_DRAW_GUIDE_HAIRS) {
+				glDisable(GL_LIGHTING);
+				glDisable(GL_COLOR_MATERIAL);
+				glDisableClientState(GL_NORMAL_ARRAY);
+				glDisableClientState(GL_COLOR_ARRAY);
+				for (a = 0, pa = psys->particles; a < totpart; a++, pa++) {
+					if (pa->totkey > 1) {
+						HairKey *hkey = pa->hair;
+						
+						glVertexPointer(3, GL_FLOAT, sizeof(HairKey), hkey->world_co);
+						
+						// XXX use proper theme color here
+//						UI_ThemeColor(TH_NORMAL);
+						glColor3f(0.58f, 0.67f, 1.0f);
+						
+						glDrawArrays(GL_LINE_STRIP, 0, pa->totkey);
+					}
+				}
+				glEnable(GL_LIGHTING);
+				glEnable(GL_COLOR_MATERIAL);
+				glEnableClientState(GL_NORMAL_ARRAY);
+				if ((dflag & DRAW_CONSTCOLOR) == 0)
+					if (part->draw_col == PART_DRAW_COL_MAT)
+						glEnableClientState(GL_COLOR_ARRAY);
+			}
+		}
 		
 		/* draw child particles */
 		cache = psys->childcache;
diff --git a/source/blender/makesdna/DNA_particle_types.h b/source/blender/makesdna/DNA_particle_types.h
index c03d6de..5a4a2c1 100644
--- a/source/blender/makesdna/DNA_particle_types.h
+++ b/source/blender/makesdna/DNA_particle_types.h
@@ -44,6 +44,7 @@ typedef struct HairKey {
 	float weight;	/* softbody weight */
 	short editflag;	/* saved particled edit mode flags */
 	short pad;
+	float world_co[3];
 } HairKey;
 
 typedef struct ParticleKey {	/* when changed update size of struct to copy_particleKey()!! */
@@ -316,6 +317,28 @@ typedef struct ParticleSystem {
 	float pad2;
 } ParticleSystem;
 
+typedef enum eParticleDrawFlag {
+	PART_DRAW_VEL           = (1 << 0),
+	PART_DRAW_GLOBAL_OB	    = (1 << 1),
+	PART_DRAW_SIZE          = (1 << 2),
+	PART_DRAW_EMITTER       = (1 << 3), /* render emitter also */
+	PART_DRAW_HEALTH        = (1 << 4),
+	PART_ABS_PATH_TIME      = (1 << 5),
+	PART_DRAW_COUNT_GR      = (1 << 6),
+	PART_DRAW_BB_LOCK       = (1 << 7), /* used with billboards */
+	PART_DRAW_ROTATE_OB     = (1 << 7), /* used with dupliobjects/groups */
+	PART_DRAW_PARENT        = (1 << 8),
+	PART_DRAW_NUM           = (1 << 9),
+	PART_DRAW_RAND_GR       = (1 << 10),
+	PART_DRAW_REN_ADAPT     = (1 << 11),
+	PART_DRAW_VEL_LENGTH    = (1 << 12),
+	PART_DRAW_MAT_COL       = (1 << 13), /* deprecated, but used in do_versions */
+	PART_DRAW_WHOLE_GR      = (1 << 14),
+	PART_DRAW_REN_STRAND    = (1 << 15),
+	PART_DRAW_NO_SCALE_OB   = (1 << 16), /* used with dupliobjects/groups */
+	PART_DRAW_GUIDE_HAIRS   = (1 << 17),
+} eParticleDrawFlag;
+
 /* part->type */
 /* hair is allways baked static in object/geometry space */
 /* other types (normal particles) are in global space and not static baked */
@@ -394,26 +417,6 @@ typedef struct ParticleSystem {
 #define PART_KINK_WAVE		3
 #define PART_KINK_BRAID		4
 
-/* part->draw */
-#define PART_DRAW_VEL		1
-#define PART_DRAW_GLOBAL_OB	2
-#define PART_DRAW_SIZE		4
-#define PART_DRAW_EMITTER	8	/* render emitter also */
-#define PART_DRAW_HEALTH	16
-#define PART_ABS_PATH_TIME  32
-#define PART_DRAW_COUNT_GR	64
-#define PART_DRAW_BB_LOCK	128	/* used with billboards */
-#define PART_DRAW_ROTATE_OB 128 /* used with dupliobjects/groups */
-#define PART_DRAW_PARENT	256
-#define PART_DRAW_NUM		512
-#define PART_DRAW_RAND_GR	1024
-#define PART_DRAW_REN_ADAPT	2048
-#define PART_DRAW_VEL_LENGTH	(1<<12)
-#define PART_DRAW_MAT_COL		(1<<13) /* deprecated, but used in do_versions */
-#define PART_DRAW_WHOLE_GR		(1<<14)
-#define PART_DRAW_REN_STRAND	(1<<15)
-#define PART_DRAW_NO_SCALE_OB 	(1<<16) /* used with dupliobjects/groups */
-
 /* part->draw_col */
 #define PART_DRAW_COL_NONE		0
 #define PART_DRAW_COL_MAT		1
diff --git a/source/blender/makesrna/intern/rna_particle.c b/source/blender/makesrna/intern/rna_particle.c
index 0dd08d9..c283c9f 100644
--- a/source/blender/makesrna/intern/rna_particle.c
+++ b/source/blender/makesrna/intern/rna_particle.c
@@ -2252,6 +2252,11 @@ static void rna_def_particle_settings(BlenderRNA *brna)
 	RNA_def_property_update(prop, 0, "rna_Particle_reset");
 
 	/*draw flag*/
+	prop = RNA_def_property(srna, "show_guide_hairs", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "draw", PART_DRAW_GUIDE_HAIRS);
+	RNA_def_property_ui_text(prop, "Guide Hairs", "Show guide hairs");
+	RNA_def_property_update(prop, 0, "rna_Particle_redo");
+
 	prop = RNA_def_property(srna, "show_velocity", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "draw", PART_DRAW_VEL);
 	RNA_def_property_ui_text(prop, "Velocity", "Show particle velocity");




More information about the Bf-blender-cvs mailing list