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:
authorCody Winchester <CodyWinch>2020-04-19 18:25:36 +0300
committerAntonio Vazquez <blendergit@gmail.com>2020-04-19 18:29:35 +0300
commita39a6517af6603fcb16728daed88b642c88aa6eb (patch)
treeccb82a3966c6d7bef20acf618f5f4ff345d94e77 /source/blender/gpencil_modifiers
parenta0a59972e7e526ce3c49878f4607acbae8508e7a (diff)
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
Diffstat (limited to 'source/blender/gpencil_modifiers')
-rw-r--r--source/blender/gpencil_modifiers/CMakeLists.txt1
-rw-r--r--source/blender/gpencil_modifiers/MOD_gpencil_modifiertypes.h1
-rw-r--r--source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c1
-rw-r--r--source/blender/gpencil_modifiers/intern/MOD_gpenciltexture.c167
4 files changed, 170 insertions, 0 deletions
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,
+};