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
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel/intern/collection.c')
-rw-r--r--source/blender/blenkernel/intern/collection.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index 76c6dc1d5e7..b71bcef229a 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -996,9 +996,11 @@ static void collection_tag_update_parent_recursive(Main *bmain,
}
}
-static Collection *collection_parent_editable_find_recursive(Collection *collection)
+static Collection *collection_parent_editable_find_recursive(const ViewLayer *view_layer,
+ Collection *collection)
{
- if (!ID_IS_LINKED(collection) && !ID_IS_OVERRIDE_LIBRARY(collection)) {
+ if (!ID_IS_LINKED(collection) && !ID_IS_OVERRIDE_LIBRARY(collection) &&
+ (view_layer == NULL || BKE_view_layer_has_collection(view_layer, collection))) {
return collection;
}
@@ -1009,10 +1011,16 @@ static Collection *collection_parent_editable_find_recursive(Collection *collect
LISTBASE_FOREACH (CollectionParent *, collection_parent, &collection->parents) {
if (!ID_IS_LINKED(collection_parent->collection) &&
!ID_IS_OVERRIDE_LIBRARY(collection_parent->collection)) {
+ if (view_layer != NULL &&
+ !BKE_view_layer_has_collection(view_layer, collection_parent->collection)) {
+ /* In case this parent collection is not in given view_layer, there is no point in
+ * searching in its ancestors either, we can skip that whole parenting branch. */
+ continue;
+ }
return collection_parent->collection;
}
Collection *editable_collection = collection_parent_editable_find_recursive(
- collection_parent->collection);
+ view_layer, collection_parent->collection);
if (editable_collection != NULL) {
return editable_collection;
}
@@ -1110,11 +1118,23 @@ bool BKE_collection_object_add_notest(Main *bmain, Collection *collection, Objec
bool BKE_collection_object_add(Main *bmain, Collection *collection, Object *ob)
{
+ return BKE_collection_viewlayer_object_add(bmain, NULL, collection, ob);
+}
+
+bool BKE_collection_viewlayer_object_add(Main *bmain,
+ const ViewLayer *view_layer,
+ Collection *collection,
+ Object *ob)
+{
if (collection == NULL) {
return false;
}
- collection = collection_parent_editable_find_recursive(collection);
+ collection = collection_parent_editable_find_recursive(view_layer, collection);
+
+ if (collection == NULL) {
+ return false;
+ }
return BKE_collection_object_add_notest(bmain, collection, ob);
}