diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-11-20 18:38:11 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-11-20 18:38:11 +0400 |
commit | f1eb66aa68105ac27f371f4f708d8abf3b7da38b (patch) | |
tree | 77ce3c813f25702880e330740e06ae60a0aadca8 /source/blender/modifiers | |
parent | be701c7336a3f967a3a2807f8a7a0c511cb76815 (diff) |
share code for fluidsim, ocean & dynamic paint file paths.
- use BLI_join_dirfile for joining all paths (no need to ensure slash is appended).
- paths from linked library files now supported.
Diffstat (limited to 'source/blender/modifiers')
-rw-r--r-- | source/blender/modifiers/intern/MOD_fluidsim_util.c | 61 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_ocean.c | 35 |
2 files changed, 30 insertions, 66 deletions
diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.c b/source/blender/modifiers/intern/MOD_fluidsim_util.c index 15e1cdfcb62..34c8c4cc1b1 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim_util.c +++ b/source/blender/modifiers/intern/MOD_fluidsim_util.c @@ -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), "fluid_cache"); // 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; diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c index 726c37811fb..3ba49f26449 100644 --- a/source/blender/modifiers/intern/MOD_ocean.c +++ b/source/blender/modifiers/intern/MOD_ocean.c @@ -48,10 +48,13 @@ #include "MOD_util.h" #ifdef WITH_OCEANSIM -static void init_cache_data(struct OceanModifierData *omd) +static void init_cache_data(Object *ob, struct OceanModifierData *omd) { - omd->oceancache = BKE_init_ocean_cache(omd->cachepath, omd->bakestart, omd->bakeend, omd->wave_scale, - omd->chop_amount, omd->foam_coverage, omd->foam_fade, omd->resolution); + const char *relbase= modifier_path_relbase(ob); + + omd->oceancache = BKE_init_ocean_cache(omd->cachepath, relbase, + omd->bakestart, omd->bakeend, omd->wave_scale, + omd->chop_amount, omd->foam_coverage, omd->foam_fade, omd->resolution); } static void clear_cache_data(struct OceanModifierData *omd) @@ -97,7 +100,6 @@ static void initData(ModifierData *md) { #ifdef WITH_OCEANSIM OceanModifierData *omd = (OceanModifierData*) md; - int cachepathmax = sizeof(omd->cachepath); omd->resolution = 7; omd->spatial_size = 50; @@ -125,22 +127,7 @@ static void initData(ModifierData *md) omd->repeat_x = 1; omd->repeat_y = 1; - if (G.relbase_valid) { /* is the .blend saved? */ - /* subfolder next to saved file */ - BLI_strncpy(omd->cachepath, "//ocean_cache", cachepathmax); - BLI_add_slash(omd->cachepath); - } - else { - /* subfolder in temp. directory */ - BLI_strncpy(omd->cachepath, BLI_temporary_dir(), cachepathmax); - cachepathmax -= strlen(omd->cachepath); - if (cachepathmax > 1) { - BLI_strncpy(omd->cachepath+strlen(omd->cachepath), "ocean_cache", cachepathmax); - cachepathmax -= strlen("ocean_cache"); - if (cachepathmax > 1) - BLI_add_slash(omd->cachepath); - } - } + modifier_path_init(omd->cachepath, sizeof(omd->cachepath), "ocean_cache"); omd->cached = 0; omd->bakestart = 1; @@ -377,9 +364,9 @@ static DerivedMesh *generate_ocean_geometry(OceanModifierData *omd) return result; } -static DerivedMesh *doOcean(ModifierData *md, Object *UNUSED(ob), - DerivedMesh *derivedData, - int UNUSED(useRenderParams)) +static DerivedMesh *doOcean(ModifierData *md, Object *ob, + DerivedMesh *derivedData, + int UNUSED(useRenderParams)) { OceanModifierData *omd = (OceanModifierData*) md; @@ -410,7 +397,7 @@ static DerivedMesh *doOcean(ModifierData *md, Object *UNUSED(ob), /* do ocean simulation */ if (omd->cached == TRUE) { - if (!omd->oceancache) init_cache_data(omd); + if (!omd->oceancache) init_cache_data(ob, omd); BKE_simulate_ocean_cache(omd->oceancache, md->scene->r.cfra); } else { simulate_ocean_modifier(omd); |