[Bf-blender-cvs] [f956ff1] alembic_pointcache: Create an OArchive internally for writing out point cache.

Lukas Tönne noreply at git.blender.org
Thu Oct 16 16:52:38 CEST 2014


Commit: f956ff1fab4ba52401c44082cefc81aaf61d3c15
Author: Lukas Tönne
Date:   Mon Oct 7 13:24:55 2013 +0200
Branches: alembic_pointcache
https://developer.blender.org/rBf956ff1fab4ba52401c44082cefc81aaf61d3c15

Create an OArchive internally for writing out point cache.

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

M	source/blender/blenkernel/BKE_pointcache.h
M	source/blender/blenkernel/intern/pointcache.c
M	source/blender/pointcache/CMakeLists.txt
M	source/blender/pointcache/PTC_api.h

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

diff --git a/source/blender/blenkernel/BKE_pointcache.h b/source/blender/blenkernel/BKE_pointcache.h
index d5131fc..4ef13eb 100644
--- a/source/blender/blenkernel/BKE_pointcache.h
+++ b/source/blender/blenkernel/BKE_pointcache.h
@@ -53,6 +53,7 @@
 
 /* Add the blendfile name after blendcache_ */
 #define PTCACHE_EXT ".bphys"
+#define PTCACHE_ARCHIVE_EXT ".abc"
 #define PTCACHE_PATH "blendcache_"
 
 /* File open options, for BKE_ptcache_file_open */
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index 402355b..f8a1a59 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -1532,6 +1532,54 @@ static int ptcache_filename(PTCacheID *pid, char *filename, int cfra, short do_p
 	return len; /* make sure the above string is always 16 chars */
 }
 
+static int ptcache_archive_filename(PointCache *cache, Object *ob, char *filename, bool do_path, bool do_ext)
+{
+	bool is_external = (cache->flag & PTCACHE_EXTERNAL);
+	int len=0;
+	char *idname;
+	char *newname;
+	filename[0] = '\0';
+	newname = filename;
+	
+	if (!G.relbase_valid && !is_external) return 0; /* save blend file before using disk pointcache */
+	
+	/* start with temp dir */
+	if (do_path) {
+		len = ptcache_path(cache, ob, filename);
+		newname += len;
+	}
+	if (cache->name[0] == '\0' && !is_external) {
+		idname = (ob->id.name + 2);
+		/* convert chars to hex so they are always a valid filename */
+		while ('\0' != *idname) {
+			BLI_snprintf(newname, MAX_PTCACHE_FILE, "%02X", (char)(*idname++));
+			newname+=2;
+			len += 2;
+		}
+	}
+	else {
+		int temp = (int)strlen(cache->name); 
+		strcpy(newname, cache->name); 
+		newname+=temp;
+		len += temp;
+	}
+	
+	if (do_ext) {
+		if (cache->index < 0)
+			cache->index =  BKE_object_insert_ptcache(ob);
+
+		if (cache->index < 0 || !is_external) {
+			BLI_snprintf(newname, MAX_PTCACHE_FILE, PTCACHE_ARCHIVE_EXT); /* always 6 chars */
+		}
+		else {
+			BLI_snprintf(newname, MAX_PTCACHE_FILE, "_%02u"PTCACHE_ARCHIVE_EXT, cache->index); /* always 6 chars */
+		}
+		len += 16;
+	}
+	
+	return len; /* make sure the above string is always 16 chars */
+}
+
 /* youll need to close yourself after! */
 static PTCacheFile *ptcache_file_open(PTCacheID *pid, int mode, int cfra)
 {
@@ -3486,11 +3534,20 @@ void BKE_ptcache_toggle_disk_cache(PTCacheID *pid)
 	if (cache->flag & PTCACHE_DISK_CACHE) {
 		BKE_ptcache_mem_to_disk(pid);
 		
-		if (!cache->archive)
-			cache = PTC_archive_create()
+		if (!cache->archive) {
+			char filename[FILE_MAX * 2];
+			ptcache_archive_filename(cache, pid->ob, filename, true, true);
+			cache->archive = PTC_archive_create(filename);
+		}
 	}
-	else
+	else {
 		BKE_ptcache_disk_to_mem(pid);
+		
+		if (cache->archive) {
+			PTC_archive_free(cache->archive);
+			cache->archive = NULL;
+		}
+	}
 
 	cache->flag ^= PTCACHE_DISK_CACHE;
 	BKE_ptcache_id_clear(pid, PTCACHE_CLEAR_ALL, 0);
diff --git a/source/blender/pointcache/CMakeLists.txt b/source/blender/pointcache/CMakeLists.txt
index a9f4ac1..78f88dc 100644
--- a/source/blender/pointcache/CMakeLists.txt
+++ b/source/blender/pointcache/CMakeLists.txt
@@ -35,6 +35,7 @@ set(SRC
 	test.cpp
 
 	PTC_api.h
+	PTC_api.cpp
 	PTC_schema.h
 
 	PTC_archive.h
diff --git a/source/blender/pointcache/PTC_api.h b/source/blender/pointcache/PTC_api.h
index 19d3c1f..612da40 100644
--- a/source/blender/pointcache/PTC_api.h
+++ b/source/blender/pointcache/PTC_api.h
@@ -25,8 +25,15 @@ extern "C" {
 
 void test_archive();
 
-void *PTC_archive_create(const char *filename);
-void PTC_archive_free(void *archive);
+
+struct PTCArchive;
+struct PTCObject;
+
+struct PTCArchive *PTC_archive_create(const char *filename);
+void PTC_archive_free(struct PTCArchive *archive);
+
+
+//PTCObject *PTC_object_particles()
 
 #ifdef __cplusplus
 } /* extern C */




More information about the Bf-blender-cvs mailing list