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
This commit is contained in:
Pablo Dobarro 2020-08-03 18:47:08 +02:00
parent 1ae9960a15
commit 6faa765af8
Notes: blender-bot 2023-02-14 04:39:18 +01:00
Referenced by commit 956af16189, Fix Unreported: Missing box mask in sculpt
Referenced by commit 2261da2897, Fix Unreported: Missing box mask in sculpt
Referenced by commit 9daf668991, Fix T81926: Sculpt: Box Mask operator (from menu and shortcut) does
Referenced by issue #81926, Sculpt: Box Mask operator (from menu and shortcut) does nothing
6 changed files with 52 additions and 18 deletions

View File

@ -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)]}),
]},
)

View File

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

View File

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

View File

@ -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)

View File

@ -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)) {

View File

@ -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");