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
This commit is contained in:
Jesse Yurkovich 2024-07-07 21:27:01 +02:00 committed by Jesse Yurkovich
parent bdb444bc2b
commit f49780b888

@ -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<pxr::GfVec3f> 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;