[Bf-blender-cvs] [c396886] master: Debug drawing feature to visualize the hair continuum grid.

Lukas Tönne noreply at git.blender.org
Tue Jan 20 09:52:07 CET 2015


Commit: c3968861b3e5a81e138003cca2b51a040a0ed454
Author: Lukas Tönne
Date:   Fri Oct 31 14:23:32 2014 +0100
Branches: master
https://developer.blender.org/rBc3968861b3e5a81e138003cca2b51a040a0ed454

Debug drawing feature to visualize the hair continuum grid.

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

M	release/scripts/startup/bl_ui/properties_particle.py
M	source/blender/editors/space_view3d/drawobject.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesdna/DNA_particle_types.h
M	source/blender/makesrna/intern/rna_particle.c
M	source/blender/physics/intern/BPH_mass_spring.cpp
M	source/blender/physics/intern/hair_volume.c
M	source/blender/physics/intern/implicit.h

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

diff --git a/release/scripts/startup/bl_ui/properties_particle.py b/release/scripts/startup/bl_ui/properties_particle.py
index 4752b75..614a648 100644
--- a/release/scripts/startup/bl_ui/properties_particle.py
+++ b/release/scripts/startup/bl_ui/properties_particle.py
@@ -343,7 +343,9 @@ class PARTICLE_PT_hair_dynamics(ParticleButtonsPanel, Panel):
         col.label(text="Quality:")
         col.prop(cloth, "quality", text="Steps", slider=True)
 
-        col.prop(cloth_md, "show_debug_data", text="Debug")
+        row = col.row()
+        row.prop(psys.settings, "show_hair_grid", text="HairGrid")
+        row.prop(cloth_md, "show_debug_data", text="Debug")
 
         if result:
             box = layout.box()
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index d42d56e..9dfcedc 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -5186,6 +5186,79 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
 					if (part->draw_col == PART_DRAW_COL_MAT)
 						glEnableClientState(GL_COLOR_ARRAY);
 			}
+			
+			if (part->draw & PART_DRAW_HAIR_GRID) {
+				ClothModifierData *clmd = psys->clmd;
+				if (clmd) {
+					float *a = clmd->hair_grid_min;
+					float *b = clmd->hair_grid_max;
+					int *res = clmd->hair_grid_res;
+					int i;
+					
+					glDisable(GL_LIGHTING);
+					glDisable(GL_COLOR_MATERIAL);
+					glDisableClientState(GL_NORMAL_ARRAY);
+					glDisableClientState(GL_COLOR_ARRAY);
+					
+					if (select)
+						UI_ThemeColor(TH_ACTIVE);
+					else
+						UI_ThemeColor(TH_WIRE);
+					glBegin(GL_LINES);
+					glVertex3f(a[0], a[1], a[2]); glVertex3f(b[0], a[1], a[2]);
+					glVertex3f(b[0], a[1], a[2]); glVertex3f(b[0], b[1], a[2]);
+					glVertex3f(b[0], b[1], a[2]); glVertex3f(a[0], b[1], a[2]);
+					glVertex3f(a[0], b[1], a[2]); glVertex3f(a[0], a[1], a[2]);
+					
+					glVertex3f(a[0], a[1], b[2]); glVertex3f(b[0], a[1], b[2]);
+					glVertex3f(b[0], a[1], b[2]); glVertex3f(b[0], b[1], b[2]);
+					glVertex3f(b[0], b[1], b[2]); glVertex3f(a[0], b[1], b[2]);
+					glVertex3f(a[0], b[1], b[2]); glVertex3f(a[0], a[1], b[2]);
+					
+					glVertex3f(a[0], a[1], a[2]); glVertex3f(a[0], a[1], b[2]);
+					glVertex3f(b[0], a[1], a[2]); glVertex3f(b[0], a[1], b[2]);
+					glVertex3f(a[0], b[1], a[2]); glVertex3f(a[0], b[1], b[2]);
+					glVertex3f(b[0], b[1], a[2]); glVertex3f(b[0], b[1], b[2]);
+					glEnd();
+					
+					if (select)
+						UI_ThemeColorShadeAlpha(TH_ACTIVE, 0, -100);
+					else
+						UI_ThemeColorShadeAlpha(TH_WIRE, 0, -100);
+					glEnable(GL_BLEND);
+					glBegin(GL_LINES);
+					for (i = 1; i < res[0]; ++i) {
+						float f = interpf(b[0], a[0], (float)i / (float)res[0]);
+						glVertex3f(f, a[1], a[2]); glVertex3f(f, b[1], a[2]);
+						glVertex3f(f, b[1], a[2]); glVertex3f(f, b[1], b[2]);
+						glVertex3f(f, b[1], b[2]); glVertex3f(f, a[1], b[2]);
+						glVertex3f(f, a[1], b[2]); glVertex3f(f, a[1], a[2]);
+					}
+					for (i = 1; i < res[1]; ++i) {
+						float f = interpf(b[1], a[1], (float)i / (float)res[1]);
+						glVertex3f(a[0], f, a[2]); glVertex3f(b[0], f, a[2]);
+						glVertex3f(b[0], f, a[2]); glVertex3f(b[0], f, b[2]);
+						glVertex3f(b[0], f, b[2]); glVertex3f(a[0], f, b[2]);
+						glVertex3f(a[0], f, b[2]); glVertex3f(a[0], f, a[2]);
+					}
+					for (i = 1; i < res[2]; ++i) {
+						float f = interpf(b[2], a[2], (float)i / (float)res[2]);
+						glVertex3f(a[0], a[1], f); glVertex3f(b[0], a[1], f);
+						glVertex3f(b[0], a[1], f); glVertex3f(b[0], b[1], f);
+						glVertex3f(b[0], b[1], f); glVertex3f(a[0], b[1], f);
+						glVertex3f(a[0], b[1], f); glVertex3f(a[0], a[1], f);
+					}
+					glEnd();
+					glDisable(GL_BLEND);
+					
+					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 */
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 6c6d24c..09271b0 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -566,6 +566,11 @@ typedef struct ClothModifierData {
 	struct ListBase ptcaches;
 	/* XXX nasty hack, remove once hair can be separated from cloth modifier data */
 	struct ClothHairRoot *roots;
+	/* grid geometry values of hair continuum */
+	float hair_grid_min[3];
+	float hair_grid_max[3];
+	int hair_grid_res[3];
+	int pad;
 	
 	struct ClothSolverResult *solver_result;
 	
diff --git a/source/blender/makesdna/DNA_particle_types.h b/source/blender/makesdna/DNA_particle_types.h
index 90b0fab..44ef274 100644
--- a/source/blender/makesdna/DNA_particle_types.h
+++ b/source/blender/makesdna/DNA_particle_types.h
@@ -334,6 +334,7 @@ typedef enum eParticleDrawFlag {
 	PART_DRAW_REN_STRAND    = (1 << 15),
 	PART_DRAW_NO_SCALE_OB   = (1 << 16), /* used with dupliobjects/groups */
 	PART_DRAW_GUIDE_HAIRS   = (1 << 17),
+	PART_DRAW_HAIR_GRID     = (1 << 18),
 } eParticleDrawFlag;
 
 /* part->type */
diff --git a/source/blender/makesrna/intern/rna_particle.c b/source/blender/makesrna/intern/rna_particle.c
index 1fa9785..f972301 100644
--- a/source/blender/makesrna/intern/rna_particle.c
+++ b/source/blender/makesrna/intern/rna_particle.c
@@ -2182,6 +2182,11 @@ static void rna_def_particle_settings(BlenderRNA *brna)
 	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_hair_grid", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "draw", PART_DRAW_HAIR_GRID);
+	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");
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index 821b08c..55475d0 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -601,6 +601,11 @@ static void cloth_continuum_step(ClothModifierData *clmd)
 	float gmin[3], gmax[3];
 	int i;
 	
+	/* clear grid info */
+	zero_v3_int(clmd->hair_grid_res);
+	zero_v3(clmd->hair_grid_min);
+	zero_v3(clmd->hair_grid_max);
+	
 	hair_get_boundbox(clmd, gmin, gmax);
 	
 	/* gather velocities & density */
@@ -637,6 +642,9 @@ static void cloth_continuum_step(ClothModifierData *clmd)
 			BPH_mass_spring_set_new_velocity(data, i, nv);
 		}
 		
+		/* store basic grid info in the modifier data */
+		BPH_hair_volume_grid_geometry(vertex_grid, NULL, clmd->hair_grid_res, clmd->hair_grid_min, clmd->hair_grid_max);
+		
 		BPH_hair_volume_free_vertex_grid(vertex_grid);
 	}
 }
diff --git a/source/blender/physics/intern/hair_volume.c b/source/blender/physics/intern/hair_volume.c
index 87f202b..b5c4188 100644
--- a/source/blender/physics/intern/hair_volume.c
+++ b/source/blender/physics/intern/hair_volume.c
@@ -38,9 +38,14 @@
 
 /* ================ Volumetric Hair Interaction ================
  * adapted from
- *      Volumetric Methods for Simulation and Rendering of Hair
- *      by Lena Petrovic, Mark Henne and John Anderson
- *      Pixar Technical Memo #06-08, Pixar Animation Studios
+ * 
+ * Volumetric Methods for Simulation and Rendering of Hair
+ *     (Petrovic, Henne, Anderson, Pixar Technical Memo #06-08, Pixar Animation Studios)
+ * 
+ * as well as
+ * 
+ * "Detail Preserving Continuum Simulation of Straight Hair"
+ *     (McAdams, Selle 2009)
  */
 
 /* Note about array indexing:
@@ -113,6 +118,10 @@ BLI_INLINE int hair_grid_interp_weights(int res, const float gmin[3], const floa
 	uvw[1] = (vec[1] - gmin[1]) / scale[1] - (float)j;
 	uvw[2] = (vec[2] - gmin[2]) / scale[2] - (float)k;
 	
+//	BLI_assert(0.0f <= uvw[0] && uvw[0] <= 1.0001f);
+//	BLI_assert(0.0f <= uvw[1] && uvw[1] <= 1.0001f);
+//	BLI_assert(0.0f <= uvw[2] && uvw[2] <= 1.0001f);
+	
 	return offset;
 }
 
@@ -244,6 +253,15 @@ BLI_INLINE float dist_tent_v3f3(const float a[3], float x, float y, float z)
 	return w;
 }
 
+BLI_INLINE float weights_sum(const float weights[8])
+{
+	float totweight = 0.0f;
+	int i;
+	for (i = 0; i < 8; ++i)
+		totweight += weights[i];
+	return totweight;
+}
+
 /* returns the grid array offset as well to avoid redundant calculation */
 static int hair_grid_weights(int res, const float gmin[3], const float scale[3], const float vec[3], float weights[8])
 {
@@ -268,6 +286,8 @@ static int hair_grid_weights(int res, const float gmin[3], const float scale[3],
 	weights[6] = dist_tent_v3f3(uvw, (float)i    , (float)(j+1), (float)(k+1));
 	weights[7] = dist_tent_v3f3(uvw, (float)(i+1), (float)(j+1), (float)(k+1));
 	
+//	BLI_assert(fabsf(weights_sum(weights) - 1.0f) < 0.0001f);
+	
 	return offset;
 }
 
@@ -409,6 +429,14 @@ void BPH_hair_volume_free_vertex_grid(HairVertexGrid *grid)
 	}
 }
 
+void BPH_hair_volume_grid_geometry(HairVertexGrid *grid, float cellsize[3], int res[3], float gmin[3], float gmax[3])
+{
+	if (cellsize) copy_v3_v3(cellsize, grid->scale);
+	if (res) { res[0] = res[1] = res[2] = grid->res; }
+	if (gmin) copy_v3_v3(gmin, grid->gmin);
+	if (gmax) copy_v3_v3(gmax, grid->gmax);
+}
+
 #if 0
 static HairGridVert *hair_volume_create_collision_grid(ClothModifierData *clmd, lfVector *lX, unsigned int numverts)
 {
diff --git a/source/blender/physics/intern/implicit.h b/source/blender/physics/intern/implicit.h
index 012125b..9ec7e76 100644
--- a/source/blender/physics/intern/implicit.h
+++ b/source/blender/physics/intern/implicit.h
@@ -170,6 +170,7 @@ struct HairColliderGrid;
 
 struct HairVertexGrid *BPH_hair_volume_create_vertex_grid(int res, const float gmin[3], const float gmax[3]);
 void BPH_hair_volume_free_vertex_grid(struct HairVertexGrid *grid);
+void BPH_hair_volume_grid_geometry(struct HairVertexGrid *gri

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list