diff options
Diffstat (limited to 'source/blender/blenkernel/intern/key.c')
-rw-r--r-- | source/blender/blenkernel/intern/key.c | 156 |
1 files changed, 110 insertions, 46 deletions
diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index 755a41ec4b2..595ba37e09c 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -35,8 +35,8 @@ #include "MEM_guardedalloc.h" +#include "DNA_anim_types.h" #include "DNA_curve_types.h" -#include "DNA_ipo_types.h" #include "DNA_key_types.h" #include "DNA_lattice_types.h" #include "DNA_mesh_types.h" @@ -44,12 +44,11 @@ #include "DNA_object_types.h" #include "DNA_scene_types.h" +#include "BKE_animsys.h" #include "BKE_action.h" -#include "BKE_bad_level_calls.h" #include "BKE_blender.h" #include "BKE_curve.h" #include "BKE_global.h" -#include "BKE_ipo.h" #include "BKE_key.h" #include "BKE_lattice.h" #include "BKE_library.h" @@ -60,7 +59,6 @@ #include "BLI_blenlib.h" -#include "blendef.h" #ifdef HAVE_CONFIG_H #include <config.h> @@ -69,6 +67,11 @@ #define KEY_BPOINT 1 #define KEY_BEZTRIPLE 2 + // old defines from DNA_ipo_types.h for data-type +#define IPO_FLOAT 4 +#define IPO_BEZTRIPLE 100 +#define IPO_BPOINT 101 + int slurph_opt= 1; @@ -76,8 +79,7 @@ void free_key(Key *key) { KeyBlock *kb; - if(key->ipo) key->ipo->id.us--; - + BKE_free_animdata((ID *)key); while( (kb= key->block.first) ) { @@ -112,6 +114,7 @@ Key *add_key(ID *id) /* common function */ key->type= KEY_NORMAL; key->from= id; + // XXX the code here uses some defines which will soon be depreceated... if( GS(id->name)==ID_ME) { el= key->elemstr; @@ -152,9 +155,11 @@ Key *copy_key(Key *key) keyn= copy_libblock(key); +#if 0 // XXX old animation system keyn->ipo= copy_ipo(key->ipo); - - duplicatelist(&keyn->block, &key->block); +#endif // XXX old animation system + + BLI_duplicatelist(&keyn->block, &key->block); kb= key->block.first; kbn= keyn->block.first; @@ -181,11 +186,13 @@ void make_local_key(Key *key) key->id.lib= 0; new_id(0, (ID *)key, 0); + +#if 0 // XXX old animation system make_local_ipo(key->ipo); +#endif // XXX old animation system } -/* - * Sort shape keys and Ipo curves after a change. This assumes that at most +/* Sort shape keys and Ipo curves after a change. This assumes that at most * one key was moved, which is a valid assumption for the places it's * currently being called. */ @@ -193,30 +200,30 @@ void make_local_key(Key *key) void sort_keys(Key *key) { KeyBlock *kb; - short i, adrcode; - IpoCurve *icu = NULL; + //short i, adrcode; + //IpoCurve *icu = NULL; KeyBlock *kb2; /* locate the key which is out of position */ - for( kb= key->block.first; kb; kb= kb->next ) - if( kb->next && kb->pos > kb->next->pos ) + for (kb= key->block.first; kb; kb= kb->next) + if ((kb->next) && (kb->pos > kb->next->pos)) break; /* if we find a key, move it */ - if( kb ) { + if (kb) { kb = kb->next; /* next key is the out-of-order one */ BLI_remlink(&key->block, kb); - + /* find the right location and insert before */ - for( kb2=key->block.first; kb2; kb2= kb2->next ) { - if( kb2->pos > kb->pos ) { + for (kb2=key->block.first; kb2; kb2= kb2->next) { + if (kb2->pos > kb->pos) { BLI_insertlink(&key->block, kb2->prev, kb); break; } } - + /* if more than one Ipo curve, see if this key had a curve */ - +#if 0 // XXX old animation system if(key->ipo && key->ipo->curve.first != key->ipo->curve.last ) { for(icu= key->ipo->curve.first; icu; icu= icu->next) { /* if we find the curve, remove it and reinsert in the @@ -234,13 +241,13 @@ void sort_keys(Key *key) } } } - + /* kb points at the moved key, icu at the moved ipo (if it exists). * go back now and renumber adrcodes */ /* first new code */ adrcode = kb2->adrcode; - for( i = kb->adrcode - adrcode; i >= 0; --i, ++adrcode ) { + for (i = kb->adrcode - adrcode; i >= 0; i--, adrcode++) { /* if the next ipo curve matches the current key, renumber it */ if(icu && icu->adrcode == kb->adrcode ) { icu->adrcode = adrcode; @@ -250,6 +257,7 @@ void sort_keys(Key *key) kb->adrcode = adrcode; kb = kb->next; } +#endif // XXX old animation system } /* new rule; first key is refkey, this to match drawing channels... */ @@ -638,6 +646,8 @@ void do_rel_key(int start, int end, int tot, char *basispoin, Key *key, int mode if(key->from==NULL) return; + if (G.f & G_DEBUG) printf("do_rel_key() \n"); + if( GS(key->from->name)==ID_ME ) { ofs[0]= sizeof(MVert); ofs[1]= 0; @@ -673,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; + if (G.f & G_DEBUG) 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; + if (G.f & G_DEBUG) printf("\t\tnot skipped \n"); + poin= basispoin; from= kb->data; /* reference now can be any block */ @@ -748,6 +762,8 @@ static void do_key(int start, int end, int tot, char *poin, Key *key, KeyBlock * if(key->from==0) return; + if (G.f & G_DEBUG) printf("do_key() \n"); + if( GS(key->from->name)==ID_ME ) { ofs[0]= sizeof(MVert); ofs[1]= 0; @@ -995,7 +1011,7 @@ static float *get_weights_array(Object *ob, char *vgroup) return NULL; } -static int do_mesh_key(Object *ob, Mesh *me) +static int do_mesh_key(Scene *scene, Object *ob, Mesh *me) { KeyBlock *k[4]; float cfra, ctime, t[4], delta, loc[3], size[3]; @@ -1008,7 +1024,11 @@ static int do_mesh_key(Object *ob, Mesh *me) /* prevent python from screwing this up? anyhoo, the from pointer could be dropped */ me->key->from= (ID *)me; + if (G.f & G_DEBUG) 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 ) { + if (G.f & G_DEBUG) printf("\tslurph key\n"); + delta= me->key->slurph; delta/= me->totvert; @@ -1019,15 +1039,20 @@ static int do_mesh_key(Object *ob, Mesh *me) /* in do_key and cp_key the case a>tot is handled */ } - cfra= G.scene->r.cfra; + cfra= (float)scene->r.cfra; for(a=0; a<me->totvert; a+=step, cfra+= delta) { - ctime= bsystem_time(0, cfra, 0.0); + ctime= bsystem_time(scene, 0, cfra, 0.0); // xxx ugly cruft! +#if 0 // XXX old animation system if(calc_ipo_spec(me->key->ipo, KEY_SPEED, &ctime)==0) { ctime /= 100.0; 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) { @@ -1043,10 +1068,11 @@ static int do_mesh_key(Object *ob, Mesh *me) else boundbox_mesh(me, loc, size); } else { - if(me->key->type==KEY_RELATIVE) { KeyBlock *kb; + if (G.f & G_DEBUG) printf("\tdo relative \n"); + for(kb= me->key->block.first; kb; kb= kb->next) kb->weights= get_weights_array(ob, kb->vgroup); @@ -1058,13 +1084,20 @@ static int do_mesh_key(Object *ob, Mesh *me) } } else { - ctime= bsystem_time(ob, G.scene->r.cfra, 0.0); - + if (G.f & G_DEBUG) printf("\tdo absolute \n"); + + ctime= bsystem_time(scene, ob, (float)scene->r.cfra, 0.0f); // xxx old cruft + +#if 0 // XXX old animation system if(calc_ipo_spec(me->key->ipo, KEY_SPEED, &ctime)==0) { ctime /= 100.0; 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) { do_key(0, me->totvert, me->totvert, (char *)me->mvert->co, me->key, k, t, 0); @@ -1151,7 +1184,7 @@ static void do_rel_cu_key(Curve *cu, float ctime) } } -static int do_curve_key(Curve *cu) +static int do_curve_key(Scene *scene, Curve *cu) { KeyBlock *k[4]; float cfra, ctime, t[4], delta; @@ -1174,15 +1207,16 @@ static int do_curve_key(Curve *cu) /* in do_key and cp_key the case a>tot has been handled */ } - cfra= G.scene->r.cfra; + cfra= (float)scene->r.cfra; for(a=0; a<tot; a+=step, cfra+= delta) { - - ctime= bsystem_time(0, cfra, 0.0); + ctime= bsystem_time(scene, 0, cfra, 0.0f); // XXX old cruft +#if 0 // XXX old animation system if(calc_ipo_spec(cu->key->ipo, KEY_SPEED, &ctime)==0) { ctime /= 100.0; CLAMP(ctime, 0.0, 1.0); } +#endif // XXX old animation system flag= setkeys(ctime, &cu->key->block, k, t, 0); if(flag==0) { @@ -1200,16 +1234,18 @@ static int do_curve_key(Curve *cu) } else { - ctime= bsystem_time(NULL, (float)G.scene->r.cfra, 0.0); + ctime= bsystem_time(scene, NULL, (float)scene->r.cfra, 0.0); if(cu->key->type==KEY_RELATIVE) { do_rel_cu_key(cu, ctime); } else { +#if 0 // XXX old animation system if(calc_ipo_spec(cu->key->ipo, KEY_SPEED, &ctime)==0) { ctime /= 100.0; CLAMP(ctime, 0.0, 1.0); } +#endif // XXX old animation system flag= setkeys(ctime, &cu->key->block, k, t, 0); @@ -1223,7 +1259,7 @@ static int do_curve_key(Curve *cu) return 1; } -static int do_latt_key(Object *ob, Lattice *lt) +static int do_latt_key(Scene *scene, Object *ob, Lattice *lt) { KeyBlock *k[4]; float delta, cfra, ctime, t[4]; @@ -1238,15 +1274,17 @@ static int do_latt_key(Object *ob, Lattice *lt) delta= lt->key->slurph; delta/= (float)tot; - cfra= G.scene->r.cfra; + cfra= (float)scene->r.cfra; for(a=0; a<tot; a++, cfra+= delta) { - ctime= bsystem_time(0, cfra, 0.0); + ctime= bsystem_time(scene, 0, cfra, 0.0); // XXX old cruft +#if 0 // XXX old animation system if(calc_ipo_spec(lt->key->ipo, KEY_SPEED, &ctime)==0) { ctime /= 100.0; CLAMP(ctime, 0.0, 1.0); } +#endif // XXX old animation system flag= setkeys(ctime, <->key->block, k, t, 0); if(flag==0) { @@ -1259,7 +1297,7 @@ static int do_latt_key(Object *ob, Lattice *lt) } } else { - ctime= bsystem_time(NULL, (float)G.scene->r.cfra, 0.0); + ctime= bsystem_time(scene, NULL, (float)scene->r.cfra, 0.0); if(lt->key->type==KEY_RELATIVE) { KeyBlock *kb; @@ -1275,10 +1313,12 @@ static int do_latt_key(Object *ob, Lattice *lt) } } else { +#if 0 // XXX old animation system if(calc_ipo_spec(lt->key->ipo, KEY_SPEED, &ctime)==0) { ctime /= 100.0; CLAMP(ctime, 0.0, 1.0); } +#endif // XXX old animation system flag= setkeys(ctime, <->key->block, k, t, 0); if(flag==0) { @@ -1296,7 +1336,7 @@ static int do_latt_key(Object *ob, Lattice *lt) } /* returns 1 when key applied */ -int do_ob_key(Object *ob) +int do_ob_key(Scene *scene, Object *ob) { Key *key= ob_get_key(ob); @@ -1305,7 +1345,9 @@ int do_ob_key(Object *ob) if(ob->shapeflag & (OB_SHAPE_LOCK|OB_SHAPE_TEMPLOCK)) { KeyBlock *kb= BLI_findlink(&key->block, ob->shapenr-1); - + + if (G.f & G_DEBUG) printf("ob %s, key %s locked \n", ob->id.name+2, key->id.name+2); + if(kb && (kb->flag & KEYBLOCK_MUTE)) kb= key->refkey; @@ -1340,17 +1382,24 @@ int do_ob_key(Object *ob) return 1; } else { +#if 0 // XXX old animation system + // NOTE: this stuff was NEVER reliable at all... if(ob->ipoflag & OB_ACTION_KEY) - do_all_object_actions(ob); + do_all_object_actions(scene, ob); else { - calc_ipo(key->ipo, bsystem_time(ob, G.scene->r.cfra, 0.0)); + calc_ipo(key->ipo, bsystem_time(scene, ob, scene->r.cfra, 0.0)); execute_ipo((ID *)key, key->ipo); } +#endif // XXX old animation system + /* do shapekey local drivers */ + float ctime= (float)scene->r.cfra; // XXX this needs to be checked + if (G.f & G_DEBUG) 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(ob, ob->data); - else if(ob->type==OB_CURVE) return do_curve_key( ob->data); - else if(ob->type==OB_SURF) return do_curve_key( ob->data); - else if(ob->type==OB_LATTICE) return do_latt_key(ob, ob->data); + if(ob->type==OB_MESH) return do_mesh_key(scene, ob, ob->data); + else if(ob->type==OB_CURVE) return do_curve_key(scene, ob->data); + else if(ob->type==OB_SURF) return do_curve_key(scene, ob->data); + else if(ob->type==OB_LATTICE) return do_latt_key(scene, ob, ob->data); } return 0; @@ -1407,3 +1456,18 @@ KeyBlock *key_get_keyblock(Key *key, int index) return NULL; } + +/* get the appropriate KeyBlock given a name to search for */ +KeyBlock *key_get_named_keyblock(Key *key, const char name[]) +{ + KeyBlock *kb; + + if (key && name) { + for (kb= key->block.first; kb; kb= kb->next) { + if (strcmp(name, kb->name)==0) + return kb; + } + } + + return NULL; +} |