diff options
-rw-r--r-- | release/scripts/startup/bl_ui/space_nla.py | 3 | ||||
-rw-r--r-- | source/blender/editors/space_nla/nla_edit.c | 75 | ||||
-rw-r--r-- | source/blender/editors/space_nla/nla_intern.h | 2 | ||||
-rw-r--r-- | source/blender/editors/space_nla/nla_ops.c | 5 |
4 files changed, 85 insertions, 0 deletions
diff --git a/release/scripts/startup/bl_ui/space_nla.py b/release/scripts/startup/bl_ui/space_nla.py index ae5d308b0d3..06fe73a543c 100644 --- a/release/scripts/startup/bl_ui/space_nla.py +++ b/release/scripts/startup/bl_ui/space_nla.py @@ -147,6 +147,9 @@ class NLA_MT_edit(Menu): layout.operator("nla.action_sync_length").active = False layout.separator() + layout.operator("nla.make_single_user") + + layout.separator() layout.operator("nla.swap") layout.operator("nla.move_up") layout.operator("nla.move_down") diff --git a/source/blender/editors/space_nla/nla_edit.c b/source/blender/editors/space_nla/nla_edit.c index bb1e0e4245f..4eea5de616c 100644 --- a/source/blender/editors/space_nla/nla_edit.c +++ b/source/blender/editors/space_nla/nla_edit.c @@ -49,6 +49,7 @@ #include "BKE_fcurve.h" #include "BKE_nla.h" #include "BKE_context.h" +#include "BKE_library.h" #include "BKE_main.h" #include "BKE_report.h" #include "BKE_screen.h" @@ -1709,6 +1710,80 @@ void NLA_OT_action_sync_length(wmOperatorType *ot) ot->prop = RNA_def_boolean(ot->srna, "active", 1, "Active Strip Only", "Only sync the active length for the active strip"); } +/* ******************** Make Single User ********************************* */ +/* Ensure that each strip has its own action */ + +static int nlaedit_make_single_user_exec(bContext *C, wmOperator *UNUSED(op)) +{ + bAnimContext ac; + + ListBase anim_data = {NULL, NULL}; + bAnimListElem *ale; + int filter; + + /* get editor data */ + if (ANIM_animdata_get_context(C, &ac) == 0) + return OPERATOR_CANCELLED; + + /* get a list of the editable tracks being shown in the NLA */ + filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); + ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); + + /* Ensure that each action used only has a single user + * - This is done in reverse order so that the original strips are + * likely to still get to keep their action + */ + for (ale = anim_data.last; ale; ale = ale->prev) { + NlaTrack *nlt = (NlaTrack *)ale->data; + NlaStrip *strip; + + for (strip = nlt->strips.last; strip; strip = strip->prev) { + /* must be action-clip only (as only these have actions) */ + if ((strip->flag & NLASTRIP_FLAG_SELECT) && (strip->type == NLASTRIP_TYPE_CLIP)) { + if (strip->act == NULL) + continue; + + /* multi-user? */ + if (ID_REAL_USERS(strip->act) > 1) { + /* make a new copy of the action for us to use (it will have 1 user already) */ + bAction *new_action = BKE_action_copy(strip->act); + + /* decrement user count of our existing action */ + id_us_min(&strip->act->id); + + /* switch to the new copy */ + strip->act = new_action; + } + } + } + } + + /* free temp data */ + BLI_freelistN(&anim_data); + + /* set notifier that things have changed */ + WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_EDITED, NULL); + + /* done */ + return OPERATOR_FINISHED; +} + +void NLA_OT_make_single_user(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Make Single User"; + ot->idname = "NLA_OT_make_single_user"; + ot->description = "Ensure that each action is only used once in the set of strips selected"; + + /* api callbacks */ + ot->invoke = WM_operator_confirm; + ot->exec = nlaedit_make_single_user_exec; + ot->poll = nlaop_poll_tweakmode_off; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + /* ******************** Apply Scale Operator ***************************** */ /* Reset the scaling of the selected strips to 1.0f */ diff --git a/source/blender/editors/space_nla/nla_intern.h b/source/blender/editors/space_nla/nla_intern.h index 8d49d54375a..ad1a4dfa432 100644 --- a/source/blender/editors/space_nla/nla_intern.h +++ b/source/blender/editors/space_nla/nla_intern.h @@ -112,6 +112,8 @@ void NLA_OT_move_down(wmOperatorType *ot); void NLA_OT_action_sync_length(wmOperatorType *ot); +void NLA_OT_make_single_user(wmOperatorType *ot); + void NLA_OT_apply_scale(wmOperatorType *ot); void NLA_OT_clear_scale(wmOperatorType *ot); diff --git a/source/blender/editors/space_nla/nla_ops.c b/source/blender/editors/space_nla/nla_ops.c index 9dc598bc382..47496684380 100644 --- a/source/blender/editors/space_nla/nla_ops.c +++ b/source/blender/editors/space_nla/nla_ops.c @@ -158,6 +158,8 @@ void nla_operatortypes(void) WM_operatortype_append(NLA_OT_action_sync_length); + WM_operatortype_append(NLA_OT_make_single_user); + WM_operatortype_append(NLA_OT_apply_scale); WM_operatortype_append(NLA_OT_clear_scale); @@ -261,6 +263,9 @@ static void nla_keymap_main(wmKeyConfig *keyconf, wmKeyMap *keymap) kmi = WM_keymap_add_item(keymap, "NLA_OT_duplicate", DKEY, KM_PRESS, KM_ALT, 0); RNA_boolean_set(kmi->ptr, "linked", true); + + /* single user */ + WM_keymap_add_item(keymap, "NLA_OT_make_single_user", UKEY, KM_PRESS, 0, 0); /* delete */ WM_keymap_add_item(keymap, "NLA_OT_delete", XKEY, KM_PRESS, 0, 0); |