Blender  V3.3
gpencil_io_import_base.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2020 Blender Foundation. All rights reserved. */
3 
7 #include "BLI_math_vector.h"
8 
9 #include "DNA_material_types.h"
10 #include "DNA_object_types.h"
11 #include "DNA_scene_types.h"
12 
13 #include "BKE_gpencil.h"
14 #include "BKE_material.h"
15 
16 #include "ED_gpencil.h"
17 #include "ED_object.h"
18 
20 
21 namespace blender::io::gpencil {
22 
23 /* Constructor. */
25 {
26  /* Nothing to do yet */
27 }
28 
30 {
31  const float *cur_loc = scene_->cursor.location;
32  const float rot[3] = {0.0f};
33  ushort local_view_bits = (params_.v3d && params_.v3d->localvd) ? params_.v3d->local_view_uuid :
34  (ushort)0;
35 
36  Object *ob_gpencil = ED_object_add_type(params_.C,
37  OB_GPENCIL,
38  (params_.filename[0] != '\0') ? params_.filename :
39  nullptr,
40  cur_loc,
41  rot,
42  false,
43  local_view_bits);
44 
45  /* Set object defaults. */
46  ED_gpencil_add_defaults(params_.C, ob_gpencil);
47 
48  return ob_gpencil;
49 }
50 
51 int32_t GpencilImporter::create_material(const char *name, const bool stroke, const bool fill)
52 {
53  const float default_stroke_color[4] = {0.0f, 0.0f, 0.0f, 1.0f};
54  const float default_fill_color[4] = {0.5f, 0.5f, 0.5f, 1.0f};
56  /* Stroke and Fill material. */
57  if (mat_index == -1) {
58  int32_t new_idx;
59  Material *mat_gp = BKE_gpencil_object_material_new(bmain_, params_.ob, name, &new_idx);
60  MaterialGPencilStyle *gp_style = mat_gp->gp_style;
61  gp_style->flag &= ~GP_MATERIAL_STROKE_SHOW;
62  gp_style->flag &= ~GP_MATERIAL_FILL_SHOW;
63 
64  copy_v4_v4(gp_style->stroke_rgba, default_stroke_color);
65  copy_v4_v4(gp_style->fill_rgba, default_fill_color);
66  if (stroke) {
67  gp_style->flag |= GP_MATERIAL_STROKE_SHOW;
68  }
69  if (fill) {
70  gp_style->flag |= GP_MATERIAL_FILL_SHOW;
71  }
72  mat_index = params_.ob->totcol - 1;
73  }
74 
75  return mat_index;
76 }
77 
78 } // 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:1734
int BKE_gpencil_material_find_index_by_name_prefix(struct Object *ob, const char *name_prefix)
Definition: gpencil.c:2855
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:68
@ GP_MATERIAL_STROKE_SHOW
@ GP_MATERIAL_FILL_SHOW
Object is a sort of wrapper for general info.
@ OB_GPENCIL
struct Object * ED_object_add_type(struct bContext *C, int type, const char *name, const float loc[3], const float rot[3], bool enter_editmode, unsigned short local_view_bits) ATTR_NONNULL(1) ATTR_RETURNS_NONNULL
Definition: object_add.cc:668
GpencilImporter(const struct GpencilIOParams *iparams)
int32_t create_material(const char *name, bool stroke, bool fill)
#define rot(x, k)
void ED_gpencil_add_defaults(bContext *C, Object *ob)
signed int int32_t
Definition: stdint.h:77
char filename[128]
Definition: gpencil_io.h:39
bContext * C
Definition: gpencil_io.h:19
View3D * v3d
Definition: gpencil_io.h:21
Object * ob
Definition: gpencil_io.h:23
struct MaterialGPencilStyle * gp_style
View3DCursor cursor
unsigned short local_view_uuid
struct View3D * localvd