forked from bartvdbraak/blender
Reimplemented the voxel texture type for displaying hair continuum grids.
Conflicts: source/blender/physics/intern/BPH_mass_spring.cpp
This commit is contained in:
parent
cd717f145d
commit
d42525a9b5
@ -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),
|
||||
@ -50,7 +53,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 BKE_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
|
||||
}
|
||||
|
@ -584,6 +584,23 @@ 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];
|
||||
|
||||
BPH_mass_spring_get_position(data, i, x);
|
||||
BPH_mass_spring_get_new_velocity(data, i, 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;
|
||||
@ -609,25 +626,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];
|
||||
|
||||
BPH_mass_spring_get_motion_state(data, i, x, v);
|
||||
BPH_mass_spring_get_position(data, i, x);
|
||||
BPH_mass_spring_get_new_velocity(data, i, 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];
|
||||
|
||||
/* calculate volumetric velocity influence */
|
||||
@ -842,3 +848,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;
|
||||
}
|
||||
|
@ -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;
|
||||
vd->resol[0] = grid->res;
|
||||
vd->resol[1] = grid->res;
|
||||
vd->resol[2] = grid->res;
|
||||
|
||||
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;
|
||||
|
||||
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
|
||||
|
@ -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
|
||||
|
@ -33,6 +33,7 @@ set(INC
|
||||
../imbuf
|
||||
../makesdna
|
||||
../makesrna
|
||||
../physics
|
||||
../../../intern/guardedalloc
|
||||
../../../intern/mikktspace
|
||||
../../../intern/smoke/extern
|
||||
|
@ -40,6 +40,7 @@ incs = [
|
||||
'../imbuf',
|
||||
'../makesdna',
|
||||
'../makesrna',
|
||||
'../physics',
|
||||
'../../../intern/mikktspace',
|
||||
'../../../intern/smoke/extern',
|
||||
]
|
||||
|
@ -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"
|
||||
@ -380,8 +381,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user