Sculpt: Add fast solver option for trim operations #119699

Merged
Hans Goudey merged 4 commits from Sean-Kim/blender:fast-trim-option into main 2024-03-26 17:25:16 +01:00
2 changed files with 37 additions and 2 deletions

View File

@ -1488,6 +1488,7 @@ class _defs_sculpt:
def trim_box():
def draw_settings(_context, layout, tool):
props = tool.operator_properties("sculpt.trim_box_gesture")
layout.prop(props, "trim_solver", expand=False)
layout.prop(props, "trim_mode", expand=False)
layout.prop(props, "trim_orientation", expand=False)
layout.prop(props, "trim_extrude_mode", expand=False)
@ -1505,6 +1506,7 @@ class _defs_sculpt:
def trim_lasso():
def draw_settings(_context, layout, tool):
props = tool.operator_properties("sculpt.trim_lasso_gesture")
layout.prop(props, "trim_solver", expand=False)
layout.prop(props, "trim_mode", expand=False)
layout.prop(props, "trim_orientation", expand=False)
layout.prop(props, "trim_extrude_mode", expand=False)

View File

@ -32,6 +32,7 @@
#include "bmesh.hh"
#include "tools/bmesh_boolean.hh"
#include "tools/bmesh_intersect.hh"
#include "paint_intern.hh"
#include "sculpt_intern.hh"
@ -90,6 +91,17 @@ static EnumPropertyItem extrude_modes[] = {
{0, nullptr, 0, nullptr, nullptr},
};
enum class SolverMode {
Exact = 0,
Fast = 1,
};
static EnumPropertyItem solver_modes[] = {
{int(SolverMode::Exact), "EXACT", 0, "Exact", "Use the exact boolean solver"},
{int(SolverMode::Fast), "FAST", 0, "Fast", "Use the fast float boolean solver"},
{0, nullptr, 0, nullptr, nullptr},
};
struct TrimOperation {
gesture::Operation op;
@ -102,6 +114,7 @@ struct TrimOperation {
bool use_cursor_depth;
OperationType mode;
SolverMode solver_mode;
OrientationType orientation;
ExtrudeMode extrude_mode;
};
@ -502,8 +515,25 @@ static void apply_trim(gesture::GestureData &gesture_data)
BLI_assert(false);
break;
}
BM_mesh_boolean(
bm, corner_tris, bm_face_isect_pair, nullptr, 2, true, true, false, boolean_mode);
if (trim_operation->solver_mode == SolverMode::Exact) {
BM_mesh_boolean(
bm, corner_tris, bm_face_isect_pair, nullptr, 2, true, true, false, boolean_mode);
}
else {
BM_mesh_intersect(bm,
corner_tris,
bm_face_isect_pair,
nullptr,
false,
false,
true,
true,
false,
false,
boolean_mode,
1e-6f);
}
}
BMeshToMeshParams convert_params{};
@ -573,6 +603,7 @@ static void init_operation(gesture::GestureData &gesture_data, wmOperator &op)
trim_operation->use_cursor_depth = RNA_boolean_get(op.ptr, "use_cursor_depth");
trim_operation->orientation = OrientationType(RNA_enum_get(op.ptr, "trim_orientation"));
trim_operation->extrude_mode = ExtrudeMode(RNA_enum_get(op.ptr, "trim_extrude_mode"));
trim_operation->solver_mode = SolverMode(RNA_enum_get(op.ptr, "trim_solver"));
/* If the cursor was not over the mesh, force the orientation to view. */
if (!gesture_data.ss->gesture_initial_hit) {
@ -606,6 +637,8 @@ static void operator_properties(wmOperatorType *ot)
int(ExtrudeMode::Fixed),
"Extrude Mode",
nullptr);
RNA_def_enum(ot->srna, "trim_solver", solver_modes, int(SolverMode::Fast), "Solver", nullptr);
}
Sean-Kim marked this conversation as resolved Outdated

How about just trim_solver instead of adding mode at the end? That would be more consistent with the equivalent property on the boolean node and modifier.

How about just `trim_solver` instead of adding `mode` at the end? That would be more consistent with the equivalent property on the boolean node and modifier.

Sorry I wasn't clearer, I think the property name should just be "Solver" too

Sorry I wasn't clearer, I think the property name should just be "Solver" too
static int gesture_box_exec(bContext *C, wmOperator *op)