[Bf-blender-cvs] [def37147942] usd-importer-T81257: USD importer: handle 'normals' primvar.

makowalski noreply at git.blender.org
Sun Dec 27 22:18:14 CET 2020


Commit: def371479422e4fe93c5cce58973969204f72b01
Author: makowalski
Date:   Sun Dec 27 14:27:59 2020 -0500
Branches: usd-importer-T81257
https://developer.blender.org/rBdef371479422e4fe93c5cce58973969204f72b01

USD importer: handle 'normals' primvar.

This fix was provided by Koen Vroeijenstijn.  Added logic
to read the normals from 'primvars:normals', if this
primvar exists.

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

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

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

diff --git a/source/blender/io/usd/import/usd_reader_mesh.cc b/source/blender/io/usd/import/usd_reader_mesh.cc
index 5a35efd8077..5b1a52f88d2 100644
--- a/source/blender/io/usd/import/usd_reader_mesh.cc
+++ b/source/blender/io/usd/import/usd_reader_mesh.cc
@@ -62,6 +62,7 @@ struct MeshSampleData {
 };
 
 const pxr::TfToken st_primvar_name("st", pxr::TfToken::Immortal);
+const pxr::TfToken normals_primvar_name("normals", pxr::TfToken::Immortal);
 
 void sample_uvs(const pxr::UsdGeomMesh &mesh,
                 MeshSampleData &mesh_data,
@@ -404,8 +405,18 @@ Mesh *USDMeshReader::create_mesh(Main *bmain, double time)
   read_mpolys(mesh, mesh_data);
 
   if (this->context_.import_params.import_normals) {
-    mesh_.GetNormalsAttr().Get(&mesh_data.normals, time);
-    mesh_data.normals_interpolation = mesh_.GetNormalsInterpolation();
+
+    /* If 'normals' and 'primvars:normals' are both specified, the latter has precedence. */
+    pxr::UsdGeomPrimvar primvar = mesh_.GetPrimvar(normals_primvar_name);
+    if (primvar.HasValue()) {
+      primvar.ComputeFlattened(&mesh_data.normals, time);
+      mesh_data.normals_interpolation = primvar.GetInterpolation();
+    }
+    else {
+      mesh_.GetNormalsAttr().Get(&mesh_data.normals, time);
+      mesh_data.normals_interpolation = mesh_.GetNormalsInterpolation();
+    }
+
     process_normals(mesh, mesh_data);
   }
   else {



More information about the Bf-blender-cvs mailing list