Smoke:
* bugfix for crash when loading smoke files more once on linux/mac * could also fix occasional explosions * code cleanup
This commit is contained in:
2
intern/smoke/extern/smoke_API.h
vendored
2
intern/smoke/extern/smoke_API.h
vendored
@@ -32,7 +32,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#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_free(struct FLUID_3D *fluid);
|
||||||
|
|
||||||
void smoke_initBlenderRNA(struct FLUID_3D *fluid, float *alpha, float *beta);
|
void smoke_initBlenderRNA(struct FLUID_3D *fluid, float *alpha, float *beta);
|
||||||
|
@@ -41,7 +41,7 @@ static void shift3D(float*& field, int xRes, int yRes, int zRes)
|
|||||||
int xHalf = xRes / 2;
|
int xHalf = xRes / 2;
|
||||||
int yHalf = yRes / 2;
|
int yHalf = yRes / 2;
|
||||||
int zHalf = zRes / 2;
|
int zHalf = zRes / 2;
|
||||||
int slabSize = xRes * yRes;
|
// int slabSize = xRes * yRes;
|
||||||
for (int z = 0; z < zHalf; z++)
|
for (int z = 0; z < zHalf; z++)
|
||||||
for (int y = 0; y < yHalf; y++)
|
for (int y = 0; y < yHalf; y++)
|
||||||
for (int x = 0; x < xHalf; x++)
|
for (int x = 0; x < xHalf; x++)
|
||||||
|
@@ -38,7 +38,7 @@
|
|||||||
// Construction/Destruction
|
// 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)
|
_xRes(res[0]), _yRes(res[1]), _zRes(res[2]), _res(0.0f), _dt(dt)
|
||||||
{
|
{
|
||||||
// set simulation consts
|
// set simulation consts
|
||||||
@@ -122,6 +122,8 @@ FLUID_3D::FLUID_3D(int *res, int amplify, float *p0, float dt) :
|
|||||||
_yVorticity[x] = 0.0f;
|
_yVorticity[x] = 0.0f;
|
||||||
_zVorticity[x] = 0.0f;
|
_zVorticity[x] = 0.0f;
|
||||||
_residual[x] = 0.0f;
|
_residual[x] = 0.0f;
|
||||||
|
_q[x] = 0.0f;
|
||||||
|
_direction[x] = 0.0f;
|
||||||
_h[x] = 0.0f;
|
_h[x] = 0.0f;
|
||||||
_Precond[x] = 0.0f;
|
_Precond[x] = 0.0f;
|
||||||
_obstacles[x] = false;
|
_obstacles[x] = false;
|
||||||
@@ -487,7 +489,7 @@ void FLUID_3D::setObstaclePressure()
|
|||||||
_pressure[index] = 0.0f;
|
_pressure[index] = 0.0f;
|
||||||
|
|
||||||
// average pressure neighbors
|
// average pressure neighbors
|
||||||
float pcnt = 0., vp = 0.;
|
float pcnt = 0.;
|
||||||
if (left && !right) {
|
if (left && !right) {
|
||||||
_pressure[index] += _pressure[index + 1];
|
_pressure[index] += _pressure[index + 1];
|
||||||
pcnt += 1.;
|
pcnt += 1.;
|
||||||
|
@@ -37,7 +37,7 @@ class WTURBULENCE;
|
|||||||
class FLUID_3D
|
class FLUID_3D
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FLUID_3D(int *res, int amplify, float *p0, float dt);
|
FLUID_3D(int *res, /* int amplify, */ float *p0, float dt);
|
||||||
FLUID_3D() {};
|
FLUID_3D() {};
|
||||||
virtual ~FLUID_3D();
|
virtual ~FLUID_3D();
|
||||||
|
|
||||||
|
@@ -26,11 +26,17 @@
|
|||||||
|
|
||||||
void FLUID_3D::solvePressurePre(float* field, float* b, unsigned char* skip)
|
void FLUID_3D::solvePressurePre(float* field, float* b, unsigned char* skip)
|
||||||
{
|
{
|
||||||
int x, y, z, index;
|
size_t x, y, z, index;
|
||||||
|
|
||||||
// i = 0
|
// i = 0
|
||||||
int 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
|
// r = b - Ax
|
||||||
index = _slabSize + _xRes + 1;
|
index = _slabSize + _xRes + 1;
|
||||||
for (z = 1; z < _zRes - 1; z++, index += 2 * _xRes)
|
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];
|
deltaNew += _residual[index] * _direction[index];
|
||||||
|
|
||||||
// delta0 = deltaNew
|
// delta0 = deltaNew
|
||||||
float delta0 = deltaNew;
|
// float delta0 = deltaNew;
|
||||||
|
|
||||||
// While deltaNew > (eps^2) * delta0
|
// While deltaNew > (eps^2) * delta0
|
||||||
const float eps = SOLVER_ACCURACY;
|
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)
|
void FLUID_3D::solvePressure(float* field, float* b, unsigned char* skip)
|
||||||
{
|
{
|
||||||
int x, y, z, index;
|
size_t x, y, z, index;
|
||||||
|
|
||||||
// i = 0
|
// i = 0
|
||||||
int 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
|
// r = b - Ax
|
||||||
index = _slabSize + _xRes + 1;
|
index = _slabSize + _xRes + 1;
|
||||||
for (z = 1; z < _zRes - 1; z++, index += 2 * _xRes)
|
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)
|
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);
|
const float heatConst = _dt * _heatDiffusion / (_dx * _dx);
|
||||||
|
|
||||||
// i = 0
|
// i = 0
|
||||||
int 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
|
// r = b - Ax
|
||||||
index = _slabSize + _xRes + 1;
|
index = _slabSize + _xRes + 1;
|
||||||
for (z = 1; z < _zRes - 1; z++, index += 2 * _xRes)
|
for (z = 1; z < _zRes - 1; z++, index += 2 * _xRes)
|
||||||
|
@@ -600,6 +600,7 @@ void FLUID_3D::writeImageSliceXZ(const float *field, Vec3Int res, int slice, str
|
|||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// Helper function for projecting densities along a dimension
|
// Helper function for projecting densities along a dimension
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
/*
|
||||||
static int getOtherDir(int dir1, int dir2) {
|
static int getOtherDir(int dir1, int dir2) {
|
||||||
switch(dir1) {
|
switch(dir1) {
|
||||||
case 0:
|
case 0:
|
||||||
@@ -622,6 +623,7 @@ static int getOtherDir(int dir1, int dir2) {
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// average densities along third spatial direction
|
// average densities along third spatial direction
|
||||||
|
@@ -774,7 +774,7 @@ void WTURBULENCE::stepTurbulenceFull(float dtOrg, float* xvel, float* yvel, floa
|
|||||||
#endif
|
#endif
|
||||||
{ float maxVelMag1 = 0.;
|
{ float maxVelMag1 = 0.;
|
||||||
#if PARALLEL==1
|
#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
|
#endif
|
||||||
|
|
||||||
// vector noise main loop
|
// vector noise main loop
|
||||||
|
@@ -32,10 +32,10 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
// y in smoke is z in blender
|
// 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
|
// 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]);
|
// printf("xres: %d, yres: %d, zres: %d\n", res[0], res[1], res[2]);
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* BKE_cloth.h
|
* BKE_smoke.h
|
||||||
*
|
*
|
||||||
* $Id$
|
* $Id$
|
||||||
*
|
*
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* BKE_cloth.h
|
* smoke.c
|
||||||
*
|
*
|
||||||
* $Id$
|
* $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]);
|
// 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
|
// 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->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->time = scene->r.cfra;
|
||||||
smd->domain->firstframe = smd->time;
|
smd->domain->firstframe = smd->time;
|
||||||
|
Reference in New Issue
Block a user