[Bf-blender-cvs] [3d5f5c2d9a5] blender-v3.2-release: Color Attributes: Add initial fill color option

Ethan-Hall noreply at git.blender.org
Mon May 2 12:18:24 CEST 2022


Commit: 3d5f5c2d9a5f1c04ea4d8722bfcb78ea7eedfa8b
Author: Ethan-Hall
Date:   Mon May 2 12:18:04 2022 +0200
Branches: blender-v3.2-release
https://developer.blender.org/rB3d5f5c2d9a5f1c04ea4d8722bfcb78ea7eedfa8b

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

===================================================================

M	source/blender/blenkernel/BKE_paint.h
M	source/blender/editors/geometry/geometry_attributes.cc
M	source/blender/editors/sculpt_paint/paint_vertex.cc

===================================================================

diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index f0488e84091..0e976f04dd1 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -730,6 +730,21 @@ enum {
   SCULPT_MASK_LAYER_CALC_LOOP = (1 << 1),
 };
 
+/* paint_vertex.cc */
+
+/**
+ * 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.
+ */
+bool BKE_object_attributes_active_color_fill(struct Object *ob,
+                                             const float fill_color[4],
+                                             bool only_selected);
+
 /* paint_canvas.cc */
 
 /**
diff --git a/source/blender/editors/geometry/geometry_attributes.cc b/source/blender/editors/geometry/geometry_attributes.cc
index 7bba297af8c..05f9e19da71 100644
--- a/source/blender/editors/geometry/geometry_attributes.cc
+++ b/source/blender/editors/geometry/geometry_attributes.cc
@@ -18,6 +18,7 @@
 #include "BKE_lib_id.h"
 #include "BKE_mesh.h"
 #include "BKE_object_deform.h"
+#include "BKE_paint.h"
 #include "BKE_report.h"
 
 #include "RNA_access.h"
@@ -221,6 +222,9 @@ static int geometry_color_attribute_add_exec(bContext *C, wmOperator *op)
   AttributeDomain domain = (AttributeDomain)RNA_enum_get(op->ptr, "domain");
   CustomDataLayer *layer = BKE_id_attribute_new(id, name, type, domain, op->reports);
 
+  float color[4];
+  RNA_float_get_array(op->ptr, "color", color);
+
   if (layer == nullptr) {
     return OPERATOR_CANCELLED;
   }
@@ -231,6 +235,8 @@ static int geometry_color_attribute_add_exec(bContext *C, wmOperator *op)
     BKE_id_attributes_render_color_set(id, layer);
   }
 
+  BKE_object_attributes_active_color_fill(ob, color, false);
+
   DEG_id_tag_update(id, ID_RECALC_GEOMETRY);
   WM_main_add_notifier(NC_GEOM | ND_DATA, id);
 
@@ -353,6 +359,7 @@ static void geometry_color_attribute_add_ui(bContext *UNUSED(C), wmOperator *op)
   uiItemR(layout, op->ptr, "name", 0, nullptr, ICON_NONE);
   uiItemR(layout, op->ptr, "domain", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
   uiItemR(layout, op->ptr, "data_type", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
+  uiItemR(layout, op->ptr, "color", 0, nullptr, ICON_NONE);
 }
 
 void GEOMETRY_OT_color_attribute_add(wmOperatorType *ot)
@@ -399,6 +406,13 @@ void GEOMETRY_OT_color_attribute_add(wmOperatorType *ot)
                       CD_PROP_COLOR,
                       "Data Type",
                       "Type of data stored in attribute");
+
+  static float default_color[4] = {0.0f, 0.0f, 0.0f, 1.0f};
+
+  prop = RNA_def_float_color(
+      ot->srna, "color", 4, NULL, 0.0f, FLT_MAX, "Color", "Default fill color", 0.0f, 1.0f);
+  RNA_def_property_subtype(prop, PROP_COLOR_GAMMA);
+  RNA_def_property_float_array_default(prop, default_color);
 }
 
 static int geometry_color_attribute_set_render_exec(bContext *C, wmOperator *op)
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;
   }



More information about the Bf-blender-cvs mailing list