diff options
author | Ethan-Hall <Ethan1080> | 2022-05-02 13:18:04 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2022-05-02 13:18:23 +0300 |
commit | 3d5f5c2d9a5f1c04ea4d8722bfcb78ea7eedfa8b (patch) | |
tree | ba1bef22278e195f03f0329e6b98078055d36403 /source/blender/editors/sculpt_paint/paint_vertex.cc | |
parent | 38394e1a321ef0d139c0040cbd36c7627276c28e (diff) |
Color Attributes: Add initial fill color option
This patch adds allows the user to select the initial fill color when
adding a new color attribute layer.
---
{F13035372}
Reviewed By: JulienKaspar, joeedh
Differential Revision: https://developer.blender.org/D14743
Diffstat (limited to 'source/blender/editors/sculpt_paint/paint_vertex.cc')
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_vertex.cc | 68 |
1 files changed, 51 insertions, 17 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_vertex.cc b/source/blender/editors/sculpt_paint/paint_vertex.cc index a474767b1a1..747295f3de0 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.cc +++ b/source/blender/editors/sculpt_paint/paint_vertex.cc @@ -4144,43 +4144,77 @@ static bool vertex_color_set(Object *ob, ColorPaint4f paintcol_in, Color *color_ return true; } -static int vertex_color_set_exec(bContext *C, wmOperator *UNUSED(op)) +/** + * Fills the object's active color atribute layer with the fill color. + * + * \param[in] ob: The object. + * \param[in] fill_color: The fill color. + * \param[in] only_selected: Limit the fill to selected faces or vertices. + * + * \return #true if successful. + */ +static bool paint_object_attributes_active_color_fill_ex(Object *ob, + ColorPaint4f fill_color, + bool only_selected = true) { - Scene *scene = CTX_data_scene(C); - Object *obact = CTX_data_active_object(C); - Mesh *me = BKE_object_get_original_mesh(obact); - - // uint paintcol = vpaint_get_current_color(scene, scene->toolsettings->vpaint, false); - ColorPaint4f paintcol = vpaint_get_current_col<ColorPaint4f, FloatTraits, ATTR_DOMAIN_POINT>( - scene, scene->toolsettings->vpaint, false); - - bool ok = false; - + Mesh *me = BKE_object_get_original_mesh(ob); + if (!me) { + return false; + } CustomDataLayer *layer = BKE_id_attributes_active_color_get(&me->id); + if (!layer) { + return false; + } + /* Store original #Mesh.editflag.*/ + const decltype(me->editflag) editflag = me->editflag; + if (!only_selected) { + me->editflag &= ~ME_EDIT_PAINT_FACE_SEL; + me->editflag &= ~ME_EDIT_PAINT_VERT_SEL; + } AttributeDomain domain = BKE_id_attribute_domain(&me->id, layer); - + bool ok = false; if (domain == ATTR_DOMAIN_POINT) { if (layer->type == CD_PROP_COLOR) { ok = vertex_color_set<ColorPaint4f, FloatTraits, ATTR_DOMAIN_POINT>( - obact, paintcol, static_cast<ColorPaint4f *>(layer->data)); + ob, fill_color, static_cast<ColorPaint4f *>(layer->data)); } else if (layer->type == CD_PROP_BYTE_COLOR) { ok = vertex_color_set<ColorPaint4b, ByteTraits, ATTR_DOMAIN_POINT>( - obact, paintcol, static_cast<ColorPaint4b *>(layer->data)); + ob, fill_color, static_cast<ColorPaint4b *>(layer->data)); } } else { if (layer->type == CD_PROP_COLOR) { ok = vertex_color_set<ColorPaint4f, FloatTraits, ATTR_DOMAIN_CORNER>( - obact, paintcol, static_cast<ColorPaint4f *>(layer->data)); + ob, fill_color, static_cast<ColorPaint4f *>(layer->data)); } else if (layer->type == CD_PROP_BYTE_COLOR) { ok = vertex_color_set<ColorPaint4b, ByteTraits, ATTR_DOMAIN_CORNER>( - obact, paintcol, static_cast<ColorPaint4b *>(layer->data)); + ob, fill_color, static_cast<ColorPaint4b *>(layer->data)); } } + /* Restore #Mesh.editflag. */ + me->editflag = editflag; + return ok; +} + +extern "C" bool BKE_object_attributes_active_color_fill(Object *ob, + const float fill_color[4], + bool only_selected) +{ + return paint_object_attributes_active_color_fill_ex(ob, ColorPaint4f(fill_color), only_selected); +} + +static int vertex_color_set_exec(bContext *C, wmOperator *UNUSED(op)) +{ + Scene *scene = CTX_data_scene(C); + Object *obact = CTX_data_active_object(C); + + // uint paintcol = vpaint_get_current_color(scene, scene->toolsettings->vpaint, false); + ColorPaint4f paintcol = vpaint_get_current_col<ColorPaint4f, FloatTraits, ATTR_DOMAIN_POINT>( + scene, scene->toolsettings->vpaint, false); - if (ok) { + if (paint_object_attributes_active_color_fill_ex(obact, paintcol)) { WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obact); return OPERATOR_FINISHED; } |