Blender
V3.3
source
blender
editors
gpencil
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];
36
}
ColorTemplate
;
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
);
48
srgb_to_linearrgb_v4
(ma->
gp_style
->
stroke_rgba
, ma->
gp_style
->
stroke_rgba
);
49
50
copy_v4_v4
(ma->
gp_style
->
fill_rgba
, pct->
fill
);
51
srgb_to_linearrgb_v4
(ma->
gp_style
->
fill_rgba
, ma->
gp_style
->
fill_rgba
);
52
53
if
(fill) {
54
ma->
gp_style
->
flag
|=
GP_MATERIAL_FILL_SHOW
;
55
}
56
57
return
index;
58
}
59
60
/* ***************************************************************** */
61
/* Color Data */
62
63
static
const
ColorTemplate
gp_stroke_material_black
= {
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
72
void
ED_gpencil_create_lineart
(
bContext
*
C
,
Object
*ob)
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. */
91
DEG_id_tag_update
(&gpd->
id
,
ID_RECALC_TRANSFORM
|
ID_RECALC_GEOMETRY
);
92
gpd->
flag
|=
GP_DATA_CACHE_IS_DIRTY
;
93
}
BKE_brush.h
BKE_context.h
CTX_data_main
struct Main * CTX_data_main(const bContext *C)
Definition:
context.c:1074
BKE_gpencil.h
BKE_gpencil_frame_addnew
struct bGPDframe * BKE_gpencil_frame_addnew(struct bGPDlayer *gpl, int cframe)
Definition:
gpencil.c:514
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:2228
BKE_gpencil_layer_addnew
struct bGPDlayer * BKE_gpencil_layer_addnew(struct bGPdata *gpd, const char *name, bool setactive, bool add_to_header)
Definition:
gpencil.c:621
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:77
copy_v4_v4
MINLINE void copy_v4_v4(float r[4], const float a[4])
Definition:
math_vector_inline.c:56
BLI_utildefines.h
BLT_translation.h
DATA_
#define DATA_(msgid)
Definition:
BLT_translation.h:39
DEG_depsgraph.h
DEG_id_tag_update
void DEG_id_tag_update(struct ID *id, int flag)
Definition:
depsgraph_tag.cc:750
DEG_depsgraph_query.h
ID_RECALC_TRANSFORM
@ ID_RECALC_TRANSFORM
Definition:
DNA_ID.h:771
ID_RECALC_GEOMETRY
@ ID_RECALC_GEOMETRY
Definition:
DNA_ID.h:791
DNA_gpencil_types.h
GP_DATA_CACHE_IS_DIRTY
@ GP_DATA_CACHE_IS_DIRTY
Definition:
DNA_gpencil_types.h:799
DNA_material_types.h
GP_MATERIAL_FILL_SHOW
@ GP_MATERIAL_FILL_SHOW
Definition:
DNA_material_types.h:126
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:25
gp_stroke_material_black
static const ColorTemplate gp_stroke_material_black
Definition:
gpencil_add_lineart.c:63
ED_gpencil_create_lineart
void ED_gpencil_create_lineart(bContext *C, Object *ob)
Definition:
gpencil_add_lineart.c:72
gpencil_lineart_material
static int gpencil_lineart_material(Main *bmain, Object *ob, const ColorTemplate *pct, const bool fill)
Definition:
gpencil_add_lineart.c:39
ColorTemplate
struct ColorTemplate ColorTemplate
ColorTemplate
Definition:
gpencil_add_blank.c:29
ColorTemplate::fill
float fill[4]
Definition:
gpencil_add_blank.c:32
ColorTemplate::line
float line[4]
Definition:
gpencil_add_blank.c:31
ColorTemplate::name
const char * name
Definition:
gpencil_add_blank.c:30
Main
Definition:
BKE_main.h:121
MaterialGPencilStyle::stroke_rgba
float stroke_rgba[4]
Definition:
DNA_material_types.h:57
MaterialGPencilStyle::fill_rgba
float fill_rgba[4]
Definition:
DNA_material_types.h:59
MaterialGPencilStyle::flag
short flag
Definition:
DNA_material_types.h:63
Material
Definition:
DNA_material_types.h:164
Material::gp_style
struct MaterialGPencilStyle * gp_style
Definition:
DNA_material_types.h:230
Object
Definition:
DNA_object_types.h:242
Object::actcol
int actcol
Definition:
DNA_object_types.h:307
Object::data
void * data
Definition:
DNA_object_types.h:271
bContext
Definition:
context.c:56
bGPDlayer
Definition:
DNA_gpencil_types.h:467
bGPdata
Definition:
DNA_gpencil_types.h:670
bGPdata::flag
int flag
Definition:
DNA_gpencil_types.h:682
bGPdata::id
ID id
Definition:
DNA_gpencil_types.h:674
N_
#define N_(msgid)
Definition:
versioning_userdef.c:46
Generated on Tue Oct 22 2024 13:18:25 for Blender by
doxygen
1.9.1