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>2021-10-21 08:44:05 +0300
committerCampbell Barton <ideasman42@gmail.com>2021-10-21 08:57:53 +0300
commit063c4e467da3d926fc6447418e3f04fded9c051f (patch)
tree700ae5aea6d2d0d33724a3478ecfd2e2683e9d5e /source/blender/blenloader/intern/readfile.c
parent2a047fadc021539d51f4cb37995f9bbc33d4b9f5 (diff)
Cleanup: de-duplicate function to instantiate objects
De-duplicates wm_append_loose_data_instantiate_object_base_instance_init and object_base_instance_init. Add BLO_object_instantiate_object_base_instance_init which also adds to a collection since all callers did this.
Diffstat (limited to 'source/blender/blenloader/intern/readfile.c')
-rw-r--r--source/blender/blenloader/intern/readfile.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index bc50a14ac40..ba152bbf2c6 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4471,7 +4471,7 @@ static bool object_in_any_collection(Main *bmain, Object *ob)
* 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)
+ Object *ob, ViewLayer *view_layer, const View3D *v3d, const int flag, bool set_active)
{
Base *base = BKE_view_layer_base_find(view_layer, ob);
@@ -4479,7 +4479,7 @@ static void object_base_instance_init(
base->local_view_bits |= v3d->local_view_uuid;
}
- if (set_selected) {
+ if (flag & FILE_AUTOSELECT) {
if (base->flag & BASE_SELECTABLE) {
base->flag |= BASE_SELECTED;
}
@@ -4492,6 +4492,22 @@ static void object_base_instance_init(
BKE_scene_object_base_flag_sync_from_base(base);
}
+/**
+ * Exported for link/append to create objects as well.
+ */
+void BLO_object_instantiate_object_base_instance_init(Main *bmain,
+ Collection *collection,
+ Object *ob,
+ ViewLayer *view_layer,
+ const View3D *v3d,
+ const int flag,
+ bool set_active)
+{
+ BKE_collection_object_add(bmain, collection, ob);
+
+ object_base_instance_init(ob, view_layer, v3d, flag, set_active);
+}
+
static void add_loose_objects_to_scene(Main *mainvar,
Main *bmain,
Scene *scene,
@@ -4540,13 +4556,11 @@ static void add_loose_objects_to_scene(Main *mainvar,
CLAMP_MIN(ob->id.us, 0);
ob->mode = OB_MODE_OBJECT;
- BKE_collection_object_add(bmain, active_collection, ob);
-
- 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);
+ BLO_object_instantiate_object_base_instance_init(
+ bmain, active_collection, ob, view_layer, v3d, flag, set_active);
ob->id.tag &= ~LIB_TAG_INDIRECT;
ob->id.flag &= ~LIB_INDIRECT_WEAK_LINK;
@@ -4602,13 +4616,11 @@ static void add_loose_object_data_to_scene(Main *mainvar,
id_us_plus(id);
BKE_object_materials_test(bmain, ob, ob->data);
- BKE_collection_object_add(bmain, active_collection, ob);
-
- 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);
+ BLO_object_instantiate_object_base_instance_init(
+ bmain, active_collection, ob, view_layer, v3d, flag, set_active);
copy_v3_v3(ob->loc, scene->cursor.location);
}
@@ -4641,13 +4653,12 @@ static void add_collections_to_scene(Main *mainvar,
ob->type = OB_EMPTY;
ob->empty_drawsize = U.collection_instance_empty_size;
- BKE_collection_object_add(bmain, active_collection, ob);
-
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);
+ BLO_object_instantiate_object_base_instance_init(
+ bmain, active_collection, ob, view_layer, v3d, flag, set_active);
DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION);