Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Vazquez <blendergit@gmail.com>2021-07-02 13:04:07 +0300
committerAntonio Vazquez <blendergit@gmail.com>2021-07-02 13:04:07 +0300
commit29b65f5345128ee035599aa7233315a74fe6afe6 (patch)
tree7ba21663688b5eca67c1884a8da5e0aa9a125c64 /source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c
parent9f5c0ffb5ec293af2e4f003c2178d21e20805b47 (diff)
GPencil: New modifier to generate weights dynamically
his new modifier allows to generate weights base on: * Angle of the stroke relative to object or world orientation. For example, if the value is 90, the maximum weights will be for vertical lines and minimum for horizontal lines. * Distance to Target object. The distance calculated is normalized to get valid weights between 0 and 1.0. The weights are created in an existing vertex group and the data can be replaced or mixed with the existing value to combine different weight effects. The minimum parameter, allows to define the minimum weight generated. This is useful to avoid very low weights. The generated weights can be used in any modifier. For example, the angle weight value can be used to mimic FreeStyle Caligraphy modifier using the weight with the thickness modifier. Also some modifier has been changed to inlude a new option to use the weights as factor of the effect. As result of this change, the fading option has been removed from Thickness and Opacity modifiers because this can be done using the new modifier, it's not logic to repeat the same. Reviewed By: mendio, filedescriptor Differential Revision: https://developer.blender.org/D11604
Diffstat (limited to 'source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c')
-rw-r--r--source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c84
1 files changed, 20 insertions, 64 deletions
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c
index 126949cd659..cac700e15f4 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c
@@ -43,8 +43,6 @@
#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"
@@ -118,42 +116,28 @@ static void deformStroke(GpencilModifierData *md,
}
float stroke_thickness_inv = 1.0f / max_ii(gps->thickness, 1);
+ const bool is_normalized = (mmd->flag & GP_THICK_NORMALIZE);
+ bool is_inverted = ((mmd->flag & GP_THICK_WEIGHT_FACTOR) == 0) &&
+ ((mmd->flag & GP_THICK_INVERT_VGROUP) != 0);
for (int i = 0; i < gps->totpoints; i++) {
bGPDspoint *pt = &gps->points[i];
MDeformVert *dvert = gps->dvert != NULL ? &gps->dvert[i] : NULL;
/* Verify point is part of vertex group. */
- float weight = get_modifier_point_weight(
- dvert, (mmd->flag & GP_THICK_INVERT_VGROUP) != 0, def_nr);
+ float weight = get_modifier_point_weight(dvert, is_inverted, def_nr);
if (weight < 0.0f) {
continue;
}
- 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;
- }
- }
+ /* Apply weight directly. */
+ if ((!is_normalized) && (mmd->flag & GP_THICK_WEIGHT_FACTOR)) {
+ pt->pressure *= ((mmd->flag & GP_THICK_INVERT_VGROUP) ? 1.0f - weight : weight);
+ CLAMP_MIN(pt->pressure, 0.0f);
+ continue;
}
+ float curvef = 1.0f;
+
if ((mmd->flag & GP_THICK_CUSTOM_CURVE) && (mmd->curve_thickness)) {
/* Normalize value to evaluate curve. */
float value = (float)i / (gps->totpoints - 1);
@@ -161,7 +145,7 @@ static void deformStroke(GpencilModifierData *md,
}
float target;
- if (mmd->flag & GP_THICK_NORMALIZE) {
+ if (is_normalized) {
target = mmd->thickness * stroke_thickness_inv;
target *= curvef;
}
@@ -170,11 +154,6 @@ static void deformStroke(GpencilModifierData *md,
weight *= curvef;
}
- /* Apply distance fading. */
- if (mmd->flag & GP_THICK_FADING) {
- target = interpf(target, mmd->fading_end_factor, factor_depth);
- }
-
pt->pressure = interpf(target, pt->pressure, weight);
CLAMP_MIN(pt->pressure, 0.0f);
@@ -202,32 +181,6 @@ 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)
@@ -239,12 +192,17 @@ static void panel_draw(const bContext *UNUSED(C), Panel *panel)
uiLayoutSetPropSep(layout, true);
uiItemR(layout, ptr, "normalize_thickness", 0, NULL, ICON_NONE);
-
if (RNA_boolean_get(ptr, "normalize_thickness")) {
uiItemR(layout, ptr, "thickness", 0, NULL, ICON_NONE);
}
else {
- uiItemR(layout, ptr, "thickness_factor", 0, NULL, ICON_NONE);
+ const bool is_weighted = !RNA_boolean_get(ptr, "use_weight_factor");
+ uiLayout *row = uiLayoutRow(layout, true);
+ uiLayoutSetActive(row, is_weighted);
+ uiItemR(row, ptr, "thickness_factor", 0, NULL, ICON_NONE);
+ uiLayout *sub = uiLayoutRow(row, true);
+ uiLayoutSetActive(sub, true);
+ uiItemR(row, ptr, "use_weight_factor", 0, "", ICON_MOD_VERTEX_WEIGHT);
}
gpencil_modifier_panel_end(layout, ptr);
@@ -259,8 +217,6 @@ 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,
@@ -288,7 +244,7 @@ GpencilModifierTypeInfo modifierType_Gpencil_Thick = {
/* initData */ initData,
/* freeData */ freeData,
/* isDisabled */ NULL,
- /* updateDepsgraph */ updateDepsgraph,
+ /* updateDepsgraph */ NULL,
/* dependsOnTime */ NULL,
/* foreachIDLink */ foreachIDLink,
/* foreachTexLink */ NULL,