[Bf-blender-cvs] [a477c2e0e07] master: Fix unreported GPencil Thickness modifier affecting strokes not in Vertex Groups

S J Bennett quollism noreply at git.blender.org
Sat Aug 17 11:18:01 CEST 2019


Commit: a477c2e0e07943553e319d430dce0df1015d790b
Author: S J Bennett (quollism)
Date:   Sat Aug 17 11:16:49 2019 +0200
Branches: master
https://developer.blender.org/rBa477c2e0e07943553e319d430dce0df1015d790b

Fix unreported GPencil Thickness modifier affecting strokes not in Vertex Groups

Prior to this commit: If the Grease Pencil Thickness modifier is set to Normalize and a Vertex Group is selected, the thickness of all strokes are effected when changing the Thickness parameter. Points on strokes are only normalised (= pressure set to 1.0) if they are part of the Vertex Group; the strokes themselves may still change thickness.

With this patch: If Normalize is selected with a Vertex Group, Blender now pre-checks each stroke to determine whether it has vertices within or outside the Vertex Group. If all the points on the stroke belong to the Vertex Group, it normalises the whole stroke to a uniform thickness. If some or none of the points of the stroke belong to the Vertex Group, the stroke is now left as is.

Reviewed By: @antoniov
Differential Revision: https://developer.blender.org/D5483 with minor edit.

===================================================================

M	source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c

===================================================================

diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c
index 357e36a06b2..8ab72716f4d 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c
@@ -102,16 +102,41 @@ static void deformStroke(GpencilModifierData *md,
     return;
   }
 
-  /* if normalize, set stroke thickness */
+  /* 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 */
 
   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 vertex group */
+    /* Verify point is part of vertex group. */
     const float weight = get_modifier_point_weight(
         dvert, (mmd->flag & GP_THICK_INVERT_VGROUP) != 0, def_nr);
     if (weight < 0.0f) {
@@ -119,11 +144,21 @@ static void deformStroke(GpencilModifierData *md,
     }
 
     if (mmd->flag & GP_THICK_NORMALIZE) {
-      pt->pressure = 1.0f;
+      if (gps_has_unaffected_points) {
+        /* Clamp value for very weird situations when stroke thickness can be zero. */
+        CLAMP_MIN(gps->thickness, 0.001f);
+        /* 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;
+      }
     }
     else {
       if ((mmd->flag & GP_THICK_CUSTOM_CURVE) && (mmd->curve_thickness)) {
-        /* normalize value to evaluate curve */
+        /* Normalize value to evaluate curve. */
         float value = (float)i / (gps->totpoints - 1);
         curvef = BKE_curvemapping_evaluateF(mmd->curve_thickness, 0, value);
       }



More information about the Bf-blender-cvs mailing list