diff options
Diffstat (limited to 'source/blender/editors')
18 files changed, 229 insertions, 84 deletions
diff --git a/source/blender/editors/animation/anim_channels_defines.c b/source/blender/editors/animation/anim_channels_defines.c index 79c465c1f33..53401e0c05a 100644 --- a/source/blender/editors/animation/anim_channels_defines.c +++ b/source/blender/editors/animation/anim_channels_defines.c @@ -4708,6 +4708,7 @@ static void achannel_setting_slider_cb(bContext *C, void *id_poin, void *fcu_poi ReportList *reports = CTX_wm_reports(C); Scene *scene = CTX_data_scene(C); + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); ToolSettings *ts = scene->toolsettings; ListBase nla_cache = {NULL, NULL}; PointerRNA id_ptr, ptr; @@ -4720,8 +4721,10 @@ static void achannel_setting_slider_cb(bContext *C, void *id_poin, void *fcu_poi RNA_id_pointer_create(id, &id_ptr); /* Get NLA context for value remapping */ + const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct(depsgraph, + (float)CFRA); NlaKeyframingContext *nla_context = BKE_animsys_get_nla_keyframing_context( - &nla_cache, &id_ptr, adt, (float)CFRA, false); + &nla_cache, &id_ptr, adt, &anim_eval_context, false); /* get current frame and apply NLA-mapping to it (if applicable) */ cfra = BKE_nla_tweakedit_remap(adt, (float)CFRA, NLATIME_CONVERT_UNMAP); @@ -4738,7 +4741,7 @@ static void achannel_setting_slider_cb(bContext *C, void *id_poin, void *fcu_poi /* insert a keyframe for this F-Curve */ done = insert_keyframe_direct( - reports, ptr, prop, fcu, cfra, ts->keyframe_type, nla_context, flag); + reports, ptr, prop, fcu, &anim_eval_context, ts->keyframe_type, nla_context, flag); if (done) { if (adt->action != NULL) { @@ -4762,23 +4765,26 @@ static void achannel_setting_slider_shapekey_cb(bContext *C, void *key_poin, voi ReportList *reports = CTX_wm_reports(C); Scene *scene = CTX_data_scene(C); + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); ToolSettings *ts = scene->toolsettings; ListBase nla_cache = {NULL, NULL}; PointerRNA id_ptr, ptr; PropertyRNA *prop; eInsertKeyFlags flag = 0; bool done = false; - float cfra; /* Get RNA pointer */ RNA_id_pointer_create((ID *)key, &id_ptr); /* Get NLA context for value remapping */ + const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct(depsgraph, + (float)CFRA); NlaKeyframingContext *nla_context = BKE_animsys_get_nla_keyframing_context( - &nla_cache, &id_ptr, key->adt, (float)CFRA, false); + &nla_cache, &id_ptr, key->adt, &anim_eval_context, false); /* get current frame and apply NLA-mapping to it (if applicable) */ - cfra = BKE_nla_tweakedit_remap(key->adt, (float)CFRA, NLATIME_CONVERT_UNMAP); + const float remapped_frame = BKE_nla_tweakedit_remap( + key->adt, anim_eval_context.eval_time, NLATIME_CONVERT_UNMAP); /* get flags for keyframing */ flag = ANIM_get_keyframing_flags(scene, true); @@ -4791,13 +4797,21 @@ static void achannel_setting_slider_shapekey_cb(bContext *C, void *key_poin, voi FCurve *fcu = ED_action_fcurve_ensure(bmain, act, NULL, &ptr, rna_path, 0); /* set the special 'replace' flag if on a keyframe */ - if (fcurve_frame_has_keyframe(fcu, cfra, 0)) { + if (fcurve_frame_has_keyframe(fcu, remapped_frame, 0)) { flag |= INSERTKEY_REPLACE; } /* insert a keyframe for this F-Curve */ - done = insert_keyframe_direct( - reports, ptr, prop, fcu, cfra, ts->keyframe_type, nla_context, flag); + const AnimationEvalContext remapped_anim_eval_context = BKE_animsys_eval_context_construct_at( + &anim_eval_context, remapped_frame); + done = insert_keyframe_direct(reports, + ptr, + prop, + fcu, + &remapped_anim_eval_context, + ts->keyframe_type, + nla_context, + flag); if (done) { WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, NULL); @@ -4848,7 +4862,11 @@ static void achannel_setting_slider_nla_curve_cb(bContext *C, } /* insert a keyframe for this F-Curve */ - done = insert_keyframe_direct(reports, ptr, prop, fcu, cfra, ts->keyframe_type, NULL, flag); + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); + const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct(depsgraph, + cfra); + done = insert_keyframe_direct( + reports, ptr, prop, fcu, &anim_eval_context, ts->keyframe_type, NULL, flag); if (done) { WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, NULL); diff --git a/source/blender/editors/animation/anim_filter.c b/source/blender/editors/animation/anim_filter.c index bbb673caa71..50733afe6fb 100644 --- a/source/blender/editors/animation/anim_filter.c +++ b/source/blender/editors/animation/anim_filter.c @@ -419,6 +419,7 @@ bool ANIM_animdata_get_context(const bContext *C, bAnimContext *ac) ac->markers = ED_context_get_markers(C); } ac->view_layer = CTX_data_view_layer(C); + ac->depsgraph = CTX_data_depsgraph_pointer(C); ac->obact = (ac->view_layer->basact) ? ac->view_layer->basact->object : NULL; ac->area = area; ac->region = region; diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c index 9cb41e06aa0..8c2f4216aa9 100644 --- a/source/blender/editors/animation/keyframing.c +++ b/source/blender/editors/animation/keyframing.c @@ -1113,7 +1113,7 @@ static bool insert_keyframe_value(ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, FCurve *fcu, - float cfra, + const AnimationEvalContext *anim_eval_context, float curval, eBezTriple_KeyframeType keytype, eInsertKeyFlags flag) @@ -1130,13 +1130,15 @@ static bool insert_keyframe_value(ReportList *reports, return false; } + float cfra = anim_eval_context->eval_time; + /* adjust frame on which to add keyframe */ if ((flag & INSERTKEY_DRIVER) && (fcu->driver)) { PathResolvedRNA anim_rna; if (RNA_path_resolved_create(ptr, prop, fcu->array_index, &anim_rna)) { /* for making it easier to add corrective drivers... */ - cfra = evaluate_driver(&anim_rna, fcu->driver, fcu->driver, cfra); + cfra = evaluate_driver(&anim_rna, fcu->driver, fcu->driver, anim_eval_context); } else { cfra = 0.0f; @@ -1202,7 +1204,7 @@ bool insert_keyframe_direct(ReportList *reports, PointerRNA ptr, PropertyRNA *prop, FCurve *fcu, - float cfra, + const AnimationEvalContext *anim_eval_context, eBezTriple_KeyframeType keytype, struct NlaKeyframingContext *nla_context, eInsertKeyFlags flag) @@ -1274,7 +1276,7 @@ bool insert_keyframe_direct(ReportList *reports, MEM_freeN(values); } - return insert_keyframe_value(reports, &ptr, prop, fcu, cfra, curval, keytype, flag); + return insert_keyframe_value(reports, &ptr, prop, fcu, anim_eval_context, curval, keytype, flag); } /* Find or create the FCurve based on the given path, and insert the specified value into it. */ @@ -1286,7 +1288,7 @@ static bool insert_keyframe_fcurve_value(Main *bmain, const char group[], const char rna_path[], int array_index, - float cfra, + const AnimationEvalContext *anim_eval_context, float curval, eBezTriple_KeyframeType keytype, eInsertKeyFlags flag) @@ -1320,12 +1322,35 @@ static bool insert_keyframe_fcurve_value(Main *bmain, update_autoflags_fcurve_direct(fcu, prop); /* insert keyframe */ - return insert_keyframe_value(reports, ptr, prop, fcu, cfra, curval, keytype, flag); + return insert_keyframe_value( + reports, ptr, prop, fcu, anim_eval_context, curval, keytype, flag); } return false; } +static AnimationEvalContext nla_time_remap(const AnimationEvalContext *anim_eval_context, + PointerRNA *id_ptr, + AnimData *adt, + bAction *act, + ListBase *nla_cache, + NlaKeyframingContext **r_nla_context) +{ + if (adt && adt->action == act) { + /* Get NLA context for value remapping. */ + *r_nla_context = BKE_animsys_get_nla_keyframing_context( + nla_cache, id_ptr, adt, anim_eval_context, false); + + /* Apply NLA-mapping to frame. */ + const float remapped_frame = BKE_nla_tweakedit_remap( + adt, anim_eval_context->eval_time, NLATIME_CONVERT_UNMAP); + return BKE_animsys_eval_context_construct_at(anim_eval_context, remapped_frame); + } + + *r_nla_context = NULL; + return *anim_eval_context; +} + /** * Main Keyframing API call * @@ -1346,7 +1371,7 @@ int insert_keyframe(Main *bmain, const char group[], const char rna_path[], int array_index, - float cfra, + const AnimationEvalContext *anim_eval_context, eBezTriple_KeyframeType keytype, ListBase *nla_cache, eInsertKeyFlags flag) @@ -1393,15 +1418,8 @@ int insert_keyframe(Main *bmain, /* apply NLA-mapping to frame to use (if applicable) */ adt = BKE_animdata_from_id(id); - - if (adt && adt->action == act) { - /* Get NLA context for value remapping. */ - nla_context = BKE_animsys_get_nla_keyframing_context( - nla_cache ? nla_cache : &tmp_nla_cache, &id_ptr, adt, cfra, false); - - /* Apply NLA-mapping to frame. */ - cfra = BKE_nla_tweakedit_remap(adt, cfra, NLATIME_CONVERT_UNMAP); - } + const AnimationEvalContext remapped_context = nla_time_remap( + anim_eval_context, &id_ptr, adt, act, nla_cache ? nla_cache : &tmp_nla_cache, &nla_context); /* Obtain values to insert. */ float value_buffer[RNA_MAX_ARRAY_LENGTH]; @@ -1435,7 +1453,7 @@ int insert_keyframe(Main *bmain, group, rna_path, array_index, - cfra, + &remapped_context, values[array_index], keytype, flag)) { @@ -1458,7 +1476,7 @@ int insert_keyframe(Main *bmain, group, rna_path, array_index, - cfra, + &remapped_context, values[array_index], keytype, flag); @@ -1477,7 +1495,7 @@ int insert_keyframe(Main *bmain, group, rna_path, array_index, - cfra, + &remapped_context, values[array_index], keytype, flag); @@ -1495,7 +1513,7 @@ int insert_keyframe(Main *bmain, group, rna_path, array_index, - cfra, + &remapped_context, values[array_index], keytype, flag); @@ -2375,7 +2393,8 @@ static int insert_key_button_exec(bContext *C, wmOperator *op) PropertyRNA *prop = NULL; char *path; uiBut *but; - float cfra = (float)CFRA; + const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct( + CTX_data_depsgraph_pointer(C), (float)CFRA); bool changed = false; int index; const bool all = RNA_boolean_get(op->ptr, "all"); @@ -2401,7 +2420,7 @@ static int insert_key_button_exec(bContext *C, wmOperator *op) if (fcu) { changed = insert_keyframe_direct( - op->reports, ptr, prop, fcu, cfra, ts->keyframe_type, NULL, 0); + op->reports, ptr, prop, fcu, &anim_eval_context, ts->keyframe_type, NULL, 0); } else { BKE_report(op->reports, @@ -2417,8 +2436,14 @@ static int insert_key_button_exec(bContext *C, wmOperator *op) fcu = BKE_fcurve_find_by_rna_context_ui(C, &ptr, prop, index, NULL, NULL, &driven, &special); if (fcu && driven) { - changed = insert_keyframe_direct( - op->reports, ptr, prop, fcu, cfra, ts->keyframe_type, NULL, INSERTKEY_DRIVER); + changed = insert_keyframe_direct(op->reports, + ptr, + prop, + fcu, + &anim_eval_context, + ts->keyframe_type, + NULL, + INSERTKEY_DRIVER); } } else { @@ -2461,7 +2486,7 @@ static int insert_key_button_exec(bContext *C, wmOperator *op) group, path, index, - cfra, + &anim_eval_context, ts->keyframe_type, NULL, flag) != 0); @@ -2769,7 +2794,10 @@ bool fcurve_frame_has_keyframe(FCurve *fcu, float frame, short filter) } /* Returns whether the current value of a given property differs from the interpolated value. */ -bool fcurve_is_changed(PointerRNA ptr, PropertyRNA *prop, FCurve *fcu, float frame) +bool fcurve_is_changed(PointerRNA ptr, + PropertyRNA *prop, + FCurve *fcu, + const AnimationEvalContext *anim_eval_context) { PathResolvedRNA anim_rna; anim_rna.ptr = ptr; @@ -2780,7 +2808,7 @@ bool fcurve_is_changed(PointerRNA ptr, PropertyRNA *prop, FCurve *fcu, float fra int count, index = fcu->array_index; float *values = setting_get_rna_values(&ptr, prop, buffer, RNA_MAX_ARRAY_LENGTH, &count); - float fcurve_val = calculate_fcurve(&anim_rna, fcu, frame); + float fcurve_val = calculate_fcurve(&anim_rna, fcu, anim_eval_context); float cur_val = (index >= 0 && index < count) ? values[index] : 0.0f; if (values != buffer) { @@ -2987,6 +3015,9 @@ bool ED_autokeyframe_property( bContext *C, Scene *scene, PointerRNA *ptr, PropertyRNA *prop, int rnaindex, float cfra) { Main *bmain = CTX_data_main(C); + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); + const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct(depsgraph, + cfra); ID *id; bAction *action; FCurve *fcu; @@ -3007,7 +3038,8 @@ bool ED_autokeyframe_property( ReportList *reports = CTX_wm_reports(C); ToolSettings *ts = scene->toolsettings; - changed = insert_keyframe_direct(reports, *ptr, prop, fcu, cfra, ts->keyframe_type, NULL, 0); + changed = insert_keyframe_direct( + reports, *ptr, prop, fcu, &anim_eval_context, ts->keyframe_type, NULL, 0); WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); } } @@ -3020,7 +3052,7 @@ bool ED_autokeyframe_property( ToolSettings *ts = scene->toolsettings; changed = insert_keyframe_direct( - reports, *ptr, prop, fcu, cfra, ts->keyframe_type, NULL, INSERTKEY_DRIVER); + reports, *ptr, prop, fcu, &anim_eval_context, ts->keyframe_type, NULL, INSERTKEY_DRIVER); WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); } } @@ -3044,7 +3076,7 @@ bool ED_autokeyframe_property( ((fcu->grp) ? (fcu->grp->name) : (NULL)), fcu->rna_path, rnaindex, - cfra, + &anim_eval_context, ts->keyframe_type, NULL, flag) != 0; diff --git a/source/blender/editors/animation/keyingsets.c b/source/blender/editors/animation/keyingsets.c index 5e4b39d9d81..876740b889a 100644 --- a/source/blender/editors/animation/keyingsets.c +++ b/source/blender/editors/animation/keyingsets.c @@ -1120,6 +1120,9 @@ int ANIM_apply_keyingset( /* for each possible index, perform operation * - assume that arraylen is greater than index */ + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); + const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct(depsgraph, + cfra); for (; i < arraylen; i++) { /* action to take depends on mode */ if (mode == MODIFYKEY_MODE_INSERT) { @@ -1130,7 +1133,7 @@ int ANIM_apply_keyingset( groupname, ksp->rna_path, i, - cfra, + &anim_eval_context, keytype, &nla_cache, kflag2); diff --git a/source/blender/editors/armature/pose_lib.c b/source/blender/editors/armature/pose_lib.c index 6ce9ed06f1a..c9d0478270a 100644 --- a/source/blender/editors/armature/pose_lib.c +++ b/source/blender/editors/armature/pose_lib.c @@ -1023,7 +1023,8 @@ static void poselib_backup_free_data(tPoseLib_PreviewData *pld) * - gets the string to print in the header * - this code is based on the code for extract_pose_from_action in blenkernel/action.c */ -static void poselib_apply_pose(tPoseLib_PreviewData *pld) +static void poselib_apply_pose(tPoseLib_PreviewData *pld, + const AnimationEvalContext *anim_eval_context) { PointerRNA *ptr = &pld->rna_ptr; bArmature *arm = pld->arm; @@ -1049,6 +1050,8 @@ static void poselib_apply_pose(tPoseLib_PreviewData *pld) group_ok_cb = ANIM_editkeyframes_ok(BEZT_OK_FRAMERANGE); ked.f1 = ((float)frame) - 0.5f; ked.f2 = ((float)frame) + 0.5f; + AnimationEvalContext anim_context_at_frame = BKE_animsys_eval_context_construct_at( + anim_eval_context, frame); /* start applying - only those channels which have a key at this point in time! */ for (agrp = act->groups.first; agrp; agrp = agrp->next) { @@ -1075,7 +1078,7 @@ static void poselib_apply_pose(tPoseLib_PreviewData *pld) } if (ok) { - animsys_evaluate_action_group(ptr, act, agrp, (float)frame); + animsys_evaluate_action_group(ptr, act, agrp, &anim_context_at_frame); } } } @@ -1150,7 +1153,11 @@ static void poselib_preview_apply(bContext *C, wmOperator *op) /* pose should be the right one to draw (unless we're temporarily not showing it) */ if ((pld->flag & PL_PREVIEW_SHOWORIGINAL) == 0) { RNA_int_set(op->ptr, "pose_index", BLI_findindex(&pld->act->markers, pld->marker)); - poselib_apply_pose(pld); + struct Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); + + const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct( + depsgraph, 0.0f /* poselib_apply_pose() determines its own evaluation time. */); + poselib_apply_pose(pld, &anim_eval_context); } else { RNA_int_set(op->ptr, "pose_index", -2); /* -2 means don't apply any pose */ diff --git a/source/blender/editors/armature/pose_transform.c b/source/blender/editors/armature/pose_transform.c index 1d2bf152777..615d59c3154 100644 --- a/source/blender/editors/armature/pose_transform.c +++ b/source/blender/editors/armature/pose_transform.c @@ -1219,7 +1219,9 @@ static int pose_clear_user_transforms_exec(bContext *C, wmOperator *op) ViewLayer *view_layer = CTX_data_view_layer(C); View3D *v3d = CTX_wm_view3d(C); Scene *scene = CTX_data_scene(C); - float cframe = (float)CFRA; + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); + const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct(depsgraph, + (float)CFRA); const bool only_select = RNA_boolean_get(op->ptr, "only_selected"); FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, OB_ARMATURE, OB_MODE_POSE, ob) { @@ -1240,7 +1242,8 @@ static int pose_clear_user_transforms_exec(bContext *C, wmOperator *op) workob.adt = ob->adt; workob.pose = dummyPose; - BKE_animsys_evaluate_animdata(&workob.id, workob.adt, cframe, ADT_RECALC_ANIM, false); + BKE_animsys_evaluate_animdata( + &workob.id, workob.adt, &anim_eval_context, ADT_RECALC_ANIM, false); /* copy back values, but on selected bones only */ for (pchan = dummyPose->chanbase.first; pchan; pchan = pchan->next) { diff --git a/source/blender/editors/gpencil/gpencil_convert.c b/source/blender/editors/gpencil/gpencil_convert.c index e111ce44bc4..52e9a437830 100644 --- a/source/blender/editors/gpencil/gpencil_convert.c +++ b/source/blender/editors/gpencil/gpencil_convert.c @@ -48,6 +48,7 @@ #include "DNA_space_types.h" #include "DNA_view3d_types.h" +#include "BKE_animsys.h" #include "BKE_collection.h" #include "BKE_context.h" #include "BKE_curve.h" @@ -399,6 +400,7 @@ static void gpencil_stroke_path_animation_preprocess_gaps(tGpTimingData *gtd, static void gpencil_stroke_path_animation_add_keyframes(ReportList *reports, PointerRNA ptr, PropertyRNA *prop, + Depsgraph *depsgraph, FCurve *fcu, Curve *cu, tGpTimingData *gtd, @@ -453,8 +455,16 @@ static void gpencil_stroke_path_animation_add_keyframes(ReportList *reports, if ((cfra - last_valid_time) < MIN_TIME_DELTA) { cfra = last_valid_time + MIN_TIME_DELTA; } - insert_keyframe_direct( - reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_KEYFRAME, NULL, INSERTKEY_FAST); + const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct( + depsgraph, cfra); + insert_keyframe_direct(reports, + ptr, + prop, + fcu, + &anim_eval_context, + BEZT_KEYTYPE_KEYFRAME, + NULL, + INSERTKEY_FAST); last_valid_time = cfra; } else if (G.debug & G_DEBUG) { @@ -466,8 +476,16 @@ static void gpencil_stroke_path_animation_add_keyframes(ReportList *reports, if ((cfra - last_valid_time) < MIN_TIME_DELTA) { cfra = last_valid_time + MIN_TIME_DELTA; } - insert_keyframe_direct( - reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_KEYFRAME, NULL, INSERTKEY_FAST); + const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct(depsgraph, + cfra); + insert_keyframe_direct(reports, + ptr, + prop, + fcu, + &anim_eval_context, + BEZT_KEYTYPE_KEYFRAME, + NULL, + INSERTKEY_FAST); last_valid_time = cfra; } else { @@ -475,8 +493,16 @@ static void gpencil_stroke_path_animation_add_keyframes(ReportList *reports, * and also far enough from (not yet added!) end_stroke keyframe! */ if ((cfra - last_valid_time) > MIN_TIME_DELTA && (end_stroke_time - cfra) > MIN_TIME_DELTA) { - insert_keyframe_direct( - reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_BREAKDOWN, NULL, INSERTKEY_FAST); + const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct( + depsgraph, cfra); + insert_keyframe_direct(reports, + ptr, + prop, + fcu, + &anim_eval_context, + BEZT_KEYTYPE_BREAKDOWN, + NULL, + INSERTKEY_FAST); last_valid_time = cfra; } else if (G.debug & G_DEBUG) { @@ -496,6 +522,7 @@ static void gpencil_stroke_path_animation(bContext *C, { Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); bAction *act; FCurve *fcu; PointerRNA ptr; @@ -537,8 +564,16 @@ static void gpencil_stroke_path_animation(bContext *C, cu->ctime = 0.0f; cfra = (float)gtd->start_frame; - insert_keyframe_direct( - reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_KEYFRAME, NULL, INSERTKEY_FAST); + AnimationEvalContext anim_eval_context_start = BKE_animsys_eval_context_construct(depsgraph, + cfra); + insert_keyframe_direct(reports, + ptr, + prop, + fcu, + &anim_eval_context_start, + BEZT_KEYTYPE_KEYFRAME, + NULL, + INSERTKEY_FAST); cu->ctime = cu->pathlen; if (gtd->realtime) { @@ -547,8 +582,16 @@ static void gpencil_stroke_path_animation(bContext *C, else { cfra = (float)gtd->end_frame; } - insert_keyframe_direct( - reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_KEYFRAME, NULL, INSERTKEY_FAST); + AnimationEvalContext anim_eval_context_end = BKE_animsys_eval_context_construct(depsgraph, + cfra); + insert_keyframe_direct(reports, + ptr, + prop, + fcu, + &anim_eval_context_end, + BEZT_KEYTYPE_KEYFRAME, + NULL, + INSERTKEY_FAST); } else { /* Use actual recorded timing! */ @@ -575,7 +618,7 @@ static void gpencil_stroke_path_animation(bContext *C, } gpencil_stroke_path_animation_add_keyframes( - reports, ptr, prop, fcu, cu, gtd, rng, time_range, nbr_gaps, tot_gaps_time); + reports, ptr, prop, depsgraph, fcu, cu, gtd, rng, time_range, nbr_gaps, tot_gaps_time); BLI_rng_free(rng); } diff --git a/source/blender/editors/include/ED_anim_api.h b/source/blender/editors/include/ED_anim_api.h index bffa11a32f2..9d9f2925c23 100644 --- a/source/blender/editors/include/ED_anim_api.h +++ b/source/blender/editors/include/ED_anim_api.h @@ -95,6 +95,8 @@ typedef struct bAnimContext { struct Scene *scene; /** active scene layer */ struct ViewLayer *view_layer; + /** active dependency graph */ + struct Depsgraph *depsgraph; /** active object */ struct Object *obact; /** active set of markers */ diff --git a/source/blender/editors/include/ED_keyframing.h b/source/blender/editors/include/ED_keyframing.h index 5635ef2800a..3fe6407aae7 100644 --- a/source/blender/editors/include/ED_keyframing.h +++ b/source/blender/editors/include/ED_keyframing.h @@ -38,6 +38,7 @@ struct Scene; struct KeyingSet; +struct AnimationEvalContext; struct BezTriple; struct FCurve; struct bAction; @@ -118,7 +119,7 @@ bool insert_keyframe_direct(struct ReportList *reports, struct PointerRNA ptr, struct PropertyRNA *prop, struct FCurve *fcu, - float cfra, + const struct AnimationEvalContext *anim_eval_context, eBezTriple_KeyframeType keytype, struct NlaKeyframingContext *nla, eInsertKeyFlags flag); @@ -136,7 +137,7 @@ int insert_keyframe(struct Main *bmain, const char group[], const char rna_path[], int array_index, - float cfra, + const struct AnimationEvalContext *anim_eval_context, eBezTriple_KeyframeType keytype, struct ListBase *nla_cache, eInsertKeyFlags flag); @@ -458,7 +459,7 @@ bool fcurve_frame_has_keyframe(struct FCurve *fcu, float frame, short filter); bool fcurve_is_changed(struct PointerRNA ptr, struct PropertyRNA *prop, struct FCurve *fcu, - float frame); + const struct AnimationEvalContext *anim_eval_context); /** * Main Keyframe Checking API call: diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 28b86674fdd..106145005bd 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -44,6 +44,7 @@ #include "BLI_utildefines.h" +#include "BKE_animsys.h" #include "BKE_context.h" #include "BKE_idprop.h" #include "BKE_main.h" @@ -1733,6 +1734,7 @@ void UI_block_end_ex(const bContext *C, uiBlock *block, const int xy[2], int r_x wmWindow *window = CTX_wm_window(C); Scene *scene = CTX_data_scene(C); ARegion *region = CTX_wm_region(C); + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); uiBut *but; BLI_assert(block->active); @@ -1761,7 +1763,9 @@ void UI_block_end_ex(const bContext *C, uiBlock *block, const int xy[2], int r_x } } - ui_but_anim_flag(but, (scene) ? scene->r.cfra : 0.0f); + const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct( + depsgraph, (scene) ? scene->r.cfra : 0.0f); + ui_but_anim_flag(but, &anim_eval_context); ui_but_override_flag(CTX_data_main(C), but); if (UI_but_is_decorator(but)) { ui_but_anim_decorate_update_from_flag(but); diff --git a/source/blender/editors/interface/interface_anim.c b/source/blender/editors/interface/interface_anim.c index 5bf2147aff5..8d12a1dd1ad 100644 --- a/source/blender/editors/interface/interface_anim.c +++ b/source/blender/editors/interface/interface_anim.c @@ -33,6 +33,7 @@ #include "BLI_string_utf8.h" #include "BLI_utildefines.h" +#include "BKE_animsys.h" #include "BKE_context.h" #include "BKE_fcurve.h" #include "BKE_fcurve_driver.h" @@ -65,7 +66,7 @@ static FCurve *ui_but_get_fcurve( but->block->evil_C, &but->rnapoin, but->rnaprop, rnaindex, adt, action, r_driven, r_special); } -void ui_but_anim_flag(uiBut *but, float cfra) +void ui_but_anim_flag(uiBut *but, const AnimationEvalContext *anim_eval_context) { AnimData *adt; bAction *act; @@ -95,6 +96,7 @@ void ui_but_anim_flag(uiBut *but, float cfra) * we need to correct the frame number to "look inside" the * remapped action */ + float cfra = anim_eval_context->eval_time; if (adt) { cfra = BKE_nla_tweakedit_remap(adt, cfra, NLATIME_CONVERT_UNMAP); } @@ -105,7 +107,9 @@ void ui_but_anim_flag(uiBut *but, float cfra) /* XXX: this feature is totally broken and useless with NLA */ if (adt == NULL || adt->nla_tracks.first == NULL) { - if (fcurve_is_changed(but->rnapoin, but->rnaprop, fcu, cfra)) { + const AnimationEvalContext remapped_context = BKE_animsys_eval_context_construct_at( + anim_eval_context, cfra); + if (fcurve_is_changed(but->rnapoin, but->rnaprop, fcu, &remapped_context)) { but->drawflag |= UI_BUT_ANIMATED_CHANGED; } } diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 43c91f1d2eb..988d19e30d3 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -47,6 +47,7 @@ #include "PIL_time.h" +#include "BKE_animsys.h" #include "BKE_blender_undo.h" #include "BKE_brush.h" #include "BKE_colorband.h" @@ -8408,6 +8409,9 @@ void UI_context_update_anim_flag(const bContext *C) { Scene *scene = CTX_data_scene(C); ARegion *region = CTX_wm_region(C); + struct Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); + const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct( + depsgraph, (scene) ? scene->r.cfra : 0.0f); uiBlock *block; uiBut *but, *activebut; @@ -8417,7 +8421,7 @@ void UI_context_update_anim_flag(const bContext *C) for (block = region->uiblocks.first; block; block = block->next) { for (but = block->buttons.first; but; but = but->next) { - ui_but_anim_flag(but, (scene) ? scene->r.cfra : 0.0f); + ui_but_anim_flag(but, &anim_eval_context); ui_but_override_flag(CTX_data_main(C), but); if (UI_but_is_decorator(but)) { ui_but_anim_decorate_update_from_flag(but); diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index a7cbfc23399..249134c6abf 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -32,6 +32,7 @@ #include "UI_interface.h" #include "UI_resources.h" +struct AnimationEvalContext; struct ARegion; struct ID; struct ImBuf; @@ -938,7 +939,7 @@ int ui_but_align_opposite_to_area_align_get(const struct ARegion *region) ATTR_W void ui_block_align_calc(uiBlock *block, const struct ARegion *region); /* interface_anim.c */ -void ui_but_anim_flag(uiBut *but, float cfra); +void ui_but_anim_flag(uiBut *but, const struct AnimationEvalContext *anim_eval_context); void ui_but_anim_copy_driver(struct bContext *C); void ui_but_anim_paste_driver(struct bContext *C); bool ui_but_anim_expression_get(uiBut *but, char *str, size_t maxlen); diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index 6f254ea9400..4470269ec23 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -2796,12 +2796,16 @@ static int ocean_bake_exec(bContext *C, wmOperator *op) cfra = scene->r.cfra; /* precalculate time variable before baking */ + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); for (f = omd->bakestart; f <= omd->bakeend; f++) { /* For now only simple animation of time value is supported, nothing else. * No drivers or other modifier parameters. */ /* TODO(sergey): This operates on an original data, so no flush is needed. However, baking * usually should happen on an evaluated objects, so this seems to be deeper issue here. */ - BKE_animsys_evaluate_animdata((ID *)ob, ob->adt, f, ADT_RECALC_ANIM, false); + + const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct(depsgraph, + f); + BKE_animsys_evaluate_animdata((ID *)ob, ob->adt, &anim_eval_context, ADT_RECALC_ANIM, false); och->time[i] = omd->time; i++; diff --git a/source/blender/editors/space_action/action_edit.c b/source/blender/editors/space_action/action_edit.c index 185066b49ce..af8e0e9d9de 100644 --- a/source/blender/editors/space_action/action_edit.c +++ b/source/blender/editors/space_action/action_edit.c @@ -724,9 +724,10 @@ static void insert_action_keys(bAnimContext *ac, short mode) flag = ANIM_get_keyframing_flags(scene, true); /* insert keyframes */ + const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct(ac->depsgraph, + (float)CFRA); for (ale = anim_data.first; ale; ale = ale->next) { FCurve *fcu = (FCurve *)ale->key_data; - float cfra = (float)CFRA; /* Read value from property the F-Curve represents, or from the curve only? * - ale->id != NULL: @@ -745,7 +746,7 @@ static void insert_action_keys(bAnimContext *ac, short mode) ((fcu->grp) ? (fcu->grp->name) : (NULL)), fcu->rna_path, fcu->array_index, - cfra, + &anim_eval_context, ts->keyframe_type, &nla_cache, flag); @@ -754,8 +755,9 @@ static void insert_action_keys(bAnimContext *ac, short mode) AnimData *adt = ANIM_nla_mapping_get(ac, ale); /* adjust current frame for NLA-scaling */ + float cfra = anim_eval_context.eval_time; if (adt) { - cfra = BKE_nla_tweakedit_remap(adt, (float)CFRA, NLATIME_CONVERT_UNMAP); + cfra = BKE_nla_tweakedit_remap(adt, cfra, NLATIME_CONVERT_UNMAP); } const float curval = evaluate_fcurve(fcu, cfra); diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c index 1925a3847d6..68fdef54a53 100644 --- a/source/blender/editors/space_graph/graph_edit.c +++ b/source/blender/editors/space_graph/graph_edit.c @@ -681,9 +681,10 @@ static void insert_graph_keys(bAnimContext *ac, eGraphKeys_InsertKey_Types mode) } } else { + const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct( + ac->depsgraph, (float)CFRA); for (ale = anim_data.first; ale; ale = ale->next) { FCurve *fcu = (FCurve *)ale->key_data; - float cfra = (float)CFRA; /* Read value from property the F-Curve represents, or from the curve only? * @@ -705,7 +706,7 @@ static void insert_graph_keys(bAnimContext *ac, eGraphKeys_InsertKey_Types mode) ((fcu->grp) ? (fcu->grp->name) : (NULL)), fcu->rna_path, fcu->array_index, - cfra, + &anim_eval_context, ts->keyframe_type, &nla_cache, flag); @@ -714,6 +715,7 @@ static void insert_graph_keys(bAnimContext *ac, eGraphKeys_InsertKey_Types mode) AnimData *adt = ANIM_nla_mapping_get(ac, ale); /* adjust current frame for NLA-mapping */ + float cfra = (float)CFRA; if ((sipo) && (sipo->mode == SIPO_MODE_DRIVERS)) { cfra = sipo->cursorTime; } diff --git a/source/blender/editors/transform/transform_convert_armature.c b/source/blender/editors/transform/transform_convert_armature.c index f721ed0b866..9885c8fc3a6 100644 --- a/source/blender/editors/transform/transform_convert_armature.c +++ b/source/blender/editors/transform/transform_convert_armature.c @@ -115,7 +115,9 @@ static void autokeyframe_pose( ToolSettings *ts = scene->toolsettings; KeyingSet *active_ks = ANIM_scene_get_active_keyingset(scene); ListBase nla_cache = {NULL, NULL}; - float cfra = (float)CFRA; + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); + const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct(depsgraph, + (float)CFRA); eInsertKeyFlags flag = 0; /* flag is initialized from UserPref keyframing settings @@ -146,7 +148,8 @@ static void autokeyframe_pose( /* only insert into active keyingset? */ if (IS_AUTOKEY_FLAG(scene, ONLYKEYINGSET) && (active_ks)) { /* run the active Keying Set on the current datasource */ - ANIM_apply_keyingset(C, &dsources, NULL, active_ks, MODIFYKEY_MODE_INSERT, cfra); + ANIM_apply_keyingset( + C, &dsources, NULL, active_ks, MODIFYKEY_MODE_INSERT, anim_eval_context.eval_time); } /* only insert into available channels? */ else if (IS_AUTOKEY_FLAG(scene, INSERTAVAIL)) { @@ -169,7 +172,7 @@ static void autokeyframe_pose( ((fcu->grp) ? (fcu->grp->name) : (NULL)), fcu->rna_path, fcu->array_index, - cfra, + &anim_eval_context, ts->keyframe_type, &nla_cache, flag); @@ -220,21 +223,25 @@ static void autokeyframe_pose( if (do_loc) { KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_LOCATION_ID); - ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra); + ANIM_apply_keyingset( + C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, anim_eval_context.eval_time); } if (do_rot) { KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_ROTATION_ID); - ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra); + ANIM_apply_keyingset( + C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, anim_eval_context.eval_time); } if (do_scale) { KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_SCALING_ID); - ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra); + ANIM_apply_keyingset( + C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, anim_eval_context.eval_time); } } /* insert keyframe in all (transform) channels */ else { KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_LOC_ROT_SCALE_ID); - ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra); + ANIM_apply_keyingset( + C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, anim_eval_context.eval_time); } /* free temp info */ diff --git a/source/blender/editors/transform/transform_convert_object.c b/source/blender/editors/transform/transform_convert_object.c index 92ed477eb25..2e92b4e5c09 100644 --- a/source/blender/editors/transform/transform_convert_object.c +++ b/source/blender/editors/transform/transform_convert_object.c @@ -794,7 +794,9 @@ static void autokeyframe_object( ToolSettings *ts = scene->toolsettings; KeyingSet *active_ks = ANIM_scene_get_active_keyingset(scene); ListBase dsources = {NULL, NULL}; - float cfra = (float)CFRA; // xxx this will do for now + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); + const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct(depsgraph, + (float)CFRA); eInsertKeyFlags flag = 0; /* Get flags used for inserting keyframes. */ @@ -808,7 +810,8 @@ static void autokeyframe_object( * NOTE: we assume here that the active Keying Set * does not need to have its iterator overridden. */ - ANIM_apply_keyingset(C, &dsources, NULL, active_ks, MODIFYKEY_MODE_INSERT, cfra); + ANIM_apply_keyingset( + C, &dsources, NULL, active_ks, MODIFYKEY_MODE_INSERT, anim_eval_context.eval_time); } else if (IS_AUTOKEY_FLAG(scene, INSERTAVAIL)) { AnimData *adt = ob->adt; @@ -824,7 +827,7 @@ static void autokeyframe_object( (fcu->grp ? fcu->grp->name : NULL), fcu->rna_path, fcu->array_index, - cfra, + &anim_eval_context, ts->keyframe_type, &nla_cache, flag); @@ -872,21 +875,25 @@ static void autokeyframe_object( /* 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); - ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra); + ANIM_apply_keyingset( + C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, anim_eval_context.eval_time); } if (do_rot) { KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_ROTATION_ID); - ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra); + ANIM_apply_keyingset( + C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, anim_eval_context.eval_time); } if (do_scale) { KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_SCALING_ID); - ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra); + ANIM_apply_keyingset( + C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, anim_eval_context.eval_time); } } /* insert keyframe in all (transform) channels */ else { KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_LOC_ROT_SCALE_ID); - ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra); + ANIM_apply_keyingset( + C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, anim_eval_context.eval_time); } /* free temp info */ |