From 04c75c5ce7699a1502a7c2212d4aa57166465514 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 3 Aug 2021 12:19:31 +1000 Subject: Edit Mesh: Correct normal calculation for "Set From Faces" Setting normals from faces wasn't weighting the faces contribution by the corner angle, giving lop-sided results in some cases. This removes the epsilon check for CLNORS_VALID_VEC_LEN, in favor of matching the behavior of vertex normals exactly. --- source/blender/editors/mesh/editmesh_tools.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'source/blender/editors/mesh/editmesh_tools.c') diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index 41a9f426798..7e94383390e 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -9538,18 +9538,11 @@ static int edbm_set_normals_from_faces_exec(bContext *C, wmOperator *op) BKE_editmesh_ensure_autosmooth(em, obedit->data); BKE_editmesh_lnorspace_update(em, obedit->data); - float(*vnors)[3] = MEM_callocN(sizeof(*vnors) * bm->totvert, __func__); - BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) { - if (BM_elem_flag_test(f, BM_ELEM_SELECT)) { - BM_ITER_ELEM (v, &viter, f, BM_VERTS_OF_FACE) { - const int v_index = BM_elem_index_get(v); - add_v3_v3(vnors[v_index], f->no); - } - } - } - for (int i = 0; i < bm->totvert; i++) { - if (!is_zero_v3(vnors[i]) && normalize_v3(vnors[i]) < CLNORS_VALID_VEC_LEN) { - zero_v3(vnors[i]); + float(*vnors)[3] = MEM_mallocN(sizeof(*vnors) * bm->totvert, __func__); + { + int v_index; + BM_ITER_MESH_INDEX (v, &viter, bm, BM_VERTS_OF_MESH, v_index) { + BM_vert_calc_normal_ex(v, BM_ELEM_SELECT, vnors[v_index]); } } -- cgit v1.2.3