svn merge ^/trunk/blender -r42009:42053
[blender.git] / source / blender / modifiers / intern / MOD_fluidsim_util.c
index 236351a..16de49a 100644 (file)
@@ -69,8 +69,7 @@ void fluidsim_init(FluidsimModifierData *fluidmd)
        if(fluidmd)
        {
                FluidsimSettings *fss = MEM_callocN(sizeof(FluidsimSettings), "fluidsimsettings");
-               int surfdataPathMax = FILE_MAX;
-               
+
                fluidmd->fss = fss;
                
                if(!fss)
@@ -103,24 +102,7 @@ void fluidsim_init(FluidsimModifierData *fluidmd)
                // fluid/inflow settings
                // fss->iniVel --> automatically set to 0
 
-               /*  elubie: changed this to default to the same dir as the render output
-               to prevent saving to C:\ on Windows */
-               if (G.relbase_valid) {          /* is the .blend saved? */
-                       /* subfolder next to saved file */
-                       BLI_strncpy(fss->surfdataPath, "//fluid_cache", surfdataPathMax);
-                       BLI_add_slash(fss->surfdataPath);
-               }
-               else {
-                       /* subfolder in temp. directory */
-                       BLI_strncpy(fss->surfdataPath, BLI_temporary_dir(), surfdataPathMax);
-                       surfdataPathMax -= strlen(fss->surfdataPath);
-                       if (surfdataPathMax > 1) {
-                               BLI_strncpy(fss->surfdataPath+strlen(fss->surfdataPath), "fluid_cache", surfdataPathMax);
-                               surfdataPathMax -= strlen("fluid_cache");
-                               if (surfdataPathMax > 1)
-                                       BLI_add_slash(fss->surfdataPath);
-                       }
-               }
+               modifier_path_init(fss->surfdataPath, sizeof(fss->surfdataPath), "cache_fluid");
 
                // first init of bounding box
                // no bounding box needed
@@ -461,11 +443,11 @@ static void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh *
        gzclose(gzf);
 }
 
-static DerivedMesh *fluidsim_read_cache(DerivedMesh *orgdm, FluidsimModifierData *fluidmd, int framenr, int useRenderParams)
+static DerivedMesh *fluidsim_read_cache(Object *ob, DerivedMesh *orgdm, FluidsimModifierData *fluidmd, int framenr, int useRenderParams)
 {
        int displaymode = 0;
        int curFrame = framenr - 1 /*scene->r.sfra*/; /* start with 0 at start frame */
-       char targetDir[FILE_MAXFILE+FILE_MAXDIR], targetFile[FILE_MAXFILE+FILE_MAXDIR];
+       char targetFile[FILE_MAXFILE+FILE_MAXDIR];
        FluidsimSettings *fss = fluidmd->fss;
        DerivedMesh *dm = NULL;
        MFace *mface;
@@ -478,27 +460,22 @@ static DerivedMesh *fluidsim_read_cache(DerivedMesh *orgdm, FluidsimModifierData
                displaymode = fss->renderDisplayMode;
        }
 
-       BLI_strncpy(targetDir, fss->surfdataPath, sizeof(targetDir));
-
-       // use preview or final mesh?
-       if(displaymode==1)
-       {
-               // just display original object
+       switch (displaymode) {
+       case 1:
+               /* just display original object */
                return NULL;
+       case 2:
+               /* use preview mesh */
+               BLI_join_dirfile(targetFile, sizeof(targetFile), fss->surfdataPath, OB_FLUIDSIM_SURF_PREVIEW_OBJ_FNAME);
+               break;
+       default: /* 3 */
+               /* 3. use final mesh */
+               BLI_join_dirfile(targetFile, sizeof(targetFile), fss->surfdataPath, OB_FLUIDSIM_SURF_FINAL_OBJ_FNAME);
+               break;
        }
-       else if(displaymode==2)
-       {
-               strcat(targetDir,"fluidsurface_preview_####");
-       }
-       else
-       { // 3
-               strcat(targetDir,"fluidsurface_final_####");
-       }
-
-       BLI_path_abs(targetDir, G.main->name);
-       BLI_path_frame(targetDir, curFrame, 0); // fixed #frame-no
 
-       BLI_snprintf(targetFile, sizeof(targetFile), "%s.bobj.gz", targetDir);
+       BLI_path_abs(targetFile, modifier_path_relbase(ob));
+       BLI_path_frame(targetFile, curFrame, 0); // fixed #frame-no
 
        dm = fluidsim_read_obj(targetFile);
 
@@ -554,7 +531,7 @@ static DerivedMesh *fluidsim_read_cache(DerivedMesh *orgdm, FluidsimModifierData
 #endif // WITH_MOD_FLUID
 
 DerivedMesh *fluidsimModifier_do(FluidsimModifierData *fluidmd, Scene *scene,
-                                               Object *UNUSED(ob),
+                                               Object *ob,
                                                DerivedMesh *dm,
                                                int useRenderParams, int UNUSED(isFinalCalc))
 {
@@ -587,7 +564,7 @@ DerivedMesh *fluidsimModifier_do(FluidsimModifierData *fluidmd, Scene *scene,
        
        /* try to read from cache */
        /* if the frame is there, fine, otherwise don't do anything */
-       if((result = fluidsim_read_cache(dm, fluidmd, framenr, useRenderParams)))
+       if((result = fluidsim_read_cache(ob, dm, fluidmd, framenr, useRenderParams)))
                return result;
        
        return dm;