Added stepsize option for Pose ghosting draw. Patch provided by Roland
authorTon Roosendaal <ton@blender.org>
Wed, 16 Nov 2005 21:03:16 +0000 (21:03 +0000)
committerTon Roosendaal <ton@blender.org>
Wed, 16 Nov 2005 21:03:16 +0000 (21:03 +0000)
Hess.

In a comment on maillist I already mentioned a weird 0.5 in the code,
which I added to ensure correct rounding to integer frame numbers.
With a variable step size however, this won't work properly. You could
see it in the patch, because the ghost steps were animating.... they
should remain frozen, looks much nicer then. So I've added some fmod
voodoo here.

source/blender/blenloader/intern/readfile.c
source/blender/makesdna/DNA_armature_types.h
source/blender/src/buttons_editing.c
source/blender/src/drawarmature.c

index c974187fffc7979bddbc799f57fb4487417b5fb8..ede1c3be45ceb2e39e8b190b5a6722e753c3abd2 100644 (file)
@@ -5009,6 +5009,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
        if(main->versionfile <= 239) {
+               bArmature *arm;
                Object *ob;
                Scene *sce= main->scene.first;
                Camera *cam= main->camera.first;
@@ -5030,6 +5031,11 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        }
                }
                
+               /* updating stepsize for ghost drawing */
+               for(arm= main->armature.first; arm; arm= arm->id.next) {
+                       if (arm->ghostsize==0) arm->ghostsize=1;
+               }
+               
                while(sce) {
                        /* make 'innervert' the default subdivide type, for backwards compat */
                        sce->toolsettings->cornertype=1;
index b31a803718e213f8da1dc19e9552f57ecc3cec62..77b8ffd22868cc6a4ee720a313c100891c155577 100644 (file)
@@ -77,7 +77,7 @@ typedef struct bArmature {
        int                     flag;
        int                     drawtype;                       
        int                     deformflag;
-       short           ghostep, pad;
+       short           ghostep, ghostsize;
 }bArmature;
 
 /* armature->flag */
index 1eeb7e7793f9e5c6f469665886ffce93109950ee..c42420d47b2ff36619478cd25a90bf047b6a2272 100644 (file)
@@ -2758,9 +2758,10 @@ static void editing_panel_armature_type(Object *ob, bArmature *arm)
        uiDefButI(block, ROW, REDRAWVIEW3D, "B-Bone",   155, 100,70,20, &arm->drawtype, 0, ARM_B_BONE, 0, 0, "Draw bones as boxes, showing subdivision and b-splines");
        uiDefButI(block, ROW, REDRAWVIEW3D, "Envelope", 225, 100,85,20, &arm->drawtype, 0, ARM_ENVELOPE, 0, 0, "Draw bones as extruded spheres, showing deformation influence volume");
 
-       uiDefButBitI(block, TOG, ARM_DRAWAXES, REDRAWVIEW3D, "Draw Axes", 10, 80,100,20, &arm->flag, 0, 0, 0, 0, "Draw bone axes");
-       uiDefButBitI(block, TOG, ARM_DRAWNAMES, REDRAWVIEW3D, "Draw Names", 110,80,100,20, &arm->flag, 0, 0, 0, 0, "Draw bone names");
-       uiDefButS(block, NUM, REDRAWVIEW3D, "Ghost: ", 210,80,100,20, &arm->ghostep, 0.0f, 30.0f, 0, 0, "Draw Ghosts around current frame, for current Action");
+       uiDefButBitI(block, TOG, ARM_DRAWAXES, REDRAWVIEW3D, "Draw Axes", 10, 80,80,20, &arm->flag, 0, 0, 0, 0, "Draw bone axes");
+       uiDefButBitI(block, TOG, ARM_DRAWNAMES, REDRAWVIEW3D, "Draw Names", 90,80,80,20, &arm->flag, 0, 0, 0, 0, "Draw bone names");
+       uiDefButS(block, NUM, REDRAWVIEW3D, "Ghost: ", 170,80,80,20, &arm->ghostep, 0.0f, 30.0f, 0, 0, "Draw Ghosts around current frame, for current Action");
+       uiDefButS(block, NUM, REDRAWVIEW3D, "Step: ", 250,80,60,20, &arm->ghostsize, 1.0f, 20.0f, 0, 0, "How many frames between Ghost instances");
        uiBlockEndAlign(block);
        
        uiDefBut(block, LABEL, 0, "Deform Options", 10,60,150,20, 0, 0, 0, 0, 0, "");
index 1a6133c8f705712d4de403fbd38cd8220cc51581..fc02d18c655ce6029932ea786381cd7b4062ef50 100644 (file)
@@ -1721,8 +1721,8 @@ static void draw_ghost_poses(Base *base)
        bArmature *arm= ob->data;
        bPose *posen, *poseo;
        bActionStrip *strip;
-       float cur, start, end, stepsize, range, colfac, actframe;
-       int cfrao, maptime, flago;
+       float cur, start, end, stepsize, range, colfac, actframe, ctime;
+       int cfrao, maptime, flago, ipoflago;
        
        /* pre conditions, get an action with sufficient frames */
        if(ob->action==NULL)
@@ -1732,8 +1732,8 @@ static void draw_ghost_poses(Base *base)
        if(start==end)
                return;
 
-       stepsize= 1.0f;
-       range= (float)(arm->ghostep);
+       stepsize= (float)(arm->ghostsize);
+       range= (float)(arm->ghostep)*stepsize + 0.5f;   /* plus half to make the for loop end correct */
        
        /* we only map time for armature when an active strip exists */
        for (strip=ob->nlastrips.first; strip; strip=strip->next)
@@ -1749,6 +1749,8 @@ static void draw_ghost_poses(Base *base)
        else actframe= CFRA;
        flago= arm->flag;
        arm->flag &= ~(ARM_DRAWNAMES|ARM_DRAWAXES);
+       ipoflago= ob->ipoflag; 
+       ob->ipoflag |= OB_DISABLE_PATH;
        
        /* copy the pose */
        poseo= ob->pose;
@@ -1759,17 +1761,18 @@ static void draw_ghost_poses(Base *base)
        glEnable(GL_BLEND);
        if(G.vd->zbuf) glDisable(GL_DEPTH_TEST);
        
-       /* draw from lowest blend to darkest */
-       for(cur= 0.5f; cur<range; cur+=stepsize) {
+       /* draw from darkest blend to lowest */
+       for(cur= stepsize; cur<range; cur+=stepsize) {
                
-               colfac= cur/range;
+               ctime= cur - fmod((float)cfrao, stepsize);      /* ensures consistant stepping */
+               colfac= ctime/range;
                BIF_ThemeColorShadeAlpha(TH_WIRE, 0, -128-(int)(120.0f*sqrt(colfac)));
                
                /* only within action range */
-               if(actframe+cur >= start && actframe+cur <= end) {
+               if(actframe+ctime >= start && actframe+ctime <= end) {
                        
-                       if(maptime) CFRA= (int)get_action_frame_inv(ob, actframe+cur);
-                       else CFRA= (int)(actframe+cur);
+                       if(maptime) CFRA= (int)get_action_frame_inv(ob, actframe+ctime);
+                       else CFRA= (int)floor(actframe+ctime);
                        
                        if(CFRA!=cfrao) {
                                do_all_pose_actions(ob);
@@ -1777,12 +1780,17 @@ static void draw_ghost_poses(Base *base)
                                draw_pose_channels(base, OB_WIRE);
                        }
                }
+               
+               ctime= cur + fmod((float)cfrao, stepsize) - stepsize+1.0f;      /* ensures consistant stepping */
+               colfac= ctime/range;
+               BIF_ThemeColorShadeAlpha(TH_WIRE, 0, -128-(int)(120.0f*sqrt(colfac)));
+               
                /* only within action range */
-               if(actframe-cur >= start && actframe-cur <= end) {
-                       
-                       if(maptime) CFRA= (int)get_action_frame_inv(ob, actframe-cur);
-                       else CFRA= (int)(actframe-cur);
+               if(actframe-ctime >= start && actframe-ctime <= end) {
                        
+                       if(maptime) CFRA= (int)get_action_frame_inv(ob, actframe-ctime);
+                       else CFRA= (int)floor(actframe-ctime);
+
                        if(CFRA!=cfrao) {
                                do_all_pose_actions(ob);
                                where_is_pose(ob);
@@ -1801,8 +1809,9 @@ static void draw_ghost_poses(Base *base)
        ob->pose= poseo;
        arm->flag= flago;
        armature_rebuild_pose(ob, ob->data);
-       
        ob->flag |= OB_POSEMODE;
+       ob->ipoflag= ipoflago; 
+
 }
 
 /* called from drawobject.c */