[Bf-blender-cvs] [fe04d8b] alembic_pointcache: Use the cache library to construct cache file paths instead of the relative point cache paths.
Lukas Tönne
noreply at git.blender.org
Thu Feb 19 17:05:28 CET 2015
Commit: fe04d8b17694d10b0d313b4a56a3a0cc93691bd5
Author: Lukas Tönne
Date: Thu Feb 19 17:02:28 2015 +0100
Branches: alembic_pointcache
https://developer.blender.org/rBfe04d8b17694d10b0d313b4a56a3a0cc93691bd5
Use the cache library to construct cache file paths instead of the
relative point cache paths.
===================================================================
M source/blender/pointcache/alembic/abc_reader.cpp
M source/blender/pointcache/alembic/abc_writer.cpp
M source/blender/pointcache/util/util_path.cpp
M source/blender/pointcache/util/util_path.h
===================================================================
diff --git a/source/blender/pointcache/alembic/abc_reader.cpp b/source/blender/pointcache/alembic/abc_reader.cpp
index d445196..c9f88fa 100644
--- a/source/blender/pointcache/alembic/abc_reader.cpp
+++ b/source/blender/pointcache/alembic/abc_reader.cpp
@@ -27,6 +27,7 @@
extern "C" {
#include "BLI_fileops.h"
+#include "DNA_pointcache_types.h"
#include "DNA_scene_types.h"
}
@@ -38,10 +39,12 @@ AbcReaderArchive::AbcReaderArchive(Scene *scene, ID *id, PointCache *cache, Erro
FrameMapper(scene),
m_error_handler(error_handler)
{
- std::string filename = ptc_archive_path(cache, id);
- PTC_SAFE_CALL_BEGIN
- archive = IArchive(AbcCoreHDF5::ReadArchive(), filename, Abc::ErrorHandler::kThrowPolicy);
- PTC_SAFE_CALL_END_HANDLER(m_error_handler)
+ std::string filename;
+ if (ptc_archive_path(cache->cachelib, filename, id->lib)) {
+ PTC_SAFE_CALL_BEGIN
+ archive = IArchive(AbcCoreHDF5::ReadArchive(), filename, Abc::ErrorHandler::kThrowPolicy);
+ PTC_SAFE_CALL_END_HANDLER(m_error_handler)
+ }
}
AbcReaderArchive::~AbcReaderArchive()
diff --git a/source/blender/pointcache/alembic/abc_writer.cpp b/source/blender/pointcache/alembic/abc_writer.cpp
index 8ab9ac1..8b64a30 100644
--- a/source/blender/pointcache/alembic/abc_writer.cpp
+++ b/source/blender/pointcache/alembic/abc_writer.cpp
@@ -25,6 +25,7 @@ extern "C" {
#include "BLI_fileops.h"
#include "BLI_path_util.h"
+#include "DNA_pointcache_types.h"
#include "DNA_scene_types.h"
}
@@ -44,18 +45,20 @@ AbcWriterArchive::AbcWriterArchive(Scene *scene, ID *id, PointCache *cache, Erro
FrameMapper(scene),
m_error_handler(error_handler)
{
- std::string filename = ptc_archive_path(cache, id);
- ensure_directory(filename.c_str());
-
- PTC_SAFE_CALL_BEGIN
-
- archive = OArchive(AbcCoreHDF5::WriteArchive(), filename, Abc::ErrorHandler::kThrowPolicy);
-
- chrono_t cycle_time = seconds_per_frame();
- chrono_t start_time = 0.0f;
- m_frame_sampling = archive.addTimeSampling(TimeSampling(cycle_time, start_time));
-
- PTC_SAFE_CALL_END_HANDLER(m_error_handler)
+ std::string filename;
+ if (ptc_archive_path(cache->cachelib, filename, id->lib)) {
+ ensure_directory(filename.c_str());
+
+ PTC_SAFE_CALL_BEGIN
+
+ archive = OArchive(AbcCoreHDF5::WriteArchive(), filename, Abc::ErrorHandler::kThrowPolicy);
+
+ chrono_t cycle_time = seconds_per_frame();
+ chrono_t start_time = 0.0f;
+ m_frame_sampling = archive.addTimeSampling(TimeSampling(cycle_time, start_time));
+
+ PTC_SAFE_CALL_END_HANDLER(m_error_handler)
+ }
}
AbcWriterArchive::~AbcWriterArchive()
diff --git a/source/blender/pointcache/util/util_path.cpp b/source/blender/pointcache/util/util_path.cpp
index 4d543fb..b82a467 100644
--- a/source/blender/pointcache/util/util_path.cpp
+++ b/source/blender/pointcache/util/util_path.cpp
@@ -21,8 +21,10 @@
#include "util_path.h"
extern "C" {
+#include "BLI_fileops.h"
#include "BLI_path_util.h"
#include "BLI_string.h"
+#include "BLI_utildefines.h"
#include "DNA_ID.h"
#include "DNA_pointcache_types.h"
@@ -34,86 +36,65 @@ extern "C" {
namespace PTC {
-/* XXX do we want to use BLI C string functions here? just copied from BKE_pointcache for now */
+BLI_INLINE bool path_is_rel(const std::string &path)
+{
+ return BLI_path_is_rel(path.c_str());
+}
-static int ptc_path(char *filename, const char *path, ID *id, bool is_external, bool ignore_libpath)
+BLI_INLINE bool is_dir(const std::string &path)
{
- Library *lib = id ? id->lib : NULL;
- const char *blendfilename= (lib && !ignore_libpath) ? lib->filepath: G.main->name;
+ return BLI_is_dir(path.c_str());
+}
- if (path && is_external) {
- strcpy(filename, path);
+BLI_INLINE bool path_is_dirpath(const std::string &path)
+{
+ /* last char is a slash? */
+ return *(BLI_last_slash(path.c_str()) + 1) == '\0';
+}
- if (BLI_path_is_rel(filename)) {
- BLI_path_abs(filename, blendfilename);
- }
- }
- else if (G.relbase_valid || lib) {
- char file[FILE_MAXFILE]; /* we don't want the dir, only the file */
+BLI_INLINE std::string path_join_dirfile(const std::string &dir, const std::string &file)
+{
+ char path[FILE_MAX];
+ BLI_join_dirfile(path, sizeof(path), dir.c_str(), file.c_str());
+ return std::string(path);
+}
- BLI_split_file_part(blendfilename, file, sizeof(file));
- BLI_replace_extension(file, sizeof(file), ""); /* remove extension */
- BLI_snprintf(filename, FILE_MAX, "//" PTC_DIRECTORY "%s", file); /* add blend file name to pointcache dir */
- BLI_path_abs(filename, blendfilename);
- }
- else {
- /* use the temp path. this is weak but better then not using point cache at all */
- /* temporary directory is assumed to exist and ALWAYS has a trailing slash */
- BLI_snprintf(filename, FILE_MAX, "%s" PTC_DIRECTORY, BKE_tempdir_session());
- }
-
- return BLI_add_slash(filename); /* new strlen() */
+BLI_INLINE std::string path_abs(const std::string &path, const std::string &basepath)
+{
+ char npath[FILE_MAX];
+ BLI_strncpy(npath, path.c_str(), sizeof(npath));
+ BLI_path_abs(npath, basepath.c_str());
+ return std::string(npath);
}
-static int ptc_filename(char *filename, const char *name, int index, const char *path, ID *id,
- bool do_path, bool do_ext, bool is_external, bool ignore_libpath)
+bool ptc_archive_path(CacheLibrary *cachelib, std::string &filepath, Library *lib)
{
- char *newname;
- int len = 0;
- filename[0] = '\0';
- newname = filename;
+ filepath = "";
- if (!G.relbase_valid && !is_external)
- return 0; /* save blend file before using disk pointcache */
+ if (!cachelib)
+ return false;
- /* start with temp dir */
- if (do_path) {
- len = ptc_path(filename, path, id, is_external, ignore_libpath);
- newname += len;
- }
- if (name[0] == '\0' && !is_external) {
- const char *idname = (id->name + 2);
- /* convert chars to hex so they are always a valid filename */
- while ('\0' != *idname) {
- BLI_snprintf(newname, FILE_MAX, "%02X", (char)(*idname++));
- newname += 2;
- len += 2;
+ std::string abspath;
+ if (path_is_rel(cachelib->filepath)) {
+ if (G.relbase_valid || lib) {
+ std::string relbase = lib ? lib->filepath: G.main->name;
+ abspath = path_abs(cachelib->filepath, relbase);
}
+ else
+ return false;
}
else {
- int namelen = (int)strlen(name);
- strcpy(newname, name);
- newname += namelen;
- len += namelen;
+ abspath = cachelib->filepath;
}
- if (do_ext) {
- if (index < 0 || !is_external) {
- len += BLI_snprintf(newname, FILE_MAX, PTC_EXTENSION);
- }
- else {
- len += BLI_snprintf(newname, FILE_MAX, "_%02u" PTC_EXTENSION, index);
- }
+ if (path_is_dirpath(abspath) || is_dir(abspath)) {
+ filepath = path_join_dirfile(abspath, cachelib->id.name+2);
+ }
+ else {
+ filepath = abspath;
}
- return len;
-}
-
-std::string ptc_archive_path(PointCache *cache, ID *id)
-{
- char filename[FILE_MAX];
- ptc_filename(filename, cache->name, cache->index, cache->path, id, true, true, cache->flag & PTC_EXTERNAL, cache->flag & PTC_IGNORE_LIBPATH);
- return std::string(filename);
+ return true;
}
} /* namespace PTC */
diff --git a/source/blender/pointcache/util/util_path.h b/source/blender/pointcache/util/util_path.h
index 5cff2f7..210a371 100644
--- a/source/blender/pointcache/util/util_path.h
+++ b/source/blender/pointcache/util/util_path.h
@@ -22,15 +22,12 @@
#include <string>
struct ID;
-struct PointCache;
+struct CacheLibrary;
+struct Library;
namespace PTC {
-/* XXX make these configurable, just copied from BKE_pointcache for now */
-#define PTC_EXTENSION ".abc"
-#define PTC_DIRECTORY "blendcache_"
-
-std::string ptc_archive_path(PointCache *cache, ID *id);
+bool ptc_archive_path(CacheLibrary *cachelib, std::string &filepath, Library *lib);
} /* namespace PTC */
More information about the Bf-blender-cvs
mailing list