[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20646] branches/soc-2009-aligorith/source /blender: NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both )

Joshua Leung aligorith at gmail.com
Fri Jun 5 07:18:07 CEST 2009


Revision: 20646
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20646
Author:   aligorith
Date:     2009-06-05 07:18:07 +0200 (Fri, 05 Jun 2009)

Log Message:
-----------
NLA SoC: Operators for 'tweaking' strip actions (TAB-Key for both)

In this commit, I've introduced the mechanism by which actions already referenced by strips used in the NLA can be edited (or 'tweaked'). To use, simply select a strip you wish to edit, and hit that TAB key to start tweaking that strip's action, and hit TAB again once you're done.


What happens when you enter 'tweak mode':
1) The action of the active strip temporarily becomes the 'active action' of the AnimData block. You are now able to edit this in one of the Animation Editors (DopeSheet/Action, Graph Editors) as per normal (i.e. sliding keyframes around, inserting keyframes, etc.). The 'action-line' will therefore get drawn immediately above the active track containing the active strip, so that it's clear that that's what we're editing.

2) All the NLA-tracks (and all the strips within them) that occur after the track that the active strip lived in get disabled while you're in tweakmode. This is equivalent to travelling back to an earlier state in a construction history stack.

3) The active NLA track also gets disabled while in tweakmode, since it would otherwise interfere with the correct functioning of the tweaking for the action of interest.

4) The 'real' active action (i.e. the one displaced by the active strip's action) gets put into temp storage, and will be restored after you exit tweakmode.

5) Any strips which also reference the action being tweaked will get highlighted in red shading to indicate that you may be making some changes to the action which you don't really want to make for the other users too.


Please note though, that this is only a rough prototype of this functionality, with some niceties still to come. i.e.:
* NLA-tracks after the active track should still get drawn above the 'tweaking action line', but perhaps with different appearance?
* Various tools will still need awareness of this to prevent corrupting operations from taking place. How to proceed is still undecided...
* When exiting tweak-mode, the strip the action came from still needs some form of syncing with the modified action... there are a few tricky issues here that will need to be solved
* Evaluation code doesn't totally take this into account yet...

---
Also, fixed a number of bugs with various code (notably selection, and also a few drawing bugs)

Modified Paths:
--------------
    branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h
    branches/soc-2009-aligorith/source/blender/blenkernel/intern/anim_sys.c
    branches/soc-2009-aligorith/source/blender/blenkernel/intern/nla.c
    branches/soc-2009-aligorith/source/blender/editors/animation/anim_channels.c
    branches/soc-2009-aligorith/source/blender/editors/animation/anim_filter.c
    branches/soc-2009-aligorith/source/blender/editors/include/ED_anim_api.h
    branches/soc-2009-aligorith/source/blender/editors/include/ED_screen.h
    branches/soc-2009-aligorith/source/blender/editors/screen/screen_ops.c
    branches/soc-2009-aligorith/source/blender/editors/space_action/action_select.c
    branches/soc-2009-aligorith/source/blender/editors/space_graph/graph_select.c
    branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_channels.c
    branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_draw.c
    branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_edit.c
    branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_intern.h
    branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_ops.c
    branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_select.c
    branches/soc-2009-aligorith/source/blender/makesdna/DNA_action_types.h
    branches/soc-2009-aligorith/source/blender/makesdna/DNA_anim_types.h
    branches/soc-2009-aligorith/source/blender/makesdna/DNA_scene_types.h

Modified: branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h
===================================================================
--- branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h	2009-06-05 04:15:19 UTC (rev 20645)
+++ branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h	2009-06-05 05:18:07 UTC (rev 20646)
@@ -59,9 +59,13 @@
 short BKE_nlatrack_has_space(struct NlaTrack *nlt, float start, float end);
 void BKE_nlatrack_sort_strips(struct NlaTrack *nlt);
 
+struct NlaStrip *BKE_nlastrip_find_active(struct NlaTrack *nlt);
 short BKE_nlastrip_within_bounds(struct NlaStrip *strip, float min, float max);
 
 void BKE_nla_action_pushdown(struct AnimData *adt);
 
+short BKE_nla_tweakmode_enter(struct AnimData *adt);
+void BKE_nla_tweakmode_exit(struct AnimData *adt);
+
 #endif
 

Modified: branches/soc-2009-aligorith/source/blender/blenkernel/intern/anim_sys.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/blenkernel/intern/anim_sys.c	2009-06-05 04:15:19 UTC (rev 20645)
+++ branches/soc-2009-aligorith/source/blender/blenkernel/intern/anim_sys.c	2009-06-05 05:18:07 UTC (rev 20646)
@@ -118,6 +118,9 @@
 			/* unlink action (don't free, as it's in its own list) */
 			if (adt->action)
 				adt->action->id.us--;
+			/* same goes for the temporarily displaced action */
+			if (adt->tmpact)
+				adt->tmpact->id.us--;
 				
 			/* free nla data */
 			free_nladata(&adt->nla_tracks);
@@ -151,6 +154,7 @@
 	// XXX review this... it might not be optimal behaviour yet...
 	//id_us_plus((ID *)dadt->action);
 	dadt->action= copy_action(adt->action);
+	dadt->tmpact= copy_action(adt->action);
 	
 	/* duplicate NLA data */
 	copy_nladata(&dadt->nla_tracks, &adt->nla_tracks);
@@ -595,7 +599,7 @@
 	scale = (float)fabs(strip->scale); /* scale must be positive - we've got a special flag for reversing */
 	
 	/* length of referenced action */
-	actlength = strip->actend-strip->actstart;
+	actlength = strip->actend - strip->actstart;
 	if (actlength == 0.0f) actlength = 1.0f;
 	
 	/* length of strip */
@@ -630,11 +634,11 @@
 	// the +0.0001 factors are to combat rounding errors
 	if (IS_EQ(strip->blendin, 0)==0 && (cframe <= (strip->start + strip->blendin))) {
 		/* there is some blend-in */
-		return (float)(fabs(cframe - strip->start) + 0.0001) / (strip->blendin);
+		return (float)fabs(cframe - strip->start) / (strip->blendin);
 	}
 	else if (IS_EQ(strip->blendout, 0)==0 && (cframe >= (strip->end - strip->blendout))) {
 		/* there is some blend-out */
-		return (float)(fabs(strip->end - cframe) + 0.0001) / (strip->blendout);
+		return (float)fabs(strip->end - cframe) / (strip->blendout);
 	}
 	else {
 		/* in the middle of the strip, we should be full strength */
@@ -674,8 +678,8 @@
 	NlaEvalStrip *nes;
 	short side= 0;
 	
-	/* skip if track is muted */
-	if (nlt->flag & NLATRACK_MUTED) 
+	/* skip if track is muted or disabled */
+	if (nlt->flag & (NLATRACK_MUTED|NLATRACK_DISABLED)) 
 		return;
 	
 	/* loop over strips, checking if they fall within the range */
@@ -1104,6 +1108,7 @@
 	 *	- NLA before Active Action, as Active Action behaves as 'tweaking track'
 	 *	  that overrides 'rough' work in NLA
 	 */
+	// TODO: need to double check that this all works correctly
 	if ((recalc & ADT_RECALC_ANIM) || (adt->recalc & ADT_RECALC_ANIM))
  	{
 		/* evaluate NLA data */

Modified: branches/soc-2009-aligorith/source/blender/blenkernel/intern/nla.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/blenkernel/intern/nla.c	2009-06-05 04:15:19 UTC (rev 20645)
+++ branches/soc-2009-aligorith/source/blender/blenkernel/intern/nla.c	2009-06-05 05:18:07 UTC (rev 20646)
@@ -583,4 +583,104 @@
 	}
 }
 
+
+/* Find the active strip + track combo, and set them up as the tweaking track,
+ * and return if successful or not.
+ */
+short BKE_nla_tweakmode_enter (AnimData *adt)
+{
+	NlaTrack *nlt, *activeTrack=NULL;
+	NlaStrip *strip, *activeStrip=NULL;
+	
+	/* verify that data is valid */
+	if ELEM(NULL, adt, adt->nla_tracks.first)
+		return 0;
+		
+	/* if block is already in tweakmode, just leave, but we should report 
+	 * that this block is in tweakmode (as our returncode)
+	 */
+	// FIXME: hopefully the flag is correct!
+	if (adt->flag & ADT_NLA_EDIT_ON)
+		return 1;
+		
+	/* go over the tracks, finding the active one, and its active strip
+	 * 	- if we cannot find both, then there's nothing to do
+	 */
+	for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next) {
+		/* check if active */
+		if (nlt->flag & NLATRACK_ACTIVE) {
+			/* store reference to this active track */
+			activeTrack= nlt;
+			
+			/* now try to find active strip */
+			activeStrip= BKE_nlastrip_find_active(nlt);
+			break;
+		}	
+	}
+	if ELEM3(NULL, activeTrack, activeStrip, activeStrip->act) {
+		printf("NLA tweakmode enter - neither active requirement found \n");
+		return 0;
+	}
+		
+	/* go over all the tracks up to the active one, tagging each strip that uses the same 
+	 * action as the active strip, but leaving everything else alone
+	 */
+	for (nlt= activeTrack->prev; nlt; nlt= nlt->prev) {
+		for (strip= nlt->strips.first; strip; strip= strip->next) {
+			if (strip->act == activeStrip->act)
+				strip->flag |= NLASTRIP_FLAG_TWEAKUSER;
+			else
+				strip->flag &= ~NLASTRIP_FLAG_TWEAKUSER; // XXX probably don't need to clear this...
+		}
+	}
+	
+	
+	/* go over all the tracks after AND INCLUDING the active one, tagging them as being disabled 
+	 *	- the active track needs to also be tagged, otherwise, it'll overlap with the tweaks going on
+	 */
+	for (nlt= activeTrack; nlt; nlt= nlt->next)
+		nlt->flag |= NLATRACK_DISABLED;
+	
+	/* handle AnimData level changes:
+	 *	- 'real' active action to temp storage (no need to change user-counts)
+	 *	- action of active strip set to be the 'active action'
+	 *	- editing-flag for this AnimData block should also get turned on (for more efficient restoring)
+	 */
+	adt->tmpact= adt->action;
+	adt->action= activeStrip->act;
+	adt->flag |= ADT_NLA_EDIT_ON;
+	
+	/* done! */
+	return 1;
+}
+
+/* Exit tweakmode for this AnimData block */
+void BKE_nla_tweakmode_exit (AnimData *adt)
+{
+	NlaTrack *nlt;
+	
+	/* verify that data is valid */
+	if ELEM(NULL, adt, adt->nla_tracks.first)
+		return;
+		
+	/* hopefully the flag is correct - skip if not on */
+	if ((adt->flag & ADT_NLA_EDIT_ON) == 0)
+		return;
+		
+	// TODO: need to sync the user-strip with the new state of the action!
+		
+	/* for all NLA-tracks, clear the 'disabled' flag */
+	for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next)
+		nlt->flag &= ~NLATRACK_DISABLED;
+	
+	/* handle AnimData level changes:
+	 *	- 'real' active action is restored from storage
+	 *	- storage pointer gets cleared (to avoid having bad notes hanging around)
+	 *	- editing-flag for this AnimData block should also get turned off
+	 */
+	adt->action= adt->tmpact;
+	adt->tmpact= NULL;
+	adt->flag &= ~ADT_NLA_EDIT_ON;
+}
+
 /* *************************************************** */

Modified: branches/soc-2009-aligorith/source/blender/editors/animation/anim_channels.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/editors/animation/anim_channels.c	2009-06-05 04:15:19 UTC (rev 20645)
+++ branches/soc-2009-aligorith/source/blender/editors/animation/anim_channels.c	2009-06-05 05:18:07 UTC (rev 20646)
@@ -90,14 +90,13 @@
 /* -------------------------- Exposed API ----------------------------------- */
 
 /* Set the given animation-channel as the active one for the active context */
-void ANIM_set_active_channel (void *data, short datatype, int filter, void *channel_data, short channel_type)
+void ANIM_set_active_channel (bAnimContext *ac, void *data, short datatype, int filter, void *channel_data, short channel_type)
 {
 	ListBase anim_data = {NULL, NULL};
 	bAnimListElem *ale;
 	
 	/* try to build list of filtered items */
-	// XXX we don't need/supply animcontext for now, since in this case, there's nothing really essential there that isn't already covered
-	ANIM_animdata_filter(NULL, &anim_data, filter, data, datatype);
+	ANIM_animdata_filter(ac, &anim_data, filter, data, datatype);
 	if (anim_data.first == NULL)
 		return;
 		
@@ -151,8 +150,7 @@
 			case ANIMTYPE_NLATRACK:
 			{
 				NlaTrack *nlt= (NlaTrack *)channel_data;
-				
-				ACHANNEL_SET_FLAG(nlt, ACHANNEL_SETFLAG_CLEAR, NLATRACK_ACTIVE);
+				nlt->flag |= NLATRACK_ACTIVE;
 			}
 				break;
 		}
@@ -1474,7 +1472,7 @@
 				
 				/* if group is selected now, make group the 'active' one in the visible list */
 				if (agrp->flag & AGRP_SELECTED)
-					ANIM_set_active_channel(ac->data, ac->datatype, filter, agrp, ANIMTYPE_GROUP);
+					ANIM_set_active_channel(ac, ac->data, ac->datatype, filter, agrp, ANIMTYPE_GROUP);
 			}
 		}
 			break;
@@ -1520,7 +1518,7 @@
 				
 				/* if F-Curve is selected now, make F-Curve the 'active' one in the visible list */
 				if (fcu->flag & FCURVE_SELECTED)
-					ANIM_set_active_channel(ac->data, ac->datatype, filter, fcu, ANIMTYPE_FCURVE);
+					ANIM_set_active_channel(ac, ac->data, ac->datatype, filter, fcu, ANIMTYPE_FCURVE);
 			}
 		}
 			break;

Modified: branches/soc-2009-aligorith/source/blender/editors/animation/anim_filter.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/editors/animation/anim_filter.c	2009-06-05 04:15:19 UTC (rev 20645)
+++ branches/soc-2009-aligorith/source/blender/editors/animation/anim_filter.c	2009-06-05 05:18:07 UTC (rev 20646)
@@ -343,19 +343,33 @@
 /* quick macro to test if AnimData is usable for NLA */
 #define ANIMDATA_HAS_NLA(id) ((id)->adt && (id)->adt->nla_tracks.first)
 
-/* quick macro to test for all three avove usability tests, performing the appropriate provided 
+
+/* Quick macro to test for all three avove usability tests, performing the appropriate provided 
  * action for each when the AnimData context is appropriate. 
  *
- * Priority order for this goes (most important, to least): NLA, Drivers, Keyframes
+ * Priority order for this goes (most important, to least): AnimData blocks, NLA, Drivers, Keyframes.
  *
+ * For this to work correctly, a standard set of data needs to be available within the scope that this
+ * gets called in: 
+ *	- ListBase anim_data;
+ *	- bDopeSheet *ads;
+ *	- bAnimListElem *ale;
+ * 	- int items;
+ *

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list