Cleanup: Remove poly normal writing

The potential optimization in the normal edit modifier when flipping
faces isn't worth the "API impurity" and complexity introduced by
adding poly normal editing as part of the API. This change simplifies
future changes to the ownership of poly normals with a shared cache,
which can prevent recomputing poly normals completely.
This commit is contained in:
Hans Goudey
2023-04-03 12:11:21 -04:00
parent e76f4d9f9a
commit 7a1ec82af4
3 changed files with 9 additions and 47 deletions

View File

@@ -333,30 +333,11 @@ const float (*BKE_mesh_poly_normals_ensure(const struct Mesh *mesh))[3];
*/
float (*BKE_mesh_vert_normals_for_write(struct Mesh *mesh))[3];
/**
* Retrieve write access to the cached polygon normals, ensuring that they are allocated but *not*
* that they are calculated. The provided polygon normals should be the same as if they were
* calculated automatically.
*
* \note In order to clear the dirty flag, this function should be followed by a call to
* #BKE_mesh_poly_normals_clear_dirty. This is separate so that normals are still tagged dirty
* while they are being assigned.
*
* \warning The memory returned by this function is not initialized if it was not previously
* allocated.
*/
float (*BKE_mesh_poly_normals_for_write(struct Mesh *mesh))[3];
/**
* Mark the mesh's vertex normals non-dirty, for when they are calculated or assigned manually.
*/
void BKE_mesh_vert_normals_clear_dirty(struct Mesh *mesh);
/**
* Mark the mesh's poly normals non-dirty, for when they are calculated or assigned manually.
*/
void BKE_mesh_poly_normals_clear_dirty(struct Mesh *mesh);
/**
* Return true if the mesh vertex normals either are not stored or are dirty.
* This can be used to help decide whether to transfer them when copying a mesh.

View File

@@ -106,24 +106,12 @@ float (*BKE_mesh_vert_normals_for_write(Mesh *mesh))[3]
return reinterpret_cast<float(*)[3]>(mesh->runtime->vert_normals.data());
}
float (*BKE_mesh_poly_normals_for_write(Mesh *mesh))[3]
{
mesh->runtime->poly_normals.reinitialize(mesh->totpoly);
return reinterpret_cast<float(*)[3]>(mesh->runtime->poly_normals.data());
}
void BKE_mesh_vert_normals_clear_dirty(Mesh *mesh)
{
mesh->runtime->vert_normals_dirty = false;
BLI_assert(mesh->runtime->vert_normals.size() == mesh->totvert);
}
void BKE_mesh_poly_normals_clear_dirty(Mesh *mesh)
{
mesh->runtime->poly_normals_dirty = false;
BLI_assert(mesh->runtime->poly_normals.size() == mesh->totpoly);
}
bool BKE_mesh_vert_normals_are_dirty(const Mesh *mesh)
{
return mesh->runtime->vert_normals_dirty;

View File

@@ -184,7 +184,7 @@ static bool polygons_check_flip(blender::MutableSpan<int> corner_verts,
blender::float3 *nos,
CustomData *ldata,
const blender::Span<MPoly> polys,
float (*poly_normals)[3])
const blender::Span<blender::float3> poly_normals)
{
MDisps *mdisp = static_cast<MDisps *>(
CustomData_get_layer_for_write(ldata, CD_MDISPS, corner_verts.size()));
@@ -211,7 +211,6 @@ static bool polygons_check_flip(blender::MutableSpan<int> corner_verts,
reinterpret_cast<float(*)[3]>(nos),
mdisp,
true);
negate_v3(poly_normals[i]);
flipped = true;
}
}
@@ -324,13 +323,10 @@ static void normalEditModifier_do_radial(NormalEditModifierData *enmd,
nos.data());
}
if (do_polynors_fix && polygons_check_flip(corner_verts,
corner_edges,
nos.data(),
&mesh->ldata,
polys,
BKE_mesh_poly_normals_for_write(mesh))) {
mesh->runtime->vert_normals_dirty = true;
if (do_polynors_fix &&
polygons_check_flip(
corner_verts, corner_edges, nos.data(), &mesh->ldata, polys, mesh->poly_normals())) {
BKE_mesh_tag_face_winding_changed(mesh);
}
const bool *sharp_faces = static_cast<const bool *>(
CustomData_get_layer_named(&mesh->pdata, CD_PROP_BOOL, "sharp_face"));
@@ -434,13 +430,10 @@ static void normalEditModifier_do_directional(NormalEditModifierData *enmd,
nos.data());
}
if (do_polynors_fix && polygons_check_flip(corner_verts,
corner_edges,
nos.data(),
&mesh->ldata,
polys,
BKE_mesh_poly_normals_for_write(mesh))) {
mesh->runtime->vert_normals_dirty = true;
if (do_polynors_fix &&
polygons_check_flip(
corner_verts, corner_edges, nos.data(), &mesh->ldata, polys, mesh->poly_normals())) {
BKE_mesh_tag_face_winding_changed(mesh);
}
const bool *sharp_faces = static_cast<const bool *>(
CustomData_get_layer_named(&mesh->pdata, CD_PROP_BOOL, "sharp_face"));