[Bf-blender-cvs] [2e146df5158] temp-vertex-paint: temp-vertex-paint: Vertex paint branch
Joseph Eagar
noreply at git.blender.org
Wed Feb 23 08:03:12 CET 2022
Commit: 2e146df51589281ac2cacef117f5f94fcbb4c7b7
Author: Joseph Eagar
Date: Tue Feb 22 23:01:08 2022 -0800
Branches: temp-vertex-paint
https://developer.blender.org/rB2e146df51589281ac2cacef117f5f94fcbb4c7b7
temp-vertex-paint: Vertex paint branch
I have successully ported vertex paint's
draw brush to C++ thanks to the magic
of templates. It's amazing how easy
this is.
===================================================================
M source/blender/blenkernel/BKE_pbvh.h
M source/blender/editors/sculpt_paint/CMakeLists.txt
R085 source/blender/editors/sculpt_paint/paint_vertex.c source/blender/editors/sculpt_paint/paint_vertex.cc
M source/blender/editors/sculpt_paint/sculpt_intern.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 6abc6f6dcc7..ba40bb10310 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -482,7 +482,7 @@ void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int m
vi.co = vi.bm_vert->co; \
vi.fno = vi.bm_vert->no; \
vi.index = BM_elem_index_get(vi.bm_vert); \
- vi.mask = BM_ELEM_CD_GET_VOID_P(vi.bm_vert, vi.cd_vert_mask_offset); \
+ vi.mask = (float*)BM_ELEM_CD_GET_VOID_P(vi.bm_vert, vi.cd_vert_mask_offset); \
}
#define BKE_pbvh_vertex_iter_end \
diff --git a/source/blender/editors/sculpt_paint/CMakeLists.txt b/source/blender/editors/sculpt_paint/CMakeLists.txt
index fcde780fc58..67bc8f542a4 100644
--- a/source/blender/editors/sculpt_paint/CMakeLists.txt
+++ b/source/blender/editors/sculpt_paint/CMakeLists.txt
@@ -37,7 +37,7 @@ set(SRC
paint_ops.c
paint_stroke.c
paint_utils.c
- paint_vertex.c
+ paint_vertex.cc
paint_vertex_color_ops.c
paint_vertex_color_utils.c
paint_vertex_proj.c
diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.cc
similarity index 85%
rename from source/blender/editors/sculpt_paint/paint_vertex.c
rename to source/blender/editors/sculpt_paint/paint_vertex.cc
index e2f8d81fe13..0580648d5a6 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex.cc
@@ -18,6 +18,7 @@
#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"
@@ -27,6 +28,7 @@
#include "RNA_access.h"
+#include "BKE_attribute.h"
#include "BKE_brush.h"
#include "BKE_colortools.h"
#include "BKE_context.h"
@@ -65,10 +67,222 @@
#include "paint_intern.h" /* own include */
#include "sculpt_intern.h"
+using blender::IndexRange;
+
+/*
+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
* \{ */
+struct ByteColor {
+ using ValueType = uchar;
+ static const size_t ValueRange = 255;
+ static const size_t ValueSize = 1;
+
+ ByteColor()
+ {
+ }
+
+ ByteColor(uint col)
+ {
+ data.i = col;
+ }
+
+ ByteColor(ValueType r, ValueType g, ValueType b, ValueType a)
+ {
+ data.rgba[0] = r;
+ data.rgba[1] = g;
+ data.rgba[2] = b;
+ data.rgba[3] = a;
+ }
+
+ static ByteColor zero()
+ {
+ ByteColor c;
+
+ c.data.i = 0;
+ return c;
+ }
+
+ static ByteColor one()
+ {
+ ByteColor c;
+ memset(reinterpret_cast<void *>(&c.data), 255, sizeof(c.data));
+ return c;
+ }
+
+ static ByteColor fromFloat(float r, float g, float b, float a)
+ {
+ float col[4] = {r, g, b, a};
+ ByteColor c;
+
+ linearrgb_to_srgb_v3_v3(col, col);
+
+ c.data.rgba[0] = (ValueType)(col[0] * 255.0f);
+ c.data.rgba[1] = (ValueType)(col[1] * 255.0f);
+ c.data.rgba[2] = (ValueType)(col[2] * 255.0f);
+ c.data.rgba[3] = (ValueType)(col[3] * 255.0f);
+
+ return c;
+ }
+
+ bool isZero() const
+ {
+ return data.i == 0;
+ }
+
+ ByteColor &operator=(uint c)
+ {
+ data.i = c;
+ return *this;
+ }
+
+ ValueType &r()
+ {
+ return data.rgba[0];
+ }
+ ValueType &g()
+ {
+ return data.rgba[1];
+ }
+ ValueType &b()
+ {
+ return data.rgba[2];
+ }
+ ValueType &a()
+ {
+ return data.rgba[3];
+ }
+
+ void toFloat(float r_color[4]) const
+ {
+ rgba_uchar_to_float(r_color, this->data.rgba);
+ srgb_to_linearrgb_v3_v3(r_color, r_color);
+ }
+
+ static ByteColor blendTool(const int tool,
+ const ByteColor &col,
+ const ByteColor &paintcol,
+ const ValueType alpha)
+ {
+ uint res = ED_vpaint_blend_tool(tool, col.data.i, paintcol.data.i, alpha);
+ return ByteColor(res);
+ }
+
+ void fromFloat(float color[4])
+ {
+ float temp[4];
+ copy_v4_v4(temp, color);
+
+ linearrgb_to_srgb_v3_v3(temp, temp);
+ rgba_float_to_uchar(this->data.rgba, color);
+ }
+ union {
+ uint i;
+ ValueType rgba[4];
+ } data;
+};
+
+
+struct FloatColor {
+ using ValueType = float;
+ static const size_t ValueRange = 1;
+ static const size_t ValueSize = sizeof(float);
+
+ FloatColor()
+ {
+ }
+
+ FloatColor(uint c)
+ {
+ uchar *rgba = reinterpret_cast<uchar *>(&c);
+
+ rgba_uchar_to_float(data, rgba);
+ srgb_to_linearrgb_v3_v3(data, data);
+ }
+
+ FloatColor(const FloatColor &b)
+ {
+ data[0] = b.data[0];
+ data[1] = b.data[1];
+ data[2] = b.data[2];
+ data[3] = b.data[3];
+ }
+
+ FloatColor(ValueType r, ValueType g, ValueType b, ValueType a)
+ {
+ data[0] = r;
+ data[1] = g;
+ data[2] = b;
+ data[3] = a;
+ }
+
+ static FloatColor zero()
+ {
+ return FloatColor(0.0f, 0.0f, 0.0f, 0.0f);
+ }
+
+ static FloatColor one()
+ {
+ return FloatColor(1.0f, 1.0f, 1.0f, 1.0f);
+ }
+
+ static FloatColor fromFloat(float r, float g, float b, float a)
+ {
+ return FloatColor(r, g, b, a);
+ }
+
+ bool isZero() const
+ {
+ return data[0] == 0.0f && data[1] == 0.0f && data[2] == 0.0f && data[3] == 0.0f;
+ }
+
+ ValueType &r()
+ {
+ return data[0];
+ }
+ ValueType &g()
+ {
+ return data[1];
+ }
+ ValueType &b()
+ {
+ return data[2];
+ }
+ ValueType &a()
+ {
+ return data[3];
+ }
+
+ void toFloat(float r_color[4]) const
+ {
+ copy_v4_v4(r_color, data);
+ }
+
+ static FloatColor blendTool(const int tool,
+ const FloatColor &col,
+ const FloatColor &paintcol,
+ const ValueType alpha)
+ {
+ FloatColor result;
+ IMB_blend_color_float(result.data, col.data, paintcol.data, (IMB_BlendMode)tool);
+ return result;
+ }
+
+ void fromFloat(float color[4])
+ {
+ copy_v4_v4(data, color);
+ }
+
+ float data[4];
+};
+
/* Use for 'blur' brush, align with PBVH nodes, created and freed on each update. */
struct VPaintAverageAccum {
uint len;
@@ -186,14 +400,14 @@ static void paint_last_stroke_update(Scene *scene, const float location[3])
ups->last_stroke_valid = true;
}
-bool vertex_paint_mode_poll(bContext *C)
+extern "C" 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;
}
-static bool vertex_paint_poll_ex(bContext *C, bool check_tool)
+extern "C" static bool vertex_paint_poll_ex(bContext *C, bool check_tool)
{
if (vertex_paint_mode_poll(C) && BKE_paint_brush(&CTX_data_tool_settings(C)->vpaint->paint)) {
ScrArea *area = CTX_wm_area(C);
@@ -226,7 +440,7 @@ bool weight_paint_mode_poll(bContext *C)
return ob && ob->mode == OB_MODE_WEIGHT_PAINT && ((Mesh *)ob->data)->totpoly;
}
-static bool weight_paint_poll_ex(bContext *C, bool check_tool)
+extern "C" static bool weight_paint_poll_ex(bContext *C, bool check_tool)
{
Object *ob = CTX_data_active_object(C);
ScrArea *area;
@@ -266,29 +480,30 @@ uint vpaint_get_current_col(Scene *scene, VPaint *vp, bool secondary)
}
/* wpaint has 'wpaint_blend' */
-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)
+template<class Color, typename Value = typename Color::ValueType>
+static Color vpaint_blend_cpp(const VPaint *vp,
+ Color color_curr,
+ Color color_orig,
+ Color color_paint,
+ const Value alpha_i,
+ const Value brush_alpha_value_i)
{
const Brush *brush = vp->paint.brush;
- const IMB_BlendMode blend = brush->blend;
+ const IMB_BlendMode blend = (IMB_BlendMode)brush->blend;
- uint color_blend = ED_vpaint_blend_tool(blend, color_curr, color_paint, alpha_i);
+ Color color_blend = Color::blendTool(blend, color_curr, color_paint, alpha_i);
/* If no accumulate, clip color adding with `color_orig` & `color_test`. */
if (!brush_use_accumulate(vp)) {
- uint color_test, a;
- char *cp, *ct, *co;
+ uint a;
+ Color color_test;
+ Value *cp, *ct, *co;
- color_test = ED_vpaint_blend_tool(blend, color_orig, color_paint, brush_alpha_value_i);
+ color_test = Color::blendTool(blend, color_orig, color_paint, brush_alpha_value_i);
- cp = (char *)&color_blend;
- ct = (char *)&color_test;
- co = (char *)&color_orig;
+ cp = (Value *)&color_blend;
+ ct = (Value *)&color_test;
+ co = (Value *)&color_orig;
for (a = 0; a < 4; a++) {
if (ct[a] < co[a]) {
@@ -312,34 +527,26 @@ static uint vpaint_blend(const VPaint *vp,
if ((brush->flag & BRUSH_LOCK_ALPHA) &&
!ELEM(blend, IMB_BLEND_ERASE_ALPHA, IMB_BLEND_ADD_ALPHA)) {
- char *cp, *cc;
- cp = (char *)&color_blend;
- cc = (char *)&color_curr;
+ Value *cp, *cc;
+ cp = (Value *)&color_blend;
+ cc = (Value *)&color_curr;
cp[3] = cc[3];
}
return color_blend;
}
-static void tex_color_alpha(VPaint *vp, const ViewContext *vc, const float co[3], float r_rgba[4])
+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)
{
- 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 {
- f
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list