Understanding UsdUtils.StageCache and mayaUsd.lib.StageCache #1377
-
Starting from a simple stage: from pxr import Usd, UsdGeom
# Export a simple stage
stage = Usd.Stage.CreateInMemory()
UsdGeom.Cube.Define(stage, "/cube")
stage.Export("/tmp/cube.usda") Consider this example: import mayaUsd
from maya import cmds
from pxr import UsdUtils
cmds.file(new=True, force=True)
cmds.loadPlugin("mayaUsdPlugin")
# Clear caches
maya_cache = mayaUsd.lib.StageCache.Get(loadAll=True)
usd_cache = UsdUtils.StageCache.Get()
maya_cache.Clear()
usd_cache.Clear()
assert not maya_cache.GetAllStages()
assert not usd_cache.GetAllStages()
# Import stage
shape = cmds.ls(cmds.createNode("mayaUsdProxyShape"), long=True)[0]
cmds.setAttr("{}.filePath".format(shape), "/tmp/cube.usda", type="string")
# Query by stage
assert maya_cache.GetId(mayaUsd.ufe.getStage(shape)).IsValid()
#assert usd_cache.GetId(mayaUsd.ufe.getStage(shape)).IsValid() # False
# Query by id
cache_id = cmds.getAttr("{}.outStageCacheId".format(shape))
#assert maya_cache.Find(Usd.StageCache.Id.FromLongInt(cache_id)) # None
assert usd_cache.Find(Usd.StageCache.Id.FromLongInt(cache_id)) In the above snippet the Maya cache is queryable by stage, and the UsdUtils cache is queryable by cache id (populated on attribute get). Is this behaviour intended? Which cache (and strategy) should I prefer for fetching stages within a Maya session? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Can you tell me more about how you are intending to use the stage after? Is it something you want to pass to another DG node? Pass the stages across different libraries? Will you mutate the data in the stage or it's for reading only? Any expectations about the lifetime of this stage? |
Beta Was this translation helpful? Give feedback.
-
Thank you for the additional context. In short, I would recommend relying more on Maya's data model and not on stage caches. This is exactly what we do for UFE workflows (see stage map) and in Layer Editor (see maya session state). What it means is that you will build tools that work with proxy shapes and query the stage from the proxy. FWIW. you can query stage directly from proxy using python - two possible ways are described in this discussion post. Now, a little about the stage caches. MayaUsd stage cache ( For USD global stage cache ( |
Beta Was this translation helpful? Give feedback.
Thank you for the additional context.
In short, I would recommend relying more on Maya's data model and not on stage caches. This is exactly what we do for UFE workflows (see stage map) and in Layer Editor (see maya session state). What it means is that you will build tools that work with proxy shapes and query the stage from the proxy. FWIW. you can query stage directly from proxy using python - two possible ways are described in this discussion post.
Now, a little about the stage caches. MayaUsd stage cache (
mayaUsd.lib.StageCache
) should really be considered as an implementation detail. For some time we were forced to include all proxy shape stages into the stage cache because data sto…