diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-09-03 09:23:49 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-09-03 09:27:15 +0300 |
commit | 3cbfe96681f69fcbccd1519d731168700dbf878a (patch) | |
tree | b603e609537172bd41139eb42c9ca1711aa22cc0 /source/blender/blenkernel/intern | |
parent | c017e1cb676314690a8c0b7da154a0815024171e (diff) |
Object: add BKE_object_obdata_to_type utility function
Move functionality to get the object type from an ID
into it's own function.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/curve.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 38 |
2 files changed, 39 insertions, 1 deletions
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 4d6b8feea26..4ac6399c4e4 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -268,7 +268,7 @@ ListBase *BKE_curve_editNurbs_get(Curve *cu) return NULL; } -short BKE_curve_type_get(Curve *cu) +short BKE_curve_type_get(const Curve *cu) { Nurb *nu; int type = cu->type; diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index b7694afb55b..871861c3167 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -1274,6 +1274,44 @@ void *BKE_object_obdata_add_from_type(Main *bmain, int type, const char *name) } } +/** + * Return -1 on failure. + */ +int BKE_object_obdata_to_type(const ID *id) +{ + /* Keep in sync with #OB_DATA_SUPPORT_ID macro. */ + switch (GS(id->name)) { + case ID_ME: + return OB_MESH; + case ID_CU: + return BKE_curve_type_get((const Curve *)id); + case ID_MB: + return OB_MBALL; + case ID_LA: + return OB_LAMP; + case ID_SPK: + return OB_SPEAKER; + case ID_CA: + return OB_CAMERA; + case ID_LT: + return OB_LATTICE; + case ID_GD: + return OB_GPENCIL; + case ID_AR: + return OB_ARMATURE; + case ID_LP: + return OB_LIGHTPROBE; + case ID_HA: + return OB_HAIR; + case ID_PT: + return OB_POINTCLOUD; + case ID_VO: + return OB_VOLUME; + default: + return -1; + } +} + /* more general add: creates minimum required data, but without vertices etc. */ Object *BKE_object_add_only_object(Main *bmain, int type, const char *name) { |