Skip to content

Commit

Permalink
MAYA-127478 fix bulk save of root layer filename
Browse files Browse the repository at this point in the history
When doing a bulk-save of layers when saving a Maya scene for the first time, the multiple-parts of teh saving process could end-up using stale data. That is because there is a first batch-save delegate (customizable callback) that can do a partial save, then a fallback save is done for any layer that did not get saved.

When a stage has just been created, it contains an anonymous root layer which gets replaced by a non-anonymous by the batch save delegate. When the root layer is swapped, the stage proxy shape is updated by setting its stage name attribute.  Unfortunately, the USD stage object was being cached and the attribute chage was thus not use immediately. Thus the 2nd part fallback-save thought that the root layer was still anonymous.

The fix is to refresh the cached USD stages by pulling again on the proxy stage node so that it updates itself when its attributes have been changed.
  • Loading branch information
pierrebai-adsk committed Feb 3, 2023
1 parent 4bbc17f commit 521931a
Showing 1 changed file with 31 additions and 0 deletions.
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();

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

0 comments on commit 521931a

Please sign in to comment.