@@ -302,22 +302,40 @@ IECoreScene::ConstShaderNetworkPtr adaptShaderNetworkForWriting( const IECoreSce
302302 return result;
303303}
304304
305- pxr::UsdShadeConnectableAPI createShaderPrim ( const IECoreScene::Shader *shader, const pxr::UsdStagePtr &stage, const pxr::SdfPath &path )
305+ pxr::UsdShadeConnectableAPI createShaderPrim ( const IECoreScene::Shader *shader, const pxr::UsdStagePtr &stage, const pxr::SdfPath &path, const std::string &shaderNetworkType )
306306{
307307 pxr::UsdShadeShader usdShader = pxr::UsdShadeShader::Define ( stage, path );
308308 if ( !usdShader )
309309 {
310310 throw IECore::Exception ( " Could not create shader at " + path.GetAsString () );
311311 }
312+
312313 const std::string type = shader->getType ();
314+
315+ bool exportTypePrefixes = false ;
316+
317+ if ( shaderNetworkType == " arnold" )
318+ {
319+ exportTypePrefixes = true ;
320+ }
321+ else if ( shaderNetworkType != " ri" )
322+ {
323+ // \todo : This is currently here just for backwards compatibility. In the long run
324+ // we should probably remove this, and only use shader type prefixes for Arnold, which requires them.
325+ exportTypePrefixes = true ;
326+ }
327+
313328 std::string typePrefix;
314- size_t typeColonPos = type.find ( " :" );
315- if ( typeColonPos != std::string::npos )
329+ if ( exportTypePrefixes )
316330 {
317- typePrefix = type.substr ( 0 , typeColonPos ) + " :" ;
318- if ( typePrefix == " ai: " )
331+ size_t typeColonPos = type.find ( " :" ) ;
332+ if ( typeColonPos != std::string::npos )
319333 {
320- typePrefix = " arnold:" ;
334+ typePrefix = type.substr ( 0 , typeColonPos ) + " :" ;
335+ if ( typePrefix == " ai:" )
336+ {
337+ typePrefix = " arnold:" ;
338+ }
321339 }
322340 }
323341 usdShader.SetShaderId ( pxr::TfToken ( typePrefix + shader->getName () ) );
@@ -404,6 +422,11 @@ void writeShaderConnections( const IECoreScene::ShaderNetwork *shaderNetwork, co
404422} // namespace
405423
406424pxr::UsdShadeOutput IECoreUSD::ShaderAlgo::writeShaderNetwork ( const IECoreScene::ShaderNetwork *shaderNetwork, pxr::UsdPrim shaderContainer )
425+ {
426+ return writeShaderNetwork ( shaderNetwork, shaderContainer, " " );
427+ }
428+
429+ pxr::UsdShadeOutput IECoreUSD::ShaderAlgo::writeShaderNetwork ( const IECoreScene::ShaderNetwork *shaderNetwork, pxr::UsdPrim shaderContainer, const std::string &shaderNetworkType )
407430{
408431 IECoreScene::ConstShaderNetworkPtr adaptedNetwork = adaptShaderNetworkForWriting ( shaderNetwork );
409432 shaderNetwork = adaptedNetwork.get ();
@@ -423,7 +446,7 @@ pxr::UsdShadeOutput IECoreUSD::ShaderAlgo::writeShaderNetwork( const IECoreScene
423446 for ( const auto &shader : shaderNetwork->shaders () )
424447 {
425448 const pxr::SdfPath usdShaderPath = shaderContainer.GetPath ().AppendChild ( pxr::TfToken ( pxr::TfMakeValidIdentifier ( shader.first .string () ) ) );
426- pxr::UsdShadeConnectableAPI usdShader = createShaderPrim ( shader.second .get (), shaderContainer.GetStage (), usdShaderPath );
449+ pxr::UsdShadeConnectableAPI usdShader = createShaderPrim ( shader.second .get (), shaderContainer.GetStage (), usdShaderPath, shaderNetworkType );
427450 writeShaderParameterValues ( shader.second .get (), usdShader );
428451 usdShaders[shader.first ] = usdShader;
429452
@@ -559,7 +582,7 @@ void IECoreUSD::ShaderAlgo::writeLight( const IECoreScene::ShaderNetwork *shader
559582 continue ;
560583 }
561584 const pxr::SdfPath usdShaderPath = prim.GetPath ().AppendChild ( pxr::TfToken ( pxr::TfMakeValidIdentifier ( shader.first .string () ) ) );
562- pxr::UsdShadeConnectableAPI usdShader = createShaderPrim ( shader.second .get (), prim.GetStage (), usdShaderPath );
585+ pxr::UsdShadeConnectableAPI usdShader = createShaderPrim ( shader.second .get (), prim.GetStage (), usdShaderPath, " " );
563586 writeShaderParameterValues ( shader.second .get (), usdShader );
564587 usdShaders[shader.first ] = usdShader;
565588 }
0 commit comments