Blender V5.3
editors/sculpt_paint/mesh/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
8
9#include "BLI_string_ref.hh"
10
11#include "DNA_brush_types.h"
12#include "DNA_material_types.h"
13#include "DNA_scene_types.h"
14#include "DNA_userdef_types.h"
15#include "DNA_workspace_types.h"
16
17#include "BKE_context.hh"
18#include "BKE_material.hh"
19#include "BKE_object_types.hh"
20#include "BKE_paint.hh"
21
22#include "WM_toolsystem.hh"
23
24#include "ED_paint.hh"
25
26namespace blender {
27
30{
32 if (mat == nullptr) {
33 return nullptr;
34 }
35 if (mat->texpaintslot == nullptr) {
36 return nullptr;
37 }
38 if (mat->paint_active_slot >= mat->tot_slots) {
39 return nullptr;
40 }
41
42 TexPaintSlot *slot = &mat->texpaintslot[mat->paint_active_slot];
43 return slot;
44}
45
46} // namespace ed::sculpt_paint::canvas
47
49
50/* Does the paint tool with the given idname use a canvas. */
52{
53 return ELEM(idname, "builtin.color_filter");
54}
55
57{
60 if (brush == nullptr) {
61 return false;
62 }
63
64 return ELEM(brush->sculpt_brush_type,
68}
69
71{
72 /* TODO(jbakker): complete this list. */
73 return ELEM(idname, "builtin_brush.Mask");
74}
75
77{
78 if (ob == nullptr || ob->runtime->sculpt_session == nullptr) {
79 return;
80 }
81
83 if (tref == nullptr) {
84 return;
85 }
86 /* Do not modify when tool follows lat used tool. */
88 return;
89 }
90
93}
94
96{
97 if (ob == nullptr || ob->runtime->sculpt_session == nullptr) {
98 return false;
99 }
100
102 if (tref == nullptr) {
103 return false;
104 }
105
107}
108
110{
111 BLI_assert(C || tref);
112
113 if (tref == nullptr) {
115 }
116 if (tref == nullptr) {
117 return false;
118 }
119
121}
122
124 const PaintModeSettings *settings,
125 Object &ob,
126 eV3DShadingColorType orig_color_type)
127{
128 if (!USER_EXPERIMENTAL_TEST(&U, use_3d_texture_paint)) {
129 return orig_color_type;
130 }
131 /* NOTE: This early exit is temporarily, until a paint mode has been added.
132 * For better integration with the vertex paint in sculpt mode we sticky
133 * with the last stoke when using tools like masking.
134 */
135 if (!ED_paint_brush_type_use_canvas(C, nullptr) &&
138 {
139 return orig_color_type;
140 }
141
142 eV3DShadingColorType color_type = orig_color_type;
143 switch (settings->canvas_source) {
145 color_type = V3D_SHADING_VERTEX_COLOR;
146 break;
148 color_type = V3D_SHADING_TEXTURE_COLOR;
149 break;
151 TexPaintSlot *slot = get_active_slot(ob);
152 if (slot == nullptr) {
153 break;
154 }
155
156 if (slot->ima) {
157 color_type = V3D_SHADING_TEXTURE_COLOR;
158 }
159 if (slot->attribute_name) {
160 color_type = V3D_SHADING_VERTEX_COLOR;
161 }
162
163 break;
164 }
165 }
166
167 return color_type;
168}
169
170} // namespace blender
General operations, lookup, etc. for materials.
#define USER_EXPERIMENTAL_TEST(userdef, member)
#define C
Definition RandGen.cpp:29
#define ELEM(...)
static TexPaintSlot * get_active_slot(Object *ob)
BMesh Iterators.
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
Material * BKE_object_material_get(Object *ob, short act)
void ED_paint_brush_type_update_sticky_shading_color(bContext *C, Object *ob)
static bool paint_brush_type_shading_color_follows_last_used_tool(bContext *C, Object *ob)
bool ED_paint_brush_type_use_canvas(bContext *C, bToolRef *tref)
@ SCULPT_BRUSH_TYPE_SMEAR
@ SCULPT_BRUSH_TYPE_BLUR
@ SCULPT_BRUSH_TYPE_PAINT
static bool paint_brush_type_shading_color_follows_last_used(StringRef idname)
static bool paint_brush_uses_canvas(bContext *C)
eV3DShadingColorType ED_paint_shading_color_override(bContext *C, const PaintModeSettings *settings, Object &ob, eV3DShadingColorType orig_color_type)
@ V3D_SHADING_VERTEX_COLOR
@ V3D_SHADING_TEXTURE_COLOR
const Brush * BKE_paint_brush_for_read(const Paint *paint)
bToolRef * WM_toolsystem_ref_from_context(const bContext *C)
Paint * BKE_paint_get_active_from_context(const bContext *C)
@ PAINT_CANVAS_SOURCE_IMAGE
@ PAINT_CANVAS_SOURCE_MATERIAL
@ PAINT_CANVAS_SOURCE_COLOR_ATTRIBUTE
static bool paint_tool_uses_canvas(StringRef idname)
bke::ObjectRuntime * runtime
ePaintCanvasSource canvas_source