Blender  V2.93
MOD_gpenciloffset.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_utildefines.h"
28 
29 #include "BLI_math.h"
30 
31 #include "DNA_defaults.h"
33 #include "DNA_gpencil_types.h"
34 #include "DNA_meshdata_types.h"
35 #include "DNA_object_types.h"
36 #include "DNA_screen_types.h"
37 
38 #include "BKE_context.h"
39 #include "BKE_deform.h"
40 #include "BKE_gpencil_geom.h"
41 #include "BKE_gpencil_modifier.h"
42 #include "BKE_lib_query.h"
43 #include "BKE_modifier.h"
44 #include "BKE_screen.h"
45 
46 #include "DEG_depsgraph.h"
47 
48 #include "UI_interface.h"
49 #include "UI_resources.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 
69 /* change stroke offsetness */
72  Object *ob,
73  bGPDlayer *gpl,
74  bGPDframe *UNUSED(gpf),
75  bGPDstroke *gps)
76 {
78  const int def_nr = BKE_object_defgroup_name_index(ob, mmd->vgname);
79 
80  float mat[4][4];
81  float loc[3], rot[3], scale[3];
82 
84  mmd->layername,
85  mmd->material,
86  mmd->pass_index,
87  mmd->layer_pass,
88  1,
89  gpl,
90  gps,
95  return;
96  }
97  bGPdata *gpd = ob->data;
98 
99  for (int i = 0; i < gps->totpoints; i++) {
100  bGPDspoint *pt = &gps->points[i];
101  MDeformVert *dvert = gps->dvert != NULL ? &gps->dvert[i] : NULL;
102 
103  /* Verify vertex group. */
104  const float weight = get_modifier_point_weight(
105  dvert, (mmd->flag & GP_OFFSET_INVERT_VGROUP) != 0, def_nr);
106  if (weight < 0.0f) {
107  continue;
108  }
109  /* Calculate matrix. */
110  mul_v3_v3fl(loc, mmd->loc, weight);
111  mul_v3_v3fl(rot, mmd->rot, weight);
112  mul_v3_v3fl(scale, mmd->scale, weight);
113  add_v3_fl(scale, 1.0);
114  loc_eul_size_to_mat4(mat, loc, rot, scale);
115 
116  /* Apply scale to thickness. */
117  float unit_scale = (scale[0] + scale[1] + scale[2]) / 3.0f;
118  pt->pressure *= unit_scale;
119 
120  mul_m4_v3(mat, &pt->x);
121  }
122  /* Calc geometry data. */
124 }
125 
126 static void bakeModifier(struct Main *UNUSED(bmain),
129  Object *ob)
130 {
131  bGPdata *gpd = ob->data;
132 
133  LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
134  LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
135  LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
136  deformStroke(md, depsgraph, ob, gpl, gpf, gps);
137  }
138  }
139  }
140 }
141 
142 static void foreachIDLink(GpencilModifierData *md, Object *ob, IDWalkFunc walk, void *userData)
143 {
145 
146  walk(userData, ob, (ID **)&mmd->material, IDWALK_CB_USER);
147 }
148 
149 static void panel_draw(const bContext *UNUSED(C), Panel *panel)
150 {
151  uiLayout *layout = panel->layout;
152 
154 
155  uiLayoutSetPropSep(layout, true);
156 
157  uiItemR(layout, ptr, "location", 0, NULL, ICON_NONE);
158  uiItemR(layout, ptr, "rotation", 0, NULL, ICON_NONE);
159  uiItemR(layout, ptr, "scale", 0, NULL, ICON_NONE);
160 
162 }
163 
164 static void mask_panel_draw(const bContext *UNUSED(C), Panel *panel)
165 {
166  gpencil_modifier_masking_panel_draw(panel, true, true);
167 }
168 
169 static void panelRegister(ARegionType *region_type)
170 {
174  region_type, "mask", "Influence", NULL, mask_panel_draw, panel_type);
175 }
176 
178  /* name */ "Offset",
179  /* structName */ "OffsetGpencilModifierData",
180  /* structSize */ sizeof(OffsetGpencilModifierData),
183 
184  /* copyData */ copyData,
185 
186  /* deformStroke */ deformStroke,
187  /* generateStrokes */ NULL,
188  /* bakeModifier */ bakeModifier,
189  /* remapTime */ NULL,
190 
191  /* initData */ initData,
192  /* freeData */ NULL,
193  /* isDisabled */ NULL,
194  /* updateDepsgraph */ NULL,
195  /* dependsOnTime */ NULL,
196  /* foreachIDLink */ foreachIDLink,
197  /* foreachTexLink */ NULL,
198  /* panelRegister */ panelRegister,
199 };
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
void mul_m4_v3(const float M[4][4], float r[3])
Definition: math_matrix.c:732
void loc_eul_size_to_mat4(float R[4][4], const float loc[3], const float eul[3], const float size[3])
Definition: math_matrix.c:2653
MINLINE void add_v3_fl(float r[3], float f)
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
#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 OffsetGpencilModifierData OffsetGpencilModifierData
@ GP_OFFSET_INVERT_MATERIAL
@ GP_OFFSET_INVERT_LAYER
@ GP_OFFSET_INVERT_VGROUP
@ GP_OFFSET_INVERT_LAYERPASS
@ eGpencilModifierType_Offset
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)
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)
GpencilModifierTypeInfo modifierType_Gpencil_Offset
#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
#define rot(x, k)
Definition: DNA_ID.h:273
Definition: BKE_main.h:116
void * data
struct uiLayout * layout
ListBase frames
bGPDspoint * points
struct MDeformVert * dvert
ListBase layers
PointerRNA * ptr
Definition: wm_files.c:3157