Merge of itasc branch. Project files, scons and cmake should be working. Makefile...
[blender.git] / source / blender / blenkernel / intern / action.c
index 9ed469c..4cfd35a 100644 (file)
@@ -21,6 +21,7 @@
  * All rights reserved.
  *
  * Contributor(s): Full recode, Ton Roosendaal, Crete 2005
+ *                              Full recode, Joshua Leung, 2009
  *
  * ***** END GPL LICENSE BLOCK *****
  */
@@ -31,7 +32,8 @@
 
 #include <string.h>
 #include <math.h>
-#include <stdlib.h>    /* for NULL */
+#include <stdlib.h>
+#include <stddef.h>    
 
 #include "MEM_guardedalloc.h"
 
 #include "BKE_main.h"
 #include "BKE_object.h"
 #include "BKE_utildefines.h"
+#include "BIK_api.h"
 
 #include "BLI_arithb.h"
 #include "BLI_blenlib.h"
 #include "BLI_ghash.h"
 
-//XXX #include "nla.h"
+#include "RNA_access.h"
+#include "RNA_types.h"
 
 /* *********************** NOTE ON POSE AND ACTION **********************
 
@@ -169,17 +173,39 @@ void free_action (bAction *act)
 bAction *copy_action (bAction *src)
 {
        bAction *dst = NULL;
-       //bActionGroup *dgrp, *sgrp;    // XXX not used yet
+       bActionGroup *dgrp, *sgrp;
+       FCurve *dfcu, *sfcu;
        
        if (src == NULL) 
                return NULL;
        dst= copy_libblock(src);
        
-       BLI_duplicatelist(&dst->groups, &src->groups);  // XXX not used yet
+       /* duplicate the lists of groups and markers */
+       BLI_duplicatelist(&dst->groups, &src->groups);
        BLI_duplicatelist(&dst->markers, &src->markers);
        
-       /* copy f-curves */
-       copy_fcurves(&dst->curves, &src->curves);
+       /* copy F-Curves, fixing up the links as we go */
+       dst->curves.first= dst->curves.last= NULL;
+       
+       for (sfcu= src->curves.first; sfcu; sfcu= sfcu->next) {
+               /* duplicate F-Curve */
+               dfcu= copy_fcurve(sfcu);
+               BLI_addtail(&dst->curves, dfcu);
+               
+               /* fix group links (kindof bad list-in-list search, but this is the most reliable way) */
+               for (dgrp=dst->groups.first, sgrp=src->groups.first; dgrp && sgrp; dgrp=dgrp->next, sgrp=sgrp->next) {
+                       if (sfcu->grp == sgrp) {
+                               dfcu->grp= dgrp;
+                               
+                               if (dgrp->channels.first == sfcu)
+                                       dgrp->channels.first= dfcu;
+                               if (dgrp->channels.last == sfcu)
+                                       dgrp->channels.last= dfcu;
+                                       
+                               break;
+                       }
+               }
+       }
        
        dst->id.flag |= LIB_FAKEUSER; // XXX this is nasty for new users... maybe we don't want this anymore
        dst->id.us++;
@@ -187,6 +213,7 @@ bAction *copy_action (bAction *src)
        return dst;
 }
 
+/* *************** Action Groups *************** */
 
 /* Get the active action-group for an Action */
 bActionGroup *get_active_actiongroup (bAction *act)
@@ -379,14 +406,15 @@ bActionGroup *action_groups_find_named (bAction *act, const char name[])
        return NULL;
 }
 
-/* ************************ Pose channels *************** */
+/* *************** Pose channels *************** */
 
 /* usually used within a loop, so we got a N^2 slowdown */
 bPoseChannel *get_pose_channel(const bPose *pose, const char *name)
 {
        bPoseChannel *chan;
-
-       if (pose==NULL) return NULL;
+       
+       if (ELEM(NULL, pose, name) || (name[0] == 0))
+               return NULL;
        
        for (chan=pose->chanbase.first; chan; chan=chan->next) {
                if (chan->name[0] == name[0]) {
@@ -424,7 +452,7 @@ bPoseChannel *verify_pose_channel(bPose* pose, const char* name)
        chan->limitmin[0]= chan->limitmin[1]= chan->limitmin[2]= -180.0f;
        chan->limitmax[0]= chan->limitmax[1]= chan->limitmax[2]= 180.0f;
        chan->stiffness[0]= chan->stiffness[1]= chan->stiffness[2]= 0.0f;
-       
+       chan->ikrotweight = chan->iklinweight = 0.0f;
        Mat4One(chan->constinv);
        
        BLI_addtail(&pose->chanbase, chan);
@@ -450,7 +478,18 @@ bPoseChannel *get_active_posechannel (Object *ob)
        return NULL;
 }
 
-
+const char *get_ikparam_name(bPose *pose)
+{
+       if (pose) {
+               switch (pose->iksolver) {
+               case IKSOLVER_LEGACY:
+                       return NULL;
+               case IKSOLVER_ITASC:
+                       return "bItasc";
+               }
+       }
+       return NULL;
+}
 /* dst should be freed already, makes entire duplicate */
 void copy_pose (bPose **dst, bPose *src, int copycon)
 {
@@ -472,7 +511,10 @@ void copy_pose (bPose **dst, bPose *src, int copycon)
        outPose= MEM_callocN(sizeof(bPose), "pose");
        
        BLI_duplicatelist(&outPose->chanbase, &src->chanbase);
-       
+       outPose->iksolver = src->iksolver;
+       outPose->ikdata = NULL;
+       outPose->ikparam = MEM_dupallocN(src->ikparam);
+
        if (copycon) {
                for (pchan=outPose->chanbase.first; pchan; pchan=pchan->next) {
                        copy_constraints(&listb, &pchan->constraints);  // copy_constraints NULLs listb
@@ -484,6 +526,39 @@ void copy_pose (bPose **dst, bPose *src, int copycon)
        *dst=outPose;
 }
 
+void init_pose_itasc(bItasc *itasc)
+{
+       if (itasc) {
+               itasc->iksolver = IKSOLVER_ITASC;
+               itasc->minstep = 0.01f;
+               itasc->maxstep = 0.06f;
+               itasc->numiter = 100;
+               itasc->numstep = 4;
+               itasc->precision = 0.005f;
+               itasc->flag = ITASC_AUTO_STEP|ITASC_INITIAL_REITERATION|ITASC_SIMULATION;
+               itasc->feedback = 20.f;
+               itasc->maxvel = 50.f;
+               itasc->solver = ITASC_SOLVER_SDLS;
+               itasc->dampmax = 0.5;
+               itasc->dampeps = 0.15;
+       }
+}
+void init_pose_ikparam(bPose *pose)
+{
+       bItasc *itasc;
+       switch (pose->iksolver) {
+       case IKSOLVER_ITASC:
+               itasc = MEM_callocN(sizeof(bItasc), "itasc");
+               init_pose_itasc(itasc);
+               pose->ikparam = itasc;
+               break;
+       case IKSOLVER_LEGACY:
+       default:
+               pose->ikparam = NULL;
+               break;
+       }
+}
+
 void free_pose_channels(bPose *pose) 
 {
        bPoseChannel *pchan;
@@ -507,62 +582,15 @@ void free_pose(bPose *pose)
                /* free pose-groups */
                if (pose->agroups.first)
                        BLI_freelistN(&pose->agroups);
-               
-               /* free pose */
-               MEM_freeN(pose);
-       }
-}
-
-void game_copy_pose(bPose **dst, bPose *src)
-{
-       bPose *out;
-       bPoseChannel *pchan, *outpchan;
-       GHash *ghash;
-       
-       /* the game engine copies the current armature pose and then swaps
-        * the object pose pointer. this makes it possible to change poses
-        * without affecting the original blender data. */
-
-       if (!src) {
-               *dst=NULL;
-               return;
-       }
-       else if (*dst==src) {
-               printf("copy_pose source and target are the same\n");
-               *dst=NULL;
-               return;
-       }
-       
-       out= MEM_dupallocN(src);
-       out->agroups.first= out->agroups.last= NULL;
-       BLI_duplicatelist(&out->chanbase, &src->chanbase);
-
-       /* remap pointers */
-       ghash= BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp);
 
-       pchan= src->chanbase.first;
-       outpchan= out->chanbase.first;
-       for (; pchan; pchan=pchan->next, outpchan=outpchan->next)
-               BLI_ghash_insert(ghash, pchan, outpchan);
+               /* free IK solver state */
+               BIK_clear_data(pose);
 
-       for (pchan=out->chanbase.first; pchan; pchan=pchan->next) {
-               pchan->parent= BLI_ghash_lookup(ghash, pchan->parent);
-               pchan->child= BLI_ghash_lookup(ghash, pchan->child);
-               pchan->path= NULL;
-       }
+               /* free IK solver param */
+               if (pose->ikparam)
+                       MEM_freeN(pose->ikparam);
 
-       BLI_ghash_free(ghash, NULL, NULL);
-       
-       *dst=out;
-}
-
-void game_free_pose(bPose *pose)
-{
-       if (pose) {
-               /* we don't free constraints, those are owned by the original pose */
-               if(pose->chanbase.first)
-                       BLI_freelistN(&pose->chanbase);
-               
+               /* free pose */
                MEM_freeN(pose);
        }
 }
@@ -669,110 +697,146 @@ void framechange_poses_clear_unkeyed(void)
        }
 }
 
-/* ************************ END Pose channels *************** */
-
-/* ************** time ****************** */
+/* ************************** Bone Groups ************************** */
 
-static bActionStrip *get_active_strip(Object *ob)
+/* Adds a new bone-group */
+void pose_add_group (Object *ob)
 {
-#if 0  // XXX old animation system
-       bActionStrip *strip;
+       bPose *pose= (ob) ? ob->pose : NULL;
+       bActionGroup *grp;
        
-       if(ob->action==NULL)
-               return NULL;
-               
-       for (strip=ob->nlastrips.first; strip; strip=strip->next)
-               if(strip->flag & ACTSTRIP_ACTIVE)
-                       break;
+       if (ELEM(NULL, ob, ob->pose))
+               return;
        
-       if(strip && strip->act==ob->action)
-               return strip;
-#endif // XXX old animation system
-               
-       return NULL;
+       grp= MEM_callocN(sizeof(bActionGroup), "PoseGroup");
+       strcpy(grp->name, "Group");
+       BLI_addtail(&pose->agroups, grp);
+       BLI_uniquename(&pose->agroups, grp, "Group", '.', offsetof(bActionGroup, name), 32);
+       
+       pose->active_group= BLI_countlist(&pose->agroups);
 }
 
-/* non clipped mapping of strip */
-static float get_actionstrip_frame(bActionStrip *strip, float cframe, int invert)
+/* Remove the active bone-group */
+void pose_remove_group (Object *ob)
 {
-       float length, actlength, repeat, scale;
-       
-       if (strip->repeat == 0.0f) strip->repeat = 1.0f;
-       repeat = (strip->flag & ACTSTRIP_USESTRIDE) ? (1.0f) : (strip->repeat);
-       
-       if (strip->scale == 0.0f) strip->scale= 1.0f;
-       scale = (float)fabs(strip->scale); /* scale must be positive (for now) */
+       bPose *pose= (ob) ? ob->pose : NULL;
+       bActionGroup *grp = NULL;
+       bPoseChannel *pchan;
        
-       actlength = strip->actend-strip->actstart;
-       if (actlength == 0.0f) actlength = 1.0f;
-       length = repeat * scale * actlength;
+       /* sanity checks */
+       if (ELEM(NULL, ob, pose))
+               return;
+       if (pose->active_group <= 0)
+               return;
        
-       /* invert = convert action-strip time to global time */
-       if (invert)
-               return length*(cframe - strip->actstart)/(repeat*actlength) + strip->start;
-       else
-               return repeat*actlength*(cframe - strip->start)/length + strip->actstart;
+       /* get group to remove */
+       grp= BLI_findlink(&pose->agroups, pose->active_group-1);
+       if (grp) {
+               /* adjust group references (the trouble of using indices!):
+                *      - firstly, make sure nothing references it 
+                *      - also, make sure that those after this item get corrected
+                */
+               for (pchan= pose->chanbase.first; pchan; pchan= pchan->next) {
+                       if (pchan->agrp_index == pose->active_group)
+                               pchan->agrp_index= 0;
+                       else if (pchan->agrp_index > pose->active_group)
+                               pchan->agrp_index--;
+               }
+               
+               /* now, remove it from the pose */
+               BLI_freelinkN(&pose->agroups, grp);
+               pose->active_group= 0;
+       }
 }
 
-/* if the conditions match, it converts current time to strip time */
-float get_action_frame(Object *ob, float cframe)
-{
-       bActionStrip *strip= get_active_strip(ob);
-       
-       if(strip)
-               return get_actionstrip_frame(strip, cframe, 0);
-       return cframe;
-}
+/* ************** F-Curve Utilities for Actions ****************** */
 
-/* inverted, strip time to current time */
-float get_action_frame_inv(Object *ob, float cframe)
+/* Check if the given action has any keyframes */
+short action_has_motion(const bAction *act)
 {
-       bActionStrip *strip= get_active_strip(ob);
+       FCurve *fcu;
+       
+       /* return on the first F-Curve that has some keyframes/samples defined */
+       if (act) {
+               for (fcu= act->curves.first; fcu; fcu= fcu->next) {
+                       if (fcu->totvert)
+                               return 1;
+               }
+       }
        
-       if(strip)
-               return get_actionstrip_frame(strip, cframe, 1);
-       return cframe;
+       /* nothing found */
+       return 0;
 }
 
-
-
-
 /* Calculate the extents of given action */
-void calc_action_range(const bAction *act, float *start, float *end, int incl_hidden)
+void calc_action_range(const bAction *act, float *start, float *end, short incl_modifiers)
 {
-       // FCurve *fcu;
+       FCurve *fcu;
        float min=999999999.0f, max=-999999999.0f;
-       int     foundvert=0;
+       short foundvert=0, foundmod=0;
 
        if (act) {
-#if 0 // XXX old animation system
-               for (chan=act->chanbase.first; chan; chan=chan->next) {
-                       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]);
-                                                       foundvert=1;
+               for (fcu= act->curves.first; fcu; fcu= fcu->next) {
+                       /* if curve has keyframes, consider them first */
+                       if (fcu->totvert) {
+                               float nmin, nmax;
+                               
+                               /* get extents for this curve */
+                               calc_fcurve_range(fcu, &nmin, &nmax);
+                               
+                               /* compare to the running tally */
+                               min= MIN2(min, nmin);
+                               max= MAX2(max, nmax);
+                               
+                               foundvert= 1;
+                       }
+                       
+                       /* if incl_modifiers is enabled, need to consider modifiers too
+                        *      - only really care about the last modifier
+                        */
+                       if ((incl_modifiers) && (fcu->modifiers.last)) {
+                               FModifier *fcm= fcu->modifiers.last;
+                               
+                               /* only use the maximum sensible limits of the modifiers if they are more extreme */
+                               switch (fcm->type) {
+                                       case FMODIFIER_TYPE_LIMITS: /* Limits F-Modifier */
+                                       {
+                                               FMod_Limits *fmd= (FMod_Limits *)fcm->data;
+                                               
+                                               if (fmd->flag & FCM_LIMIT_XMIN) {
+                                                       min= MIN2(min, fmd->rect.xmin);
                                                }
-                                       }
-                               }
-                               for (conchan=chan->constraintChannels.first; conchan; conchan=conchan->next) {
-                                       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]);
-                                                               foundvert=1;
-                                                       }
+                                               if (fmd->flag & FCM_LIMIT_XMAX) {
+                                                       max= MAX2(max, fmd->rect.xmax);
                                                }
                                        }
+                                               break;
+                                               
+                                       case FMODIFIER_TYPE_CYCLES: /* Cycles F-Modifier */
+                                       {
+                                               FMod_Cycles *fmd= (FMod_Cycles *)fcm->data;
+                                               
+                                               if (fmd->before_mode != FCM_EXTRAPOLATE_NONE)
+                                                       min= MINAFRAMEF;
+                                               if (fmd->after_mode != FCM_EXTRAPOLATE_NONE)
+                                                       max= MAXFRAMEF;
+                                       }
+                                               break;
+                                               
+                                       // TODO: function modifier may need some special limits
+                                               
+                                       default: /* all other standard modifiers are on the infinite range... */
+                                               min= MINAFRAMEF;
+                                               max= MAXFRAMEF;
+                                               break;
                                }
+                               
+                               foundmod= 1;
                        }
                }
-#endif // XXX old animation system
        }       
-       if (foundvert) {
+       
+       if (foundvert || foundmod) {
                if(min==max) max+= 1.0f;
                *start= min;
                *end= max;
@@ -783,9 +847,102 @@ void calc_action_range(const bAction *act, float *start, float *end, int incl_hi
        }
 }
 
+/* Return flags indicating which transforms the given object/posechannel has 
+ *     - if 'curves' is provided, a list of links to these curves are also returned
+ */
+short action_get_item_transforms (bAction *act, Object *ob, bPoseChannel *pchan, ListBase *curves)
+{
+       PointerRNA ptr;
+       FCurve *fcu;
+       char *basePath=NULL;
+       short flags=0;
+       
+       /* build PointerRNA from provided data to obtain the paths to use */
+       if (pchan)
+               RNA_pointer_create((ID *)ob, &RNA_PoseChannel, pchan, &ptr);
+       else if (ob)
+               RNA_id_pointer_create((ID *)ob, &ptr);
+       else    
+               return 0;
+               
+       /* get the basic path to the properties of interest */
+       basePath= RNA_path_from_ID_to_struct(&ptr);
+       if (basePath == NULL)
+               return 0;
+               
+       /* search F-Curves for the given properties 
+        *      - we cannot use the groups, since they may not be grouped in that way...
+        */
+       for (fcu= act->curves.first; fcu; fcu= fcu->next) {
+               char *bPtr=NULL, *pPtr=NULL;
+               
+               /* if enough flags have been found, we can stop checking unless we're also getting the curves */
+               if ((flags == ACT_TRANS_ALL) && (curves == NULL))
+                       break;
+                       
+               /* just in case... */
+               if (fcu->rna_path == NULL)
+                       continue;
+               
+               /* step 1: check for matching base path */
+               bPtr= strstr(fcu->rna_path, basePath);
+               
+               if (bPtr) {
+                       /* step 2: check for some property with transforms 
+                        *      - to speed things up, only check for the ones not yet found 
+                        *        unless we're getting the curves too
+                        *      - if we're getting the curves, the BLI_genericNodeN() creates a LinkData
+                        *        node wrapping the F-Curve, which then gets added to the list
+                        *      - once a match has been found, the curve cannot possibly be any other one
+                        */
+                       if ((curves) || (flags & ACT_TRANS_LOC) == 0) {
+                               pPtr= strstr(fcu->rna_path, "location");
+                               if ((pPtr) && (pPtr >= bPtr)) {
+                                       flags |= ACT_TRANS_LOC;
+                                       
+                                       if (curves) 
+                                               BLI_addtail(curves, BLI_genericNodeN(fcu));
+                                       continue;
+                               }
+                       }
+                       
+                       if ((curves) || (flags & ACT_TRANS_SCALE) == 0) {
+                               pPtr= strstr(fcu->rna_path, "scale");
+                               if ((pPtr) && (pPtr >= bPtr)) {
+                                       flags |= ACT_TRANS_SCALE;
+                                       
+                                       if (curves) 
+                                               BLI_addtail(curves, BLI_genericNodeN(fcu));
+                                       continue;
+                               }
+                       }
+                       
+                       if ((curves) || (flags & ACT_TRANS_ROT) == 0) {
+                               pPtr= strstr(fcu->rna_path, "rotation");
+                               if ((pPtr) && (pPtr >= bPtr)) {
+                                       flags |= ACT_TRANS_ROT;
+                                       
+                                       if (curves) 
+                                               BLI_addtail(curves, BLI_genericNodeN(fcu));
+                                       continue;
+                               }
+                       }
+               }
+       }
+       
+       /* free basePath */
+       MEM_freeN(basePath);
+       
+       /* return flags found */
+       return flags;
+}
+
+/* ************** Pose Management Tools ****************** */
+
 /* Copy the data from the action-pose (src) into the pose */
 /* both args are assumed to be valid */
 /* exported to game engine */
+/* Note! this assumes both poses are aligned, this isnt always true when dealing with user poses */
 void extract_pose_from_pose(bPose *pose, const bPose *src)
 {
        const bPoseChannel *schan;
@@ -796,7 +953,7 @@ void extract_pose_from_pose(bPose *pose, const bPose *src)
                return;
        }
 
-       for (schan=src->chanbase.first; schan; schan=schan->next, pchan= pchan->next) {
+       for (schan=src->chanbase.first; (schan && pchan); schan=schan->next, pchan= pchan->next) {
                copy_pose_channel_data(pchan, schan);
        }
 }
@@ -847,9 +1004,11 @@ void copy_pose_result(bPose *to, bPose *from)
                if(pchanto) {
                        Mat4CpyMat4(pchanto->pose_mat, pchanfrom->pose_mat);
                        Mat4CpyMat4(pchanto->chan_mat, pchanfrom->chan_mat);
+                       
                        /* used for local constraints */
                        VECCOPY(pchanto->loc, pchanfrom->loc);
                        QUATCOPY(pchanto->quat, pchanfrom->quat);
+                       VECCOPY(pchanto->eul, pchanfrom->eul);
                        VECCOPY(pchanto->size, pchanfrom->size);
                        
                        VECCOPY(pchanto->pose_head, pchanfrom->pose_head);
@@ -862,13 +1021,12 @@ void copy_pose_result(bPose *to, bPose *from)
 /* For the calculation of the effects of an Action at the given frame on an object 
  * This is currently only used for the Action Constraint 
  */
-void what_does_obaction (Scene *scene, Object *ob, Object *workob, bPose *pose, bAction *act, float cframe)
+void what_does_obaction (Scene *scene, Object *ob, Object *workob, bPose *pose, bAction *act, char groupname[], float cframe)
 {
-       AnimData adt;
+       bActionGroup *agrp= action_groups_find_named(act, groupname);
        
-       /* clear workob and animdata */
+       /* clear workob */
        clear_workob(workob);
-       memset(&adt, 0, sizeof(AnimData));
        
        /* init workob */
        Mat4CpyMat4(workob->obmat, ob->obmat);
@@ -893,14 +1051,30 @@ void what_does_obaction (Scene *scene, Object *ob, Object *workob, bPose *pose,
        strcpy(workob->parsubstr, ob->parsubstr);
        strcpy(workob->id.name, "OB<ConstrWorkOb>"); /* we don't use real object name, otherwise RNA screws with the real thing */
        
-       /* init animdata, and attach to workob */
-       workob->adt= &adt;
-       
-       adt.recalc= ADT_RECALC_ANIM;
-       adt.action= act;
-       
-       /* execute effects of Action on to workob (or it's PoseChannels) */
-       BKE_animsys_evaluate_animdata(&workob->id, &adt, cframe, ADT_RECALC_ANIM);
+       /* if we're given a group to use, it's likely to be more efficient (though a bit more dangerous) */
+       if (agrp) {
+               /* specifically evaluate this group only */
+               PointerRNA id_ptr;
+               
+               /* get RNA-pointer for the workob's ID */
+               RNA_id_pointer_create(&workob->id, &id_ptr);
+               
+               /* execute action for this group only */
+               animsys_evaluate_action_group(&id_ptr, act, agrp, NULL, cframe);
+       }
+       else {
+               AnimData adt;
+               
+               /* init animdata, and attach to workob */
+               memset(&adt, 0, sizeof(AnimData));
+               workob->adt= &adt;
+               
+               adt.recalc= ADT_RECALC_ANIM;
+               adt.action= act;
+               
+               /* execute effects of Action on to workob (or it's PoseChannels) */
+               BKE_animsys_evaluate_animdata(&workob->id, &adt, cframe, ADT_RECALC_ANIM);
+       }
 }
 
 /* ********** NLA with non-poses works with ipo channels ********** */
@@ -1007,75 +1181,6 @@ static void blend_pose_offset_bone(bActionStrip *strip, bPose *dst, bPose *src,
        VecAddf(dst->cyclic_offset, dst->cyclic_offset, src->cyclic_offset);
 }
 
-
-/* Only allowed for Poses with identical channels */
-void blend_poses(bPose *dst, bPose *src, float srcweight, short mode)
-{
-       bPoseChannel *dchan;
-       const bPoseChannel *schan;
-       bConstraint *dcon, *scon;
-       float dstweight;
-       int i;
-       
-       switch (mode){
-       case ACTSTRIPMODE_BLEND:
-               dstweight = 1.0F - srcweight;
-               break;
-       case ACTSTRIPMODE_ADD:
-               dstweight = 1.0F;
-               break;
-       default :
-               dstweight = 1.0F;
-       }
-       
-       schan= src->chanbase.first;
-       for (dchan = dst->chanbase.first; dchan; dchan=dchan->next, schan= schan->next){
-               if (schan->flag & (POSE_ROT|POSE_LOC|POSE_SIZE)) {
-                       /* replaced quat->matrix->quat conversion with decent quaternion interpol (ton) */
-                       
-                       /* Do the transformation blend */
-                       if (schan->flag & POSE_ROT) {
-                               /* quat interpolation done separate */
-                               if (schan->rotmode == PCHAN_ROT_QUAT) {
-                                       float dquat[4], squat[4];
-                                       
-                                       QUATCOPY(dquat, dchan->quat);
-                                       QUATCOPY(squat, schan->quat);
-                                       if (mode==ACTSTRIPMODE_BLEND)
-                                               QuatInterpol(dchan->quat, dquat, squat, srcweight);
-                                       else {
-                                               QuatMulFac(squat, srcweight);
-                                               QuatMul(dchan->quat, dquat, squat);
-                                       }
-                                       
-                                       NormalQuat(dchan->quat);
-                               }
-                       }
-
-                       for (i=0; i<3; i++) {
-                               /* blending for loc and scale are pretty self-explanatory... */
-                               if (schan->flag & POSE_LOC)
-                                       dchan->loc[i] = (dchan->loc[i]*dstweight) + (schan->loc[i]*srcweight);
-                               if (schan->flag & POSE_SIZE)
-                                       dchan->size[i] = 1.0f + ((dchan->size[i]-1.0f)*dstweight) + ((schan->size[i]-1.0f)*srcweight);
-                               
-                               /* euler-rotation interpolation done here instead... */
-                               // FIXME: are these results decent?
-                               if ((schan->flag & POSE_ROT) && (schan->rotmode))
-                                       dchan->eul[i] = (dchan->eul[i]*dstweight) + (schan->eul[i]*srcweight);
-                       }
-                       dchan->flag |= schan->flag;
-               }
-               for(dcon= dchan->constraints.first, scon= schan->constraints.first; dcon && scon; dcon= dcon->next, scon= scon->next) {
-                       /* no 'add' option for constraint blending */
-                       dcon->enforce= dcon->enforce*(1.0f-srcweight) + scon->enforce*srcweight;
-               }
-       }
-       
-       /* this pose is now in src time */
-       dst->ctime= src->ctime;
-}
-
 typedef struct NlaIpoChannel {
        struct NlaIpoChannel *next, *prev;
        float val;
@@ -1083,7 +1188,7 @@ typedef struct NlaIpoChannel {
        int type;
 } NlaIpoChannel;
 
-void extract_ipochannels_from_action(ListBase *lb, ID *id, bAction *act, const char *name, float ctime)
+static void extract_ipochannels_from_action(ListBase *lb, ID *id, bAction *act, const char *name, float ctime)
 {
        bActionChannel *achan= get_action_channel(act, name);
        IpoCurve *icu;
@@ -1176,7 +1281,7 @@ static void blend_ipochannels(ListBase *dst, ListBase *src, float srcweight, int
        }
 }
 
-int execute_ipochannels(ListBase *lb)
+static int execute_ipochannels(ListBase *lb)
 {
        NlaIpoChannel *nic;
        int count = 0;