Blender V4.3
blenkernel/intern/paint_canvas.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6#include "BLI_string.h"
7
9#include "DNA_mesh_types.h"
10#include "DNA_scene_types.h"
11
12#include "BKE_customdata.hh"
13#include "BKE_image.hh"
14#include "BKE_material.h"
15#include "BKE_paint.hh"
16
17#include "IMB_imbuf_types.hh"
18
19#include <sstream>
20
23{
25 if (mat == nullptr) {
26 return nullptr;
27 }
28 if (mat->texpaintslot == nullptr) {
29 return nullptr;
30 }
31 if (mat->paint_active_slot >= mat->tot_slots) {
32 return nullptr;
33 }
34
36 return slot;
37}
38
39} // namespace blender::bke::paint::canvas
40
41using namespace blender::bke::paint::canvas;
42
44 Object *ob,
45 Image **r_image,
46 ImageUser **r_image_user)
47{
48 *r_image = nullptr;
49 *r_image_user = nullptr;
50
51 switch (settings->canvas_source) {
53 break;
54
56 *r_image = settings->canvas_image;
57 *r_image_user = &settings->image_user;
58 break;
59
61 TexPaintSlot *slot = get_active_slot(ob);
62 if (slot == nullptr) {
63 break;
64 }
65
66 *r_image = slot->ima;
67 *r_image_user = slot->image_user;
68 break;
69 }
70 }
71 return *r_image != nullptr;
72}
73
75{
76 switch (settings->canvas_source) {
78 return -1;
80 /* Use active uv map of the object. */
81 if (ob->type != OB_MESH) {
82 return -1;
83 }
84
85 const Mesh *mesh = static_cast<Mesh *>(ob->data);
86 return CustomData_get_active_layer_index(&mesh->corner_data, CD_PROP_FLOAT2);
87 }
89 /* Use uv map of the canvas. */
90 TexPaintSlot *slot = get_active_slot(ob);
91 if (slot == nullptr) {
92 break;
93 }
94
95 if (ob->type != OB_MESH) {
96 return -1;
97 }
98
99 if (slot->uvname == nullptr) {
100 return -1;
101 }
102
103 const Mesh *mesh = static_cast<Mesh *>(ob->data);
104 return CustomData_get_named_layer_index(&mesh->corner_data, CD_PROP_FLOAT2, slot->uvname);
105 }
106 }
107 return -1;
108}
109
111{
112 std::stringstream ss;
113 int active_uv_map_layer_index = BKE_paint_canvas_uvmap_layer_index_get(settings, ob);
114 ss << "UV_MAP:" << active_uv_map_layer_index;
115
116 Image *image;
117 ImageUser *image_user;
118 if (BKE_paint_canvas_image_get(settings, ob, &image, &image_user)) {
119 ss << ",SEAM_MARGIN:" << image->seam_margin;
120 ImageUser tile_user = *image_user;
121 LISTBASE_FOREACH (ImageTile *, image_tile, &image->tiles) {
122 tile_user.tile = image_tile->tile_number;
123 ImBuf *image_buffer = BKE_image_acquire_ibuf(image, &tile_user, nullptr);
124 if (!image_buffer) {
125 continue;
126 }
127 ss << ",TILE_" << image_tile->tile_number;
128 ss << "(" << image_buffer->x << "," << image_buffer->y << ")";
129 BKE_image_release_ibuf(image, image_buffer, nullptr);
130 }
131 }
132
133 return BLI_strdup(ss.str().c_str());
134}
CustomData interface, see also DNA_customdata_types.h.
int CustomData_get_named_layer_index(const CustomData *data, eCustomDataType type, blender::StringRef name)
int CustomData_get_active_layer_index(const CustomData *data, eCustomDataType type)
ImBuf * BKE_image_acquire_ibuf(Image *ima, ImageUser *iuser, void **r_lock)
void BKE_image_release_ibuf(Image *ima, ImBuf *ibuf, void *lock)
General operations, lookup, etc. for materials.
struct Material * BKE_object_material_get(struct Object *ob, short act)
#define LISTBASE_FOREACH(type, var, list)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
Definition string.c:40
@ CD_PROP_FLOAT2
@ OB_MESH
@ PAINT_CANVAS_SOURCE_COLOR_ATTRIBUTE
@ PAINT_CANVAS_SOURCE_IMAGE
@ PAINT_CANVAS_SOURCE_MATERIAL
Contains defines and structs used throughout the imbuf module.
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 PaintModeSettings *settings, Object *ob)
char * BKE_paint_canvas_key_get(PaintModeSettings *settings, Object *ob)
input_tx image(0, GPU_RGBA16F, Qualifier::WRITE, ImageType::FLOAT_2D, "preview_img") .compute_source("compositor_compute_preview.glsl") .do_static_compilation(true)
static TexPaintSlot * get_active_slot(Object *ob)
short paint_active_slot
struct TexPaintSlot * texpaintslot
struct Image * ima
struct ImageUser * image_user