diff options
author | Hans Goudey <h.goudey@me.com> | 2022-03-22 17:33:50 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-03-22 17:33:50 +0300 |
commit | 64cd927519748bbd50b856c25f7e4eac17d8c780 (patch) | |
tree | ca23f3b5d63c5d6a01afcb8aa0177a84ee01851f /source/blender/io | |
parent | 86d87fcbdbd5f4a18d2fdcc4f827d9bee6b5ed32 (diff) |
Fix T96308: Mesh to BMesh conversion doesn't calculate vertex normals
Currently there is a "calc_face_normal" argument to mesh to bmesh
conversion, but vertex normals had always implicitly inherited whatever
dirty state the mesh input's vertex normals were in. Probably they were
most often assumed to not be dirty, but this was never really correct in
the general case.
Ever since the refactor to move vertex normals out of mesh vertices,
cfa53e0fbeed7178c7, the copying logic has been explicit: copy the
normals when they are not dirty. But it turns out that more control is
needed, and sometimes normals should be calculated for the resulting
BMesh.
This commit adds an option to the conversion to calculate vertex
normals, true by default. In almost all places except the decimate
and edge split modifiers, I just copied the value of the
"calc_face_normals" argument.
Differential Revision: https://developer.blender.org/D14406
Diffstat (limited to 'source/blender/io')
-rw-r--r-- | source/blender/io/alembic/exporter/abc_writer_mesh.cc | 1 | ||||
-rw-r--r-- | source/blender/io/collada/collada_utils.cpp | 1 | ||||
-rw-r--r-- | source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc | 13 |
3 files changed, 11 insertions, 4 deletions
diff --git a/source/blender/io/alembic/exporter/abc_writer_mesh.cc b/source/blender/io/alembic/exporter/abc_writer_mesh.cc index 11693eeb4de..bbb196dc383 100644 --- a/source/blender/io/alembic/exporter/abc_writer_mesh.cc +++ b/source/blender/io/alembic/exporter/abc_writer_mesh.cc @@ -158,6 +158,7 @@ void ABCGenericMeshWriter::do_write(HierarchyContext &context) BMeshCreateParams bmesh_create_params{}; BMeshFromMeshParams bmesh_from_mesh_params{}; bmesh_from_mesh_params.calc_face_normal = true; + bmesh_from_mesh_params.calc_vert_normal = true; BMesh *bm = BKE_mesh_to_bmesh_ex(mesh, &bmesh_create_params, &bmesh_from_mesh_params); BM_mesh_triangulate(bm, quad_method, ngon_method, 4, tag_only, nullptr, nullptr, nullptr); diff --git a/source/blender/io/collada/collada_utils.cpp b/source/blender/io/collada/collada_utils.cpp index 79ac5be35f8..8d7ada4a600 100644 --- a/source/blender/io/collada/collada_utils.cpp +++ b/source/blender/io/collada/collada_utils.cpp @@ -411,6 +411,7 @@ void bc_triangulate_mesh(Mesh *me) BMesh *bm = BM_mesh_create(&bm_mesh_allocsize_default, &bm_create_params); BMeshFromMeshParams bm_from_me_params{}; bm_from_me_params.calc_face_normal = true; + bm_from_me_params.calc_vert_normal = true; BM_mesh_bm_from_me(bm, me, &bm_from_me_params); BM_mesh_triangulate(bm, quad_method, use_beauty, 4, tag_only, nullptr, nullptr, nullptr); diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc index e92f70472d0..603e8ac755b 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc @@ -89,8 +89,13 @@ std::pair<Mesh *, bool> OBJMesh::triangulate_mesh_eval() if (export_mesh_eval_->totpoly <= 0) { return {export_mesh_eval_, false}; } - const struct BMeshCreateParams bm_create_params = {0u}; - const struct BMeshFromMeshParams bm_convert_params = {1u, 0, 0, 0}; + const BMeshCreateParams bm_create_params = {0u}; + BMeshFromMeshParams bm_convert_params{}; + bm_convert_params.calc_face_normal = true; + bm_convert_params.calc_vert_normal = true; + bm_convert_params.add_key_index = false; + bm_convert_params.use_shapekey = false; + /* Lower threshold where triangulation of a polygon starts, i.e. a quadrilateral will be * triangulated here. */ const int triangulate_min_verts = 4; @@ -377,8 +382,8 @@ void OBJMesh::store_normal_coords_and_indices() normal_to_index.reserve(export_mesh_eval_->totpoly); loop_to_normal_index_.resize(export_mesh_eval_->totloop); loop_to_normal_index_.fill(-1); - const float( - *lnors)[3] = (const float(*)[3])(CustomData_get_layer(&export_mesh_eval_->ldata, CD_NORMAL)); + const float(*lnors)[3] = (const float(*)[3])( + CustomData_get_layer(&export_mesh_eval_->ldata, CD_NORMAL)); for (int poly_index = 0; poly_index < export_mesh_eval_->totpoly; ++poly_index) { const MPoly &mpoly = export_mesh_eval_->mpoly[poly_index]; bool need_per_loop_normals = lnors != nullptr || (mpoly.flag & ME_SMOOTH); |