Fix T51733: 3d print toolbox checks report false positives.

Colinear vertices in a same face would not be handled correctly.
This commit is contained in:
Bastien Montagne
2017-06-08 14:02:49 +02:00
parent 6a546fc73e
commit c71e160c02

View File

@@ -1515,16 +1515,30 @@ float BM_loop_calc_face_angle(const BMLoop *l)
*/ */
void BM_loop_calc_face_normal(const BMLoop *l, float r_normal[3]) void BM_loop_calc_face_normal(const BMLoop *l, float r_normal[3])
{ {
if (normal_tri_v3(r_normal, #define FEPSILON 1e-5f
l->prev->v->co,
l->v->co, /* Note: we cannot use result of normal_tri_v3 here to detect colinear vectors (vertex on a straight line)
l->next->v->co) != 0.0f) * from zero value, because it does not normalize both vectors before making crossproduct.
{ * Instead of adding two costly normalize computations, just check ourselves for colinear case. */
/* pass */ /* Note: FEPSILON might need some finer tweaking at some point? Seems to be working OK for now though. */
float v1[3], v2[3], v_tmp[3];
sub_v3_v3v3(v1, l->prev->v->co, l->v->co);
sub_v3_v3v3(v2, l->next->v->co, l->v->co);
const float fac = (v2[0] == 0.0f) ? ((v2[1] == 0.0f) ? ((v2[2] == 0.0f) ? 0.0f : v1[2] / v2[2]) : v1[1] / v2[1]) : v1[0] / v2[0];
mul_v3_v3fl(v_tmp, v2, fac);
sub_v3_v3(v_tmp, v1);
if (fac != 0.0f && !is_zero_v3(v1) && len_manhattan_v3(v_tmp) > FEPSILON) {
/* Not co-linear, we can compute crossproduct and normalize it into normal. */
cross_v3_v3v3(r_normal, v1, v2);
normalize_v3(r_normal);
} }
else { else {
copy_v3_v3(r_normal, l->f->no); copy_v3_v3(r_normal, l->f->no);
} }
#undef FEPSILON
} }
/** /**