Page MenuHome

T77086 Animation: Passing Dependency Graph to Drivers
Needs ReviewPublic

Authored by Sybren A. Stüvel (sybren) on Tue, Jun 16, 12:40 PM.

Details

Summary

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. This points to a struct that's currently defined in BKE_animsys.h (I'm open to suggestions for other places to put it):

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.

There are two functions that allow creation of AnimationEvalContext objects:

  • BKE_animsys_eval_context(Depsgraph *depsgraph, float eval_time), which creates a new context object from scratch, and
  • BKE_animsys_eval_context_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.

While I was going over all the changes, I noticed that time remapping for NLA strips is done in very similar ways in various places of the code. I feel that this is something that should be refactored into a single function. This is outside the scope of this patch, though.

This also provides a fix for T75553: python unreliable result for bpy.context.view_layer.name when used in drivers, 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.

I have tested the code on a simple walk animation from Blender Cloud, as well as the EEVEE version of Spring. The test included creating an NLA action for the simple walk animation, and moving it around and animating its evaluation time.

@Clément Foucault (fclem) was added as a reviewer for the changes to EEVEE (it evaluates animation for motion blur), and @Antonio Vazquez (antoniov) for the grease pencil code.

Diff Detail

Repository
rB Blender
Branch
temp-T77086-depsgraph-pass-to-drivers (branched from master)
Build Status
Buildable 8580
Build 8580: arc lint + arc unit