[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [51351] trunk/blender/intern/smoke/intern/ FLUID_3D.cpp: Smoke: Merge parts of Smoke2 branch

Daniel Genrich daniel.genrich at gmx.net
Mon Oct 15 21:57:21 CEST 2012


Revision: 51351
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=51351
Author:   genscher
Date:     2012-10-15 19:57:18 +0000 (Mon, 15 Oct 2012)
Log Message:
-----------
Smoke: Merge parts of Smoke2 branch

New:
----------
Collision objects do cause vorticity when passing through smoke

Part of my Smoke Development Project (milestone III)

Modified Paths:
--------------
    trunk/blender/intern/smoke/intern/FLUID_3D.cpp

Modified: trunk/blender/intern/smoke/intern/FLUID_3D.cpp
===================================================================
--- trunk/blender/intern/smoke/intern/FLUID_3D.cpp	2012-10-15 17:56:53 UTC (rev 51350)
+++ trunk/blender/intern/smoke/intern/FLUID_3D.cpp	2012-10-15 19:57:18 UTC (rev 51351)
@@ -1326,9 +1326,13 @@
 			}
 }
 
+
 //////////////////////////////////////////////////////////////////////
 // add vorticity to the force field
 //////////////////////////////////////////////////////////////////////
+#define VORT_VEL(i, j) \
+	((_obstacles[obpos[(i)]] & 8) ? ((abs(objvelocity[(j)][obpos[(i)]]) > FLT_EPSILON) ? objvelocity[(j)][obpos[(i)]] : velocity[(j)][index]) : velocity[(j)][obpos[(i)]])
+
 void FLUID_3D::addVorticity(int zBegin, int zEnd)
 {
 	// set flame vorticity from RNA value
@@ -1366,9 +1370,18 @@
 	float gridSize = 0.5f / _dx;
 	//index = _slabSize + _xRes + 1;
 
+	float *velocity[3];
+	float *objvelocity[3];
 
+	velocity[0] = _xVelocity;
+	velocity[1] = _yVelocity;
+	velocity[2] = _zVelocity;
+
+	objvelocity[0] = _xVelocityOb;
+	objvelocity[1] = _yVelocityOb;
+	objvelocity[2] = _zVelocityOb;
+
 	size_t vIndex=_xRes + 1;
-
 	for (int z = zBegin + bb1; z < (zEnd - bt1); z++)
 	{
 		size_t index = index_ +(z-1)*_slabSize;
@@ -1378,25 +1391,47 @@
 		{
 			for (int x = 1; x < _xRes - 1; x++, index++)
 			{
+				if (!_obstacles[index])
+				{
+					int obpos[6];
 
-				int up    = _obstacles[index + _xRes] ? index : index + _xRes;
-				int down  = _obstacles[index - _xRes] ? index : index - _xRes;
-				float dy  = (up == index || down == index) ? 1.0f / _dx : gridSize;
-				int out   = _obstacles[index + _slabSize] ? index : index + _slabSize;
-				int in    = _obstacles[index - _slabSize] ? index : index - _slabSize;
-				float dz  = (out == index || in == index) ? 1.0f / _dx : gridSize;
-				int right = _obstacles[index + 1] ? index : index + 1;
-				int left  = _obstacles[index - 1] ? index : index - 1;
-				float dx  = (right == index || left == index) ? 1.0f / _dx : gridSize;
+					obpos[0] = (_obstacles[index + _xRes] == 1) ? index : index + _xRes; // up
+					obpos[1] = (_obstacles[index - _xRes] == 1) ? index : index - _xRes; // down
+					float dy = (obpos[0] == index || obpos[1] == index) ? 1.0f / _dx : gridSize;
 
-				_xVorticity[vIndex] = (_zVelocity[up] - _zVelocity[down]) * dy + (-_yVelocity[out] + _yVelocity[in]) * dz;
-				_yVorticity[vIndex] = (_xVelocity[out] - _xVelocity[in]) * dz + (-_zVelocity[right] + _zVelocity[left]) * dx;
-				_zVorticity[vIndex] = (_yVelocity[right] - _yVelocity[left]) * dx + (-_xVelocity[up] + _xVelocity[down])* dy;
+					obpos[2]  = (_obstacles[index + _slabSize] == 1) ? index : index + _slabSize; // out
+					obpos[3]  = (_obstacles[index - _slabSize] == 1) ? index : index - _slabSize; // in
+					float dz  = (obpos[2] == index || obpos[3] == index) ? 1.0f / _dx : gridSize;
 
-				_vorticity[vIndex] = sqrtf(_xVorticity[vIndex] * _xVorticity[vIndex] +
+					obpos[4] = (_obstacles[index + 1] == 1) ? index : index + 1; // right
+					obpos[5] = (_obstacles[index - 1] == 1) ? index : index - 1; // left
+					float dx = (obpos[4] == index || obpos[5] == index) ? 1.0f / _dx : gridSize;
+
+					float xV[2], yV[2], zV[2];
+
+					zV[1] = VORT_VEL(0, 2);
+					zV[0] = VORT_VEL(1, 2);
+					yV[1] = VORT_VEL(2, 1);
+					yV[0] = VORT_VEL(3, 1);
+					_xVorticity[vIndex] = (zV[1] - zV[0]) * dy + (-yV[1] + yV[0]) * dz;
+
+					xV[1] = VORT_VEL(2, 0);
+					xV[0] = VORT_VEL(3, 0);
+					zV[1] = VORT_VEL(4, 2);
+					zV[0] = VORT_VEL(5, 2);
+					_yVorticity[vIndex] = (xV[1] - xV[0]) * dz + (-zV[1] + zV[0]) * dx;
+
+					yV[1] = VORT_VEL(4, 1);
+					yV[0] = VORT_VEL(5, 1);
+					xV[1] = VORT_VEL(0, 0);
+					xV[0] = VORT_VEL(1, 0);
+					_zVorticity[vIndex] = (yV[1] - yV[0]) * dx + (-xV[1] + xV[0])* dy;
+
+					_vorticity[vIndex] = sqrtf(_xVorticity[vIndex] * _xVorticity[vIndex] +
 						_yVorticity[vIndex] * _yVorticity[vIndex] +
 						_zVorticity[vIndex] * _zVorticity[vIndex]);
 
+				}
 				vIndex++;
 			}
 			vIndex+=2;
@@ -1425,15 +1460,18 @@
 				{
 					float N[3];
 
-					int up    = _obstacles[index + _xRes] ? vIndex : vIndex + _xRes;
-					int down  = _obstacles[index - _xRes] ? vIndex : vIndex - _xRes;
+					int up    = (_obstacles[index + _xRes] == 1) ? vIndex : vIndex + _xRes;
+					int down  = (_obstacles[index - _xRes] == 1) ? vIndex : vIndex - _xRes;
 					float dy  = (up == vIndex || down == vIndex) ? 1.0f / _dx : gridSize;
-					int out   = _obstacles[index + _slabSize] ? vIndex : vIndex + _slabSize;
-					int in    = _obstacles[index - _slabSize] ? vIndex : vIndex - _slabSize;
+
+					int out   = (_obstacles[index + _slabSize] == 1) ? vIndex : vIndex + _slabSize;
+					int in    = (_obstacles[index - _slabSize] == 1) ? vIndex : vIndex - _slabSize;
 					float dz  = (out == vIndex || in == vIndex) ? 1.0f / _dx : gridSize;
-					int right = _obstacles[index + 1] ? vIndex : vIndex + 1;
-					int left  = _obstacles[index - 1] ? vIndex : vIndex - 1;
+
+					int right = (_obstacles[index + 1] == 1) ? vIndex : vIndex + 1;
+					int left  = (_obstacles[index - 1] == 1) ? vIndex : vIndex - 1;
 					float dx  = (right == vIndex || left == vIndex) ? 1.0f / _dx : gridSize;
+
 					N[0] = (_vorticity[right] - _vorticity[left]) * dx;
 					N[1] = (_vorticity[up] - _vorticity[down]) * dy;
 					N[2] = (_vorticity[out] - _vorticity[in]) * dz;




More information about the Bf-blender-cvs mailing list