diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_collection.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_layer.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/collection.c | 27 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/layer.c | 25 |
4 files changed, 50 insertions, 6 deletions
diff --git a/source/blender/blenkernel/BKE_collection.h b/source/blender/blenkernel/BKE_collection.h index bfdafc3ad23..309acce752d 100644 --- a/source/blender/blenkernel/BKE_collection.h +++ b/source/blender/blenkernel/BKE_collection.h @@ -44,6 +44,7 @@ struct Main; struct Object; struct Scene; struct SceneCollection; +struct ViewLayer; struct SceneCollection *BKE_collection_add( struct ID *owner_id, struct SceneCollection *sc_parent, const int type, const char *name); @@ -61,6 +62,8 @@ void BKE_collection_object_move(struct ID *owner_id, struct SceneCollection *sc_ bool BKE_collection_object_exists(struct SceneCollection *scene_collection, struct Object *ob); struct SceneCollection *BKE_collection_from_index(struct Scene *scene, const int index); +bool BKE_collection_objects_select(struct ViewLayer *view_layer, struct SceneCollection *scene_collection); + struct Group *BKE_collection_group_create(struct Main *bmain, struct Scene *scene, struct LayerCollection *lc); void BKE_collection_reinsert_after(const struct Scene *scene, struct SceneCollection *sc_reinsert, struct SceneCollection *sc_after); diff --git a/source/blender/blenkernel/BKE_layer.h b/source/blender/blenkernel/BKE_layer.h index 59aec53aa1e..8140dc5b31d 100644 --- a/source/blender/blenkernel/BKE_layer.h +++ b/source/blender/blenkernel/BKE_layer.h @@ -112,6 +112,7 @@ void BKE_collection_unlink(struct ViewLayer *view_layer, struct LayerCollection void BKE_collection_enable(struct ViewLayer *view_layer, struct LayerCollection *lc); +struct LayerCollection *BKE_layer_collection_first_from_scene_collection(struct ViewLayer *view_layer, const struct SceneCollection *scene_collection); bool BKE_view_layer_has_collection(struct ViewLayer *view_layer, const struct SceneCollection *sc); bool BKE_scene_has_object(struct Scene *scene, struct Object *ob); diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c index 669bbfb00cc..29e3539ab59 100644 --- a/source/blender/blenkernel/intern/collection.c +++ b/source/blender/blenkernel/intern/collection.c @@ -574,6 +574,33 @@ static void layer_collection_sync(LayerCollection *lc_dst, LayerCollection *lc_s } /** + * Select all the objects in this SceneCollection (and its nested collections) for this ViewLayer. + * Return true if any object was selected. + */ +bool BKE_collection_objects_select(ViewLayer *view_layer, SceneCollection *scene_collection) +{ + LayerCollection *layer_collection = BKE_layer_collection_first_from_scene_collection(view_layer, scene_collection); + if (layer_collection != NULL) { + BKE_layer_collection_objects_select(layer_collection); + return true; + } + else { + /* Slower approach, we need to iterate over all the objects and for each one we see if there is a base. */ + bool changed = false; + for (LinkData *link = scene_collection->objects.first; link; link = link->next) { + Base *base = BKE_view_layer_base_find(view_layer, link->data); + if (base != NULL) { + if (((base->flag & BASE_SELECTED) == 0) && ((base->flag & BASE_SELECTABLED) != 0)) { + base->flag |= BASE_SELECTED; + changed = true; + } + } + } + return changed; + } +} + +/** * Leave only the master collection in, remove everything else. * @param group */ diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c index 78af18fa362..65e76e619f2 100644 --- a/source/blender/blenkernel/intern/layer.c +++ b/source/blender/blenkernel/intern/layer.c @@ -1282,16 +1282,29 @@ static LayerCollection *layer_collection_add(ViewLayer *view_layer, LayerCollect /* ---------------------------------------------------------------------- */ /** - * See if render layer has the scene collection linked directly, or indirectly (nested) + * Return the first matching LayerCollection in the ViewLayer for the SceneCollection. */ -bool BKE_view_layer_has_collection(ViewLayer *view_layer, const SceneCollection *sc) +LayerCollection *BKE_layer_collection_first_from_scene_collection(ViewLayer *view_layer, const SceneCollection *scene_collection) { - for (LayerCollection *lc = view_layer->layer_collections.first; lc; lc = lc->next) { - if (find_layer_collection_by_scene_collection(lc, sc) != NULL) { - return true; + for (LayerCollection *layer_collection = view_layer->layer_collections.first; + layer_collection != NULL; + layer_collection = layer_collection->next) + { + LayerCollection *found = find_layer_collection_by_scene_collection(layer_collection, scene_collection); + + if (found != NULL) { + return found; } } - return false; + return NULL; +} + +/** + * See if view layer has the scene collection linked directly, or indirectly (nested) + */ +bool BKE_view_layer_has_collection(ViewLayer *view_layer, const SceneCollection *scene_collection) +{ + return BKE_layer_collection_first_from_scene_collection(view_layer, scene_collection) != NULL; } /** |