[Bf-blender-cvs] [4774c1f] alembic_pointcache: Use the path utility functions for generating the filename inside the new point cache, instead of using the blenkernel code.

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


Commit: 4774c1f0761e10e9c9566acd71a8c59ab9c13f57
Author: Lukas Tönne
Date:   Fri Oct 18 10:06:26 2013 +0200
Branches: alembic_pointcache
https://developer.blender.org/rB4774c1f0761e10e9c9566acd71a8c59ab9c13f57

Use the path utility functions for generating the filename inside the new point cache, instead of using the blenkernel code.

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

M	source/blender/blenkernel/intern/pointcache.c
M	source/blender/pointcache/CMakeLists.txt
M	source/blender/pointcache/PTC_api.cpp
M	source/blender/pointcache/PTC_api.h
M	source/blender/pointcache/util/util_path.cpp
M	source/blender/pointcache/util/util_path.h

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

diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index a786470..188684c 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -476,22 +476,16 @@ static void ptcache_particle_extra_read(void *psys_v, PTCacheMem *pm, float UNUS
 	}
 }
 
-static int ptcache_archive_filename(PointCache *cache, Object *ob, char *filename, bool do_path, bool do_ext);
-
 static struct PTCWriter *ptcache_particle_writer_create(Scene *scene, Object *ob, void *psys_v)
 {
 	ParticleSystem *psys = psys_v;
-	char filename[FILE_MAX * 2];
-	ptcache_archive_filename(psys->pointcache, ob, filename, true, true);
-	return PTC_writer_particles(filename, scene, ob, psys);
+	return PTC_writer_particles(scene, ob, psys);
 }
 
 static struct PTCReader *ptcache_particle_reader_create(Scene *scene, Object *ob, void *psys_v)
 {
 	ParticleSystem *psys = psys_v;
-	char filename[FILE_MAX * 2];
-	ptcache_archive_filename(psys->pointcache, ob, filename, true, true);
-	return PTC_reader_particles(filename, scene, ob, psys);
+	return PTC_reader_particles(scene, ob, psys);
 }
 
 /* Cloth functions */
@@ -1553,54 +1547,6 @@ 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)
 {
diff --git a/source/blender/pointcache/CMakeLists.txt b/source/blender/pointcache/CMakeLists.txt
index 4070cbc..c78aebf 100644
--- a/source/blender/pointcache/CMakeLists.txt
+++ b/source/blender/pointcache/CMakeLists.txt
@@ -24,6 +24,7 @@
 set(INC
 	.
 	intern
+	util
 	../blenkernel
 	../blenlib
 	../makesdna
diff --git a/source/blender/pointcache/PTC_api.cpp b/source/blender/pointcache/PTC_api.cpp
index 1ac14f5..a49fec4 100644
--- a/source/blender/pointcache/PTC_api.cpp
+++ b/source/blender/pointcache/PTC_api.cpp
@@ -24,8 +24,15 @@
 #include "writer.h"
 #include "particles.h"
 
+#include "util_path.h"
+
+extern "C" {
+#include "DNA_object_force.h"
 #include "DNA_object_types.h"
 #include "DNA_particle_types.h"
+}
+
+using namespace PTC;
 
 void PTC_writer_free(PTCWriter *_writer)
 {
@@ -39,6 +46,11 @@ void PTC_write_sample(struct PTCWriter *_writer)
 	writer->write_sample();
 }
 
+void PTC_bake(struct PTCWriter *writer, int start_frame, int end_frame)
+{
+	
+}
+
 
 void PTC_reader_free(PTCReader *_reader)
 {
@@ -54,14 +66,30 @@ void PTC_read_sample(struct PTCReader *_reader)
 
 
 /* Particles */
-PTCWriter *PTC_writer_particles(const char *filename, Scene *scene, Object *ob, ParticleSystem *psys)
+PTCWriter *PTC_writer_particles(Scene *scene, Object *ob, ParticleSystem *psys)
 {
+	PointCache *cache = psys->pointcache;
+	if (!cache)
+		return NULL;
+	std::string filename = ptc_archive_path(cache->name, cache->index, cache->path, &ob->id,
+	                                        true, true,
+	                                        cache->flag & PTCACHE_EXTERNAL,
+	                                        cache->flag & PTCACHE_IGNORE_LIBPATH);
+	
 	PTC::ParticlesWriter *writer = new PTC::ParticlesWriter(filename, ob, psys);
 	return (PTCWriter *)writer;
 }
 
-PTCReader *PTC_reader_particles(const char *filename, Scene *scene, Object *ob, ParticleSystem *psys)
+PTCReader *PTC_reader_particles(Scene *scene, Object *ob, ParticleSystem *psys)
 {
+	PointCache *cache = psys->pointcache;
+	if (!cache)
+		return NULL;
+	std::string filename = ptc_archive_path(cache->name, cache->index, cache->path, &ob->id,
+	                                        true, true,
+	                                        cache->flag & PTCACHE_EXTERNAL,
+	                                        cache->flag & PTCACHE_IGNORE_LIBPATH);
+
 	PTC::ParticlesReader *reader = new PTC::ParticlesReader(filename, ob, psys);
 	return (PTCReader *)reader;
 }
diff --git a/source/blender/pointcache/PTC_api.h b/source/blender/pointcache/PTC_api.h
index 4b448cb..0fb1ba6 100644
--- a/source/blender/pointcache/PTC_api.h
+++ b/source/blender/pointcache/PTC_api.h
@@ -35,14 +35,15 @@ struct PTCReader;
 
 void PTC_writer_free(struct PTCWriter *writer);
 void PTC_write_sample(struct PTCWriter *writer);
+void PTC_bake(struct PTCWriter *writer, int start_frame, int end_frame);
 
 void PTC_reader_free(struct PTCReader *reader);
 void PTC_read_sample(struct PTCReader *reader);
 
 
 /* Particles */
-struct PTCWriter *PTC_writer_particles(const char *filename, struct Scene *scene, struct Object *ob, struct ParticleSystem *psys);
-struct PTCReader *PTC_reader_particles(const char *filename, struct Scene *scene, struct Object *ob, struct ParticleSystem *psys);
+struct PTCWriter *PTC_writer_particles(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys);
+struct PTCReader *PTC_reader_particles(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys);
 
 #ifdef __cplusplus
 } /* extern C */
diff --git a/source/blender/pointcache/util/util_path.cpp b/source/blender/pointcache/util/util_path.cpp
index e41e6b8..6e29468 100644
--- a/source/blender/pointcache/util/util_path.cpp
+++ b/source/blender/pointcache/util/util_path.cpp
@@ -18,6 +18,8 @@
 
 #include <string.h> /* XXX needed for missing type declarations in BLI ... */
 
+#include "util_path.h"
+
 extern "C" {
 #include "BLI_path_util.h"
 #include "BLI_string.h"
@@ -30,10 +32,7 @@ extern "C" {
 #include "BKE_main.h"
 }
 
-#include "util_path.h"
-
 namespace PTC {
-namespace Util {
 
 /* XXX do we want to use BLI C string functions here? just copied from BKE_pointcache for now */
 
@@ -110,13 +109,12 @@ static int ptc_filename(char *filename, const char *name, int index, const char
 	return len;
 }
 
-std::string archive_path(const std::string &name, int index, const std::string &path, ID *id,
-                         bool do_path, bool do_ext, bool is_external, bool ignore_libpath)
+std::string ptc_archive_path(const std::string &name, int index, const std::string &path, ID *id,
+                             bool do_path, bool do_ext, bool is_external, bool ignore_libpath)
 {
 	char filename[FILE_MAX];
 	ptc_filename(filename, name.c_str(), index, path.c_str(), id, do_path, do_ext, is_external, ignore_libpath);
 	return std::string(filename);
 }
 
-} /* namespace Util */
 } /* namespace PTC */
diff --git a/source/blender/pointcache/util/util_path.h b/source/blender/pointcache/util/util_path.h
index 29f753f..63c3c2d 100644
--- a/source/blender/pointcache/util/util_path.h
+++ b/source/blender/pointcache/util/util_path.h
@@ -24,16 +24,14 @@
 struct ID;
 
 namespace PTC {
-namespace Util {
 
 /* XXX make these configurable, just copied from BKE_pointcache for now */
 #define PTC_EXTENSION ".abc"
 #define PTC_DIRECTORY "blendcache_"
 
-std::string archive_path(const std::string &name, int index, const std::string &path, ID *id,
-                         bool do_path, bool do_ext, bool is_external, bool ignore_libpath);
+std::string ptc_archive_path(const std::string &name, int index, const std::string &path, ID *id,
+                             bool do_path, bool do_ext, bool is_external, bool ignore_libpath);
 
-} /* namespace Util */
 } /* namespace PTC */
 
 #endif  /* PTC_UTIL_PATH_H */




More information about the Bf-blender-cvs mailing list