forked from bartvdbraak/blender
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.
This commit is contained in:
parent
c733062d27
commit
fbed69866e
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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 ((p->sa->spacetype == SPACE_VIEW3D) &&
|
||||
(p->flags & GP_PAINTFLAG_V3D_ERASER_DEPTH))
|
||||
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 ((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 */
|
||||
|
@ -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 */
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user