Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2010-01-05 00:15:45 +0300
committerJoshua Leung <aligorith@gmail.com>2010-01-05 00:15:45 +0300
commita9861e3381f4c2ac44fcc880aa1bd030a3ba8dae (patch)
tree72f8f0d8e7f4abb1833456bbaa8b27ac82a2e829 /source/blender/python/intern/bpy_driver.c
parentc79cf56b69ecf3f49c220ce6dea626caa48e089b (diff)
Durian Request: Drivers Recode
Highlights: * Support for Multi-Target Variables This was the main reason for this recode. Previously, variables could only be used to give some RNA property used as an input source to the driver a name. However, this meant that effects such as Rotational Difference couldn't be used in conjunction with other effects and/or settings to achieve the powerful results. Now, a variable can take several input targets, perform some interesting operations on them, and spit out a representative value based on that. * New Variable Types With the introduction of multi-target variables, there are now 3 types of variable that can be used: single property (i.e. the only type previously), Rotational Difference (angle between two bones), and Distance (distance between two objects or bones). * New Driver Types In addition to the existing 'Average', 'Sum', and 'Expression' types, there is now the additional options of 'Minimum' and 'Maximum'. These take the smallest/largest value that one of the variables evaluates to. * Fix for Driver F-Curve colouring bug Newly added drivers did not get automatically coloured in the Graph Editor properly. Was caused by inappropriate notifiers being used. Notes: * This commit breaks existing 2.5 files with drivers (in other words, they are lost forever). * Rigify has been corrected to work with the new system. The PyAPI for accessing targets used for the variables could still be made nicer (using subclassing to directly access?), but that is left for later. * Version patching for 2.49 files still needs to be put back in place.
Diffstat (limited to 'source/blender/python/intern/bpy_driver.c')
-rw-r--r--source/blender/python/intern/bpy_driver.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/source/blender/python/intern/bpy_driver.c b/source/blender/python/intern/bpy_driver.c
index 76df28494ac..016aed70c31 100644
--- a/source/blender/python/intern/bpy_driver.c
+++ b/source/blender/python/intern/bpy_driver.c
@@ -147,7 +147,7 @@ float BPY_pydriver_eval (ChannelDriver *driver)
PyObject *retval= NULL;
PyGILState_STATE gilstate;
- DriverTarget *dtar;
+ DriverVar *dvar;
float result = 0.0f; /* default return */
char *expr = NULL;
short targets_ok= 1;
@@ -174,24 +174,24 @@ float BPY_pydriver_eval (ChannelDriver *driver)
/* add target values to a dict that will be used as '__locals__' dict */
driver_vars = PyDict_New(); // XXX do we need to decref this?
- for (dtar= driver->targets.first; dtar; dtar= dtar->next) {
+ for (dvar= driver->variables.first; dvar; dvar= dvar->next) {
PyObject *driver_arg = NULL;
float tval = 0.0f;
-
+
/* try to get variable value */
- tval= driver_get_target_value(driver, dtar);
+ tval= driver_get_variable_value(driver, dvar);
driver_arg= PyFloat_FromDouble((double)tval);
-
+
/* try to add to dictionary */
- if (PyDict_SetItemString(driver_vars, dtar->name, driver_arg)) {
+ if (PyDict_SetItemString(driver_vars, dvar->name, driver_arg)) {
/* this target failed - bad name */
if (targets_ok) {
/* first one - print some extra info for easier identification */
fprintf(stderr, "\nBPY_pydriver_eval() - Error while evaluating PyDriver:\n");
targets_ok= 0;
}
-
- fprintf(stderr, "\tBPY_pydriver_eval() - couldn't add variable '%s' to namespace \n", dtar->name);
+
+ fprintf(stderr, "\tBPY_pydriver_eval() - couldn't add variable '%s' to namespace \n", dvar->name);
// BPy_errors_to_report(NULL); // TODO - reports
PyErr_Print();
PyErr_Clear();
@@ -202,12 +202,14 @@ float BPY_pydriver_eval (ChannelDriver *driver)
/* execute expression to get a value */
retval = PyRun_String(expr, Py_eval_input, bpy_pydriver_Dict, driver_vars);
#else
- if(driver->flag & DRIVER_FLAG_RECOMPILE || driver->expr_comp==NULL) {
+ /* compile the expression first if it hasn't been compiled or needs to be rebuilt */
+ if((driver->flag & DRIVER_FLAG_RECOMPILE) || (driver->expr_comp==NULL)) {
Py_XDECREF(driver->expr_comp);
driver->expr_comp= Py_CompileString(expr, "<bpy driver>", Py_eval_input);
driver->flag &= ~DRIVER_FLAG_RECOMPILE;
}
- if(driver->expr_comp)
+ /* evaluate the compiled expression */
+ if (driver->expr_comp)
retval= PyEval_EvalCode(driver->expr_comp, bpy_pydriver_Dict, driver_vars);
#endif