Commit: 675c9644420eba96751e1cadedd2656a8bc39191 Author: Pablo Dobarro Date: Sat Sep 5 20:06:27 2020 +0200 Branches: master https://developer.blender.org/rB675c9644420eba96751e1cadedd2656a8bc39191
Sculpt: Sculpt Trimming gestures tools This implements Box Trim as a boolean based trimming too gesture in sculpt mode. This is the intended way to remove parts of the sculpt instead of using box mask and mask slice. It also creates new face sets for the new faces created after the boolean operation. Reviewed By: sergey Differential Revision: https://developer.blender.org/D8766 =================================================================== M release/scripts/presets/keyconfig/keymap_data/blender_default.py M release/scripts/startup/bl_ui/space_toolsystem_toolbar.py M source/blender/editors/sculpt_paint/paint_mask.c M source/blender/editors/sculpt_paint/sculpt.c M source/blender/editors/sculpt_paint/sculpt_intern.h M source/blender/windowmanager/intern/wm_operators.c =================================================================== diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py index acb2e731e12..53b45ed6c90 100644 --- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py +++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py @@ -6332,7 +6332,6 @@ def km_3d_view_tool_sculpt_box_face_set(params): ]}, ) - def km_3d_view_tool_sculpt_lasso_face_set(params): return ( "3D View Tool: Sculpt, Lasso Face Set", @@ -6342,6 +6341,26 @@ def km_3d_view_tool_sculpt_lasso_face_set(params): None), ]}, ) + +def km_3d_view_tool_sculpt_box_trim(params): + return ( + "3D View Tool: Sculpt, Box Trim", + {"space_type": 'VIEW_3D', "region_type": 'WINDOW'}, + {"items": [ + ("sculpt.trim_box_gesture", {"type": params.tool_tweak, "value": 'ANY'}, + None), + ]}, + ) + +def km_3d_view_tool_sculpt_lasso_trim(params): + return ( + "3D View Tool: Sculpt, Lasso Trim", + {"space_type": 'VIEW_3D', "region_type": 'WINDOW'}, + {"items": [ + ("sculpt.trim_lasso_gesture", {"type": params.tool_tweak, "value": 'ANY'}, + None), + ]}, + ) def km_3d_view_tool_sculpt_mesh_filter(params): return ( @@ -6938,6 +6957,8 @@ def generate_keymaps(params=None): km_3d_view_tool_sculpt_lasso_mask(params), km_3d_view_tool_sculpt_box_face_set(params), km_3d_view_tool_sculpt_lasso_face_set(params), + km_3d_view_tool_sculpt_box_trim(params), + km_3d_view_tool_sculpt_lasso_trim(params), km_3d_view_tool_sculpt_mesh_filter(params), km_3d_view_tool_sculpt_cloth_filter(params), km_3d_view_tool_sculpt_color_filter(params), diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py index c17b981a6b8..ab7ac007257 100644 --- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py +++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py @@ -1284,6 +1284,26 @@ class _defs_sculpt: draw_settings=draw_settings, ) + @ToolDef.from_fn + def trim_box(): + return dict( + idname="builtin.box_trim", + label="Box Trim", + icon="ops.sculpt.box_trim", + widget=None, + keymap=(), + ) + + @ToolDef.from_fn + def trim_lasso(): + return dict( + idname="builtin.lasso_trim", + label="Lasso Trim", + icon="ops.sculpt.lasso_trim", + widget=None, + keymap=(), + ) + @ToolDef.from_fn def mesh_filter(): @@ -2632,6 +2652,10 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel): _defs_sculpt.face_set_lasso, ), _defs_sculpt.hide_border, + ( + _defs_sculpt.trim_box, + _defs_sculpt.trim_lasso, + ), None, _defs_sculpt.mesh_filter, _defs_sculpt.cloth_filter, diff --git a/source/blender/editors/sculpt_paint/paint_mask.c b/source/blender/editors/sculpt_paint/paint_mask.c index fd17793b6de..70f8ef89e9a 100644 --- a/source/blender/editors/sculpt_paint/paint_mask.c +++ b/source/blender/editors/sculpt_paint/paint_mask.c @@ -23,14 +23,18 @@ #include "MEM_guardedalloc.h" +#include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" +#include "DNA_modifier_types.h" #include "DNA_object_types.h" #include "DNA_vec_types.h" +#include "BLI_alloca.h" #include "BLI_bitmap_draw_2d.h" #include "BLI_lasso_2d.h" #include "BLI_math_geom.h" #include "BLI_math_matrix.h" +#include "BLI_polyfill_2d.h" #include "BLI_rect.h" #include "BLI_task.h" #include "BLI_utildefines.h" @@ -56,6 +60,8 @@ #include "ED_view3d.h" #include "bmesh.h" +#include "bmesh_tools.h" +#include "tools/bmesh_boolean.h" #include "paint_intern.h" @@ -256,10 +262,18 @@ typedef struct SculptGestureContext { struct SculptGestureOperation *operation; + /* Gesture data. */ + /* Screen space points that represent the gesture shape. */ + float (*gesture_points)[2]; + int tot_gesture_points; + /* View parameters. */ float true_view_normal[3]; float view_normal[3]; + float true_view_origin[3]; + float view_origin[3]; + float true_clip_planes[4][4]; float clip_planes[4][4]; @@ -319,6 +333,9 @@ static void sculpt_gesture_context_init_common(bContext *C, copy_m3_m4(mat, ob->imat); mul_m3_v3(mat, view_dir); normalize_v3_v3(sgcontext->true_view_normal, view_dir); + + /* View Origin. */ + copy_v3_v3(sgcontext->true_view_origin, sgcontext->vc.rv3d->viewinv[3]); } static void sculpt_gesture_lasso_px_cb(int x, int x_end, int y, void *user_data) @@ -370,6 +387,14 @@ static SculptGestureContext *sculpt_gesture_init_from_lasso(bContext *C, wmOpera sgcontext->vc.region, sgcontext->vc.obact, &sgcontext->lasso.boundbox); + + sgcontext->gesture_points = MEM_malloc_arrayN(mcoords_len, sizeof(float[2]), "trim points"); + sgcontext->tot_gesture_points = mcoords_len; + for (int i = 0; i < mcoords_len; i++) { + sgcontext->gesture_points[i][0] = mcoords[i][0]; + sgcontext->gesture_points[i][1] = mcoords[i][1]; + } + MEM_freeN((void *)mcoords); return sgcontext; @@ -390,12 +415,27 @@ static SculptGestureContext *sculpt_gesture_init_from_box(bContext *C, wmOperato ED_view3d_clipping_calc( &bb, sgcontext->true_clip_planes, sgcontext->vc.region, sgcontext->vc.obact, &rect); + sgcontext->gesture_points = MEM_calloc_arrayN(4, sizeof(float[2]), "trim points"); + sgcontext->tot_gesture_points = 4; + + sgcontext->gesture_points[0][0] = rect.xmax; + sgcontext->gesture_points[0][1] = rect.ymax; + + sgcontext->gesture_points[1][0] = rect.xmax; + sgcontext->gesture_points[1][1] = rect.ymin; + + sgcontext->gesture_points[2][0] = rect.xmin; + sgcontext->gesture_points[2][1] = rect.ymin; + + sgcontext->gesture_points[3][0] = rect.xmin; + sgcontext->gesture_points[3][1] = rect.ymax; return sgcontext; } static void sculpt_gesture_context_free(SculptGestureContext *sgcontext) { MEM_SAFE_FREE(sgcontext->lasso.mask_px); + MEM_SAFE_FREE(sgcontext->gesture_points); MEM_SAFE_FREE(sgcontext->operation); MEM_SAFE_FREE(sgcontext->nodes); MEM_SAFE_FREE(sgcontext); @@ -434,6 +474,7 @@ static void sculpt_gesture_flip_for_symmetry_pass(SculptGestureContext *sgcontex } negate_m4(sgcontext->clip_planes); flip_v3_v3(sgcontext->view_normal, sgcontext->true_view_normal, symmpass); + flip_v3_v3(sgcontext->view_origin, sgcontext->true_view_origin, symmpass); } static void sculpt_gesture_update_effected_nodes(SculptGestureContext *sgcontext) @@ -699,6 +740,361 @@ static void paint_mask_gesture_operator_properties(wmOperatorType *ot) 1.0f); } +/* Trim Gesture Operation. */ + +typedef enum eSculptTrimOperationType { + SCULPT_GESTURE_TRIM_INTERSECT, + SCULPT_GESTURE_TRIM_DIFFERENCE, +} eSculptTrimOperationType; + +static EnumPropertyItem prop_trim_operation_types[] = { + {SCULPT_GESTURE_TRIM_INTERSECT, "INTERSECT", 0, "Intersect", ""}, + {SCULPT_GESTURE_TRIM_DIFFERENCE, "DIFFERENCE", 0, "Difference", ""}, + {0, NULL, 0, NULL, NULL}, +}; + +typedef struct SculptGestureTrimOperation { + SculptGestureOperation op; + + Mesh *mesh; + float (*true_mesh_co)[3]; + + float depth_front; + float depth_back; + + eSculptTrimOperationType mode; +} SculptGestureTrimOperation; + +static void sculpt_gesture_trim_normals_update(SculptGestureContext *sgcontext) +{ + SculptGestureTrimOperation *trim_operation = (SculptGestureTrimOperation *)sgcontext->operation; + Mesh *trim_mesh = trim_operation->mesh; + BKE_mesh_calc_normals(trim_mesh); + + const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_ME(trim_mesh); + BMesh *bm; + bm = BM_mesh_create(&allocsize, + &((struct BMeshCreateParams){ + .use_toolflags = true, + })); + + BM_mesh_bm_from_me(bm, + trim_mesh, + (&(struct BMeshFromMeshParams){ + .calc_face_normal = true, + })); + BM_mesh_elem_hflag_enable_all(bm, BM_FACE, BM_ELEM_TAG, false); + BMO_op_callf(bm, + (BMO_FLAG_DEFAULTS & ~BMO_FLAG_RESPECT_HIDE), + "recalc_face_normals faces=%hf", + BM_ELEM_TAG); + BM_mesh_elem_hflag_disable_all(bm, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_TAG, false); + Mesh *result = BKE_mesh_from_bmesh_nomain(bm, + (&(struct BMeshToMeshParams){ + .calc_object_remap = false, + }), + trim_mesh); + BM_mesh_free(bm); + BKE_mesh_free(trim_mesh); + trim_operation->mesh = result; +} + +static void sculpt_gesture_trim_calculate_depth(SculptGestureContext *sgcontext) +{ + SculptGestureTrimOperation *trim_operation = (SculptGestureTrimOperation *)sgcontext->operation; + + SculptSession *ss = sgcontext->ss; + const int totvert = SCULPT_vertex_count_get(ss); + + float view_plane[4]; + plane_from_point_normal_v3(view_plane, sgcontext->true_view_origin, sgcontext->true_view_normal); + + trim_operation->depth_front = FLT_MAX; + trim_operation->depth_back = -FLT_MAX; + + for (int i = 0; i < totvert; i++) { + const float *vco = SCULPT_vertex_co_get(ss, i); + const float dist = dist_signed_to_plane_v3(vco, view_plane); + trim_operation->depth_front = min_ff(dist, trim_operation->depth_front); + trim_operation->depth_back = max_ff(dist, trim_operation->depth_back); + } +} + +static void sculpt_gesture_trim_geometry_generate(SculptGestureContext *sgcontext) +{ + SculptGestureTrimOperation *trim_operation = (SculptGestureTrimOperation *)sgcontext->operation; + ViewContext *vc = &sgcontext->vc; + ARegion *region = vc->region; + + const int tot_screen_points = sgcontext->tot_gesture_po @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs