Revision: 17745
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17745
Author:   aligorith
Date:     2008-12-08 10:16:09 +0100 (Mon, 08 Dec 2008)

Log Message:
-----------
AnimSys2: View All (HomeKey) in Dopesheet improved

* Keyframes in IPO's now get considered when doing this
* Vertical placement of view has been improved, though it's still not optimal

Modified Paths:
--------------
    branches/animsys2/source/blender/blenkernel/BKE_ipo.h
    branches/animsys2/source/blender/blenkernel/intern/action.c
    branches/animsys2/source/blender/blenkernel/intern/ipo.c
    branches/animsys2/source/blender/blenloader/intern/readfile.c
    branches/animsys2/source/blender/src/header_action.c
    branches/animsys2/source/blender/src/keyframing.c
    branches/animsys2/source/blender/src/space.c

Modified: branches/animsys2/source/blender/blenkernel/BKE_ipo.h
===================================================================
--- branches/animsys2/source/blender/blenkernel/BKE_ipo.h       2008-12-08 
06:17:12 UTC (rev 17744)
+++ branches/animsys2/source/blender/blenkernel/BKE_ipo.h       2008-12-08 
09:16:09 UTC (rev 17745)
@@ -103,6 +103,8 @@
 float calc_ipo_time(struct Ipo *ipo, float ctime);
 void calc_ipo(struct Ipo *ipo, float ctime);
 
+void calc_ipo_range(struct Ipo *ipo, float *start, float *end);
+
 /* ------------ Keyframe Column Tools -------------- */
 
 void add_to_cfra_elem(struct ListBase *lb, struct BezTriple *bezt);

Modified: branches/animsys2/source/blender/blenkernel/intern/action.c
===================================================================
--- branches/animsys2/source/blender/blenkernel/intern/action.c 2008-12-08 
06:17:12 UTC (rev 17744)
+++ branches/animsys2/source/blender/blenkernel/intern/action.c 2008-12-08 
09:16:09 UTC (rev 17745)
@@ -761,33 +761,33 @@
        dst->ctime= src->ctime;
 }
 
-
+/* Calculate the extents of given action */
 void calc_action_range(const bAction *act, float *start, float *end, int 
incl_hidden)
 {
-       const bActionChannel *chan;
-       const bConstraintChannel *conchan;
-       const IpoCurve  *icu;
-       float min=999999999.0f, max=-999999999.0;
+       bActionChannel *chan;
+       bConstraintChannel *conchan;
+       IpoCurve *icu;
+       float min=999999999.0f, max=-999999999.0f;
        int     foundvert=0;
 
-       if(act) {
+       if (act) {
                for (chan=act->chanbase.first; chan; chan=chan->next) {
-                       if(incl_hidden || (chan->flag & ACHAN_HIDDEN)==0) {
-                               if(chan->ipo) {
+                       if ((incl_hidden) || (chan->flag & ACHAN_HIDDEN)==0) {
+                               if (chan->ipo) {
                                        for (icu=chan->ipo->curve.first; icu; 
icu=icu->next) {
-                                               if(icu->totvert) {
-                                                       min= MIN2 (min, 
icu->bezt[0].vec[1][0]);
-                                                       max= MAX2 (max, 
icu->bezt[icu->totvert-1].vec[1][0]);
+                                               if (icu->totvert) {
+                                                       min= MIN2(min, 
icu->bezt[0].vec[1][0]);
+                                                       max= MAX2(max, 
icu->bezt[icu->totvert-1].vec[1][0]);
                                                        foundvert=1;
                                                }
                                        }
                                }
                                for (conchan=chan->constraintChannels.first; 
conchan; conchan=conchan->next) {
-                                       if(conchan->ipo) {
+                                       if (conchan->ipo) {
                                                for 
(icu=conchan->ipo->curve.first; icu; icu=icu->next) {
-                                                       if(icu->totvert) {
-                                                               min= MIN2 (min, 
icu->bezt[0].vec[1][0]);
-                                                               max= MAX2 (max, 
icu->bezt[icu->totvert-1].vec[1][0]);
+                                                       if (icu->totvert) {
+                                                               min= MIN2(min, 
icu->bezt[0].vec[1][0]);
+                                                               max= MAX2(max, 
icu->bezt[icu->totvert-1].vec[1][0]);
                                                                foundvert=1;
                                                        }
                                                }

Modified: branches/animsys2/source/blender/blenkernel/intern/ipo.c
===================================================================
--- branches/animsys2/source/blender/blenkernel/intern/ipo.c    2008-12-08 
06:17:12 UTC (rev 17744)
+++ branches/animsys2/source/blender/blenkernel/intern/ipo.c    2008-12-08 
09:16:09 UTC (rev 17745)
@@ -586,6 +586,35 @@
        return ctime;
 }
 
+/* Calculate the extents of IPO block's keyframes */
+void calc_ipo_range (Ipo *ipo, float *start, float *end)
+{
+       IpoCurve *icu;
+       float min=999999999.0f, max=-999999999.0f;
+       short foundvert=0;
+
+       if (ipo) {
+               for (icu=ipo->curve.first; icu; icu=icu->next) {
+                       if (icu->totvert) {
+                               min= MIN2(min, icu->bezt[0].vec[1][0]);
+                               max= MAX2(max, 
icu->bezt[icu->totvert-1].vec[1][0]);
+                               foundvert=1;
+                       }
+               }
+       }       
+       
+       /* minimum length is 1 frame */
+       if (foundvert) {
+               if (min == max) max += 1.0f;
+               *start= min;
+               *end= max;
+       }
+       else {
+               *start= 0.0f;
+               *end= 1.0f;
+       }
+}
+
 /* ***************************** IPO Curve Sanity 
********************************* */
 /* The functions here are used in various parts of Blender, usually after some 
editing
  * of keyframe data has occurred. They ensure that keyframe data is properly 
ordered and

Modified: branches/animsys2/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/animsys2/source/blender/blenloader/intern/readfile.c       
2008-12-08 06:17:12 UTC (rev 17744)
+++ branches/animsys2/source/blender/blenloader/intern/readfile.c       
2008-12-08 09:16:09 UTC (rev 17745)
@@ -8003,8 +8003,12 @@
                                                case SPACE_ACTION:
                                                {
                                                        SpaceAction *sact= 
(SpaceAction *)sl;
+                                                       
                                                        sact->mode= 
SACTCONT_DOPESHEET;
                                                        sact->autosnap= 
SACTSNAP_FRAME;
+                                                       
+                                                       sact->v2d.min[1]= 
-1000.0f;
+                                                       sact->v2d.max[0]= 0.0f;
                                                }
                                                        break;
                                                case SPACE_IPO:

Modified: branches/animsys2/source/blender/src/header_action.c
===================================================================
--- branches/animsys2/source/blender/src/header_action.c        2008-12-08 
06:17:12 UTC (rev 17744)
+++ branches/animsys2/source/blender/src/header_action.c        2008-12-08 
09:16:09 UTC (rev 17745)
@@ -50,6 +50,8 @@
 #include "DNA_screen_types.h"
 #include "DNA_space_types.h"
 
+#include "BLI_blenlib.h"
+
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 #include "BIF_editaction.h"
@@ -65,6 +67,7 @@
 #include "BKE_armature.h"
 #include "BKE_constraint.h"
 #include "BKE_depsgraph.h"
+#include "BKE_ipo.h"
 #include "BKE_global.h"
 #include "BKE_main.h"
 #include "BKE_utildefines.h"
@@ -230,26 +233,67 @@
 
 void do_action_buttons(unsigned short event)
 {
-       Object *ob= OBACT;
-
        switch(event) {
                case B_ACTHOME: /* HOMEKEY in Action Editor */
+               {
+                       ListBase act_data = {NULL, NULL};
+                       bActListElem *ale;
+                       void *data;
+                       short datatype;
+                       int filter;
+                       
+                       /* get pointer to data in editor... */
+                       data = get_action_context(&datatype);
+                       if (data == NULL) return;
+                       
                        /*      Find X extents */
-                       G.v2d->cur.xmin = 0;
-                       G.v2d->cur.ymin=-SCROLLB;
-                       
-                       if ((G.saction->mode==SACTCONT_ACTION) && 
(G.saction->action)) {
+                       if (ELEM(G.saction->mode, SACTCONT_ACTION, 
SACTCONT_DOPESHEET)) {
                                float extra;
                                
-                               calc_action_range(G.saction->action, 
&G.v2d->cur.xmin, &G.v2d->cur.xmax, 0);
-                               if (G.saction->pin==0 && ob) {
-                                       G.v2d->cur.xmin= 
get_action_frame_inv(ob, G.v2d->cur.xmin);
-                                       G.v2d->cur.xmax= 
get_action_frame_inv(ob, G.v2d->cur.xmax);
-                               }                               
-                               extra= 0.05*(G.v2d->cur.xmax - G.v2d->cur.xmin);
-                               G.v2d->cur.xmin-= extra;
-                               G.v2d->cur.xmax+= extra;
-
+                               /* get data to filter, from Action or Dopesheet 
*/
+                               filter= (ACTFILTER_VISIBLE | ACTFILTER_SEL | 
ACTFILTER_FOREDIT | ACTFILTER_IPOKEYS);
+                               actdata_filter(&act_data, filter, data, 
datatype);
+                               
+                               /* set large values to try to override */
+                               G.v2d->cur.xmin= 999999999.0f;
+                               G.v2d->cur.xmax= -999999999.0f;
+                               
+                               /* check if any channels to set range with */
+                               if (act_data.first) {
+                                       /* go through channels, finding max 
extents*/
+                                       for (ale= act_data.first; ale; ale= 
ale->next) {
+                                               Ipo *ipo= (Ipo *)ale->key_data; 
+                                               float min, max;
+                                               
+                                               /* get range and apply 
necessary scaling before */
+                                               calc_ipo_range(ipo, &min, &max);
+                                               
+                                               if (NLA_CHAN_SCALED(ale)) {
+                                                       Object *nob= 
(NLA_ACTION_SCALED) ? OBACT : (Object *)ale->id;
+                                                       min= 
get_action_frame_inv(nob, min);
+                                                       max= 
get_action_frame_inv(nob, max);
+                                               }
+                                               
+                                               /* try to set cur using these 
values, if they're more extreme than previously set values */
+                                               G.v2d->cur.xmin= MIN2(min, 
G.v2d->cur.xmin);
+                                               G.v2d->cur.xmax= MAX2(max, 
G.v2d->cur.xmax);
+                                       }
+                                       
+                                       /* free memory */
+                                       BLI_freelistN(&act_data);
+                               }
+                               else {
+                                       /* set default range */
+                                       G.v2d->cur.xmin= -5;
+                                       G.v2d->cur.xmax= 100;
+                               }
+                               
+                               /* add extra offset to the 'cur' rect so that 
keys will be in view */
+                               extra= 0.05f * (G.v2d->cur.xmax - 
G.v2d->cur.xmin);
+                               G.v2d->cur.xmin -= extra;
+                               G.v2d->cur.xmax += extra;
+                               
+                               /* set default range if same frame */
                                if (G.v2d->cur.xmin==G.v2d->cur.xmax) {
                                        G.v2d->cur.xmax= -5;
                                        G.v2d->cur.xmax= 100;
@@ -257,19 +301,19 @@
                        }
                        else { /* shapekeys and/or no action */
                                G.v2d->cur.xmin= -5.0;
-                               G.v2d->cur.xmax= 65.0;
+                               G.v2d->cur.xmax= 100.0;
                        }
                        
-                       // FIXME: this vertical alignment is bad!
-                       G.v2d->cur.ymin= -75.0;
-                       G.v2d->cur.ymax= 0.0;
+                       /* although view is supposed to go downwards starting 
from 0, this doesn't seem to be the case... */
+                       G.v2d->cur.ymin= -305.0;
+                       G.v2d->cur.ymax= -150.0;
                        
                        G.v2d->tot= G.v2d->cur;
                        test_view2d(G.v2d, curarea->winx, curarea->winy);
                        view2d_do_locks(curarea, V2D_LOCK_COPY);
                        
                        addqueue (curarea->win, REDRAW, 1);
-                       
+               }       
                        break;
                        
                /* copy/paste/paste-flip buttons in 3d-view header in PoseMode 
*/

Modified: branches/animsys2/source/blender/src/keyframing.c
===================================================================
--- branches/animsys2/source/blender/src/keyframing.c   2008-12-08 06:17:12 UTC 
(rev 17744)
+++ branches/animsys2/source/blender/src/keyframing.c   2008-12-08 09:16:09 UTC 
(rev 17745)
@@ -257,17 +257,13 @@
        BezTriple *newb;
        int i= 0;
        
-       if (icu->bezt == NULL) {
-               icu->bezt= MEM_callocN(sizeof(BezTriple), "beztriple");
-               *(icu->bezt)= *bezt;
-               icu->totvert= 1;
-       }
-       else {
+       if (icu->bezt) {
                short replace = -1;
                i = binarysearch_bezt_index(icu->bezt, bezt->vec[1][0], 
icu->totvert, &replace);
                
                if (replace) {                  
                        /* sanity check: 'i' may in rare cases exceed arraylen 
*/
+                       // FIXME: do not overwrite handletype if just 
replacing...?
                        if ((i >= 0) && (i < icu->totvert))
                                *(icu->bezt + i) = *bezt;
                }
@@ -293,7 +289,13 @@
                        icu->totvert++;
                }
        }
+       else {
+               icu->bezt= MEM_callocN(sizeof(BezTriple), "beztriple");
+               *(icu->bezt)= *bezt;
+               icu->totvert= 1;
+       }
        
+       
        /* we need to return the index, so that some tools which do 
post-processing can 
         * detect where we added the BezTriple in the array
         */

Modified: branches/animsys2/source/blender/src/space.c
===================================================================
--- branches/animsys2/source/blender/src/space.c        2008-12-08 06:17:12 UTC 
(rev 17744)
+++ branches/animsys2/source/blender/src/space.c        2008-12-08 09:16:09 UTC 
(rev 17745)
@@ -5355,10 +5355,10 @@
        saction->v2d.cur.ymax= 5.0f;
 
        saction->v2d.min[0]= 0.0f;
-       saction->v2d.min[1]= 0.0f;
+       saction->v2d.min[1]= -1000.0f;
 
        saction->v2d.max[0]= MAXFRAMEF;
-       saction->v2d.max[1]= 1000.0f;
+       saction->v2d.max[1]= 0;
        
        saction->v2d.minzoom= 0.01f;
        saction->v2d.maxzoom= 50;


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to