From e7a364ba8f70ea9951f61e647299cc156e07d8b0 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Wed, 29 Nov 2017 17:20:00 +0100 Subject: ID static override: add basic support for overriding animation. This is very bold right now - you simply can replace (or add) an action to an override data-block. Actions themselves are not 'customizable' through override at all currently (we may at least add 'add/remove/replace fcurves' feature in future), and nothing else in animdata is overridable currently. --- source/blender/makesrna/intern/rna_animation.c | 31 +++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/source/blender/makesrna/intern/rna_animation.c b/source/blender/makesrna/intern/rna_animation.c index e53533df782..b6ded7a90d8 100644 --- a/source/blender/makesrna/intern/rna_animation.c +++ b/source/blender/makesrna/intern/rna_animation.c @@ -585,6 +585,33 @@ static FCurve *rna_Driver_find(AnimData *adt, ReportList *reports, const char *d return list_find_fcurve(&adt->drivers, data_path, index); } +bool rna_AnimaData_override_apply( + PointerRNA *ptr_dst, PointerRNA *ptr_src, PointerRNA *ptr_storage, + PropertyRNA *prop_dst, PropertyRNA *prop_src, PropertyRNA *UNUSED(prop_storage), + const int len_dst, const int len_src, const int len_storage, + IDOverrideStaticPropertyOperation *opop) +{ + BLI_assert(len_dst == len_src && (!ptr_storage || len_dst == len_storage) && len_dst == 0); + BLI_assert(opop->operation == IDOVERRIDESTATIC_OP_REPLACE && "Unsupported RNA override operation on animdata pointer"); + + /* AnimData is a special case, since you cannot edit/replace it, it's either existent or not. */ + AnimData *adt_dst = RNA_property_pointer_get(ptr_dst, prop_dst).data; + AnimData *adt_src = RNA_property_pointer_get(ptr_src, prop_src).data; + + if (adt_dst == NULL && adt_src != NULL) { + /* Copy anim data from reference into final local ID. */ + BKE_animdata_copy_id(NULL, ptr_dst->id.data, ptr_src->id.data, false); + return true; + } + else if (adt_dst != NULL && adt_src == NULL) { + /* Override has cleared/removed anim data from its reference. */ + BKE_animdata_free(ptr_dst->id.data, true); + return true; + } + + return false; +} + #else /* helper function for Keying Set -> keying settings */ @@ -999,6 +1026,8 @@ void rna_def_animdata_common(StructRNA *srna) prop = RNA_def_property(srna, "animation_data", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "adt"); RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_flag(prop, PROP_OVERRIDABLE); + RNA_def_property_override_funcs(prop, NULL, NULL, "rna_AnimaData_override_apply"); RNA_def_property_ui_text(prop, "Animation Data", "Animation data for this data-block"); } @@ -1022,7 +1051,7 @@ static void rna_def_animdata(BlenderRNA *brna) /* Active Action */ prop = RNA_def_property(srna, "action", PROP_POINTER, PROP_NONE); /* this flag as well as the dynamic test must be defined for this to be editable... */ - RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT); + RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT | PROP_OVERRIDABLE); 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 data-block"); -- cgit v1.2.3