BKE_key: add BKE_key_from_id helper functions
authorCampbell Barton <ideasman42@gmail.com>
Thu, 8 Oct 2015 07:19:28 +0000 (18:19 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 8 Oct 2015 07:19:28 +0000 (18:19 +1100)
source/blender/blenkernel/BKE_key.h
source/blender/blenkernel/intern/key.c

index abe12282a1b976fc30f0caa0dfcb2b67db18c8ae..d5b3ed4be33e5bfa46e84252fdae269491633170 100644 (file)
@@ -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);
index b591dc196854a05bf6b6af4ab1235177355f6bb6..36ba43f1e8a536c7e735f0486e510a81ccc7de2e 100644 (file)
@@ -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 &lt->key;
+               }
        }
-       else if (ob->type == OB_LATTICE) {
-               Lattice *lt = ob->data;
-               return &lt->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;