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/editors/space_graph
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/editors/space_graph')
-rw-r--r--source/blender/editors/space_graph/graph_buttons.c192
1 files changed, 146 insertions, 46 deletions
diff --git a/source/blender/editors/space_graph/graph_buttons.c b/source/blender/editors/space_graph/graph_buttons.c
index 3faba9bbba7..c42dfd0015d 100644
--- a/source/blender/editors/space_graph/graph_buttons.c
+++ b/source/blender/editors/space_graph/graph_buttons.c
@@ -264,18 +264,18 @@ static void driver_add_var_cb (bContext *C, void *driver_v, void *dummy_v)
{
ChannelDriver *driver= (ChannelDriver *)driver_v;
- /* add a new var */
- driver_add_new_target(driver);
+ /* add a new variable */
+ driver_add_new_variable(driver);
}
/* callback to remove target variable from active driver */
-static void driver_delete_var_cb (bContext *C, void *driver_v, void *dtar_v)
+static void driver_delete_var_cb (bContext *C, void *driver_v, void *dvar_v)
{
ChannelDriver *driver= (ChannelDriver *)driver_v;
- DriverTarget *dtar= (DriverTarget *)dtar_v;
+ DriverVar *dvar= (DriverVar *)dvar_v;
- /* remove the active target */
- driver_free_target(driver, dtar);
+ /* remove the active variable */
+ driver_free_variable(driver, dvar);
}
/* callback to reset the driver's flags */
@@ -301,13 +301,115 @@ static int graph_panel_drivers_poll(const bContext *C, PanelType *pt)
}
+/* settings for 'single property' driver variable type */
+static void graph_panel_driverVar__singleProp(const bContext *C, uiLayout *layout, ID *id, DriverVar *dvar)
+{
+ DriverTarget *dtar= &dvar->targets[0];
+ PointerRNA dtar_ptr;
+ uiLayout *row, *col;
+ uiBlock *block;
+
+ /* initialise RNA pointer to the target */
+ RNA_pointer_create(id, &RNA_DriverTarget, dtar, &dtar_ptr);
+
+ /* Target ID */
+ row= uiLayoutRow(layout, 0);
+ uiTemplateAnyID(row, (bContext *)C, &dtar_ptr, "id", "id_type", "Value:");
+
+ /* Target Property */
+ // TODO: make this less technical...
+ if (dtar->id) {
+ PointerRNA root_ptr;
+
+ /* get pointer for resolving the property selected */
+ RNA_id_pointer_create(dtar->id, &root_ptr);
+
+ col= uiLayoutColumn(layout, 1);
+ block= uiLayoutGetBlock(col);
+ /* rna path */
+ uiTemplatePathBuilder(col, (bContext *)C, &dtar_ptr, "data_path", &root_ptr, "Path");
+ }
+}
+
+/* settings for 'rotation difference' driver variable type */
+static void graph_panel_driverVar__rotDiff(const bContext *C, uiLayout *layout, ID *id, DriverVar *dvar)
+{
+ DriverTarget *dtar= &dvar->targets[0];
+ DriverTarget *dtar2= &dvar->targets[1];
+ Object *ob1 = (Object *)dtar->id;
+ Object *ob2 = (Object *)dtar2->id;
+ PointerRNA dtar_ptr, dtar2_ptr;
+ uiLayout *col;
+
+ /* initialise RNA pointer to the target */
+ RNA_pointer_create(id, &RNA_DriverTarget, dtar, &dtar_ptr);
+ RNA_pointer_create(id, &RNA_DriverTarget, dtar2, &dtar2_ptr);
+
+ /* Bone 1 */
+ col= uiLayoutColumn(layout, 1);
+ uiTemplateAnyID(col, (bContext *)C, &dtar_ptr, "id", "id_type", "Bone 1:");
+
+ if (dtar->id && ob1->pose) {
+ PointerRNA tar_ptr;
+
+ RNA_pointer_create(dtar2->id, &RNA_Pose, ob1->pose, &tar_ptr);
+ uiItemPointerR(col, "", ICON_BONE_DATA, &dtar_ptr, "bone_target", &tar_ptr, "bones");
+ }
+
+ col= uiLayoutColumn(layout, 1);
+ uiTemplateAnyID(col, (bContext *)C, &dtar2_ptr, "id", "id_type", "Bone 2:");
+
+ if (dtar2->id && ob2->pose) {
+ PointerRNA tar_ptr;
+
+ RNA_pointer_create(dtar2->id, &RNA_Pose, ob2->pose, &tar_ptr);
+ uiItemPointerR(col, "", ICON_BONE_DATA, &dtar2_ptr, "bone_target", &tar_ptr, "bones");
+ }
+}
+
+/* settings for 'rotation difference' driver variable type */
+static void graph_panel_driverVar__locDiff(const bContext *C, uiLayout *layout, ID *id, DriverVar *dvar)
+{
+ DriverTarget *dtar= &dvar->targets[0];
+ DriverTarget *dtar2= &dvar->targets[1];
+ Object *ob1 = (Object *)dtar->id;
+ Object *ob2 = (Object *)dtar2->id;
+ PointerRNA dtar_ptr, dtar2_ptr;
+ uiLayout *col;
+
+ /* initialise RNA pointer to the target */
+ RNA_pointer_create(id, &RNA_DriverTarget, dtar, &dtar_ptr);
+ RNA_pointer_create(id, &RNA_DriverTarget, dtar2, &dtar2_ptr);
+
+ /* Bone 1 */
+ col= uiLayoutColumn(layout, 1);
+ uiTemplateAnyID(col, (bContext *)C, &dtar_ptr, "id", "id_type", "Ob/Bone 1:");
+
+ if (dtar->id && ob1->pose) {
+ PointerRNA tar_ptr;
+
+ RNA_pointer_create(dtar2->id, &RNA_Pose, ob1->pose, &tar_ptr);
+ uiItemPointerR(col, "", ICON_BONE_DATA, &dtar_ptr, "bone_target", &tar_ptr, "bones");
+ }
+
+ col= uiLayoutColumn(layout, 1);
+ uiTemplateAnyID(col, (bContext *)C, &dtar2_ptr, "id", "id_type", "Ob/Bone 2:");
+
+ if (dtar2->id && ob2->pose) {
+ PointerRNA tar_ptr;
+
+ RNA_pointer_create(dtar2->id, &RNA_Pose, ob2->pose, &tar_ptr);
+ uiItemPointerR(col, "", ICON_BONE_DATA, &dtar2_ptr, "bone_target", &tar_ptr, "bones");
+ }
+}
+
/* driver settings for active F-Curve (only for 'Drivers' mode) */
static void graph_panel_drivers(const bContext *C, Panel *pa)
{
bAnimListElem *ale;
FCurve *fcu;
ChannelDriver *driver;
- DriverTarget *dtar;
+ DriverVar *dvar;
PointerRNA driver_ptr;
uiLayout *col;
@@ -354,56 +456,54 @@ static void graph_panel_drivers(const bContext *C, Panel *pa)
uiItemL(col, "ERROR: invalid target channel(s)", ICON_ERROR);
}
- /* add driver target variables */
+ /* add driver variables */
col= uiLayoutColumn(pa->layout, 0);
block= uiLayoutGetBlock(col);
- but= uiDefBut(block, BUT, B_IPO_DEPCHANGE, "Add Target", 0, 0, 10*UI_UNIT_X, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "Add a new target variable for this Driver");
+ but= uiDefBut(block, BUT, B_IPO_DEPCHANGE, "Add Variable", 0, 0, 10*UI_UNIT_X, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "Add a new target variable for this Driver");
uiButSetFunc(but, driver_add_var_cb, driver, NULL);
/* loop over targets, drawing them */
- for (dtar= driver->targets.first; dtar; dtar= dtar->next) {
- PointerRNA dtar_ptr;
+ for (dvar= driver->variables.first; dvar; dvar= dvar->next) {
+ PointerRNA dvar_ptr;
uiLayout *box, *row;
- /* panel holding the buttons */
- box= uiLayoutBox(pa->layout);
-
- /* first row context info for driver */
- RNA_pointer_create(ale->id, &RNA_DriverTarget, dtar, &dtar_ptr);
-
- row= uiLayoutRow(box, 0);
- block= uiLayoutGetBlock(row);
- /* variable name */
- uiItemR(row, "", 0, &dtar_ptr, "name", 0);
-
- /* remove button */
- but= uiDefIconBut(block, BUT, B_IPO_DEPCHANGE, ICON_X, 290, 0, UI_UNIT_X, UI_UNIT_Y, NULL, 0.0, 0.0, 0.0, 0.0, "Delete target variable.");
- uiButSetFunc(but, driver_delete_var_cb, driver, dtar);
-
-
- /* Target ID */
- row= uiLayoutRow(box, 0);
- uiTemplateAnyID(row, (bContext *)C, &dtar_ptr, "id", "id_type", "Value:");
+ /* sub-layout column for this variable's settings */
+ col= uiLayoutColumn(pa->layout, 1);
- /* Target Property */
- // TODO: make this less technical...
- if (dtar->id) {
- PointerRNA root_ptr;
+ /* header panel */
+ box= uiLayoutBox(col);
+ /* first row context info for driver */
+ RNA_pointer_create(ale->id, &RNA_DriverVariable, dvar, &dvar_ptr);
- /* get pointer for resolving the property selected */
- RNA_id_pointer_create(dtar->id, &root_ptr);
+ row= uiLayoutRow(box, 0);
+ block= uiLayoutGetBlock(row);
+ /* variable name */
+ uiItemR(row, "", 0, &dvar_ptr, "name", 0);
+
+ /* remove button */
+ uiBlockSetEmboss(block, UI_EMBOSSN);
+ but= uiDefIconBut(block, BUT, B_IPO_DEPCHANGE, ICON_X, 290, 0, UI_UNIT_X, UI_UNIT_Y, NULL, 0.0, 0.0, 0.0, 0.0, "Delete target variable.");
+ uiButSetFunc(but, driver_delete_var_cb, driver, dvar);
+ uiBlockSetEmboss(block, UI_EMBOSS);
- col= uiLayoutColumn(box, 1);
- block= uiLayoutGetBlock(col);
- /* rna path */
- uiTemplatePathBuilder(col, (bContext *)C, &dtar_ptr, "data_path", &root_ptr, "Path");
+ /* variable type */
+ row= uiLayoutRow(box, 0);
+ uiItemR(row, "", 0, &dvar_ptr, "type", 0);
- /* array index */
- // TODO: this needs selector which limits it to ok values
- // NOTE: for for now, the array index box still gets shown when non-zero (i.e. for tweaking rigs as necessary)
- if (dtar->array_index)
- uiItemR(col, "Index", 0, &dtar_ptr, "array_index", 0);
- }
+ /* variable type settings */
+ box= uiLayoutBox(col);
+ /* controls to draw depends on the type of variable */
+ switch (dvar->type) {
+ case DVAR_TYPE_SINGLE_PROP: /* single property */
+ graph_panel_driverVar__singleProp(C, box, ale->id, dvar);
+ break;
+ case DVAR_TYPE_ROT_DIFF: /* rotational difference */
+ graph_panel_driverVar__rotDiff(C, box, ale->id, dvar);
+ break;
+ case DVAR_TYPE_LOC_DIFF: /* location difference */
+ graph_panel_driverVar__locDiff(C, box, ale->id, dvar);
+ break;
+ }
}
/* cleanup */