[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47177] branches/soc-2012-fried_chicken: * Added basic implementation of fire simulation:

Miika Hamalainen miika.hamalainen at kolumbus.fi
Tue May 29 15:41:20 CEST 2012


Revision: 47177
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47177
Author:   miikah
Date:     2012-05-29 13:41:20 +0000 (Tue, 29 May 2012)
Log Message:
-----------
* Added basic implementation of fire simulation:
* Flow settings now have a "Flow Type" menu where you can change if flow emits smoke or fire.
* Domain has a new "Flames" panel where you can adjust fire behavior.
* Added 3D-view rendering of fire together with smoke.
* Added new "Flames" voxel data type to render fire in Blender Internal render engine.

Current fire quality is very similar to the old way of using dissolving smoke to simulate fire. I'm going to work later this summer on allowing more realistic fire behavior by implementing a way to simulate the reaction "blue core".

Flow settings and initial velocity also play an important role in modeling gaseous expansion typical for burning fuel. That's what I'm going to work on next. :)

Modified Paths:
--------------
    branches/soc-2012-fried_chicken/intern/smoke/CMakeLists.txt
    branches/soc-2012-fried_chicken/intern/smoke/extern/smoke_API.h
    branches/soc-2012-fried_chicken/intern/smoke/intern/FLUID_3D.cpp
    branches/soc-2012-fried_chicken/intern/smoke/intern/FLUID_3D.h
    branches/soc-2012-fried_chicken/intern/smoke/intern/WTURBULENCE.cpp
    branches/soc-2012-fried_chicken/intern/smoke/intern/WTURBULENCE.h
    branches/soc-2012-fried_chicken/intern/smoke/intern/smoke_API.cpp
    branches/soc-2012-fried_chicken/release/scripts/startup/bl_ui/properties_physics_smoke.py
    branches/soc-2012-fried_chicken/source/blender/blenkernel/intern/pointcache.c
    branches/soc-2012-fried_chicken/source/blender/blenkernel/intern/smoke.c
    branches/soc-2012-fried_chicken/source/blender/blenloader/intern/readfile.c
    branches/soc-2012-fried_chicken/source/blender/editors/space_view3d/drawobject.c
    branches/soc-2012-fried_chicken/source/blender/editors/space_view3d/drawvolume.c
    branches/soc-2012-fried_chicken/source/blender/editors/space_view3d/view3d_intern.h
    branches/soc-2012-fried_chicken/source/blender/gpu/intern/gpu_draw.c
    branches/soc-2012-fried_chicken/source/blender/makesdna/DNA_smoke_types.h
    branches/soc-2012-fried_chicken/source/blender/makesdna/DNA_texture_types.h
    branches/soc-2012-fried_chicken/source/blender/makesrna/intern/rna_smoke.c
    branches/soc-2012-fried_chicken/source/blender/makesrna/intern/rna_texture.c
    branches/soc-2012-fried_chicken/source/blender/render/intern/source/voxeldata.c

Added Paths:
-----------
    branches/soc-2012-fried_chicken/intern/smoke/intern/spectrum.cpp
    branches/soc-2012-fried_chicken/intern/smoke/intern/spectrum.h

Modified: branches/soc-2012-fried_chicken/intern/smoke/CMakeLists.txt
===================================================================
--- branches/soc-2012-fried_chicken/intern/smoke/CMakeLists.txt	2012-05-29 13:23:34 UTC (rev 47176)
+++ branches/soc-2012-fried_chicken/intern/smoke/CMakeLists.txt	2012-05-29 13:41:20 UTC (rev 47177)
@@ -40,6 +40,7 @@
 	intern/FLUID_3D_SOLVERS.cpp
 	intern/FLUID_3D_STATIC.cpp
 	intern/LU_HELPER.cpp
+	intern/spectrum.cpp
 	intern/SPHERE.cpp
 	intern/WTURBULENCE.cpp
 	intern/smoke_API.cpp
@@ -53,6 +54,7 @@
 	intern/LU_HELPER.h
 	intern/MERSENNETWISTER.h
 	intern/OBSTACLE.h
+	intern/spectrum.h
 	intern/SPHERE.h
 	intern/VEC3.h
 	intern/WAVELET_NOISE.h

Modified: branches/soc-2012-fried_chicken/intern/smoke/extern/smoke_API.h
===================================================================
--- branches/soc-2012-fried_chicken/intern/smoke/extern/smoke_API.h	2012-05-29 13:23:34 UTC (rev 47176)
+++ branches/soc-2012-fried_chicken/intern/smoke/extern/smoke_API.h	2012-05-29 13:41:20 UTC (rev 47177)
@@ -38,16 +38,20 @@
 struct FLUID_3D;
 
 // export
-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);
+void smoke_export(struct FLUID_3D *fluid, float *dt, float *dx, float **dens, float **flame, float **fuel, float **heat, float **heatold,
+				  float **vx, float **vy, float **vz, unsigned char **obstacles);
 
 // low res
 struct FLUID_3D *smoke_init(int *res, float *p0, float dtdef);
 void smoke_free(struct FLUID_3D *fluid);
 
-void smoke_initBlenderRNA(struct FLUID_3D *fluid, float *alpha, float *beta, float *dt_factor, float *vorticity, int *border_colli);
+void smoke_initBlenderRNA(struct FLUID_3D *fluid, float *alpha, float *beta, float *dt_factor, float *vorticity, int *border_colli,
+						  float *burning_rate, float *flame_smoke, float *flame_vorticity, float *flame_ignition_temp, float *flame_max_temp);
 void smoke_step(struct FLUID_3D *fluid, float dtSubdiv);
 
 float *smoke_get_density(struct FLUID_3D *fluid);
+float *smoke_get_flame(struct FLUID_3D *fluid);
+float *smoke_get_fuel(struct FLUID_3D *fluid);
 float *smoke_get_heat(struct FLUID_3D *fluid);
 float *smoke_get_velocity_x(struct FLUID_3D *fluid);
 float *smoke_get_velocity_y(struct FLUID_3D *fluid);
@@ -73,6 +77,8 @@
 void smoke_turbulence_step(struct WTURBULENCE *wt, struct FLUID_3D *fluid);
 
 float *smoke_turbulence_get_density(struct WTURBULENCE *wt);
+float *smoke_turbulence_get_flame(struct WTURBULENCE *wt);
+float *smoke_turbulence_get_fuel(struct WTURBULENCE *wt);
 void smoke_turbulence_get_res(struct WTURBULENCE *wt, int *res);
 void smoke_turbulence_set_noise(struct WTURBULENCE *wt, int type);
 void smoke_initWaveletBlenderRNA(struct WTURBULENCE *wt, float *strength);
@@ -80,8 +86,10 @@
 void smoke_dissolve_wavelet(struct WTURBULENCE *wt, int speed, int log);
 
 // export
-void smoke_turbulence_export(struct WTURBULENCE *wt, float **dens, float **densold, float **tcu, float **tcv, float **tcw);
+void smoke_turbulence_export(struct WTURBULENCE *wt, float **dens, float **flame, float **fuel, float **tcu, float **tcv, float **tcw);
 
+void flame_get_spectrum(unsigned char *spec, int width, float t1, float t2);
+
 #ifdef __cplusplus
 }
 #endif

Modified: branches/soc-2012-fried_chicken/intern/smoke/intern/FLUID_3D.cpp
===================================================================
--- branches/soc-2012-fried_chicken/intern/smoke/intern/FLUID_3D.cpp	2012-05-29 13:23:34 UTC (rev 47176)
+++ branches/soc-2012-fried_chicken/intern/smoke/intern/FLUID_3D.cpp	2012-05-29 13:41:20 UTC (rev 47177)
@@ -105,6 +105,12 @@
 	_densityTemp   = new float[_totalCells];
 	_heatTemp      = new float[_totalCells];
 
+	// Fire simulation
+	_flame		= new float[_totalCells];
+	_fuel		= new float[_totalCells];
+	_fuelTemp	= new float[_totalCells];
+	_fuelOld	= new float[_totalCells];
+
 	// DG TODO: check if alloc went fine
 
 	for (int x = 0; x < _totalCells; x++)
@@ -126,6 +132,11 @@
 		_yForce[x]       = 0.0f;
 		_zForce[x]       = 0.0f;
 		_obstacles[x]    = false;
+
+		_flame[x]		= 0.0f;
+		_fuel[x]		= 0.0f;
+		_fuelTemp[x]	= 0.0f;
+		_fuelOld[x]		= 0.0f;
 	}
 
 	// boundary conditions of the fluid domain
@@ -212,17 +223,28 @@
 	if (_densityTemp) delete[] _densityTemp;
 	if (_heatTemp) delete[] _heatTemp;
 
+	if (_flame) delete[] _flame;
+	if (_fuel) delete[] _fuel;
+	if (_fuelTemp) delete[] _fuelTemp;
+	if (_fuelOld) delete[] _fuelOld;
+
     // printf("deleted fluid\n");
 }
 
 // init direct access functions from blender
-void FLUID_3D::initBlenderRNA(float *alpha, float *beta, float *dt_factor, float *vorticity, int *borderCollision)
+void FLUID_3D::initBlenderRNA(float *alpha, float *beta, float *dt_factor, float *vorticity, int *borderCollision,
+							  float *burning_rate, float *flame_smoke, float *flame_vorticity, float *flame_ignition_temp, float *flame_max_temp)
 {
 	_alpha = alpha;
 	_beta = beta;
 	_dtFactor = dt_factor;
 	_vorticityRNA = vorticity;
 	_borderColli = borderCollision;
+	_burning_rate = burning_rate;
+	_flame_smoke = flame_smoke;
+	_flame_vorticity = flame_vorticity;
+	_ignition_temp = flame_ignition_temp;
+	_max_temp = flame_max_temp;
 }
 
 //////////////////////////////////////////////////////////////////////
@@ -240,14 +262,21 @@
 	}
 #endif
 
+	for (int index = 0; index < _totalCells; index++)
+	{
+		_xVelocityOld[index] = -99999.f;
+		_yVelocityOld[index] = -99999.f;
+		_zVelocityOld[index] = -99999.f;
+		_densityOld[index] = -99999.f;
+		_fuelOld[index] = -99999.f;
+	}
+
 	// DG: TODO for the moment redo border for every timestep since it's been deleted every time by moving obstacles
 	setBorderCollisions();
 
 
 	// set delta time by dt_factor
 	_dt = (*_dtFactor) * dt;
-	// set vorticity from RNA value
-	_vorticityEps = (*_vorticityRNA)/_constantScaling;
 
 #if PARALLEL==1
 	int threadval = 1;
@@ -336,6 +365,7 @@
 	SWAP_POINTERS(_yVelocity, _yVelocityOld);
 	SWAP_POINTERS(_zVelocity, _zVelocityOld);
 	SWAP_POINTERS(_density, _densityOld);
+	SWAP_POINTERS(_fuel, _fuelOld);
 	SWAP_POINTERS(_heat, _heatOld);
 
 	advectMacCormackBegin(0, _zRes);
@@ -398,11 +428,8 @@
 	SWAP_POINTERS(_yVelocity, _yForce);
 	SWAP_POINTERS(_zVelocity, _zForce);
 
-
-
-
 	_totalTime += _dt;
-	_totalSteps++;		
+	_totalSteps++;
 
 	for (int i = 0; i < _totalCells; i++)
 	{
@@ -643,6 +670,7 @@
 	setZeroBorder(_yVelocity, _res, zBegin, zEnd);
 	setZeroBorder(_zVelocity, _res, zBegin, zEnd);
 	setZeroBorder(_density, _res, zBegin, zEnd);
+	setZeroBorder(_fuel, _res, zBegin, zEnd);
 }
 
 void FLUID_3D::wipeBoundariesSL(int zBegin, int zEnd)
@@ -668,6 +696,7 @@
 			_yVelocity[index] = 0.0f;
 			_zVelocity[index] = 0.0f;
 			_density[index] = 0.0f;
+			_fuel[index] = 0.0f;
 
 			// right slab
 			index += _xRes - 1;
@@ -675,6 +704,7 @@
 			_yVelocity[index] = 0.0f;
 			_zVelocity[index] = 0.0f;
 			_density[index] = 0.0f;
+			_fuel[index] = 0.0f;
 		}
 
 	/////////////////////////////////////
@@ -690,6 +720,7 @@
 			_yVelocity[index] = 0.0f;
 			_zVelocity[index] = 0.0f;
 			_density[index] = 0.0f;
+			_fuel[index] = 0.0f;
 
 			// top slab
 			index += slabSize - _xRes;
@@ -697,6 +728,7 @@
 			_yVelocity[index] = 0.0f;
 			_zVelocity[index] = 0.0f;
 			_density[index] = 0.0f;
+			_fuel[index] = 0.0f;
 
 		}
 
@@ -717,6 +749,7 @@
 			_yVelocity[index] = 0.0f;
 			_zVelocity[index] = 0.0f;
 			_density[index] = 0.0f;
+			_fuel[index] = 0.0f;
     }
 
 	if (zEnd == _zRes)
@@ -735,6 +768,7 @@
 				_yVelocity[indexx] = 0.0f;
 				_zVelocity[indexx] = 0.0f;
 				_density[indexx] = 0.0f;
+				_fuel[index] = 0.0f;
 			}
 	}
 
@@ -1192,8 +1226,11 @@
 //////////////////////////////////////////////////////////////////////
 void FLUID_3D::addVorticity(int zBegin, int zEnd)
 {
+	// set vorticity from RNA value
+	float flame_vorticity = (*_flame_vorticity)/_constantScaling;
+	_vorticityEps = (*_vorticityRNA)/_constantScaling;
 	//int x,y,z,index;
-	if(_vorticityEps<=0.) return;
+	if(_vorticityEps+flame_vorticity<=0.) return;
 
 	int _blockSize=zEnd-zBegin;
 	int _blockTotalCells = _slabSize * (_blockSize+2);
@@ -1305,9 +1342,9 @@
 						N[1] *= magnitude;
 						N[2] *= magnitude;
 
-						_xForce[index] += (N[1] * _zVorticity[vIndex] - N[2] * _yVorticity[vIndex]) * _dx * eps;
-						_yForce[index] -= (N[0] * _zVorticity[vIndex] - N[2] * _xVorticity[vIndex]) * _dx * eps;
-						_zForce[index] += (N[0] * _yVorticity[vIndex] - N[1] * _xVorticity[vIndex]) * _dx * eps;
+						_xForce[index] += (N[1] * _zVorticity[vIndex] - N[2] * _yVorticity[vIndex]) * _dx * (eps + _fuel[index]*flame_vorticity);
+						_yForce[index] -= (N[0] * _zVorticity[vIndex] - N[2] * _xVorticity[vIndex]) * _dx * (eps + _fuel[index]*flame_vorticity);
+						_zForce[index] += (N[0] * _yVorticity[vIndex] - N[1] * _xVorticity[vIndex]) * _dx * (eps + _fuel[index]*flame_vorticity);
 					}
 					}	// if
 					vIndex++;
@@ -1355,6 +1392,7 @@
 	// advectFieldMacCormack1(dt, xVelocity, yVelocity, zVelocity, oldField, newField, res)
 
 	advectFieldMacCormack1(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _densityOld, _densityTemp, res, zBegin, zEnd);
+	advectFieldMacCormack1(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _fuelOld, _fuelTemp, res, zBegin, zEnd);
 	advectFieldMacCormack1(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _heatOld, _heatTemp, res, zBegin, zEnd);
 	advectFieldMacCormack1(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _xVelocityOld, _xVelocity, res, zBegin, zEnd);
 	advectFieldMacCormack1(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _yVelocityOld, _yVelocity, res, zBegin, zEnd);
@@ -1377,6 +1415,7 @@
 	// advectFieldMacCormack2(dt, xVelocity, yVelocity, zVelocity, oldField, newField, tempfield, temp, res, obstacles)
 
 	advectFieldMacCormack2(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _densityOld, _density, _densityTemp, t1, res, _obstacles, zBegin, zEnd);
+	advectFieldMacCormack2(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _fuelOld, _fuel, _fuelTemp, t1, res, _obstacles, zBegin, zEnd);
 	advectFieldMacCormack2(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _heatOld, _heat, _heatTemp, t1, res, _obstacles, zBegin, zEnd);
 	advectFieldMacCormack2(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _xVelocityOld, _xVelocityTemp, _xVelocity, t1, res, _obstacles, zBegin, zEnd);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list