Blender  V2.93
MOD_gpencilsimplify.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 "DNA_defaults.h"
32 #include "DNA_gpencil_types.h"
33 #include "DNA_object_types.h"
34 #include "DNA_screen_types.h"
35 #include "DNA_vec_types.h"
36 
37 #include "BKE_context.h"
38 #include "BKE_gpencil_geom.h"
39 #include "BKE_gpencil_modifier.h"
40 #include "BKE_lib_query.h"
41 #include "BKE_modifier.h"
42 #include "BKE_screen.h"
43 
44 #include "DEG_depsgraph.h"
45 
46 #include "UI_interface.h"
47 #include "UI_resources.h"
48 
49 #include "RNA_access.h"
50 
52 #include "MOD_gpencil_ui_common.h"
53 #include "MOD_gpencil_util.h"
54 
55 static void initData(GpencilModifierData *md)
56 {
58 
59  BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(gpmd, modifier));
60 
62 }
63 
64 static void copyData(const GpencilModifierData *md, GpencilModifierData *target)
65 {
67 }
68 
71  Object *ob,
72  bGPDlayer *gpl,
73  bGPDframe *gpf,
74  bGPDstroke *gps)
75 {
77 
79  mmd->layername,
80  mmd->material,
81  mmd->pass_index,
82  mmd->layer_pass,
83  mmd->mode == GP_SIMPLIFY_SAMPLE ? 2 : 4,
84  gpl,
85  gps,
90  return;
91  }
92  bGPdata *gpd = ob->data;
93  /* Select simplification mode. */
94  switch (mmd->mode) {
95  case GP_SIMPLIFY_FIXED: {
96  for (int i = 0; i < mmd->step; i++) {
98  }
99  break;
100  }
101  case GP_SIMPLIFY_ADAPTIVE: {
102  /* simplify stroke using Ramer-Douglas-Peucker algorithm */
104  break;
105  }
106  case GP_SIMPLIFY_SAMPLE: {
107  BKE_gpencil_stroke_sample(gpd, gps, mmd->length, false);
108  break;
109  }
110  case GP_SIMPLIFY_MERGE: {
111  BKE_gpencil_stroke_merge_distance(gpd, gpf, gps, mmd->distance, true);
112  break;
113  }
114  default:
115  break;
116  }
117 }
118 
119 static void bakeModifier(struct Main *UNUSED(bmain),
122  Object *ob)
123 {
124  bGPdata *gpd = ob->data;
125 
126  LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
127  LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
128  LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
129  deformStroke(md, depsgraph, ob, gpl, gpf, gps);
130  }
131  }
132  }
133 }
134 
135 static void foreachIDLink(GpencilModifierData *md, Object *ob, IDWalkFunc walk, void *userData)
136 {
138 
139  walk(userData, ob, (ID **)&mmd->material, IDWALK_CB_USER);
140 }
141 
142 static void panel_draw(const bContext *UNUSED(C), Panel *panel)
143 {
144  uiLayout *layout = panel->layout;
145 
147 
148  int mode = RNA_enum_get(ptr, "mode");
149 
150  uiLayoutSetPropSep(layout, true);
151 
152  uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
153 
154  if (mode == GP_SIMPLIFY_FIXED) {
155  uiItemR(layout, ptr, "step", 0, NULL, ICON_NONE);
156  }
157  else if (mode == GP_SIMPLIFY_ADAPTIVE) {
158  uiItemR(layout, ptr, "factor", 0, NULL, ICON_NONE);
159  }
160  else if (mode == GP_SIMPLIFY_SAMPLE) {
161  uiItemR(layout, ptr, "length", 0, NULL, ICON_NONE);
162  }
163  else if (mode == GP_SIMPLIFY_MERGE) {
164  uiItemR(layout, ptr, "distance", 0, NULL, ICON_NONE);
165  }
166 
168 }
169 
170 static void mask_panel_draw(const bContext *UNUSED(C), Panel *panel)
171 {
172  gpencil_modifier_masking_panel_draw(panel, true, false);
173 }
174 
175 static void panelRegister(ARegionType *region_type)
176 {
180  region_type, "mask", "Influence", NULL, mask_panel_draw, panel_type);
181 }
182 
184  /* name */ "Simplify",
185  /* structName */ "SimplifyGpencilModifierData",
186  /* structSize */ sizeof(SimplifyGpencilModifierData),
189 
190  /* copyData */ copyData,
191 
192  /* deformStroke */ deformStroke,
193  /* generateStrokes */ NULL,
194  /* bakeModifier */ bakeModifier,
195  /* remapTime */ NULL,
196 
197  /* initData */ initData,
198  /* freeData */ NULL,
199  /* isDisabled */ NULL,
200  /* updateDepsgraph */ NULL,
201  /* dependsOnTime */ NULL,
202  /* foreachIDLink */ foreachIDLink,
203  /* foreachTexLink */ NULL,
204  /* panelRegister */ panelRegister,
205 };
void BKE_gpencil_stroke_merge_distance(struct bGPdata *gpd, struct bGPDframe *gpf, struct bGPDstroke *gps, const float threshold, const bool use_unselected)
void BKE_gpencil_stroke_simplify_adaptive(struct bGPdata *gpd, struct bGPDstroke *gps, float epsilon)
bool BKE_gpencil_stroke_sample(struct bGPdata *gpd, struct bGPDstroke *gps, const float dist, const bool select)
Definition: gpencil_geom.c:429
void BKE_gpencil_stroke_simplify_fixed(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
#define UNUSED(x)
#define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member)
#define MEMCPY_STRUCT_AFTER(struct_dst, struct_src, member)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
#define DNA_struct_default_get(struct_name)
Definition: DNA_defaults.h:44
struct SimplifyGpencilModifierData SimplifyGpencilModifierData
@ GP_SIMPLIFY_INVERT_LAYER
@ GP_SIMPLIFY_INVERT_PASS
@ GP_SIMPLIFY_INVERT_MATERIAL
@ GP_SIMPLIFY_INVERT_LAYERPASS
@ eGpencilModifierType_Simplify
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)
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 bakeModifier(struct Main *UNUSED(bmain), Depsgraph *depsgraph, GpencilModifierData *md, Object *ob)
GpencilModifierTypeInfo modifierType_Gpencil_Simplify
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 deformStroke(GpencilModifierData *md, Depsgraph *UNUSED(depsgraph), Object *ob, bGPDlayer *gpl, bGPDframe *gpf, bGPDstroke *gps)
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
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 layers
PointerRNA * ptr
Definition: wm_files.c:3157