Added 4 gui elements to structs, another 2-3 will follow; Unsolved problems: simulati...
authorDaniel Genrich <daniel.genrich@gmx.net>
Sun, 6 Jul 2008 21:55:03 +0000 (21:55 +0000)
committerDaniel Genrich <daniel.genrich@gmx.net>
Sun, 6 Jul 2008 21:55:03 +0000 (21:55 +0000)
intern/elbeem/extern/elbeem.h
intern/elbeem/intern/controlparticles.cpp
intern/elbeem/intern/elbeem.cpp
intern/elbeem/intern/ntl_geometryobject.cpp
intern/elbeem/intern/ntl_geometryobject.h
intern/elbeem/intern/solver_control.cpp
source/blender/src/fluidsim.c

index 2599432..5c1fc64 100644 (file)
@@ -116,7 +116,7 @@ typedef struct elbeemSimulationSettings {
 
 // a single mesh object
 typedef struct elbeemMesh {
-  /* obstacle,fluid or inflow... */
+  /* obstacle,fluid or inflow or control ... */
   short type;
        /* id of simulation domain it belongs to */
        short parentDomainId;
@@ -158,6 +158,13 @@ typedef struct elbeemMesh {
 
        /* name of the mesh, mostly for debugging */
        const char *name;
+       
+       /* fluid control settings */
+       // TODO dg: change to channels
+       float attractforceStrength;
+       float attractforceRadius;
+       float velocityforceStrength;
+       float velocityforceRadius;
 } elbeemMesh;
 
 // API functions
index d1f11f3..70a94bb 100644 (file)
@@ -68,10 +68,15 @@ int ControlParticles::initFromObject(ntlGeometryObjModel *model) {
        model->setLoaded(true);
        
        model->setGeoInitId(gid);
+       
+       
+       printf("a animated? %d\n", model->getIsAnimated());
+       printf("b animated? %d\n", model->getMeshAnimated());
        */
        model->setGeoInitType(FGI_FLUID);
        
        model->getTriangles(mCPSTimeStart, &triangles, &vertices, &normals, 1 ); 
+       // model->applyTransformation(mCPSTimeStart, &vertices, &normals, 0, vertices.size(), true);
        
        // valid mesh?
        if(triangles.size() <= 0) {
@@ -92,11 +97,11 @@ int ControlParticles::initFromObject(ntlGeometryObjModel *model) {
        // TODO? use params
        ntlVec3Gfx start,end;
        model->getExtends(start,end);
-       
+       /*
        printf("start - x: %f, y: %f, z: %f\n", start[0], start[1], start[2]);
        printf("end   - x: %f, y: %f, z: %f\n", end[0], end[1], end[2]);
        printf("mCPSWidth: %f\n");
-
+*/
        LbmFloat width = mCPSWidth;
        if(width<=LBM_EPSILON) { errMsg("ControlParticles::initFromMVMCMesh","Invalid mCPSWidth! "<<mCPSWidth); width=mCPSWidth=0.1; }
        ntlVec3Gfx org = start+ntlVec3Gfx(width*0.5);
@@ -104,6 +109,8 @@ int ControlParticles::initFromObject(ntlGeometryObjModel *model) {
        vector<ntlVec3Gfx> inspos;
        int approxmax = (int)( ((end[0]-start[0])/width)*((end[1]-start[1])/width)*((end[2]-start[2])/width) );
 
+       // printf("distance: %f, width: %f\n", distance, width);
+       
        while(org[2]<end[2]) {
                while(org[1]<end[1]) {
                        while(org[0]<end[0]) {
@@ -119,6 +126,8 @@ int ControlParticles::initFromObject(ntlGeometryObjModel *model) {
                org[2] += width;
                org[1] = start[1];
        }
+       
+       // printf("inspos.size(): %d\n", inspos.size());
 
        MeanValueMeshCoords mvm;
        mvm.calculateMVMCs(vertices,triangles, inspos, mCPSWeightFac);
@@ -144,6 +153,8 @@ int ControlParticles::initFromObject(ntlGeometryObjModel *model) {
 
        // init further sets, temporal mesh sampling
        double tsampling = mCPSTimestep;
+       // printf("tsampling: %f, ninspos.size(): %d, mCPSTimeEnd: %f\n", tsampling, ninspos.size(), mCPSTimeEnd);
+       
        int totcnt = (int)( (mCPSTimeEnd-mCPSTimeStart)/tsampling ), tcnt=0;
        for(double t=mCPSTimeStart+tsampling; ((t<mCPSTimeEnd) && (ninspos.size()>0.)); t+=tsampling) {
                ControlParticleSet nextcps; //T
@@ -164,8 +175,6 @@ int ControlParticles::initFromObject(ntlGeometryObjModel *model) {
                        }
                }
        }
-
-       // applyTrafos();
        
        model->setGeoInitType(FGI_CONTROL);
        
index 0a48a7a..1d8f92b 100644 (file)
@@ -159,6 +159,12 @@ void elbeemResetMesh(elbeemMesh *mesh) {
 
        /* name of the mesh, mostly for debugging */
        mesh->name = "[unnamed]";
+       
+       /* fluid control settings */
+       mesh->attractforceStrength = 0;
+       mesh->attractforceRadius = 0;
+       mesh->velocityforceStrength = 0;
+       mesh->velocityforceRadius = 0;
 }
 
 int globalMeshCounter = 1;
@@ -198,6 +204,13 @@ int elbeemAddMesh(elbeemMesh *mesh) {
        obj->setGeoInitType(initType);
        obj->setGeoPartSlipValue(mesh->obstaclePartslip);
        obj->setGeoImpactFactor(mesh->obstacleImpactFactor);
+       
+       /* fluid control features */
+       obj->setAttractForceStrength(mesh->attractforceStrength);
+       obj->setAttractForceRadius(mesh->attractforceRadius);
+       obj->setVelocityForceStrength(mesh->velocityforceStrength);
+       obj->setVelocityForceRadius(mesh->velocityforceRadius);
+       
        if((mesh->volumeInitType<VOLUMEINIT_VOLUME)||(mesh->volumeInitType>VOLUMEINIT_BOTH)) mesh->volumeInitType = VOLUMEINIT_VOLUME;
        obj->setVolumeInit(mesh->volumeInitType);
        // use channel instead, obj->setInitialVelocity( ntlVec3Gfx(mesh->iniVelocity[0], mesh->iniVelocity[1], mesh->iniVelocity[2]) );
index 9861ce8..68735ac 100644 (file)
@@ -346,6 +346,7 @@ void ntlGeometryObject::initChannels(
        if((ivel)&&(nIvel>0)) {    ADD_CHANNEL_VEC(mcInitialVelocity, nIvel, ivel); }
 
        checkIsAnimated();
+       
        if(debugInitc) { 
                debMsgStd("ntlGeometryObject::initChannels",DM_MSG,getName()<<
                                " nt:"<<mcTrans.accessValues().size()<<" nr:"<<mcRot.accessValues().size()<<
index a5afd6b..fd7455a 100644 (file)
@@ -97,7 +97,28 @@ class ntlGeometryObject : public ntlGeometryClass
                /*! Set/get the local inivel coords flag */
                inline bool getLocalCoordInivel() const { return mLocalCoordInivel; }
                inline void setLocalCoordInivel(bool set) { mLocalCoordInivel=set; }
-
+               
+               /****************************************/
+               /* fluid control features */
+               /****************************************/
+               /*! Set/get the particle control set attract force strength */
+               inline float getAttractForceStrength() const { return mAttractforceStrength; }
+               inline void setAttractForceStrength(float set) { mAttractforceStrength=set; }
+               
+               /*! Set/get the particle control set attract force radius */
+               inline float getAttractForceRadius() const { return mAttractforceRadius; }
+               inline void setAttractForceRadius(float set) { mAttractforceRadius=set; }
+               
+               /*! Set/get the particle control set velocity force strength */
+               inline float getVelocityForceStrength() const { return mVelocityforceStrength; }
+               inline void setVelocityForceStrength(float set) { mVelocityforceStrength=set; }
+               
+               /*! Set/get the particle control set velocity force radius */
+               inline float getVelocityForceRadius() const { return mVelocityforceRadius; }
+               inline void setVelocityForceRadius(float set) { mVelocityforceRadius=set; }
+               
+               /****************************************/
+               
                /*! Init channels from float arrays (for elbeem API) */
                void initChannels(
                                int nTrans, float *trans, int nRot, float *rot, int nScale, float *scale,
@@ -202,6 +223,13 @@ class ntlGeometryObject : public ntlGeometryClass
 
                /*! animated channels for in/outflow on/off */
                AnimChannel<float> mcGeoActive;
+               
+               /* fluid control settings */
+               // TODO dg: change to channels
+               float mAttractforceStrength;
+               float mAttractforceRadius;
+               float mVelocityforceStrength;
+               float mVelocityforceRadius;
 
        public:
 
index c556cbf..e4c5158 100644 (file)
@@ -218,33 +218,32 @@ LbmFsgrSolver::initCpdata()
        // manually switch on! if this is zero, nothing is done...
        mpControl->mSetForceStrength = this->mTForceStrength = 1.;
        mpControl->mCons.clear();
-
-       // add new set
-       LbmControlSet *cset;
-
-       cset = new LbmControlSet();
-       cset->initCparts();
-       
-       // dont load any file
-       cset->mContrPartFile = string("");
-
-       cset->mcForceAtt = AnimChannel<float>(0.2);
-       cset->mcRadiusAtt = AnimChannel<float>(0.75);
-       cset->mcForceVel = AnimChannel<float>(0.2);
-       cset->mcRadiusVel = AnimChannel<float>(0.75);
-
-               // this value can be left at 0.5:
-       cset->mCparts->setCPSMvmWeightFac(0.5);
-
-       mpControl->mCons.push_back( cset );
        
        // init all control fluid objects
        int numobjs = (int)(mpGiObjects->size());
        for(int o=0; o<numobjs; o++) {
                ntlGeometryObjModel *obj = (ntlGeometryObjModel *)(*mpGiObjects)[o];
                if(obj->getGeoInitType() & FGI_CONTROL) {
-                       printf("added control object\n");
-                       mpControl->mCons[0]->mCparts->initFromObject(obj);
+                       // add new control set per object
+                       LbmControlSet *cset;
+
+                       cset = new LbmControlSet();
+                       cset->initCparts();
+       
+                       // dont load any file
+                       cset->mContrPartFile = string("");
+
+                       // TODO dg: switch to channels later
+                       cset->mcForceAtt = AnimChannel<float>(obj->getAttractForceStrength());
+                       cset->mcRadiusAtt = AnimChannel<float>(obj->getAttractForceRadius());
+                       cset->mcForceVel = AnimChannel<float>(obj->getVelocityForceStrength());
+                       cset->mcRadiusVel = AnimChannel<float>(obj->getVelocityForceRadius());
+
+                       // this value can be left at 0.5:
+                       cset->mCparts->setCPSMvmWeightFac(0.5);
+
+                       mpControl->mCons.push_back( cset );
+                       mpControl->mCons[mpControl->mCons.size()-1]->mCparts->initFromObject(obj);
                }
        }
        
index 85453cc..768acc1 100644 (file)
@@ -994,7 +994,7 @@ void fluidsimBake(struct Object *ob)
                                // todo - use blenderInitElbeemMesh
                                elbeemMesh fsmesh;
                                elbeemResetMesh( &fsmesh );
-                               fsmesh.type = obit->fluidsimSettings->type;;
+                               fsmesh.type = obit->fluidsimSettings->type;
                                // get name of object for debugging solver
                                fsmesh.name = obit->id.name; 
 
@@ -1015,8 +1015,7 @@ void fluidsimBake(struct Object *ob)
                                fsmesh.channelScale            = channelObjMove[o][2];
                                fsmesh.channelActive           = channelObjActive[o];
                                if( (fsmesh.type == OB_FLUIDSIM_FLUID) ||
-                               (fsmesh.type == OB_FLUIDSIM_INFLOW) ||
-                               (fsmesh.type == OB_FLUIDSIM_CONTROL)) {
+                               (fsmesh.type == OB_FLUIDSIM_INFLOW)) {
                                        fsmesh.channelInitialVel       = channelObjInivel[o];
                                  fsmesh.localInivelCoords = ((obit->fluidsimSettings->typeFlags&OB_FSINFLOW_LOCALCOORD)?1:0);
                                } 
@@ -1027,6 +1026,17 @@ void fluidsimBake(struct Object *ob)
                                fsmesh.obstaclePartslip = obit->fluidsimSettings->partSlipValue;
                                fsmesh.volumeInitType = obit->fluidsimSettings->volumeInitType;
                                fsmesh.obstacleImpactFactor = obit->fluidsimSettings->surfaceSmoothing; // misused value
+                               
+                               if(fsmesh.type == OB_FLUIDSIM_CONTROL)
+                               {
+                                       // control fluids will get exported as whole
+                                       deform = 1;
+                                       
+                                       fsmesh.attractforceStrength = obit->fluidsimSettings->attractforceStrength;
+                                       fsmesh.attractforceRadius = obit->fluidsimSettings->attractforceRadius;
+                                       fsmesh.velocityforceStrength = obit->fluidsimSettings->velocityforceStrength;
+                                       fsmesh.velocityforceRadius = obit->fluidsimSettings->velocityforceRadius;
+                               }
 
                                // animated meshes
                                if(deform) {