Fix #119142: Skip linking collection inside another linked collection
When linking a collection from library, it can be linked inside another linked/overrided collection if it is selected in outliner. This can be prevented by linking with editable parent collection. Pull Request: https://projects.blender.org/blender/blender/pulls/119144
This commit is contained in:
committed by
Pratik Borhade
parent
f9abbeca09
commit
021565d867
@@ -305,6 +305,11 @@ bool BKE_collection_cycles_fix(struct Main *bmain, struct Collection *collection
|
||||
bool BKE_collection_has_collection(const struct Collection *parent,
|
||||
const struct Collection *collection);
|
||||
|
||||
/**
|
||||
* Return parent collection which is not linked.
|
||||
*/
|
||||
Collection *BKE_collection_parent_editable_find_recursive(const ViewLayer *view_layer,
|
||||
Collection *collection);
|
||||
/**
|
||||
* Rebuild parent relationships from child ones, for all children of given \a collection.
|
||||
*
|
||||
|
||||
@@ -520,11 +520,13 @@ static void loose_data_instantiate_ensure_active_collection(
|
||||
Scene *scene = instantiate_context->lapp_context->params->context.scene;
|
||||
ViewLayer *view_layer = instantiate_context->lapp_context->params->context.view_layer;
|
||||
|
||||
/* Find or add collection as needed. */
|
||||
/* Find or add collection as needed. When `active_collection` is non-null, it is assumed to be
|
||||
* editable. */
|
||||
if (instantiate_context->active_collection == nullptr) {
|
||||
if (lapp_context->params->flag & FILE_ACTIVE_COLLECTION) {
|
||||
LayerCollection *lc = BKE_layer_collection_get_active(view_layer);
|
||||
instantiate_context->active_collection = lc->collection;
|
||||
instantiate_context->active_collection = BKE_collection_parent_editable_find_recursive(
|
||||
view_layer, lc->collection);
|
||||
}
|
||||
else {
|
||||
if (lapp_context->params->flag & FILE_LINK) {
|
||||
|
||||
@@ -1232,8 +1232,8 @@ static void collection_gobject_assert_internal_consistency(Collection *collectio
|
||||
}
|
||||
}
|
||||
|
||||
static Collection *collection_parent_editable_find_recursive(const ViewLayer *view_layer,
|
||||
Collection *collection)
|
||||
Collection *BKE_collection_parent_editable_find_recursive(const ViewLayer *view_layer,
|
||||
Collection *collection)
|
||||
{
|
||||
if (!ID_IS_LINKED(collection) && !ID_IS_OVERRIDE_LIBRARY(collection) &&
|
||||
(view_layer == nullptr || BKE_view_layer_has_collection(view_layer, collection)))
|
||||
@@ -1258,7 +1258,7 @@ static Collection *collection_parent_editable_find_recursive(const ViewLayer *vi
|
||||
}
|
||||
return collection_parent->collection;
|
||||
}
|
||||
Collection *editable_collection = collection_parent_editable_find_recursive(
|
||||
Collection *editable_collection = BKE_collection_parent_editable_find_recursive(
|
||||
view_layer, collection_parent->collection);
|
||||
if (editable_collection != nullptr) {
|
||||
return editable_collection;
|
||||
@@ -1386,7 +1386,7 @@ bool BKE_collection_viewlayer_object_add(Main *bmain,
|
||||
return false;
|
||||
}
|
||||
|
||||
collection = collection_parent_editable_find_recursive(view_layer, collection);
|
||||
collection = BKE_collection_parent_editable_find_recursive(view_layer, collection);
|
||||
|
||||
if (collection == nullptr) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user