Skip to content

Commit

Permalink
Merge pull request #1250 from koen-v/dev
Browse files Browse the repository at this point in the history
Adding support for indexed normals on import #1029
  • Loading branch information
Krystian Ligenza authored Mar 15, 2021
2 parents 48b49ec + 24cb011 commit cc103f6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/mayaUsd/fileio/translators/translatorMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ TranslatorMeshRead::TranslatorMeshRead(
// timeInterval or default.
VtVec3fArray points;
VtVec3fArray normals;
TfToken normalsInterpolation;
UsdTimeCode pointsTimeSample = UsdTimeCode::EarliestTime();
UsdTimeCode normalsTimeSample = UsdTimeCode::EarliestTime();
std::vector<double> pointsTimeSamples;
Expand All @@ -139,7 +140,17 @@ TranslatorMeshRead::TranslatorMeshRead(
}

mesh.GetPointsAttr().Get(&points, pointsTimeSample);
mesh.GetNormalsAttr().Get(&normals, normalsTimeSample);

/* If 'normals' and 'primvars:normals' are both specified, the latter has precedence. */
UsdGeomPrimvar primvar = mesh.GetPrimvar(UsdGeomTokens->normals);

if (primvar.HasValue()) {
primvar.ComputeFlattened(&normals, normalsTimeSample);
normalsInterpolation = primvar.GetInterpolation();
} else {
mesh.GetNormalsAttr().Get(&normals, normalsTimeSample);
normalsInterpolation = mesh.GetNormalsInterpolation();
}

if (points.empty()) {
TF_RUNTIME_ERROR(
Expand Down Expand Up @@ -221,7 +232,7 @@ TranslatorMeshRead::TranslatorMeshRead(
TfToken subdScheme;
if (mesh.GetSubdivisionSchemeAttr().Get(&subdScheme) && subdScheme == UsdGeomTokens->none) {
if (normals.size() == static_cast<size_t>(meshFn.numFaceVertices())
&& mesh.GetNormalsInterpolation() == UsdGeomTokens->faceVarying) {
&& normalsInterpolation == UsdGeomTokens->faceVarying) {
UsdMayaMeshReadUtils::setEmitNormalsTag(meshFn, true);
}
} else {
Expand Down
29 changes: 29 additions & 0 deletions test/lib/usd/translators/UsdImportMeshTest/Mesh.usda
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,35 @@ def Xform "World"
uniform token subdivisionScheme = "none"
}

def Mesh "IndexedNormalsMesh" (
kind = "component"
)
{
float3[] extent = [(1.5, 1.5, 1.5), (2.5, 2.5, 2.5)]
int[] faceVertexCounts = [4, 4, 4, 4, 4, 4]
int[] faceVertexIndices = [0, 1, 3, 2, 2, 3, 5, 4, 4, 5, 7, 6, 6, 7, 1, 0, 1, 7, 5, 3, 6, 0, 2, 4]
token interpolateBoundary = "none"

normal3f[] primvars:normals = [(0, 0, 1), (0, 1, 0), (0, 0, -1), (0, -1, 0) , (1, 0, 0), (-1, 0, 0)] (
interpolation = "faceVarying"
)
int[] primvars:normals:indices = [0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5]

point3f[] points = [(2.5, 2.5, 3.5), (3.5, 2.5, 3.5), (2.5, 3.5, 3.5), (3.5, 3.5, 3.5), (2.5, 3.5, 2.5), (3.5, 3.5, 2.5), (2.5, 2.5, 2.5), (3.5, 2.5, 2.5)]
color3f[] primvars:displayColor = [(0.13320851, 0.13320851, 0.13320851)] (
customData = {
dictionary Maya = {
bool generated = 1
}
}
)
texCoord2f[] primvars:st = [(0.375, 0), (0.625, 0), (0.625, 0.25), (0.375, 0.25), (0.625, 0.5), (0.375, 0.5), (0.625, 0.75), (0.375, 0.75), (0.625, 1), (0.375, 1), (0.875, 0), (0.875, 0.25), (0.125, 0), (0.125, 0.25)] (
interpolation = "faceVarying"
)
int[] primvars:st:indices = [0, 1, 2, 3, 3, 2, 4, 5, 5, 4, 6, 7, 7, 6, 8, 9, 1, 10, 11, 2, 12, 0, 3, 13]
uniform token subdivisionScheme = "none"
}

def Mesh "LeftHandedPolyMesh" (
kind = "component"
)
Expand Down
3 changes: 3 additions & 0 deletions test/lib/usd/translators/testUsdImportMesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ def verifyPolyMeshCommonAttributes(self, mesh):
def testImportPoly(self):
self.verifyPolyMeshCommonAttributes('PolyMeshShape')

def testImportIndexedNormals(self):
self.verifyPolyMeshCommonAttributes('IndexedNormalsMeshShape')

def testImportLeftHandedPoly(self):
self.verifyPolyMeshCommonAttributes('LeftHandedPolyMeshShape')

Expand Down

0 comments on commit cc103f6

Please sign in to comment.