GPencil: New Hardeness mode for Opacity modifier

Add  new option to change the stroke hardeness. This option works at stroke level, not at point level.

Also replaced the "Both" name mode by "Stroke and Fill".

Differential Revision: https://developer.blender.org/D7195
This commit is contained in:
Antonio Vazquez 2020-03-20 15:37:56 +01:00
parent a22cd6b6a9
commit d924e31b42
5 changed files with 43 additions and 12 deletions

View File

@ -1996,16 +1996,21 @@ class DATA_PT_gpencil_modifiers(ModifierButtonsPanel, Panel):
split = layout.split()
col = split.column()
col.prop(md, "normalize_opacity")
if md.normalize_opacity is True:
text="Strength"
else:
text="Opacity Factor"
col.prop(md, "factor", text=text)
col.prop(md, "modify_color")
self.gpencil_masking(layout, ob, md, True, True)
if md.modify_color == 'HARDENESS':
col.prop(md, "hardeness")
show = False
else:
col.prop(md, "normalize_opacity")
if md.normalize_opacity is True:
text="Strength"
else:
text="Opacity Factor"
col.prop(md, "factor", text=text)
show = True
self.gpencil_masking(layout, ob, md, show, show)
def GP_ARRAY(self, layout, ob, md):
col = layout.column()

View File

@ -51,6 +51,7 @@ static void initData(GpencilModifierData *md)
OpacityGpencilModifierData *gpmd = (OpacityGpencilModifierData *)md;
gpmd->pass_index = 0;
gpmd->factor = 1.0f;
gpmd->hardeness = 1.0f;
gpmd->layername[0] = '\0';
gpmd->materialname[0] = '\0';
gpmd->vgname[0] = '\0';
@ -104,6 +105,14 @@ static void deformStroke(GpencilModifierData *md,
return;
}
/* Hardeness (at stroke level). */
if (mmd->modify_color == GP_MODIFY_COLOR_HARDENESS) {
gps->hardeness *= mmd->hardeness;
CLAMP(gps->hardeness, 0.0f, 1.0f);
return;
}
for (int i = 0; i < gps->totpoints; i++) {
bGPDspoint *pt = &gps->points[i];
MDeformVert *dvert = gps->dvert != NULL ? &gps->dvert[i] : NULL;

View File

@ -215,6 +215,7 @@ typedef enum eModifyColorGpencil_Flag {
GP_MODIFY_COLOR_BOTH = 0,
GP_MODIFY_COLOR_STROKE = 1,
GP_MODIFY_COLOR_FILL = 2,
GP_MODIFY_COLOR_HARDENESS = 3,
} eModifyColorGpencil_Flag;
typedef enum eOpacityModesGpencil_Flag {
@ -272,7 +273,7 @@ typedef struct OpacityGpencilModifierData {
/** Custom index for passes. */
int layer_pass;
char _pad1[4];
float hardeness;
struct CurveMapping *curve_intensity;
} OpacityGpencilModifierData;

View File

@ -1169,7 +1169,7 @@ static void rna_def_gpencil_options(BlenderRNA *brna)
static EnumPropertyItem gppaint_mode_types_items[] = {
{GPPAINT_MODE_STROKE, "STROKE", 0, "Stroke", "Vertex Color affects to Stroke only"},
{GPPAINT_MODE_FILL, "FILL", 0, "Fill", "Vertex Color affects to Fill only"},
{GPPAINT_MODE_BOTH, "BOTH", 0, "Both", "Vertex Color affects to Stroke and Fill"},
{GPPAINT_MODE_BOTH, "BOTH", 0, "Stroke and Fill", "Vertex Color affects to Stroke and Fill"},
{0, NULL, 0, NULL, NULL},
};

View File

@ -134,12 +134,20 @@ const EnumPropertyItem rna_enum_object_greasepencil_modifier_type_items[] = {
#ifndef RNA_RUNTIME
static const EnumPropertyItem modifier_modify_color_items[] = {
{GP_MODIFY_COLOR_BOTH, "BOTH", 0, "Both", "Modify fill and stroke colors"},
{GP_MODIFY_COLOR_BOTH, "BOTH", 0, "Stroke and Fill", "Modify fill and stroke colors"},
{GP_MODIFY_COLOR_STROKE, "STROKE", 0, "Stroke", "Modify stroke color only"},
{GP_MODIFY_COLOR_FILL, "FILL", 0, "Fill", "Modify fill color only"},
{0, NULL, 0, NULL, NULL},
};
static const EnumPropertyItem modifier_modify_opacity_items[] = {
{GP_MODIFY_COLOR_BOTH, "BOTH", 0, "Stroke and Fill", "Modify fill and stroke colors"},
{GP_MODIFY_COLOR_STROKE, "STROKE", 0, "Stroke", "Modify stroke color only"},
{GP_MODIFY_COLOR_FILL, "FILL", 0, "Fill", "Modify fill color only"},
{GP_MODIFY_COLOR_HARDENESS, "HARDENESS", 0, "Hardeness", "Modify stroke hardeness"},
{0, NULL, 0, NULL, NULL},
};
static const EnumPropertyItem modifier_gphook_falloff_items[] = {
{eGPHook_Falloff_None, "NONE", 0, "No Falloff", ""},
{eGPHook_Falloff_Curve, "CURVE", 0, "Curve", ""},
@ -1324,7 +1332,7 @@ static void rna_def_modifier_gpencilopacity(BlenderRNA *brna)
RNA_def_struct_ui_icon(srna, ICON_MOD_OPACITY);
prop = RNA_def_property(srna, "modify_color", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, modifier_modify_color_items); /* share the enum */
RNA_def_property_enum_items(prop, modifier_modify_opacity_items);
RNA_def_property_ui_text(prop, "Mode", "Set what colors of the stroke are affected");
RNA_def_property_update(prop, 0, "rna_GpencilModifier_update");
@ -1352,6 +1360,14 @@ static void rna_def_modifier_gpencilopacity(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Opacity Factor", "Factor of Opacity");
RNA_def_property_update(prop, 0, "rna_GpencilModifier_update");
prop = RNA_def_property(srna, "hardeness", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "hardeness");
RNA_def_property_range(prop, 0.0, FLT_MAX);
RNA_def_property_ui_range(prop, 0.0, FLT_MAX, 0.1, 2);
RNA_def_property_float_default(prop, 1.0f);
RNA_def_property_ui_text(prop, "Hardeness", "Factor of stroke hardeness");
RNA_def_property_update(prop, 0, "rna_GpencilModifier_update");
prop = RNA_def_property(srna, "pass_index", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "pass_index");
RNA_def_property_range(prop, 0, 100);