Skip to content

Commit

Permalink
Merge pull request #3151 from Autodesk/bailp/MAYA-129276/add-payload
Browse files Browse the repository at this point in the history
MAYA-129276 add payload
  • Loading branch information
seando-adsk authored Jun 15, 2023
2 parents 61427e8 + 049c34e commit da6b567
Show file tree
Hide file tree
Showing 12 changed files with 316 additions and 100 deletions.
6 changes: 3 additions & 3 deletions lib/mayaUsd/resources/scripts/mayaUsdAddUSDReference.mel
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ global proc addUSDReferenceCreateUi(string $parent)
{
setParent $parent;
string $layout = `scrollLayout -childResizable true`;
python("import mayaUsd_USDRootFileRelative as murel\nmurel.usdFileRelativeToEditTargetLayer.uiCreate(r'''" + $layout + "''')");
python("import mayaUsd_USDRootFileRelative as murel\nmurel.usdAddRefOrPayloadRelativeToEditTargetLayer.uiCreate(r'''" + $layout + "''')");
}

global proc addUSDReferenceInitUi(string $parent, string $filterType)
{
python("import mayaUsd_USDRootFileRelative as murel\nmurel.usdFileRelativeToEditTargetLayer.uiInit(r'''" + $parent + "''', r'''" + $filterType + "''')");
python("import mayaUsd_USDRootFileRelative as murel\nmurel.usdAddRefOrPayloadRelativeToEditTargetLayer.uiInit(r'''" + $parent + "''', r'''" + $filterType + "''')");
}

global proc addUSDReferenceToUsdCommitUi(string $parent, string $selectedFile)
{
setParent $parent;
python("import mayaUsd_USDRootFileRelative as murel\nmurel.usdFileRelativeToEditTargetLayer.uiCommit(r'''" + $parent + "''', r'''" + $selectedFile + "''')");
python("import mayaUsd_USDRootFileRelative as murel\nmurel.usdAddRefOrPayloadRelativeToEditTargetLayer.uiCommit(r'''" + $parent + "''', r'''" + $selectedFile + "''')");
}
84 changes: 9 additions & 75 deletions lib/mayaUsd/resources/scripts/mayaUsdCacheMayaReference.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,61 +47,6 @@
# Pulled Maya reference prim.
_pulledMayaRefPrim = None

_compositionArcLabels = [getMayaUsdLibString('kMenuPayload'), getMayaUsdLibString('kMenuReference')]
_compositionArcValues = [ 'Payload', 'Reference' ]

_listEditedAsLabels = [getMayaUsdLibString('kMenuAppend'), getMayaUsdLibString('kMenuPrepend')]
_listEditedAsValues = [ 'Append', 'Prepend' ]


def _getMenuGrpValue(menuName, values, defaultIndex = 0):
"""
Retrieves the currently selected values from a menu.
"""
# Note: option menu selection index start at 1, so we subtract 1.
menuIndex = cmds.optionMenuGrp(menuName, query=True, select=True) - 1
if 0 <= menuIndex < len(values):
return values[menuIndex]
else:
return values[defaultIndex]

def _getMenuValue(menuName, values, defaultIndex = 0):
"""
Retrieves the currently selected values from a menu.
"""
# Note: option menu selection index start at 1, so we subtract 1.
menuIndex = cmds.optionMenu(menuName, query=True, select=True) - 1
if 0 <= menuIndex < len(values):
return values[menuIndex]
else:
return values[defaultIndex]


def _getMenuIndex(values, current, defaultIndex = 1):
"""
Retrieves the menu index corresponding to the current value selected amongst values.
If the value is invalid, returns the defaultIndex.
"""
try:
# Note: menu index is 1-based.
return values.index(current) + 1
except:
return defaultIndex


def compositionArcChanged(selectedItem):
"""
Reacts to the composition arc type being selected by the user.
"""
pass


def listEditChanged(selectedItem):
"""
Reacts to the list edited UI being changed by the user.
"""
pass


def variantSetNameChanged(selectedItem):
"""
Expand Down Expand Up @@ -183,18 +128,7 @@ def cacheFileUsdHierarchyOptions(topForm):
l=getMayaUsdLibString('kCacheFileWillAppear'))
cmds.textField(text=str(_pulledMayaRefPrim.GetParent().GetPath()), editable=False)

with mayaRefUtils.SetParentContext(cmds.rowLayout(numberOfColumns=2)):
cmds.optionMenuGrp('compositionArcTypeMenu',
label=getMayaUsdLibString('kOptionAsUSDReference'),
cc=compositionArcChanged,
annotation=getMayaUsdLibString('kOptionAsUSDReferenceToolTip'))
for label in _compositionArcLabels:
cmds.menuItem(label=label)
cmds.optionMenu('listEditedAsMenu',
label=getMayaUsdLibString('kOptionListEditedAs'),
cc=listEditChanged)
for label in _listEditedAsLabels:
cmds.menuItem(label=label)
mayaRefUtils.createUsdRefOrPayloadUI()

variantRb = cmds.radioButtonGrp('variantRadioButton',
nrb=1,
Expand Down Expand Up @@ -322,11 +256,9 @@ def cacheInitUi(parent, filterType):
# variant is the default, otherwise all variant options are disabled.
mayaRefPrimParent = _pulledMayaRefPrim.GetParent()

menuIndex = _getMenuIndex(_compositionArcValues, optionsDict['rn_payloadOrReference'])
cmds.optionMenuGrp('compositionArcTypeMenu', edit=True, select=menuIndex)

menuIndex = _getMenuIndex(_listEditedAsValues, optionsDict['rn_listEditType'])
cmds.optionMenu('listEditedAsMenu', edit=True, select=menuIndex)
mayaRefUtils.initUsdRefOrPayloadUI({
mayaRefUtils.compositionArcKey: optionsDict['rn_payloadOrReference'],
mayaRefUtils.listEditTypeKey: optionsDict['rn_listEditType']})

if mayaRefPrimParent.HasVariantSets():
# Define in variant is the default.
Expand Down Expand Up @@ -379,8 +311,10 @@ def cacheCommitUi(parent, selectedFile):
mel.eval('mayaUsdTranslatorExport("fileOptionsScroll", "query={exportOpts}", "", "mayaUsdCacheMayaReference_setCacheOptions")'.format(exportOpts=kTranslatorExportOptions))

primName = cmds.textFieldGrp('primNameText', query=True, text=True)
payloadOrReference = _getMenuGrpValue('compositionArcTypeMenu', _compositionArcValues)
listEditType = _getMenuValue('listEditedAsMenu', _listEditedAsValues)

values = mayaRefUtils.commitUsdRefOrPayloadUI()
compositionArc = values[mayaRefUtils.compositionArcKey]
listEditType = values[mayaRefUtils.listEditTypeKey]

defineInVariant = cmds.radioButtonGrp('variantRadioButton', query=True, select=True)
if defineInVariant:
Expand All @@ -393,7 +327,7 @@ def cacheCommitUi(parent, selectedFile):
variantSetName = None

userArgs = cacheToUsd.createCacheCreationOptions(
getCacheExportOptions(), selectedFile, primName, payloadOrReference,
getCacheExportOptions(), selectedFile, primName, compositionArc,
listEditType, variantSetName, variantName)

cacheToUsd.saveCacheCreationOptions(userArgs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ global proc mayaUsdLibRegisterStrings()
register("kMayaRefEditAsMayaDataAnn", "Select this checkbox to enable editing the MayaReference prim as a Maya Reference.");
register("kMayaRefOptions", "Maya Reference Options");
register("kMayaRefCreateNew", "Create New");
register("kMayaRefAddToPrim", "Add Maya Reference to USD Prim");
register("kMayaRefAddToPrim", "Add Maya Reference to Prim");
register("kMayaRefReference", "Reference");

// Used in multiple places.
Expand Down
3 changes: 2 additions & 1 deletion lib/mayaUsd/resources/scripts/mayaUsdLibRegisterStrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ def mayaUsdLibRegisterStrings():
register('kMenuPayload', 'Payload')
register('kMenuPrepend', 'Prepend')
register('kMenuReference', 'Reference')
register('kOptionAsUSDReference', 'As USD Reference:')
register('kOptionAsUSDReference', 'Composition Arc:')
register('kOptionAsUSDReferenceToolTip', '<p>Choose the type of USD Reference composition arc for your Maya Reference:<br><br><b>Payloads</b> are a type of reference. They are recorded, but not traversed in the scene hierarchy. Select this arc if your goal is to manually construct<br>a "working set" that is a subset of an entire scene, in which only parts of the scene are required/loaded. Note: payloads are<br>weaker than direct references in any given LayerStack.<br><br><b>References</b> are general and can be used to compose smaller units of scene description into larger aggregates, building up a namespace that<br>includes the "encapsulated" result of composing the scene description targeted by a reference. Select this arc if your goal is not to unload your<br>references.</p>')
register('kOptionListEditedAs', 'List Edited As')
register('kOptionLoadPayload', 'Load Payload:')
register('kTextDefineIn', 'Define in:')
register('kTextVariant', 'Variant')
register('kTextVariantToolTip','If selected, your Maya reference will be defined in a variant. This will enable your prim to\nhave 2 variants you can switch between in the Outliner; the Maya reference and its USD cache.')
Expand Down
93 changes: 93 additions & 0 deletions lib/mayaUsd/resources/scripts/mayaUsdMayaReferenceUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,25 @@
#

import maya.cmds as cmds
from mayaUsdLibRegisterStrings import getMayaUsdLibString

# These names should not be localized as Usd only accepts [a-z,A-Z] as valid characters.
kDefaultMayaReferencePrimName = 'MayaReference1'
kDefaultVariantSetName = 'Representation'
kDefaultVariantName = 'MayaReference'

compositionArcKey = 'compositionArc'
compositionArcPayload = 'Payload'
compositionArcReference = 'Reference'
_compositionArcValues = [compositionArcPayload, compositionArcReference]

listEditTypeKey = ''
listEditTypeAppend = 'Append'
listEditTypePrepend = 'Prepend'
_listEditedAsValues = [listEditTypeAppend, listEditTypePrepend]

loadPayloadKey = 'loadPayload'

def defaultMayaReferencePrimName():
return kDefaultMayaReferencePrimName

Expand Down Expand Up @@ -64,3 +77,83 @@ def pushOptionsUITemplate():

cmds.setUITemplate('optionsTemplate', pushTemplate=True)

def _getMenuIndex(values, current, defaultIndex = 1):
"""
Retrieves the menu index corresponding to the current value selected amongst values.
If the value is invalid, returns the defaultIndex.
"""
try:
# Note: menu index is 1-based.
return values.index(current) + 1
except:
return defaultIndex

def _getMenuGrpValue(menuName, values, defaultIndex = 0):
"""
Retrieves the currently selected values from a menu.
"""
# Note: option menu selection index start at 1, so we subtract 1.
menuIndex = cmds.optionMenuGrp(menuName, query=True, select=True) - 1
if 0 <= menuIndex < len(values):
return values[menuIndex]
else:
return values[defaultIndex]

def _getMenuValue(menuName, values, defaultIndex = 0):
"""
Retrieves the currently selected values from a menu.
"""
# Note: option menu selection index start at 1, so we subtract 1.
menuIndex = cmds.optionMenu(menuName, query=True, select=True) - 1
if 0 <= menuIndex < len(values):
return values[menuIndex]
else:
return values[defaultIndex]

def _compositionArcChanged(selectedItem):
"""
Reacts to the composition arc type being selected by the user.
"""
compositionArc = _getMenuGrpValue('compositionArcTypeMenu', _compositionArcValues)
enableLoadPayload = bool(compositionArc == compositionArcPayload)
cmds.checkBoxGrp('loadPayload', edit=True, enable=enableLoadPayload)

def createUsdRefOrPayloadUI(showLoadPayload=False):
with SetParentContext(cmds.rowLayout(numberOfColumns=2)):
tooltip = getMayaUsdLibString('kOptionAsUSDReferenceToolTip')
cmds.optionMenuGrp('compositionArcTypeMenu',
label=getMayaUsdLibString('kOptionAsUSDReference'),
annotation=tooltip)
compositionArcLabels = [getMayaUsdLibString('kMenuPayload'), getMayaUsdLibString('kMenuReference')]
for label in compositionArcLabels:
cmds.menuItem(label=label)
cmds.optionMenu('listEditedAsMenu',
label=getMayaUsdLibString('kOptionListEditedAs'),
annotation=tooltip)
listEditedAsLabels = [getMayaUsdLibString('kMenuAppend'), getMayaUsdLibString('kMenuPrepend')]
for label in listEditedAsLabels:
cmds.menuItem(label=label)

if showLoadPayload:
cmds.checkBoxGrp('loadPayload',
label=getMayaUsdLibString('kOptionLoadPayload'),
ncb=1)

def initUsdRefOrPayloadUI(values, showLoadPayload=False):
compositionArcMenuIndex = _getMenuIndex(_compositionArcValues, values[compositionArcKey])
cmds.optionMenuGrp('compositionArcTypeMenu', edit=True, select=compositionArcMenuIndex)

listEditTypeMenuIndex = _getMenuIndex(_listEditedAsValues,values[listEditTypeKey])
cmds.optionMenu('listEditedAsMenu', edit=True, select=listEditTypeMenuIndex)

if showLoadPayload:
cmds.optionMenuGrp('compositionArcTypeMenu', edit=True, cc=_compositionArcChanged)
_compositionArcChanged(compositionArcMenuIndex)
cmds.checkBoxGrp('loadPayload', edit=True, value1=values[loadPayloadKey])

def commitUsdRefOrPayloadUI(showLoadPayload=False):
values = {}
values[compositionArcKey] = _getMenuGrpValue('compositionArcTypeMenu', _compositionArcValues)
values[listEditTypeKey ] = _getMenuValue('listEditedAsMenu', _listEditedAsValues)
values[loadPayloadKey ] = cmds.checkBoxGrp('loadPayload', query=True, value1=True) if showLoadPayload else True
return values
24 changes: 24 additions & 0 deletions lib/mayaUsd/resources/scripts/mayaUsdUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,28 @@ def setUserSelectedUSDDialogFileFilter(fileFilter):
_userSelectedUSDDialogFileFilter = fileFilter


def wantReferenceCompositionArc():
opVarName = "mayaUsd_WantReferenceCompositionArc"
return cmds.optionVar(exists=opVarName) and cmds.optionVar(query=opVarName)

def saveWantReferenceCompositionArc(want):
opVarName = "mayaUsd_WantReferenceCompositionArc"
cmds.optionVar(iv=(opVarName, want))

def wantPrependCompositionArc():
opVarName = "mayaUsd_WantPrependCompositionArc"
return cmds.optionVar(exists=opVarName) and cmds.optionVar(query=opVarName)

def saveWantPrependCompositionArc(want):
opVarName = "mayaUsd_WantPrependCompositionArc"
cmds.optionVar(iv=(opVarName, want))

def wantPayloadLoaded():
opVarName = "mayaUsd_WantPayloadLoaded"
return cmds.optionVar(exists=opVarName) and cmds.optionVar(query=opVarName)

def saveWantPayloadLoaded(want):
opVarName = "mayaUsd_WantPayloadLoaded"
cmds.optionVar(iv=(opVarName, want))


Loading

0 comments on commit da6b567

Please sign in to comment.