[Bf-blender-cvs] [779cf53] temp_motionpaths: Keep keyframes on undo

Antony Riakiotakis noreply at git.blender.org
Fri Mar 13 14:45:30 CET 2015


Commit: 779cf534af96b3d0f440e7eeeab97501018ee2e2
Author: Antony Riakiotakis
Date:   Thu Mar 12 12:31:30 2015 +0100
Branches: temp_motionpaths
https://developer.blender.org/rB779cf534af96b3d0f440e7eeeab97501018ee2e2

Keep keyframes on undo

WIP code to tag fcurves with existing keyframes on current frame so they
can be restored (inserted into) after cancelling tranform.

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

M	source/blender/editors/transform/transform.c
M	source/blender/editors/transform/transform.h
M	source/blender/editors/transform/transform_conversions.c
M	source/blender/editors/transform/transform_generics.c

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

diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
index 191cd7c..3eb080f 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -2363,14 +2363,14 @@ void transformApply(bContext *C, TransInfo *t)
 				//ED_pose_clear_paths(C, ob); // XXX for now, don't need to clear
 				bool targetless_ik = (t->flag & T_AUTOIK) != 0; // XXX this currently doesn't work, since flags aren't set yet!
 
-				autokeyframe_pose_cb_func(C, t->scene, (View3D *)t->view, t->poseobj, t->mode, targetless_ik, true);
+				autokeyframe_pose_cb_func(C, t->scene, (View3D *)t->view, t->poseobj, t->mode, targetless_ik);
 			}
 		}
 		else {
 			int i;
 			for (i = 0; i < t->total; i++) {
 				TransData *td = t->data + i;
-				autokeyframe_ob_cb_func(C, t->scene, (View3D *)t->view, td->ob, t->mode, true);
+				autokeyframe_ob_cb_func(C, t->scene, (View3D *)t->view, td->ob, t->mode);
 			}
 		}
 	}
diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h
index 14c0947..cd70d48 100644
--- a/source/blender/editors/transform/transform.h
+++ b/source/blender/editors/transform/transform.h
@@ -590,8 +590,8 @@ bool transdata_check_local_islands(TransInfo *t, short around);
 int count_set_pose_transflags(int *out_mode, short around, struct Object *ob);
 
 /* auto-keying stuff used by special_aftertrans_update */
-void autokeyframe_ob_cb_func(struct bContext *C, struct Scene *scene, struct View3D *v3d, struct Object *ob, int tmode, bool insert);
-void autokeyframe_pose_cb_func(struct bContext *C, struct Scene *scene, struct View3D *v3d, struct Object *ob, int tmode, bool targetless_ik, bool insert);
+void autokeyframe_ob_cb_func(struct bContext *C, struct Scene *scene, struct View3D *v3d, struct Object *ob, int tmode);
+void autokeyframe_pose_cb_func(struct bContext *C, struct Scene *scene, struct View3D *v3d, struct Object *ob, int tmode, bool targetless_ik);
 
 /*********************** Constraints *****************************/
 
diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c
index 9b5488c..18b2b73 100644
--- a/source/blender/editors/transform/transform_conversions.c
+++ b/source/blender/editors/transform/transform_conversions.c
@@ -5195,7 +5195,7 @@ static void clear_trans_object_base_flags(TransInfo *t)
  *  tmode: should be a transform mode
  */
 // NOTE: context may not always be available, so must check before using it as it's a luxury for a few cases
-void autokeyframe_ob_cb_func(bContext *C, Scene *scene, View3D *v3d, Object *ob, int tmode, bool insert)
+void autokeyframe_ob_cb_func(bContext *C, Scene *scene, View3D *v3d, Object *ob, int tmode)
 {
 	ID *id = &ob->id;
 	FCurve *fcu;
@@ -5218,10 +5218,7 @@ void autokeyframe_ob_cb_func(bContext *C, Scene *scene, View3D *v3d, Object *ob,
 			/* only insert into active keyingset 
 			 * NOTE: we assume here that the active Keying Set does not need to have its iterator overridden spe
 			 */
-			if (insert)
-				ANIM_apply_keyingset(C, &dsources, NULL, active_ks, MODIFYKEY_MODE_INSERT, cfra);
-			else
-				ANIM_apply_keyingset(C, &dsources, NULL, active_ks, MODIFYKEY_MODE_DELETE, cfra);
+			ANIM_apply_keyingset(C, &dsources, NULL, active_ks, MODIFYKEY_MODE_INSERT, cfra);
 		}
 		else if (IS_AUTOKEY_FLAG(scene, INSERTAVAIL)) {
 			AnimData *adt = ob->adt;
@@ -5229,17 +5226,10 @@ void autokeyframe_ob_cb_func(bContext *C, Scene *scene, View3D *v3d, Object *ob,
 			/* only key on available channels */
 			if (adt && adt->action) {
 				for (fcu = adt->action->curves.first; fcu; fcu = fcu->next) {
-					fcu->flag &= ~FCURVE_SELECTED;
-					if (insert) {
-						insert_keyframe(reports, id, adt->action,
-						                (fcu->grp ? fcu->grp->name : NULL),
-						                fcu->rna_path, fcu->array_index, cfra, flag);
-					}
-					else {
-						delete_keyframe(reports, id, adt->action,
-						                (fcu->grp ? fcu->grp->name : NULL),
-						                fcu->rna_path, fcu->array_index, cfra, flag);
-					}
+				fcu->flag &= ~FCURVE_SELECTED;
+					insert_keyframe(reports, id, adt->action,
+					                (fcu->grp ? fcu->grp->name : NULL),
+					                fcu->rna_path, fcu->array_index, cfra, flag);
 				}
 			}
 		}
@@ -5276,33 +5266,21 @@ void autokeyframe_ob_cb_func(bContext *C, Scene *scene, View3D *v3d, Object *ob,
 			/* insert keyframes for the affected sets of channels using the builtin KeyingSets found */
 			if (do_loc) {
 				KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_LOCATION_ID);
-				if (insert)
-					ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra);
-				else
-					ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_DELETE, cfra);
+				ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra);
 			}
 			if (do_rot) {
 				KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_ROTATION_ID);
-				if (insert)
-					ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra);
-				else
-					ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_DELETE, cfra);
+				ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra);
 			}
 			if (do_scale) {
 				KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_SCALING_ID);
-				if (insert)
-					ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra);
-				else
-					ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_DELETE, cfra);
+				ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra);
 			}
 		}
 		/* insert keyframe in all (transform) channels */
 		else {
 			KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_LOC_ROT_SCALE_ID);
-			if (insert)
-				ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra);
-			else
-				ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_DELETE, cfra);
+			ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra);
 		}
 		
 		/* only calculate paths if there are paths to be recalculated,
@@ -5326,12 +5304,96 @@ void autokeyframe_ob_cb_func(bContext *C, Scene *scene, View3D *v3d, Object *ob,
 	}
 }
 
+/* auto keyframing: we need to tag the existing fcurves before attempting to insert keyframes
+ * to avoid deleting them by mistake. Algorithm here is that if keyframe existed before,
+ * we insert old value on cancel, else we completely delete it */
+void autokeyframe_pose_tag_existing (bContext *C, Scene *scene, Object *ob, bool targetless_ik) {
+	AnimData *adt = ob->adt;
+	bAction *act = (adt) ? adt->action : NULL;
+	bPose   *pose = ob->pose;
+	bPoseChannel *pchan;
+	FCurve *fcu;
+	float cfra = (float)CFRA;
+
+	for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) {
+		if (pchan->bone->flag & BONE_TRANSFORM) {
+			if (act) {
+				for (fcu = act->curves.first; fcu; fcu = fcu->next) {
+					/* only insert keyframes for this F-Curve if it affects the current bone */
+					if (strstr(fcu->rna_path, "bones")) {
+						char *pchanName = BLI_str_quoted_substrN(fcu->rna_path, "bones[");
+
+						/* only if bone name matches too...
+						 * NOTE: this will do constraints too, but those are ok to do here too?
+						 */
+						if (pchanName && STREQ(pchanName, pchan->name)) {
+							bool replace;
+							binarysearch_bezt_index(fcu->bezt, cfra, fcu->totvert, &replace);
+							if (replace) {
+								fcu->flag |= FCURVE_TAGGED;
+							}
+						}
+						if (pchanName) MEM_freeN(pchanName);
+					}
+				}
+			}
+		}
+	}
+}
+
+
+void autokeyframe_cleanup_untagged (bContext *C, Scene *scene, View3D *v3d, Object *ob, int tmode, bool targetless_ik) {
+	ID *id = &ob->id;
+	AnimData *adt = ob->adt;
+	bAction *act = (adt) ? adt->action : NULL;
+	bPose   *pose = ob->pose;
+	bPoseChannel *pchan;
+	FCurve *fcu;
+	ReportList *reports = CTX_wm_reports(C);
+	float cfra = (float)CFRA;
+	short flag = 0;
+
+	/* flag is initialized from UserPref keyframing settings
+	 *	- special exception for targetless IK - INSERTKEY_MATRIX keyframes should get
+	 *    visual keyframes even if flag not set, as it's not that useful otherwise
+	 *	  (for quick animation recording)
+	 */
+	flag = ANIM_get_keyframing_flags(scene, 1);
+
+	if (targetless_ik)
+		flag |= INSERTKEY_MATRIX;
+
+	for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) {
+		if (pchan->bone->flag & BONE_TRANSFORM) {
+			if (act) {
+				for (fcu = act->curves.first; fcu; fcu = fcu->next) {
+					/* only insert keyframes for this F-Curve if it affects the current bone */
+					if (strstr(fcu->rna_path, "bones")) {
+						char *pchanName = BLI_str_quoted_substrN(fcu->rna_path, "bones[");
+
+						/* only if bone name matches too...
+							 * NOTE: this will do constraints too, but those are ok to do here too?
+							 */
+						if (pchanName && STREQ(pchanName, pchan->name)) {
+							if (fcu->flag & FCURVE_TAGGED)
+								insert_keyframe(reports, id, act, ((fcu->grp) ? (fcu->grp->name) : (NULL)), fcu->rna_path, fcu->array_index, cfra, flag);
+							else
+								delete_keyframe(reports, id, act, ((fcu->grp) ? (fcu->grp->name) : (NULL)), fcu->rna_path, fcu->array_index, cfra, flag);
+						}
+						if (pchanName) MEM_freeN(pchanName);
+					}
+				}
+			}
+		}
+	}
+}
+
 /* auto-keyframing feature - for poses/pose-channels
  *  tmode: should be a transform mode
  *	targetless_ik: has targetless ik been done on any channels?
  */
 // NOTE: context may not always be available, so must check before using it as it's a luxury for a few cases
-void autokeyframe_pose_cb_func(bContext *C, Scene *scene, View3D *v3d, Object *ob, int tmode, bool targetless_ik, bool insert)
+void autokeyframe_pose_cb_func(bContext *C, Scene *scene, View3D *v3d, Object *ob, int tmode, bool targetless_ik)
 {
 	ID *id = &ob->id;
 	AnimData *adt = ob->adt;
@@ -5370,10 +5432,7 @@ void autokeyframe_pose_cb_func(bContext *C, Scene *scene, View3D *v3d, Object *o
 				/* only insert into active keyingset? */
 				if (IS_AUTOKEY_FLAG(scene, ONLYKEYINGSET) && (active_ks)) {
 					/* run the active Keying Set on the current datasource */
-					if (inser

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list