diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-08-13 12:38:19 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-08-13 12:45:01 +0300 |
commit | 4cadccebfacfa8533ba06403960e8b1218da61f5 (patch) | |
tree | eed8e2f5d0c4dc08d6deebc00392bb1e03d9bc26 /source/blender/bmesh/intern | |
parent | b9486c39bcd57098b2baf8fb5d69088768a88e35 (diff) |
Revert "Mesh: replace saacos with acosf for normal calculation"
This reverts commit 41e650981861c2f18ab0548e18851d1d761066ff.
This broke "CubeMaskFirst" test.
Any value even slightly outside the [-1.0..1.0] range
caused the result to be nan, which can happen when calculating
the dot-product between two unit length vectors.
Diffstat (limited to 'source/blender/bmesh/intern')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_mesh_normals.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/source/blender/bmesh/intern/bmesh_mesh_normals.c b/source/blender/bmesh/intern/bmesh_mesh_normals.c index 6a2cfdb056c..a5e41b74ee1 100644 --- a/source/blender/bmesh/intern/bmesh_mesh_normals.c +++ b/source/blender/bmesh/intern/bmesh_mesh_normals.c @@ -84,13 +84,11 @@ BLI_INLINE void bm_vert_calc_normals_accum_loop(const BMLoop *l_iter, if ((l_iter->prev->e->v1 == l_iter->prev->v) ^ (l_iter->e->v1 == l_iter->v)) { dotprod = -dotprod; } - /* Calculate angle between the two poly edges incident on this vertex. - * NOTE: no need for #saacos here as the input has been sanitized, - * `nan` values in coordinates normalize to zero which works for `acosf`. */ - const float fac = acosf(-dotprod); - /* NAN values should never happen. */ - BLI_assert(fac == fac); - madd_v3_v3fl(v_no, f_no, fac); + const float fac = saacos(-dotprod); + /* NAN detection, otherwise this is a degenerated case, ignore that vertex in this case. */ + if (fac == fac) { + madd_v3_v3fl(v_no, f_no, fac); + } } static void bm_vert_calc_normals_impl(BMVert *v) @@ -682,11 +680,9 @@ static int bm_mesh_loops_calc_normals_for_loop(BMesh *bm, { /* Code similar to accumulate_vertex_normals_poly_v3. */ - /* Calculate angle between the two poly edges incident on this vertex. - * NOTE: no need for #saacos here as the input has been sanitized, - * `nan` values in coordinates normalize to zero which works for `acosf`. */ + /* Calculate angle between the two poly edges incident on this vertex. */ const BMFace *f = lfan_pivot->f; - const float fac = acosf(dot_v3v3(vec_next, vec_curr)); + const float fac = saacos(dot_v3v3(vec_next, vec_curr)); const float *no = fnos ? fnos[BM_elem_index_get(f)] : f->no; /* Accumulate */ madd_v3_v3fl(lnor, no, fac); |