Skip to content

Commit d31ace1

Browse files
committed
USDSceneTest : Add testRoundTripMeshLight()
1 parent 914bd02 commit d31ace1

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

contrib/IECoreUSD/test/IECoreUSD/USDSceneTest.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3997,6 +3997,59 @@ def testReadMeshLight( self ) :
39973997
self.assertIn( "__lights", root.setNames() )
39983998
self.assertEqual( root.readSet( "__lights" ), IECore.PathMatcher( [ "/meshLight/meshLightMesh" ] ) )
39993999

4000+
@unittest.skipIf( pxr.Usd.GetVersion() < ( 0, 21, 11 ), "UsdLuxLightAPI not available" )
4001+
def testRoundTripMeshLight( self ) :
4002+
4003+
# Write to USD
4004+
4005+
fileName = os.path.join( self.temporaryDirectory(), "meshLight.usda" )
4006+
root = IECoreScene.SceneInterface.create( fileName, IECore.IndexedIO.OpenMode.Write )
4007+
4008+
lightNetwork = IECoreScene.ShaderNetwork(
4009+
shaders = {
4010+
"output" : IECoreScene.Shader( "MeshLight", "light", {} ),
4011+
},
4012+
output = "output",
4013+
)
4014+
surfaceNetwork = IECoreScene.ShaderNetwork(
4015+
shaders = {
4016+
"output" : IECoreScene.Shader( "UsdPreviewSurface", "surface", {} ),
4017+
"texture" : IECoreScene.Shader( "UsdUVTexture", "surface", {} ),
4018+
},
4019+
output = "output",
4020+
connections = [ ( ( "texture", "rgb" ), ( "output", "glowColor" ) ) ],
4021+
)
4022+
4023+
meshLightObject = IECoreScene.MeshPrimitive.createPlane(
4024+
imath.Box2f( imath.V2f( 0, 0 ), imath.V2f( 1, 1 ) ),
4025+
imath.V2i( 16, 16 )
4026+
)
4027+
4028+
meshLight = root.createChild( "meshLight" )
4029+
meshLight.writeObject( meshLightObject, 0 )
4030+
meshLight.writeAttribute( "light", lightNetwork, 0 )
4031+
meshLight.writeAttribute( "surface", surfaceNetwork, 0 )
4032+
4033+
root.writeSet( "__lights", IECore.PathMatcher( [ "/meshLight" ] ) )
4034+
4035+
del meshLight, root
4036+
4037+
root = IECoreScene.SceneInterface.create( fileName, IECore.IndexedIO.OpenMode.Read )
4038+
4039+
meshLight = root.child( "meshLight" )
4040+
self.assertIn( "light", meshLight.attributeNames() )
4041+
4042+
# The Cortex shader handle is lost when converting to USD because we are only attaching
4043+
# the `MeshLightAPI` to the prim. Therefore the shader networks will not be equal, but we
4044+
# can check that the output shaders are equal.
4045+
self.assertEqual( meshLight.readAttribute( "light", 0 ).outputShader(), lightNetwork.outputShader() )
4046+
4047+
# The surface shader networks should be equivalent
4048+
self.assertEqual( meshLight.readAttribute( "surface", 0 ), surfaceNetwork )
4049+
4050+
self.assertIn( "__lights", root.setNames() )
4051+
self.assertEqual( root.readSet( "__lights" ), IECore.PathMatcher( [ "/meshLight" ] ) )
4052+
40004053
def testPointInstancerPrimvars( self ) :
40014054

40024055
# Use the USD API to author a point instancer with primvars on it.

0 commit comments

Comments
 (0)