GPv3: Add separate paint mode
This patch adds a separate paint mode for Grease Pencil 3.0. Pull Request: https://projects.blender.org/blender/blender/pulls/109453
This commit is contained in:
@@ -5170,6 +5170,26 @@ def km_weight_paint(params):
|
||||
return keymap
|
||||
|
||||
|
||||
def km_grease_pencil_paint(params):
|
||||
items = []
|
||||
keymap = (
|
||||
"Grease Pencil Paint Mode",
|
||||
{"space_type": 'EMPTY', "region_type": 'WINDOW'},
|
||||
{"items": items},
|
||||
)
|
||||
|
||||
items.extend([
|
||||
("grease_pencil.brush_stroke", {"type": 'LEFTMOUSE', "value": 'PRESS'},
|
||||
{"properties": [("mode", 'NORMAL')]}),
|
||||
("grease_pencil.brush_stroke", {"type": 'LEFTMOUSE', "value": 'PRESS', "ctrl": True},
|
||||
{"properties": [("mode", 'INVERT')]}),
|
||||
("grease_pencil.brush_stroke", {"type": 'LEFTMOUSE', "value": 'PRESS', "shift": True},
|
||||
{"properties": [("mode", 'SMOOTH')]}),
|
||||
])
|
||||
|
||||
return keymap
|
||||
|
||||
|
||||
def km_sculpt(params):
|
||||
items = []
|
||||
keymap = (
|
||||
@@ -8266,6 +8286,7 @@ def generate_keymaps(params=None):
|
||||
km_image_paint(params),
|
||||
km_vertex_paint(params),
|
||||
km_weight_paint(params),
|
||||
km_grease_pencil_paint(params),
|
||||
km_sculpt(params),
|
||||
km_mesh(params),
|
||||
km_armature(params),
|
||||
|
||||
@@ -1731,6 +1731,18 @@ class _defs_weight_paint:
|
||||
)
|
||||
|
||||
|
||||
class _defs_paint_grease_pencil:
|
||||
|
||||
@ToolDef.from_fn
|
||||
def draw():
|
||||
return dict(
|
||||
idname="builtin_brush.Draw",
|
||||
label="Draw",
|
||||
icon="brush.gpencil_draw.draw",
|
||||
data_block='DRAW',
|
||||
)
|
||||
|
||||
|
||||
class _defs_image_generic:
|
||||
|
||||
@staticmethod
|
||||
@@ -1972,13 +1984,6 @@ class _defs_gpencil_paint:
|
||||
|
||||
@staticmethod
|
||||
def generate_from_brushes(context):
|
||||
if context and context.preferences.experimental.use_grease_pencil_version3:
|
||||
return tuple([ToolDef.from_dict(dict(
|
||||
idname="builtin_brush.Draw",
|
||||
label="Draw",
|
||||
icon="brush.gpencil_draw.draw",
|
||||
data_block='DRAW',
|
||||
))])
|
||||
return generate_from_enum_ex(
|
||||
context,
|
||||
idname_prefix="builtin_brush.",
|
||||
@@ -3096,6 +3101,11 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
|
||||
),
|
||||
*_tools_annotate,
|
||||
],
|
||||
'PAINT_GREASE_PENCIL': [
|
||||
_defs_view3d_generic.cursor,
|
||||
None,
|
||||
_defs_paint_grease_pencil.draw,
|
||||
],
|
||||
'PAINT_GPENCIL': [
|
||||
_defs_view3d_generic.cursor,
|
||||
None,
|
||||
|
||||
@@ -967,7 +967,7 @@ class VIEW3D_MT_editor_menus(Menu):
|
||||
layout.menu("VIEW3D_MT_select_paint_mask")
|
||||
elif mesh.use_paint_mask_vertex and mode_string in {'PAINT_WEIGHT', 'PAINT_VERTEX'}:
|
||||
layout.menu("VIEW3D_MT_select_paint_mask_vertex")
|
||||
elif mode_string not in {'SCULPT', 'SCULPT_CURVES'}:
|
||||
elif mode_string not in {'SCULPT', 'SCULPT_CURVES', 'PAINT_GREASE_PENCIL'}:
|
||||
layout.menu("VIEW3D_MT_select_%s" % mode_string.lower())
|
||||
|
||||
if gp_edit:
|
||||
@@ -2001,6 +2001,12 @@ class VIEW3D_MT_select_edit_grease_pencil(Menu):
|
||||
layout.operator("grease_pencil.select_more")
|
||||
layout.operator("grease_pencil.select_less")
|
||||
|
||||
class VIEW3D_MT_paint_grease_pencil(Menu):
|
||||
bl_label = "Paint"
|
||||
|
||||
def draw(self, _context):
|
||||
pass
|
||||
|
||||
|
||||
class VIEW3D_MT_paint_gpencil(Menu):
|
||||
bl_label = "Paint"
|
||||
@@ -8327,6 +8333,7 @@ classes = (
|
||||
VIEW3D_MT_edit_mesh_merge,
|
||||
VIEW3D_MT_edit_mesh_split,
|
||||
VIEW3D_MT_edit_mesh_showhide,
|
||||
VIEW3D_MT_paint_grease_pencil,
|
||||
VIEW3D_MT_paint_gpencil,
|
||||
VIEW3D_MT_draw_gpencil,
|
||||
VIEW3D_MT_assign_material,
|
||||
|
||||
@@ -133,8 +133,9 @@ typedef enum eContextObjectMode {
|
||||
CTX_MODE_WEIGHT_GPENCIL_LEGACY,
|
||||
CTX_MODE_VERTEX_GPENCIL_LEGACY,
|
||||
CTX_MODE_SCULPT_CURVES,
|
||||
CTX_MODE_PAINT_GREASE_PENCIL,
|
||||
} eContextObjectMode;
|
||||
#define CTX_MODE_NUM (CTX_MODE_SCULPT_CURVES + 1)
|
||||
#define CTX_MODE_NUM (CTX_MODE_PAINT_GREASE_PENCIL + 1)
|
||||
|
||||
/* Context */
|
||||
|
||||
|
||||
@@ -1231,6 +1231,9 @@ enum eContextObjectMode CTX_data_mode_enum_ex(const Object *obedit,
|
||||
if (object_mode & OB_MODE_SCULPT_CURVES) {
|
||||
return CTX_MODE_SCULPT_CURVES;
|
||||
}
|
||||
if (object_mode & OB_MODE_PAINT_GREASE_PENCIL) {
|
||||
return CTX_MODE_PAINT_GREASE_PENCIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1250,12 +1253,31 @@ enum eContextObjectMode CTX_data_mode_enum(const bContext *C)
|
||||
* \note Must be aligned with above enum.
|
||||
*/
|
||||
static const char *data_mode_strings[] = {
|
||||
"mesh_edit", "curve_edit", "surface_edit", "text_edit",
|
||||
"armature_edit", "mball_edit", "lattice_edit", "curves_edit",
|
||||
"grease_pencil_edit", "point_cloud_edit", "posemode", "sculpt_mode",
|
||||
"weightpaint", "vertexpaint", "imagepaint", "particlemode",
|
||||
"objectmode", "greasepencil_paint", "greasepencil_edit", "greasepencil_sculpt",
|
||||
"greasepencil_weight", "greasepencil_vertex", "curves_sculpt", nullptr,
|
||||
"mesh_edit",
|
||||
"curve_edit",
|
||||
"surface_edit",
|
||||
"text_edit",
|
||||
"armature_edit",
|
||||
"mball_edit",
|
||||
"lattice_edit",
|
||||
"curves_edit",
|
||||
"grease_pencil_edit",
|
||||
"point_cloud_edit",
|
||||
"posemode",
|
||||
"sculpt_mode",
|
||||
"weightpaint",
|
||||
"vertexpaint",
|
||||
"imagepaint",
|
||||
"particlemode",
|
||||
"objectmode",
|
||||
"greasepencil_paint",
|
||||
"greasepencil_edit",
|
||||
"greasepencil_sculpt",
|
||||
"greasepencil_weight",
|
||||
"greasepencil_vertex",
|
||||
"curves_sculpt",
|
||||
"grease_pencil_paint",
|
||||
nullptr,
|
||||
};
|
||||
BLI_STATIC_ASSERT(ARRAY_SIZE(data_mode_strings) == CTX_MODE_NUM + 1,
|
||||
"Must have a string for each context mode")
|
||||
|
||||
@@ -508,6 +508,8 @@ Paint *BKE_paint_get_active(Scene *sce, ViewLayer *view_layer)
|
||||
return &ts->gp_weightpaint->paint;
|
||||
case OB_MODE_SCULPT_CURVES:
|
||||
return &ts->curves_sculpt->paint;
|
||||
case OB_MODE_PAINT_GREASE_PENCIL:
|
||||
return &ts->gp_paint->paint;
|
||||
case OB_MODE_EDIT:
|
||||
return ts->uvsculpt ? &ts->uvsculpt->paint : nullptr;
|
||||
default:
|
||||
@@ -626,6 +628,8 @@ ePaintMode BKE_paintmode_get_from_tool(const bToolRef *tref)
|
||||
return PAINT_MODE_WEIGHT_GPENCIL;
|
||||
case CTX_MODE_SCULPT_CURVES:
|
||||
return PAINT_MODE_SCULPT_CURVES;
|
||||
case CTX_MODE_PAINT_GREASE_PENCIL:
|
||||
return PAINT_MODE_GPENCIL;
|
||||
}
|
||||
}
|
||||
else if (tref->space_type == SPACE_IMAGE) {
|
||||
@@ -685,7 +689,12 @@ void BKE_paint_runtime_init(const ToolSettings *ts, Paint *paint)
|
||||
}
|
||||
else if (ts->gp_paint && paint == &ts->gp_paint->paint) {
|
||||
paint->runtime.tool_offset = offsetof(Brush, gpencil_tool);
|
||||
paint->runtime.ob_mode = OB_MODE_PAINT_GPENCIL_LEGACY;
|
||||
if (U.experimental.use_grease_pencil_version3) {
|
||||
paint->runtime.ob_mode = OB_MODE_PAINT_GREASE_PENCIL;
|
||||
}
|
||||
else {
|
||||
paint->runtime.ob_mode = OB_MODE_PAINT_GPENCIL_LEGACY;
|
||||
}
|
||||
}
|
||||
else if (ts->gp_vertexpaint && paint == &ts->gp_vertexpaint->paint) {
|
||||
paint->runtime.tool_offset = offsetof(Brush, gpencil_vertex_tool);
|
||||
|
||||
@@ -181,6 +181,7 @@ static void OVERLAY_cache_init(void *vedata)
|
||||
case CTX_MODE_EDIT_LATTICE:
|
||||
OVERLAY_edit_lattice_cache_init(data);
|
||||
break;
|
||||
case CTX_MODE_PAINT_GREASE_PENCIL:
|
||||
case CTX_MODE_EDIT_GREASE_PENCIL:
|
||||
OVERLAY_edit_grease_pencil_cache_init(data);
|
||||
break;
|
||||
|
||||
@@ -139,18 +139,6 @@ static bool gpencil_stroke_weightmode_poll_with_tool(bContext *C, const char gpe
|
||||
/* Poll callback for stroke painting (draw brush) */
|
||||
static bool gpencil_stroke_paintmode_draw_poll(bContext *C)
|
||||
{
|
||||
if (U.experimental.use_grease_pencil_version3) {
|
||||
Object *object = CTX_data_active_object(C);
|
||||
if (object == NULL || object->type != OB_GREASE_PENCIL) {
|
||||
return false;
|
||||
}
|
||||
ToolSettings *ts = CTX_data_tool_settings(C);
|
||||
if (!ts || !ts->gp_paint) {
|
||||
return false;
|
||||
}
|
||||
const Brush *brush = BKE_paint_brush_for_read(&ts->gp_paint->paint);
|
||||
return WM_toolsystem_active_tool_is_brush(C) && brush->gpencil_tool == GPAINT_TOOL_DRAW;
|
||||
}
|
||||
return gpencil_stroke_paintmode_poll_with_tool(C, GPAINT_TOOL_DRAW);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,16 +50,39 @@ bool editable_grease_pencil_point_selection_poll(bContext *C)
|
||||
return (ts->gpencil_selectmode_edit != GP_SELECTMODE_STROKE);
|
||||
}
|
||||
|
||||
bool grease_pencil_painting_poll(bContext *C)
|
||||
{
|
||||
if (!active_grease_pencil_poll(C)) {
|
||||
return false;
|
||||
}
|
||||
Object *object = CTX_data_active_object(C);
|
||||
if ((object->mode & OB_MODE_PAINT_GREASE_PENCIL) == 0) {
|
||||
return false;
|
||||
}
|
||||
ToolSettings *ts = CTX_data_tool_settings(C);
|
||||
if (!ts || !ts->gp_paint) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void keymap_grease_pencil_editing(wmKeyConfig *keyconf)
|
||||
{
|
||||
wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Edit Mode", 0, 0);
|
||||
keymap->poll = editable_grease_pencil_poll;
|
||||
}
|
||||
|
||||
static void keymap_grease_pencil_painting(wmKeyConfig *keyconf)
|
||||
{
|
||||
wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Paint Mode", 0, 0);
|
||||
keymap->poll = grease_pencil_painting_poll;
|
||||
}
|
||||
|
||||
} // namespace blender::ed::greasepencil
|
||||
|
||||
void ED_keymap_grease_pencil(wmKeyConfig *keyconf)
|
||||
{
|
||||
using namespace blender::ed::greasepencil;
|
||||
keymap_grease_pencil_editing(keyconf);
|
||||
keymap_grease_pencil_painting(keyconf);
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ namespace blender::ed::greasepencil {
|
||||
bool active_grease_pencil_poll(bContext *C);
|
||||
bool editable_grease_pencil_poll(bContext *C);
|
||||
bool editable_grease_pencil_point_selection_poll(bContext *C);
|
||||
bool grease_pencil_painting_poll(bContext *C);
|
||||
|
||||
void create_blank(Main &bmain, Object &object, int frame_number);
|
||||
void create_stroke(Main &bmain, Object &object, float4x4 matrix, int frame_number);
|
||||
|
||||
@@ -2498,6 +2498,7 @@ int UI_icon_from_object_mode(const int mode)
|
||||
return ICON_PARTICLEMODE;
|
||||
case OB_MODE_POSE:
|
||||
return ICON_POSE_HLT;
|
||||
case OB_MODE_PAINT_GREASE_PENCIL:
|
||||
case OB_MODE_PAINT_GPENCIL_LEGACY:
|
||||
return ICON_GREASEPENCIL;
|
||||
}
|
||||
|
||||
@@ -84,10 +84,8 @@ static const char *object_mode_op_string(eObjectMode mode)
|
||||
if (mode == OB_MODE_EDIT_GPENCIL_LEGACY) {
|
||||
return "GPENCIL_OT_editmode_toggle";
|
||||
}
|
||||
if (U.experimental.use_grease_pencil_version3) {
|
||||
if (mode == OB_MODE_PAINT_GPENCIL_LEGACY) {
|
||||
return "GREASE_PENCIL_OT_draw_mode_toggle";
|
||||
}
|
||||
if (mode == OB_MODE_PAINT_GREASE_PENCIL) {
|
||||
return "GREASE_PENCIL_OT_draw_mode_toggle";
|
||||
}
|
||||
if (mode == OB_MODE_PAINT_GPENCIL_LEGACY) {
|
||||
return "GPENCIL_OT_paintmode_toggle";
|
||||
@@ -156,7 +154,7 @@ bool ED_object_mode_compat_test(const Object *ob, eObjectMode mode)
|
||||
}
|
||||
break;
|
||||
case OB_GREASE_PENCIL:
|
||||
if (mode & (OB_MODE_EDIT | OB_MODE_PAINT_GPENCIL_LEGACY)) {
|
||||
if (mode & (OB_MODE_EDIT | OB_MODE_PAINT_GREASE_PENCIL)) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -188,7 +188,7 @@ static void grease_pencil_draw_mode_enter(bContext *C)
|
||||
GpPaint *grease_pencil_paint = scene->toolsettings->gp_paint;
|
||||
BKE_paint_ensure(scene->toolsettings, (Paint **)&grease_pencil_paint);
|
||||
|
||||
ob->mode = OB_MODE_PAINT_GPENCIL_LEGACY;
|
||||
ob->mode = OB_MODE_PAINT_GREASE_PENCIL;
|
||||
|
||||
/* TODO: Setup cursor color. BKE_paint_init() could be used, but creates an additional brush. */
|
||||
/* TODO: Call ED_paint_cursor_start(...) */
|
||||
@@ -212,10 +212,10 @@ static int grease_pencil_draw_mode_toggle_exec(bContext *C, wmOperator *op)
|
||||
Object *ob = CTX_data_active_object(C);
|
||||
wmMsgBus *mbus = CTX_wm_message_bus(C);
|
||||
|
||||
const bool is_mode_set = ob->mode == OB_MODE_PAINT_GPENCIL_LEGACY;
|
||||
const bool is_mode_set = ob->mode == OB_MODE_PAINT_GREASE_PENCIL;
|
||||
|
||||
if (is_mode_set) {
|
||||
if (!ED_object_mode_compat_set(C, ob, OB_MODE_PAINT_GPENCIL_LEGACY, op->reports)) {
|
||||
if (!ED_object_mode_compat_set(C, ob, OB_MODE_PAINT_GREASE_PENCIL, op->reports)) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -445,6 +445,9 @@ static void view3d_main_region_init(wmWindowManager *wm, ARegion *region)
|
||||
keymap = WM_keymap_ensure(wm->defaultconf, "Grease Pencil Edit Mode", 0, 0);
|
||||
WM_event_add_keymap_handler(®ion->handlers, keymap);
|
||||
|
||||
keymap = WM_keymap_ensure(wm->defaultconf, "Grease Pencil Paint Mode", 0, 0);
|
||||
WM_event_add_keymap_handler(®ion->handlers, keymap);
|
||||
|
||||
/* editfont keymap swallows all... */
|
||||
keymap = WM_keymap_ensure(wm->defaultconf, "Font", 0, 0);
|
||||
WM_event_add_keymap_handler(®ion->handlers, keymap);
|
||||
|
||||
@@ -30,6 +30,7 @@ typedef enum eObjectMode {
|
||||
OB_MODE_WEIGHT_GPENCIL_LEGACY = 1 << 10,
|
||||
OB_MODE_VERTEX_GPENCIL_LEGACY = 1 << 11,
|
||||
OB_MODE_SCULPT_CURVES = 1 << 12,
|
||||
OB_MODE_PAINT_GREASE_PENCIL = 1 << 13,
|
||||
} eObjectMode;
|
||||
|
||||
/** #Object.dt, #View3DShading.type */
|
||||
@@ -63,7 +64,8 @@ typedef enum eDrawType {
|
||||
#define OB_MODE_ALL_MODE_DATA \
|
||||
(OB_MODE_EDIT | OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_SCULPT | OB_MODE_POSE | \
|
||||
OB_MODE_PAINT_GPENCIL_LEGACY | OB_MODE_EDIT_GPENCIL_LEGACY | OB_MODE_SCULPT_GPENCIL_LEGACY | \
|
||||
OB_MODE_WEIGHT_GPENCIL_LEGACY | OB_MODE_VERTEX_GPENCIL_LEGACY | OB_MODE_SCULPT_CURVES)
|
||||
OB_MODE_WEIGHT_GPENCIL_LEGACY | OB_MODE_VERTEX_GPENCIL_LEGACY | OB_MODE_SCULPT_CURVES | \
|
||||
OB_MODE_PAINT_GREASE_PENCIL)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ const EnumPropertyItem rna_enum_context_mode_items[] = {
|
||||
{CTX_MODE_WEIGHT_GPENCIL_LEGACY, "WEIGHT_GPENCIL", 0, "Grease Pencil Weight Paint", ""},
|
||||
{CTX_MODE_VERTEX_GPENCIL_LEGACY, "VERTEX_GPENCIL", 0, "Grease Pencil Vertex Paint", ""},
|
||||
{CTX_MODE_SCULPT_CURVES, "SCULPT_CURVES", 0, "Curves Sculpt", ""},
|
||||
{CTX_MODE_PAINT_GREASE_PENCIL, "PAINT_GREASE_PENCIL", 0, "Grease Pencil Paint", ""},
|
||||
{0, nullptr, 0, nullptr, nullptr},
|
||||
};
|
||||
|
||||
|
||||
@@ -86,6 +86,11 @@ const EnumPropertyItem rna_enum_object_mode_items[] = {
|
||||
"Vertex Paint",
|
||||
"Grease Pencil Vertex Paint Strokes"},
|
||||
{OB_MODE_SCULPT_CURVES, "SCULPT_CURVES", ICON_SCULPTMODE_HLT, "Sculpt Mode", ""},
|
||||
{OB_MODE_PAINT_GREASE_PENCIL,
|
||||
"PAINT_GREASE_PENCIL",
|
||||
ICON_GREASEPENCIL,
|
||||
"Draw Mode",
|
||||
"Paint Grease Pencil Strokes"},
|
||||
{0, nullptr, 0, nullptr, nullptr},
|
||||
};
|
||||
|
||||
|
||||
@@ -345,7 +345,12 @@ static bool rna_Brush_mode_with_tool_poll(PointerRNA *ptr, PointerRNA value)
|
||||
if (slot_index != brush->gpencil_tool) {
|
||||
return false;
|
||||
}
|
||||
mode = OB_MODE_PAINT_GPENCIL_LEGACY;
|
||||
if (U.experimental.use_grease_pencil_version3) {
|
||||
mode = OB_MODE_PAINT_GREASE_PENCIL;
|
||||
}
|
||||
else {
|
||||
mode = OB_MODE_PAINT_GPENCIL_LEGACY;
|
||||
}
|
||||
}
|
||||
else if (paint_contains_brush_slot(&ts->gp_vertexpaint->paint, tslot, &slot_index)) {
|
||||
if (slot_index != brush->gpencil_vertex_tool) {
|
||||
|
||||
@@ -151,6 +151,9 @@ wmKeyMap *WM_keymap_guess_from_context(const bContext *C)
|
||||
case CTX_MODE_SCULPT_CURVES:
|
||||
km_id = "Sculpt Curves";
|
||||
break;
|
||||
case CTX_MODE_PAINT_GREASE_PENCIL:
|
||||
km_id = "Grease Pencil Paint Mode";
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (sl->spacetype == SPACE_IMAGE) {
|
||||
|
||||
Reference in New Issue
Block a user