[Bf-blender-cvs] [6faa765af89] master: Sculpt: Split Box Mask into its own operator

Pablo Dobarro noreply at git.blender.org
Tue Aug 4 22:52:51 CEST 2020


Commit: 6faa765af8954948de3cec75a2261a5aa139b4e5
Author: Pablo Dobarro
Date:   Mon Aug 3 18:47:08 2020 +0200
Branches: master
https://developer.blender.org/rB6faa765af8954948de3cec75a2261a5aa139b4e5

Sculpt: Split Box Mask into its own operator

Box mask is not a selection, so it should not be part of the select
operator. This allows to add more sculpt mode specific functionality and
properties and to share more code with the lasso mask operator in a
later refactor.

Reviewed By: sergey

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

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

M	release/scripts/presets/keyconfig/keymap_data/blender_default.py
M	source/blender/editors/sculpt_paint/paint_intern.h
M	source/blender/editors/sculpt_paint/paint_mask.c
M	source/blender/editors/sculpt_paint/paint_ops.c
M	source/blender/editors/space_view3d/view3d_select.c
M	source/blender/windowmanager/intern/wm_operators.c

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

diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index ef4e1a9f77b..6a05ba2b3c7 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -6288,10 +6288,10 @@ def km_3d_view_tool_sculpt_box_mask(params):
         "3D View Tool: Sculpt, Box Mask",
         {"space_type": 'VIEW_3D', "region_type": 'WINDOW'},
         {"items": [
-            ("view3d.select_box", {"type": params.tool_tweak, "value": 'ANY'},
-             {"properties": [("mode", 'ADD')]}),
-            ("view3d.select_box", {"type": params.tool_tweak, "value": 'ANY', "ctrl": True},
-             {"properties": [("mode", 'SUB')]}),
+            ("paint.mask_box_gesture", {"type": params.tool_tweak, "value": 'ANY'},
+             {"properties": [("value", 1.0)]}),
+            ("paint.mask_box_gesture", {"type": params.tool_tweak, "value": 'ANY', "ctrl": True},
+             {"properties": [("value", 0.0)]}),
         ]},
     )
 
diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h
index 0d4e957c77b..feadeb28cd5 100644
--- a/source/blender/editors/sculpt_paint/paint_intern.h
+++ b/source/blender/editors/sculpt_paint/paint_intern.h
@@ -341,6 +341,7 @@ typedef enum {
 
 void PAINT_OT_mask_flood_fill(struct wmOperatorType *ot);
 void PAINT_OT_mask_lasso_gesture(struct wmOperatorType *ot);
+void PAINT_OT_mask_box_gesture(struct wmOperatorType *ot);
 
 /* paint_curve.c */
 void PAINTCURVE_OT_new(struct wmOperatorType *ot);
diff --git a/source/blender/editors/sculpt_paint/paint_mask.c b/source/blender/editors/sculpt_paint/paint_mask.c
index 6e0402fc6e0..c255cbcaaab 100644
--- a/source/blender/editors/sculpt_paint/paint_mask.c
+++ b/source/blender/editors/sculpt_paint/paint_mask.c
@@ -25,6 +25,7 @@
 
 #include "DNA_meshdata_types.h"
 #include "DNA_object_types.h"
+#include "DNA_vec_types.h"
 
 #include "BLI_bitmap_draw_2d.h"
 #include "BLI_lasso_2d.h"
@@ -290,27 +291,32 @@ static void mask_box_select_task_cb(void *__restrict userdata,
   }
 }
 
-bool ED_sculpt_mask_box_select(struct bContext *C, ViewContext *vc, const rcti *rect, bool select)
+static int paint_mask_gesture_box_exec(bContext *C, wmOperator *op)
 {
+  ViewContext vc;
   Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
-  Sculpt *sd = vc->scene->toolsettings->sculpt;
+  ED_view3d_viewcontext_init(C, &vc, depsgraph);
+
+  Sculpt *sd = vc.scene->toolsettings->sculpt;
   BoundBox bb;
   float clip_planes[4][4];
   float clip_planes_final[4][4];
-  ARegion *region = vc->region;
-  Object *ob = vc->obact;
-  PaintMaskFloodMode mode;
+  ARegion *region = vc.region;
+  Object *ob = vc.obact;
   bool multires;
   PBVH *pbvh;
   PBVHNode **nodes;
   int totnode;
   int symm = sd->paint.symmetry_flags & PAINT_SYMM_AXIS_ALL;
 
-  mode = PAINT_MASK_FLOOD_VALUE;
-  float value = select ? 1.0f : 0.0f;
+  const PaintMaskFloodMode mode = RNA_enum_get(op->ptr, "mode");
+  const float value = RNA_float_get(op->ptr, "value");
+
+  rcti rect;
+  WM_operator_properties_border_to_rcti(op, &rect);
 
   /* Transform the clip planes in object space. */
-  ED_view3d_clipping_calc(&bb, clip_planes, vc->region, vc->obact, rect);
+  ED_view3d_clipping_calc(&bb, clip_planes, vc.region, vc.obact, &rect);
 
   BKE_sculpt_update_object_for_edit(depsgraph, ob, false, true, false);
   pbvh = ob->sculpt->pbvh;
@@ -589,3 +595,33 @@ void PAINT_OT_mask_lasso_gesture(wmOperatorType *ot)
       0.0f,
       1.0f);
 }
+
+void PAINT_OT_mask_box_gesture(wmOperatorType *ot)
+{
+  ot->name = "Mask Box Gesture";
+  ot->idname = "PAINT_OT_mask_box_gesture";
+  ot->description = "Add mask within the box as you move the brush";
+
+  ot->invoke = WM_gesture_box_invoke;
+  ot->modal = WM_gesture_box_modal;
+  ot->exec = paint_mask_gesture_box_exec;
+
+  ot->poll = SCULPT_mode_poll;
+
+  ot->flag = OPTYPE_REGISTER;
+
+  /* Properties. */
+  WM_operator_properties_border(ot);
+
+  RNA_def_enum(ot->srna, "mode", mode_items, PAINT_MASK_FLOOD_VALUE, "Mode", NULL);
+  RNA_def_float(
+      ot->srna,
+      "value",
+      1.0f,
+      0.0f,
+      1.0f,
+      "Value",
+      "Mask level to use when mode is 'Value'; zero means no masking and one is fully masked",
+      0.0f,
+      1.0f);
+}
diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c
index d65f158174f..0fe6e259d8d 100644
--- a/source/blender/editors/sculpt_paint/paint_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_ops.c
@@ -1356,6 +1356,7 @@ void ED_operatortypes_paint(void)
   /* paint masking */
   WM_operatortype_append(PAINT_OT_mask_flood_fill);
   WM_operatortype_append(PAINT_OT_mask_lasso_gesture);
+  WM_operatortype_append(PAINT_OT_mask_box_gesture);
 }
 
 void ED_keymap_paint(wmKeyConfig *keyconf)
diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index e23dd48b8b9..9490c807989 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -3335,12 +3335,7 @@ static int view3d_box_select_exec(bContext *C, wmOperator *op)
     FOREACH_OBJECT_IN_MODE_END;
   }
   else { /* No edit-mode, unified for bones and objects. */
-    if (vc.obact && vc.obact->mode & OB_MODE_SCULPT) {
-      /* XXX, this is not selection, could be it's own operator. */
-      changed_multi = ED_sculpt_mask_box_select(
-          C, &vc, &rect, sel_op == SEL_OP_ADD ? true : false);
-    }
-    else if (vc.obact && BKE_paint_select_face_test(vc.obact)) {
+    if (vc.obact && BKE_paint_select_face_test(vc.obact)) {
       changed_multi = do_paintface_box_select(&vc, wm_userdata, &rect, sel_op);
     }
     else if (vc.obact && BKE_paint_select_vert_test(vc.obact)) {
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 1c277b27943..72cc5a3d7dd 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -3917,6 +3917,7 @@ static void gesture_box_modal_keymap(wmKeyConfig *keyconf)
   WM_modalkeymap_assign(keymap, "CLIP_OT_select_box");
   WM_modalkeymap_assign(keymap, "CLIP_OT_graph_select_box");
   WM_modalkeymap_assign(keymap, "MASK_OT_select_box");
+  WM_modalkeymap_assign(keymap, "PAINT_OT_mask_box_gesture");
   WM_modalkeymap_assign(keymap, "VIEW2D_OT_zoom_border");
   WM_modalkeymap_assign(keymap, "VIEW3D_OT_clip_border");
   WM_modalkeymap_assign(keymap, "VIEW3D_OT_render_border");



More information about the Bf-blender-cvs mailing list