[Bf-blender-cvs] [1251043636d] blender2.8: Collections: API to check if object is in collection

Dalai Felinto noreply at git.blender.org
Fri Mar 30 01:05:54 CEST 2018


Commit: 1251043636d37f36bc2e7c845e6542898476707d
Author: Dalai Felinto
Date:   Thu Mar 29 16:23:43 2018 -0300
Branches: blender2.8
https://developer.blender.org/rB1251043636d37f36bc2e7c845e6542898476707d

Collections: API to check if object is in collection

===================================================================

M	source/blender/blenkernel/BKE_collection.h
M	source/blender/blenkernel/intern/collection.c

===================================================================

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;



More information about the Bf-blender-cvs mailing list