Sculpt: Expose Edit Face Set as a tool

Previously the way to use this operations was using the shortcut Ctrl +
W and Ctrl + Alt + W, which was not very discoverable and it was
limiting the amount of options that can be added to the operator.Now the
same functionality of the operator is available as a tool, which will
make easier to add other editing operations and options without adding
more entries to the keymap.

Reviewed By: sergey

Differential Revision: https://developer.blender.org/D8545
This commit is contained in:
Pablo Dobarro 2020-08-11 19:24:01 +02:00
parent 051f067fb8
commit 77e40708c2
3 changed files with 45 additions and 1 deletions

View File

@ -6347,6 +6347,18 @@ def km_3d_view_tool_sculpt_mask_by_color(params):
]},
)
def km_3d_view_tool_sculpt_face_set_edit(params):
return (
"3D View Tool: Sculpt, Face Set Edit",
{"space_type": 'VIEW_3D', "region_type": 'WINDOW'},
{"items": [
("sculpt.face_set_edit", {"type": params.tool_mouse, "value": 'ANY'},
None),
("sculpt.face_set_edit", {"type": params.tool_tweak, "value": 'ANY'},
None)
]},
)
def km_3d_view_tool_paint_weight_sample_weight(params):
return (
"3D View Tool: Paint Weight, Sample Weight",
@ -6890,6 +6902,7 @@ def generate_keymaps(params=None):
km_3d_view_tool_sculpt_cloth_filter(params),
km_3d_view_tool_sculpt_color_filter(params),
km_3d_view_tool_sculpt_mask_by_color(params),
km_3d_view_tool_sculpt_face_set_edit(params),
km_3d_view_tool_paint_weight_sample_weight(params),
km_3d_view_tool_paint_weight_sample_vertex_group(params),
km_3d_view_tool_paint_weight_gradient(params),

View File

@ -1335,6 +1335,22 @@ class _defs_sculpt:
draw_settings=draw_settings,
)
@ToolDef.from_fn
def face_set_edit():
def draw_settings(_context, layout, tool):
props = tool.operator_properties("sculpt.face_set_edit")
layout.prop(props, "mode", expand=False)
layout.prop(props, "modify_hidden")
return dict(
idname="builtin.face_set_edit",
label="Edit Face Set",
icon="ops.sculpt.face_set_edit",
widget=None,
keymap="3D View Tool: Sculpt, Face Set Edit",
draw_settings=draw_settings,
)
class _defs_vertex_paint:
@ -2595,6 +2611,8 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
else ()
),
None,
_defs_sculpt.face_set_edit,
None,
_defs_transform.translate,
_defs_transform.rotate,
_defs_transform.scale,

View File

@ -1082,7 +1082,7 @@ static void sculpt_face_set_apply_edit(Object *ob,
MEM_SAFE_FREE(prev_face_sets);
}
static int sculpt_face_set_edit_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static int sculpt_face_set_edit_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
Object *ob = CTX_data_active_object(C);
SculptSession *ss = ob->sculpt;
@ -1096,8 +1096,21 @@ static int sculpt_face_set_edit_invoke(bContext *C, wmOperator *op, const wmEven
return OPERATOR_CANCELLED;
}
/* Ignore other events to avoid repeated operations. */
if (event->val != KM_PRESS) {
return OPERATOR_CANCELLED;
}
BKE_sculpt_update_object_for_edit(depsgraph, ob, true, false, false);
/* Update the current active Face Set and Vertex as the operator can be used directly from the
* tool without brush cursor. */
SculptCursorGeometryInfo sgi;
float mouse[2];
mouse[0] = event->mval[0];
mouse[1] = event->mval[1];
SCULPT_cursor_geometry_info_update(C, &sgi, mouse, false);
PBVH *pbvh = ob->sculpt->pbvh;
PBVHNode **nodes;
int totnode;