[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25940] trunk/blender/source/blender: NLA: fix keyframes getting messed up when making strips longer.

Brecht Van Lommel brecht at blender.org
Tue Jan 12 22:20:09 CET 2010


Revision: 25940
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25940
Author:   blendix
Date:     2010-01-12 22:20:09 +0100 (Tue, 12 Jan 2010)

Log Message:
-----------
NLA: fix keyframes getting messed up when making strips longer. For drawing
and other operations the nla mapping would be applied to the curves, but not
restored correctly. The unmap function was not the inverse of the map function,
and it's not clear to me it's even possible to make it so due to repeat, so
now the old coordinates are backed up in a list and then restored afterwards.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/animation/anim_draw.c
    trunk/blender/source/blender/editors/animation/keyframes_draw.c
    trunk/blender/source/blender/editors/include/ED_anim_api.h
    trunk/blender/source/blender/editors/include/ED_keyframes_edit.h
    trunk/blender/source/blender/editors/space_action/action_edit.c
    trunk/blender/source/blender/editors/space_action/action_select.c
    trunk/blender/source/blender/editors/space_graph/graph_draw.c
    trunk/blender/source/blender/editors/space_graph/graph_edit.c
    trunk/blender/source/blender/editors/space_graph/graph_select.c
    trunk/blender/source/blender/editors/transform/transform_conversions.c
    trunk/blender/source/blender/makesrna/intern/rna_nla.c

Modified: trunk/blender/source/blender/editors/animation/anim_draw.c
===================================================================
--- trunk/blender/source/blender/editors/animation/anim_draw.c	2010-01-12 19:51:26 UTC (rev 25939)
+++ trunk/blender/source/blender/editors/animation/anim_draw.c	2010-01-12 21:20:09 UTC (rev 25940)
@@ -252,21 +252,23 @@
 
 /* ------------------- */
 
+typedef struct NlaMappingApplyBackup {
+	struct NlaMappingBackup *next, *prev;
+	BezTriple bezt;
+} NlaMappingApplyBackup;
+
 /* helper function for ANIM_nla_mapping_apply_fcurve() -> "restore", i.e. mapping points back to action-time */
 static short bezt_nlamapping_restore(BeztEditData *bed, BezTriple *bezt)
 {
-	/* AnimData block providing scaling is stored in 'data', only_keys option is stored in i1 */
-	AnimData *adt= (AnimData *)bed->data;
-	short only_keys= (short)bed->i1;
+	ListBase *lb= (ListBase*)bed->data2;
+	NlaMappingApplyBackup *backup= lb->first;
+
+	/* restore beztriple from backup list. this used to use NLATIME_CONVERT_UNMAP,
+	   but this was not the inverse of NLATIME_CONVERT_MAP and it's not clear how
+	   that is even possible due to repeats - brecht. */
+	*bezt= backup->bezt;
+	BLI_freelinkN(lb, backup);
 	
-	/* adjust BezTriple handles only if allowed to */
-	if (only_keys == 0) {
-		bezt->vec[0][0]= BKE_nla_tweakedit_remap(adt, bezt->vec[0][0], NLATIME_CONVERT_UNMAP);
-		bezt->vec[2][0]= BKE_nla_tweakedit_remap(adt, bezt->vec[2][0], NLATIME_CONVERT_UNMAP);
-	}
-	
-	bezt->vec[1][0]= BKE_nla_tweakedit_remap(adt, bezt->vec[1][0], NLATIME_CONVERT_UNMAP);
-	
 	return 0;
 }
 
@@ -274,8 +276,15 @@
 static short bezt_nlamapping_apply(BeztEditData *bed, BezTriple *bezt)
 {
 	/* AnimData block providing scaling is stored in 'data', only_keys option is stored in i1 */
-	AnimData *adt= (AnimData *)bed->data;
+	AnimData *adt= (AnimData*)bed->data;
+	ListBase *lb= (ListBase*)bed->data2;
+	NlaMappingApplyBackup *backup;
 	short only_keys= (short)bed->i1;
+
+	/* backup for restore later */
+	backup= MEM_callocN(sizeof(NlaMappingApplyBackup), "NlaMappingApplyBackup");
+	backup->bezt= *bezt;
+	BLI_addtail(lb, backup);
 	
 	/* adjust BezTriple handles only if allowed to */
 	if (only_keys == 0) {
@@ -289,12 +298,11 @@
 }
 
 
-
 /* Apply/Unapply NLA mapping to all keyframes in the nominated F-Curve 
  *	- restore = whether to map points back to non-mapped time 
  * 	- only_keys = whether to only adjust the location of the center point of beztriples
  */
-void ANIM_nla_mapping_apply_fcurve (AnimData *adt, FCurve *fcu, short restore, short only_keys)
+void ANIM_nla_mapping_apply_fcurve (AnimData *adt, FCurve *fcu, short restore, short only_keys, ListBase *backup)
 {
 	BeztEditData bed;
 	BeztEditFunc map_cb;
@@ -305,7 +313,11 @@
 	 */
 	memset(&bed, 0, sizeof(BeztEditData));
 	bed.data= (void *)adt;
+	bed.data2= (void *)backup;
 	bed.i1= (int)only_keys;
+
+	if(!restore)
+		backup->first= backup->last= NULL;
 	
 	/* get editing callback */
 	if (restore)

Modified: trunk/blender/source/blender/editors/animation/keyframes_draw.c
===================================================================
--- trunk/blender/source/blender/editors/animation/keyframes_draw.c	2010-01-12 19:51:26 UTC (rev 25939)
+++ trunk/blender/source/blender/editors/animation/keyframes_draw.c	2010-01-12 21:20:09 UTC (rev 25940)
@@ -850,12 +850,13 @@
 {
 	DLRBT_Tree *beztTree = NULL;
 	BezTriple *bezt;
+	ListBase nlabackup;
 	int v;
 	
 	if (fcu && fcu->totvert && fcu->bezt) {
 		/* apply NLA-mapping (if applicable) */
 		if (adt)	
-			ANIM_nla_mapping_apply_fcurve(adt, fcu, 0, 1);
+			ANIM_nla_mapping_apply_fcurve(adt, fcu, 0, 1, &nlabackup);
 		
 		/* if getting long keyframes too, grab the BezTriples in a BST for 
 		 * accelerated searching...
@@ -891,7 +892,8 @@
 		}
 		
 		/* unapply NLA-mapping if applicable */
-		ANIM_nla_mapping_apply_fcurve(adt, fcu, 1, 1);
+		if (adt)
+			ANIM_nla_mapping_apply_fcurve(adt, fcu, 1, 1, &nlabackup);
 	}
 }
 

Modified: trunk/blender/source/blender/editors/include/ED_anim_api.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_anim_api.h	2010-01-12 19:51:26 UTC (rev 25939)
+++ trunk/blender/source/blender/editors/include/ED_anim_api.h	2010-01-12 21:20:09 UTC (rev 25940)
@@ -453,7 +453,7 @@
 struct AnimData *ANIM_nla_mapping_get(bAnimContext *ac, bAnimListElem *ale);
 
 /* Apply/Unapply NLA mapping to all keyframes in the nominated F-Curve */
-void ANIM_nla_mapping_apply_fcurve(struct AnimData *adt, struct FCurve *fcu, short restore, short only_keys);
+void ANIM_nla_mapping_apply_fcurve(struct AnimData *adt, struct FCurve *fcu, short restore, short only_keys, ListBase *backup);
 
 /* ..... */
 

Modified: trunk/blender/source/blender/editors/include/ED_keyframes_edit.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_keyframes_edit.h	2010-01-12 19:51:26 UTC (rev 25939)
+++ trunk/blender/source/blender/editors/include/ED_keyframes_edit.h	2010-01-12 21:20:09 UTC (rev 25940)
@@ -94,6 +94,7 @@
 	ListBase list;				/* temp list for storing custom list of data to check */
 	struct Scene *scene;		/* pointer to current scene - many tools need access to cfra/etc.  */
 	void *data;					/* pointer to custom data - usually 'Object' but also 'rectf', but could be other types too */
+	void *data2;				/* pointer to more custom data */
 	float f1, f2;				/* storage of times/values as 'decimals' */
 	int i1, i2;					/* storage of times/values/flags as 'whole' numbers */
 } BeztEditData;

Modified: trunk/blender/source/blender/editors/space_action/action_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_action/action_edit.c	2010-01-12 19:51:26 UTC (rev 25939)
+++ trunk/blender/source/blender/editors/space_action/action_edit.c	2010-01-12 21:20:09 UTC (rev 25940)
@@ -1133,11 +1133,12 @@
 	
 	for (ale= anim_data.first; ale; ale= ale->next) {
 		AnimData *adt= ANIM_nla_mapping_get(&ac, ale);
-		
 		if (adt) {
-			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1); 
+			ListBase nlabackup;
+
+			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1, &nlabackup); 
 			ANIM_fcurve_keys_bezier_loop(&bed, ale->key_data, NULL, bezt_calc_average, NULL);
-			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1);
+			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1, &nlabackup);
 		}
 		else
 			ANIM_fcurve_keys_bezier_loop(&bed, ale->key_data, NULL, bezt_calc_average, NULL);
@@ -1215,9 +1216,11 @@
 		AnimData *adt= ANIM_nla_mapping_get(ac, ale);
 		
 		if (adt) {
-			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1); 
+			ListBase nlabackup;
+
+			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1, &nlabackup); 
 			ANIM_fcurve_keys_bezier_loop(&bed, ale->key_data, NULL, edit_cb, calchandles_fcurve);
-			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1);
+			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1, &nlabackup);
 		}
 		//else if (ale->type == ACTTYPE_GPLAYER)
 		//	snap_gplayer_frames(ale->data, mode);
@@ -1332,9 +1335,11 @@
 		AnimData *adt= ANIM_nla_mapping_get(ac, ale);
 		
 		if (adt) {
-			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1); 
+			ListBase nlabackup;
+
+			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1, &nlabackup); 
 			ANIM_fcurve_keys_bezier_loop(&bed, ale->key_data, NULL, edit_cb, calchandles_fcurve);
-			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1);
+			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1, &nlabackup);
 		}
 		//else if (ale->type == ACTTYPE_GPLAYER)
 		//	snap_gplayer_frames(ale->data, mode);

Modified: trunk/blender/source/blender/editors/space_action/action_select.c
===================================================================
--- trunk/blender/source/blender/editors/space_action/action_select.c	2010-01-12 19:51:26 UTC (rev 25939)
+++ trunk/blender/source/blender/editors/space_action/action_select.c	2010-01-12 21:20:09 UTC (rev 25940)
@@ -417,9 +417,11 @@
 		AnimData *adt= ANIM_nla_mapping_get(ac, ale);
 		
 		if (adt) {	
-			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1);
+			ListBase nlabackup;
+
+			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1, &nlabackup);
 			ANIM_fcurve_keys_bezier_loop(&bed, ale->key_data, ok_cb, select_cb, NULL);
-			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1);
+			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1, &nlabackup);
 		}
 		else {
 			ANIM_fcurve_keys_bezier_loop(&bed, ale->key_data, ok_cb, select_cb, NULL);
@@ -663,9 +665,11 @@
 		AnimData *adt= ANIM_nla_mapping_get(ac, ale);
 		
 		if (adt) {
-			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1);
+			ListBase nlabackup;
+
+			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1, &nlabackup);
 			ANIM_fcurve_keys_bezier_loop(&bed, ale->key_data, ok_cb, select_cb, NULL);
-			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1);
+			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1, &nlabackup);
 		}
 		//else if (ale->type == ANIMTYPE_GPLAYER)
 		//	borderselect_gplayer_frames(ale->data, min, max, SELECT_ADD);

Modified: trunk/blender/source/blender/editors/space_graph/graph_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_graph/graph_draw.c	2010-01-12 19:51:26 UTC (rev 25939)
+++ trunk/blender/source/blender/editors/space_graph/graph_draw.c	2010-01-12 21:20:09 UTC (rev 25940)
@@ -819,10 +819,11 @@
 		FCurve *fcu= (FCurve *)ale->key_data;
 		FModifier *fcm= find_active_fmodifier(&fcu->modifiers);
 		AnimData *adt= ANIM_nla_mapping_get(ac, ale);
+		ListBase nlabackup;
 		
 		/* map keyframes for drawing if scaled F-Curve */
 		if (adt)
-			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 0); 
+			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 0, &nlabackup); 
 		
 		/* draw curve:
 		 *	- curve line may be result of one or more destructive modifiers or just the raw data,
@@ -908,7 +909,7 @@
 		
 		/* undo mapping of keyframes for drawing if scaled F-Curve */
 		if (adt)
-			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 0); 
+			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 0, &nlabackup); 
 	}
 	
 	/* free list of curves */

Modified: trunk/blender/source/blender/editors/space_graph/graph_edit.c
===================================================================

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list