diff options
Diffstat (limited to 'source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c')
-rw-r--r-- | source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c index a13f8d64755..512e3af063a 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c @@ -43,6 +43,8 @@ #include "BKE_screen.h" #include "DEG_depsgraph.h" +#include "DEG_depsgraph_build.h" +#include "DEG_depsgraph_query.h" #include "UI_interface.h" #include "UI_resources.h" @@ -128,6 +130,30 @@ static void deformStroke(GpencilModifierData *md, } float curvef = 1.0f; + + float factor_depth = 1.0f; + + if (mmd->flag & GP_THICK_FADING) { + if (mmd->object) { + float gvert[3]; + mul_v3_m4v3(gvert, ob->obmat, &pt->x); + float dist = len_v3v3(mmd->object->obmat[3], gvert); + float fading_max = MAX2(mmd->fading_start, mmd->fading_end); + float fading_min = MIN2(mmd->fading_start, mmd->fading_end); + + /* Better with ratiof() function from line art. */ + if (dist > fading_max) { + factor_depth = 0.0f; + } + else if (dist <= fading_max && dist > fading_min) { + factor_depth = (fading_max - dist) / (fading_max - fading_min); + } + else { + factor_depth = 1.0f; + } + } + } + if ((mmd->flag & GP_THICK_CUSTOM_CURVE) && (mmd->curve_thickness)) { /* Normalize value to evaluate curve. */ float value = (float)i / (gps->totpoints - 1); @@ -144,6 +170,9 @@ static void deformStroke(GpencilModifierData *md, weight *= curvef; } + float fac_begin = mmd->flag & GP_THICK_NORMALIZE ? 1 : mmd->thickness_fac; + target *= interpf(fac_begin, mmd->fading_end_factor, factor_depth); + pt->pressure = interpf(target, pt->pressure, weight); CLAMP_MIN(pt->pressure, 0.0f); @@ -171,6 +200,32 @@ static void foreachIDLink(GpencilModifierData *md, Object *ob, IDWalkFunc walk, ThickGpencilModifierData *mmd = (ThickGpencilModifierData *)md; walk(userData, ob, (ID **)&mmd->material, IDWALK_CB_USER); + walk(userData, ob, (ID **)&mmd->object, IDWALK_CB_NOP); +} + +static void updateDepsgraph(GpencilModifierData *md, + const ModifierUpdateDepsgraphContext *ctx, + const int UNUSED(mode)) +{ + ThickGpencilModifierData *mmd = (ThickGpencilModifierData *)md; + if (mmd->object != NULL) { + DEG_add_object_relation(ctx->node, mmd->object, DEG_OB_COMP_TRANSFORM, "Thickness Modifier"); + } + DEG_add_object_relation(ctx->node, ctx->object, DEG_OB_COMP_TRANSFORM, "Thickness Modifier"); +} + +static void fading_header_draw(const bContext *UNUSED(C), Panel *panel) +{ + uiLayout *layout = panel->layout; + + PointerRNA *ptr = gpencil_modifier_panel_get_property_pointers(panel, NULL); + + uiItemR(layout, ptr, "use_fading", 0, NULL, ICON_NONE); +} + +static void fading_panel_draw(const bContext *C, Panel *panel) +{ + gpencil_modifier_fading_draw(C, panel); } static void panel_draw(const bContext *UNUSED(C), Panel *panel) @@ -202,6 +257,8 @@ static void panelRegister(ARegionType *region_type) { PanelType *panel_type = gpencil_modifier_panel_register( region_type, eGpencilModifierType_Thick, panel_draw); + gpencil_modifier_subpanel_register( + region_type, "fading", "", fading_header_draw, fading_panel_draw, panel_type); PanelType *mask_panel_type = gpencil_modifier_subpanel_register( region_type, "mask", "Influence", NULL, mask_panel_draw, panel_type); gpencil_modifier_subpanel_register(region_type, @@ -229,7 +286,7 @@ GpencilModifierTypeInfo modifierType_Gpencil_Thick = { /* initData */ initData, /* freeData */ freeData, /* isDisabled */ NULL, - /* updateDepsgraph */ NULL, + /* updateDepsgraph */ updateDepsgraph, /* dependsOnTime */ NULL, /* foreachIDLink */ foreachIDLink, /* foreachTexLink */ NULL, |