[Bf-blender-cvs] [bec72a43aef] blender-v3.0-release: Fix T92874: Custom normals reset when vertex is deleted

Campbell Barton noreply at git.blender.org
Wed Nov 10 11:20:54 CET 2021


Commit: bec72a43aef0d0f4553f193be6d67df001dfe3b7
Author: Campbell Barton
Date:   Wed Nov 10 21:11:41 2021 +1100
Branches: blender-v3.0-release
https://developer.blender.org/rBbec72a43aef0d0f4553f193be6d67df001dfe3b7

Fix T92874: Custom normals reset when vertex is deleted

Storing and restoring custom normals was broken by
39b2a7bb7e815e051348bf5c5ec777d091324164

This also caused "Sharp Edge" option for Weld by Distance to fail,
reported as T92875.

===================================================================

M	source/blender/bmesh/intern/bmesh_mesh_normals.c

===================================================================

diff --git a/source/blender/bmesh/intern/bmesh_mesh_normals.c b/source/blender/bmesh/intern/bmesh_mesh_normals.c
index 186c85abe58..16ce9703568 100644
--- a/source/blender/bmesh/intern/bmesh_mesh_normals.c
+++ b/source/blender/bmesh/intern/bmesh_mesh_normals.c
@@ -404,16 +404,13 @@ void BM_normals_loops_edges_tag(BMesh *bm, const bool do_edges)
  */
 static void bm_mesh_edges_sharp_tag(BMesh *bm,
                                     const float (*fnos)[3],
-                                    const float split_angle,
+                                    float split_angle_cos,
                                     const bool do_sharp_edges_tag)
 {
   BMIter eiter;
   BMEdge *e;
   int i;
 
-  const bool check_angle = (split_angle < (float)M_PI);
-  const float split_angle_cos = check_angle ? cosf(split_angle) : -1.0f;
-
   if (fnos) {
     BM_mesh_elem_index_ensure(bm, BM_FACE);
   }
@@ -451,7 +448,7 @@ void BM_edges_sharp_from_angle_set(BMesh *bm, const float split_angle)
     return;
   }
 
-  bm_mesh_edges_sharp_tag(bm, NULL, split_angle, true);
+  bm_mesh_edges_sharp_tag(bm, NULL, cosf(split_angle), true);
 }
 
 /** \} */
@@ -1110,11 +1107,13 @@ static void bm_mesh_loops_calc_normals__single_threaded(BMesh *bm,
                                                         const short (*clnors_data)[2],
                                                         const int cd_loop_clnors_offset,
                                                         const bool do_rebuild,
-                                                        const float split_angle)
+                                                        const float split_angle_cos)
 {
   BMIter fiter;
   BMFace *f_curr;
   const bool has_clnors = clnors_data || (cd_loop_clnors_offset != -1);
+  /* When false the caller must have already tagged the edges. */
+  const bool do_edge_tag = (split_angle_cos != EDGE_TAG_FROM_SPLIT_ANGLE_BYPASS);
 
   MLoopNorSpaceArray _lnors_spacearr = {NULL};
 
@@ -1155,7 +1154,9 @@ static void bm_mesh_loops_calc_normals__single_threaded(BMesh *bm,
 
   /* Always tag edges based on winding & sharp edge flag
    * (even when the auto-smooth angle doesn't need to be calculated). */
-  bm_mesh_edges_sharp_tag(bm, fnos, has_clnors ? (float)M_PI : split_angle, false);
+  if (do_edge_tag) {
+    bm_mesh_edges_sharp_tag(bm, fnos, has_clnors ? -1.0f : split_angle_cos, false);
+  }
 
   /* We now know edges that can be smoothed (they are tagged),
    * and edges that will be hard (they aren't).
@@ -1308,12 +1309,9 @@ static void bm_mesh_loops_calc_normals__multi_threaded(BMesh *bm,
                                                        const short (*clnors_data)[2],
                                                        const int cd_loop_clnors_offset,
                                                        const bool do_rebuild,
-                                                       const float split_angle)
+                                                       const float split_angle_cos)
 {
   const bool has_clnors = clnors_data || (cd_loop_clnors_offset != -1);
-  const bool check_angle = (split_angle < (float)M_PI);
-  const float split_angle_cos = check_angle ? cosf(split_angle) : -1.0f;
-
   MLoopNorSpaceArray _lnors_spacearr = {NULL};
 
   {
@@ -1387,7 +1385,7 @@ static void bm_mesh_loops_calc_normals(BMesh *bm,
                                        const short (*clnors_data)[2],
                                        const int cd_loop_clnors_offset,
                                        const bool do_rebuild,
-                                       const float split_angle)
+                                       const float split_angle_cos)
 {
   if (bm->totloop < BM_OMP_LIMIT) {
     bm_mesh_loops_calc_normals__single_threaded(bm,
@@ -1398,7 +1396,7 @@ static void bm_mesh_loops_calc_normals(BMesh *bm,
                                                 clnors_data,
                                                 cd_loop_clnors_offset,
                                                 do_rebuild,
-                                                split_angle);
+                                                split_angle_cos);
   }
   else {
     bm_mesh_loops_calc_normals__multi_threaded(bm,
@@ -1409,7 +1407,7 @@ static void bm_mesh_loops_calc_normals(BMesh *bm,
                                                clnors_data,
                                                cd_loop_clnors_offset,
                                                do_rebuild,
-                                               split_angle);
+                                               split_angle_cos);
   }
 }
 
@@ -1620,7 +1618,7 @@ static void bm_mesh_loops_custom_normals_set(BMesh *bm,
 
   /* Tag smooth edges and set lnos from vnos when they might be completely smooth...
    * When using custom loop normals, disable the angle feature! */
-  bm_mesh_edges_sharp_tag(bm, fnos, (float)M_PI, false);
+  bm_mesh_edges_sharp_tag(bm, fnos, -1.0f, false);
 
   /* Finish computing lnos by accumulating face normals
    * in each fan of faces defined by sharp edges. */
@@ -1751,7 +1749,7 @@ void BM_loops_calc_normal_vcos(BMesh *bm,
                                clnors_data,
                                cd_loop_clnors_offset,
                                do_rebuild,
-                               has_clnors ? (float)M_PI : split_angle);
+                               has_clnors ? -1.0f : cosf(split_angle));
   }
   else {
     BLI_assert(!r_lnors_spacearr);



More information about the Bf-blender-cvs mailing list