[Bf-blender-cvs] [2169e58] alembic_basic_io: Store a pointer to an open Alembic archive in the CacheFile data-block.
Kévin Dietrich
noreply at git.blender.org
Tue Jun 21 14:11:05 CEST 2016
Commit: 2169e583cf4885319db10445fe1a1b61dd885ab2
Author: Kévin Dietrich
Date: Tue Jun 21 13:30:33 2016 +0200
Branches: alembic_basic_io
https://developer.blender.org/rB2169e583cf4885319db10445fe1a1b61dd885ab2
Store a pointer to an open Alembic archive in the CacheFile data-block.
This avoids re-opening the same file over and over again for every
modifier/constraint that references it and it provides a unique place to
open archives for new frames when using file sequences.
===================================================================
M source/blender/alembic/ABC_alembic.h
M source/blender/alembic/intern/alembic_capi.cc
M source/blender/blenkernel/BKE_cachefile.h
M source/blender/blenkernel/intern/cachefile.c
M source/blender/blenkernel/intern/constraint.c
M source/blender/blenkernel/intern/library.c
M source/blender/blenkernel/intern/scene.c
M source/blender/blenloader/CMakeLists.txt
M source/blender/blenloader/intern/readfile.c
M source/blender/makesdna/DNA_cachefile_types.h
M source/blender/makesrna/intern/rna_cachefile.c
M source/blender/modifiers/intern/MOD_meshsequencecache.c
===================================================================
diff --git a/source/blender/alembic/ABC_alembic.h b/source/blender/alembic/ABC_alembic.h
index 1d17b79..9baa2d5 100644
--- a/source/blender/alembic/ABC_alembic.h
+++ b/source/blender/alembic/ABC_alembic.h
@@ -40,6 +40,8 @@ enum {
#define BL_ABC_NO_ERR 0
#define BL_ABC_UNKNOWN_ERROR 1
+typedef struct AbcArchiveHandle AbcArchiveHandle;
+
int ABC_get_version(void);
int ABC_export(struct Scene *scene, struct bContext *C, const char *filepath,
@@ -61,14 +63,15 @@ void ABC_import(struct bContext *C, const char *filepath, float scale, bool is_s
void ABC_get_vertex_cache(const char *filepath, float time, void *verts, int max_verts, const char *object_path, int is_mvert);
-int ABC_check_subobject_valid(const char *filepath, const char *object_path);
+int ABC_check_subobject_valid(const char *filename, const char *object_path);
+
+AbcArchiveHandle *ABC_create_handle(const char *filename);
-void ABC_get_transform(struct Object *ob, const char *filepath, const char *object_path, float r_mat[4][4], float time, float scale);
+void ABC_free_handle(AbcArchiveHandle *handle);
-struct DerivedMesh *ABC_read_mesh(struct DerivedMesh *dm, const char *filepath, const char *object_path, const float time);
+void ABC_get_transform(AbcArchiveHandle *handle, struct Object *ob, const char *object_path, float r_mat[4][4], float time, float scale);
-void ABC_read_vertex_cache(const char *filepath, const char *object_path, const float time,
- float (*vertexCos)[3], int max_verts);
+struct DerivedMesh *ABC_read_mesh(AbcArchiveHandle *handle, struct DerivedMesh *dm, const char *object_path, const float time);
#ifdef __cplusplus
}
diff --git a/source/blender/alembic/intern/alembic_capi.cc b/source/blender/alembic/intern/alembic_capi.cc
index 95492ab..c49dc58 100644
--- a/source/blender/alembic/intern/alembic_capi.cc
+++ b/source/blender/alembic/intern/alembic_capi.cc
@@ -100,36 +100,60 @@ using Alembic::AbcGeom::IN3fGeomParam;
using Alembic::AbcMaterial::IMaterial;
-int ABC_get_version()
+struct AbcArchiveHandle {
+ int unused;
+};
+
+ABC_INLINE IArchive *archive_from_handle(AbcArchiveHandle *handle)
{
- return ALEMBIC_LIBRARY_VERSION;
+ return reinterpret_cast<IArchive *>(handle);
+}
+
+ABC_INLINE AbcArchiveHandle *handle_from_archive(IArchive *archive)
+{
+ return reinterpret_cast<AbcArchiveHandle *>(archive);
}
-static IArchive open_archive(const std::string &filename)
+static IArchive *open_archive(const std::string &filename)
{
Alembic::AbcCoreAbstract::ReadArraySampleCachePtr cache_ptr;
- IArchive archive;
+ IArchive *archive;
try {
- archive = IArchive(Alembic::AbcCoreHDF5::ReadArchive(),
- filename.c_str(), ErrorHandler::kThrowPolicy,
- cache_ptr);
+ archive = new IArchive(Alembic::AbcCoreHDF5::ReadArchive(),
+ filename.c_str(), ErrorHandler::kThrowPolicy,
+ cache_ptr);
}
catch (const Exception &) {
try {
- archive = IArchive(Alembic::AbcCoreOgawa::ReadArchive(),
- filename.c_str(), ErrorHandler::kThrowPolicy,
- cache_ptr);
+ archive = new IArchive(Alembic::AbcCoreOgawa::ReadArchive(),
+ filename.c_str(), ErrorHandler::kThrowPolicy,
+ cache_ptr);
}
catch (const Exception &e) {
std::cerr << e.what() << '\n';
- return IArchive();
+ return NULL;
}
}
return archive;
}
+AbcArchiveHandle *ABC_create_handle(const char *filename)
+{
+ return handle_from_archive(open_archive(filename));
+}
+
+void ABC_free_handle(AbcArchiveHandle *handle)
+{
+ delete archive_from_handle(handle);
+}
+
+int ABC_get_version()
+{
+ return ALEMBIC_LIBRARY_VERSION;
+}
+
static size_t update_points(std::pair<IPolyMeshSchema, IObject> schema,
const ISampleSelector &sample_sel,
MVert *verts, size_t vtx_start, int max_verts = -1,
@@ -198,13 +222,13 @@ static void find_iobject(const IObject &object, IObject &ret,
void ABC_get_vertex_cache(const char *filepath, float time, void *verts,
int max_verts, const char *object_path, int is_mverts)
{
- IArchive archive = open_archive(filepath);
+ IArchive *archive = open_archive(filepath);
- if (!archive || !archive.valid()) {
+ if (!archive || !archive->valid()) {
return;
}
- IObject top = archive.getTop();
+ IObject top = archive->getTop();
if (!top.valid()) {
return;
@@ -230,22 +254,24 @@ void ABC_get_vertex_cache(const char *filepath, float time, void *verts,
update_points(std::pair<IPolyMeshSchema, IObject>(schema, iobject),
sample_sel, NULL, 0, max_verts, vcos);
}
+
+ /* TODO. */
+ delete archive;
}
-int ABC_check_subobject_valid(const char *filepath, const char *object_path)
+int ABC_check_subobject_valid(const char *filename, const char *object_path)
{
- if ((filepath[0] == '\0') || (object_path[0] == '\0')) {
- return 0;
- }
-
- IArchive archive = open_archive(filepath);
+ IArchive *archive = open_archive(filename);
- if (!archive.valid()) {
- return 0;
+ if (!archive || !archive->valid()) {
+ return false;
}
IObject ob;
- find_iobject(archive.getTop(), ob, object_path);
+ find_iobject(archive->getTop(), ob, object_path);
+
+ /* TODO. */
+ delete archive;
return (ob.valid());
}
@@ -500,9 +526,9 @@ static void import_startjob(void *user_data, short *stop, short *do_update, floa
data->do_update = do_update;
data->progress = progress;
- IArchive archive = open_archive(data->filename);
+ IArchive *archive = open_archive(data->filename);
- if (!archive.valid()) {
+ if (!archive || !archive->valid()) {
return;
}
@@ -510,6 +536,7 @@ static void import_startjob(void *user_data, short *stop, short *do_update, floa
cache_file->is_sequence = data->settings.is_sequence;
cache_file->scale = data->settings.scale;
+ cache_file->handle = handle_from_archive(archive);
BLI_strncpy(cache_file->filepath, data->filename, 1024);
data->settings.cache_file = cache_file;
@@ -521,7 +548,7 @@ static void import_startjob(void *user_data, short *stop, short *do_update, floa
/* Parse Alembic Archive. */
- visit_object(archive.getTop(), data->readers, data->parent_map, data->settings);
+ visit_object(archive->getTop(), data->readers, data->parent_map, data->settings);
if (G.is_break) {
return;
@@ -670,16 +697,16 @@ void ABC_import(bContext *C, const char *filepath, float scale, bool is_sequence
/* ******************************* */
-void ABC_get_transform(Object *ob, const char *filepath, const char *object_path, float r_mat[4][4], float time, float scale)
+void ABC_get_transform(AbcArchiveHandle *handle, Object *ob, const char *object_path, float r_mat[4][4], float time, float scale)
{
- IArchive archive = open_archive(filepath);
+ IArchive *archive = archive_from_handle(handle);
- if (!archive.valid()) {
+ if (!archive || !archive->valid()) {
return;
}
IObject tmp;
- find_iobject(archive.getTop(), tmp, object_path);
+ find_iobject(archive->getTop(), tmp, object_path);
IXform ixform;
@@ -865,16 +892,16 @@ static DerivedMesh *read_curves_sample(DerivedMesh *dm, const IObject &iobject,
return dm;
}
-DerivedMesh *ABC_read_mesh(DerivedMesh *dm, const char *filepath, const char *object_path, const float time)
+DerivedMesh *ABC_read_mesh(AbcArchiveHandle *handle, DerivedMesh *dm, const char *object_path, const float time)
{
- IArchive archive = open_archive(filepath);
+ IArchive *archive = archive_from_handle(handle);
- if (!archive.valid()) {
- return NULL;
+ if (!archive || !archive->valid()) {
+ return dm;
}
IObject iobject;
- find_iobject(archive.getTop(), iobject, object_path);
+ find_iobject(archive->getTop(), iobject, object_path);
if (!iobject.valid()) {
return NULL;
diff --git a/source/blender/blenkernel/BKE_cachefile.h b/source/blender/blenkernel/BKE_cachefile.h
index 9b5b22d..1f201ef 100644
--- a/source/blender/blenkernel/BKE_cachefile.h
+++ b/source/blender/blenkernel/BKE_cachefile.h
@@ -34,10 +34,15 @@
extern "C" {
#endif
+struct CacheFile;
struct Main;
void *BKE_cachefile_add(struct Main *bmain, const char *name);
+void BKE_cachefile_free(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,
char *r_filename);
diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c
index 93eb81d..009528e 100644
--- a/source/blender/blenkernel/intern/cachefile.c
+++ b/source/blender/blenkernel/intern/cachefile.c
@@ -33,6 +33,7 @@
#include "BLI_fileops.h"
#include "BLI_path_util.h"
#include "BLI_string.h"
+#include "BLI_utildefines.h"
#include "BKE_cachefile.h"
#include "BKE_global.h"
@@ -40,10 +41,15 @@
#include "BKE_main.h"
#include "BKE_scene.h"
+#ifdef WITH_ALEMBIC
+# include "ABC_alembic.h"
+#endif
+
void *BKE_cachefile_add(Main *bmain, const char *name)
{
CacheFile *cache_file = BKE_libblock_alloc(bmain, ID_CF, name);
+ cache_file->handle = NULL;
cache_file->filepath[0] = '\0';
cache_file->frame_start = 0.0f;
cache_file->frame_scale = 1.0f;
@@ -52,9 +58,37 @@ void *BKE_cachefile_add(Main *bmain, const char *name)
return cache_file;
}
+void BKE_cachefile_free(CacheFile *cache_file)
+{
+#ifdef WITH_ALEMBIC
+ ABC_free_handle(cache_file->handle);
+#else
+ UNUSED_VARS(cache_file);
+#endif
+}
+
+void BKE_cachefiles_open_next_file(Main *bmain, float ctime)
+{
+ CacheFile *cache_file;
+ char filename[FILE_MAX];
+
+ for (cache_file = bmain->cachefiles.first; cache_file; cache_file = cache_file->id.next) {
+ if (!cache_file->is_sequence) {
+ continue;
+ }
+
+ if (BKE_cachefile_filepath_get(cache_file, ctime, filename)) {
+#ifdef WITH_ALEMBIC
+ ABC_free_handle(cache_file->handle);
+ cache_file->handle = ABC_create_handle(filename);
+#endif
+ }
+ }
+}
+
bool BKE_cachefile_filepath_get(CacheFile *cache_file, float frame, char *r_filepath)
{
- BLI_strncpy(r_filepath, cache_file->filepath, 1024);
+ BLI_strncpy(r_filepath, cache_file->filepath,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list