[Bf-blender-cvs] [b1a8b98] alembic: Simplification of the cache library filtering mechanism.

Lukas Tönne noreply at git.blender.org
Mon Mar 30 18:47:12 CEST 2015


Commit: b1a8b9806b6ab7b4087fa0870158663584c65815
Author: Lukas Tönne
Date:   Mon Mar 30 18:43:31 2015 +0200
Branches: alembic
https://developer.blender.org/rBb1a8b9806b6ab7b4087fa0870158663584c65815

Simplification of the cache library filtering mechanism.

Now the filtering is simply based on the data types that should go into
the cache, instead of selecting each object and component individually.

This is slightly more limited and may need to be revisited again later,
but for the time being it is much less confusing and clumsy. Filtering
by objects can be accomplished by creating groups accordingly. Making
groups specifically for caching is totally acceptable.

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

M	release/scripts/startup/bl_ui/properties_object.py
M	source/blender/blenkernel/BKE_cache_library.h
M	source/blender/blenkernel/intern/cache_library.c
M	source/blender/blenkernel/intern/object.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/io/io_cache_library.c
M	source/blender/editors/io/io_cache_library.h
M	source/blender/editors/io/io_ops.c
M	source/blender/makesdna/DNA_cache_library_types.h
M	source/blender/makesrna/RNA_enum_types.h
M	source/blender/makesrna/intern/rna_cache_library.c
M	source/blender/makesrna/intern/rna_ui_api.c
M	source/blender/pointcache/alembic/abc_group.cpp

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

diff --git a/release/scripts/startup/bl_ui/properties_object.py b/release/scripts/startup/bl_ui/properties_object.py
index 5c81aea..4830f52 100644
--- a/release/scripts/startup/bl_ui/properties_object.py
+++ b/release/scripts/startup/bl_ui/properties_object.py
@@ -265,14 +265,6 @@ bpy.types.CacheLibrary.filter_string = \
         name="Filter Object Name",
         description="Filter cache library objects by name",
         )
-bpy.types.CacheLibrary.filter_types = \
-    bpy.props.EnumProperty(
-        name="Filter Item Type",
-        description="Filter cache library items by type",
-        options={'ENUM_FLAG'},
-        items=[ (e.identifier, e.name, e.description, e.icon, 2**i) for i, e in enumerate(bpy.types.CacheItem.bl_rna.properties['type'].enum_items) ],
-        default=set( e.identifier for e in bpy.types.CacheItem.bl_rna.properties['type'].enum_items ),
-        )
 
 def cachelib_objects(cachelib, group):
     if not cachelib or not group:
@@ -284,10 +276,9 @@ def cachelib_objects(cachelib, group):
     else:
         return group.objects
 
-# Yields (item, type, index, enabled)
-# Note that item can be None when not included in the cache yet
+# Yields (type, index, enabled)
 def cachelib_object_items(cachelib, ob):
-    filter_types = cachelib.filter_types
+    filter_types = cachelib.data_types
 
     def items_desc():
         yield 'OBJECT', -1
@@ -302,26 +293,20 @@ def cachelib_object_items(cachelib, ob):
                 yield 'HAIR', index
                 yield 'HAIR_PATHS', index
 
-    for item_type, item_index in items_desc():
-        item = cachelib.cache_item_find(ob, item_type, item_index)
-        
+    for datatype, index in items_desc():
         show = False
         enable = False
-        # always show existing items
-        if item and item.enabled:
-            show = True
-            enable = True
         # always show selected types
-        elif item_type in filter_types:
+        if datatype in filter_types:
             show = True
             enable = True
         # special case: OBJECT type used as top level, show but disable
-        elif item_type == 'OBJECT':
+        elif datatype == 'OBJECT':
             show = True
             enable = False
         
         if show:
-            yield item, item_type, item_index, enable
+            yield datatype, index, enable
 
 class OBJECT_PT_duplication(ObjectButtonsPanel, Panel):
     bl_label = "Duplication"
@@ -355,12 +340,13 @@ class OBJECT_PT_duplication(ObjectButtonsPanel, Panel):
         row.prop(ob, "use_dupli_cache_read", text="Read", toggle=True)
         row.prop(ob, "use_dupli_cache_write", text="Write", toggle=True)
         col.operator("cachelibrary.bake")
-        row = col.row(align=True)
+        row = col.row()
         row.prop(cachelib, "eval_mode", toggle=True, expand=True)
+        row = col.row()
+        row.prop(cachelib, "data_types", icon_only=True, toggle=True)
 
         row = layout.row(align=True)
         row.label("Filter:")
-        row.prop(cachelib, "filter_types", icon_only=True, toggle=True)
         row.prop(cachelib, "filter_string", icon='VIEWZOOM', text="")
 
         first = True
@@ -372,10 +358,10 @@ class OBJECT_PT_duplication(ObjectButtonsPanel, Panel):
                 layout.separator()
                 first = False
 
-            for item, item_type, item_index, enable in cachelib_object_items(cachelib, ob):
+            for datatype, index, enable in cachelib_object_items(cachelib, ob):
                 row = layout.row(align=True)
                 row.alignment = 'LEFT'
-                row.template_cache_library_item(cachelib, ob, item_type, item_index, enable)
+                row.template_cache_library_item(cachelib, ob, datatype, index, enable)
     
         layout.operator_menu_enum("cachelibrary.add_modifier", "type")
 
diff --git a/source/blender/blenkernel/BKE_cache_library.h b/source/blender/blenkernel/BKE_cache_library.h
index 50c69fb..fb808de 100644
--- a/source/blender/blenkernel/BKE_cache_library.h
+++ b/source/blender/blenkernel/BKE_cache_library.h
@@ -67,31 +67,12 @@ 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);
 
-typedef struct CacheLibraryItemsIterator {
-	struct Object *ob;
-	struct CacheItem *items;
-	int totitems;
-	
-	struct CacheItem *cur;
-} CacheLibraryItemsIterator;
-
-void BKE_cache_item_iter_init(CacheLibraryItemsIterator *iter, struct Object *ob);
-bool BKE_cache_item_iter_valid(CacheLibraryItemsIterator *iter);
-void BKE_cache_item_iter_next(CacheLibraryItemsIterator *iter);
-void BKE_cache_item_iter_end(CacheLibraryItemsIterator *iter);
-
 const char *BKE_cache_item_name_prefix(int type);
 void BKE_cache_item_name(struct Object *ob, int type, int index, char *name);
 int BKE_cache_item_name_length(struct Object *ob, int type, int index);
 eCacheReadSampleResult BKE_cache_read_result(int ptc_result);
 
-struct CacheItem *BKE_cache_library_find_item(struct CacheLibrary *cachelib, struct Object *ob, int type, int index);
-struct CacheItem *BKE_cache_library_add_item(struct CacheLibrary *cachelib, struct Object *ob, int type, int index);
-void BKE_cache_library_remove_item(struct CacheLibrary *cachelib, struct CacheItem *item);
-void BKE_cache_library_clear(struct CacheLibrary *cachelib);
-
 bool BKE_cache_library_validate_item(struct CacheLibrary *cachelib, struct Object *ob, int type, int index);
-void BKE_cache_library_group_update(struct Main *bmain, struct CacheLibrary *cachelib);
 
 /* ========================================================================= */
 
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index 636124a..4f9452a 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -76,6 +76,9 @@ CacheLibrary *BKE_cache_library_add(Main *bmain, const char *name)
 
 	cachelib->eval_mode = CACHE_LIBRARY_EVAL_REALTIME | CACHE_LIBRARY_EVAL_RENDER;
 
+	/* cache everything by default */
+	cachelib->data_types = CACHE_TYPE_ALL;
+
 	return cachelib;
 }
 
@@ -85,10 +88,6 @@ CacheLibrary *BKE_cache_library_copy(CacheLibrary *cachelib)
 	
 	cachelibn = BKE_libblock_copy(&cachelib->id);
 	
-	BLI_duplicatelist(&cachelibn->items, &cachelib->items);
-	/* hash table will be rebuilt when needed */
-	cachelibn->items_hash = NULL;
-	
 	{
 		CacheModifier *md;
 		BLI_listbase_clear(&cachelibn->modifiers);
@@ -106,10 +105,6 @@ CacheLibrary *BKE_cache_library_copy(CacheLibrary *cachelib)
 
 void BKE_cache_library_free(CacheLibrary *cachelib)
 {
-	BLI_freelistN(&cachelib->items);
-	if (cachelib->items_hash)
-		BLI_ghash_free(cachelib->items_hash, NULL, NULL);
-	
 	BKE_cache_modifier_clear(cachelib);
 }
 
@@ -195,160 +190,6 @@ void BKE_object_cache_iter_end(CacheLibraryObjectsIterator *iter)
 
 /* ========================================================================= */
 
-static int cache_count_items(Object *ob) {
-	ParticleSystem *psys;
-	int totitem = 1; /* base object */
-	
-	if (ob->type == OB_MESH)
-		totitem += 1; /* derived mesh */
-	
-	for (psys = ob->particlesystem.first; psys; psys = psys->next) {
-		if (psys->part->type == PART_HAIR) {
-			totitem += 2; /* hair and hair paths */
-		}
-		else {
-			totitem += 1; /* particles */
-		}
-	}
-	
-	return totitem;
-}
-
-static void cache_make_items(Object *ob, CacheItem *item) {
-	ParticleSystem *psys;
-	int i;
-	
-	/* base object */
-	item->ob = ob;
-	item->type = CACHE_TYPE_OBJECT;
-	item->index = -1;
-	++item;
-	
-	if (ob->type == OB_MESH) {
-		/* derived mesh */
-		item->ob = ob;
-		item->type = CACHE_TYPE_DERIVED_MESH;
-		item->index = -1;
-		++item;
-	}
-	
-	for (psys = ob->particlesystem.first, i = 0; psys; psys = psys->next, ++i) {
-		if (psys->part->type == PART_HAIR) {
-			/* hair */
-			item->ob = ob;
-			item->type = CACHE_TYPE_HAIR;
-			item->index = i;
-			++item;
-			
-			/* hair paths */
-			item->ob = ob;
-			item->type = CACHE_TYPE_HAIR_PATHS;
-			item->index = i;
-			++item;
-		}
-		else {
-			/* hair paths */
-			item->ob = ob;
-			item->type = CACHE_TYPE_PARTICLES;
-			item->index = i;
-			++item;
-		}
-	}
-}
-
-void BKE_cache_item_iter_init(CacheLibraryItemsIterator *iter, Object *ob)
-{
-	iter->ob = ob;
-	iter->totitems = cache_count_items(ob);
-	iter->items = MEM_mallocN(sizeof(CacheItem) * iter->totitems, "object cache items");
-	cache_make_items(ob, iter->items);
-	
-	iter->cur = iter->items;
-}
-
-bool BKE_cache_item_iter_valid(CacheLibraryItemsIterator *iter)
-{
-	return (int)(iter->cur - iter->items) < iter->totitems;
-}
-
-void BKE_cache_item_iter_next(CacheLibraryItemsIterator *iter)
-{
-	++iter->cur;
-}
-
-void BKE_cache_item_iter_end(CacheLibraryItemsIterator *iter)
-{
-	if (iter->items)
-		MEM_freeN(iter->items);
-}
-
-/* ========================================================================= */
-
-BLI_INLINE unsigned int hash_int_2d(unsigned int kx, unsigned int ky)
-{
-#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
-
-	unsigned int a, b, c;
-
-	a = b = c = 0xdeadbeef + (2 << 2) + 13;
-	a += kx;
-	b += ky;
-
-	c ^= b; c -= rot(b,14);
-	a ^= c; a -= rot(c,11);
-	b ^= a; b -= rot(a,25);
-	c ^= b; c -= rot(b,16);
-	a ^= c; a -= rot(c,4);
-	b ^= a; b -= rot(a,14);
-	c ^= b; c -= rot(b,24);
-
-	return c;
-
-#undef rot
-}
-
-static unsigned int cache_item_hash(const void *key)
-{
-	const CacheItem *item = key;
-	unsigned int hash;
-	
-	hash = BLI_ghashutil_inthash(item->type);
-	
-	if (item->ob)
-		hash = hash_int_2d(hash, BLI_ghashutil_ptrhash(item->ob));
-	if (item->index >= 0)
-		hash = hash_int_2d(hash, BLI_ghashutil_inthash(item->index));
-	
-	return hash;
-}
-
-static bool cache_item_cmp(const void *key_a, const void *key_b)
-{
-	const CacheItem *item_a = key_a, *item_b = key_b;
-	
-	if (item_a->type != item_b->type)
-		return true;
-	if (item_a->ob != item_b->ob)
-		return true;
-	if (item_a->index >= 0 || item_b->index >= 0) {
-		if (item_a->index != item_b->index)
-			return true;
-	}
-	
-	return false;
-}
-
-BLI_INLINE void print_cachelib_items(CacheLibrary *cachelib)
-{
-	CacheItem *it

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list