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.
This commit is contained in:
Joshua Leung
2009-07-06 11:06:34 +00:00
parent f87fcde686
commit 1586570261
9 changed files with 415 additions and 9 deletions

View File

@@ -58,6 +58,12 @@ void BKE_nlastrips_sort_strips(ListBase *strips);
short BKE_nlastrips_add_strip(ListBase *strips, struct NlaStrip *strip);
void BKE_nlastrips_make_metas(ListBase *strips, short temp);
void BKE_nlastrips_clear_metas(ListBase *strips, short onlySel, short onlyTemp);
short BKE_nlameta_add_strip(struct NlaStrip *mstrip, struct NlaStrip *strip);
void BKE_nlameta_flush_transforms(struct NlaStrip *mstrip);
/* ............ */
struct NlaTrack *BKE_nlatrack_find_active(ListBase *tracks);

View File

@@ -616,6 +616,199 @@ short BKE_nlastrips_add_strip (ListBase *strips, NlaStrip *strip)
return 1;
}
/* Meta-Strips ------------------------------------ */
/* Convert 'islands' (i.e. continuous string of) selected strips to be
* contained within 'Meta-Strips' which act as strips which contain strips.
* temp: are the meta-strips to be created 'temporary' ones used for transforms?
*/
void BKE_nlastrips_make_metas (ListBase *strips, short temp)
{
NlaStrip *mstrip = NULL;
NlaStrip *strip, *stripn;
/* sanity checks */
if ELEM(NULL, strips, strips->first)
return;
/* group all continuous chains of selected strips into meta-strips */
for (strip= strips->first; strip; strip= stripn) {
stripn= strip->next;
if (strip->flag & NLASTRIP_FLAG_SELECT) {
/* if there is an existing meta-strip, add this strip to it, otherwise, create a new one */
if (mstrip == NULL) {
/* add a new meta-strip, and add it before the current strip that it will replace... */
mstrip= MEM_callocN(sizeof(NlaStrip), "Meta-NlaStrip");
mstrip->type = NLASTRIP_TYPE_META;
BLI_insertlinkbefore(strips, strip, mstrip);
/* set flags */
mstrip->flag = NLASTRIP_FLAG_SELECT;
/* set temp flag if appropriate (i.e. for transform-type editing) */
if (temp)
mstrip->flag |= NLASTRIP_FLAG_TEMP_META;
/* make its start frame be set to the start frame of the current strip */
mstrip->start= strip->start;
}
/* remove the selected strips from the track, and add to the meta */
BLI_remlink(strips, strip);
BLI_addtail(&mstrip->strips, strip);
/* expand the meta's dimensions to include the newly added strip- i.e. its last frame */
mstrip->end= strip->end;
}
else {
/* current strip wasn't selected, so the end of 'island' of selected strips has been reached,
* so stop adding strips to the current meta
*/
mstrip= NULL;
}
}
}
/* Remove meta-strips (i.e. flatten the list of strips) from the top-level of the list of strips
* sel: only consider selected meta-strips, otherwise all meta-strips are removed
* onlyTemp: only remove the 'temporary' meta-strips used for transforms
*/
void BKE_nlastrips_clear_metas (ListBase *strips, short onlySel, short onlyTemp)
{
NlaStrip *strip, *stripn;
/* sanity checks */
if ELEM(NULL, strips, strips->first)
return;
/* remove meta-strips fitting the criteria of the arguments */
for (strip= strips->first; strip; strip= stripn) {
stripn= strip->next;
/* check if strip is a meta-strip */
if (strip->type == NLASTRIP_TYPE_META) {
/* if check if selection and 'temporary-only' considerations are met */
if ((onlySel==0) || (strip->flag & NLASTRIP_FLAG_SELECT)) {
if ((!onlyTemp) || (strip->flag & NLASTRIP_FLAG_TEMP_META)) {
NlaStrip *cs, *csn;
/* move each one of the meta-strip's children before the meta-strip
* in the list of strips after unlinking them from the meta-strip
*/
for (cs= strip->strips.first; cs; cs= csn) {
csn= cs->next;
BLI_remlink(&strip->strips, cs);
BLI_insertlinkbefore(strips, strip, cs);
}
/* free the meta-strip now */
BLI_freelinkN(strips, strip);
}
}
}
}
}
/* Add the given NLA-Strip to the given Meta-Strip, assuming that the
* strip isn't attached to anyy list of strips
*/
short BKE_nlameta_add_strip (NlaStrip *mstrip, NlaStrip *strip)
{
/* sanity checks */
if ELEM(NULL, mstrip, strip)
return 0;
/* firstly, check if the meta-strip has space for this */
if (BKE_nlastrips_has_space(&mstrip->strips, strip->start, strip->end) == 0)
return 0;
/* check if this would need to be added to the ends of the meta,
* and subsequently, if the neighbouring strips allow us enough room
*/
if (strip->start < mstrip->start) {
/* check if strip to the left (if it exists) ends before the
* start of the strip we're trying to add
*/
if ((mstrip->prev == NULL) || (mstrip->prev->end <= strip->start)) {
/* add strip to start of meta's list, and expand dimensions */
BLI_addhead(&mstrip->strips, strip);
mstrip->start= strip->start;
return 1;
}
else /* failed... no room before */
return 0;
}
else if (strip->end > mstrip->end) {
/* check if strip to the right (if it exists) starts before the
* end of the strip we're trying to add
*/
if ((mstrip->next == NULL) || (mstrip->next->start >= strip->end)) {
/* add strip to end of meta's list, and expand dimensions */
BLI_addtail(&mstrip->strips, strip);
mstrip->end= strip->end;
return 1;
}
else /* failed... no room after */
return 0;
}
else {
/* just try to add to the meta-strip (no dimension changes needed) */
return BKE_nlastrips_add_strip(&mstrip->strips, strip);
}
}
/* Adjust the settings of NLA-Strips contained within a Meta-Strip (recursively),
* until the Meta-Strips children all fit within the Meta-Strip's new dimensions
*/
void BKE_nlameta_flush_transforms (NlaStrip *mstrip)
{
NlaStrip *strip;
float oStart, oEnd, offset;
/* sanity checks
* - strip must exist
* - strip must be a meta-strip with some contents
*/
if ELEM(NULL, mstrip, mstrip->strips.first)
return;
if (mstrip->type != NLASTRIP_TYPE_META)
return;
/* get the original start/end points, and calculate the start-frame offset
* - these are simply the start/end frames of the child strips,
* since we assume they weren't transformed yet
*/
oStart= ((NlaStrip *)mstrip->strips.first)->start;
oEnd= ((NlaStrip *)mstrip->strips.last)->end;
offset= mstrip->start - oStart;
/* optimisation:
* don't flush if nothing changed yet
* TODO: maybe we need a flag to say always flush?
*/
if (IS_EQ(oStart, mstrip->start) && IS_EQ(oEnd, mstrip->end))
return;
/* for each child-strip, calculate new start/end points based on this new info */
for (strip= mstrip->strips.first; strip; strip= strip->next) {
//PointerRNA strip_ptr;
/* firstly, just apply the changes in offset to both ends of the strip */
strip->start += offset;
strip->end += offset;
/* now, we need to fix the endpoint to take into account scaling */
// TODO..
/* finally, make sure the strip's children (if it is a meta-itself), get updated */
BKE_nlameta_flush_transforms(strip);
}
}
/* NLA-Tracks ---------------------------------------- */
/* Find the active NLA-track for the given stack */

View File

@@ -176,6 +176,23 @@ static void nla_strip_get_color_inside (AnimData *adt, NlaStrip *strip, float co
color[2]= 0.19f;
}
}
else if (strip->type == NLASTRIP_TYPE_META) {
/* Meta Clip */
if (strip->flag & NLASTRIP_FLAG_SELECT) {
/* selected - use a bold purple color */
// FIXME: hardcoded temp-hack colors
color[0]= 0.41f;
color[1]= 0.13f;
color[2]= 0.59f;
}
else {
/* normal, unselected strip - use (hardly noticable) dark purple tinge */
// FIXME: hardcoded temp-hack colors
color[0]= 0.20f;
color[1]= 0.15f;
color[2]= 0.26f;
}
}
else {
/* Action Clip (default/normal type of strip) */
if ((strip->flag & NLASTRIP_FLAG_ACTIVE) && (adt && (adt->flag & ADT_NLA_EDIT_ON))) {
@@ -293,7 +310,7 @@ static void nla_draw_strip (AnimData *adt, NlaTrack *nlt, NlaStrip *strip, View2
/* draw outline */
gl_round_box_shade(GL_LINE_LOOP, strip->start, yminc, strip->end, ymaxc, 0.0, 0.0, 0.1);
/* if action-clip strip, draw lines delimiting repeats too (in the same colour */
/* if action-clip strip, draw lines delimiting repeats too (in the same color as outline) */
if ((strip->type == NLASTRIP_TYPE_CLIP) && IS_EQ(strip->repeat, 1.0f)==0) {
float repeatLen = (strip->actend - strip->actstart) * strip->scale;
int i;
@@ -309,6 +326,26 @@ static void nla_draw_strip (AnimData *adt, NlaTrack *nlt, NlaStrip *strip, View2
fdrawline(repeatPos, yminc, repeatPos, ymaxc);
}
}
/* or if meta-strip, draw lines delimiting extents of sub-strips (in same color as outline, if more than 1 exists) */
else if ((strip->type == NLASTRIP_TYPE_META) && (strip->strips.first != strip->strips.last)) {
NlaStrip *cs;
float y= (ymaxc-yminc)/2.0f + yminc;
/* only draw first-level of child-strips, but don't draw any lines on the endpoints */
for (cs= strip->strips.first; cs; cs= cs->next) {
/* draw start-line if not same as end of previous (and only if not the first strip)
* - on upper half of strip
*/
if ((cs->prev) && IS_EQ(cs->prev->end, cs->start)==0)
fdrawline(cs->start, y, cs->start, ymaxc);
/* draw end-line if not the last strip
* - on lower half of strip
*/
if (cs->next)
fdrawline(cs->end, yminc, cs->end, y);
}
}
/* reset linestyle */
setlinestyle(0);

View File

@@ -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 */

View File

@@ -70,6 +70,8 @@
#include "ED_markers.h"
#include "nla_intern.h"
/* button events */
enum {
B_REDR = 0,
@@ -142,9 +144,18 @@ static void nla_edit_transformmenu(bContext *C, uiLayout *layout, void *arg_unus
uiItemEnumO(layout, "Scale", 0, "TFM_OT_transform", "mode", TFM_TIME_SCALE);
}
static void nla_edit_snapmenu(bContext *C, uiLayout *layout, void *arg_unused)
{
uiItemEnumO(layout, NULL, 0, "NLA_OT_snap", "type", NLAEDIT_SNAP_CFRA);
uiItemEnumO(layout, NULL, 0, "NLA_OT_snap", "type", NLAEDIT_SNAP_NEAREST_FRAME);
uiItemEnumO(layout, NULL, 0, "NLA_OT_snap", "type", NLAEDIT_SNAP_NEAREST_SECOND);
uiItemEnumO(layout, NULL, 0, "NLA_OT_snap", "type", NLAEDIT_SNAP_NEAREST_MARKER);
}
static void nla_editmenu(bContext *C, uiLayout *layout, void *arg_unused)
{
uiItemMenuF(layout, "Transform", 0, nla_edit_transformmenu);
uiItemMenuF(layout, "Snap", 0, nla_edit_snapmenu);
uiItemS(layout);
@@ -173,6 +184,11 @@ static void nla_addmenu(bContext *C, uiLayout *layout, void *arg_unused)
uiItemS(layout);
uiItemO(layout, NULL, 0, "NLA_OT_add_meta");
uiItemO(layout, NULL, 0, "NLA_OT_remove_meta");
uiItemS(layout);
uiItemO(layout, NULL, 0, "NLA_OT_add_tracks");
uiItemBooleanO(layout, "Add Tracks Above Selected", 0, "NLA_OT_add_tracks", "above_selected", 1);
}

View File

@@ -106,6 +106,9 @@ void NLA_OT_tweakmode_exit(wmOperatorType *ot);
void NLA_OT_add_actionclip(wmOperatorType *ot);
void NLA_OT_add_transition(wmOperatorType *ot);
void NLA_OT_add_meta(wmOperatorType *ot);
void NLA_OT_remove_meta(wmOperatorType *ot);
void NLA_OT_duplicate(wmOperatorType *ot);
void NLA_OT_delete(wmOperatorType *ot);
void NLA_OT_split(wmOperatorType *ot);
@@ -116,6 +119,8 @@ void NLA_OT_move_down(wmOperatorType *ot);
void NLA_OT_apply_scale(wmOperatorType *ot);
void NLA_OT_clear_scale(wmOperatorType *ot);
void NLA_OT_snap(wmOperatorType *ot);
void NLA_OT_fmodifier_add(wmOperatorType *ot);

View File

@@ -146,6 +146,9 @@ void nla_operatortypes(void)
WM_operatortype_append(NLA_OT_add_actionclip);
WM_operatortype_append(NLA_OT_add_transition);
WM_operatortype_append(NLA_OT_add_meta);
WM_operatortype_append(NLA_OT_remove_meta);
WM_operatortype_append(NLA_OT_duplicate);
WM_operatortype_append(NLA_OT_delete);
WM_operatortype_append(NLA_OT_split);
@@ -156,6 +159,8 @@ void nla_operatortypes(void)
WM_operatortype_append(NLA_OT_apply_scale);
WM_operatortype_append(NLA_OT_clear_scale);
WM_operatortype_append(NLA_OT_snap);
WM_operatortype_append(NLA_OT_fmodifier_add);
}
@@ -236,6 +241,10 @@ static void nla_keymap_main (wmWindowManager *wm, ListBase *keymap)
/* add strips */
WM_keymap_add_item(keymap, "NLA_OT_add_actionclip", AKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_item(keymap, "NLA_OT_add_transition", TKEY, KM_PRESS, KM_SHIFT, 0);
/* meta-strips */
WM_keymap_add_item(keymap, "NLA_OT_add_meta", GKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_item(keymap, "NLA_OT_remove_meta", GKEY, KM_PRESS, KM_ALT, 0);
/* duplicate */
WM_keymap_add_item(keymap, "NLA_OT_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
@@ -257,6 +266,9 @@ static void nla_keymap_main (wmWindowManager *wm, ListBase *keymap)
/* clear scale */
WM_keymap_add_item(keymap, "NLA_OT_clear_scale", SKEY, KM_PRESS, KM_ALT, 0);
/* snap */
WM_keymap_add_item(keymap, "NLA_OT_snap", SKEY, KM_PRESS, KM_SHIFT, 0);
/* add f-modifier */
WM_keymap_add_item(keymap, "NLA_OT_fmodifier_add", MKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);

View File

@@ -510,8 +510,8 @@ enum {
/* temporary editing flags */
/* NLA-Strip is really just a temporary meta used to facilitate easier transform code */
NLASTRIP_FLAG_TEMP_META = (1<<30),
NLASTRIP_FLAG_EDIT_TOUCHED = (1<<31),
NLASTRIP_FLAG_TEMP_META = (1<<14),
NLASTRIP_FLAG_EDIT_TOUCHED = (1<<15),
} eNlaStrip_Flag;
/* NLA Strip Type */

View File

@@ -207,6 +207,7 @@ void rna_def_nlastrip(BlenderRNA *brna)
static EnumPropertyItem prop_type_items[] = {
{NLASTRIP_TYPE_CLIP, "CLIP", 0, "Action Clip", "NLA Strip references some Action."},
{NLASTRIP_TYPE_TRANSITION, "TRANSITION", 0, "Transition", "NLA Strip 'transitions' between adjacent strips."},
{NLASTRIP_TYPE_META, "META", 0, "Strip Container", "NLA Strip acts as a container for adjacent strips."},
{0, NULL, 0, NULL, NULL}};
static EnumPropertyItem prop_mode_blend_items[] = {
{NLASTRIP_MODE_BLEND, "BLEND", 0, "Blend", "Results of strip and accumulated results are combined in ratio governed by influence."},