diff --git a/scene/resources/3d/importer_mesh.cpp b/scene/resources/3d/importer_mesh.cpp index 375efcb22782..f912d2650daf 100644 --- a/scene/resources/3d/importer_mesh.cpp +++ b/scene/resources/3d/importer_mesh.cpp @@ -295,6 +295,7 @@ void ImporterMesh::generate_lods(float p_normal_merge_angle, float p_normal_spli Vector vertices = surfaces[i].arrays[RS::ARRAY_VERTEX]; PackedInt32Array indices = surfaces[i].arrays[RS::ARRAY_INDEX]; Vector normals = surfaces[i].arrays[RS::ARRAY_NORMAL]; + Vector tangents = surfaces[i].arrays[RS::ARRAY_TANGENT]; Vector uvs = surfaces[i].arrays[RS::ARRAY_TEX_UV]; Vector uv2s = surfaces[i].arrays[RS::ARRAY_TEX_UV2]; Vector bones = surfaces[i].arrays[RS::ARRAY_BONES]; @@ -354,6 +355,7 @@ void ImporterMesh::generate_lods(float p_normal_merge_angle, float p_normal_spli LocalVector merged_normals_counts; const Vector2 *uvs_ptr = uvs.ptr(); const Vector2 *uv2s_ptr = uv2s.ptr(); + const float *tangents_ptr = tangents.ptr(); for (unsigned int j = 0; j < vertex_count; j++) { const Vector3 &v = vertices_ptr[j]; @@ -368,9 +370,10 @@ void ImporterMesh::generate_lods(float p_normal_merge_angle, float p_normal_spli for (const Pair &idx : close_verts) { bool is_uvs_close = (!uvs_ptr || uvs_ptr[j].distance_squared_to(uvs_ptr[idx.second]) < CMP_EPSILON2); bool is_uv2s_close = (!uv2s_ptr || uv2s_ptr[j].distance_squared_to(uv2s_ptr[idx.second]) < CMP_EPSILON2); + bool is_tang_aligned = !tangents_ptr || (tangents_ptr[j * 4 + 3] < 0) == (tangents_ptr[idx.second * 4 + 3] < 0); ERR_FAIL_INDEX(idx.second, normals.size()); bool is_normals_close = normals[idx.second].dot(n) > normal_merge_threshold; - if (is_uvs_close && is_uv2s_close && is_normals_close) { + if (is_uvs_close && is_uv2s_close && is_normals_close && is_tang_aligned) { vertex_remap.push_back(idx.first); merged_normals[idx.first] += normals[idx.second]; merged_normals_counts[idx.first]++;