[Bf-blender-cvs] [eceda09a3b3] temp-vertex-paint: temp-vertex-paint: finish C++ port of vertex paint
Joseph Eagar
noreply at git.blender.org
Fri Feb 25 23:12:55 CET 2022
Commit: eceda09a3b3a538d9b4cfeac214bae666a2ca589
Author: Joseph Eagar
Date: Fri Feb 25 14:10:32 2022 -0800
Branches: temp-vertex-paint
https://developer.blender.org/rBeceda09a3b3a538d9b4cfeac214bae666a2ca589
temp-vertex-paint: finish C++ port of vertex paint
* Ported smudge and average brushes.
* The attribute domain is now passed via
template argument instead of a "bool is_verts."
* VPaintData (which is internal to paint_vertex.cc)
is now a template.
===================================================================
M source/blender/editors/sculpt_paint/paint_intern.h
M source/blender/editors/sculpt_paint/paint_vertex.cc
M source/blender/editors/sculpt_paint/paint_vertex_color_ops.c
M source/blender/editors/sculpt_paint/sculpt_intern.h
===================================================================
diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h
index e45228274d3..ea803559d46 100644
--- a/source/blender/editors/sculpt_paint/paint_intern.h
+++ b/source/blender/editors/sculpt_paint/paint_intern.h
@@ -133,7 +133,9 @@ 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_col(struct Scene *scene, struct VPaint *vp, bool secondary, float r_color[4]);
+unsigned int vpaint_get_current_color(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.cc
index c3565928104..40b3a2b6bcf 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex.cc
+++ b/source/blender/editors/sculpt_paint/paint_vertex.cc
@@ -73,6 +73,8 @@
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
@@ -126,9 +128,9 @@ template<typename Color = Color4f> static Color fromFloat(const Color4f &c)
}
/* Use for 'blur' brush, align with PBVH nodes, created and freed on each update. */
-struct VPaintAverageAccum {
- uint len;
- uint value[3];
+template<typename BlendType> struct VPaintAverageAccum {
+ BlendType len;
+ BlendType value[3];
};
struct WPaintAverageAccum {
@@ -148,11 +150,16 @@ struct NormalAnglePrecalc {
float angle_range;
};
-static int get_vcol_elements(Mesh *me)
+/* 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;
@@ -325,19 +332,29 @@ bool weight_paint_poll_ignore_tool(bContext *C)
return weight_paint_poll_ex(C, false);
}
-uint vpaint_get_current_col(Scene *scene, VPaint *vp, bool secondary, float floatcolor[4])
+template<typename Color, typename Traits, AttributeDomain domain>
+Color vpaint_get_current_col(Scene *scene, VPaint *vp, bool secondary)
{
Brush *brush = BKE_paint_brush(&vp->paint);
- uchar col[4];
+ const float *color = secondary ? BKE_brush_secondary_color_get(scene, brush) :
+ BKE_brush_color_get(scene, brush);
+ Color4f col(color);
- copy_v4_v4(floatcolor,
- secondary ? BKE_brush_secondary_color_get(scene, brush) :
- BKE_brush_color_get(scene, brush));
+ col[3] = 1.0f; /* alpha isn't used, could even be removed to speedup paint a little */
- rgb_float_to_uchar(col, floatcolor);
+ if constexpr (std::is_same_v<Color, Color4b>) {
+ return col.encode();
+ }
+ else {
+ return col;
+ }
+}
+
+extern "C" 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);
- col[3] = 255; /* alpha isn't used, could even be removed to speedup paint a little */
- return *(uint *)col;
+ return *(reinterpret_cast<uint *>(&col.r));
}
/* wpaint has 'wpaint_blend' */
@@ -1199,12 +1216,12 @@ static void vertex_paint_init_session(Depsgraph *depsgraph,
BLI_assert(ob->sculpt == NULL);
ob->sculpt = (SculptSession *)MEM_callocN(sizeof(SculptSession), "sculpt session");
ob->sculpt->mode_type = object_mode;
- BKE_sculpt_update_object_for_edit(depsgraph, ob, false, false, false);
+ BKE_sculpt_update_object_for_edit(depsgraph, ob, true, false, false);
}
static void vertex_paint_init_stroke(Depsgraph *depsgraph, Object *ob)
{
- BKE_sculpt_update_object_for_edit(depsgraph, ob, false, false, false);
+ BKE_sculpt_update_object_for_edit(depsgraph, ob, true, false, false);
}
static void vertex_paint_init_session_data(const ToolSettings *ts, Object *ob)
@@ -1226,7 +1243,9 @@ static void vertex_paint_init_session_data(const ToolSettings *ts, Object *ob)
}
Mesh *me = (Mesh *)ob->data;
- int totelem = get_vcol_elements(me);
+ size_t elemSize;
+
+ int totelem = get_vcol_elements(me, &elemSize);
if (gmap->vert_to_loop == NULL) {
gmap->vert_map_mem = NULL;
@@ -1251,9 +1270,6 @@ static void vertex_paint_init_session_data(const ToolSettings *ts, Object *ob)
/* Create average brush arrays */
if (ob->mode == OB_MODE_VERTEX_PAINT) {
- CustomDataLayer *layer = BKE_id_attributes_active_color_get(&me->id);
- size_t elemSize = layer && layer->type == CD_PROP_COLOR ? sizeof(float) * 4 : 4;
-
if (!brush_use_accumulate(ts->vpaint)) {
if (ob->sculpt->mode.vpaint.previous_color == NULL) {
ob->sculpt->mode.vpaint.previous_color = (uint *)MEM_callocN(totelem * elemSize, __func__);
@@ -2814,12 +2830,17 @@ void PAINT_OT_vertex_paint_toggle(wmOperatorType *ot)
* - revise whether op->customdata should be added in object, in set_vpaint.
*/
-struct VPaintData {
+struct VPaintDataHeader {
ViewContext vc;
+ AttributeDomain domain;
+ CustomDataType type;
+};
+
+template<typename Color, typename Traits, AttributeDomain domain> struct VPaintData {
+ VPaintDataHeader head;
struct NormalAnglePrecalc normal_angle_precalc;
- uint paintcol;
- float floatcolor[4];
+ Color paintcol;
struct VertProjHandle *vp_handle;
struct CoNo *vertexcosnos;
@@ -2838,52 +2859,44 @@ struct VPaintData {
/* Special storage for smear brush, avoid feedback loop - update each step. */
struct {
- uint *color_prev;
- uint *color_curr;
+ void *color_prev;
+ void *color_curr;
} smear;
};
-extern "C" static bool vpaint_stroke_test_start(bContext *C,
- struct wmOperator *op,
- const float mouse[2])
+template<typename Color, typename Traits, AttributeDomain domain>
+static void *vpaint_init_vpaint(bContext *C,
+ struct wmOperator *op,
+ Scene *scene,
+ Depsgraph *depsgraph,
+ VPaint *vp,
+ Object *ob,
+ Mesh *me,
+ const Brush *brush)
{
- Scene *scene = CTX_data_scene(C);
- ToolSettings *ts = scene->toolsettings;
- struct PaintStroke *stroke = (PaintStroke *)op->customdata;
- VPaint *vp = ts->vpaint;
- Brush *brush = BKE_paint_brush(&vp->paint);
- struct VPaintData *vpd;
- Object *ob = CTX_data_active_object(C);
- Mesh *me;
- SculptSession *ss = ob->sculpt;
- Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
-
- /* context checks could be a poll() */
- me = BKE_mesh_from_object(ob);
- if (me == NULL || me->totpoly == 0) {
- return false;
- }
+ VPaintData<Color, Traits, domain> *vpd;
- ED_mesh_color_ensure(me, NULL);
+ size_t elemSize;
+ int totelem = get_vcol_elements(me, &elemSize);
+ /* make mode data storage */
+ vpd = MEM_new<VPaintData<Color, Traits, domain>>("VPaintData");
- CustomDataLayer *layer = BKE_id_attributes_active_color_get(&me->id);
- if (!layer) {
- return false;
+ if constexpr (std::is_same_v<Color, Color4f>) {
+ vpd->head.type = CD_PROP_COLOR;
+ }
+ else {
+ vpd->head.type = CD_MLOOPCOL;
}
- const size_t elemSize = layer->type == CD_PROP_COLOR ? sizeof(float) * 4 : 4;
- int totelem = get_vcol_elements(me);
+ vpd->head.domain = domain;
- /* make mode data storage */
- vpd = (VPaintData *)MEM_callocN(sizeof(*vpd), "VPaintData");
- paint_stroke_set_mode_data(stroke, vpd);
- ED_view3d_viewcontext_init(C, &vpd->vc, depsgraph);
+ ED_view3d_viewcontext_init(C, &vpd->head.vc, depsgraph);
view_angle_limits_init(&vpd->normal_angle_precalc,
vp->paint.brush->falloff_angle,
(vp->paint.brush->flag & BRUSH_FRONTFACE_FALLOFF) != 0);
- vpd->paintcol = vpaint_get_current_col(
- scene, vp, (RNA_enum_get(op->ptr, "mode") == BRUSH_STROKE_INVERT), vpd->floatcolor);
+ vpd->paintcol = vpaint_get_current_col<Color, Traits, domain>(
+ scene, vp, (RNA_enum_get(op->ptr, "mode") == BRUSH_STROKE_INVERT));
vpd->is_texbrush = !(brush->vertexpaint_tool == VPAINT_TOOL_BLUR) && brush->mtex.tex;
@@ -2904,8 +2917,11 @@ extern "C" static bool vpaint_stroke_test_start(bContext *C,
}
if (brush->vertexpaint_tool == VPAINT_TOOL_SMEAR) {
- vpd->smear.color_prev = (uint *)MEM_mallocN(elemSize * totelem, __func__);
- memcpy(vpd->smear.color_prev, me->mloopcol, elemSize * totelem);
+ CustomDataLayer *layer = BKE_id_attributes_active_color_get(&me->id);
+
+ vpd->smear.color_prev = MEM_malloc_arrayN(totelem, elemSize, __func__);
+ memcpy(vpd->smear.color_prev, layer->data, elemSize * totelem);
+
vpd->smear.color_curr = (uint *)MEM_dupallocN(vpd->smear.color_prev);
}
@@ -2916,184 +2932,81 @@ extern "C" static bool vpaint_stroke_test_start(bContext *C,
ob->sculpt->building_vp_handle = false;
}
- /* If not previously created, create vertex/weight paint mode session data */
- vertex_paint_init_stroke(depsgraph, ob);
- vwpaint_update_cache_invariants(C, vp, ss, op, mouse);
- vertex_paint_init_session_data(ts, ob);
-
if (ob->sculpt->mode.vpaint.previous_color != NULL) {
memset(ob->sculpt->mode.vpaint.previous_color, 0, elemSize * totelem);
}
- return true;
+ return static_cast<void *>(vpd);
}
-extern "C" static void do_vpaint_brush_calc_average_color_cb_ex(
- void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls))
+extern "C" static bool vpaint_stroke_test_start(bContext *C,
+ struct wmOperator *op,
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list