@@ -55,8 +55,19 @@ static const pxr::TfToken g_cortexPrimitiveVariableMetadataTokenDeprecated( "IEC
5555static const std::string g_primVarPrefix = " primvars:" ;
5656static const std::string g_primVarUserPrefix = " primvars:user:" ;
5757static const std::string g_renderPrefix = " render:" ;
58+ static const std::string g_riPrefix = " ri:" ;
59+ static const std::string g_riAttributesPrefix = " ri:attributes:" ;
5860static const std::string g_userPrefix = " user:" ;
5961
62+ bool writeConformantRenderManAttributes ()
63+ {
64+ if ( const char *e = getenv ( " IECOREUSD_WRITE_CONFORMANT_RENDERMAN_ATTRIBUTES" ) )
65+ {
66+ return strcmp ( e, " 0" );
67+ }
68+ return false ;
69+ }
70+
6071}
6172
6273bool IECoreUSD::AttributeAlgo::isCortexAttribute ( const pxr::UsdGeomPrimvar &primVar )
@@ -122,12 +133,19 @@ pxr::TfToken IECoreUSD::AttributeAlgo::cortexPrimitiveVariableMetadataTokenDepre
122133
123134IECoreUSD::AttributeAlgo::Name IECoreUSD::AttributeAlgo::nameToUSD ( std::string name )
124135{
136+ if ( boost::starts_with ( name, g_riPrefix ) && writeConformantRenderManAttributes () )
137+ {
138+ return { pxr::TfToken ( g_riAttributesPrefix + name.substr ( g_riPrefix.size () ) ), true };
139+ }
140+
125141 bool isPrimvar = false ;
126142
127143 // The long term plan is to convert only "render:" prefixed attributes to primvars, and it will
128144 // be the client's responsibility to ensure everything important gets prefixed with "render:".
129145 // But for the moment, Gaffer doesn't do this yet, so we support the two most important prefixes
130- // for Gaffer currently: "user:" and "ai:"
146+ // for Gaffer currently: "user:" and "ai:".
147+ // / \todo I don't think the `render:` plan is working out - it may well be better to just map
148+ // / all Cortex attributes to primvars.
131149 if ( boost::starts_with ( name, " render:" ) || boost::starts_with ( name, " user:" ) || boost::starts_with ( name, " ai:" ) )
132150 {
133151 isPrimvar = true ;
@@ -170,7 +188,12 @@ IECoreUSD::AttributeAlgo::Name IECoreUSD::AttributeAlgo::nameToUSD( std::string
170188IECore::InternedString IECoreUSD::AttributeAlgo::nameFromUSD ( IECoreUSD::AttributeAlgo::Name name )
171189{
172190 std::string nameStr = name.name ;
173- if ( nameStr == " arnold:displacement" )
191+
192+ if ( boost::starts_with ( nameStr, g_riAttributesPrefix ) )
193+ {
194+ return g_riPrefix + nameStr.substr ( g_riAttributesPrefix.size () );
195+ }
196+ else if ( nameStr == " arnold:displacement" )
174197 {
175198 // Special case where the whole name is different, not just prefix
176199 nameStr = " ai:disp_map" ;
@@ -198,7 +221,9 @@ IECore::InternedString IECoreUSD::AttributeAlgo::nameFromUSD( IECoreUSD::Attribu
198221
199222 // The long term plan is to always prefix primitive variables converted to attributes with "render:".
200223 // But for the moment, Gaffer doesn't support this, so we skip the prefix for the two most important prefixes
201- // for Gaffer currently: "user:" and "ai:"
224+ // for Gaffer currently: "user:" and "ai:".
225+ // / \todo I don't think the `render:` plan is working out - it may well be better to just map
226+ // / all Cortex attributes to primvars.
202227 if ( !boost::starts_with ( nameStr, g_userPrefix ) && !boost::starts_with ( nameStr, " ai:" ) && name.isPrimvar )
203228 {
204229 nameStr = " render:" + nameStr;
0 commit comments