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-127478 fix bulk save of root layer filename #2864

Merged
merged 1 commit into from
Feb 16, 2023
Merged
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
31 changes: 31 additions & 0 deletions lib/mayaUsd/nodes/layerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ class LayerDatabase : public TfWeakBase
void saveUsdLayerToMayaFile(SdfLayerRefPtr layer, bool asAnonymous);
void clearProxies();
bool hasDirtyLayer() const;
void refreshProxiesToSave();

std::map<std::string, SdfLayerRefPtr> _idToLayer;
TfNotice::Key _onStageSetKey;
Expand Down Expand Up @@ -520,6 +521,27 @@ bool LayerDatabase::getProxiesToSave(bool isExport)

bool LayerDatabase::saveInteractionRequired() { return _proxiesToSave.size() > 0; }

static void refreshSavingInfo(StageSavingInfo& info)
{
MFnDependencyNode fn;
MObject mobj = info.dagPath.node();
fn.setObject(mobj);
if (!fn.isFromReferencedFile() && LayerDatabase::instance().supportedNodeType(fn.typeId())) {
MayaUsdProxyShapeBase* pShape = static_cast<MayaUsdProxyShapeBase*>(fn.userNode());
info.stage = pShape ? pShape->getUsdStage() : nullptr;
}
}

void LayerDatabase::refreshProxiesToSave()
{
for (StageSavingInfo& info : _proxiesToSave) {
refreshSavingInfo(info);
}
for (StageSavingInfo& info : _internalProxiesToSave) {
refreshSavingInfo(info);
}
}

bool LayerDatabase::saveUsd(bool isExport)
{
BatchSaveResult result = MayaUsd::kNotHandled;
Expand Down Expand Up @@ -555,6 +577,12 @@ bool LayerDatabase::saveUsd(bool isExport)
return true;
}

// After the potentially partial save, we need to refresh the stages
// to be saved because the saving might have modified the proxy shape
// attributes and we need to re-evaluate these nodes so that the stages
// are re-created with the new attribute values if needed.
refreshProxiesToSave();
Copy link
Collaborator

Choose a reason for hiding this comment

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

By doing this pull here does it cause any notifications to be sent and could that potentially mess up the clients since we've only done a partial save?

Copy link
Collaborator Author

@pierrebai-adsk pierrebai-adsk Feb 3, 2023

Choose a reason for hiding this comment

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

At the point this is called, we are in a pre-save callback AFAIK, so there should be no issue. The "partial" of the comment is in reference to the fact not all layers may have been saved and we are about to save the layers that have not been saved by that partial operation.

OTOH, if the partial save saved only a subset of a complex hierarchy of layers, and the subsequent saving of the remaining layer change their name, they, yes we could be inconsistent in theory. But this was always the case, this PR does not change this nor fix this.

That is, if a stage has the layer hierarchy:

A
|--B
   |-- C

And the partial save only saved 'B' and the the fallback save saves A and C but changes C filenames for any reason, then the sub-layer reference in B won't be the one saved. There is not much we can do about it, but fortunately, this never happens in practice. It may be feasible to artificially trigger this bad behavior in head-less Maya by creating such a hierarchy and writing a batch save delegate that only saves B, but that would be stretching it...


if (MayaUsd::utils::kSaveToUSDFiles == opt) {
result = saveUsdToUsdFiles();
} else {
Expand Down Expand Up @@ -781,6 +809,9 @@ void LayerDatabase::convertAnonymousLayers(

convertAnonymousLayersRecursive(root, proxyName, stage);

// Note: retrieve root again since it may have been changed by the call
// to convertAnonymousLayersRecursive
root = stage->GetRootLayer();
if (root->IsAnonymous()) {
PXR_NS::SdfFileFormat::FileFormatArguments args;
std::string newFileName = MayaUsd::utils::generateUniqueFileName(proxyName);
Expand Down