diff options
author | Lukas Tönne <lukas.toenne@gmail.com> | 2014-10-31 16:23:32 +0300 |
---|---|---|
committer | Lukas Tönne <lukas.toenne@gmail.com> | 2015-01-20 11:30:05 +0300 |
commit | c3968861b3e5a81e138003cca2b51a040a0ed454 (patch) | |
tree | c197df6f86c76ead3e76c9b3f4fc7caa0f4b584d /source | |
parent | aea309779f631e4f0bb6fa2a38f39d4f4db4de97 (diff) |
Debug drawing feature to visualize the hair continuum grid.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/space_view3d/drawobject.c | 73 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_modifier_types.h | 5 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_particle_types.h | 1 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_particle.c | 5 | ||||
-rw-r--r-- | source/blender/physics/intern/BPH_mass_spring.cpp | 8 | ||||
-rw-r--r-- | source/blender/physics/intern/hair_volume.c | 34 | ||||
-rw-r--r-- | source/blender/physics/intern/implicit.h | 1 |
7 files changed, 124 insertions, 3 deletions
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index d42d56e614e..9dfcedceb61 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 6c6d24cb7a7..09271b03b57 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 90b0fab5073..44ef2746159 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 1fa9785397c..f97230144d6 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 821b08ce334..55475d06d8d 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 87f202bbb2c..b5c41880268 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 012125b4c87..9ec7e763415 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 *grid, float cellsize[3], int res[3], float gmin[3], float gmax[3]); void BPH_hair_volume_add_vertex(struct HairVertexGrid *grid, const float x[3], const float v[3]); void BPH_hair_volume_normalize_vertex_grid(struct HairVertexGrid *grid); |