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-126483 Fix a bug where materials got created in the wrong scope. #2783

Merged
merged 2 commits into from
Jan 3, 2023

Conversation

frohnej-adsk
Copy link
Collaborator

When using "Assign New Material", a new material gets created in the default materials scope. This scope is usually called "mtl". In the previous implementation, there was a bug where materials got created in any scope that starts with "mtl". If, for example, there was a scope called "mtlFoo", and no scope called "mtl", the new material got created in "mtlFoo". However, the expected behaviour in this example is to create a scope called "mtl" and to create the new material in there.

This is the expected behaviour in a more general sense: If the default materials scope name (usually "mtl") is available, create the new material in a scope with this name. If the default materials scope name is not available i.e., there is already something that is not of type "Scope" that is using that name (e.g. an Xform called "mtl"), append a number suffix to the default materials scope name (e.g. "mtl1") and try to use that. If this name is not available either, increment the number suffix until an available name is found.

This PDF contains a list of examples to illustrate the expected behaviour: materialScopesAcceptanceCriteria.pdf

When using "Assign New Material", a new material gets created in the default materials scope. This
scope is usually called "mtl". In the previous implementation, there was a bug where materials got
created in *any* scope that starts with "mtl". If, for example, there was a scope called "mtlFoo",
and no scope called "mtl", the new material got created in "mtlFoo". However, the expected behaviour
in this example is to create a scope called "mtl" and to create the new material in there.

This is the expected behaviour in a more general sense: If the default materials scope name (usually
"mtl") is available, create the new material in a scope with this name.
If the default materials scope name is not available i.e., there is already something that is not
of type "Scope" that is using that name (e.g. an Xform called "mtl"), append a number suffix to the
default materials scope name (e.g. "mtl1") and try to use that. If this name is not available
either, increment the number suffix until an available name is found.
//
// 5. Bind the material to all selected primitives in the stage:
//
for (const auto& parentPath : selectedPaths) {
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 moved steps 1 through 4 out of the inner loop. These steps were only executed in the first iteration of the inner loop anyway, so moving them out reduces unnecessary indentation and should improve readability.

Ufe::SceneItem::Ptr materialsScope = nullptr;
std::string materialsScopeName = materialsScopeNamePrefix;
Ufe::SceneItemList children = stageHierarchy->children();
for (size_t i = 1;; ++i) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

My only concern is that somehow this loop will go beyond then end of the children list. Is that possible?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is not used to index the child list. Only for adding a digit to the end of the search string for the std::find_if.

The worry is a scene with 5000 XForms named mtl1 to mtl4999 as the search at line 341 will make this quadratic. Building a std::unordered_map of the children, keyed on the name would keep this linear, but the worst case is so unlikely I am not sure I would mandate this.

@frohnej-adsk frohnej-adsk added the ready-for-merge Development process is finished, PR is ready for merge label Jan 2, 2023
@seando-adsk seando-adsk added the ufe-usd Related to UFE-USD plugin in Maya-Usd label Jan 3, 2023
@seando-adsk seando-adsk merged commit 2526f07 into dev Jan 3, 2023
@seando-adsk seando-adsk deleted the frohnej/MAYA-126483/useCorrectMaterialsScope branch January 3, 2023 16:50
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