Blender  V3.3
MOD_gpencil_util.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2017 Blender Foundation. */
3 
8 #include <stdio.h>
9 
10 #include "BLI_listbase.h"
11 #include "BLI_math_vector.h"
12 #include "BLI_utildefines.h"
13 
15 #include "DNA_gpencil_types.h"
16 #include "DNA_material_types.h"
17 #include "DNA_meshdata_types.h"
18 #include "DNA_object_types.h"
19 #include "DNA_scene_types.h"
20 
21 #include "BKE_deform.h"
22 #include "BKE_gpencil_modifier.h"
23 #include "BKE_material.h"
24 #include "BKE_scene.h"
25 
27 #include "MOD_gpencil_util.h"
28 
29 #include "DEG_depsgraph_query.h"
30 
32 {
33 #define INIT_GP_TYPE(typeName) \
34  (types[eGpencilModifierType_##typeName] = &modifierType_Gpencil_##typeName)
37  INIT_GP_TYPE(Simplify);
38  INIT_GP_TYPE(Thick);
39  INIT_GP_TYPE(Tint);
41  INIT_GP_TYPE(Array);
42  INIT_GP_TYPE(Build);
43  INIT_GP_TYPE(Opacity);
46  INIT_GP_TYPE(Mirror);
47  INIT_GP_TYPE(Smooth);
48  INIT_GP_TYPE(Hook);
50  INIT_GP_TYPE(Armature);
51  INIT_GP_TYPE(Time);
54  INIT_GP_TYPE(WeightAngle);
55  INIT_GP_TYPE(WeightProximity);
56  INIT_GP_TYPE(Lineart);
57  INIT_GP_TYPE(Dash);
58  INIT_GP_TYPE(Shrinkwrap);
59  INIT_GP_TYPE(Envelope);
60 #undef INIT_GP_TYPE
61 }
62 
64  char *mlayername,
66  const int mpassindex,
67  const int gpl_passindex,
68  const int minpoints,
69  bGPDlayer *gpl,
70  bGPDstroke *gps,
71  const bool inv1,
72  const bool inv2,
73  const bool inv3,
74  const bool inv4)
75 {
76  Material *ma_gps = BKE_gpencil_material(ob, gps->mat_nr + 1);
77  MaterialGPencilStyle *gp_style = ma_gps->gp_style;
78 
79  /* omit if filter by layer */
80  if (mlayername[0] != '\0') {
81  if (inv1 == false) {
82  if (!STREQ(mlayername, gpl->info)) {
83  return false;
84  }
85  }
86  else {
87  if (STREQ(mlayername, gpl->info)) {
88  return false;
89  }
90  }
91  }
92  /* Omit if filter by material. */
93  if (material != NULL) {
94  /* Requires to use the original material to compare the same pointer address. */
95  Material *ma_md_orig = (Material *)DEG_get_original_id(&material->id);
96  Material *ma_gps_orig = (Material *)DEG_get_original_id(&ma_gps->id);
97  if (inv4 == false) {
98  if (ma_md_orig != ma_gps_orig) {
99  return false;
100  }
101  }
102  else {
103  if (ma_md_orig == ma_gps_orig) {
104  return false;
105  }
106  }
107  }
108  /* verify layer pass */
109  if (gpl_passindex > 0) {
110  if (inv3 == false) {
111  if (gpl->pass_index != gpl_passindex) {
112  return false;
113  }
114  }
115  else {
116  if (gpl->pass_index == gpl_passindex) {
117  return false;
118  }
119  }
120  }
121  /* verify material pass */
122  if (mpassindex > 0) {
123  if (inv2 == false) {
124  if (gp_style->index != mpassindex) {
125  return false;
126  }
127  }
128  else {
129  if (gp_style->index == mpassindex) {
130  return false;
131  }
132  }
133  }
134  /* need to have a minimum number of points */
135  if ((minpoints > 0) && (gps->totpoints < minpoints)) {
136  return false;
137  }
138 
139  return true;
140 }
141 
142 float get_modifier_point_weight(MDeformVert *dvert, bool inverse, int def_nr)
143 {
144  float weight = 1.0f;
145 
146  if ((dvert != NULL) && (def_nr != -1)) {
147  MDeformWeight *dw = BKE_defvert_find_index(dvert, def_nr);
148  weight = dw ? dw->weight : -1.0f;
149  if ((weight >= 0.0f) && (inverse)) {
150  return 1.0f - weight;
151  }
152 
153  if ((weight < 0.0f) && (!inverse)) {
154  return -1.0f;
155  }
156 
157  /* if inverse, weight is always 1 */
158  if ((weight < 0.0f) && (inverse)) {
159  return 1.0f;
160  }
161  }
162 
163  /* handle special empty groups */
164  if ((dvert == NULL) && (def_nr != -1)) {
165  if (inverse == 1) {
166  return 1.0f;
167  }
168 
169  return -1.0f;
170  }
171 
172  return weight;
173 }
174 
176  Depsgraph *depsgraph, GpencilModifierData *md, Object *ob, const bool retime, gpBakeCb bake_cb)
177 {
179  bGPdata *gpd = ob->data;
180  int oldframe = (int)DEG_get_ctime(depsgraph);
181 
182  LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
183  LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
184  if (retime) {
185  scene->r.cfra = gpf->framenum;
187  }
188  LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
189  bake_cb(md, depsgraph, ob, gpl, gpf, gps);
190  }
191  }
192  }
193 
194  /* Return frame state and DB to original state. */
195  if (retime) {
196  scene->r.cfra = oldframe;
198  }
199 }
support for deformation groups and hooks.
struct MDeformWeight * BKE_defvert_find_index(const struct MDeformVert *dv, int defgroup)
General operations, lookup, etc. for materials.
struct Material * BKE_gpencil_material(struct Object *ob, short act)
Definition: material.c:795
void BKE_scene_graph_update_for_newframe(struct Depsgraph *depsgraph)
Definition: scene.cc:2728
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
#define STREQ(a, b)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
float DEG_get_ctime(const Depsgraph *graph)
struct ID * DEG_get_original_id(struct ID *id)
struct Scene * DEG_get_evaluated_scene(const struct Depsgraph *graph)
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)
void generic_bake_deform_stroke(Depsgraph *depsgraph, GpencilModifierData *md, Object *ob, const bool retime, gpBakeCb bake_cb)
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[])
void(* gpBakeCb)(struct GpencilModifierData *md_, struct Depsgraph *depsgraph_, struct Object *ob_, struct bGPDlayer *gpl_, struct bGPDframe *gpf_, struct bGPDstroke *gps_)
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between and object coordinate space Combine Create a color from its and value channels Color Retrieve a color or the default fallback if none is specified Separate Split a vector into its and Z components Generates normals with round corners and may slow down renders Vector Displace the surface along an arbitrary direction White Return a random value or color based on an input seed Float Map an input float to a curve and outputs a float value Separate Color
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Texture
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between and object coordinate space Combine Create a color from its and value channels Color Retrieve a color or the default fallback if none is specified Separate Split a vector into its and Z components Generates normals with round corners and may slow down renders Vector Displace the surface along an arbitrary direction White Noise
btMatrix3x3 inverse() const
Return the inverse of the matrix.
Definition: btTransform.h:182
Scene scene
Material material
const Depsgraph * depsgraph
static char ** types
Definition: makesdna.c:67
MIKK_INLINE float Length(const SVec3 v)
Definition: mikktspace.c:81
void Multiply(const JntArray &src, const double &factor, JntArray &dest)
Definition: jntarray.cpp:117
struct MaterialGPencilStyle * gp_style
void * data
Definition: msgfmt.c:165
struct RenderData r
char info[128]
ListBase layers