Example #1
0
void ui_but_anim_autokey(uiBut *but, Scene *scene, float cfra)
{
	ID *id;
	bAction *action;
	FCurve *fcu;
	int driven;

	fcu= ui_but_get_fcurve(but, &action, &driven);

	if(fcu && !driven) {
		id= but->rnapoin.id.data;
		
		// TODO: this should probably respect the keyingset only option for anim
		if(autokeyframe_cfra_can_key(scene, id)) {
			short flag = 0;
			
			if (IS_AUTOKEY_FLAG(INSERTNEEDED))
				flag |= INSERTKEY_NEEDED;
			if (IS_AUTOKEY_FLAG(AUTOMATKEY))
				flag |= INSERTKEY_MATRIX;
			if (IS_AUTOKEY_MODE(scene, EDITKEYS))
				flag |= INSERTKEY_REPLACE;
			
			fcu->flag &= ~FCURVE_SELECTED;
			insert_keyframe(id, action, ((fcu->grp)?(fcu->grp->name):(NULL)), fcu->rna_path, fcu->array_index, cfra, flag);
		}
	}
}
Example #2
0
/* After previewing poses */
static void poselib_preview_cleanup (bContext *C, wmOperator *op)
{
	tPoseLib_PreviewData *pld= (tPoseLib_PreviewData *)op->customdata;
	Scene *scene= pld->scene;
	Object *ob= pld->ob;
	bPose *pose= pld->pose;
	bArmature *arm= pld->arm;
	bAction *act= pld->act;
	TimeMarker *marker= pld->marker;
	
	/* redraw the header so that it doesn't show any of our stuff anymore */
	ED_area_headerprint(pld->sa, NULL);
	
	/* this signal does one recalc on pose, then unlocks, so ESC or edit will work */
	pose->flag |= POSE_DO_UNLOCK;
	
	/* clear pose if cancelled */
	if (pld->state == PL_PREVIEW_CANCEL) {
		poselib_backup_restore(pld);
		
		/* old optimize trick... this enforces to bypass the depgraph 
		 *	- note: code copied from transform_generics.c -> recalcData()
		 */
		if ((arm->flag & ARM_DELAYDEFORM)==0)
			DAG_id_tag_update(&ob->id, OB_RECALC_DATA);  /* sets recalc flags */
		else
			where_is_pose(scene, ob);
		
	}
	else if (pld->state == PL_PREVIEW_CONFIRM) {
		/* tag poses as appropriate */
		poselib_keytag_pose(C, scene, pld);
		
		/* change active pose setting */
		act->active_marker= BLI_findindex(&act->markers, marker) + 1;
		action_set_activemarker(act, marker, NULL);
		
		/* Update event for pose and deformation children */
		DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
		
		/* updates */
		if (IS_AUTOKEY_MODE(scene, NORMAL)) {
			//remake_action_ipos(ob->action);
		}
		else
			where_is_pose(scene, ob);
	}
	
	/* free memory used for backups and searching */
	poselib_backup_free_data(pld);
	BLI_freelistN(&pld->searchp);
	
	/* free temp data for operator */
	MEM_freeN(pld);
	op->customdata= NULL;
}
Example #3
0
/* this function is responsible for snapping keyframes to frame-times */
static void insert_action_keys(bAnimContext *ac, short mode) 
{
	ListBase anim_data = {NULL, NULL};
	bAnimListElem *ale;
	int filter;
	
	Scene *scene= ac->scene;
	float cfra= (float)CFRA;
	short flag = 0;
	
	/* filter data */
	filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY);
	if (mode == 2) 			filter |= ANIMFILTER_SEL;
	else if (mode == 3) 	filter |= ANIMFILTER_ACTGROUPED;
	
	ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
	
	/* init keyframing flag */
	if (IS_AUTOKEY_FLAG(AUTOMATKEY)) flag |= INSERTKEY_MATRIX;
	if (IS_AUTOKEY_FLAG(INSERTNEEDED)) flag |= INSERTKEY_NEEDED;
	if (IS_AUTOKEY_MODE(scene, EDITKEYS)) flag |= INSERTKEY_REPLACE;
	
	/* insert keyframes */
	for (ale= anim_data.first; ale; ale= ale->next) {
		AnimData *adt= ANIM_nla_mapping_get(ac, ale);
		FCurve *fcu= (FCurve *)ale->key_data;
		
		/* adjust current frame for NLA-scaling */
		if (adt)
			cfra= BKE_nla_tweakedit_remap(adt, (float)CFRA, NLATIME_CONVERT_UNMAP);
		else 
			cfra= (float)CFRA;
			
		/* if there's an id */
		if (ale->id)
			insert_keyframe(ale->id, NULL, ((fcu->grp)?(fcu->grp->name):(NULL)), fcu->rna_path, fcu->array_index, cfra, flag);
		else
			insert_vert_fcurve(fcu, cfra, fcu->curval, 0);
	}
	
	BLI_freelistN(&anim_data);
}