[Bf-blender-cvs] [df9120b3653] master: Fix T89864: Adding an asset referencing other objects adds it to scene but only adds data-blocks of referenced objects.

Bastien Montagne noreply at git.blender.org
Wed Sep 29 17:10:49 CEST 2021


Commit: df9120b365380cc1d64006e0d37a650eaaff9776
Author: Bastien Montagne
Date:   Wed Sep 29 15:32:53 2021 +0200
Branches: master
https://developer.blender.org/rBdf9120b365380cc1d64006e0d37a650eaaff9776

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

===================================================================

M	source/blender/editors/interface/interface.c
M	source/blender/windowmanager/WM_types.h
M	source/blender/windowmanager/intern/wm_dragdrop.c

===================================================================

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);
   }



More information about the Bf-blender-cvs mailing list