Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/fcurve_driver.c
| Show All 37 Lines | |||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_string_utils.h" | #include "BLI_string_utils.h" | ||||
| #include "BLI_threads.h" | #include "BLI_threads.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BLT_translation.h" | #include "BLT_translation.h" | ||||
| #include "BKE_action.h" | #include "BKE_action.h" | ||||
| #include "BKE_animsys.h" | |||||
| #include "BKE_armature.h" | #include "BKE_armature.h" | ||||
| #include "BKE_constraint.h" | #include "BKE_constraint.h" | ||||
| #include "BKE_fcurve_driver.h" | #include "BKE_fcurve_driver.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| ▲ Show 20 Lines • Show All 1,173 Lines • ▼ Show 20 Lines | static void evaluate_driver_min_max(ChannelDriver *driver) | ||||
| /* store value in driver */ | /* store value in driver */ | ||||
| driver->curval = value; | driver->curval = value; | ||||
| } | } | ||||
| static void evaluate_driver_python(PathResolvedRNA *anim_rna, | static void evaluate_driver_python(PathResolvedRNA *anim_rna, | ||||
| ChannelDriver *driver, | ChannelDriver *driver, | ||||
| ChannelDriver *driver_orig, | ChannelDriver *driver_orig, | ||||
| const float evaltime) | const AnimationEvalContext *anim_eval_context) | ||||
| { | { | ||||
| /* check for empty or invalid expression */ | /* check for empty or invalid expression */ | ||||
| if ((driver_orig->expression[0] == '\0') || (driver_orig->flag & DRIVER_FLAG_INVALID)) { | if ((driver_orig->expression[0] == '\0') || (driver_orig->flag & DRIVER_FLAG_INVALID)) { | ||||
| driver->curval = 0.0f; | driver->curval = 0.0f; | ||||
| } | } | ||||
| else if (!driver_try_evaluate_simple_expr(driver, driver_orig, &driver->curval, evaltime)) { | else if (!driver_try_evaluate_simple_expr( | ||||
| driver, driver_orig, &driver->curval, anim_eval_context->eval_time)) { | |||||
| #ifdef WITH_PYTHON | #ifdef WITH_PYTHON | ||||
| /* this evaluates the expression using Python, and returns its result: | /* this evaluates the expression using Python, and returns its result: | ||||
| * - on errors it reports, then returns 0.0f | * - on errors it reports, then returns 0.0f | ||||
| */ | */ | ||||
| BLI_mutex_lock(&python_driver_lock); | BLI_mutex_lock(&python_driver_lock); | ||||
| driver->curval = BPY_driver_exec(anim_rna, driver, driver_orig, evaltime); | driver->curval = BPY_driver_exec(anim_rna, driver, driver_orig, anim_eval_context); | ||||
| BLI_mutex_unlock(&python_driver_lock); | BLI_mutex_unlock(&python_driver_lock); | ||||
| #else /* WITH_PYTHON*/ | #else /* WITH_PYTHON*/ | ||||
| UNUSED_VARS(anim_rna, evaltime); | UNUSED_VARS(anim_rna, anim_eval_context); | ||||
| #endif /* WITH_PYTHON*/ | #endif /* WITH_PYTHON*/ | ||||
| } | } | ||||
| } | } | ||||
| /* Evaluate an Channel-Driver to get a 'time' value to use instead of "evaltime" | /* Evaluate an Channel-Driver to get a 'time' value to use instead of "evaltime" | ||||
| * - "evaltime" is the frame at which F-Curve is being evaluated | * - "evaltime" is the frame at which F-Curve is being evaluated | ||||
| * - has to return a float value | * - has to return a float value | ||||
| * - driver_orig is where we cache Python expressions, in case of COW | * - driver_orig is where we cache Python expressions, in case of COW | ||||
| */ | */ | ||||
| float evaluate_driver(PathResolvedRNA *anim_rna, | float evaluate_driver(PathResolvedRNA *anim_rna, | ||||
| ChannelDriver *driver, | ChannelDriver *driver, | ||||
| ChannelDriver *driver_orig, | ChannelDriver *driver_orig, | ||||
| const float evaltime) | const AnimationEvalContext *anim_eval_context) | ||||
| { | { | ||||
| /* check if driver can be evaluated */ | /* check if driver can be evaluated */ | ||||
| if (driver_orig->flag & DRIVER_FLAG_INVALID) { | if (driver_orig->flag & DRIVER_FLAG_INVALID) { | ||||
| return 0.0f; | return 0.0f; | ||||
| } | } | ||||
| switch (driver->type) { | switch (driver->type) { | ||||
| case DRIVER_TYPE_AVERAGE: /* average values of driver targets */ | case DRIVER_TYPE_AVERAGE: /* average values of driver targets */ | ||||
| case DRIVER_TYPE_SUM: /* sum values of driver targets */ | case DRIVER_TYPE_SUM: /* sum values of driver targets */ | ||||
| evaluate_driver_sum(driver); | evaluate_driver_sum(driver); | ||||
| break; | break; | ||||
| case DRIVER_TYPE_MIN: /* smallest value */ | case DRIVER_TYPE_MIN: /* smallest value */ | ||||
| case DRIVER_TYPE_MAX: /* largest value */ | case DRIVER_TYPE_MAX: /* largest value */ | ||||
| evaluate_driver_min_max(driver); | evaluate_driver_min_max(driver); | ||||
| break; | break; | ||||
| case DRIVER_TYPE_PYTHON: /* expression */ | case DRIVER_TYPE_PYTHON: /* expression */ | ||||
| evaluate_driver_python(anim_rna, driver, driver_orig, evaltime); | evaluate_driver_python(anim_rna, driver, driver_orig, anim_eval_context); | ||||
| break; | break; | ||||
| default: | default: | ||||
| /* special 'hack' - just use stored value | /* special 'hack' - just use stored value | ||||
| * This is currently used as the mechanism which allows animated settings to be able | * This is currently used as the mechanism which allows animated settings to be able | ||||
| * to be changed via the UI. | * to be changed via the UI. | ||||
| */ | */ | ||||
| break; | break; | ||||
| } | } | ||||
| /* return value for driver */ | /* return value for driver */ | ||||
| return driver->curval; | return driver->curval; | ||||
| } | } | ||||