[Bf-blender-cvs] [dbc4be3] alembic: New cache modifier type "Strands Key" for implementing shape keys on cached strands data.

Lukas Tönne noreply at git.blender.org
Sun May 3 18:29:56 CEST 2015


Commit: dbc4be381d4fb44d2915d6d78588fa860cff8bd1
Author: Lukas Tönne
Date:   Sun May 3 12:13:03 2015 +0200
Branches: alembic
https://developer.blender.org/rBdbc4be381d4fb44d2915d6d78588fa860cff8bd1

New cache modifier type "Strands Key" for implementing shape keys on
cached strands data.

This modifier acts as a container for shape key data (i.e. as part of
the cache library). Such shape data can be applied to cached strands
data, which allows tweaking of animated hair shapes.

This could work both as a shape for the strand goals (adding dynamics
on top) or as a final modification after dynamics. Both methods have
their advantages (pre-sim allows control and sim at the same time,
post-sim gives accurate shapes but becomes rigid).

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

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

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

diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index 8d59020..e5d781ea 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -1218,11 +1218,58 @@ CacheModifierTypeInfo cacheModifierType_ShrinkWrap = {
     /* free */              (CacheModifier_FreeFunc)shrinkwrap_free,
 };
 
+/* ------------------------------------------------------------------------- */
+
+static void strandskey_init(StrandsKeyCacheModifier *skmd)
+{
+	skmd->object = NULL;
+	skmd->hair_system = -1;
+}
+
+static void strandskey_copy(StrandsKeyCacheModifier *UNUSED(skmd), StrandsKeyCacheModifier *UNUSED(tskmd))
+{
+}
+
+static void strandskey_free(StrandsKeyCacheModifier *UNUSED(skmd))
+{
+}
+
+static void strandskey_foreach_id_link(StrandsKeyCacheModifier *skmd, CacheLibrary *cachelib, CacheModifier_IDWalkFunc walk, void *userdata)
+{
+	walk(userdata, cachelib, &skmd->modifier, (ID **)(&skmd->object));
+}
+
+static void strandskey_process(StrandsKeyCacheModifier *skmd, CacheProcessContext *UNUSED(ctx), CacheProcessData *data, int frame, int frame_prev, eCacheLibrary_EvalMode UNUSED(eval_mode))
+{
+	Object *ob = skmd->object;
+	Strands *strands;
+	
+	/* skip first step and potential backward steps */
+	if (frame <= frame_prev)
+		return;
+	
+	if (!BKE_cache_modifier_find_strands(data->dupcache, ob, skmd->hair_system, NULL, &strands))
+		return;
+}
+
+CacheModifierTypeInfo cacheModifierType_StrandsKey = {
+    /* name */              "StrandsKey",
+    /* structName */        "StrandsKeyCacheModifier",
+    /* structSize */        sizeof(StrandsKeyCacheModifier),
+
+    /* copy */              (CacheModifier_CopyFunc)strandskey_copy,
+    /* foreachIDLink */     (CacheModifier_ForeachIDLinkFunc)strandskey_foreach_id_link,
+    /* process */           (CacheModifier_ProcessFunc)strandskey_process,
+    /* init */              (CacheModifier_InitFunc)strandskey_init,
+    /* free */              (CacheModifier_FreeFunc)strandskey_free,
+};
+
 void BKE_cache_modifier_init(void)
 {
 	cache_modifier_type_set(eCacheModifierType_HairSimulation, &cacheModifierType_HairSimulation);
 	cache_modifier_type_set(eCacheModifierType_ForceField, &cacheModifierType_ForceField);
 	cache_modifier_type_set(eCacheModifierType_ShrinkWrap, &cacheModifierType_ShrinkWrap);
+	cache_modifier_type_set(eCacheModifierType_StrandsKey, &cacheModifierType_StrandsKey);
 }
 
 /* ========================================================================= */
diff --git a/source/blender/makesdna/DNA_cache_library_types.h b/source/blender/makesdna/DNA_cache_library_types.h
index cb074de..5d98dee 100644
--- a/source/blender/makesdna/DNA_cache_library_types.h
+++ b/source/blender/makesdna/DNA_cache_library_types.h
@@ -169,6 +169,7 @@ typedef enum eCacheModifier_Type {
 	eCacheModifierType_HairSimulation               = 1,
 	eCacheModifierType_ForceField                   = 2,
 	eCacheModifierType_ShrinkWrap                   = 3,
+	eCacheModifierType_StrandsKey                      = 4,
 	
 	NUM_CACHE_MODIFIER_TYPES
 } eCacheModifier_Type;
@@ -229,4 +230,14 @@ typedef struct ShrinkWrapCacheModifier {
 	struct Object *target;
 } ShrinkWrapCacheModifier;
 
+typedef struct StrandsKeyCacheModifier {
+	CacheModifier modifier;
+	
+	struct Object *object;
+	int hair_system;
+	int pad;
+	
+	struct Key *key;
+} StrandsKeyCacheModifier;
+
 #endif
diff --git a/source/blender/makesrna/intern/rna_cache_library.c b/source/blender/makesrna/intern/rna_cache_library.c
index f205433..625c9f6 100644
--- a/source/blender/makesrna/intern/rna_cache_library.c
+++ b/source/blender/makesrna/intern/rna_cache_library.c
@@ -59,6 +59,7 @@ EnumPropertyItem cache_modifier_type_items[] = {
     {eCacheModifierType_HairSimulation, "HAIR_SIMULATION", ICON_HAIR, "Hair Simulation", ""},
     {eCacheModifierType_ForceField, "FORCE_FIELD", ICON_FORCE_FORCE, "Force Field", ""},
     {eCacheModifierType_ShrinkWrap, "SHRINK_WRAP", ICON_MOD_SHRINKWRAP, "Shrink Wrap", ""},
+    {eCacheModifierType_StrandsKey, "STRANDS_KEY", ICON_SHAPEKEY_DATA, "Strands Key", "Shape key for strands"},
     {0, NULL, 0, NULL, NULL}
 };
 
@@ -122,6 +123,8 @@ static StructRNA *rna_CacheModifier_refine(struct PointerRNA *ptr)
 			return &RNA_ForceFieldCacheModifier;
 		case eCacheModifierType_ShrinkWrap:
 			return &RNA_ShrinkWrapCacheModifier;
+		case eCacheModifierType_StrandsKey:
+			return &RNA_StrandsKeyCacheModifier;
 			
 		/* Default */
 		case eCacheModifierType_None:
@@ -270,6 +273,37 @@ static int rna_ShrinkWrapCacheModifier_hair_system_poll(PointerRNA *ptr, Pointer
 	return true;
 }
 
+static PointerRNA rna_StrandsKeyCacheModifier_hair_system_get(PointerRNA *ptr)
+{
+	StrandsKeyCacheModifier *skmd = ptr->data;
+	ParticleSystem *psys = skmd->object ? BLI_findlink(&skmd->object->particlesystem, skmd->hair_system) : NULL;
+	PointerRNA value;
+	
+	RNA_pointer_create(ptr->id.data, &RNA_ParticleSystem, psys, &value);
+	return value;
+}
+
+static void rna_StrandsKeyCacheModifier_hair_system_set(PointerRNA *ptr, PointerRNA value)
+{
+	StrandsKeyCacheModifier *skmd = ptr->data;
+	ParticleSystem *psys = value.data;
+	skmd->hair_system = skmd->object ? BLI_findindex(&skmd->object->particlesystem, psys) : -1;
+}
+
+static int rna_StrandsKeyCacheModifier_hair_system_poll(PointerRNA *ptr, PointerRNA value)
+{
+	StrandsKeyCacheModifier *skmd = ptr->data;
+	ParticleSystem *psys = value.data;
+	
+	if (!skmd->object)
+		return false;
+	if (BLI_findindex(&skmd->object->particlesystem, psys) == -1)
+		return false;
+	if (!psys->part || psys->part->type != PART_HAIR)
+		return false;
+	return true;
+}
+
 static void rna_CacheArchiveInfoNode_bytes_size_get(PointerRNA *ptr, char *value)
 {
 	CacheArchiveInfoNode *node = ptr->data;
@@ -503,6 +537,37 @@ static void rna_def_cache_modifier_shrink_wrap(BlenderRNA *brna)
 	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
 }
 
+static void rna_def_cache_modifier_strands_key(BlenderRNA *brna)
+{
+	StructRNA *srna;
+	PropertyRNA *prop;
+	
+	srna = RNA_def_struct(brna, "StrandsKeyCacheModifier", "CacheLibraryModifier");
+	RNA_def_struct_sdna(srna, "StrandsKeyCacheModifier");
+	RNA_def_struct_ui_text(srna, "Strands Key Cache Modifier", "");
+	RNA_def_struct_ui_icon(srna, ICON_SHAPEKEY_DATA);
+	
+	prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
+	RNA_def_property_pointer_sdna(prop, NULL, "object");
+	RNA_def_property_struct_type(prop, "Object");
+	RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_CacheLibraryModifier_hair_object_poll");
+	RNA_def_property_flag(prop, PROP_EDITABLE);
+	RNA_def_property_ui_text(prop, "Object", "Object whose cache to simulate");
+	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
+	
+	prop = RNA_def_property(srna, "hair_system_index", PROP_INT, PROP_NONE);
+	RNA_def_property_int_sdna(prop, NULL, "hair_system");
+	RNA_def_property_ui_text(prop, "Hair System Index", "Hair system cache to simulate");
+	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
+	
+	prop = RNA_def_property(srna, "hair_system", PROP_POINTER, PROP_NONE);
+	RNA_def_property_pointer_funcs(prop, "rna_StrandsKeyCacheModifier_hair_system_get", "rna_StrandsKeyCacheModifier_hair_system_set", NULL, "rna_StrandsKeyCacheModifier_hair_system_poll");
+	RNA_def_property_struct_type(prop, "ParticleSystem");
+	RNA_def_property_flag(prop, PROP_EDITABLE);
+	RNA_def_property_ui_text(prop, "Hair System", "Hair system cache to simulate");
+	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
+}
+
 static void rna_def_cache_modifier(BlenderRNA *brna)
 {
 	StructRNA *srna;
@@ -530,6 +595,7 @@ static void rna_def_cache_modifier(BlenderRNA *brna)
 	rna_def_cache_modifier_hair_simulation(brna);
 	rna_def_cache_modifier_force_field(brna);
 	rna_def_cache_modifier_shrink_wrap(brna);
+	rna_def_cache_modifier_strands_key(brna);
 }
 
 static void rna_def_cache_library_modifiers(BlenderRNA *brna, PropertyRNA *cprop)




More information about the Bf-blender-cvs mailing list