[Bf-blender-cvs] [bf96400] master: Use a fixed, uniform cell size for hair continuum grids.
Lukas Tönne
noreply at git.blender.org
Tue Jan 20 09:52:26 CET 2015
Commit: bf96400558db9e8e79a00a73eba99a1ca008231f
Author: Lukas Tönne
Date: Thu Nov 6 14:05:32 2014 +0100
Branches: master
https://developer.blender.org/rBbf96400558db9e8e79a00a73eba99a1ca008231f
Use a fixed, uniform cell size for hair continuum grids.
This is a bit more awkward for artists to use, but necessary for
a stable solution of the hair continuum calculation. The grid size is
defined by the user, the extent of the grid is then calculated based on
the hair geometry. A hard upper limit prevents bad memory allocation
in case too small values are entered.
Conflicts:
source/blender/physics/intern/BPH_mass_spring.cpp
===================================================================
M release/scripts/startup/bl_ui/properties_particle.py
M source/blender/blenkernel/intern/cloth.c
M source/blender/makesdna/DNA_cloth_types.h
M source/blender/makesrna/intern/rna_cloth.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 614a648..690a9d1 100644
--- a/release/scripts/startup/bl_ui/properties_particle.py
+++ b/release/scripts/startup/bl_ui/properties_particle.py
@@ -329,7 +329,7 @@ class PARTICLE_PT_hair_dynamics(ParticleButtonsPanel, Panel):
# XXX disabled due to stability issues
#sub.prop(cloth, "pressure", slider=True, text="Pressure")
#sub.prop(cloth, "pressure_threshold", slider=True, text="Threshold")
- col.prop(cloth, "voxel_resolution")
+ col.prop(cloth, "voxel_cell_size")
split.separator()
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index a8d7d0a..09239a7 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -153,7 +153,7 @@ void cloth_init(ClothModifierData *clmd )
clmd->sim_parms->goalfrict = 0.0f;
clmd->sim_parms->velocity_smooth = 0.0f;
- clmd->sim_parms->voxel_res = 32;
+ clmd->sim_parms->voxel_cell_size = 0.1f;
if (!clmd->sim_parms->effector_weights)
clmd->sim_parms->effector_weights = BKE_add_effector_weights(NULL);
diff --git a/source/blender/makesdna/DNA_cloth_types.h b/source/blender/makesdna/DNA_cloth_types.h
index c32f6db..f4d8faa 100644
--- a/source/blender/makesdna/DNA_cloth_types.h
+++ b/source/blender/makesdna/DNA_cloth_types.h
@@ -80,7 +80,7 @@ typedef struct ClothSimSettings {
* should really be separate, this struct is a horrible mess already
*/
float bending_damping; /* damping of bending springs */
- int voxel_res; /* resolution of voxel grid for interaction */
+ float voxel_cell_size; /* size of voxel grid cells for continuum dynamics */
int pad;
int stepsPerFrame; /* Number of time steps per frame. */
diff --git a/source/blender/makesrna/intern/rna_cloth.c b/source/blender/makesrna/intern/rna_cloth.c
index ff5f2d2..1176da7 100644
--- a/source/blender/makesrna/intern/rna_cloth.c
+++ b/source/blender/makesrna/intern/rna_cloth.c
@@ -470,11 +470,11 @@ static void rna_def_cloth_sim_settings(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Shrink Factor Max", "Max amount to shrink cloth by");
RNA_def_property_update(prop, 0, "rna_cloth_update");
- prop = RNA_def_property(srna, "voxel_resolution", PROP_INT, PROP_UNSIGNED);
- RNA_def_property_int_sdna(prop, NULL, "voxel_res");
- RNA_def_property_range(prop, 1, 128);
- RNA_def_property_int_default(prop, 32);
- RNA_def_property_ui_text(prop, "Voxel Grid Resolution", "Resolution of the voxel grid for interaction effects");
+ prop = RNA_def_property(srna, "voxel_cell_size", PROP_FLOAT, PROP_UNSIGNED);
+ RNA_def_property_float_sdna(prop, NULL, "voxel_cell_size");
+ RNA_def_property_range(prop, 0.0001f, 10000.0f);
+ RNA_def_property_float_default(prop, 0.1f);
+ RNA_def_property_ui_text(prop, "Voxel Grid Cell Size", "Size of the voxel grid cells for interaction effects");
RNA_def_property_update(prop, 0, "rna_cloth_update");
/* springs */
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index 1569396..45032b1 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -584,7 +584,7 @@ static void cloth_calc_volume_force(ClothModifierData *clmd)
#endif
/* returns active vertexes' motion state, or original location the vertex is disabled */
-BLI_INLINE bool cloth_get_grid_location(Implicit_Data *data, const float cell_scale[3], const float cell_offset[3],
+BLI_INLINE bool cloth_get_grid_location(Implicit_Data *data, float cell_scale, const float cell_offset[3],
ClothVertex *vert, int index, float x[3], float v[3])
{
bool is_motion_state;
@@ -592,7 +592,7 @@ BLI_INLINE bool cloth_get_grid_location(Implicit_Data *data, const float cell_sc
BPH_mass_spring_get_new_velocity(data, index, v);
is_motion_state = true;
- mul_v3_v3(x, cell_scale);
+ mul_v3_fl(x, cell_scale);
add_v3_v3(x, cell_offset);
return is_motion_state;
@@ -618,7 +618,7 @@ BLI_INLINE LinkNode *hair_spring_next(LinkNode *spring_link)
* (3,4), (2,3), (1,2)
* This is currently the only way to figure out hair geometry inside this code ...
*/
-static LinkNode *cloth_continuum_add_hair_segments(HairGrid *grid, const float cell_scale[3], const float cell_offset[3], Cloth *cloth, LinkNode *spring_link)
+static LinkNode *cloth_continuum_add_hair_segments(HairGrid *grid, const float cell_scale, const float cell_offset[3], Cloth *cloth, LinkNode *spring_link)
{
Implicit_Data *data = cloth->implicit;
LinkNode *next_spring_link = NULL; /* return value */
@@ -723,16 +723,14 @@ static void cloth_continuum_fill_grid(HairGrid *grid, Cloth *cloth)
}
#else
LinkNode *link;
- float cellsize[3], gmin[3], cell_scale[3], cell_offset[3];
+ float cellsize, gmin[3], cell_scale, cell_offset[3];
/* scale and offset for transforming vertex locations into grid space
* (cell size is 0..1, gmin becomes origin)
*/
- BPH_hair_volume_grid_geometry(grid, cellsize, NULL, gmin, NULL);
- cell_scale[0] = cellsize[0] > 0.0f ? 1.0f / cellsize[0] : 0.0f;
- cell_scale[1] = cellsize[1] > 0.0f ? 1.0f / cellsize[1] : 0.0f;
- cell_scale[2] = cellsize[2] > 0.0f ? 1.0f / cellsize[2] : 0.0f;
- mul_v3_v3v3(cell_offset, gmin, cell_scale);
+ BPH_hair_volume_grid_geometry(grid, &cellsize, NULL, gmin, NULL);
+ cell_scale = cellsize > 0.0f ? 1.0f / cellsize : 0.0f;
+ mul_v3_v3fl(cell_offset, gmin, cell_scale);
negate_v3(cell_offset);
link = cloth->springs;
@@ -760,7 +758,6 @@ static void cloth_continuum_step(ClothModifierData *clmd)
float pressfac = parms->pressure;
float minpress = parms->pressure_threshold;
float gmin[3], gmax[3];
- float cellsize[3];
int i;
/* clear grid info */
@@ -772,11 +769,9 @@ static void cloth_continuum_step(ClothModifierData *clmd)
/* gather velocities & density */
if (smoothfac > 0.0f || pressfac > 0.0f) {
- HairGrid *grid = BPH_hair_volume_create_vertex_grid(clmd->sim_parms->voxel_res, gmin, gmax);
+ HairGrid *grid = BPH_hair_volume_create_vertex_grid(clmd->sim_parms->voxel_cell_size, gmin, gmax);
BPH_hair_volume_set_debug_data(grid, clmd->debug_data);
- BPH_hair_volume_grid_geometry(grid, cellsize, NULL, NULL, NULL);
-
cloth_continuum_fill_grid(grid, cloth);
for (i = 0, vert = cloth->verts; i < numverts; i++, vert++) {
@@ -1010,7 +1005,7 @@ bool BPH_cloth_solver_get_texture_data(Object *UNUSED(ob), ClothModifierData *cl
hair_get_boundbox(clmd, gmin, gmax);
- grid = BPH_hair_volume_create_vertex_grid(clmd->sim_parms->voxel_res, gmin, gmax);
+ grid = BPH_hair_volume_create_vertex_grid(clmd->sim_parms->voxel_cell_size, gmin, gmax);
cloth_continuum_fill_grid(grid, cloth);
BPH_hair_volume_get_texture_data(grid, vd);
diff --git a/source/blender/physics/intern/hair_volume.c b/source/blender/physics/intern/hair_volume.c
index 77c3af3..0713878 100644
--- a/source/blender/physics/intern/hair_volume.c
+++ b/source/blender/physics/intern/hair_volume.c
@@ -66,15 +66,9 @@
static float I[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
-static int hair_grid_size(int res)
+BLI_INLINE int hair_grid_size(const int res[3])
{
- return res * res * res;
-}
-
-BLI_INLINE void hair_grid_get_scale(int res, const float gmin[3], const float gmax[3], float scale[3])
-{
- sub_v3_v3v3(scale, gmax, gmin);
- mul_v3_fl(scale, 1.0f / (res-1));
+ return res[0] * res[1] * res[2];
}
typedef struct HairGridVert {
@@ -86,36 +80,36 @@ typedef struct HairGridVert {
typedef struct HairGrid {
HairGridVert *verts;
- int res;
+ int res[3];
float gmin[3], gmax[3];
- float scale[3];
+ float cellsize, inv_cellsize;
struct SimDebugData *debug_data;
} HairGrid;
-#define HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, axis) ( min_ii( max_ii( (int)((vec[axis] - gmin[axis]) / scale[axis]), 0), res-2 ) )
+#define HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, axis) ( min_ii( max_ii( (int)((vec[axis] - gmin[axis]) * scale), 0), res[axis]-2 ) )
-BLI_INLINE int hair_grid_offset(const float vec[3], int res, const float gmin[3], const float scale[3])
+BLI_INLINE int hair_grid_offset(const float vec[3], const int res[3], const float gmin[3], float scale)
{
int i, j, k;
i = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 0);
j = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 1);
k = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 2);
- return i + (j + k*res)*res;
+ return i + (j + k*res[1])*res[0];
}
-BLI_INLINE int hair_grid_interp_weights(int res, const float gmin[3], const float scale[3], const float vec[3], float uvw[3])
+BLI_INLINE int hair_grid_interp_weights(const int res[3], const float gmin[3], float scale, const float vec[3], float uvw[3])
{
int i, j, k, offset;
i = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 0);
j = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 1);
k = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 2);
- offset = i + (j + k*res)*res;
+ offset = i + (j + k*res[1])*res[0];
- uvw[0] = (vec[0] - gmin[0]) / scale[0] - (float)i;
- uvw[1] = (vec[1] - gmin[1]) / scale[1] - (float)j;
- uvw[2] = (vec[2] - gmin[2]) / scale[2] - (float)k;
+ uvw[0] = (vec[0] - gmin[0]) * scale - (float)i;
+ uvw[1] = (vec[1] - gmin[1]) * scale - (float)j;
+ uvw[2] = (vec[2] - gmin[2]) * scale - (float)k;
// BLI_assert(0.0f <= uvw[0] && uvw[0] <= 1.0001f);
// BLI_assert(0.0f <= uvw[1] && uvw[1] <= 1.0001f);
@@ -124,12 +118,12 @@ BLI_INLINE int hair_grid_interp_weights(int res, const float gmin[3], const floa
return offset;
}
-BLI_INLINE void hair_grid_interpolate(const HairGridVert *grid, int res, const float gmin[3], const float scale[3], const float vec[3],
+BLI_INLINE void hair_grid_interpolate(const HairGridVert *grid, const int res[3], const float gmin[3], float scale, const float vec[3],
float *density, float velocity[3], float density_gradient[3], float velocity_gradient[3][3])
{
HairGridVert data[8];
float uvw[3], muvw[3];
- int res2 = res * res;
+ int res2 = res[1] * res[0];
int offset;
offset = hair_grid_interp_weights(res
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list