[Bf-blender-cvs] [ae04ef9c407] usd-importer-T81257-merge: USD Import: UV import fixes.

makowalski noreply at git.blender.org
Mon Apr 5 22:44:35 CEST 2021


Commit: ae04ef9c407dca7a8db847ff96e3037a50f53e1f
Author: makowalski
Date:   Mon Apr 5 15:21:30 2021 -0400
Branches: usd-importer-T81257-merge
https://developer.blender.org/rBae04ef9c407dca7a8db847ff96e3037a50f53e1f

USD Import: UV import fixes.

Now skipping UV sets with interpolation types other than vextex
and faceVarying, since these are the only types we currently
support.  Also, calling UsdGeomPrimvar::ComputeFlattened() on
the UV primvars to avoid special logic to handle indexed UVs.

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

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 0cdff46aace..6c63f72756d 100644
--- a/source/blender/io/usd/intern/usd_reader_mesh.cc
+++ b/source/blender/io/usd/intern/usd_reader_mesh.cc
@@ -335,7 +335,6 @@ void USDMeshReader::read_uvs(Mesh *mesh,
 
   struct UVSample {
     pxr::VtVec2fArray uvs;
-    pxr::VtIntArray indices;  // Non-empty for indexed UVs
     pxr::TfToken interpolation;
   };
 
@@ -375,8 +374,7 @@ void USDMeshReader::read_uvs(Mesh *mesh,
       }
 
       if (pxr::UsdGeomPrimvar uv_primvar = mesh_prim_.GetPrimvar(uv_token)) {
-        uv_primvar.Get<pxr::VtVec2fArray>(&uv_primvars[layer_idx].uvs, motionSampleTime);
-        uv_primvar.GetIndices(&uv_primvars[layer_idx].indices, motionSampleTime);
+        uv_primvar.ComputeFlattened(&uv_primvars[layer_idx].uvs, motionSampleTime);
         uv_primvars[layer_idx].interpolation = uv_primvar.GetInterpolation();
       }
     }
@@ -407,15 +405,22 @@ void USDMeshReader::read_uvs(Mesh *mesh,
 
         const UVSample &sample = uv_primvars[layer_idx];
 
+        if (!(sample.interpolation == pxr::UsdGeomTokens->faceVarying ||
+              sample.interpolation == pxr::UsdGeomTokens->vertex)) {
+          /* Shouldn't happen. */
+          std::cerr << "WARNING: unexpected interpolation type " << sample.interpolation << " for uv "
+            << layer->name << std::endl;
+          continue;
+        }
+
         // For Vertex interpolation, use the vertex index.
         int usd_uv_index = sample.interpolation == pxr::UsdGeomTokens->vertex ?
                                mesh->mloop[loop_index].v :
                                loop_index;
 
-        // Handle indexed UVs.
-        usd_uv_index = sample.indices.empty() ? usd_uv_index : sample.indices[usd_uv_index];
-
         if (usd_uv_index >= sample.uvs.size()) {
+          std::cerr << "WARNING: out of bounds uv index " << usd_uv_index << " for uv "
+                    << layer->name << " of size " << sample.uvs.size() << std::endl;
           continue;
         }
 
@@ -767,6 +772,14 @@ Mesh *USDMeshReader::read_mesh(Mesh *existing_mesh,
     }
 
     if (is_uv) {
+
+      pxr::TfToken interp = p.GetInterpolation();
+
+      if (!(interp == pxr::UsdGeomTokens->faceVarying ||
+            interp == pxr::UsdGeomTokens->vertex)) {
+        continue;
+      }
+
       uv_tokens.push_back(p.GetBaseName());
       has_uvs_ = true;



More information about the Bf-blender-cvs mailing list