Blender  V2.93
MOD_gpencilthick.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 "DNA_defaults.h"
32 #include "DNA_gpencil_types.h"
33 #include "DNA_meshdata_types.h"
34 #include "DNA_object_types.h"
35 #include "DNA_screen_types.h"
36 
37 #include "BKE_colortools.h"
38 #include "BKE_context.h"
39 #include "BKE_deform.h"
40 #include "BKE_gpencil_modifier.h"
41 #include "BKE_lib_query.h"
42 #include "BKE_modifier.h"
43 #include "BKE_screen.h"
44 
45 #include "DEG_depsgraph.h"
46 
47 #include "UI_interface.h"
48 #include "UI_resources.h"
49 
50 #include "RNA_access.h"
51 
53 #include "MOD_gpencil_ui_common.h"
54 #include "MOD_gpencil_util.h"
55 
56 static void initData(GpencilModifierData *md)
57 {
59 
60  BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(gpmd, modifier));
61 
63 
64  gpmd->curve_thickness = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
66 }
67 
68 static void freeData(GpencilModifierData *md)
69 {
71 
72  if (gpmd->curve_thickness) {
74  }
75 }
76 
77 static void copyData(const GpencilModifierData *md, GpencilModifierData *target)
78 {
81 
82  if (tgmd->curve_thickness != NULL) {
84  tgmd->curve_thickness = NULL;
85  }
86 
88 
90 }
91 
92 /* change stroke thickness */
95  Object *ob,
96  bGPDlayer *gpl,
97  bGPDframe *UNUSED(gpf),
98  bGPDstroke *gps)
99 {
101  const int def_nr = BKE_object_defgroup_name_index(ob, mmd->vgname);
102 
104  mmd->layername,
105  mmd->material,
106  mmd->pass_index,
107  mmd->layer_pass,
108  1,
109  gpl,
110  gps,
112  mmd->flag & GP_THICK_INVERT_PASS,
114  mmd->flag & GP_THICK_INVERT_MATERIAL)) {
115  return;
116  }
117 
118  float stroke_thickness_inv = 1.0f / max_ii(gps->thickness, 1);
119 
120  for (int i = 0; i < gps->totpoints; i++) {
121  bGPDspoint *pt = &gps->points[i];
122  MDeformVert *dvert = gps->dvert != NULL ? &gps->dvert[i] : NULL;
123  /* Verify point is part of vertex group. */
124  float weight = get_modifier_point_weight(
125  dvert, (mmd->flag & GP_THICK_INVERT_VGROUP) != 0, def_nr);
126  if (weight < 0.0f) {
127  continue;
128  }
129 
130  float curvef = 1.0f;
131  if ((mmd->flag & GP_THICK_CUSTOM_CURVE) && (mmd->curve_thickness)) {
132  /* Normalize value to evaluate curve. */
133  float value = (float)i / (gps->totpoints - 1);
134  curvef = BKE_curvemapping_evaluateF(mmd->curve_thickness, 0, value);
135  }
136 
137  float target;
138  if (mmd->flag & GP_THICK_NORMALIZE) {
139  target = mmd->thickness * stroke_thickness_inv;
140  target *= curvef;
141  }
142  else {
143  target = pt->pressure * mmd->thickness_fac;
144  weight *= curvef;
145  }
146 
147  pt->pressure = interpf(target, pt->pressure, weight);
148 
149  CLAMP_MIN(pt->pressure, 0.0f);
150  }
151 }
152 
153 static void bakeModifier(struct Main *UNUSED(bmain),
156  Object *ob)
157 {
158  bGPdata *gpd = ob->data;
159 
160  LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
161  LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
162  LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
163  deformStroke(md, depsgraph, ob, gpl, gpf, gps);
164  }
165  }
166  }
167 }
168 
169 static void foreachIDLink(GpencilModifierData *md, Object *ob, IDWalkFunc walk, void *userData)
170 {
172 
173  walk(userData, ob, (ID **)&mmd->material, IDWALK_CB_USER);
174 }
175 
176 static void panel_draw(const bContext *UNUSED(C), Panel *panel)
177 {
178  uiLayout *layout = panel->layout;
179 
181 
182  uiLayoutSetPropSep(layout, true);
183 
184  uiItemR(layout, ptr, "normalize_thickness", 0, NULL, ICON_NONE);
185 
186  if (RNA_boolean_get(ptr, "normalize_thickness")) {
187  uiItemR(layout, ptr, "thickness", 0, NULL, ICON_NONE);
188  }
189  else {
190  uiItemR(layout, ptr, "thickness_factor", 0, NULL, ICON_NONE);
191  }
192 
194 }
195 
196 static void mask_panel_draw(const bContext *UNUSED(C), Panel *panel)
197 {
198  gpencil_modifier_masking_panel_draw(panel, true, true);
199 }
200 
201 static void panelRegister(ARegionType *region_type)
202 {
204  region_type, eGpencilModifierType_Thick, panel_draw);
206  region_type, "mask", "Influence", NULL, mask_panel_draw, panel_type);
208  "curve",
209  "",
212  mask_panel_type);
213 }
214 
216  /* name */ "Thickness",
217  /* structName */ "ThickGpencilModifierData",
218  /* structSize */ sizeof(ThickGpencilModifierData),
221 
222  /* copyData */ copyData,
223 
224  /* deformStroke */ deformStroke,
225  /* generateStrokes */ NULL,
226  /* bakeModifier */ bakeModifier,
227  /* remapTime */ NULL,
228 
229  /* initData */ initData,
230  /* freeData */ freeData,
231  /* isDisabled */ NULL,
232  /* updateDepsgraph */ NULL,
233  /* dependsOnTime */ NULL,
234  /* foreachIDLink */ foreachIDLink,
235  /* foreachTexLink */ NULL,
236  /* panelRegister */ panelRegister,
237 };
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)
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 int max_ii(int a, int b)
MINLINE float interpf(float a, float b, float t)
#define UNUSED(x)
#define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member)
#define MEMCPY_STRUCT_AFTER(struct_dst, struct_src, member)
#define CLAMP_MIN(a, b)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
#define DNA_struct_default_get(struct_name)
Definition: DNA_defaults.h:44
@ GP_THICK_INVERT_VGROUP
@ GP_THICK_INVERT_MATERIAL
@ GP_THICK_INVERT_LAYERPASS
struct ThickGpencilModifierData ThickGpencilModifierData
@ eGpencilModifierType_Thick
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)
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)
static void copyData(const GpencilModifierData *md, GpencilModifierData *target)
static void panel_draw(const bContext *UNUSED(C), Panel *panel)
GpencilModifierTypeInfo modifierType_Gpencil_Thick
static void panelRegister(ARegionType *region_type)
static void initData(GpencilModifierData *md)
#define C
Definition: RandGen.cpp:39
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
const Depsgraph * depsgraph
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6261
Definition: DNA_ID.h:273
Definition: BKE_main.h:116
void * data
struct uiLayout * layout
struct CurveMapping * curve_thickness
ListBase frames
bGPDspoint * points
struct MDeformVert * dvert
ListBase layers
PointerRNA * ptr
Definition: wm_files.c:3157