Sculpt: Union and Join mode for trim tools

This enables a union boolean mode for the trimming gestures tools which
adds geometry to the mesh instead of cutting it.
It also adds a Join mode, which adds the geometry directly without
using a boolean operation.
Depending if you plan to use dyntopo or not, it is useful to have both
options available.

This is using the full depth of the object from the camera view for the
depth of the geometry, but options for controlling the trimming depth in
all modes are going to be added in later patches

Reviewed By: mont29

Differential Revision: https://developer.blender.org/D9066
This commit is contained in:
Pablo Dobarro 2020-10-06 18:07:39 +02:00
parent d43e3f34d2
commit 2b72860ff4
2 changed files with 41 additions and 12 deletions

View File

@ -1304,22 +1304,30 @@ class _defs_sculpt:
@ToolDef.from_fn
def trim_box():
def draw_settings(_context, layout, tool):
props = tool.operator_properties("sculpt.trim_box_gesture")
layout.prop(props, "trim_mode", expand=False)
return dict(
idname="builtin.box_trim",
label="Box Trim",
icon="ops.sculpt.box_trim",
widget=None,
keymap=(),
draw_settings=draw_settings,
)
@ToolDef.from_fn
def trim_lasso():
def draw_settings(_context, layout, tool):
props = tool.operator_properties("sculpt.trim_lasso_gesture")
layout.prop(props, "trim_mode", expand=False)
return dict(
idname="builtin.lasso_trim",
label="Lasso Trim",
icon="ops.sculpt.lasso_trim",
widget=None,
keymap=(),
draw_settings=draw_settings,
)
@ToolDef.from_fn

View File

@ -821,11 +821,24 @@ static void paint_mask_gesture_operator_properties(wmOperatorType *ot)
typedef enum eSculptTrimOperationType {
SCULPT_GESTURE_TRIM_INTERSECT,
SCULPT_GESTURE_TRIM_DIFFERENCE,
SCULPT_GESTURE_TRIM_UNION,
SCULPT_GESTURE_TRIM_JOIN,
} eSculptTrimOperationType;
/* Intersect is not exposed in the UI because it does not work correctly with symmetry (it deletes
* the symmetrical part of the mesh in the first symmetry pass). */
static EnumPropertyItem prop_trim_operation_types[] = {
{SCULPT_GESTURE_TRIM_INTERSECT, "INTERSECT", 0, "Intersect", ""},
{SCULPT_GESTURE_TRIM_DIFFERENCE, "DIFFERENCE", 0, "Difference", ""},
{SCULPT_GESTURE_TRIM_DIFFERENCE,
"DIFFERENCE",
0,
"Difference",
"Use a difference boolean operation"},
{SCULPT_GESTURE_TRIM_UNION, "UNION", 0, "Union", "Use a union boolean operation"},
{SCULPT_GESTURE_TRIM_JOIN,
"JOIN",
0,
"Join",
"Join the new mesh as separate geometry, without preforming any boolean operation"},
{0, NULL, 0, NULL, NULL},
};
@ -1088,18 +1101,26 @@ static void sculpt_gesture_apply_trim(SculptGestureContext *sgcontext)
}
}
int boolean_mode;
switch (trim_operation->mode) {
case SCULPT_GESTURE_TRIM_INTERSECT:
boolean_mode = eBooleanModifierOp_Intersect;
break;
case SCULPT_GESTURE_TRIM_DIFFERENCE:
boolean_mode = eBooleanModifierOp_Difference;
break;
/* Join does not do a boolean operation, it just adds the geometry. */
if (trim_operation->mode != SCULPT_GESTURE_TRIM_JOIN) {
int boolean_mode = 0;
switch (trim_operation->mode) {
case SCULPT_GESTURE_TRIM_INTERSECT:
boolean_mode = eBooleanModifierOp_Intersect;
break;
case SCULPT_GESTURE_TRIM_DIFFERENCE:
boolean_mode = eBooleanModifierOp_Difference;
break;
case SCULPT_GESTURE_TRIM_UNION:
boolean_mode = eBooleanModifierOp_Union;
break;
case SCULPT_GESTURE_TRIM_JOIN:
BLI_assert(false);
break;
}
BM_mesh_boolean(bm, looptris, tottri, bm_face_isect_pair, NULL, 2, false, boolean_mode);
}
BM_mesh_boolean(bm, looptris, tottri, bm_face_isect_pair, NULL, 2, false, boolean_mode);
Mesh *result = BKE_mesh_from_bmesh_for_eval_nomain(bm, NULL, sculpt_mesh);
BM_mesh_free(bm);
result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;