Cleanup: de-duplicate code for instancing objects when linking
Ref D8843
This commit is contained in:
parent
605425c006
commit
a51455918c
|
@ -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;
|
||||
}
|
||||
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);
|
||||
|
||||
if ((flag & FILE_AUTOSELECT) && (base->flag & BASE_SELECTABLE)) {
|
||||
base->flag |= BASE_SELECTED;
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue