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:
authorBastien Montagne <bastien@blender.org>2021-09-29 16:32:53 +0300
committerBastien Montagne <bastien@blender.org>2021-09-29 18:10:42 +0300
commitdf9120b365380cc1d64006e0d37a650eaaff9776 (patch)
treea503aa77796a9ce9eb57495484c0dd8e15a3112a
parent6aac892fad9e6447cf7cfdaee5c2e9c61e2e99fe (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
-rw-r--r--source/blender/editors/interface/interface.c7
-rw-r--r--source/blender/windowmanager/WM_types.h7
-rw-r--r--source/blender/windowmanager/intern/wm_dragdrop.c36
3 files changed, 43 insertions, 7 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index beee622673c..a98af00572d 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -6224,6 +6224,13 @@ void UI_but_drag_set_asset(uiBut *but,
asset_drag->id_type = ED_asset_handle_get_id_type(asset);
asset_drag->import_type = import_type;
+ /* FIXME: This is temporary evil solution to get scene/viewlayer/etc in the copy callback of the
+ * #wmDropBox.
+ * TODO: Handle link/append in operator called at the end of the drop process, and NOT in its
+ * copy callback.
+ * */
+ asset_drag->evil_C = but->block->evil_C;
+
but->dragtype = WM_DRAG_ASSET;
ui_def_but_icon(but, icon, 0); /* no flag UI_HAS_ICON, so icon doesn't draw in button */
if (but->dragflag & UI_BUT_DRAGPOIN_FREE) {
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index df6dc3af3cb..d0690cfd738 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -944,6 +944,13 @@ typedef struct wmDragAsset {
const char *path;
int id_type;
int import_type; /* eFileAssetImportType */
+
+ /* FIXME: This is temporary evil solution to get scene/viewlayer/etc in the copy callback of the
+ * #wmDropBox.
+ * TODO: Handle link/append in operator called at the end of the drop process, and NOT in its
+ * copy callback.
+ * */
+ struct bContext *evil_C;
} wmDragAsset;
typedef char *(*WMDropboxTooltipFunc)(struct bContext *,
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);
}