Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormakowalski <makowalski@nvidia.com>2021-02-09 00:14:47 +0300
committermakowalski <makowalski@nvidia.com>2021-02-09 00:14:47 +0300
commit63adcda7da073abcb0bb2a78921417a12afceb19 (patch)
treef8f30b0ba21dad720e02301fb2f45dea9b8ce5c3
parentb16b847882d24df11fa88cc47441f240640daba0 (diff)
Apply orientation when importing USD normals.
Also added check to ensure normal and loop counts match.
-rw-r--r--source/blender/io/usd/intern/usd_reader_mesh.cc20
1 files changed, 17 insertions, 3 deletions
diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc
index e48ce812a2e..9c735e930f0 100644
--- a/source/blender/io/usd/intern/usd_reader_mesh.cc
+++ b/source/blender/io/usd/intern/usd_reader_mesh.cc
@@ -510,7 +510,14 @@ void USDMeshReader::process_normals_vertex_varying(Mesh *mesh)
void USDMeshReader::process_normals_face_varying(Mesh *mesh)
{
- if (m_normals.size() <= 0) {
+ if (m_normals.empty()) {
+ BKE_mesh_calc_normals(mesh);
+ return;
+ }
+
+ // Check for normals count mismatches to prevent crashes.
+ if (m_normals.size() != mesh->totloop) {
+ std::cerr << "WARNING: loop normal count mismatch for mesh " << mesh->id.name << std::endl;
BKE_mesh_calc_normals(mesh);
return;
}
@@ -523,12 +530,19 @@ void USDMeshReader::process_normals_face_varying(Mesh *mesh)
MEM_malloc_arrayN(loop_count, sizeof(float[3]), "USD::FaceNormals"));
MPoly *mpoly = mesh->mpoly;
- int usd_index = 0;
for (int i = 0, e = mesh->totpoly; i < e; ++i, ++mpoly) {
- for (int j = 0; j < mpoly->totloop; j++, usd_index++) {
+ for (int j = 0; j < mpoly->totloop; j++) {
int blender_index = mpoly->loopstart + j;
+ int usd_index = mpoly->loopstart;
+ if (m_isLeftHanded) {
+ usd_index += mpoly->totloop - 1 - j;
+ }
+ else {
+ usd_index += j;
+ }
+
lnors[blender_index][0] = m_normals[usd_index][0];
lnors[blender_index][1] = m_normals[usd_index][1];
lnors[blender_index][2] = m_normals[usd_index][2];