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/blenkernel | |
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/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_image.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_modifier.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_ocean.h | 8 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/dynamicpaint.c | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/image.c | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/modifier.c | 38 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/ocean.c | 25 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/particle_system.c | 7 |
8 files changed, 69 insertions, 22 deletions
diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index adb34f4c501..a3e0b5b6d5a 100644 --- a/source/blender/blenkernel/BKE_image.h +++ b/source/blender/blenkernel/BKE_image.h @@ -52,7 +52,7 @@ void BKE_stamp_buf(struct Scene *scene, struct Object *camera, unsigned char *re int BKE_alphatest_ibuf(struct ImBuf *ibuf); int BKE_write_ibuf_stamp(struct Scene *scene, struct Object *camera, struct ImBuf *ibuf, const char *name, int imtype, int subimtype, int quality); int BKE_write_ibuf(struct ImBuf *ibuf, const char *name, int imtype, int subimtype, int quality); -void BKE_makepicstring(char *string, const char *base, int frame, int imtype, const short use_ext, const short use_frames); +void BKE_makepicstring(char *string, const char *base, const char *relbase, int frame, int imtype, const short use_ext, const short use_frames); int BKE_add_image_extension(char *string, int imtype); int BKE_ftype_to_imtype(int ftype); int BKE_imtype_to_ftype(int imtype); diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h index a47cefe6f65..84f8995b480 100644 --- a/source/blender/blenkernel/BKE_modifier.h +++ b/source/blender/blenkernel/BKE_modifier.h @@ -364,5 +364,8 @@ void test_object_modifiers(struct Object *ob); /* here for do_versions */ void modifier_mdef_compact_influences(struct ModifierData *md); +void modifier_path_init(char *path, int path_maxlen, const char *name); +const char *modifier_path_relbase(struct Object *ob); + #endif diff --git a/source/blender/blenkernel/BKE_ocean.h b/source/blender/blenkernel/BKE_ocean.h index c1f228fe186..c8ce3f8ce63 100644 --- a/source/blender/blenkernel/BKE_ocean.h +++ b/source/blender/blenkernel/BKE_ocean.h @@ -48,7 +48,8 @@ typedef struct OceanCache { struct ImBuf **ibufs_foam; struct ImBuf **ibufs_norm; - char *bakepath; + const char *bakepath; + const char *relbase; /* precalculated for time range */ float *time; @@ -92,8 +93,9 @@ void BKE_ocean_eval_ij(struct Ocean * oc, struct OceanResult *ocr, int i, int j) /* ocean cache handling */ -struct OceanCache *BKE_init_ocean_cache(char *bakepath, int start, int end, float wave_scale, - float chop_amount, float foam_coverage, float foam_fade, int resolution); +struct OceanCache *BKE_init_ocean_cache(const char *bakepath, const char *relbase, + int start, int end, float wave_scale, + float chop_amount, float foam_coverage, float foam_fade, int resolution); void BKE_simulate_ocean_cache(struct OceanCache *och, int frame); void BKE_bake_ocean(struct Ocean *o, struct OceanCache *och, void (*update_cb)(void *, float progress, int *cancel), void *update_cb_data); diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index 6cb021b51b7..36ae764198a 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -976,8 +976,8 @@ struct DynamicPaintSurface *dynamicPaint_createNewSurface(DynamicPaintCanvasSett surface->wave_timescale = 1.0f; surface->wave_spring = 0.20f; - BLI_snprintf(surface->image_output_path, sizeof(surface->image_output_path), "%sdynamicpaint", U.textudir); - BLI_cleanup_dir(NULL, surface->image_output_path); + modifier_path_init(surface->image_output_path, sizeof(surface->image_output_path), "dynamicpaint"); + dynamicPaintSurface_setUniqueName(surface, "Surface"); surface->effector_weights = BKE_add_effector_weights(NULL); diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 08440849a4e..a61ae705020 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -1484,11 +1484,11 @@ int BKE_write_ibuf_stamp(Scene *scene, struct Object *camera, ImBuf *ibuf, const } -void BKE_makepicstring(char *string, const char *base, int frame, int imtype, const short use_ext, const short use_frames) +void BKE_makepicstring(char *string, const char *base, const char *relbase, int frame, int imtype, const short use_ext, const short use_frames) { if (string==NULL) return; BLI_strncpy(string, base, FILE_MAX - 10); /* weak assumption */ - BLI_path_abs(string, G.main->name); + BLI_path_abs(string, relbase); if(use_frames) BLI_path_frame(string, frame, 4); diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index bbc1b596889..f09be8c34ad 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -60,6 +60,11 @@ #include "BKE_key.h" #include "BKE_multires.h" +/* may move these, only for modifier_path_relbase */ +#include "BKE_global.h" /* ugh, G.main->name only */ +#include "BKE_main.h" +/* end */ + #include "MOD_modifiertypes.h" ModifierTypeInfo *modifierType_getInfo(ModifierType type) @@ -573,3 +578,36 @@ void test_object_modifiers(Object *ob) } } } + +/* where should this go?, it doesnt fit well anywhere :S - campbell */ + +/* elubie: changed this to default to the same dir as the render output + * to prevent saving to C:\ on Windows */ + +/* campbell: logic behind this... + * + * - if the ID is from a library, return library path + * - else if the file has been saved return the blend file path. + * - else if the file isn't saved and the ID isnt from a library, return the temp dir. + */ +const char *modifier_path_relbase(Object *ob) +{ + if (G.relbase_valid || ob->id.lib) { + return ID_BLEND_PATH(G.main, &ob->id); + } + else { + /* last resort, better then using "" which resolves to the current + * working directory */ + return BLI_temporary_dir(); + } +} + +/* initializes the path with either */ +void modifier_path_init(char *path, int path_maxlen, const char *name) +{ + /* elubie: changed this to default to the same dir as the render output + * to prevent saving to C:\ on Windows */ + BLI_join_dirfile(path, path_maxlen, + G.relbase_valid ? "//" : BLI_temporary_dir(), + name); +} diff --git a/source/blender/blenkernel/intern/ocean.c b/source/blender/blenkernel/intern/ocean.c index df4cd94cf38..5cf0b8c2348 100644 --- a/source/blender/blenkernel/intern/ocean.c +++ b/source/blender/blenkernel/intern/ocean.c @@ -998,7 +998,7 @@ void BKE_free_ocean(struct Ocean *oc) #define CACHE_TYPE_FOAM 2 #define CACHE_TYPE_NORMAL 3 -static void cache_filename(char *string, const char *path, int frame, int type) +static void cache_filename(char *string, const char *path, const char *relbase, int frame, int type) { char cachepath[FILE_MAX]; const char *fname; @@ -1018,7 +1018,7 @@ static void cache_filename(char *string, const char *path, int frame, int type) BLI_join_dirfile(cachepath, sizeof(cachepath), path, fname); - BKE_makepicstring(string, cachepath, frame, R_OPENEXR, 1, TRUE); + BKE_makepicstring(string, cachepath, relbase, frame, R_OPENEXR, 1, TRUE); } void BKE_free_ocean_cache(struct OceanCache *och) @@ -1119,12 +1119,15 @@ void BKE_ocean_cache_eval_ij(struct OceanCache *och, struct OceanResult *ocr, in } } -struct OceanCache *BKE_init_ocean_cache(char *bakepath, int start, int end, float wave_scale, - float chop_amount, float foam_coverage, float foam_fade, int resolution) +struct OceanCache *BKE_init_ocean_cache(const char *bakepath, const char *relbase, + int start, int end, float wave_scale, + float chop_amount, float foam_coverage, float foam_fade, int resolution) { OceanCache *och = MEM_callocN(sizeof(OceanCache), "ocean cache data"); och->bakepath = bakepath; + och->relbase = relbase; + och->start = start; och->end = end; och->duration = (end - start) + 1; @@ -1158,17 +1161,17 @@ void BKE_simulate_ocean_cache(struct OceanCache *och, int frame) if (och->ibufs_disp[f] != NULL ) return; - cache_filename(string, och->bakepath, frame, CACHE_TYPE_DISPLACE); + cache_filename(string, och->bakepath, och->relbase, frame, CACHE_TYPE_DISPLACE); och->ibufs_disp[f] = IMB_loadiffname(string, 0); //if (och->ibufs_disp[f] == NULL) printf("error loading %s \n", string); //else printf("loaded cache %s \n", string); - cache_filename(string, och->bakepath, frame, CACHE_TYPE_FOAM); + cache_filename(string, och->bakepath, och->relbase, frame, CACHE_TYPE_FOAM); och->ibufs_foam[f] = IMB_loadiffname(string, 0); //if (och->ibufs_foam[f] == NULL) printf("error loading %s \n", string); //else printf("loaded cache %s \n", string); - cache_filename(string, och->bakepath, frame, CACHE_TYPE_NORMAL); + cache_filename(string, och->bakepath, och->relbase, frame, CACHE_TYPE_NORMAL); och->ibufs_norm[f] = IMB_loadiffname(string, 0); //if (och->ibufs_norm[f] == NULL) printf("error loading %s \n", string); //else printf("loaded cache %s \n", string); @@ -1288,18 +1291,18 @@ void BKE_bake_ocean(struct Ocean *o, struct OceanCache *och, void (*update_cb)(v } /* write the images */ - cache_filename(string, och->bakepath, f, CACHE_TYPE_DISPLACE); + cache_filename(string, och->bakepath, och->relbase, f, CACHE_TYPE_DISPLACE); if(0 == BKE_write_ibuf(ibuf_disp, string, R_OPENEXR, R_OPENEXR_HALF, 2)) // 2 == ZIP exr codec printf("Cannot save Displacement File Output to %s\n", string); if (o->_do_jacobian) { - cache_filename(string, och->bakepath, f, CACHE_TYPE_FOAM); + cache_filename(string, och->bakepath, och->relbase, f, CACHE_TYPE_FOAM); if(0 == BKE_write_ibuf(ibuf_foam, string, R_OPENEXR, R_OPENEXR_HALF, 2)) // 2 == ZIP exr codec printf("Cannot save Foam File Output to %s\n", string); } if (o->_do_normals) { - cache_filename(string, och->bakepath, f, CACHE_TYPE_NORMAL); + cache_filename(string, och->bakepath, och->relbase, f, CACHE_TYPE_NORMAL); if(0 == BKE_write_ibuf(ibuf_normal, string, R_OPENEXR, R_OPENEXR_HALF, 2)) // 2 == ZIP exr codec printf("Cannot save Normal File Output to %s\n", string); } @@ -1409,7 +1412,7 @@ struct OceanCache *BKE_init_ocean_cache(char *UNUSED(bakepath), int UNUSED(start return och; } -void BKE_simulate_ocean_cache(struct OceanCache *UNUSED(och), int UNUSED(frame)) +void BKE_simulate_ocean_cache(struct OceanCache *UNUSED(och), const char *UNUSED(relbase), int UNUSED(frame)) { } diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index 74fd8ff128b..a955643cbcc 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -3935,9 +3935,10 @@ static void particles_fluid_step(ParticleSimulationData *sim, int UNUSED(cfra)) // return; // ok, start loading - BLI_snprintf(filename, sizeof(filename), "%sfluidsurface_particles_####.gz", fss->surfdataPath); - - BLI_path_abs(filename, G.main->name); + BLI_join_dirfile(filename, sizeof(filename), fss->surfdataPath, OB_FLUIDSIM_SURF_PARTICLES_FNAME); + + BLI_path_abs(filename, modifier_path_relbase(sim->ob)); + BLI_path_frame(filename, curFrame, 0); // fixed #frame-no gzf = gzopen(filename, "rb"); |