Skip to content

Commit

Permalink
Fix import of UsdLuxLight Prims
Browse files Browse the repository at this point in the history
Fixes a bug where UsdLuxLight prims underneath a Scope
were not being imported properly (if the Scope only had light prims
underneath it).

The import logic for "Scope" uses a heuristic to see if that scope is a
"Looks" or "Materials" scope.  It did this by checking if any of the
children nodes were UsdShadeConnectableAPI.  Unfortunately, lights (and
other non-shading prims) can be UsdShadeConnectableAPI.

This new heursistic checks for Material prims.  Note, this was more or
less the original version that Autodesk proposed in:
Autodesk#985
  • Loading branch information
dj-mcg committed Feb 11, 2022
1 parent f37eaa1 commit 7a263a4
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 6 deletions.
15 changes: 12 additions & 3 deletions lib/usd/translators/scopeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,30 @@

#include <pxr/pxr.h>
#include <pxr/usd/usd/prim.h>
#include <pxr/usd/usdShade/connectableAPI.h>
#include <pxr/usd/usdShade/material.h>

#include <maya/MObject.h>

PXR_NAMESPACE_OPEN_SCOPE

static bool
_IsShadingNode(const UsdPrim& prim)
{
// Note, UsdShadeShader prims are used in other contexts that aren't just
// surface shading, so we just look for UsdShadeMaterial nodes.
return prim.IsA<UsdShadeMaterial>();
}

PXRUSDMAYA_DEFINE_READER(UsdGeomScope, args, context)
{
const UsdPrim& usdPrim = args.GetUsdPrim();

// If this scope contains only UsdShade nodes, just skip.
// If this scope contains only "shading" nodes (as in the "Looks" or
// "Material" scopes that is often in assets), just skip.
bool hasShadingData = false;
bool hasNonShadingData = false;
for (const auto& child : usdPrim.GetChildren()) {
if (UsdShadeConnectableAPI(child)) {
if (_IsShadingNode(child)) {
hasShadingData = true;
} else {
hasNonShadingData = true;
Expand Down
8 changes: 7 additions & 1 deletion test/lib/usd/translators/UsdImportLightTest/LightsTest.usda
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,10 @@ def Xform "LightsTest" (
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateXYZ", "xformOp:scale"]
}

}
def Scope "NonMaterialsScope"
{
def RectLight "NonRootRectLight"
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,10 @@ def Xform "LightsTest" (
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateXYZ", "xformOp:scale"]
}

}
def Scope "NonMaterialsScope"
{
def RectLight "NonRootRectLight"
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,10 @@ def Xform "LightsTest" (
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateXYZ", "xformOp:scale"]
}

}
def Scope "NonMaterialsScope"
{
def RectLight "NonRootRectLight"
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -266,5 +266,12 @@ def Xform "RfMLightsTest" (
}
}
}

def Scope "NonMaterialsScope"
{
def RectLight "NonRootRectLight"
{
}
}
}

11 changes: 11 additions & 0 deletions test/lib/usd/translators/testUsdImportLight.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,16 @@ def _ValidateMayaAreaLight(self):
if getMayaAPIVersion() > 2019:
self.assertTrue(cmds.getAttr('%s.normalize' % nodePath) == 0)

def _ValidateLightImportedUnderScope(self):
# This tests a case where the "Scope" translator was treating lights as
# materials and deciding to not translate the scope. This would result in
# the "NonRootRectLight" here to be translated at the scene root.
nodePath = '|LightsTest|NonMaterialsScope|NonRootRectLight'
depNodeFn = self._GetMayaDependencyNode(nodePath)

# _GetMayaDependencyNode already does this assert, but in case we ever
# remove that, just redundantly assert here.
self.assertTrue(depNodeFn)

def testImportMayaLights(self):
"""
Expand All @@ -243,6 +253,7 @@ def testImportMayaLights(self):
self._ValidateMayaPointLight()
self._ValidateMayaSpotLight()
self._ValidateMayaAreaLight()
self._ValidateLightImportedUnderScope()



Expand Down
13 changes: 13 additions & 0 deletions test/lib/usd/translators/testUsdImportRfMLight.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,17 @@ def _ValidateMayaLightShadow(self):
self.assertTrue(Gf.IsClose(cmds.getAttr('%s.shadowFalloffGamma' % nodePath),
expectedShadowFalloffGamma, 1e-6))

def _ValidatePxrLightImportedUnderScope(self):
# This tests a case where the "Scope" translator was treating lights as
# materials and deciding to not translate the scope. This would result in
# the "NonRootRectLight" here to be translated at the scene root.
nodePath = '|RfMLightsTest|NonMaterialsScope|NonRootRectLight'
depNodeFn = self._GetMayaDependencyNode(nodePath)

# _GetMayaDependencyNode already does this assert, but in case we ever
# remove that, just redundantly assert here.
self.assertTrue(depNodeFn)

def testImportRenderManForMayaLights(self):
"""
Tests that UsdLux schema USD prims import into Maya as the appropriate
Expand Down Expand Up @@ -380,6 +391,8 @@ def testImportRenderManForMayaLights(self):

self._ValidateMayaLightShadow()

self._ValidatePxrLightImportedUnderScope()


if __name__ == '__main__':
unittest.main(verbosity=2)

0 comments on commit 7a263a4

Please sign in to comment.