Fix paste/append w/ local-view
Paste in local-view wasn't setting local-view bits.
This commit is contained in:
parent
afc4cd1e67
commit
372fd07a8e
Notes:
blender-bot
2023-02-14 11:01:33 +01:00
Referenced by issue #59529, Auto Smooth Angle Ignored in Object Mode
|
@ -98,7 +98,7 @@ bool BKE_copybuffer_read(Main *bmain_dst, const char *libname, ReportList *repor
|
|||
/* Here appending/linking starts. */
|
||||
Main *mainl = BLO_library_link_begin(bmain_dst, &bh, libname);
|
||||
BLO_library_link_copypaste(mainl, bh);
|
||||
BLO_library_link_end(mainl, &bh, 0, NULL, NULL, NULL);
|
||||
BLO_library_link_end(mainl, &bh, 0, NULL, NULL, NULL, NULL);
|
||||
/* Mark all library linked objects to be updated. */
|
||||
BKE_main_lib_objects_recalc_all(bmain_dst);
|
||||
IMB_colormanagement_check_file_config(bmain_dst);
|
||||
|
@ -121,6 +121,7 @@ bool BKE_copybuffer_paste(bContext *C, const char *libname, const short flag, Re
|
|||
Main *bmain = CTX_data_main(C);
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
View3D *v3d = CTX_wm_view3d(C); /* may be NULL. */
|
||||
Main *mainl = NULL;
|
||||
Library *lib;
|
||||
BlendHandle *bh;
|
||||
|
@ -145,7 +146,7 @@ bool BKE_copybuffer_paste(bContext *C, const char *libname, const short flag, Re
|
|||
|
||||
BLO_library_link_copypaste(mainl, bh);
|
||||
|
||||
BLO_library_link_end(mainl, &bh, flag, bmain, scene, view_layer);
|
||||
BLO_library_link_end(mainl, &bh, flag, bmain, scene, view_layer, v3d);
|
||||
|
||||
/* mark all library linked objects to be updated */
|
||||
BKE_main_lib_objects_recalc_all(bmain);
|
||||
|
|
|
@ -142,10 +142,10 @@ struct ID *BLO_library_link_named_part(struct Main *mainl, BlendHandle **bh, con
|
|||
struct ID *BLO_library_link_named_part_ex(
|
||||
struct Main *mainl, BlendHandle **bh,
|
||||
const short idcode, const char *name, const int flag,
|
||||
struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer);
|
||||
struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer, const struct View3D *v3d);
|
||||
void BLO_library_link_end(
|
||||
struct Main *mainl, BlendHandle **bh, int flag,
|
||||
struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer);
|
||||
struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer, const struct View3D *v3d);
|
||||
|
||||
void BLO_library_link_copypaste(struct Main *mainl, BlendHandle *bh);
|
||||
|
||||
|
|
|
@ -10268,7 +10268,8 @@ static Collection *get_collection_active(
|
|||
}
|
||||
|
||||
static void add_loose_objects_to_scene(
|
||||
Main *mainvar, Main *bmain, Scene *scene, ViewLayer *view_layer, Library *lib, const short flag)
|
||||
Main *mainvar, Main *bmain,
|
||||
Scene *scene, ViewLayer *view_layer, const View3D *v3d, Library *lib, const short flag)
|
||||
{
|
||||
const bool is_link = (flag & FILE_LINK) != 0;
|
||||
|
||||
|
@ -10296,6 +10297,11 @@ static void add_loose_objects_to_scene(
|
|||
Collection *active_collection = get_collection_active(bmain, scene, view_layer, FILE_ACTIVE_COLLECTION);
|
||||
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;
|
||||
}
|
||||
|
||||
BKE_scene_object_base_flag_sync_from_base(base);
|
||||
|
||||
if (flag & FILE_AUTOSELECT) {
|
||||
|
@ -10316,7 +10322,8 @@ static void add_loose_objects_to_scene(
|
|||
}
|
||||
|
||||
static void add_collections_to_scene(
|
||||
Main *mainvar, Main *bmain, Scene *scene, ViewLayer *view_layer, Library *UNUSED(lib), const short flag)
|
||||
Main *mainvar, Main *bmain,
|
||||
Scene *scene, ViewLayer *view_layer, const View3D *v3d, Library *UNUSED(lib), const short flag)
|
||||
{
|
||||
Collection *active_collection = get_collection_active(bmain, scene, view_layer, FILE_ACTIVE_COLLECTION);
|
||||
|
||||
|
@ -10334,6 +10341,10 @@ static void add_collections_to_scene(
|
|||
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 (base->flag & BASE_SELECTABLE) {
|
||||
base->flag |= BASE_SELECTED;
|
||||
}
|
||||
|
@ -10428,7 +10439,8 @@ static ID *link_named_part(
|
|||
return id;
|
||||
}
|
||||
|
||||
static void link_object_postprocess(ID *id, Main *bmain, Scene *scene, ViewLayer *view_layer, const int flag)
|
||||
static void link_object_postprocess(
|
||||
ID *id, Main *bmain, Scene *scene, ViewLayer *view_layer, const View3D *v3d, const int flag)
|
||||
{
|
||||
if (scene) {
|
||||
/* link to scene */
|
||||
|
@ -10444,6 +10456,11 @@ static void link_object_postprocess(ID *id, Main *bmain, Scene *scene, ViewLayer
|
|||
base = BKE_view_layer_base_find(view_layer, ob);
|
||||
BKE_scene_object_base_flag_sync_from_base(base);
|
||||
|
||||
/* Link at active local view (view3d if available in context. */
|
||||
if (v3d != NULL) {
|
||||
base->local_view_bits |= v3d->local_view_uuid;
|
||||
}
|
||||
|
||||
if (flag & FILE_AUTOSELECT) {
|
||||
if (base->flag & BASE_SELECTABLE) {
|
||||
base->flag |= BASE_SELECTED;
|
||||
|
@ -10491,12 +10508,12 @@ void BLO_library_link_copypaste(Main *mainl, BlendHandle *bh)
|
|||
|
||||
static ID *link_named_part_ex(
|
||||
Main *mainl, FileData *fd, const short idcode, const char *name, const int flag,
|
||||
Main *bmain, Scene *scene, ViewLayer *view_layer)
|
||||
Main *bmain, Scene *scene, ViewLayer *view_layer, const View3D *v3d)
|
||||
{
|
||||
ID *id = link_named_part(mainl, fd, idcode, name, flag);
|
||||
|
||||
if (id && (GS(id->name) == ID_OB)) { /* loose object: give a base */
|
||||
link_object_postprocess(id, bmain, scene, view_layer, flag);
|
||||
link_object_postprocess(id, bmain, scene, view_layer, v3d, flag);
|
||||
}
|
||||
else if (id && (GS(id->name) == ID_GR)) {
|
||||
/* tag as needing to be instantiated or linked */
|
||||
|
@ -10537,10 +10554,10 @@ ID *BLO_library_link_named_part(Main *mainl, BlendHandle **bh, const short idcod
|
|||
ID *BLO_library_link_named_part_ex(
|
||||
Main *mainl, BlendHandle **bh,
|
||||
const short idcode, const char *name, const int flag,
|
||||
Main *bmain, Scene *scene, ViewLayer *view_layer)
|
||||
Main *bmain, Scene *scene, ViewLayer *view_layer, const View3D *v3d)
|
||||
{
|
||||
FileData *fd = (FileData *)(*bh);
|
||||
return link_named_part_ex(mainl, fd, idcode, name, flag, bmain, scene, view_layer);
|
||||
return link_named_part_ex(mainl, fd, idcode, name, flag, bmain, scene, view_layer, v3d);
|
||||
}
|
||||
|
||||
static void link_id_part(ReportList *reports, FileData *fd, Main *mainvar, ID *id, ID **r_id)
|
||||
|
@ -10653,7 +10670,9 @@ static void split_main_newid(Main *mainptr, Main *main_newid)
|
|||
}
|
||||
|
||||
/* scene and v3d may be NULL. */
|
||||
static void library_link_end(Main *mainl, FileData **fd, const short flag, Main *bmain, Scene *scene, ViewLayer *view_layer)
|
||||
static void library_link_end(
|
||||
Main *mainl, FileData **fd, const short flag, Main *bmain,
|
||||
Scene *scene, ViewLayer *view_layer, const View3D *v3d)
|
||||
{
|
||||
Main *mainvar;
|
||||
Library *curlib;
|
||||
|
@ -10711,8 +10730,8 @@ static void library_link_end(Main *mainl, FileData **fd, const short flag, Main
|
|||
* Only directly linked objects & collections are instantiated by `BLO_library_link_named_part_ex()` & co,
|
||||
* here we handle indirect ones and other possible edge-cases. */
|
||||
if (scene) {
|
||||
add_collections_to_scene(mainvar, bmain, scene, view_layer, curlib, flag);
|
||||
add_loose_objects_to_scene(mainvar, bmain, scene, view_layer, curlib, flag);
|
||||
add_collections_to_scene(mainvar, bmain, scene, view_layer, v3d, curlib, flag);
|
||||
add_loose_objects_to_scene(mainvar, bmain, scene, view_layer, v3d, curlib, flag);
|
||||
}
|
||||
else {
|
||||
/* printf("library_append_end, scene is NULL (objects wont get bases)\n"); */
|
||||
|
@ -10739,11 +10758,14 @@ static void library_link_end(Main *mainl, FileData **fd, const short flag, Main
|
|||
* \param bmain: The main database in which to instantiate objects/collections
|
||||
* \param scene: The scene in which to instantiate objects/collections (if NULL, no instantiation is done).
|
||||
* \param view_layer: The scene layer in which to instantiate objects/collections (if NULL, no instantiation is done).
|
||||
* \param v3d: The active View3D (only to define local-view for instantiated objects & groups, can be NULL).
|
||||
*/
|
||||
void BLO_library_link_end(Main *mainl, BlendHandle **bh, int flag, Main *bmain, Scene *scene, ViewLayer *view_layer)
|
||||
void BLO_library_link_end(
|
||||
Main *mainl, BlendHandle **bh, int flag, Main *bmain,
|
||||
Scene *scene, ViewLayer *view_layer, const View3D *v3d)
|
||||
{
|
||||
FileData *fd = (FileData *)(*bh);
|
||||
library_link_end(mainl, &fd, flag, bmain, scene, view_layer);
|
||||
library_link_end(mainl, &fd, flag, bmain, scene, view_layer, v3d);
|
||||
*bh = (BlendHandle *)fd;
|
||||
}
|
||||
|
||||
|
|
|
@ -403,7 +403,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
|
|||
}
|
||||
else {
|
||||
Library *lib = mainl->curlib; /* newly added lib, assign before append end */
|
||||
BLO_library_link_end(mainl, &(self->blo_handle), self->flag, NULL, NULL, NULL);
|
||||
BLO_library_link_end(mainl, &(self->blo_handle), self->flag, NULL, NULL, NULL, NULL);
|
||||
BLO_blendhandle_close(self->blo_handle);
|
||||
self->blo_handle = NULL;
|
||||
|
||||
|
|
|
@ -210,7 +210,8 @@ static WMLinkAppendDataItem *wm_link_append_data_item_add(
|
|||
}
|
||||
|
||||
static void wm_link_do(
|
||||
WMLinkAppendData *lapp_data, ReportList *reports, Main *bmain, Scene *scene, ViewLayer *view_layer)
|
||||
WMLinkAppendData *lapp_data, ReportList *reports, Main *bmain,
|
||||
Scene *scene, ViewLayer *view_layer, const View3D *v3d)
|
||||
{
|
||||
Main *mainl;
|
||||
BlendHandle *bh;
|
||||
|
@ -262,7 +263,9 @@ static void wm_link_do(
|
|||
continue;
|
||||
}
|
||||
|
||||
new_id = BLO_library_link_named_part_ex(mainl, &bh, item->idcode, item->name, flag, bmain, scene, view_layer);
|
||||
new_id = BLO_library_link_named_part_ex(
|
||||
mainl, &bh, item->idcode, item->name, flag, bmain,
|
||||
scene, view_layer, v3d);
|
||||
|
||||
if (new_id) {
|
||||
/* If the link is successful, clear item's libs 'todo' flags.
|
||||
|
@ -272,7 +275,7 @@ static void wm_link_do(
|
|||
}
|
||||
}
|
||||
|
||||
BLO_library_link_end(mainl, &bh, flag, bmain, scene, view_layer);
|
||||
BLO_library_link_end(mainl, &bh, flag, bmain, scene, view_layer, v3d);
|
||||
BLO_blendhandle_close(bh);
|
||||
}
|
||||
}
|
||||
|
@ -449,7 +452,7 @@ static int wm_link_append_exec(bContext *C, wmOperator *op)
|
|||
/* XXX We'd need re-entrant locking on Main for this to work... */
|
||||
/* BKE_main_lock(bmain); */
|
||||
|
||||
wm_link_do(lapp_data, op->reports, bmain, scene, view_layer);
|
||||
wm_link_do(lapp_data, op->reports, bmain, scene, view_layer, CTX_wm_view3d(C));
|
||||
|
||||
/* BKE_main_unlock(bmain); */
|
||||
|
||||
|
@ -647,7 +650,7 @@ static void lib_relocate_do(
|
|||
BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, true);
|
||||
|
||||
/* We do not want any instantiation here! */
|
||||
wm_link_do(lapp_data, reports, bmain, NULL, NULL);
|
||||
wm_link_do(lapp_data, reports, bmain, NULL, NULL, NULL);
|
||||
|
||||
BKE_main_lock(bmain);
|
||||
|
||||
|
|
Loading…
Reference in New Issue