[Bf-blender-cvs] [92a06831a84] asset-engine: Add drag'n'drop-linking of material onto object in 3DView.

Bastien Montagne noreply at git.blender.org
Mon Oct 30 17:36:17 CET 2017


Commit: 92a06831a84ded45dabc5860ddf72b2e0556328a
Author: Bastien Montagne
Date:   Mon Oct 30 17:35:18 2017 +0100
Branches: asset-engine
https://developer.blender.org/rB92a06831a84ded45dabc5860ddf72b2e0556328a

Add drag'n'drop-linking of material onto object in 3DView.

Probably needs to be reorganized a bit better, but basically working.

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

M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/windowmanager/intern/wm_files_link.c

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

diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index 3353c475848..fc268ddc117 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -588,7 +588,7 @@ static void view3d_main_region_exit(wmWindowManager *wm, ARegion *ar)
 	}
 }
 
-static int view3d_path_link_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *event)
+static int view3d_path_link_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
 {
 	if (event->shift == false) {
 		if (drag->type == WM_DRAG_LIBRARY) {
@@ -601,6 +601,11 @@ static int view3d_path_link_drop_poll(bContext *UNUSED(C), wmDrag *drag, const w
 			switch (BKE_idcode_from_name(group)) {
 				case ID_OB:
 					return 1;
+				case ID_MA:
+				{
+					Base *base = ED_view3d_give_base_under_cursor(C, event->mval);
+					return (base != NULL && base->object->id.lib == NULL);
+				}
 			}
 		}
 	}
@@ -691,6 +696,7 @@ static void view3d_path_link_drop_copy(wmDrag *drag, wmDropBox *drop)
 	RNA_string_set(drop->ptr, "asset_engine", drag_data->ae_idname);
 	RNA_string_set(drop->ptr, "directory", "");
 	RNA_string_set(drop->ptr, "filename", drag_data->path);
+	RNA_string_set(drop->ptr, "filepath", drag_data->path);  /* Needed only to avoid invoke to open filebrowser. */
 	RNA_int_set_array(drop->ptr, "uuid_repository", drag_data->uuid.uuid_repository);
 	RNA_int_set_array(drop->ptr, "uuid_asset", drag_data->uuid.uuid_asset);
 	RNA_int_set_array(drop->ptr, "uuid_variant", drag_data->uuid.uuid_variant);
@@ -738,11 +744,9 @@ static void view3d_id_path_drop_copy(wmDrag *drag, wmDropBox *drop)
 /* region dropbox definition */
 static void view3d_dropboxes(void)
 {
-	wmDropBox *drop;
 	ListBase *lb = WM_dropboxmap_find("View3D", SPACE_VIEW3D, RGN_TYPE_WINDOW);
 	
-	drop = WM_dropbox_add(lb, "WM_OT_link", view3d_path_link_drop_poll, view3d_path_link_drop_copy);
-	drop->opcontext = WM_OP_EXEC_DEFAULT;
+	WM_dropbox_add(lb, "WM_OT_link", view3d_path_link_drop_poll, view3d_path_link_drop_copy);
 	WM_dropbox_add(lb, "OBJECT_OT_add_named", view3d_ob_drop_poll, view3d_ob_drop_copy);
 	WM_dropbox_add(lb, "OBJECT_OT_drop_named_material", view3d_mat_drop_poll, view3d_id_drop_copy);
 	WM_dropbox_add(lb, "MESH_OT_drop_named_image", view3d_ima_mesh_drop_poll, view3d_id_path_drop_copy);
diff --git a/source/blender/windowmanager/intern/wm_files_link.c b/source/blender/windowmanager/intern/wm_files_link.c
index 613bed5fa90..872447c9945 100644
--- a/source/blender/windowmanager/intern/wm_files_link.c
+++ b/source/blender/windowmanager/intern/wm_files_link.c
@@ -42,6 +42,8 @@
 #include "MEM_guardedalloc.h"
 
 #include "DNA_ID.h"
+#include "DNA_material_types.h"
+#include "DNA_object_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_space_types.h"
@@ -68,6 +70,7 @@
 #include "BKE_library.h"
 #include "BKE_library_override.h"
 #include "BKE_library_remap.h"
+#include "BKE_material.h"
 #include "BKE_global.h"
 #include "BKE_image.h"
 #include "BKE_main.h"
@@ -82,6 +85,7 @@
 
 #include "ED_screen.h"
 #include "ED_fileselect.h"
+#include "ED_view3d.h"
 
 #include "GPU_material.h"
 
@@ -108,8 +112,10 @@ static int wm_link_append_poll(bContext *C)
 	return 0;
 }
 
-static int wm_link_append_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+static int wm_link_append_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
+	RNA_int_set_array(op->ptr, "mouse_coordinates", event->mval);
+
 	if (RNA_struct_property_is_set(op->ptr, "filepath")) {
 		return WM_operator_call_notest(C, op);
 	}
@@ -564,6 +570,25 @@ static int wm_link_append_exec(bContext *C, wmOperator *op)
 
 	/* BKE_main_unlock(bmain); */
 
+	/* Try to do smart things from context in some cases (like drag'n'drop of material over object...) */
+	prop = RNA_struct_find_property(op->ptr, "mouse_coordinates");
+	if (prop && RNA_property_is_set(op->ptr, prop)) {
+		int mval[2];
+		RNA_property_int_get_array(op->ptr, prop, mval);
+		Base *obbase = ED_view3d_give_base_under_cursor(C, mval);
+		if (obbase) {
+			LinkNode *itemlink;
+			for (itemlink = lapp_data->items.list; itemlink; itemlink = itemlink->next) {
+				ID *new_id = ((WMLinkAppendDataItem *)(itemlink->link))->new_id;
+
+				if (new_id && GS(new_id->name) == ID_MA) {
+					assign_material(obbase->object, (Material *)new_id, obbase->object->actcol, BKE_MAT_ASSIGN_USERPREF);
+				}
+			}
+		}
+		printf("%s\n", obbase ? obbase->object->id.name : "<NULL>");
+	}
+
 	/* mark all library linked objects to be updated */
 	BKE_main_lib_objects_recalc_all(bmain);
 	IMB_colormanagement_check_file_config(bmain);
@@ -636,6 +661,11 @@ static void wm_link_append_properties_common(wmOperatorType *ot, bool is_link)
 	prop = RNA_def_boolean(ot->srna, "instance_groups", is_link,
 	                       "Instance Groups", "Create Dupli-Group instances for each group");
 	RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+
+	prop = RNA_def_int_vector(ot->srna, "mouse_coordinates", 2, (const int [2]){0, 0}, INT_MIN, INT_MAX, "Mouse Coordinates",
+	                          "Store sompe mouse coordinates (e.g. to get object on which linked material was dropped...)",
+	                          INT_MIN, INT_MAX);
+	RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_HIDDEN);
 }
 
 void WM_OT_link(wmOperatorType *ot)



More information about the Bf-blender-cvs mailing list