diff options
author | Joshua Leung <aligorith@gmail.com> | 2009-07-06 15:06:34 +0400 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2009-07-06 15:06:34 +0400 |
commit | 158657026122d3b169f1bea12a69ff8eb16bbe04 (patch) | |
tree | 2309b1d1da32715341981735789e4312539c9af9 /source/blender/editors/space_nla/nla_edit.c | |
parent | f87fcde686c85820c510c5c7806f6b6b8466ba5c (diff) |
NLA SoC: More work on Meta-Strips
* Added several API functions for Meta-Strips editing. One of these (flush transform) still needs a few tweaks before it does its job well enough for all cases.
* Meta strips are now drawn with a purple-ish colour. The start/end points of the strips they encompass are shown with lines along the length of the strips, with lines starting from the top indicating start-points and lines starting from the bottom indicating end-points.
* Meta strips can be made (i.e. strips can be assigned to meta-strips) by selecting some strips and pressing Shift-G.
Meta strips can be removed by selecting some meta-strips and pressing Alt-G.
* Strips can now be 'snapped' to start from: the current frame, the nearest frame, the nearest second, or the nearest marker; using the Shift-S hotkey.
'Islands' of adjacent selected strips occurring in the same track are moved together as a single strip so that the start-point of the first strip is on the sepcified time, but all the relative lengths of strips stay the same. Internally, temporary meta-strips are created to facilitate this.
Diffstat (limited to 'source/blender/editors/space_nla/nla_edit.c')
-rw-r--r-- | source/blender/editors/space_nla/nla_edit.c | 148 |
1 files changed, 142 insertions, 6 deletions
diff --git a/source/blender/editors/space_nla/nla_edit.c b/source/blender/editors/space_nla/nla_edit.c index e95d0b1a50a..f7d4db17e2c 100644 --- a/source/blender/editors/space_nla/nla_edit.c +++ b/source/blender/editors/space_nla/nla_edit.c @@ -346,7 +346,6 @@ void NLA_OT_add_actionclip (wmOperatorType *ot) /* ******************** Add Transition Operator ***************************** */ /* Add a new transition strip between selected strips */ -/* add the specified action as new strip */ static int nlaedit_add_transition_exec (bContext *C, wmOperator *op) { bAnimContext ac; @@ -453,6 +452,113 @@ void NLA_OT_add_transition (wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } +/* ******************** Add Meta-Strip Operator ***************************** */ +/* Add new meta-strips incorporating the selected strips */ + +/* add the specified action as new strip */ +static int nlaedit_add_meta_exec (bContext *C, wmOperator *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_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT); + ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); + + /* for each track, find pairs of strips to add transitions to */ + for (ale= anim_data.first; ale; ale= ale->next) { + NlaTrack *nlt= (NlaTrack *)ale->data; + + /* create meta-strips from the continuous chains of selected strips */ + BKE_nlastrips_make_metas(&nlt->strips, 0); + } + + /* free temp data */ + BLI_freelistN(&anim_data); + + /* set notifier that things have changed */ + ANIM_animdata_send_notifiers(C, &ac, ANIM_CHANGED_BOTH); + WM_event_add_notifier(C, NC_SCENE, NULL); + + /* done */ + return OPERATOR_FINISHED; +} + +void NLA_OT_add_meta (wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Add Meta-Strips"; + ot->idname= "NLA_OT_add_meta"; + ot->description= "Add new meta-strips incorporating the selected strips."; + + /* api callbacks */ + ot->exec= nlaedit_add_meta_exec; + ot->poll= nlaop_poll_tweakmode_off; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +/* ******************** Remove Meta-Strip Operator ***************************** */ +/* Separate out the strips held by the selected meta-strips */ + +static int nlaedit_remove_meta_exec (bContext *C, wmOperator *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_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT); + ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); + + /* for each track, find pairs of strips to add transitions to */ + for (ale= anim_data.first; ale; ale= ale->next) { + NlaTrack *nlt= (NlaTrack *)ale->data; + + /* clear all selected meta-strips, regardless of whether they are temporary or not */ + BKE_nlastrips_clear_metas(&nlt->strips, 1, 0); + } + + /* free temp data */ + BLI_freelistN(&anim_data); + + /* set notifier that things have changed */ + ANIM_animdata_send_notifiers(C, &ac, ANIM_CHANGED_BOTH); + WM_event_add_notifier(C, NC_SCENE, NULL); + + /* done */ + return OPERATOR_FINISHED; +} + +void NLA_OT_remove_meta (wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Remove Meta-Strips"; + ot->idname= "NLA_OT_remove_meta"; + ot->description= "Separate out the strips held by the selected meta-strips."; + + /* api callbacks */ + ot->exec= nlaedit_remove_meta_exec; + ot->poll= nlaop_poll_tweakmode_off; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + /* ******************** Duplicate Strips Operator ************************** */ /* Duplicates the selected NLA-Strips, putting them on new tracks above the one * the originals were housed in. @@ -1047,9 +1153,9 @@ static int nlaedit_snap_exec (bContext *C, wmOperator *op) bAnimListElem *ale; int filter; - Scene *scene= ac.scene; + Scene *scene; int mode = RNA_enum_get(op->ptr, "type"); - const float secf = (float)FPS; + float secf; /* get editor data */ if (ANIM_animdata_get_context(C, &ac) == 0) @@ -1059,17 +1165,28 @@ static int nlaedit_snap_exec (bContext *C, wmOperator *op) filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); + /* get some necessary vars */ + scene= ac.scene; + secf= (float)FPS; + /* since we may add tracks, perform this in reverse order */ for (ale= anim_data.last; ale; ale= ale->prev) { ListBase tmp_strips = {NULL, NULL}; + AnimData *adt= BKE_animdata_from_id(ale->id); NlaTrack *nlt= (NlaTrack *)ale->data; NlaStrip *strip, *stripn; + NlaTrack *track; - /* first pass: move all selected strips to a separate buffer, and apply snapping to them */ + /* create meta-strips from the continuous chains of selected strips */ + BKE_nlastrips_make_metas(&nlt->strips, 1); + + /* apply the snapping to all the temp meta-strips, then put them in a separate list to be added + * back to the original only if they still fit + */ for (strip= nlt->strips.first; strip; strip= stripn) { stripn= strip->next; - if (strip->flag & NLASTRIP_FLAG_SELECT) { + if (strip->flag & NLASTRIP_FLAG_TEMP_META) { float start, end; /* get the existing end-points */ @@ -1098,13 +1215,32 @@ static int nlaedit_snap_exec (bContext *C, wmOperator *op) /* get new endpoint based on start-point (and old length) */ strip->end= strip->start + (end - start); + /* apply transforms to meta-strip to its children */ + BKE_nlameta_flush_transforms(strip); + /* remove strip from track, and add to the temp buffer */ BLI_remlink(&nlt->strips, strip); BLI_addtail(&tmp_strips, strip); } } - // TODO: finish this... + /* try adding each meta-strip back to the track one at a time, to make sure they'll fit */ + for (strip= tmp_strips.first; strip; strip= stripn) { + stripn= strip->next; + + /* remove from temp-strips list */ + BLI_remlink(&tmp_strips, strip); + + /* in case there's no space in the current track, try adding */ + if (BKE_nlatrack_add_strip(nlt, strip) == 0) { + /* need to add a new track above the current one */ + track= add_nlatrack(adt, nlt); + BKE_nlatrack_add_strip(track, strip); + } + } + + /* remove the meta-strips now that we're done */ + BKE_nlastrips_clear_metas(&nlt->strips, 0, 1); } /* free temp data */ |