Cleanup: Reduce use and scope of templates in vertex paint #2

Closed
Hans Goudey wants to merge 10 commits from paint-vertex-fewer-templates into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
7 changed files with 785 additions and 738 deletions
Showing only changes of commit 779a808174 - Show all commits

View File

@ -1023,7 +1023,7 @@ static void ccgDM_release(DerivedMesh *dm)
if (ccgdm->multires.modified_flags) {
/* Check that mmd still exists */
if (!ccgdm->multires.local_mmd &&
BLI_findindex(&ccgdm->multires.ob->modifiers, ccgdm->multires.mmd) < 0)
BLI_findindex(&ccgdm->multires.ob->modifiers, ccgdm->multires.mmd) == -1)
{
ccgdm->multires.mmd = nullptr;
}

View File

@ -3009,6 +3009,36 @@ static void do_vpaint_brush_blur_loops(bContext *C,
continue;
}
/* Use rgb^2 color averaging. */
Color *col = &color_final;
color_final.r = Traits::round(sqrtf(Traits::divide_round(blend[0], total_hit_loops)));
color_final.g = Traits::round(sqrtf(Traits::divide_round(blend[1], total_hit_loops)));
color_final.b = Traits::round(sqrtf(Traits::divide_round(blend[2], total_hit_loops)));
color_final.a = Traits::round(sqrtf(Traits::divide_round(blend[3], total_hit_loops)));
/* For each poly owning this vert,
* paint each loop belonging to this vert. */
for (const int j : gmap->vert_to_poly[v_index].index_range()) {
const int p_index = gmap->vert_to_poly[v_index][j];
const int l_index = gmap->vert_to_loop[v_index][j];
BLI_assert(ss->corner_verts[l_index] == v_index);
if (use_face_sel && !select_poly[p_index]) {
continue;
}
Color color_orig(0, 0, 0, 0); /* unused when array is nullptr */
if (previous_color != nullptr) {
/* Get the previous loop color */
if (isZero(previous_color[l_index])) {
previous_color[l_index] = lcol[l_index];
}
}
if (total_hit_loops == 0) {
continue;
}
/* Use rgb^2 color averaging. */
Color *col = &;
@ -3039,8 +3069,12 @@ static void do_vpaint_brush_blur_loops(bContext *C,
brush_alpha_pressure * grid_alpha;
/* Mix the new color with the original
* based on the brush strength and the curve. */
lcol[l_index] = vpaint_blend<Color, Traits>(
vp, lcol[l_index], color_orig, *col, final_alpha, Traits::range * brush_strength);
lcol[l_index] = vpaint_blend<Color, Traits>(vp,
lcol[l_index],
color_orig,
*col,
final_alpha,
Traits::range * brush_strength);
}
});
}
@ -3110,13 +3144,15 @@ static void do_vpaint_brush_blur_verts(bContext *C,
}
float brush_strength = cache->bstrength;
const float angle_cos = (use_normal && vd.no) ? dot_v3v3(sculpt_normal_frontface, vd.no) :
const float angle_cos = (use_normal && vd.no) ?
dot_v3v3(sculpt_normal_frontface, vd.no) :
1.0f;
if (!test_brush_angle_falloff(
*brush, vpd->normal_angle_precalc, angle_cos, &brush_strength)) {
continue;
}
const float brush_fade = BKE_brush_curve_strength(brush, sqrtf(test.dist), cache->radius);
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) {
@ -3174,8 +3210,12 @@ static void do_vpaint_brush_blur_verts(bContext *C,
brush_alpha_pressure * grid_alpha;
/* Mix the new color with the original
* based on the brush strength and the curve. */
lcol[v_index] = vpaint_blend<Color, Traits>(
vp, lcol[v_index], color_orig, *col, final_alpha, Traits::range * brush_strength);
lcol[v_index] = vpaint_blend<Color, Traits>(vp,
lcol[v_index],
color_orig,
*col,
final_alpha,
Traits::range * brush_strength);
}
});
}
@ -3261,13 +3301,15 @@ static void do_vpaint_brush_smear(bContext *C,
/* Calculate the dot prod. between ray norm on surf and current vert
* (ie splash prevention factor), and only paint front facing verts. */
float brush_strength = cache->bstrength;
const float angle_cos = (use_normal && vd.no) ? dot_v3v3(sculpt_normal_frontface, vd.no) :
const float angle_cos = (use_normal && vd.no) ?
dot_v3v3(sculpt_normal_frontface, vd.no) :
1.0f;
if (!test_brush_angle_falloff(
*brush, vpd->normal_angle_precalc, angle_cos, &brush_strength)) {
continue;
}
const float brush_fade = BKE_brush_curve_strength(brush, sqrtf(test.dist), cache->radius);
const float brush_fade = BKE_brush_curve_strength(
brush, sqrtf(test.dist), cache->radius);
bool do_color = false;
/* Minimum dot product between brush direction and current
@ -3554,13 +3596,15 @@ static void vpaint_do_draw(bContext *C,
/* Calc the dot prod. between ray norm on surf and current vert
* (ie splash prevention factor), and only paint front facing verts. */
float brush_strength = cache->bstrength;
const float angle_cos = (use_normal && vd.no) ? dot_v3v3(sculpt_normal_frontface, vd.no) :
const float angle_cos = (use_normal && vd.no) ?
dot_v3v3(sculpt_normal_frontface, vd.no) :
1.0f;
if (!test_brush_angle_falloff(
*brush, vpd->normal_angle_precalc, angle_cos, &brush_strength)) {
continue;
}
const float brush_fade = BKE_brush_curve_strength(brush, sqrtf(test.dist), cache->radius);
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);
@ -3614,8 +3658,8 @@ static void vpaint_do_draw(bContext *C,
}
color_orig = previous_color[l_index];
}
const float final_alpha = Traits::frange * brush_fade * brush_strength * tex_alpha *
brush_alpha_pressure * grid_alpha;
const float final_alpha = Traits::frange * brush_fade * brush_strength *
tex_alpha * brush_alpha_pressure * grid_alpha;
/* Mix the new color with the original based on final_alpha. */
lcol[l_index] = vpaint_blend<Color, Traits>(vp,
@ -4078,7 +4122,8 @@ 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);
return paint_object_attributes_active_color_fill_ex(
ob, ColorPaint4f(fill_color), only_selected);
}
static int vertex_color_set_exec(bContext *C, wmOperator * /*op*/)
@ -4110,4 +4155,4 @@ void PAINT_OT_vertex_color_set(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/** \} */
/** \} */

View File

@ -658,7 +658,7 @@ static void rna_ArmatureConstraint_target_remove(
bArmatureConstraint *acon = static_cast<bArmatureConstraint *>(con->data);
bConstraintTarget *tgt = static_cast<bConstraintTarget *>(target_ptr->data);
if (BLI_findindex(&acon->targets, tgt) < 0) {
if (BLI_findindex(&acon->targets, tgt) == -1) {
BKE_report(reports, RPT_ERROR, "Target is not in the constraint target list");
return;
}

View File

@ -1474,8 +1474,9 @@ static Sequence *rna_SeqTimelineChannel_owner_get(Editing *ed, SeqTimelineChanne
if (seq->type != SEQ_TYPE_META) {
continue;
}
if (BLI_findindex(&seq->channels, channel) >= 0) {
if (BLI_findindex(&seq->channels, channel) != -1) {
channel_owner = seq;
break;
}
}

View File

@ -280,7 +280,8 @@ int seq_get_shown_sequences(const Scene *scene,
scene, channels, seqbase, timeline_frame, chanshown);
const int strip_count = BLI_gset_len(collection->set);
if (strip_count > MAXSEQ) {
if (UNLIKELY(strip_count > MAXSEQ)) {
SEQ_collection_free(collection);
BLI_assert_msg(0, "Too many strips, this shouldn't happen");
return 0;
}
@ -1878,7 +1879,7 @@ static ImBuf *seq_render_strip_stack(const SeqRenderData *context,
ImBuf *out = NULL;
count = seq_get_shown_sequences(
context->scene, channels, seqbasep, timeline_frame, chanshown, (Sequence **)&seq_arr);
context->scene, channels, seqbasep, timeline_frame, chanshown, seq_arr);
if (count == 0) {
return NULL;

View File

@ -377,7 +377,7 @@ ListBase *SEQ_get_seqbase_by_seq(const Scene *scene, Sequence *seq)
if (seq_meta != NULL) {
return &seq_meta->seqbase;
}
if (BLI_findindex(main_seqbase, seq) >= 0) {
if (BLI_findindex(main_seqbase, seq) != -1) {
return main_seqbase;
}
return NULL;

View File

@ -1950,7 +1950,7 @@ void wm_window_delete_removed_timers(wmWindowManager *wm)
void WM_event_remove_timer(wmWindowManager *wm, wmWindow *UNUSED(win), wmTimer *timer)
{
/* Extra security check. */
if (BLI_findindex(&wm->timers, timer) < 0) {
if (BLI_findindex(&wm->timers, timer) == -1) {
return;
}