From f9132e2bbf009309d7d744e2da636db12dde38f8 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Wed, 15 Mar 2023 14:33:51 -0400 Subject: [PATCH] Cleanup: Remove redundant mesh normals dirty tag function Since normals are derived data, it's always a change to something else that will cause them to change, like the winding order of a face or vertex positions. So it's clearer to use tags for those things directly. It's correct to remove the tag in one place since dirty is the default state of a new mesh. --- source/blender/blenkernel/BKE_mesh.h | 8 -------- source/blender/blenkernel/intern/mesh_normals.cc | 5 ----- source/blender/blenkernel/intern/mesh_runtime.cc | 3 ++- source/blender/editors/mesh/mesh_data.cc | 4 ++-- source/blender/modifiers/intern/MOD_normal_edit.cc | 5 ++--- source/blender/modifiers/intern/MOD_solidify_extrude.cc | 1 - 6 files changed, 6 insertions(+), 20 deletions(-) diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index ec675f231ad..ee8ff5f4510 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -336,14 +336,6 @@ const float (*BKE_mesh_vert_normals_ensure(const struct Mesh *mesh))[3]; */ const float (*BKE_mesh_poly_normals_ensure(const struct Mesh *mesh))[3]; -/** - * Tag mesh vertex and face normals to be recalculated when/if they are needed later. - * - * \note Dirty tagged normals are the default state of a new mesh, so tagging them - * dirty explicitly is not always necessary if the mesh is created locally. - */ -void BKE_mesh_normals_tag_dirty(struct Mesh *mesh); - /** * Retrieve write access to the cached vertex normals, ensuring that they are allocated but *not* * that they are calculated. The provided vertex normals should be the same as if they were diff --git a/source/blender/blenkernel/intern/mesh_normals.cc b/source/blender/blenkernel/intern/mesh_normals.cc index 3d2357b3b80..11a844411e4 100644 --- a/source/blender/blenkernel/intern/mesh_normals.cc +++ b/source/blender/blenkernel/intern/mesh_normals.cc @@ -100,11 +100,6 @@ static void add_v3_v3_atomic(float r[3], const float a[3]) * Related to managing normals but not directly related to calculating normals. * \{ */ -void BKE_mesh_normals_tag_dirty(Mesh *mesh) -{ - mesh->runtime->vert_normals_dirty = true; - mesh->runtime->poly_normals_dirty = true; -} float (*BKE_mesh_vert_normals_for_write(Mesh *mesh))[3] { diff --git a/source/blender/blenkernel/intern/mesh_runtime.cc b/source/blender/blenkernel/intern/mesh_runtime.cc index 65a001f71fd..03dafc4c1c4 100644 --- a/source/blender/blenkernel/intern/mesh_runtime.cc +++ b/source/blender/blenkernel/intern/mesh_runtime.cc @@ -246,7 +246,8 @@ void BKE_mesh_tag_edges_split(struct Mesh *mesh) void BKE_mesh_tag_positions_changed(Mesh *mesh) { - BKE_mesh_normals_tag_dirty(mesh); + mesh->runtime->vert_normals_dirty = true; + mesh->runtime->poly_normals_dirty = true; free_bvh_cache(*mesh->runtime); mesh->runtime->looptris_cache.tag_dirty(); mesh->runtime->bounds_cache.tag_dirty(); diff --git a/source/blender/editors/mesh/mesh_data.cc b/source/blender/editors/mesh/mesh_data.cc index 5aeb6b24598..9627d88f258 100644 --- a/source/blender/editors/mesh/mesh_data.cc +++ b/source/blender/editors/mesh/mesh_data.cc @@ -1116,8 +1116,8 @@ void ED_mesh_update(Mesh *mesh, bContext *C, bool calc_edges, bool calc_edges_lo /* Default state is not to have tessface's so make sure this is the case. */ BKE_mesh_tessface_clear(mesh); - /* Tag lazily calculated data as dirty. */ - BKE_mesh_normals_tag_dirty(mesh); + mesh->runtime->vert_normals_dirty = true; + mesh->runtime->poly_normals_dirty = true; DEG_id_tag_update(&mesh->id, 0); WM_event_add_notifier(C, NC_GEOM | ND_DATA, mesh); diff --git a/source/blender/modifiers/intern/MOD_normal_edit.cc b/source/blender/modifiers/intern/MOD_normal_edit.cc index daf65bd8e13..2262e904166 100644 --- a/source/blender/modifiers/intern/MOD_normal_edit.cc +++ b/source/blender/modifiers/intern/MOD_normal_edit.cc @@ -315,8 +315,7 @@ static void normalEditModifier_do_radial(NormalEditModifierData *enmd, if (do_polynors_fix && polygons_check_flip( loops, nos.data(), &mesh->ldata, polys, BKE_mesh_poly_normals_for_write(mesh))) { - /* We need to recompute vertex normals! */ - BKE_mesh_normals_tag_dirty(mesh); + mesh->runtime->vert_normals_dirty = true; } const bool *sharp_faces = static_cast( CustomData_get_layer_named(&mesh->pdata, CD_PROP_BOOL, "sharp_face")); @@ -422,7 +421,7 @@ static void normalEditModifier_do_directional(NormalEditModifierData *enmd, if (do_polynors_fix && polygons_check_flip( loops, nos.data(), &mesh->ldata, polys, BKE_mesh_poly_normals_for_write(mesh))) { - BKE_mesh_normals_tag_dirty(mesh); + mesh->runtime->vert_normals_dirty = true; } const bool *sharp_faces = static_cast( CustomData_get_layer_named(&mesh->pdata, CD_PROP_BOOL, "sharp_face")); diff --git a/source/blender/modifiers/intern/MOD_solidify_extrude.cc b/source/blender/modifiers/intern/MOD_solidify_extrude.cc index 47715737c58..63b8cf1eeab 100644 --- a/source/blender/modifiers/intern/MOD_solidify_extrude.cc +++ b/source/blender/modifiers/intern/MOD_solidify_extrude.cc @@ -971,7 +971,6 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex /* must recalculate normals with vgroups since they can displace unevenly #26888. */ if (BKE_mesh_vert_normals_are_dirty(mesh) || do_rim || dvert) { - BKE_mesh_normals_tag_dirty(result); } else if (do_shell) { uint i;