Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAYA-124820: When adding an Xform to a USD prim two entries are shown… #2565

Merged
merged 2 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/mayaUsd/ufe/UsdAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Comment on lines +263 to +266
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored the USD attribute cache, but only for attributes which do not change.

#else
fUsdAttributes[name] = newAttr;
#endif

return newAttr;
}

Expand Down
3 changes: 3 additions & 0 deletions lib/mayaUsd/ufe/UsdAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ class UsdAttributes : public Ufe::Attributes
private:
UsdSceneItem::Ptr fItem;
PXR_NS::UsdPrim fPrim;

typedef std::unordered_map<std::string, Ufe::Attribute::Ptr> AttributeMap;
AttributeMap fUsdAttributes;
}; // UsdAttributes

} // namespace ufe
Expand Down