4141#include " IECore/MessageHandler.h"
4242#include " IECore/SimpleTypedData.h"
4343
44+ #if PXR_VERSION >= 2111
45+ #include " pxr/usd/usdLux/cylinderLight.h"
46+ #include " pxr/usd/usdLux/sphereLight.h"
47+ #endif
48+
4449#include " boost/algorithm/string/replace.hpp"
4550#include " boost/pointer_cast.hpp"
4651
@@ -53,21 +58,44 @@ namespace
5358
5459pxr::TfToken g_adapterLabelToken ( IECoreScene::ShaderNetworkAlgo::componentConnectionAdapterLabel().string() );
5560
56- pxr::TfToken shaderId ( const pxr::UsdShadeConnectableAPI &connectable )
61+ std::pair< pxr::TfToken, std::string> shaderIdAndType ( const pxr::UsdShadeConnectableAPI &connectable )
5762{
58- pxr::TfToken result;
63+ pxr::TfToken id;
64+ std::string type;
5965 if ( auto shader = pxr::UsdShadeShader ( connectable ) )
6066 {
61- shader.GetShaderId ( &result );
67+ shader.GetShaderId ( &id );
68+ type = " surface" ;
6269 }
6370#if PXR_VERSION >= 2111
6471 else if ( auto light = pxr::UsdLuxLightAPI ( connectable ) )
6572 {
66- light.GetShaderIdAttr ().Get ( &result );
73+ light.GetShaderIdAttr ().Get ( &id );
74+ type = " light" ;
6775 }
6876#endif
6977
70- return result;
78+ return std::make_pair ( id, type );
79+ }
80+
81+ void readAdditionalLightParameters ( const pxr::UsdPrim &prim, IECore::CompoundDataMap ¶meters )
82+ {
83+ // Just to keep us on our toes, not all light parameters are stored as UsdShade inputs,
84+ // so we have special-case code for loading those here.
85+ #if PXR_VERSION >= 2111
86+ if ( auto sphereLight = pxr::UsdLuxSphereLight ( prim ) )
87+ {
88+ bool treatAsPoint = false ;
89+ sphereLight.GetTreatAsPointAttr ().Get ( &treatAsPoint );
90+ parameters[" treatAsPoint" ] = new IECore::BoolData ( treatAsPoint );
91+ }
92+ else if ( auto cylinderLight = pxr::UsdLuxCylinderLight ( prim ) )
93+ {
94+ bool treatAsLine = false ;
95+ cylinderLight.GetTreatAsLineAttr ().Get ( &treatAsLine );
96+ parameters[" treatAsLine" ] = new IECore::BoolData ( treatAsLine );
97+ }
98+ #endif
7199}
72100
73101IECoreScene::ShaderNetwork::Parameter readShaderNetworkWalk ( const pxr::SdfPath &anchorPath, const pxr::UsdShadeOutput &output, IECoreScene::ShaderNetwork &shaderNetwork );
@@ -81,9 +109,8 @@ IECore::InternedString readShaderNetworkWalk( const pxr::SdfPath &anchorPath, co
81109 return handle;
82110 }
83111
84- const pxr::TfToken id = shaderId ( usdShader );
112+ auto [id, shaderType] = shaderIdAndType ( usdShader );
85113 std::string shaderName = " defaultsurface" ;
86- std::string shaderType = " surface" ;
87114 if ( id.size () )
88115 {
89116 std::string name = id.GetString ();
@@ -137,6 +164,8 @@ IECore::InternedString readShaderNetworkWalk( const pxr::SdfPath &anchorPath, co
137164 }
138165 }
139166
167+ readAdditionalLightParameters ( usdShader.GetPrim (), parameters );
168+
140169 parametersData = boost::const_pointer_cast< IECore::CompoundData >( IECoreScene::ShaderNetworkAlgo::collapseSplineParameters ( parametersData ) );
141170
142171 IECoreScene::ShaderPtr newShader = new IECoreScene::Shader ( shaderName, shaderType, parametersData );
0 commit comments