Blender V4.3
editors/sculpt_paint/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
7#include "DNA_brush_types.h"
9#include "DNA_scene_types.h"
10#include "DNA_workspace_types.h"
11
12#include "BKE_context.hh"
13#include "BKE_material.h"
14#include "BKE_paint.hh"
15
16#include "WM_toolsystem.hh"
17
18#include "ED_paint.hh"
19
22{
24 if (mat == nullptr) {
25 return nullptr;
26 }
27 if (mat->texpaintslot == nullptr) {
28 return nullptr;
29 }
30 if (mat->paint_active_slot >= mat->tot_slots) {
31 return nullptr;
32 }
33
35 return slot;
36}
37
38} // namespace blender::ed::sculpt_paint::canvas
39
41
42/* Does the paint tool with the given idname use a canvas. */
44{
45 return ELEM(idname, "builtin.color_filter");
46}
47
49{
51 const Brush *brush = BKE_paint_brush_for_read(paint);
52 if (brush == nullptr) {
53 return false;
54 }
55
57}
58
60{
61 /* TODO(jbakker): complete this list. */
62 return ELEM(idname, "builtin_brush.Mask");
63}
64
66{
67 if (ob == nullptr || ob->sculpt == nullptr) {
68 return;
69 }
70
72 if (tref == nullptr) {
73 return;
74 }
75 /* Do not modify when tool follows lat used tool. */
77 return;
78 }
79
82}
83
85{
86 if (ob == nullptr || ob->sculpt == nullptr) {
87 return false;
88 }
89
91 if (tref == nullptr) {
92 return false;
93 }
94
96}
97
99{
100 if (tref == nullptr) {
102 }
103 if (tref == nullptr) {
104 return false;
105 }
106
108}
109
111 const PaintModeSettings *settings,
112 Object &ob,
113 eV3DShadingColorType orig_color_type)
114{
115 if (!U.experimental.use_sculpt_texture_paint) {
116 return orig_color_type;
117 }
118 /* NOTE: This early exit is temporarily, until a paint mode has been added.
119 * For better integration with the vertex paint in sculpt mode we sticky
120 * with the last stoke when using tools like masking.
121 */
122 if (!ED_image_paint_brush_type_use_canvas(C, nullptr) &&
125 {
126 return orig_color_type;
127 }
128
129 eV3DShadingColorType color_type = orig_color_type;
130 switch (settings->canvas_source) {
132 color_type = V3D_SHADING_VERTEX_COLOR;
133 break;
135 color_type = V3D_SHADING_TEXTURE_COLOR;
136 break;
138 TexPaintSlot *slot = get_active_slot(ob);
139 if (slot == nullptr) {
140 break;
141 }
142
143 if (slot->ima) {
144 color_type = V3D_SHADING_TEXTURE_COLOR;
145 }
146 if (slot->attribute_name) {
147 color_type = V3D_SHADING_VERTEX_COLOR;
148 }
149
150 break;
151 }
152 }
153
154 return color_type;
155}
General operations, lookup, etc. for materials.
struct Material * BKE_object_material_get(struct Object *ob, short act)
const Brush * BKE_paint_brush_for_read(const Paint *paint)
Definition paint.cc:654
Paint * BKE_paint_get_active_from_context(const bContext *C)
Definition paint.cc:477
#define ELEM(...)
@ SCULPT_BRUSH_TYPE_SMEAR
@ SCULPT_BRUSH_TYPE_PAINT
@ PAINT_CANVAS_SOURCE_COLOR_ATTRIBUTE
@ PAINT_CANVAS_SOURCE_IMAGE
@ PAINT_CANVAS_SOURCE_MATERIAL
eV3DShadingColorType
@ V3D_SHADING_TEXTURE_COLOR
@ V3D_SHADING_VERTEX_COLOR
unsigned int U
Definition btGjkEpa3.h:78
eV3DShadingColorType ED_paint_shading_color_override(bContext *C, const PaintModeSettings *settings, Object &ob, eV3DShadingColorType orig_color_type)
static bool image_paint_brush_uses_canvas(bContext *C)
static bool image_paint_brush_type_shading_color_follows_last_used_tool(bContext *C, Object *ob)
static bool image_paint_brush_type_shading_color_follows_last_used(blender::StringRef idname)
void ED_image_paint_brush_type_update_sticky_shading_color(bContext *C, Object *ob)
static bool image_paint_tool_uses_canvas(blender::StringRef idname)
bool ED_image_paint_brush_type_use_canvas(bContext *C, bToolRef *tref)
static TexPaintSlot * get_active_slot(Object &ob)
char sculpt_brush_type
short paint_active_slot
struct TexPaintSlot * texpaintslot
struct SculptSession * sculpt
bool sticky_shading_color
Definition BKE_paint.hh:505
struct Image * ima
bToolRef * WM_toolsystem_ref_from_context(const bContext *C)