[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24804] trunk/blender/source/blender/ editors: Auto-Keyframing and Clear Transform Operators:

Joshua Leung aligorith at gmail.com
Mon Nov 23 12:58:31 CET 2009


Revision: 24804
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24804
Author:   aligorith
Date:     2009-11-23 12:58:30 +0100 (Mon, 23 Nov 2009)

Log Message:
-----------
Auto-Keyframing and Clear Transform Operators:

Clear Location/Rotation/Scale (Alt-G/R/S) now insert keyframes when Auto-Keyframing is enabled.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/animation/keyingsets.c
    trunk/blender/source/blender/editors/armature/editarmature.c
    trunk/blender/source/blender/editors/object/object_transform.c

Modified: trunk/blender/source/blender/editors/animation/keyingsets.c
===================================================================
--- trunk/blender/source/blender/editors/animation/keyingsets.c	2009-11-23 11:57:41 UTC (rev 24803)
+++ trunk/blender/source/blender/editors/animation/keyingsets.c	2009-11-23 11:58:30 UTC (rev 24804)
@@ -1294,6 +1294,10 @@
 	int kflag=0, success= 0;
 	char *groupname= NULL;
 	
+	/* sanity checks */
+	if (ks == NULL)
+		return 0;
+	
 	/* get flags to use */
 	if (mode == MODIFYKEY_MODE_INSERT) {
 		/* use KeyingSet's flags as base */

Modified: trunk/blender/source/blender/editors/armature/editarmature.c
===================================================================
--- trunk/blender/source/blender/editors/armature/editarmature.c	2009-11-23 11:57:41 UTC (rev 24803)
+++ trunk/blender/source/blender/editors/armature/editarmature.c	2009-11-23 11:58:30 UTC (rev 24804)
@@ -33,6 +33,7 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "DNA_anim_types.h"
 #include "DNA_action_types.h"
 #include "DNA_armature_types.h"
 #include "DNA_constraint_types.h"
@@ -83,6 +84,7 @@
 #include "WM_types.h"
 
 #include "ED_armature.h"
+#include "ED_keyframing.h"
 #include "ED_mesh.h"
 #include "ED_object.h"
 #include "ED_screen.h"
@@ -4843,8 +4845,17 @@
 
 static int pose_clear_scale_exec(bContext *C, wmOperator *op) 
 {
+	Scene *scene= CTX_data_scene(C);
 	Object *ob= CTX_data_active_object(C);
 	
+	KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Scaling");
+	bCommonKeySrc cks;
+	ListBase dsources = {&cks, &cks};
+	
+	/* init common-key-source for use by KeyingSets */
+	memset(&cks, 0, sizeof(bCommonKeySrc));
+	cks.id= &ob->id;
+	
 	/* only clear those channels that are not locked */
 	CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans) {
 		if ((pchan->protectflag & OB_LOCK_SCALEX)==0)
@@ -4854,8 +4865,21 @@
 		if ((pchan->protectflag & OB_LOCK_SCALEZ)==0)
 			pchan->size[2]= 1.0f;
 			
-		/* the current values from IPO's may not be zero, so tag as unkeyed */
-		//pchan->bone->flag |= BONE_UNKEYED;
+		/* do auto-keyframing as appropriate */
+		if (autokeyframe_cfra_can_key(scene, &ob->id)) {
+			/* init cks for this PoseChannel, then use the relative KeyingSets to keyframe it */
+			cks.pchan= pchan;
+			modify_keyframes(scene, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
+			
+			/* clear any unkeyed tags */
+			if (pchan->bone)
+				pchan->bone->flag &= ~BONE_UNKEYED;
+		}
+		else {
+			/* add unkeyed tags */
+			if (pchan->bone)
+				pchan->bone->flag |= BONE_UNKEYED;
+		}
 	}
 	CTX_DATA_END;
 	
@@ -4884,10 +4908,20 @@
 
 static int pose_clear_loc_exec(bContext *C, wmOperator *op) 
 {
+	Scene *scene= CTX_data_scene(C);
 	Object *ob= CTX_data_active_object(C);
 	
+	KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Location");
+	bCommonKeySrc cks;
+	ListBase dsources = {&cks, &cks};
+	
+	/* init common-key-source for use by KeyingSets */
+	memset(&cks, 0, sizeof(bCommonKeySrc));
+	cks.id= &ob->id;
+	
 	/* only clear those channels that are not locked */
 	CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans) {
+		/* clear location */
 		if ((pchan->protectflag & OB_LOCK_LOCX)==0)
 			pchan->loc[0]= 0.0f;
 		if ((pchan->protectflag & OB_LOCK_LOCY)==0)
@@ -4895,8 +4929,21 @@
 		if ((pchan->protectflag & OB_LOCK_LOCZ)==0)
 			pchan->loc[2]= 0.0f;
 			
-		/* the current values from IPO's may not be zero, so tag as unkeyed */
-		//pchan->bone->flag |= BONE_UNKEYED;
+		/* do auto-keyframing as appropriate */
+		if (autokeyframe_cfra_can_key(scene, &ob->id)) {
+			/* init cks for this PoseChannel, then use the relative KeyingSets to keyframe it */
+			cks.pchan= pchan;
+			modify_keyframes(scene, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
+			
+			/* clear any unkeyed tags */
+			if (pchan->bone)
+				pchan->bone->flag &= ~BONE_UNKEYED;
+		}
+		else {
+			/* add unkeyed tags */
+			if (pchan->bone)
+				pchan->bone->flag |= BONE_UNKEYED;
+		}
 	}
 	CTX_DATA_END;
 	
@@ -4925,8 +4972,17 @@
 
 static int pose_clear_rot_exec(bContext *C, wmOperator *op) 
 {
+	Scene *scene= CTX_data_scene(C);
 	Object *ob= CTX_data_active_object(C);
 	
+	KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Rotation");
+	bCommonKeySrc cks;
+	ListBase dsources = {&cks, &cks};
+	
+	/* init common-key-source for use by KeyingSets */
+	memset(&cks, 0, sizeof(bCommonKeySrc));
+	cks.id= &ob->id;
+	
 	/* only clear those channels that are not locked */
 	CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans) {
 		if (pchan->protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ|OB_LOCK_ROTW)) {
@@ -5021,8 +5077,21 @@
 			}
 		}
 		
-		/* the current values from IPO's may not be zero, so tag as unkeyed */
-		//pchan->bone->flag |= BONE_UNKEYED;
+		/* do auto-keyframing as appropriate */
+		if (autokeyframe_cfra_can_key(scene, &ob->id)) {
+			/* init cks for this PoseChannel, then use the relative KeyingSets to keyframe it */
+			cks.pchan= pchan;
+			modify_keyframes(scene, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
+			
+			/* clear any unkeyed tags */
+			if (pchan->bone)
+				pchan->bone->flag &= ~BONE_UNKEYED;
+		}
+		else {
+			/* add unkeyed tags */
+			if (pchan->bone)
+				pchan->bone->flag |= BONE_UNKEYED;
+		}
 	}
 	CTX_DATA_END;
 	

Modified: trunk/blender/source/blender/editors/object/object_transform.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_transform.c	2009-11-23 11:57:41 UTC (rev 24803)
+++ trunk/blender/source/blender/editors/object/object_transform.c	2009-11-23 11:58:30 UTC (rev 24804)
@@ -27,6 +27,7 @@
 
 #include <stdlib.h>
 
+#include "DNA_anim_types.h"
 #include "DNA_action_types.h"
 #include "DNA_armature_types.h"
 #include "DNA_curve_types.h"
@@ -61,6 +62,7 @@
 #include "ED_anim_api.h"
 #include "ED_armature.h"
 #include "ED_curve.h"
+#include "ED_keyframing.h"
 #include "ED_mesh.h"
 #include "ED_object.h"
 #include "ED_screen.h"
@@ -72,8 +74,16 @@
 
 static int object_location_clear_exec(bContext *C, wmOperator *op)
 {
-	int armature_clear= 0;
-
+	Scene *scene= CTX_data_scene(C);
+	
+	KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Location");
+	bCommonKeySrc cks;
+	ListBase dsources = {&cks, &cks};
+	
+	/* init common-key-source for use by KeyingSets */
+	memset(&cks, 0, sizeof(bCommonKeySrc));
+	
+	/* clear location of selected objects if not in weight-paint mode */
 	CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
 		if(!(ob->mode & OB_MODE_WEIGHT_PAINT)) {
 			if((ob->protectflag & OB_LOCK_LOCX)==0)
@@ -82,13 +92,17 @@
 				ob->loc[1]= ob->dloc[1]= 0.0f;
 			if((ob->protectflag & OB_LOCK_LOCZ)==0)
 				ob->loc[2]= ob->dloc[2]= 0.0f;
+				
+			/* do auto-keyframing as appropriate */
+			if (autokeyframe_cfra_can_key(scene, &ob->id)) {
+				/* init cks for this object, then use the relative KeyingSets to keyframe it */
+				cks.id= &ob->id;
+				modify_keyframes(scene, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
+			}
 		}
 		ob->recalc |= OB_RECALC_OB;
 	}
 	CTX_DATA_END;
-
-	if(armature_clear==0) /* in this case flush was done */
-		ED_anim_dag_flush_update(C);	
 	
 	WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
 	
@@ -112,8 +126,16 @@
 
 static int object_rotation_clear_exec(bContext *C, wmOperator *op)
 {
-	int armature_clear= 0;
-
+	Scene *scene= CTX_data_scene(C);
+	
+	KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Rotation");
+	bCommonKeySrc cks;
+	ListBase dsources = {&cks, &cks};
+	
+	/* init common-key-source for use by KeyingSets */
+	memset(&cks, 0, sizeof(bCommonKeySrc));
+	
+	/* clear rotation of selected objects if not in weight-paint mode */
 	CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
 		if(!(ob->mode & OB_MODE_WEIGHT_PAINT)) {
 			if (ob->protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ|OB_LOCK_ROTW)) {
@@ -206,13 +228,17 @@
 					ob->rot[0]= ob->rot[1]= ob->rot[2]= 0.0f;
 				}
 			}
+			
+			/* do auto-keyframing as appropriate */
+			if (autokeyframe_cfra_can_key(scene, &ob->id)) {
+				/* init cks for this object, then use the relative KeyingSets to keyframe it */
+				cks.id= &ob->id;
+				modify_keyframes(scene, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
+			}
 		}
 		ob->recalc |= OB_RECALC_OB;
 	}
 	CTX_DATA_END;
-
-	if(armature_clear==0) /* in this case flush was done */
-		ED_anim_dag_flush_update(C);	
 	
 	WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
 	
@@ -236,8 +262,16 @@
 
 static int object_scale_clear_exec(bContext *C, wmOperator *op)
 {
-	int armature_clear= 0;
-
+	Scene *scene= CTX_data_scene(C);
+	
+	KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Scaling");
+	bCommonKeySrc cks;
+	ListBase dsources = {&cks, &cks};
+	
+	/* init common-key-source for use by KeyingSets */
+	memset(&cks, 0, sizeof(bCommonKeySrc));
+	
+	/* clear scales of selected objects if not in weight-paint mode */
 	CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
 		if(!(ob->mode & OB_MODE_WEIGHT_PAINT)) {
 			if((ob->protectflag & OB_LOCK_SCALEX)==0) {
@@ -252,14 +286,18 @@
 				ob->dsize[2]= 0.0f;
 				ob->size[2]= 1.0f;
 			}
+			
+			/* do auto-keyframing as appropriate */
+			if (autokeyframe_cfra_can_key(scene, &ob->id)) {
+				/* init cks for this object, then use the relative KeyingSets to keyframe it */
+				cks.id= &ob->id;
+				modify_keyframes(scene, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
+			}
 		}
 		ob->recalc |= OB_RECALC_OB;
 	}
 	CTX_DATA_END;
 	
-	if(armature_clear==0) /* in this case flush was done */
-		ED_anim_dag_flush_update(C);	
-	
 	WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
 	
 	return OPERATOR_FINISHED;





More information about the Bf-blender-cvs mailing list