Almost done with 'Phase 1': Fixed depsgraph update of modifier, fixed material index...
authorDaniel Genrich <daniel.genrich@gmx.net>
Sun, 27 Jul 2008 12:28:34 +0000 (12:28 +0000)
committerDaniel Genrich <daniel.genrich@gmx.net>
Sun, 27 Jul 2008 12:28:34 +0000 (12:28 +0000)
source/blender/blenkernel/BKE_fluidsim.h
source/blender/blenkernel/intern/fluidsim.c
source/blender/blenkernel/intern/modifier.c
source/blender/blenloader/intern/readfile.c
source/blender/src/buttons_object.c
source/blender/src/fluidsim.c

index 12df42e85c1c39549caa854354db5b032159d489..a3a109a1aa696211325519af02774a5fc1b4662a 100644 (file)
@@ -47,7 +47,7 @@ void loadFluidsimMesh(Object *srcob, int useRenderParams);
 void fluidsim_init(FluidsimModifierData *fluidmd);
 void fluidsim_free(FluidsimModifierData *fluidmd);
 
-DerivedMesh *fluidsim_read_cache(Object *ob, FluidsimModifierData *fluidmd, int framenr, int useRenderParams);
+DerivedMesh *fluidsim_read_cache(Object *ob, DerivedMesh *orgdm, FluidsimModifierData *fluidmd, int framenr, int useRenderParams);
 DerivedMesh *fluidsimModifier_do(FluidsimModifierData *fluidmd, Object *ob, DerivedMesh *dm, int useRenderParams, int isFinalCalc);
 
 void fluid_get_bb(MVert *mvert, int totvert, float obmat[][4],
index 3b369e52c439a75b93e6417138fead9e1fd02ba2..032dc7f44ed3058d4cbd47cdfb90c62c7d6c9aa4 100644 (file)
@@ -179,9 +179,9 @@ DerivedMesh *fluidsimModifier_do(FluidsimModifierData *fluidmd, Object *ob, Deri
        // clmd->sim_parms->timescale= timescale;
        
        /* try to read from cache */
-       if((result = fluidsim_read_cache(ob, fluidmd, framenr, useRenderParams))) 
+       if(((fss->lastgoodframe >= framenr) || (fss->lastgoodframe < 0)) && (result = fluidsim_read_cache(ob, dm, fluidmd, framenr, useRenderParams)))
        {
-               fss->lastgoodframe = framenr;
+               // fss->lastgoodframe = framenr; // set also in src/fluidsim.c
                return result;
        }
        else
@@ -189,13 +189,20 @@ DerivedMesh *fluidsimModifier_do(FluidsimModifierData *fluidmd, Object *ob, Deri
                // display last known good frame
                if(fss->lastgoodframe >= 0)
                {
-                       if((result = fluidsim_read_cache(ob, fluidmd, fss->lastgoodframe, useRenderParams))) 
+                       if((result = fluidsim_read_cache(ob, dm, fluidmd, fss->lastgoodframe, useRenderParams))) 
                        {
                                return result;
                        }
                        
                        // it was supposed to be a valid frame but it isn't!
-                       fss->lastgoodframe = -1;
+                       fss->lastgoodframe = framenr - 1;
+                       
+                       
+                       // this could be likely the case when you load an old fluidsim
+                       if((result = fluidsim_read_cache(ob, dm, fluidmd, fss->lastgoodframe, useRenderParams))) 
+                       {
+                               return result;
+                       }
                }
                
                result = CDDM_copy(dm);
@@ -216,7 +223,7 @@ static DerivedMesh *fluidsim_read_obj(char *filename)
        float wrf;
        int gotBytes;
        gzFile gzf;
-       int numverts = 0, numfaces = 0, numedges = 0;
+       int numverts = 0, numfaces = 0;
        DerivedMesh *dm = NULL;
        MFace *mface;
        MVert *mvert;
@@ -364,13 +371,16 @@ static DerivedMesh *fluidsim_read_obj(char *filename)
        return dm;
 }
 
-DerivedMesh *fluidsim_read_cache(Object *ob, FluidsimModifierData *fluidmd, int framenr, int useRenderParams)
+DerivedMesh *fluidsim_read_cache(Object *ob, DerivedMesh *orgdm, FluidsimModifierData *fluidmd, int framenr, int useRenderParams)
 {
        int displaymode = 0;
        int curFrame = framenr - 1 /*G.scene->r.sfra*/; /* start with 0 at start frame */
        char targetDir[FILE_MAXFILE+FILE_MAXDIR], targetFile[FILE_MAXFILE+FILE_MAXDIR];
        FluidsimSettings *fss = fluidmd->fss;
        DerivedMesh *dm = NULL;
+       MFace *mface;
+       int numfaces;
+       int mat_nr, flag, i;
        
        if(!useRenderParams) {
                displaymode = fss->guiDisplayMode;
@@ -421,6 +431,19 @@ DerivedMesh *fluidsim_read_cache(Object *ob, FluidsimModifierData *fluidmd, int
                // display org. object upon failure which is in dm
                return NULL;
        }
+       
+       // assign material + flags to new dm
+       mface = orgdm->getFaceArray(orgdm);
+       mat_nr = mface[0].mat_nr;
+       flag = mface[0].flag;
+       
+       mface = dm->getFaceArray(dm);
+       numfaces = dm->getNumFaces(dm);
+       for(i=0; i<numfaces; i++) 
+       {
+               mface[i].mat_nr = mat_nr;
+               mface[i].flag = flag;
+       }
 
        // load vertex velocities, if they exist...
        // TODO? use generate flag as loading flag as well?
index 1f2c570321e870dde064e2380ea482d92d1509a1..d970b064a449772c0e7d4f2ea867fd60ac44c0d1 100644 (file)
@@ -6932,6 +6932,36 @@ static DerivedMesh * fluidsimModifier_applyModifier(
        return derivedData;
 }
 
+static void fluidsimModifier_updateDepgraph(
+               ModifierData *md, DagForest *forest,
+      Object *ob, DagNode *obNode)
+{
+       FluidsimModifierData *fluidmd= (FluidsimModifierData*) md;
+       Base *base;
+
+       if(fluidmd && fluidmd->fss)
+       {
+               if(fluidmd->fss->type == OB_FLUIDSIM_DOMAIN)
+               {
+                       for(base = G.scene->base.first; base; base= base->next) 
+                       {
+                               Object *ob1= base->object;
+                               if(ob1 != ob)
+                               {
+                                       FluidsimModifierData *fluidmdtmp = (FluidsimModifierData *)modifiers_findByType(ob1, eModifierType_Fluidsim);
+                                       
+                                       // only put dependancies from NON-DOMAIN fluids in here
+                                       if(fluidmdtmp && fluidmdtmp->fss && (fluidmdtmp->fss->type!=OB_FLUIDSIM_DOMAIN))
+                                       {
+                                               DagNode *curNode = dag_get_node(forest, ob1);
+                                               dag_add_relation(forest, curNode, obNode, DAG_RL_DATA_DATA|DAG_RL_OB_DATA, "Fluidsim Object");
+                                       }
+                               }
+                       }
+               }
+       }
+}
+
 static int fluidsimModifier_dependsOnTime(ModifierData *md) 
 {
        return 1;
@@ -7577,6 +7607,7 @@ ModifierTypeInfo *modifierType_getInfo(ModifierType type)
                mti->freeData = fluidsimModifier_freeData;
                mti->dependsOnTime = fluidsimModifier_dependsOnTime;
                mti->applyModifier = fluidsimModifier_applyModifier;
+               mti->updateDepgraph = fluidsimModifier_updateDepgraph;
 
                typeArrInit = 0;
 #undef INIT_TYPE
index 65c5aad43a71410be9e3ef8a9c486ce3a3fb788c..82269357b24069464fffd59e1ea4edc69e073233 100644 (file)
@@ -7745,6 +7745,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                fluidmd->fss = MEM_dupallocN(ob->fluidsimSettings);
                                fluidmd->fss->ipo = newlibadr_us(fd, ob->id.lib, ob->fluidsimSettings->ipo);
                                MEM_freeN(ob->fluidsimSettings);
+                               
+                               fluidmd->fss->lastgoodframe = INT_MAX;
                        }
                }
        }
index b63933f7abfc7687929c2f7684519cbfa5c3c49d..4fc665c96432ea35422787bbb498ee90bc4e05de 100644 (file)
@@ -5041,7 +5041,6 @@ static void object_panel_fluidsim(Object *ob)
                {
                        const int maxRes = 512;
                        char memString[32];
-                       int i;
                        Mesh *mesh = ob->data;
                
                        // use mesh bounding box and object scaling
index 1b57356e39e8f945c9d33d75dd830ca8cf507471..153d53a1cde632f04582eff71557c2a855037ba5 100644 (file)
@@ -1038,6 +1038,10 @@ void fluidsimBake(struct Object *ob)
                                        if(event == ESCKEY) {
                                                // abort...
                                                SDL_mutexP(globalBakeLock);
+                                               
+                                               if(domainSettings)
+                                                       domainSettings->lastgoodframe = startFrame+globalBakeFrame;
+                                               
                                                done = -1;
                                                globalBakeFrame = 0;
                                                globalBakeState = -1;
@@ -1078,6 +1082,13 @@ void fluidsimBake(struct Object *ob)
 
        // go back to "current" blender time
        waitcursor(0);
+       
+       if(globalBakeState >= 0)
+       {
+               if(domainSettings)
+                       domainSettings->lastgoodframe = startFrame+globalBakeFrame;
+       }
+       
   G.scene->r.cfra = origFrame;
   scene_update_for_newframe(G.scene, G.scene->lay);
        allqueue(REDRAWVIEW3D, 0);