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
path: root/source
diff options
context:
space:
mode:
authorDalai Felinto <dfelinto@gmail.com>2016-12-12 14:56:40 +0300
committerDalai Felinto <dfelinto@gmail.com>2016-12-12 14:56:40 +0300
commit3839afe03d43d73626ec5fb008a040d173dec029 (patch)
treead7e3787f3e508e039eb93cbbed6a7d2250e8de2 /source
parentc96c3c8bbe51a7dd26addcdeac9d0bb2e992cca1 (diff)
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
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/BKE_collection.h2
-rw-r--r--source/blender/blenkernel/intern/collection.c39
-rw-r--r--source/blender/editors/object/object_relations.c4
3 files changed, 38 insertions, 7 deletions
diff --git a/source/blender/blenkernel/BKE_collection.h b/source/blender/blenkernel/BKE_collection.h
index fc2cf1c268d..846f7f14bf0 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 a3112097141..1f19330768a 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 18884881a04..109074ab737 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);
}