diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-10-08 10:19:28 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-10-08 10:19:28 +0300 |
commit | 1d9de55949a4b1a79370c23e11ad59bffc5ae440 (patch) | |
tree | 70e1283b57e9c9694360731696b80725cae08d5e /source | |
parent | 04c7894f4d36ab7eef5126efb00db7433428eb8e (diff) |
BKE_key: add BKE_key_from_id helper functions
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_key.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/key.c | 53 |
2 files changed, 41 insertions, 14 deletions
diff --git a/source/blender/blenkernel/BKE_key.h b/source/blender/blenkernel/BKE_key.h index abe12282a1b..d5b3ed4be33 100644 --- a/source/blender/blenkernel/BKE_key.h +++ b/source/blender/blenkernel/BKE_key.h @@ -65,6 +65,8 @@ float *BKE_key_evaluate_object_ex( float *BKE_key_evaluate_object( struct Object *ob, int *r_totelem); +struct Key **BKE_key_from_id_p(struct ID *id); +struct Key *BKE_key_from_id(struct ID *id); struct Key **BKE_key_from_object_p(struct Object *ob); struct Key *BKE_key_from_object(struct Object *ob); struct KeyBlock *BKE_keyblock_from_object(struct Object *ob); diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index b591dc19685..36ba43f1e8a 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -1392,26 +1392,51 @@ float *BKE_key_evaluate_object(Object *ob, int *r_totelem) return BKE_key_evaluate_object_ex(ob, r_totelem, NULL, 0); } -Key **BKE_key_from_object_p(Object *ob) +Key **BKE_key_from_id_p(ID *id) { - if (ob == NULL) - return NULL; - - if (ob->type == OB_MESH) { - Mesh *me = ob->data; - return &me->key; - } - else if (ELEM(ob->type, OB_CURVE, OB_SURF)) { - Curve *cu = ob->data; - return &cu->key; + switch (GS(id->name)) { + case ID_ME: + { + Mesh *me = (Mesh *)id; + return &me->key; + } + case ID_CU: + { + Curve *cu = (Curve *)id; + if (cu->vfont == NULL) { + return &cu->key; + } + break; + } + case ID_LT: + { + Lattice *lt = (Lattice *)id; + return <->key; + } } - else if (ob->type == OB_LATTICE) { - Lattice *lt = ob->data; - return <->key; + + return NULL; +} + +Key *BKE_key_from_id(ID *id) +{ + Key **key_p; + key_p = BKE_key_from_id_p(id); + if (key_p) { + return *key_p; } + return NULL; } +Key **BKE_key_from_object_p(Object *ob) +{ + if (ob == NULL || ob->data == NULL) + return NULL; + + return BKE_key_from_id_p(ob->data); +} + Key *BKE_key_from_object(Object *ob) { Key **key_p; |