AL_USDMaya has limited support via Maya commands for editing or retrieving layer contents. It does know which layers have been modified in memory by tracking which layers have been set as an EditTarget and that are dirtied via the LayerManager node.
Typically a user of AL_USDMaya will do modifications directly via the USD API and AL_USDMaya will react accordingly.
The LayerManager is a singleton that tracks all layers that have been set as an EditTarget and that are classified as "Dirty" by USD. The LayerManager can be retrieved via it's Python bindings or directly in C++, you can also retrieve it's tracked layer contents via the AL_usdmaya_LayerManager command. The tracked layers will be serialised to the Maya scene when the scene is saved, and reapplied when the scene is re-opened. To record edits to a layer, you need to set it as the current Edit Target. AL_USDMaya will record which layers have been set as the edit target during a session, and when the scene is saved (via an OnSceneSaved callback) will serialise their content into the maya scene. Those layers will be deserialised into the live USD model after the scene has been opened again via an equivalent OnSceneOpened callback). Normally, the default Edit Target in USD will be the Root Layer of the scene, although using the Session Layer is something we should consider.
After doing in-memory edits to our USD scene changes(typically via Maya) we then translate our USD scene, which is a filepath to the root layer and the serialised content of all the modified in-memory layers that are tracked by the LayerManager, into our renderers scene description for rendering.
There are a number of layer-related commands available, all are available via MEL, and some from the USD->Layers dropdow in the UI.
- AL_usdmaya_LayerSave
- AL_usdmaya_LayerCreateLayer
- AL_usdmaya_LayerCurrentEditTarget
- AL_usdmaya_LayerGetLayers
- AL_usdmaya_LayerSetMuted
These are documented in detail via their respective command help strings (-h/-help)
This example shows how we record changes to the current Edit Target Layer, and output them to a string (can of course be saved to file also)
#set this to the root of your source distribution
AL_USDMayaRootPath = 'MYSOURCEROOT'
from maya import cmds
#Import very simple ball - everything will be displayed in hydra, so this should create a single transform and shape
maya.cmds.AL_usdmaya_ProxyShapeImport(f=AL_USDMayaRoot + '/extras/usd/tutorials/endToEndMaya/assets/Ball/Ball.usd', name='shot')
#Create a maya transform (which will drive the USD values) for each prim in USD
#Create maya transforms for all of the prim paths, and move the ball
cmds.select("AL_usdmaya_ProxyShape1")
maya.cmds.AL_usdmaya_ProxyShapeImportAllTransforms(pushToPrim=True)
maya.cmds.setAttr("shot|Ball|mesh.translateY",10)
#Export the root layer to a string
from AL import usdmaya
theStageCache = usdmaya.StageCache.Get()
theStage = theStageCache.GetAllStages()[0]
print theStage.GetRootLayer().ExportToString() #making an assumption about root layer being current layer
You can see that this will be serialised in the maya scene if you find the appropriate layer, and print the contents of its "serialised"(szd) attribute:
print cmds.getAttr("Ball_usd.szd")
Layer manager defines Hydra renderer plugin that is used by all Proxy shapes for rendering. It can be set directly (AL_usdmaya_LayerManger.rendererPluginName
) or with command (AL_usdmaya_ManageRenderer -setPlugin "Glimpse"
).
List of available renderers is based on plugins discovered by USD. If there is more than one renderer plugin available a new menu entry USD > Renderer is added.