diff --git a/lib/mayaUsd/ufe/UsdAttributes.cpp b/lib/mayaUsd/ufe/UsdAttributes.cpp index b5b4773ee1..03517a6781 100644 --- a/lib/mayaUsd/ufe/UsdAttributes.cpp +++ b/lib/mayaUsd/ufe/UsdAttributes.cpp @@ -120,6 +120,11 @@ static PXR_NS::UsdAttribute _GetAttributeType(const PXR_NS::UsdPrim& prim, const Ufe::Attribute::Type UsdAttributes::attributeType(const std::string& name) { + // If we've already created an attribute for this name, just return the type. + auto iter = fUsdAttributes.find(name); + if (iter != std::end(fUsdAttributes)) + return iter->second->type(); + PXR_NS::TfToken tok(name); PXR_NS::UsdAttribute usdAttr = _GetAttributeType(fPrim, name); if (usdAttr.IsValid()) { @@ -146,6 +151,11 @@ Ufe::Attribute::Ptr UsdAttributes::attribute(const std::string& name) return nullptr; } + // If we've already created an attribute for this name, just return it. + auto iter = fUsdAttributes.find(name); + if (iter != std::end(fUsdAttributes)) + return iter->second; + // No attribute for the input name was found -> create one. PXR_NS::TfToken tok(name); PXR_NS::UsdAttribute usdAttr = _GetAttributeType(fPrim, name); @@ -249,6 +259,15 @@ Ufe::Attribute::Ptr UsdAttributes::attribute(const std::string& name) newAttr = ctorIt->second(fItem, usdAttr); #endif +#if (UFE_PREVIEW_VERSION_NUM >= 4024) + // If this is a Usd attribute (cannot change) then we cache it for future access. + if (!canRemoveAttribute(fItem, name)) { + fUsdAttributes[name] = newAttr; + } +#else + fUsdAttributes[name] = newAttr; +#endif + return newAttr; } diff --git a/lib/mayaUsd/ufe/UsdAttributes.h b/lib/mayaUsd/ufe/UsdAttributes.h index 53378fc57d..397a4b12b4 100644 --- a/lib/mayaUsd/ufe/UsdAttributes.h +++ b/lib/mayaUsd/ufe/UsdAttributes.h @@ -89,6 +89,9 @@ class UsdAttributes : public Ufe::Attributes private: UsdSceneItem::Ptr fItem; PXR_NS::UsdPrim fPrim; + + typedef std::unordered_map AttributeMap; + AttributeMap fUsdAttributes; }; // UsdAttributes } // namespace ufe