[Bf-blender-cvs] [a3adbe5] alembic_basic_io: Store the paths of the objects in the archive in a collection.

Kévin Dietrich noreply at git.blender.org
Tue Jul 12 16:04:02 CEST 2016


Commit: a3adbe557ad0ec07d09a15479b03cb4505fdbf71
Author: Kévin Dietrich
Date:   Tue Jul 12 11:22:24 2016 +0200
Branches: alembic_basic_io
https://developer.blender.org/rBa3adbe557ad0ec07d09a15479b03cb4505fdbf71

Store the paths of the objects in the archive in a collection.

This is mainly for use in a drop down menu in the UI.

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

M	release/scripts/startup/bl_ui/properties_constraint.py
M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/alembic/ABC_alembic.h
M	source/blender/alembic/intern/alembic_capi.cc
M	source/blender/blenkernel/intern/cachefile.c
M	source/blender/editors/io/io_cache.c
M	source/blender/makesdna/DNA_cachefile_types.h
M	source/blender/makesrna/intern/rna_cachefile.c

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

diff --git a/release/scripts/startup/bl_ui/properties_constraint.py b/release/scripts/startup/bl_ui/properties_constraint.py
index 7fe4f40..ede202c 100644
--- a/release/scripts/startup/bl_ui/properties_constraint.py
+++ b/release/scripts/startup/bl_ui/properties_constraint.py
@@ -882,7 +882,11 @@ class ConstraintButtonsPanel:
 
     def TRANSFORMCACHE(self, context, layout, con):
         layout.template_cache_file(con, "cache_file")
-        layout.prop(con, "abc_object_path")
+
+        cache_file = con.cache_file
+
+        if cache_file != None:
+            layout.prop_search(con, "abc_object_path", cache_file, "object_paths")
 
     def SCRIPT(self, context, layout, con):
         layout.label("Blender 2.6 doesn't support python constraints yet")
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 5c14cea..275bef7 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -224,7 +224,10 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
 
     def MESH_SEQUENCE_CACHE(self, layout, ob, md):
         layout.template_cache_file(md, "cache_file")
-        layout.prop(md, "abc_object_path")
+
+        cache_file = md.cache_file
+        if cache_file != None:
+            layout.prop_search(md, "abc_object_path", cache_file, "object_paths")
 
     def CAST(self, layout, ob, md):
         split = layout.split(percentage=0.25)
diff --git a/source/blender/alembic/ABC_alembic.h b/source/blender/alembic/ABC_alembic.h
index 1e2850a..f1ba6c3 100644
--- a/source/blender/alembic/ABC_alembic.h
+++ b/source/blender/alembic/ABC_alembic.h
@@ -29,6 +29,7 @@ extern "C" {
 
 struct bContext;
 struct DerivedMesh;
+struct ListBase;
 struct Object;
 struct Scene;
 
@@ -73,7 +74,7 @@ void ABC_import(struct bContext *C,
                 int sequence_len,
                 int offset);
 
-AbcArchiveHandle *ABC_create_handle(const char *filename);
+AbcArchiveHandle *ABC_create_handle(const char *filename, struct ListBase *object_paths);
 
 void ABC_free_handle(AbcArchiveHandle *handle);
 
diff --git a/source/blender/alembic/intern/alembic_capi.cc b/source/blender/alembic/intern/alembic_capi.cc
index 21c048b..97d9c18 100644
--- a/source/blender/alembic/intern/alembic_capi.cc
+++ b/source/blender/alembic/intern/alembic_capi.cc
@@ -153,9 +153,102 @@ static IArchive *open_archive(const std::string &filename)
 	return archive;
 }
 
-AbcArchiveHandle *ABC_create_handle(const char *filename)
+/* NOTE: this function is similar to visit_objects below, need to keep them in
+ * sync. */
+static void gather_objects_paths(const IObject &object, ListBase *object_paths)
 {
-	return handle_from_archive(open_archive(filename));
+	if (!object.valid()) {
+		return;
+	}
+
+	for (int i = 0; i < object.getNumChildren(); ++i) {
+		IObject child = object.getChild(i);
+
+		if (!child.valid()) {
+			continue;
+		}
+
+		bool get_path = false;
+
+		const MetaData &md = child.getMetaData();
+
+		if (IXform::matches(md)) {
+			/* Check whether or not this object is a Maya locator, which is
+			 * similar to empties used as parent object in Blender. */
+			if (has_property(child.getProperties(), "locator")) {
+				get_path = true;
+			}
+			else {
+				/* Avoid creating an empty object if the child of this transform
+				 * is not a transform (that is an empty). */
+				if (child.getNumChildren() == 1) {
+					if (IXform::matches(child.getChild(0).getMetaData())) {
+						get_path = true;
+					}
+#if 0
+					else {
+						std::cerr << "Skipping " << child.getFullName() << '\n';
+					}
+#endif
+				}
+				else {
+					get_path = true;
+				}
+			}
+		}
+		else if (IPolyMesh::matches(md)) {
+			get_path = true;
+		}
+		else if (ISubD::matches(md)) {
+			get_path = true;
+		}
+		else if (INuPatch::matches(md)) {
+			get_path = true;
+		}
+		else if (ICamera::matches(md)) {
+			get_path = true;
+		}
+		else if (IPoints::matches(md)) {
+			get_path = true;
+		}
+		else if (IMaterial::matches(md)) {
+			/* Pass for now. */
+		}
+		else if (ILight::matches(md)) {
+			/* Pass for now. */
+		}
+		else if (IFaceSet::matches(md)) {
+			/* Pass, those are handled in the mesh reader. */
+		}
+		else if (ICurves::matches(md)) {
+			get_path = true;
+		}
+		else {
+			assert(false);
+		}
+
+		if (get_path) {
+			AlembicObjectPath *abc_path = static_cast<AlembicObjectPath *>(
+			                                  MEM_callocN(sizeof(AlembicObjectPath), "AlembicObjectPath"));
+
+			BLI_strncpy(abc_path->path, child.getFullName().c_str(), PATH_MAX);
+
+			BLI_addtail(object_paths, abc_path);
+		}
+
+		gather_objects_paths(child, object_paths);
+	}
+}
+
+AbcArchiveHandle *ABC_create_handle(const char *filename, ListBase *object_paths)
+{
+	IArchive *archive = open_archive(filename);
+
+	if (object_paths) {
+		gather_objects_paths(archive->getTop(), object_paths);
+	}
+
+	return handle_from_archive(archive);
 }
 
 void ABC_free_handle(AbcArchiveHandle *handle)
@@ -410,6 +503,13 @@ static void visit_object(const IObject &object,
 		if (reader) {
 			readers.push_back(reader);
 
+			AlembicObjectPath *abc_path = static_cast<AlembicObjectPath *>(
+			                                  MEM_callocN(sizeof(AlembicObjectPath), "AlembicObjectPath"));
+
+			BLI_strncpy(abc_path->path, child.getFullName().c_str(), PATH_MAX);
+
+			BLI_addtail(&settings.cache_file->object_paths, abc_path);
+
 			/* Cast to `void *` explicitly to avoid compiler errors because it
 			 * is a `const char *` which the compiler cast to `const void *`
 			 * instead of the expected `void *`. */
diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c
index d5d4eb7..3234e5e 100644
--- a/source/blender/blenkernel/intern/cachefile.c
+++ b/source/blender/blenkernel/intern/cachefile.c
@@ -32,6 +32,7 @@
 #include "DNA_scene_types.h"
 
 #include "BLI_fileops.h"
+#include "BLI_listbase.h"
 #include "BLI_path_util.h"
 #include "BLI_string.h"
 #include "BLI_utildefines.h"
@@ -78,6 +79,8 @@ void BKE_cachefile_free(CacheFile *cache_file)
 #ifdef WITH_ALEMBIC
 	ABC_free_handle(cache_file->handle);
 #endif
+
+	BLI_freelistN(&cache_file->object_paths);
 }
 
 CacheFile *BKE_cachefile_copy(Main *bmain, CacheFile *cache_file)
@@ -112,7 +115,7 @@ void BKE_cachefile_load(CacheFile *cache_file, const char *relabase)
 		ABC_free_handle(cache_file->handle);
 	}
 
-	cache_file->handle = ABC_create_handle(filename);
+	cache_file->handle = ABC_create_handle(filename, &cache_file->object_paths);
 #endif
 }
 
@@ -134,7 +137,7 @@ void BKE_cachefile_update_frame(Main *bmain, Scene *scene, const float ctime, co
 		if (BKE_cachefile_filepath_get(cache_file, time, filename)) {
 #ifdef WITH_ALEMBIC
 			ABC_free_handle(cache_file->handle);
-			cache_file->handle = ABC_create_handle(filename);
+			cache_file->handle = ABC_create_handle(filename, &cache_file->object_paths);
 #endif
 		}
 	}
diff --git a/source/blender/editors/io/io_cache.c b/source/blender/editors/io/io_cache.c
index 9fc7677..3f898ac 100644
--- a/source/blender/editors/io/io_cache.c
+++ b/source/blender/editors/io/io_cache.c
@@ -30,6 +30,7 @@
 #include "BLI_path_util.h"
 #include "BLI_string.h"
 
+#include "BKE_cachefile.h"
 #include "BKE_context.h"
 #include "BKE_global.h"
 #include "BKE_library.h"
@@ -91,6 +92,7 @@ static int cachefile_open_exec(bContext *C, wmOperator *op)
 
 	CacheFile *cache_file = BKE_libblock_alloc(bmain, ID_CF, BLI_path_basename(filename));
 	BLI_strncpy(cache_file->filepath, filename, FILE_MAX);
+	BKE_cachefile_load(cache_file, bmain->name);
 
 	/* hook into UI */
 	PropertyPointerRNA *pprop = op->customdata;
diff --git a/source/blender/makesdna/DNA_cachefile_types.h b/source/blender/makesdna/DNA_cachefile_types.h
index f8dcade..5768a19 100644
--- a/source/blender/makesdna/DNA_cachefile_types.h
+++ b/source/blender/makesdna/DNA_cachefile_types.h
@@ -42,12 +42,22 @@ enum {
 	CACHEFILE_DS_EXPAND = (1 << 0),
 };
 
+typedef struct AlembicObjectPath {
+	struct AlembicObjectPath *next, *prev;
+
+	char path[1024];  /* 1024 = FILE_MAX, might use PATH_MAX in the future. */
+} AlembicObjectPath;
+
 typedef struct CacheFile {
 	ID id;
 	struct AnimData *adt;
 
 	struct AbcArchiveHandle *handle;
 
+	/* Paths of the objects inside of the Alembic archive referenced by this
+	 * CacheFile. */
+	ListBase object_paths;
+
 	char filepath[1024];  /* 1024 = FILE_MAX */
 
 	char is_sequence;
diff --git a/source/blender/makesrna/intern/rna_cachefile.c b/source/blender/makesrna/intern/rna_cachefile.c
index 68e5e65..f2cb744 100644
--- a/source/blender/makesrna/intern/rna_cachefile.c
+++ b/source/blender/makesrna/intern/rna_cachefile.c
@@ -63,8 +63,35 @@ static void rna_CacheFile_update_handle(Main *bmain, Scene *scene, PointerRNA *p
 	rna_CacheFile_update(bmain, scene, ptr);
 }
 
+static void rna_CacheFile_object_paths_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
+{
+	CacheFile *cache_file = (CacheFile *)ptr->data;
+	rna_iterator_listbase_begin(iter, &cache_file->object_paths, NULL);
+}
+
 #else
 
+/* cachefile.object_paths */
+static void rna_def_alembic_object_path(BlenderRNA *brna)
+{
+	StructRNA *srna = RNA_def_struct(brna, "AlembicObjectPath", NULL);
+	RNA_def_struct_sdna(srna, "AlembicObjectPath");
+	RNA_def_struct_ui_text(srna, "Object Path", "Path of an object inside of an Alembic archive");
+
+	PropertyRNA *prop = RNA_def_property(srna, "path", PROP_STRING, PROP_NONE);
+	RNA_def_property_ui_text(prop, "Path", "Object path");
+	RNA_def_struct_name_property(srna, prop);
+}
+
+/* cachefile.object_paths */
+static void rna_def_cachefile_object_paths(BlenderRNA *brna, PropertyRNA *cprop)
+{
+	RNA_def_property_srna(cprop, "AlembicObjectPaths");
+	StructRNA *srna = RNA_def_struct(brna, "AlembicObjectPaths", NULL);
+	RNA_def_struct_sdna(srna, "CacheFile");
+	RNA_def_struct_ui_text(srna, "Object Paths", "Collection of object paths");
+}
+
 static void rna_def_cachefile(BlenderRNA *brna)
 {
 	StructRNA *srna = RNA_def_struct(brna, "CacheFile", "ID");
@@ -116,12 +143,24 @@ static void rna_def_cachefile(BlenderRNA *brna)
 	                                        " only applicable through a Trans

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list