Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2020-11-06 07:00:07 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-11-06 07:00:07 +0300
commita51455918cb9289224d56fa0e756c6abc801dc32 (patch)
tree146c65a05ec514ef61b534c7b31d0f2726512919 /source/blender/blenloader/intern/readfile.c
parent605425c0063f2e357df5a00056c2ca3439e46533 (diff)
Cleanup: de-duplicate code for instancing objects when linking
Ref D8843
Diffstat (limited to 'source/blender/blenloader/intern/readfile.c')
-rw-r--r--source/blender/blenloader/intern/readfile.c77
1 files changed, 40 insertions, 37 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 080e22c68b9..855d320a63d 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -7069,6 +7069,31 @@ static bool object_in_any_collection(Main *bmain, Object *ob)
return false;
}
+/**
+ * Shared operations to perform on the object's base after adding it to the scene.
+ */
+static void object_base_instance_init(
+ Object *ob, bool set_selected, bool set_active, ViewLayer *view_layer, const View3D *v3d)
+{
+ Base *base = BKE_view_layer_base_find(view_layer, ob);
+
+ if (v3d != NULL) {
+ base->local_view_bits |= v3d->local_view_uuid;
+ }
+
+ if (set_selected) {
+ if (base->flag & BASE_SELECTABLE) {
+ base->flag |= BASE_SELECTED;
+ }
+ }
+
+ if (set_active) {
+ view_layer->basact = base;
+ }
+
+ BKE_scene_object_base_flag_sync_from_base(base);
+}
+
static void add_loose_objects_to_scene(Main *mainvar,
Main *bmain,
Scene *scene,
@@ -7114,19 +7139,12 @@ static void add_loose_objects_to_scene(Main *mainvar,
ob->mode = OB_MODE_OBJECT;
BKE_collection_object_add(bmain, active_collection, ob);
- Base *base = BKE_view_layer_base_find(view_layer, ob);
- if (v3d != NULL) {
- base->local_view_bits |= v3d->local_view_uuid;
- }
-
- if ((flag & FILE_AUTOSELECT) && (base->flag & BASE_SELECTABLE)) {
- /* Do NOT make base active here! screws up GUI stuff,
- * if you want it do it at the editor level. */
- base->flag |= BASE_SELECTED;
- }
-
- BKE_scene_object_base_flag_sync_from_base(base);
+ const bool set_selected = (flag & FILE_AUTOSELECT) != 0;
+ /* Do NOT make base active here! screws up GUI stuff,
+ * if you want it do it at the editor level. */
+ const bool set_active = false;
+ object_base_instance_init(ob, set_selected, set_active, view_layer, v3d);
ob->id.tag &= ~LIB_TAG_INDIRECT;
ob->id.flag &= ~LIB_INDIRECT_WEAK_LINK;
@@ -7172,19 +7190,12 @@ static void add_loose_object_data_to_scene(Main *mainvar,
BKE_object_materials_test(bmain, ob, ob->data);
BKE_collection_object_add(bmain, active_collection, ob);
- Base *base = BKE_view_layer_base_find(view_layer, ob);
- if (v3d != NULL) {
- base->local_view_bits |= v3d->local_view_uuid;
- }
-
- if ((flag & FILE_AUTOSELECT) && (base->flag & BASE_SELECTABLE)) {
- /* Do NOT make base active here! screws up GUI stuff,
- * if you want it do it at the editor level. */
- base->flag |= BASE_SELECTED;
- }
-
- BKE_scene_object_base_flag_sync_from_base(base);
+ const bool set_selected = (flag & FILE_AUTOSELECT) != 0;
+ /* Do NOT make base active here! screws up GUI stuff,
+ * if you want it do it at the editor level. */
+ bool set_active = false;
+ object_base_instance_init(ob, set_selected, set_active, view_layer, v3d);
copy_v3_v3(ob->loc, scene->cursor.location);
}
@@ -7218,23 +7229,15 @@ static void add_collections_to_scene(Main *mainvar,
ob->empty_drawsize = U.collection_instance_empty_size;
BKE_collection_object_add(bmain, active_collection, ob);
- Base *base = BKE_view_layer_base_find(view_layer, ob);
-
- if (v3d != NULL) {
- base->local_view_bits |= v3d->local_view_uuid;
- }
- if ((flag & FILE_AUTOSELECT) && (base->flag & BASE_SELECTABLE)) {
- base->flag |= BASE_SELECTED;
- }
+ const bool set_selected = (flag & FILE_AUTOSELECT) != 0;
+ /* TODO: why is it OK to make this active here but not in other situations?
+ * See other callers of #object_base_instance_init */
+ const bool set_active = set_selected;
+ object_base_instance_init(ob, set_selected, set_active, view_layer, v3d);
- BKE_scene_object_base_flag_sync_from_base(base);
DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION);
- if (flag & FILE_AUTOSELECT) {
- view_layer->basact = base;
- }
-
/* Assign the collection. */
ob->instance_collection = collection;
id_us_plus(&collection->id);