Blender V5.0
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
5#include "BLI_string_ref.hh"
6
7#include "DNA_brush_types.h"
9#include "DNA_scene_types.h"
10#include "DNA_userdef_types.h"
11#include "DNA_workspace_types.h"
12
13#include "BKE_context.hh"
14#include "BKE_material.hh"
15#include "BKE_paint.hh"
16
17#include "WM_toolsystem.hh"
18
19#include "ED_paint.hh"
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::ed::sculpt_paint::canvas
40
42
43/* Does the paint tool with the given idname use a canvas. */
45{
46 return ELEM(idname, "builtin.color_filter");
47}
48
50{
52 const Brush *brush = BKE_paint_brush_for_read(paint);
53 if (brush == nullptr) {
54 return false;
55 }
56
58}
59
61{
62 /* TODO(jbakker): complete this list. */
63 return ELEM(idname, "builtin_brush.Mask");
64}
65
67{
68 if (ob == nullptr || ob->sculpt == nullptr) {
69 return;
70 }
71
73 if (tref == nullptr) {
74 return;
75 }
76 /* Do not modify when tool follows lat used tool. */
78 return;
79 }
80
83}
84
86{
87 if (ob == nullptr || ob->sculpt == nullptr) {
88 return false;
89 }
90
92 if (tref == nullptr) {
93 return false;
94 }
95
97}
98
100{
101 if (tref == nullptr) {
103 }
104 if (tref == nullptr) {
105 return false;
106 }
107
109}
110
112 const PaintModeSettings *settings,
113 Object &ob,
114 eV3DShadingColorType orig_color_type)
115{
116 if (!USER_EXPERIMENTAL_TEST(&U, use_sculpt_texture_paint)) {
117 return orig_color_type;
118 }
119 /* NOTE: This early exit is temporarily, until a paint mode has been added.
120 * For better integration with the vertex paint in sculpt mode we sticky
121 * with the last stoke when using tools like masking.
122 */
126 {
127 return orig_color_type;
128 }
129
130 eV3DShadingColorType color_type = orig_color_type;
131 switch (settings->canvas_source) {
133 color_type = V3D_SHADING_VERTEX_COLOR;
134 break;
136 color_type = V3D_SHADING_TEXTURE_COLOR;
137 break;
139 TexPaintSlot *slot = get_active_slot(ob);
140 if (slot == nullptr) {
141 break;
142 }
143
144 if (slot->ima) {
145 color_type = V3D_SHADING_TEXTURE_COLOR;
146 }
147 if (slot->attribute_name) {
148 color_type = V3D_SHADING_VERTEX_COLOR;
149 }
150
151 break;
152 }
153 }
154
155 return color_type;
156}
General operations, lookup, etc. for materials.
Material * BKE_object_material_get(Object *ob, short act)
const Brush * BKE_paint_brush_for_read(const Paint *paint)
Definition paint.cc:650
Paint * BKE_paint_get_active_from_context(const bContext *C)
Definition paint.cc:476
#define ELEM(...)
@ SCULPT_BRUSH_TYPE_SMEAR
@ SCULPT_BRUSH_TYPE_PAINT
@ PAINT_CANVAS_SOURCE_COLOR_ATTRIBUTE
@ PAINT_CANVAS_SOURCE_IMAGE
@ PAINT_CANVAS_SOURCE_MATERIAL
#define USER_EXPERIMENTAL_TEST(userdef, member)
eV3DShadingColorType
@ V3D_SHADING_TEXTURE_COLOR
@ V3D_SHADING_VERTEX_COLOR
#define C
Definition RandGen.cpp:29
#define U
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:509
struct Image * ima
bToolRef * WM_toolsystem_ref_from_context(const bContext *C)