[Bf-blender-cvs] [78e7a6ef13f] greasepencil-object: GPencil: Fix problems with the vertex color modifier

Antonio Vazquez noreply at git.blender.org
Tue Nov 5 19:52:01 CET 2019


Commit: 78e7a6ef13f9fc6204e899c88b13c2b6684c20dd
Author: Antonio Vazquez
Date:   Tue Nov 5 19:48:06 2019 +0100
Branches: greasepencil-object
https://developer.blender.org/rB78e7a6ef13f9fc6204e899c88b13c2b6684c20dd

GPencil: Fix problems with the vertex color modifier

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/gpencil_modifiers/intern/MOD_gpencilvertexcolor.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 8890bb9a1ec..d9b6830e2f1 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -2352,25 +2352,23 @@ class DATA_PT_gpencil_modifiers(ModifierButtonsPanel, Panel):
 
     def GP_VERTEXCOLOR(self, layout, ob, md):
         gpd = ob.data
-        split = layout.split()
 
-        col = split.column()
+        col = layout.column()
+        col.prop(md, "vertex_mode")
+
+        col. separator()
         col.label(text="Object:")
         col.prop(md, "object", text="")
 
-        layout.separator()
-
-        row = layout.row(align=True)
-        row.prop(md, "radius")
-        row = layout.row(align=True)
-        row.prop(md, "factor", slider=True)
+        col.separator()
+        col.prop(md, "radius")
+        col.prop(md, "factor", slider=True)
+        col.prop(md, "use_decay_color")
 
-        col = layout.column()
         col.separator()
         col.label(text="Colors:")
         col.template_color_ramp(md, "colors")
 
-        col = layout.column()
         col.separator()
         col.label(text="Vertex Group:")
         row = col.row(align=True)
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilvertexcolor.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilvertexcolor.c
index 9cdc6097fac..17a0a2046fc 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencilvertexcolor.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilvertexcolor.c
@@ -63,19 +63,22 @@ static void initData(GpencilModifierData *md)
   gpmd->materialname[0] = '\0';
   gpmd->vgname[0] = '\0';
   gpmd->object = NULL;
+  gpmd->radius = 1.0f;
+  gpmd->factor = 1.0f;
+
+  /* Add default color ramp. */
   gpmd->colorband = BKE_colorband_add(false);
   if (gpmd->colorband) {
     BKE_colorband_init(gpmd->colorband, true);
+    CBData *ramp = gpmd->colorband->data;
+    ramp[0].r = ramp[0].g = ramp[0].b = ramp[0].a = 1.0f;
+    ramp[0].pos = 0.0f;
+    ramp[1].r = ramp[1].g = ramp[1].b = 0.0f;
+    ramp[1].a = 1.0f;
+    ramp[1].pos = 1.0f;
+
+    gpmd->colorband->tot = 2;
   }
-  CBData *ramp = gpmd->colorband->data;
-  /* Add default smooth-falloff ramp. */
-  ramp[0].r = ramp[0].g = ramp[0].b = ramp[0].a = 1.0f;
-  ramp[0].pos = 0.0f;
-  ramp[1].r = ramp[1].g = ramp[1].b = 0.0f;
-  ramp[1].a = 1.0f;
-  ramp[1].pos = 1.0f;
-
-  gpmd->colorband->tot = 2;
 }
 
 static void copyData(const GpencilModifierData *md, GpencilModifierData *target)
@@ -122,11 +125,13 @@ static void deformStroke(GpencilModifierData *md,
   }
 
   float radius_sqr = mmd->radius * mmd->radius;
+  float coba_res[4];
 
   /* loop points and apply deform */
   float target_loc[3];
   copy_v3_v3(target_loc, mmd->object->loc);
 
+  bool doit = false;
   for (int i = 0; i < gps->totpoints; i++) {
     bGPDspoint *pt = &gps->points[i];
     MDeformVert *dvert = gps->dvert != NULL ? &gps->dvert[i] : NULL;
@@ -143,19 +148,35 @@ static void deformStroke(GpencilModifierData *md,
       continue;
     }
 
-    /* Verify vertex group. */
-    const float weight = get_modifier_point_weight(
-        dvert, (mmd->flag & GP_HOOK_INVERT_VGROUP) != 0, def_nr);
-    if (weight < 0.0f) {
-      continue;
+    if (!doit) {
+      /* Apply to fill. */
+      if (mmd->mode != GPPAINT_MODE_STROKE) {
+        BKE_colorband_evaluate(mmd->colorband, 1.0f, coba_res);
+        interp_v3_v3v3(gps->mix_color_fill, gps->mix_color_fill, coba_res, mmd->factor);
+        gps->mix_color_fill[3] = mmd->factor;
+      }
+      /* If no stroke, cancel loop. */
+      if (mmd->mode != GPPAINT_MODE_BOTH) {
+        break;
+      }
+
+      doit = true;
     }
-    /* Calc the factor using the distance and get mix color. */
-    float mix_factor = dist_sqr / radius_sqr;
-    float coba_res[4];
-    BKE_colorband_evaluate(mmd->colorband, mix_factor, coba_res);
 
-    interp_v3_v3v3(pt->mix_color, pt->mix_color, coba_res, mmd->factor);
-    pt->mix_color[3] = mmd->factor;
+    /* Verify vertex group. */
+    if (mmd->mode != GPPAINT_MODE_FILL) {
+      const float weight = get_modifier_point_weight(
+          dvert, (mmd->flag & GP_HOOK_INVERT_VGROUP) != 0, def_nr);
+      if (weight < 0.0f) {
+        continue;
+      }
+      /* Calc the factor using the distance and get mix color. */
+      float mix_factor = dist_sqr / radius_sqr;
+      BKE_colorband_evaluate(mmd->colorband, mix_factor, coba_res);
+
+      interp_v3_v3v3(pt->mix_color, pt->mix_color, coba_res, mmd->factor * weight);
+      pt->mix_color[3] = mmd->factor * (1.0f - mix_factor);
+    }
   }
 }
 
diff --git a/source/blender/makesdna/DNA_gpencil_modifier_types.h b/source/blender/makesdna/DNA_gpencil_modifier_types.h
index 428167f5907..3c439558ea4 100644
--- a/source/blender/makesdna/DNA_gpencil_modifier_types.h
+++ b/source/blender/makesdna/DNA_gpencil_modifier_types.h
@@ -673,6 +673,7 @@ typedef enum eVertexcolorGpencil_Flag {
   GP_VERTEXCOL_UNIFORM_SPACE = (1 << 3),
   GP_VERTEXCOL_INVERT_LAYERPASS = (1 << 4),
   GP_VERTEXCOL_INVERT_MATERIAL = (1 << 5),
+  GP_VERTEXCOL_DECAY_COLOR = (1 << 6),
 } eVertexcolorGpencil_Flag;
 
 #endif /* __DNA_GPENCIL_MODIFIER_TYPES_H__ */
diff --git a/source/blender/makesrna/intern/rna_gpencil_modifier.c b/source/blender/makesrna/intern/rna_gpencil_modifier.c
index 2686592c52a..d65065d71db 100644
--- a/source/blender/makesrna/intern/rna_gpencil_modifier.c
+++ b/source/blender/makesrna/intern/rna_gpencil_modifier.c
@@ -1963,6 +1963,11 @@ static void rna_def_modifier_gpencilvertexcolor(BlenderRNA *brna)
   RNA_def_property_ui_text(prop, "Inverse Pass", "Inverse filter");
   RNA_def_property_update(prop, 0, "rna_GpencilModifier_update");
 
+  prop = RNA_def_property(srna, "use_decay_color", PROP_BOOLEAN, PROP_NONE);
+  RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_VERTEXCOL_DECAY_COLOR);
+  RNA_def_property_ui_text(prop, "Decay", "The tinting decrease with the distance");
+  RNA_def_property_update(prop, 0, "rna_GpencilModifier_update");
+
   prop = RNA_def_property(srna, "factor", PROP_FLOAT, PROP_FACTOR);
   RNA_def_property_float_sdna(prop, NULL, "factor");
   RNA_def_property_range(prop, 0.0f, 1.0f);
@@ -1980,8 +1985,9 @@ static void rna_def_modifier_gpencilvertexcolor(BlenderRNA *brna)
   prop = RNA_def_property(srna, "vertex_mode", PROP_ENUM, PROP_NONE);
   RNA_def_property_enum_bitflag_sdna(prop, NULL, "mode");
   RNA_def_property_enum_items(prop, vertexcol_mode_types_items);
-  RNA_def_property_ui_text(prop, "Mode Type", "Defines how vertex color affect to the strokes");
+  RNA_def_property_ui_text(prop, "Mode", "Defines how vertex color affect to the strokes");
   RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+  RNA_def_property_update(prop, 0, "rna_GpencilModifier_update");
 
   /* Color band */
   prop = RNA_def_property(srna, "colors", PROP_POINTER, PROP_NONE);



More information about the Bf-blender-cvs mailing list