@@ -813,12 +813,16 @@ std::pair< size_t, size_t > getEndPointDuplication( const T &basis )
813813}
814814
815815std::tuple< const std::string*, const std::string*, const std::string*, const std::string*, const std::string* >
816- lookupSplinePlugSuffixes ( const std::string &shaderBaseName )
816+ lookupSplinePlugSuffixes ( const std::string &shaderName )
817817{
818818 // We seem to be able to identify shaders that should use the PRMan convention by whether they start
819- // with one of the PRMan prefixes
820- if ( boost::starts_with ( shaderBaseName, " Pxr" ) || boost::starts_with ( shaderBaseName, " Lama" ) )
819+ // with one of the PRMan prefixes.
820+ // NOTE : This will fail if a shader is loaded from an explicit path, rather than being found in the
821+ // search path, because the shader name will include the full file path. We consider this an
822+ // acceptable failure, because shaders should be found in the search paths.
823+ if ( boost::starts_with ( shaderName, " Pxr" ) || boost::starts_with ( shaderName, " Lama" ) )
821824 {
825+ // The convention used by the PRMan shader library.
822826 static const std::string positions ( " _Knots" );
823827 static const std::string floatValues ( " _Floats" );
824828 static const std::string colorValues ( " _Colors" );
@@ -828,6 +832,7 @@ lookupSplinePlugSuffixes( const std::string &shaderBaseName )
828832 }
829833 else
830834 {
835+ // The convention used by the OSL shaders that we ship with Gaffer.
831836 static const std::string positions ( " Positions" );
832837 static const std::string values ( " Values" );
833838 static const std::string basis ( " Basis" );
@@ -836,7 +841,7 @@ lookupSplinePlugSuffixes( const std::string &shaderBaseName )
836841}
837842
838843template <typename Spline>
839- void expandSpline ( const InternedString &name, const Spline &spline, CompoundDataMap &newParameters, const std::string &shaderBaseName )
844+ void expandSpline ( const InternedString &name, const Spline &spline, CompoundDataMap &newParameters, const std::string &shaderName )
840845{
841846 const char *basis = " catmull-rom" ;
842847 if ( spline.basis == Spline::Basis::bezier () )
@@ -890,7 +895,7 @@ void expandSpline( const InternedString &name, const Spline &spline, CompoundDat
890895 }
891896 }
892897
893- auto [ positionsSuffix, floatValuesSuffix, colorValuesSuffix, basisSuffix, countSuffix ] = lookupSplinePlugSuffixes ( shaderBaseName );
898+ auto [ positionsSuffix, floatValuesSuffix, colorValuesSuffix, basisSuffix, countSuffix ] = lookupSplinePlugSuffixes ( shaderName );
894899
895900 newParameters[ name.string () + *positionsSuffix ] = positionsData;
896901 if constexpr ( std::is_same_v< typename Spline::YType, float > )
@@ -980,10 +985,10 @@ void ensureParametersCopy(
980985 }
981986}
982987
983- IECore::ConstCompoundDataPtr collapseSplineParametersInternal ( const IECore::ConstCompoundDataPtr ¶metersData, const std::string &shaderBaseName )
988+ IECore::ConstCompoundDataPtr collapseSplineParametersInternal ( const IECore::ConstCompoundDataPtr ¶metersData, const std::string &shaderName )
984989{
985990
986- auto [ positionsSuffix, floatValuesSuffix, colorValuesSuffix, basisSuffix, countSuffix ] = lookupSplinePlugSuffixes ( shaderBaseName );
991+ auto [ positionsSuffix, floatValuesSuffix, colorValuesSuffix, basisSuffix, countSuffix ] = lookupSplinePlugSuffixes ( shaderName );
987992
988993 const CompoundDataMap ¶meters ( parametersData->readable () );
989994 CompoundDataPtr newParametersData;
@@ -1003,35 +1008,26 @@ IECore::ConstCompoundDataPtr collapseSplineParametersInternal( const IECore::Con
10031008
10041009
10051010 std::string prefix = maybeBasis.first .string ().substr ( 0 , maybeBasis.first .string ().size () - basisSuffix->size () );
1006- IECore::InternedString positionsName = prefix + *positionsSuffix;
1007- const auto positionsIter = parameters.find ( positionsName );
1008- const FloatVectorData *floatPositions = nullptr ;
1009-
1010- if ( positionsIter != parameters.end () )
1011- {
1012- floatPositions = runTimeCast<const FloatVectorData>( positionsIter->second .get () );
1013- }
1014-
1011+ const IECore::InternedString positionsName = prefix + *positionsSuffix;
1012+ const FloatVectorData *floatPositions = parametersData->member <const FloatVectorData>( positionsName );
10151013 if ( !floatPositions )
10161014 {
10171015 continue ;
10181016 }
10191017
1018+ IECore::InternedString countName;
1019+ const IntData *countData = nullptr ;
1020+
10201021 if ( countSuffix )
10211022 {
1022- IECore::InternedString countName = prefix + *countSuffix;
1023- const auto countIter = parameters.find ( countName );
1024- const IntData *countData = nullptr ;
1025- if ( countIter == parameters.end () )
1026- {
1027- countData = runTimeCast<const IntData>( countIter->second .get () );
1028- }
1023+ countName = prefix + *countSuffix;
1024+ countData = parametersData->member <const IntData>( countName );
10291025
10301026 if ( !countData )
10311027 {
10321028 IECore::msg (
10331029 Msg::Error, " ShaderNetworkAlgo" ,
1034- " Using spline format that expects count plug , but no int count plug found matching \" " + countName.string () + " \" "
1030+ " Using spline format that expects count parameter , but no int count parameter found matching \" " + countName.string () + " \" "
10351031 );
10361032 }
10371033 else
@@ -1046,39 +1042,39 @@ IECore::ConstCompoundDataPtr collapseSplineParametersInternal( const IECore::Con
10461042 }
10471043 }
10481044
1049- IECore::InternedString floatValuesName = prefix + *floatValuesSuffix;
1050- auto valuesIter = parameters. find ( floatValuesName ) ;
1051- if ( valuesIter == parameters. end ( ) )
1045+ IECore::InternedString valuesName = prefix + *floatValuesSuffix;
1046+ IECore::DataPtr foundSpline ;
1047+ if ( const FloatVectorData *floatValues = parametersData-> member < const FloatVectorData>( valuesName ) )
10521048 {
1053- IECore::InternedString colorValuesName = prefix + *colorValuesSuffix;
1054- valuesIter = parameters.find ( colorValuesName );
1049+ foundSpline = loadSpline<SplineffData>( basis, floatPositions, floatValues );
10551050 }
1056-
1057-
1058- IECore::DataPtr foundSpline;
1059- if ( valuesIter != parameters.end () )
1051+ else
10601052 {
1061- if ( const FloatVectorData *floatValues = runTimeCast<const FloatVectorData>( valuesIter->second .get () ) )
1062- {
1063- foundSpline = loadSpline<SplineffData>( basis, floatPositions, floatValues );
1064- }
1065- else if ( const Color3fVectorData *color3Values = runTimeCast<const Color3fVectorData>( valuesIter->second .get () ) )
1053+ valuesName = prefix + *colorValuesSuffix;
1054+ if ( const Color3fVectorData *color3Values = parametersData->member <const Color3fVectorData>( valuesName ) )
10661055 {
10671056 foundSpline = loadSpline<SplinefColor3fData>( basis, floatPositions, color3Values );
10681057 }
1069- else if ( const Color4fVectorData *color4Values = runTimeCast <const Color4fVectorData>( valuesIter-> second . get () ) )
1058+ else if ( const Color4fVectorData *color4Values = parametersData-> member <const Color4fVectorData>( valuesName ) )
10701059 {
10711060 foundSpline = loadSpline<SplinefColor4fData>( basis, floatPositions, color4Values );
10721061 }
1062+
10731063 }
10741064
10751065 if ( foundSpline )
10761066 {
10771067 ensureParametersCopy ( parameters, newParametersData, newParameters );
1078- (*newParameters)[prefix] = foundSpline;
10791068 newParameters->erase ( maybeBasis.first );
10801069 newParameters->erase ( positionsName );
1081- newParameters->erase ( valuesIter->first );
1070+ newParameters->erase ( valuesName );
1071+ if ( countData )
1072+ {
1073+ newParameters->erase ( countName );
1074+ }
1075+
1076+ (*newParameters)[prefix] = foundSpline;
1077+
10821078 }
10831079 }
10841080
@@ -1166,11 +1162,6 @@ std::pair< InternedString, int > createSplineInputAdapter(
11661162 return std::make_pair ( adapterHandle, getEndPointDuplication ( splineData->readable ().basis ).first );
11671163}
11681164
1169- std::string shaderBaseNameFromPath ( const std::string shaderName )
1170- {
1171- return std::filesystem::path ( shaderName ).filename ().string ();
1172- }
1173-
11741165} // namespace
11751166
11761167void ShaderNetworkAlgo::collapseSplines ( ShaderNetwork *network, std::string targetPrefix )
@@ -1195,12 +1186,12 @@ void ShaderNetworkAlgo::collapseSplines( ShaderNetwork *network, std::string tar
11951186 }
11961187
11971188 // For nodes which aren't spline adapters, we just need to deal with any parameters that are splines
1198- ConstCompoundDataPtr collapsed = collapseSplineParametersInternal ( shader->parametersData (), shaderBaseNameFromPath ( shader->getName () ) );
1189+ ConstCompoundDataPtr collapsed = collapseSplineParametersInternal ( shader->parametersData (), shader->getName () );
11991190 if ( collapsed != shader->parametersData () )
12001191 {
12011192 // \todo - this const_cast is ugly, although safe because if the return from collapseSplineParameterInternals
12021193 // doesn't match the input, it is freshly allocated. Once collapseSplineParameters is fully
1203- // deprecated, and no longer visible publicly, an internal version of collapseSplineParametersInternal could
1194+ // deprecated, and no longer visible publicly, collapseSplineParametersInternal could
12041195 // just return a non-const new parameter data, or nullptr if no changes are needed.
12051196 network->setShader ( name, std::move ( new Shader ( shader->getName (), shader->getType (), const_cast < CompoundData *>( collapsed.get () ) ) ) );
12061197 }
@@ -1322,13 +1313,13 @@ void ShaderNetworkAlgo::expandSplines( ShaderNetwork *network, std::string targe
13221313 {
13231314 ensureParametersCopy ( origParameters, newParametersData, newParameters );
13241315 newParameters->erase ( name );
1325- expandSpline ( name, colorSpline->readable (), *newParameters, shaderBaseNameFromPath ( s.second ->getName () ) );
1316+ expandSpline ( name, colorSpline->readable (), *newParameters, s.second ->getName () );
13261317 }
13271318 else if ( const SplineffData *floatSpline = runTimeCast<const SplineffData>( value.get () ) )
13281319 {
13291320 ensureParametersCopy ( origParameters, newParametersData, newParameters );
13301321 newParameters->erase ( name );
1331- expandSpline ( name, floatSpline->readable (), *newParameters, shaderBaseNameFromPath ( s.second ->getName () ) );
1322+ expandSpline ( name, floatSpline->readable (), *newParameters, s.second ->getName () );
13321323 }
13331324 }
13341325
0 commit comments