[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45745] branches/smoke2: Smoke: Support moving collision objects.
Daniel Genrich
daniel.genrich at gmx.net
Wed Apr 18 15:04:29 CEST 2012
Revision: 45745
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45745
Author: genscher
Date: 2012-04-18 13:04:28 +0000 (Wed, 18 Apr 2012)
Log Message:
-----------
Smoke: Support moving collision objects.
Tested: Rigid movement.
Untested: Armature/etc (individual vertices) movement.
Sponsored by the Blender Development Fund.
Modified Paths:
--------------
branches/smoke2/intern/elbeem/intern/solver_init.cpp
branches/smoke2/intern/smoke/extern/smoke_API.h
branches/smoke2/intern/smoke/intern/FLUID_3D.cpp
branches/smoke2/intern/smoke/intern/FLUID_3D.h
branches/smoke2/intern/smoke/intern/OBSTACLE.h
branches/smoke2/intern/smoke/intern/WTURBULENCE.cpp
branches/smoke2/intern/smoke/intern/smoke_API.cpp
branches/smoke2/release/scripts/startup/bl_ui/properties_physics_smoke.py
branches/smoke2/source/blender/blenkernel/intern/smoke.c
branches/smoke2/source/blender/makesdna/DNA_smoke_types.h
branches/smoke2/source/blender/makesrna/intern/rna_smoke.c
Modified: branches/smoke2/intern/elbeem/intern/solver_init.cpp
===================================================================
--- branches/smoke2/intern/elbeem/intern/solver_init.cpp 2012-04-18 12:54:12 UTC (rev 45744)
+++ branches/smoke2/intern/elbeem/intern/solver_init.cpp 2012-04-18 13:04:28 UTC (rev 45745)
@@ -1406,9 +1406,14 @@
for(int OId=0; OId<numobjs; OId++) {
ntlGeometryObject *obj = (*mpGiObjects)[OId];
bool skip = false;
+
+ int wasActive = ((obj->getGeoActive(sourceTime)>0.)? 1:0);
+ int active = ((obj->getGeoActive(targetTime)>0.)? 1:0);
+
if(obj->getGeoInitId() != mLbmInitId) skip=true;
if( (!staticInit) && (!obj->getIsAnimated()) ) skip=true;
if( ( staticInit) && ( obj->getIsAnimated()) ) skip=true;
+
if(skip) continue;
debMsgStd("LbmFsgrSolver::initMovingObstacles",DM_MSG," obj "<<obj->getName()<<" skip:"<<skip<<", static:"<<staticInit<<" anim:"<<obj->getIsAnimated()<<" gid:"<<obj->getGeoInitId()<<" simgid:"<<mLbmInitId, 10);
@@ -1448,8 +1453,6 @@
otype = ntype = CFMbndOutflow;
break;
}
- int wasActive = ((obj->getGeoActive(sourceTime)>0.)? 1:0);
- int active = ((obj->getGeoActive(targetTime)>0.)? 1:0);
//errMsg("GEOACTT"," obj "<<obj->getName()<<" a:"<<active<<","<<wasActive<<" s"<<sourceTime<<" t"<<targetTime <<" v"<<mObjectSpeeds[OId] );
// skip inactive in/out flows
if(ntype==CFInvalid){ errMsg("LbmFsgrSolver::initMovingObstacles","Invalid obj type "<<obj->getGeoInitType()); continue; }
@@ -1658,7 +1661,7 @@
const LbmFloat usqr = (vel[0]*vel[0]+vel[1]*vel[1]+vel[2]*vel[2])*1.5;
USQRMAXCHECK(usqr,vel[0],vel[1],vel[2], mMaxVlen, mMxvx,mMxvy,mMxvz);
//errMsg("LbmFsgrSolver::initMovingObstacles","id"<<OId<<" "<<obj->getName()<<" inflow "<<staticInit<<" "<<mMOIVertices.size() );
-
+
for(size_t n=0; n<mMOIVertices.size(); n++) {
POS2GRID_CHECK(mMOIVertices,n);
// TODO - also reinit interface cells !?
@@ -1696,6 +1699,7 @@
else if(ntype&CFMbndOutflow){
const LbmFloat iniRho = 0.0;
+
for(size_t n=0; n<mMOIVertices.size(); n++) {
POS2GRID_CHECK(mMOIVertices,n);
// FIXME check fluid/inter cells for non-static!?
@@ -1792,7 +1796,7 @@
int numobjs = (int)(mpGiObjects->size());
for(int o=0; o<numobjs; o++) {
ntlGeometryObject *obj = (*mpGiObjects)[o];
- //debMsgStd("LbmFsgrSolver::initMovingObstacles",DM_MSG," obj "<<obj->getName()<<" type "<<obj->getGeoInitType()<<" anim"<<obj->getIsAnimated()<<" "<<obj->getVolumeInit() ,9);
+ // debMsgStd("LbmFsgrSolver::initMovingObstacles",DM_MSG," obj "<<obj->getName()<<" type "<<obj->getGeoInitType()<<" anim"<<obj->getIsAnimated()<<" "<<obj->getVolumeInit() ,9);
if(
((obj->getGeoInitType()&FGI_ALLBOUNDS) && (obj->getIsAnimated())) ||
(obj->getVolumeInit()&VOLUMEINIT_SHELL) ) {
@@ -1857,16 +1861,19 @@
if(inside) {
pObj = (*mpGiObjects)[OId];
switch( pObj->getGeoInitType() ){
- case FGI_MBNDINFLOW:
- if(! pObj->getIsAnimated() ) {
+ case FGI_MBNDINFLOW:
+ if(! pObj->getIsAnimated()) {
rhomass = 1.0;
ntype = CFFluid | CFMbndInflow;
} else {
- ntype = CFInvalid;
- }
+ // ntype = CFInvalid;
+
+ rhomass = 1.0;
+ ntype = CFFluid;
+ }
break;
case FGI_MBNDOUTFLOW:
- if(! pObj->getIsAnimated() ) {
+ if(! pObj->getIsAnimated()) {
rhomass = 0.0;
ntype = CFEmpty|CFMbndOutflow;
} else {
Modified: branches/smoke2/intern/smoke/extern/smoke_API.h
===================================================================
--- branches/smoke2/intern/smoke/extern/smoke_API.h 2012-04-18 12:54:12 UTC (rev 45744)
+++ branches/smoke2/intern/smoke/extern/smoke_API.h 2012-04-18 13:04:28 UTC (rev 45745)
@@ -41,11 +41,11 @@
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);
// low res
-struct FLUID_3D *smoke_init(int *res, float *p0);
+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_step(struct FLUID_3D *fluid, size_t framenr, float fps);
+void smoke_step(struct FLUID_3D *fluid, float dtSubdiv);
float *smoke_get_density(struct FLUID_3D *fluid);
float *smoke_get_heat(struct FLUID_3D *fluid);
@@ -53,11 +53,15 @@
float *smoke_get_velocity_y(struct FLUID_3D *fluid);
float *smoke_get_velocity_z(struct FLUID_3D *fluid);
+/* Moving obstacle velocity provided by blender */
+void smoke_get_ob_velocity(struct FLUID_3D *fluid, float **x, float **y, float **z);
+
float *smoke_get_force_x(struct FLUID_3D *fluid);
float *smoke_get_force_y(struct FLUID_3D *fluid);
float *smoke_get_force_z(struct FLUID_3D *fluid);
unsigned char *smoke_get_obstacle(struct FLUID_3D *fluid);
+unsigned char *smoke_get_obstacle_anim(struct FLUID_3D *fluid);
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);
Modified: branches/smoke2/intern/smoke/intern/FLUID_3D.cpp
===================================================================
--- branches/smoke2/intern/smoke/intern/FLUID_3D.cpp 2012-04-18 12:54:12 UTC (rev 45744)
+++ branches/smoke2/intern/smoke/intern/FLUID_3D.cpp 2012-04-18 13:04:28 UTC (rev 45745)
@@ -34,6 +34,8 @@
#include "SPHERE.h"
#include <zlib.h>
+#include "float.h"
+
#if PARALLEL==1
#include <omp.h>
#endif // PARALLEL
@@ -42,11 +44,11 @@
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
-FLUID_3D::FLUID_3D(int *res, float *p0) :
+FLUID_3D::FLUID_3D(int *res, float *p0, float dtdef) :
_xRes(res[0]), _yRes(res[1]), _zRes(res[2]), _res(0.0f)
{
// set simulation consts
- _dt = DT_DEFAULT; // just in case. set in step from a RNA factor
+ _dt = dtdef; // just in case. set in step from a RNA factor
// start point of array
_p0[0] = p0[0];
@@ -81,6 +83,9 @@
_xVelocity = new float[_totalCells];
_yVelocity = new float[_totalCells];
_zVelocity = new float[_totalCells];
+ _xVelocityOb = new float[_totalCells];
+ _yVelocityOb = new float[_totalCells];
+ _zVelocityOb = new float[_totalCells];
_xVelocityOld = new float[_totalCells];
_yVelocityOld = new float[_totalCells];
_zVelocityOld = new float[_totalCells];
@@ -111,6 +116,9 @@
_xVelocity[x] = 0.0f;
_yVelocity[x] = 0.0f;
_zVelocity[x] = 0.0f;
+ _xVelocityOb[x] = 0.0f;
+ _yVelocityOb[x] = 0.0f;
+ _zVelocityOb[x] = 0.0f;
_xVelocityOld[x] = 0.0f;
_yVelocityOld[x] = 0.0f;
_zVelocityOld[x] = 0.0f;
@@ -131,9 +139,15 @@
_colloPrev = 1; // default value
+ setBorderObstacles(); // walls
+}
+
+void FLUID_3D::setBorderObstacles()
+{
+
// set side obstacles
- int index;
+ unsigned int index;
for (int y = 0; y < _yRes; y++)
for (int x = 0; x < _xRes; x++)
{
@@ -169,7 +183,6 @@
index += _xRes - 1;
if(_domainBcRight==1) _obstacles[index] = 1;
}
-
}
FLUID_3D::~FLUID_3D()
@@ -177,6 +190,9 @@
if (_xVelocity) delete[] _xVelocity;
if (_yVelocity) delete[] _yVelocity;
if (_zVelocity) delete[] _zVelocity;
+ if (_xVelocityOb) delete[] _xVelocityOb;
+ if (_yVelocityOb) delete[] _yVelocityOb;
+ if (_zVelocityOb) delete[] _zVelocityOb;
if (_xVelocityOld) delete[] _xVelocityOld;
if (_yVelocityOld) delete[] _yVelocityOld;
if (_zVelocityOld) delete[] _zVelocityOld;
@@ -214,12 +230,20 @@
//////////////////////////////////////////////////////////////////////
void FLUID_3D::step(float dt)
{
+#if 0
// If border rules have been changed
if (_colloPrev != *_borderColli) {
+ printf("Border collisions changed\n");
+
+ // DG TODO: Need to check that no animated obstacle flags are overwritten
setBorderCollisions();
}
+#endif
+ // 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
@@ -786,6 +810,7 @@
memset(_pressure, 0, sizeof(float)*_totalCells);
memset(_divergence, 0, sizeof(float)*_totalCells);
+ // set velocity and pressure inside of obstacles to zero
setObstacleBoundaries(_pressure, 0, _zRes);
// copy out the boundaries
@@ -798,12 +823,49 @@
if(_domainBcTop == 0) setNeumannZ(_zVelocity, _res, 0, _zRes);
else setZeroZ(_zVelocity, _res, 0, _zRes);
+ /*
+ {
+ float maxx = 0, maxy = 0, maxz = 0;
+ for(unsigned int i = 0; i < _xRes * _yRes * _zRes; i++)
+ {
+ if(_xVelocity[i] > maxx)
+ maxx = _xVelocity[i];
+ if(_yVelocity[i] > maxy)
+ maxy = _yVelocity[i];
+ if(_zVelocity[i] > maxz)
+ maxz = _zVelocity[i];
+ }
+ printf("Max velx: %f, vely: %f, velz: %f\n", maxx, maxy, maxz);
+ }
+ */
+
+ /*
+ {
+ float maxvalue = 0;
+ for(unsigned int i = 0; i < _xRes * _yRes * _zRes; i++)
+ {
+ if(_heat[i] > maxvalue)
+ maxvalue = _heat[i];
+
+ }
+ printf("Max heat: %f\n", maxvalue);
+ }
+ */
+
// calculate divergence
index = _slabSize + _xRes + 1;
for (z = 1; z < _zRes - 1; z++, index += 2 * _xRes)
for (y = 1; y < _yRes - 1; y++, index += 2)
for (x = 1; x < _xRes - 1; x++, index++)
{
+
+ if(_obstacles[index])
+ {
+ _divergence[index] = 0.0f;
+ continue;
+ }
+
+
float xright = _xVelocity[index + 1];
float xleft = _xVelocity[index - 1];
float yup = _yVelocity[index + _xRes];
@@ -811,26 +873,82 @@
float ztop = _zVelocity[index + _slabSize];
float zbottom = _zVelocity[index - _slabSize];
- if(_obstacles[index+1]) xright = - _xVelocity[index];
+ if(_obstacles[index+1]) xright = - _xVelocity[index]; // DG: +=
if(_obstacles[index-1]) xleft = - _xVelocity[index];
if(_obstacles[index+_xRes]) yup = - _yVelocity[index];
if(_obstacles[index-_xRes]) ydown = - _yVelocity[index];
if(_obstacles[index+_slabSize]) ztop = - _zVelocity[index];
if(_obstacles[index-_slabSize]) zbottom = - _zVelocity[index];
+ if(_obstacles[index+1] & 8) xright += _xVelocityOb[index + 1];
+ if(_obstacles[index-1] & 8) xleft += _xVelocityOb[index - 1];
+ if(_obstacles[index+_xRes] & 8) yup += _yVelocityOb[index + _xRes];
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list