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

LOOKDEVX-2403 - Recognize NodeGraph EnumString attributes #3568

Merged

Conversation

JGamache-autodesk
Copy link
Collaborator

Also refactored the enum discovery to prevent code duplication.

@JGamache-autodesk JGamache-autodesk self-assigned this Jan 22, 2024
@JGamache-autodesk JGamache-autodesk added the ufe-usd Related to UFE-USD plugin in Maya-Usd label Jan 22, 2024
return retVal;
}

UsdAttributeHolder::EnumOptions UsdAttributeHolder::getEnums() const
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved from UsdAttributes to prevent duplicating the added "enum" handling code.

public:
UsdAttributeHolder(const PXR_NS::UsdAttribute& usdAttr);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Allow creating a quick transient holder to access enum information.

Copy link
Collaborator

@pierrebai-adsk pierrebai-adsk Jan 23, 2024

Choose a reason for hiding this comment

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

Another alternative would be to make my suggested function be static and pass the UsdAttribute to it and be public. (See my comment about moving enum-building to a function)

UFE_ATTRIBUTES_BASE::Enums result;
PXR_NS::SdrShaderPropertyConstPtr shaderProp = _GetSdrPropertyAndType(fItem, attrName).first;
if (shaderProp) {
for (const auto& option : shaderProp->GetOptions()) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved to UsdShaderAttributeHolder where it belongs.

result.emplace_back(option.first.GetString(), option.second.GetString());
auto shaderPropAndType = _GetSdrPropertyAndType(fItem, attrName);
if (shaderPropAndType.first) {
const auto shaderPropertyHolder = UsdShaderAttributeHolder(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Use transient holders to get the info.

if (portType == UsdShadeAttributeType::Input) {
const auto input = UsdShadeInput(usdAttr);
if (!input.GetSdrMetadataByKey(TfToken("enum")).empty()) {
return Ufe::Attribute::kEnumString;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Recognize enum ports on NodeGraph and Material prims.

feldstj
feldstj previously approved these changes Jan 23, 2024
Copy link
Collaborator

@feldstj feldstj left a comment

Choose a reason for hiding this comment

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

Looks good, 2 minor comments.

retVal.emplace_back(token.GetString(), "");
}
}
// We might have a propagated enum copied into the created the NodeGraph port, resulting
Copy link
Collaborator

Choose a reason for hiding this comment

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

(minor) Grammar. Guessing just remove the "the".

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

enums = testAttrs.getEnums("inputs:enumString")
self.assertEqual(len(enums), 3)
self.assertEqual(len(enums[0]), 2)
self.assertEqual(enums[0][0], "foo")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should you be testing bar and baz too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am confident the other two labels are correct. There is also a complete check at line 986.

}
}

const bool hasValues = allLabels.size() == allValues.size();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd be more comfortable with parentheses to hekp the reader be sure of the order of evaluation of = vs ==.

// We might have a propagated enum copied into the created the NodeGraph port, resulting
// from connecting a shader enum property.
PXR_NS::UsdShadeNodeGraph ngPrim(_usdAttr.GetPrim());
if (ngPrim && UsdShadeInput::IsInput(_usdAttr)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The code would be slightly clearer if this was moved to a function with a illuminating name name, like retrieveEnumValueNames() or some such. If you're going to have another version for otehr reason, it would be nice to do this refactor.

Copy link
Collaborator

@pierrebai-adsk pierrebai-adsk left a comment

Choose a reason for hiding this comment

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

OK, suggested changes are minors, not necessarily blocking

@JGamache-autodesk JGamache-autodesk added the ready-for-merge Development process is finished, PR is ready for merge label Jan 23, 2024
@JGamache-autodesk
Copy link
Collaborator Author

@seando-adsk ready for merge. Preflight passed and subsequent commit is only modifying a comment.
@pierrebai-adsk Thanks for the comments. I will implement them in a follow-up.

@seando-adsk seando-adsk merged commit 0e2d250 into dev Jan 24, 2024
11 checks passed
@seando-adsk seando-adsk deleted the gamaj/LOOKDEVX-2403/recognize_enum_ports_on_node_graphs branch January 24, 2024 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge Development process is finished, PR is ready for merge ufe-usd Related to UFE-USD plugin in Maya-Usd
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants