Blender  V2.93
MOD_gpenciltexture.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2017, Blender Foundation
17  * This is a new part of Blender
18  */
19 
24 #include <stdio.h>
25 
26 #include "BLI_listbase.h"
27 #include "BLI_math.h"
28 #include "BLI_utildefines.h"
29 
30 #include "BLT_translation.h"
31 
32 #include "DNA_defaults.h"
34 #include "DNA_gpencil_types.h"
35 #include "DNA_meshdata_types.h"
36 #include "DNA_object_types.h"
37 #include "DNA_screen_types.h"
38 
39 #include "BKE_context.h"
40 #include "BKE_deform.h"
41 #include "BKE_gpencil_geom.h"
42 #include "BKE_gpencil_modifier.h"
43 #include "BKE_lib_query.h"
44 #include "BKE_modifier.h"
45 #include "BKE_screen.h"
46 
47 #include "DEG_depsgraph.h"
48 
49 #include "UI_interface.h"
50 #include "UI_resources.h"
51 
52 #include "RNA_access.h"
53 
55 #include "MOD_gpencil_ui_common.h"
56 #include "MOD_gpencil_util.h"
57 
58 static void initData(GpencilModifierData *md)
59 {
61 
62  BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(gpmd, modifier));
63 
65 }
66 
67 static void copyData(const GpencilModifierData *md, GpencilModifierData *target)
68 {
70 }
71 
72 /* change stroke uv texture values */
75  Object *ob,
76  bGPDlayer *gpl,
77  bGPDframe *UNUSED(gpf),
78  bGPDstroke *gps)
79 {
81  const int def_nr = BKE_object_defgroup_name_index(ob, mmd->vgname);
82  bGPdata *gpd = ob->data;
83 
85  mmd->layername,
86  mmd->material,
87  mmd->pass_index,
88  mmd->layer_pass,
89  1,
90  gpl,
91  gps,
93  mmd->flag & GP_TEX_INVERT_PASS,
95  mmd->flag & GP_TEX_INVERT_MATERIAL)) {
96  return;
97  }
98  if (ELEM(mmd->mode, FILL, STROKE_AND_FILL)) {
99  gps->uv_rotation += mmd->fill_rotation;
100  gps->uv_translation[0] += mmd->fill_offset[0];
101  gps->uv_translation[1] += mmd->fill_offset[1];
102  gps->uv_scale *= mmd->fill_scale;
104  }
105 
106  if (ELEM(mmd->mode, STROKE, STROKE_AND_FILL)) {
107  float totlen = 1.0f;
108  if (mmd->fit_method == GP_TEX_FIT_STROKE) {
109  totlen = 0.0f;
110  for (int i = 1; i < gps->totpoints; i++) {
111  totlen += len_v3v3(&gps->points[i - 1].x, &gps->points[i].x);
112  }
113  }
114 
115  for (int i = 0; i < gps->totpoints; i++) {
116  bGPDspoint *pt = &gps->points[i];
117  MDeformVert *dvert = gps->dvert != NULL ? &gps->dvert[i] : NULL;
118  /* Verify point is part of vertex group. */
119  float weight = get_modifier_point_weight(
120  dvert, (mmd->flag & GP_TEX_INVERT_VGROUP) != 0, def_nr);
121  if (weight < 0.0f) {
122  continue;
123  }
124 
125  pt->uv_fac /= totlen;
126  pt->uv_fac *= mmd->uv_scale;
127  pt->uv_fac += mmd->uv_offset;
128  pt->uv_rot += mmd->alignment_rotation;
129  }
130  }
131 }
132 
133 static void bakeModifier(struct Main *UNUSED(bmain),
136  Object *ob)
137 {
138  bGPdata *gpd = ob->data;
139 
140  LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
141  LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
142  LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
143  deformStroke(md, depsgraph, ob, gpl, gpf, gps);
144  }
145  }
146  }
147 }
148 
149 static void foreachIDLink(GpencilModifierData *md, Object *ob, IDWalkFunc walk, void *userData)
150 {
152 
153  walk(userData, ob, (ID **)&mmd->material, IDWALK_CB_USER);
154 }
155 
156 static void panel_draw(const bContext *UNUSED(C), Panel *panel)
157 {
158  uiLayout *col;
159  uiLayout *layout = panel->layout;
160 
162 
163  int mode = RNA_enum_get(ptr, "mode");
164 
165  uiLayoutSetPropSep(layout, true);
166 
167  uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
168 
169  if (ELEM(mode, STROKE, STROKE_AND_FILL)) {
170  col = uiLayoutColumn(layout, false);
171  uiItemR(col, ptr, "fit_method", 0, IFACE_("Stroke Fit Method"), ICON_NONE);
172  uiItemR(col, ptr, "uv_offset", 0, NULL, ICON_NONE);
173  uiItemR(col, ptr, "alignment_rotation", 0, NULL, ICON_NONE);
174  uiItemR(col, ptr, "uv_scale", 0, IFACE_("Scale"), ICON_NONE);
175  }
176 
177  if (mode == STROKE_AND_FILL) {
178  uiItemS(layout);
179  }
180 
181  if (ELEM(mode, FILL, STROKE_AND_FILL)) {
182  col = uiLayoutColumn(layout, false);
183  uiItemR(col, ptr, "fill_rotation", 0, NULL, ICON_NONE);
184  uiItemR(col, ptr, "fill_offset", 0, IFACE_("Offset"), ICON_NONE);
185  uiItemR(col, ptr, "fill_scale", 0, IFACE_("Scale"), ICON_NONE);
186  }
187 
189 }
190 
191 static void mask_panel_draw(const bContext *UNUSED(C), Panel *panel)
192 {
193  gpencil_modifier_masking_panel_draw(panel, true, true);
194 }
195 
196 static void panelRegister(ARegionType *region_type)
197 {
201  region_type, "mask", "Influence", NULL, mask_panel_draw, panel_type);
202 }
203 
205  /* name */ "TextureMapping",
206  /* structName */ "TextureGpencilModifierData",
207  /* structSize */ sizeof(TextureGpencilModifierData),
210 
211  /* copyData */ copyData,
212 
213  /* deformStroke */ deformStroke,
214  /* generateStrokes */ NULL,
215  /* bakeModifier */ bakeModifier,
216  /* remapTime */ NULL,
217 
218  /* initData */ initData,
219  /* freeData */ NULL,
220  /* isDisabled */ NULL,
221  /* updateDepsgraph */ NULL,
222  /* dependsOnTime */ NULL,
223  /* foreachIDLink */ foreachIDLink,
224  /* foreachTexLink */ NULL,
225  /* panelRegister */ panelRegister,
226 };
support for deformation groups and hooks.
int BKE_object_defgroup_name_index(const struct Object *ob, const char *name)
void BKE_gpencil_stroke_geometry_update(struct bGPdata *gpd, struct bGPDstroke *gps)
void BKE_gpencil_modifier_copydata_generic(const struct GpencilModifierData *md_src, struct GpencilModifierData *md_dst)
@ eGpencilModifierTypeFlag_SupportsEditmode
@ eGpencilModifierTypeType_Gpencil
@ IDWALK_CB_USER
Definition: BKE_lib_query.h:87
void(* IDWalkFunc)(void *userData, struct Object *ob, struct ID **idpoin, int cb_flag)
Definition: BKE_modifier.h:120
#define BLI_assert(a)
Definition: BLI_assert.h:58
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:172
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
#define UNUSED(x)
#define ELEM(...)
#define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member)
#define MEMCPY_STRUCT_AFTER(struct_dst, struct_src, member)
#define IFACE_(msgid)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
#define DNA_struct_default_get(struct_name)
Definition: DNA_defaults.h:44
struct TextureGpencilModifierData TextureGpencilModifierData
@ GP_TEX_INVERT_LAYERPASS
@ GP_TEX_INVERT_MATERIAL
@ eGpencilModifierType_Texture
Object is a sort of wrapper for general info.
PointerRNA * gpencil_modifier_panel_get_property_pointers(Panel *panel, PointerRNA *r_ob_ptr)
void gpencil_modifier_masking_panel_draw(Panel *panel, bool use_material, bool use_vertex)
void gpencil_modifier_panel_end(uiLayout *layout, PointerRNA *ptr)
PanelType * gpencil_modifier_subpanel_register(ARegionType *region_type, const char *name, const char *label, PanelDrawFn draw_header, PanelDrawFn draw, PanelType *parent)
PanelType * gpencil_modifier_panel_register(ARegionType *region_type, GpencilModifierType type, PanelDrawFn draw)
float get_modifier_point_weight(MDeformVert *dvert, bool inverse, int def_nr)
bool is_stroke_affected_by_modifier(Object *ob, char *mlayername, Material *material, const int mpassindex, const int gpl_passindex, const int minpoints, bGPDlayer *gpl, bGPDstroke *gps, const bool inv1, const bool inv2, const bool inv3, const bool inv4)
static void deformStroke(GpencilModifierData *md, Depsgraph *UNUSED(depsgraph), Object *ob, bGPDlayer *gpl, bGPDframe *UNUSED(gpf), bGPDstroke *gps)
static void bakeModifier(struct Main *UNUSED(bmain), Depsgraph *depsgraph, GpencilModifierData *md, Object *ob)
GpencilModifierTypeInfo modifierType_Gpencil_Texture
static void mask_panel_draw(const bContext *UNUSED(C), Panel *panel)
static void foreachIDLink(GpencilModifierData *md, Object *ob, IDWalkFunc walk, void *userData)
static void copyData(const GpencilModifierData *md, GpencilModifierData *target)
static void panel_draw(const bContext *UNUSED(C), Panel *panel)
static void panelRegister(ARegionType *region_type)
static void initData(GpencilModifierData *md)
#define C
Definition: RandGen.cpp:39
uiLayout * uiLayoutColumn(uiLayout *layout, bool align)
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
void uiItemS(uiLayout *layout)
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
const Depsgraph * depsgraph
uint col
int RNA_enum_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6402
Definition: DNA_ID.h:273
Definition: BKE_main.h:116
void * data
struct uiLayout * layout
ListBase frames
bGPDspoint * points
float uv_translation[2]
struct MDeformVert * dvert
ListBase layers
PointerRNA * ptr
Definition: wm_files.c:3157