diff --git a/source/blender/blenkernel/BKE_mesh_runtime.h b/source/blender/blenkernel/BKE_mesh_runtime.h index 01e382aaead..083f83ef059 100644 --- a/source/blender/blenkernel/BKE_mesh_runtime.h +++ b/source/blender/blenkernel/BKE_mesh_runtime.h @@ -39,7 +39,7 @@ bool BKE_mesh_runtime_ensure_edit_data(struct Mesh *mesh); void BKE_mesh_runtime_reset_edit_data(struct Mesh *mesh); /** - * Clear and any derived caches associated with the mesh geometry data. Examples include BVH + * Clear and free any derived caches associated with the mesh geometry data. Examples include BVH * caches, normals, triangulation, etc. This should be called when replacing a mesh's geometry * directly or making other large changes to topology. It does not need to be called on new meshes. * diff --git a/source/blender/blenkernel/BKE_mesh_types.h b/source/blender/blenkernel/BKE_mesh_types.h index 793f1085aaa..5f20a6c2e14 100644 --- a/source/blender/blenkernel/BKE_mesh_types.h +++ b/source/blender/blenkernel/BKE_mesh_types.h @@ -149,8 +149,8 @@ struct MeshRuntime { * #CustomData because they can be calculated on a `const` mesh, and adding custom data layers on * a `const` mesh is not thread-safe. */ - bool vert_normals_dirty = false; - bool poly_normals_dirty = false; + bool vert_normals_dirty = true; + bool poly_normals_dirty = true; float (*vert_normals)[3] = nullptr; float (*poly_normals)[3] = nullptr; diff --git a/source/blender/blenkernel/intern/mesh.cc b/source/blender/blenkernel/intern/mesh.cc index 59f946889b0..8331369cb38 100644 --- a/source/blender/blenkernel/intern/mesh.cc +++ b/source/blender/blenkernel/intern/mesh.cc @@ -91,10 +91,6 @@ static void mesh_init_data(ID *id) mesh->runtime = new blender::bke::MeshRuntime(); - /* A newly created mesh does not have normals, so tag them dirty. This will be cleared - * by #BKE_mesh_vertex_normals_clear_dirty or #BKE_mesh_poly_normals_ensure. */ - BKE_mesh_normals_tag_dirty(mesh); - mesh->face_sets_color_seed = BLI_hash_int(PIL_check_seconds_timer_i() & UINT_MAX); } @@ -163,13 +159,6 @@ static void mesh_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int mesh_dst->mselect = (MSelect *)MEM_dupallocN(mesh_dst->mselect); - /* Set normal layers dirty. They should be dirty by default on new meshes anyway, but being - * explicit about it is safer. Alternatively normal layers could be copied if they aren't dirty, - * avoiding recomputation in some cases. However, a copied mesh is often changed anyway, so that - * idea is not clearly better. With proper reference counting, all custom data layers could be - * copied as the cost would be much lower. */ - BKE_mesh_normals_tag_dirty(mesh_dst); - /* TODO: Do we want to add flag to prevent this? */ if (mesh_src->key && (flag & LIB_ID_COPY_SHAPEKEY)) { BKE_id_copy_ex(bmain, &mesh_src->key->id, (ID **)&mesh_dst->key, flag); @@ -363,10 +352,6 @@ static void mesh_blend_read_data(BlendDataReader *reader, ID *id) BLI_endian_switch_uint32_array(tf->col, 4); } } - - /* We don't expect to load normals from files, since they are derived data. */ - BKE_mesh_normals_tag_dirty(mesh); - BKE_mesh_assert_normals_dirty_or_calculated(mesh); } static void mesh_blend_read_lib(BlendLibReader *reader, ID *id) diff --git a/source/blender/editors/mesh/meshtools.cc b/source/blender/editors/mesh/meshtools.cc index a1f6683a13b..64e49c1c06d 100644 --- a/source/blender/editors/mesh/meshtools.cc +++ b/source/blender/editors/mesh/meshtools.cc @@ -688,9 +688,6 @@ int ED_mesh_join_objects_exec(bContext *C, wmOperator *op) me->ldata = ldata; me->pdata = pdata; - /* Tag normals dirty because vertex positions could be changed from the original. */ - BKE_mesh_normals_tag_dirty(me); - /* old material array */ for (a = 1; a <= ob->totcol; a++) { ma = ob->mat[a - 1]; diff --git a/source/blender/editors/sculpt_paint/sculpt_ops.c b/source/blender/editors/sculpt_paint/sculpt_ops.c index 28d67518b66..fcebf2df4ba 100644 --- a/source/blender/editors/sculpt_paint/sculpt_ops.c +++ b/source/blender/editors/sculpt_paint/sculpt_ops.c @@ -220,7 +220,6 @@ static int sculpt_symmetrize_exec(bContext *C, wmOperator *op) BKE_mesh_mirror_apply_mirror_on_axis(bmain, mesh, sd->symmetrize_direction, dist); ED_sculpt_undo_geometry_end(ob); - BKE_mesh_normals_tag_dirty(mesh); BKE_mesh_batch_cache_dirty_tag(ob->data, BKE_MESH_BATCH_DIRTY_ALL); break; diff --git a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp index 64e7be5169c..1c51ff02aaf 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp +++ b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp @@ -797,7 +797,6 @@ void BlenderStrokeRenderer::GenerateStrokeMesh(StrokeGroup *group, bool hasTex) } // loop over strokes BKE_object_materials_test(freestyle_bmain, object_mesh, (ID *)mesh); - BKE_mesh_normals_tag_dirty(mesh); #if 0 // XXX BLI_assert(mesh->totvert == vertex_index); diff --git a/source/blender/io/alembic/intern/abc_reader_mesh.cc b/source/blender/io/alembic/intern/abc_reader_mesh.cc index 2531bd62609..458fd72501d 100644 --- a/source/blender/io/alembic/intern/abc_reader_mesh.cc +++ b/source/blender/io/alembic/intern/abc_reader_mesh.cc @@ -147,6 +147,7 @@ static void read_mverts(CDStreamConfig &config, const AbcMeshData &mesh_data) mesh_data.ceil_positions != nullptr && mesh_data.ceil_positions->size() == positions->size()) { read_mverts_interp(mverts, positions, mesh_data.ceil_positions, config.weight); + BKE_mesh_tag_coords_changed(config.mesh); return; } @@ -162,6 +163,8 @@ void read_mverts(Mesh &mesh, const P3fArraySamplePtr positions, const N3fArraySa copy_zup_from_yup(mvert.co, pos_in.getValue()); } + BKE_mesh_tag_coords_changed(&mesh); + if (normals) { float(*vert_normals)[3] = BKE_mesh_vertex_normals_for_write(&mesh); for (const int64_t i : IndexRange(normals->size())) { @@ -246,7 +249,6 @@ static void read_mpolys(CDStreamConfig &config, const AbcMeshData &mesh_data) static void process_no_normals(CDStreamConfig &config) { /* Absence of normals in the Alembic mesh is interpreted as 'smooth'. */ - BKE_mesh_normals_tag_dirty(config.mesh); } static void process_loop_normals(CDStreamConfig &config, const N3fArraySamplePtr loop_normals_ptr) diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc index 8138f38fcad..52cd3b32b49 100644 --- a/source/blender/io/usd/intern/usd_reader_mesh.cc +++ b/source/blender/io/usd/intern/usd_reader_mesh.cc @@ -613,14 +613,12 @@ void USDMeshReader::process_normals_vertex_varying(Mesh *mesh) void USDMeshReader::process_normals_face_varying(Mesh *mesh) { if (normals_.empty()) { - BKE_mesh_normals_tag_dirty(mesh); return; } /* Check for normals count mismatches to prevent crashes. */ if (normals_.size() != mesh->totloop) { std::cerr << "WARNING: loop normal count mismatch for mesh " << mesh->id.name << std::endl; - BKE_mesh_normals_tag_dirty(mesh); return; } @@ -658,14 +656,12 @@ void USDMeshReader::process_normals_face_varying(Mesh *mesh) void USDMeshReader::process_normals_uniform(Mesh *mesh) { if (normals_.empty()) { - BKE_mesh_normals_tag_dirty(mesh); return; } /* Check for normals count mismatches to prevent crashes. */ if (normals_.size() != mesh->totpoly) { std::cerr << "WARNING: uniform normal count mismatch for mesh " << mesh->id.name << std::endl; - BKE_mesh_normals_tag_dirty(mesh); return; } @@ -706,6 +702,7 @@ void USDMeshReader::read_mesh_sample(ImportSettings *settings, mvert.co[1] = positions_[i][1]; mvert.co[2] = positions_[i][2]; } + BKE_mesh_tag_coords_changed(mesh); read_vertex_creases(mesh, motionSampleTime); } @@ -718,10 +715,6 @@ void USDMeshReader::read_mesh_sample(ImportSettings *settings, else if (normal_interpolation_ == pxr::UsdGeomTokens->uniform) { process_normals_uniform(mesh); } - else { - /* Default */ - BKE_mesh_normals_tag_dirty(mesh); - } } /* Process point normals after reading polys. */ diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c index f13132b5b7c..247e1cd1173 100644 --- a/source/blender/makesrna/intern/rna_mesh.c +++ b/source/blender/makesrna/intern/rna_mesh.c @@ -716,7 +716,6 @@ static void rna_MeshPolygon_flip(ID *id, MPoly *mp) BKE_mesh_polygon_flip(mp, loops, &me->ldata); BKE_mesh_tessface_clear(me); BKE_mesh_runtime_clear_geometry(me); - BKE_mesh_normals_tag_dirty(me); } static void rna_MeshLoopTriangle_verts_get(PointerRNA *ptr, int *values) diff --git a/source/blender/makesrna/intern/rna_mesh_api.c b/source/blender/makesrna/intern/rna_mesh_api.c index 6b1df3fc4d4..90267a3c3c5 100644 --- a/source/blender/makesrna/intern/rna_mesh_api.c +++ b/source/blender/makesrna/intern/rna_mesh_api.c @@ -169,7 +169,6 @@ static void rna_Mesh_flip_normals(Mesh *mesh) BKE_mesh_polys_flip( BKE_mesh_polys(mesh), BKE_mesh_loops_for_write(mesh), &mesh->ldata, mesh->totpoly); BKE_mesh_tessface_clear(mesh); - BKE_mesh_normals_tag_dirty(mesh); BKE_mesh_runtime_clear_geometry(mesh); DEG_id_tag_update(&mesh->id, 0);