Blender  V3.3
gpencil_add_lineart.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 "BLI_math.h"
9 #include "BLI_utildefines.h"
10 
11 #include "DNA_gpencil_types.h"
12 #include "DNA_material_types.h"
13 #include "DNA_object_types.h"
14 #include "DNA_scene_types.h"
15 
16 #include "BKE_brush.h"
17 #include "BKE_context.h"
18 #include "BKE_gpencil.h"
19 #include "BKE_gpencil_geom.h"
20 #include "BKE_lib_id.h"
21 #include "BKE_main.h"
22 #include "BKE_material.h"
23 
24 #include "BLT_translation.h"
25 
26 #include "DEG_depsgraph.h"
27 #include "DEG_depsgraph_query.h"
28 
29 #include "ED_gpencil.h"
30 
31 /* Definition of the most important info from a color */
32 typedef struct ColorTemplate {
33  const char *name;
34  float line[4];
35  float fill[4];
37 
38 /* Add color an ensure duplications (matched by name) */
39 static int gpencil_lineart_material(Main *bmain,
40  Object *ob,
41  const ColorTemplate *pct,
42  const bool fill)
43 {
44  int index;
45  Material *ma = BKE_gpencil_object_material_ensure_by_name(bmain, ob, DATA_(pct->name), &index);
46 
47  copy_v4_v4(ma->gp_style->stroke_rgba, pct->line);
49 
50  copy_v4_v4(ma->gp_style->fill_rgba, pct->fill);
52 
53  if (fill) {
55  }
56 
57  return index;
58 }
59 
60 /* ***************************************************************** */
61 /* Color Data */
62 
64  N_("Black"),
65  {0.0f, 0.0f, 0.0f, 1.0f},
66  {0.0f, 0.0f, 0.0f, 0.0f},
67 };
68 
69 /* ***************************************************************** */
70 /* LineArt API */
71 
73 {
74  Main *bmain = CTX_data_main(C);
75  bGPdata *gpd = (bGPdata *)ob->data;
76 
77  /* create colors */
78  int color_black = gpencil_lineart_material(bmain, ob, &gp_stroke_material_black, false);
79 
80  /* set first color as active and in brushes */
81  ob->actcol = color_black + 1;
82 
83  /* layers */
84  bGPDlayer *lines = BKE_gpencil_layer_addnew(gpd, "Lines", true, false);
85 
86  /* frames */
87  BKE_gpencil_frame_addnew(lines, 0);
88 
89  /* update depsgraph */
90  /* To trigger modifier update, this is still needed although we don't have any strokes. */
93 }
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1074
struct bGPDframe * BKE_gpencil_frame_addnew(struct bGPDlayer *gpl, int cframe)
Definition: gpencil.c:514
struct Material * BKE_gpencil_object_material_ensure_by_name(struct Main *bmain, struct Object *ob, const char *name, int *r_index)
Definition: gpencil.c:2228
struct bGPDlayer * BKE_gpencil_layer_addnew(struct bGPdata *gpd, const char *name, bool setactive, bool add_to_header)
Definition: gpencil.c:621
General operations, lookup, etc. for materials.
MINLINE void srgb_to_linearrgb_v4(float linear[4], const float srgb[4])
MINLINE void copy_v4_v4(float r[4], const float a[4])
#define DATA_(msgid)
void DEG_id_tag_update(struct ID *id, int flag)
@ ID_RECALC_TRANSFORM
Definition: DNA_ID.h:771
@ ID_RECALC_GEOMETRY
Definition: DNA_ID.h:791
@ GP_DATA_CACHE_IS_DIRTY
@ GP_MATERIAL_FILL_SHOW
Object is a sort of wrapper for general info.
#define C
Definition: RandGen.cpp:25
static const ColorTemplate gp_stroke_material_black
void ED_gpencil_create_lineart(bContext *C, Object *ob)
static int gpencil_lineart_material(Main *bmain, Object *ob, const ColorTemplate *pct, const bool fill)
struct ColorTemplate ColorTemplate
const char * name
Definition: BKE_main.h:121
struct MaterialGPencilStyle * gp_style
void * data
#define N_(msgid)