Blender  V2.93
gpencil_add_lineart.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 "BLI_math.h"
25 #include "BLI_utildefines.h"
26 
27 #include "DNA_gpencil_types.h"
28 #include "DNA_material_types.h"
29 #include "DNA_object_types.h"
30 #include "DNA_scene_types.h"
31 
32 #include "BKE_brush.h"
33 #include "BKE_context.h"
34 #include "BKE_gpencil.h"
35 #include "BKE_gpencil_geom.h"
36 #include "BKE_lib_id.h"
37 #include "BKE_main.h"
38 #include "BKE_material.h"
39 
40 #include "DEG_depsgraph.h"
41 #include "DEG_depsgraph_query.h"
42 
43 #include "ED_gpencil.h"
44 
45 /* Definition of the most important info from a color */
46 typedef struct ColorTemplate {
47  const char *name;
48  float line[4];
49  float fill[4];
51 
52 /* Add color an ensure duplications (matched by name) */
53 static int gpencil_lineart_material(Main *bmain,
54  Object *ob,
55  const ColorTemplate *pct,
56  const bool fill)
57 {
58  int index;
59  Material *ma = BKE_gpencil_object_material_ensure_by_name(bmain, ob, pct->name, &index);
60 
61  copy_v4_v4(ma->gp_style->stroke_rgba, pct->line);
63 
64  copy_v4_v4(ma->gp_style->fill_rgba, pct->fill);
66 
67  if (fill) {
69  }
70 
71  return index;
72 }
73 
74 /* ***************************************************************** */
75 /* Color Data */
76 
78  "Black",
79  {0.0f, 0.0f, 0.0f, 1.0f},
80  {0.0f, 0.0f, 0.0f, 0.0f},
81 };
82 
83 /* ***************************************************************** */
84 /* LineArt API */
85 
86 /* Add a Simple LineArt setup. */
88 {
89  Main *bmain = CTX_data_main(C);
90  bGPdata *gpd = (bGPdata *)ob->data;
91 
92  /* create colors */
93  int color_black = gpencil_lineart_material(bmain, ob, &gp_stroke_material_black, false);
94 
95  /* set first color as active and in brushes */
96  ob->actcol = color_black + 1;
97 
98  /* layers */
99  bGPDlayer *lines = BKE_gpencil_layer_addnew(gpd, "Lines", true);
100 
101  /* frames */
102  BKE_gpencil_frame_addnew(lines, 0);
103 
104  /* update depsgraph */
105  /* To trigger modifier update, this is still needed although we don't have any strokes. */
108 }
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1018
struct bGPDframe * BKE_gpencil_frame_addnew(struct bGPDlayer *gpl, int cframe)
Definition: gpencil.c:539
struct Material * BKE_gpencil_object_material_ensure_by_name(struct Main *bmain, struct Object *ob, const char *name, int *r_index)
Definition: gpencil.c:2466
struct bGPDlayer * BKE_gpencil_layer_addnew(struct bGPdata *gpd, const char *name, bool setactive)
Definition: gpencil.c:659
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])
void DEG_id_tag_update(struct ID *id, int flag)
@ ID_RECALC_TRANSFORM
Definition: DNA_ID.h:599
@ ID_RECALC_GEOMETRY
Definition: DNA_ID.h:611
@ GP_DATA_CACHE_IS_DIRTY
@ GP_MATERIAL_FILL_SHOW
Object is a sort of wrapper for general info.
#define C
Definition: RandGen.cpp:39
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:116
struct MaterialGPencilStyle * gp_style
void * data