[Bf-blender-cvs] [5caa6022eff] temp-T90576-asset-browser-drop-on-material-slot: Asset: Dropping Material assets on material slot under mouse cursor.

Jeroen Bakker noreply at git.blender.org
Wed Aug 11 11:10:51 CEST 2021


Commit: 5caa6022effa4d9ae71155ae9d7fad58c7a65eec
Author: Jeroen Bakker
Date:   Wed Aug 11 09:14:09 2021 +0200
Branches: temp-T90576-asset-browser-drop-on-material-slot
https://developer.blender.org/rB5caa6022effa4d9ae71155ae9d7fad58c7a65eec

Asset: Dropping Material assets on material slot under mouse cursor.

This patch allows dropping material assets from material slot under the mouse
cursor. Before this change the material slot had to be hand-picked from the
properties panel.

Differential Revision: https://developer.blender.org/D12190

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

M	source/blender/draw/DRW_engine.h
M	source/blender/draw/engines/basic/basic_engine.c
M	source/blender/draw/intern/DRW_render.h
M	source/blender/draw/intern/draw_manager.c
M	source/blender/draw/intern/draw_manager.h
M	source/blender/draw/intern/draw_manager_data.c
M	source/blender/editors/include/ED_view3d.h
M	source/blender/editors/space_view3d/view3d_select.c
M	source/blender/editors/space_view3d/view3d_view.c

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

diff --git a/source/blender/draw/DRW_engine.h b/source/blender/draw/DRW_engine.h
index 8a35ab2aeb9..a125a13eaf9 100644
--- a/source/blender/draw/DRW_engine.h
+++ b/source/blender/draw/DRW_engine.h
@@ -110,6 +110,7 @@ void DRW_draw_select_loop(struct Depsgraph *depsgraph,
                           bool use_obedit_skip,
                           bool draw_surface,
                           bool use_nearest,
+                          const bool do_material_sub_selection,
                           const struct rcti *rect,
                           DRW_SelectPassFn select_pass_fn,
                           void *select_pass_user_data,
diff --git a/source/blender/draw/engines/basic/basic_engine.c b/source/blender/draw/engines/basic/basic_engine.c
index c120df7e897..6f6dc898d1c 100644
--- a/source/blender/draw/engines/basic/basic_engine.c
+++ b/source/blender/draw/engines/basic/basic_engine.c
@@ -80,6 +80,7 @@ typedef struct BASIC_PrivateData {
   DRWShadingGroup *depth_shgrp[2];
   DRWShadingGroup *depth_shgrp_cull[2];
   DRWShadingGroup *depth_hair_shgrp[2];
+  bool use_material_slot_selection;
 } BASIC_PrivateData; /* Transient data */
 
 /* Functions */
@@ -131,6 +132,8 @@ static void basic_cache_init(void *vedata)
     stl->g_data = MEM_callocN(sizeof(*stl->g_data), __func__);
   }
 
+  stl->g_data->use_material_slot_selection = DRW_state_is_material_select();
+
   /* Twice for normal and in front objects. */
   for (int i = 0; i < 2; i++) {
     DRWState clip_state = (draw_ctx->sh_cfg == GPU_SHADER_CFG_CLIPPED) ? DRW_STATE_CLIP_PLANES : 0;
@@ -211,9 +214,24 @@ static void basic_cache_populate(void *vedata, Object *ob)
     DRW_shgroup_call_sculpt(shgrp, ob, false, false);
   }
   else {
-    struct GPUBatch *geom = DRW_cache_object_surface_get(ob);
-    if (geom) {
-      DRW_shgroup_call(shgrp, geom, ob);
+    if (stl->g_data->use_material_slot_selection) {
+      struct GPUBatch **geoms = DRW_cache_mesh_surface_texpaint_get(ob);
+      if (geoms) {
+        const int materials_len = DRW_cache_object_material_count_get(ob);
+        for (int i = 0; i < materials_len; i++) {
+          if (geoms[i] == NULL) {
+            continue;
+          }
+          const short material_slot_select_id = i + 1;
+          DRW_shgroup_call_subselection(shgrp, geoms[i], ob, material_slot_select_id);
+        }
+      }
+    }
+    else {
+      struct GPUBatch *geom = DRW_cache_object_surface_get(ob);
+      if (geom) {
+        DRW_shgroup_call(shgrp, geom, ob);
+      }
     }
   }
 }
diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h
index 1292eea4c12..4855c8677f1 100644
--- a/source/blender/draw/intern/DRW_render.h
+++ b/source/blender/draw/intern/DRW_render.h
@@ -411,24 +411,28 @@ void DRW_shgroup_call_ex(DRWShadingGroup *shgroup,
                          float (*obmat)[4],
                          struct GPUBatch *geom,
                          bool bypass_culling,
+                         short sub_select_id,
                          void *user_data);
 
 /* If ob is NULL, unit modelmatrix is assumed and culling is bypassed. */
 #define DRW_shgroup_call(shgroup, geom, ob) \
-  DRW_shgroup_call_ex(shgroup, ob, NULL, geom, false, NULL)
+  DRW_shgroup_call_ex(shgroup, ob, NULL, geom, false, 0, NULL)
 
 /* Same as DRW_shgroup_call but override the obmat. Not culled. */
 #define DRW_shgroup_call_obmat(shgroup, geom, obmat) \
-  DRW_shgroup_call_ex(shgroup, NULL, obmat, geom, false, NULL)
+  DRW_shgroup_call_ex(shgroup, NULL, obmat, geom, false, 0, NULL)
 
 /* TODO(fclem): remove this when we have DRWView */
 /* user_data is used by DRWCallVisibilityFn defined in DRWView. */
 #define DRW_shgroup_call_with_callback(shgroup, geom, ob, user_data) \
-  DRW_shgroup_call_ex(shgroup, ob, NULL, geom, false, user_data)
+  DRW_shgroup_call_ex(shgroup, ob, NULL, geom, false, 0, user_data)
 
 /* Same as DRW_shgroup_call but bypass culling even if ob is not NULL. */
 #define DRW_shgroup_call_no_cull(shgroup, geom, ob) \
-  DRW_shgroup_call_ex(shgroup, ob, NULL, geom, true, NULL)
+  DRW_shgroup_call_ex(shgroup, ob, NULL, geom, true, 0, NULL)
+
+#define DRW_shgroup_call_subselection(shgroup, geom, ob, sub_select_id) \
+  DRW_shgroup_call_ex(shgroup, ob, NULL, geom, false, sub_select_id, NULL)
 
 void DRW_shgroup_call_range(
     DRWShadingGroup *shgroup, Object *ob, struct GPUBatch *geom, uint v_sta, uint v_ct);
@@ -727,6 +731,7 @@ void DRW_select_load_id(uint id);
 /* Draw State */
 bool DRW_state_is_fbo(void);
 bool DRW_state_is_select(void);
+bool DRW_state_is_material_select(void);
 bool DRW_state_is_depth(void);
 bool DRW_state_is_image_render(void);
 bool DRW_state_do_color_management(void);
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index 027ab8ce32b..52d44fd59af 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -2282,6 +2282,7 @@ void DRW_draw_select_loop(struct Depsgraph *depsgraph,
                           bool use_obedit_skip,
                           bool draw_surface,
                           bool UNUSED(use_nearest),
+                          const bool do_material_sub_selection,
                           const rcti *rect,
                           DRW_SelectPassFn select_pass_fn,
                           void *select_pass_user_data,
@@ -2349,6 +2350,9 @@ void DRW_draw_select_loop(struct Depsgraph *depsgraph,
 
   DST.viewport = viewport;
   DST.options.is_select = true;
+  DST.options.is_material_select = do_material_sub_selection;
+  BLI_assert_msg(!DST.options.is_material_select || object_mode == OB_MODE_OBJECT,
+                 "Material selection only supported in object mode.");
   drw_task_graph_init();
   /* Get list of enabled engines */
   if (use_obedit) {
@@ -2824,6 +2828,11 @@ bool DRW_state_is_select(void)
   return DST.options.is_select;
 }
 
+bool DRW_state_is_material_select(void)
+{
+  return DST.options.is_material_select;
+}
+
 bool DRW_state_is_depth(void)
 {
   return DST.options.is_depth;
diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h
index 512c2775850..16019d16fda 100644
--- a/source/blender/draw/intern/draw_manager.h
+++ b/source/blender/draw/intern/draw_manager.h
@@ -540,6 +540,7 @@ typedef struct DRWManager {
 
   struct {
     uint is_select : 1;
+    uint is_material_select : 1;
     uint is_depth : 1;
     uint is_image_render : 1;
     uint is_scene_render : 1;
diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c
index af331c86a8b..0f3f22e87f3 100644
--- a/source/blender/draw/intern/draw_manager_data.c
+++ b/source/blender/draw/intern/draw_manager_data.c
@@ -793,11 +793,12 @@ void DRW_shgroup_call_ex(DRWShadingGroup *shgroup,
                          float (*obmat)[4],
                          struct GPUBatch *geom,
                          bool bypass_culling,
+                         short sub_select_id,
                          void *user_data)
 {
   BLI_assert(geom != NULL);
   if (G.f & G_FLAG_PICKSEL) {
-    drw_command_set_select_id(shgroup, NULL, DST.select_id);
+    drw_command_set_select_id(shgroup, NULL, DST.select_id + (sub_select_id << 16));
   }
   DRWResourceHandle handle = drw_resource_handle(shgroup, ob ? ob->obmat : obmat, ob);
   drw_command_draw(shgroup, geom, handle);
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index 31aae02fe22..cf8dcbd7995 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -566,6 +566,13 @@ eV3DSelectObjectFilter ED_view3d_select_filter_from_mode(const struct Scene *sce
 void view3d_opengl_select_cache_begin(void);
 void view3d_opengl_select_cache_end(void);
 
+int view3d_opengl_select_ex(struct ViewContext *vc,
+                            unsigned int *buffer,
+                            unsigned int bufsize,
+                            const struct rcti *input,
+                            eV3DSelectMode select_mode,
+                            eV3DSelectObjectFilter select_filter,
+                            const bool do_material_slot_selection);
 int view3d_opengl_select(struct ViewContext *vc,
                          unsigned int *buffer,
                          unsigned int bufsize,
diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index 56d70702570..6e3857c67fe 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -1953,7 +1953,8 @@ static int mixed_bones_object_selectbuffer(ViewContext *vc,
                                            const int mval[2],
                                            eV3DSelectObjectFilter select_filter,
                                            bool do_nearest,
-                                           bool do_nearest_xray_if_supported)
+                                           bool do_nearest_xray_if_supported,
+                                           const bool do_material_slot_selection)
 {
   rcti rect;
   int hits15, hits9 = 0, hits5 = 0;
@@ -1972,7 +1973,8 @@ static int mixed_bones_object_selectbuffer(ViewContext *vc,
   view3d_opengl_select_cache_begin();
 
   BLI_rcti_init_pt_radius(&rect, mval, 14);
-  hits15 = view3d_opengl_select(vc, buffer, MAXPICKBUF, &rect, select_mode, select_filter);
+  hits15 = view3d_opengl_select_ex(
+      vc, buffer, MAXPICKBUF, &rect, select_mode, select_filter, do_material_slot_selection);
   if (hits15 == 1) {
     hits = selectbuffer_ret_hits_15(buffer, hits15);
     goto finally;
@@ -2071,7 +2073,8 @@ static int mixed_bones_object_selectbuffer_extended(ViewContext *vc,
 
   do_nearest = do_nearest && !enumerate;
 
-  int hits = mixed_bones_object_selectbuffer(vc, buffer, mval, select_filter, do_nearest, true);
+  int hits = mixed_bones_object_selectbuffer(
+      vc, buffer, mval, select_filter, do_nearest, true, false);
 
   return hits;
 }
@@ -2211,8 +2214,9 @@ static Base *ed_view3d_give_base_under_cursor_ex(bContext *C,
   ED_view3d_viewcontext_init(C

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list