[Bf-blender-cvs] [4e794686a93] temp-sculpt-colors: Remove vertex paint patch

Joseph Eagar noreply at git.blender.org
Wed Mar 30 20:28:28 CEST 2022


Commit: 4e794686a934cc5245bee652246ac3af2bd72cac
Author: Joseph Eagar
Date:   Wed Mar 30 11:28:12 2022 -0700
Branches: temp-sculpt-colors
https://developer.blender.org/rB4e794686a934cc5245bee652246ac3af2bd72cac

Remove vertex paint patch

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

M	source/blender/editors/sculpt_paint/CMakeLists.txt
M	source/blender/editors/sculpt_paint/paint_intern.h
R064	source/blender/editors/sculpt_paint/paint_vertex.cc	source/blender/editors/sculpt_paint/paint_vertex.c
M	source/blender/editors/sculpt_paint/paint_vertex_color_ops.c
D	source/blender/editors/sculpt_paint/paint_vertex_color_utils.hh
M	source/blender/editors/sculpt_paint/sculpt_intern.h

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

diff --git a/source/blender/editors/sculpt_paint/CMakeLists.txt b/source/blender/editors/sculpt_paint/CMakeLists.txt
index d0ff1d09c39..c422c8c2033 100644
--- a/source/blender/editors/sculpt_paint/CMakeLists.txt
+++ b/source/blender/editors/sculpt_paint/CMakeLists.txt
@@ -46,10 +46,9 @@ set(SRC
   paint_ops.c
   paint_stroke.c
   paint_utils.c
-  paint_vertex.cc
+  paint_vertex.c
   paint_vertex_color_ops.c
   paint_vertex_color_utils.c
-  paint_vertex_color_utils.hh
   paint_vertex_proj.c
   paint_vertex_weight_ops.c
   paint_vertex_weight_utils.c
diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h
index ea803559d46..82fdf49c28e 100644
--- a/source/blender/editors/sculpt_paint/paint_intern.h
+++ b/source/blender/editors/sculpt_paint/paint_intern.h
@@ -133,9 +133,7 @@ void PAINT_OT_weight_gradient(struct wmOperatorType *ot);
 void PAINT_OT_vertex_paint_toggle(struct wmOperatorType *ot);
 void PAINT_OT_vertex_paint(struct wmOperatorType *ot);
 
-unsigned int vpaint_get_current_color(struct Scene *scene,
-                                      struct VPaint *vp,
-                                      bool secondary);
+unsigned int vpaint_get_current_col(struct Scene *scene, struct VPaint *vp, bool secondary);
 
 /* paint_vertex_color_utils.c */
 
diff --git a/source/blender/editors/sculpt_paint/paint_vertex.cc b/source/blender/editors/sculpt_paint/paint_vertex.c
similarity index 64%
rename from source/blender/editors/sculpt_paint/paint_vertex.cc
rename to source/blender/editors/sculpt_paint/paint_vertex.c
index f3790b5d552..e3d632b72f5 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex.cc
+++ b/source/blender/editors/sculpt_paint/paint_vertex.c
@@ -13,13 +13,11 @@
 #include "MEM_guardedalloc.h"
 
 #include "BLI_array_utils.h"
-#include "BLI_color.hh"
 #include "BLI_listbase.h"
 #include "BLI_math.h"
 #include "BLI_rect.h"
 #include "BLI_string.h"
 #include "BLI_task.h"
-#include "BLI_task.hh"
 
 #include "DNA_brush_types.h"
 #include "DNA_mesh_types.h"
@@ -68,69 +66,14 @@
 #include "paint_intern.h" /* own include */
 #include "sculpt_intern.h"
 
-#include "paint_vertex_color_utils.hh"
-
-using blender::IndexRange;
-using namespace blender::paint;
-
-static ViewContext *vpaint_get_viewcontext(Object *ob, void *vpd);
-
-/*
-WM_msg_publish_rna_prop declares externs locally,
-however that doesn't work in C++ since we need
-to extern "C" it, which has to be global.
-*/
-extern "C" PropertyRNA rna_Object_mode;
-
 /* -------------------------------------------------------------------- */
 /** \name Internal Utilities
  * \{ */
 
-static Color4b uint2color(uint c)
-{
-  uchar *rgba = (uchar *)&c;
-  return Color4b(rgba[0], rgba[1], rgba[2], rgba[3]);
-}
-
-static uint color2uint(Color4b c)
-{
-  return *(reinterpret_cast<uint *>(&c));
-}
-
-static bool isZero(Color4f c)
-{
-  return c.r == 0.0f && c.g == 0.0f && c.b == 0.0f && c.a == 0.0f;
-}
-
-static bool isZero(Color4b c)
-{
-  return c.r == 0 && c.g == 0 && c.b == 0 && c.a == 0;
-}
-
-template<typename Color = Color4f> static Color4f toFloat(const Color &c)
-{
-  if constexpr (std::is_same_v<Color, Color4b>) {
-    return c.decode();
-  }
-  else {
-    return c;
-  }
-}
-
-template<typename Color = Color4f> static Color fromFloat(const Color4f &c)
-{
-  if constexpr (std::is_same_v<Color, Color4b>) {
-    return c.encode();
-  }
-  else {
-    return c;
-  }
-}
-
 /* Use for 'blur' brush, align with PBVH nodes, created and freed on each update. */
-template<typename BlendType> struct VPaintAverageAccum {
-  BlendType len;
-  BlendType value[3];
+struct VPaintAverageAccum {
+  uint len;
+  uint value[3];
 };
 
 struct WPaintAverageAccum {
@@ -150,32 +93,6 @@ struct NormalAnglePrecalc {
   float angle_range;
 };
 
-template<typename Color> struct VPaintModeData {
-  SculptVertexPaintGeomMap gmap;
-
-  Color *previous_color;
-};
-
-/* Returns number of elements. */
-static int get_vcol_elements(Mesh *me, size_t *r_elem_size)
-{
-  CustomDataLayer *layer = BKE_id_attributes_active_color_get(&me->id);
-  AttributeDomain domain = BKE_id_attribute_domain(&me->id, layer);
-
-  if (r_elem_size) {
-    *r_elem_size = layer->type == CD_PROP_COLOR ? sizeof(float) * 4ULL : 4ULL;
-  }
-
-  switch (domain) {
-    case ATTR_DOMAIN_POINT:
-      return me->totvert;
-    case ATTR_DOMAIN_CORNER:
-      return me->totloop;
-    default:
-      return 0;
-  }
-}
-
 static void view_angle_limits_init(struct NormalAnglePrecalc *a, float angle, bool do_mask_normal)
 {
   angle = RAD2DEGF(angle);
@@ -274,7 +191,15 @@ bool vertex_paint_mode_poll(bContext *C)
 {
   Object *ob = CTX_data_active_object(C);
 
-  return ob && ob->mode == OB_MODE_VERTEX_PAINT && ((Mesh *)ob->data)->totpoly;
+  if (!(ob && ob->mode == OB_MODE_VERTEX_PAINT && ((Mesh *)ob->data)->totpoly)) {
+    return false;
+  }
+
+  return true;
+  CustomDataLayer *layer = BKE_id_attributes_active_color_get((ID *)ob->data);
+  AttributeDomain domain = BKE_id_attribute_domain((ID *)ob->data, layer);
+
+  return layer && layer->type == CD_MLOOPCOL && domain == ATTR_DOMAIN_CORNER;
 }
 
 static bool vertex_paint_poll_ex(bContext *C, bool check_tool)
@@ -338,61 +263,41 @@ bool weight_paint_poll_ignore_tool(bContext *C)
   return weight_paint_poll_ex(C, false);
 }
 
-template<typename Color, typename Traits, AttributeDomain domain>
-Color vpaint_get_current_col(Scene *scene, VPaint *vp, bool secondary)
+uint vpaint_get_current_col(Scene *scene, VPaint *vp, bool secondary)
 {
   Brush *brush = BKE_paint_brush(&vp->paint);
-  const float *color = secondary ? BKE_brush_secondary_color_get(scene, brush) :
-                                   BKE_brush_color_get(scene, brush);
-  Color4f col(color);
-
-  col[3] = 1.0f; /* alpha isn't used, could even be removed to speedup paint a little */
-
-  if constexpr (std::is_same_v<Color, Color4b>) {
-    return col.encode();
-  }
-  else {
-    return col;
-  }
-}
-
-uint vpaint_get_current_color(Scene *scene, VPaint *vp, bool secondary)
-{
-  Color4b col = vpaint_get_current_col<Color4b, ByteTraits, ATTR_DOMAIN_CORNER>(
-      scene, vp, secondary);
-
-  return *(reinterpret_cast<uint *>(&col.r));
+  uchar col[4];
+  rgb_float_to_uchar(col,
+                     secondary ? BKE_brush_secondary_color_get(scene, brush) :
+                                 BKE_brush_color_get(scene, brush));
+  col[3] = 255; /* alpha isn't used, could even be removed to speedup paint a little */
+  return *(uint *)col;
 }
 
 /* wpaint has 'wpaint_blend' */
-template<typename Color, typename Traits>
-static Color vpaint_blend_cpp(const VPaint *vp,
-                              Color color_curr,
-                              Color color_orig,
-                              Color color_paint,
-                              const typename Traits::ValueType alpha_i,
-                              const typename Traits::BlendType brush_alpha_value_i)
+static uint vpaint_blend(const VPaint *vp,
+                         uint color_curr,
+                         uint color_orig,
+                         uint color_paint,
+                         const int alpha_i,
+                         /* pre scaled from [0-1] --> [0-255] */
+                         const int brush_alpha_value_i)
 {
-  using Value = typename Traits::ValueType;
-
   const Brush *brush = vp->paint.brush;
-  const IMB_BlendMode blend = (IMB_BlendMode)brush->blend;
+  const IMB_BlendMode blend = brush->blend;
 
-  Color color_blend = ED_vpaint_blend_tool2<Color, Traits>(
-      blend, color_curr, color_paint, alpha_i);
+  uint color_blend = ED_vpaint_blend_tool(blend, color_curr, color_paint, alpha_i);
 
   /* If no accumulate, clip color adding with `color_orig` & `color_test`. */
   if (!brush_use_accumulate(vp)) {
-    uint a;
-    Color color_test;
-    Value *cp, *ct, *co;
+    uint color_test, a;
+    char *cp, *ct, *co;
 
-    color_test = ED_vpaint_blend_tool2<Color, Traits>(
-        blend, color_orig, color_paint, brush_alpha_value_i);
+    color_test = ED_vpaint_blend_tool(blend, color_orig, color_paint, brush_alpha_value_i);
 
-    cp = (Value *)&color_blend;
-    ct = (Value *)&color_test;
-    co = (Value *)&color_orig;
+    cp = (char *)&color_blend;
+    ct = (char *)&color_test;
+    co = (char *)&color_orig;
 
     for (a = 0; a < 4; a++) {
       if (ct[a] < co[a]) {
@@ -416,28 +321,34 @@ static Color vpaint_blend_cpp(const VPaint *vp,
 
   if ((brush->flag & BRUSH_LOCK_ALPHA) &&
       !ELEM(blend, IMB_BLEND_ERASE_ALPHA, IMB_BLEND_ADD_ALPHA)) {
-    Value *cp, *cc;
-    cp = (Value *)&color_blend;
-    cc = (Value *)&color_curr;
+    char *cp, *cc;
+    cp = (char *)&color_blend;
+    cc = (char *)&color_curr;
     cp[3] = cc[3];
   }
 
   return color_blend;
 }
 
-static uint vpaint_blend(const VPaint *vp,
-                         uint color_curr,
-                         uint color_orig,
-                         uint color_paint,
-                         const int alpha_i,
-                         const int brush_alpha_value_i)
+static void tex_color_alpha(VPaint *vp, const ViewContext *vc, const float co[3], float r_rgba[4])
 {
-  return color2uint(vpaint_blend_cpp<Color4b, ByteTraits>(vp,
-                                                          uint2color(color_curr),
-                                                          uint2color(color_orig),
-                                                          uint2color(color_paint),
-                                                          alpha_i,
-                                                          brush_alpha_value_i));
+  const Brush *brush = BKE_paint_brush(&vp->paint);
+  BLI_assert(brush->mtex.tex != NULL);
+  if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_3D) {
+    BKE_brush_sample_tex_3d(vc->scene, brush, co, r_rgba, 0, NULL);
+  }
+  else {
+    float co_ss[2]; /* screenspace */
+    if (ED_view3d_project_float_object(
+            vc->region, co, co_ss, V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_NEAR) ==
+        V3D_PROJ_RET_OK) {
+      const float co_ss_3d[3] = {co_ss[0], co_ss[1], 0.0f}; /* we need a 3rd empty value */
+      BKE_brush_sample_tex_3d(vc->scene, brush, co_ss_3d, r_rgba, 0, NULL);
+    }
+    els

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list