From ae79bc490a761cf351f09514356994d6efd586db Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Wed, 31 Aug 2022 15:10:13 +0200 Subject: GPencil: Apply Brush Size to Outline thickness while drawing The new factor allows to apply the current brush size to the external stroke perimeter conversion done in draw mode. --- release/scripts/startup/bl_ui/space_view3d_toolbar.py | 6 ++++++ source/blender/editors/gpencil/gpencil_paint.c | 5 ++++- source/blender/makesdna/DNA_brush_types.h | 4 ++++ source/blender/makesrna/intern/rna_brush.c | 9 +++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py index aa0e834cfa7..d15be4a9d3f 100644 --- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py +++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py @@ -1742,12 +1742,18 @@ class VIEW3D_PT_tools_grease_pencil_brush_post_processing(View3DPanel, Panel): col1 = col.column(align=True) col1.prop(gp_settings, "use_trim") + col.separator() + row = col.row(heading="Outline", align=True) row.prop(gp_settings, "use_settings_outline", text="") row2 = row.row(align=True) row2.enabled = gp_settings.use_settings_outline row2.prop(gp_settings, "material_alt", text="") + row2 = col.row(align=True) + row2.enabled = gp_settings.use_settings_outline + row2.prop(gp_settings, "outline_thickness_factor") + class VIEW3D_PT_tools_grease_pencil_brush_random(View3DPanel, Panel): bl_context = ".greasepencil_paint" diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index b196fcae51c..cbc88b57c65 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -943,8 +943,9 @@ static bGPDstroke *gpencil_stroke_to_outline(tGPsdata *p, bGPDstroke *gps) /* Stroke. */ float diff_mat[4][4]; unit_m4(diff_mat); + const float outline_thickness = (float)brush->size * gpencil_settings->outline_fac * 0.5f; bGPDstroke *gps_perimeter = BKE_gpencil_stroke_perimeter_from_view( - rv3d, p->gpd, gpl, gps_duplicate, 3, diff_mat, 0.0f); + rv3d, p->gpd, gpl, gps_duplicate, 3, diff_mat, outline_thickness); /* Assign material. */ if (gpencil_settings->material_alt == NULL) { gps_perimeter->mat_nr = gps->mat_nr; @@ -961,6 +962,8 @@ static bGPDstroke *gpencil_stroke_to_outline(tGPsdata *p, bGPDstroke *gps) } /* Set pressure constant. */ + gps_perimeter->thickness = max_ii((int)outline_thickness, 1); + bGPDspoint *pt; for (int i = 0; i < gps_perimeter->totpoints; i++) { pt = &gps_perimeter->points[i]; diff --git a/source/blender/makesdna/DNA_brush_types.h b/source/blender/makesdna/DNA_brush_types.h index 174ec614238..33f5d8eea12 100644 --- a/source/blender/makesdna/DNA_brush_types.h +++ b/source/blender/makesdna/DNA_brush_types.h @@ -132,6 +132,10 @@ typedef struct BrushGpencilSettings { struct CurveMapping *curve_rand_saturation; struct CurveMapping *curve_rand_value; + /** Factor for external line thickness conversion to outline. */ + float outline_fac; + char _pad1[4]; + /* optional link of material to replace default in context */ /** Material. */ struct Material *material; diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c index 989b0654104..2aa0a1bba01 100644 --- a/source/blender/makesrna/intern/rna_brush.c +++ b/source/blender/makesrna/intern/rna_brush.c @@ -1654,6 +1654,15 @@ static void rna_def_gpencil_options(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL); + /* Factor to determine outline external perimeter thickness. */ + prop = RNA_def_property(srna, "outline_thickness_factor", PROP_FLOAT, PROP_FACTOR); + RNA_def_property_float_sdna(prop, NULL, "outline_fac"); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_float_default(prop, 0.0f); + RNA_def_property_ui_text( + prop, "Thickness", "Thickness of the outline stroke relative to current brush thickness"); + RNA_def_parameter_clear_flags(prop, PROP_ANIMATABLE, 0); + /* Flags */ prop = RNA_def_property(srna, "use_pressure", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_BRUSH_USE_PRESSURE); -- cgit v1.2.3