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:
Diffstat (limited to 'source/blender/gpencil_modifiers/intern/MOD_gpencilsmooth.c')
-rw-r--r--source/blender/gpencil_modifiers/intern/MOD_gpencilsmooth.c52
1 files changed, 43 insertions, 9 deletions
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilsmooth.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilsmooth.c
index b6b5bf05a9d..896333318aa 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencilsmooth.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilsmooth.c
@@ -23,6 +23,7 @@
#include <stdio.h>
+#include "BLI_listbase.h"
#include "BLI_utildefines.h"
#include "DNA_meshdata_types.h"
@@ -30,6 +31,7 @@
#include "DNA_gpencil_types.h"
#include "DNA_gpencil_modifier_types.h"
+#include "BKE_colortools.h"
#include "BKE_deform.h"
#include "BKE_gpencil.h"
#include "BKE_gpencil_modifier.h"
@@ -49,11 +51,27 @@ static void initData(GpencilModifierData *md)
gpmd->materialname[0] = '\0';
gpmd->vgname[0] = '\0';
gpmd->step = 1;
+
+ gpmd->curve_intensity = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
+ if (gpmd->curve_intensity) {
+ CurveMapping *curve = gpmd->curve_intensity;
+ BKE_curvemapping_initialize(curve);
+ }
}
static void copyData(const GpencilModifierData *md, GpencilModifierData *target)
{
+ SmoothGpencilModifierData *gmd = (SmoothGpencilModifierData *)md;
+ SmoothGpencilModifierData *tgmd = (SmoothGpencilModifierData *)target;
+
+ if (tgmd->curve_intensity != NULL) {
+ BKE_curvemapping_free(tgmd->curve_intensity);
+ tgmd->curve_intensity = NULL;
+ }
+
BKE_gpencil_modifier_copyData_generic(md, target);
+
+ tgmd->curve_intensity = BKE_curvemapping_copy(gmd->curve_intensity);
}
/* aply smooth effect based on stroke direction */
@@ -66,6 +84,7 @@ static void deformStroke(GpencilModifierData *md,
{
SmoothGpencilModifierData *mmd = (SmoothGpencilModifierData *)md;
const int def_nr = BKE_object_defgroup_name_index(ob, mmd->vgname);
+ const bool use_curve = (mmd->flag & GP_SMOOTH_CUSTOM_CURVE) != 0 && mmd->curve_intensity;
if (!is_stroke_affected_by_modifier(ob,
mmd->layername,
@@ -89,28 +108,34 @@ static void deformStroke(GpencilModifierData *md,
MDeformVert *dvert = gps->dvert != NULL ? &gps->dvert[i] : NULL;
/* verify vertex group */
- const float weight = get_modifier_point_weight(
+ float weight = get_modifier_point_weight(
dvert, (mmd->flag & GP_SMOOTH_INVERT_VGROUP) != 0, def_nr);
if (weight < 0.0f) {
continue;
}
+ /* Custom curve to modulate value. */
+ if (use_curve) {
+ float value = (float)i / (gps->totpoints - 1);
+ weight *= BKE_curvemapping_evaluateF(mmd->curve_intensity, 0, value);
+ }
+
const float val = mmd->factor * weight;
/* perform smoothing */
if (mmd->flag & GP_SMOOTH_MOD_LOCATION) {
- BKE_gpencil_smooth_stroke(gps, i, val);
+ BKE_gpencil_stroke_smooth(gps, i, val);
}
if (mmd->flag & GP_SMOOTH_MOD_STRENGTH) {
- BKE_gpencil_smooth_stroke_strength(gps, i, val);
+ BKE_gpencil_stroke_smooth_strength(gps, i, val);
}
if ((mmd->flag & GP_SMOOTH_MOD_THICKNESS) && (val > 0.0f)) {
/* thickness need to repeat process several times */
for (int r2 = 0; r2 < r * 10; r2++) {
- BKE_gpencil_smooth_stroke_thickness(gps, i, val);
+ BKE_gpencil_stroke_smooth_thickness(gps, i, val);
}
}
if (mmd->flag & GP_SMOOTH_MOD_UV) {
- BKE_gpencil_smooth_stroke_uv(gps, i, val);
+ BKE_gpencil_stroke_smooth_uv(gps, i, val);
}
}
}
@@ -124,15 +149,24 @@ static void bakeModifier(struct Main *UNUSED(bmain),
{
bGPdata *gpd = ob->data;
- 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) {
+ LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
+ LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
+ LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
deformStroke(md, depsgraph, ob, gpl, gpf, gps);
}
}
}
}
+static void freeData(GpencilModifierData *md)
+{
+ SmoothGpencilModifierData *gpmd = (SmoothGpencilModifierData *)md;
+
+ if (gpmd->curve_intensity) {
+ BKE_curvemapping_free(gpmd->curve_intensity);
+ }
+}
+
GpencilModifierTypeInfo modifierType_Gpencil_Smooth = {
/* name */ "Smooth",
/* structName */ "SmoothGpencilModifierData",
@@ -148,7 +182,7 @@ GpencilModifierTypeInfo modifierType_Gpencil_Smooth = {
/* remapTime */ NULL,
/* initData */ initData,
- /* freeData */ NULL,
+ /* freeData */ freeData,
/* isDisabled */ NULL,
/* updateDepsgraph */ NULL,
/* dependsOnTime */ NULL,