Move util function to add new scene collection when active is not available from object to layer
This commit is contained in:
@@ -79,6 +79,7 @@ void BKE_scene_layer_base_select(struct SceneLayer *sl, struct Base *selbase);
|
||||
void BKE_layer_collection_free(struct SceneLayer *sl, struct LayerCollection *lc);
|
||||
|
||||
struct LayerCollection *BKE_layer_collection_active(struct SceneLayer *sl);
|
||||
struct LayerCollection *BKE_layer_collection_get_active_ensure(struct Scene *scene, struct SceneLayer *sl);
|
||||
|
||||
int BKE_layer_collection_count(struct SceneLayer *sl);
|
||||
|
||||
|
||||
@@ -370,6 +370,25 @@ LayerCollection *BKE_layer_collection_active(SceneLayer *sl)
|
||||
return collection_from_index(&sl->layer_collections, sl->active_collection, &i);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return layer collection to add new object(s).
|
||||
* Create one if none exists.
|
||||
*/
|
||||
LayerCollection *BKE_layer_collection_get_active_ensure(Scene *scene, SceneLayer *sl)
|
||||
{
|
||||
LayerCollection *lc = BKE_layer_collection_active(sl);
|
||||
|
||||
if (lc == NULL) {
|
||||
BLI_assert(BLI_listbase_is_empty(&sl->layer_collections));
|
||||
/* When there is no collection linked to this SceneLayer, create one. */
|
||||
SceneCollection *sc = BKE_collection_add(scene, NULL, NULL);
|
||||
lc = BKE_collection_link(sl, sc);
|
||||
}
|
||||
|
||||
return lc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively get the count of collections
|
||||
*/
|
||||
|
||||
@@ -703,14 +703,7 @@ Object *BKE_object_add(
|
||||
|
||||
ob->data = BKE_object_obdata_add_from_type(bmain, type, name);
|
||||
|
||||
lc = BKE_layer_collection_active(sl);
|
||||
|
||||
if (lc == NULL) {
|
||||
BLI_assert(BLI_listbase_count_ex(&sl->layer_collections, 1) == 0);
|
||||
/* when there is no collection linked to this SceneLayer, create one */
|
||||
SceneCollection *sc = BKE_collection_add(scene, NULL, NULL);
|
||||
lc = BKE_collection_link(sl, sc);
|
||||
}
|
||||
lc = BKE_layer_collection_get_active_ensure(scene, sl);
|
||||
|
||||
BKE_collection_object_add(scene, lc->scene_collection, ob);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user