Collections: API to check if object is in collection

This commit is contained in:
Dalai Felinto 2018-03-29 16:23:43 -03:00
parent b882257fbd
commit 1251043636
2 changed files with 13 additions and 1 deletions

View File

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

View File

@ -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;