Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Parborg <darkdefende@gmail.com>2020-08-04 20:30:14 +0300
committerSebastian Parborg <darkdefende@gmail.com>2020-08-04 20:43:34 +0300
commite4370eccdf8e718b4d20ad6121145883407f686e (patch)
treea748db7d3fc941bcfdb877e5df78a53f9805eb72
parente818f1274b8ec774eb4ad27e2cc31c5722a561a9 (diff)
Fix T71488: Flipping Custom Split Normal Data leads to artifacts
The winding order of the faces changes when flipping the faces. This lead to the loop indices changing as well. Now we take this into account when restoring and flipping the custom normals. Before the normals would be swapped.
-rw-r--r--source/blender/editors/mesh/editmesh_tools.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c
index d699d761709..4de7143682a 100644
--- a/source/blender/editors/mesh/editmesh_tools.c
+++ b/source/blender/editors/mesh/editmesh_tools.c
@@ -2035,19 +2035,26 @@ static bool flip_custom_normals(BMesh *bm, BMLoopNorEditDataArray *lnors_ed_arr)
}
BMFace *f;
- BMLoop *l;
- BMIter iter_f, iter_l;
+ BMLoop *l, *l_start;
+ BMIter iter_f;
BM_ITER_MESH (f, &iter_f, bm, BM_FACES_OF_MESH) {
+ /* Flip all the custom loop normals on the selected faces. */
if (!BM_elem_flag_test(f, BM_ELEM_SELECT)) {
continue;
}
- /* Flip all the custom loop normals on the selected faces. */
- BM_ITER_ELEM (l, &iter_l, f, BM_LOOPS_OF_FACE) {
+ /* Because the winding has changed, we need to go the reverse way around the face to get the
+ * correct placement of the normals. However we need to derive the old loop index to get the
+ * correct data. Note that the first loop index is the same though. So the loop starts and ends
+ * in the same place as before the flip.
+ */
+ l_start = l = BM_FACE_FIRST_LOOP(f);
+ int old_index = BM_elem_index_get(l);
+ do {
int loop_index = BM_elem_index_get(l);
- BMLoopNorEditData *lnor_ed = lnors_ed_arr->lidx_to_lnor_editdata[loop_index];
+ BMLoopNorEditData *lnor_ed = lnors_ed_arr->lidx_to_lnor_editdata[old_index];
BMLoopNorEditData *lnor_ed_new = lnors_ed_arr_new_full->lidx_to_lnor_editdata[loop_index];
BLI_assert(lnor_ed != NULL && lnor_ed_new != NULL);
@@ -2055,7 +2062,10 @@ static bool flip_custom_normals(BMesh *bm, BMLoopNorEditDataArray *lnors_ed_arr)
BKE_lnor_space_custom_normal_to_data(
bm->lnor_spacearr->lspacearr[loop_index], lnor_ed->nloc, lnor_ed_new->clnors_data);
- }
+
+ old_index++;
+ l = l->prev;
+ } while (l != l_start);
}
BM_loop_normal_editdata_array_free(lnors_ed_arr_new_full);
return true;