Blender  V3.3
blenkernel/intern/paint_canvas.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 #include "BLI_compiler_compat.h"
3 
4 #include "DNA_material_types.h"
5 #include "DNA_mesh_types.h"
6 #include "DNA_scene_types.h"
7 
8 #include "BKE_customdata.h"
9 #include "BKE_image.h"
10 #include "BKE_material.h"
11 #include "BKE_paint.h"
12 
13 #include "IMB_imbuf_types.h"
14 
17 {
18  Material *mat = BKE_object_material_get(ob, ob->actcol);
19  if (mat == nullptr) {
20  return nullptr;
21  }
22  if (mat->texpaintslot == nullptr) {
23  return nullptr;
24  }
25  if (mat->paint_active_slot >= mat->tot_slots) {
26  return nullptr;
27  }
28 
29  TexPaintSlot *slot = &mat->texpaintslot[mat->paint_active_slot];
30  return slot;
31 }
32 
33 } // namespace blender::bke::paint::canvas
34 
35 extern "C" {
36 
37 using namespace blender::bke::paint::canvas;
38 
40  Object *ob,
41  Image **r_image,
42  ImageUser **r_image_user)
43 {
44  *r_image = nullptr;
45  *r_image_user = nullptr;
46 
47  switch (settings->canvas_source) {
49  break;
50 
52  *r_image = settings->canvas_image;
53  *r_image_user = &settings->image_user;
54  break;
55 
57  TexPaintSlot *slot = get_active_slot(ob);
58  if (slot == nullptr) {
59  break;
60  }
61 
62  *r_image = slot->ima;
63  *r_image_user = slot->image_user;
64  break;
65  }
66  }
67  return *r_image != nullptr;
68 }
69 
71  struct Object *ob)
72 {
73  switch (settings->canvas_source) {
75  return -1;
77  /* Use active uv map of the object. */
78  if (ob->type != OB_MESH) {
79  return -1;
80  }
81 
82  const Mesh *mesh = static_cast<Mesh *>(ob->data);
84  }
86  /* Use uv map of the canvas. */
87  TexPaintSlot *slot = get_active_slot(ob);
88  if (slot == nullptr) {
89  break;
90  }
91 
92  if (ob->type != OB_MESH) {
93  return -1;
94  }
95 
96  if (slot->uvname == nullptr) {
97  return -1;
98  }
99 
100  const Mesh *mesh = static_cast<Mesh *>(ob->data);
102  }
103  }
104  return -1;
105 }
106 
107 char *BKE_paint_canvas_key_get(struct PaintModeSettings *settings, struct Object *ob)
108 {
109  std::stringstream ss;
110  int active_uv_map_layer_index = BKE_paint_canvas_uvmap_layer_index_get(settings, ob);
111  ss << "UV_MAP:" << active_uv_map_layer_index;
112 
113  Image *image;
114  ImageUser *image_user;
115  if (BKE_paint_canvas_image_get(settings, ob, &image, &image_user)) {
116  ImageUser tile_user = *image_user;
117  LISTBASE_FOREACH (ImageTile *, image_tile, &image->tiles) {
118  tile_user.tile = image_tile->tile_number;
119  ImBuf *image_buffer = BKE_image_acquire_ibuf(image, &tile_user, nullptr);
120  if (!image_buffer) {
121  continue;
122  }
123  ss << ",TILE_" << image_tile->tile_number;
124  ss << "(" << image_buffer->x << "," << image_buffer->y << ")";
125  BKE_image_release_ibuf(image, image_buffer, nullptr);
126  }
127  }
128 
129  return BLI_strdup(ss.str().c_str());
130 }
131 }
CustomData interface, see also DNA_customdata_types.h.
int CustomData_get_active_layer_index(const struct CustomData *data, int type)
int CustomData_get_named_layer_index(const struct CustomData *data, int type, const char *name)
void BKE_image_release_ibuf(struct Image *ima, struct ImBuf *ibuf, void *lock)
struct ImBuf * BKE_image_acquire_ibuf(struct Image *ima, struct ImageUser *iuser, void **r_lock)
General operations, lookup, etc. for materials.
struct Material * BKE_object_material_get(struct Object *ob, short act)
Definition: material.c:687
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
Definition: string.c:42
@ CD_MLOOPUV
@ OB_MESH
@ PAINT_CANVAS_SOURCE_COLOR_ATTRIBUTE
@ PAINT_CANVAS_SOURCE_IMAGE
@ PAINT_CANVAS_SOURCE_MATERIAL
Contains defines and structs used throughout the imbuf module.
char * BKE_paint_canvas_key_get(struct PaintModeSettings *settings, struct Object *ob)
bool BKE_paint_canvas_image_get(PaintModeSettings *settings, Object *ob, Image **r_image, ImageUser **r_image_user)
int BKE_paint_canvas_uvmap_layer_index_get(const struct PaintModeSettings *settings, struct Object *ob)
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx in_weight_img image(1, GPU_R32F, Qualifier::WRITE, ImageType::FLOAT_2D_ARRAY, "out_weight_img") .image(3
static TexPaintSlot * get_active_slot(Object *ob)
short paint_active_slot
struct TexPaintSlot * texpaintslot
CustomData ldata
void * data
struct Image * ima
struct ImageUser * image_user