Skip to content

Commit b57d820

Browse files
committed
USD DataAlgo : Fix valueTypeName() for Color4f[Vector]Data
We weren't specifying the "Color" role, which meant we couldn't round-trip shaders with Color4f parameters. They were being written as `float4` and then not loaded at all.
1 parent f5977e9 commit b57d820

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

contrib/IECoreUSD/src/IECoreUSD/DataAlgo.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,21 @@ struct VtValueTypeNameFromData
412412
return s.FindType( TfType::Find<typename CortexTypeTraits<Imath::Color3<T>>::USDType>(), g_color );
413413
}
414414

415+
template<typename T>
416+
SdfValueTypeName operator()( const IECore::TypedData<vector<Imath::Color4<T>>> *data ) const
417+
{
418+
using ArrayType = VtArray<typename CortexTypeTraits<Imath::Color4<T>>::USDType>;
419+
const auto &s = SdfSchema::GetInstance();
420+
return s.FindType( TfType::Find<ArrayType>(), g_color );
421+
}
422+
423+
template<typename T>
424+
SdfValueTypeName operator()( const IECore::TypedData<Imath::Color4<T>> *data ) const
425+
{
426+
const auto &s = SdfSchema::GetInstance();
427+
return s.FindType( TfType::Find<typename CortexTypeTraits<Imath::Color4<T>>::USDType>(), g_color );
428+
}
429+
415430
// Generic
416431

417432
template<typename T>

contrib/IECoreUSD/test/IECoreUSD/USDSceneTest.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3047,5 +3047,34 @@ def testWriteDoubleSidedAttribute( self ) :
30473047
doubleSided
30483048
)
30493049

3050+
def testColor4fShaderParameter( self ) :
3051+
3052+
network = IECoreScene.ShaderNetwork(
3053+
shaders = {
3054+
"output" : IECoreScene.Shader(
3055+
"mySurface", "surface",
3056+
{
3057+
"color4fParameter" : imath.Color4f( 1, 2, 3, 4 ),
3058+
"color4fArrayParameter" : IECore.Color4fVectorData( [
3059+
imath.Color4f( 1, 2, 3, 4 ),
3060+
imath.Color4f( 5, 6, 7, 8 ),
3061+
] ),
3062+
}
3063+
),
3064+
},
3065+
output = "output"
3066+
)
3067+
3068+
fileName = os.path.join( self.temporaryDirectory(), "shader.usda" )
3069+
root = IECoreScene.SceneInterface.create( fileName, IECore.IndexedIO.OpenMode.Write )
3070+
child = root.createChild( "child" )
3071+
child.writeAttribute( "surface", network, 0 )
3072+
3073+
del child, root
3074+
3075+
root = IECoreScene.SceneInterface.create( fileName, IECore.IndexedIO.OpenMode.Read )
3076+
child = root.child( "child" )
3077+
self.assertEqual( child.readAttribute( "surface", 0 ), network )
3078+
30503079
if __name__ == "__main__":
30513080
unittest.main()

0 commit comments

Comments
 (0)