59 (mesh && mesh->faces_num && !mesh->deform_verts().is_empty());
65 Mesh &mesh = *
static_cast<Mesh *
>(
object.data);
88 if (!mesh->attributes().contains(mesh->active_color_attribute)) {
93 const int active_vertex_group_index = mesh->vertex_group_active_index - 1;
95 BLI_findlink(&mesh->vertex_group_names, active_vertex_group_index));
96 if (deform_group ==
nullptr) {
104 mesh->active_color_attribute);
105 if (!color_attribute) {
112 const GVArray vertex_group = *attributes.lookup(
114 bke::AttrDomain::Point,
115 bke::cpp_type_to_custom_data_type(color_attribute.
varray.
type()));
122 attributes.adapt_domain(vertex_group, bke::AttrDomain::Point, color_attribute.
domain)};
144 ot->
name =
"Vertex Color from Weight";
145 ot->
idname =
"PAINT_OT_vertex_color_from_weight";
146 ot->
description =
"Convert active weight into gray scale vertex colors";
172 const VArray<bool> selection = *attributes.lookup_or_default<
bool>(
173 ".select_poly", domain,
false);
174 return IndexMask::from_bools(selection, memory);
177 const VArray<bool> selection = *attributes.lookup_or_default<
bool>(
178 ".select_vert", domain,
false);
179 return IndexMask::from_bools(selection, memory);
181 return IndexMask(attributes.domain_size(domain));
187 const StringRef name = mesh.active_color_attribute;
194 if (attribute.domain == bke::AttrDomain::Point) {
198 GVArray color_attribute_point = *attributes.lookup(name, bke::AttrDomain::Point);
199 GVArray color_attribute_corner = attributes.adapt_domain(
200 color_attribute_point, bke::AttrDomain::Point, bke::AttrDomain::Corner);
201 color_attribute_corner.
materialize(selection, attribute.span.data());
238 ot->
name =
"Smooth Vertex Colors";
239 ot->
idname =
"PAINT_OT_vertex_color_smooth";
260 const StringRef name = mesh.active_color_attribute;
262 if (!attributes.contains(name)) {
268 if (!color_attribute) {
277 color_attribute.
varray.
type().to_static_type_tag<ColorGeometry4f, ColorGeometry4b>(
280 using T =
typename decltype(type_tag)::type;
281 for ([[maybe_unused]]
const int i : segment) {
282 if constexpr (std::is_void_v<T>) {
285 else if constexpr (std::is_same_v<T, ColorGeometry4f>) {
290 else if constexpr (std::is_same_v<T, ColorGeometry4b>) {
318 undo::push_begin(scene, obact, op);
323 const IndexMask node_mask = bke::pbvh::all_leaf_nodes(pbvh, memory);
324 undo::push_nodes(
depsgraph, obact, node_mask, undo::Type::Color);
331 undo::push_end(obact);
343 brightness /= 100.0f;
344 float delta = contrast / 200.0f;
351 gain = 1.0f - delta * 2.0f;
352 gain = 1.0f /
max_ff(gain, FLT_EPSILON);
353 offset = gain * (brightness - delta);
357 gain =
max_ff(1.0f - delta * 2.0f, 0.0f);
358 offset = gain * brightness + delta;
370 for (
int i = 0; i < 3; i++) {
371 color[i] = gain * color[i] + offset;
383 ot->
name =
"Vertex Paint Brightness/Contrast";
384 ot->
idname =
"PAINT_OT_vertex_color_brightness_contrast";
395 const float min = -100, max = +100;
420 hsv[0] += (hue - 0.5f);
424 else if (hsv[0] < 0.0f) {
439 ot->
name =
"Vertex Paint Hue/Saturation/Value";
440 ot->
idname =
"PAINT_OT_vertex_color_hsv";
441 ot->
description =
"Adjust vertex color Hue/Saturation/Value";
468 for (
int i = 0; i < 3; i++) {
469 color[i] = 1.0f - color[i];
479 ot->
name =
"Vertex Paint Invert";
480 ot->
idname =
"PAINT_OT_vertex_color_invert";
506 for (
int i = 0; i < 3; i++) {
507 color[i] = gain * (color[i] + offset);
519 ot->
name =
"Vertex Paint Levels";
520 ot->
idname =
"PAINT_OT_vertex_color_levels";
532 ot->
srna,
"offset", 0.0f, -1.0f, 1.0f,
"Offset",
"Value to add to colors", -1.0f, 1.0f);
534 ot->
srna,
"gain", 1.0f, 0.0f,
FLT_MAX,
"Gain",
"Value to multiply colors by", 0.0f, 10.0f);
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
Object * CTX_data_active_object(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
void BKE_mesh_batch_cache_dirty_tag(Mesh *mesh, eMeshBatchDirtyMode mode)
Mesh * BKE_mesh_from_object(Object *ob)
@ BKE_MESH_BATCH_DIRTY_ALL
void BKE_sculpt_update_object_for_edit(Depsgraph *depsgraph, Object *ob_orig, bool is_paint_tool)
#define BLI_assert_unreachable()
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
MINLINE float max_ff(float a, float b)
void hsv_to_rgb_v(const float hsv[3], float r_rgb[3])
void rgb_to_hsv_v(const float rgb[3], float r_hsv[3])
void DEG_id_tag_update(ID *id, unsigned int flags)
Object is a sort of wrapper for general info.
bool ED_mesh_color_ensure(Mesh *mesh, const char *name)
Read Guarded memory(de)allocation.
const CPPType & type() const
void materialize(void *dst) const
void get(int64_t index, void *r_value) const
void set_all(const void *src)
void set_by_copy(int64_t index, const void *value)
void tag_attribute_changed(const IndexMask &node_mask, StringRef attribute_name)
const Depsgraph * depsgraph
bool vertex_paint_mode_poll(bContext *C)
static bool vertex_color_smooth(Object &ob)
void PAINT_OT_vertex_color_smooth(wmOperatorType *ot)
static bool vertex_weight_paint_mode_poll(bContext *C)
void PAINT_OT_vertex_color_hsv(wmOperatorType *ot)
static IndexMask get_selected_indices(const Mesh &mesh, const blender::bke::AttrDomain domain, IndexMaskMemory &memory)
static int vertex_color_levels_exec(bContext *C, wmOperator *op)
static void transform_active_color_data(Mesh &mesh, const FunctionRef< void(ColorGeometry4f &color)> transform_fn)
static bool vertex_paint_from_weight(Object &ob)
static int vertex_color_hsv_exec(bContext *C, wmOperator *op)
static void face_corner_color_equalize_verts(Mesh &mesh, const IndexMask selection)
static void tag_object_after_update(Object &object)
void PAINT_OT_vertex_color_levels(wmOperatorType *ot)
void PAINT_OT_vertex_color_from_weight(wmOperatorType *ot)
void PAINT_OT_vertex_color_brightness_contrast(wmOperatorType *ot)
static int vertex_color_brightness_contrast_exec(bContext *C, wmOperator *op)
static int vertex_paint_from_weight_exec(bContext *C, wmOperator *)
void PAINT_OT_vertex_color_invert(wmOperatorType *ot)
static int vertex_color_invert_exec(bContext *C, wmOperator *op)
static void transform_active_color(bContext *C, wmOperator *op, const FunctionRef< void(ColorGeometry4f &color)> transform_fn)
static int vertex_color_smooth_exec(bContext *C, wmOperator *)
float RNA_float_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
bool(* poll)(bContext *C) ATTR_WARN_UNUSED_RESULT
int(* exec)(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
void WM_event_add_notifier(const bContext *C, uint type, void *reference)