40#include "RNA_prototypes.hh"
58static Mutex python_driver_lock;
81#define BEGIN_DVAR_TYPEDEF(type) {
84#define END_DVAR_TYPEDEF }
100 return driver_target_context;
116 &driver_target_context->
scene->
id, RNA_ViewLayer, driver_target_context->
view_layer);
126 *r_property_ptr = {};
140 if (dtar->
id ==
nullptr) {
174 if (driver ==
nullptr) {
202 &property_ptr, dtar->
rna_path, &value_ptr, &value_prop, &
index))
211 "Driver Evaluation Error: cannot resolve target for %s -> %s",
231 "Driver Evaluation Error: array index is out of bounds for %s -> %s (%d)",
295 if (
ELEM(
nullptr, driver, dtar)) {
334 "Driver Evaluation Error: cannot resolve target for %s -> %s",
351 const bool allow_no_index =
true;
363 "Driver Evaluation Error: array index is out of bounds for %s -> %s (%d)",
382 short valid_targets = 0;
385 Object *ob = id_cast<Object *>(dtar->id);
401 return valid_targets;
430 "RotDiff DVar: not enough valid targets (n = %d) (a = %p, b = %p)",
438 const float (*mat[2])[4];
441 for (
int i = 0; i < 2; i++) {
444 Object *ob = id_cast<Object *>(dtar->
id);
460 mat[i] = ob->object_to_world().ptr();
464 float q1[4], q2[4], quat[4],
angle;
487 float loc1[3] = {0.0f, 0.0f, 0.0f};
488 float loc2[3] = {0.0f, 0.0f, 0.0f};
492 if (valid_targets < dvar->num_targets) {
495 "LocDiff DVar: not enough valid targets (n = %d) (a = %p, b = %p)",
507 Object *ob = id_cast<Object *>(dtar->id);
540 mul_m4_v3(ob->object_to_world().ptr(), tmp_loc);
565 copy_v3_v3(tmp_loc, ob->object_to_world().location());
592 Object *ob = id_cast<Object *>(dtar->
id);
595 float oldEul[3] = {0.0f, 0.0f, 0.0f};
596 bool use_eulers =
false;
719 return quat[channel];
741 for (
int i = 1; i < 4; i++) {
745 else if (channel == 0) {
749 quat[channel] = 2.0f *
safe_asinf(quat[channel]);
754 float mat[4][4],
int auto_order,
int rotation_mode,
int channel,
bool angles,
float r_buf[4])
756 float *
const quat = r_buf;
757 float *
const eul = r_buf + 1;
779 float raw_quat[4], twist;
783 if (channel == axis + 1) {
793 quat[axis + 1] = twist;
816 {
"Object/Bone 1",
"Object/Bone 2"},
823 {
"Object/Bone 1",
"Object/Bone 2"},
861 if (dvar ==
nullptr) {
872 if (dtar->rna_path) {
873 MEM_delete(dtar->rna_path);
900 if (dtar->rna_path) {
901 dtar->rna_path = MEM_dupalloc(dtar->rna_path);
913 if (
ELEM(
nullptr, dvar, dvti)) {
931 dtar->idtype =
ID_OB;
940 const char special_char_blacklist[] = {
941 '~',
'`',
'!',
'@',
'#',
'$',
'%',
'^',
'&',
'*',
'+',
'=',
'-',
'/',
'\\',
942 '?',
':',
';',
'<',
'>',
'{',
'}',
'[',
']',
'|',
' ',
'.',
'\t',
'\n',
'\r',
946 if (dvar ==
nullptr) {
954 if (dvar->
name[0] ==
'\0') {
964 else if (dvar->
name[0] ==
'_') {
971 if (strchr(dvar->
name,
' ')) {
974 if (strchr(dvar->
name,
'.')) {
979 for (
int i = 0; i <
sizeof(special_char_blacklist); i++) {
980 char *match = strchr(dvar->
name, special_char_blacklist[i]);
982 if (match == dvar->
name) {
985 else if (match !=
nullptr) {
1017 if (driver ==
nullptr) {
1022 dvar = MEM_new<DriverVar>(
"DriverVar");
1026 const char *name_default =
"var";
1055 for (dvar = driver->
variables.first(); dvar; dvar = dvarn) {
1080 if (driver ==
nullptr) {
1085 ndriver = MEM_dupalloc(driver);
1116 int names_len = driver->
variables.count();
1117 const char **names =
static_cast<const char **
>(
1124 names[i++] = dvar.
name;
1143 int vars_len = driver->
variables.count();
1157 const char *message;
1161 if (isfinite(result_val)) {
1230 if (expression[0] ==
'\0') {
1234 if (strchr(expression,
'(') !=
nullptr) {
1238 if (strstr(expression,
"frame") !=
nullptr) {
1264 bool varname_changed)
1266 if (expr_changed || varname_changed) {
1276 if (varname_changed) {
1295 if (
ELEM(
nullptr, driver, dvar)) {
1339 driver->
curval = tot ? (value /
float(tot)) : 0.0f;
1361 value = std::max(tmp_val, value);
1365 value = std::min(tmp_val, value);
1396 std::scoped_lock
lock(python_driver_lock);
1416 switch (driver->
type) {
Blender kernel action and pose functionality.
#define DRIVER_TARGETS_LOOPER_BEGIN(dvar)
#define DRIVER_TARGETS_USED_LOOPER_BEGIN(dvar)
#define DRIVER_TARGETS_LOOPER_END
General operations, lookup, etc. for blender objects.
#define BLI_array_alloca(arr, realsize)
#define STRNCPY_UTF8(dst, src)
#define CLOG_ERROR(clg_ref,...)
#define CLOG_WARN(clg_ref,...)
#define MAX_DRIVER_TARGETS
#define DVAR_ALL_INVALID_FLAGS
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
Provides wrapper around system-specific atomic primitives, and some extensions (faked-atomic operatio...
ATOMIC_INLINE void * atomic_cas_ptr(void **v, void *old, void *_new)
#define BLI_assert_unreachable()
#define IN_RANGE_INCL(a, b, c)
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
#define BEGIN_DVAR_TYPEDEF(type)
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static bool driver_compile_simple_expr(ChannelDriver *driver)
static bool python_driver_exression_depends_on_time(const char *expression)
@ DVAR_TYPE_TRANSFORM_CHAN
static float dvar_eval_rotDiff(const AnimationEvalContext *, ChannelDriver *driver, DriverVar *dvar)
static float dvar_eval_contextProp(const AnimationEvalContext *anim_eval_context, ChannelDriver *driver, DriverVar *dvar)
MINLINE float safe_asinf(float a)
static short driver_check_valid_targets(ChannelDriver *driver, DriverVar *dvar)
MINLINE void copy_v3_v3(float r[3], const float a[3])
static void evaluate_driver_python(PathResolvedRNA *anim_rna, ChannelDriver *driver, ChannelDriver *driver_orig, const AnimationEvalContext *anim_eval_context)
void mat4_to_quat(float q[4], const float mat[4][4])
static bool driver_try_evaluate_simple_expr(const AnimationEvalContext *anim_eval_context, ChannelDriver *driver, ChannelDriver *driver_orig, float *result, float time)
float quat_split_swing_and_twist(const float q_in[4], int axis, float r_swing[4], float r_twist[4])
void BKE_driver_invalidate_expression(struct ChannelDriver *driver, bool expr_changed, bool varname_changed)
PointerRNA RNA_id_pointer_create(ID *id)
float BPY_driver_exec(PathResolvedRNA *anim_rna, ChannelDriver *driver, ChannelDriver *driver_orig, const AnimationEvalContext *anim_eval_context)
float evaluate_driver(struct PathResolvedRNA *anim_rna, struct ChannelDriver *driver, struct ChannelDriver *driver_orig, const struct AnimationEvalContext *anim_eval_context)
void void void void void void BLI_duplicatelist(ListBase *dst, const ListBase *src) ATTR_NONNULL(1
ExprPyLike_Parsed * BLI_expr_pylike_parse(const char *expression, const char **param_names, int param_names_len)
@ EXPR_PYLIKE_DIV_BY_ZERO
void BKE_driver_target_matrix_to_rot_channels(float mat[4][4], int auto_order, int rotation_mode, int channel, bool angles, float r_buf[4])
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
float RNA_property_float_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
struct ChannelDriver * fcurve_copy_driver(const struct ChannelDriver *driver)
void driver_free_variable_ex(struct ChannelDriver *driver, struct DriverVar *dvar)
MINLINE float safe_acosf(float a)
bool BPY_string_is_keyword(const char *str)
static float dvar_eval_transChan(const AnimationEvalContext *, ChannelDriver *driver, DriverVar *dvar)
eDriverVariablePropertyResult driver_get_variable_property(const struct AnimationEvalContext *anim_eval_context, struct ChannelDriver *driver, struct DriverVar *dvar, struct DriverTarget *dtar, struct PointerRNA *r_ptr, struct PropertyRNA **r_prop, int *r_index)
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
void BPY_DECREF(void *pyob_ptr)
void mul_qt_qtqt(float q[4], const float a[4], const float b[4])
void BKE_pchan_to_mat4(bke::PChanBoneConst pchanbone, float r_chanmat[4][4])
@ DTAR_ROTMODE_QUATERNION
@ DTAR_ROTMODE_SWING_TWIST_Z
@ DTAR_ROTMODE_SWING_TWIST_X
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
bool RNA_property_array_check(PropertyRNA *prop)
MINLINE void zero_v4(float r[4])
void mul_m4_v3(const float M[4][4], float r[3])
PropertyType RNA_property_type(PropertyRNA *prop)
static DriverTargetContext driver_target_context_from_animation_context(const AnimationEvalContext *anim_eval_context)
bool driver_get_target_property(const DriverTargetContext *driver_target_context, struct DriverVar *dvar, struct DriverTarget *dtar, struct PointerRNA *r_prop)
eExprPyLike_EvalStatus BLI_expr_pylike_eval(struct ExprPyLike_Parsed *expr, const double *param_values, int param_values_len, double *r_result)
void BLI_uniquename(const ListBase *list, void *vlink, const char *defname, char delim, int name_offset, size_t name_maxncpy) ATTR_NONNULL(1
static float dvar_eval_locDiff(const AnimationEvalContext *, ChannelDriver *driver, DriverVar *dvar)
void BKE_constraint_mat_convertspace(struct Object *ob, struct bPoseChannel *pchan, struct bConstraintOb *cob, float mat[4][4], short from, short to, bool keep_scale)
static void evaluate_driver_min_max(const AnimationEvalContext *anim_eval_context, ChannelDriver *driver)
static bool driver_check_simple_expr_depends_on_time(const ExprPyLike_Parsed *expr)
void BLI_expr_pylike_free(struct ExprPyLike_Parsed *expr)
static void evaluate_driver_sum(const AnimationEvalContext *anim_eval_context, ChannelDriver *driver)
static DriverVarTypeInfo dvar_types[MAX_DVAR_TYPES]
void BKE_object_to_mat4(const Object *ob, float r_mat[4][4])
@ DTAR_CONTEXT_PROPERTY_ACTIVE_SCENE
@ DTAR_CONTEXT_PROPERTY_ACTIVE_VIEW_LAYER
bool RNA_property_boolean_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
@ DTAR_OPTION_USE_FALLBACK
eDriverVariablePropertyResult
@ DRIVER_VAR_PROPERTY_SUCCESS
@ DRIVER_VAR_PROPERTY_FALLBACK
@ DRIVER_VAR_PROPERTY_INVALID_INDEX
@ DRIVER_VAR_PROPERTY_INVALID
void BLI_freelinkN(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
static void quaternion_to_angles(float quat[4], int channel)
void invert_qt_normalized(float q[4])
void driver_variable_name_validate(struct DriverVar *dvar)
static float dtar_get_prop_val(const AnimationEvalContext *anim_eval_context, ChannelDriver *driver, DriverVar *dvar, DriverTarget *dtar)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
ViewLayer * DEG_get_evaluated_view_layer(const Depsgraph *graph)
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
static float dvar_eval_singleProp(const AnimationEvalContext *anim_eval_context, ChannelDriver *driver, DriverVar *dvar)
void mat4_to_eulO(float eul[3], short order, const float m[4][4])
float driver_get_variable_value(const struct AnimationEvalContext *anim_eval_context, struct ChannelDriver *driver, struct DriverVar *dvar)
@ DTAR_TRANSCHAN_SCALE_AVG
@ MAX_DTAR_TRANSCHAN_TYPES
float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
static bool dtar_try_use_fallback(DriverTarget *dtar)
static const DriverVarTypeInfo * get_dvar_typeinfo(eDriverVar_Types type)
bool BLI_expr_pylike_is_valid(const struct ExprPyLike_Parsed *expr)
void driver_variable_unique_name(struct DriverVar *dvar)
ID_Type GS(const char *name)
bool BKE_driver_expression_depends_on_time(struct ChannelDriver *driver)
static bool driver_get_target_context_property(const DriverTargetContext *driver_target_context, DriverTarget *dtar, PointerRNA *r_property_ptr)
void fcurve_free_driver(struct FCurve *fcu)
static ExprPyLike_Parsed * driver_compile_simple_expr_impl(ChannelDriver *driver)
void compatible_eul(float eul[3], const float oldrot[3])
void copy_m4_m4(float m1[4][4], const float m2[4][4])
float mat4_to_volume_scale(const float mat[4][4])
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
@ DTAR_FLAG_FALLBACK_USED
@ DVAR_FLAG_INVALID_HAS_DOT
@ DVAR_FLAG_INVALID_EMPTY
@ DVAR_FLAG_INVALID_HAS_SPECIAL
@ DVAR_FLAG_INVALID_PY_KEYWORD
@ DVAR_FLAG_INVALID_HAS_SPACE
@ DVAR_FLAG_INVALID_START_NUM
@ DVAR_FLAG_INVALID_START_CHAR
Scene * DEG_get_evaluated_scene(const Depsgraph *graph)
bool BKE_driver_has_simple_expression(struct ChannelDriver *driver)
void driver_change_variable_type(struct DriverVar *dvar, eDriverVar_Types type)
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
void driver_variables_copy(ListBaseT< DriverVar > *dst_vars, const ListBaseT< DriverVar > *src_vars)
ListBase BLI_listbase_from_link(Link *some_link)
bool RNA_path_resolve_property_full(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index)
static bool driver_evaluate_simple_expr(const AnimationEvalContext *anim_eval_context, ChannelDriver *driver, ExprPyLike_Parsed *expr, float *result, float time)
bPoseChannel * BKE_pose_channel_find_name(const bPose *pose, const char *name)
int RNA_property_int_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
bool BLI_expr_pylike_is_using_param(const struct ExprPyLike_Parsed *expr, int index)
void driver_free_variable(ListBaseT< DriverVar > *variables, struct DriverVar *dvar)
struct DriverVar * driver_add_new_variable(struct ChannelDriver *driver)
bool RNA_path_resolve_full(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
ListBaseT< DriverVar > variables
struct ExprPyLike_Parsed * expr_simple
struct ViewLayer * view_layer
eDriverTarget_Options options
eDriverTarget_ContextProperty context_property
eDriverTarget_RotationMode rotation_mode
eDriverTarget_TransformChannels transChan
float(*) get_value(const AnimationEvalContext *anim_eval_context, ChannelDriver *driver, DriverVar *dvar)
const char * target_names[MAX_DRIVER_TARGETS]
eDriverTarget_Flag target_flags[MAX_DRIVER_TARGETS]