Skip to content

Commit

Permalink
Merge pull request #2360 from Autodesk/t_bailp/MAYA-122926/cache-turn…
Browse files Browse the repository at this point in the history
…-off-auto-edit

MAYA-122926 turn off auto-edit when caching
  • Loading branch information
seando-adsk authored May 18, 2022
2 parents ad586af + 245a537 commit e1e2219
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 9 deletions.
22 changes: 15 additions & 7 deletions lib/usd/translators/mayaReferenceUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@
#include <maya/MFnAttribute.h>

namespace {

void clearAutoEdit(const UsdPrim& prim)
{
if (prim.IsValid()) {
UsdAttribute mayaAutoEditAttr = prim.GetAttribute(MayaUsd_SchemasTokens->mayaAutoEdit);
if (mayaAutoEditAttr.IsValid()) {
mayaAutoEditAttr.Set<bool>(false);
}
}
}

std::string findValue(const PXR_NS::VtDictionary& routingData, const PXR_NS::TfToken& key)
{
auto found = routingData.find(key);
Expand Down Expand Up @@ -233,13 +244,7 @@ bool PxrUsdTranslators_MayaReferenceUpdater::discardEdits()
if (PrimUpdaterManager::readPullInformation(dagPath, pulledPath)) {
// Reset the auto-edit when discarding the edit.
UsdPrim prim = MayaUsd::ufe::ufePathToPrim(pulledPath);
if (prim.IsValid()) {
UsdAttribute mayaAutoEditAttr
= prim.GetAttribute(MayaUsd_SchemasTokens->mayaAutoEdit);
if (mayaAutoEditAttr.IsValid()) {
mayaAutoEditAttr.Set<bool>(false);
}
}
clearAutoEdit(prim);
}
}

Expand All @@ -266,6 +271,9 @@ bool PxrUsdTranslators_MayaReferenceUpdater::pushEnd()
MayaUsd::LockNodesUndoItem::lock(
"Maya reference pulled transform unlocking", transformPath, false);

// Clear the auto-edit flag.
clearAutoEdit(getUsdPrim());

return true;
}

Expand Down
82 changes: 80 additions & 2 deletions test/lib/mayaUsd/fileio/testCacheToUsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,26 @@ def setUpClass(cls):
def tearDownClass(cls):
standalone.uninitialize()

def getCacheFileName(self):
return 'testCacheToUsd.usda'

def removeCacheFile(self):
'''
Remove the cache file if it exists. Ignore error if it does not exists.
'''
try:
os.remove(self.getCacheFileName())
except:
pass

def setUp(self):
# Start each test with a new scene with empty stage.
cmds.file(new=True, force=True)
import mayaUsd_createStageWithNewLayer
self.proxyShapePathStr = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()
self.stage = mayaUsd.lib.GetPrim(self.proxyShapePathStr).GetStage()
# Make sure the cache file is removed in case a previous test failed mid-way.
self.removeCacheFile()

def runTestCacheToUsd(self, createMayaRefPrimFn, checkCacheParentFn):
'''Cache edits on a pulled Maya reference prim test engine.'''
Expand Down Expand Up @@ -176,7 +190,7 @@ def runTestCacheToUsd(self, createMayaRefPrimFn, checkCacheParentFn):

# Cache to USD, using a payload composition arc.
defaultExportOptions = cacheToUsd.getDefaultExportOptions()
cacheFile = 'testCacheToUsd.usda'
cacheFile = self.getCacheFileName()
cachePrimName = 'cachePrimName'
payloadOrReference = 'Payload'
listEditType = 'Prepend'
Expand Down Expand Up @@ -237,13 +251,77 @@ def runTestCacheToUsd(self, createMayaRefPrimFn, checkCacheParentFn):
self.assertTrue(foundPayload)

# Clean up
os.remove(cacheFile)
self.removeCacheFile()


def testCacheToUsdSibling(self):
self.runTestCacheToUsd(createMayaRefPrimSiblingCache, checkSiblingCacheParent)

def testCacheToUsdVariant(self):
self.runTestCacheToUsd(createMayaRefPrimVariantCache, checkVariantCacheParent)


def testAutoEditAndCache(self):
'''Test editing then caching a Maya Reference.
Add a Maya Reference using auto-edit, then cache the edits.
'''
kDefaultPrimName = mayaRefUtils.defaultMayaReferencePrimName()

# Since this is a brand new prim, it should not have variant sets.
primTestDefault = self.stage.DefinePrim('/Test_Default', 'Xform')
primPathStr = self.proxyShapePathStr + ',/Test_Default'
self.assertFalse(primTestDefault.HasVariantSets())

variantSetName = 'new_variant_set'
variantName = 'new_variant'

mayaRefPrim = mayaUsdAddMayaReference.createMayaReferencePrim(
primPathStr,
self.mayaSceneStr,
self.kDefaultNamespace,
variantSet=(variantSetName, variantName),
mayaAutoEdit=True)

# The prim should have variant set.
self.assertTrue(primTestDefault.HasVariantSets())

# Verify that a Maya Reference prim was created.
self.assertTrue(mayaRefPrim.IsValid())
self.assertEqual(str(mayaRefPrim.GetName()), kDefaultPrimName)
self.assertEqual(mayaRefPrim, primTestDefault.GetChild(kDefaultPrimName))
self.assertTrue(mayaRefPrim.GetPrimTypeInfo().GetTypeName(), 'MayaReference')

attr = mayaRefPrim.GetAttribute('mayaAutoEdit')
self.assertTrue(attr.IsValid())
self.assertEqual(attr.Get(), True)

# Cache to USD, using a payload composition arc.
defaultExportOptions = cacheToUsd.getDefaultExportOptions()
cacheFile = self.getCacheFileName()
cachePrimName = 'cachePrimName'
payloadOrReference = 'Payload'
listEditType = 'Prepend'

userArgs = cacheToUsd.createCacheCreationOptions(
defaultExportOptions, cacheFile, cachePrimName, payloadOrReference,
listEditType, variantSetName, variantName)

# Merge Maya edits.
aMayaItem = ufe.GlobalSelection.get().front()
aMayaPath = aMayaItem.path()
aMayaPathStr = ufe.PathString.string(aMayaPath)

with mayaUsd.lib.OpUndoItemList():
self.assertTrue(mayaUsd.lib.PrimUpdaterManager.mergeToUsd(aMayaPathStr, userArgs))

# Verify that the auto-edit has been turned off
attr = mayaRefPrim.GetAttribute('mayaAutoEdit')
self.assertTrue(attr.IsValid())
self.assertEqual(attr.Get(), False)

self.removeCacheFile()


if __name__ == '__main__':
unittest.main(verbosity=2)

0 comments on commit e1e2219

Please sign in to comment.