Cleanup: make BKE_mesh_ensure_normals_for_display public
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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). */
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user