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-127817] mayaUsdProxyShape fails to load the stage when reopening the previous saved maya file with stage loaded by mayaUsdProxyShape via stageID. #2872

Closed
NickWu opened this issue Feb 10, 2023 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@NickWu
Copy link

NickWu commented Feb 10, 2023

Describe the bug
Hi, I found mayaUsdProxyShape fails to load the stage when opening the previous saved maya file with stage loaded by mayaUsdProxyShape via stageID.

Steps to reproduce
Steps to reproduce the behavior:

  1. Run the following code to load the a simple attached USD file:
    code:
from pxr import Usd, UsdUtils
from mayaUsd import lib as mayaUsdLib 
from maya import cmds 

filePath = './sphere.usda'

stageCache = UsdUtils.StageCache.Get()
with Usd.StageCacheContext(stageCache):
    cachedStage = Usd.Stage.Open(filePath)
    
stageId = stageCache.GetId(cachedStage).ToLongInt()
shapeNode = cmds.createNode('mayaUsdProxyShape')
cmds.setAttr('{}.stageCacheId'.format(shapeNode), stageId)
  1. Save the maya file and open a new scene.
  2. Open the saved maya file.
  3. You will see mayaUsdProxyShape, but stage is not loaded.

I think the root cause for this maybe because when mayaUsdProxyShape opens a stage via stageID, so the maya file is saved with mayaUsdProxyShape only has stageID. When reopening the saved maya file, the stageID that mayaUsdProxyShape has would become invalid.

I found AL_usdmaya_ProxyShape doesn't have this issue because it sets the filePath attribute when the stage is opened via stageID:

file.set(m_stage->GetRootLayer()->GetIdentifier().c_str());

When reopening the saved maya file, AL_usdmaya_ProxyShape would then be able to load the stage via filePath attribute.

Expected behavior
mayaUsdProxyShape should be able to load the stage when reopening from the saved maya file again even the stage was loaded via stageID.

Attachments
sphere.usda file:

#usda 1.0
(
)

def Sphere "pSphere"
{
    double3 xformOp:translate = (0, 1, 0)
    uniform token[] xformOpOrder = ["xformOp:translate"]
}

Specs (if applicable):

  • OS & version : CentOS 7.8
  • Compiler & version : GCC 9.3.1
  • Maya version: Maya-2023.2.0-11.0.PFIX & Maya 2022.4.0-24.0.PFIX
  • Maya USD commit SHA: latest dev at 4bbc17f
  • Pixar USD: official 22.11
@NickWu NickWu added the bug Something isn't working label Feb 10, 2023
@santosg87 santosg87 changed the title mayaUsdProxyShape fails to load the stage when reopening the previous saved maya file with stage loaded by mayaUsdProxyShape via stageID. [MAYA-127817] mayaUsdProxyShape fails to load the stage when reopening the previous saved maya file with stage loaded by mayaUsdProxyShape via stageID. Feb 16, 2023
@santosg87
Copy link
Collaborator

@NickWu thanks for reporting this. I am also able to reproduce this on our side. I logged it internally as MAYA-127817 as we investigate more and figure out the next steps on this issue.

@santosg87
Copy link
Collaborator

@NickWu we are trying to understand the usage on this workflow a bit better. using the stageCache to load a stage is not quite recommended, since nothing gets written to disk - would you be able to give us a bit more info on the usage for you guys?

we have an internal issue to track any work needed for this, but it is not a high priority issue for the time being.

Cheers!

@NickWu
Copy link
Author

NickWu commented Feb 23, 2023

Hey @santosg87 , thank you for taking a look.

At Animal Logic, before creating a proxy shape, our pipeline would load a stage with Load Rule set to Usd.Stage.LoadNone so that payloads are not loaded. For instance:

SC = UsdUtils.StageCache.Get()
with Usd.StageCacheContext(SC):
    cachedStage = Usd.Stage.Open(usdfilePath, load=Usd.Stage.LoadNone)

This way, our tool can show loaded prims in a GUI and artists can select which prims they want to load into the proxy shape before loading any heavy payloads as sometimes artists don't want to see everything in a stage. Once artists have decided, our pipeline tool would build the stage (load the payloads, only the ones artists want to work with, by calling cachedStage.SetLoadRules(loadRules)) and create the proxy shape with the stageID retrieved from the stage cache.

Hope that makes sense.

@pierrebai-adsk
Copy link
Collaborator

@NickWu Is there any reason why you could not provide the stage via the proxy shape filePath attribute? Is it because the stage is not in the MayaUSD cache and the proxy shape would not find the stage in the cache?

Also, the MayaUSD proxy shape has a loadPayloads boolean attribute which can be set to false to not load any payload. Would that not be a simpler approach than the pre-load you are doing?

@NickWu
Copy link
Author

NickWu commented Apr 11, 2023

Hi @pierrebai-adsk , at first, I thought I could use the following approach to use Usd.StageCacheContext to force mayaUsdProxyShape's filePath open to use the existing opened stage in the cache instead of opening a new stage with the same file path:

SC = UsdUtils.StageCache.Get()
with Usd.StageCacheContext(SC):
    shapeNode = cmds.createNode('mayaUsdProxyShape')
    cmds.setAttr('{}.filePath'.format(shapeNode), cachedStage.GetRootLayer().identifier, type='string') 
   
print(SC.GetAllStages())  # we would have two stages 

But it didn't work as the proxy shape still opened another new stage judging from the SC.GetAllStages() call. Also, I tried the second approach:

SC = UsdUtils.StageCache.Get()
with Usd.StageCacheContext(SC):
    shapeNode = cmds.createNode('mayaUsdProxyShape')
    cmds.setAttr('{}.stageCacheId'.format(shapeNode), stageId)
    cmds.setAttr('{}.filePath'.format(shapeNode), cachedStage.GetRootLayer().identifier, type='string') 
   
print(SC.GetAllStages())  # we would have two stages 

We still got two stages, which is not ideal, but we are now using the stage we previously opened in the cache.

@NickWu
Copy link
Author

NickWu commented Apr 14, 2023

Hi @pierrebai-adsk , I notice this PR #3010 has been merged which address the issue related to the conversation here. Therefor, I'll close this issue now. Thank you for looking into it.

@NickWu NickWu closed this as completed Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

3 participants