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(
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);

View File

@ -1392,24 +1392,49 @@ 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_id_p(ID *id)
{
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;
}
}
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)
if (ob == NULL || ob->data == 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;
}
else if (ob->type == OB_LATTICE) {
Lattice *lt = ob->data;
return &lt->key;
}
return NULL;
return BKE_key_from_id_p(ob->data);
}
Key *BKE_key_from_object(Object *ob)