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
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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 *,
|
||||
|
||||
@@ -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);
|
||||
case FILE_ASSET_IMPORT_APPEND_REUSE:
|
||||
return WM_file_append_datablock(G_MAIN,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
return WM_file_append_datablock(bmain,
|
||||
scene,
|
||||
view_layer,
|
||||
view3d,
|
||||
asset_drag->path,
|
||||
idtype,
|
||||
name,
|
||||
BLO_LIBLINK_APPEND_RECURSIVE |
|
||||
BLO_LIBLINK_APPEND_RECURSIVE | FILE_ACTIVE_COLLECTION);
|
||||
case FILE_ASSET_IMPORT_APPEND_REUSE:
|
||||
return WM_file_append_datablock(G_MAIN,
|
||||
scene,
|
||||
view_layer,
|
||||
view3d,
|
||||
asset_drag->path,
|
||||
idtype,
|
||||
name,
|
||||
BLO_LIBLINK_APPEND_RECURSIVE | FILE_ACTIVE_COLLECTION |
|
||||
BLO_LIBLINK_APPEND_LOCAL_ID_REUSE);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user