From 71c2cafb40bd7d2b4e2cd64949a0828751557434 Mon Sep 17 00:00:00 2001 From: Sean Donnelly <23455376+seando-adsk@users.noreply.github.com> Date: Mon, 22 Aug 2022 15:27:28 -0400 Subject: [PATCH 1/2] MAYA-124820: When adding an Xform to a USD prim two entries are shown in the channel box * Restore Attribute cache for USD attributes which don't change. --- lib/mayaUsd/ufe/UsdAttributes.cpp | 15 +++++++++++++++ lib/mayaUsd/ufe/UsdAttributes.h | 3 +++ 2 files changed, 18 insertions(+) diff --git a/lib/mayaUsd/ufe/UsdAttributes.cpp b/lib/mayaUsd/ufe/UsdAttributes.cpp index b5b4773ee1..df1312b249 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,11 @@ Ufe::Attribute::Ptr UsdAttributes::attribute(const std::string& name) newAttr = ctorIt->second(fItem, usdAttr); #endif + // If this is a Usd attribute (cannot change) then we cache it for future access. + if (!canRemoveAttribute(fItem, name)) { + fUsdAttributes[name] = newAttr; + } + 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 From 335139cdfcf52bb89d8746aa6bb74294ee4691e5 Mon Sep 17 00:00:00 2001 From: Sean Donnelly <23455376+seando-adsk@users.noreply.github.com> Date: Mon, 29 Aug 2022 11:42:32 -0400 Subject: [PATCH 2/2] MAYA-124820: When adding an Xform to a USD prim two entries are shown in the channel box * Handle attribute cache differently depending on Ufe version. --- lib/mayaUsd/ufe/UsdAttributes.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/mayaUsd/ufe/UsdAttributes.cpp b/lib/mayaUsd/ufe/UsdAttributes.cpp index df1312b249..03517a6781 100644 --- a/lib/mayaUsd/ufe/UsdAttributes.cpp +++ b/lib/mayaUsd/ufe/UsdAttributes.cpp @@ -259,10 +259,14 @@ 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; }