Blender  V2.93
MOD_gpencilsmooth.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 #include <string.h> /* For #MEMCPY_STRUCT_AFTER. */
26 
27 #include "BLI_listbase.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_colortools.h"
40 #include "BKE_context.h"
41 #include "BKE_deform.h"
42 #include "BKE_gpencil_geom.h"
43 #include "BKE_gpencil_modifier.h"
44 #include "BKE_lib_query.h"
45 #include "BKE_modifier.h"
46 #include "BKE_screen.h"
47 
48 #include "DEG_depsgraph.h"
49 
50 #include "UI_interface.h"
51 #include "UI_resources.h"
52 
54 #include "MOD_gpencil_ui_common.h"
55 #include "MOD_gpencil_util.h"
56 
57 static void initData(GpencilModifierData *md)
58 {
60 
61  BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(gpmd, modifier));
62 
64 
65  gpmd->curve_intensity = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
67 }
68 
69 static void copyData(const GpencilModifierData *md, GpencilModifierData *target)
70 {
73 
74  if (tgmd->curve_intensity != NULL) {
76  tgmd->curve_intensity = NULL;
77  }
78 
80 
82 }
83 
89  Object *ob,
90  bGPDlayer *gpl,
91  bGPDframe *UNUSED(gpf),
92  bGPDstroke *gps)
93 {
95  const int def_nr = BKE_object_defgroup_name_index(ob, mmd->vgname);
96  const bool use_curve = (mmd->flag & GP_SMOOTH_CUSTOM_CURVE) != 0 && mmd->curve_intensity;
97 
99  mmd->layername,
100  mmd->material,
101  mmd->pass_index,
102  mmd->layer_pass,
103  3,
104  gpl,
105  gps,
110  return;
111  }
112 
113  /* smooth stroke */
114  if (mmd->factor > 0.0f) {
115  for (int r = 0; r < mmd->step; r++) {
116  for (int i = 0; i < gps->totpoints; i++) {
117  MDeformVert *dvert = gps->dvert != NULL ? &gps->dvert[i] : NULL;
118 
119  /* verify vertex group */
120  float weight = get_modifier_point_weight(
121  dvert, (mmd->flag & GP_SMOOTH_INVERT_VGROUP) != 0, def_nr);
122  if (weight < 0.0f) {
123  continue;
124  }
125 
126  /* Custom curve to modulate value. */
127  if (use_curve) {
128  float value = (float)i / (gps->totpoints - 1);
129  weight *= BKE_curvemapping_evaluateF(mmd->curve_intensity, 0, value);
130  }
131 
132  const float val = mmd->factor * weight;
133  /* perform smoothing */
134  if (mmd->flag & GP_SMOOTH_MOD_LOCATION) {
135  BKE_gpencil_stroke_smooth(gps, i, val);
136  }
137  if (mmd->flag & GP_SMOOTH_MOD_STRENGTH) {
139  }
140  if ((mmd->flag & GP_SMOOTH_MOD_THICKNESS) && (val > 0.0f)) {
141  /* thickness need to repeat process several times */
142  for (int r2 = 0; r2 < r * 10; r2++) {
144  }
145  }
146  if (mmd->flag & GP_SMOOTH_MOD_UV) {
147  BKE_gpencil_stroke_smooth_uv(gps, i, val);
148  }
149  }
150  }
151  }
152 }
153 
154 static void bakeModifier(struct Main *UNUSED(bmain),
157  Object *ob)
158 {
159  bGPdata *gpd = ob->data;
160 
161  LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
162  LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
163  LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
164  deformStroke(md, depsgraph, ob, gpl, gpf, gps);
165  }
166  }
167  }
168 }
169 
171 {
173 
174  if (gpmd->curve_intensity) {
176  }
177 }
178 
179 static void foreachIDLink(GpencilModifierData *md, Object *ob, IDWalkFunc walk, void *userData)
180 {
182 
183  walk(userData, ob, (ID **)&mmd->material, IDWALK_CB_USER);
184 }
185 
186 static void panel_draw(const bContext *UNUSED(C), Panel *panel)
187 {
188  uiLayout *row;
189  uiLayout *layout = panel->layout;
190 
192 
193  row = uiLayoutRow(layout, true);
194  uiItemR(row, ptr, "use_edit_position", UI_ITEM_R_TOGGLE, IFACE_("Position"), ICON_NONE);
195  uiItemR(row, ptr, "use_edit_strength", UI_ITEM_R_TOGGLE, IFACE_("Strength"), ICON_NONE);
196  uiItemR(row, ptr, "use_edit_thickness", UI_ITEM_R_TOGGLE, IFACE_("Thickness"), ICON_NONE);
197  uiItemR(row, ptr, "use_edit_uv", UI_ITEM_R_TOGGLE, IFACE_("UV"), ICON_NONE);
198 
199  uiLayoutSetPropSep(layout, true);
200 
201  uiItemR(layout, ptr, "factor", 0, NULL, ICON_NONE);
202  uiItemR(layout, ptr, "step", 0, IFACE_("Repeat"), ICON_NONE);
203 
205 }
206 
207 static void mask_panel_draw(const bContext *UNUSED(C), Panel *panel)
208 {
209  gpencil_modifier_masking_panel_draw(panel, true, true);
210 }
211 
212 static void panelRegister(ARegionType *region_type)
213 {
217  region_type, "mask", "Influence", NULL, mask_panel_draw, panel_type);
219  "curve",
220  "",
223  mask_panel_type);
224 }
225 
227  /* name */ "Smooth",
228  /* structName */ "SmoothGpencilModifierData",
229  /* structSize */ sizeof(SmoothGpencilModifierData),
232 
233  /* copyData */ copyData,
234 
235  /* deformStroke */ deformStroke,
236  /* generateStrokes */ NULL,
237  /* bakeModifier */ bakeModifier,
238  /* remapTime */ NULL,
239 
240  /* initData */ initData,
241  /* freeData */ freeData,
242  /* isDisabled */ NULL,
243  /* updateDepsgraph */ NULL,
244  /* dependsOnTime */ NULL,
245  /* foreachIDLink */ foreachIDLink,
246  /* foreachTexLink */ NULL,
247  /* panelRegister */ panelRegister,
248 };
typedef float(TangentPoint)[2]
void BKE_curvemapping_init(struct CurveMapping *cumap)
Definition: colortools.c:1200
struct CurveMapping * BKE_curvemapping_copy(const struct CurveMapping *cumap)
float BKE_curvemapping_evaluateF(const struct CurveMapping *cumap, int cur, float value)
void BKE_curvemapping_free(struct CurveMapping *cumap)
Definition: colortools.c:119
struct CurveMapping * BKE_curvemapping_add(int tot, float minx, float miny, float maxx, float maxy)
Definition: colortools.c:88
support for deformation groups and hooks.
int BKE_object_defgroup_name_index(const struct Object *ob, const char *name)
bool BKE_gpencil_stroke_smooth_strength(struct bGPDstroke *gps, int point_index, float influence)
Definition: gpencil_geom.c:841
bool BKE_gpencil_stroke_smooth_thickness(struct bGPDstroke *gps, int point_index, float influence)
Definition: gpencil_geom.c:905
bool BKE_gpencil_stroke_smooth_uv(struct bGPDstroke *gps, int point_index, float influence)
Definition: gpencil_geom.c:968
bool BKE_gpencil_stroke_smooth(struct bGPDstroke *gps, int i, float inf)
Definition: gpencil_geom.c:778
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
#define UNUSED(x)
#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 SmoothGpencilModifierData SmoothGpencilModifierData
@ GP_SMOOTH_INVERT_LAYERPASS
@ GP_SMOOTH_MOD_LOCATION
@ GP_SMOOTH_MOD_STRENGTH
@ GP_SMOOTH_MOD_THICKNESS
@ GP_SMOOTH_INVERT_LAYER
@ GP_SMOOTH_CUSTOM_CURVE
@ GP_SMOOTH_INVERT_MATERIAL
@ GP_SMOOTH_INVERT_VGROUP
@ eGpencilModifierType_Smooth
Object is a sort of wrapper for general info.
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
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)
void gpencil_modifier_curve_header_draw(const bContext *UNUSED(C), Panel *panel)
void gpencil_modifier_curve_panel_draw(const bContext *UNUSED(C), Panel *panel)
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 freeData(GpencilModifierData *md)
static void bakeModifier(struct Main *UNUSED(bmain), Depsgraph *depsgraph, GpencilModifierData *md, Object *ob)
static void mask_panel_draw(const bContext *UNUSED(C), Panel *panel)
static void foreachIDLink(GpencilModifierData *md, Object *ob, IDWalkFunc walk, void *userData)
GpencilModifierTypeInfo modifierType_Gpencil_Smooth
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
@ UI_ITEM_R_TOGGLE
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
uiLayout * uiLayoutRow(uiLayout *layout, bool align)
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
const Depsgraph * depsgraph
Definition: DNA_ID.h:273
Definition: BKE_main.h:116
void * data
struct uiLayout * layout
ListBase frames
struct MDeformVert * dvert
ListBase layers
PointerRNA * ptr
Definition: wm_files.c:3157