[Bf-blender-cvs] [a39a6517af6] master: GPencil: Add Texture modifier

Cody Winchester noreply at git.blender.org
Sun Apr 19 17:30:21 CEST 2020


Commit: a39a6517af6603fcb16728daed88b642c88aa6eb
Author: Cody Winchester
Date:   Sun Apr 19 17:25:36 2020 +0200
Branches: master
https://developer.blender.org/rBa39a6517af6603fcb16728daed88b642c88aa6eb

GPencil: Add Texture modifier

This patch aims to add a new modifier for grease pencil objects that gives more control over the strokes texture UVs.

There are 3 modes.
1 Control the stroke texture UVs alone
2 Control the fill texture UVs alone
3 Control both the fill and stroke texture UVs

For the stroke texture UVs there are 2 options for fitting the texture to the stroke.
1 The texture uvs are kept a consistent length how it currently is set by default.
2 The uvs are normalized to fit the length of the stroke regardless of how long or short it gets allowing the texture to fit the length of the stroke.

 There are then 2 controls to scale up and down the uvs and an offset value that allows moving the texture along the stroke.

For the fill texture UVs it includes all of the transformational controls. Location offset, scale, and rotation.

Reviewed By: antoniov, mendio

Differential Revision: https://developer.blender.org/D7439

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/gpencil_modifiers/CMakeLists.txt
M	source/blender/gpencil_modifiers/MOD_gpencil_modifiertypes.h
M	source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c
A	source/blender/gpencil_modifiers/intern/MOD_gpenciltexture.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 b9fc7431a9a..03debee4384 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1976,6 +1976,27 @@ class DATA_PT_gpencil_modifiers(ModifierButtonsPanel, Panel):
 
         self.gpencil_masking(layout, ob, md, True, True)
 
+    def GP_TEXTURE(self, layout, ob, md):
+        col = layout.column()
+
+        col.prop(md, "mode")
+        if md.mode in {'STROKE', 'STROKE_AND_FILL'}:
+            col.label(text="Stroke Texture Control:")
+            col.prop(md, "fit_method")
+            col.prop(md, "uv_offset")
+            col.prop(md, "uv_scale")
+
+        if md.mode == 'STROKE_AND_FILL':
+            col.separator()
+
+        if md.mode in {'FILL', 'STROKE_AND_FILL'}:
+            col.label(text="Fill Texture Control:")
+            col.prop(md, "fill_rotation", text="Rotation")
+            col.prop(md, "fill_offset", text="Location")
+            col.prop(md, "fill_scale", text="Scale")
+
+        self.gpencil_masking(layout, ob, md, True)
+
     def GP_TINT(self, layout, ob, md):
         layout.row().prop(md, "tint_type", expand=True)
 
diff --git a/source/blender/gpencil_modifiers/CMakeLists.txt b/source/blender/gpencil_modifiers/CMakeLists.txt
index 87743911add..0e8aafad7ac 100644
--- a/source/blender/gpencil_modifiers/CMakeLists.txt
+++ b/source/blender/gpencil_modifiers/CMakeLists.txt
@@ -59,6 +59,7 @@ set(SRC
   intern/MOD_gpencilthick.c
   intern/MOD_gpenciltime.c
   intern/MOD_gpenciltint.c
+  intern/MOD_gpenciltexture.c
 
   MOD_gpencil_modifiertypes.h
 )
diff --git a/source/blender/gpencil_modifiers/MOD_gpencil_modifiertypes.h b/source/blender/gpencil_modifiers/MOD_gpencil_modifiertypes.h
index f5c064c1c07..a7a4333d82e 100644
--- a/source/blender/gpencil_modifiers/MOD_gpencil_modifiertypes.h
+++ b/source/blender/gpencil_modifiers/MOD_gpencil_modifiertypes.h
@@ -43,6 +43,7 @@ extern GpencilModifierTypeInfo modifierType_Gpencil_Offset;
 extern GpencilModifierTypeInfo modifierType_Gpencil_Armature;
 extern GpencilModifierTypeInfo modifierType_Gpencil_Time;
 extern GpencilModifierTypeInfo modifierType_Gpencil_Multiply;
+extern GpencilModifierTypeInfo modifierType_Gpencil_Texture;
 
 /* MOD_gpencil_util.c */
 void gpencil_modifier_type_init(GpencilModifierTypeInfo *types[]);
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c b/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c
index 7df0440aa85..f7b51b08c44 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c
@@ -72,6 +72,7 @@ void gpencil_modifier_type_init(GpencilModifierTypeInfo *types[])
   INIT_GP_TYPE(Armature);
   INIT_GP_TYPE(Time);
   INIT_GP_TYPE(Multiply);
+  INIT_GP_TYPE(Texture);
 #undef INIT_GP_TYPE
 }
 
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpenciltexture.c b/source/blender/gpencil_modifiers/intern/MOD_gpenciltexture.c
new file mode 100644
index 00000000000..d22056ea41d
--- /dev/null
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpenciltexture.c
@@ -0,0 +1,167 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software  Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2017, Blender Foundation
+ * This is a new part of Blender
+ */
+
+/** \file
+ * \ingroup modifiers
+ */
+
+#include <stdio.h>
+
+#include "BLI_listbase.h"
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
+
+#include "DNA_gpencil_modifier_types.h"
+#include "DNA_gpencil_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+
+#include "BKE_gpencil_geom.h"
+#include "BKE_colortools.h"
+#include "BKE_deform.h"
+#include "BKE_gpencil.h"
+#include "BKE_gpencil_modifier.h"
+
+#include "DEG_depsgraph.h"
+
+#include "MOD_gpencil_modifiertypes.h"
+#include "MOD_gpencil_util.h"
+
+static void initData(GpencilModifierData *md)
+{
+  TextureGpencilModifierData *gpmd = (TextureGpencilModifierData *)md;
+  gpmd->fit_method = GP_TEX_CONSTANT_LENGTH;
+  gpmd->fill_rotation = 0.0f;
+  gpmd->fill_scale = 1.0f;
+  gpmd->fill_offset[0] = 0.0f;
+  gpmd->fill_offset[1] = 0.0f;
+  gpmd->uv_offset = 0.0f;
+  gpmd->uv_scale = 1.0f;
+  gpmd->pass_index = 0;
+  gpmd->layername[0] = '\0';
+  gpmd->materialname[0] = '\0';
+  gpmd->vgname[0] = '\0';
+}
+
+
+static void copyData(const GpencilModifierData *md, GpencilModifierData *target)
+{
+  BKE_gpencil_modifier_copyData_generic(md, target);
+}
+
+/* change stroke uv texture values */
+static void deformStroke(GpencilModifierData *md,
+                         Depsgraph *UNUSED(depsgraph),
+                         Object *ob,
+                         bGPDlayer *gpl,
+                         bGPDframe *UNUSED(gpf),
+                         bGPDstroke *gps)
+{
+  TextureGpencilModifierData *mmd = (TextureGpencilModifierData *)md;
+  const int def_nr = BKE_object_defgroup_name_index(ob, mmd->vgname);
+
+  if (!is_stroke_affected_by_modifier(ob,
+                                      mmd->layername,
+                                      mmd->materialname,
+                                      mmd->pass_index,
+                                      mmd->layer_pass,
+                                      1,
+                                      gpl,
+                                      gps,
+                                      mmd->flag & GP_TEX_INVERT_LAYER,
+                                      mmd->flag & GP_TEX_INVERT_PASS,
+                                      mmd->flag & GP_TEX_INVERT_LAYERPASS,
+                                      mmd->flag & GP_TEX_INVERT_MATERIAL)) {
+    return;
+  }
+  if ((mmd->mode == FILL) || (mmd->mode == STROKE_AND_FILL)) {
+    gps->uv_rotation += mmd->fill_rotation;
+    gps->uv_translation[0] += mmd->fill_offset[0];
+    gps->uv_translation[1] += mmd->fill_offset[1];
+    gps->uv_scale *= mmd->fill_scale;
+    BKE_gpencil_stroke_geometry_update(gps);
+  }
+
+  if ((mmd->mode == STROKE) || (mmd->mode == STROKE_AND_FILL)) {
+    float totlen = 1.0f;
+    if (mmd->fit_method == GP_TEX_FIT_STROKE) {
+      totlen = 0.0f;
+      for (int i = 1; i < gps->totpoints; i++) {
+        totlen += len_v3v3(&gps->points[i - 1].x, &gps->points[i].x);
+      }
+    }
+
+    for (int i = 0; i < gps->totpoints; i++) {
+      bGPDspoint *pt = &gps->points[i];
+      MDeformVert *dvert = gps->dvert != NULL ? &gps->dvert[i] : NULL;
+      /* Verify point is part of vertex group. */
+      float weight = get_modifier_point_weight(
+          dvert, (mmd->flag & GP_TEX_INVERT_VGROUP) != 0, def_nr);
+      if (weight < 0.0f) {
+        continue;
+      }
+
+      pt->uv_fac /= totlen;
+      pt->uv_fac *= mmd->uv_scale;
+      pt->uv_fac += mmd->uv_offset;
+    }
+  }
+
+}
+
+static void bakeModifier(struct Main *UNUSED(bmain),
+                         Depsgraph *depsgraph,
+                         GpencilModifierData *md,
+                         Object *ob)
+{
+  bGPdata *gpd = ob->data;
+
+  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);
+      }
+    }
+  }
+}
+
+GpencilModifierTypeInfo modifierType_Gpencil_Texture = {
+    /* name */ "Texture",
+    /* structName */ "TextureGpencilModifierData",
+    /* structSize */ sizeof(TextureGpencilModifierData),
+    /* type */ eGpencilModifierTypeType_Gpencil,
+    /* flags */ eGpencilModifierTypeFlag_SupportsEditmode,
+
+    /* copyData */ copyData,
+
+    /* deformStroke */ deformStroke,
+    /* generateStrokes */ NULL,
+    /* bakeModifier */ bakeModifier,
+    /* remapTime */ NULL,
+
+    /* initData */ initData,
+    /* freeData */ NULL,
+    /* isDisabled */ NULL,
+    /* updateDepsgraph */ NULL,
+    /* dependsOnTime */ NULL,
+    /* foreachObjectLink */ NULL,
+    /* foreachIDLink */ NULL,
+    /* foreachTexLink */ NULL,
+};
diff --git a/source/blender/makesdna/DNA_gpencil_modifier_types.h b/source/blender/makesdna/DNA_gpencil_modifier_types.h
index c3425826d36..1265ce0983c 100644
--- a/source/blender/makesdna/DNA_gpencil_modifier_types.h
+++ b/source/blender/makesdna/DNA_gpencil_modifier_types.h
@@ -47,6 +47,7 @@ typedef enum GpencilModifierType {
   eGpencilModifierType_Armature = 15,
   eGpencilModifierType_Time = 16,
   eGpencilModifierType_Multiply = 17,
+  eGpencilModifierType_Texture = 18,
   NUM_GREASEPENCIL_MODIFIER_TYPES,
 } GpencilModifierType;
 
@@ -713,4 +714,50 @@ typedef enum eTintGpencil_Flag {
   GP_TINT_CUSTOM_CURVE = (1 << 6),
 } eTintGpencil_Flag;
 
+typedef struct TextureGpencilModifierData {
+  GpencilModifierData modifier;
+  /** Layer name. */
+  char layername[64];
+  /** Material name. */
+  char materialname[64];
+  /** Optional vertexgroup name, MAX_VGROUP_NAME. */
+  char vgname[64];
+  /** Custom index for passes. */
+  int pass_index;
+  /** Flags. */
+  int flag;
+  /** Offset value to add to uv_fac. */
+  float uv_offset;
+  float uv_scale;
+  float fill_rotation;
+  float fill_offset[2];
+  float fill_scale;
+  /** Custom index for passes. */
+  int layer_pass;
+  /** Texture fit options. */
+  short fit_method;
+  short mode;
+} TextureGpencilModifierData;
+
+typedef enum eTextureGpencil_Flag {
+  GP_TEX_INVERT_LAYER = (1 << 0),
+  GP_TEX_INVERT_PASS = (1 << 1),
+  GP_TEX_INVERT_VGROUP = (1 << 2),
+  GP_TEX_INVERT_LAYERPASS = (1 <<

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list