Skip to content

Commit 96ba92d

Browse files
committed
IECoreUSD::ShaderAlgo : Handle connections to exposed material inputs
1 parent b74da8c commit 96ba92d

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

contrib/IECoreUSD/src/IECoreUSD/ShaderAlgo.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,25 @@ IECore::InternedString readShaderNetworkWalk( const pxr::SdfPath &anchorPath, co
8888
pxr::TfToken usdSourceName;
8989
pxr::UsdShadeAttributeType usdSourceType;
9090

91-
if( IECore::DataPtr d = IECoreUSD::DataAlgo::fromUSD( pxr::UsdAttribute( i ) ) )
91+
pxr::UsdAttribute valueAttribute = i;
92+
if( i.GetConnectedSource( &usdSource, &usdSourceName, &usdSourceType ) )
9293
{
93-
parameters[ i.GetBaseName().GetString() ] = d;
94+
if( !usdSource.IsContainer() )
95+
{
96+
connections.push_back( { i.GetBaseName().GetString(), usdSource, usdSourceName.GetString() } );
97+
}
98+
else
99+
{
100+
// Connected to an exposed input on the material container. We don't
101+
// have an equivalent in IECoreScene::ShaderNetwork yet, so just take
102+
// the parameter value from the exposed input.
103+
valueAttribute = usdSource.GetInput( usdSourceName );
104+
}
94105
}
95106

96-
if( i.GetConnectedSource( &usdSource, &usdSourceName, &usdSourceType ) )
107+
if( IECore::DataPtr d = IECoreUSD::DataAlgo::fromUSD( pxr::UsdAttribute( valueAttribute ) ) )
97108
{
98-
connections.push_back( { i.GetBaseName().GetString(), usdSource, usdSourceName.GetString() } );
109+
parameters[ i.GetBaseName().GetString() ] = d;
99110
}
100111
}
101112

contrib/IECoreUSD/test/IECoreUSD/USDSceneTest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2952,5 +2952,20 @@ def testAssetAttributes( self ) :
29522952
IECore.StringData( os.path.join( os.path.dirname( __file__ ), "data", "cube.usda" ) )
29532953
)
29542954

2955+
def testExposedShaderInput( self ) :
2956+
2957+
root = IECoreScene.SceneInterface.create(
2958+
os.path.join( os.path.dirname( __file__ ), "data", "exposedShaderInput.usda" ),
2959+
IECore.IndexedIO.OpenMode.Read
2960+
)
2961+
sphere = root.child( "model" ).child( "sphere" )
2962+
2963+
self.assertEqual( sphere.attributeNames(), [ "surface" ] )
2964+
network = sphere.readAttribute( "surface", 0 )
2965+
2966+
self.assertEqual( network.size(), 1 )
2967+
self.assertEqual( network.getOutput(), "surface" )
2968+
self.assertEqual( network.getShader( "surface" ).parameters["diffuse_roughness"].value, 0.75 )
2969+
29552970
if __name__ == "__main__":
29562971
unittest.main()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#usda 1.0
2+
3+
def "model"
4+
{
5+
6+
def Sphere "sphere"
7+
{
8+
rel material:binding = </model/materials/material1>
9+
}
10+
11+
def Scope "materials"
12+
{
13+
14+
def Material "material1"
15+
{
16+
17+
float inputs:exposedRoughness = 0.75
18+
token outputs:surface.connect = </model/materials/material1/surface.outputs:DEFAULT_OUTPUT>
19+
20+
def Shader "surface"
21+
{
22+
uniform token info:id = "arnold:standard_surface"
23+
float inputs:diffuse_roughness.connect = </model/materials/material1.inputs:exposedRoughness>
24+
token outputs:DEFAULT_OUTPUT
25+
}
26+
}
27+
28+
}
29+
30+
}

0 commit comments

Comments
 (0)