[Bf-blender-cvs] [18aa00c] fluid-mantaflow: more fire integration
Sebastián Barschkis
noreply at git.blender.org
Thu Jan 28 12:36:27 CET 2016
Commit: 18aa00cc5e98d20c34cd4dcc62253384c4cf6e92
Author: Sebastián Barschkis
Date: Sat Sep 5 18:35:38 2015 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rB18aa00cc5e98d20c34cd4dcc62253384c4cf6e92
more fire integration
===================================================================
M intern/smoke/intern/FLUID_3D.cpp
M intern/smoke/intern/MANTA.cpp
M intern/smoke/intern/scenarios/smoke.h
M source/blender/python/manta_full/CMakeLists.txt
M source/blender/python/manta_full/source/plugin/fire.cpp
===================================================================
diff --git a/intern/smoke/intern/FLUID_3D.cpp b/intern/smoke/intern/FLUID_3D.cpp
index 4a5d7ed..dc47708 100644
--- a/intern/smoke/intern/FLUID_3D.cpp
+++ b/intern/smoke/intern/FLUID_3D.cpp
@@ -701,6 +701,25 @@ void FLUID_3D::initColors(float init_r, float init_g, float init_b)
void FLUID_3D::initFire()
{
if (!_flame) {
+ _flame = new float[_totalCells];
+ _fuel = new float[_totalCells];
+ _fuelTemp = new float[_totalCells];
+ _fuelOld = new float[_totalCells];
+ _react = new float[_totalCells];
+ _reactTemp = new float[_totalCells];
+ _reactOld = new float[_totalCells];
+
+ for (int x = 0; x < _totalCells; x++)
+ {
+ _flame[x] = 0.0f;
+ _fuel[x] = 0.0f;
+ _fuelTemp[x] = 0.0f;
+ _fuelOld[x] = 0.0f;
+ _react[x] = 0.0f;
+ _reactTemp[x] = 0.0f;
+ _reactOld[x] = 0.0f;
+ }
+
using_fire = true;
PyGILState_STATE gilstate = PyGILState_Ensure();
PyRun_SimpleString(smoke_init_fire_low.c_str());
@@ -784,66 +803,19 @@ void FLUID_3D::step(float dt, float gravity[3])
void FLUID_3D::processBurn(float *fuel, float *smoke, float *react, float *heat,
float *r, float *g, float *b, int total_cells, float dt)
{
- float burning_rate = *_burning_rate;
- float flame_smoke = *_flame_smoke;
- float ignition_point = *_ignition_temp;
- float temp_max = *_max_temp;
-
- for (int index = 0; index < total_cells; index++)
- {
- float orig_fuel = fuel[index];
- float orig_smoke = smoke[index];
- float smoke_emit = 0.0f;
- float flame = 0.0f;
- /* process fuel */
- fuel[index] -= burning_rate * dt;
- if (fuel[index] < 0.0f) fuel[index] = 0.0f;
- /* process reaction coordinate */
- if (orig_fuel > FLT_EPSILON) {
- react[index] *= fuel[index]/orig_fuel;
- flame = pow(react[index], 0.5f);
- }
- else {
- react[index] = 0.0f;
- }
-
- /* emit smoke based on fuel burn rate and "flame_smoke" factor */
- smoke_emit = (orig_fuel < 1.0f) ? (1.0f - orig_fuel)*0.5f : 0.0f;
- smoke_emit = (smoke_emit + 0.5f) * (orig_fuel-fuel[index]) * 0.1f * flame_smoke;
- smoke[index] += smoke_emit;
- CLAMP(smoke[index], 0.0f, 1.0f);
-
- /* set fluid temperature from the flame temperature profile */
- if (heat && flame)
- heat[index] = (1.0f - flame)*ignition_point + flame*temp_max;
-
- /* mix new color */
- if (r && smoke_emit > FLT_EPSILON) {
- float smoke_factor = smoke[index]/(orig_smoke+smoke_emit);
- r[index] = (r[index] + _flame_smoke_color[0] * smoke_emit) * smoke_factor;
- g[index] = (g[index] + _flame_smoke_color[1] * smoke_emit) * smoke_factor;
- b[index] = (b[index] + _flame_smoke_color[2] * smoke_emit) * smoke_factor;
- }
- }
+ PyGILState_STATE gilstate = PyGILState_Ensure();
+ PyRun_SimpleString(fire_process_burn.c_str());
+ PyGILState_Release(gilstate);
+ Manta_API::updatePointers(this, true);
}
void FLUID_3D::updateFlame(float *react, float *flame, int total_cells)
{
- for (int index = 0; index < total_cells; index++)
- {
- /* model flame temperature curve from the reaction coordinate (fuel)
- * TODO: Would probably be best to get rid of whole "flame" data field.
- * Currently it's just sqrt mirror of reaction coordinate, and therefore
- * basically just waste of memory and disk space...
- */
- if (react[index]>0.0f) {
- /* do a smooth falloff for rest of the values */
- flame[index] = pow(react[index], 0.5f);
- }
- else
- flame[index] = 0.0f;
- }
+ PyGILState_STATE gilstate = PyGILState_Ensure();
+ PyRun_SimpleString(fire_update_flame.c_str());
+ PyGILState_Release(gilstate);
+ Manta_API::updatePointers(this, true);
}
#endif /*WITH_MANTA*/
@@ -907,8 +879,6 @@ void FLUID_3D::setBorderObstacles()
}
}
-
-
// Set border collision model from RNA setting
void FLUID_3D::setBorderCollisions() {
@@ -954,7 +924,6 @@ void FLUID_3D::setBorderCollisions() {
// (only needed for velocity, strength (w) depends on testcase...
//////////////////////////////////////////////////////////////////////
-
void FLUID_3D::artificialDampingSL(int zBegin, int zEnd) {
const float w = 0.9;
@@ -1009,8 +978,6 @@ void FLUID_3D::artificialDampingSL(int zBegin, int zEnd) {
}
}
-
-
void FLUID_3D::artificialDampingExactSL(int pos) {
const float w = 0.9;
int index, x,y,z;
@@ -1703,7 +1670,6 @@ void FLUID_3D::addBuoyancy(float *heat, float *density, float gravity[3], int zB
}
}
-
//////////////////////////////////////////////////////////////////////
// add vorticity to the force field
//////////////////////////////////////////////////////////////////////
@@ -1880,7 +1846,6 @@ void FLUID_3D::addVorticity(int zBegin, int zEnd)
if (_vorticity) delete[] _vorticity;
}
-
void FLUID_3D::advectMacCormackBegin(int zBegin, int zEnd)
{
Vec3Int res = Vec3Int(_xRes,_yRes,_zRes);
diff --git a/intern/smoke/intern/MANTA.cpp b/intern/smoke/intern/MANTA.cpp
index bd727b6..828bda5 100644
--- a/intern/smoke/intern/MANTA.cpp
+++ b/intern/smoke/intern/MANTA.cpp
@@ -659,7 +659,9 @@ void Manta_API::updatePointers(FLUID_3D *fluid, bool updateColor)
cout<< "Updating Heat" << fluid->_heat<< endl;
}
if (fluid->using_fire) {
- // TODO
+ fluid->_flame = (float* )pointerFromString(getGridPointer("flame_low", "s"));
+ fluid->_fuel = (float* )pointerFromString(getGridPointer("fuel_low", "s"));
+ fluid->_react = (float* )pointerFromString(getGridPointer("react_low", "s"));
}
}
diff --git a/intern/smoke/intern/scenarios/smoke.h b/intern/smoke/intern/scenarios/smoke.h
index b9a7e88..6ff7347 100644
--- a/intern/smoke/intern/scenarios/smoke.h
+++ b/intern/smoke/intern/scenarios/smoke.h
@@ -144,6 +144,12 @@ inflow_grid.save(os.path.join('$MANTA_EXPORT_PATH$','inflow.uni'))\n\
forces.save(os.path.join('$MANTA_EXPORT_PATH$','forces.uni'))\n\
print('Grids exported')";
+const string fire_process_burn = "\n\
+processBurn(fuel=fuel_low, density=density, react=react_low, heat=heat_low, red=color_r_low, green=color_g_low, blue=color_b_low)";
+
+const string fire_update_flame = "\n\
+updateFlame(react=react_low, flame=flame_low)";
+
const string standalone = "\
if (GUI):\n\
gui=Gui()\n\
@@ -181,8 +187,6 @@ const string smoke_step_low = "def sim_step_low(t, standalone = False):\n\
advectSemiLagrange(flags=flags, vel=vel, grid=color_b_low, order=$ADVECT_ORDER$)\n\
print ('Advecting fire grids')\n\
if manta_using_fire:\n\
- print ('Advecting fire grids')\n\
- advectSemiLagrange(flags=flags, vel=vel, grid=flame_low, order=$ADVECT_ORDER$)\n\
advectSemiLagrange(flags=flags, vel=vel, grid=fuel_low, order=$ADVECT_ORDER$)\n\
advectSemiLagrange(flags=flags, vel=vel, grid=react_low, order=$ADVECT_ORDER$)\n\
print ('Advecting density')\n\
diff --git a/source/blender/python/manta_full/CMakeLists.txt b/source/blender/python/manta_full/CMakeLists.txt
index 8fc5304..bf6e8b5 100755
--- a/source/blender/python/manta_full/CMakeLists.txt
+++ b/source/blender/python/manta_full/CMakeLists.txt
@@ -152,8 +152,8 @@ SET(PP_SOURCES
source/plugin/meshplugins.cpp
source/plugin/vortexplugins.cpp
source/plugin/waveletturbulence.cpp
+ source/plugin/fire.cpp
source/python/defines.py
- source/python/fire.cpp
source/test.cpp
)
diff --git a/source/blender/python/manta_full/source/plugin/fire.cpp b/source/blender/python/manta_full/source/plugin/fire.cpp
index 8cfa468..ea183ad 100644
--- a/source/blender/python/manta_full/source/plugin/fire.cpp
+++ b/source/blender/python/manta_full/source/plugin/fire.cpp
@@ -15,8 +15,6 @@
#include <float.h>
#include "vectorbase.h"
#include "grid.h"
-#include "shapes.h"
-#include "blenderHelper.h"
using namespace std;
@@ -26,8 +24,8 @@ namespace Manta {
const Real burningRate = 0.75;
const Real flameSmoke = 1.0;
const Real flameVorticity = 0.5;
-const Real flameIgnition = 1.25;
-const Real flameMaxTemp = 1.75;
+const Real ignitionPoint = 1.25;
+const Real tempMax = 1.75;
const Vec3 flameSmokeColor = Vec3(0.7f, 0.7f, 0.7f);
// default flow values
@@ -46,9 +44,9 @@ const bool withSmoke = true;
const bool withFire = true;
KERNEL (bnd=1)
-void KnProcessBurn(FlagGrid& flags,
+void KnProcessBurn(//FlagGrid& flags,
Grid<Real>& fuel,
- Grid<Real>& density,
+ LevelsetGrid& density,
Grid<Real>& react,
Grid<Real>& heat,
Grid<Real>& red,
@@ -61,8 +59,8 @@ void KnProcessBurn(FlagGrid& flags,
float dt,
Vec3 flameSmokeColor)
{
- if (flags.isFluid(i,j,k))
- {
+ //if (flags.isFluid(i,j,k))
+ //{
// Save initial values
float origFuel = fuel(i,j,k);
float origSmoke = density(i,j,k);
@@ -107,7 +105,7 @@ void KnProcessBurn(FlagGrid& flags,
green(i,j,k) = (green(i,j,k) + flameSmokeColor.y * smokeEmit) * smokeFactor;
blue(i,j,k) = (blue(i,j,k) + flameSmokeColor.z * smokeEmit) * smokeFactor;
}
- }
+ //}
}
KERNEL (bnd=1)
@@ -119,24 +117,21 @@ void KnUpdateFlame(Grid<Real>& react, Grid<Real>& flame)
flame(i,j,k) = 0.0f;
}
-PYTHON void KnProcessBurn()
+PYTHON void processBurn(Grid<Real>& fuel,
+ Grid<Real>& density,
+ Grid<Real>& react,
+ Grid<Real>& heat,
+ Grid<Real>& red,
+ Grid<Real>& green,
+ Grid<Real>& blue)
{
- KnProcessBurn(FlagGrid& flags,
- Grid<Real>& fuel,
- Grid<Real>& density,
- Grid<Real>& react,
- Grid<Real>& heat,
- Grid<Real>& red,
- Grid<Real>& green,
- Grid<Real>& blue,
- float burningRate,
- float flameSmoke,
- float ignitionPoint,
- float tempMax,
- float dt,
- Vec3 flameSmokeColor);
+ KnProcessBurn(fuel, density, react, heat, red, green, blue, burningRate,
+ flameSmoke, ignitionPoint, tempMax, dtDefault, flameSmokeColor);
}
-
+PYTHON void updateFlame(Grid<Real>& react, Grid<Real>& flame)
+{
+ KnUpdateFlame(react, flame);
+}
} // namespace
\ No newline at end of file
More information about the Bf-blender-cvs
mailing list