From e88fd8a76d2c916fb6347dc0147ea765c3d40e10 Mon Sep 17 00:00:00 2001 From: Alex Fuller Date: Wed, 9 Oct 2024 12:12:08 +1100 Subject: [PATCH] USDShader : Fixed default preset values on IntPlugs that are intended to be enum indexes instead of string values. --- Changes.md | 1 + python/GafferUSDUI/USDShaderUI.py | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Changes.md b/Changes.md index 6e6ad0b6a4b..f0f43aee171 100644 --- a/Changes.md +++ b/Changes.md @@ -5,6 +5,7 @@ Fixes ----- - ShaderView : Fixed crash caused by a SceneCreator returning `None`. +- USDShader : Fixed default preset values on IntPlugs that are intended to be enum indexes instead of string values. 1.4.14.0 (relative to 1.4.13.0) ======== diff --git a/python/GafferUSDUI/USDShaderUI.py b/python/GafferUSDUI/USDShaderUI.py index 086a4e92e83..d05734650c5 100644 --- a/python/GafferUSDUI/USDShaderUI.py +++ b/python/GafferUSDUI/USDShaderUI.py @@ -190,12 +190,17 @@ def __presetValues( plug ) : property = __primProperty( plug ) if property : allowedTokens = property.GetMetadata( "allowedTokens" ) - return IECore.StringVectorData( allowedTokens ) if allowedTokens else None + if allowedTokens and isinstance( plug, Gaffer.IntPlug ) : + return IECore.IntVectorData( [ i for i in range( len( allowedTokens ) ) ] ) + else : + return IECore.StringVectorData( allowedTokens ) if allowedTokens else None property = __sdrProperty( plug ) options = property.GetOptions() if options : - if len( options ) > 1 and all( o[1] == "" for o in options ) : + if isinstance( plug, Gaffer.IntPlug ) : + return IECore.IntVectorData( [ i for i in range( len( options ) ) ] ) + elif len( options ) > 1 and all( o[1] == "" for o in options ) : # USD's `_CreateSdrShaderProperty` method in `shaderDefUtils.cpp` # always uses an empty string for the option value when converting # from `allowedTokens`. Ignore that, and use the names as the values