@@ -866,7 +866,7 @@ def testSubdOptions( self ) :
866
866
( "interpolateBoundary" , allowedIB ),
867
867
( "faceVaryingLinearInterpolation" , allowedFVLI ),
868
868
( "triangleSubdivisionRule" , allowedTS ),
869
-
869
+
870
870
]:
871
871
for value in allowed :
872
872
@@ -889,7 +889,7 @@ def testSubdOptions( self ) :
889
889
890
890
if property == "triangleSubdivisionRule" :
891
891
mesh .CreateTriangleSubdivisionRuleAttr ().Set ( value , 0.0 )
892
-
892
+
893
893
stage .GetRootLayer ().Save ()
894
894
del stage
895
895
@@ -4091,5 +4091,88 @@ def testRoundTripArnoldLight( self ) :
4091
4091
self .assertIn ( "__lights" , root .setNames () )
4092
4092
self .assertEqual ( root .readSet ( "__lights" ), IECore .PathMatcher ( [ "/light" ] ) )
4093
4093
4094
+ def testArnoldSpecificLightInputs ( self ) :
4095
+
4096
+ # The `arnold-usd` project doesn't represent Arnold-specific UsdLux
4097
+ # extensions as `inputs:arnold:*` attributes as it logically should :
4098
+ # instead it uses `primvars:arnold:*` attributes. In Cortex/Gaffer we
4099
+ # wish to use regular `arnold:*` shader parameters rather than primvars,
4100
+ # so must convert to and from the less logical form in USDScene.
4101
+
4102
+ lightShader = IECoreScene .ShaderNetwork (
4103
+ shaders = {
4104
+ "light" : IECoreScene .Shader (
4105
+ "RectLight" , "light" ,
4106
+ parameters = {
4107
+ "exposure" : 1.0 ,
4108
+ "arnold:roundness" : 2.0 ,
4109
+ }
4110
+ )
4111
+ },
4112
+ output = "light" ,
4113
+ )
4114
+
4115
+ fileName = os .path .join ( self .temporaryDirectory (), "test.usda" )
4116
+ root = IECoreScene .SceneInterface .create ( fileName , IECore .IndexedIO .OpenMode .Write )
4117
+ light = root .createChild ( "light" )
4118
+ light .writeAttribute ( "light" , lightShader , 0 )
4119
+ del root , light
4120
+
4121
+ stage = pxr .Usd .Stage .Open ( fileName )
4122
+ shadeAPI = pxr .UsdShade .ConnectableAPI ( stage .GetPrimAtPath ( "/light" ) )
4123
+ self .assertTrue ( shadeAPI .GetInput ( "exposure" ) )
4124
+ self .assertFalse ( shadeAPI .GetInput ( "arnold:roundness" ) )
4125
+ primvarsAPI = pxr .UsdGeom .PrimvarsAPI ( stage .GetPrimAtPath ( "/light" ) )
4126
+ self .assertTrue ( primvarsAPI .HasPrimvar ( "arnold:roundness" ) )
4127
+ self .assertEqual ( primvarsAPI .GetPrimvar ( "arnold:roundness" ).Get (), 2.0 )
4128
+ del stage , shadeAPI , primvarsAPI
4129
+
4130
+ root = IECoreScene .SceneInterface .create ( fileName , IECore .IndexedIO .OpenMode .Read )
4131
+ self .assertEqual ( root .child ( "light" ).readAttribute ( "light" , 0 ), lightShader )
4132
+
4133
+ def testTreatLightAsPointOrLine ( self ) :
4134
+
4135
+ # `treatAsPoint` and `treatAsLine` aren't defined as UsdShade inputs but we store
4136
+ # them as regular shader parameter, so they need special handling when writing to USD.
4137
+
4138
+ sphereLightShader = IECoreScene .ShaderNetwork (
4139
+ shaders = {
4140
+ "sphereLight" : IECoreScene .Shader (
4141
+ "SphereLight" , "light" ,
4142
+ parameters = {
4143
+ "treatAsPoint" : True ,
4144
+ }
4145
+ )
4146
+ },
4147
+ output = "sphereLight" ,
4148
+ )
4149
+
4150
+ cylinderLightShader = IECoreScene .ShaderNetwork (
4151
+ shaders = {
4152
+ "cylinderLight" : IECoreScene .Shader (
4153
+ "CylinderLight" , "light" ,
4154
+ parameters = {
4155
+ "treatAsLine" : True ,
4156
+ }
4157
+ )
4158
+ },
4159
+ output = "cylinderLight" ,
4160
+ )
4161
+
4162
+ fileName = os .path .join ( self .temporaryDirectory (), "test.usda" )
4163
+ root = IECoreScene .SceneInterface .create ( fileName , IECore .IndexedIO .OpenMode .Write )
4164
+ root .createChild ( "sphereLight" ).writeAttribute ( "light" , sphereLightShader , 0 )
4165
+ root .createChild ( "cylinderLight" ).writeAttribute ( "light" , cylinderLightShader , 0 )
4166
+ del root
4167
+
4168
+ stage = pxr .Usd .Stage .Open ( fileName )
4169
+ self .assertEqual ( pxr .UsdLux .SphereLight ( stage .GetPrimAtPath ( "/sphereLight" ) ).GetTreatAsPointAttr ().Get (), True )
4170
+ self .assertEqual ( pxr .UsdLux .CylinderLight ( stage .GetPrimAtPath ( "/cylinderLight" ) ).GetTreatAsLineAttr ().Get (), True )
4171
+ del stage
4172
+
4173
+ root = IECoreScene .SceneInterface .create ( fileName , IECore .IndexedIO .OpenMode .Read )
4174
+ self .assertEqual ( root .child ( "sphereLight" ).readAttribute ( "light" , 0 ), sphereLightShader )
4175
+ self .assertEqual ( root .child ( "cylinderLight" ).readAttribute ( "light" , 0 ), cylinderLightShader )
4176
+
4094
4177
if __name__ == "__main__" :
4095
4178
unittest .main ()
0 commit comments