Commit: fbed69866ea574dcf3a304ca2ca5b223f997b13f
Author: Antonioya
Date:   Sun Dec 16 18:24:52 2018 +0100
Branches: blender2.8
https://developer.blender.org/rBfbed69866ea574dcf3a304ca2ca5b223f997b13f

GP: Add option to occlude eraser

This adds the functionality requested in T59417 adding a new button near of 
pressure button of the brush to enable/disable occlude effect for eraser.

===================================================================

M       release/scripts/startup/bl_ui/space_topbar.py
M       release/scripts/startup/bl_ui/space_view3d_toolbar.py
M       source/blender/editors/gpencil/gpencil_paint.c
M       source/blender/makesdna/DNA_brush_types.h
M       source/blender/makesrna/intern/rna_brush.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_topbar.py 
b/release/scripts/startup/bl_ui/space_topbar.py
index a94ebea4561..0f8aaa89667 100644
--- a/release/scripts/startup/bl_ui/space_topbar.py
+++ b/release/scripts/startup/bl_ui/space_topbar.py
@@ -347,6 +347,7 @@ class _draw_left_context_mode:
                 row = layout.row(align=True)
                 row.prop(brush, "size", text="Radius")
                 row.prop(gp_settings, "use_pressure", text="", 
icon='STYLUS_PRESSURE')
+                row.prop(gp_settings, "use_occlude_eraser", text="", 
icon='XRAY')
                 if gp_settings.eraser_mode == 'SOFT':
                     row = layout.row(align=True)
                     row.prop(gp_settings, "pen_strength", slider=True)
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py 
b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index eeb00fe09f8..b80085503e9 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -1501,6 +1501,7 @@ class VIEW3D_PT_tools_grease_pencil_brush(View3DPanel, 
Panel):
                 row = layout.row(align=True)
                 row.prop(brush, "size", text="Radius")
                 row.prop(gp_settings, "use_pressure", text="", 
icon='STYLUS_PRESSURE')
+                row.prop(gp_settings, "use_occlude_eraser", text="", 
icon='XRAY')
 
                 if gp_settings.eraser_mode == 'SOFT':
                     row = layout.row(align=True)
diff --git a/source/blender/editors/gpencil/gpencil_paint.c 
b/source/blender/editors/gpencil/gpencil_paint.c
index c163ce40a6c..35e7ca1132f 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -116,7 +116,6 @@ typedef enum eGP_StrokeAdd_Result {
 typedef enum eGPencil_PaintFlags {
        GP_PAINTFLAG_FIRSTRUN       = (1 << 0),    /* operator just started */
        GP_PAINTFLAG_STROKEADDED    = (1 << 1),
-       GP_PAINTFLAG_V3D_ERASER_DEPTH = (1 << 2),
        GP_PAINTFLAG_SELECTMASK     = (1 << 3),
        GP_PAINTFLAG_HARD_ERASER    = (1 << 4),
        GP_PAINTFLAG_STROKE_ERASER  = (1 << 5),
@@ -1200,9 +1199,19 @@ static float view3d_point_depth(const RegionView3D 
*rv3d, const float co[3])
 static bool gp_stroke_eraser_is_occluded(tGPsdata *p, const bGPDspoint *pt, 
const int x, const int y)
 {
        Object *obact = (Object *)p->ownerPtr.data;
+       Brush *brush = p->brush;
+       Brush *eraser = p->eraser;
+       BrushGpencilSettings *gp_settings = NULL;
+
+       if (brush->gpencil_tool == GPAINT_TOOL_ERASE) {
+               gp_settings = brush->gpencil_settings;
+       }
+       else if ((eraser != NULL) & (eraser->gpencil_tool == 
GPAINT_TOOL_ERASE)) {
+               gp_settings = eraser->gpencil_settings;
+       }
 
-       if ((p->sa->spacetype == SPACE_VIEW3D) &&
-           (p->flags & GP_PAINTFLAG_V3D_ERASER_DEPTH))
+       if ((gp_settings != NULL) && (p->sa->spacetype == SPACE_VIEW3D) &&
+           (gp_settings->flag & GP_BRUSH_OCCLUDE_ERASER))
        {
                RegionView3D *rv3d = p->ar->regiondata;
                bGPDlayer *gpl = p->gpl;
@@ -1550,13 +1559,16 @@ static void gp_stroke_doeraser(tGPsdata *p)
        Brush *eraser = p->eraser;
        bool use_pressure = false;
        float press = 1.0f;
+       BrushGpencilSettings *gp_settings = NULL;
 
        /* detect if use pressure in eraser */
        if (brush->gpencil_tool == GPAINT_TOOL_ERASE) {
                use_pressure = (bool)(brush->gpencil_settings->flag & 
GP_BRUSH_USE_PRESSURE);
+               gp_settings = brush->gpencil_settings;
        }
        else if ((eraser != NULL) & (eraser->gpencil_tool == 
GPAINT_TOOL_ERASE)) {
                use_pressure = (bool)(eraser->gpencil_settings->flag & 
GP_BRUSH_USE_PRESSURE);
+               gp_settings = eraser->gpencil_settings;
        }
        if (use_pressure) {
                press = p->pressure;
@@ -1570,7 +1582,7 @@ static void gp_stroke_doeraser(tGPsdata *p)
        rect.ymax = p->mval[1] + calc_radius;
 
        if (p->sa->spacetype == SPACE_VIEW3D) {
-               if (p->flags & GP_PAINTFLAG_V3D_ERASER_DEPTH) {
+               if ((gp_settings != NULL) && (gp_settings->flag & 
GP_BRUSH_OCCLUDE_ERASER)) {
                        View3D *v3d = p->sa->spacedata.first;
                        view3d_region_operator_needs_opengl(p->win, p->ar);
                        ED_view3d_autodist_init(p->depsgraph, p->ar, v3d, 0);
@@ -2063,23 +2075,10 @@ static void gp_paint_initstroke(tGPsdata *p, 
eGPencil_PaintModes paintmode, Deps
        p->paintmode = paintmode;
        if (p->paintmode == GP_PAINTMODE_ERASER) {
                p->gpd->runtime.sbuffer_sflag |= GP_STROKE_ERASER;
-
-               /* check if we should respect depth while erasing */
-               if (p->sa->spacetype == SPACE_VIEW3D) {
-                       if (p->gpl->flag & GP_LAYER_NO_XRAY) {
-                               p->flags |= GP_PAINTFLAG_V3D_ERASER_DEPTH;
-                       }
-               }
        }
        else {
                /* disable eraser flags - so that we can switch modes during a 
session */
                p->gpd->runtime.sbuffer_sflag &= ~GP_STROKE_ERASER;
-
-               if (p->sa->spacetype == SPACE_VIEW3D) {
-                       if (p->gpl->flag & GP_LAYER_NO_XRAY) {
-                               p->flags &= ~GP_PAINTFLAG_V3D_ERASER_DEPTH;
-                       }
-               }
        }
 
        /* set special fill stroke mode */
diff --git a/source/blender/makesdna/DNA_brush_types.h 
b/source/blender/makesdna/DNA_brush_types.h
index d51c94fb536..398c79e0111 100644
--- a/source/blender/makesdna/DNA_brush_types.h
+++ b/source/blender/makesdna/DNA_brush_types.h
@@ -123,6 +123,8 @@ typedef enum eGPDbrush_Flag {
        GP_BRUSH_MATERIAL_PINNED = (1 << 13),
        /* Do not show fill color while drawing (no lasso mode) */
        GP_BRUSH_DISSABLE_LASSO = (1 << 14),
+       /* Do not erase strokes oLcluded */
+       GP_BRUSH_OCCLUDE_ERASER = (1 << 15),
 } eGPDbrush_Flag;
 
 /* BrushGpencilSettings->gp_fill_draw_mode */
diff --git a/source/blender/makesrna/intern/rna_brush.c 
b/source/blender/makesrna/intern/rna_brush.c
index 445ceb6ddb5..ccf6f73f284 100644
--- a/source/blender/makesrna/intern/rna_brush.c
+++ b/source/blender/makesrna/intern/rna_brush.c
@@ -1227,6 +1227,12 @@ static void rna_def_gpencil_options(BlenderRNA *brna)
        RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", 
GP_BRUSH_DISSABLE_LASSO);
        RNA_def_property_ui_text(prop, "Show Lasso", "Do not draw fill color 
while drawing the stroke");
        RNA_def_parameter_clear_flags(prop, PROP_ANIMATABLE, 0);
+
+       prop = RNA_def_property(srna, "use_occlude_eraser", PROP_BOOLEAN, 
PROP_NONE);
+       RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", 
GP_BRUSH_OCCLUDE_ERASER);
+       RNA_def_property_ui_text(prop, "Occlude Eraser",
+               "Erase only strokes visible and not occluded");
+       RNA_def_parameter_clear_flags(prop, PROP_ANIMATABLE, 0);
 }
 
 static void rna_def_brush(BlenderRNA *brna)

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to