[Bf-blender-cvs] [2fec46c3e61] master: Asset Browser: Support dragging in object-data assets (meshes, curves, etc.)

Julian Eisel noreply at git.blender.org
Sun Jan 24 22:34:36 CET 2021


Commit: 2fec46c3e614c10cadef945855747d0f3f251fd4
Author: Julian Eisel
Date:   Sun Jan 24 22:17:06 2021 +0100
Branches: master
https://developer.blender.org/rB2fec46c3e614c10cadef945855747d0f3f251fd4

Asset Browser: Support dragging in object-data assets (meshes, curves, etc.)

The Asset Browser already displayed object-data assets, but you couldn't
actually drag & drop them. This is now supported.

The object-data drop poll needed access to the data-block. But with a small
tweak it doesn't need that and can just check the ID type (which is known for
asset dragging too).

Part of T82661.

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

M	source/blender/editors/space_view3d/space_view3d.c

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

diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index 9f7cf48da0c..215166a6158 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -468,16 +468,30 @@ static bool view3d_drop_in_main_region_poll(bContext *C, const wmEvent *event)
   return ED_region_overlap_isect_any_xy(area, &event->x) == false;
 }
 
-static ID *view3d_drop_id_in_main_region_poll_id(bContext *C,
-                                                 wmDrag *drag,
-                                                 const wmEvent *event,
-                                                 ID_Type id_type)
+static ID_Type view3d_drop_id_in_main_region_poll_get_id_type(bContext *C,
+                                                              wmDrag *drag,
+                                                              const wmEvent *event)
 {
-  ScrArea *area = CTX_wm_area(C);
+  const ScrArea *area = CTX_wm_area(C);
+
   if (ED_region_overlap_isect_any_xy(area, &event->x)) {
-    return NULL;
+    return 0;
+  }
+  if (!view3d_drop_in_main_region_poll(C, event)) {
+    return 0;
+  }
+
+  ID *local_id = WM_drag_get_local_ID(drag, 0);
+  if (local_id) {
+    return GS(local_id->name);
+  }
+
+  wmDragAsset *asset_drag = WM_drag_get_asset_data(drag, 0);
+  if (asset_drag) {
+    return asset_drag->id_type;
   }
-  return view3d_drop_in_main_region_poll(C, event) ? WM_drag_get_local_ID(drag, id_type) : NULL;
+
+  return 0;
 }
 
 static bool view3d_drop_id_in_main_region_poll(bContext *C,
@@ -521,9 +535,9 @@ static bool view3d_object_data_drop_poll(bContext *C,
                                          const wmEvent *event,
                                          const char **r_tooltip)
 {
-  ID *id = view3d_drop_id_in_main_region_poll_id(C, drag, event, 0);
-  if (id != NULL) {
-    if (BKE_object_obdata_to_type(id) != -1) {
+  ID_Type id_type = view3d_drop_id_in_main_region_poll_get_id_type(C, drag, event);
+  if (id_type) {
+    if (OB_DATA_SUPPORT_ID(id_type)) {
       *r_tooltip = TIP_("Create object instance from object-data");
       return true;
     }
@@ -628,7 +642,7 @@ static void view3d_id_drop_copy(wmDrag *drag, wmDropBox *drop)
 
 static void view3d_id_drop_copy_with_type(wmDrag *drag, wmDropBox *drop)
 {
-  ID *id = WM_drag_get_local_ID(drag, 0);
+  ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, 0);
 
   RNA_string_set(drop->ptr, "name", id->name + 2);
   RNA_enum_set(drop->ptr, "type", GS(id->name));



More information about the Bf-blender-cvs mailing list