static int add_default_keyingset_exec (bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); short flag=0, keyingflag=0; /* validate flags * - absolute KeyingSets should be created by default */ flag |= KEYINGSET_ABSOLUTE; if (IS_AUTOKEY_FLAG(AUTOMATKEY)) keyingflag |= INSERTKEY_MATRIX; if (IS_AUTOKEY_FLAG(INSERTNEEDED)) keyingflag |= INSERTKEY_NEEDED; /* call the API func, and set the active keyingset index */ BKE_keyingset_add(&scene->keyingsets, NULL, flag, keyingflag); scene->active_keyingset= BLI_countlist(&scene->keyingsets); /* send notifiers */ WM_event_add_notifier(C, NC_SCENE|ND_KEYINGSET, NULL); return OPERATOR_FINISHED; }
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); } } }
/* Get Keying Set to use for Auto-Keyframing some transforms */ KeyingSet *ANIM_get_keyingset_for_autokeying(Scene *scene, const char *tranformKSName) { /* get KeyingSet to use * - use the active KeyingSet if defined (and user wants to use it for all autokeying), * or otherwise key transforms only */ if (IS_AUTOKEY_FLAG(scene, ONLYKEYINGSET) && (scene->active_keyingset)) return ANIM_scene_get_active_keyingset(scene); else if (IS_AUTOKEY_FLAG(scene, INSERTAVAIL)) return ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_AVAILABLE_ID); else return ANIM_builtin_keyingset_get_named(NULL, tranformKSName); }
/* 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); }
static int add_keyingset_button_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); KeyingSet *ks = NULL; PropertyRNA *prop = NULL; PointerRNA ptr = {{NULL}}; char *path = NULL; short success = 0; int index = 0, pflag = 0; const bool all = RNA_boolean_get(op->ptr, "all"); /* verify the Keying Set to use: * - use the active one for now (more control over this can be added later) * - add a new one if it doesn't exist */ if (scene->active_keyingset == 0) { short flag = 0, keyingflag = 0; /* validate flags * - absolute KeyingSets should be created by default */ flag |= KEYINGSET_ABSOLUTE; keyingflag |= ANIM_get_keyframing_flags(scene, 0); if (IS_AUTOKEY_FLAG(scene, XYZ2RGB)) keyingflag |= INSERTKEY_XYZ2RGB; /* call the API func, and set the active keyingset index */ ks = BKE_keyingset_add(&scene->keyingsets, "ButtonKeyingSet", "Button Keying Set", flag, keyingflag); scene->active_keyingset = BLI_countlist(&scene->keyingsets); } else if (scene->active_keyingset < 0) { BKE_report(op->reports, RPT_ERROR, "Cannot add property to built in keying set"); return OPERATOR_CANCELLED; } else { ks = BLI_findlink(&scene->keyingsets, scene->active_keyingset - 1); } /* try to add to keyingset using property retrieved from UI */ uiContextActiveProperty(C, &ptr, &prop, &index); /* check if property is able to be added */ if (ptr.id.data && ptr.data && prop && RNA_property_animateable(&ptr, prop)) { path = RNA_path_from_ID_to_property(&ptr, prop); if (path) { /* set flags */ if (all) { pflag |= KSP_FLAG_WHOLE_ARRAY; /* we need to set the index for this to 0, even though it may break in some cases, this is * necessary if we want the entire array for most cases to get included without the user * having to worry about where they clicked */ index = 0; } /* add path to this setting */ BKE_keyingset_add_path(ks, ptr.id.data, NULL, path, index, pflag, KSP_GROUP_KSNAME); ks->active_path = BLI_countlist(&ks->paths); success = 1; /* free the temp path created */ MEM_freeN(path); } } if (success) { /* send updates */ WM_event_add_notifier(C, NC_SCENE | ND_KEYINGSET, NULL); /* show notification/report header, so that users notice that something changed */ BKE_reportf(op->reports, RPT_INFO, "Property added to Keying Set: '%s'", ks->name); } return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; }
static int add_keyingset_button_exec (bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); KeyingSet *ks = NULL; PropertyRNA *prop= NULL; PointerRNA ptr; char *path = NULL; short success= 0; int index=0, pflag=0; int all= RNA_boolean_get(op->ptr, "all"); /* verify the Keying Set to use: * - use the active one for now (more control over this can be added later) * - add a new one if it doesn't exist */ if (scene->active_keyingset == 0) { short flag=0, keyingflag=0; /* validate flags * - absolute KeyingSets should be created by default */ flag |= KEYINGSET_ABSOLUTE; if (IS_AUTOKEY_FLAG(AUTOMATKEY)) keyingflag |= INSERTKEY_MATRIX; if (IS_AUTOKEY_FLAG(INSERTNEEDED)) keyingflag |= INSERTKEY_NEEDED; /* call the API func, and set the active keyingset index */ ks= BKE_keyingset_add(&scene->keyingsets, "ButtonKeyingSet", flag, keyingflag); scene->active_keyingset= BLI_countlist(&scene->keyingsets); } else ks= BLI_findlink(&scene->keyingsets, scene->active_keyingset-1); /* try to add to keyingset using property retrieved from UI */ memset(&ptr, 0, sizeof(PointerRNA)); uiAnimContextProperty(C, &ptr, &prop, &index); /* check if property is able to be added */ if (ptr.data && prop && RNA_property_animateable(ptr.data, prop)) { path= RNA_path_from_ID_to_property(&ptr, prop); if (path) { /* set flags */ if (all) { pflag |= KSP_FLAG_WHOLE_ARRAY; /* we need to set the index for this to 0, even though it may break in some cases, this is * necessary if we want the entire array for most cases to get included without the user * having to worry about where they clicked */ index= 0; } /* add path to this setting */ BKE_keyingset_add_destination(ks, ptr.id.data, NULL, path, index, pflag, KSP_GROUP_KSNAME); ks->active_path= BLI_countlist(&ks->paths); success= 1; /* free the temp path created */ MEM_freeN(path); } } if (success) { /* send updates */ ED_anim_dag_flush_update(C); /* for now, only send ND_KEYS for KeyingSets */ WM_event_add_notifier(C, NC_SCENE|ND_KEYINGSET, NULL); } return (success)? OPERATOR_FINISHED: OPERATOR_CANCELLED; }