diff options
5 files changed, 45 insertions, 30 deletions
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py index 3a1801f2a53..5b3d89c30a5 100644 --- a/release/scripts/startup/bl_ui/properties_data_modifier.py +++ b/release/scripts/startup/bl_ui/properties_data_modifier.py @@ -1802,6 +1802,9 @@ class DATA_PT_gpencil_modifiers(ModifierButtonsPanel, Panel): row = col.row(align=True) row.prop(md, "pass_index", text="Pass") row.prop(md, "invert_pass", text="", icon="ARROW_LEFTRIGHT") + + row = layout.row() + row.prop(md, "create_materials") def GP_INSTANCE(self, layout, ob, md): gpd = ob.data diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c b/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c index 151218c06e4..3914d960a79 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c @@ -165,7 +165,7 @@ void gpencil_apply_modifier_material( copy_v4_v4(newmat->gp_style->stroke_rgba, gps->runtime.tmp_stroke_rgba); copy_v4_v4(newmat->gp_style->fill_rgba, gps->runtime.tmp_fill_rgba); - BLI_ghash_insert(gh_color, mat->id.name, newmat); + BLI_ghash_insert(gh_color, newmat->id.name, newmat); DEG_id_tag_update(&newmat->id, DEG_TAG_COPY_ON_WRITE); } /* reasign color index */ diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c index 74b24acdfb6..541b37523b2 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c @@ -31,6 +31,8 @@ #include <stdio.h> #include "BLI_blenlib.h" +#include "BLI_ghash.h" +#include "BLI_math_vector.h" #include "BLI_utildefines.h" #include "DNA_meshdata_types.h" @@ -44,6 +46,7 @@ #include "BKE_material.h" #include "BKE_gpencil.h" #include "BKE_gpencil_modifier.h" +#include "BKE_main.h" #include "DEG_depsgraph.h" @@ -57,6 +60,7 @@ static void initData(GpencilModifierData *md) gpmd->factor = 1.0f; gpmd->layername[0] = '\0'; gpmd->vgname[0] = '\0'; + gpmd->flag |= GP_OPACITY_CREATE_COLORS; } static void copyData(const GpencilModifierData *md, GpencilModifierData *target) @@ -70,29 +74,28 @@ static void deformStroke( Object *ob, bGPDlayer *gpl, bGPDstroke *gps) { OpacityGpencilModifierData *mmd = (OpacityGpencilModifierData *)md; - MaterialGPencilStyle *gp_style = BKE_material_gpencil_settings_get(ob, gps->mat_nr + 1); int vindex = defgroup_name_index(ob, mmd->vgname); if (!is_stroke_affected_by_modifier( ob, - mmd->layername, mmd->pass_index, 3, gpl, gps, + mmd->layername, mmd->pass_index, 1, gpl, gps, mmd->flag & GP_OPACITY_INVERT_LAYER, mmd->flag & GP_OPACITY_INVERT_PASS)) { return; } - gp_style->fill_rgba[3] *= mmd->factor; + gps->runtime.tmp_fill_rgba[3] *= mmd->factor; /* if factor is > 1, then force opacity */ if (mmd->factor > 1.0f) { - gp_style->stroke_rgba[3] += mmd->factor - 1.0f; - if (gp_style->fill_rgba[3] > 1e-5) { - gp_style->fill_rgba[3] += mmd->factor - 1.0f; + gps->runtime.tmp_stroke_rgba[3] += mmd->factor - 1.0f; + if (gps->runtime.tmp_fill_rgba[3] > 1e-5) { + gps->runtime.tmp_fill_rgba[3] += mmd->factor - 1.0f; } } - CLAMP(gp_style->stroke_rgba[3], 0.0f, 1.0f); - CLAMP(gp_style->fill_rgba[3], 0.0f, 1.0f); + CLAMP(gps->runtime.tmp_stroke_rgba[3], 0.0f, 1.0f); + CLAMP(gps->runtime.tmp_fill_rgba[3], 0.0f, 1.0f); /* if opacity > 1.0, affect the strength of the stroke */ if (mmd->factor > 1.0f) { @@ -111,40 +114,43 @@ static void deformStroke( CLAMP(pt->strength, 0.0f, 1.0f); } } - else { - for (int i = 0; i < gps->totpoints; i++) { - bGPDspoint *pt = &gps->points[i]; - MDeformVert *dvert = &gps->dvert[i]; - - /* verify vertex group */ - if (mmd->vgname == NULL) { - pt->strength *= mmd->factor; - } - else { - float weight = get_modifier_point_weight(dvert, ((mmd->flag & GP_OPACITY_INVERT_VGROUP) != 0), vindex); - if (weight >= 0) { - pt->strength *= mmd->factor * weight; - } - } - CLAMP(pt->strength, 0.0f, 1.0f); - } - } - } static void bakeModifier( - struct Main *UNUSED(bmain), Depsgraph *depsgraph, - GpencilModifierData *md, Object *ob) + Main *bmain, Depsgraph *depsgraph, + GpencilModifierData *md, Object *ob) { + OpacityGpencilModifierData *mmd = (OpacityGpencilModifierData *)md; bGPdata *gpd = ob->data; + GHash *gh_color = BLI_ghash_str_new("GP_Opacity modifier"); for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) { for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { + + Material *mat = give_current_material(ob, gps->mat_nr + 1); + if (mat == NULL) + continue; + MaterialGPencilStyle *gp_style = mat->gp_style; + /* skip stroke if it doesn't have color info */ + if (ELEM(NULL, gp_style)) + continue; + + copy_v4_v4(gps->runtime.tmp_stroke_rgba, gp_style->stroke_rgba); + copy_v4_v4(gps->runtime.tmp_fill_rgba, gp_style->fill_rgba); + deformStroke(md, depsgraph, ob, gpl, gps); + + gpencil_apply_modifier_material(bmain, ob, mat, gh_color, gps, + (bool)(mmd->flag & GP_OPACITY_CREATE_COLORS)); } } } + /* free hash buffers */ + if (gh_color) { + BLI_ghash_free(gh_color, NULL, NULL); + gh_color = NULL; + } } GpencilModifierTypeInfo modifierType_Gpencil_Opacity = { diff --git a/source/blender/makesdna/DNA_gpencil_modifier_types.h b/source/blender/makesdna/DNA_gpencil_modifier_types.h index 1e3a4bf09f0..c1e2244427e 100644 --- a/source/blender/makesdna/DNA_gpencil_modifier_types.h +++ b/source/blender/makesdna/DNA_gpencil_modifier_types.h @@ -182,6 +182,7 @@ typedef enum eOpacityGpencil_Flag { GP_OPACITY_INVERT_LAYER = (1 << 0), GP_OPACITY_INVERT_PASS = (1 << 1), GP_OPACITY_INVERT_VGROUP = (1 << 2), + GP_OPACITY_CREATE_COLORS = (1 << 3), } eOpacityGpencil_Flag; typedef struct InstanceGpencilModifierData { diff --git a/source/blender/makesrna/intern/rna_gpencil_modifier.c b/source/blender/makesrna/intern/rna_gpencil_modifier.c index 1bfcf415a94..4f29ed58ba7 100644 --- a/source/blender/makesrna/intern/rna_gpencil_modifier.c +++ b/source/blender/makesrna/intern/rna_gpencil_modifier.c @@ -788,6 +788,11 @@ static void rna_def_modifier_gpencilopacity(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Factor", "Factor of Opacity"); RNA_def_property_update(prop, 0, "rna_GpencilModifier_update"); + prop = RNA_def_property(srna, "create_materials", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_OPACITY_CREATE_COLORS); + RNA_def_property_ui_text(prop, "Create Materials", "When apply modifier, create new material"); + 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); |