BKE_key: add BKE_key_from_id helper functions

This commit is contained in:
Campbell Barton
2015-10-08 18:19:28 +11:00
parent 04c7894f4d
commit 1d9de55949
2 changed files with 41 additions and 14 deletions

View File

@@ -65,6 +65,8 @@ float *BKE_key_evaluate_object_ex(
float *BKE_key_evaluate_object( float *BKE_key_evaluate_object(
struct Object *ob, int *r_totelem); 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_p(struct Object *ob);
struct Key *BKE_key_from_object(struct Object *ob); struct Key *BKE_key_from_object(struct Object *ob);
struct KeyBlock *BKE_keyblock_from_object(struct Object *ob); struct KeyBlock *BKE_keyblock_from_object(struct Object *ob);

View 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); 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) switch (GS(id->name)) {
return NULL; case ID_ME:
{
if (ob->type == OB_MESH) { Mesh *me = (Mesh *)id;
Mesh *me = ob->data;
return &me->key; return &me->key;
} }
else if (ELEM(ob->type, OB_CURVE, OB_SURF)) { case ID_CU:
Curve *cu = ob->data; {
Curve *cu = (Curve *)id;
if (cu->vfont == NULL) {
return &cu->key; return &cu->key;
} }
else if (ob->type == OB_LATTICE) { break;
Lattice *lt = ob->data; }
case ID_LT:
{
Lattice *lt = (Lattice *)id;
return &lt->key; return &lt->key;
} }
}
return NULL; 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 *BKE_key_from_object(Object *ob)
{ {
Key **key_p; Key **key_p;