[Bf-blender-cvs] [ba7052caa94] refactor-mesh-corner-normals-lazy: Cleanup: Make function, remove function

Hans Goudey noreply at git.blender.org
Tue Nov 29 20:15:41 CET 2022


Commit: ba7052caa949449e78252a363f7e673ed189328c
Author: Hans Goudey
Date:   Tue Nov 29 13:06:49 2022 -0600
Branches: refactor-mesh-corner-normals-lazy
https://developer.blender.org/rBba7052caa949449e78252a363f7e673ed189328c

Cleanup: Make function, remove function

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

M	source/blender/blenkernel/BKE_mesh.h
M	source/blender/blenkernel/intern/mesh.cc

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

diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index 3f2d9f14436..950b48f0ad4 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -418,6 +418,8 @@ float (*BKE_mesh_vertex_normals_for_write(struct Mesh *mesh))[3];
  */
 float (*BKE_mesh_poly_normals_for_write(struct Mesh *mesh))[3];
 
+float (*BKE_mesh_corner_normals_for_write(struct Mesh *mesh))[3];
+
 /**
  * Mark the mesh's vertex normals non-dirty, for when they are calculated or assigned manually.
  */
@@ -684,17 +686,6 @@ void BKE_mesh_normals_loop_to_vertex(int numVerts,
  */
 bool BKE_mesh_has_custom_loop_normals(struct Mesh *me);
 
-/**
- * Compute 'split' (aka loop, or per face corner's) normals.
- *
- * \param r_lnors_spacearr: Allows to get computed loop normal space array.
- * That data, among other things, contains 'smooth fan' info, useful e.g.
- * to split geometry along sharp edges.
- */
-void BKE_mesh_calc_normals_split_ex(struct Mesh *mesh,
-                                    struct MLoopNorSpaceArray *r_lnors_spacearr,
-                                    float (*r_corner_normals)[3]);
-
 /**
  * Higher level functions hiding most of the code needed around call to
  * #BKE_mesh_normals_loop_custom_set().
diff --git a/source/blender/blenkernel/intern/mesh.cc b/source/blender/blenkernel/intern/mesh.cc
index ccf3b688424..808e751209e 100644
--- a/source/blender/blenkernel/intern/mesh.cc
+++ b/source/blender/blenkernel/intern/mesh.cc
@@ -1753,36 +1753,14 @@ void BKE_mesh_vert_coords_apply_with_mat4(Mesh *mesh,
   BKE_mesh_tag_coords_changed(mesh);
 }
 
-static float (*ensure_corner_normal_layer(Mesh &mesh))[3]
+static void calc_normals_split(Mesh *mesh,
+                               MLoopNorSpaceArray *r_lnors_spacearr,
+                               float (*r_corner_normals)[3])
 {
-  float(*r_loopnors)[3];
-  if (CustomData_has_layer(&mesh.ldata, CD_NORMAL)) {
-    r_loopnors = (float(*)[3])CustomData_get_layer(&mesh.ldata, CD_NORMAL);
-    memset(r_loopnors, 0, sizeof(float[3]) * mesh.totloop);
-  }
-  else {
-    r_loopnors = (float(*)[3])CustomData_add_layer(
-        &mesh.ldata, CD_NORMAL, CD_SET_DEFAULT, nullptr, mesh.totloop);
-    CustomData_set_layer_flag(&mesh.ldata, CD_NORMAL, CD_FLAG_TEMPORARY);
-  }
-  return r_loopnors;
-}
-
-void BKE_mesh_calc_normals_split_ex(Mesh *mesh,
-                                    MLoopNorSpaceArray *r_lnors_spacearr,
-                                    float (*r_corner_normals)[3])
-{
-  short(*clnors)[2] = nullptr;
-
-  /* Note that we enforce computing clnors when the clnor space array is requested by caller here.
-   * However, we obviously only use the auto-smooth angle threshold
-   * only in case auto-smooth is enabled. */
-  const bool use_split_normals = (r_lnors_spacearr != nullptr) ||
-                                 ((mesh->flag & ME_AUTOSMOOTH) != 0);
   const float split_angle = (mesh->flag & ME_AUTOSMOOTH) != 0 ? mesh->smoothresh : float(M_PI);
 
   /* may be nullptr */
-  clnors = (short(*)[2])CustomData_get_layer(&mesh->ldata, CD_CUSTOMLOOPNORMAL);
+  short(*clnors)[2] = (short(*)[2])CustomData_get_layer(&mesh->ldata, CD_CUSTOMLOOPNORMAL);
 
   const Span<MVert> verts = mesh->verts();
   const Span<MEdge> edges = mesh->edges();
@@ -1800,14 +1778,13 @@ void BKE_mesh_calc_normals_split_ex(Mesh *mesh,
                               polys.data(),
                               BKE_mesh_poly_normals_ensure(mesh),
                               polys.size(),
-                              use_split_normals,
+                              true,
                               split_angle,
                               nullptr,
                               r_lnors_spacearr,
                               clnors);
 }
 
-
 /* Split faces helper functions. */
 
 struct SplitFaceNewVert {
@@ -2018,7 +1995,7 @@ void BKE_mesh_split_faces(Mesh *mesh, bool free_loop_normals)
 
   MLoopNorSpaceArray lnors_spacearr = {nullptr};
   /* Compute loop normals and loop normal spaces (a.k.a. smooth fans of faces around vertices). */
-  BKE_mesh_calc_normals_split_ex(mesh, &lnors_spacearr, ensure_corner_normal_layer(*mesh));
+  calc_normals_split(mesh, &lnors_spacearr, BKE_mesh_corner_normals_for_write(mesh));
   /* Stealing memarena from loop normals space array. */
   MemArena *memarena = lnors_spacearr.mem;



More information about the Bf-blender-cvs mailing list