[Bf-blender-cvs] [0305ebc] alembic_basic_io: De-duplicate cache file loading logic.

Kévin Dietrich noreply at git.blender.org
Thu Jun 23 21:18:31 CEST 2016


Commit: 0305ebcee39bfd37a8a6a25471b9220d6f211f73
Author: Kévin Dietrich
Date:   Thu Jun 23 21:17:01 2016 +0200
Branches: alembic_basic_io
https://developer.blender.org/rB0305ebcee39bfd37a8a6a25471b9220d6f211f73

De-duplicate cache file loading logic.

===================================================================

M	source/blender/blenkernel/BKE_cachefile.h
M	source/blender/blenkernel/intern/cachefile.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/makesrna/intern/rna_cachefile.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_cachefile.h b/source/blender/blenkernel/BKE_cachefile.h
index 1f201ef..b101bb6 100644
--- a/source/blender/blenkernel/BKE_cachefile.h
+++ b/source/blender/blenkernel/BKE_cachefile.h
@@ -41,6 +41,8 @@ void *BKE_cachefile_add(struct Main *bmain, const char *name);
 
 void BKE_cachefile_free(struct CacheFile *cache_file);
 
+void BKE_cachefile_load(struct CacheFile *cache_file);
+
 void BKE_cachefiles_open_next_file(struct Main *bmain, float ctime);
 
 bool BKE_cachefile_filepath_get(struct CacheFile *cache_file, float frame,
diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c
index 009528e..35a98b8 100644
--- a/source/blender/blenkernel/intern/cachefile.c
+++ b/source/blender/blenkernel/intern/cachefile.c
@@ -67,6 +67,25 @@ void BKE_cachefile_free(CacheFile *cache_file)
 #endif
 }
 
+void BKE_cachefile_load(CacheFile *cache_file)
+{
+	char filename[FILE_MAX];
+	BLI_strncpy(filename, cache_file->filepath, FILE_MAX);
+
+	/* Ensure absolute paths. */
+	if (BLI_path_is_rel(filename)) {
+		BLI_path_abs(filename, G.main->name);
+	}
+
+#ifdef WITH_ALEMBIC
+	if (cache_file->handle) {
+		ABC_free_handle(cache_file->handle);
+	}
+
+	cache_file->handle = ABC_create_handle(filename);
+#endif
+}
+
 void BKE_cachefiles_open_next_file(Main *bmain, float ctime)
 {
 	CacheFile *cache_file;
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 423bd45..6b09b3a 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -116,6 +116,7 @@
 #include "BKE_armature.h"
 #include "BKE_blender_version.h"
 #include "BKE_brush.h"
+#include "BKE_cachefile.h"
 #include "BKE_cloth.h"
 #include "BKE_constraint.h"
 #include "BKE_context.h"
@@ -159,10 +160,6 @@
 
 #include "readfile.h"
 
-#ifdef WITH_ALEMBIC
-#  include "ABC_alembic.h"
-#endif
-
 #include <errno.h>
 
 /**
@@ -2284,12 +2281,8 @@ static void lib_link_cachefiles(FileData *fd, Main *main)
 
 static void direct_link_cachefile(FileData *fd, CacheFile *cache_file)
 {
-#ifdef WITH_ALEMBIC
-	cache_file->handle = ABC_create_handle(cache_file->filepath);
-#else
-	UNUSED_VARS(cache_file);
-#endif
-
+	cache_file->handle = NULL;
+	BKE_cachefile_load(cache_file);
 	UNUSED_VARS(fd);
 }
 
diff --git a/source/blender/makesrna/intern/rna_cachefile.c b/source/blender/makesrna/intern/rna_cachefile.c
index ac9bf8b..46b9f1e 100644
--- a/source/blender/makesrna/intern/rna_cachefile.c
+++ b/source/blender/makesrna/intern/rna_cachefile.c
@@ -34,20 +34,17 @@
 
 #ifdef RNA_RUNTIME
 
+#include "BKE_cachefile.h"
+
 #ifdef WITH_ALEMBIC
 #  include "../../../alembic/ABC_alembic.h"
 #endif
 
 static void rna_CacheFile_update_handle(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
-#ifdef WITH_ALEMBIC
 	CacheFile *cache_file = (CacheFile *)ptr->data;
 
-	ABC_free_handle(cache_file->handle);
-	cache_file->handle = ABC_create_handle(cache_file->filepath);
-#else
-	UNUSED_VARS(ptr);
-#endif
+	BKE_cachefile_load(cache_file);
 
 	UNUSED_VARS(bmain, scene);
 }




More information about the Bf-blender-cvs mailing list