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-499 - Dirty layers don't get saved in Maya files #3402

Merged
merged 1 commit into from
Oct 23, 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
8 changes: 7 additions & 1 deletion lib/mayaUsd/nodes/proxyShapeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,13 @@ bool MayaUsdProxyShapeBase::isStageIncoming() const
CHECK_MSTATUS_AND_RETURN(localStatus, false);
const auto cacheId = UsdStageCache::Id::FromLongInt(cacheIdNum);
const auto stageCached = cacheId.IsValid() && UsdUtilsStageCache::Get().Contains(cacheId);
if (stageCached) {

// Check what is the cache connected to
MStringArray result;
MGlobal::executeCommand(("listConnections -shapes on " + this->name()), result);
Copy link

@NickWu NickWu Oct 24, 2023

Choose a reason for hiding this comment

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

Hi @samuelliu-adsk , thanks for working on this for the issue #3243. I tested it but unfortunately it doesn't resolve the issue due to the following code:

MGlobal::executeCommand(("listConnections -shapes on " + this->name()), result);

This is because a mayaUsdProxyShape usually has a time1 node's connection to its time attribute. The maya-usd code base does this as well. Please see https://github.com/Autodesk/maya-usd/blob/dev/plugin/adsk/scripts/mayaUsd_createStageWithNewLayer.py#L39 and https://github.com/Autodesk/maya-usd/blob/dev/lib/mayaUsd/ufe/UsdUndoCreateStageWithNewLayerCommand.cpp#L150-L151. Hence, MGlobal::executeCommand(("listConnections -shapes on " + this->name()), result) would return a time1 node and the isIncomingStage would be set to true which is not correct. I guess you might have been using the example code on the issue page #3243 to test the solution but the code example is missing time1 node's connection. Sorry for that.

According to the logic we discussed on the issue page:

If "mayaUsdProxyShape.stageCacheId" is connected, don't save, else if the stageCacheId refer an existing stage save its content.

I would suggest the following solution (I tested it and it resolves the issue):

bool isIncomingStage = false;
if (!inDataHandle.data().isNull()) {
    isIncomingStage = true;
} 

This is because the !inDataHandle.data().isNull() check already takes care of checking whether the proxy shape has an incoming connection to its inStageData attribute which might be from a bifrost graph or another proxy shape node. If there is no connection to it then we can consider isIncomingStage is false. I don't think we need to check the stageCacheId value because if it has value and is valid and in USD stage cache then isIncomingStage should be false. And if stageCacheId value is set but it's not valid then isIncomingStage should be false too.

I did a test for our internal patch which you could use to test as well:

from pxr import Usd, UsdUtils, UsdGeom
from maya import cmds 
import mayaUsd.lib
import tempfile

# you can find this file in maya-usd repo: maya-usd/test/lib/mayaUsd/nodes/ProxyShapeBaseTest/CubeModel.usda
filePath = '/home/users/nickw/Test/CubeModel.usda'
stageCache = UsdUtils.StageCache.Get()
with Usd.StageCacheContext(stageCache):
    cachedStage = Usd.Stage.Open(filePath)
    
stageId = stageCache.GetId(cachedStage).ToLongInt()
shapeNode = cmds.createNode('mayaUsdProxyShape')
cmds.connectAttr('time1.outTime', '{}.time'.format(shapeNode))

cmds.setAttr('{}.stageCacheId'.format(shapeNode), stageId)
cachedStage.SetEditTarget(cachedStage.GetSessionLayer())

fullPath = cmds.ls(shapeNode, long=True)[0]
cmds.select("{},/CubeModel".format(fullPath))
# Move the cube prim
cmds.move(0, 0, 2, r=True)

# Make sure shareStage is ON
assert cmds.getAttr('{}.{}'.format(shapeNode,"shareStage"))

# Make sure there is no connection to inStageData
assert not cmds.listConnections('{}.inStageData'.format(shapeNode), s=True, d=False)

cmds.select(cmds.listRelatives(fullPath, p=True)[0], r=True)

with tempfile.TemporaryDirectory(prefix='ProxyShapeBase') as testDir:
    pathToSave = "{}/CubeModel.ma".format(testDir)

    cmds.file(rename=pathToSave)
    cmds.file(save=True, force=True, type='mayaAscii')
    
    cmds.file(new=True, force=True)
    cmds.file(pathToSave, force=True, open=True)

    stage = mayaUsd.lib.GetPrim(fullPath).GetStage()
    prim = stage.GetPrimAtPath('/CubeModel')
    assert prim.IsValid()
    
    # Verify we get the saved changes we did 
    xform = UsdGeom.Xformable(prim)
    translate = xform.GetOrderedXformOps()[0].Get()
    assert translate[2] == 2

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks @NickWu , I'll make a new PR with the fixes.

Copy link

@NickWu NickWu Oct 24, 2023

Choose a reason for hiding this comment

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

Hi @samuelliu-adsk , thanks for working on this. I forgot to add the code to connect time1 again. I have updated the test code with this line cmds.connectAttr('time1.outTime', '{}.time'.format(shapeNode))


// The stage is only incoming if the cache is connected to a shape
if (stageCached && result.length()) {
isIncomingStage = true;
}
}
Expand Down