87 const Span<int3> tris = mesh_eval->corner_tris();
88 const Span<int> tri_faces = mesh_eval->corner_tri_faces();
95 const int face_i = tri_faces[tri_index];
101 const TexPaintSlot *slot = &ma->texpaintslot[ma->paint_active_slot];
102 if (slot && slot->
uvname) {
123 if (
mesh.faces_num == 0) {
132 const float4x4 &world_to_object = vc->
obact->world_to_object();
138 const std::optional<bke::bvh::RayHit> ray_hit = mesh_bvh.
ray_intersect(ray);
144 mesh.vert_positions(),
146 mesh.corner_tris()[ray_hit->index],
147 ray_hit->position(ray));
149 *r_tri_index = ray_hit->index;
150 *r_face_index =
mesh.corner_tri_faces()[ray_hit->index];
168 if (mesh_eval->uv_map_names().is_empty()) {
175 const VArray<bool> hide_poly = *mesh_eval->attributes().lookup_or_default<
bool>(
178 &vc, mval, &tri_index, &face_index, &
bary_coord, *mesh_eval) &&
179 !hide_poly[face_index];
196 if (ma && ma->texpaintslot) {
197 image = ma->texpaintslot[ma->paint_active_slot].ima;
198 interp = ma->texpaintslot[ma->paint_active_slot].interp;
230 float u =
uv[0] * ibuf->
x;
231 float v =
uv[1] * ibuf->
y;
268 if (!color_attribute || !active_element || !std::holds_alternative<int>(active_element->vert)) {
273 const int vert = std::get<int>(active_element->vert);
274 const int face = active_element->active_face_idx;
279 return sampled_color.xyz();
283 faces, corner_verts, vert_to_face_map, colors, color_attribute.
domain, vert)
291 const float3 &sampled_color,
292 const bool use_palette)
314 const bool use_merged_texture)
325 std::optional<float3> sampled_color;
326 if (v3d && !use_merged_texture) {
341 else if (sima !=
nullptr) {
347 sampled_color = rgba_f;
352 if (!sampled_color) {
363 sampled_color = rgb_f;
367 return sampled_color.value_or(
float3(0.0f));
386 IFACE_(
"Sample color for %s"),
387 !
data->sample_palette ?
388 IFACE_(
"Brush. Use Left Click to sample for palette instead") :
389 IFACE_(
"Palette. Use Left Click to sample more colors"));
396 if (
data ==
nullptr) {
397 return sampled_color;
400 data->accum_color += sampled_color;
433 location.x = std::clamp(location.x, 0,
int(region->
winx));
434 location.y = std::clamp(location.y, 0,
int(region->
winy));
473 data->sample_palette =
false;
478 data->num_samples = 0;
490 int2 mval(std::clamp(event->
mval[0], 0,
int(region->
winx)),
491 std::clamp(event->
mval[1], 0,
int(region->
winy)));
512 if (
data->show_cursor) {
516 if (
data->sample_palette) {
529 int2 mval(std::clamp(event->
mval[0], 0,
int(region->
winx)),
530 std::clamp(event->
mval[1], 0,
int(region->
winy)));
534 switch (event->
type) {
550 if (!
data->sample_palette) {
551 data->sample_palette =
true;
580 ot->
name =
"Sample Color";
581 ot->
idname =
"PAINT_OT_sample_color";
582 ot->
description =
"Use the mouse to sample a color in the image";
597 ot->
srna,
"location", 2,
nullptr, 0,
INT_MAX,
"Location",
"", 0, 16384);
600 RNA_def_boolean(ot->
srna,
"merged",
false,
"Sample Merged",
"Sample the output display color");
CustomData interface, see also DNA_customdata_types.h.
General operations, lookup, etc. for materials.
General operations, lookup, etc. for blender objects.
#define BLI_SCOPED_DEFER(function_to_defer)
#define SNPRINTF_UTF8(dst, format,...)
Object is a sort of wrapper for general info.
#define IMAGEPAINT_MODE_MATERIAL
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
GAttributeReader lookup(const StringRef name) const
std::optional< RayHit > ray_intersect(const Ray &ray) const
constexpr bool is_empty() const
ccl_device_inline float interp(const float a, const float b, const float t)
float3 compute_bary_coord_in_triangle(Span< float3 > vert_positions, Span< int > corner_verts, const int3 &corner_tri, const float3 &position)
T sample_corner_attribute_with_bary_coords(const float3 &bary_weights, const int3 &corner_tri, const Span< T > corner_attribute)
int face_find_corner_from_vert(const IndexRange face, const Span< int > corner_verts, const int vert)
bool grease_pencil_vertex_painting_poll(bContext *C)
bool grease_pencil_painting_poll(bContext *C)
float4 color_vert_get(OffsetIndices< int > faces, Span< int > corner_verts, GroupedSpan< int > vert_to_face_map, GSpan color_attribute, bke::AttrDomain color_domain, int vert)
bke::GAttributeReader active_color_attribute(const Mesh &mesh)
float4 color_corner_get(const GSpan color_attribute, int corner_index)
void PAINT_OT_sample_color(wmOperatorType *ot)
static void apply_sampled_color(Main &bMain, Paint &paint, const float3 &sampled_color, const bool use_palette)
static wmOperatorStatus sample_color_exec(bContext *C, wmOperator *op)
static void sample_color_update_header(SampleColorData *data, bContext *C)
static float3 paint_sample_color(bContext *C, ARegion *region, const int2 mval, const bool use_merged_texture)
bool sculpt_mode_poll(bContext *C)
static wmOperatorStatus sample_color_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static bool imapaint_pick_face(ViewContext *vc, const int mval[2], int *r_tri_index, int *r_face_index, float3 *r_bary_coord, const Mesh &mesh)
bool color_supported_check(const Scene &scene, Object &object, ReportList *reports)
static wmOperatorStatus sample_color_modal(bContext *C, wmOperator *op, const wmEvent *event)
static std::optional< float3 > sample_mesh_attribute_color(ViewContext &vc, Object &object, int2 mval)
std::optional< ActiveElementInfo > active_element_info_get(ViewContext &vc, const float2 &mval)
static bool sample_color_poll(bContext *C)
static float3 sample_average_color(SampleColorData *data, const float3 &sampled_color)
static std::optional< float3 > sample_texture_paint_color(const Depsgraph &depsgraph, Scene &scene, ViewContext &vc, Object *object, const int2 mval)
static float2 imapaint_pick_uv(const Mesh *mesh_eval, Scene &scene, Object *ob_eval, const int tri_index, const float3 &bary_coord)
uchar4 interpolate_nearest_wrap_byte(const ImBuf *in, float u, float v)
uchar4 interpolate_bilinear_wrap_byte(const ImBuf *in, float u, float v)
float4 interpolate_nearest_wrap_fl(const ImBuf *in, float u, float v)
float4 interpolate_bilinear_wrap_fl(const ImBuf *in, float u, float v)
T clamp(const T &a, const T &min, const T &max)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
int BKE_image_get_tile_from_pos(Image *ima, const float uv[2], float r_uv[2], float r_ofs[2])
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
VecBase< uint8_t, 4 > uchar4
ScrArea * CTX_wm_area(const bContext *C)
void BKE_palette_color_set(PaletteColor *color, const float rgb[3])
MINLINE void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
ViewContext ED_view3d_viewcontext_init(bContext *C, Depsgraph *depsgraph)
bool vertex_paint_poll_ignore_tool(bContext *C)
Material * BKE_object_material_get(Object *ob, short act)
void WM_cursor_modal_set(wmWindow *win, int val)
PropertyRNA * RNA_def_int_vector(StructOrFunctionRNA *cont_, const char *identifier, const int len, const int *default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
wmWindow * CTX_wm_window(const bContext *C)
ATTR_WARN_UNUSED_RESULT const BMVert * v
MatBase< float, 4, 4 > float4x4
ViewLayer * CTX_data_view_layer(const bContext *C)
VecBase< float, 4 > float4
void IMB_colormanagement_colorspace_to_scene_linear_v3(float pixel[3], const ColorSpace *colorspace)
void RNA_int_set_array(PointerRNA *ptr, const char *name, const int *values)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma, const Object *ob)
bool WM_window_pixels_read_sample(bContext *C, wmWindow *win, const int pos[2], float r_col[3])
void BKE_report(ReportList *reports, eReportType type, const char *message)
BMesh const char void * data
void RNA_int_get_array(PointerRNA *ptr, const char *name, int *values)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
Palette * BKE_paint_palette(Paint *paint)
void BKE_brush_color_set(Paint *paint, Brush *brush, const float3 &color)
void WM_cursor_modal_restore(wmWindow *win)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
void WM_redraw_windows(bContext *C)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void IMB_colormanagement_display_to_scene_linear_v3(float pixel[3], const ColorManagedDisplay *display, ColorManagedDisplaySpace display_space=DISPLAY_SPACE_DRAW)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
PaletteColor * BKE_palette_color_add(Palette *palette)
ImBuf * BKE_image_acquire_ibuf(Image *ima, ImageUser *iuser, void **r_lock)
SpaceImage * CTX_wm_space_image(const bContext *C)
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Main * CTX_data_main(const bContext *C)
Paint * BKE_paint_get_active_from_context(const bContext *C)
bool ED_view3d_win_to_segment_clipped(const Depsgraph *depsgraph, const ARegion *region, const View3D *v3d, const float mval[2], float r_ray_start[3], float r_ray_end[3], bool do_clip_planes)
@ PAINT_CANVAS_SOURCE_MATERIAL
void BKE_sculptsession_update_for_edit(Depsgraph *depsgraph, Object *ob_orig, bool is_paint_tool)
Brush * BKE_paint_brush(Paint *paint)
Scene * CTX_data_scene(const bContext *C)
float3 BKE_brush_color_get(const Paint *paint, const Brush *brush)
const ColorManagedDisplay * IMB_colormanagement_display_get_named(const char *name)
@ OPTYPE_DEPENDS_ON_CURSOR
VecBase< float, 3 > float3
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
int WM_userdef_event_type_from_keymap_type(int kmitype)
void BKE_imageuser_default(ImageUser *iuser)
Object * CTX_data_active_object(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
void ED_workspace_status_text(bContext *C, const char *str)
PaintMode BKE_paintmode_get_active_from_context(const bContext *C)
void BKE_paint_palette_set(Paint *paint, Palette *palette)
MINLINE void straight_to_premul_v4(float color[4])
View3D * CTX_wm_view3d(const bContext *C)
bool image_paint_poll_ignore_tool(bContext *C)
void WM_paint_cursor_tag_redraw(wmWindow *win, ARegion *)
bool ED_space_image_color_sample(SpaceImage *sima, ARegion *region, const int mval[2], float r_col[3], bool *r_is_data)
ocio::Display ColorManagedDisplay
Mesh * BKE_object_get_evaluated_mesh(const Object *object_eval)
Palette * BKE_palette_add(Main *bmain, const char *name)
void BKE_image_release_ibuf(Image *ima, ImBuf *ibuf, void *lock)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
const ColorSpace * colorspace
ImBufByteBuffer byte_buffer
const uint8_t * byte_data() const
bool colorspace_is_data() const
const float * float_data() const
eImagePaint_Interpolation interp
ListBaseT< PaletteColor > colors
ColorManagedDisplaySettings display_settings
struct ToolSettings * toolsettings
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
struct ReportList * reports