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

Assign new material to multiple objects #2641

Merged
merged 7 commits into from
Nov 21, 2022

Conversation

stefanminning-autodesk
Copy link
Collaborator

This PR adds functionality to the existing UsdUndoAssignNewMaterialCommand, allowing for a new material to be assigned to multiple objects.

The command's original functionality remains untouched, as I wanted to avoid breaking API changes.

@seando-adsk
Copy link
Collaborator

@stefanminning-autodesk Before we start the code review and preflight process can you please clean this up by squashing the 11 commits?

@stefanminning-autodesk stefanminning-autodesk force-pushed the minnins/assign-new-material-to-multiple-objects branch from cadd76e to 8dd50e8 Compare October 5, 2022 13:11
@stefanminning-autodesk
Copy link
Collaborator Author

Sure, I've pushed with squashed history.

@seando-adsk seando-adsk added the ufe-usd Related to UFE-USD plugin in Maya-Usd label Oct 5, 2022
@seando-adsk
Copy link
Collaborator

@womanyoyoyo-adsk Natalia can you please have a look at this from a design perspective?
@stefanminning-autodesk From the code changes it looks to me as if you are always applying the material the selection, regardless of the item the context menu was opened on. Normally the behavior would be:
Q: "is the item on which the context menu was opened in the selection or not"?
Yes - apply operation to selection
No - apply operation only to context item

@stefanminning-autodesk
Copy link
Collaborator Author

stefanminning-autodesk commented Oct 7, 2022

Right, I've coded it to match the current behaviour, where a new material would be assigned to an object when the right-click operation is applied upon it, regardless of its selection state. Additional selected objects will then also receive the new material.

But what you're describing also seems like a perfectly valid option. I'll leave it to the UX team to decide what the best workflow is. I've asked in our team for clarification. Should be an easy change, either way.

@seando-adsk
Copy link
Collaborator

@stefanminning-autodesk Actually sorry I don't think that is correct. With your changes it applies the material to all the selected objects. If the object you right click on is not selected, then the material is not applied to it. The normal context menu behavior would be "if the context object is selected?" then apply to selection, otherwise apply only to context object.

@stefanminning-autodesk
Copy link
Collaborator Author

Ah yes, you're right: Looking at the code again, it should not be ignoring fItem. Could have sworn I'd accounted for that at some point... must have slipped through the cracks.

Anyway, guess I'll have to have another look at this when the designers are back from holidays and they've clarified the exact behaviour they'd like to see.

@womanyoyoyo-adsk
Copy link
Collaborator

Hi, myself and Lookdevx designer are looking into this. Keep you posted.

@stefanminning-autodesk stefanminning-autodesk force-pushed the minnins/assign-new-material-to-multiple-objects branch 2 times, most recently from a90833f to 66dd552 Compare October 18, 2022 09:56
@stefanminning-autodesk
Copy link
Collaborator Author

As discussed with the UX team, the new material will be assigned to all of the following:

  • The selected object(s)
  • The object which received the right-click (regardless of its selection state)

The designers would also like to see additional UI feedback for the right-clicked item, but that will come as part of another task.

Copy link
Collaborator

@hodoulp hodoulp left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -105,6 +111,11 @@ class MAYAUSD_CORE_PUBLIC UsdUndoAssignNewMaterialCommand : public Ufe::InsertCh
//! sdrShaderIdentifier and assigns it to \p parentItem
static UsdUndoAssignNewMaterialCommand::Ptr
create(const UsdSceneItem::Ptr& parentItem, const std::string& sdrShaderIdentifier);
//! Create a UsdUndoAssignNewMaterialCommand that creates a new material based on \p
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not clear about Doxygen but I would have move \p close to the parameter name sdrShaderIdentifier

_stagesAndPaths[stage].push_back(parentPath);
}

UsdUndoAssignNewMaterialCommand::UsdUndoAssignNewMaterialCommand(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does that code need UFE_PREVIEW_XX defines protection?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good question, honestly not sure.

These changes are entirely contained in MayaUSD, with no UFE update required. What UFE version would I be looking for?

//! sdrShaderIdentifier and assigns it to multiple \p parentItems
static UsdUndoAssignNewMaterialCommand::Ptr
create(const std::vector<const UsdSceneItem::Ptr>& parentItems,
const std::string& sdrShaderIdentifier);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should the new method be protected by UFE_PREVIEW_XX defines?

@@ -93,6 +96,9 @@ class MAYAUSD_CORE_PUBLIC UsdUndoAssignNewMaterialCommand : public Ufe::InsertCh
UsdUndoAssignNewMaterialCommand(
const UsdSceneItem::Ptr& parentItem,
const std::string& sdrShaderIdentifier);
UsdUndoAssignNewMaterialCommand(
const std::vector<const UsdSceneItem::Ptr>& parentItems,
const std::string& sdrShaderIdentifier);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should the new method be protected by UFE_PREVIEW_XX defines?

@@ -116,8 +126,8 @@ class MAYAUSD_CORE_PUBLIC UsdUndoAssignNewMaterialCommand : public Ufe::InsertCh
void connectShaderToMaterial(Ufe::SceneItem::Ptr shaderItem, PXR_NS::UsdPrim materialPrim);
void markAsFailed();

const Ufe::Path _parentPath;
const std::string _nodeId;
std::map<pxr::UsdStageWeakPtr, std::vector<const Ufe::Path>> _stagesAndPaths;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry I didn't catch this earlier. We shouldn't use the namespace name directly, but instead the define. So "pxr::" should be "PXR_NS::" (see line 126).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Once this and the merge conflict is fixed, you can run another preflight and if it passes add the label "ready for merge" and I'll merge it. I confirmed with our designer that the multiple selection workflow is okay.

@stefanminning-autodesk
Copy link
Collaborator Author

Please ignore for now, I botched the merge apparently.

@stefanminning-autodesk stefanminning-autodesk added the do-not-merge-yet Development is not finished, PR not ready for merge label Nov 2, 2022
@hodoulp hodoulp changed the title Assign new material to multiple objects WIP - Assign new material to multiple objects Nov 2, 2022
@stefanminning-autodesk stefanminning-autodesk force-pushed the minnins/assign-new-material-to-multiple-objects branch from 3619924 to 656a49c Compare November 2, 2022 12:34
@stefanminning-autodesk stefanminning-autodesk removed the do-not-merge-yet Development is not finished, PR not ready for merge label Nov 2, 2022
@stefanminning-autodesk
Copy link
Collaborator Author

Alright, merge issue should be fixed.

seando-adsk
seando-adsk previously approved these changes Nov 3, 2022
@seando-adsk
Copy link
Collaborator

@stefanminning-autodesk There are clang-format errors that need to be fixed. Please see codingGuidelines for info on clang-format.

@stefanminning-autodesk
Copy link
Collaborator Author

@seando-adsk Sorry about that. I've now let clang-format do its thing and it fixed two issues. Fingers crossed!

seando-adsk
seando-adsk previously approved these changes Nov 3, 2022
@stefanminning-autodesk stefanminning-autodesk force-pushed the minnins/assign-new-material-to-multiple-objects branch from b7124b4 to 1b03a5d Compare November 11, 2022 09:35
@stefanminning-autodesk
Copy link
Collaborator Author

@seando-adsk @hodoulp I have added a unit test to test the multiple material assignment test case. Please have a look.

Comment on lines 736 to 741
os.putenv("MAYAUSD_MATERIALS_SCOPE_NAME", "test_scope")
ufeCmd.execute(cmdSS)
checkMaterial(self, rootHier, 5, 1, 1, 0, "standard_surface", "mtlx", "out", "/test_scope")

# Clear the envvar, otherwise we're affecting the results of following tests.
os.putenv("MAYAUSD_MATERIALS_SCOPE_NAME", "")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should have a way to make sure this is automatically restored using a context manager object. Look at TemporaryDirectory. You can create one that will restore an env var. The input would be the env var and the new value. The init will get the current value, store it and set the env var to input and the exit will restore to stored value. Then you can wrap this section of code in a with ... statement.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good idea, will do.

Copy link
Collaborator

@seando-adsk seando-adsk left a comment

Choose a reason for hiding this comment

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

Thanks for the test. If you could just create a new context object and use it the two places that env var is set/restored that would be great. The new context object can be in testUtils.py

Comment on lines 84 to 85
Context manager that creates a temporary environment variable and deletes it on exit,
so it's usable with "with" statement.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rather than deleting it upon exit, you should save the current env var value (if any) in the init and restore it in the exit (if one was saved).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Alright, I've changed it to restore the original value.

seando-adsk
seando-adsk previously approved these changes Nov 15, 2022
Copy link
Collaborator

@seando-adsk seando-adsk left a comment

Choose a reason for hiding this comment

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

Everything looks good now. Thanks.

@stefanminning-autodesk stefanminning-autodesk added the ready-for-merge Development process is finished, PR is ready for merge label Nov 16, 2022
@seando-adsk seando-adsk removed the ready-for-merge Development process is finished, PR is ready for merge label Nov 16, 2022
@seando-adsk
Copy link
Collaborator

@stefanminning-autodesk FYI, any new commit (such as your latest one merging in dev) will invalidate the preflight check and it must be run again. So I've removed the ready for merge label and re-started the preflight for you. When it passes, you may add back the label and I'll merge.

@stefanminning-autodesk
Copy link
Collaborator Author

Thanks @seando-adsk. The preflight succeeded, but then it was complaining about a tiny merge issues which I resolved right here in Github. I've kicked off another preflight just to be sure.

@stefanminning-autodesk stefanminning-autodesk added the ready-for-merge Development process is finished, PR is ready for merge label Nov 21, 2022
@seando-adsk seando-adsk merged commit 346fdd9 into dev Nov 21, 2022
@seando-adsk seando-adsk deleted the minnins/assign-new-material-to-multiple-objects branch November 21, 2022 15:18
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.

5 participants