diff options
author | Bastien Montagne <bastien@blender.org> | 2021-09-29 16:32:53 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2021-09-29 18:10:42 +0300 |
commit | df9120b365380cc1d64006e0d37a650eaaff9776 (patch) | |
tree | a503aa77796a9ce9eb57495484c0dd8e15a3112a /source/blender/windowmanager/intern/wm_dragdrop.c | |
parent | 6aac892fad9e6447cf7cfdaee5c2e9c61e2e99fe (diff) |
Fix T89864: Adding an asset referencing other objects adds it to scene but only adds data-blocks of referenced objects.
Link/append code needs proper access to scene/view3d data to handle
collections/objects instantiation.
Note that this is a temporary hack more than a proper fix, which would require
a deeper redesign of drag&drop code.
Also note that this will not handle 'properly' (i.e. as user would
expect it) cases like implicitely appended parent objects, in that only
the explicitely appended object will be dropped to the nes location, the
others will remain at their original coordinates.
Differential Revision: https://developer.blender.org/D12696
Diffstat (limited to 'source/blender/windowmanager/intern/wm_dragdrop.c')
-rw-r--r-- | source/blender/windowmanager/intern/wm_dragdrop.c | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/source/blender/windowmanager/intern/wm_dragdrop.c b/source/blender/windowmanager/intern/wm_dragdrop.c index 93038b5709c..c5a89e3ad9f 100644 --- a/source/blender/windowmanager/intern/wm_dragdrop.c +++ b/source/blender/windowmanager/intern/wm_dragdrop.c @@ -42,6 +42,7 @@ #include "BKE_global.h" #include "BKE_idtype.h" #include "BKE_lib_id.h" +#include "BKE_main.h" #include "BLO_readfile.h" @@ -392,21 +393,42 @@ static ID *wm_drag_asset_id_import(wmDragAsset *asset_drag) const char *name = asset_drag->name; ID_Type idtype = asset_drag->id_type; + /* FIXME: Link/Append should happens in the operator called at the end of drop process, not from + * here. */ + + Main *bmain = CTX_data_main(asset_drag->evil_C); + Scene *scene = CTX_data_scene(asset_drag->evil_C); + ViewLayer *view_layer = CTX_data_view_layer(asset_drag->evil_C); + View3D *view3d = CTX_wm_view3d(asset_drag->evil_C); + switch ((eFileAssetImportType)asset_drag->import_type) { case FILE_ASSET_IMPORT_LINK: - return WM_file_link_datablock(G_MAIN, NULL, NULL, NULL, asset_drag->path, idtype, name, 0); + return WM_file_link_datablock(bmain, + scene, + view_layer, + view3d, + asset_drag->path, + idtype, + name, + FILE_ACTIVE_COLLECTION); case FILE_ASSET_IMPORT_APPEND: - return WM_file_append_datablock( - G_MAIN, NULL, NULL, NULL, asset_drag->path, idtype, name, BLO_LIBLINK_APPEND_RECURSIVE); + return WM_file_append_datablock(bmain, + scene, + view_layer, + view3d, + asset_drag->path, + idtype, + name, + BLO_LIBLINK_APPEND_RECURSIVE | FILE_ACTIVE_COLLECTION); case FILE_ASSET_IMPORT_APPEND_REUSE: return WM_file_append_datablock(G_MAIN, - NULL, - NULL, - NULL, + scene, + view_layer, + view3d, asset_drag->path, idtype, name, - BLO_LIBLINK_APPEND_RECURSIVE | + BLO_LIBLINK_APPEND_RECURSIVE | FILE_ACTIVE_COLLECTION | BLO_LIBLINK_APPEND_LOCAL_ID_REUSE); } |