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>2020-03-09 18:27:24 +0300
committerAntonio Vazquez <blendergit@gmail.com>2020-03-09 18:27:24 +0300
commit29f3af95272590d26f610ae828b2eeee89c82a00 (patch)
treea696a58a2561c48f7ec6166e369e22081e0a64d8 /source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c
parentdcb93126876879d969a30a7865700abd072066f8 (diff)
GPencil: Refactor of Draw Engine, Vertex Paint and all internal functions
This commit is a full refactor of the grease pencil modules including Draw Engine, Modifiers, VFX, depsgraph update, improvements in operators and conversion of Sculpt and Weight paint tools to real brushes. Also, a huge code cleanup has been done at all levels. Thanks to @fclem for his work and yo @pepeland and @mendio for the testing and help in the development. Differential Revision: https://developer.blender.org/D6293
Diffstat (limited to 'source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c')
-rw-r--r--source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c79
1 files changed, 25 insertions, 54 deletions
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c
index 694b932a6bf..894dff46ac2 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c
@@ -23,6 +23,8 @@
#include <stdio.h>
+#include "BLI_listbase.h"
+#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "DNA_meshdata_types.h"
@@ -45,7 +47,8 @@ static void initData(GpencilModifierData *md)
{
ThickGpencilModifierData *gpmd = (ThickGpencilModifierData *)md;
gpmd->pass_index = 0;
- gpmd->thickness = 2;
+ gpmd->thickness_fac = 1.0f;
+ gpmd->thickness = 30;
gpmd->layername[0] = '\0';
gpmd->materialname[0] = '\0';
gpmd->vgname[0] = '\0';
@@ -105,70 +108,38 @@ static void deformStroke(GpencilModifierData *md,
return;
}
- /* Check to see if we normalize the whole stroke or only certain points along it. */
- bool gps_has_affected_points = false;
- bool gps_has_unaffected_points = false;
-
- if (mmd->flag & GP_THICK_NORMALIZE) {
- for (int i = 0; i < gps->totpoints; i++) {
- MDeformVert *dvert = gps->dvert != NULL ? &gps->dvert[i] : NULL;
- const float weight = get_modifier_point_weight(
- dvert, (mmd->flag & GP_THICK_INVERT_VGROUP) != 0, def_nr);
- if (weight < 0.0f) {
- gps_has_unaffected_points = true;
- }
- else {
- gps_has_affected_points = true;
- }
-
- /* If both checks are true, we have what we need so we can stop looking. */
- if (gps_has_affected_points && gps_has_unaffected_points) {
- break;
- }
- }
- }
-
- /* If we are normalizing and all points of the stroke are affected, it's safe to reset thickness
- */
- if (mmd->flag & GP_THICK_NORMALIZE && gps_has_affected_points && !gps_has_unaffected_points) {
- gps->thickness = mmd->thickness;
- }
- /* Without this check, modifier alters the thickness of strokes which have no points in scope */
+ float stroke_thickness_inv = 1.0f / max_ii(gps->thickness, 1);
for (int i = 0; i < gps->totpoints; i++) {
bGPDspoint *pt = &gps->points[i];
MDeformVert *dvert = gps->dvert != NULL ? &gps->dvert[i] : NULL;
- float curvef = 1.0f;
/* Verify point is part of vertex group. */
- const float weight = get_modifier_point_weight(
+ float weight = get_modifier_point_weight(
dvert, (mmd->flag & GP_THICK_INVERT_VGROUP) != 0, def_nr);
if (weight < 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);
+ curvef = BKE_curvemapping_evaluateF(mmd->curve_thickness, 0, value);
+ }
+
+ float target;
if (mmd->flag & GP_THICK_NORMALIZE) {
- if (gps_has_unaffected_points) {
- /* Clamp value for very weird situations when stroke thickness can be zero. */
- CLAMP_MIN(gps->thickness, 1);
- /* Calculate pressure value to match the width of strokes with reset thickness and 1.0
- * pressure. */
- pt->pressure = (float)mmd->thickness / (float)gps->thickness;
- }
- else {
- /* Reset point pressure values so only stroke thickness counts. */
- pt->pressure = 1.0f;
- }
+ target = mmd->thickness * stroke_thickness_inv;
+ target *= curvef;
}
else {
- if ((mmd->flag & GP_THICK_CUSTOM_CURVE) && (mmd->curve_thickness)) {
- /* Normalize value to evaluate curve. */
- float value = (float)i / (gps->totpoints - 1);
- curvef = BKE_curvemapping_evaluateF(mmd->curve_thickness, 0, value);
- }
-
- pt->pressure += mmd->thickness * weight * curvef;
- CLAMP_MIN(pt->pressure, 0.1f);
+ target = pt->pressure * mmd->thickness_fac;
+ weight *= curvef;
}
+
+ pt->pressure = interpf(target, pt->pressure, weight);
+
+ CLAMP_MIN(pt->pressure, 0.1f);
}
}
@@ -179,9 +150,9 @@ 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);
}
}