[Bf-blender-cvs] [6a2ea7e] hair_immediate_fixes: Reimplemented the voxel texture type for displaying hair continuum grids.

Lukas Tönne noreply at git.blender.org
Fri Oct 31 20:30:36 CET 2014


Commit: 6a2ea7eb4e5b934109edf8cf68d0439a66ecd92d
Author: Lukas Tönne
Date:   Fri Oct 31 20:29:51 2014 +0100
Branches: hair_immediate_fixes
https://developer.blender.org/rB6a2ea7eb4e5b934109edf8cf68d0439a66ecd92d

Reimplemented the voxel texture type for displaying hair continuum grids.

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

M	source/blender/physics/BPH_mass_spring.h
M	source/blender/physics/intern/BPH_mass_spring.cpp
M	source/blender/physics/intern/hair_volume.c
M	source/blender/physics/intern/implicit.h
M	source/blender/render/CMakeLists.txt
M	source/blender/render/SConscript
M	source/blender/render/intern/source/voxeldata.c

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

diff --git a/source/blender/physics/BPH_mass_spring.h b/source/blender/physics/BPH_mass_spring.h
index 10f05fc..f2bd34e 100644
--- a/source/blender/physics/BPH_mass_spring.h
+++ b/source/blender/physics/BPH_mass_spring.h
@@ -33,7 +33,10 @@ extern "C" {
 #endif
 
 struct Implicit_Data;
+struct Object;
 struct ClothModifierData;
+struct ListBase;
+struct VoxelData;
 
 typedef enum eMassSpringSolverStatus {
 	BPH_SOLVER_SUCCESS              = (1 << 0),
@@ -51,7 +54,7 @@ void BPH_cloth_solver_free(struct ClothModifierData *clmd);
 int BPH_cloth_solve(struct Object *ob, float frame, struct ClothModifierData *clmd, struct ListBase *effectors);
 void BPH_cloth_solver_set_positions(struct ClothModifierData *clmd);
 
-bool implicit_hair_volume_get_texture_data(struct Object *UNUSED(ob), struct ClothModifierData *clmd, struct ListBase *UNUSED(effectors), struct VoxelData *vd);
+bool BPH_cloth_solver_get_texture_data(struct Object *ob, struct ClothModifierData *clmd, struct VoxelData *vd);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index 95cbc4c..c024344 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -697,6 +697,29 @@ static void cloth_calc_volume_force(ClothModifierData *clmd)
 }
 #endif
 
+static void cloth_continuum_fill_grid(HairVertexGrid *grid, Cloth *cloth)
+{
+	Implicit_Data *data = cloth->implicit;
+	int numverts = cloth->numverts;
+	ClothVertex *vert;
+	int i;
+	
+	for (i = 0, vert = cloth->verts; i < numverts; i++, vert++) {
+		float x[3], v[3];
+		
+		if (vert->solver_index < 0) {
+			copy_v3_v3(x, vert->x);
+			copy_v3_v3(v, vert->v);
+		}
+		else {
+			BPH_mass_spring_get_position(data, vert->solver_index, x);
+			BPH_mass_spring_get_new_velocity(data, vert->solver_index, v);
+		}
+		BPH_hair_volume_add_vertex(grid, x, v);
+	}
+	BPH_hair_volume_normalize_vertex_grid(grid);
+}
+
 static void cloth_continuum_step(ClothModifierData *clmd)
 {
 	ClothSimSettings *parms = clmd->sim_parms;
@@ -722,30 +745,14 @@ static void cloth_continuum_step(ClothModifierData *clmd)
 	/* gather velocities & density */
 	if (smoothfac > 0.0f || pressfac > 0.0f) {
 		HairVertexGrid *vertex_grid = BPH_hair_volume_create_vertex_grid(clmd->sim_parms->voxel_res, gmin, gmax);
-		
-		vert = cloth->verts;
-		for (i = 0; i < numverts; i++, vert++) {
-			float x[3], v[3];
-			
-			if (vert->solver_index < 0) {
-				copy_v3_v3(x, vert->x);
-				copy_v3_v3(v, vert->v);
-			}
-			else {
-				BPH_mass_spring_get_position(data, vert->solver_index, x);
-				BPH_mass_spring_get_new_velocity(data, vert->solver_index, v);
-			}
-			BPH_hair_volume_add_vertex(vertex_grid, x, v);
-		}
-		BPH_hair_volume_normalize_vertex_grid(vertex_grid);
+		cloth_continuum_fill_grid(vertex_grid, cloth);
 		
 #if 0
 		/* apply velocity filter */
 		BPH_hair_volume_vertex_grid_filter_box(vertex_grid, clmd->sim_parms->voxel_filter_size);
 #endif
 		
-		vert = cloth->verts;
-		for (i = 0; i < numverts; i++, vert++) {
+		for (i = 0, vert = cloth->verts; i < numverts; i++, vert++) {
 			float x[3], v[3], nv[3];
 			
 			if (vert->solver_index < 0)
@@ -980,3 +987,24 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase *
 	
 	return 1;
 }
+
+bool BPH_cloth_solver_get_texture_data(Object *UNUSED(ob), ClothModifierData *clmd, VoxelData *vd)
+{
+	Cloth *cloth = clmd->clothObject;
+	HairVertexGrid *grid;
+	float gmin[3], gmax[3];
+	
+	if (!clmd->clothObject || !clmd->clothObject->implicit)
+		return false;
+	
+	hair_get_boundbox(clmd, gmin, gmax);
+	
+	grid = BPH_hair_volume_create_vertex_grid(clmd->sim_parms->voxel_res, gmin, gmax);
+	cloth_continuum_fill_grid(grid, cloth);
+	
+	BPH_hair_volume_get_texture_data(grid, vd);
+	
+	BPH_hair_volume_free_vertex_grid(grid);
+	
+	return true;
+}
diff --git a/source/blender/physics/intern/hair_volume.c b/source/blender/physics/intern/hair_volume.c
index b5c4188..988bf4b 100644
--- a/source/blender/physics/intern/hair_volume.c
+++ b/source/blender/physics/intern/hair_volume.c
@@ -34,6 +34,8 @@
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
 
+#include "DNA_texture_types.h"
+
 #include "implicit.h"
 
 /* ================ Volumetric Hair Interaction ================
@@ -509,30 +511,16 @@ static HairGridVert *hair_volume_create_collision_grid(ClothModifierData *clmd,
 }
 #endif
 
-#if 0
-bool implicit_hair_volume_get_texture_data(Object *UNUSED(ob), ClothModifierData *clmd, ListBase *UNUSED(effectors), VoxelData *vd)
+bool BPH_hair_volume_get_texture_data(HairVertexGrid *grid, VoxelData *vd)
 {
-	lfVector *lX, *lV;
-	HairGridVert *hairgrid/*, *collgrid*/;
-	int numverts;
 	int totres, i;
 	int depth;
 
-	if (!clmd->clothObject || !clmd->clothObject->implicit)
-		return false;
-
-	lX = clmd->clothObject->implicit->X;
-	lV = clmd->clothObject->implicit->V;
-	numverts = clmd->clothObject->numverts;
-
-	hairgrid = hair_volume_create_hair_grid(clmd, lX, lV, numverts);
-//	collgrid = hair_volume_create_collision_grid(clmd, lX, numverts);
-
-	vd->resol[0] = hair_grid_res;
-	vd->resol[1] = hair_grid_res;
-	vd->resol[2] = hair_grid_res;
+	vd->resol[0] = grid->res;
+	vd->resol[1] = grid->res;
+	vd->resol[2] = grid->res;
 	
-	totres = hair_grid_size(hair_grid_res);
+	totres = hair_grid_size(grid->res);
 	
 	if (vd->hair_type == TEX_VD_HAIRVELOCITY) {
 		depth = 4;
@@ -549,20 +537,21 @@ bool implicit_hair_volume_get_texture_data(Object *UNUSED(ob), ClothModifierData
 		for (i = 0; i < totres; ++i) {
 			switch (vd->hair_type) {
 				case TEX_VD_HAIRDENSITY:
-					vd->dataset[i] = hairgrid[i].density;
+					vd->dataset[i] = grid->verts[i].density;
 					break;
 				
 				case TEX_VD_HAIRRESTDENSITY:
 					vd->dataset[i] = 0.0f; // TODO
 					break;
 				
-				case TEX_VD_HAIRVELOCITY:
-					vd->dataset[i + 0*totres] = hairgrid[i].velocity[0];
-					vd->dataset[i + 1*totres] = hairgrid[i].velocity[1];
-					vd->dataset[i + 2*totres] = hairgrid[i].velocity[2];
-					vd->dataset[i + 3*totres] = len_v3(hairgrid[i].velocity);
+				case TEX_VD_HAIRVELOCITY: {
+					float tmp = grid->verts[i].velocity[1];
+					vd->dataset[i + 0*totres] = grid->verts[i].velocity[0];
+					vd->dataset[i + 1*totres] = grid->verts[i].velocity[1];
+					vd->dataset[i + 2*totres] = grid->verts[i].velocity[2];
+					vd->dataset[i + 3*totres] = len_v3(grid->verts[i].velocity);
 					break;
-				
+				}
 				case TEX_VD_HAIRENERGY:
 					vd->dataset[i] = 0.0f; // TODO
 					break;
@@ -573,10 +562,5 @@ bool implicit_hair_volume_get_texture_data(Object *UNUSED(ob), ClothModifierData
 		vd->dataset = NULL;
 	}
 	
-	MEM_freeN(hairgrid);
-//	MEM_freeN(collgrid);
-	
 	return true;
 }
-
-#endif
diff --git a/source/blender/physics/intern/implicit.h b/source/blender/physics/intern/implicit.h
index 9ec7e76..b7eeea1 100644
--- a/source/blender/physics/intern/implicit.h
+++ b/source/blender/physics/intern/implicit.h
@@ -168,6 +168,9 @@ bool BPH_mass_spring_force_spring_goal(struct Implicit_Data *data, int i, const
 struct HairVertexGrid;
 struct HairColliderGrid;
 
+struct Object;
+struct VoxelData;
+
 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]);
@@ -195,6 +198,8 @@ void BPH_hair_volume_vertex_grid_forces(struct HairVertexGrid *grid, const float
                                         float smoothfac, float pressurefac, float minpressure,
                                         float f[3], float dfdx[3][3], float dfdv[3][3]);
 
+bool BPH_hair_volume_get_texture_data(struct HairVertexGrid *grid, struct VoxelData *vd);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/render/CMakeLists.txt b/source/blender/render/CMakeLists.txt
index e516c95..36b9f8a 100644
--- a/source/blender/render/CMakeLists.txt
+++ b/source/blender/render/CMakeLists.txt
@@ -33,6 +33,7 @@ set(INC
 	../imbuf
 	../makesdna
 	../makesrna
+	../physics
 	../../../intern/guardedalloc
 	../../../intern/mikktspace
 	../../../intern/smoke/extern
diff --git a/source/blender/render/SConscript b/source/blender/render/SConscript
index 7f45944..b8cdd70 100644
--- a/source/blender/render/SConscript
+++ b/source/blender/render/SConscript
@@ -41,6 +41,7 @@ incs = [
     '../include',
     '../makesdna',
     '../makesrna',
+    '../physics',
     '../../../intern/mikktspace',
     '../../../intern/smoke/extern',
     ]
diff --git a/source/blender/render/intern/source/voxeldata.c b/source/blender/render/intern/source/voxeldata.c
index a6feea9..036743a 100644
--- a/source/blender/render/intern/source/voxeldata.c
+++ b/source/blender/render/intern/source/voxeldata.c
@@ -58,6 +58,7 @@
 #include "BKE_modifier.h"
 
 #include "smoke_API.h"
+#include "BPH_mass_spring.h"
 
 #include "DNA_texture_types.h"
 #include "DNA_object_force.h"
@@ -381,8 +382,7 @@ static void init_frame_hair(VoxelData *vd, int UNUSED(cfra))
 		ParticleSystemModifierData *pmd = (ParticleSystemModifierData *)md;
 		
 		if (pmd->psys && pmd->psys->clmd) {
-			// XXX TODO was moved into own subfolder, figure out how to handle this (perhaps make a wrapper in BKE)
-//			found |= implicit_hair_volume_get_texture_data(ob, pmd->psys->clmd, NULL, vd);
+			found |= BPH_cloth_solver_get_texture_data(ob, pmd->psys->clmd, vd);
 		}
 	}




More information about the Bf-blender-cvs mailing list