Skip to content

Commit a3f2815

Browse files
authored
Merge pull request #1283 from johnhaddon/usdLuxImprovements
USDScene : Load `treatAsPoint` and `treatAsLine` for UsdLuxLights
2 parents 198c48a + be83869 commit a3f2815

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

contrib/IECoreUSD/src/IECoreUSD/ShaderAlgo.cpp

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
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

5459
pxr::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 &parameters )
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

73101
IECoreScene::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 );

contrib/IECoreUSD/test/IECoreUSD/USDSceneTest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3022,6 +3022,9 @@ def testLightAttribute( self ) :
30223022
self.assertEqual( shader.size(), 1 )
30233023
self.assertEqual( shader.getOutput(), "SpotLight23" )
30243024

3025+
self.assertEqual( shader.getShader( "SpotLight23" ).name, "SphereLight" )
3026+
self.assertEqual( shader.getShader( "SpotLight23" ).type, "light" )
3027+
30253028
self.assertEqual(
30263029
shader.getShader( "SpotLight23" ).parameters,
30273030
IECore.CompoundData( {
@@ -3031,6 +3034,7 @@ def testLightAttribute( self ) :
30313034
"exposure" : 0.0,
30323035
"intensity" : 30000.0,
30333036
"radius" : 0.0,
3037+
"treatAsPoint" : True,
30343038
"shaping:cone:angle" : 66.0,
30353039
"shaping:cone:softness" : 1.0
30363040
} )

0 commit comments

Comments
 (0)