Blender  V3.3
editors/sculpt_paint/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_scene_types.h"
6 #include "DNA_workspace_types.h"
7 
8 #include "BKE_material.h"
9 #include "BKE_paint.h"
10 
11 #include "WM_toolsystem.h"
12 
13 #include "ED_paint.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::ed::sculpt_paint::canvas
34 
35 extern "C" {
36 
37 using namespace blender::ed::sculpt_paint::canvas;
38 
39 /* Does the paint tool with the given idname uses a canvas. */
41 {
42  return ELEM(idname, "builtin_brush.Paint", "builtin_brush.Smear", "builtin.color_filter");
43 }
44 
46 {
47  /* TODO(jbakker): complete this list. */
48  return ELEM(idname, "builtin_brush.Mask");
49 }
50 
52 {
53  if (ob == nullptr || ob->sculpt == nullptr) {
54  return;
55  }
56 
58  if (tref == nullptr) {
59  return;
60  }
61  /* Do not modify when tool follows lat used tool. */
63  return;
64  }
65 
67 }
68 
70 {
71  if (ob == nullptr || ob->sculpt == nullptr) {
72  return false;
73  }
74 
76  if (tref == nullptr) {
77  return false;
78  }
79 
81 }
82 
84 {
85  if (tref == nullptr) {
87  }
88  if (tref == nullptr) {
89  return false;
90  }
91 
92  return paint_tool_uses_canvas(tref->idname);
93 }
94 
96  const PaintModeSettings *settings,
97  Object *ob,
98  eV3DShadingColorType orig_color_type)
99 {
100  if (!U.experimental.use_sculpt_texture_paint) {
101  return orig_color_type;
102  }
103  /* NOTE: This early exit is temporarily, until a paint mode has been added.
104  * For better integration with the vertex paint in sculpt mode we sticky
105  * with the last stoke when using tools like masking.
106  */
107  if (!ED_paint_tool_use_canvas(C, nullptr) &&
110  return orig_color_type;
111  }
112 
113  eV3DShadingColorType color_type = orig_color_type;
114  switch (settings->canvas_source) {
116  color_type = V3D_SHADING_VERTEX_COLOR;
117  break;
119  color_type = V3D_SHADING_TEXTURE_COLOR;
120  break;
122  TexPaintSlot *slot = get_active_slot(ob);
123  if (slot == nullptr) {
124  break;
125  }
126 
127  if (slot->ima) {
128  color_type = V3D_SHADING_TEXTURE_COLOR;
129  }
130  if (slot->attribute_name) {
131  color_type = V3D_SHADING_VERTEX_COLOR;
132  }
133 
134  break;
135  }
136  }
137 
138  return color_type;
139 }
140 }
General operations, lookup, etc. for materials.
struct Material * BKE_object_material_get(struct Object *ob, short act)
Definition: material.c:687
#define ELEM(...)
@ PAINT_CANVAS_SOURCE_COLOR_ATTRIBUTE
@ PAINT_CANVAS_SOURCE_IMAGE
@ PAINT_CANVAS_SOURCE_MATERIAL
eV3DShadingColorType
@ V3D_SHADING_TEXTURE_COLOR
@ V3D_SHADING_VERTEX_COLOR
#define C
Definition: RandGen.cpp:25
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 paint_tool_shading_color_follows_last_used(blender::StringRef idname)
static bool paint_tool_uses_canvas(blender::StringRef idname)
void ED_paint_tool_update_sticky_shading_color(struct bContext *C, struct Object *ob)
bool ED_paint_tool_use_canvas(struct bContext *C, bToolRef *tref)
static bool paint_tool_shading_color_follows_last_used_tool(struct bContext *C, struct Object *ob)
static TexPaintSlot * get_active_slot(Object *ob)
short paint_active_slot
struct TexPaintSlot * texpaintslot
struct SculptSession * sculpt
bool sticky_shading_color
Definition: BKE_paint.h:659
struct Image * ima
char idname[64]
struct bToolRef * WM_toolsystem_ref_from_context(struct bContext *C)
Definition: wm_toolsystem.c:57