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 #include #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 */ diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c index 726c898e843..888ab9769d8 100644 --- a/source/blender/editors/animation/keyframing.c +++ b/source/blender/editors/animation/keyframing.c @@ -231,7 +231,7 @@ int insert_bezt_fcurve (FCurve *fcu, BezTriple *bezt, short flag) dst->vec[0][1] += dy; dst->vec[1][1] += dy; dst->vec[2][1] += dy; - + dst->f1= bezt->f1; dst->f2= bezt->f2; dst->f3= bezt->f3;