diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2017-05-26 16:10:35 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2017-05-26 18:44:00 +0300 |
commit | 0ab9b943a2aae617d36a4010bb60d3cbe8bd5d57 (patch) | |
tree | 91be34274eaeebe834917dd77b41340951df636f /source/blender | |
parent | 0c6227ce7770c53d8306b21d682e9c3d68573855 (diff) |
Move util function to add new scene collection when active is not available from object to layer
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_layer.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/layer.c | 19 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 9 |
3 files changed, 21 insertions, 8 deletions
diff --git a/source/blender/blenkernel/BKE_layer.h b/source/blender/blenkernel/BKE_layer.h index decba7c2ace..55b9f25a59c 100644 --- a/source/blender/blenkernel/BKE_layer.h +++ b/source/blender/blenkernel/BKE_layer.h @@ -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); diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c index 8f384db40e3..77545016c57 100644 --- a/source/blender/blenkernel/intern/layer.c +++ b/source/blender/blenkernel/intern/layer.c @@ -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 */ diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 380b0a894df..8776e341b84 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -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); |