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

Returning an enum from UI delegate #1259

Merged
merged 4 commits into from
Mar 24, 2021

Conversation

fowlertADSK
Copy link
Contributor

Have the UI delegate return an enum that describes what happened instead of a plain bool.
Keep track of the parent of any anonymous layer to be saved. Should be either another layer, where the identifier would need to be remapped, or if it's the root layer then its Stage, where the owning Proxy will need to have its path attribute remapped. The Session layer is the only one that would have neither a parent layer or proxy/stage tracked.
Initial set of test for serialization of Usd edits.

Have the UI delegate return an enum that describes what happened instead of a plain bool.
Keep track of the parent of any anonymous layer to be saved.  Should be either another layer, where the identifier would need to be remapped, or if it's the root layer then its Stage, where the owning Proxy will need to have its path attribute remapped.
Initial set of test for serialization of Usd edits.
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.

Other than one minor question, it all looks good to me.

Comment on lines 70 to 83
struct LayerParent
{
// Every layer that we are saving should have either a parent layer that
// we will need to remap to point to the new path, or the stage if it is an
// anonymous root layer.
SdfLayerRefPtr _layerParent;
UsdStageRefPtr _stageParent;
};

struct stageLayersToSave
{
std::vector<std::pair<SdfLayerRefPtr, LayerParent>> _anonLayers;
std::vector<SdfLayerRefPtr> _dirtyFileBackedLayers;
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do these two structs need to have the "MAYAUSD_CORE_PUBLIC" so they will be exported as well?

@fowlertADSK
Copy link
Contributor Author

We had two issues with the change:

  1. It failed in non-UFE builds (Maya 2018 or when disabling it explicitly).
  2. In practice there has normally been a 1:1 mapping from proxy to usd stage, but there is in-progress work that will change this, and given a usd stage it will no longer be able to always uniquely identify the owning proxy.

To fix both of these issues I changed all the places that we were holding to a stage ptr in order to track what needs to be saved and switched to using a proxy path. A string for the full path or a MDagPath.

The one reason we needed UFE was for the utility function that maps between stage and proxy shape, so moving to the proxy name removed that dependency entirely. I added a new utility function to help go from the proxy name string to the usd stage, which was always possible but I didn't see any other utility function that did exactly that.

@fowlertADSK
Copy link
Contributor Author

Just noticed a linter problem. Will look into that now...

@@ -226,6 +228,20 @@ MStatus UsdMayaUtil::GetDagPathByName(const std::string& nodeName, MDagPath& dag
return status;
}

UsdStageRefPtr UsdMayaUtil::GetStageByProxyName(const std::string& proxyPath)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I get that this is to remove dependence on UFE, but in doing so this is adding a by-name lookup of a proxy shape. If it's not called a lot, this is fine.

Also, I think it would be good to steer readers of this code to lib/mayaUsd/ufe/Utils.h, which will have much better performance, if a dependence on UFE is not an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Couple thoughts:

  1. Do you think lookup performance would be bad given a unique path? It might not be as fast as some of the structures in UFE, but I would hope that when looking for a single object given a unique string that it would be fairly quick. Right now this function will be called once per proxy shape when saving, so it shouldn't be too many and definitely not called interactively.

  2. We are going to have to revisit the utility function that I am replacing soon anyways, since it will no longer be valid to map between proxies and stages like we have it now. The stage cache map code that can go from UsdStage ptr to proxy is the one that will have to change.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Once per proxy shape when saving is fine, not an issue.

@@ -180,6 +181,10 @@ MString GetUniqueNameOfDagNode(const MObject& node);
MAYAUSD_CORE_PUBLIC
MStatus GetMObjectByName(const std::string& nodeName, MObject& mObj);

/// Gets the UsdStage for the proxy shape node named \p nodeName.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would add a comment pointer here to lib/mayaUsd/ufe/Utils.h

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, you just want me to mention in the comments that there is a similar function that uses UFE over in a different utilities file?
I believe the UFE approach would be to:
Convert the MDagPath into a UFE PathSegment.
Convert the PathSegment into a UFE Path.
Use the stage map to go from a Path to a stage ptr.

The only issue with the Maya way is what the performance is when you have a unique dag path and want the depend node, which I don't think is all that bad. Once you have the node then it's just a cast to our base class and we call the function on it to return the stage ptr.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That seems very roundabout... If you have an MDagPath, you don't need to go through UFE! You can just get the MObject from the tail of the path, and get a pointer from that.

And yes, just add a comment saying if you already have a dependence on UFE, then lib/mayaUsd/ufe/Utils.h is better.

@kxl-adsk kxl-adsk added the workflows Related to in-context workflows label Mar 24, 2021
debug cleanup
@fowlertADSK fowlertADSK added the ready-for-merge Development process is finished, PR is ready for merge label Mar 24, 2021
@kxl-adsk kxl-adsk merged commit 4545f04 into dev Mar 24, 2021
@kxl-adsk kxl-adsk deleted the fowlert/MAYA-109976/return-error-code-for-issues-saving branch March 24, 2021 20:12
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 workflows Related to in-context workflows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants