Blender  V2.93
MOD_gpencil_util.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_utildefines.h"
27 
28 #include "BLI_math_vector.h"
29 
31 #include "DNA_gpencil_types.h"
32 #include "DNA_material_types.h"
33 #include "DNA_meshdata_types.h"
34 #include "DNA_object_types.h"
35 
36 #include "BKE_deform.h"
37 #include "BKE_gpencil_modifier.h"
38 #include "BKE_material.h"
39 
41 #include "MOD_gpencil_util.h"
42 
44 {
45 #define INIT_GP_TYPE(typeName) \
46  (types[eGpencilModifierType_##typeName] = &modifierType_Gpencil_##typeName)
49  INIT_GP_TYPE(Simplify);
50  INIT_GP_TYPE(Thick);
51  INIT_GP_TYPE(Tint);
53  INIT_GP_TYPE(Array);
54  INIT_GP_TYPE(Build);
55  INIT_GP_TYPE(Opacity);
57  INIT_GP_TYPE(Mirror);
58  INIT_GP_TYPE(Smooth);
59  INIT_GP_TYPE(Hook);
61  INIT_GP_TYPE(Armature);
65  INIT_GP_TYPE(Lineart);
66 #undef INIT_GP_TYPE
67 }
68 
69 /* verify if valid layer, material and pass index */
71  char *mlayername,
73  const int mpassindex,
74  const int gpl_passindex,
75  const int minpoints,
76  bGPDlayer *gpl,
77  bGPDstroke *gps,
78  const bool inv1,
79  const bool inv2,
80  const bool inv3,
81  const bool inv4)
82 {
83  Material *ma = BKE_gpencil_material(ob, gps->mat_nr + 1);
84  MaterialGPencilStyle *gp_style = ma->gp_style;
85 
86  /* omit if filter by layer */
87  if (mlayername[0] != '\0') {
88  if (inv1 == false) {
89  if (!STREQ(mlayername, gpl->info)) {
90  return false;
91  }
92  }
93  else {
94  if (STREQ(mlayername, gpl->info)) {
95  return false;
96  }
97  }
98  }
99  /* Omit if filter by material. */
100  if (material != NULL) {
101  if (inv4 == false) {
102  if (material != ma) {
103  return false;
104  }
105  }
106  else {
107  if (material == ma) {
108  return false;
109  }
110  }
111  }
112  /* verify layer pass */
113  if (gpl_passindex > 0) {
114  if (inv3 == false) {
115  if (gpl->pass_index != gpl_passindex) {
116  return false;
117  }
118  }
119  else {
120  if (gpl->pass_index == gpl_passindex) {
121  return false;
122  }
123  }
124  }
125  /* verify material pass */
126  if (mpassindex > 0) {
127  if (inv2 == false) {
128  if (gp_style->index != mpassindex) {
129  return false;
130  }
131  }
132  else {
133  if (gp_style->index == mpassindex) {
134  return false;
135  }
136  }
137  }
138  /* need to have a minimum number of points */
139  if ((minpoints > 0) && (gps->totpoints < minpoints)) {
140  return false;
141  }
142 
143  return true;
144 }
145 
146 /* verify if valid vertex group *and return weight */
147 float get_modifier_point_weight(MDeformVert *dvert, bool inverse, int def_nr)
148 {
149  float weight = 1.0f;
150 
151  if ((dvert != NULL) && (def_nr != -1)) {
152  MDeformWeight *dw = BKE_defvert_find_index(dvert, def_nr);
153  weight = dw ? dw->weight : -1.0f;
154  if ((weight >= 0.0f) && (inverse == 1)) {
155  return -1.0f;
156  }
157 
158  if ((weight < 0.0f) && (inverse == 0)) {
159  return -1.0f;
160  }
161 
162  /* if inverse, weight is always 1 */
163  if ((weight < 0.0f) && (inverse == 1)) {
164  return 1.0f;
165  }
166  }
167 
168  /* handle special empty groups */
169  if ((dvert == NULL) && (def_nr != -1)) {
170  if (inverse == 1) {
171  return 1.0f;
172  }
173 
174  return -1.0f;
175  }
176 
177  return weight;
178 }
support for deformation groups and hooks.
struct MDeformWeight * BKE_defvert_find_index(const struct MDeformVert *dv, const int defgroup)
General operations, lookup, etc. for materials.
struct Material * BKE_gpencil_material(struct Object *ob, short act)
Definition: material.c:703
#define STREQ(a, b)
Object is a sort of wrapper for general info.
float get_modifier_point_weight(MDeformVert *dvert, bool inverse, int def_nr)
#define INIT_GP_TYPE(typeName)
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)
void gpencil_modifier_type_init(GpencilModifierTypeInfo *types[])
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Time
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Texture
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Color
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White Noise
btMatrix3x3 inverse() const
Return the inverse of the matrix.
Definition: btTransform.h:182
Material material
static char ** types
Definition: makesdna.c:164
void Multiply(const JntArray &src, const double &factor, JntArray &dest)
Definition: jntarray.cpp:117
struct MaterialGPencilStyle * gp_style
Definition: msgfmt.c:181
char info[128]