[Bf-blender-cvs] [d1e3ba22a03] tmp-CollectionsAnim: Collections: Initial support for animating/driving collection properties (T55233)

Joshua Leung noreply at git.blender.org
Sat Jun 2 20:03:52 CEST 2018


Commit: d1e3ba22a03c5b30b39acbf6ea66978379e116d6
Author: Joshua Leung
Date:   Tue May 29 11:47:47 2018 +0200
Branches: tmp-CollectionsAnim
https://developer.blender.org/rBd1e3ba22a03c5b30b39acbf6ea66978379e116d6

Collections: Initial support for animating/driving collection properties (T55233)

(Just committing this now to a temp branch so that I can continue working on this
from another machine later. This is a re-based+squashed, re-pushed version of what
I just pushed earlier, but now based on current 2.8 code, not from several days ago)

Rationale:
The Spring team needs a way to hide objects from the viewport, so that parts of
the rig can be enabled/disabled per shot. An example of this is how the cornea
meshes are typically hidden from the viewport so that the animators can see
the irises, and hence, where the character is looking.

(Another reason we may want this in future is to make it so that a bunch of
objects/rigs can be keyframed together in the same action, making it easier
to manage their actions)

Status:
* Currently all necessary data and animation editor support changes should be
  in place and working. Hopefully I haven't missed any - the checklist may need
  updating for 2.8

* Depsgraph support however is still incomplete. We still need to figure out what
  needs to happen with the animated values to make objects actually appear/disappear
  when triggered via the animation system, just like they do now from the UIwip

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

M	source/blender/blenkernel/intern/anim_sys.c
M	source/blender/blenkernel/intern/collection.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
M	source/blender/depsgraph/intern/builder/deg_builder_relations.cc
M	source/blender/editors/animation/anim_channels_defines.c
M	source/blender/editors/animation/anim_channels_edit.c
M	source/blender/editors/animation/anim_filter.c
M	source/blender/editors/include/ED_anim_api.h
M	source/blender/editors/space_action/action_draw.c
M	source/blender/editors/space_nla/nla_buttons.c
M	source/blender/editors/space_nla/nla_channels.c
M	source/blender/makesdna/DNA_group_types.h
M	source/blender/makesrna/intern/rna_group.c

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

diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c
index e5a68fa7476..22db91190a5 100644
--- a/source/blender/blenkernel/intern/anim_sys.c
+++ b/source/blender/blenkernel/intern/anim_sys.c
@@ -104,6 +104,7 @@ bool id_type_can_have_animdata(const short id_type)
 		case ID_MSK:
 		case ID_GD:
 		case ID_CF:
+		case ID_GR:
 			return true;
 		
 		/* no AnimData */
@@ -1135,6 +1136,9 @@ void BKE_animdata_main_cb(Main *mainptr, ID_AnimData_Edit_Callback func, void *u
 	/* masks */
 	ANIMDATA_IDS_CB(mainptr->mask.first);
 	
+	/* collections */
+	ANIMDATA_IDS_CB(mainptr->collection.first);
+	
 	/* worlds */
 	ANIMDATA_NODETREE_IDS_CB(mainptr->world.first, World);
 
@@ -1234,6 +1238,9 @@ void BKE_animdata_fix_paths_rename_all(ID *ref_id, const char *prefix, const cha
 	/* worlds */
 	RENAMEFIX_ANIM_NODETREE_IDS(mainptr->world.first, World);
 	
+	/* collections */
+	RENAMEFIX_ANIM_IDS(mainptr->collection.first);
+	
 	/* linestyles */
 	RENAMEFIX_ANIM_IDS(mainptr->linestyle.first);
 	
@@ -2935,6 +2942,9 @@ void BKE_animsys_evaluate_all_animation(Main *main, Depsgraph *depsgraph, Scene
 	/* masks */
 	EVAL_ANIM_IDS(main->mask.first, ADT_RECALC_ANIM);
 	
+	/* collections */
+	EVAL_ANIM_IDS(main->collection.first, ADT_RECALC_ANIM);
+	
 	/* worlds */
 	EVAL_ANIM_NODETREE_IDS(main->world.first, World, ADT_RECALC_ANIM);
 	
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index c4709a32f78..295b7d39f13 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -35,6 +35,7 @@
 #include "BLT_translation.h"
 #include "BLI_string_utils.h"
 
+#include "BKE_animsys.h"
 #include "BKE_collection.h"
 #include "BKE_icons.h"
 #include "BKE_idprop.h"
@@ -112,7 +113,8 @@ Collection *BKE_collection_add(Main *bmain, Collection *collection_parent, const
 /** Free (or release) any data used by this collection (does not free the collection itself). */
 void BKE_collection_free(Collection *collection)
 {
-	/* No animdata here. */
+	BKE_animdata_free(&collection->id, false);
+
 	BKE_previewimg_free(&collection->preview);
 
 	BLI_freelistN(&collection->gobject);
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index d2542e977e3..8f0c470929e 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -5679,6 +5679,9 @@ static void direct_link_collection(FileData *fd, Collection *collection)
 	link_list(fd, &collection->gobject);
 	link_list(fd, &collection->children);
 
+	collection->adt = newdataadr(fd, collection->adt);
+	direct_link_animdata(fd, collection->adt);
+
 	collection->preview = direct_link_preview_image(fd, collection->preview);
 
 	collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE;
@@ -5733,6 +5736,7 @@ static void lib_link_collection(FileData *fd, Main *main)
 		if (collection->id.tag & LIB_TAG_NEED_LINK) {
 			collection->id.tag &= ~LIB_TAG_NEED_LINK;
 			IDP_LibLinkProperty(collection->id.properties, fd);
+			lib_link_animdata(fd, &collection->id, collection->adt);
 
 #ifdef USE_COLLECTION_COMPAT_28
 			if (collection->collection) {
@@ -9272,6 +9276,10 @@ static void expand_particlesettings(FileData *fd, Main *mainvar, ParticleSetting
 
 static void expand_collection(FileData *fd, Main *mainvar, Collection *collection)
 {
+	if (collection->adt) {
+		expand_animdata(fd, mainvar, collection->adt);
+	}
+	
 	for (CollectionObject *cob = collection->gobject.first; cob; cob = cob->next) {
 		expand_doit(fd, mainvar, cob->ob);
 	}
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index de1699e24b7..e47a5ec2823 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2376,6 +2376,10 @@ static void write_collection(WriteData *wd, Collection *collection)
 		/* write LibData */
 		writestruct(wd, ID_GR, Collection, 1, collection);
 		write_iddata(wd, &collection->id);
+		
+		if (collection->adt) {
+			write_animdata(wd, collection->adt);
+		}
 
 		write_collection_nolib(wd, collection);
 	}
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
index 5867e278c78..a746b00b548 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
@@ -435,6 +435,8 @@ void DepsgraphNodeBuilder::build_collection(Collection *collection)
 	LISTBASE_FOREACH (CollectionChild *, child, &collection->children) {
 		build_collection(child->collection);
 	}
+	/* Build animation data. */
+	build_animdata(&collection->id);
 
 	add_id_node(&collection->id);
 }
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
index d5ea8103742..acb599ce46e 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
@@ -444,6 +444,8 @@ void DepsgraphRelationBuilder::build_collection(Object *object, Collection *coll
 		LISTBASE_FOREACH (CollectionChild *, child, &collection->children) {
 			build_collection(NULL, child->collection);
 		}
+		/* Animation data - should only need one set of relations per collection, not once per instance */
+		build_animdata(&collection->id);
 	}
 	if (object != NULL) {
 		const ListBase group_objects = BKE_collection_object_cache_get(collection);
diff --git a/source/blender/editors/animation/anim_channels_defines.c b/source/blender/editors/animation/anim_channels_defines.c
index d48798ece97..23009ae5385 100644
--- a/source/blender/editors/animation/anim_channels_defines.c
+++ b/source/blender/editors/animation/anim_channels_defines.c
@@ -626,6 +626,111 @@ static bAnimChannelType ACF_SCENE =
 	acf_scene_setting_ptr           /* pointer for setting */
 };
 
+/* Collection ------------------------------------------- */
+
+// TODO: just get this from RNA?
+static int acf_collection_icon(bAnimListElem *UNUSED(ale))
+{
+	return ICON_GROUP;
+}
+
+/* check if some setting exists for this channel */
+static bool acf_collection_setting_valid(bAnimContext *ac, bAnimListElem *UNUSED(ale), eAnimChannel_Settings setting)
+{
+	switch (setting) {
+		/* muted only in NLA */
+		case ACHANNEL_SETTING_MUTE: 
+			return ((ac) && (ac->spacetype == SPACE_NLA));
+			
+		/* visible only in Graph Editor */
+		case ACHANNEL_SETTING_VISIBLE: 
+			return ((ac) && (ac->spacetype == SPACE_IPO));
+		
+		/* only select and expand supported otherwise */
+		case ACHANNEL_SETTING_SELECT:
+		case ACHANNEL_SETTING_EXPAND:
+			return true;
+
+		case ACHANNEL_SETTING_ALWAYS_VISIBLE:
+			return false;
+
+		default:
+			return false;
+	}
+}
+
+/* get the appropriate flag(s) for the setting when it is valid  */
+static int acf_collection_setting_flag(bAnimContext *UNUSED(ac), eAnimChannel_Settings setting, bool *neg)
+{
+	/* clear extra return data first */
+	*neg = false;
+	
+	switch (setting) {
+		case ACHANNEL_SETTING_SELECT: /* selected */
+			return COLLECTION_DS_SELECTED;
+			
+		case ACHANNEL_SETTING_EXPAND: /* expanded */
+			*neg = true;
+			return COLLECTION_DS_COLLAPSED;
+			
+		case ACHANNEL_SETTING_MUTE: /* mute (only in NLA) */
+			return ADT_NLA_EVAL_OFF;
+			
+		case ACHANNEL_SETTING_VISIBLE: /* visible (only in Graph Editor) */
+			*neg = true;
+			return ADT_CURVES_NOT_VISIBLE;
+
+		default: /* unsupported */
+			return 0;
+	}
+}
+
+/* get pointer to the setting */
+static void *acf_collection_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings setting, short *type)
+{
+	Collection *collection = (Collection *)ale->data;
+	
+	/* clear extra return data first */
+	*type = 0;
+	
+	switch (setting) {
+		case ACHANNEL_SETTING_SELECT: /* selected */
+			return GET_ACF_FLAG_PTR(collection->flag, type);
+			
+		case ACHANNEL_SETTING_EXPAND: /* expanded */
+			return GET_ACF_FLAG_PTR(collection->flag, type);
+		
+		case ACHANNEL_SETTING_MUTE: /* mute (only in NLA) */
+		case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */
+			if (collection->adt)
+				return GET_ACF_FLAG_PTR(collection->adt->flag, type);
+			return NULL;
+			
+		default: /* unsupported */
+			return NULL;
+	}
+}
+
+/* collection type define */
+static bAnimChannelType ACF_COLLECTION = 
+{
+	"Collection",                   /* type name */
+	ACHANNEL_ROLE_EXPANDER,         /* role */
+
+	acf_generic_root_color,         /* backdrop color */
+	acf_generic_root_backdrop,      /* backdrop */
+	acf_generic_indention_0,        /* indent level */
+	NULL,                           /* offset */
+
+	acf_generic_idblock_name,       /* name */
+	acf_generic_idblock_name_prop,  /* name prop */
+	acf_collection_icon,            /* icon */
+
+	acf_collection_setting_valid,   /* has setting */
+	acf_collection_setting_flag,    /* flag for setting */
+	acf_collection_setting_ptr      /* pointer for setting */
+};
+
 /* Object ------------------------------------------- */
 
 static int acf_object_icon(bAnimListElem *ale)
@@ -3567,8 +3672,9 @@ static void ANIM_init_channel_typeinfo_data(void)
 		animchannelTypeInfo[type++] = &ACF_SUMMARY;      /* Motion Summary */
 		
 		animchannelTypeInfo[type++] = &ACF_SCENE;        /* Scene */
+		animchannelTypeInfo[type++] = &ACF_COLLECTION;   /* Collection */
 		animchannelTypeInfo[type++] = &ACF_OBJECT;       /* Object */
-		animchannelTypeInfo[type++] = &ACF_GROUP;        /* Group */
+		animchannelTypeInfo[type++] = &ACF_GROUP;        /* ActionGroup */
 		animchannelTypeInfo[type++] = &ACF_FCURVE;       /* F-Curve */
 		
 		animchannelTypeInfo[type++] = &ACF_NLACONTROLS;  /* NLA Control FCurve Expander */
diff --git a/source/blender/editors/animation/anim_channels_edit.c b/source/blender/editors/animation/anim_channels_edit.c
index 6d9a2d3b2b7..5b174d6506e 100644
--- a/source/blender/editors/animation/anim_channels_edit.c
+++ b/source/blender/editors/animation/anim_channels_edit.c
@@ -280,6 +280,10 @@ void ANIM_deselect_anim_channels(bAnimContext *ac, void *data, eAnimCont_Types d
 					if (ale->flag & SCE

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list