Skip to content

Commit

Permalink
Ondine: add Weight Gradient tool for GPv3
Browse files Browse the repository at this point in the history
  • Loading branch information
SietseB committed Jun 9, 2024
1 parent f789ec1 commit 9708e98
Show file tree
Hide file tree
Showing 15 changed files with 505 additions and 28 deletions.
29 changes: 29 additions & 0 deletions scripts/presets/keyconfig/keymap_data/blender_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -4792,6 +4792,34 @@ def km_grease_pencil_weight_paint(params):
return keymap


def km_grease_pencil_weight_gradient(params):
items = []
keymap = (
"Grease Pencil Weight Gradient",
{"space_type": 'EMPTY', "region_type": 'WINDOW'},
{"items": items},
)

items.extend([
("grease_pencil.weight_gradient",
{"type": params.tool_mouse, "value": params.tool_maybe_tweak_value},
{"properties": [("mode", 'NORMAL')]}),
("grease_pencil.weight_gradient",
{"type": params.tool_mouse, "value": params.tool_maybe_tweak_value, "ctrl": True},
{"properties": [("mode", 'INVERT')]}),
# Radial controls
*_template_paint_radial_control("gpencil_weight_paint"),
("wm.radial_control", {"type": 'F', "value": 'PRESS', "ctrl": True},
radial_control_properties("gpencil_weight_paint", 'weight', 'use_unified_weight')),
# Toggle Add/Subtract for weight draw tool
("grease_pencil.weight_toggle_direction", {"type": 'D', "value": 'PRESS'}, None),
# Context menu
*_template_items_context_panel("VIEW3D_PT_gpencil_weight_context_menu", params.context_menu_event),
])

return keymap


# Grease Pencil v3 Fill Tool.
def km_grease_pencil_fill_tool(_params):
items = []
Expand Down Expand Up @@ -9108,6 +9136,7 @@ def generate_keymaps(params=None):
km_grease_pencil_edit_mode(params),
km_grease_pencil_sculpt_mode(params),
km_grease_pencil_weight_paint(params),
km_grease_pencil_weight_gradient(params),
km_grease_pencil_brush_stroke(params),
km_grease_pencil_fill_tool(params),
# Object mode.
Expand Down
37 changes: 24 additions & 13 deletions scripts/startup/bl_ui/properties_paint_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: GPL-2.0-or-later

from bpy.types import Menu
from bpy.types import Menu, WindowManager


class BrushAssetShelf:
Expand Down Expand Up @@ -1625,18 +1625,21 @@ def brush_basic_gpencil_vertex_settings(layout, _context, brush, *, compact=Fals


def brush_basic_grease_pencil_weight_settings(layout, context, brush, *, compact=False):
UnifiedPaintPanel.prop_unified(
layout,
context,
brush,
"size",
pressure_name="use_pressure_size",
unified_name="use_unified_size",
text="Radius",
slider=True,
header=compact,
)
# Brush radius
if brush.gpencil_weight_tool != 'GRADIENT':
UnifiedPaintPanel.prop_unified(
layout,
context,
brush,
"size",
pressure_name="use_pressure_size",
unified_name="use_unified_size",
text="Radius",
slider=True,
header=compact,
)

# Strength
capabilities = brush.sculpt_capabilities
pressure_name = "use_pressure_strength" if capabilities.has_strength_pressure else None
UnifiedPaintPanel.prop_unified(
Expand All @@ -1650,7 +1653,8 @@ def brush_basic_grease_pencil_weight_settings(layout, context, brush, *, compact
header=compact,
)

if brush.gpencil_weight_tool in {'WEIGHT'}:
# Weight
if brush.gpencil_weight_tool in {'WEIGHT', 'GRADIENT'}:
UnifiedPaintPanel.prop_unified(
layout,
context,
Expand All @@ -1661,8 +1665,15 @@ def brush_basic_grease_pencil_weight_settings(layout, context, brush, *, compact
slider=True,
header=compact,
)

# Direction: add/subtract
layout.prop(brush, "direction", expand=True, text="" if compact else "Direction")

# Gradient type: linear/radial
if brush.gpencil_weight_tool == 'GRADIENT':
# Bit of a trick, but the only working way to expose the operator property `type`
layout.prop(WindowManager.operator_properties_last("grease_pencil.weight_gradient"), "type", expand=True)


classes = (
VIEW3D_MT_tools_projectpaint_clone,
Expand Down
3 changes: 0 additions & 3 deletions scripts/startup/bl_ui/space_toolsystem_toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2861,9 +2861,6 @@ def generate_from_brushes(context):
type=bpy.types.Brush,
# Uses GPv2 tool settings
attr="gpencil_weight_tool",
tooldef_keywords=dict(
operator="grease_pencil.weight_brush_stroke",
),
)


Expand Down
1 change: 1 addition & 0 deletions source/blender/blenkernel/intern/brush.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,7 @@ void BKE_gpencil_brush_preset_set(Main *bmain, Brush *brush, const short type)
}
case GP_BRUSH_PRESET_WEIGHT_GRADIENT: {
brush->gpencil_settings->icon_id = GP_BRUSH_ICON_VERTEX_BLUR;
brush->gpencil_weight_tool = GPWEIGHT_TOOL_GRADIENT;

brush->alpha = 1.0f;
brush->weight = 1.0f;
Expand Down
1 change: 1 addition & 0 deletions source/blender/editors/datafiles/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@ set_property(GLOBAL PROPERTY ICON_GEOM_NAMES
ops.gpencil.sculpt_blur
ops.gpencil.sculpt_clone
ops.gpencil.sculpt_grab
ops.gpencil.sculpt_gradient
ops.gpencil.sculpt_pinch
ops.gpencil.sculpt_push
ops.gpencil.sculpt_randomize
Expand Down
2 changes: 1 addition & 1 deletion source/blender/editors/gpencil_legacy/gpencil_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2107,7 +2107,7 @@ static void gpencil_brush_delete_mode_brushes(Main *bmain,
}

if (mode == CTX_MODE_WEIGHT_GPENCIL_LEGACY) {
if ((preset < GP_BRUSH_PRESET_WEIGHT_DRAW) || (preset > GP_BRUSH_PRESET_WEIGHT_SMEAR)) {
if ((preset < GP_BRUSH_PRESET_WEIGHT_DRAW) || (preset > GP_BRUSH_PRESET_WEIGHT_GRADIENT)) {
continue;
}
if ((brush_active) && (brush_active->gpencil_weight_tool != brush->gpencil_weight_tool)) {
Expand Down
23 changes: 22 additions & 1 deletion source/blender/editors/grease_pencil/intern/grease_pencil_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,25 @@ bool grease_pencil_weight_painting_poll(bContext *C)
if (!ts || !ts->gp_weightpaint) {
return false;
}
return true;
Brush *brush = BKE_paint_brush(&ts->gp_weightpaint->paint);
return brush && brush->gpencil_settings && brush->gpencil_weight_tool != GPWEIGHT_TOOL_GRADIENT;
}

bool grease_pencil_weight_gradient_poll(bContext *C)
{
if (!active_grease_pencil_poll(C)) {
return false;
}
Object *object = CTX_data_active_object(C);
if ((object->mode & OB_MODE_WEIGHT_GPENCIL_LEGACY) == 0) {
return false;
}
ToolSettings *ts = CTX_data_tool_settings(C);
if (!ts || !ts->gp_weightpaint) {
return false;
}
Brush *brush = BKE_paint_brush(&ts->gp_weightpaint->paint);
return brush && brush->gpencil_settings && brush->gpencil_weight_tool == GPWEIGHT_TOOL_GRADIENT;
}

static void keymap_grease_pencil_edit_mode(wmKeyConfig *keyconf)
Expand Down Expand Up @@ -143,6 +161,9 @@ static void keymap_grease_pencil_weight_paint_mode(wmKeyConfig *keyconf)
wmKeyMap *keymap = WM_keymap_ensure(
keyconf, "Grease Pencil Weight Paint", SPACE_EMPTY, RGN_TYPE_WINDOW);
keymap->poll = grease_pencil_weight_painting_poll;
keymap = WM_keymap_ensure(
keyconf, "Grease Pencil Weight Gradient", SPACE_EMPTY, RGN_TYPE_WINDOW);
keymap->poll = grease_pencil_weight_gradient_poll;
}

/* Enabled for all tools except the fill tool. */
Expand Down
Loading

0 comments on commit 9708e98

Please sign in to comment.