[Bf-blender-cvs] [b28a240] master: Action Editor: Added "Push Down" operator to send the current action on to the NLA Stack

Joshua Leung noreply at git.blender.org
Sat Feb 28 14:37:08 CET 2015


Commit: b28a24091facf64c93b5eee89d6595f32354545b
Author: Joshua Leung
Date:   Fri Feb 27 17:06:44 2015 +1300
Branches: master
https://developer.blender.org/rBb28a24091facf64c93b5eee89d6595f32354545b

Action Editor: Added "Push Down" operator to send the current action on to the NLA Stack

This commit exposes the "Push Down" button/functionality found in the NLA Editor
to the Action Editor, so that actions can be added NLA Stack from here too. The
main point of this for now is to make the whole layered-animation workflow nicer
more efficient, but not requiring the second editor be visible in common cases.
It also conveniently sets things up for the next few changes (already hinted at
here)...

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

M	release/scripts/startup/bl_ui/space_dopesheet.py
M	source/blender/editors/space_action/action_edit.c
M	source/blender/editors/space_action/action_intern.h
M	source/blender/editors/space_action/action_ops.c

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

diff --git a/release/scripts/startup/bl_ui/space_dopesheet.py b/release/scripts/startup/bl_ui/space_dopesheet.py
index e52d180..16dfb1d 100644
--- a/release/scripts/startup/bl_ui/space_dopesheet.py
+++ b/release/scripts/startup/bl_ui/space_dopesheet.py
@@ -124,6 +124,10 @@ class DOPESHEET_HT_header(Header):
         if st.mode in {'ACTION', 'SHAPEKEY'}:
             layout.template_ID(st, "action", new="action.new")
 
+            row = layout.row(align=True)
+            row.operator("action.push_down", text="", icon='NLA_PUSHDOWN')
+            row.operator("action.push_down", text="", icon='FREEZE') # XXX: "stash"
+
         # Grease Pencil mode doesn't need snapping, as it's frame-aligned only
         if st.mode != 'GPENCIL':
             layout.prop(st, "auto_snap", text="")
diff --git a/source/blender/editors/space_action/action_edit.c b/source/blender/editors/space_action/action_edit.c
index 28e10a9..e8ee993 100644
--- a/source/blender/editors/space_action/action_edit.c
+++ b/source/blender/editors/space_action/action_edit.c
@@ -42,6 +42,8 @@
 
 #include "DNA_anim_types.h"
 #include "DNA_gpencil_types.h"
+#include "DNA_key_types.h"
+#include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_mask_types.h"
 
@@ -52,6 +54,7 @@
 #include "BKE_action.h"
 #include "BKE_fcurve.h"
 #include "BKE_global.h"
+#include "BKE_key.h"
 #include "BKE_main.h"
 #include "BKE_nla.h"
 #include "BKE_context.h"
@@ -145,6 +148,87 @@ void ACTION_OT_new(wmOperatorType *ot)
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
+/* ******************* Action Push-Down Operator ******************** */
+
+/* Criteria:
+ *  1) There must be an dopesheet/action editor, and it must be in a mode which uses actions 
+ *  2) There must be an action active
+ *  3) The associated AnimData block must not be in tweakmode
+ */
+static int action_pushdown_poll(bContext *C)
+{
+	if (ED_operator_action_active(C)) {
+		SpaceAction *saction = (SpaceAction *)CTX_wm_space_data(C);
+		Scene *scene = CTX_data_scene(C);
+		Object *ob = CTX_data_active_object(C);
+		
+		/* Check for actions and that tweakmode is off */
+		if ((saction->action) && !(scene->flag & SCE_NLA_EDIT_ON)) {
+			/* For now, actions are only for the active object, and on object and shapekey levels... */
+			if (saction->mode == SACTCONT_ACTION) {
+				return (ob->adt != NULL);
+			}
+			else if (saction->mode == SACTCONT_SHAPEKEY) {
+				Key *key = BKE_key_from_object(ob);
+				
+				return (key && key->adt);
+			}
+		}	
+	}
+	
+	/* something failed... */
+	return false;
+}
+
+static int action_pushdown_exec(bContext *C, wmOperator *op)
+{
+	SpaceAction *saction = (SpaceAction *)CTX_wm_space_data(C);
+	Object *ob = CTX_data_active_object(C);
+	AnimData *adt = NULL;
+	
+	/* Get AnimData block to use */
+	if (saction->mode == SACTCONT_ACTION) {
+		/* Currently, "Action Editor" means object-level only... */
+		adt = ob->adt;
+	}
+	else if (saction->mode == SACTCONT_SHAPEKEY) {
+		Key *key = BKE_key_from_object(ob);
+		adt = key->adt;
+	}
+	
+	/* Do the deed... */
+	if (adt) {
+		/* Perform the pushdown operation
+		 * - This will deal with all the AnimData-side usercounts
+		 */
+		BKE_nla_action_pushdown(adt);
+		
+		/* Stop displaying this action in this editor
+		 * NOTE: The editor itself doesn't set a user...
+		 */
+		saction->action = NULL;
+	}
+	
+	/* Send notifiers that stuff has changed */
+	WM_event_add_notifier(C, NC_ANIMATION | ND_NLA_ACTCHANGE, NULL);
+	return OPERATOR_FINISHED;
+}
+
+void ACTION_OT_push_down(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Push Down Action";
+	ot->idname = "ACTION_OT_push_down";
+	ot->description = "Push action down on to the NLA stack as a new strip";
+	
+	/* callbacks */
+	ot->exec = action_pushdown_exec;
+	ot->poll = action_pushdown_poll;
+	
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
 /* ************************************************************************** */
 /* POSE MARKERS STUFF */
 
diff --git a/source/blender/editors/space_action/action_intern.h b/source/blender/editors/space_action/action_intern.h
index 8f39a38..8bade7a 100644
--- a/source/blender/editors/space_action/action_intern.h
+++ b/source/blender/editors/space_action/action_intern.h
@@ -101,6 +101,7 @@ void ACTION_OT_snap(struct wmOperatorType *ot);
 void ACTION_OT_mirror(struct wmOperatorType *ot);
 
 void ACTION_OT_new(struct wmOperatorType *ot);
+void ACTION_OT_push_down(struct wmOperatorType *ot);
 
 void ACTION_OT_markers_make_local(struct wmOperatorType *ot);
 
diff --git a/source/blender/editors/space_action/action_ops.c b/source/blender/editors/space_action/action_ops.c
index 0fbacef..76b0801 100644
--- a/source/blender/editors/space_action/action_ops.c
+++ b/source/blender/editors/space_action/action_ops.c
@@ -77,7 +77,9 @@ void action_operatortypes(void)
 	WM_operatortype_append(ACTION_OT_keyframe_insert);
 	WM_operatortype_append(ACTION_OT_copy);
 	WM_operatortype_append(ACTION_OT_paste);
+	
 	WM_operatortype_append(ACTION_OT_new);
+	WM_operatortype_append(ACTION_OT_push_down);
 	
 	WM_operatortype_append(ACTION_OT_previewrange_set);
 	WM_operatortype_append(ACTION_OT_view_all);




More information about the Bf-blender-cvs mailing list