diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-04-12 15:05:16 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-04-12 15:05:16 +0400 |
commit | 4c9486f13d40cb066ad4643537d926559c6ea481 (patch) | |
tree | 62ef92d3d84b3675a7f2167fb589de5fb3cdcde6 /source | |
parent | 4b8ab31d81e335a1d5e45dc950ea1350dc1ca1c4 (diff) |
change add_keyblock() not to sort keyblocks by time since this can be a problem when using the function in lower level parts of the code, instead add add_keyblock_ctime() which sets time and sorts on absolute shape keys.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_key.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/key.c | 27 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 12 |
3 files changed, 28 insertions, 12 deletions
diff --git a/source/blender/blenkernel/BKE_key.h b/source/blender/blenkernel/BKE_key.h index c241160102e..63d9d731097 100644 --- a/source/blender/blenkernel/BKE_key.h +++ b/source/blender/blenkernel/BKE_key.h @@ -63,6 +63,7 @@ float *do_ob_key(struct Scene *scene, struct Object *ob); struct Key *ob_get_key(struct Object *ob); struct KeyBlock *add_keyblock(struct Key *key, const char *name); +struct KeyBlock *add_keyblock_ctime(struct Key *key, const char * name, const short do_force); struct KeyBlock *ob_get_keyblock(struct Object *ob); struct KeyBlock *ob_get_reference_keyblock(struct Object *ob); struct KeyBlock *key_get_keyblock(struct Key *key, int index); diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index 62701f4e98e..74d56a82c75 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -1472,15 +1472,30 @@ KeyBlock *add_keyblock(Key *key, const char *name) kb->slidermin= 0.0f; kb->slidermax= 1.0f; - - // XXX kb->pos is the confusing old horizontal-line RVK crap in old IPO Editor... - if (key->type == KEY_RELATIVE) { - kb->pos= curpos + 0.1f; - } - else { + + /** + * \note caller may want to set this to current time, but don't do it here since we need to sort + * which could cause problems in some cases, see #add_keyblock_ctime */ + kb->pos = curpos + 0.1f; /* only used for absolute shape keys */ + + return kb; +} + +/** + * \note sorting is a problematic side effect in some cases, + * better only do this explicitly by having its own function, + * + * \param do_force always use ctime even for relative keys. + */ +KeyBlock *add_keyblock_ctime(Key *key, const char *name, const short do_force) +{ + KeyBlock *kb = add_keyblock(key, name); + + if (do_force || (key->type != KEY_RELATIVE)) { kb->pos = key->ctime / 100.0f; sort_keys(key); } + return kb; } diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 237d268e307..4d8d6e937a9 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -2869,7 +2869,7 @@ static KeyBlock *insert_meshkey(Scene *scene, Object *ob, const char *name, int if (newkey || from_mix==FALSE) { /* create from mesh */ - kb= add_keyblock(key, name); + kb = add_keyblock_ctime(key, name, FALSE); mesh_to_key(me, kb); } else { @@ -2877,7 +2877,7 @@ static KeyBlock *insert_meshkey(Scene *scene, Object *ob, const char *name, int float *data= do_ob_key(scene, ob); /* create new block with prepared data */ - kb= add_keyblock(key, name); + kb = add_keyblock_ctime(key, name, FALSE); kb->data= data; kb->totelem= me->totvert; } @@ -2899,7 +2899,7 @@ static KeyBlock *insert_lattkey(Scene *scene, Object *ob, const char *name, int } if (newkey || from_mix==FALSE) { - kb= add_keyblock(key, name); + kb = add_keyblock_ctime(key, name, FALSE); if (!newkey) { KeyBlock *basekb= (KeyBlock *)key->block.first; kb->data= MEM_dupallocN(basekb->data); @@ -2914,7 +2914,7 @@ static KeyBlock *insert_lattkey(Scene *scene, Object *ob, const char *name, int float *data= do_ob_key(scene, ob); /* create new block with prepared data */ - kb= add_keyblock(key, name); + kb = add_keyblock_ctime(key, name, FALSE); kb->totelem= lt->pntsu*lt->pntsv*lt->pntsw; kb->data= data; } @@ -2938,7 +2938,7 @@ static KeyBlock *insert_curvekey(Scene *scene, Object *ob, const char *name, int if (newkey || from_mix==FALSE) { /* create from curve */ - kb= add_keyblock(key, name); + kb = add_keyblock_ctime(key, name, FALSE); if (!newkey) { KeyBlock *basekb= (KeyBlock *)key->block.first; kb->data= MEM_dupallocN(basekb->data); @@ -2953,7 +2953,7 @@ static KeyBlock *insert_curvekey(Scene *scene, Object *ob, const char *name, int float *data= do_ob_key(scene, ob); /* create new block with prepared data */ - kb= add_keyblock(key, name); + kb = add_keyblock_ctime(key, name, FALSE); kb->totelem= count_curveverts(lb); kb->data= data; } |