Blender  V2.93
MOD_gpencilsubdiv.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_object_types.h"
36 #include "DNA_screen_types.h"
37 
38 #include "BKE_context.h"
39 #include "BKE_gpencil_geom.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 
51 #include "MOD_gpencil_ui_common.h"
52 #include "MOD_gpencil_util.h"
53 
54 static void initData(GpencilModifierData *md)
55 {
57 
58  BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(gpmd, modifier));
59 
61 }
62 
63 static void copyData(const GpencilModifierData *md, GpencilModifierData *target)
64 {
66 }
67 
68 /* subdivide stroke to get more control points */
71  Object *ob,
72  bGPDlayer *gpl,
73  bGPDframe *UNUSED(gpf),
74  bGPDstroke *gps)
75 {
77  bGPdata *gpd = ob->data;
78 
79  /* It makes sense when adding points to a straight line */
80  /* e.g. for creating thickness variation in later modifiers. */
81  const int minimum_vert = (mmd->flag & GP_SUBDIV_SIMPLE) ? 2 : 3;
82 
84  mmd->layername,
85  mmd->material,
86  mmd->pass_index,
87  mmd->layer_pass,
88  minimum_vert,
89  gpl,
90  gps,
95  return;
96  }
97 
98  BKE_gpencil_stroke_subdivide(gpd, gps, mmd->level, mmd->type);
99 
100  /* If the stroke is cyclic, must generate the closing geometry. */
101  if (gps->flag & GP_STROKE_CYCLIC) {
103  }
104 }
105 
106 static void bakeModifier(struct Main *UNUSED(bmain),
109  Object *ob)
110 {
111  bGPdata *gpd = ob->data;
112 
113  LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
114  LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
115  LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
116  deformStroke(md, depsgraph, ob, gpl, gpf, gps);
117  }
118  }
119  }
120 }
121 
122 static void foreachIDLink(GpencilModifierData *md, Object *ob, IDWalkFunc walk, void *userData)
123 {
125 
126  walk(userData, ob, (ID **)&mmd->material, IDWALK_CB_USER);
127 }
128 
129 static void panel_draw(const bContext *UNUSED(C), Panel *panel)
130 {
131  uiLayout *layout = panel->layout;
132 
134 
135  uiLayoutSetPropSep(layout, true);
136 
137  uiItemR(layout, ptr, "subdivision_type", 0, NULL, ICON_NONE);
138  uiItemR(layout, ptr, "level", 0, IFACE_("Subdivisions"), ICON_NONE);
139 
141 }
142 
143 static void mask_panel_draw(const bContext *UNUSED(C), Panel *panel)
144 {
145  gpencil_modifier_masking_panel_draw(panel, true, false);
146 }
147 
148 static void panelRegister(ARegionType *region_type)
149 {
153  region_type, "mask", "Influence", NULL, mask_panel_draw, panel_type);
154 }
155 
157  /* name */ "Subdivide",
158  /* structName */ "SubdivGpencilModifierData",
159  /* structSize */ sizeof(SubdivGpencilModifierData),
162 
163  /* copyData */ copyData,
164 
165  /* deformStroke */ deformStroke,
166  /* generateStrokes */ NULL,
167  /* bakeModifier */ bakeModifier,
168  /* remapTime */ NULL,
169 
170  /* initData */ initData,
171  /* freeData */ NULL,
172  /* isDisabled */ NULL,
173  /* updateDepsgraph */ NULL,
174  /* dependsOnTime */ NULL,
175  /* foreachIDLink */ foreachIDLink,
176  /* foreachTexLink */ NULL,
177  /* panelRegister */ panelRegister,
178 };
void BKE_gpencil_stroke_subdivide(struct bGPdata *gpd, struct bGPDstroke *gps, int level, int type)
bool BKE_gpencil_stroke_close(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)
#define IFACE_(msgid)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
#define DNA_struct_default_get(struct_name)
Definition: DNA_defaults.h:44
@ GP_SUBDIV_INVERT_MATERIAL
@ GP_SUBDIV_INVERT_LAYERPASS
@ GP_SUBDIV_INVERT_LAYER
struct SubdivGpencilModifierData SubdivGpencilModifierData
@ eGpencilModifierType_Subdiv
@ GP_STROKE_CYCLIC
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 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_Subdiv
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
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
Definition: DNA_ID.h:273
Definition: BKE_main.h:116
void * data
struct uiLayout * layout
ListBase frames
ListBase layers
PointerRNA * ptr
Definition: wm_files.c:3157