Blender
V2.93
source
blender
editors
gpencil
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];
50
}
ColorTemplate
;
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
);
62
srgb_to_linearrgb_v4
(ma->
gp_style
->
stroke_rgba
, ma->
gp_style
->
stroke_rgba
);
63
64
copy_v4_v4
(ma->
gp_style
->
fill_rgba
, pct->
fill
);
65
srgb_to_linearrgb_v4
(ma->
gp_style
->
fill_rgba
, ma->
gp_style
->
fill_rgba
);
66
67
if
(fill) {
68
ma->
gp_style
->
flag
|=
GP_MATERIAL_FILL_SHOW
;
69
}
70
71
return
index;
72
}
73
74
/* ***************************************************************** */
75
/* Color Data */
76
77
static
const
ColorTemplate
gp_stroke_material_black
= {
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. */
87
void
ED_gpencil_create_lineart
(
bContext
*
C
,
Object
*ob)
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. */
106
DEG_id_tag_update
(&gpd->
id
,
ID_RECALC_TRANSFORM
|
ID_RECALC_GEOMETRY
);
107
gpd->
flag
|=
GP_DATA_CACHE_IS_DIRTY
;
108
}
BKE_brush.h
BKE_context.h
CTX_data_main
struct Main * CTX_data_main(const bContext *C)
Definition:
context.c:1018
BKE_gpencil.h
BKE_gpencil_frame_addnew
struct bGPDframe * BKE_gpencil_frame_addnew(struct bGPDlayer *gpl, int cframe)
Definition:
gpencil.c:539
BKE_gpencil_object_material_ensure_by_name
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
BKE_gpencil_layer_addnew
struct bGPDlayer * BKE_gpencil_layer_addnew(struct bGPdata *gpd, const char *name, bool setactive)
Definition:
gpencil.c:659
BKE_gpencil_geom.h
BKE_lib_id.h
BKE_main.h
BKE_material.h
General operations, lookup, etc. for materials.
BLI_math.h
srgb_to_linearrgb_v4
MINLINE void srgb_to_linearrgb_v4(float linear[4], const float srgb[4])
Definition:
math_color_inline.c:95
copy_v4_v4
MINLINE void copy_v4_v4(float r[4], const float a[4])
Definition:
math_vector_inline.c:74
BLI_utildefines.h
DEG_depsgraph.h
DEG_id_tag_update
void DEG_id_tag_update(struct ID *id, int flag)
Definition:
depsgraph_tag.cc:745
DEG_depsgraph_query.h
ID_RECALC_TRANSFORM
@ ID_RECALC_TRANSFORM
Definition:
DNA_ID.h:599
ID_RECALC_GEOMETRY
@ ID_RECALC_GEOMETRY
Definition:
DNA_ID.h:611
DNA_gpencil_types.h
GP_DATA_CACHE_IS_DIRTY
@ GP_DATA_CACHE_IS_DIRTY
Definition:
DNA_gpencil_types.h:765
DNA_material_types.h
GP_MATERIAL_FILL_SHOW
@ GP_MATERIAL_FILL_SHOW
Definition:
DNA_material_types.h:131
DNA_object_types.h
Object is a sort of wrapper for general info.
DNA_scene_types.h
ED_gpencil.h
C
#define C
Definition:
RandGen.cpp:39
gp_stroke_material_black
static const ColorTemplate gp_stroke_material_black
Definition:
gpencil_add_lineart.c:77
ED_gpencil_create_lineart
void ED_gpencil_create_lineart(bContext *C, Object *ob)
Definition:
gpencil_add_lineart.c:87
gpencil_lineart_material
static int gpencil_lineart_material(Main *bmain, Object *ob, const ColorTemplate *pct, const bool fill)
Definition:
gpencil_add_lineart.c:53
ColorTemplate
struct ColorTemplate ColorTemplate
ColorTemplate
Definition:
gpencil_add_lineart.c:46
ColorTemplate::fill
float fill[4]
Definition:
gpencil_add_lineart.c:49
ColorTemplate::line
float line[4]
Definition:
gpencil_add_lineart.c:48
ColorTemplate::name
const char * name
Definition:
gpencil_add_lineart.c:47
Main
Definition:
BKE_main.h:116
MaterialGPencilStyle::stroke_rgba
float stroke_rgba[4]
Definition:
DNA_material_types.h:62
MaterialGPencilStyle::fill_rgba
float fill_rgba[4]
Definition:
DNA_material_types.h:64
MaterialGPencilStyle::flag
short flag
Definition:
DNA_material_types.h:68
Material
Definition:
DNA_material_types.h:158
Material::gp_style
struct MaterialGPencilStyle * gp_style
Definition:
DNA_material_types.h:222
Object
Definition:
DNA_object_types.h:239
Object::actcol
int actcol
Definition:
DNA_object_types.h:302
Object::data
void * data
Definition:
DNA_object_types.h:265
bContext
Definition:
context.c:69
bGPDlayer
Definition:
DNA_gpencil_types.h:454
bGPdata
Definition:
DNA_gpencil_types.h:645
bGPdata::flag
int flag
Definition:
DNA_gpencil_types.h:655
bGPdata::id
ID id
Definition:
DNA_gpencil_types.h:647
Generated on Tue Jan 31 2023 14:37:24 for Blender by
doxygen
1.9.1