[Bf-blender-cvs] [ef4c69a7159] greasepencil-object: Add curve options to Thick modifier
Antonio Vazquez
noreply at git.blender.org
Sun Oct 1 18:54:51 CEST 2017
Commit: ef4c69a71594ceb42aac8e4d4cd0ed0523adb34f
Author: Antonio Vazquez
Date: Sun Oct 1 18:54:30 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rBef4c69a71594ceb42aac8e4d4cd0ed0523adb34f
Add curve options to Thick modifier
New options to adjust the thickness of the stroke using a curve to get more artistics effects.
===================================================================
M release/scripts/startup/bl_ui/properties_data_modifier.py
M source/blender/blenkernel/intern/gpencil_modifier.c
M source/blender/blenloader/intern/readfile.c
M source/blender/blenloader/intern/writefile.c
M source/blender/makesdna/DNA_modifier_types.h
M source/blender/makesrna/intern/rna_modifier.c
M source/blender/modifiers/intern/MOD_gpencilthick.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index db15f6d7e50..c34423ca8f3 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1635,6 +1635,13 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
row.prop_search(md, "vertex_group", ob, "vertex_groups", text="")
row.prop(md, "inverse_vertex", text="", icon="ARROW_LEFTRIGHT")
+ split = layout.split()
+ col = split.column()
+ col.prop(md, "use_custom_curve")
+
+ if md.use_custom_curve:
+ col.template_curve_mapping(md, "curve")
+
def GP_TINT(self, layout, ob, md):
gpd = ob.grease_pencil
split = layout.split()
diff --git a/source/blender/blenkernel/intern/gpencil_modifier.c b/source/blender/blenkernel/intern/gpencil_modifier.c
index 81f599faef4..8973162965a 100644
--- a/source/blender/blenkernel/intern/gpencil_modifier.c
+++ b/source/blender/blenkernel/intern/gpencil_modifier.c
@@ -48,6 +48,7 @@
#include "BKE_lattice.h"
#include "BKE_gpencil.h"
#include "BKE_modifier.h"
+#include "BKE_colortools.h"
/* used to save temp strokes */
typedef struct tGPencilStrokeCache {
@@ -387,6 +388,7 @@ void BKE_gpencil_thick_modifier(int UNUSED(id), GpencilThickModifierData *mmd, O
bGPDspoint *pt;
int vindex = get_vertex_group_index(ob, mmd->vgname);
float weight = 1.0f;
+ float curvef = 1.0;
if (!is_stroke_affected_by_modifier(mmd->layername, mmd->passindex, 3, gpl, gps,
(bool)mmd->flag & GP_THICK_INVERSE_LAYER, (bool)mmd->flag & GP_THICK_INVERSE_PASS)) {
@@ -394,6 +396,7 @@ void BKE_gpencil_thick_modifier(int UNUSED(id), GpencilThickModifierData *mmd, O
}
for (int i = 0; i < gps->totpoints; ++i) {
+ curvef = 1.0;
pt = &gps->points[i];
/* verify vertex group */
weight = is_point_affected_by_modifier(pt, (int)(!(mmd->flag & GP_THICK_INVERSE_VGROUP) == 0), vindex);
@@ -401,7 +404,13 @@ void BKE_gpencil_thick_modifier(int UNUSED(id), GpencilThickModifierData *mmd, O
continue;
}
- pt->pressure += mmd->thickness * weight;
+ if ((mmd->flag & GP_THICK_CUSTOM_CURVE) && (mmd->cur_thickness)) {
+ /* nomalize value */
+ float value = (float)i / (gps->totpoints - 1);
+ curvef = curvemapping_evaluateF(mmd->cur_thickness, 0, value);
+ }
+
+ pt->pressure += mmd->thickness * weight * curvef;
CLAMP(pt->strength, 0.0f, 1.0f);
}
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index bca05b4437d..ada87b0aeb0 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -5479,6 +5479,15 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
GpencilLatticeModifierData *gpmd = (GpencilLatticeModifierData*)md;
gpmd->cache_data = NULL;
}
+ else if (md->type == eModifierType_GpencilThick) {
+ GpencilThickModifierData *gpmd = (GpencilThickModifierData *)md;
+
+ gpmd->cur_thickness = newdataadr(fd, gpmd->cur_thickness);
+ if (gpmd->cur_thickness) {
+ direct_link_curvemapping(fd, gpmd->cur_thickness);
+ }
+ }
+
}
}
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index c2e22a45ccd..d5a552a7577 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1731,6 +1731,13 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
writedata(wd, DATA, sizeof(int) * hmd->totindex, hmd->indexar);
}
+ else if (md->type == eModifierType_GpencilThick) {
+ GpencilThickModifierData *gpmd = (GpencilThickModifierData *)md;
+
+ if (gpmd->cur_thickness) {
+ write_curvemapping(wd, gpmd->cur_thickness);
+ }
+ }
else if (md->type == eModifierType_Cloth) {
ClothModifierData *clmd = (ClothModifierData *)md;
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index c04acaf989c..d6ce0ec690e 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1686,12 +1686,14 @@ typedef struct GpencilThickModifierData {
int flag; /* flags */
int thickness; /* Thickness change */
char pad[4];
+ struct CurveMapping *cur_thickness;
} GpencilThickModifierData;
typedef enum eGpencilThick_Flag {
GP_THICK_INVERSE_LAYER = (1 << 0),
GP_THICK_INVERSE_PASS = (1 << 1),
GP_THICK_INVERSE_VGROUP = (1 << 2),
+ GP_THICK_CUSTOM_CURVE = (1 << 3),
} eGpencilThick_Flag;
typedef struct GpencilTintModifierData {
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 612fbdc8964..cb988ec5203 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -5074,6 +5074,16 @@ static void rna_def_modifier_gpencilthick(BlenderRNA *brna)
RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_THICK_INVERSE_VGROUP);
RNA_def_property_ui_text(prop, "Inverse VertexGroup", "Inverse filter");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+ prop = RNA_def_property(srna, "use_custom_curve", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_THICK_CUSTOM_CURVE);
+ RNA_def_property_ui_text(prop, "Custom Curve", "Use a custom curve to define thickness changes");
+ RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+ prop = RNA_def_property(srna, "curve", PROP_POINTER, PROP_NONE);
+ RNA_def_property_pointer_sdna(prop, NULL, "cur_thickness");
+ RNA_def_property_ui_text(prop, "Curve", "Custom Thickness Curve");
+ RNA_def_property_update(prop, 0, "rna_Modifier_update");
}
static void rna_def_modifier_gpenciltint(BlenderRNA *brna)
diff --git a/source/blender/modifiers/intern/MOD_gpencilthick.c b/source/blender/modifiers/intern/MOD_gpencilthick.c
index 8376d062a79..69f39a76d39 100644
--- a/source/blender/modifiers/intern/MOD_gpencilthick.c
+++ b/source/blender/modifiers/intern/MOD_gpencilthick.c
@@ -35,8 +35,10 @@
#include "DNA_gpencil_types.h"
#include "BLI_utildefines.h"
+
#include "BKE_DerivedMesh.h"
#include "BKE_gpencil.h"
+#include "BKE_colortools.h"
#include "MOD_modifiertypes.h"
@@ -47,13 +49,35 @@ static void initData(ModifierData *md)
gpmd->thickness = 0;
gpmd->layername[0] = '\0';
gpmd->vgname[0] = '\0';
+ gpmd->cur_thickness = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
+ if (gpmd->cur_thickness) {
+ curvemapping_initialize(gpmd->cur_thickness);
+ }
BKE_gpencil_batch_cache_alldirty();
}
+static void freeData(ModifierData *md)
+{
+ GpencilThickModifierData *gpmd = (GpencilThickModifierData *)md;
+
+ if (gpmd->cur_thickness) {
+ curvemapping_free(gpmd->cur_thickness);
+ }
+}
+
static void copyData(ModifierData *md, ModifierData *target)
{
+ GpencilThickModifierData *gmd = (GpencilThickModifierData *)md;
+ GpencilThickModifierData *tgmd = (GpencilThickModifierData *)target;
+
+ if (tgmd->cur_thickness != NULL) {
+ curvemapping_free(tgmd->cur_thickness);
+ }
+
modifier_copyData_generic(md, target);
+
+ tgmd->cur_thickness = curvemapping_copy(gmd->cur_thickness);
}
static DerivedMesh *applyModifier(
@@ -94,7 +118,7 @@ ModifierTypeInfo modifierType_GpencilThick = {
/* applyModifierEM */ NULL,
/* initData */ initData,
/* requiredDataMask */ NULL,
- /* freeData */ NULL,
+ /* freeData */ freeData,
/* isDisabled */ NULL,
/* updateDepsgraph */ NULL,
/* dependsOnTime */ NULL,
More information about the Bf-blender-cvs
mailing list