From fd4a3308fe3f70579f4eb609b9f38d0bd49d6da0 Mon Sep 17 00:00:00 2001 From: Sean Kim Date: Tue, 19 Mar 2024 16:32:36 -0700 Subject: [PATCH 1/3] Sculpt: Add fast solver option for trim operations --- .../startup/bl_ui/space_toolsystem_toolbar.py | 2 + .../editors/sculpt_paint/sculpt_trim.cc | 55 +++++++++++++++---- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/scripts/startup/bl_ui/space_toolsystem_toolbar.py index 42e774ed35e..83844961d16 100644 --- a/scripts/startup/bl_ui/space_toolsystem_toolbar.py +++ b/scripts/startup/bl_ui/space_toolsystem_toolbar.py @@ -1489,6 +1489,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_mode", expand=False) layout.prop(props, "trim_mode", expand=False) layout.prop(props, "trim_orientation", expand=False) layout.prop(props, "trim_extrude_mode", expand=False) @@ -1506,6 +1507,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_mode", expand=False) layout.prop(props, "trim_mode", expand=False) layout.prop(props, "trim_orientation", expand=False) layout.prop(props, "trim_extrude_mode", expand=False) diff --git a/source/blender/editors/sculpt_paint/sculpt_trim.cc b/source/blender/editors/sculpt_paint/sculpt_trim.cc index 2b401158665..fc2515729fc 100644 --- a/source/blender/editors/sculpt_paint/sculpt_trim.cc +++ b/source/blender/editors/sculpt_paint/sculpt_trim.cc @@ -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; }; @@ -503,16 +516,34 @@ static void apply_trim(gesture::GestureData &gesture_data) BLI_assert(false); break; } - BM_mesh_boolean(bm, - corner_tris, - corner_tris_tot, - bm_face_isect_pair, - nullptr, - 2, - true, - true, - false, - boolean_mode); + + if (trim_operation->solver_mode == SolverMode::Exact) { + BM_mesh_boolean(bm, + corner_tris, + corner_tris_tot, + bm_face_isect_pair, + nullptr, + 2, + true, + true, + false, + boolean_mode); + } + else { + BM_mesh_intersect(bm, + corner_tris, + corner_tris_tot, + bm_face_isect_pair, + nullptr, + false, + false, + true, + true, + false, + false, + boolean_mode, + 1e-6f); + } } MEM_freeN(corner_tris); @@ -584,6 +615,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_mode")); /* If the cursor was not over the mesh, force the orientation to view. */ if (!gesture_data.ss->gesture_initial_hit) { @@ -617,6 +649,9 @@ static void operator_properties(wmOperatorType *ot) int(ExtrudeMode::Fixed), "Extrude Mode", nullptr); + + RNA_def_enum( + ot->srna, "trim_solver_mode", solver_modes, int(SolverMode::Fast), "Solver Mode", nullptr); } static int gesture_box_exec(bContext *C, wmOperator *op) -- 2.30.2 From f0018742114ac83a06451279f7b1684031fbe150 Mon Sep 17 00:00:00 2001 From: Sean Kim Date: Mon, 25 Mar 2024 22:44:03 -0700 Subject: [PATCH 2/3] Address PR feedback --- scripts/startup/bl_ui/space_toolsystem_toolbar.py | 4 ++-- source/blender/editors/sculpt_paint/sculpt_trim.cc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/scripts/startup/bl_ui/space_toolsystem_toolbar.py index 142f22d0ea3..e0195d19ce2 100644 --- a/scripts/startup/bl_ui/space_toolsystem_toolbar.py +++ b/scripts/startup/bl_ui/space_toolsystem_toolbar.py @@ -1488,7 +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_mode", expand=False) + 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) @@ -1506,7 +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_mode", expand=False) + 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) diff --git a/source/blender/editors/sculpt_paint/sculpt_trim.cc b/source/blender/editors/sculpt_paint/sculpt_trim.cc index 9c921e627c3..c48b4723008 100644 --- a/source/blender/editors/sculpt_paint/sculpt_trim.cc +++ b/source/blender/editors/sculpt_paint/sculpt_trim.cc @@ -603,7 +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_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) { @@ -639,7 +639,7 @@ static void operator_properties(wmOperatorType *ot) nullptr); RNA_def_enum( - ot->srna, "trim_solver_mode", solver_modes, int(SolverMode::Fast), "Solver Mode", nullptr); + ot->srna, "trim_solver", solver_modes, int(SolverMode::Fast), "Solver Mode", nullptr); } static int gesture_box_exec(bContext *C, wmOperator *op) -- 2.30.2 From e653f77d9a5d29985cb9fe768c99690791d5a02a Mon Sep 17 00:00:00 2001 From: Sean Kim Date: Tue, 26 Mar 2024 09:20:47 -0700 Subject: [PATCH 3/3] Address PR comment --- source/blender/editors/sculpt_paint/sculpt_trim.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/blender/editors/sculpt_paint/sculpt_trim.cc b/source/blender/editors/sculpt_paint/sculpt_trim.cc index c48b4723008..0d34f92cae9 100644 --- a/source/blender/editors/sculpt_paint/sculpt_trim.cc +++ b/source/blender/editors/sculpt_paint/sculpt_trim.cc @@ -638,8 +638,7 @@ static void operator_properties(wmOperatorType *ot) "Extrude Mode", nullptr); - RNA_def_enum( - ot->srna, "trim_solver", solver_modes, int(SolverMode::Fast), "Solver Mode", nullptr); + RNA_def_enum(ot->srna, "trim_solver", solver_modes, int(SolverMode::Fast), "Solver", nullptr); } static int gesture_box_exec(bContext *C, wmOperator *op) -- 2.30.2