[Bf-blender-cvs] [a9b77cb74f8] usd-importer-T81257-merge: USD import: handle primvars:normals if specified.

makowalski noreply at git.blender.org
Mon Feb 8 22:21:43 CET 2021


Commit: a9b77cb74f870f6cd5d14cd60b3a55f00498dd25
Author: makowalski
Date:   Mon Feb 8 12:59:18 2021 -0500
Branches: usd-importer-T81257-merge
https://developer.blender.org/rBa9b77cb74f870f6cd5d14cd60b3a55f00498dd25

USD import: handle primvars:normals if specified.

Per Pixar UsdGeomPointBased documentation: If 'normals' and
'primvars:normals' are both specified, the latter has precedence.

===================================================================

M	source/blender/io/usd/intern/usd_reader_mesh.cc

===================================================================

diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc
index 8afd8378386..0bc21145e5b 100644
--- a/source/blender/io/usd/intern/usd_reader_mesh.cc
+++ b/source/blender/io/usd/intern/usd_reader_mesh.cc
@@ -72,6 +72,7 @@ static const pxr::TfToken st("st", pxr::TfToken::Immortal);
 static const pxr::TfToken UVMap("UVMap", pxr::TfToken::Immortal);
 static const pxr::TfToken Cd("Cd", pxr::TfToken::Immortal);
 static const pxr::TfToken displayColor("displayColor", pxr::TfToken::Immortal);
+static const pxr::TfToken normalsPrimvar("normals", pxr::TfToken::Immortal);
 }  // namespace usdtokens
 
 namespace utils {
@@ -239,7 +240,16 @@ bool USDMeshReader::topology_changed(Mesh *existing_mesh, double motionSampleTim
   faceVertCountsAttr.Get(&m_face_counts, motionSampleTime);
   pointsAttr.Get(&m_positions, motionSampleTime);
 
-  normalsAttr.Get(&m_normals, motionSampleTime);
+  // If 'normals' and 'primvars:normals' are both specified, the latter has precedence.
+  pxr::UsdGeomPrimvar primvar = mesh_prim.GetPrimvar(usdtokens::normalsPrimvar);
+  if (primvar.HasValue()) {
+    primvar.ComputeFlattened(&m_normals, motionSampleTime);
+    m_normalInterpolation = primvar.GetInterpolation();
+  }
+  else {
+    mesh_prim.GetNormalsAttr().Get(&m_normals, motionSampleTime);
+    m_normalInterpolation = mesh_prim.GetNormalsInterpolation();
+  }
 
   if (m_lastNumPositions != m_positions.size()) {
     m_lastNumPositions = m_positions.size();
@@ -655,8 +665,6 @@ Mesh *USDMeshReader::read_mesh(Mesh *existing_mesh,
   // pxr::UsdAttribute faceVertCountsAttr = mesh_prim.GetFaceVertexCountsAttr();
   // pxr::UsdAttribute faceVertIndicesAttr = mesh_prim.GetFaceVertexIndicesAttr();
 
-  m_normalInterpolation = mesh_prim.GetNormalsInterpolation();
-
   mesh_prim.GetOrientationAttr().Get(&m_orientation);
   if (m_orientation == pxr::UsdGeomTokens->leftHanded)
     m_isLeftHanded = true;



More information about the Bf-blender-cvs mailing list