Sculpt: Add mask filter tool and target step count

This commit is contained in:
Pablo Dobarro 2021-02-24 20:00:02 +01:00
parent 773c5c7464
commit 76de0eeb95
3 changed files with 55 additions and 6 deletions

View File

@ -6621,6 +6621,16 @@ def km_3d_view_tool_sculpt_mesh_filter(params):
]},
)
def km_3d_view_tool_sculpt_ipmask_filter(params):
return (
"3D View Tool: Sculpt, IPMask Filter",
{"space_type": 'VIEW_3D', "region_type": 'WINDOW'},
{"items": [
("sculpt.ipmask_filter", {"type": params.tool_tweak, "value": 'ANY'},
None)
]},
)
def km_3d_view_tool_sculpt_cloth_filter(params):
return (
@ -7241,6 +7251,7 @@ def generate_keymaps(params=None):
km_3d_view_tool_sculpt_lasso_project(params),
km_3d_view_tool_sculpt_box_project(params),
km_3d_view_tool_sculpt_mesh_filter(params),
km_3d_view_tool_sculpt_ipmask_filter(params),
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),

View File

@ -1480,6 +1480,21 @@ class _defs_sculpt:
draw_settings=draw_settings,
)
@ToolDef.from_fn
def ipmask_filter():
def draw_settings(_context, layout, tool):
props = tool.operator_properties("sculpt.ipmask_filter")
layout.prop(props, "type", expand=False)
return dict(
idname="builtin.ipmask_filter",
label="IPMask Filter",
icon="ops.sculpt.ipmask_filter",
widget=None,
keymap=(),
draw_settings=draw_settings,
)
@ToolDef.from_fn
def cloth_filter():
def draw_settings(_context, layout, tool):
@ -2872,6 +2887,7 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
None,
_defs_sculpt.mesh_filter,
_defs_sculpt.cloth_filter,
_defs_sculpt.ipmask_filter,
lambda context: (
(_defs_sculpt.color_filter,)
if context is None or (

View File

@ -354,6 +354,33 @@ static int sculpt_ipmask_filter_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
#define IPMASK_FILTER_STEP_SENSITIVITY 0.05f
static int sculpt_ipmask_filter_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
Object *ob = CTX_data_active_object(C);
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
SculptSession *ss = ob->sculpt;
Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
if (event->type == LEFTMOUSE && event->val == KM_RELEASE) {
SCULPT_filter_cache_free(ss);
SCULPT_undo_push_end();
SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_MASK);
return OPERATOR_FINISHED;
}
BKE_sculpt_update_object_for_edit(depsgraph, ob, true, true, false);
const float len = event->x - event->prevclickx;
const int target_step = len * IPMASK_FILTER_STEP_SENSITIVITY * UI_DPI_FAC;
printf("TARGET STEP %d\n", target_step);
return OPERATOR_RUNNING_MODAL;
}
void SCULPT_OT_ipmask_filter(struct wmOperatorType *ot)
{
/* Identifiers. */
@ -364,6 +391,7 @@ void SCULPT_OT_ipmask_filter(struct wmOperatorType *ot)
/* API callbacks. */
ot->exec = sculpt_ipmask_filter_exec;
ot->invoke = sculpt_ipmask_filter_invoke;
ot->modal = sculpt_ipmask_filter_modal;
ot->poll = SCULPT_mode_poll;
ot->flag = OPTYPE_REGISTER;
@ -384,12 +412,6 @@ void SCULPT_OT_ipmask_filter(struct wmOperatorType *ot)
"Number of times that the filter is going to be applied",
1,
100);
RNA_def_boolean(
ot->srna,
"auto_iteration_count",
false,
"Auto Iteration Count",
"Use a automatic number of iterations based on the number of vertices of the sculpt");
}
/******************************************************************************************/