[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21416] branches/soc-2009-aligorith/source /blender: NLA SoC: Influence/Time properties for strips can now be animated

Joshua Leung aligorith at gmail.com
Wed Jul 8 07:00:11 CEST 2009


Revision: 21416
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21416
Author:   aligorith
Date:     2009-07-08 07:00:10 +0200 (Wed, 08 Jul 2009)

Log Message:
-----------
NLA SoC: Influence/Time properties for strips can now be animated

* These settings can now be edited + keyframed (using IKEY over the button only for now... other cases will fail)

* Reshuffled some of the keyframing code to make this sort of thing easier to do. Also, restored corrections for NLA-mapping when inserting/removing keyframes.


TODOS:
* animation editors don't show these keyframes yet
* the buttons don't change colour yet to reflect this state. How to do this efficiently?
* allow keyframing of these in more places
* more robust UI handling for this.

Modified Paths:
--------------
    branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h
    branches/soc-2009-aligorith/source/blender/blenkernel/intern/nla.c
    branches/soc-2009-aligorith/source/blender/editors/animation/keyframing.c
    branches/soc-2009-aligorith/source/blender/editors/include/ED_keyframing.h
    branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_buttons.c
    branches/soc-2009-aligorith/source/blender/makesrna/intern/rna_nla.c

Modified: branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h
===================================================================
--- branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h	2009-07-07 23:33:39 UTC (rev 21415)
+++ branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h	2009-07-08 05:00:10 UTC (rev 21416)
@@ -80,9 +80,13 @@
 /* ............ */
 
 struct NlaStrip *BKE_nlastrip_find_active(struct NlaTrack *nlt);
+
 short BKE_nlastrip_within_bounds(struct NlaStrip *strip, float min, float max);
 
+void BKE_nlastrip_validate_fcurves(struct NlaStrip *strip);
 
+/* ............ */
+
 void BKE_nla_action_pushdown(struct AnimData *adt);
 
 short BKE_nla_tweakmode_enter(struct AnimData *adt);

Modified: branches/soc-2009-aligorith/source/blender/blenkernel/intern/nla.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/blenkernel/intern/nla.c	2009-07-07 23:33:39 UTC (rev 21415)
+++ branches/soc-2009-aligorith/source/blender/blenkernel/intern/nla.c	2009-07-08 05:00:10 UTC (rev 21416)
@@ -1049,6 +1049,58 @@
 	/* should be first now */
 	return 1;
 }
+
+/* Validate the NLA-Strips 'control' F-Curves based on the flags set*/
+void BKE_nlastrip_validate_fcurves (NlaStrip *strip) 
+{
+	FCurve *fcu;
+	
+	/* sanity checks */
+	if (strip == NULL)
+		return;
+	
+	/* if controlling influence... */
+	if (strip->flag & NLASTRIP_FLAG_USR_INFLUENCE) {
+		/* try to get F-Curve */
+		fcu= list_find_fcurve(&strip->fcurves, "influence", 0);
+		
+		/* add one if not found */
+		if (fcu == NULL) {
+			/* make new F-Curve */
+			fcu= MEM_callocN(sizeof(FCurve), "NlaStrip FCurve");
+			BLI_addtail(&strip->fcurves, fcu);
+			
+			/* set default flags */
+			fcu->flag = (FCURVE_VISIBLE|FCURVE_AUTO_HANDLES|FCURVE_SELECTED);
+			
+			/* store path - make copy, and store that */
+			fcu->rna_path= BLI_strdupn("influence", 9);
+			
+			// TODO: insert a few keyframes to ensure default behaviour?
+		}
+	}
+	
+	/* if controlling time... */
+	if (strip->flag & NLASTRIP_FLAG_USR_TIME) {
+		/* try to get F-Curve */
+		fcu= list_find_fcurve(&strip->fcurves, "strip_time", 0);
+		
+		/* add one if not found */
+		if (fcu == NULL) {
+			/* make new F-Curve */
+			fcu= MEM_callocN(sizeof(FCurve), "NlaStrip FCurve");
+			BLI_addtail(&strip->fcurves, fcu);
+			
+			/* set default flags */
+			fcu->flag = (FCURVE_VISIBLE|FCURVE_AUTO_HANDLES|FCURVE_SELECTED);
+			
+			/* store path - make copy, and store that */
+			fcu->rna_path= BLI_strdupn("strip_time", 10);
+			
+			// TODO: insert a few keyframes to ensure default behaviour?
+		}
+	}
+}
  
 /* Tools ------------------------------------------- */
 

Modified: branches/soc-2009-aligorith/source/blender/editors/animation/keyframing.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/editors/animation/keyframing.c	2009-07-07 23:33:39 UTC (rev 21415)
+++ branches/soc-2009-aligorith/source/blender/editors/animation/keyframing.c	2009-07-08 05:00:10 UTC (rev 21416)
@@ -54,6 +54,7 @@
 #include "BKE_action.h"
 #include "BKE_constraint.h"
 #include "BKE_fcurve.h"
+#include "BKE_nla.h"
 #include "BKE_global.h"
 #include "BKE_utildefines.h"
 #include "BKE_context.h"
@@ -722,9 +723,119 @@
 
 /* ------------------------- Insert Key API ------------------------- */
 
+/* Secondary Keyframing API call: 
+ * 	Use this when validation of necessary animation data is not necessary, since an RNA-pointer to the necessary
+ *	data being keyframed, and a pointer to the F-Curve to use have both been provided.
+ *
+ *	The flag argument is used for special settings that alter the behaviour of
+ *	the keyframe insertion. These include the 'visual' keyframing modes, quick refresh,
+ *	and extra keyframe filtering.
+ */
+short insert_keyframe_direct (PointerRNA ptr, PropertyRNA *prop, FCurve *fcu, float cfra, short flag)
+{
+	float curval= 0.0f;
+	
+	/* no F-Curve to add keyframe to? */
+	if (fcu == NULL) {
+		printf("ERROR: no F-Curve to add keyframes to \n");
+		return 0;
+	}
+	
+	/* if no property given yet, try to validate from F-Curve info */
+	if ((ptr.id.data == NULL) && (ptr.data==NULL)) {
+		printf("ERROR: no RNA-pointer available to retrieve values for keyframing from\n");
+		return 0;
+	}
+	if (prop == NULL) {
+		PointerRNA tmp_ptr;
+		
+		/* try to get property we should be affecting */
+		if ((RNA_path_resolve(&ptr, fcu->rna_path, &tmp_ptr, &prop) == 0) || (prop == NULL)) {
+			/* property not found... */
+			char *idname= (ptr.id.data) ? ((ID *)ptr.id.data)->name : "<No ID-Pointer>";
+			
+			printf("Insert Key: Could not insert keyframe, as RNA Path is invalid for the given ID (ID = %s, Path = %s)\n", idname, fcu->rna_path);
+			return 0;
+		}
+		else {
+			/* property found, so overwrite 'ptr' to make later code easier */
+			ptr= tmp_ptr;
+		}
+	}
+	
+	/* set additional flags for the F-Curve (i.e. only integer values) */
+	fcu->flag &= ~(FCURVE_INT_VALUES|FCURVE_DISCRETE_VALUES);
+	switch (RNA_property_type(prop)) {
+		case PROP_FLOAT:
+			/* do nothing */
+			break;
+		case PROP_INT:
+			/* do integer (only 'whole' numbers) interpolation between all points */
+			fcu->flag |= FCURVE_INT_VALUES;
+			break;
+		default:
+			/* do 'discrete' (i.e. enum, boolean values which cannot take any intermediate
+			 * values at all) interpolation between all points
+			 *	- however, we must also ensure that evaluated values are only integers still
+			 */
+			fcu->flag |= (FCURVE_DISCRETE_VALUES|FCURVE_INT_VALUES);
+			break;
+	}
+	
+	/* obtain value to give keyframe */
+	if ( (flag & INSERTKEY_MATRIX) && 
+		 (visualkey_can_use(&ptr, prop)) ) 
+	{
+		/* visual-keying is only available for object and pchan datablocks, as 
+		 * it works by keyframing using a value extracted from the final matrix 
+		 * instead of using the kt system to extract a value.
+		 */
+		curval= visualkey_get_value(&ptr, prop, fcu->array_index);
+	}
+	else {
+		/* read value from system */
+		curval= setting_get_rna_value(&ptr, prop, fcu->array_index);
+	}
+	
+	/* only insert keyframes where they are needed */
+	if (flag & INSERTKEY_NEEDED) {
+		short insert_mode;
+		
+		/* check whether this curve really needs a new keyframe */
+		insert_mode= new_key_needed(fcu, cfra, curval);
+		
+		/* insert new keyframe at current frame */
+		if (insert_mode)
+			insert_vert_fcurve(fcu, cfra, curval, (flag & INSERTKEY_FAST));
+		
+		/* delete keyframe immediately before/after newly added */
+		switch (insert_mode) {
+			case KEYNEEDED_DELPREV:
+				delete_fcurve_key(fcu, fcu->totvert-2, 1);
+				break;
+			case KEYNEEDED_DELNEXT:
+				delete_fcurve_key(fcu, 1, 1);
+				break;
+		}
+		
+		/* only return success if keyframe added */
+		if (insert_mode)
+			return 1;
+	}
+	else {
+		/* just insert keyframe */
+		insert_vert_fcurve(fcu, cfra, curval, (flag & INSERTKEY_FAST));
+		
+		/* return success */
+		return 1;
+	}
+	
+	/* failed */
+	return 0;
+}
+
 /* Main Keyframing API call:
- *	Use this when validation of necessary animation data isn't necessary as it
- *	already exists. It will insert a keyframe using the current value being keyframed.
+ *	Use this when validation of necessary animation data is necessary, since it may not exist yet.
  *	
  *	The flag argument is used for special settings that alter the behaviour of
  *	the keyframe insertion. These include the 'visual' keyframing modes, quick refresh,
@@ -744,102 +855,31 @@
 	}
 	
 	/* get F-Curve - if no action is provided, keyframe to the default one attached to this ID-block */
-	if (act == NULL)
+	if (act == NULL) {
+		AnimData *adt= BKE_animdata_from_id(id);
+		
+		/* get action to add F-Curve+keyframe to */
 		act= verify_adt_action(id, 1);
+		
+		/* apply NLA-mapping to frame to use (if applicable) */
+		cfra= BKE_nla_tweakedit_remap(adt, cfra, NLATIME_CONVERT_UNMAP);
+	}
 	fcu= verify_fcurve(act, group, rna_path, array_index, 1);
 	
-	/* only continue if we have an F-Curve to add keyframe to */
-	if (fcu) {
-		float curval= 0.0f;
+	/* apply special time tweaking */
+		// XXX check on this stuff...
+	if (GS(id->name) == ID_OB) {
+		//Object *ob= (Object *)id;
 		
-		/* set additional flags for the F-Curve (i.e. only integer values) */
-		fcu->flag &= ~(FCURVE_INT_VALUES|FCURVE_DISCRETE_VALUES);
-		switch (RNA_property_type(prop)) {
-			case PROP_FLOAT:
-				/* do nothing */
-				break;
-			case PROP_INT:
-				/* do integer (only 'whole' numbers) interpolation between all points */
-				fcu->flag |= FCURVE_INT_VALUES;
-				break;
-			default:
-				/* do 'discrete' (i.e. enum, boolean values which cannot take any intermediate
-				 * values at all) interpolation between all points
-				 *	- however, we must also ensure that evaluated values are only integers still
-				 */
-				fcu->flag |= (FCURVE_DISCRETE_VALUES|FCURVE_INT_VALUES);
-				break;
-		}
-		
-		/* apply special time tweaking */
-			// XXX check on this stuff...
-		if (GS(id->name) == ID_OB) {
-			//Object *ob= (Object *)id;
-			
-			/* apply NLA-scaling (if applicable) */
-			//cfra= get_action_frame(ob, cfra);
-			
-			/* ancient time-offset cruft */
-			//if ( (ob->ipoflag & OB_OFFS_OB) && (give_timeoffset(ob)) ) {
-			//	/* actually frametofloat calc again! */
-			//	cfra-= give_timeoffset(ob)*scene->r.framelen;
-			//}
-		}
-		
-		/* obtain value to give keyframe */
-		if ( (flag & INSERTKEY_MATRIX) && 
-			 (visualkey_can_use(&ptr, prop)) ) 
-		{
-			/* visual-keying is only available for object and pchan datablocks, as 
-			 * it works by keyframing using a value extracted from the final matrix 
-			 * instead of using the kt system to extract a value.
-			 */
-			curval= visualkey_get_value(&ptr, prop, array_index);
-		}
-		else {
-			/* read value from system */
-			curval= setting_get_rna_value(&ptr, prop, array_index);
-		}
-		
-		/* only insert keyframes where they are needed */
-		if (flag & INSERTKEY_NEEDED) {
-			short insert_mode;
-			
-			/* check whether this curve really needs a new keyframe */
-			insert_mode= new_key_needed(fcu, cfra, curval);
-			
-			/* insert new keyframe at current frame */
-			if (insert_mode)
-				insert_vert_fcurve(fcu, cfra, curval, (flag & INSERTKEY_FAST));
-			
-			/* delete keyframe immediately before/after newly added */
-			switch (insert_mode) {
-				case KEYNEEDED_DELPREV:
-					delete_fcurve_key(fcu, fcu->totvert-2, 1);
-					break;
-				case KEYNEEDED_DELNEXT:
-					delete_fcurve_key(fcu, 1, 1);
-					break;
-			}
-			

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list