Skip to content

Commit 9f3800b

Browse files
authored
Merge pull request #2311 from Autodesk/t_bailp/MAYA-122361/cache-file-format
MAYA-122361 enforce cache file format
2 parents dccfcf7 + c76a306 commit 9f3800b

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

lib/mayaUsd/resources/scripts/mayaUsdCacheMayaReference.mel

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ global proc mayaUsdCacheMayaReference_cacheCommitUi(string $parent, string $sele
3434
+ $parent + "', '" + $selectedFile + "')");
3535
}
3636

37+
global proc mayaUsdCacheMayaReference_fileTypeChangedUi(string $parent, string $fileType)
38+
{
39+
python("from mayaUsdCacheMayaReference import fileTypeChangedUi; fileTypeChangedUi('"
40+
+ $parent + "', '" + $fileType + "')");
41+
}
3742

3843
// mayaUsdTranslatorExport() requires a MEL procedure as a callback, to return
3944
// options read from the UI.

lib/mayaUsd/resources/scripts/mayaUsdCacheMayaReference.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,16 @@ def cacheCommitUi(parent, selectedFile):
409409
cmds.error(errorMsg)
410410

411411

412+
def fileTypeChangedUi(parent, fileType):
413+
'''
414+
Callback called when the user change the file dialog file format drop-down.
415+
Used to disable the binary/ASCII drop-down when the selected file format only
416+
supports one type.
417+
'''
418+
forcedFormat = fileType in ['*.usda', '*.usdc', '*.usdz']
419+
cmds.optionMenuGrp("defaultUSDFormatPopup", edit=True, enable=not forcedFormat)
420+
421+
412422
def cacheDialog(dagPath, pulledMayaRefPrim, _):
413423
'''Display dialog to cache the argument pulled Maya reference prim to USD.'''
414424

@@ -433,5 +443,6 @@ def cacheDialog(dagPath, pulledMayaRefPrim, _):
433443
optionsUIInit="mayaUsdCacheMayaReference_cacheInitUi",
434444
optionsUITitle="",
435445
optionsUICommit2="mayaUsdCacheMayaReference_cacheCommitUi",
446+
fileTypeChanged="mayaUsdCacheMayaReference_fileTypeChangedUi",
436447
startingDirectory=cmds.workspace(query=True, directory=True)
437448
)

lib/mayaUsd/utils/editRouter.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <pxr/usd/usd/payloads.h>
2424
#include <pxr/usd/usd/references.h>
2525
#include <pxr/usd/usd/stage.h>
26+
#include <pxr/usd/usd/usdFileFormat.h>
2627
#include <pxr/usd/usd/variantSets.h>
2728
#include <pxr/usd/usdGeom/gprim.h>
2829

@@ -79,13 +80,26 @@ void cacheMayaReference(const PXR_NS::VtDictionary& context, PXR_NS::VtDictionar
7980
if (dstLayerPath.empty() || dstPrimName.empty())
8081
return;
8182

83+
// Determine the file format
84+
PXR_NS::SdfLayer::FileFormatArguments fileFormatArgs;
85+
PXR_NS::SdfFileFormatConstPtr fileFormat;
86+
87+
auto fileFormatExtension
88+
= PXR_NS::VtDictionaryGet<std::string>(context, "defaultUSDFormat", PXR_NS::VtDefault = "");
89+
if (fileFormatExtension.size() > 0) {
90+
fileFormatArgs[PXR_NS::UsdUsdFileFormatTokens->FormatArg] = fileFormatExtension;
91+
auto dummyFilename = std::string("a.") + fileFormatExtension;
92+
fileFormat = PXR_NS::SdfFileFormat::FindByExtension(dummyFilename, fileFormatArgs);
93+
}
94+
8295
// Prepare the layer
8396
PXR_NS::SdfPath dstPrimPath
8497
= PXR_NS::SdfPath(dstPrimName).MakeAbsolutePath(PXR_NS::SdfPath::AbsoluteRootPath());
85-
PXR_NS::SdfLayerRefPtr tmpLayer = PXR_NS::SdfLayer::CreateAnonymous();
98+
PXR_NS::SdfLayerRefPtr tmpLayer
99+
= PXR_NS::SdfLayer::CreateAnonymous("", fileFormat, fileFormatArgs);
86100
SdfJustCreatePrimInLayer(tmpLayer, dstPrimPath);
87101

88-
tmpLayer->Export(dstLayerPath);
102+
tmpLayer->Export(dstLayerPath, "", fileFormatArgs);
89103
PXR_NS::SdfLayerRefPtr dstLayer = PXR_NS::SdfLayer::FindOrOpen(dstLayerPath);
90104
if (!dstLayer)
91105
return;

0 commit comments

Comments
 (0)