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:
authorCampbell Barton <ideasman42@gmail.com>2018-10-11 08:32:49 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-10-11 08:34:12 +0300
commitb7363941f7ddfd5154a0a61f17c6186d049793be (patch)
treebe23f7256974558ab872ebbd4547ac99d8451b60 /source/blender/blenkernel/intern/mesh_evaluate.c
parentbf455c2ca98ff3062a733ad357f2c2c43ffda5df (diff)
Cleanup: make BKE_mesh_ensure_normals_for_display public
Diffstat (limited to 'source/blender/blenkernel/intern/mesh_evaluate.c')
-rw-r--r--source/blender/blenkernel/intern/mesh_evaluate.c29
1 files changed, 29 insertions, 0 deletions
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)
{