smoke: decoupling high-res, introducing reset for heat+gravity, fixing another obstacle problem

This commit is contained in:
2009-08-06 16:50:02 +00:00
parent 65cf500fdc
commit 2fd0263602
9 changed files with 194 additions and 107 deletions

View File

@@ -283,7 +283,7 @@ int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, Derive
// printf("res[0]: %d, res[1]: %d, res[2]: %d\n", smd->domain->res[0], smd->domain->res[1], smd->domain->res[2]);
// dt max is 0.1
smd->domain->fluid = smoke_init(smd->domain->res, smd->domain->amplify, smd->domain->p0, smd->domain->p1, 2.5 / FPS);
smd->domain->fluid = smoke_init(smd->domain->res, (smd->domain->flags & MOD_SMOKE_HIGHRES) ? (smd->domain->amplify + 1) : 0, smd->domain->p0, smd->domain->p1, 2.5 / FPS);
smd->time = scene->r.cfra;
smd->domain->firstframe = smd->time;
@@ -324,6 +324,10 @@ int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, Derive
size_t max_points = 0;
size_t quads = 0, facecounter = 0;
// copy obmat
Mat4CpyMat4(scs->mat, ob->obmat);
Mat4CpyMat4(scs->mat_old, ob->obmat);
// count quads
for(i = 0; i < dm->getNumFaces(dm); i++)
{
@@ -451,7 +455,7 @@ int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, Derive
if(!smd->coll->bvhtree)
{
smd->coll->bvhtree = bvhtree_build_from_smoke ( ob->obmat, dm->getFaceArray(dm), dm->getNumFaces(dm), dm->getVertArray(dm), dm->getNumVerts(dm), 0.0 );
smd->coll->bvhtree = NULL; // bvhtree_build_from_smoke ( ob->obmat, dm->getFaceArray(dm), dm->getNumFaces(dm), dm->getVertArray(dm), dm->getNumVerts(dm), 0.0 );
}
}
@@ -504,12 +508,12 @@ void calcTriangleDivs(Object *ob, MVert *verts, int numverts, MFace *faces, int
if(INPR(side1, side1) > fsTri*fsTri)
{
float tmp = Normalize(side1);
divs1 = (int)(tmp/fsTri);
divs1 = (int)ceil(tmp/fsTri);
}
if(INPR(side2, side2) > fsTri*fsTri)
{
float tmp = Normalize(side2);
divs2 = (int)(tmp/fsTri);
divs2 = (int)ceil(tmp/fsTri);
/*
// debug
@@ -529,9 +533,11 @@ void calcTriangleDivs(Object *ob, MVert *verts, int numverts, MFace *faces, int
facecounter++;
VECCOPY(p1, verts[faces[i].v3].co);
VECCOPY(p0, verts[faces[i].v3].co);
Mat4MulVecfl (ob->obmat, p0);
VECCOPY(p1, verts[faces[i].v4].co);
Mat4MulVecfl (ob->obmat, p1);
VECCOPY(p2, verts[faces[i].v4].co);
VECCOPY(p2, verts[faces[i].v1].co);
Mat4MulVecfl (ob->obmat, p2);
VECSUB(side1, p1, p0);
@@ -541,12 +547,12 @@ void calcTriangleDivs(Object *ob, MVert *verts, int numverts, MFace *faces, int
if(INPR(side1, side1) > fsTri*fsTri)
{
float tmp = Normalize(side1);
divs1 = (int)(tmp/fsTri);
divs1 = (int)ceil(tmp/fsTri);
}
if(INPR(side2, side2) > fsTri*fsTri)
{
float tmp = Normalize(side2);
divs2 = (int)(tmp/fsTri);
divs2 = (int)ceil(tmp/fsTri);
}
(*tridivs)[3 * facecounter + 0] = divs1;
@@ -612,6 +618,10 @@ void smokeModifier_freeCollision(SmokeModifierData *smd)
smd->coll->bvhtree = NULL;
}
if(smd->coll->dm)
smd->coll->dm->release(smd->coll->dm);
smd->coll->dm = NULL;
MEM_freeN(smd->coll);
smd->coll = NULL;
}
@@ -670,6 +680,11 @@ void smokeModifier_reset(struct SmokeModifierData *smd)
BLI_bvhtree_free(smd->coll->bvhtree);
smd->coll->bvhtree = NULL;
}
if(smd->coll->dm)
smd->coll->dm->release(smd->coll->dm);
smd->coll->dm = NULL;
}
}
}
@@ -703,7 +718,7 @@ void smokeModifier_createType(struct SmokeModifierData *smd)
smd->domain->fluid_group = NULL;
smd->domain->coll_group = NULL;
smd->domain->maxres = 32;
smd->domain->amplify = 2;
smd->domain->amplify = 1;
smd->domain->omega = 1.0;
smd->domain->alpha = -0.001;
smd->domain->beta = 0.1;
@@ -747,6 +762,7 @@ void smokeModifier_createType(struct SmokeModifierData *smd)
smd->coll->points = NULL;
smd->coll->numpoints = 0;
smd->coll->bvhtree = NULL;
smd->coll->dm = NULL;
}
}
}
@@ -783,6 +799,15 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM
bvhtree_update_from_smoke ( ob->obmat, smd->coll->bvhtree, dm->getFaceArray(dm), dm->getNumFaces(dm), dm->getVertArray(dm), dm->getNumVerts(dm));
else
printf("smoke coll with no bvh\n");
if(smd->coll->dm)
smd->coll->dm->release(smd->coll->dm);
smd->coll->dm = CDDM_copy(dm);
// rigid movement support
Mat4CpyMat4(smd->coll->mat_old, smd->coll->mat);
Mat4CpyMat4(smd->coll->mat, ob->obmat);
}
else if(scene->r.cfra < smd->time)
{
@@ -883,9 +908,7 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM
float *velocity_x = smoke_get_velocity_x(sds->fluid);
float *velocity_y = smoke_get_velocity_y(sds->fluid);
float *velocity_z = smoke_get_velocity_z(sds->fluid);
int bigres[3];
smoke_get_bigres(smd->domain->fluid, bigres);
int bigres[3];
// mostly copied from particle code
for(p=0, pa=psys->particles; p<psys->totpart; p++, pa++)
@@ -926,15 +949,20 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM
{
heat[index] = sfs->temp;
density[index] = sfs->density;
/*
velocity_x[index] = pa->state.vel[0];
velocity_y[index] = pa->state.vel[1];
velocity_z[index] = pa->state.vel[2];
*/
// we need different handling for the high-res feature
if(bigdensity)
{
// init all surrounding cells according to amplification, too
int i, j, k;
smoke_get_bigres(smd->domain->fluid, bigres);
for(i = 0; i < smd->domain->amplify; i++)
for(j = 0; j < smd->domain->amplify; j++)
for(k = 0; k < smd->domain->amplify; k++)
@@ -957,6 +985,9 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM
{
// init all surrounding cells according to amplification, too
int i, j, k;
smoke_get_bigres(smd->domain->fluid, bigres);
for(i = 0; i < smd->domain->amplify; i++)
for(j = 0; j < smd->domain->amplify; j++)
for(k = 0; k < smd->domain->amplify; k++)
@@ -1039,16 +1070,14 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM
{
// we got nice collision object
SmokeCollSettings *scs = smd2->coll;
int cell[3];
size_t index = 0;
size_t i, j;
unsigned char *obstacles = smoke_get_obstacle(smd->domain->fluid);
// int BLI_bvhtree_find_nearest(BVHTree *tree, const float *co, BVHTreeNearest *nearest, BVHTree_NearestPointCallback callback, void *userdata);
for(i = 0; i < scs->numpoints; i++)
{
int badcell = 0;
size_t index = 0;
int cell[3];
// 1. get corresponding cell
get_cell(smd, &scs->points[3 * i], cell, 0);

View File

@@ -5349,7 +5349,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
float *buffer = NULL;
int res[3];
float bigfactor = 1.0;
int big = smd->domain->flags & MOD_SMOKE_HIGHRES;
int big = (smd->domain->flags & MOD_SMOKE_HIGHRES) && (smd->domain->viewsettings & MOD_SMOKE_VIEW_USEBIG);
int new = 0;
// GUI sent redraw event

View File

@@ -44,6 +44,7 @@
#define MOD_SMOKE_VIEW_CHANGETOBIG (1<<5)
#define MOD_SMOKE_VIEW_REDRAWNICE (1<<6)
#define MOD_SMOKE_VIEW_REDRAWALL (1<<7)
#define MOD_SMOKE_VIEW_USEBIG (1<<8)
typedef struct SmokeDomainSettings {
struct SmokeModifierData *smd; /* for fast RNA access */
@@ -103,6 +104,7 @@ typedef struct SmokeFlowSettings {
typedef struct SmokeCollSettings {
struct SmokeModifierData *smd; /* for fast RNA access */
struct BVHTree *bvhtree; /* bounding volume hierarchy for this cloth object */
struct DerivedMesh *dm;
float *points;
float *points_old;
float *vel;

View File

@@ -150,8 +150,13 @@ static void rna_def_smoke_domain_settings(BlenderRNA *brna)
prop= RNA_def_property(srna, "highres", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flags", MOD_SMOKE_HIGHRES);
RNA_def_property_ui_text(prop, "High res", "Show high resolution (using amplification).");
RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
RNA_def_property_ui_text(prop, "High res", "Enable high resolution (using amplification).");
RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Smoke_reset");
prop= RNA_def_property(srna, "viewhighres", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "viewsettings", MOD_SMOKE_VIEW_USEBIG);
RNA_def_property_ui_text(prop, "Show high res", "Show high resolution (using amplification).");
RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, NULL);
prop= RNA_def_property(srna, "noise_type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "noise");
@@ -171,14 +176,14 @@ static void rna_def_smoke_domain_settings(BlenderRNA *brna)
RNA_def_property_range(prop, -5.0, 5.0);
RNA_def_property_ui_range(prop, -5.0, 5.0, 0.02, 5);
RNA_def_property_ui_text(prop, "Gravity", "Higher value results in sinking smoke");
RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, NULL);
RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Smoke_reset");
prop= RNA_def_property(srna, "beta", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "beta");
RNA_def_property_range(prop, -5.0, 5.0);
RNA_def_property_ui_range(prop, -5.0, 5.0, 0.02, 5);
RNA_def_property_ui_text(prop, "Heat", "Higher value results in faster rising smoke.");
RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, NULL);
RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Smoke_reset");
prop= RNA_def_property(srna, "coll_group", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "coll_group");