diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2018-03-29 22:23:43 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2018-03-30 02:03:47 +0300 |
commit | 1251043636d37f36bc2e7c845e6542898476707d (patch) | |
tree | 77925fd003f592360c1e296b35cb8bb3dc585b51 /source | |
parent | b882257fbd38f56b512a79027f91f8ff282f31b5 (diff) |
Collections: API to check if object is in collection
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_collection.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/collection.c | 13 |
2 files changed, 13 insertions, 1 deletions
diff --git a/source/blender/blenkernel/BKE_collection.h b/source/blender/blenkernel/BKE_collection.h index af8047bf373..b646d1d5e40 100644 --- a/source/blender/blenkernel/BKE_collection.h +++ b/source/blender/blenkernel/BKE_collection.h @@ -58,6 +58,7 @@ void BKE_collection_object_add_from(struct Scene *scene, struct Object *ob_src, bool BKE_collection_object_remove(struct Main *bmain, struct ID *owner_id, struct SceneCollection *sc, struct Object *object, const bool free_us); bool BKE_collections_object_remove(struct Main *bmain, struct ID *owner_id, struct Object *object, const bool free_us); void BKE_collection_object_move(struct ID *owner_id, struct SceneCollection *sc_dst, struct SceneCollection *sc_src, struct Object *ob); +bool BKE_collection_object_exists(struct SceneCollection *scene_collection, struct Object *ob); struct Group *BKE_collection_group_create(struct Main *bmain, struct Scene *scene, struct LayerCollection *lc); diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c index 880d28970c0..aed0ffb9fc3 100644 --- a/source/blender/blenkernel/intern/collection.c +++ b/source/blender/blenkernel/intern/collection.c @@ -390,7 +390,7 @@ static void collection_object_add(const ID *owner_id, SceneCollection *sc, Objec */ bool BKE_collection_object_add(const ID *owner_id, SceneCollection *sc, Object *ob) { - if (BLI_findptr(&sc->objects, ob, offsetof(LinkData, data))) { + if (BKE_collection_object_exists(sc, ob)) { /* don't add the same object twice */ return false; } @@ -512,6 +512,17 @@ void BKE_collection_object_move(ID *owner_id, SceneCollection *sc_dst, SceneColl } } +/** + * Whether the object is directly inside the collection. + */ +bool BKE_collection_object_exists(struct SceneCollection *scene_collection, struct Object *ob) +{ + if (BLI_findptr(&scene_collection->objects, ob, offsetof(LinkData, data))) { + return true; + } + return false; +} + static void layer_collection_sync(LayerCollection *lc_dst, LayerCollection *lc_src) { lc_dst->flag = lc_src->flag; |