Animato - More compatability work
authorJoshua Leung <aligorith@gmail.com>
Fri, 23 Jan 2009 23:11:12 +0000 (23:11 +0000)
committerJoshua Leung <aligorith@gmail.com>
Fri, 23 Jan 2009 23:11:12 +0000 (23:11 +0000)
* Absolute shapekeys work again. For now, the 'speed' curve isn't converted yet (same goes for 'Curves'). Those were kindof hacky, since they manipulated time in weird ways. Probably the clamping to 0.0-1.0 range can go though.

* Materials, Textures, Cameras, and local-constraint IPO's are now converted properly to the new system

source/blender/blenkernel/intern/ipo.c
source/blender/blenkernel/intern/key.c

index 6706bd8b8bfeda83ede5467aed820a1476ec515c..38b423430d18f2ca2e28722e2fed594c5572c80c 100644 (file)
@@ -344,6 +344,105 @@ static char *texture_adrcodes_to_paths (int adrcode, int *array_index)
        return NULL;
 }
 
+/* Material Types */
+static char *material_adrcodes_to_paths (int adrcode, int *array_index)
+{
+       /* set array index like this in-case nothing sets it correctly  */
+       *array_index= 0;
+       
+       /* result depends on adrcode */
+       switch (adrcode) {
+               case MA_COL_R:
+                       *array_index= 0; return "diffuse_color";
+               case MA_COL_G:
+                       *array_index= 1; return "diffuse_color";
+               case MA_COL_B:
+                       *array_index= 2; return "diffuse_color";
+                       
+               case MA_SPEC_R:
+                       *array_index= 0; return "specular_color";
+               case MA_SPEC_G:
+                       *array_index= 1; return "specular_color";
+               case MA_SPEC_B:
+                       *array_index= 2; return "specular_color";
+                       
+               case MA_MIR_R:
+                       *array_index= 0; return "mirror_color";
+               case MA_MIR_G:
+                       *array_index= 1; return "mirror_color";
+               case MA_MIR_B:
+                       *array_index= 2; return "mirror_color";
+                       
+               case MA_ALPHA:
+                       return "alpha";
+                       
+               case MA_REF:
+                       return "diffuse_reflection";
+                       
+               // XXX add other types...
+       }
+       
+       return NULL;
+       
+#if 0
+       case MA_EMIT:
+               poin= &(ma->emit); break;
+       case MA_AMB:
+               poin= &(ma->amb); break;
+       case MA_SPEC:
+               poin= &(ma->spec); break;
+       case MA_HARD:
+               poin= &(ma->har); *type= IPO_SHORT; break;
+       case MA_SPTR:
+               poin= &(ma->spectra); break;
+       case MA_IOR:
+               poin= &(ma->ang); break;
+       case MA_MODE:
+               poin= &(ma->mode); *type= IPO_INT_BIT; break; // evil... dumping bitflags directly to user!
+       case MA_HASIZE:
+               poin= &(ma->hasize); break;
+       case MA_TRANSLU:
+               poin= &(ma->translucency); break;
+       case MA_RAYM:
+               poin= &(ma->ray_mirror); break;
+       case MA_FRESMIR:
+               poin= &(ma->fresnel_mir); break;
+       case MA_FRESMIRI:
+               poin= &(ma->fresnel_mir_i); break;
+       case MA_FRESTRA:
+               poin= &(ma->fresnel_tra); break;
+       case MA_FRESTRAI:
+               poin= &(ma->fresnel_tra_i); break;
+       case MA_ADD:
+               poin= &(ma->add); break;
+       
+       if (poin == NULL) {
+               if (icu->adrcode & MA_MAP1) mtex= ma->mtex[0];
+               else if (icu->adrcode & MA_MAP2) mtex= ma->mtex[1];
+               else if (icu->adrcode & MA_MAP3) mtex= ma->mtex[2];
+               else if (icu->adrcode & MA_MAP4) mtex= ma->mtex[3];
+               else if (icu->adrcode & MA_MAP5) mtex= ma->mtex[4];
+               else if (icu->adrcode & MA_MAP6) mtex= ma->mtex[5];
+               else if (icu->adrcode & MA_MAP7) mtex= ma->mtex[6];
+               else if (icu->adrcode & MA_MAP8) mtex= ma->mtex[7];
+               else if (icu->adrcode & MA_MAP9) mtex= ma->mtex[8];
+               else if (icu->adrcode & MA_MAP10) mtex= ma->mtex[9];
+               else if (icu->adrcode & MA_MAP12) mtex= ma->mtex[11];
+               else if (icu->adrcode & MA_MAP11) mtex= ma->mtex[10];
+               else if (icu->adrcode & MA_MAP13) mtex= ma->mtex[12];
+               else if (icu->adrcode & MA_MAP14) mtex= ma->mtex[13];
+               else if (icu->adrcode & MA_MAP15) mtex= ma->mtex[14];
+               else if (icu->adrcode & MA_MAP16) mtex= ma->mtex[15];
+               else if (icu->adrcode & MA_MAP17) mtex= ma->mtex[16];
+               else if (icu->adrcode & MA_MAP18) mtex= ma->mtex[17];
+               
+               if (mtex)
+                       poin= give_mtex_poin(mtex, (icu->adrcode & (MA_MAP1-1)));
+       }
+#endif
+       
+}
+
 /* Camera Types */
 static char *camera_adrcodes_to_paths (int adrcode, int *array_index)
 {
@@ -414,20 +513,24 @@ char *get_rna_access (int blocktype, int adrcode, char actname[], char constname
                        propname= shapekey_adrcodes_to_paths(adrcode, &dummy_index);
                        break;
                        
-               case ID_TE: /* textures */
+               case ID_TE: /* texture */
                        propname= texture_adrcodes_to_paths(adrcode, &dummy_index);
                        break;
                        
-               case ID_CA:
+               case ID_MA: /* material */
+                       propname= material_adrcodes_to_paths(adrcode, &dummy_index);
+                       break;
+                       
+               case ID_CA: /* camera */
                        propname= camera_adrcodes_to_paths(adrcode, &dummy_index);
                        break;
                        
                /* XXX problematic blocktypes */
-               case ID_CU:
+               case ID_CU: /* curve */
                        propname= "speed"; // XXX this was a 'dummy curve' that didn't really correspond to any real var...
                        break;
                        
-               case ID_SEQ:
+               case ID_SEQ: /* sequencer strip */
                        //SEQ_FAC1:
                        //      poin= &(seq->facf0); // XXX this doesn't seem to be included anywhere in sequencer RNA...
                        break;
@@ -898,6 +1001,14 @@ void do_versions_ipos_to_animato(Main *main)
                                        /* if constraint has own IPO, convert add these to Object 
                                         * (NOTE: they're most likely to be drivers too) 
                                         */
+                                       if (con->ipo) {
+                                               /* although this was the constraint's local IPO, we still need to provide pchan + con 
+                                                * so that drivers can be added properly...
+                                                */
+                                               ipo_to_animdata(id, con->ipo, pchan->name, con->name);
+                                               con->ipo->id.us--;
+                                               con->ipo= NULL;
+                                       }
                                         
                                        /* check for Action Constraint */
                                        // XXX do we really want to do this here?
@@ -905,6 +1016,24 @@ void do_versions_ipos_to_animato(Main *main)
                        }
                }
                
+               /* check constraints for local IPO's */
+               for (con= ob->constraints.first; con; con= con->next) {
+                       /* if constraint has own IPO, convert add these to Object 
+                        * (NOTE: they're most likely to be drivers too) 
+                        */
+                       if (con->ipo) {
+                               /* although this was the constraint's local IPO, we still need to provide con 
+                                * so that drivers can be added properly...
+                                */
+                               ipo_to_animdata(id, con->ipo, NULL, con->name);
+                               con->ipo->id.us--;
+                               con->ipo= NULL;
+                       }
+                        
+                       /* check for Action Constraint */
+                       // XXX do we really want to do this here?
+               }
+               
                /* check constraint channels - we need to remove them anyway... */
                for (conchan= ob->constraintChannels.first; conchan; conchan= conchann) {
                        /* get pointer to next Constraint Channel */
@@ -943,6 +1072,60 @@ void do_versions_ipos_to_animato(Main *main)
                }
        }
        
+       /* materials */
+       for (id= main->mat.first; id; id= id->next) {
+               Material *ma= (Material *)id;
+               
+               printf("\tconverting material %s \n", id->name+2);
+               
+               /* we're only interested in the IPO */
+               if (ma->ipo) {
+                       /* Add AnimData block */
+                       adt= BKE_id_add_animdata(id);
+                       
+                       /* Convert Material data... */
+                       ipo_to_animdata(id, ma->ipo, NULL, NULL);
+                       ma->ipo->id.us--;
+                       ma->ipo= NULL;
+               }
+       }
+       
+       /* textures */
+       for (id= main->tex.first; id; id= id->next) {
+               Tex *te= (Tex *)id;
+               
+               printf("\tconverting texture %s \n", id->name+2);
+               
+               /* we're only interested in the IPO */
+               if (te->ipo) {
+                       /* Add AnimData block */
+                       adt= BKE_id_add_animdata(id);
+                       
+                       /* Convert Texture data... */
+                       ipo_to_animdata(id, te->ipo, NULL, NULL);
+                       te->ipo->id.us--;
+                       te->ipo= NULL;
+               }
+       }
+       
+       /* cameras */
+       for (id= main->camera.first; id; id= id->next) {
+               Camera *ca= (Camera *)id;
+               
+               printf("\tconverting camera %s \n", id->name+2);
+               
+               /* we're only interested in the IPO */
+               if (ca->ipo) {
+                       /* Add AnimData block */
+                       adt= BKE_id_add_animdata(id);
+                       
+                       /* Convert Camera data... */
+                       ipo_to_animdata(id, ca->ipo, NULL, NULL);
+                       ca->ipo->id.us--;
+                       ca->ipo= NULL;
+               }
+       }
+       
        // XXX add other types too...
        
        printf("INFO: animato convert done \n"); // xxx debug
@@ -1027,90 +1210,6 @@ void *get_ipo_poin (ID *id, IpoCurve *icu, int *type)
 
        /* data is divided into 'blocktypes' based on ID-codes */
        switch (GS(id->name)) {
-               case ID_MA: /* material channels -----------------------------  */
-               {
-                       Material *ma= (Material *)id;
-                       
-                       switch (icu->adrcode) {
-                       case MA_COL_R:
-                               poin= &(ma->r); break;
-                       case MA_COL_G:
-                               poin= &(ma->g); break;
-                       case MA_COL_B:
-                               poin= &(ma->b); break;
-                       case MA_SPEC_R:
-                               poin= &(ma->specr); break;
-                       case MA_SPEC_G:
-                               poin= &(ma->specg); break;
-                       case MA_SPEC_B:
-                               poin= &(ma->specb); break;
-                       case MA_MIR_R:
-                               poin= &(ma->mirr); break;
-                       case MA_MIR_G:
-                               poin= &(ma->mirg); break;
-                       case MA_MIR_B:
-                               poin= &(ma->mirb); break;
-                       case MA_REF:
-                               poin= &(ma->ref); break;
-                       case MA_ALPHA:
-                               poin= &(ma->alpha); break;
-                       case MA_EMIT:
-                               poin= &(ma->emit); break;
-                       case MA_AMB:
-                               poin= &(ma->amb); break;
-                       case MA_SPEC:
-                               poin= &(ma->spec); break;
-                       case MA_HARD:
-                               poin= &(ma->har); *type= IPO_SHORT; break;
-                       case MA_SPTR:
-                               poin= &(ma->spectra); break;
-                       case MA_IOR:
-                               poin= &(ma->ang); break;
-                       case MA_MODE:
-                               poin= &(ma->mode); *type= IPO_INT_BIT; break; // evil... dumping bitflags directly to user!
-                       case MA_HASIZE:
-                               poin= &(ma->hasize); break;
-                       case MA_TRANSLU:
-                               poin= &(ma->translucency); break;
-                       case MA_RAYM:
-                               poin= &(ma->ray_mirror); break;
-                       case MA_FRESMIR:
-                               poin= &(ma->fresnel_mir); break;
-                       case MA_FRESMIRI:
-                               poin= &(ma->fresnel_mir_i); break;
-                       case MA_FRESTRA:
-                               poin= &(ma->fresnel_tra); break;
-                       case MA_FRESTRAI:
-                               poin= &(ma->fresnel_tra_i); break;
-                       case MA_ADD:
-                               poin= &(ma->add); break;
-                       }
-                       
-                       if (poin == NULL) {
-                               if (icu->adrcode & MA_MAP1) mtex= ma->mtex[0];
-                               else if (icu->adrcode & MA_MAP2) mtex= ma->mtex[1];
-                               else if (icu->adrcode & MA_MAP3) mtex= ma->mtex[2];
-                               else if (icu->adrcode & MA_MAP4) mtex= ma->mtex[3];
-                               else if (icu->adrcode & MA_MAP5) mtex= ma->mtex[4];
-                               else if (icu->adrcode & MA_MAP6) mtex= ma->mtex[5];
-                               else if (icu->adrcode & MA_MAP7) mtex= ma->mtex[6];
-                               else if (icu->adrcode & MA_MAP8) mtex= ma->mtex[7];
-                               else if (icu->adrcode & MA_MAP9) mtex= ma->mtex[8];
-                               else if (icu->adrcode & MA_MAP10) mtex= ma->mtex[9];
-                               else if (icu->adrcode & MA_MAP12) mtex= ma->mtex[11];
-                               else if (icu->adrcode & MA_MAP11) mtex= ma->mtex[10];
-                               else if (icu->adrcode & MA_MAP13) mtex= ma->mtex[12];
-                               else if (icu->adrcode & MA_MAP14) mtex= ma->mtex[13];
-                               else if (icu->adrcode & MA_MAP15) mtex= ma->mtex[14];
-                               else if (icu->adrcode & MA_MAP16) mtex= ma->mtex[15];
-                               else if (icu->adrcode & MA_MAP17) mtex= ma->mtex[16];
-                               else if (icu->adrcode & MA_MAP18) mtex= ma->mtex[17];
-                               
-                               if (mtex)
-                                       poin= give_mtex_poin(mtex, (icu->adrcode & (MA_MAP1-1)));
-                       }
-               }
-                       break;
                case ID_WO: /* world channels -----------------------------  */
                {
                        World *wo= (World *)id;
index 8c5bac3019e8def23cf704c34a268b0e5618e120..27f91c2f2ae69b380310ea40708441c2ae86d805 100644 (file)
@@ -646,6 +646,8 @@ void do_rel_key(int start, int end, int tot, char *basispoin, Key *key, int mode
        
        if(key->from==NULL) return;
        
+       printf("do_rel_key() \n");
+       
        if( GS(key->from->name)==ID_ME ) {
                ofs[0]= sizeof(MVert);
                ofs[1]= 0;
@@ -681,11 +683,15 @@ void do_rel_key(int start, int end, int tot, char *basispoin, Key *key, int mode
                if(kb!=key->refkey) {
                        float icuval= kb->curval;
                        
+                       printf("\tdo rel key %s : %s = %f \n", key->id.name+2, kb->name, icuval);
+                       
                        /* only with value, and no difference allowed */
                        if(!(kb->flag & KEYBLOCK_MUTE) && icuval!=0.0f && kb->totelem==tot) {
                                KeyBlock *refb;
                                float weight, *weights= kb->weights;
                                
+                               printf("\t\tnot skipped \n");
+                               
                                poin= basispoin;
                                from= kb->data;
                                /* reference now can be any block */
@@ -756,6 +762,8 @@ static void do_key(int start, int end, int tot, char *poin, Key *key, KeyBlock *
 
        if(key->from==0) return;
 
+       printf("do_key() \n");
+       
        if( GS(key->from->name)==ID_ME ) {
                ofs[0]= sizeof(MVert);
                ofs[1]= 0;
@@ -1016,7 +1024,11 @@ static int do_mesh_key(Scene *scene, Object *ob, Mesh *me)
        /* prevent python from screwing this up? anyhoo, the from pointer could be dropped */
        me->key->from= (ID *)me;
        
+       printf("do mesh key ob:%s me:%s ke:%s \n", ob->id.name+2, me->id.name+2, me->key->id.name+2);
+       
        if(me->key->slurph && me->key->type!=KEY_RELATIVE ) {
+               printf("\tslurph key\n");
+               
                delta= me->key->slurph;
                delta/= me->totvert;
                
@@ -1038,6 +1050,9 @@ static int do_mesh_key(Scene *scene, Object *ob, Mesh *me)
                                CLAMP(ctime, 0.0, 1.0);
                        }
 #endif // XXX old animation system
+                       // XXX for now... since speed curve cannot be directly ported yet
+                       ctime /= 100.0f;
+                       CLAMP(ctime, 0.0f, 1.0f); // XXX for compat, we use this, but this clamping was confusing
                
                        flag= setkeys(ctime, &me->key->block, k, t, 0);
                        if(flag==0) {
@@ -1053,10 +1068,11 @@ static int do_mesh_key(Scene *scene, Object *ob, Mesh *me)
                else boundbox_mesh(me, loc, size);
        }
        else {
-               
                if(me->key->type==KEY_RELATIVE) {
                        KeyBlock *kb;
                        
+                       printf("\tdo relative \n");
+                       
                        for(kb= me->key->block.first; kb; kb= kb->next)
                                kb->weights= get_weights_array(ob, kb->vgroup);
 
@@ -1068,6 +1084,8 @@ static int do_mesh_key(Scene *scene, Object *ob, Mesh *me)
                        }
                }
                else {
+                       printf("\tdo absolute \n");
+                       
                        ctime= bsystem_time(scene, ob, scene->r.cfra, 0.0); // xxx old cruft
                        
 #if 0 // XXX old animation system
@@ -1076,6 +1094,9 @@ static int do_mesh_key(Scene *scene, Object *ob, Mesh *me)
                                CLAMP(ctime, 0.0, 1.0);
                        }
 #endif // XXX old animation system
+                       // XXX for now... since speed curve cannot be directly ported yet
+                       ctime /= 100.0f;
+                       CLAMP(ctime, 0.0f, 1.0f); // XXX for compat, we use this, but this clamping was confusing
                        
                        flag= setkeys(ctime, &me->key->block, k, t, 0);
                        if(flag==0) {
@@ -1324,7 +1345,9 @@ int do_ob_key(Scene *scene, Object *ob)
                
        if(ob->shapeflag & (OB_SHAPE_LOCK|OB_SHAPE_TEMPLOCK)) {
                KeyBlock *kb= BLI_findlink(&key->block, ob->shapenr-1);
-
+               
+               printf("ob %s, key %s locked \n", ob->id.name+2, key->id.name+2);
+               
                if(kb && (kb->flag & KEYBLOCK_MUTE))
                        kb= key->refkey;
 
@@ -1370,7 +1393,7 @@ int do_ob_key(Scene *scene, Object *ob)
 #endif // XXX old animation system
                /* do shapekey local drivers */
                float ctime= (float)scene->r.cfra; // XXX this needs to be checked
-               printf("ob %s - do shapekey drivers \n", ob->id.name+2);
+               printf("ob %s - do shapekey (%s) drivers \n", ob->id.name+2, key->id.name+2);
                BKE_animsys_evaluate_animdata(&key->id, key->adt, ctime, ADT_RECALC_DRIVERS);
                
                if(ob->type==OB_MESH) return do_mesh_key(scene, ob, ob->data);