[Bf-blender-cvs] [affe9e0b925] greasepencil-object: Pencil: Modifier: Change Thickness modifier behavior

Clément Foucault noreply at git.blender.org
Thu Mar 5 00:11:29 CET 2020


Commit: affe9e0b925d0259bdbec4a88a7ad34b4da353dc
Author: Clément Foucault
Date:   Thu Mar 5 00:08:13 2020 +0100
Branches: greasepencil-object
https://developer.blender.org/rBaffe9e0b925d0259bdbec4a88a7ad34b4da353dc

Pencil: Modifier: Change Thickness modifier behavior

Normalize option is now Replace Thickness.
A separate factor is used when switching to relative mode.

Custom Curve profile is also applied in replace thickness mode to shape
the profile.

Simplify the modifier code by only modifying the pt->pressure.

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c
M	source/blender/makesdna/DNA_gpencil_modifier_types.h
M	source/blender/makesrna/intern/rna_gpencil_modifier.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 8a6fd3321f4..81532734889 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1858,21 +1858,21 @@ class DATA_PT_gpencil_modifiers(ModifierButtonsPanel, Panel):
         self.gpencil_masking(layout, ob, md, False)
 
     def GP_THICK(self, layout, ob, md):
-        split = layout.split()
-
-        col = split.column()
-        row = col.row(align=True)
-        row.prop(md, "thickness", text="Thickness Factor")
+        col = layout.column()
 
         col.prop(md, "normalize_thickness")
 
-        if not md.normalize_thickness:
-            split = layout.split()
-            col = split.column()
-            col.prop(md, "use_custom_curve")
+        if md.normalize_thickness:
+            col.prop(md, "thickness")
+        else:
+            col.prop(md, "thickness_factor")
+
+        col.separator()
+
+        col.prop(md, "use_custom_curve")
 
-            if md.use_custom_curve:
-                col.template_curve_mapping(md, "curve")
+        if md.use_custom_curve:
+            col.template_curve_mapping(md, "curve")
 
         self.gpencil_masking(layout, ob, md, True)
 
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index 24696efe11b..c4b0674d03c 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -4681,5 +4681,18 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
    */
   {
     /* Keep this block, even when empty. */
+
+    /* Grease pencil modifiers changes. */
+    if (!DNA_struct_elem_find(
+            fd->filesdna, "ThickGpencilModifierData", "float", "thickness_fac")) {
+      LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
+        LISTBASE_FOREACH (ModifierData *, md, &ob->greasepencil_modifiers) {
+          if (md->type == eGpencilModifierType_Thick) {
+            ThickGpencilModifierData *gpmd = (ThickGpencilModifierData *)md;
+            gpmd->thickness_fac = gpmd->thickness;
+          }
+        }
+      }
+    }
   }
 }
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c
index 0f9b2ea52d2..200e361181a 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c
@@ -24,6 +24,7 @@
 #include <stdio.h>
 
 #include "BLI_listbase.h"
+#include "BLI_math.h"
 #include "BLI_utildefines.h"
 
 #include "DNA_meshdata_types.h"
@@ -46,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';
@@ -106,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);
   }
 }
 
diff --git a/source/blender/makesdna/DNA_gpencil_modifier_types.h b/source/blender/makesdna/DNA_gpencil_modifier_types.h
index 001ff2fd9ef..bedfd957f9a 100644
--- a/source/blender/makesdna/DNA_gpencil_modifier_types.h
+++ b/source/blender/makesdna/DNA_gpencil_modifier_types.h
@@ -156,10 +156,13 @@ typedef struct ThickGpencilModifierData {
   int pass_index;
   /** Flags. */
   int flag;
-  /** Thickness change. */
+  /** Relative thickness factor. */
+  float thickness_fac;
+  /** Absolute thickness overide. */
   int thickness;
   /** Custom index for passes. */
   int layer_pass;
+  char _pad[4];
   struct CurveMapping *curve_thickness;
 } ThickGpencilModifierData;
 
diff --git a/source/blender/makesrna/intern/rna_gpencil_modifier.c b/source/blender/makesrna/intern/rna_gpencil_modifier.c
index e72317d1585..88181860836 100644
--- a/source/blender/makesrna/intern/rna_gpencil_modifier.c
+++ b/source/blender/makesrna/intern/rna_gpencil_modifier.c
@@ -813,7 +813,15 @@ static void rna_def_modifier_gpencilthick(BlenderRNA *brna)
   prop = RNA_def_property(srna, "thickness", PROP_INT, PROP_NONE);
   RNA_def_property_int_sdna(prop, NULL, "thickness");
   RNA_def_property_range(prop, -100, 500);
-  RNA_def_property_ui_text(prop, "Thickness", "Factor of thickness change");
+  RNA_def_property_ui_text(prop, "Thickness", "Absolute thickness to apply everywhere");
+  RNA_def_property_update(prop, 0, "rna_GpencilModifier_update");
+
+  prop = RNA_def_property(srna, "thickness_factor", PROP_FLOAT, PROP_NONE);
+  RNA_def_property_float_sdna(prop, NULL, "thickness_fac");
+  RNA_def_property_range(prop, 0.0, FLT_MAX);
+  RNA_def_property_ui_range(prop, 0.0, 10.0, 0.1, 3);
+  RNA_def_property_float_default(prop, 1.0f);
+  RNA_def_property_ui_text(prop, "Thickness Factor", "Factor to multiply the thickness with");
   RNA_def_property_update(prop, 0, "rna_GpencilModifier_update");
 
   prop = RNA_def_property(srna, "pass_index", PROP_INT, PROP_NONE);
@@ -855,12 +863,15 @@ static void rna_def_modifier_gpencilthick(BlenderRNA *brna)
 
   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_ui_text(prop,
+                           "Custom Curve",
+                           "Use a custom curve to define thickness changes"
+                           "along the strokes");
   RNA_def_property_update(prop, 0, "rna_GpencilModifier_update");
 
   prop = RNA_def_property(srna, "normalize_thickness", PROP_BOOLEAN, PROP_NONE);
   RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_THICK_NORMALIZE);
-  RNA_def_property_ui_text(prop, "Normalize", "Normalize the full stroke to modifier thickness");
+  RNA_def_property_ui_text(prop, "Replace Thickness", "Replace stroke thickness");
   RNA_def_property_update(prop, 0, "rna_GpencilModifier_update");
 
   prop = RNA_def_property(srna, "curve", PROP_POINTER, PROP_NONE);



More information about the Bf-blender-cvs mailing list