From f49780b8881591b23907d2d218ba30993c4f6eec Mon Sep 17 00:00:00 2001 From: Jesse Yurkovich Date: Sun, 7 Jul 2024 21:27:01 +0200 Subject: [PATCH] Fix #120590: USD: Ensure mesh normals are actually normalized This normal data is eventually passed into `BKE_mesh_set_custom_normals` and through to `mesh_normals_corner_custom_set` which expects normals to actually be normalized per its documentation. Not doing so would yield meshes with incorrect "sharp" data for affected edges. Pull Request: https://projects.blender.org/blender/blender/pulls/124267 --- source/blender/io/usd/intern/usd_reader_mesh.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc index f3bc638fc99..bbcdc064031 100644 --- a/source/blender/io/usd/intern/usd_reader_mesh.cc +++ b/source/blender/io/usd/intern/usd_reader_mesh.cc @@ -25,6 +25,7 @@ #include "BLI_map.hh" #include "BLI_math_vector_types.hh" #include "BLI_span.hh" +#include "BLI_task.hh" #include "DNA_customdata_types.h" #include "DNA_material_types.h" @@ -269,6 +270,14 @@ bool USDMeshReader::topology_changed(const Mesh *existing_mesh, const double mot normal_interpolation_ = mesh_prim_.GetNormalsInterpolation(); } + /* Blender expects mesh normals to actually be normalized. */ + MutableSpan usd_data(normals_.data(), normals_.size()); + threading::parallel_for(usd_data.index_range(), 4096, [&](const IndexRange range) { + for (const int normal_i : range) { + usd_data[normal_i].Normalize(); + } + }); + return positions_.size() != existing_mesh->verts_num || face_counts_.size() != existing_mesh->faces_num || face_indices_.size() != existing_mesh->corners_num;