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

EMSUSD-1266 don't depend on MayaUSD if not using it #3794

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
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
16 changes: 13 additions & 3 deletions lib/mayaUsd/nodes/layerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class LayerDatabase : public TfWeakBase
static void clearManagerNode(MayaUsd::LayerManager* lm);
static void removeManagerNode(MayaUsd::LayerManager* lm = nullptr);

bool getProxiesToSave(bool isExport);
bool getProxiesToSave(bool isExport, bool* hasAnyProxy);
bool saveInteractionRequired();
bool supportedNodeType(MTypeId type);
void addSupportForNodeType(MTypeId type);
Expand Down Expand Up @@ -415,7 +415,8 @@ void LayerDatabase::prepareForWriteCheck(bool* retCode, bool isExport)

LayerDatabase::instance().saveLayerManagerSelectedStage();

if (LayerDatabase::instance().getProxiesToSave(isExport)) {
bool hasAnyProxy = false;
if (LayerDatabase::instance().getProxiesToSave(isExport, &hasAnyProxy)) {

int dialogResult = true;

Expand All @@ -434,6 +435,9 @@ void LayerDatabase::prepareForWriteCheck(bool* retCode, bool isExport)
} else {
*retCode = true;
}

if (!hasAnyProxy)
removeManagerNode(nullptr);
}

void LayerDatabase::cleanupForWrite()
Expand Down Expand Up @@ -486,8 +490,11 @@ bool LayerDatabase::hasDirtyLayer() const
return false;
}

bool LayerDatabase::getProxiesToSave(bool isExport)
bool LayerDatabase::getProxiesToSave(bool isExport, bool* hasAnyProxy)
{
if (hasAnyProxy)
*hasAnyProxy = false;

bool checkSelection = isExport && (MFileIO::kExportTypeSelected == MFileIO::exportType());
const Ufe::GlobalSelection::Ptr& ufeSelection = Ufe::GlobalSelection::get();

Expand All @@ -499,6 +506,9 @@ bool LayerDatabase::getProxiesToSave(bool isExport)
MObject mobj = iter.item();
fn.setObject(mobj);
if (!fn.isFromReferencedFile() && supportedNodeType(fn.typeId())) {
if (hasAnyProxy)
*hasAnyProxy = true;

MayaUsdProxyShapeBase* pShape = static_cast<MayaUsdProxyShapeBase*>(fn.userNode());
UsdStageRefPtr stage = pShape ? pShape->getUsdStage() : nullptr;
if (!stage) {
Expand Down
18 changes: 18 additions & 0 deletions test/lib/mayaUsd/nodes/testLayerManagerSerialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@ def confirmEditsSavedStatus(self, fileBackedSavedStatus, sessionSavedStatus):
self.assertEqual(
sessionSavedStatus, stage.GetPrimAtPath(newPrimPath).IsValid())

def testSaveWithoutStage(self):
'''
Verify that when saving a Maya scene, if no stage have been created then
the scene does not depends on teh MayaUSD plugin.
'''
self._currentTestDir = tempfile.mkdtemp(prefix='testSaveWithoutStage')
self._tempMayaFile = os.path.join(
self._currentTestDir, 'EmptySerializationTest.ma')
cmds.file(new=True, force=True)
cmds.file(rename=self._tempMayaFile)
cmds.file(save=True, force=True, type='mayaAscii')
cmds.file(new=True, force=True)
for i, line in enumerate(open(self._tempMayaFile)):
self.assertFalse('mayaUsdPlugin' in line,
'Found mayaUSdPlugin depedency in line %d of %s' % (i+1, self._tempMayaFile))

shutil.rmtree(self._currentTestDir)

def testSaveAllToMaya(self):
'''
Verify that all USD edits are save into the Maya file.
Expand Down
Loading