forked from blender/blender
Cleanup: Reduce use and scope of templates in vertex paint #2
@ -136,8 +136,6 @@ void PAINT_OT_weight_gradient(wmOperatorType *ot);
|
||||
void PAINT_OT_vertex_paint_toggle(wmOperatorType *ot);
|
||||
void PAINT_OT_vertex_paint(wmOperatorType *ot);
|
||||
|
||||
unsigned int vpaint_get_current_color(Scene *scene, VPaint *vp, bool secondary);
|
||||
|
||||
/**
|
||||
* \note weight-paint has an equivalent function: #ED_wpaint_blend_tool
|
||||
*/
|
||||
|
@ -2790,6 +2790,22 @@ void PAINT_OT_vertex_paint_toggle(wmOperatorType *ot)
|
||||
* - revise whether op->customdata should be added in object, in set_vpaint.
|
||||
*/
|
||||
|
||||
template<typename Func>
|
||||
static void to_static_color_type(const eCustomDataType type, const Func &func)
|
||||
{
|
||||
switch (type) {
|
||||
case CD_PROP_COLOR:
|
||||
func(ColorPaint4f());
|
||||
break;
|
||||
case CD_PROP_BYTE_COLOR:
|
||||
func(ColorPaint4b());
|
||||
break;
|
||||
default:
|
||||
BLI_assert_unreachable();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
struct VPaintData {
|
||||
ViewContext vc;
|
||||
eAttrDomain domain;
|
||||
@ -2833,7 +2849,6 @@ static VPaintData *vpaint_init_vpaint(bContext *C,
|
||||
|
||||
vpd->paintcol = vpaint_get_current_col(
|
||||
scene, vp, (RNA_enum_get(op->ptr, "mode") == BRUSH_STROKE_INVERT));
|
||||
;
|
||||
|
||||
vpd->is_texbrush = !(brush->vertexpaint_tool == VPAINT_TOOL_BLUR) && brush->mtex.tex;
|
||||
|
||||
@ -2903,8 +2918,6 @@ static void do_vpaint_brush_blur_loops(bContext *C,
|
||||
Span<PBVHNode *> nodes,
|
||||
GMutableSpan lcol)
|
||||
{
|
||||
using Blend = typename Traits::BlendType;
|
||||
|
||||
SculptSession *ss = ob->sculpt;
|
||||
|
||||
const Brush *brush = ob->sculpt->cache->brush;
|
||||
@ -2966,6 +2979,9 @@ static void do_vpaint_brush_blur_loops(bContext *C,
|
||||
|
||||
const float brush_fade = BKE_brush_curve_strength(brush, sqrtf(test.dist), cache->radius);
|
||||
|
||||
to_static_color_type(vpd->type, [&](auto dummy) {
|
||||
using Color = decltype(dummy);
|
||||
using Blend = typename Traits::BlendType;
|
||||
/* Get the average poly color */
|
||||
Color color_final(0, 0, 0, 0);
|
||||
|
||||
@ -3026,6 +3042,7 @@ static void do_vpaint_brush_blur_loops(bContext *C,
|
||||
lcol[l_index] = vpaint_blend<Color, Traits>(
|
||||
vp, lcol[l_index], color_orig, *col, final_alpha, Traits::range * brush_strength);
|
||||
}
|
||||
});
|
||||
}
|
||||
BKE_pbvh_vertex_iter_end;
|
||||
};
|
||||
@ -3041,8 +3058,6 @@ static void do_vpaint_brush_blur_verts(bContext *C,
|
||||
Span<PBVHNode *> nodes,
|
||||
GMutableSpan lcol)
|
||||
{
|
||||
using Blend = typename Traits::BlendType;
|
||||
|
||||
SculptSession *ss = ob->sculpt;
|
||||
|
||||
const Brush *brush = ob->sculpt->cache->brush;
|
||||
@ -3104,6 +3119,9 @@ static void do_vpaint_brush_blur_verts(bContext *C,
|
||||
const float brush_fade = BKE_brush_curve_strength(brush, sqrtf(test.dist), cache->radius);
|
||||
|
||||
/* Get the average poly color */
|
||||
to_static_color_type(vpd->type, [&](auto dummy) {
|
||||
using Color = decltype(dummy);
|
||||
using Blend = typename Traits::BlendType;
|
||||
Color color_final(0, 0, 0, 0);
|
||||
|
||||
int total_hit_loops = 0;
|
||||
@ -3159,6 +3177,7 @@ static void do_vpaint_brush_blur_verts(bContext *C,
|
||||
lcol[v_index] = vpaint_blend<Color, Traits>(
|
||||
vp, lcol[v_index], color_orig, *col, final_alpha, Traits::range * brush_strength);
|
||||
}
|
||||
});
|
||||
}
|
||||
BKE_pbvh_vertex_iter_end;
|
||||
};
|
||||
@ -3190,27 +3209,20 @@ static void do_vpaint_brush_smear(bContext *C,
|
||||
GMutableSpan color_prev_smear = vpd->smear.color_prev;
|
||||
GMutableSpan color_prev = ss->cache->prev_colors_vpaint;
|
||||
|
||||
const blender::VArray<bool> select_vert = *me->attributes().lookup_or_default<bool>(
|
||||
".select_vert", ATTR_DOMAIN_POINT, false);
|
||||
const blender::VArray<bool> select_poly = *me->attributes().lookup_or_default<bool>(
|
||||
".select_poly", ATTR_DOMAIN_FACE, false);
|
||||
|
||||
blender::threading::parallel_for(nodes.index_range(), 1LL, [&](IndexRange range) {
|
||||
for (int n : range) {
|
||||
float brush_size_pressure, brush_alpha_value, brush_alpha_pressure;
|
||||
|
||||
get_brush_alpha_data(
|
||||
scene, ss, brush, &brush_size_pressure, &brush_alpha_value, &brush_alpha_pressure);
|
||||
const bool use_normal = vwpaint_use_normal(vp);
|
||||
const bool use_vert_sel = (me->editflag &
|
||||
(ME_EDIT_PAINT_FACE_SEL | ME_EDIT_PAINT_VERT_SEL)) != 0;
|
||||
const bool use_vert_sel = (me->editflag & (ME_EDIT_PAINT_FACE_SEL | ME_EDIT_PAINT_VERT_SEL)) !=
|
||||
0;
|
||||
const bool use_face_sel = (me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0;
|
||||
|
||||
float brush_dir[3];
|
||||
sub_v3_v3v3(brush_dir, cache->location, cache->last_location);
|
||||
project_plane_v3_v3v3(brush_dir, brush_dir, cache->view_normal);
|
||||
if (normalize_v3(brush_dir) == 0.0f) {
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
SculptBrushTest test;
|
||||
@ -3219,6 +3231,14 @@ static void do_vpaint_brush_smear(bContext *C,
|
||||
const float *sculpt_normal_frontface = SCULPT_brush_frontface_normal_from_falloff_shape(
|
||||
ss, brush->falloff_shape);
|
||||
|
||||
const blender::VArray<bool> select_vert = *me->attributes().lookup_or_default<bool>(
|
||||
".select_vert", ATTR_DOMAIN_POINT, false);
|
||||
const blender::VArray<bool> select_poly = *me->attributes().lookup_or_default<bool>(
|
||||
".select_poly", ATTR_DOMAIN_FACE, false);
|
||||
|
||||
blender::threading::parallel_for(nodes.index_range(), 1LL, [&](IndexRange range) {
|
||||
for (int n : range) {
|
||||
|
||||
/* For each vertex */
|
||||
PBVHVertexIter vd;
|
||||
BKE_pbvh_vertex_iter_begin (ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) {
|
||||
@ -3256,6 +3276,8 @@ static void do_vpaint_brush_smear(bContext *C,
|
||||
|
||||
/* Get the color of the loop in the opposite
|
||||
* direction of the brush movement */
|
||||
to_static_color_type(vpd->type, [&](auto dummy) {
|
||||
using Color = decltype(dummy);
|
||||
Color color_final(0, 0, 0, 0);
|
||||
|
||||
for (const int j : gmap->vert_to_poly[v_index].index_range()) {
|
||||
@ -3283,7 +3305,7 @@ static void do_vpaint_brush_smear(bContext *C,
|
||||
const float stroke_dot = dot_v3v3(other_dir, brush_dir);
|
||||
int elem_index;
|
||||
|
||||
if constexpr (domain == ATTR_DOMAIN_POINT) {
|
||||
if (domain == ATTR_DOMAIN_POINT) {
|
||||
elem_index = v_other_index;
|
||||
}
|
||||
else {
|
||||
@ -3311,7 +3333,7 @@ static void do_vpaint_brush_smear(bContext *C,
|
||||
const int p_index = gmap->vert_to_poly[v_index][j];
|
||||
|
||||
int elem_index;
|
||||
if constexpr (domain == ATTR_DOMAIN_POINT) {
|
||||
if (vpd->domain == ATTR_DOMAIN_POINT) {
|
||||
elem_index = v_index;
|
||||
}
|
||||
else {
|
||||
@ -3344,6 +3366,7 @@ static void do_vpaint_brush_smear(bContext *C,
|
||||
|
||||
color_curr[elem_index] = lcol[elem_index];
|
||||
}
|
||||
});
|
||||
}
|
||||
BKE_pbvh_vertex_iter_end;
|
||||
}
|
||||
@ -3357,32 +3380,34 @@ static void calculate_average_color(VPaintData *vpd,
|
||||
GMutableSpan lcol,
|
||||
Span<PBVHNode *> nodes)
|
||||
{
|
||||
using Blend = typename Traits::BlendType;
|
||||
|
||||
const blender::VArray<bool> select_vert = *me->attributes().lookup_or_default<bool>(
|
||||
".select_vert", ATTR_DOMAIN_POINT, false);
|
||||
|
||||
VPaintAverageAccum<Blend> *accum = (VPaintAverageAccum<Blend> *)MEM_mallocN(
|
||||
sizeof(*accum) * nodes.size(), __func__);
|
||||
blender::threading::parallel_for(nodes.index_range(), 1LL, [&](IndexRange range) {
|
||||
for (int n : range) {
|
||||
SculptSession *ss = ob->sculpt;
|
||||
const PBVHType pbvh_type = BKE_pbvh_type(ss->pbvh);
|
||||
const bool has_grids = (pbvh_type == PBVH_GRIDS);
|
||||
const SculptVertexPaintGeomMap *gmap = &ss->mode.vpaint.gmap;
|
||||
|
||||
StrokeCache *cache = ss->cache;
|
||||
const bool use_vert_sel = (me->editflag &
|
||||
(ME_EDIT_PAINT_FACE_SEL | ME_EDIT_PAINT_VERT_SEL)) != 0;
|
||||
|
||||
VPaintAverageAccum<Blend> *accum2 = accum + n;
|
||||
accum2->len = 0;
|
||||
memset(accum2->value, 0, sizeof(accum2->value));
|
||||
const bool use_vert_sel = (me->editflag & (ME_EDIT_PAINT_FACE_SEL | ME_EDIT_PAINT_VERT_SEL)) !=
|
||||
0;
|
||||
|
||||
SculptBrushTest test;
|
||||
SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape(
|
||||
ss, &test, brush->falloff_shape);
|
||||
|
||||
const blender::VArray<bool> select_vert = *me->attributes().lookup_or_default<bool>(
|
||||
".select_vert", ATTR_DOMAIN_POINT, false);
|
||||
|
||||
to_static_color_type(vpd->type, [&](auto dummy) {
|
||||
using Color = decltype(dummy);
|
||||
using Blend = typename Traits::BlendType;
|
||||
|
||||
VPaintAverageAccum<Blend> *accum = (VPaintAverageAccum<Blend> *)MEM_mallocN(
|
||||
sizeof(*accum) * nodes.size(), __func__);
|
||||
blender::threading::parallel_for(nodes.index_range(), 1LL, [&](IndexRange range) {
|
||||
for (int n : range) {
|
||||
VPaintAverageAccum<Blend> *accum2 = accum + n;
|
||||
accum2->len = 0;
|
||||
memset(accum2->value, 0, sizeof(accum2->value));
|
||||
|
||||
/* For each vertex */
|
||||
PBVHVertexIter vd;
|
||||
BKE_pbvh_vertex_iter_begin (ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) {
|
||||
@ -3405,7 +3430,7 @@ static void calculate_average_color(VPaintData *vpd,
|
||||
for (int j = 0; j < gmap->vert_to_poly[v_index].size(); j++) {
|
||||
int elem_index;
|
||||
|
||||
if constexpr (domain == ATTR_DOMAIN_CORNER) {
|
||||
if (vpd->domain == ATTR_DOMAIN_CORNER) {
|
||||
elem_index = gmap->vert_to_loop[v_index][j];
|
||||
}
|
||||
else {
|
||||
@ -3442,6 +3467,7 @@ static void calculate_average_color(VPaintData *vpd,
|
||||
|
||||
vpd->paintcol = blend;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
template<typename Color>
|
||||
@ -3477,6 +3503,24 @@ static void vpaint_do_draw(bContext *C,
|
||||
const Brush *brush = ob->sculpt->cache->brush;
|
||||
const Scene *scene = CTX_data_scene(C);
|
||||
|
||||
const bool has_grids = (pbvh_type == PBVH_GRIDS);
|
||||
const SculptVertexPaintGeomMap *gmap = &ss->mode.vpaint.gmap;
|
||||
|
||||
const StrokeCache *cache = ss->cache;
|
||||
float brush_size_pressure, brush_alpha_value, brush_alpha_pressure;
|
||||
get_brush_alpha_data(
|
||||
scene, ss, brush, &brush_size_pressure, &brush_alpha_value, &brush_alpha_pressure);
|
||||
const bool use_normal = vwpaint_use_normal(vp);
|
||||
const bool use_vert_sel = (me->editflag & (ME_EDIT_PAINT_FACE_SEL | ME_EDIT_PAINT_VERT_SEL)) !=
|
||||
0;
|
||||
const bool use_face_sel = (me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0;
|
||||
|
||||
SculptBrushTest test;
|
||||
SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape(
|
||||
ss, &test, brush->falloff_shape);
|
||||
const float *sculpt_normal_frontface = SCULPT_brush_frontface_normal_from_falloff_shape(
|
||||
ss, brush->falloff_shape);
|
||||
|
||||
GMutableSpan previous_color = ss->cache->prev_colors_vpaint;
|
||||
|
||||
const blender::VArray<bool> select_vert = *me->attributes().lookup_or_default<bool>(
|
||||
@ -3486,25 +3530,7 @@ static void vpaint_do_draw(bContext *C,
|
||||
|
||||
blender::threading::parallel_for(nodes.index_range(), 1LL, [&](IndexRange range) {
|
||||
for (int n : range) {
|
||||
const bool has_grids = (pbvh_type == PBVH_GRIDS);
|
||||
const SculptVertexPaintGeomMap *gmap = &ss->mode.vpaint.gmap;
|
||||
|
||||
const StrokeCache *cache = ss->cache;
|
||||
float brush_size_pressure, brush_alpha_value, brush_alpha_pressure;
|
||||
get_brush_alpha_data(
|
||||
scene, ss, brush, &brush_size_pressure, &brush_alpha_value, &brush_alpha_pressure);
|
||||
const bool use_normal = vwpaint_use_normal(vp);
|
||||
const bool use_vert_sel = (me->editflag &
|
||||
(ME_EDIT_PAINT_FACE_SEL | ME_EDIT_PAINT_VERT_SEL)) != 0;
|
||||
const bool use_face_sel = (me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0;
|
||||
|
||||
SculptBrushTest test;
|
||||
SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape(
|
||||
ss, &test, brush->falloff_shape);
|
||||
const float *sculpt_normal_frontface = SCULPT_brush_frontface_normal_from_falloff_shape(
|
||||
ss, brush->falloff_shape);
|
||||
|
||||
Color paintcol = vpd->paintcol;
|
||||
ColorPaint4f paintcol = vpd->paintcol;
|
||||
|
||||
/* For each vertex */
|
||||
PBVHVertexIter vd;
|
||||
@ -3536,6 +3562,8 @@ static void vpaint_do_draw(bContext *C,
|
||||
}
|
||||
const float brush_fade = BKE_brush_curve_strength(brush, sqrtf(test.dist), cache->radius);
|
||||
|
||||
to_static_color_type(vpd->type, [&](auto dummy) {
|
||||
using Color = decltype(dummy);
|
||||
Color color_final = paintcol;
|
||||
|
||||
/* If we're painting with a texture, sample the texture color and alpha. */
|
||||
@ -3548,7 +3576,7 @@ static void vpaint_do_draw(bContext *C,
|
||||
|
||||
Color color_orig(0, 0, 0, 0);
|
||||
|
||||
if constexpr (domain == ATTR_DOMAIN_POINT) {
|
||||
if (vpd->domain == ATTR_DOMAIN_POINT) {
|
||||
int v_index = vd.index;
|
||||
|
||||
if (previous_color != nullptr) {
|
||||
@ -3598,6 +3626,7 @@ static void vpaint_do_draw(bContext *C,
|
||||
Traits::range * brush_strength);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
BKE_pbvh_vertex_iter_end;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user