Commit: 8c81b3fb8b9c857626c037fe0c95c5d48a3ca20f Author: Pablo Dobarro Date: Sat Sep 26 21:59:30 2020 +0200 Branches: master https://developer.blender.org/rB8c81b3fb8b9c857626c037fe0c95c5d48a3ca20f
Sculpt: Line gestures and Mask Line tool This adds support for line gesture to SculptGestureContext and implements a Mask Line tool, which affects everything to the right of a plane defined by the straightline gesture. For this to work, a new WM_gesture_straightline_oneshot_modal is needed which only runs exec when the gesture is over. Added as experimental as it does not have icon. Reviewed By: Severin Differential Revision: https://developer.blender.org/D8722 =================================================================== 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_intern.h M source/blender/editors/sculpt_paint/paint_mask.c M source/blender/editors/sculpt_paint/paint_ops.c M source/blender/windowmanager/WM_api.h M source/blender/windowmanager/intern/wm_gesture_ops.c 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 fdd654009a7..f3e4c82090e 100644 --- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py +++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py @@ -6388,6 +6388,17 @@ def km_3d_view_tool_sculpt_lasso_trim(params): ]}, ) +def km_3d_view_tool_sculpt_line_mask(params): + return ( + "3D View Tool: Sculpt, Line Mask", + {"space_type": 'VIEW_3D', "region_type": 'WINDOW'}, + {"items": [ + ("paint.mask_line_gesture", {"type": params.tool_tweak, "value": 'ANY'}, + {"properties": [("value", 1.0)]}), + ("paint.mask_line_gesture", {"type": params.tool_tweak, "value": 'ANY', "ctrl": True}, + {"properties": [("value", 0.0)]}), + ]}, + ) def km_3d_view_tool_sculpt_mesh_filter(params): return ( @@ -6993,6 +7004,7 @@ def generate_keymaps(params=None): 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_line_mask(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 75dfd60b1d4..3f7a3604741 100644 --- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py +++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py @@ -1258,6 +1258,21 @@ class _defs_sculpt: draw_settings=draw_settings, ) + @ToolDef.from_fn + def mask_line(): + def draw_settings(_context, layout, tool): + props = tool.operator_properties("paint.mask_line_gesture") + layout.prop(props, "use_front_faces_only", expand=False) + + return dict( + idname="builtin.line_mask", + label="Line Mask", + icon="ops.sculpt.line_mask", + widget=None, + keymap=(), + draw_settings=draw_settings, + ) + @ToolDef.from_fn def face_set_box(): def draw_settings(_context, layout, tool): @@ -1273,6 +1288,7 @@ class _defs_sculpt: draw_settings=draw_settings, ) + @ToolDef.from_fn def face_set_lasso(): def draw_settings(_context, layout, tool): @@ -1308,7 +1324,6 @@ class _defs_sculpt: keymap=(), ) - @ToolDef.from_fn def mesh_filter(): def draw_settings(_context, layout, tool): @@ -2652,6 +2667,13 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel): _defs_sculpt.mask_lasso, ), _defs_sculpt.hide_border, + lambda context: ( + (_defs_sculpt.mask_line,) + if context is None or ( + context.preferences.view.show_developer_ui and + context.preferences.experimental.use_tools_missing_icons) + else () + ), lambda context: ( (_defs_sculpt.face_set_box,) if context is None or ( diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index a1894e1b4c6..175d98ba9aa 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -341,6 +341,7 @@ typedef enum { void PAINT_OT_mask_flood_fill(struct wmOperatorType *ot); void PAINT_OT_mask_lasso_gesture(struct wmOperatorType *ot); void PAINT_OT_mask_box_gesture(struct wmOperatorType *ot); +void PAINT_OT_mask_line_gesture(struct wmOperatorType *ot); /* paint_curve.c */ void PAINTCURVE_OT_new(struct wmOperatorType *ot); diff --git a/source/blender/editors/sculpt_paint/paint_mask.c b/source/blender/editors/sculpt_paint/paint_mask.c index fc17af8d2cb..0f2ebdd28aa 100644 --- a/source/blender/editors/sculpt_paint/paint_mask.c +++ b/source/blender/editors/sculpt_paint/paint_mask.c @@ -234,6 +234,7 @@ void PAINT_OT_mask_flood_fill(struct wmOperatorType *ot) typedef enum eSculptGestureShapeType { SCULPT_GESTURE_SHAPE_BOX, SCULPT_GESTURE_SHAPE_LASSO, + SCULPT_GESTURE_SHAPE_LINE, } eMaskGesturesShapeType; typedef struct LassoGestureData { @@ -246,6 +247,11 @@ typedef struct LassoGestureData { BLI_bitmap *mask_px; } LassoGestureData; +typedef struct LineGestureData { + float true_plane[4]; + float plane[4]; +} LineGestureData; + struct SculptGestureOperation; typedef struct SculptGestureContext { @@ -280,6 +286,9 @@ typedef struct SculptGestureContext { /* Lasso Gesture. */ LassoGestureData lasso; + /* Line Gesture. */ + LineGestureData line; + /* Task Callback Data. */ PBVHNode **nodes; int totnode; @@ -430,6 +439,44 @@ static SculptGestureContext *sculpt_gesture_init_from_box(bContext *C, wmOperato return sgcontext; } +static SculptGestureContext *sculpt_gesture_init_from_line(bContext *C, wmOperator *op) +{ + SculptGestureContext *sgcontext = MEM_callocN(sizeof(SculptGestureContext), + "sculpt gesture context line"); + sgcontext->shape_type = SCULPT_GESTURE_SHAPE_LINE; + + sculpt_gesture_context_init_common(C, op, sgcontext); + + float line_points[2][2]; + line_points[0][0] = RNA_int_get(op->ptr, "xstart"); + line_points[0][1] = RNA_int_get(op->ptr, "ystart"); + line_points[1][0] = RNA_int_get(op->ptr, "xend"); + line_points[1][1] = RNA_int_get(op->ptr, "yend"); + + float depth_point[3]; + float plane_points[3][3]; + + /* Calculate a triangle in the line's plane. */ + add_v3_v3v3(depth_point, sgcontext->true_view_origin, sgcontext->true_view_normal); + ED_view3d_win_to_3d( + sgcontext->vc.v3d, sgcontext->vc.region, depth_point, line_points[0], plane_points[0]); + + madd_v3_v3v3fl(depth_point, sgcontext->true_view_origin, sgcontext->true_view_normal, 10.0f); + ED_view3d_win_to_3d( + sgcontext->vc.v3d, sgcontext->vc.region, depth_point, line_points[0], plane_points[1]); + ED_view3d_win_to_3d( + sgcontext->vc.v3d, sgcontext->vc.region, depth_point, line_points[1], plane_points[2]); + + /* Calculate final line plane and normal using the triangle. */ + float normal[3]; + normal_tri_v3(normal, plane_points[0], plane_points[1], plane_points[2]); + if (!sgcontext->vc.rv3d->is_persp) { + mul_v3_fl(normal, -1.0f); + } + plane_from_point_normal_v3(sgcontext->line.true_plane, plane_points[0], normal); + return sgcontext; +} + static void sculpt_gesture_context_free(SculptGestureContext *sgcontext) { MEM_SAFE_FREE(sgcontext->lasso.mask_px); @@ -470,12 +517,28 @@ static void sculpt_gesture_flip_for_symmetry_pass(SculptGestureContext *sgcontex for (int j = 0; j < 4; j++) { flip_plane(sgcontext->clip_planes[j], sgcontext->true_clip_planes[j], symmpass); } + 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); + flip_plane(sgcontext->line.plane, sgcontext->line.true_plane, symmpass); } -static void sculpt_gesture_update_effected_nodes(SculptGestureContext *sgcontext) +static void sculpt_gesture_update_effected_nodes_by_line_plane(SculptGestureContext *sgcontext) +{ + SculptSession *ss = sgcontext->ss; + float clip_planes[1][4]; + copy_v4_v4(clip_planes[0], sgcontext->line.plane); + PBVHFrustumPlanes frustum = {.planes = clip_planes, .num_planes = 1}; + BKE_pbvh_search_gather(ss->pbvh, + BKE_pbvh_node_frustum_contain_AABB, + &frustum, + &sgcontext->nodes, + &sgcontext->totnode); +} + +static void sculpt_gesture_update_effected_nodes_by_clip_planes(SculptGestureContext *sgcontext) { SculptSession *ss = sgcontext->ss; float clip_planes[4][4]; @@ -489,6 +552,19 @@ static void sculpt_gesture_update_effected_nodes(SculptGestureContext *sgcontext &sgcontext->totnode); } +static void sculpt_gesture_update_effected_nodes(SculptGestureContext *sgcontext) +{ + switch (sgcontext->shape_type) { + case SCULPT_GESTURE_SHAPE_BOX: + case SCULPT_GESTURE_SHAPE_LASSO: + sculpt_gesture_update_effected_nodes_by_clip_planes(sgcontext); + break; + case SCULPT_GESTURE_SHAPE_LINE: + sculpt_gesture_update_effected_nodes_by_line_plane(sgcontext); + break; + } +} + static bool sculpt_gesture_is_effected_lasso(SculptGestureContext *sgcontext, const float co[3]) { float scr_co_f[2]; @@ -532,6 +608,8 @@ static bool sculpt_gesture_is_vertex_effected(SculptGestureContext *sgcontext, P return isect_point_planes_v3(sgcontext->clip_planes, 4, vd->co); case SCULPT_GESTURE_SHAPE_LASSO: return sculpt_gesture_is_effected_lasso(sgcontext, vd->co); + case SCULPT_GESTURE_SHAPE_LINE: + return plane_point_side_v3(sgcontext->line.plane, vd->co) > 0.0f; } return false; } @@ -1117,6 +1195,18 @@ static int paint_mask_gesture_lasso_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } +static int paint_mask_gesture_line_exec(bContext *C, wmOperator *op) +{ + SculptGestureContext *sgcontext = sculpt_gesture_init_from_line(C, op); + if (!sgcontext) { + return OPERATOR_CANCELLED; + } + sculpt_gesture_init_mask_properties(sgcontext, op); + sculpt_gesture_apply(C, sgcontext); + sculpt_gesture_context_free(sgcontext); + return OPERATOR_FINISHED; +} + static int face_set_gesture_box_exec(bContext *C, wmOperator *op) { SculptGestureContext *sgcontext = sculpt_gesture_init_from_box(C, op); @@ -1222,6 +1312,27 @@ void PAINT_OT_mask_box_gesture(wmOperatorType *ot) paint_mask_gesture_operator_properties(ot); } +void PAINT_OT_mask_line_gesture(wmOperatorType *ot) +{ + ot->name = "Mask Line Gesture"; + ot->idname = "PAINT_OT_mask_line_gesture"; + ot->description = "Add mask to the right of a line as you m @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list [email protected] https://lists.blender.org/mailman/listinfo/bf-blender-cvs
