static bool _GatherRibAttributes( const UsdPrim &prim, double currentTime, FnKat::GroupBuilder& attrsBuilder) { bool hasAttrs = false; // USD SHADING STYLE ATTRIBUTES UsdRiStatements riStatements(prim); if (riStatements) { const std::vector<UsdProperty> props = riStatements.GetRiAttributes(); std::string attrName; TF_FOR_ALL(propItr, props) { UsdProperty prop = *propItr; if (!prop) continue; std::string nameSpace = riStatements.GetRiAttributeNameSpace(prop).GetString(); nameSpace = TfStringReplace(nameSpace, ":", ".") + "."; attrName = nameSpace + riStatements.GetRiAttributeName(prop).GetString(); VtValue vtValue; UsdAttribute usdAttr = prim.GetAttribute(prop.GetName()); if (usdAttr) { if (not usdAttr.Get(&vtValue, currentTime)) continue; // XXX asShaderParam really means: // "For arrays, as a single attr vs a type/value pair group" // The type/value pair group is meaningful for attrs who don't // have a formal type definition -- like a "user" RiAttribute. // // However, other array values (such as two-element shadingrate) // are not expecting the type/value pair form and will not // generate rib correctly. As such, we'll handle the "user" // attribute as a special case. bool asShaderParam = true; if (nameSpace == "user.") { asShaderParam = false; } attrsBuilder.set(attrName, PxrUsdKatanaUtils::ConvertVtValueToKatAttr(vtValue, asShaderParam) ); } else { UsdRelationship usdRel = prim.GetRelationship(prop.GetName()); attrsBuilder.set(attrName, PxrUsdKatanaUtils::ConvertRelTargetsToKatAttr(usdRel, /* asShaderParam */ false) ); } hasAttrs = true; } }
/* static */ UsdAttribute PxrUsdMayaWriteUtil::GetOrCreateUsdRiAttribute( const MPlug& attrPlug, const UsdPrim& usdPrim, const std::string& attrName, const std::string& nameSpace, const bool translateMayaDoubleToUsdSinglePrecision) { UsdAttribute usdAttr; if (!usdPrim) { return usdAttr; } MObject attrObj(attrPlug.attribute()); TfToken riAttrNameToken(attrName); if (riAttrNameToken.IsEmpty()) { MGlobal::displayError( TfStringPrintf("Invalid UsdRi attribute name '%s' for Maya plug '%s'", attrName.c_str(), attrPlug.name().asChar()).c_str()); return usdAttr; } UsdRiStatements riStatements(usdPrim); if (!riStatements) { return usdAttr; } // See if a UsdRi attribute with this name already exists. If so, return it. // XXX: There isn't currently API for looking for a specific UsdRi attribute // by name, so we have to get them all and then see if one matches. const std::vector<UsdProperty>& riAttrs = riStatements.GetRiAttributes(nameSpace); TF_FOR_ALL(iter, riAttrs) { if (iter->GetBaseName() == riAttrNameToken) { // Re-get the attribute from the prim so we can return it as a // UsdAttribute rather than a UsdProperty. return usdPrim.GetAttribute(iter->GetName()); } } const SdfValueTypeName& typeName = PxrUsdMayaWriteUtil::GetUsdTypeName(attrPlug, translateMayaDoubleToUsdSinglePrecision); if (typeName) { usdAttr = riStatements.CreateRiAttribute(riAttrNameToken, typeName.GetType(), nameSpace); } return usdAttr; }