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
path: root/source
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2011-04-26 17:49:40 +0400
committerJoshua Leung <aligorith@gmail.com>2011-04-26 17:49:40 +0400
commit64a37fadf09e32772520272a831034a9fe790fc8 (patch)
tree6cadbf712bc9186b731cfeeda256d2228820da5f /source
parent481aed1d0e7f943b9b7caa12a890c0cc4286ac00 (diff)
Adding support for adding copies of existing drivers to other animdata
blocks via PyAPI/RNA For example: ob = bpy.context.active_object # assumes default cube has some drivers added already before running script dst = bpy.data.objects["Camera"] adt = dst.animation_data_create() for driver in ob.animation_data.drivers: new_driver = adt.drivers.from_existing(driver)
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/intern/anim_sys.c16
-rw-r--r--source/blender/makesrna/intern/rna_animation.c47
2 files changed, 53 insertions, 10 deletions
diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c
index f7eaff475fa..5198172c205 100644
--- a/source/blender/blenkernel/intern/anim_sys.c
+++ b/source/blender/blenkernel/intern/anim_sys.c
@@ -194,7 +194,7 @@ AnimData *BKE_copy_animdata (AnimData *adt, const short do_action)
dadt= MEM_dupallocN(adt);
/* make a copy of action - at worst, user has to delete copies... */
- if(do_action) {
+ if (do_action) {
dadt->action= copy_action(adt->action);
dadt->tmpact= copy_action(adt->tmpact);
}
@@ -216,11 +216,11 @@ AnimData *BKE_copy_animdata (AnimData *adt, const short do_action)
return dadt;
}
-int BKE_copy_animdata_id(struct ID *id_to, struct ID *id_from, const short do_action)
+int BKE_copy_animdata_id (ID *id_to, ID *id_from, const short do_action)
{
AnimData *adt;
- if((id_to && id_from) && (GS(id_to->name) != GS(id_from->name)))
+ if ((id_to && id_from) && (GS(id_to->name) != GS(id_from->name)))
return 0;
BKE_free_animdata(id_to);
@@ -237,13 +237,13 @@ int BKE_copy_animdata_id(struct ID *id_to, struct ID *id_from, const short do_ac
void BKE_copy_animdata_id_action(struct ID *id)
{
AnimData *adt= BKE_animdata_from_id(id);
- if(adt) {
- if(adt->action) {
- ((ID *)adt->action)->us--;
+ if (adt) {
+ if (adt->action) {
+ id_us_min((ID *)adt->action);
adt->action= copy_action(adt->action);
}
- if(adt->tmpact) {
- ((ID *)adt->tmpact)->us--;
+ if (adt->tmpact) {
+ id_us_min((ID *)adt->tmpact);
adt->tmpact= copy_action(adt->tmpact);
}
}
diff --git a/source/blender/makesrna/intern/rna_animation.c b/source/blender/makesrna/intern/rna_animation.c
index 8e210a7a4cb..fb23e5ac63d 100644
--- a/source/blender/makesrna/intern/rna_animation.c
+++ b/source/blender/makesrna/intern/rna_animation.c
@@ -55,6 +55,7 @@ EnumPropertyItem keyingset_path_grouping_items[] = {
#ifdef RNA_RUNTIME
#include "BKE_animsys.h"
+#include "BKE_fcurve.h"
#include "BKE_nla.h"
#include "WM_api.h"
@@ -457,6 +458,24 @@ static void rna_NlaTrack_active_set(PointerRNA *ptr, PointerRNA value)
BKE_nlatrack_set_active(&adt->nla_tracks, track);
}
+
+static FCurve *rna_Driver_from_existing(AnimData *adt, bContext *C, FCurve *src_driver)
+{
+ /* verify that we've got a driver to duplicate */
+ if (ELEM(NULL, src_driver, src_driver->driver)) {
+ BKE_reportf(CTX_wm_reports(C), RPT_ERROR, "No valid driver data to create copy of");
+ return NULL;
+ }
+ else {
+ /* just make a copy of the existing one and add to self */
+ FCurve *new_fcu = copy_fcurve(src_driver);
+
+ // XXX: if we impose any ordering on these someday, this will be problematic
+ BLI_addtail(&adt->drivers, new_fcu);
+ return new_fcu;
+ }
+}
+
#else
/* helper function for Keying Set -> keying settings */
@@ -724,7 +743,7 @@ static void rna_api_animdata_nla_tracks(BlenderRNA *brna, PropertyRNA *cprop)
func = RNA_def_function(srna, "new", "rna_NlaTrack_new");
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
- RNA_def_function_ui_description(func, "Add a new NLA Tracks");
+ RNA_def_function_ui_description(func, "Add a new NLA Track");
RNA_def_pointer(func, "prev", "NlaTrack", "", "NLA Track to add the new one after.");
/* return type */
parm = RNA_def_pointer(func, "track", "NlaTrack", "", "New NLA Track.");
@@ -745,6 +764,28 @@ static void rna_api_animdata_nla_tracks(BlenderRNA *brna, PropertyRNA *cprop)
RNA_def_property_update(prop, NC_ANIMATION|ND_NLA|NA_SELECTED, NULL);
}
+static void rna_api_animdata_drivers(BlenderRNA *brna, PropertyRNA *cprop)
+{
+ StructRNA *srna;
+ PropertyRNA *parm;
+ FunctionRNA *func;
+
+ PropertyRNA *prop;
+
+ RNA_def_property_srna(cprop, "AnimDataDrivers");
+ srna= RNA_def_struct(brna, "AnimDataDrivers", NULL);
+ RNA_def_struct_sdna(srna, "AnimData");
+ RNA_def_struct_ui_text(srna, "Drivers", "Collection of Driver F-Curves");
+
+ func = RNA_def_function(srna, "from_existing", "rna_Driver_from_existing");
+ RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+ RNA_def_function_ui_description(func, "Add a new driver given an existing one");
+ RNA_def_pointer(func, "src_driver", "FCurve", "", "Existing Driver F-Curve to use as template for a new one");
+ /* return type */
+ parm = RNA_def_pointer(func, "driver", "FCurve", "", "New Driver F-Curve.");
+ RNA_def_function_return(func, parm);
+}
+
void rna_def_animdata_common(StructRNA *srna)
{
PropertyRNA *prop;
@@ -774,7 +815,7 @@ void rna_def_animdata(BlenderRNA *brna)
/* Active Action */
prop= RNA_def_property(srna, "action", PROP_POINTER, PROP_NONE);
RNA_def_property_flag(prop, PROP_EDITABLE); /* this flag as well as the dynamic test must be defined for this to be editable... */
- RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_Action_id_poll");
+ RNA_def_property_pointer_funcs(prop, NULL, "rna_AnimData_action_set", NULL, "rna_Action_id_poll");
RNA_def_property_editable_func(prop, "rna_AnimData_action_editable");
RNA_def_property_ui_text(prop, "Action", "Active Action for this datablock");
RNA_def_property_update(prop, NC_ANIMATION, NULL); /* this will do? */
@@ -805,6 +846,8 @@ void rna_def_animdata(BlenderRNA *brna)
RNA_def_property_struct_type(prop, "FCurve");
RNA_def_property_ui_text(prop, "Drivers", "The Drivers/Expressions for this datablock");
+ rna_api_animdata_drivers(brna, prop);
+
/* General Settings */
prop= RNA_def_property(srna, "use_nla", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", ADT_NLA_EVAL_OFF);