PyDriver support for all RNA property types

Support for driver variables that don't resolve to numbers, eg:
objects, bones, curves... etc.

Without this, Python expressions to access this data needed to use an absolute path from `bpy.data`,
however this is inconvenient, breaks easily (based on naming) and wouldn't set the dependencies correctly.
This commit is contained in:
2016-04-05 07:02:43 +10:00
parent 65f279b770
commit 82b0a9e369
6 changed files with 204 additions and 6 deletions

View File

@@ -42,10 +42,13 @@
#include "BKE_fcurve.h"
#include "BKE_global.h"
#include "bpy_rna_driver.h" /* for pyrna_driver_get_variable_value */
#include "bpy_driver.h"
extern void BPY_update_rna_module(void);
#define USE_RNA_AS_PYOBJECT
/* for pydrivers (drivers using one-line Python expressions to express relationships between targets) */
PyObject *bpy_pydriver_Dict = NULL;
@@ -262,12 +265,24 @@ float BPY_driver_exec(ChannelDriver *driver, const float evaltime)
driver_vars = PyDict_New();
for (dvar = driver->variables.first, i = 0; dvar; dvar = dvar->next) {
PyObject *driver_arg = NULL;
float tval = 0.0f;
/* try to get variable value */
tval = driver_get_variable_value(driver, dvar);
driver_arg = PyFloat_FromDouble((double)tval);
/* support for any RNA data */
#ifdef USE_RNA_AS_PYOBJECT
if (dvar->type == DVAR_TYPE_SINGLE_PROP) {
driver_arg = pyrna_driver_get_variable_value(driver, &dvar->targets[0]);
if (driver_arg == NULL) {
driver_arg = PyFloat_FromDouble(0.0);
}
}
else
#endif
{
/* try to get variable value */
float tval = driver_get_variable_value(driver, dvar);
driver_arg = PyFloat_FromDouble((double)tval);
}
/* try to add to dictionary */
/* if (PyDict_SetItemString(driver_vars, dvar->name, driver_arg)) { */
if (PyDict_SetItem(driver_vars, PyTuple_GET_ITEM(expr_vars, i++), driver_arg) < 0) {