[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22411] branches/blender2.5/blender: Smoke :

Daniel Genrich daniel.genrich at gmx.net
Wed Aug 12 19:32:03 CEST 2009


Revision: 22411
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22411
Author:   genscher
Date:     2009-08-12 19:32:02 +0200 (Wed, 12 Aug 2009)

Log Message:
-----------
Smoke: 
* New feature: "Dissolve Smoke" - Idea by nudelZ

Modified Paths:
--------------
    branches/blender2.5/blender/intern/smoke/extern/smoke_API.h
    branches/blender2.5/blender/intern/smoke/intern/FLUID_3D.cpp
    branches/blender2.5/blender/intern/smoke/intern/FLUID_3D.h
    branches/blender2.5/blender/intern/smoke/intern/FLUID_3D_STATIC.cpp
    branches/blender2.5/blender/intern/smoke/intern/smoke_API.cpp
    branches/blender2.5/blender/release/ui/buttons_physics_smoke.py
    branches/blender2.5/blender/source/blender/blenkernel/intern/smoke.c
    branches/blender2.5/blender/source/blender/makesdna/DNA_smoke_types.h
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_smoke.c

Modified: branches/blender2.5/blender/intern/smoke/extern/smoke_API.h
===================================================================
--- branches/blender2.5/blender/intern/smoke/extern/smoke_API.h	2009-08-12 17:02:03 UTC (rev 22410)
+++ branches/blender2.5/blender/intern/smoke/extern/smoke_API.h	2009-08-12 17:32:02 UTC (rev 22411)
@@ -36,7 +36,7 @@
 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);
+void smoke_step(struct FLUID_3D *fluid, size_t framenr);
 
 float *smoke_get_density(struct FLUID_3D *fluid);
 float *smoke_get_heat(struct FLUID_3D *fluid);
@@ -49,6 +49,8 @@
 size_t smoke_get_index(int x, int max_x, int y, int max_y, int z);
 size_t smoke_get_index2d(int x, int max_x, int y);
 
+void smoke_dissolve(struct FLUID_3D *fluid, int speed, int log);
+
 // wavelet turbulence functions
 struct WTURBULENCE *smoke_turbulence_init(int *res, int amplify, int noisetype);
 void smoke_turbulence_free(struct WTURBULENCE *wt);
@@ -59,6 +61,8 @@
 void smoke_turbulence_set_noise(struct WTURBULENCE *wt, int type);
 void smoke_initWaveletBlenderRNA(struct WTURBULENCE *wt, float *strength);
 
+void smoke_dissolve_wavelet(struct WTURBULENCE *wt, int speed, int log);
+
 #ifdef __cplusplus
 }
 #endif

Modified: branches/blender2.5/blender/intern/smoke/intern/FLUID_3D.cpp
===================================================================
--- branches/blender2.5/blender/intern/smoke/intern/FLUID_3D.cpp	2009-08-12 17:02:03 UTC (rev 22410)
+++ branches/blender2.5/blender/intern/smoke/intern/FLUID_3D.cpp	2009-08-12 17:32:02 UTC (rev 22411)
@@ -101,6 +101,11 @@
 	_h			  = new float[_totalCells];
 	_Precond	  = new float[_totalCells];
 
+	_spectrum = new unsigned char[256*4*16*16];
+
+
+	// DG TODO: check if alloc went fine
+
 	for (int x = 0; x < _totalCells; x++)
 	{
 		_density[x]      = 0.0f;
@@ -202,6 +207,8 @@
 	if (_obstacles) delete[] _obstacles;
     // if (_wTurbulence) delete _wTurbulence;
 
+	if(_spectrum) delete[] _spectrum;
+
     printf("deleted fluid\n");
 }
 
@@ -219,7 +226,10 @@
 {
 	// wipe forces
 	for (int i = 0; i < _totalCells; i++)
+	{
 		_xForce[i] = _yForce[i] = _zForce[i] = 0.0f;
+		_obstacles[i] &= ~2;
+	}
 
 	wipeBoundaries();
 
@@ -683,16 +693,17 @@
 
 	const float dt0 = _dt / _dx;
 	// use force arrays as temp arrays
-  for (int x = 0; x < _totalCells; x++)
-    _xForce[x] = _yForce[x] = 0.0;
+	for (int x = 0; x < _totalCells; x++)
+		_xForce[x] = _yForce[x] = 0.0;
+
 	float* t1 = _xForce;
 	float* t2 = _yForce;
 
-	advectFieldMacCormack(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _densityOld, _density, t1,t2, res, NULL);
-	advectFieldMacCormack(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _heatOld, _heat, t1,t2, res, NULL);
-	advectFieldMacCormack(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _xVelocityOld, _xVelocity, t1,t2, res, NULL);
-	advectFieldMacCormack(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _yVelocityOld, _yVelocity, t1,t2, res, NULL);
-	advectFieldMacCormack(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _zVelocityOld, _zVelocity, t1,t2, res, NULL);
+	advectFieldMacCormack(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _densityOld, _density, t1,t2, res, _obstacles);
+	advectFieldMacCormack(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _heatOld, _heat, t1,t2, res, _obstacles);
+	advectFieldMacCormack(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _xVelocityOld, _xVelocity, t1,t2, res, _obstacles);
+	advectFieldMacCormack(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _yVelocityOld, _yVelocity, t1,t2, res, _obstacles);
+	advectFieldMacCormack(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _zVelocityOld, _zVelocity, t1,t2, res, _obstacles);
 
 	if(DOMAIN_BC_LEFT == 0) copyBorderX(_xVelocity, res);
 	else setZeroX(_xVelocity, res);

Modified: branches/blender2.5/blender/intern/smoke/intern/FLUID_3D.h
===================================================================
--- branches/blender2.5/blender/intern/smoke/intern/FLUID_3D.h	2009-08-12 17:02:03 UTC (rev 22410)
+++ branches/blender2.5/blender/intern/smoke/intern/FLUID_3D.h	2009-08-12 17:32:02 UTC (rev 22411)
@@ -99,6 +99,7 @@
 		float* _h;
 		float* _Precond;
 		unsigned char*  _obstacles;
+		unsigned char *_spectrum;
 
 		// CG fields
 		float* _residual;
@@ -161,13 +162,13 @@
 		static void advectFieldSemiLagrange(const float dt, const float* velx, const float* vely,  const float* velz,
 				float* oldField, float* newField, Vec3Int res);
 		static void advectFieldMacCormack(const float dt, const float* xVelocity, const float* yVelocity, const float* zVelocity, 
-				float* oldField, float* newField, float* temp1, float* temp2, Vec3Int res, const float* obstacles);
+				float* oldField, float* newField, float* temp1, float* temp2, Vec3Int res, const unsigned char* obstacles);
 
 		// maccormack helper functions
 		static void clampExtrema(const float dt, const float* xVelocity, const float* yVelocity,  const float* zVelocity,
 				float* oldField, float* newField, Vec3Int res);
 		static void clampOutsideRays(const float dt, const float* xVelocity, const float* yVelocity,  const float* zVelocity,
-				float* oldField, float* newField, Vec3Int res, const float* obstacles, const float *oldAdvection);
+				float* oldField, float* newField, Vec3Int res, const unsigned char* obstacles, const float *oldAdvection);
 
 		// output helper functions
 		// static void writeImageSliceXY(const float *field, Vec3Int res, int slice, string prefix, int picCnt, float scale=1.);

Modified: branches/blender2.5/blender/intern/smoke/intern/FLUID_3D_STATIC.cpp
===================================================================
--- branches/blender2.5/blender/intern/smoke/intern/FLUID_3D_STATIC.cpp	2009-08-12 17:02:03 UTC (rev 22410)
+++ branches/blender2.5/blender/intern/smoke/intern/FLUID_3D_STATIC.cpp	2009-08-12 17:32:02 UTC (rev 22411)
@@ -338,7 +338,7 @@
 // comments are the pseudocode from selle's paper
 //////////////////////////////////////////////////////////////////////
 void FLUID_3D::advectFieldMacCormack(const float dt, const float* xVelocity, const float* yVelocity, const float* zVelocity,
-		float* oldField, float* newField, float* temp1, float* temp2, Vec3Int res, const float* obstacles)
+		float* oldField, float* newField, float* temp1, float* temp2, Vec3Int res, const unsigned char* obstacles)
 {
 	float* phiHatN  = temp1;
 	float* phiHatN1 = temp2;
@@ -459,7 +459,7 @@
 // incorrect
 //////////////////////////////////////////////////////////////////////
 void FLUID_3D::clampOutsideRays(const float dt, const float* velx, const float* vely, const float* velz,
-		float* oldField, float* newField, Vec3Int res, const float* obstacles, const float *oldAdvection)
+		float* oldField, float* newField, Vec3Int res, const unsigned char* obstacles, const float *oldAdvection)
 {
 	const int sx= res[0];
 	const int sy= res[1];

Modified: branches/blender2.5/blender/intern/smoke/intern/smoke_API.cpp
===================================================================
--- branches/blender2.5/blender/intern/smoke/intern/smoke_API.cpp	2009-08-12 17:02:03 UTC (rev 22410)
+++ branches/blender2.5/blender/intern/smoke/intern/smoke_API.cpp	2009-08-12 17:32:02 UTC (rev 22411)
@@ -63,8 +63,19 @@
 	 wt = NULL;
 }
 
-extern "C" void smoke_step(FLUID_3D *fluid)
+extern "C" size_t smoke_get_index(int x, int max_x, int y, int max_y, int z /*, int max_z */)
 {
+	// // const int index = x + y * smd->res[0] + z * smd->res[0]*smd->res[1];
+	return x + y * max_x + z * max_x*max_y;
+}
+
+extern "C" size_t smoke_get_index2d(int x, int max_x, int y /*, int max_y, int z, int max_z */)
+{
+	return x + y * max_x;
+}
+
+extern "C" void smoke_step(FLUID_3D *fluid, size_t framenr)
+{
 	fluid->step();
 }
 
@@ -79,6 +90,84 @@
 	fluid->initBlenderRNA(alpha, beta);
 }
 
+extern "C" void smoke_dissolve(FLUID_3D *fluid, int speed, int log)
+{
+	float *density = fluid->_density;
+	float *densityOld = fluid->_densityOld;
+	float *heat = fluid->_heat;
+
+	if(log)
+	{
+		/* max density/speed = dydx */
+		float dydx = 1.0 / (float)speed;
+
+		for(size_t i = 0; i < fluid->_xRes * fluid->_yRes * fluid->_zRes; i++)
+		{
+			density[i] *= (1.0 - dydx);
+
+			if(density[i] < 0.0f)
+				density[i] = 0.0f;
+
+			heat[i] *= (1.0 - dydx);
+
+			if(heat[i] < 0.0f)
+				heat[i] = 0.0f;
+		}
+	}
+	else // linear falloff
+	{
+		/* max density/speed = dydx */
+		float dydx = 1.0 / (float)speed;
+
+		for(size_t i = 0; i < fluid->_xRes * fluid->_yRes * fluid->_zRes; i++)
+		{
+			density[i] -= dydx;
+
+			if(density[i] < 0.0f)
+				density[i] = 0.0f;
+
+			heat[i] -= dydx;
+
+			if(heat[i] < 0.0f)
+				heat[i] = 0.0f;
+				
+		}
+	}
+}
+
+extern "C" void smoke_dissolve_wavelet(WTURBULENCE *wt, int speed, int log)
+{
+	float *density = wt->getDensityBig();
+	Vec3Int r = wt->getResBig();
+
+	if(log)
+	{
+		/* max density/speed = dydx */
+		float dydx = 1.0 / (float)speed;
+
+		for(size_t i = 0; i < r[0] * r[1] * r[2]; i++)
+		{
+			density[i] *= (1.0 - dydx);
+
+			if(density[i] < 0.0f)
+				density[i] = 0.0f;
+		}
+	}
+	else // linear falloff
+	{
+		/* max density/speed = dydx */
+		float dydx = 1.0 / (float)speed;
+
+		for(size_t i = 0; i < r[0] * r[1] * r[2]; i++)
+		{
+			density[i] -= dydx;
+
+			if(density[i] < 0.0f)
+				density[i] = 0.0f;				
+		}
+	}
+}
+
 extern "C" void smoke_initWaveletBlenderRNA(WTURBULENCE *wt, float *strength)
 {
 	wt->initBlenderRNA(strength);
@@ -134,17 +223,6 @@
 	return fluid->_obstacles;
 }
 
-extern "C" size_t smoke_get_index(int x, int max_x, int y, int max_y, int z /*, int max_z */)
-{
-	// // const int index = x + y * smd->res[0] + z * smd->res[0]*smd->res[1];
-	return x + y * max_x + z * max_x*max_y;
-}
-
-extern "C" size_t smoke_get_index2d(int x, int max_x, int y /*, int max_y, int z, int max_z */)
-{
-	return x + y * max_x;
-}
-
 extern "C" void smoke_turbulence_set_noise(WTURBULENCE *wt, int type)
 {
 	wt->setNoise(type);

Modified: branches/blender2.5/blender/release/ui/buttons_physics_smoke.py
===================================================================
--- branches/blender2.5/blender/release/ui/buttons_physics_smoke.py	2009-08-12 17:02:03 UTC (rev 22410)
+++ branches/blender2.5/blender/release/ui/buttons_physics_smoke.py	2009-08-12 17:32:02 UTC (rev 22411)
@@ -72,7 +72,15 @@
 				sub = split.column()
 				
 				split = layout.split()
+				col = split.column()

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list