Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Vazquez <blendergit@gmail.com>2020-03-09 18:27:24 +0300
committerAntonio Vazquez <blendergit@gmail.com>2020-03-09 18:27:24 +0300
commit29f3af95272590d26f610ae828b2eeee89c82a00 (patch)
treea696a58a2561c48f7ec6166e369e22081e0a64d8 /source/blender/editors/gpencil/gpencil_ops.c
parentdcb93126876879d969a30a7865700abd072066f8 (diff)
GPencil: Refactor of Draw Engine, Vertex Paint and all internal functions
This commit is a full refactor of the grease pencil modules including Draw Engine, Modifiers, VFX, depsgraph update, improvements in operators and conversion of Sculpt and Weight paint tools to real brushes. Also, a huge code cleanup has been done at all levels. Thanks to @fclem for his work and yo @pepeland and @mendio for the testing and help in the development. Differential Revision: https://developer.blender.org/D6293
Diffstat (limited to 'source/blender/editors/gpencil/gpencil_ops.c')
-rw-r--r--source/blender/editors/gpencil/gpencil_ops.c316
1 files changed, 312 insertions, 4 deletions
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index 7a541cd8f03..275075c38db 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -95,6 +95,60 @@ static bool gp_stroke_paintmode_poll_with_tool(bContext *C, const char gpencil_t
WM_toolsystem_active_tool_is_brush(C) && (brush->gpencil_tool == gpencil_tool));
}
+static bool gp_stroke_vertexmode_poll_with_tool(bContext *C, const char gpencil_vertex_tool)
+{
+ bGPdata *gpd = CTX_data_gpencil_data(C);
+ if (!gpd) {
+ return false;
+ }
+
+ ToolSettings *ts = CTX_data_tool_settings(C);
+ if (!ts || !ts->gp_vertexpaint) {
+ return false;
+ }
+
+ Brush *brush = BKE_paint_brush(&ts->gp_vertexpaint->paint);
+ return ((gpd->flag & GP_DATA_STROKE_VERTEXMODE) && (brush && brush->gpencil_settings) &&
+ WM_toolsystem_active_tool_is_brush(C) &&
+ (brush->gpencil_vertex_tool == gpencil_vertex_tool));
+}
+
+static bool gp_stroke_sculptmode_poll_with_tool(bContext *C, const char gpencil_sculpt_tool)
+{
+ bGPdata *gpd = CTX_data_gpencil_data(C);
+ if (!gpd) {
+ return false;
+ }
+
+ ToolSettings *ts = CTX_data_tool_settings(C);
+ if (!ts || !ts->gp_sculptpaint) {
+ return false;
+ }
+
+ Brush *brush = BKE_paint_brush(&ts->gp_sculptpaint->paint);
+ return ((gpd->flag & GP_DATA_STROKE_SCULPTMODE) && (brush && brush->gpencil_settings) &&
+ WM_toolsystem_active_tool_is_brush(C) &&
+ (brush->gpencil_sculpt_tool == gpencil_sculpt_tool));
+}
+
+static bool gp_stroke_weightmode_poll_with_tool(bContext *C, const char gpencil_weight_tool)
+{
+ bGPdata *gpd = CTX_data_gpencil_data(C);
+ if (!gpd) {
+ 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 ((gpd->flag & GP_DATA_STROKE_WEIGHTMODE) && (brush && brush->gpencil_settings) &&
+ WM_toolsystem_active_tool_is_brush(C) &&
+ (brush->gpencil_weight_tool == gpencil_weight_tool));
+}
+
/* Poll callback for stroke painting (draw brush) */
static bool gp_stroke_paintmode_draw_poll(bContext *C)
{
@@ -113,6 +167,12 @@ static bool gp_stroke_paintmode_fill_poll(bContext *C)
return gp_stroke_paintmode_poll_with_tool(C, GPAINT_TOOL_FILL);
}
+/* Poll callback for stroke painting (tint) */
+static bool gp_stroke_paintmode_tint_poll(bContext *C)
+{
+ return gp_stroke_paintmode_poll_with_tool(C, GPAINT_TOOL_TINT);
+}
+
/* Poll callback for stroke sculpting mode */
static bool gp_stroke_sculptmode_poll(bContext *C)
{
@@ -125,9 +185,8 @@ static bool gp_stroke_sculptmode_poll(bContext *C)
return ((gpd) && (gpd->flag & GP_DATA_STROKE_EDITMODE));
}
else {
- /* weight paint is a submode of sculpt */
if ((ob) && (ob->type == OB_GPENCIL)) {
- return GPENCIL_SCULPT_OR_WEIGHT_MODE(gpd);
+ return GPENCIL_SCULPT_MODE(gpd);
}
}
@@ -141,12 +200,113 @@ static bool gp_stroke_weightmode_poll(bContext *C)
Object *ob = CTX_data_active_object(C);
if ((ob) && (ob->type == OB_GPENCIL)) {
- return (gpd && (gpd->flag & GP_DATA_STROKE_WEIGHTMODE));
+ return GPENCIL_WEIGHT_MODE(gpd);
}
return 0;
}
+/* Poll callback for stroke vertex paint mode */
+static bool gp_stroke_vertexmode_poll(bContext *C)
+{
+ bGPdata *gpd = CTX_data_gpencil_data(C);
+ Object *ob = CTX_data_active_object(C);
+
+ if ((ob) && (ob->type == OB_GPENCIL)) {
+ return (gpd && (gpd->flag & GP_DATA_STROKE_VERTEXMODE));
+ }
+
+ return 0;
+}
+
+/* Poll callback for vertex painting (draw) */
+static bool gp_stroke_vertexmode_draw_poll(bContext *C)
+{
+ return gp_stroke_vertexmode_poll_with_tool(C, GPVERTEX_TOOL_DRAW);
+}
+
+/* Poll callback for vertex painting (blur) */
+static bool gp_stroke_vertexmode_blur_poll(bContext *C)
+{
+ return gp_stroke_vertexmode_poll_with_tool(C, GPVERTEX_TOOL_BLUR);
+}
+
+/* Poll callback for vertex painting (average) */
+static bool gp_stroke_vertexmode_average_poll(bContext *C)
+{
+ return gp_stroke_vertexmode_poll_with_tool(C, GPVERTEX_TOOL_AVERAGE);
+}
+
+/* Poll callback for vertex painting (smear) */
+static bool gp_stroke_vertexmode_smear_poll(bContext *C)
+{
+ return gp_stroke_vertexmode_poll_with_tool(C, GPVERTEX_TOOL_SMEAR);
+}
+
+/* Poll callback for vertex painting (replace) */
+static bool gp_stroke_vertexmode_replace_poll(bContext *C)
+{
+ return gp_stroke_vertexmode_poll_with_tool(C, GPVERTEX_TOOL_REPLACE);
+}
+
+/* Poll callback for sculpt (Smooth) */
+static bool gp_stroke_sculptmode_smooth_poll(bContext *C)
+{
+ return gp_stroke_sculptmode_poll_with_tool(C, GPSCULPT_TOOL_SMOOTH);
+}
+/* Poll callback for sculpt (Thickness) */
+static bool gp_stroke_sculptmode_thickness_poll(bContext *C)
+{
+ return gp_stroke_sculptmode_poll_with_tool(C, GPSCULPT_TOOL_THICKNESS);
+}
+
+/* Poll callback for sculpt (Strength) */
+static bool gp_stroke_sculptmode_strength_poll(bContext *C)
+{
+ return gp_stroke_sculptmode_poll_with_tool(C, GPSCULPT_TOOL_STRENGTH);
+}
+
+/* Poll callback for sculpt (Grab) */
+static bool gp_stroke_sculptmode_grab_poll(bContext *C)
+{
+ return gp_stroke_sculptmode_poll_with_tool(C, GPSCULPT_TOOL_GRAB);
+}
+
+/* Poll callback for sculpt (Push) */
+static bool gp_stroke_sculptmode_push_poll(bContext *C)
+{
+ return gp_stroke_sculptmode_poll_with_tool(C, GPSCULPT_TOOL_PUSH);
+}
+
+/* Poll callback for sculpt (Twist) */
+static bool gp_stroke_sculptmode_twist_poll(bContext *C)
+{
+ return gp_stroke_sculptmode_poll_with_tool(C, GPSCULPT_TOOL_TWIST);
+}
+
+/* Poll callback for sculpt (Pinch) */
+static bool gp_stroke_sculptmode_pinch_poll(bContext *C)
+{
+ return gp_stroke_sculptmode_poll_with_tool(C, GPSCULPT_TOOL_PINCH);
+}
+/* Poll callback for sculpt (Randomize) */
+static bool gp_stroke_sculptmode_randomize_poll(bContext *C)
+{
+ return gp_stroke_sculptmode_poll_with_tool(C, GPSCULPT_TOOL_RANDOMIZE);
+}
+
+/* Poll callback for sculpt (Clone) */
+static bool gp_stroke_sculptmode_clone_poll(bContext *C)
+{
+ return gp_stroke_sculptmode_poll_with_tool(C, GPSCULPT_TOOL_CLONE);
+}
+
+/* Poll callback for weight paint (Draw) */
+static bool gp_stroke_weightmode_draw_poll(bContext *C)
+{
+ return gp_stroke_weightmode_poll_with_tool(C, GPWEIGHT_TOOL_DRAW);
+}
+
/* Stroke Editing Keymap - Only when editmode is enabled */
static void ed_keymap_gpencil_editing(wmKeyConfig *keyconf)
{
@@ -177,6 +337,13 @@ static void ed_keymap_gpencil_painting_fill(wmKeyConfig *keyconf)
keymap->poll = gp_stroke_paintmode_fill_poll;
}
+/* keys for draw with a tint brush */
+static void ed_keymap_gpencil_painting_tint(wmKeyConfig *keyconf)
+{
+ wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Stroke Paint (Tint)", 0, 0);
+ keymap->poll = gp_stroke_paintmode_tint_poll;
+}
+
/* Stroke Painting Keymap - Only when paintmode is enabled */
static void ed_keymap_gpencil_painting(wmKeyConfig *keyconf)
{
@@ -200,6 +367,106 @@ static void ed_keymap_gpencil_weightpainting(wmKeyConfig *keyconf)
wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Stroke Weight Mode", 0, 0);
keymap->poll = gp_stroke_weightmode_poll;
}
+
+static void ed_keymap_gpencil_vertexpainting(wmKeyConfig *keyconf)
+{
+ /* set poll callback - so that this keymap only gets enabled when stroke vertex is enabled */
+ wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Stroke Vertex Mode", 0, 0);
+ keymap->poll = gp_stroke_vertexmode_poll;
+}
+
+/* keys for vertex with a draw brush */
+static void ed_keymap_gpencil_vertexpainting_draw(wmKeyConfig *keyconf)
+{
+ wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Stroke Vertex (Draw)", 0, 0);
+ keymap->poll = gp_stroke_vertexmode_draw_poll;
+}
+
+/* keys for vertex with a blur brush */
+static void ed_keymap_gpencil_vertexpainting_blur(wmKeyConfig *keyconf)
+{
+ wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Stroke Vertex (Blur)", 0, 0);
+ keymap->poll = gp_stroke_vertexmode_blur_poll;
+}
+/* keys for vertex with a average brush */
+static void ed_keymap_gpencil_vertexpainting_average(wmKeyConfig *keyconf)
+{
+ wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Stroke Vertex (Average)", 0, 0);
+ keymap->poll = gp_stroke_vertexmode_average_poll;
+}
+/* keys for vertex with a smear brush */
+static void ed_keymap_gpencil_vertexpainting_smear(wmKeyConfig *keyconf)
+{
+ wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Stroke Vertex (Smear)", 0, 0);
+ keymap->poll = gp_stroke_vertexmode_smear_poll;
+}
+/* keys for vertex with a replace brush */
+static void ed_keymap_gpencil_vertexpainting_replace(wmKeyConfig *keyconf)
+{
+ wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Stroke Vertex (Replace)", 0, 0);
+ keymap->poll = gp_stroke_vertexmode_replace_poll;
+}
+/* keys for sculpt with a smooth brush */
+static void ed_keymap_gpencil_sculptpainting_smooth(wmKeyConfig *keyconf)
+{
+ wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Stroke Sculpt (Smooth)", 0, 0);
+ keymap->poll = gp_stroke_sculptmode_smooth_poll;
+}
+/* keys for sculpt with a thickness brush */
+static void ed_keymap_gpencil_sculptpainting_thickness(wmKeyConfig *keyconf)
+{
+ wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Stroke Sculpt (Thickness)", 0, 0);
+ keymap->poll = gp_stroke_sculptmode_thickness_poll;
+}
+/* keys for sculpt with a strength brush */
+static void ed_keymap_gpencil_sculptpainting_strength(wmKeyConfig *keyconf)
+{
+ wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Stroke Sculpt (Strength)", 0, 0);
+ keymap->poll = gp_stroke_sculptmode_strength_poll;
+}
+/* keys for sculpt with a grab brush */
+static void ed_keymap_gpencil_sculptpainting_grab(wmKeyConfig *keyconf)
+{
+ wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Stroke Sculpt (Grab)", 0, 0);
+ keymap->poll = gp_stroke_sculptmode_grab_poll;
+}
+/* keys for sculpt with a push brush */
+static void ed_keymap_gpencil_sculptpainting_push(wmKeyConfig *keyconf)
+{
+ wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Stroke Sculpt (Push)", 0, 0);
+ keymap->poll = gp_stroke_sculptmode_push_poll;
+}
+/* keys for sculpt with a twist brush */
+static void ed_keymap_gpencil_sculptpainting_twist(wmKeyConfig *keyconf)
+{
+ wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Stroke Sculpt (Twist)", 0, 0);
+ keymap->poll = gp_stroke_sculptmode_twist_poll;
+}
+/* keys for sculpt with a pinch brush */
+static void ed_keymap_gpencil_sculptpainting_pinch(wmKeyConfig *keyconf)
+{
+ wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Stroke Sculpt (Pinch)", 0, 0);
+ keymap->poll = gp_stroke_sculptmode_pinch_poll;
+}
+/* keys for sculpt with a randomize brush */
+static void ed_keymap_gpencil_sculptpainting_randomize(wmKeyConfig *keyconf)
+{
+ wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Stroke Sculpt (Randomize)", 0, 0);
+ keymap->poll = gp_stroke_sculptmode_randomize_poll;
+}
+/* keys for sculpt with a clone brush */
+static void ed_keymap_gpencil_sculptpainting_clone(wmKeyConfig *keyconf)
+{
+ wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Stroke Sculpt (Clone)", 0, 0);
+ keymap->poll = gp_stroke_sculptmode_clone_poll;
+}
+/* keys for weight with a draw brush */
+static void ed_keymap_gpencil_weightpainting_draw(wmKeyConfig *keyconf)
+{
+ wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Stroke Weight (Draw)", 0, 0);
+ keymap->poll = gp_stroke_weightmode_draw_poll;
+}
+
/* ==================== */
void ED_keymap_gpencil(wmKeyConfig *keyconf)
@@ -210,8 +477,25 @@ void ED_keymap_gpencil(wmKeyConfig *keyconf)
ed_keymap_gpencil_painting_draw(keyconf);
ed_keymap_gpencil_painting_erase(keyconf);
ed_keymap_gpencil_painting_fill(keyconf);
+ ed_keymap_gpencil_painting_tint(keyconf);
ed_keymap_gpencil_sculpting(keyconf);
+ ed_keymap_gpencil_sculptpainting_smooth(keyconf);
+ ed_keymap_gpencil_sculptpainting_thickness(keyconf);
+ ed_keymap_gpencil_sculptpainting_strength(keyconf);
+ ed_keymap_gpencil_sculptpainting_grab(keyconf);
+ ed_keymap_gpencil_sculptpainting_push(keyconf);
+ ed_keymap_gpencil_sculptpainting_twist(keyconf);
+ ed_keymap_gpencil_sculptpainting_pinch(keyconf);
+ ed_keymap_gpencil_sculptpainting_randomize(keyconf);
+ ed_keymap_gpencil_sculptpainting_clone(keyconf);
ed_keymap_gpencil_weightpainting(keyconf);
+ ed_keymap_gpencil_weightpainting_draw(keyconf);
+ ed_keymap_gpencil_vertexpainting(keyconf);
+ ed_keymap_gpencil_vertexpainting_draw(keyconf);
+ ed_keymap_gpencil_vertexpainting_blur(keyconf);
+ ed_keymap_gpencil_vertexpainting_average(keyconf);
+ ed_keymap_gpencil_vertexpainting_smear(keyconf);
+ ed_keymap_gpencil_vertexpainting_replace(keyconf);
}
/* ****************************************** */
@@ -226,6 +510,12 @@ void ED_operatortypes_gpencil(void)
WM_operatortype_append(GPENCIL_OT_draw);
WM_operatortype_append(GPENCIL_OT_fill);
+ WM_operatortype_append(GPENCIL_OT_vertex_paint);
+ WM_operatortype_append(GPENCIL_OT_vertex_color_brightness_contrast);
+ WM_operatortype_append(GPENCIL_OT_vertex_color_hsv);
+ WM_operatortype_append(GPENCIL_OT_vertex_color_invert);
+ WM_operatortype_append(GPENCIL_OT_vertex_color_levels);
+ WM_operatortype_append(GPENCIL_OT_vertex_color_set);
/* Guides ----------------------- */
@@ -238,6 +528,7 @@ void ED_operatortypes_gpencil(void)
WM_operatortype_append(GPENCIL_OT_paintmode_toggle);
WM_operatortype_append(GPENCIL_OT_sculptmode_toggle);
WM_operatortype_append(GPENCIL_OT_weightmode_toggle);
+ WM_operatortype_append(GPENCIL_OT_vertexmode_toggle);
WM_operatortype_append(GPENCIL_OT_selection_opacity_toggle);
WM_operatortype_append(GPENCIL_OT_select);
@@ -253,6 +544,7 @@ void ED_operatortypes_gpencil(void)
WM_operatortype_append(GPENCIL_OT_select_first);
WM_operatortype_append(GPENCIL_OT_select_last);
WM_operatortype_append(GPENCIL_OT_select_alternate);
+ WM_operatortype_append(GPENCIL_OT_select_color);
WM_operatortype_append(GPENCIL_OT_duplicate);
WM_operatortype_append(GPENCIL_OT_delete);
@@ -263,6 +555,7 @@ void ED_operatortypes_gpencil(void)
WM_operatortype_append(GPENCIL_OT_move_to_layer);
WM_operatortype_append(GPENCIL_OT_layer_change);
+ WM_operatortype_append(GPENCIL_OT_layer_active);
WM_operatortype_append(GPENCIL_OT_set_active_material);
@@ -271,8 +564,10 @@ void ED_operatortypes_gpencil(void)
WM_operatortype_append(GPENCIL_OT_snap_cursor_to_selected);
WM_operatortype_append(GPENCIL_OT_reproject);
+ WM_operatortype_append(GPENCIL_OT_recalc_geometry);
WM_operatortype_append(GPENCIL_OT_sculpt_paint);
+ WM_operatortype_append(GPENCIL_OT_weight_paint);
/* Editing (Buttons) ------------ */
@@ -288,6 +583,9 @@ void ED_operatortypes_gpencil(void)
WM_operatortype_append(GPENCIL_OT_layer_duplicate);
WM_operatortype_append(GPENCIL_OT_layer_duplicate_object);
+ WM_operatortype_append(GPENCIL_OT_layer_mask_add);
+ WM_operatortype_append(GPENCIL_OT_layer_mask_remove);
+
WM_operatortype_append(GPENCIL_OT_hide);
WM_operatortype_append(GPENCIL_OT_reveal);
WM_operatortype_append(GPENCIL_OT_lock_all);
@@ -306,6 +604,8 @@ void ED_operatortypes_gpencil(void)
WM_operatortype_append(GPENCIL_OT_convert);
+ WM_operatortype_append(GPENCIL_OT_image_to_grease_pencil);
+
WM_operatortype_append(GPENCIL_OT_stroke_arrange);
WM_operatortype_append(GPENCIL_OT_stroke_change_color);
WM_operatortype_append(GPENCIL_OT_stroke_lock_color);
@@ -325,8 +625,16 @@ void ED_operatortypes_gpencil(void)
WM_operatortype_append(GPENCIL_OT_stroke_cutter);
WM_operatortype_append(GPENCIL_OT_stroke_trim);
WM_operatortype_append(GPENCIL_OT_stroke_merge_by_distance);
+ WM_operatortype_append(GPENCIL_OT_stroke_merge_material);
+
+ WM_operatortype_append(GPENCIL_OT_material_to_vertex_color);
+ WM_operatortype_append(GPENCIL_OT_extract_palette_vertex);
+
+ WM_operatortype_append(GPENCIL_OT_transform_fill);
+ WM_operatortype_append(GPENCIL_OT_reset_transform_fill);
- WM_operatortype_append(GPENCIL_OT_brush_presets_create);
+ WM_operatortype_append(GPENCIL_OT_brush_reset);
+ WM_operatortype_append(GPENCIL_OT_brush_reset_all);
/* vertex groups */
WM_operatortype_append(GPENCIL_OT_vertex_group_assign);