[Bf-blender-cvs] [4716a87] alembic_pointcache: Define a collection of "object_caches" in the CacheLibrary RNA for iterating over all objects eligible for caching in the group.

Lukas Tönne noreply at git.blender.org
Mon Feb 23 14:06:43 CET 2015


Commit: 4716a87636d72d2a0643fe9df493c75ddeb30368
Author: Lukas Tönne
Date:   Mon Feb 23 14:04:30 2015 +0100
Branches: alembic_pointcache
https://developer.blender.org/rB4716a87636d72d2a0643fe9df493c75ddeb30368

Define a collection of "object_caches" in the CacheLibrary RNA for
iterating over all objects eligible for caching in the group.

This allows for nested dupligroup instances as well. All objects that
are instantiated at least once by any group can be included in the
respective cache, but get represented only once because the cached data
is the same anyway.

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

M	source/blender/blenkernel/BKE_cache_library.h
M	source/blender/blenkernel/intern/cache_library.c
M	source/blender/makesrna/intern/rna_cache_library.c

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

diff --git a/source/blender/blenkernel/BKE_cache_library.h b/source/blender/blenkernel/BKE_cache_library.h
index a80aeec..b66678c 100644
--- a/source/blender/blenkernel/BKE_cache_library.h
+++ b/source/blender/blenkernel/BKE_cache_library.h
@@ -32,17 +32,33 @@
  *  \ingroup bke
  */
 
+#include "DNA_cache_library_types.h"
+
+struct ListBase;
 struct Main;
-struct CacheLibrary;
-struct CacheItem;
-struct CacheItemPath;
+struct Object;
 
 struct CacheLibrary *BKE_cache_library_add(struct Main *bmain, const char *name);
 struct CacheLibrary *BKE_cache_library_copy(struct CacheLibrary *cachelib);
 void BKE_cache_library_free(struct CacheLibrary *cachelib);
 
+void BKE_cache_library_make_object_list(struct Main *main, struct CacheLibrary *cachelib, struct ListBase *lb);
+
+typedef struct CacheLibraryObjectsIterator {
+	ListBase objects;
+	LinkData *cur;
+} CacheLibraryObjectsIterator;
+
+void BKE_object_cache_iter_init(CacheLibraryObjectsIterator *iter, struct CacheLibrary *cachelib);
+bool BKE_object_cache_iter_valid(CacheLibraryObjectsIterator *iter);
+void BKE_object_cache_iter_next(CacheLibraryObjectsIterator *iter);
+void BKE_object_cache_iter_end(CacheLibraryObjectsIterator *iter);
+struct Object *BKE_object_cache_iter_get(CacheLibraryObjectsIterator *iter);
+
+#if 0
 typedef void (*CacheGroupWalkFunc)(void *userdata, struct CacheLibrary *cachelib, const struct CacheItemPath *path);
 void BKE_cache_library_walk(struct CacheLibrary *cachelib, CacheGroupWalkFunc walk, void *userdata);
+#endif
 
 struct CacheItem *BKE_cache_library_find_item(struct CacheLibrary *cachelib, const struct CacheItemPath *path);
 struct CacheItem *BKE_cache_library_add_item(struct CacheLibrary *cachelib, const struct CacheItemPath *path);
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index 02d626a..ab6db2a 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -33,6 +33,7 @@
 
 #include "BLI_blenlib.h"
 #include "BLI_ghash.h"
+#include "BLI_listbase.h"
 #include "BLI_string.h"
 #include "BLI_utildefines.h"
 
@@ -112,6 +113,80 @@ static void cache_path_copy(CacheItemPath *dst, const CacheItemPath *src)
 	memcpy(dst, src, sizeof(CacheItemPath));
 }
 
+/* ========================================================================= */
+
+static void cache_library_tag_recursive(CacheLibrary *cachelib, int level, Object *ob)
+{
+	if (level > MAX_CACHE_GROUP_LEVEL)
+		return;
+	
+	ob->id.flag |= LIB_DOIT;
+	
+	/* dupli group recursion */
+	if ((ob->transflag & OB_DUPLIGROUP) && ob->dup_group) {
+		GroupObject *gob;
+		
+		for (gob = ob->dup_group->gobject.first; gob; gob = gob->next) {
+			cache_library_tag_recursive(cachelib, level + 1, gob->ob);
+		}
+	}
+}
+
+/* tag IDs contained in the cache library group */
+void BKE_cache_library_make_object_list(Main *main, CacheLibrary *cachelib, ListBase *lb)
+{
+	if (cachelib && cachelib->group) {
+		Object *ob;
+		LinkData *link;
+		GroupObject *gob;
+		
+		/* clear tags */
+		BKE_main_id_tag_idcode(main, ID_OB, false);
+		
+		for (gob = cachelib->group->gobject.first; gob; gob = gob->next) {
+			cache_library_tag_recursive(cachelib, 0, gob->ob);
+		}
+		
+		/* store object pointers in the list */
+		for (ob = main->object.first; ob; ob = ob->id.next) {
+			if (ob->id.flag & LIB_DOIT) {
+				link = MEM_callocN(sizeof(LinkData), "cache library ID link");
+				link->data = ob;
+				BLI_addtail(lb, link);
+			}
+		}
+	}
+}
+
+void BKE_object_cache_iter_init(CacheLibraryObjectsIterator *iter, CacheLibrary *cachelib)
+{
+	BLI_listbase_clear(&iter->objects);
+	BKE_cache_library_make_object_list(G.main, cachelib, &iter->objects);
+	
+	iter->cur = iter->objects.first;
+}
+
+bool BKE_object_cache_iter_valid(CacheLibraryObjectsIterator *iter)
+{
+	return iter->cur != NULL;
+}
+
+void BKE_object_cache_iter_next(CacheLibraryObjectsIterator *iter)
+{
+	iter->cur = iter->cur->next;
+}
+
+Object *BKE_object_cache_iter_get(CacheLibraryObjectsIterator *iter)
+{
+	return iter->cur->data;
+}
+
+void BKE_object_cache_iter_end(CacheLibraryObjectsIterator *iter)
+{
+	BLI_freelistN(&iter->objects);
+}
+
+#if 0
 static void cache_library_walk_recursive(CacheLibrary *cachelib, CacheGroupWalkFunc walk, void *userdata, int level, Object *ob)
 {
 	CacheItemPath path;
@@ -143,6 +218,7 @@ void BKE_cache_library_walk(CacheLibrary *cachelib, CacheGroupWalkFunc walk, voi
 		}
 	}
 }
+#endif
 
 /* ========================================================================= */
 
diff --git a/source/blender/makesrna/intern/rna_cache_library.c b/source/blender/makesrna/intern/rna_cache_library.c
index 31e9aba..49942c5 100644
--- a/source/blender/makesrna/intern/rna_cache_library.c
+++ b/source/blender/makesrna/intern/rna_cache_library.c
@@ -40,9 +40,14 @@
 
 #include "MEM_guardedalloc.h"
 
-#include "RNA_access.h"
+#include "BLI_listbase.h"
+
+#include "DNA_object_types.h"
 
 #include "BKE_cache_library.h"
+#include "BKE_main.h"
+
+#include "RNA_access.h"
 
 #include "WM_api.h"
 
@@ -50,8 +55,116 @@ static void rna_CacheLibrary_update(Main *UNUSED(main), Scene *UNUSED(scene), Po
 {
 }
 
+/* ========================================================================= */
+
+static PointerRNA rna_ObjectCache_object_get(PointerRNA *ptr)
+{
+	Object *ob = ptr->data;
+	PointerRNA rptr;
+	RNA_id_pointer_create((ID *)ob, &rptr);
+	return rptr;
+}
+
+/* ========================================================================= */
+
+static void rna_CacheLibrary_object_caches_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
+{
+	CacheLibraryObjectsIterator *internal = (CacheLibraryObjectsIterator *)(&iter->internal.listbase);
+	CacheLibrary *cachelib = ptr->data;
+	
+	/* XXX this is not particularly elegant, but works:
+	 * abuse the internal union for storing our own iterator
+	 */
+	BLI_STATIC_ASSERT(sizeof(iter->internal) >= sizeof(CacheLibraryObjectsIterator), "CollectionPropertyIterator internal not large enough");
+	
+	BKE_object_cache_iter_init(internal, cachelib);
+	iter->valid = BKE_object_cache_iter_valid(internal);
+}
+
+void rna_CacheLibrary_object_caches_next(CollectionPropertyIterator *iter)
+{
+	CacheLibraryObjectsIterator *internal = (CacheLibraryObjectsIterator *)(&iter->internal.listbase);
+	
+	BKE_object_cache_iter_next(internal);
+	iter->valid = BKE_object_cache_iter_valid(internal);
+}
+
+void rna_CacheLibrary_object_caches_end(CollectionPropertyIterator *iter)
+{
+	CacheLibraryObjectsIterator *internal = (CacheLibraryObjectsIterator *)(&iter->internal.listbase);
+	
+	BKE_object_cache_iter_end(internal);
+}
+
+PointerRNA rna_CacheLibrary_object_caches_get(CollectionPropertyIterator *iter)
+{
+	CacheLibraryObjectsIterator *internal = (CacheLibraryObjectsIterator *)(&iter->internal.listbase);
+	PointerRNA rptr;
+	
+	RNA_pointer_create((ID *)iter->parent.id.data, &RNA_ObjectCache, BKE_object_cache_iter_get(internal), &rptr);
+	
+	return rptr;
+}
+
 #else
 
+static void rna_def_cache_item_path(BlenderRNA *brna)
+{
+	StructRNA *srna;
+	PropertyRNA *prop;
+	
+	static EnumPropertyItem cache_path_type_items[] = {
+	    {CACHE_TYPE_OBJECT,         "OBJECT",			ICON_OBJECT_DATA,       "Object", "Object base properties"},
+	    {CACHE_TYPE_DERIVED_MESH,   "DERIVED_MESH",     ICON_OUTLINER_OB_MESH,  "Derived Mesh", "Mesh result from modifiers"},
+	    {CACHE_TYPE_HAIR,           "HAIR",             ICON_PARTICLE_POINT,    "Hair", "Hair parent strands"},
+	    {CACHE_TYPE_HAIR_PATHS,     "HAIR_PATHS",       ICON_PARTICLE_PATH,     "Hair Paths", "Full hair paths"},
+	    {0, NULL, 0, NULL, NULL}
+	};
+	
+	srna = RNA_def_struct(brna, "CacheItemPath", NULL);
+	RNA_def_struct_ui_text(srna, "Cache Path", "Description of a cacheable item in an object group");
+	
+	prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_sdna(prop, NULL, "type");
+	RNA_def_property_enum_items(prop, cache_path_type_items);
+	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+	RNA_def_property_ui_text(prop, "Type", "Type of cached data");
+	
+	prop = RNA_def_property(srna, "cache_id_data", PROP_POINTER, PROP_NONE);
+	RNA_def_property_pointer_sdna(prop, NULL, "id");
+	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+	RNA_def_property_ui_text(prop, "ID", "ID datablock");
+	
+	prop = RNA_def_property(srna, "index", PROP_INT, PROP_NONE);
+	RNA_def_property_int_sdna(prop, NULL, "index");
+	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+	RNA_def_property_ui_text(prop, "Index", "Index of the cached data");
+}
+
+static void rna_def_object_cache(BlenderRNA *brna)
+{
+	StructRNA *srna;
+	PropertyRNA *prop;
+	
+	srna = RNA_def_struct(brna, "ObjectCache", NULL);
+	RNA_def_struct_ui_text(srna, "Object Cache", "Cacheable data in an Object");
+	
+	prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
+	RNA_def_property_pointer_funcs(prop, "rna_ObjectCache_object_get", NULL, NULL, NULL);
+	RNA_def_property_struct_type(prop, "Object");
+	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+	RNA_def_property_ui_text(prop, "Object", "");
+}
+
+static void rna_def_cache_item(BlenderRNA *brna)
+{
+	StructRNA *srna;
+//	PropertyRNA *prop;
+	
+	srna = RNA_def_struct(brna, "CacheItem", NULL);
+	RNA_def_struct_ui_text(srna, "Cache Item", "Cached item included in a Cache Library");
+}
+
 static void rna_def_cache_library(BlenderRNA *brna)
 {
 	StructRNA *srna;
@@ -70,10 +183,19 @@ static void rna_def_cache_library(BlenderRNA *brna)
 	RNA_def_property_flag(prop, PROP_EDITABLE);
 	RNA_def_property_ui_text(prop, "Group", "Cached object group");
 	RNA_def_property_update(prop, 0, "rna_CacheLibrary_update");
+	
+	prop = RNA_def_property(srna, "object_caches", PROP_COLLECTION, PROP_NONE);
+	RNA_def_property_struct_type(prop, "ObjectCache");
+	RNA_def_property_collection_funcs(prop, "rna_CacheLibrary_object_caches_begin", "rna_CacheLibrary_object_caches_next", "rna_CacheLibrary_object_caches_end",
+	                                  "rna_CacheLibrary_object_caches_get", NULL, NULL, NULL, NULL);
+	RNA_def_property_ui_text(prop, "Object Caches", "Cacheable objects inside the cache library group");
 }
 
 void RNA_def_cache_library(BlenderRNA *brna)
 {
+	rna_de

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list