diff options
author | Sybren A. Stüvel <sybren> | 2020-07-17 18:38:09 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2020-07-20 12:51:09 +0300 |
commit | 686ab4c9401a90b22fb17e46c992eb513fe4f693 (patch) | |
tree | c83b4da92fbd12b0c78e2ce5c3041ada23b5ef4b /source/blender/editors/interface | |
parent | 6fbfa522e66d41839449899ab53dbf20d280d5ec (diff) |
T77086 Animation: Passing Dependency Graph to Drivers
Custom driver functions need access to the dependency graph that is
triggering the evaluation of the driver. This patch passes the
dependency graph pointer through all the animation-related calls.
Instead of passing the evaluation time to functions, the code now passes
an `AnimationEvalContext` pointer:
```
typedef struct AnimationEvalContext {
struct Depsgraph *const depsgraph;
const float eval_time;
} AnimationEvalContext;
```
These structs are read-only, meaning that the code cannot change the
evaluation time. Note that the `depsgraph` pointer itself is const, but
it points to a non-const depsgraph.
FCurves and Drivers can be evaluated at a different time than the
current scene time, for example when evaluating NLA strips. This means
that, even though the current time is stored in the dependency graph, we
need an explicit evaluation time.
There are two functions that allow creation of `AnimationEvalContext`
objects:
- `BKE_animsys_eval_context_construct(Depsgraph *depsgraph, float
eval_time)`, which creates a new context object from scratch, and
- `BKE_animsys_eval_context_construct_at(AnimationEvalContext
*anim_eval_context, float eval_time)`, which can be used to create a
`AnimationEvalContext` with the same depsgraph, but at a different
time. This makes it possible to later add fields without changing any
of the code that just want to change the eval time.
This also provides a fix for T75553, although it does require a change
to the custom driver function. The driver should call
`custom_function(depsgraph)`, and the function should use that depsgraph
instead of information from `bpy.context`.
Reviewed By: brecht, sergey
Differential Revision: https://developer.blender.org/D8047
Diffstat (limited to 'source/blender/editors/interface')
4 files changed, 18 insertions, 5 deletions
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); |