Blender  V2.93
fcurve_driver.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2009 Blender Foundation, Joshua Leung
17  * All rights reserved.
18  */
19 
24 #include "MEM_guardedalloc.h"
25 
26 #include "DNA_anim_types.h"
27 #include "DNA_constraint_types.h"
28 #include "DNA_object_types.h"
29 
30 #include "BLI_alloca.h"
31 #include "BLI_expr_pylike_eval.h"
32 #include "BLI_math.h"
33 #include "BLI_string_utils.h"
34 #include "BLI_threads.h"
35 #include "BLI_utildefines.h"
36 
37 #include "BLT_translation.h"
38 
39 #include "BKE_action.h"
40 #include "BKE_animsys.h"
41 #include "BKE_armature.h"
42 #include "BKE_constraint.h"
43 #include "BKE_fcurve_driver.h"
44 #include "BKE_global.h"
45 #include "BKE_object.h"
46 
47 #include "RNA_access.h"
48 
49 #include "atomic_ops.h"
50 
51 #include "CLG_log.h"
52 
53 #ifdef WITH_PYTHON
54 # include "BPY_extern.h"
55 #endif
56 
57 #ifdef WITH_PYTHON
58 static ThreadMutex python_driver_lock = BLI_MUTEX_INITIALIZER;
59 #endif
60 
61 static CLG_LogRef LOG = {"bke.fcurve"};
62 
63 /* -------------------------------------------------------------------- */
67 /* TypeInfo for Driver Variables (dvti) */
68 typedef struct DriverVarTypeInfo {
69  /* Evaluation callback. */
70  float (*get_value)(ChannelDriver *driver, DriverVar *dvar);
71 
72  /* Allocation of target slots. */
73  int num_targets; /* Number of target slots required. */
74  const char *target_names[MAX_DRIVER_TARGETS]; /* UI names that should be given to the slots. */
75  short target_flags[MAX_DRIVER_TARGETS]; /* Flags defining the requirements for each slot. */
77 
78 /* Macro to begin definitions */
79 #define BEGIN_DVAR_TYPEDEF(type) {
80 
81 /* Macro to end definitions */
82 #define END_DVAR_TYPEDEF }
83 
86 /* -------------------------------------------------------------------- */
91 {
92  if (id && GS(id->name) == ID_OB && ((Object *)id)->proxy_from) {
93  return (ID *)(((Object *)id)->proxy_from);
94  }
95  return id;
96 }
97 
102 static float dtar_get_prop_val(ChannelDriver *driver, DriverTarget *dtar)
103 {
104  PointerRNA id_ptr, ptr;
105  PropertyRNA *prop;
106  ID *id;
107  int index = -1;
108  float value = 0.0f;
109 
110  /* Sanity check. */
111  if (ELEM(NULL, driver, dtar)) {
112  return 0.0f;
113  }
114 
115  id = dtar_id_ensure_proxy_from(dtar->id);
116 
117  /* Error check for missing pointer. */
118  if (id == NULL) {
119  if (G.debug & G_DEBUG) {
120  CLOG_ERROR(&LOG, "driver has an invalid target to use (path = %s)", dtar->rna_path);
121  }
122 
123  driver->flag |= DRIVER_FLAG_INVALID;
124  dtar->flag |= DTAR_FLAG_INVALID;
125  return 0.0f;
126  }
127 
128  /* Get RNA-pointer for the ID-block given in target. */
129  RNA_id_pointer_create(id, &id_ptr);
130 
131  /* Get property to read from, and get value as appropriate. */
132  if (!RNA_path_resolve_property_full(&id_ptr, dtar->rna_path, &ptr, &prop, &index)) {
133  /* Path couldn't be resolved. */
134  if (G.debug & G_DEBUG) {
135  CLOG_ERROR(&LOG,
136  "Driver Evaluation Error: cannot resolve target for %s -> %s",
137  id->name,
138  dtar->rna_path);
139  }
140 
141  driver->flag |= DRIVER_FLAG_INVALID;
142  dtar->flag |= DTAR_FLAG_INVALID;
143  return 0.0f;
144  }
145 
146  if (RNA_property_array_check(prop)) {
147  /* Array. */
148  if (index < 0 || index >= RNA_property_array_length(&ptr, prop)) {
149  /* Out of bounds. */
150  if (G.debug & G_DEBUG) {
151  CLOG_ERROR(&LOG,
152  "Driver Evaluation Error: array index is out of bounds for %s -> %s (%d)",
153  id->name,
154  dtar->rna_path,
155  index);
156  }
157 
158  driver->flag |= DRIVER_FLAG_INVALID;
159  dtar->flag |= DTAR_FLAG_INVALID;
160  return 0.0f;
161  }
162 
163  switch (RNA_property_type(prop)) {
164  case PROP_BOOLEAN:
165  value = (float)RNA_property_boolean_get_index(&ptr, prop, index);
166  break;
167  case PROP_INT:
168  value = (float)RNA_property_int_get_index(&ptr, prop, index);
169  break;
170  case PROP_FLOAT:
171  value = RNA_property_float_get_index(&ptr, prop, index);
172  break;
173  default:
174  break;
175  }
176  }
177  else {
178  /* Not an array. */
179  switch (RNA_property_type(prop)) {
180  case PROP_BOOLEAN:
181  value = (float)RNA_property_boolean_get(&ptr, prop);
182  break;
183  case PROP_INT:
184  value = (float)RNA_property_int_get(&ptr, prop);
185  break;
186  case PROP_FLOAT:
187  value = RNA_property_float_get(&ptr, prop);
188  break;
189  case PROP_ENUM:
190  value = (float)RNA_property_enum_get(&ptr, prop);
191  break;
192  default:
193  break;
194  }
195  }
196 
197  /* If we're still here, we should be ok. */
198  dtar->flag &= ~DTAR_FLAG_INVALID;
199  return value;
200 }
201 
206  DriverTarget *dtar,
207  PointerRNA *r_ptr,
208  PropertyRNA **r_prop,
209  int *r_index)
210 {
211  PointerRNA id_ptr;
212  PointerRNA ptr;
213  PropertyRNA *prop;
214  ID *id;
215  int index = -1;
216 
217  /* Sanity check. */
218  if (ELEM(NULL, driver, dtar)) {
219  return false;
220  }
221 
222  id = dtar_id_ensure_proxy_from(dtar->id);
223 
224  /* Error check for missing pointer. */
225  if (id == NULL) {
226  if (G.debug & G_DEBUG) {
227  CLOG_ERROR(&LOG, "driver has an invalid target to use (path = %s)", dtar->rna_path);
228  }
229 
230  driver->flag |= DRIVER_FLAG_INVALID;
231  dtar->flag |= DTAR_FLAG_INVALID;
232  return false;
233  }
234 
235  /* Get RNA-pointer for the ID-block given in target. */
236  RNA_id_pointer_create(id, &id_ptr);
237 
238  /* Get property to read from, and get value as appropriate. */
239  if (dtar->rna_path == NULL || dtar->rna_path[0] == '\0') {
241  prop = NULL; /* OK. */
242  }
243  else if (RNA_path_resolve_full(&id_ptr, dtar->rna_path, &ptr, &prop, &index)) {
244  /* OK. */
245  }
246  else {
247  /* Path couldn't be resolved. */
248  if (G.debug & G_DEBUG) {
249  CLOG_ERROR(&LOG,
250  "Driver Evaluation Error: cannot resolve target for %s -> %s",
251  id->name,
252  dtar->rna_path);
253  }
254 
256  *r_prop = NULL;
257  *r_index = -1;
258 
259  driver->flag |= DRIVER_FLAG_INVALID;
260  dtar->flag |= DTAR_FLAG_INVALID;
261  return false;
262  }
263 
264  *r_ptr = ptr;
265  *r_prop = prop;
266  *r_index = index;
267 
268  /* If we're still here, we should be ok. */
269  dtar->flag &= ~DTAR_FLAG_INVALID;
270  return true;
271 }
272 
274 {
275  short valid_targets = 0;
276 
278  Object *ob = (Object *)dtar_id_ensure_proxy_from(dtar->id);
279 
280  /* Check if this target has valid data. */
281  if ((ob == NULL) || (GS(ob->id.name) != ID_OB)) {
282  /* Invalid target, so will not have enough targets. */
283  driver->flag |= DRIVER_FLAG_INVALID;
284  dtar->flag |= DTAR_FLAG_INVALID;
285  }
286  else {
287  /* Target seems to be OK now. */
288  dtar->flag &= ~DTAR_FLAG_INVALID;
289  valid_targets++;
290  }
291  }
293 
294  return valid_targets;
295 }
296 
299 /* -------------------------------------------------------------------- */
303 /* Evaluate 'single prop' driver variable. */
304 static float dvar_eval_singleProp(ChannelDriver *driver, DriverVar *dvar)
305 {
306  /* Just evaluate the first target slot. */
307  return dtar_get_prop_val(driver, &dvar->targets[0]);
308 }
309 
310 /* Evaluate 'rotation difference' driver variable. */
311 static float dvar_eval_rotDiff(ChannelDriver *driver, DriverVar *dvar)
312 {
313  short valid_targets = driver_check_valid_targets(driver, dvar);
314 
315  /* Make sure we have enough valid targets to use - all or nothing for now. */
316  if (driver_check_valid_targets(driver, dvar) != 2) {
317  if (G.debug & G_DEBUG) {
318  CLOG_WARN(&LOG,
319  "RotDiff DVar: not enough valid targets (n = %d) (a = %p, b = %p)",
320  valid_targets,
321  dvar->targets[0].id,
322  dvar->targets[1].id);
323  }
324  return 0.0f;
325  }
326 
327  float(*mat[2])[4];
328 
329  /* NOTE: for now, these are all just worldspace */
330  for (int i = 0; i < 2; i++) {
331  /* Get pointer to loc values to store in. */
332  DriverTarget *dtar = &dvar->targets[i];
333  Object *ob = (Object *)dtar_id_ensure_proxy_from(dtar->id);
334  bPoseChannel *pchan;
335 
336  /* After the checks above, the targets should be valid here. */
337  BLI_assert((ob != NULL) && (GS(ob->id.name) == ID_OB));
338 
339  /* Try to get pose-channel. */
340  pchan = BKE_pose_channel_find_name(ob->pose, dtar->pchan_name);
341 
342  /* Check if object or bone. */
343  if (pchan) {
344  /* Bone. */
345  mat[i] = pchan->pose_mat;
346  }
347  else {
348  /* Object. */
349  mat[i] = ob->obmat;
350  }
351  }
352 
353  float q1[4], q2[4], quat[4], angle;
354 
355  /* Use the final posed locations. */
356  mat4_to_quat(q1, mat[0]);
357  mat4_to_quat(q2, mat[1]);
358 
360  mul_qt_qtqt(quat, q1, q2);
361  angle = 2.0f * (saacos(quat[0]));
362  angle = fabsf(angle);
363 
364  return (angle > (float)M_PI) ? (float)((2.0f * (float)M_PI) - angle) : (float)(angle);
365 }
366 
372 static float dvar_eval_locDiff(ChannelDriver *driver, DriverVar *dvar)
373 {
374  float loc1[3] = {0.0f, 0.0f, 0.0f};
375  float loc2[3] = {0.0f, 0.0f, 0.0f};
376  short valid_targets = driver_check_valid_targets(driver, dvar);
377 
378  /* Make sure we have enough valid targets to use - all or nothing for now. */
379  if (valid_targets < dvar->num_targets) {
380  if (G.debug & G_DEBUG) {
381  CLOG_WARN(&LOG,
382  "LocDiff DVar: not enough valid targets (n = %d) (a = %p, b = %p)",
383  valid_targets,
384  dvar->targets[0].id,
385  dvar->targets[1].id);
386  }
387  return 0.0f;
388  }
389 
390  /* SECOND PASS: get two location values */
391  /* NOTE: for now, these are all just world-space */
393  /* Get pointer to loc values to store in. */
394  Object *ob = (Object *)dtar_id_ensure_proxy_from(dtar->id);
395  bPoseChannel *pchan;
396  float tmp_loc[3];
397 
398  /* After the checks above, the targets should be valid here. */
399  BLI_assert((ob != NULL) && (GS(ob->id.name) == ID_OB));
400 
401  /* Try to get pose-channel. */
402  pchan = BKE_pose_channel_find_name(ob->pose, dtar->pchan_name);
403 
404  /* Check if object or bone. */
405  if (pchan) {
406  /* Bone. */
407  if (dtar->flag & DTAR_FLAG_LOCALSPACE) {
408  if (dtar->flag & DTAR_FLAG_LOCAL_CONSTS) {
409  float mat[4][4];
410 
411  /* Extract transform just like how the constraints do it! */
412  copy_m4_m4(mat, pchan->pose_mat);
414  ob, pchan, NULL, mat, CONSTRAINT_SPACE_POSE, CONSTRAINT_SPACE_LOCAL, false);
415 
416  /* ... and from that, we get our transform. */
417  copy_v3_v3(tmp_loc, mat[3]);
418  }
419  else {
420  /* Transform space (use transform values directly). */
421  copy_v3_v3(tmp_loc, pchan->loc);
422  }
423  }
424  else {
425  /* Convert to worldspace. */
426  copy_v3_v3(tmp_loc, pchan->pose_head);
427  mul_m4_v3(ob->obmat, tmp_loc);
428  }
429  }
430  else {
431  /* Object. */
432  if (dtar->flag & DTAR_FLAG_LOCALSPACE) {
433  if (dtar->flag & DTAR_FLAG_LOCAL_CONSTS) {
434  /* XXX: this should practically be the same as transform space. */
435  float mat[4][4];
436 
437  /* Extract transform just like how the constraints do it! */
438  copy_m4_m4(mat, ob->obmat);
441 
442  /* ... and from that, we get our transform. */
443  copy_v3_v3(tmp_loc, mat[3]);
444  }
445  else {
446  /* Transform space (use transform values directly). */
447  copy_v3_v3(tmp_loc, ob->loc);
448  }
449  }
450  else {
451  /* World-space. */
452  copy_v3_v3(tmp_loc, ob->obmat[3]);
453  }
454  }
455 
456  /* Copy the location to the right place. */
457  if (tarIndex) {
458  copy_v3_v3(loc2, tmp_loc);
459  }
460  else {
461  copy_v3_v3(loc1, tmp_loc);
462  }
463  }
465 
466  /* If we're still here, there should now be two targets to use,
467  * so just take the length of the vector between these points. */
468  return len_v3v3(loc1, loc2);
469 }
470 
474 static float dvar_eval_transChan(ChannelDriver *driver, DriverVar *dvar)
475 {
476  DriverTarget *dtar = &dvar->targets[0];
477  Object *ob = (Object *)dtar_id_ensure_proxy_from(dtar->id);
478  bPoseChannel *pchan;
479  float mat[4][4];
480  float oldEul[3] = {0.0f, 0.0f, 0.0f};
481  bool use_eulers = false;
482  short rot_order = ROT_MODE_EUL;
483 
484  /* Check if this target has valid data. */
485  if ((ob == NULL) || (GS(ob->id.name) != ID_OB)) {
486  /* Invalid target, so will not have enough targets. */
487  driver->flag |= DRIVER_FLAG_INVALID;
488  dtar->flag |= DTAR_FLAG_INVALID;
489  return 0.0f;
490  }
491 
492  /* Target should be valid now. */
493  dtar->flag &= ~DTAR_FLAG_INVALID;
494 
495  /* Try to get pose-channel. */
496  pchan = BKE_pose_channel_find_name(ob->pose, dtar->pchan_name);
497 
498  /* Check if object or bone, and get transform matrix accordingly:
499  * - "use_eulers" code is used to prevent the problems associated with non-uniqueness
500  * of euler decomposition from matrices T20870.
501  * - "local-space" is for T21384, where parent results are not wanted
502  * but #DTAR_FLAG_LOCAL_CONSTS is for all the common "corrective-shapes-for-limbs" situations.
503  */
504  if (pchan) {
505  /* Bone. */
506  if (pchan->rotmode > 0) {
507  copy_v3_v3(oldEul, pchan->eul);
508  rot_order = pchan->rotmode;
509  use_eulers = true;
510  }
511 
512  if (dtar->flag & DTAR_FLAG_LOCALSPACE) {
513  if (dtar->flag & DTAR_FLAG_LOCAL_CONSTS) {
514  /* Just like how the constraints do it! */
515  copy_m4_m4(mat, pchan->pose_mat);
517  ob, pchan, NULL, mat, CONSTRAINT_SPACE_POSE, CONSTRAINT_SPACE_LOCAL, false);
518  }
519  else {
520  /* Specially calculate local matrix, since chan_mat is not valid
521  * since it stores delta transform of pose_mat so that deforms work
522  * so it cannot be used here for "transform" space. */
523  BKE_pchan_to_mat4(pchan, mat);
524  }
525  }
526  else {
527  /* World-space matrix. */
528  mul_m4_m4m4(mat, ob->obmat, pchan->pose_mat);
529  }
530  }
531  else {
532  /* Object. */
533  if (ob->rotmode > 0) {
534  copy_v3_v3(oldEul, ob->rot);
535  rot_order = ob->rotmode;
536  use_eulers = true;
537  }
538 
539  if (dtar->flag & DTAR_FLAG_LOCALSPACE) {
540  if (dtar->flag & DTAR_FLAG_LOCAL_CONSTS) {
541  /* Just like how the constraints do it! */
542  copy_m4_m4(mat, ob->obmat);
545  }
546  else {
547  /* Transforms to matrix. */
548  BKE_object_to_mat4(ob, mat);
549  }
550  }
551  else {
552  /* World-space matrix - just the good-old one. */
553  copy_m4_m4(mat, ob->obmat);
554  }
555  }
556 
557  /* Check which transform. */
558  if (dtar->transChan >= MAX_DTAR_TRANSCHAN_TYPES) {
559  /* Not valid channel. */
560  return 0.0f;
561  }
562  if (dtar->transChan == DTAR_TRANSCHAN_SCALE_AVG) {
563  /* Cubic root of the change in volume, equal to the geometric mean
564  * of scale over all three axes unless the matrix includes shear. */
565  return cbrtf(mat4_to_volume_scale(mat));
566  }
568  /* Extract scale, and choose the right axis,
569  * inline 'mat4_to_size'. */
570  return len_v3(mat[dtar->transChan - DTAR_TRANSCHAN_SCALEX]);
571  }
572  if (dtar->transChan >= DTAR_TRANSCHAN_ROTX) {
573  /* Extract rotation as eulers (if needed)
574  * - definitely if rotation order isn't eulers already
575  * - if eulers, then we have 2 options:
576  * a) decompose transform matrix as required, then try to make eulers from
577  * there compatible with original values
578  * b) [NOT USED] directly use the original values (no decomposition)
579  * - only an option for "transform space", if quality is really bad with a)
580  */
581  float quat[4];
582  int channel;
583 
584  if (dtar->transChan == DTAR_TRANSCHAN_ROTW) {
585  channel = 0;
586  }
587  else {
588  channel = 1 + dtar->transChan - DTAR_TRANSCHAN_ROTX;
589  BLI_assert(channel < 4);
590  }
591 
593  mat, rot_order, dtar->rotation_mode, channel, false, quat);
594 
595  if (use_eulers && dtar->rotation_mode == DTAR_ROTMODE_AUTO) {
596  compatible_eul(quat + 1, oldEul);
597  }
598 
599  return quat[channel];
600  }
601 
602  /* Extract location and choose right axis. */
603  return mat[3][dtar->transChan];
604 }
605 
606 /* Convert a quaternion to pseudo-angles representing the weighted amount of rotation. */
607 static void quaternion_to_angles(float quat[4], int channel)
608 {
609  if (channel < 0) {
610  quat[0] = 2.0f * saacosf(quat[0]);
611 
612  for (int i = 1; i < 4; i++) {
613  quat[i] = 2.0f * saasinf(quat[i]);
614  }
615  }
616  else if (channel == 0) {
617  quat[0] = 2.0f * saacosf(quat[0]);
618  }
619  else {
620  quat[channel] = 2.0f * saasinf(quat[channel]);
621  }
622 }
623 
624 /* Compute channel values for a rotational Transform Channel driver variable. */
626  float mat[4][4], int auto_order, int rotation_mode, int channel, bool angles, float r_buf[4])
627 {
628  float *const quat = r_buf;
629  float *const eul = r_buf + 1;
630 
631  zero_v4(r_buf);
632 
633  if (rotation_mode == DTAR_ROTMODE_AUTO) {
634  mat4_to_eulO(eul, auto_order, mat);
635  }
636  else if (rotation_mode >= DTAR_ROTMODE_EULER_MIN && rotation_mode <= DTAR_ROTMODE_EULER_MAX) {
637  mat4_to_eulO(eul, rotation_mode, mat);
638  }
639  else if (rotation_mode == DTAR_ROTMODE_QUATERNION) {
640  mat4_to_quat(quat, mat);
641 
642  /* For Transformation constraint convenience, convert to pseudo-angles. */
643  if (angles) {
644  quaternion_to_angles(quat, channel);
645  }
646  }
647  else if (rotation_mode >= DTAR_ROTMODE_SWING_TWIST_X &&
648  rotation_mode <= DTAR_ROTMODE_SWING_TWIST_Z) {
649  int axis = rotation_mode - DTAR_ROTMODE_SWING_TWIST_X;
650  float raw_quat[4], twist;
651 
652  mat4_to_quat(raw_quat, mat);
653 
654  if (channel == axis + 1) {
655  /* If only the twist angle is needed, skip computing swing. */
656  twist = quat_split_swing_and_twist(raw_quat, axis, NULL, NULL);
657  }
658  else {
659  twist = quat_split_swing_and_twist(raw_quat, axis, quat, NULL);
660 
661  quaternion_to_angles(quat, channel);
662  }
663 
664  quat[axis + 1] = twist;
665  }
666  else {
667  BLI_assert(false);
668  }
669 }
670 
673 /* -------------------------------------------------------------------- */
677 /* Table of Driver Variable Type Info Data */
680  1, /* Number of targets used. */
681  {"Property"}, /* UI names for targets */
682  {0} /* Flags. */
684 
686  2, /* Number of targets used. */
687  {"Object/Bone 1", "Object/Bone 2"}, /* UI names for targets */
691 
693  2, /* Number of targets used. */
694  {"Object/Bone 1", "Object/Bone 2"}, /* UI names for targets */
698 
700  1, /* Number of targets used. */
701  {"Object/Bone"}, /* UI names for targets */
704 };
705 
706 /* Get driver variable typeinfo */
708 {
709  /* Check if valid type. */
710  if ((type >= 0) && (type < MAX_DVAR_TYPES)) {
711  return &dvar_types[type];
712  }
713 
714  return NULL;
715 }
716 
719 /* -------------------------------------------------------------------- */
723 /* Perform actual freeing driver variable and remove it from the given list */
724 void driver_free_variable(ListBase *variables, DriverVar *dvar)
725 {
726  /* Sanity checks. */
727  if (dvar == NULL) {
728  return;
729  }
730 
731  /* Free target vars:
732  * - need to go over all of them, not just up to the ones that are used
733  * currently, since there may be some lingering RNA paths from
734  * previous users needing freeing
735  */
737  /* Free RNA path if applicable. */
738  if (dtar->rna_path) {
739  MEM_freeN(dtar->rna_path);
740  }
741  }
743 
744  /* Remove the variable from the driver. */
745  BLI_freelinkN(variables, dvar);
746 }
747 
748 /* Free the driver variable and do extra updates */
750 {
751  /* Remove and free the driver variable. */
752  driver_free_variable(&driver->variables, dvar);
753 
754  /* Since driver variables are cached, the expression needs re-compiling too. */
755  BKE_driver_invalidate_expression(driver, false, true);
756 }
757 
758 /* Copy driver variables from src_vars list to dst_vars list */
759 void driver_variables_copy(ListBase *dst_vars, const ListBase *src_vars)
760 {
762  BLI_duplicatelist(dst_vars, src_vars);
763 
764  LISTBASE_FOREACH (DriverVar *, dvar, dst_vars) {
765  /* Need to go over all targets so that we don't leave any dangling paths. */
767  /* Make a copy of target's rna path if available. */
768  if (dtar->rna_path) {
769  dtar->rna_path = MEM_dupallocN(dtar->rna_path);
770  }
771  }
773  }
774 }
775 
776 /* Change the type of driver variable */
778 {
780 
781  /* Sanity check. */
782  if (ELEM(NULL, dvar, dvti)) {
783  return;
784  }
785 
786  /* Set the new settings. */
787  dvar->type = type;
788  dvar->num_targets = dvti->num_targets;
789 
790  /* Make changes to the targets based on the defines for these types.
791  * NOTE: only need to make sure the ones we're using here are valid. */
793  short flags = dvti->target_flags[tarIndex];
794 
795  /* Store the flags. */
796  dtar->flag = flags;
797 
798  /* Object ID types only, or idtype not yet initialized. */
799  if ((flags & DTAR_FLAG_ID_OB_ONLY) || (dtar->idtype == 0)) {
800  dtar->idtype = ID_OB;
801  }
802  }
804 }
805 
806 /* Validate driver name (after being renamed) */
808 {
809  /* Special character blacklist */
810  const char special_char_blacklist[] = {
811  '~', '`', '!', '@', '#', '$', '%', '^', '&', '*', '+', '=', '-', '/', '\\',
812  '?', ':', ';', '<', '>', '{', '}', '[', ']', '|', ' ', '.', '\t', '\n', '\r',
813  };
814 
815  /* Sanity checks. */
816  if (dvar == NULL) {
817  return;
818  }
819 
820  /* Clear all invalid-name flags. */
821  dvar->flag &= ~DVAR_ALL_INVALID_FLAGS;
822 
823  /* 0) Zero-length identifiers are not allowed */
824  if (dvar->name[0] == '\0') {
825  dvar->flag |= DVAR_FLAG_INVALID_EMPTY;
826  }
827 
828  /* 1) Must start with a letter */
829  /* XXX: We assume that valid unicode letters in other languages are ok too,
830  * hence the blacklisting. */
831  if (IN_RANGE_INCL(dvar->name[0], '0', '9')) {
833  }
834  else if (dvar->name[0] == '_') {
835  /* NOTE: We don't allow names to start with underscores
836  * (i.e. it helps when ruling out security risks) */
838  }
839 
840  /* 2) Must not contain invalid stuff in the middle of the string */
841  if (strchr(dvar->name, ' ')) {
843  }
844  if (strchr(dvar->name, '.')) {
846  }
847 
848  /* 3) Check for special characters - Either at start, or in the middle */
849  for (int i = 0; i < sizeof(special_char_blacklist); i++) {
850  char *match = strchr(dvar->name, special_char_blacklist[i]);
851 
852  if (match == dvar->name) {
854  }
855  else if (match != NULL) {
857  }
858  }
859 
860  /* 4) Check if the name is a reserved keyword
861  * NOTE: These won't confuse Python, but it will be impossible to use the variable
862  * in an expression without Python misinterpreting what these are for
863  */
864 #ifdef WITH_PYTHON
865  if (BPY_string_is_keyword(dvar->name)) {
867  }
868 #endif
869 
870  /* If any these conditions match, the name is invalid */
871  if (dvar->flag & DVAR_ALL_INVALID_FLAGS) {
872  dvar->flag |= DVAR_FLAG_INVALID_NAME;
873  }
874 }
875 
876 /* Add a new driver variable */
878 {
879  DriverVar *dvar;
880 
881  /* Sanity checks. */
882  if (driver == NULL) {
883  return NULL;
884  }
885 
886  /* Make a new variable. */
887  dvar = MEM_callocN(sizeof(DriverVar), "DriverVar");
888  BLI_addtail(&driver->variables, dvar);
889 
890  /* Give the variable a 'unique' name. */
891  strcpy(dvar->name, CTX_DATA_(BLT_I18NCONTEXT_ID_ACTION, "var"));
892  BLI_uniquename(&driver->variables,
893  dvar,
895  '_',
896  offsetof(DriverVar, name),
897  sizeof(dvar->name));
898 
899  /* Set the default type to 'single prop'. */
901 
902  /* Since driver variables are cached, the expression needs re-compiling too. */
903  BKE_driver_invalidate_expression(driver, false, true);
904 
905  /* Return the target. */
906  return dvar;
907 }
908 
909 /* This frees the driver itself */
911 {
912  ChannelDriver *driver;
913  DriverVar *dvar, *dvarn;
914 
915  /* Sanity checks. */
916  if (ELEM(NULL, fcu, fcu->driver)) {
917  return;
918  }
919  driver = fcu->driver;
920 
921  /* Free driver targets. */
922  for (dvar = driver->variables.first; dvar; dvar = dvarn) {
923  dvarn = dvar->next;
924  driver_free_variable_ex(driver, dvar);
925  }
926 
927 #ifdef WITH_PYTHON
928  /* Free compiled driver expression. */
929  if (driver->expr_comp) {
930  BPY_DECREF(driver->expr_comp);
931  }
932 #endif
933 
935 
936  /* Free driver itself, then set F-Curve's point to this to NULL
937  * (as the curve may still be used). */
938  MEM_freeN(driver);
939  fcu->driver = NULL;
940 }
941 
942 /* This makes a copy of the given driver */
944 {
945  ChannelDriver *ndriver;
946 
947  /* Sanity checks. */
948  if (driver == NULL) {
949  return NULL;
950  }
951 
952  /* Copy all data. */
953  ndriver = MEM_dupallocN(driver);
954  ndriver->expr_comp = NULL;
955  ndriver->expr_simple = NULL;
956 
957  /* Copy variables. */
958 
959  /* To get rid of refs to non-copied data (that's still used on original). */
960  BLI_listbase_clear(&ndriver->variables);
961  driver_variables_copy(&ndriver->variables, &driver->variables);
962 
963  /* Return the new driver. */
964  return ndriver;
965 }
966 
969 /* -------------------------------------------------------------------- */
973 /* Index constants for the expression parameter array. */
974 enum {
975  /* Index of the 'frame' variable. */
977  /* Index of the first user-defined driver variable. */
979 };
980 
982 {
983  /* Prepare parameter names. */
984  int names_len = BLI_listbase_count(&driver->variables);
986  int i = VAR_INDEX_CUSTOM;
987 
988  names[VAR_INDEX_FRAME] = "frame";
989 
990  LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) {
991  names[i++] = dvar->name;
992  }
993 
995 }
996 
998 {
999  /* Check if the 'frame' parameter is actually used. */
1001 }
1002 
1004  ExprPyLike_Parsed *expr,
1005  float *result,
1006  float time)
1007 {
1008  /* Prepare parameter values. */
1009  int vars_len = BLI_listbase_count(&driver->variables);
1010  double *vars = BLI_array_alloca(vars, vars_len + VAR_INDEX_CUSTOM);
1011  int i = VAR_INDEX_CUSTOM;
1012 
1013  vars[VAR_INDEX_FRAME] = time;
1014 
1015  LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) {
1016  vars[i++] = driver_get_variable_value(driver, dvar);
1017  }
1018 
1019  /* Evaluate expression. */
1020  double result_val;
1022  expr, vars, vars_len + VAR_INDEX_CUSTOM, &result_val);
1023  const char *message;
1024 
1025  switch (status) {
1026  case EXPR_PYLIKE_SUCCESS:
1027  if (isfinite(result_val)) {
1028  *result = (float)result_val;
1029  }
1030  return true;
1031 
1034  message = (status == EXPR_PYLIKE_DIV_BY_ZERO) ? "Division by Zero" : "Math Domain Error";
1035  CLOG_ERROR(&LOG, "%s in Driver: '%s'", message, driver->expression);
1036 
1037  driver->flag |= DRIVER_FLAG_INVALID;
1038  return true;
1039 
1040  default:
1041  /* Arriving here means a bug, not user error. */
1042  CLOG_ERROR(&LOG, "simple driver expression evaluation failed: '%s'", driver->expression);
1043  return false;
1044  }
1045 }
1046 
1047 /* Compile and cache the driver expression if necessary, with thread safety. */
1049 {
1050  if (driver->expr_simple != NULL) {
1051  return true;
1052  }
1053 
1054  if (driver->type != DRIVER_TYPE_PYTHON) {
1055  return false;
1056  }
1057 
1058  /* It's safe to parse in multiple threads; at worst it'll
1059  * waste some effort, but in return avoids mutex contention. */
1061 
1062  /* Store the result if the field is still NULL, or discard
1063  * it if another thread got here first. */
1064  if (atomic_cas_ptr((void **)&driver->expr_simple, NULL, expr) != NULL) {
1065  BLI_expr_pylike_free(expr);
1066  }
1067 
1068  return true;
1069 }
1070 
1071 /* Try using the simple expression evaluator to compute the result of the driver.
1072  * On success, stores the result and returns true; on failure result is set to 0. */
1074  ChannelDriver *driver_orig,
1075  float *result,
1076  float time)
1077 {
1078  *result = 0.0f;
1079 
1080  return driver_compile_simple_expr(driver_orig) &&
1081  BLI_expr_pylike_is_valid(driver_orig->expr_simple) &&
1082  driver_evaluate_simple_expr(driver, driver_orig->expr_simple, result, time);
1083 }
1084 
1085 /* Check if the expression in the driver conforms to the simple subset. */
1087 {
1089 }
1090 
1091 /* TODO(sergey): This is somewhat weak, but we don't want neither false-positive
1092  * time dependencies nor special exceptions in the depsgraph evaluation. */
1093 static bool python_driver_exression_depends_on_time(const char *expression)
1094 {
1095  if (expression[0] == '\0') {
1096  /* Empty expression depends on nothing. */
1097  return false;
1098  }
1099  if (strchr(expression, '(') != NULL) {
1100  /* Function calls are considered dependent on a time. */
1101  return true;
1102  }
1103  if (strstr(expression, "frame") != NULL) {
1104  /* Variable `frame` depends on time. */
1105  /* TODO(sergey): This is a bit weak, but not sure about better way of handling this. */
1106  return true;
1107  }
1108  /* Possible indirect time relation s should be handled via variable targets. */
1109  return false;
1110 }
1111 
1112 /* Check if the expression in the driver may depend on the current frame. */
1114 {
1115  if (driver->type != DRIVER_TYPE_PYTHON) {
1116  return false;
1117  }
1118 
1119  if (BKE_driver_has_simple_expression(driver)) {
1120  /* Simple expressions can be checked exactly. */
1122  }
1123 
1124  /* Otherwise, heuristically scan the expression string for certain patterns. */
1126 }
1127 
1128 /* Reset cached compiled expression data */
1130  bool expr_changed,
1131  bool varname_changed)
1132 {
1133  if (expr_changed || varname_changed) {
1135  driver->expr_simple = NULL;
1136  }
1137 
1138 #ifdef WITH_PYTHON
1139  if (expr_changed) {
1140  driver->flag |= DRIVER_FLAG_RECOMPILE;
1141  }
1142 
1143  if (varname_changed) {
1144  driver->flag |= DRIVER_FLAG_RENAMEVAR;
1145  }
1146 #endif
1147 }
1148 
1151 /* -------------------------------------------------------------------- */
1155 /* Evaluate a Driver Variable to get a value that contributes to the final */
1157 {
1158  const DriverVarTypeInfo *dvti;
1159 
1160  /* Sanity check. */
1161  if (ELEM(NULL, driver, dvar)) {
1162  return 0.0f;
1163  }
1164 
1165  /* Call the relevant callbacks to get the variable value
1166  * using the variable type info, storing the obtained value
1167  * in `dvar->curval` so that drivers can be debugged. */
1168  dvti = get_dvar_typeinfo(dvar->type);
1169 
1170  if (dvti && dvti->get_value) {
1171  dvar->curval = dvti->get_value(driver, dvar);
1172  }
1173  else {
1174  dvar->curval = 0.0f;
1175  }
1176 
1177  return dvar->curval;
1178 }
1179 
1181 {
1182  DriverVar *dvar;
1183 
1184  /* Check how many variables there are first (i.e. just one?). */
1185  if (BLI_listbase_is_single(&driver->variables)) {
1186  /* Just one target, so just use that. */
1187  dvar = driver->variables.first;
1188  driver->curval = driver_get_variable_value(driver, dvar);
1189  return;
1190  }
1191 
1192  /* More than one target, so average the values of the targets. */
1193  float value = 0.0f;
1194  int tot = 0;
1195 
1196  /* Loop through targets, adding (hopefully we don't get any overflow!). */
1197  for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
1198  value += driver_get_variable_value(driver, dvar);
1199  tot++;
1200  }
1201 
1202  /* Perform operations on the total if appropriate. */
1203  if (driver->type == DRIVER_TYPE_AVERAGE) {
1204  driver->curval = tot ? (value / (float)tot) : 0.0f;
1205  }
1206  else {
1207  driver->curval = value;
1208  }
1209 }
1210 
1212 {
1213  DriverVar *dvar;
1214  float value = 0.0f;
1215 
1216  /* Loop through the variables, getting the values and comparing them to existing ones. */
1217  for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
1218  /* Get value. */
1219  float tmp_val = driver_get_variable_value(driver, dvar);
1220 
1221  /* Store this value if appropriate. */
1222  if (dvar->prev) {
1223  /* Check if greater/smaller than the baseline. */
1224  if (driver->type == DRIVER_TYPE_MAX) {
1225  /* Max? */
1226  if (tmp_val > value) {
1227  value = tmp_val;
1228  }
1229  }
1230  else {
1231  /* Min? */
1232  if (tmp_val < value) {
1233  value = tmp_val;
1234  }
1235  }
1236  }
1237  else {
1238  /* First item - make this the baseline for comparisons. */
1239  value = tmp_val;
1240  }
1241  }
1242 
1243  /* Store value in driver. */
1244  driver->curval = value;
1245 }
1246 
1248  ChannelDriver *driver,
1249  ChannelDriver *driver_orig,
1250  const AnimationEvalContext *anim_eval_context)
1251 {
1252  /* Check for empty or invalid expression. */
1253  if ((driver_orig->expression[0] == '\0') || (driver_orig->flag & DRIVER_FLAG_INVALID)) {
1254  driver->curval = 0.0f;
1255  }
1257  driver, driver_orig, &driver->curval, anim_eval_context->eval_time)) {
1258 #ifdef WITH_PYTHON
1259  /* This evaluates the expression using Python, and returns its result:
1260  * - on errors it reports, then returns 0.0f. */
1261  BLI_mutex_lock(&python_driver_lock);
1262 
1263  driver->curval = BPY_driver_exec(anim_rna, driver, driver_orig, anim_eval_context);
1264 
1265  BLI_mutex_unlock(&python_driver_lock);
1266 #else /* WITH_PYTHON */
1267  UNUSED_VARS(anim_rna, anim_eval_context);
1268 #endif /* WITH_PYTHON */
1269  }
1270 }
1271 
1281  ChannelDriver *driver,
1282  ChannelDriver *driver_orig,
1283  const AnimationEvalContext *anim_eval_context)
1284 {
1285  /* Check if driver can be evaluated. */
1286  if (driver_orig->flag & DRIVER_FLAG_INVALID) {
1287  return 0.0f;
1288  }
1289 
1290  switch (driver->type) {
1291  case DRIVER_TYPE_AVERAGE: /* Average values of driver targets. */
1292  case DRIVER_TYPE_SUM: /* Sum values of driver targets. */
1293  evaluate_driver_sum(driver);
1294  break;
1295  case DRIVER_TYPE_MIN: /* Smallest value. */
1296  case DRIVER_TYPE_MAX: /* Largest value. */
1297  evaluate_driver_min_max(driver);
1298  break;
1299  case DRIVER_TYPE_PYTHON: /* Expression. */
1300  evaluate_driver_python(anim_rna, driver, driver_orig, anim_eval_context);
1301  break;
1302  default:
1303  /* Special 'hack' - just use stored value
1304  * This is currently used as the mechanism which allows animated settings to be able
1305  * to be changed via the UI. */
1306  break;
1307  }
1308 
1309  /* Return value for driver. */
1310  return driver->curval;
1311 }
typedef float(TangentPoint)[2]
Blender kernel action and pose functionality.
struct bPoseChannel * BKE_pose_channel_find_name(const struct bPose *pose, const char *name)
void BKE_pchan_to_mat4(const struct bPoseChannel *pchan, float r_chanmat[4][4])
void BKE_constraint_mat_convertspace(struct Object *ob, struct bPoseChannel *pchan, struct bConstraintOb *cob, float mat[4][4], short from, short to, const bool keep_scale)
Definition: constraint.c:264
#define DRIVER_TARGETS_LOOPER_BEGIN(dvar)
#define DRIVER_TARGETS_USED_LOOPER_BEGIN(dvar)
#define DRIVER_TARGETS_LOOPER_END
@ G_DEBUG
Definition: BKE_global.h:133
General operations, lookup, etc. for blender objects.
void BKE_object_to_mat4(struct Object *ob, float r_mat[4][4])
Definition: object.c:3234
#define BLI_array_alloca(arr, realsize)
Definition: BLI_alloca.h:36
#define BLI_assert(a)
Definition: BLI_assert.h:58
eExprPyLike_EvalStatus
@ EXPR_PYLIKE_SUCCESS
@ EXPR_PYLIKE_DIV_BY_ZERO
@ EXPR_PYLIKE_MATH_ERROR
eExprPyLike_EvalStatus BLI_expr_pylike_eval(struct ExprPyLike_Parsed *expr, const double *param_values, int param_values_len, double *r_result)
ExprPyLike_Parsed * BLI_expr_pylike_parse(const char *expression, const char **param_names, int param_names_len)
void BLI_expr_pylike_free(struct ExprPyLike_Parsed *expr)
bool BLI_expr_pylike_is_using_param(struct ExprPyLike_Parsed *expr, int index)
bool BLI_expr_pylike_is_valid(struct ExprPyLike_Parsed *expr)
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
Definition: BLI_listbase.h:124
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:172
void BLI_freelinkN(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:281
void void void void void BLI_duplicatelist(struct ListBase *dst, const struct ListBase *src) ATTR_NONNULL(1
BLI_INLINE void BLI_listbase_clear(struct ListBase *lb)
Definition: BLI_listbase.h:128
void void BLI_INLINE bool BLI_listbase_is_single(const struct ListBase *lb)
Definition: BLI_listbase.h:120
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:110
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
MINLINE float saacos(float fac)
MINLINE float saasinf(float f)
MINLINE float saacosf(float f)
#define M_PI
Definition: BLI_math_base.h:38
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
Definition: math_matrix.c:262
void mul_m4_v3(const float M[4][4], float r[3])
Definition: math_matrix.c:732
void copy_m4_m4(float m1[4][4], const float m2[4][4])
Definition: math_matrix.c:95
float mat4_to_volume_scale(const float M[4][4])
Definition: math_matrix.c:2177
void invert_qt_normalized(float q[4])
void mul_qt_qtqt(float q[4], const float a[4], const float b[4])
Definition: math_rotation.c:65
void mat4_to_quat(float q[4], const float mat[4][4])
void compatible_eul(float eul[3], const float old[3])
float quat_split_swing_and_twist(const float q[4], int axis, float r_swing[4], float r_twist[4])
void mat4_to_eulO(float eul[3], const short order, const float mat[4][4])
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void zero_v4(float r[4])
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
bool BLI_uniquename(struct ListBase *list, void *vlink, const char *defname, char delim, int name_offset, size_t len)
Definition: string_utils.c:381
#define BLI_MUTEX_INITIALIZER
Definition: BLI_threads.h:84
void BLI_mutex_lock(ThreadMutex *mutex)
Definition: threads.cc:401
void BLI_mutex_unlock(ThreadMutex *mutex)
Definition: threads.cc:406
pthread_mutex_t ThreadMutex
Definition: BLI_threads.h:83
#define UNUSED_VARS(...)
#define ELEM(...)
#define IN_RANGE_INCL(a, b, c)
#define BLT_I18NCONTEXT_ID_ACTION
#define CTX_DATA_(context, msgid)
bool BPY_string_is_keyword(const char *str)
float BPY_driver_exec(struct PathResolvedRNA *anim_rna, struct ChannelDriver *driver, struct ChannelDriver *driver_orig, const struct AnimationEvalContext *anim_eval_context)
void BPY_DECREF(void *pyob_ptr)
#define CLOG_ERROR(clg_ref,...)
Definition: CLG_log.h:204
#define CLOG_WARN(clg_ref,...)
Definition: CLG_log.h:203
@ ID_OB
Definition: DNA_ID_enums.h:59
@ ROT_MODE_EUL
#define MAX_DRIVER_TARGETS
@ DTAR_TRANSCHAN_SCALEX
@ DTAR_TRANSCHAN_SCALEZ
@ DTAR_TRANSCHAN_ROTW
@ DTAR_TRANSCHAN_ROTX
@ MAX_DTAR_TRANSCHAN_TYPES
@ DTAR_TRANSCHAN_SCALE_AVG
@ DTAR_TRANSCHAN_SCALEY
@ DRIVER_TYPE_AVERAGE
@ DRIVER_TYPE_PYTHON
@ DRIVER_TYPE_MAX
@ DRIVER_TYPE_MIN
@ DRIVER_TYPE_SUM
@ DVAR_TYPE_LOC_DIFF
@ DVAR_TYPE_TRANSFORM_CHAN
@ DVAR_TYPE_ROT_DIFF
@ MAX_DVAR_TYPES
@ DVAR_TYPE_SINGLE_PROP
@ DTAR_ROTMODE_QUATERNION
@ DTAR_ROTMODE_SWING_TWIST_X
@ DTAR_ROTMODE_EULER_MIN
@ DTAR_ROTMODE_AUTO
@ DTAR_ROTMODE_EULER_MAX
@ DTAR_ROTMODE_SWING_TWIST_Z
@ DTAR_FLAG_LOCAL_CONSTS
@ DTAR_FLAG_LOCALSPACE
@ DTAR_FLAG_ID_OB_ONLY
@ DTAR_FLAG_INVALID
@ DTAR_FLAG_STRUCT_REF
@ DRIVER_FLAG_INVALID
@ DRIVER_FLAG_RECOMPILE
@ DRIVER_FLAG_RENAMEVAR
#define DVAR_ALL_INVALID_FLAGS
@ DVAR_FLAG_INVALID_START_CHAR
@ DVAR_FLAG_INVALID_NAME
@ DVAR_FLAG_INVALID_EMPTY
@ DVAR_FLAG_INVALID_START_NUM
@ DVAR_FLAG_INVALID_HAS_SPACE
@ DVAR_FLAG_INVALID_HAS_DOT
@ DVAR_FLAG_INVALID_HAS_SPECIAL
@ DVAR_FLAG_INVALID_PY_KEYWORD
@ CONSTRAINT_SPACE_POSE
@ CONSTRAINT_SPACE_WORLD
@ CONSTRAINT_SPACE_LOCAL
Object is a sort of wrapper for general info.
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Read Guarded memory(de)allocation.
@ PROP_FLOAT
Definition: RNA_types.h:75
@ PROP_BOOLEAN
Definition: RNA_types.h:73
@ PROP_ENUM
Definition: RNA_types.h:77
@ PROP_INT
Definition: RNA_types.h:74
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)
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition: btVector3.h:356
double time
void driver_change_variable_type(DriverVar *dvar, int type)
static short driver_check_valid_targets(ChannelDriver *driver, DriverVar *dvar)
static void evaluate_driver_min_max(ChannelDriver *driver)
void fcurve_free_driver(FCurve *fcu)
static ExprPyLike_Parsed * driver_compile_simple_expr_impl(ChannelDriver *driver)
static float dvar_eval_transChan(ChannelDriver *driver, DriverVar *dvar)
bool driver_get_variable_property(ChannelDriver *driver, DriverTarget *dtar, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index)
static ID * dtar_id_ensure_proxy_from(ID *id)
Definition: fcurve_driver.c:90
bool BKE_driver_expression_depends_on_time(ChannelDriver *driver)
float evaluate_driver(PathResolvedRNA *anim_rna, ChannelDriver *driver, ChannelDriver *driver_orig, const AnimationEvalContext *anim_eval_context)
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])
static float dvar_eval_singleProp(ChannelDriver *driver, DriverVar *dvar)
static void evaluate_driver_python(PathResolvedRNA *anim_rna, ChannelDriver *driver, ChannelDriver *driver_orig, const AnimationEvalContext *anim_eval_context)
static bool python_driver_exression_depends_on_time(const char *expression)
void driver_free_variable(ListBase *variables, DriverVar *dvar)
static const DriverVarTypeInfo * get_dvar_typeinfo(int type)
static void evaluate_driver_sum(ChannelDriver *driver)
struct DriverVarTypeInfo DriverVarTypeInfo
void driver_variable_name_validate(DriverVar *dvar)
void driver_variables_copy(ListBase *dst_vars, const ListBase *src_vars)
ChannelDriver * fcurve_copy_driver(const ChannelDriver *driver)
static float dvar_eval_rotDiff(ChannelDriver *driver, DriverVar *dvar)
#define END_DVAR_TYPEDEF
Definition: fcurve_driver.c:82
static bool driver_compile_simple_expr(ChannelDriver *driver)
static float dvar_eval_locDiff(ChannelDriver *driver, DriverVar *dvar)
DriverVar * driver_add_new_variable(ChannelDriver *driver)
static bool driver_check_simple_expr_depends_on_time(ExprPyLike_Parsed *expr)
static CLG_LogRef LOG
Definition: fcurve_driver.c:61
static float dtar_get_prop_val(ChannelDriver *driver, DriverTarget *dtar)
#define BEGIN_DVAR_TYPEDEF(type)
Definition: fcurve_driver.c:79
void driver_free_variable_ex(ChannelDriver *driver, DriverVar *dvar)
static bool driver_evaluate_simple_expr(ChannelDriver *driver, ExprPyLike_Parsed *expr, float *result, float time)
static bool driver_try_evaluate_simple_expr(ChannelDriver *driver, ChannelDriver *driver_orig, float *result, float time)
@ VAR_INDEX_FRAME
@ VAR_INDEX_CUSTOM
static void quaternion_to_angles(float quat[4], int channel)
static DriverVarTypeInfo dvar_types[MAX_DVAR_TYPES]
bool BKE_driver_has_simple_expression(ChannelDriver *driver)
void BKE_driver_invalidate_expression(ChannelDriver *driver, bool expr_changed, bool varname_changed)
float driver_get_variable_value(ChannelDriver *driver, DriverVar *dvar)
#define GS(x)
Definition: iris.c:241
#define fabsf(x)
static char ** names
Definition: makesdna.c:162
static int names_len
Definition: makesdna.c:158
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_dupallocN)(const void *vmemh)
Definition: mallocn.c:42
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
bool isfinite(uchar)
Definition: image.cpp:44
float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2941
bool RNA_property_array_check(PropertyRNA *prop)
Definition: rna_access.c:1223
bool RNA_path_resolve_full(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index)
Definition: rna_access.c:5416
void RNA_id_pointer_create(ID *id, PointerRNA *r_ptr)
Definition: rna_access.c:122
int RNA_property_int_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
Definition: rna_access.c:2759
float RNA_property_float_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
Definition: rna_access.c:3108
PropertyType RNA_property_type(PropertyRNA *prop)
Definition: rna_access.c:1155
const PointerRNA PointerRNA_NULL
Definition: rna_access.c:71
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2331
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2607
bool RNA_path_resolve_property_full(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index)
Definition: rna_access.c:5454
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:1218
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:3543
bool RNA_property_boolean_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
Definition: rna_access.c:2453
ListBase variables
char expression[256]
struct ExprPyLike_Parsed * expr_simple
char pchan_name[64]
short target_flags[MAX_DRIVER_TARGETS]
Definition: fcurve_driver.c:75
float(* get_value)(ChannelDriver *driver, DriverVar *dvar)
Definition: fcurve_driver.c:70
const char * target_names[MAX_DRIVER_TARGETS]
Definition: fcurve_driver.c:74
struct DriverVar * next
char num_targets
DriverTarget targets[8]
char name[64]
struct DriverVar * prev
ChannelDriver * driver
Definition: DNA_ID.h:273
char name[66]
Definition: DNA_ID.h:283
void * first
Definition: DNA_listBase.h:47
struct bPose * pose
float loc[3]
float rot[3]
float obmat[4][4]
short rotmode
float pose_head[3]
float pose_mat[4][4]
#define G(x, y, z)
PointerRNA * ptr
Definition: wm_files.c:3157