Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2020-09-03 09:23:49 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-09-03 09:27:15 +0300
commit3cbfe96681f69fcbccd1519d731168700dbf878a (patch)
treeb603e609537172bd41139eb42c9ca1711aa22cc0 /source/blender/blenkernel/intern/object.c
parentc017e1cb676314690a8c0b7da154a0815024171e (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/object.c')
-rw-r--r--source/blender/blenkernel/intern/object.c38
1 files changed, 38 insertions, 0 deletions
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)
{