[Bf-blender-cvs] [f79cf18] hair_immediate_fixes: Fallback method for defining density in the hair grid using discrete samples.

Lukas Tönne noreply at git.blender.org
Fri Nov 14 15:11:51 CET 2014


Commit: f79cf1884840f5c33d9f476b2d3521c2e8bc2cbd
Author: Lukas Tönne
Date:   Fri Nov 14 11:10:45 2014 +0100
Branches: hair_immediate_fixes
https://developer.blender.org/rBf79cf1884840f5c33d9f476b2d3521c2e8bc2cbd

Fallback method for defining density in the hair grid using discrete
samples.

This is just an intermediate method to make sure the density is valid.
Eventually the closest-point method should be used, but for testing
the poisson solver this is easier to debug.

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

M	source/blender/physics/intern/BPH_mass_spring.cpp
M	source/blender/physics/intern/hair_volume.cpp

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

diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index baac772..bdc4ced 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -950,6 +950,8 @@ static void cloth_continuum_step(ClothModifierData *clmd, float dt)
 					if (!is_zero_v3(gvel) || !is_zero_v3(gvel_smooth)) {
 						BKE_sim_debug_data_add_vector(clmd->debug_data, x, gvel, 0.4, 0, 1, "grid velocity", hash_int_2d(hash_int_2d(i, j), 3112));
 						BKE_sim_debug_data_add_vector(clmd->debug_data, x, gvel_smooth, 0.6, 4, 1, "grid velocity", hash_int_2d(hash_int_2d(i, j), 3113));
+						if (gdensity > 0.0f)
+							BKE_sim_debug_data_add_circle(clmd->debug_data, x, gdensity * clmd->sim_parms->density_strength, 0, 1, 0.4, "grid velocity", hash_int_2d(354, hash_int_2d(i, j)));
 					}
 				}
 			}
diff --git a/source/blender/physics/intern/hair_volume.cpp b/source/blender/physics/intern/hair_volume.cpp
index 3a0e702..ddc5066 100644
--- a/source/blender/physics/intern/hair_volume.cpp
+++ b/source/blender/physics/intern/hair_volume.cpp
@@ -63,6 +63,16 @@ extern "C" {
 
 static float I[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
 
+BLI_INLINE int floor_int(float value)
+{
+	return value > 0.0f ? (int)value : ((int)value) - 1;
+}
+
+BLI_INLINE float floor_mod(float value)
+{
+	return value - floorf(value);
+}
+
 BLI_INLINE int hair_grid_size(const int res[3])
 {
 	return res[0] * res[1] * res[2];
@@ -325,6 +335,7 @@ void BPH_hair_volume_add_vertex(HairGrid *grid, const float x[3], const float v[
 	}
 }
 
+#if 0
 BLI_INLINE void hair_volume_eval_grid_vertex(HairGridVert *vert, const float loc[3], float radius, float dist_scale,
                                              const float x2[3], const float v2[3], const float x3[3], const float v3[3])
 {
@@ -345,16 +356,6 @@ BLI_INLINE void hair_volume_eval_grid_vertex(HairGridVert *vert, const float loc
 	}
 }
 
-BLI_INLINE int floor_int(float value)
-{
-	return value > 0.0f ? (int)value : ((int)value) - 1;
-}
-
-BLI_INLINE float floor_mod(float value)
-{
-	return value - floorf(value);
-}
-
 BLI_INLINE int major_axis_v3(const float v[3])
 {
 	const float a = fabsf(v[0]);
@@ -518,6 +519,68 @@ void BPH_hair_volume_add_segment(HairGrid *grid,
 		                           i);
 	}
 }
+#else
+BLI_INLINE void hair_volume_eval_grid_vertex_sample(HairGridVert *vert, const float loc[3], float radius, float dist_scale,
+                                                    const float x[3], const float v[3])
+{
+	float dist, weight;
+	
+	dist = len_v3v3(x, loc);
+	
+	weight = (radius - dist) * dist_scale;
+	
+	if (weight > 0.0f) {
+		madd_v3_v3fl(vert->velocity, v, weight);
+		vert->density += weight;
+		vert->samples += 1;
+	}
+}
+
+/* XXX simplified test implementation using a series of discrete sample along the segment,
+ * instead of finding the closest point for all affected grid vertices.
+ */
+void BPH_hair_volume_add_segment(HairGrid *grid,
+                                 const float UNUSED(x1[3]), const float UNUSED(v1[3]), const float x2[3], const float v2[3],
+                                 const float x3[3], const float v3[3], const float UNUSED(x4[3]), const float UNUSED(v4[3]),
+                                 const float UNUSED(dir1[3]), const float UNUSED(dir2[3]), const float UNUSED(dir3[3]))
+{
+	const float radius = 1.5f;
+	const float dist_scale = grid->inv_cellsize;
+	
+	const int res[3] = { grid->res[0], grid->res[1], grid->res[2] };
+	const int stride[3] = { 1, res[0], res[0] * res[1] };
+	const int num_samples = 10;
+	
+	int s;
+	
+	for (s = 0; s < num_samples; ++s) {
+		float x[3], v[3];
+		int i, j, k;
+		
+		float f = (float)s / (float)(num_samples-1);
+		interp_v3_v3v3(x, x2, x3, f);
+		interp_v3_v3v3(v, v2, v3, f);
+		
+		int imin = max_ii(floor_int(x[0]) - 2, 0);
+		int imax = min_ii(floor_int(x[0]) + 2, res[0]-1);
+		int jmin = max_ii(floor_int(x[1]) - 2, 0);
+		int jmax = min_ii(floor_int(x[1]) + 2, res[1]-1);
+		int kmin = max_ii(floor_int(x[2]) - 2, 0);
+		int kmax = min_ii(floor_int(x[2]) + 2, res[2]-1);
+		
+		for (k = kmin; k <= kmax; ++k) {
+			for (j = jmin; j <= jmax; ++j) {
+				for (i = imin; i <= imax; ++i) {
+					float loc[3] = { (float)i, (float)j, (float)k };
+					HairGridVert *vert = grid->verts + i * stride[0] + j * stride[1] + k * stride[2];
+					
+					hair_volume_eval_grid_vertex_sample(vert, loc, radius, dist_scale, x, v);
+				}
+			}
+		}
+	}
+}
+#endif
 
 void BPH_hair_volume_normalize_vertex_grid(HairGrid *grid)
 {




More information about the Bf-blender-cvs mailing list