Cycles: svn merge -r39870:r40266 https://svn.blender.org/svnroot/bf-blender/trunk...
[blender-staging.git] / source / blender / blenkernel / intern / key.c
index a3c8ea0c194556b725779a8a941124dd17bc6899..2aef5b39c71866112d4706cb090d37b8a78c0b2b 100644 (file)
  * ***** END GPL LICENSE BLOCK *****
  */
 
+/** \file blender/blenkernel/intern/key.c
+ *  \ingroup bke
+ */
+
+
 #include <math.h>
 #include <string.h>
 #include <stddef.h>
@@ -58,6 +63,7 @@
 #include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_object.h"
+#include "BKE_deform.h"
 
 
 #include "RNA_access.h"
@@ -150,7 +156,7 @@ Key *copy_key(Key *key)
        Key *keyn;
        KeyBlock *kbn, *kb;
        
-       if(key==0) return 0;
+       if(key==NULL) return NULL;
        
        keyn= copy_libblock(key);
        
@@ -177,10 +183,10 @@ void make_local_key(Key *key)
        * - only local users: set flag
        * - mixed: make copy
        */
-       if(key==0) return;
+       if(key==NULL) return;
        
-       key->id.lib= 0;
-       new_id(0, (ID *)key, 0);
+       key->id.lib= NULL;
+       new_id(NULL, (ID *)key, NULL);
 }
 
 /* Sort shape keys and Ipo curves after a change.  This assumes that at most
@@ -365,14 +371,14 @@ static int setkeys(float fac, ListBase *lb, KeyBlock *k[], float *t, int cycl)
 
        /* if(fac<0.0 || fac>1.0) return 1; */
 
-       if(k1->next==0) return 1;
+       if(k1->next==NULL) return 1;
 
        if(cycl) {      /* pre-sort */
                k[2]= k1->next;
                k[3]= k[2]->next;
-               if(k[3]==0) k[3]=k1;
+               if(k[3]==NULL) k[3]=k1;
                while(k1) {
-                       if(k1->next==0) k[0]=k1;
+                       if(k1->next==NULL) k[0]=k1;
                        k1=k1->next;
                }
                k1= k[1];
@@ -393,13 +399,13 @@ static int setkeys(float fac, ListBase *lb, KeyBlock *k[], float *t, int cycl)
                k[2]= k1->next;
                t[2]= k[2]->pos;
                k[3]= k[2]->next;
-               if(k[3]==0) k[3]= k[2];
+               if(k[3]==NULL) k[3]= k[2];
                t[3]= k[3]->pos;
                k1= k[3];
        }
        
        while( t[2]<fac ) {     /* find correct location */
-               if(k1->next==0) {
+               if(k1->next==NULL) {
                        if(cycl) {
                                k1= firstkey;
                                ofs+= dpos;
@@ -417,7 +423,7 @@ static int setkeys(float fac, ListBase *lb, KeyBlock *k[], float *t, int cycl)
                t[3]= k1->pos+ofs; 
                k[3]= k1;
 
-               if(ofs>2.1+lastpos) break;
+               if(ofs > 2.1f + lastpos) break;
        }
        
        bsplinetype= 0;
@@ -443,7 +449,7 @@ static int setkeys(float fac, ListBase *lb, KeyBlock *k[], float *t, int cycl)
        }
 
        d= t[2]-t[1];
-       if(d==0.0) {
+       if(d == 0.0f) {
                if(bsplinetype==0) {
                        return 1;       /* both keys equal */
                }
@@ -468,20 +474,20 @@ static int setkeys(float fac, ListBase *lb, KeyBlock *k[], float *t, int cycl)
 
 }
 
-static void flerp(int aantal, float *in, float *f0, float *f1, float *f2, float *f3, float *t) 
+static void flerp(int tot, float *in, float *f0, float *f1, float *f2, float *f3, float *t)
 {
        int a;
 
-       for(a=0; a<aantal; a++) {
+       for(a=0; a<tot; a++) {
                in[a]= t[0]*f0[a]+t[1]*f1[a]+t[2]*f2[a]+t[3]*f3[a];
        }
 }
 
-static void rel_flerp(int aantal, float *in, float *ref, float *out, float fac)
+static void rel_flerp(int tot, float *in, float *ref, float *out, float fac)
 {
        int a;
        
-       for(a=0; a<aantal; a++) {
+       for(a=0; a<tot; a++) {
                in[a]-= fac*(ref[a]-out[a]);
        }
 }
@@ -644,8 +650,8 @@ static void cp_key(const int start, int end, const int tot, char *poin, Key *key
                /* are we going to be nasty? */
                if(flagflo) {
                        ktot+= kd;
-                       while(ktot>=1.0) {
-                               ktot-= 1.0;
+                       while(ktot >= 1.0f) {
+                               ktot -= 1.0f;
                                k1+= elemsize;
                                kref+= elemsize;
                        }
@@ -948,8 +954,8 @@ static void do_key(const int start, int end, const int tot, char *poin, Key *key
                if(flagdo & 1) {
                        if(flagflo & 1) {
                                k1tot+= k1d;
-                               while(k1tot>=1.0) {
-                                       k1tot-= 1.0;
+                               while(k1tot >= 1.0f) {
+                                       k1tot -= 1.0f;
                                        k1+= elemsize;
                                }
                        }
@@ -958,8 +964,8 @@ static void do_key(const int start, int end, const int tot, char *poin, Key *key
                if(flagdo & 2) {
                        if(flagflo & 2) {
                                k2tot+= k2d;
-                               while(k2tot>=1.0) {
-                                       k2tot-= 1.0;
+                               while(k2tot >= 1.0f) {
+                                       k2tot -= 1.0f;
                                        k2+= elemsize;
                                }
                        }
@@ -968,8 +974,8 @@ static void do_key(const int start, int end, const int tot, char *poin, Key *key
                if(flagdo & 4) {
                        if(flagflo & 4) {
                                k3tot+= k3d;
-                               while(k3tot>=1.0) {
-                                       k3tot-= 1.0;
+                               while(k3tot >= 1.0f) {
+                                       k3tot -= 1.0f;
                                        k3+= elemsize;
                                }
                        }
@@ -978,8 +984,8 @@ static void do_key(const int start, int end, const int tot, char *poin, Key *key
                if(flagdo & 8) {
                        if(flagflo & 8) {
                                k4tot+= k4d;
-                               while(k4tot>=1.0) {
-                                       k4tot-= 1.0;
+                               while(k4tot >= 1.0f) {
+                                       k4tot -= 1.0f;
                                        k4+= elemsize;
                                }
                        }
@@ -1000,7 +1006,7 @@ static float *get_weights_array(Object *ob, char *vgroup)
        MDeformVert *dvert= NULL;
        EditMesh *em= NULL;
        EditVert *eve;
-       int totvert= 0, index= 0;
+       int totvert= 0, defgrp_index= 0;
        
        /* no vgroup string set? */
        if(vgroup[0]==0) return NULL;
@@ -1023,10 +1029,10 @@ static float *get_weights_array(Object *ob, char *vgroup)
        if(dvert==NULL) return NULL;
        
        /* find the group (weak loop-in-loop) */
-       index= defgroup_name_index(ob, vgroup);
-       if(index >= 0) {
+       defgrp_index= defgroup_name_index(ob, vgroup);
+       if(defgrp_index >= 0) {
                float *weights;
-               int i, j;
+               int i;
                
                weights= MEM_callocN(totvert*sizeof(float), "weights");
 
@@ -1035,23 +1041,13 @@ static float *get_weights_array(Object *ob, char *vgroup)
                                dvert= CustomData_em_get(&em->vdata, eve->data, CD_MDEFORMVERT);
 
                                if(dvert) {
-                                       for(j=0; j<dvert->totweight; j++) {
-                                               if(dvert->dw[j].def_nr == index) {
-                                                       weights[i]= dvert->dw[j].weight;
-                                                       break;
-                                               }
-                                       }
+                                       weights[i]= defvert_find_weight(dvert, defgrp_index);
                                }
                        }
                }
                else {
                        for(i=0; i < totvert; i++, dvert++) {
-                               for(j=0; j<dvert->totweight; j++) {
-                                       if(dvert->dw[j].def_nr == index) {
-                                               weights[i]= dvert->dw[j].weight;
-                                               break;
-                                       }
-                               }
+                               weights[i]= defvert_find_weight(dvert, defgrp_index);
                        }
                }
 
@@ -1081,7 +1077,7 @@ static void do_mesh_key(Scene *scene, Object *ob, Key *key, char *out, const int
                
                for(a=0; a<tot; a+=step, cfra+= delta) {
                        
-                       ctime= bsystem_time(scene, 0, cfra, 0.0); // xxx  ugly cruft!
+                       ctime= bsystem_time(scene, NULL, cfra, 0.0); // xxx  ugly cruft!
 #if 0 // XXX old animation system
                        if(calc_ipo_spec(key->ipo, KEY_SPEED, &ctime)==0) {
                                ctime /= 100.0;
@@ -1213,7 +1209,7 @@ static void do_curve_key(Scene *scene, Object *ob, Key *key, char *out, const in
                        while (a < estep) {
                                if (remain <= 0) {
                                        cfra+= delta;
-                                       ctime= bsystem_time(scene, 0, cfra, 0.0f); // XXX old cruft
+                                       ctime= bsystem_time(scene, NULL, cfra, 0.0f); // XXX old cruft
 
                                        ctime /= 100.0f;
                                        CLAMP(ctime, 0.0f, 1.0f); // XXX for compat, we use this, but this clamping was confusing
@@ -1276,7 +1272,7 @@ static void do_latt_key(Scene *scene, Object *ob, Key *key, char *out, const int
                
                for(a=0; a<tot; a++, cfra+= delta) {
                        
-                       ctime= bsystem_time(scene, 0, cfra, 0.0); // XXX old cruft
+                       ctime= bsystem_time(scene, NULL, cfra, 0.0); // XXX old cruft
 #if 0 // XXX old animation system
                        if(calc_ipo_spec(key->ipo, KEY_SPEED, &ctime)==0) {
                                ctime /= 100.0;
@@ -1404,7 +1400,7 @@ float *do_ob_key(Scene *scene, Object *ob)
                /* do shapekey local drivers */
                float ctime= (float)scene->r.cfra; // XXX this needs to be checked
                
-               BKE_animsys_evaluate_animdata(&key->id, key->adt, ctime, ADT_RECALC_DRIVERS);
+               BKE_animsys_evaluate_animdata(scene, &key->id, key->adt, ctime, ADT_RECALC_DRIVERS);
                
                if(ob->type==OB_MESH) do_mesh_key(scene, ob, key, out, tot);
                else if(ob->type==OB_LATTICE) do_latt_key(scene, ob, key, out, tot);
@@ -1468,7 +1464,7 @@ KeyBlock *add_keyblock(Key *key, const char *name)
        
        // XXX kb->pos is the confusing old horizontal-line RVK crap in old IPO Editor...
        if(key->type == KEY_RELATIVE) 
-               kb->pos= curpos+0.1;
+               kb->pos= curpos + 0.1f;
        else {
 #if 0 // XXX old animation system
                curpos= bsystem_time(scene, 0, (float)CFRA, 0.0);