[Bf-blender-cvs] [297bbc3] alembic: Simplified functions for generating absolute file paths from the base cache library and modifiers.
Lukas Tönne
noreply at git.blender.org
Mon Mar 30 12:39:53 CEST 2015
Commit: 297bbc316ac88aea9065750f6e9ad8b6d99e38fb
Author: Lukas Tönne
Date: Mon Mar 30 10:31:58 2015 +0200
Branches: alembic
https://developer.blender.org/rB297bbc316ac88aea9065750f6e9ad8b6d99e38fb
Simplified functions for generating absolute file paths from the base
cache library and modifiers.
===================================================================
M source/blender/blenkernel/BKE_cache_library.h
M source/blender/blenkernel/intern/cache_library.c
M source/blender/editors/io/io_cache_library.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_cache_library.h b/source/blender/blenkernel/BKE_cache_library.h
index 0fdfadb..75f4deb 100644
--- a/source/blender/blenkernel/BKE_cache_library.h
+++ b/source/blender/blenkernel/BKE_cache_library.h
@@ -100,8 +100,9 @@ void BKE_cache_library_group_update(struct Main *bmain, struct CacheLibrary *cac
/* ========================================================================= */
-bool BKE_cache_archive_path_test(const char *path, ID *id, Library *lib);
-void BKE_cache_archive_path(const char *path, ID *id, Library *lib, char *result, int max);
+bool BKE_cache_archive_path_test(const char *path, Library *lib);
+void BKE_cache_library_archive_path(struct CacheLibrary *cachelib, char *result, int max);
+void BKE_cache_modifier_archive_path(struct CacheLibrary *cachelib, struct CacheModifier *md, char *result, int max);
void BKE_cache_library_dag_recalc_tag(struct EvaluationContext *eval_ctx, struct Main *bmain);
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index 872d74e..f1bc60e 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -620,15 +620,13 @@ void BKE_cache_library_update_items(CacheLibrary *cachelib)
/* ========================================================================= */
-static const char *default_filename = "blendcache";
-
BLI_INLINE bool path_is_dirpath(const char *path)
{
/* last char is a slash? */
return *(BLI_last_slash(path) + 1) == '\0';
}
-bool BKE_cache_archive_path_test(const char *path, ID *UNUSED(id), Library *lib)
+bool BKE_cache_archive_path_test(const char *path, Library *lib)
{
if (BLI_path_is_rel(path)) {
if (!(G.relbase_valid || lib))
@@ -639,7 +637,7 @@ bool BKE_cache_archive_path_test(const char *path, ID *UNUSED(id), Library *lib)
}
-void BKE_cache_archive_path(const char *path, ID *id, Library *lib, char *result, int max)
+static void cache_archive_path(const char *path, Library *lib, char *result, int max, const char *default_filename)
{
char abspath[FILE_MAX];
@@ -665,13 +663,23 @@ void BKE_cache_archive_path(const char *path, ID *id, Library *lib, char *result
result[0] = '\0';
}
else if (path_is_dirpath(abspath) || BLI_is_dir(abspath)) {
- BLI_join_dirfile(result, max, abspath, id ? id->name+2 : default_filename);
+ BLI_join_dirfile(result, max, abspath, default_filename);
}
else {
BLI_strncpy(result, abspath, max);
}
}
+void BKE_cache_library_archive_path(struct CacheLibrary *cachelib, char *result, int max)
+{
+ cache_archive_path(cachelib->filepath, cachelib->id.lib, result, max, cachelib->id.name+2);
+}
+
+void BKE_cache_modifier_archive_path(struct CacheLibrary *cachelib, struct CacheModifier *md, char *result, int max)
+{
+ cache_archive_path(md->filepath, cachelib->id.lib, result, max, md->name);
+}
+
static struct PTCReaderArchive *find_active_cache(Scene *scene, CacheLibrary *cachelib)
{
@@ -681,14 +689,14 @@ static struct PTCReaderArchive *find_active_cache(Scene *scene, CacheLibrary *ca
/* look for last valid modifier output */
for (md = cachelib->modifiers.last; md; md = md->prev) {
- BKE_cache_archive_path(md->filepath, (ID *)cachelib, cachelib->id.lib, filename, sizeof(filename));
+ BKE_cache_modifier_archive_path(cachelib, md, filename, sizeof(filename));
archive = PTC_open_reader_archive(scene, filename);
if (archive)
return archive;
}
/* if no modifier has a valid output, try the base cache */
- BKE_cache_archive_path(cachelib->filepath, (ID *)cachelib, cachelib->id.lib, filename, sizeof(filename));
+ BKE_cache_library_archive_path(cachelib, filename, sizeof(filename));
archive = PTC_open_reader_archive(scene, filename);
if (archive)
return archive;
@@ -900,11 +908,11 @@ void BKE_cache_modifier_foreachIDLink(struct CacheLibrary *cachelib, struct Cach
}
/* Warning! Deletes existing files if possible, operator should show confirm dialog! */
-static bool cache_modifier_bake_ensure_file_target(const char *filepath, ID *id)
+static bool cache_modifier_bake_ensure_file_target(CacheLibrary *cachelib, CacheModifier *md)
{
char filename[FILE_MAX];
- BKE_cache_archive_path(filepath, id, id->lib, filename, sizeof(filename));
+ BKE_cache_modifier_archive_path(cachelib, md, filename, sizeof(filename));
if (BLI_exists(filename)) {
if (BLI_is_dir(filename)) {
@@ -962,7 +970,7 @@ void BKE_cache_modifier_bake(const bContext *C, Group *group, CacheLibrary *cach
wmJob *wm_job;
/* make sure we can write */
- cache_modifier_bake_ensure_file_target(md->filepath, &cachelib->id);
+ cache_modifier_bake_ensure_file_target(cachelib, md);
/* XXX annoying hack: needed to prevent data corruption when changing
* scene frame in separate threads
@@ -1036,7 +1044,7 @@ static void hairsim_bake(HairSimCacheModifier *hsmd, CacheLibrary *cachelib, Cac
scene->r.framelen = 1.0f;
- BKE_cache_archive_path(hsmd->modifier.filepath, (ID *)cachelib, cachelib->id.lib, filename, sizeof(filename));
+ BKE_cache_modifier_archive_path(cachelib, &hsmd->modifier, filename, sizeof(filename));
archive = PTC_open_writer_archive(scene, filename);
if (archive) {
diff --git a/source/blender/editors/io/io_cache_library.c b/source/blender/editors/io/io_cache_library.c
index 2e974a6..3cc1c28 100644
--- a/source/blender/editors/io/io_cache_library.c
+++ b/source/blender/editors/io/io_cache_library.c
@@ -306,7 +306,7 @@ static void cache_library_bake_startjob(void *customdata, short *stop, short *do
data->origframelen = scene->r.framelen;
scene->r.framelen = 1.0f;
- BKE_cache_archive_path(data->cachelib->filepath, (ID *)data->cachelib, data->cachelib->id.lib, filename, sizeof(filename));
+ BKE_cache_library_archive_path(data->cachelib, filename, sizeof(filename));
data->archive = PTC_open_writer_archive(scene, filename);
if (data->archive) {
@@ -355,7 +355,7 @@ static bool cache_library_bake_ensure_file_target(CacheLibrary *cachelib)
{
char filename[FILE_MAX];
- BKE_cache_archive_path(cachelib->filepath, (ID *)cachelib, cachelib->id.lib, filename, sizeof(filename));
+ BKE_cache_library_archive_path(cachelib, filename, sizeof(filename));
if (BLI_exists(filename)) {
if (BLI_is_dir(filename)) {
@@ -426,12 +426,12 @@ static int cache_library_bake_invoke(bContext *C, wmOperator *op, const wmEvent
if (!cachelib)
return OPERATOR_CANCELLED;
- if (!BKE_cache_archive_path_test(cachelib->filepath, (ID *)cachelib, cachelib->id.lib)) {
+ if (!BKE_cache_archive_path_test(cachelib->filepath, cachelib->id.lib)) {
BKE_reportf(op->reports, RPT_ERROR, "Cannot create file path for cache library %200s", cachelib->id.name+2);
return OPERATOR_CANCELLED;
}
- BKE_cache_archive_path(cachelib->filepath, (ID *)cachelib, cachelib->id.lib, filename, sizeof(filename));
+ BKE_cache_library_archive_path(cachelib, filename, sizeof(filename));
if (BLI_exists(filename)) {
if (BLI_is_dir(filename)) {
@@ -537,7 +537,7 @@ static int cache_library_archive_info_exec(bContext *C, wmOperator *op)
struct PTCReaderArchive *archive;
char *info;
- BKE_cache_archive_path(cachelib->filepath, (ID *)cachelib, cachelib->id.lib, filename, sizeof(filename));
+ BKE_cache_library_archive_path(cachelib, filename, sizeof(filename));
archive = PTC_open_reader_archive(scene, filename);
if (!archive) {
BKE_reportf(op->reports, RPT_ERROR, "Cannot open cache file at '%s'", cachelib->filepath);
More information about the Bf-blender-cvs
mailing list