[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21381] branches/soc-2009-aligorith/source /blender: NLA SoC: More work on Meta-Strips
Joshua Leung
aligorith at gmail.com
Mon Jul 6 13:06:34 CEST 2009
Revision: 21381
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21381
Author: aligorith
Date: 2009-07-06 13:06:34 +0200 (Mon, 06 Jul 2009)
Log Message:
-----------
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.
Modified Paths:
--------------
branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h
branches/soc-2009-aligorith/source/blender/blenkernel/intern/nla.c
branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_draw.c
branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_edit.c
branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_header.c
branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_intern.h
branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_ops.c
branches/soc-2009-aligorith/source/blender/makesdna/DNA_anim_types.h
branches/soc-2009-aligorith/source/blender/makesrna/intern/rna_nla.c
Modified: branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h
===================================================================
--- branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h 2009-07-06 10:45:14 UTC (rev 21380)
+++ branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h 2009-07-06 11:06:34 UTC (rev 21381)
@@ -58,6 +58,12 @@
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);
Modified: branches/soc-2009-aligorith/source/blender/blenkernel/intern/nla.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/blenkernel/intern/nla.c 2009-07-06 10:45:14 UTC (rev 21380)
+++ branches/soc-2009-aligorith/source/blender/blenkernel/intern/nla.c 2009-07-06 11:06:34 UTC (rev 21381)
@@ -616,6 +616,199 @@
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 */
Modified: branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_draw.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_draw.c 2009-07-06 10:45:14 UTC (rev 21380)
+++ branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_draw.c 2009-07-06 11:06:34 UTC (rev 21381)
@@ -176,6 +176,23 @@
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 @@
/* 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 @@
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);
Modified: branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_edit.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_edit.c 2009-07-06 10:45:14 UTC (rev 21380)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list