diff options
Diffstat (limited to 'intern')
-rw-r--r-- | intern/CMakeLists.txt | 4 | ||||
-rw-r--r-- | intern/ghost/CMakeLists.txt | 3 | ||||
-rw-r--r-- | intern/ghost/SConscript | 4 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_SystemCocoa.mm | 5 | ||||
-rw-r--r-- | intern/guardedalloc/MEM_guardedalloc.h | 2 | ||||
-rw-r--r-- | intern/iksolver/intern/TNT/vec.h | 2 | ||||
-rw-r--r-- | intern/itasc/MovingFrame.cpp | 2 | ||||
-rw-r--r-- | intern/smoke/extern/smoke_API.h | 6 | ||||
-rw-r--r-- | intern/smoke/intern/FLUID_3D.cpp | 197 | ||||
-rw-r--r-- | intern/smoke/intern/FLUID_3D.h | 24 | ||||
-rw-r--r-- | intern/smoke/intern/WTURBULENCE.cpp | 17 | ||||
-rw-r--r-- | intern/smoke/intern/smoke_API.cpp | 44 | ||||
-rw-r--r-- | intern/string/intern/STR_String.cpp | 8 |
13 files changed, 253 insertions, 65 deletions
diff --git a/intern/CMakeLists.txt b/intern/CMakeLists.txt index a370118f061..d64029a6671 100644 --- a/intern/CMakeLists.txt +++ b/intern/CMakeLists.txt @@ -38,8 +38,8 @@ ADD_SUBDIRECTORY(boolop) ADD_SUBDIRECTORY(opennl) ADD_SUBDIRECTORY(smoke) -IF(WITH_ELBEEM) +IF(WITH_FLUID) ADD_SUBDIRECTORY(elbeem) -ENDIF(WITH_ELBEEM) +ENDIF(WITH_FLUID) ADD_SUBDIRECTORY(bsp) diff --git a/intern/ghost/CMakeLists.txt b/intern/ghost/CMakeLists.txt index 1a7627c9099..c262ea8aadd 100644 --- a/intern/ghost/CMakeLists.txt +++ b/intern/ghost/CMakeLists.txt @@ -85,6 +85,9 @@ ELSEIF(UNIX) ${CMAKE_CURRENT_SOURCE_DIR}/intern/GHOST_SystemX11.cpp ${CMAKE_CURRENT_SOURCE_DIR}/intern/GHOST_WindowX11.cpp ) + + ADD_DEFINITIONS(-DPREFIX="${CMAKE_INSTALL_PREFIX}") + ENDIF(APPLE) BLENDERLIB(bf_ghost "${SRC}" "${INC}") diff --git a/intern/ghost/SConscript b/intern/ghost/SConscript index 65c00b16373..9ecd61857ce 100644 --- a/intern/ghost/SConscript +++ b/intern/ghost/SConscript @@ -14,7 +14,7 @@ if window_system == 'darwin': pf = ['GHOST_DisplayManager', 'GHOST_System', 'GHOST_Window', 'GHOST_DropTarget'] defs=['_USE_MATH_DEFINES'] -if window_system in ('linux2', 'openbsd3', 'sunos5', 'freebsd6', 'irix6', 'aix4', 'aix5'): +if window_system in ('linux2', 'openbsd3', 'sunos5', 'freebsd7', 'freebsd8', 'freebsd9', 'irix6', 'aix4', 'aix5'): for f in pf: try: sources.remove('intern' + os.sep + f + 'Win32.cpp') @@ -60,4 +60,4 @@ if env['BF_GHOST_DEBUG']: incs = '. ../string #extern/glew/include #source/blender/imbuf #source/blender/makesdna ' + env['BF_OPENGL_INC'] if window_system in ('win32-vc', 'win32-mingw', 'cygwin', 'linuxcross', 'win64-vc'): incs = env['BF_WINTAB_INC'] + ' ' + incs -env.BlenderLib ('bf_ghost', sources, Split(incs), defines=defs, libtype=['intern','player'], priority = [40,15] ) +env.BlenderLib ('bf_ghost', sources, Split(incs), defines=defs, libtype=['intern','player'], priority = [40,15] )
\ No newline at end of file diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm index a763309a09a..7e99c369f6a 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.mm +++ b/intern/ghost/intern/GHOST_SystemCocoa.mm @@ -1299,6 +1299,11 @@ GHOST_TUns8 GHOST_SystemCocoa::handleQuitRequest() NSArray *windowsList = [NSApp orderedWindows]; if ([windowsList count]) { [[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil]; + //Handle the modifiers keyes changed state issue + //as recovering from the quit dialog is like application + //gaining focus back. + //Main issue fixed is Cmd modifier not being cleared + handleApplicationBecomeActiveEvent(); } } diff --git a/intern/guardedalloc/MEM_guardedalloc.h b/intern/guardedalloc/MEM_guardedalloc.h index 8c5caa6f359..b909ac9e051 100644 --- a/intern/guardedalloc/MEM_guardedalloc.h +++ b/intern/guardedalloc/MEM_guardedalloc.h @@ -63,7 +63,7 @@ extern "C" { #endif - /** Returns the lenght of the allocated memory segment pointed at + /** Returns the length of the allocated memory segment pointed at * by vmemh. If the pointer was not previously allocated by this * module, the result is undefined.*/ size_t MEM_allocN_len(void *vmemh); diff --git a/intern/iksolver/intern/TNT/vec.h b/intern/iksolver/intern/TNT/vec.h index 1729d83ca10..040097afbd9 100644 --- a/intern/iksolver/intern/TNT/vec.h +++ b/intern/iksolver/intern/TNT/vec.h @@ -416,7 +416,7 @@ void vectoradd( A[i] += B[i]; } -// same with seperate output vector +// same with separate output vector template <class T> void vectoradd( diff --git a/intern/itasc/MovingFrame.cpp b/intern/itasc/MovingFrame.cpp index e923b1fab27..914f950e436 100644 --- a/intern/itasc/MovingFrame.cpp +++ b/intern/itasc/MovingFrame.cpp @@ -52,7 +52,7 @@ void MovingFrame::pushInternalFrame(CacheTS timestamp) } } -// load pose just preceeding timestamp +// load pose just preceding timestamp // return false if no cache position was found bool MovingFrame::popInternalFrame(CacheTS timestamp) { diff --git a/intern/smoke/extern/smoke_API.h b/intern/smoke/extern/smoke_API.h index 3e296fd7c90..b340c914519 100644 --- a/intern/smoke/extern/smoke_API.h +++ b/intern/smoke/extern/smoke_API.h @@ -38,11 +38,11 @@ struct FLUID_3D; void smoke_export(struct FLUID_3D *fluid, float *dt, float *dx, float **dens, float **densold, float **heat, float **heatold, float **vx, float **vy, float **vz, float **vxold, float **vyold, float **vzold, unsigned char **obstacles); // low res -struct FLUID_3D *smoke_init(int *res, float *p0, float dt); +struct FLUID_3D *smoke_init(int *res, float *p0); void smoke_free(struct FLUID_3D *fluid); -void smoke_initBlenderRNA(struct FLUID_3D *fluid, float *alpha, float *beta); -void smoke_step(struct FLUID_3D *fluid, size_t framenr); +void smoke_initBlenderRNA(struct FLUID_3D *fluid, float *alpha, float *beta, float *dt_factor, float *vorticity, int *border_colli); +void smoke_step(struct FLUID_3D *fluid, size_t framenr, float fps); float *smoke_get_density(struct FLUID_3D *fluid); float *smoke_get_heat(struct FLUID_3D *fluid); diff --git a/intern/smoke/intern/FLUID_3D.cpp b/intern/smoke/intern/FLUID_3D.cpp index 4ac960b5ef0..05fbb918d24 100644 --- a/intern/smoke/intern/FLUID_3D.cpp +++ b/intern/smoke/intern/FLUID_3D.cpp @@ -35,23 +35,15 @@ #include <omp.h> #endif // PARALLEL -// boundary conditions of the fluid domain -#define DOMAIN_BC_FRONT 0 // z -#define DOMAIN_BC_TOP 1 // y -#define DOMAIN_BC_LEFT 1 // x -#define DOMAIN_BC_BACK DOMAIN_BC_FRONT -#define DOMAIN_BC_BOTTOM DOMAIN_BC_TOP -#define DOMAIN_BC_RIGHT DOMAIN_BC_LEFT - ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// -FLUID_3D::FLUID_3D(int *res, float *p0, float dt) : - _xRes(res[0]), _yRes(res[1]), _zRes(res[2]), _res(0.0f), _dt(dt) +FLUID_3D::FLUID_3D(int *res, float *p0) : + _xRes(res[0]), _yRes(res[1]), _zRes(res[2]), _res(0.0f) { // set simulation consts - // _dt = dt; // 0.10 + _dt = DT_DEFAULT; // just in case. set in step from a RNA factor // start point of array _p0[0] = p0[0]; @@ -61,7 +53,6 @@ FLUID_3D::FLUID_3D(int *res, float *p0, float dt) : _iterations = 100; _tempAmb = 0; _heatDiffusion = 1e-3; - _vorticityEps = 2.0; _totalTime = 0.0f; _totalSteps = 0; _res = Vec3Int(_xRes,_yRes,_zRes); @@ -77,9 +68,9 @@ FLUID_3D::FLUID_3D(int *res, float *p0, float dt) : // scale the constants according to the refinement of the grid _dx = 1.0f / (float)_maxRes; - float scaling = 64.0f / _maxRes; - scaling = (scaling < 1.0f) ? 1.0f : scaling; - _vorticityEps /= scaling; + _constantScaling = 64.0f / _maxRes; + _constantScaling = (_constantScaling < 1.0f) ? 1.0f : _constantScaling; + _vorticityEps = 2.0f / _constantScaling; // Just in case set a default value // allocate arrays _totalCells = _xRes * _yRes * _zRes; @@ -126,30 +117,42 @@ FLUID_3D::FLUID_3D(int *res, float *p0, float dt) : _obstacles[x] = false; } + // boundary conditions of the fluid domain + // set default values -> vertically non-colliding + _domainBcFront = true; + _domainBcTop = false; + _domainBcLeft = true; + _domainBcBack = _domainBcFront; + _domainBcBottom = _domainBcTop; + _domainBcRight = _domainBcLeft; + + _colloPrev = 1; // default value + + // set side obstacles int index; for (int y = 0; y < _yRes; y++) for (int x = 0; x < _xRes; x++) { - // front slab + // bottom slab index = x + y * _xRes; - if(DOMAIN_BC_FRONT==1) _obstacles[index] = 1; + if(_domainBcBottom==1) _obstacles[index] = 1; - // back slab + // top slab index += _totalCells - _slabSize; - if(DOMAIN_BC_BACK==1) _obstacles[index] = 1; + if(_domainBcTop==1) _obstacles[index] = 1; } for (int z = 0; z < _zRes; z++) for (int x = 0; x < _xRes; x++) { - // bottom slab + // front slab index = x + z * _slabSize; - if(DOMAIN_BC_BOTTOM==1) _obstacles[index] = 1; + if(_domainBcFront==1) _obstacles[index] = 1; - // top slab + // back slab index += _slabSize - _xRes; - if(DOMAIN_BC_TOP==1) _obstacles[index] = 1; + if(_domainBcBack==1) _obstacles[index] = 1; } for (int z = 0; z < _zRes; z++) @@ -157,12 +160,13 @@ FLUID_3D::FLUID_3D(int *res, float *p0, float dt) : { // left slab index = y * _xRes + z * _slabSize; - if(DOMAIN_BC_LEFT==1) _obstacles[index] = 1; + if(_domainBcLeft==1) _obstacles[index] = 1; // right slab index += _xRes - 1; - if(DOMAIN_BC_RIGHT==1) _obstacles[index] = 1; + if(_domainBcRight==1) _obstacles[index] = 1; } + } FLUID_3D::~FLUID_3D() @@ -193,17 +197,32 @@ FLUID_3D::~FLUID_3D() } // init direct access functions from blender -void FLUID_3D::initBlenderRNA(float *alpha, float *beta) +void FLUID_3D::initBlenderRNA(float *alpha, float *beta, float *dt_factor, float *vorticity, int *borderCollision) { _alpha = alpha; _beta = beta; + _dtFactor = dt_factor; + _vorticityRNA = vorticity; + _borderColli = borderCollision; } ////////////////////////////////////////////////////////////////////// // step simulation once ////////////////////////////////////////////////////////////////////// -void FLUID_3D::step() +void FLUID_3D::step(float dt) { + // If border rules have been changed + if (_colloPrev != *_borderColli) { + setBorderCollisions(); + } + + + // set delta time by dt_factor + _dt = (*_dtFactor) * dt; + // set vorticity from RNA value + _vorticityEps = (*_vorticityRNA)/_constantScaling; + + #if PARALLEL==1 int threadval = 1; threadval = omp_get_max_threads(); @@ -246,6 +265,13 @@ void FLUID_3D::step() #pragma omp single { #endif + /* + * addForce() changed Temp values to preserve thread safety + * (previous functions in per thread loop still needed + * original velocity data) + * + * So swap temp values to velocity + */ SWAP_POINTERS(_xVelocity, _xVelocityTemp); SWAP_POINTERS(_yVelocity, _yVelocityTemp); SWAP_POINTERS(_zVelocity, _zVelocityTemp); @@ -276,6 +302,10 @@ void FLUID_3D::step() #pragma omp single { #endif + /* + * For thread safety use "Old" to read + * "current" values but still allow changing values. + */ SWAP_POINTERS(_xVelocity, _xVelocityOld); SWAP_POINTERS(_yVelocity, _yVelocityOld); SWAP_POINTERS(_zVelocity, _zVelocityOld); @@ -334,6 +364,10 @@ void FLUID_3D::step() } #endif + /* + * swap final velocity back to Velocity array + * from temp xForce storage + */ SWAP_POINTERS(_xVelocity, _xForce); SWAP_POINTERS(_yVelocity, _yForce); SWAP_POINTERS(_zVelocity, _zForce); @@ -351,6 +385,88 @@ void FLUID_3D::step() } + +// Set border collision model from RNA setting + +void FLUID_3D::setBorderCollisions() { + + + _colloPrev = *_borderColli; // saving the current value + + // boundary conditions of the fluid domain + if (_colloPrev == 0) + { + // No collisions + _domainBcFront = false; + _domainBcTop = false; + _domainBcLeft = false; + } + else if (_colloPrev == 2) + { + // Collide with all sides + _domainBcFront = true; + _domainBcTop = true; + _domainBcLeft = true; + } + else + { + // Default values: Collide with "walls", but not top and bottom + _domainBcFront = true; + _domainBcTop = false; + _domainBcLeft = true; + } + + _domainBcBack = _domainBcFront; + _domainBcBottom = _domainBcTop; + _domainBcRight = _domainBcLeft; + + + + // set side obstacles + int index; + for (int y = 0; y < _yRes; y++) + for (int x = 0; x < _xRes; x++) + { + // front slab + index = x + y * _xRes; + if(_domainBcBottom==1) _obstacles[index] = 1; + else _obstacles[index] = 0; + + // back slab + index += _totalCells - _slabSize; + if(_domainBcTop==1) _obstacles[index] = 1; + else _obstacles[index] = 0; + } + + for (int z = 0; z < _zRes; z++) + for (int x = 0; x < _xRes; x++) + { + // bottom slab + index = x + z * _slabSize; + if(_domainBcFront==1) _obstacles[index] = 1; + else _obstacles[index] = 0; + + // top slab + index += _slabSize - _xRes; + if(_domainBcBack==1) _obstacles[index] = 1; + else _obstacles[index] = 0; + } + + for (int z = 0; z < _zRes; z++) + for (int y = 0; y < _yRes; y++) + { + // left slab + index = y * _xRes + z * _slabSize; + if(_domainBcLeft==1) _obstacles[index] = 1; + else _obstacles[index] = 0; + + // right slab + index += _xRes - 1; + if(_domainBcRight==1) _obstacles[index] = 1; + else _obstacles[index] = 0; + } +} + ////////////////////////////////////////////////////////////////////// // helper function to dampen co-located grid artifacts of given arrays in intervals // (only needed for velocity, strength (w) depends on testcase... @@ -428,6 +544,10 @@ void FLUID_3D::artificialDampingExactSL(int pos) { for (y = 1; y < _res[1]-1; y++) for (x = 1+(y+z)%2; x < _res[0]-1; x+=2) { index = x + y*_res[0] + posslab; + /* + * Uses xForce as temporary storage to allow other threads to read + * old values from xVelocityTemp + */ _xForce[index] = (1-w)*_xVelocityTemp[index] + 1./6. * w*( _xVelocityTemp[index+1] + _xVelocityTemp[index-1] + _xVelocityTemp[index+_res[0]] + _xVelocityTemp[index-_res[0]] + @@ -450,6 +570,11 @@ void FLUID_3D::artificialDampingExactSL(int pos) { for (y = 1; y < _res[1]-1; y++) for (x = 1+(y+z+1)%2; x < _res[0]-1; x+=2) { index = x + y*_res[0] + posslab; + + /* + * Uses xForce as temporary storage to allow other threads to read + * old values from xVelocityTemp + */ _xForce[index] = (1-w)*_xVelocityTemp[index] + 1./6. * w*( _xVelocityTemp[index+1] + _xVelocityTemp[index-1] + _xVelocityTemp[index+_res[0]] + _xVelocityTemp[index-_res[0]] + @@ -661,13 +786,13 @@ void FLUID_3D::project() setObstacleBoundaries(_pressure, 0, _zRes); // copy out the boundaries - if(DOMAIN_BC_LEFT == 0) setNeumannX(_xVelocity, _res, 0, _zRes); + if(_domainBcLeft == 0) setNeumannX(_xVelocity, _res, 0, _zRes); else setZeroX(_xVelocity, _res, 0, _zRes); - if(DOMAIN_BC_TOP == 0) setNeumannY(_yVelocity, _res, 0, _zRes); + if(_domainBcFront == 0) setNeumannY(_yVelocity, _res, 0, _zRes); else setZeroY(_yVelocity, _res, 0, _zRes); - if(DOMAIN_BC_FRONT == 0) setNeumannZ(_zVelocity, _res, 0, _zRes); + if(_domainBcTop == 0) setNeumannZ(_zVelocity, _res, 0, _zRes); else setZeroZ(_zVelocity, _res, 0, _zRes); // calculate divergence @@ -1060,13 +1185,13 @@ void FLUID_3D::advectMacCormackBegin(int zBegin, int zEnd) { Vec3Int res = Vec3Int(_xRes,_yRes,_zRes); - if(DOMAIN_BC_LEFT == 0) copyBorderX(_xVelocityOld, res, zBegin, zEnd); + if(_domainBcLeft == 0) copyBorderX(_xVelocityOld, res, zBegin, zEnd); else setZeroX(_xVelocityOld, res, zBegin, zEnd); - if(DOMAIN_BC_TOP == 0) copyBorderY(_yVelocityOld, res, zBegin, zEnd); + if(_domainBcFront == 0) copyBorderY(_yVelocityOld, res, zBegin, zEnd); else setZeroY(_yVelocityOld, res, zBegin, zEnd); - if(DOMAIN_BC_FRONT == 0) copyBorderZ(_zVelocityOld, res, zBegin, zEnd); + if(_domainBcTop == 0) copyBorderZ(_zVelocityOld, res, zBegin, zEnd); else setZeroZ(_zVelocityOld, res, zBegin, zEnd); } @@ -1114,13 +1239,13 @@ void FLUID_3D::advectMacCormackEnd2(int zBegin, int zEnd) advectFieldMacCormack2(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _yVelocityOld, _yVelocityTemp, _yVelocity, t1, res, _obstacles, zBegin, zEnd); advectFieldMacCormack2(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _zVelocityOld, _zVelocityTemp, _zVelocity, t1, res, _obstacles, zBegin, zEnd); - if(DOMAIN_BC_LEFT == 0) copyBorderX(_xVelocityTemp, res, zBegin, zEnd); + if(_domainBcLeft == 0) copyBorderX(_xVelocityTemp, res, zBegin, zEnd); else setZeroX(_xVelocityTemp, res, zBegin, zEnd); - if(DOMAIN_BC_TOP == 0) copyBorderY(_yVelocityTemp, res, zBegin, zEnd); + if(_domainBcFront == 0) copyBorderY(_yVelocityTemp, res, zBegin, zEnd); else setZeroY(_yVelocityTemp, res, zBegin, zEnd); - if(DOMAIN_BC_FRONT == 0) copyBorderZ(_zVelocityTemp, res, zBegin, zEnd); + if(_domainBcTop == 0) copyBorderZ(_zVelocityTemp, res, zBegin, zEnd); else setZeroZ(_zVelocityTemp, res, zBegin, zEnd); setZeroBorder(_density, res, zBegin, zEnd); diff --git a/intern/smoke/intern/FLUID_3D.h b/intern/smoke/intern/FLUID_3D.h index ab121ef506e..c244180ee57 100644 --- a/intern/smoke/intern/FLUID_3D.h +++ b/intern/smoke/intern/FLUID_3D.h @@ -30,11 +30,15 @@ #include <cstdlib> #include <cmath> +#include <cstring> #include <iostream> #include "OBSTACLE.h" // #include "WTURBULENCE.h" #include "VEC3.h" +// timestep default value for nice appearance +#define DT_DEFAULT 0.1f; + using namespace std; using namespace BasicVector; class WTURBULENCE; @@ -42,11 +46,11 @@ class WTURBULENCE; class FLUID_3D { public: - FLUID_3D(int *res, /* int amplify, */ float *p0, float dt); + FLUID_3D(int *res, /* int amplify, */ float *p0); FLUID_3D() {}; virtual ~FLUID_3D(); - void initBlenderRNA(float *alpha, float *beta); + void initBlenderRNA(float *alpha, float *beta, float *dt_factor, float *vorticity, int *border_colli); // create & allocate vector noise advection void initVectorNoise(int amplify); @@ -54,7 +58,7 @@ class FLUID_3D void addSmokeColumn(); static void addSmokeTestCase(float* field, Vec3Int res); - void step(); + void step(float dt); void addObstacle(OBSTACLE* obstacle); const float* xVelocity() { return _xVelocity; }; @@ -110,11 +114,25 @@ class FLUID_3D // simulation constants float _dt; + float *_dtFactor; float _vorticityEps; float _heatDiffusion; + float *_vorticityRNA; // RNA-pointer. float *_alpha; // for the buoyancy density term <-- as pointer to get blender RNA in here float *_beta; // was _buoyancy <-- as pointer to get blender RNA in here float _tempAmb; /* ambient temperature */ + float _constantScaling; + + bool _domainBcFront; // z + bool _domainBcTop; // y + bool _domainBcLeft; // x + bool _domainBcBack; // DOMAIN_BC_FRONT + bool _domainBcBottom; // DOMAIN_BC_TOP + bool _domainBcRight; // DOMAIN_BC_LEFT + int *_borderColli; // border collision rules <-- as pointer to get blender RNA in here + int _colloPrev; // To track whether value has been changed (to not + // have to recalibrate borders if nothing has changed + void setBorderCollisions(); // WTURBULENCE object, if active // WTURBULENCE* _wTurbulence; diff --git a/intern/smoke/intern/WTURBULENCE.cpp b/intern/smoke/intern/WTURBULENCE.cpp index 6d43bc95471..917c510348a 100644 --- a/intern/smoke/intern/WTURBULENCE.cpp +++ b/intern/smoke/intern/WTURBULENCE.cpp @@ -825,13 +825,18 @@ void WTURBULENCE::stepTurbulenceFull(float dtOrg, float* xvel, float* yvel, floa // get LU factorization of texture jacobian and apply // it to unit vectors sLU LU = computeLU(jacobian); - float xUnwarped[] = {1.0f, 0.0f, 0.0f}; - float yUnwarped[] = {0.0f, 1.0f, 0.0f}; - float zUnwarped[] = {0.0f, 0.0f, 1.0f}; - float xWarped[] = {1.0f, 0.0f, 0.0f}; - float yWarped[] = {0.0f, 1.0f, 0.0f}; - float zWarped[] = {0.0f, 0.0f, 1.0f}; + float xUnwarped[3], yUnwarped[3], zUnwarped[3]; + float xWarped[3], yWarped[3], zWarped[3]; bool nonSingular = isNonsingular(LU); + + xUnwarped[0] = 1.0f; xUnwarped[1] = 0.0f; xUnwarped[2] = 0.0f; + yUnwarped[0] = 0.0f; yUnwarped[1] = 1.0f; yUnwarped[2] = 0.0f; + zUnwarped[0] = 0.0f; zUnwarped[1] = 0.0f; zUnwarped[2] = 1.0f; + + xWarped[0] = 1.0f; xWarped[1] = 0.0f; xWarped[2] = 0.0f; + yWarped[0] = 0.0f; yWarped[1] = 1.0f; yWarped[2] = 0.0f; + zWarped[0] = 0.0f; zWarped[1] = 0.0f; zWarped[2] = 1.0f; + #if 0 // UNUSED float eigMax = 10.0f; diff --git a/intern/smoke/intern/smoke_API.cpp b/intern/smoke/intern/smoke_API.cpp index 427f4d53171..168395f370d 100644 --- a/intern/smoke/intern/smoke_API.cpp +++ b/intern/smoke/intern/smoke_API.cpp @@ -33,10 +33,10 @@ #include <math.h> // y in smoke is z in blender -extern "C" FLUID_3D *smoke_init(int *res, float *p0, float dt) +extern "C" FLUID_3D *smoke_init(int *res, float *p0) { // smoke lib uses y as top-bottom/vertical axis where blender uses z - FLUID_3D *fluid = new FLUID_3D(res, p0, dt); + FLUID_3D *fluid = new FLUID_3D(res, p0); // printf("xres: %d, yres: %d, zres: %d\n", res[0], res[1], res[2]); @@ -75,9 +75,41 @@ extern "C" size_t smoke_get_index2d(int x, int max_x, int y /*, int max_y, int z return x + y * max_x; } -extern "C" void smoke_step(FLUID_3D *fluid, size_t framenr) +extern "C" void smoke_step(FLUID_3D *fluid, size_t framenr, float fps) { - fluid->step(); + /* stability values copied from wturbulence.cpp */ + const int maxSubSteps = 25; + const float maxVel = 0.5f; /* TODO: maybe 0.5 is still too high, please confirm! -dg */ + + float dt = DT_DEFAULT; + float maxVelMag = 0.0f; + int totalSubsteps; + int substep = 0; + float dtSubdiv; + + /* get max velocity and lower the dt value if it is too high */ + size_t size= fluid->_xRes * fluid->_yRes * fluid->_zRes; + + for(size_t i = 0; i < size; i++) + { + float vtemp = (fluid->_xVelocity[i]*fluid->_xVelocity[i]+fluid->_yVelocity[i]*fluid->_yVelocity[i]+fluid->_zVelocity[i]*fluid->_zVelocity[i]); + if(vtemp > maxVelMag) + maxVelMag = vtemp; + } + + /* adapt timestep for different framerates, dt = 0.1 is at 25fps */ + dt *= (25.0f / fps); + + maxVelMag = sqrt(maxVelMag) * dt * (*(fluid->_dtFactor)); + totalSubsteps = (int)((maxVelMag / maxVel) + 1.0f); /* always round up */ + totalSubsteps = (totalSubsteps < 1) ? 1 : totalSubsteps; + totalSubsteps = (totalSubsteps > maxSubSteps) ? maxSubSteps : totalSubsteps; + dtSubdiv = (float)dt / (float)totalSubsteps; + + // printf("totalSubsteps: %d, maxVelMag: %f, dt: %f\n", totalSubsteps, maxVelMag, dt); + + for(substep = 0; substep < totalSubsteps; substep++) + fluid->step(dtSubdiv); } extern "C" void smoke_turbulence_step(WTURBULENCE *wt, FLUID_3D *fluid) @@ -85,9 +117,9 @@ extern "C" void smoke_turbulence_step(WTURBULENCE *wt, FLUID_3D *fluid) wt->stepTurbulenceFull(fluid->_dt/fluid->_dx, fluid->_xVelocity, fluid->_yVelocity, fluid->_zVelocity, fluid->_obstacles); } -extern "C" void smoke_initBlenderRNA(FLUID_3D *fluid, float *alpha, float *beta) +extern "C" void smoke_initBlenderRNA(FLUID_3D *fluid, float *alpha, float *beta, float *dt_factor, float *vorticity, int *border_colli) { - fluid->initBlenderRNA(alpha, beta); + fluid->initBlenderRNA(alpha, beta, dt_factor, vorticity, border_colli); } extern "C" void smoke_dissolve(FLUID_3D *fluid, int speed, int log) diff --git a/intern/string/intern/STR_String.cpp b/intern/string/intern/STR_String.cpp index d468cd4bdbd..3e035fd7905 100644 --- a/intern/string/intern/STR_String.cpp +++ b/intern/string/intern/STR_String.cpp @@ -359,7 +359,7 @@ int STR_String::Find(char c, int pos) const // -// Find the first occurence of <str> in the string +// Find the first occurrence of <str> in the string // int STR_String::Find(const char *str, int pos) const { @@ -373,7 +373,7 @@ int STR_String::Find(const char *str, int pos) const // -// Find the first occurence of <str> in the string +// Find the first occurrence of <str> in the string // int STR_String::Find(rcSTR_String str, int pos) const { @@ -387,7 +387,7 @@ int STR_String::Find(rcSTR_String str, int pos) const // -// Find the last occurence of <c> in the string +// Find the last occurrence of <c> in the string // int STR_String::RFind(char c) const { @@ -399,7 +399,7 @@ int STR_String::RFind(char c) const // -// Find the first occurence of any character in character set <set> in the string +// Find the first occurrence of any character in character set <set> in the string // int STR_String::FindOneOf(const char *set, int pos) const { |