[Bf-blender-cvs] [89ea3e7] alembic: New modifier system for cache libraries.

Lukas Tönne noreply at git.blender.org
Fri Mar 27 11:22:05 CET 2015


Commit: 89ea3e73ee08804bd3c6f0f322e5634fb3a73da1
Author: Lukas Tönne
Date:   Thu Mar 26 15:52:34 2015 +0100
Branches: alembic
https://developer.blender.org/rB89ea3e73ee08804bd3c6f0f322e5634fb3a73da1

New modifier system for cache libraries.

This system imitates the modifier stack for mesh objects. It will be
used to handle simulations and similar processing of cached data.

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

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/modifier.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/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_access.h
M	source/blender/makesrna/RNA_enum_types.h
M	source/blender/makesrna/intern/rna_cache_library.c

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

diff --git a/release/scripts/startup/bl_ui/properties_object.py b/release/scripts/startup/bl_ui/properties_object.py
index a36d321..8fd90b9 100644
--- a/release/scripts/startup/bl_ui/properties_object.py
+++ b/release/scripts/startup/bl_ui/properties_object.py
@@ -326,6 +326,15 @@ def cachelib_object_items(cachelib, ob):
 class OBJECT_PT_duplication(ObjectButtonsPanel, Panel):
     bl_label = "Duplication"
 
+    def draw_cache_modifier(self, context, layout, cachelib, md):
+        row = layout.row(align=True)
+        row.context_pointer_set("cache_modifier", md)
+        row.prop(md, "name", text="")
+        row.operator("cachelibrary.remove_modifier", icon='X', text="", emboss=False)
+
+        # match enum type to our functions, avoids a lookup table.
+        getattr(self, md.type)(layout, cachelib, md)
+
     def draw_cachelib(self, context, layout, ob, cachelib, objects):
         col = layout.column(align=True)
         colrow = col.row(align=True)
@@ -361,6 +370,12 @@ class OBJECT_PT_duplication(ObjectButtonsPanel, Panel):
                 row = layout.row(align=True)
                 row.alignment = 'LEFT'
                 row.template_cache_library_item(cachelib, ob, item_type, item_index, enable)
+    
+        layout.operator_menu_enum("cachelibrary.add_modifier", "type")
+
+        for md in cachelib.modifiers:
+            box = layout.box()
+            self.draw_cache_modifier(context, box, cachelib, md)
 
     def draw(self, context):
         layout = self.layout
@@ -401,6 +416,9 @@ class OBJECT_PT_duplication(ObjectButtonsPanel, Panel):
                 cache_objects = cachelib_objects(ob.cache_library, ob.dupli_group)
                 self.draw_cachelib(context, layout, ob, ob.cache_library, cache_objects)
 
+    def HAIR_SIMULATION(self, layout, cachelib, md):
+        pass
+
 
 class OBJECT_PT_relations_extras(ObjectButtonsPanel, Panel):
     bl_label = "Relations Extras"
diff --git a/source/blender/blenkernel/BKE_cache_library.h b/source/blender/blenkernel/BKE_cache_library.h
index 48e2e7f..32484fc 100644
--- a/source/blender/blenkernel/BKE_cache_library.h
+++ b/source/blender/blenkernel/BKE_cache_library.h
@@ -42,6 +42,8 @@ struct EvaluationContext;
 struct ParticleSystem;
 struct DupliCache;
 struct DupliObjectData;
+struct CacheModifier;
+struct ID;
 
 struct ClothModifierData;
 
@@ -106,4 +108,73 @@ bool BKE_cache_read_dupli_cache(struct Scene *scene, float frame, eCacheLibrary_
 bool BKE_cache_read_dupli_object(struct Scene *scene, float frame, eCacheLibrary_EvalMode eval_mode,
                                  struct Object *ob, struct DupliObjectData *data, struct CacheLibrary *cachelib);
 
+/* ========================================================================= */
+
+typedef void (*CacheModifier_IDWalkFunc)(void *userdata, struct CacheLibrary *cachelib, struct CacheModifier *md, struct ID **id_ptr);
+
+typedef void (*CacheModifier_InitFunc)(struct CacheModifier *md);
+typedef void (*CacheModifier_FreeFunc)(struct CacheModifier *md);
+typedef void (*CacheModifier_CopyFunc)(struct CacheModifier *md, struct CacheModifier *target);
+typedef void (*CacheModifier_ForeachIDLinkFunc)(struct CacheModifier *md, struct CacheLibrary *cachelib,
+                                                CacheModifier_IDWalkFunc walk, void *userData);
+
+typedef struct CacheModifierTypeInfo {
+	/* The user visible name for this modifier */
+	char name[32];
+
+	/* The DNA struct name for the modifier data type,
+	 * used to write the DNA data out.
+	 */
+	char struct_name[32];
+
+	/* The size of the modifier data type, used by allocation. */
+	int struct_size;
+
+	/********************* Non-optional functions *********************/
+
+	/* Copy instance data for this modifier type. Should copy all user
+	 * level settings to the target modifier.
+	 */
+	CacheModifier_CopyFunc copy;
+
+	/* Should call the given walk function with a pointer to each ID
+	 * pointer (i.e. each datablock pointer) that the modifier data
+	 * stores. This is used for linking on file load and for
+	 * unlinking datablocks or forwarding datablock references.
+	 *
+	 * This function is optional.
+	 */
+	CacheModifier_ForeachIDLinkFunc foreachIDLink;
+
+	/********************* Optional functions *********************/
+
+	/* Initialize new instance data for this modifier type, this function
+	 * should set modifier variables to their default values.
+	 * 
+	 * This function is optional.
+	 */
+	CacheModifier_InitFunc init;
+
+	/* Free internal modifier data variables, this function should
+	 * not free the md variable itself.
+	 *
+	 * This function is optional.
+	 */
+	CacheModifier_FreeFunc free;
+} CacheModifierTypeInfo;
+
+void BKE_cache_modifier_init(void);
+
+const char *BKE_cache_modifier_type_name(eCacheModifier_Type type);
+const char *BKE_cache_modifier_type_struct_name(eCacheModifier_Type type);
+int BKE_cache_modifier_type_struct_size(eCacheModifier_Type type);
+
+bool BKE_cache_modifier_unique_name(struct ListBase *modifiers, struct CacheModifier *md);
+struct CacheModifier *BKE_cache_modifier_add(struct CacheLibrary *cachelib, const char *name, eCacheModifier_Type type);
+void BKE_cache_modifier_remove(struct CacheLibrary *cachelib, struct CacheModifier *md);
+void BKE_cache_modifier_clear(struct CacheLibrary *cachelib);
+struct CacheModifier *BKE_cache_modifier_copy(struct CacheLibrary *cachelib, struct CacheModifier *md);
+
+void BKE_cache_modifier_foreachIDLink(struct CacheLibrary *cachelib, struct CacheModifier *md, CacheModifier_IDWalkFunc walk, void *userdata);
+
 #endif
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index 52ab72d..90f7081 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -56,6 +56,8 @@
 #include "BKE_main.h"
 #include "BKE_modifier.h"
 
+#include "BLF_translation.h"
+
 #include "PTC_api.h"
 
 CacheLibrary *BKE_cache_library_add(Main *bmain, const char *name)
@@ -84,6 +86,14 @@ CacheLibrary *BKE_cache_library_copy(CacheLibrary *cachelib)
 	/* hash table will be rebuilt when needed */
 	cachelibn->items_hash = NULL;
 	
+	{
+		CacheModifier *md;
+		BLI_listbase_clear(&cachelibn->modifiers);
+		for (md = cachelib->modifiers.first; md; md = md->next) {
+			BKE_cache_modifier_copy(cachelibn, md);
+		}
+	}
+	
 	if (cachelib->id.lib) {
 		BKE_id_lib_local_paths(G.main, cachelib->id.lib, &cachelibn->id);
 	}
@@ -96,6 +106,8 @@ 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);
 }
 
 void BKE_cache_library_unlink(CacheLibrary *UNUSED(cachelib))
@@ -746,3 +758,156 @@ void BKE_cache_library_dag_recalc_tag(EvaluationContext *eval_ctx, Main *bmain)
 	}
 #endif
 }
+
+/* ========================================================================= */
+
+CacheModifierTypeInfo cache_modifier_types[NUM_CACHE_MODIFIER_TYPES];
+
+static CacheModifierTypeInfo *cache_modifier_type_get(eCacheModifier_Type type)
+{
+	return &cache_modifier_types[type];
+}
+
+static void cache_modifier_type_set(eCacheModifier_Type type, CacheModifierTypeInfo *mti)
+{
+	memcpy(&cache_modifier_types[type], mti, sizeof(CacheModifierTypeInfo));
+}
+
+const char *BKE_cache_modifier_type_name(eCacheModifier_Type type)
+{
+	return cache_modifier_type_get(type)->name;
+}
+
+const char *BKE_cache_modifier_type_struct_name(eCacheModifier_Type type)
+{
+	return cache_modifier_type_get(type)->struct_name;
+}
+
+int BKE_cache_modifier_type_struct_size(eCacheModifier_Type type)
+{
+	return cache_modifier_type_get(type)->struct_size;
+}
+
+/* ------------------------------------------------------------------------- */
+
+bool BKE_cache_modifier_unique_name(ListBase *modifiers, CacheModifier *md)
+{
+	if (modifiers && md) {
+		CacheModifierTypeInfo *mti = cache_modifier_type_get(md->type);
+
+		return BLI_uniquename(modifiers, md, DATA_(mti->name), '.', offsetof(CacheModifier, name), sizeof(md->name));
+	}
+	return false;
+}
+
+CacheModifier *BKE_cache_modifier_add(CacheLibrary *cachelib, const char *name, eCacheModifier_Type type)
+{
+	CacheModifierTypeInfo *mti = cache_modifier_type_get(type);
+	
+	CacheModifier *md = MEM_callocN(mti->struct_size, "cache modifier");
+	
+	if (!name)
+		name = mti->name;
+	BLI_strncpy_utf8(md->name, name, sizeof(md->name));
+	/* make sure modifier has unique name */
+	BKE_cache_modifier_unique_name(&cachelib->modifiers, md);
+	
+	if (mti->init)
+		mti->init(md);
+	
+	BLI_addtail(&cachelib->modifiers, md);
+	
+	return md;
+}
+
+void BKE_cache_modifier_remove(CacheLibrary *cachelib, CacheModifier *md)
+{
+	CacheModifierTypeInfo *mti = cache_modifier_type_get(md->type);
+	
+	BLI_remlink(&cachelib->modifiers, md);
+	
+	if (mti->free)
+		mti->free(md);
+	
+	MEM_freeN(md);
+}
+
+void BKE_cache_modifier_clear(CacheLibrary *cachelib)
+{
+	CacheModifier *md, *md_next;
+	for (md = cachelib->modifiers.first; md; md = md_next) {
+		CacheModifierTypeInfo *mti = cache_modifier_type_get(md->type);
+		md_next = md->next;
+		
+		if (mti->free)
+			mti->free(md);
+		
+		MEM_freeN(md);
+	}
+	
+	BLI_listbase_clear(&cachelib->modifiers);
+}
+
+CacheModifier *BKE_cache_modifier_copy(CacheLibrary *cachelib, CacheModifier *md)
+{
+	CacheModifierTypeInfo *mti = cache_modifier_type_get(md->type);
+	
+	CacheModifier *tmd = MEM_dupallocN(md);
+	
+	if (mti->copy)
+		mti->copy(md, tmd);
+	
+	BLI_addtail(&cachelib->modifiers, md);
+	
+	return tmd;
+}
+
+void BKE_cache_modifier_foreachIDLink(struct CacheLibrary *cachelib, struct CacheModifier *md, CacheModifier_IDWalkFunc walk, void *userdata)
+{
+	CacheModifierTypeInfo *mti = cache_modifier_type_get(md->type);
+	
+	if (mti->foreachIDLink)
+		mti->foreachIDLink(md, cachelib, walk, userdata);
+	
+	
+}
+
+/* ------------------------------------------------------------------------- */
+
+#if 0
+void BKE_cache_modifier_type_init(CacheModifierTypeInfo *mti, const char *name, const char *struct_name, int struct_size,
+                                  CacheModifier_InitFunc init, CacheModifier_FreeFunc free, CacheModifier_CopyFunc copy)
+{
+	mti->nam

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list