Commit: 3019eff71ea2c178003c21fd8894d13868985cee
Author: Lukas Tönne
Date:   Tue Jun 2 17:59:47 2015 +0200
Branches: alembic
https://developer.blender.org/rB3019eff71ea2c178003c21fd8894d13868985cee

Use ID property groups for storing and loading metadata associated to
Alembic archives.

Two separate property groups for metadata are used (so that reading
caches does not overwrite metadata for output caches).

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

M       source/blender/blenkernel/BKE_cache_library.h
M       source/blender/blenkernel/intern/cache_library.c
M       source/blender/editors/io/io_cache_library.c
M       source/blender/pointcache/PTC_api.cpp
M       source/blender/pointcache/PTC_api.h
M       source/blender/pointcache/alembic/abc_info.cpp
M       source/blender/pointcache/alembic/abc_reader.cpp
M       source/blender/pointcache/alembic/abc_reader.h
M       source/blender/pointcache/alembic/abc_writer.cpp
M       source/blender/pointcache/alembic/abc_writer.h
M       source/blender/pointcache/alembic/alembic.cpp
M       source/blender/pointcache/alembic/alembic.h
M       source/blender/pointcache/intern/ptc_types.h
M       source/blender/pointcache/intern/reader.h

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

diff --git a/source/blender/blenkernel/BKE_cache_library.h 
b/source/blender/blenkernel/BKE_cache_library.h
index 88eb7e9..62ec261 100644
--- a/source/blender/blenkernel/BKE_cache_library.h
+++ b/source/blender/blenkernel/BKE_cache_library.h
@@ -69,6 +69,9 @@ eCacheReadSampleResult BKE_cache_read_result(int ptc_result);
 
 bool BKE_cache_library_validate_item(struct CacheLibrary *cachelib, struct 
Object *ob, int type, int index);
 
+struct IDProperty *BKE_cache_library_get_input_metadata(struct CacheLibrary 
*cachelib, bool create);
+struct IDProperty *BKE_cache_library_get_output_metadata(struct CacheLibrary 
*cachelib, bool create);
+
 /* ========================================================================= */
 
 void BKE_cache_library_get_read_flags(struct CacheLibrary *cachelib, bool 
use_render, bool for_display, bool *read_strands_motion, bool 
*read_strands_children);
diff --git a/source/blender/blenkernel/intern/cache_library.c 
b/source/blender/blenkernel/intern/cache_library.c
index 37cc45d..370a2fc 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -61,6 +61,7 @@
 #include "BKE_effect.h"
 #include "BKE_global.h"
 #include "BKE_group.h"
+#include "BKE_idprop.h"
 #include "BKE_key.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
@@ -271,6 +272,32 @@ void BKE_cache_library_tag_used_objects(CacheLibrary 
*cachelib)
 
 /* ========================================================================= */
 
+static IDProperty *cache_library_get_metadata(CacheLibrary *cachelib, const 
char *name, bool create)
+{
+       IDProperty *idprops = IDP_GetProperties((ID *)cachelib, create);
+       IDProperty *metadata = NULL;
+       if (idprops) {
+               metadata = IDP_GetPropertyFromGroup(idprops, name);
+               if (!metadata && create) {
+                       IDPropertyTemplate val;
+                       val.i = 0;
+                       metadata = IDP_New(IDP_GROUP, &val, name);
+                       IDP_AddToGroup(idprops, metadata);
+               }
+       }
+       return metadata;
+}
+
+IDProperty *BKE_cache_library_get_input_metadata(CacheLibrary *cachelib, bool 
create)
+{
+       return cache_library_get_metadata(cachelib, "input_metadata", create);
+}
+
+IDProperty *BKE_cache_library_get_output_metadata(CacheLibrary *cachelib, bool 
create)
+{
+       return cache_library_get_metadata(cachelib, "output_metadata", create);
+}
+
 BLI_INLINE bool path_is_dirpath(const char *path)
 {
        /* last char is a slash? */
@@ -377,8 +404,10 @@ static struct PTCReaderArchive *find_active_cache(Scene 
*scene, CacheLibrary *ca
        else
                cachelib->archive_info = BKE_cache_archive_info_new();
        BLI_strncpy(cachelib->archive_info->filepath, filename, 
sizeof(cachelib->archive_info->filepath));
-       if (archive)
-               PTC_get_archive_info(archive, cachelib->archive_info);
+       if (archive) {
+               IDProperty *metadata = 
BKE_cache_library_get_input_metadata(cachelib, true);
+               PTC_get_archive_info(archive, cachelib->archive_info, metadata);
+       }
        
        return archive;
 }
diff --git a/source/blender/editors/io/io_cache_library.c 
b/source/blender/editors/io/io_cache_library.c
index def99d0..f7076ae 100644
--- a/source/blender/editors/io/io_cache_library.c
+++ b/source/blender/editors/io/io_cache_library.c
@@ -368,6 +368,7 @@ static void cache_library_bake_start(void *customdata, 
short *stop, short *do_up
        Scene *scene = data->scene;
        char filename[FILE_MAX];
        char app_name[MAX_NAME];
+       IDProperty *metadata;
        
        data->stop = stop;
        data->do_update = do_update;
@@ -379,7 +380,10 @@ static void cache_library_bake_start(void *customdata, 
short *stop, short *do_up
        
        BKE_cache_archive_output_path(data->cachelib, filename, 
sizeof(filename));
        BLI_snprintf(app_name, sizeof(app_name), "Blender %s", versionstr);
-       data->archive = PTC_open_writer_archive(FPS, data->start_frame, 
filename, archive_res, app_name, data->cachelib->description, NULL);
+       
+       metadata = BKE_cache_library_get_output_metadata(data->cachelib, false);
+       
+       data->archive = PTC_open_writer_archive(FPS, data->start_frame, 
filename, archive_res, app_name, data->cachelib->description, NULL, metadata);
        
        if (data->archive) {
                
@@ -629,6 +633,7 @@ static int cache_library_archive_slice_exec(bContext *C, 
wmOperator *op)
        struct PTCWriterArchive *output_archive;
        PTCArchiveResolution archive_res;
        CacheArchiveInfo info;
+       IDProperty *metadata;
        
        RNA_string_get(op->ptr, "input_filepath", input_filepath);
        if (input_filepath[0] == '\0')
@@ -650,9 +655,18 @@ static int cache_library_archive_slice_exec(bContext *C, 
wmOperator *op)
        }
        
        archive_res = PTC_reader_archive_get_resolutions(input_archive);
-       PTC_get_archive_info(input_archive, &info);
+       {
+               IDPropertyTemplate val;
+               val.i = 0;
+               metadata = IDP_New(IDP_GROUP, &val, "cache input metadata");
+       }
+       PTC_get_archive_info(input_archive, &info, metadata);
+       
+       output_archive = PTC_open_writer_archive(FPS, start_frame, 
output_filename, archive_res, info.app_name, info.description, NULL, metadata);
+       
+       IDP_FreeProperty(metadata);
+       MEM_freeN(metadata);
        
-       output_archive = PTC_open_writer_archive(FPS, start_frame, 
output_filename, archive_res, info.app_name, info.description, NULL);
        if (!output_archive) {
                BKE_reportf(op->reports, RPT_ERROR, "Cannot write to cache file 
at '%s'", output_filepath);
                return OPERATOR_CANCELLED;
diff --git a/source/blender/pointcache/PTC_api.cpp 
b/source/blender/pointcache/PTC_api.cpp
index 4aecf55..6f4f6da 100644
--- a/source/blender/pointcache/PTC_api.cpp
+++ b/source/blender/pointcache/PTC_api.cpp
@@ -131,9 +131,9 @@ const char *PTC_get_default_archive_extension(void)
 }
 
 PTCWriterArchive *PTC_open_writer_archive(double fps, float start_frame, const 
char *path, PTCArchiveResolution resolutions,
-                                          const char *app_name, const char 
*description, const struct tm *time)
+                                          const char *app_name, const char 
*description, const struct tm *time, struct IDProperty *metadata)
 {
-       return (PTCWriterArchive 
*)PTC::Factory::alembic->open_writer_archive(fps, start_frame, path, 
resolutions, app_name, description, time, NULL);
+       return (PTCWriterArchive 
*)PTC::Factory::alembic->open_writer_archive(fps, start_frame, path, 
resolutions, app_name, description, time, metadata, NULL);
 }
 
 void PTC_close_writer_archive(PTCWriterArchive *_archive)
@@ -251,10 +251,10 @@ void PTC_get_archive_info_stream(PTCReaderArchive 
*_archive, void (*stream)(void
        archive->get_info_stream(stream, userdata);
 }
 
-void PTC_get_archive_info(PTCReaderArchive *_archive, struct CacheArchiveInfo 
*info)
+void PTC_get_archive_info(PTCReaderArchive *_archive, struct CacheArchiveInfo 
*info, IDProperty *metadata)
 {
        PTC::ReaderArchive *archive = (PTC::ReaderArchive *)_archive;
-       archive->get_info(info);
+       archive->get_info(info, metadata);
 }
 
 void PTC_get_archive_info_nodes(PTCReaderArchive *_archive, struct 
CacheArchiveInfo *info, bool calc_bytes_size)
diff --git a/source/blender/pointcache/PTC_api.h 
b/source/blender/pointcache/PTC_api.h
index e00739e..1795d2b 100644
--- a/source/blender/pointcache/PTC_api.h
+++ b/source/blender/pointcache/PTC_api.h
@@ -39,6 +39,7 @@ struct DupliCache;
 struct ClothModifierData;
 struct DerivedMesh;
 struct Group;
+struct IDProperty;
 struct ModifierData;
 struct Object;
 struct ParticleSystem;
@@ -62,7 +63,7 @@ void PTC_error_handler_modifier(struct ModifierData *md);
 const char *PTC_get_default_archive_extension(void);
 
 struct PTCWriterArchive *PTC_open_writer_archive(double fps, float 
start_frame, const char *path, PTCArchiveResolution resolutions,
-                                                 const char *app_name, const 
char *description, const struct tm *time);
+                                                 const char *app_name, const 
char *description, const struct tm *time, struct IDProperty *metadata);
 void PTC_close_writer_archive(struct PTCWriterArchive *archive);
 void PTC_writer_archive_use_render(struct PTCWriterArchive *archive, bool 
enable);
 
@@ -87,7 +88,7 @@ PTCReadSampleResult PTC_read_sample(struct PTCReader *reader, 
float frame);
 PTCReadSampleResult PTC_test_sample(struct PTCReader *reader, float frame);
 
 void PTC_get_archive_info_stream(struct PTCReaderArchive *archive, void 
(*stream)(void *, const char *), void *userdata);
-void PTC_get_archive_info(struct PTCReaderArchive *_archive, struct 
CacheArchiveInfo *info);
+void PTC_get_archive_info(struct PTCReaderArchive *_archive, struct 
CacheArchiveInfo *info, struct IDProperty *metadata);
 void PTC_get_archive_info_nodes(struct PTCReaderArchive *_archive, struct 
CacheArchiveInfo *info, bool calc_bytes_size);
 
 void PTC_archive_slice(struct PTCReaderArchive *in, struct PTCWriterArchive 
*out, float start_frame, float end_frame);
diff --git a/source/blender/pointcache/alembic/abc_info.cpp 
b/source/blender/pointcache/alembic/abc_info.cpp
index 57dbf3f..2010997 100644
--- a/source/blender/pointcache/alembic/abc_info.cpp
+++ b/source/blender/pointcache/alembic/abc_info.cpp
@@ -66,13 +66,136 @@ extern "C" {
 #include "BLI_string.h"
 #include "BLI_utildefines.h"
 
+#include "DNA_ID.h"
+
 #include "BKE_cache_library.h"
+#include "BKE_idprop.h"
 }
 
 using namespace ::Alembic::AbcGeom;
 
 namespace PTC {
 
+static void metadata_from_idprops(MetaData &md, IDProperty *prop);
+
+void abc_metadata_from_idprops_group(MetaData &md, IDProperty *prop)
+{
+       if (!prop)
+               return;
+       
+       IDProperty *child;
+       for (child = (IDProperty *)prop->data.group.first; child; child = 
child->next)
+               metadata_from_idprops(md, child);
+}
+
+static void metadata_from_idprops(MetaData &md, IDProperty *prop)
+{
+       /* skip default metadata entries, these are set explicitly */
+       std::string key(prop->name);
+       if (key.compare(kApplicationNameKey)==0 || 
key.compare(kDateWrittenKey)==0 || key.compare(kUserDescriptionKey)==0)
+               return;
+       
+       switch (prop->type) {
+#if 0 /* don't support recursion yet */
+               case IDP_GROUP: {
+                       metadata_from_idprops_group(md, child);
+                       break;
+               }
+               
+               case IDP_ARRAY: {
+                       if (prop->data.pointer) {
+                               IDProperty **array = (IDProperty 
**)prop->data.pointer;
+                               for (int a = 0; a < prop->len; a++)
+                                       metadata_from_idprops(md, array[a]);
+                       }
+               }
+#endif
+               
+               case IDP_STRING: {
+                       std::stringstream ss;
+                       ss << IDP_String(pro

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to