diff options
Diffstat (limited to 'intern/smoke/intern/smoke_API.cpp')
-rw-r--r-- | intern/smoke/intern/smoke_API.cpp | 44 |
1 files changed, 38 insertions, 6 deletions
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) |