From e7e97127df9c9f1d5f9868f4fde950fae7066655 Mon Sep 17 00:00:00 2001 From: pellerington Date: Thu, 19 Dec 2024 14:39:08 -0800 Subject: [PATCH] Fixed a bug in sdr where int arrays would always default to zero. (Internal change: 2352232) --- pxr/usd/sdr/shaderProperty.cpp | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/pxr/usd/sdr/shaderProperty.cpp b/pxr/usd/sdr/shaderProperty.cpp index 07f9b9a0e3..bd4efe940f 100644 --- a/pxr/usd/sdr/shaderProperty.cpp +++ b/pxr/usd/sdr/shaderProperty.cpp @@ -615,6 +615,44 @@ namespace { } } + // INT ARRAY (FIXED SIZE 2, 3, 4) + // --------------------------------------------------------------------- + else if (sdrType == SdrPropertyTypes->Int && + isArray) { + VtIntArray arrayVal; + _GetValue(sdrDefaultValue, &arrayVal); + + if (arrayVal.size() != arraySize) { + TF_DEBUG(SDR_TYPE_CONFORMANCE).Msg( + "Default value for fixed size int array type does not " + "have the right length (%zu vs expected %zu)", + arrayVal.size(), arraySize); + return sdrDefaultValue; + } + + // We return a fixed-size array for arrays with size 2, 3, or 4 + // because SdrShaderProperty::GetTypeAsSdfType returns a specific + // size type (Int2, Int3, Int4). If in the future we want to + // return a VtIntArray instead, we need to change the logic in + // SdrShaderProperty::GetTypeAsSdfType + if (arraySize == 2) { + return VtValue( + GfVec2i(arrayVal[0], + arrayVal[1])); + } else if (arraySize == 3) { + return VtValue( + GfVec3i(arrayVal[0], + arrayVal[1], + arrayVal[2])); + } else if (arraySize == 4) { + return VtValue( + GfVec4i(arrayVal[0], + arrayVal[1], + arrayVal[2], + arrayVal[3])); + } + } + // Default value's type was not conformant, but no special translation // step was found. So we use the default value of the SdfTypeName, which // is guaranteed to match