Changeset View
Standalone View
source/blender/blenkernel/intern/collection.c
| Show First 20 Lines • Show All 1,767 Lines • ▼ Show 20 Lines | LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { | ||||
| /* Recursively save flags from collection children. */ | /* Recursively save flags from collection children. */ | ||||
| layer_collection_flags_store_recursive(layer_collection, flag); | layer_collection_flags_store_recursive(layer_collection, flag); | ||||
| BLI_addtail(r_layer_level_list, flag); | BLI_addtail(r_layer_level_list, flag); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void layer_collection_flags_free_recursive(LayerCollectionFlag *flag) | |||||
| { | |||||
| LISTBASE_FOREACH (LayerCollectionFlag *, child, &flag->children) { | |||||
| layer_collection_flags_free_recursive(child); | |||||
| } | |||||
| BLI_freelistN(&flag->children); | |||||
| } | |||||
| static void layer_collection_flags_restore_recursive(LayerCollection *layer_collection, | static void layer_collection_flags_restore_recursive(LayerCollection *layer_collection, | ||||
| LayerCollectionFlag *flag) | LayerCollectionFlag *flag) | ||||
| { | { | ||||
| /* There should be a flag struct for every layer collection. */ | /* There should be a flag struct for every layer collection. */ | ||||
| BLI_assert(BLI_listbase_count(&layer_collection->layer_collections) == | BLI_assert(BLI_listbase_count(&layer_collection->layer_collections) == | ||||
| BLI_listbase_count(&flag->children)); | BLI_listbase_count(&flag->children)); | ||||
| /* The flag and the the layer collection should actually correspond. */ | /* The flag and the the layer collection should actually correspond. */ | ||||
| BLI_assert(flag->collection == layer_collection->collection); | BLI_assert(flag->collection == layer_collection->collection); | ||||
| LayerCollectionFlag *child_flag = flag->children.first; | LayerCollectionFlag *child_flag = flag->children.first; | ||||
| LISTBASE_FOREACH (LayerCollection *, child, &layer_collection->layer_collections) { | LISTBASE_FOREACH (LayerCollection *, child, &layer_collection->layer_collections) { | ||||
| layer_collection_flags_restore_recursive(child, child_flag); | layer_collection_flags_restore_recursive(child, child_flag); | ||||
| child_flag = child_flag->next; | child_flag = child_flag->next; | ||||
| } | } | ||||
| BLI_freelistN(&flag->children); | |||||
| /* We treat exclude as a special case. | /* We treat exclude as a special case. | ||||
| * | * | ||||
| * If in a different view layer the parent collection was disabled (e.g., background) | * If in a different view layer the parent collection was disabled (e.g., background) | ||||
| * and now we moved a new collection to be part of the background this collection should | * and now we moved a new collection to be part of the background this collection should | ||||
| * probably be disabled. | * probably be disabled. | ||||
| * | * | ||||
| * Note: If we were to also keep the exclude flag we would need to re-sync the collections. | * Note: If we were to also keep the exclude flag we would need to re-sync the collections. | ||||
| Show All 9 Lines | |||||
| { | { | ||||
| LISTBASE_FOREACH (LayerCollectionFlag *, flag, flags) { | LISTBASE_FOREACH (LayerCollectionFlag *, flag, flags) { | ||||
| ViewLayer *view_layer = flag->view_layer; | ViewLayer *view_layer = flag->view_layer; | ||||
| /* The top level of flag structs must have this set. */ | /* The top level of flag structs must have this set. */ | ||||
| BLI_assert(view_layer != NULL); | BLI_assert(view_layer != NULL); | ||||
| LayerCollection *layer_collection = BKE_layer_collection_first_from_scene_collection( | LayerCollection *layer_collection = BKE_layer_collection_first_from_scene_collection( | ||||
| view_layer, collection); | view_layer, collection); | ||||
| /* The flags should only be added if the collection is in the view layer. */ | /* The flags should only be added if the collection is the scene in the first place, which | ||||
mont29: `is in the` I guess? | |||||
mont29Unsubmitted Done Inline Actionsrestored mont29: restored | |||||
mont29Unsubmitted Done Inline Actionsis still in the scene, mont29: `is still in the scene,` | |||||
| BLI_assert(layer_collection != NULL); | * means that it should also be in the view layer. However, the scene collection is local to | ||||
mont29Unsubmitted Done Inline Actions-> master mont29: -> `master` | |||||
mont29Unsubmitted Done Inline Actionsits mont29: its | |||||
| * each scene, even when it is created with "Linked Copy". So if the collection is dragged to | |||||
| * the scene collection, it will no longer exist in the other scenes. */ | |||||
mont29Unsubmitted Done Inline Actions-> master mont29: -> `master`
| |||||
mont29Unsubmitted Done Inline ActionsDo not focus on linked copy here, there are many other ways to end up sharing a same collection in several scenes, and all those would trigger this special case when moved to the master one. In fact, it can even happen when a sub-collection is moved to anther regular collection in one scene, that does not exist in the other scene that shared it previously. However, if we move a sub-collection shared by several scenes, it may effectively remove it from some non-active scenes hierarchy (e.g. if moved into current scene's master collection). Those non-active scene view layers won't contain a matching layer collection anymore then. ? mont29: Do not focus on `linked copy` here, there are many other ways to end up sharing a same… | |||||
| if (layer_collection != NULL) { | |||||
| layer_collection_flags_restore_recursive(layer_collection, flag); | layer_collection_flags_restore_recursive(layer_collection, flag); | ||||
| } | } | ||||
| layer_collection_flags_free_recursive(flag); | |||||
| } | |||||
| BLI_freelistN(flags); | BLI_freelistN(flags); | ||||
| } | } | ||||
| bool BKE_collection_move(Main *bmain, | bool BKE_collection_move(Main *bmain, | ||||
| Collection *to_parent, | Collection *to_parent, | ||||
| Collection *from_parent, | Collection *from_parent, | ||||
| Collection *relative, | Collection *relative, | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | bool BKE_collection_move(Main *bmain, | ||||
| ListBase layer_flags; | ListBase layer_flags; | ||||
| if (do_flag_sync) { | if (do_flag_sync) { | ||||
| layer_collection_flags_store(bmain, collection, &layer_flags); | layer_collection_flags_store(bmain, collection, &layer_flags); | ||||
| } | } | ||||
| /* Create and remove layer collections. */ | /* Create and remove layer collections. */ | ||||
| BKE_main_collection_sync(bmain); | BKE_main_collection_sync(bmain); | ||||
| /* Restore the original layer collection flags. */ | /* Restore and free the original layer collection flags. */ | ||||
mont29Unsubmitted Done Inline ActionsRestore the original layer collection flags and free their temp storage. mont29: `Restore the original layer collection flags and free their temp storage.` | |||||
| if (do_flag_sync) { | if (do_flag_sync) { | ||||
| layer_collection_flags_restore(&layer_flags, collection); | layer_collection_flags_restore(&layer_flags, collection); | ||||
| } | } | ||||
| /* We need to sync it again to pass the correct flags to the collections objects. */ | /* We need to sync it again to pass the correct flags to the collections objects. */ | ||||
| BKE_main_collection_sync(bmain); | BKE_main_collection_sync(bmain); | ||||
| return true; | return true; | ||||
| ▲ Show 20 Lines • Show All 194 Lines • Show Last 20 Lines | |||||
is in the I guess?