* bugfix for crash when loading smoke files more once on linux/mac
* could also fix occasional explosions
* code cleanup
This commit is contained in:
Daniel Genrich
2009-08-10 14:09:56 +00:00
parent eafef35cd8
commit f1c69e9d84
10 changed files with 38 additions and 20 deletions

View File

@@ -32,7 +32,7 @@
extern "C" {
#endif
struct FLUID_3D *smoke_init(int *res, int amplify, float *p0, float *p1, float dt);
struct FLUID_3D *smoke_init(int *res, float *p0, float dt);
void smoke_free(struct FLUID_3D *fluid);
void smoke_initBlenderRNA(struct FLUID_3D *fluid, float *alpha, float *beta);

View File

@@ -41,7 +41,7 @@ static void shift3D(float*& field, int xRes, int yRes, int zRes)
int xHalf = xRes / 2;
int yHalf = yRes / 2;
int zHalf = zRes / 2;
int slabSize = xRes * yRes;
// int slabSize = xRes * yRes;
for (int z = 0; z < zHalf; z++)
for (int y = 0; y < yHalf; y++)
for (int x = 0; x < xHalf; x++)

View File

@@ -38,7 +38,7 @@
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
FLUID_3D::FLUID_3D(int *res, int amplify, float *p0, float dt) :
FLUID_3D::FLUID_3D(int *res, float *p0, float dt) :
_xRes(res[0]), _yRes(res[1]), _zRes(res[2]), _res(0.0f), _dt(dt)
{
// set simulation consts
@@ -122,6 +122,8 @@ FLUID_3D::FLUID_3D(int *res, int amplify, float *p0, float dt) :
_yVorticity[x] = 0.0f;
_zVorticity[x] = 0.0f;
_residual[x] = 0.0f;
_q[x] = 0.0f;
_direction[x] = 0.0f;
_h[x] = 0.0f;
_Precond[x] = 0.0f;
_obstacles[x] = false;
@@ -487,7 +489,7 @@ void FLUID_3D::setObstaclePressure()
_pressure[index] = 0.0f;
// average pressure neighbors
float pcnt = 0., vp = 0.;
float pcnt = 0.;
if (left && !right) {
_pressure[index] += _pressure[index + 1];
pcnt += 1.;

View File

@@ -37,7 +37,7 @@ class WTURBULENCE;
class FLUID_3D
{
public:
FLUID_3D(int *res, int amplify, float *p0, float dt);
FLUID_3D(int *res, /* int amplify, */ float *p0, float dt);
FLUID_3D() {};
virtual ~FLUID_3D();

View File

@@ -26,11 +26,17 @@
void FLUID_3D::solvePressurePre(float* field, float* b, unsigned char* skip)
{
int x, y, z, index;
size_t x, y, z, index;
// i = 0
int i = 0;
memset(_residual, 0, sizeof(float)*_xRes*_yRes*_zRes);
memset(_q, 0, sizeof(float)*_xRes*_yRes*_zRes);
memset(_direction, 0, sizeof(float)*_xRes*_yRes*_zRes);
memset(_h, 0, sizeof(float)*_xRes*_yRes*_zRes);
memset(_Precond, 0, sizeof(float)*_xRes*_yRes*_zRes);
// r = b - Ax
index = _slabSize + _xRes + 1;
for (z = 1; z < _zRes - 1; z++, index += 2 * _xRes)
@@ -78,7 +84,7 @@ void FLUID_3D::solvePressurePre(float* field, float* b, unsigned char* skip)
deltaNew += _residual[index] * _direction[index];
// delta0 = deltaNew
float delta0 = deltaNew;
// float delta0 = deltaNew;
// While deltaNew > (eps^2) * delta0
const float eps = SOLVER_ACCURACY;
@@ -191,11 +197,15 @@ void FLUID_3D::solvePressurePre(float* field, float* b, unsigned char* skip)
//////////////////////////////////////////////////////////////////////
void FLUID_3D::solvePressure(float* field, float* b, unsigned char* skip)
{
int x, y, z, index;
size_t x, y, z, index;
// i = 0
int i = 0;
memset(_residual, 0, sizeof(float)*_xRes*_yRes*_zRes);
memset(_q, 0, sizeof(float)*_xRes*_yRes*_zRes);
memset(_direction, 0, sizeof(float)*_xRes*_yRes*_zRes);
// r = b - Ax
index = _slabSize + _xRes + 1;
for (z = 1; z < _zRes - 1; z++, index += 2 * _xRes)
@@ -338,12 +348,16 @@ void FLUID_3D::solvePressure(float* field, float* b, unsigned char* skip)
//////////////////////////////////////////////////////////////////////
void FLUID_3D::solveHeat(float* field, float* b, unsigned char* skip)
{
int x, y, z, index;
size_t x, y, z, index;
const float heatConst = _dt * _heatDiffusion / (_dx * _dx);
// i = 0
int i = 0;
memset(_residual, 0, sizeof(float)*_xRes*_yRes*_zRes);
memset(_q, 0, sizeof(float)*_xRes*_yRes*_zRes);
memset(_direction, 0, sizeof(float)*_xRes*_yRes*_zRes);
// r = b - Ax
index = _slabSize + _xRes + 1;
for (z = 1; z < _zRes - 1; z++, index += 2 * _xRes)

View File

@@ -600,6 +600,7 @@ void FLUID_3D::writeImageSliceXZ(const float *field, Vec3Int res, int slice, str
//////////////////////////////////////////////////////////////////////
// Helper function for projecting densities along a dimension
//////////////////////////////////////////////////////////////////////
/*
static int getOtherDir(int dir1, int dir2) {
switch(dir1) {
case 0:
@@ -622,6 +623,7 @@ static int getOtherDir(int dir1, int dir2) {
}
return 0;
}
*/
//////////////////////////////////////////////////////////////////////
// average densities along third spatial direction

View File

@@ -774,7 +774,7 @@ void WTURBULENCE::stepTurbulenceFull(float dtOrg, float* xvel, float* yvel, floa
#endif
{ float maxVelMag1 = 0.;
#if PARALLEL==1
const int id = omp_get_thread_num(), num = omp_get_num_threads();
const int id = omp_get_thread_num(); /*, num = omp_get_num_threads(); */
#endif
// vector noise main loop

View File

@@ -32,10 +32,10 @@
#include <stdlib.h>
// y in smoke is z in blender
extern "C" FLUID_3D *smoke_init(int *res, int amplify, float *p0, float *p1, float dt)
extern "C" FLUID_3D *smoke_init(int *res, float *p0, float dt)
{
// smoke lib uses y as top-bottom/vertical axis where blender uses z
FLUID_3D *fluid = new FLUID_3D(res, amplify, p0, dt);
FLUID_3D *fluid = new FLUID_3D(res, p0, dt);
// printf("xres: %d, yres: %d, zres: %d\n", res[0], res[1], res[2]);

View File

@@ -1,5 +1,5 @@
/**
* BKE_cloth.h
* BKE_smoke.h
*
* $Id$
*

View File

@@ -1,5 +1,5 @@
/**
* BKE_cloth.h
* smoke.c
*
* $Id$
*
@@ -207,7 +207,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, 0, smd->domain->p0, smd->domain->p1, 2.5 / FPS);
smd->domain->fluid = smoke_init(smd->domain->res, smd->domain->p0, 2.5 / FPS);
smd->domain->wt = smoke_turbulence_init(smd->domain->res, (smd->domain->flags & MOD_SMOKE_HIGHRES) ? (smd->domain->amplify + 1) : 0, smd->domain->noise);
smd->time = scene->r.cfra;
smd->domain->firstframe = smd->time;