Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BKE_gpencil_modifier.h « blenkernel « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 96c405e46ec6930ffb170b0cfc20821ac8959d30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
/* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once

/** \file
 * \ingroup bke
 */

#include "BLI_compiler_attrs.h"
#include "DNA_gpencil_modifier_types.h" /* needed for all enum typdefs */

#ifdef __cplusplus
extern "C" {
#endif

struct ARegionType;
struct BlendDataReader;
struct BlendLibReader;
struct BlendWriter;
struct Depsgraph;
struct GpencilModifierData;
struct ID;
struct ListBase;
struct Main;
struct ModifierUpdateDepsgraphContext;
struct Object;
struct Scene;
/* NOTE: bakeModifier() called from UI:
 * needs to create new data-blocks, hence the need for this. */
struct bGPDframe;
struct bGPDlayer;
struct bGPDstroke;

#define GPENCIL_MODIFIER_ACTIVE(_md, _is_render) \
  ((((_md)->mode & eGpencilModifierMode_Realtime) && (_is_render == false)) || \
   (((_md)->mode & eGpencilModifierMode_Render) && (_is_render == true)))
#define GPENCIL_MODIFIER_EDIT(_md, _is_edit) \
  ((((_md)->mode & eGpencilModifierMode_Editmode) == 0) && (_is_edit))

typedef enum {
  /** Should not be used, only for None modifier type. */
  eGpencilModifierTypeType_None,

  /** Grease pencil modifiers. */
  eGpencilModifierTypeType_Gpencil,
} GpencilModifierTypeType;

typedef enum {
  /* eGpencilModifierTypeFlag_SupportsMapping = (1 << 0), */ /* UNUSED */
  eGpencilModifierTypeFlag_SupportsEditmode = (1 << 1),

  /**
   * For modifiers that support edit-mode this determines if the
   * modifier should be enabled by default in edit-mode. This should
   * only be used by modifiers that are relatively speedy and
   * also generally used in edit-mode, otherwise let the user enable it by hand.
   */
  eGpencilModifierTypeFlag_EnableInEditmode = (1 << 2),

  /**
   * For modifiers that require original data and so cannot
   * be placed after any non-deform modifier.
   */
  /* eGpencilModifierTypeFlag_RequiresOriginalData = (1 << 3), */ /* UNUSED */

  /** Max one per type. */
  eGpencilModifierTypeFlag_Single = (1 << 4),

  /** Can't be added manually by user. */
  eGpencilModifierTypeFlag_NoUserAdd = (1 << 5),
  /** Can't be applied. */
  eGpencilModifierTypeFlag_NoApply = (1 << 6),
} GpencilModifierTypeFlag;

typedef void (*GreasePencilIDWalkFunc)(void *userData,
                                       struct Object *ob,
                                       struct ID **idpoin,
                                       int cb_flag);
typedef void (*GreasePencilTexWalkFunc)(void *userData,
                                        struct Object *ob,
                                        struct GpencilModifierData *md,
                                        const char *propname);

typedef struct GpencilModifierTypeInfo {
  /** The user visible name for this modifier */
  char name[32];

  /**
   * The DNA struct name for the modifier data type, used to
   * write the DNA data out.
   */
  char struct_name[32];

  /** The size of the modifier data type, used by allocation. */
  int struct_size;

  GpencilModifierTypeType type;
  GpencilModifierTypeFlag flags;

  /********************* Non-optional functions *********************/

  /**
   * Copy instance data for this modifier type. Should copy all user
   * level settings to the target modifier.
   */
  void (*copyData)(const struct GpencilModifierData *md, struct GpencilModifierData *target);

  /**
   * Callback for GP "stroke" modifiers that operate on the
   * shape and parameters of the provided strokes (e.g. Thickness, Noise, etc.)
   *
   * The gpl parameter contains the GP layer that the strokes come from.
   * While access is provided to this data, you should not directly access
   * the gpl->frames data from the modifier. Instead, use the gpf parameter
   * instead.
   *
   * The gps parameter contains the GP stroke to operate on. This is usually a copy
   * of the original (unmodified and saved to files) stroke data.
   */
  void (*deformStroke)(struct GpencilModifierData *md,
                       struct Depsgraph *depsgraph,
                       struct Object *ob,
                       struct bGPDlayer *gpl,
                       struct bGPDframe *gpf,
                       struct bGPDstroke *gps);

  /**
   * Callback for GP "geometry" modifiers that create extra geometry
   * in the frame (e.g. Array)
   */
  void (*generateStrokes)(struct GpencilModifierData *md,
                          struct Depsgraph *depsgraph,
                          struct Object *ob);

  /**
   * Bake-down GP modifier's effects into the GP data-block.
   *
   * This gets called when the user clicks the "Apply" button in the UI.
   * As such, this callback needs to go through all layers/frames in the
   * data-block, mutating the geometry and/or creating new data-blocks/objects
   */
  void (*bakeModifier)(struct Main *bmain,
                       struct Depsgraph *depsgraph,
                       struct GpencilModifierData *md,
                       struct Object *ob);

  /********************* Optional functions *********************/

  /**
   * Callback for GP "time" modifiers that offset keyframe time
   * Returns the frame number to be used after apply the modifier. This is
   * usually an offset of the animation for duplicated data-blocks.
   *
   * This function is optional.
   */
  int (*remapTime)(struct GpencilModifierData *md,
                   struct Depsgraph *depsgraph,
                   struct Scene *scene,
                   struct Object *ob,
                   struct bGPDlayer *gpl,
                   int cfra);

  /**
   * Initialize new instance data for this modifier type, this function
   * should set modifier variables to their default values.
   *
   * This function is optional.
   */
  void (*initData)(struct GpencilModifierData *md);

  /**
   * Free internal modifier data variables, this function should
   * not free the md variable itself.
   *
   * This function is optional.
   */
  void (*freeData)(struct GpencilModifierData *md);

  /**
   * Return a boolean value indicating if this modifier is able to be
   * calculated based on the modifier data. This is *not* regarding the
   * md->flag, that is tested by the system, this is just if the data
   * validates (for example, a lattice will return false if the lattice
   * object is not defined).
   *
   * This function is optional (assumes never disabled if not present).
   */
  bool (*isDisabled)(struct GpencilModifierData *md, int userRenderParams);

  /**
   * Add the appropriate relations to the dependency graph.
   *
   * This function is optional.
   */
  void (*updateDepsgraph)(struct GpencilModifierData *md,
                          const struct ModifierUpdateDepsgraphContext *ctx,
                          int mode);

  /**
   * Should return true if the modifier needs to be recalculated on time
   * changes.
   *
   * This function is optional (assumes false if not present).
   */
  bool (*dependsOnTime)(struct GpencilModifierData *md);

  /**
   * Should call the given walk function with a pointer to each ID
   * pointer (i.e. each data-block pointer) that the modifier data
   * stores. This is used for linking on file load and for
   * unlinking data-blocks or forwarding data-block references.
   *
   * This function is optional.
   */
  void (*foreachIDLink)(struct GpencilModifierData *md,
                        struct Object *ob,
                        GreasePencilIDWalkFunc walk,
                        void *userData);

  /**
   * Should call the given walk function for each texture that the
   * modifier data stores. This is used for finding all textures in
   * the context for the UI.
   *
   * This function is optional. If it is not present, it will be
   * assumed the modifier has no textures.
   */
  void (*foreachTexLink)(struct GpencilModifierData *md,
                         struct Object *ob,
                         GreasePencilTexWalkFunc walk,
                         void *userData);

  /* Register the panel types for the modifier's UI. */
  void (*panelRegister)(struct ARegionType *region_type);
} GpencilModifierTypeInfo;

#define GPENCIL_MODIFIER_TYPE_PANEL_PREFIX "MOD_PT_gpencil_"

/**
 * Initialize modifier's global data (type info and some common global storage).
 */
void BKE_gpencil_modifier_init(void);

/**
 * Get the idname of the modifier type's panel, which was defined in the #panelRegister callback.
 *
 * \param type: Type of modifier.
 * \param r_idname: ID name.
 */
void BKE_gpencil_modifierType_panel_id(GpencilModifierType type, char *r_idname);
void BKE_gpencil_modifier_panel_expand(struct GpencilModifierData *md);
/**
 * Get grease pencil modifier information.
 * \param type: Type of modifier.
 * \return Pointer to type
 */
const GpencilModifierTypeInfo *BKE_gpencil_modifier_get_info(GpencilModifierType type);
/**
 * Create new grease pencil modifier.
 * \param type: Type of modifier.
 * \return New modifier pointer.
 */
struct GpencilModifierData *BKE_gpencil_modifier_new(int type);
/**
 * Free grease pencil modifier data
 * \param md: Modifier data.
 * \param flag: Flags.
 */
void BKE_gpencil_modifier_free_ex(struct GpencilModifierData *md, int flag);
/**
 * Free grease pencil modifier data
 * \param md: Modifier data.
 */
void BKE_gpencil_modifier_free(struct GpencilModifierData *md);
/* check unique name */
bool BKE_gpencil_modifier_unique_name(struct ListBase *modifiers, struct GpencilModifierData *gmd);
/**
 * Check if grease pencil modifier depends on time.
 * \param md: Modifier data.
 * \return True if depends on time.
 */
bool BKE_gpencil_modifier_depends_ontime(struct GpencilModifierData *md);
struct GpencilModifierData *BKE_gpencil_modifiers_findby_type(struct Object *ob,
                                                              GpencilModifierType type);
/**
 * Find grease pencil modifier by name.
 * \param ob: Grease pencil object.
 * \param name: Name to find.
 * \return Pointer to modifier.
 */
struct GpencilModifierData *BKE_gpencil_modifiers_findby_name(struct Object *ob, const char *name);
/**
 * Generic grease pencil modifier copy data.
 * \param md_src: Source modifier data.
 * \param md_dst: Target modifier data.
 */
void BKE_gpencil_modifier_copydata_generic(const struct GpencilModifierData *md_src,
                                           struct GpencilModifierData *md_dst);
/**
 * Copy grease pencil modifier data.
 * \param md: Source modifier data.
 * \param target: Target modifier data.
 */
void BKE_gpencil_modifier_copydata(struct GpencilModifierData *md,
                                   struct GpencilModifierData *target);
/**
 * Copy grease pencil modifier data.
 * \param md: Source modifier data.
 * \param target: Target modifier data.
 * \param flag: Flags.
 */
void BKE_gpencil_modifier_copydata_ex(struct GpencilModifierData *md,
                                      struct GpencilModifierData *target,
                                      int flag);
/**
 * Set grease pencil modifier error.
 * \param md: Modifier data.
 * \param format: Format.
 */
void BKE_gpencil_modifier_set_error(struct GpencilModifierData *md, const char *format, ...)
    ATTR_PRINTF_FORMAT(2, 3);
/**
 * Link grease pencil modifier related IDs.
 * \param ob: Grease pencil object.
 * \param walk: Walk option.
 * \param userData: User data.
 */
void BKE_gpencil_modifiers_foreach_ID_link(struct Object *ob,
                                           GreasePencilIDWalkFunc walk,
                                           void *userData);
/**
 * Link grease pencil modifier related Texts.
 * \param ob: Grease pencil object.
 * \param walk: Walk option.
 * \param userData: User data.
 */
void BKE_gpencil_modifiers_foreach_tex_link(struct Object *ob,
                                            GreasePencilTexWalkFunc walk,
                                            void *userData);

/**
 * Check whether given modifier is not local (i.e. from linked data) when the object is a library
 * override.
 *
 * \param gmd: May be NULL, in which case we consider it as a non-local modifier case.
 */
bool BKE_gpencil_modifier_is_nonlocal_in_liboverride(const struct Object *ob,
                                                     const struct GpencilModifierData *gmd);

typedef struct GpencilVirtualModifierData {
  ArmatureGpencilModifierData amd;
  LatticeGpencilModifierData lmd;
} GpencilVirtualModifierData;

/**
 * This is to include things that are not modifiers in the evaluation of the modifier stack,
 * for example parenting to an armature or lattice without having a real modifier.
 */
struct GpencilModifierData *BKE_gpencil_modifiers_get_virtual_modifierlist(
    const struct Object *ob, struct GpencilVirtualModifierData *data);

/**
 * Check if object has grease pencil Geometry modifiers.
 * \param ob: Grease pencil object.
 * \return True if exist.
 */
bool BKE_gpencil_has_geometry_modifiers(struct Object *ob);
/**
 * Check if object has grease pencil Time modifiers.
 * \param ob: Grease pencil object.
 * \return True if exist.
 */
bool BKE_gpencil_has_time_modifiers(struct Object *ob);
/**
 * Check if object has grease pencil transform stroke modifiers.
 * \param ob: Grease pencil object.
 * \return True if exist.
 */
bool BKE_gpencil_has_transform_modifiers(struct Object *ob);

/* Stores the maximum calculation range in the whole modifier stack for line art so the cache can
 * cover everything that will be visible. */
typedef struct GpencilLineartLimitInfo {
  char min_level;
  char max_level;
  short edge_types;
} GpencilLineartLimitInfo;

GpencilLineartLimitInfo BKE_gpencil_get_lineart_modifier_limits(const struct Object *ob);

void BKE_gpencil_set_lineart_modifier_limits(struct GpencilModifierData *md,
                                             const struct GpencilLineartLimitInfo *info,
                                             bool is_first_lineart);
bool BKE_gpencil_is_first_lineart_in_stack(const struct Object *ob,
                                           const struct GpencilModifierData *md);

/**
 * Init grease pencil cache deform data.
 * \param ob: Grease pencil object
 */
void BKE_gpencil_cache_data_init(struct Depsgraph *depsgraph, struct Object *ob);
/**
 * Clear grease pencil cache deform data.
 * \param ob: Grease pencil object
 */
void BKE_gpencil_cache_data_clear(struct Object *ob);

/**
 * Calculate grease-pencil modifiers.
 * \param depsgraph: Current depsgraph.
 * \param scene: Current scene.
 * \param ob: Grease pencil object.
 */
void BKE_gpencil_modifiers_calc(struct Depsgraph *depsgraph,
                                struct Scene *scene,
                                struct Object *ob);

/**
 * Prepare grease pencil eval data for modifiers
 * \param depsgraph: Current depsgraph.
 * \param scene: Current scene.
 * \param ob: Grease pencil object.
 */
void BKE_gpencil_prepare_eval_data(struct Depsgraph *depsgraph,
                                   struct Scene *scene,
                                   struct Object *ob);

/**
 * Get the current frame re-timed with time modifiers.
 * \param depsgraph: Current depsgraph.
 * \param scene: Current scene.
 * \param ob: Grease pencil object.
 * \param gpl: Grease pencil layer.
 * \return New frame number.
 */
struct bGPDframe *BKE_gpencil_frame_retime_get(struct Depsgraph *depsgraph,
                                               struct Scene *scene,
                                               struct Object *ob,
                                               struct bGPDlayer *gpl);
/**
 * Get Time modifier frame number.
 */
int BKE_gpencil_time_modifier_cfra(struct Depsgraph *depsgraph,
                                   struct Scene *scene,
                                   struct Object *ob,
                                   struct bGPDlayer *gpl,
                                   int cfra,
                                   bool is_render);

void BKE_gpencil_modifier_blend_write(struct BlendWriter *writer, struct ListBase *modbase);
void BKE_gpencil_modifier_blend_read_data(struct BlendDataReader *reader, struct ListBase *lb);
void BKE_gpencil_modifier_blend_read_lib(struct BlendLibReader *reader, struct Object *ob);

#ifdef __cplusplus
}
#endif