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-122362 cache-to-USD file type persistence #2316

Merged
merged 6 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
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
17 changes: 15 additions & 2 deletions lib/mayaUsd/resources/scripts/mayaUsdCacheMayaReference.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from mayaUsd.lib import cacheToUsd

from mayaUsdLibRegisterStrings import getMayaUsdLibString
import mayaUsdUtils
import mayaUsdMayaReferenceUtils as mayaRefUtils
import mayaUsdOptions

Expand Down Expand Up @@ -361,6 +362,10 @@ def cacheInitUi(parent, filterType):
primName = mayaUsd.ufe.uniqueChildName(mayaRefPrimParent, kDefaultCachePrimName)
cmds.textFieldGrp('primNameText', edit=True, text=primName)

# Call the file-filter changed callback as it does not get called by the dialog
# creation and it is used to update some UI elements.
fileTypeChangedUi(parent, filterType)

# By default we want to collapse certain sections.
cmds.frameLayout('outputFrameLayout', edit=True, collapse=False)
cmds.frameLayout('geometryFrameLayout', edit=True, collapse=True)
Expand Down Expand Up @@ -415,8 +420,14 @@ def fileTypeChangedUi(parent, fileType):
Used to disable the binary/ASCII drop-down when the selected file format only
supports one type.
'''
forcedFormat = fileType in ['*.usda', '*.usdc', '*.usdz']
# Note: initial file type is set using only its label, but the callback
# give the label + file pattern, so that is why we use 'fileType in ff'
# in the loop below.
forcedFormat = False
for ff in mayaUsdUtils.getMonoFormatFileFilterLabels():
forcedFormat = forcedFormat or fileType in ff
cmds.optionMenuGrp("defaultUSDFormatPopup", edit=True, enable=not forcedFormat)
mayaUsdUtils.setLastUsedUSDDialogFileFilter(fileType)


def cacheDialog(dagPath, pulledMayaRefPrim, _):
Expand All @@ -429,14 +440,16 @@ def cacheDialog(dagPath, pulledMayaRefPrim, _):
_pulledMayaRefPrim = pulledMayaRefPrim

ok = getMayaUsdLibString('kCacheMayaRefCache')
fileFilter = getMayaUsdLibString("kAllUsdFiles") + " (*.usd *.usda *.usdc *.usdz);;*.usd;;*.usda;;*.usdc;;*.usdz";
fileFilter = mayaUsdUtils.getUSDDialogFileFilters()
selectedFileFilter = mayaUsdUtils.getLastUsedUSDDialogFileFilter()

# As per Maya projectViewer.mel code structure, the UI creation
# (optionsUICreate) creates the main UI framework, and UI initialization
# (optionsUIInit) puts up the export options.
files = cmds.fileDialog2(
returnFilter=1, fileMode=0, caption=getMayaUsdLibString('kCaptionCacheToUsd'),
fileFilter=fileFilter, dialogStyle=2, okCaption=ok,
selectFileFilter=selectedFileFilter,
# The callbacks below must be MEL procedures, as per fileDialog2
# requirements. They call their corresponding Python functions.
optionsUICreate="mayaUsdCacheMayaReference_cacheCreateUi",
Expand Down
4 changes: 4 additions & 0 deletions lib/mayaUsd/resources/scripts/mayaUsdLibRegisterStrings.mel
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ global proc mayaUsdLibRegisterStrings()

// Used in multiple places.
register("kAllUsdFiles", "All USD Files");
register("kUsdFiles", "USD Files");
register("kUsdASCIIFiles", "USD ASCII Files");
register("kUsdBinaryFiles", "USD Binary Files");
register("kUsdCompressedFiles", "USD Compressed Files");
}
78 changes: 78 additions & 0 deletions lib/mayaUsd/resources/scripts/mayaUsdUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
# limitations under the License.
#

from re import L
from mayaUsdLibRegisterStrings import getMayaUsdLibString

from maya.api import OpenMaya as om
import maya.cmds as cmds

import mayaUsd

Expand Down Expand Up @@ -71,3 +75,77 @@ def isPulledMayaReference(dagPath):

_, _, _, prim = getPulledInfo(dagPath)
return prim and prim.GetTypeName() == 'MayaReference'


def getMonoFormatFileFilterLabels(includeCompressed = True):
"""
Returns a list of file-format labels for individual USD file formats.
This list is not directly usable in the dialog command, they would need
to be join with ';;'. Call getUSDDialogFileFilters() instead as it does
the joining.
"""
labelAndFilters = [
("kUsdASCIIFiles", "*.usda"),
("kUsdBinaryFiles", "*.usdc"),
]

if includeCompressed:
labelAndFilters.append(
("kUsdCompressedFiles", "*.usdz")
)

localizedLabels = [getMayaUsdLibString(labelKey) + ' ' + filter for labelKey, filter in labelAndFilters]
return localizedLabels


def getMultiFormatsFileFilterLabels(includeCompressed = True):
"""
Returns a list of file-format labels for multi-formats USD file formats.
This list is not directly usable in the dialog command, they would need
to be join with ';;'. Call getUSDDialogFileFilters() instead as it does
the joining.
"""
labelAndFilters = [
("kAllUsdFiles", "(*.usd *.usda *.usdc)"),
("kUsdFiles", "*.usd"),
]

if includeCompressed:
labelAndFilters[0] = ("kAllUsdFiles", "(*.usd *.usda *.usdc *.usdz)")

localizedLabels = [getMayaUsdLibString(labelKey) + ' ' + filter for labelKey, filter in labelAndFilters]
return localizedLabels


def getUSDDialogFileFilters(includeCompressed = True):
"""
Returns a text string of all USD file formats, ';;'-separated.
Directly usable in the Maya SDK dialog commands.
"""
localizedLabels = getMultiFormatsFileFilterLabels(includeCompressed) + getMonoFormatFileFilterLabels(includeCompressed)
fileFilters = ';;'.join(localizedLabels)
return fileFilters


def _getLastUsedUSDDialogFileFilterOptionVarName():
return "mayaUsd_LastUsedUSDDialogFileFilter"


def getLastUsedUSDDialogFileFilter():
"""
Retrieves the last-used USD file filter.
If the option variable doesn't exist, return the default file filter.
"""
varName = _getLastUsedUSDDialogFileFilterOptionVarName()
if cmds.optionVar(exists=varName):
return cmds.optionVar(query=varName)
else:
return getMayaUsdLibString("kAllUsdFiles")


def setLastUsedUSDDialogFileFilter(fileFilter):
"""
Sets the last-used USD file filter.
"""
varName = _getLastUsedUSDDialogFileFilterOptionVarName()
return cmds.optionVar(stringValue=(varName, fileFilter))
4 changes: 2 additions & 2 deletions plugin/adsk/scripts/AETemplateHelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import ufe
import mayaUsd.ufe
from mayaUSDRegisterStrings import getMayaUsdString
from mayaUsdLibRegisterStrings import getMayaUsdLibString
from mayaUsdUtils import getUSDDialogFileFilters

def debugMessage(msg):
DEBUG = False
Expand Down Expand Up @@ -124,7 +124,7 @@ def ProxyShapeFilePathChanged(filePathAttr, newFilePath=None):
# Pop the file open dialog for user to load new usd file.
title = getMayaUsdString("kLoadUSDFile")
okCaption = getMayaUsdString("kLoad")
fileFilter = getMayaUsdLibString("kAllUsdFiles") + ' (*.usd *.usda *.usdc *.usdz );;*.usd;;*.usda;;*.usdc;;*.usdz';
fileFilter = getUSDDialogFileFilters()
res = cmds.fileDialog2(caption=title, fileMode=1, ff=fileFilter, okc=okCaption)
if res and len(res) == 1:
debugMessage(' User picked USD file, setting file path attribute')
Expand Down
2 changes: 1 addition & 1 deletion plugin/adsk/scripts/mayaUsd_createStageFromFile.mel
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ global proc mayaUsd_createStageFromFile() {
setOptionVars(false);

$caption = getMayaUsdString("kCreateUsdStageFromFile");
$fileFilter = getMayaUsdLibString("kAllUsdFiles") + " (*.usd *.usda *.usdc *.usdz);;*.usd;;*.usda;;*.usdc;;*.usdz";
$fileFilter = python("from mayaUsdUtils import getUSDDialogFileFilters; getUSDDialogFileFilters()");
$okCaption = getMayaUsdString("kCreateStage");

string $startFolder = getLatestLoadStageFolder();
Expand Down
4 changes: 2 additions & 2 deletions plugin/adsk/scripts/mayaUsd_layerEditorFileDialogs.mel
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//

global proc string UsdLayerEditor_SaveLayerFileDialog() {
string $fileFilter = getMayaUsdLibString("kAllUsdFiles") + " (*.usd *.usda *.usdc );;*.usd;;*.usda;;*.usdc";
string $fileFilter = python("from mayaUsdUtils import getUSDDialogFileFilters; getUSDDialogFileFilters(False)");

string $result[] = `fileDialog2
-fileMode 0
Expand All @@ -41,7 +41,7 @@ global proc string UsdLayerEditor_LoadLayersFileDialogOptions_Create(string $par


global proc string[] UsdLayerEditor_LoadLayersFileDialog(string $title, string $folder) {
string $fileFilter = getMayaUsdLibString("kAllUsdFiles") + " (*.usd *.usda *.usdc );;*.usd;;*.usda;;*.usdc";
string $fileFilter = python("from mayaUsdUtils import getUSDDialogFileFilters; getUSDDialogFileFilters(False)");
$okCaption = getMayaUsdString("kLoad");

string $result[] = `fileDialog2
Expand Down