[Bf-blender-cvs] [b7363941f7d] blender2.8: Cleanup: make BKE_mesh_ensure_normals_for_display public

Campbell Barton noreply at git.blender.org
Thu Oct 11 07:34:44 CEST 2018


Commit: b7363941f7ddfd5154a0a61f17c6186d049793be
Author: Campbell Barton
Date:   Thu Oct 11 16:32:49 2018 +1100
Branches: blender2.8
https://developer.blender.org/rBb7363941f7ddfd5154a0a61f17c6186d049793be

Cleanup: make BKE_mesh_ensure_normals_for_display public

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

M	source/blender/blenkernel/BKE_mesh.h
M	source/blender/blenkernel/intern/DerivedMesh.c
M	source/blender/blenkernel/intern/mesh_evaluate.c

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

diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index 44a3b56a320..89bde516264 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -235,6 +235,7 @@ void BKE_mesh_calc_normals_poly(
         const bool only_face_normals);
 void BKE_mesh_calc_normals(struct Mesh *me);
 void BKE_mesh_ensure_normals(struct Mesh *me);
+void BKE_mesh_ensure_normals_for_display(struct Mesh *mesh);
 void BKE_mesh_calc_normals_tessface(
         struct MVert *mverts, int numVerts,
         const struct MFace *mfaces, int numFaces,
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index e04a5bcf0a3..d1f58b675b2 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -1363,37 +1363,6 @@ static void add_shapekey_layers(Mesh *me_dst, Mesh *me_src, Object *UNUSED(ob))
 	}
 }
 
-/**
- * Called after calculating all modifiers.
- *
- * \note tessfaces should already be calculated.
- */
-static void mesh_ensure_display_normals(Mesh *mesh)
-{
-	/* Note: mesh *may* have a poly CD_NORMAL layer (generated by a modifier needing poly normals e.g.).
-	 *       We do not use it here, though. And it should be tagged as temp!
-	 */
-	/* BLI_assert((CustomData_has_layer(&mesh->pdata, CD_NORMAL) == false)); */
-
-	if (mesh->runtime.cd_dirty_vert & CD_MASK_NORMAL || !CustomData_has_layer(&mesh->pdata, CD_NORMAL)) {
-		float (*face_nors)[3] = NULL;
-		face_nors = MEM_malloc_arrayN(mesh->totpoly, sizeof(*face_nors), "face_nors");
-
-		/* if normals are dirty we want to calculate vertex normals too */
-		bool only_face_normals = !(mesh->runtime.cd_dirty_vert & CD_MASK_NORMAL);
-
-		/* calculate face normals */
-		BKE_mesh_calc_normals_poly(
-		        mesh->mvert, NULL, mesh->totvert, mesh->mloop, mesh->mpoly,
-		        mesh->totloop, mesh->totpoly, face_nors,
-		        only_face_normals);
-
-		CustomData_add_layer(&mesh->pdata, CD_NORMAL, CD_ASSIGN, face_nors, mesh->totpoly);
-
-		mesh->runtime.cd_dirty_vert &= ~CD_MASK_NORMAL;
-	}
-}
-
 static void mesh_calc_modifiers(
         struct Depsgraph *depsgraph, Scene *scene, Object *ob, float (*inputVertexCos)[3],
         int useDeform,
@@ -1828,7 +1797,7 @@ static void mesh_calc_modifiers(
 		 * If using loop normals, poly nors have already been computed.
 		 */
 		if (!do_loop_normals) {
-			mesh_ensure_display_normals(*r_final);
+			BKE_mesh_ensure_normals_for_display(*r_final);
 		}
 	}
 
@@ -2167,7 +2136,7 @@ static void editbmesh_calc_modifiers(
 
 	/* same as mesh_calc_modifiers (if using loop normals, poly nors have already been computed). */
 	if (!do_loop_normals) {
-		mesh_ensure_display_normals(*r_final);
+		BKE_mesh_ensure_normals_for_display(*r_final);
 
 		/* Some modifiers, like datatransfer, may generate those data, we do not want to keep them,
 		 * as they are used by display code when available (i.e. even if autosmooth is disabled). */
diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c
index f20d17c7917..f9ced904536 100644
--- a/source/blender/blenkernel/intern/mesh_evaluate.c
+++ b/source/blender/blenkernel/intern/mesh_evaluate.c
@@ -354,6 +354,35 @@ void BKE_mesh_ensure_normals(Mesh *mesh)
 	BLI_assert((mesh->runtime.cd_dirty_vert & CD_MASK_NORMAL) == 0);
 }
 
+/**
+ * Called after calculating all modifiers.
+ */
+void BKE_mesh_ensure_normals_for_display(Mesh *mesh)
+{
+	/* Note: mesh *may* have a poly CD_NORMAL layer (generated by a modifier needing poly normals e.g.).
+	 *       We do not use it here, though. And it should be tagged as temp!
+	 */
+	/* BLI_assert((CustomData_has_layer(&mesh->pdata, CD_NORMAL) == false)); */
+
+	if (mesh->runtime.cd_dirty_vert & CD_MASK_NORMAL || !CustomData_has_layer(&mesh->pdata, CD_NORMAL)) {
+		float (*poly_nors)[3] = NULL;
+		poly_nors = MEM_malloc_arrayN((size_t)mesh->totpoly, sizeof(*poly_nors), __func__);
+
+		/* if normals are dirty we want to calculate vertex normals too */
+		bool only_face_normals = !(mesh->runtime.cd_dirty_vert & CD_MASK_NORMAL);
+
+		/* calculate face normals */
+		BKE_mesh_calc_normals_poly(
+		        mesh->mvert, NULL, mesh->totvert, mesh->mloop, mesh->mpoly,
+		        mesh->totloop, mesh->totpoly, poly_nors,
+		        only_face_normals);
+
+		CustomData_add_layer(&mesh->pdata, CD_NORMAL, CD_ASSIGN, poly_nors, mesh->totpoly);
+
+		mesh->runtime.cd_dirty_vert &= ~CD_MASK_NORMAL;
+	}
+}
+
 /* Note that this does not update the CD_NORMAL layer, but does update the normals in the CD_MVERT layer. */
 void BKE_mesh_calc_normals(Mesh *mesh)
 {



More information about the Bf-blender-cvs mailing list