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>2011-01-14 05:06:35 +0300
committerJoshua Leung <aligorith@gmail.com>2011-01-14 05:06:35 +0300
commit423fbcfa5c3674fcbd828f0b51de863cb74d6b9d (patch)
tree24cd206df391d85c4692882764d55f4833f5a0ac /source/blender/editors/animation/drivers.c
parent3bf46c57c972598a17a0eddc8bc70ad3b20a95da (diff)
Driver creation hack:
Drivers created from the Properties Editor for Materials and Textures will now be created on Object-level instead of on their owner Material/Texture as for their keyframes. The intention of this hack is to allow users to be able to easily set up drivers for materials and textures. Without this hack, users would have had to do this manually via the Datablocks editor (I've described this method a few times in detail, though this still attracts complaints), as the way the depsgraph works does not allow ID blocks other than Objects and directly-linked Object data to be driven. As a result, although this hack can be done for these two cases, there are no workarounds possible for Scene and Scene-linked settings. There are 2 issues that will be noticed with this approach: 1) There may be confusion over why the drivers are found under Object level and not Material/Texture level. 2) Driver status will not be shown in the buttons, leading to attempts to try to keyframe the properties directly later and subsequent confusion when finding that that won't work. However, these are the sacrifices we'll need to make to get easy-setup working in the meantime until the proper fixes can be done.
Diffstat (limited to 'source/blender/editors/animation/drivers.c')
-rw-r--r--source/blender/editors/animation/drivers.c99
1 files changed, 92 insertions, 7 deletions
diff --git a/source/blender/editors/animation/drivers.c b/source/blender/editors/animation/drivers.c
index c6c333755b0..8d74e7b1b59 100644
--- a/source/blender/editors/animation/drivers.c
+++ b/source/blender/editors/animation/drivers.c
@@ -27,6 +27,7 @@
* ***** END GPL LICENSE BLOCK *****
*/
+#include <stdio.h>
#include <string.h>
#include "MEM_guardedalloc.h"
@@ -35,12 +36,19 @@
#include "BLI_utildefines.h"
#include "DNA_anim_types.h"
+#include "DNA_object_types.h"
+#include "DNA_material_types.h"
+#include "DNA_texture_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_space_types.h"
#include "BKE_animsys.h"
#include "BKE_depsgraph.h"
#include "BKE_fcurve.h"
#include "BKE_context.h"
#include "BKE_report.h"
+#include "BKE_material.h"
+#include "BKE_texture.h"
#include "ED_keyframing.h"
@@ -386,6 +394,83 @@ short ANIM_paste_driver (ReportList *reports, ID *id, const char rna_path[], int
/* ************************************************** */
/* UI-Button Interface */
+/* Temporary wrapper for driver operators for buttons to make it easier to create
+ * such drivers by rerouting all paths through the active object instead so that
+ * they will get picked up by the dependency system.
+ *
+ * < C: context pointer - for getting active data
+ * <> ptr: RNA pointer for property's datablock. May be modified as result of path remapping.
+ * < prop: RNA definition of property to add for
+ *
+ * > returns: MEM_alloc'd string representing the path to the property from the given PointerRNA
+ */
+static char *get_driver_path_hack (bContext *C, PointerRNA *ptr, PropertyRNA *prop)
+{
+ ID *id = (ID *)ptr->id.data;
+ ScrArea *sa = CTX_wm_area(C);
+
+ /* get standard path which may be extended */
+ char *basepath = RNA_path_from_ID_to_property(ptr, prop);
+ char *path = basepath; /* in case no remapping is needed */
+
+ /* Remapping will only be performed in the Properties Editor, as only this
+ * restricts the subspace of options to the 'active' data (a manageable state)
+ */
+ // TODO: watch out for pinned context?
+ if ((sa) && (sa->spacetype == SPACE_BUTS)) {
+ Object *ob = CTX_data_active_object(C);
+
+ if (ob && id) {
+ /* only id-types which can be remapped to go through objects should be considered */
+ switch (GS(id->name)) {
+ case ID_MA: /* materials */
+ {
+ Material *ma = give_current_material(ob, ob->actcol);
+
+ /* assumes: material will only be shown if it is active objects's active material it's ok */
+ if ((ID*)ma == id) {
+ /* create new path */
+ // TODO: use RNA path functions to construct instead?
+ path = BLI_sprintfN("material_slots[\"%s\"].material.%s",
+ ma->id.name+2, basepath);
+
+ /* free old one */
+ MEM_freeN(basepath);
+ }
+ }
+ break;
+
+ case ID_TE: /* textures */
+ {
+ Material *ma = give_current_material(ob, ob->actcol);
+ Tex *tex = give_current_material_texture(ma);
+
+ /* assumes: texture will only be shown if it is active material's active texture it's ok */
+ if ((ID*)tex == id) {
+ /* create new path */
+ // TODO: use RNA path functions to construct step by step instead?
+ path = BLI_sprintfN("material_slots[\"%s\"].material.texture_slots[\"%s\"].texture.%s",
+ ma->id.name+2, tex->id.name+2, basepath);
+
+ /* free old one */
+ MEM_freeN(basepath);
+ }
+ }
+ break;
+ }
+
+ /* fix RNA pointer, as we've now changed the ID root by changing the paths */
+ if (basepath != path) {
+ /* rebase provided pointer so that it starts from object... */
+ RNA_pointer_create(&ob->id, ptr->type, ptr->data, ptr);
+ }
+ }
+ }
+
+ /* the path should now have been corrected for use */
+ return path;
+}
+
/* Add Driver Button Operator ------------------------ */
static int add_driver_button_exec (bContext *C, wmOperator *op)
@@ -397,12 +482,12 @@ static int add_driver_button_exec (bContext *C, wmOperator *op)
/* try to create driver using property retrieved from UI */
uiContextActiveProperty(C, &ptr, &prop, &index);
-
+
if (all)
index= -1;
-
+
if (ptr.id.data && ptr.data && prop && RNA_property_animateable(&ptr, prop)) {
- char *path= RNA_path_from_ID_to_property(&ptr, prop);
+ char *path= get_driver_path_hack(C, &ptr, prop);
short flags = CREATEDRIVER_WITH_DEFAULT_DVAR;
if (path) {
@@ -456,9 +541,9 @@ static int remove_driver_button_exec (bContext *C, wmOperator *op)
if (all)
index= -1;
-
+
if (ptr.id.data && ptr.data && prop) {
- char *path= RNA_path_from_ID_to_property(&ptr, prop);
+ char *path= get_driver_path_hack(C, &ptr, prop);
success= ANIM_remove_driver(op->reports, ptr.id.data, path, index, 0);
MEM_freeN(path);
@@ -507,7 +592,7 @@ static int copy_driver_button_exec (bContext *C, wmOperator *op)
uiContextActiveProperty(C, &ptr, &prop, &index);
if (ptr.id.data && ptr.data && prop && RNA_property_animateable(&ptr, prop)) {
- char *path= RNA_path_from_ID_to_property(&ptr, prop);
+ char *path= get_driver_path_hack(C, &ptr, prop);
if (path) {
/* only copy the driver for the button that this was involved for */
@@ -551,7 +636,7 @@ static int paste_driver_button_exec (bContext *C, wmOperator *op)
uiContextActiveProperty(C, &ptr, &prop, &index);
if (ptr.id.data && ptr.data && prop && RNA_property_animateable(&ptr, prop)) {
- char *path= RNA_path_from_ID_to_property(&ptr, prop);
+ char *path= get_driver_path_hack(C, &ptr, prop);
if (path) {
/* only copy the driver for the button that this was involved for */