Blender  V2.93
gpencil_io_import_base.cc
Go to the documentation of this file.
1 
2 
3 /*
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2020 Blender Foundation
19  * All rights reserved.
20  */
21 
25 #include "BLI_math_vector.h"
26 
27 #include "DNA_material_types.h"
28 #include "DNA_object_types.h"
29 #include "DNA_scene_types.h"
30 
31 #include "BKE_gpencil.h"
32 #include "BKE_material.h"
33 
34 #include "ED_gpencil.h"
35 
37 
38 namespace blender::io::gpencil {
39 
40 /* Constructor. */
42 {
43  /* Nothing to do yet */
44 }
45 
47 {
48  const float *cur = scene_->cursor.location;
49  ushort local_view_bits = (params_.v3d && params_.v3d->localvd) ? params_.v3d->local_view_uuid :
50  (ushort)0;
51  Object *ob_gpencil = ED_gpencil_add_object(params_.C, cur, local_view_bits);
52 
53  return ob_gpencil;
54 }
55 
56 int32_t GpencilImporter::create_material(const char *name, const bool stroke, const bool fill)
57 {
58  const float default_stroke_color[4] = {0.0f, 0.0f, 0.0f, 1.0f};
59  const float default_fill_color[4] = {0.5f, 0.5f, 0.5f, 1.0f};
61  /* Stroke and Fill material. */
62  if (mat_index == -1) {
63  int32_t new_idx;
64  Material *mat_gp = BKE_gpencil_object_material_new(bmain_, params_.ob, name, &new_idx);
65  MaterialGPencilStyle *gp_style = mat_gp->gp_style;
66  gp_style->flag &= ~GP_MATERIAL_STROKE_SHOW;
67  gp_style->flag &= ~GP_MATERIAL_FILL_SHOW;
68 
69  copy_v4_v4(gp_style->stroke_rgba, default_stroke_color);
70  copy_v4_v4(gp_style->fill_rgba, default_fill_color);
71  if (stroke) {
72  gp_style->flag |= GP_MATERIAL_STROKE_SHOW;
73  }
74  if (fill) {
75  gp_style->flag |= GP_MATERIAL_FILL_SHOW;
76  }
77  mat_index = params_.ob->totcol - 1;
78  }
79 
80  return mat_index;
81 }
82 
83 } // namespace blender::io::gpencil
struct Material * BKE_gpencil_object_material_new(struct Main *bmain, struct Object *ob, const char *name, int *r_index)
Definition: gpencil.c:1873
int BKE_gpencil_material_find_index_by_name_prefix(struct Object *ob, const char *name_prefix)
Definition: gpencil.c:3031
General operations, lookup, etc. for materials.
MINLINE void copy_v4_v4(float r[4], const float a[4])
unsigned short ushort
Definition: BLI_sys_types.h:84
@ GP_MATERIAL_STROKE_SHOW
@ GP_MATERIAL_FILL_SHOW
Object is a sort of wrapper for general info.
GpencilImporter(const struct GpencilIOParams *iparams)
int32_t create_material(const char *name, const bool stroke, const bool fill)
Object * ED_gpencil_add_object(bContext *C, const float loc[3], ushort local_view_bits)
signed int int32_t
Definition: stdint.h:80
bContext * C
Definition: gpencil_io.h:35
View3D * v3d
Definition: gpencil_io.h:37
Object * ob
Definition: gpencil_io.h:39
struct MaterialGPencilStyle * gp_style
View3DCursor cursor
unsigned short local_view_uuid
struct View3D * localvd