Revision: 14584
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14584
Author:   aligorith
Date:     2008-04-28 06:46:28 +0200 (Mon, 28 Apr 2008)

Log Message:
-----------
Assorted tidy-ups for keyframing (including auto-keying), while trying to track 
down a bug.

Modified Paths:
--------------
    trunk/blender/source/blender/src/editipo.c
    trunk/blender/source/blender/src/transform_conversions.c

Modified: trunk/blender/source/blender/src/editipo.c
===================================================================
--- trunk/blender/source/blender/src/editipo.c  2008-04-28 00:51:31 UTC (rev 
14583)
+++ trunk/blender/source/blender/src/editipo.c  2008-04-28 04:46:28 UTC (rev 
14584)
@@ -2032,15 +2032,17 @@
 #define BEZT_INSERT_THRESH     0.00001
 
 /* Binary search algorithm for finding where to insert BezTriple. (for use by 
insert_bezt_icu)
- * Returns the index to insert before, OR the -(index + 1) to replace. 
- * Caller will need to decrement index if > 0 to add to right place (and avoid 
segfaults)
+ * Returns the index to insert at (data already at that index will be offset 
if replace is 0)
  */
-static int binarysearch_bezt_index (BezTriple array[], BezTriple *item, int 
arraylen)
+static int binarysearch_bezt_index (BezTriple array[], BezTriple *item, int 
arraylen, short *replace)
 {
        int start=0, end=arraylen;
        int loopbreaker= 0, maxloop= arraylen * 2;
        const float frame= (item)? item->vec[1][0] : 0.0f;
        
+       /* initialise replace-flag first */
+       *replace= 0;
+       
        /* sneaky optimisations (don't go through searching process if...):
         *      - keyframe to be added is to be added out of current bounds
         *      - keyframe to be added would replace one of the existing ones 
on bounds
@@ -2055,15 +2057,19 @@
                
                /* 'First' Keyframe (when only one keyframe, this case is used) 
*/
                framenum= array[0].vec[1][0];
-               if (IS_EQT(frame, framenum, BEZT_INSERT_THRESH))
-                       return -1;
+               if (IS_EQT(frame, framenum, BEZT_INSERT_THRESH)) {
+                       *replace = 1;
+                       return 0;
+               }
                else if (frame < framenum)
                        return 0;
                        
                /* 'Last' Keyframe */
                framenum= array[(arraylen-1)].vec[1][0];
-               if (IS_EQT(frame, framenum, BEZT_INSERT_THRESH))
-                       return -(arraylen);
+               if (IS_EQT(frame, framenum, BEZT_INSERT_THRESH)) {
+                       *replace= 1;
+                       return (arraylen - 1);
+               }
                else if (frame > framenum)
                        return arraylen;
        }
@@ -2078,8 +2084,10 @@
                float midfra= array[mid].vec[1][0];
                
                /* check if exactly equal to midpoint */
-               if (IS_EQT(frame, midfra, BEZT_INSERT_THRESH))
-                       return -(mid + 1);
+               if (IS_EQT(frame, midfra, BEZT_INSERT_THRESH)) {
+                       *replace = 1;
+                       return mid;
+               }
                
                /* repeat in upper/lower half */
                if (frame > midfra)
@@ -2118,19 +2126,17 @@
                icu->totvert= 1;
        }
        else {
-               i = binarysearch_bezt_index(icu->bezt, bezt, icu->totvert);
+               short replace = -1;
+               i = binarysearch_bezt_index(icu->bezt, bezt, icu->totvert, 
&replace);
                
-               if (i < 0) {
-                       /* replace existing item (need to 'invert' i first and 
decremement by 1) */
-                       i = -i - 1;
-                       
+               if (replace) {                  
                        /* sanity check: 'i' may in rare cases exceed arraylen 
*/
-                       if (i < icu->totvert)
+                       if ((i >= 0) && (i < icu->totvert))
                                *(icu->bezt + i) = *bezt;
                }
                else {
                        /* add new */
-                       newb= MEM_callocN( (icu->totvert+1)*sizeof(BezTriple), 
"beztriple");
+                       newb= MEM_callocN((icu->totvert+1)*sizeof(BezTriple), 
"beztriple");
                        
                        /* add the beztriples that should occur before the 
beztriple to be pasted (originally in ei->icu) */
                        if (i > 0)

Modified: trunk/blender/source/blender/src/transform_conversions.c
===================================================================
--- trunk/blender/source/blender/src/transform_conversions.c    2008-04-28 
00:51:31 UTC (rev 14583)
+++ trunk/blender/source/blender/src/transform_conversions.c    2008-04-28 
04:46:28 UTC (rev 14584)
@@ -3188,7 +3188,7 @@
                        actname= "Object";
                
                if (IS_AUTOKEY_FLAG(INSERTAVAIL)) {
-                       if (ob->ipo || ob->action) {
+                       if ((ob->ipo) || (ob->action)) {
                                ID *id= (ID *)(ob);
                                
                                if (ob->ipo) {
@@ -3215,6 +3215,7 @@
                        }
                }
                else if (IS_AUTOKEY_FLAG(INSERTNEEDED)) {
+                       ID *id= (ID *)(ob);
                        short doLoc=0, doRot=0, doScale=0;
                        
                        /* filter the conditions when this happens (assume that 
curarea->spacetype==SPACE_VIE3D) */
@@ -3245,33 +3246,35 @@
                        }
                        
                        if (doLoc) {
-                               insertkey_smarter(&ob->id, ID_OB, actname, 
NULL, OB_LOC_X);
-                               insertkey_smarter(&ob->id, ID_OB, actname, 
NULL, OB_LOC_Y);
-                               insertkey_smarter(&ob->id, ID_OB, actname, 
NULL, OB_LOC_Z);
+                               insertkey_smarter(id, ID_OB, actname, NULL, 
OB_LOC_X);
+                               insertkey_smarter(id, ID_OB, actname, NULL, 
OB_LOC_Y);
+                               insertkey_smarter(id, ID_OB, actname, NULL, 
OB_LOC_Z);
                        }
                        if (doRot) {
-                               insertkey_smarter(&ob->id, ID_OB, actname, 
NULL, OB_ROT_X);
-                               insertkey_smarter(&ob->id, ID_OB, actname, 
NULL, OB_ROT_Y);
-                               insertkey_smarter(&ob->id, ID_OB, actname, 
NULL, OB_ROT_Z);
+                               insertkey_smarter(id, ID_OB, actname, NULL, 
OB_ROT_X);
+                               insertkey_smarter(id, ID_OB, actname, NULL, 
OB_ROT_Y);
+                               insertkey_smarter(id, ID_OB, actname, NULL, 
OB_ROT_Z);
                        }
                        if (doScale) {
-                               insertkey_smarter(&ob->id, ID_OB, actname, 
NULL, OB_SIZE_X);
-                               insertkey_smarter(&ob->id, ID_OB, actname, 
NULL, OB_SIZE_Y);
-                               insertkey_smarter(&ob->id, ID_OB, actname, 
NULL, OB_SIZE_Z);
+                               insertkey_smarter(id, ID_OB, actname, NULL, 
OB_SIZE_X);
+                               insertkey_smarter(id, ID_OB, actname, NULL, 
OB_SIZE_Y);
+                               insertkey_smarter(id, ID_OB, actname, NULL, 
OB_SIZE_Z);
                        }
                }
                else {
-                       insertkey(&ob->id, ID_OB, actname, NULL, OB_LOC_X, 0);
-                       insertkey(&ob->id, ID_OB, actname, NULL, OB_LOC_Y, 0);
-                       insertkey(&ob->id, ID_OB, actname, NULL, OB_LOC_Z, 0);
+                       ID *id= (ID *)(ob);
                        
-                       insertkey(&ob->id, ID_OB, actname, NULL, OB_ROT_X, 0);
-                       insertkey(&ob->id, ID_OB, actname, NULL, OB_ROT_Y, 0);
-                       insertkey(&ob->id, ID_OB, actname, NULL, OB_ROT_Z, 0);
-                                               
-                       insertkey(&ob->id, ID_OB, actname, NULL, OB_SIZE_X, 0);
-                       insertkey(&ob->id, ID_OB, actname, NULL, OB_SIZE_Y, 0);
-                       insertkey(&ob->id, ID_OB, actname, NULL, OB_SIZE_Z, 0);
+                       insertkey(id, ID_OB, actname, NULL, OB_LOC_X, 0);
+                       insertkey(id, ID_OB, actname, NULL, OB_LOC_Y, 0);
+                       insertkey(id, ID_OB, actname, NULL, OB_LOC_Z, 0);
+                       
+                       insertkey(id, ID_OB, actname, NULL, OB_ROT_X, 0);
+                       insertkey(id, ID_OB, actname, NULL, OB_ROT_Y, 0);
+                       insertkey(id, ID_OB, actname, NULL, OB_ROT_Z, 0);
+                       
+                       insertkey(id, ID_OB, actname, NULL, OB_SIZE_X, 0);
+                       insertkey(id, ID_OB, actname, NULL, OB_SIZE_Y, 0);
+                       insertkey(id, ID_OB, actname, NULL, OB_SIZE_Z, 0);
                }
                
                remake_object_ipos(ob);
@@ -3286,6 +3289,7 @@
  */
 void autokeyframe_pose_cb_func(Object *ob, int tmode, short targetless_ik)
 {
+       ID *id= (ID *)(ob);
        bArmature *arm= ob->data;
        bAction *act;
        bPose   *pose;
@@ -3348,36 +3352,36 @@
                                        }
                                        
                                        if (doLoc) {
-                                               insertkey_smarter(&ob->id, 
ID_PO, pchan->name, NULL, AC_LOC_X);
-                                               insertkey_smarter(&ob->id, 
ID_PO, pchan->name, NULL, AC_LOC_Y);
-                                               insertkey_smarter(&ob->id, 
ID_PO, pchan->name, NULL, AC_LOC_Z);
+                                               insertkey_smarter(id, ID_PO, 
pchan->name, NULL, AC_LOC_X);
+                                               insertkey_smarter(id, ID_PO, 
pchan->name, NULL, AC_LOC_Y);
+                                               insertkey_smarter(id, ID_PO, 
pchan->name, NULL, AC_LOC_Z);
                                        }
                                        if (doRot) {
-                                               insertkey_smarter(&ob->id, 
ID_PO, pchan->name, NULL, AC_QUAT_W);
-                                               insertkey_smarter(&ob->id, 
ID_PO, pchan->name, NULL, AC_QUAT_X);
-                                               insertkey_smarter(&ob->id, 
ID_PO, pchan->name, NULL, AC_QUAT_Y);
-                                               insertkey_smarter(&ob->id, 
ID_PO, pchan->name, NULL, AC_QUAT_Z);
+                                               insertkey_smarter(id, ID_PO, 
pchan->name, NULL, AC_QUAT_W);
+                                               insertkey_smarter(id, ID_PO, 
pchan->name, NULL, AC_QUAT_X);
+                                               insertkey_smarter(id, ID_PO, 
pchan->name, NULL, AC_QUAT_Y);
+                                               insertkey_smarter(id, ID_PO, 
pchan->name, NULL, AC_QUAT_Z);
                                        }
                                        if (doScale) {
-                                               insertkey_smarter(&ob->id, 
ID_PO, pchan->name, NULL, AC_SIZE_X);
-                                               insertkey_smarter(&ob->id, 
ID_PO, pchan->name, NULL, AC_SIZE_Y);
-                                               insertkey_smarter(&ob->id, 
ID_PO, pchan->name, NULL, AC_SIZE_Z);
+                                               insertkey_smarter(id, ID_PO, 
pchan->name, NULL, AC_SIZE_X);
+                                               insertkey_smarter(id, ID_PO, 
pchan->name, NULL, AC_SIZE_Y);
+                                               insertkey_smarter(id, ID_PO, 
pchan->name, NULL, AC_SIZE_Z);
                                        }
                                }
                                /* insert keyframe in any channel that's 
appropriate */
                                else {
-                                       insertkey(&ob->id, ID_PO, pchan->name, 
NULL, AC_SIZE_X, 0);
-                                       insertkey(&ob->id, ID_PO, pchan->name, 
NULL, AC_SIZE_Y, 0);
-                                       insertkey(&ob->id, ID_PO, pchan->name, 
NULL, AC_SIZE_Z, 0);
+                                       insertkey(id, ID_PO, pchan->name, NULL, 
AC_SIZE_X, 0);
+                                       insertkey(id, ID_PO, pchan->name, NULL, 
AC_SIZE_Y, 0);
+                                       insertkey(id, ID_PO, pchan->name, NULL, 
AC_SIZE_Z, 0);
                                        
-                                       insertkey(&ob->id, ID_PO, pchan->name, 
NULL, AC_QUAT_W, 0);
-                                       insertkey(&ob->id, ID_PO, pchan->name, 
NULL, AC_QUAT_X, 0);
-                                       insertkey(&ob->id, ID_PO, pchan->name, 
NULL, AC_QUAT_Y, 0);
-                                       insertkey(&ob->id, ID_PO, pchan->name, 
NULL, AC_QUAT_Z, 0);
+                                       insertkey(id, ID_PO, pchan->name, NULL, 
AC_QUAT_W, 0);
+                                       insertkey(id, ID_PO, pchan->name, NULL, 
AC_QUAT_X, 0);
+                                       insertkey(id, ID_PO, pchan->name, NULL, 
AC_QUAT_Y, 0);
+                                       insertkey(id, ID_PO, pchan->name, NULL, 
AC_QUAT_Z, 0);
                                        
-                                       insertkey(&ob->id, ID_PO, pchan->name, 
NULL, AC_LOC_X, 0);
-                                       insertkey(&ob->id, ID_PO, pchan->name, 
NULL, AC_LOC_Y, 0);
-                                       insertkey(&ob->id, ID_PO, pchan->name, 
NULL, AC_LOC_Z, 0);
+                                       insertkey(id, ID_PO, pchan->name, NULL, 
AC_LOC_X, 0);
+                                       insertkey(id, ID_PO, pchan->name, NULL, 
AC_LOC_Y, 0);
+                                       insertkey(id, ID_PO, pchan->name, NULL, 
AC_LOC_Z, 0);
                                }
                        }
                }


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

Reply via email to