[Bf-blender-cvs] [3839afe] render-layers: Layers: change the API so that we can run a function on every object of the scene

Dalai Felinto noreply at git.blender.org
Mon Dec 12 12:57:15 CET 2016


Commit: 3839afe03d43d73626ec5fb008a040d173dec029
Author: Dalai Felinto
Date:   Mon Dec 12 12:56:40 2016 +0100
Branches: render-layers
https://developer.blender.org/rB3839afe03d43d73626ec5fb008a040d173dec029

Layers: change the API so that we can run a function on every object of the scene

use tag to make sure we call each object only once

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

M	source/blender/blenkernel/BKE_collection.h
M	source/blender/blenkernel/intern/collection.c
M	source/blender/editors/object/object_relations.c

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

diff --git a/source/blender/blenkernel/BKE_collection.h b/source/blender/blenkernel/BKE_collection.h
index fc2cf1c..846f7f1 100644
--- a/source/blender/blenkernel/BKE_collection.h
+++ b/source/blender/blenkernel/BKE_collection.h
@@ -41,7 +41,7 @@ struct SceneCollection *BKE_collection_master(struct Scene *scene);
 void BKE_collection_master_free(struct Scene *scene);
 void BKE_collection_object_add(struct Scene *scene, struct SceneCollection *sc, struct Object *object);
 void BKE_collection_object_remove(struct Scene *scene, struct SceneCollection *sc, struct Object *object);
-void BKE_collection_objects_callback(struct SceneCollection *sc, void (*callback)(struct Object *_ob, void *_data), void *data);
+void BKE_scene_objects_callback(struct Scene *scene, void (*callback)(struct Object *_ob, void *_data), void *data);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index a311209..1f19330 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -199,12 +199,34 @@ void BKE_collection_object_remove(struct Scene *UNUSED(scene), struct SceneColle
 }
 
 /*
+ * Tag util functions to make sure the same object is not called twice
+ */
+
+static void object_tag(Object *ob)
+{
+	ob->flag |= BA_TEMP_TAG;
+}
+
+static void object_tag_clear(Object *ob, void *UNUSED(data))
+{
+	ob->flag &= ~BA_TEMP_TAG;
+}
+
+static bool object_tag_test(Object *ob)
+{
+	return (ob->flag & BA_TEMP_TAG) != 0;
+}
+
+/*
  * Recursively calls the callback function for the objects in a SceneCollection
  */
-void BKE_collection_objects_callback(SceneCollection *sc, void (*callback)(struct Object *_ob, void *_data), void *data)
+static void collection_objects_callback(SceneCollection *sc, void (*callback)(struct Object *_ob, void *_data), void *data)
 {
 	for (LinkData *link= sc->objects.first; link; link = link->next) {
-		callback(link->data, data);
+		if (object_tag_test(link->data)) {
+			callback(link->data, data);
+			object_tag(link->data);
+		}
 	}
 
 	for (LinkData *link= sc->filter_objects.first; link; link = link->next) {
@@ -212,6 +234,17 @@ void BKE_collection_objects_callback(SceneCollection *sc, void (*callback)(struc
 	}
 
 	for (SceneCollection *nsc = sc->scene_collections.first; nsc; nsc = nsc->next) {
-		BKE_collection_objects_callback(nsc, callback, data);
+		collection_objects_callback(nsc, callback, data);
 	}
 }
+
+/*
+ * Recursively calls the callback function for the objects in a Scene
+ * The same object
+ */
+void BKE_scene_objects_callback(Scene *scene, void (*callback)(struct Object *_ob, void *_data), void *data)
+{
+	SceneCollection *sc = BKE_collection_master(scene);
+	collection_objects_callback(sc, object_tag_clear, NULL);
+	collection_objects_callback(sc, callback, data);
+}
diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c
index 1888488..109074a 100644
--- a/source/blender/editors/object/object_relations.c
+++ b/source/blender/editors/object/object_relations.c
@@ -1868,9 +1868,7 @@ static void object_untag_OB_DONE(Object *ob, void *UNUSED(data))
  * button can be functional.*/
 void ED_object_single_user(Main *bmain, Scene *scene, Object *ob)
 {
-	SceneCollection *msc = BKE_collection_master(scene);
-	BKE_collection_objects_callback(msc, object_untag_OB_DONE, NULL);
-
+	BKE_scene_objects_callback(scene, object_untag_OB_DONE, NULL);
 	ob->flag |= OB_DONE;
 	single_object_users(bmain, scene, NULL, OB_DONE, false);
 }




More information about the Bf-blender-cvs mailing list