Skip to content

Commit

Permalink
Fix texture writer path resolver to work relative to final export pat…
Browse files Browse the repository at this point in the history
…h rather than any temp paths the exporter sets.

Address Autodesk#972
  • Loading branch information
dgovil committed Jan 5, 2021
1 parent 19d82e8 commit ee4df76
Show file tree
Hide file tree
Showing 9 changed files with 378 additions and 15 deletions.
4 changes: 3 additions & 1 deletion lib/mayaUsd/commands/baseExportCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ MStatus MayaUSDExportCommand::doIt(const MArgList& args)
}

// Read all of the dictionary args first.
const VtDictionary userArgs = UsdMayaUtil::GetDictionaryFromArgDatabase(
VtDictionary userArgs = UsdMayaUtil::GetDictionaryFromArgDatabase(
argData, UsdMayaJobExportArgs::GetDefaultDictionary());

// Now read all of the other args that are specific to this command.
Expand All @@ -231,6 +231,8 @@ MStatus MayaUSDExportCommand::doIt(const MArgList& args)
if (fileName.empty()) {
fileName = tmpVal.asChar();
}

userArgs["fileName"] = fileName;
} else {
TF_RUNTIME_ERROR("-file not specified.");
return MS::kFailure;
Expand Down
3 changes: 3 additions & 0 deletions lib/mayaUsd/fileio/jobs/jobArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ UsdMayaJobExportArgs::UsdMayaJobExportArgs(
UsdMayaJobExportArgsTokens->none,
{ UsdMayaJobExportArgsTokens->auto_, UsdMayaJobExportArgsTokens->explicit_ }))
, exportVisibility(_Boolean(userArgs, UsdMayaJobExportArgsTokens->exportVisibility))
, fileName(_String(userArgs, UsdMayaJobExportArgsTokens->fileName))
, materialCollectionsPath(
_AbsolutePath(userArgs, UsdMayaJobExportArgsTokens->materialCollectionsPath))
, materialsScopeName(
Expand Down Expand Up @@ -387,6 +388,7 @@ std::ostream& operator<<(std::ostream& out, const UsdMayaJobExportArgs& exportAr
<< "exportSkels: " << TfStringify(exportArgs.exportSkels) << std::endl
<< "exportSkin: " << TfStringify(exportArgs.exportSkin) << std::endl
<< "exportVisibility: " << TfStringify(exportArgs.exportVisibility) << std::endl
<< "fileName: " << exportArgs.fileName << std::endl
<< "materialCollectionsPath: " << exportArgs.materialCollectionsPath << std::endl
<< "materialsScopeName: " << exportArgs.materialsScopeName << std::endl
<< "mergeTransformAndShape: " << TfStringify(exportArgs.mergeTransformAndShape) << std::endl
Expand Down Expand Up @@ -470,6 +472,7 @@ const VtDictionary& UsdMayaJobExportArgs::GetDefaultDictionary()
d[UsdMayaJobExportArgsTokens->exportSkels] = UsdMayaJobExportArgsTokens->none.GetString();
d[UsdMayaJobExportArgsTokens->exportUVs] = true;
d[UsdMayaJobExportArgsTokens->exportVisibility] = true;
d[UsdMayaJobExportArgsTokens->fileName] = UsdMayaJobExportArgsTokens->fileName;
d[UsdMayaJobExportArgsTokens->kind] = std::string();
d[UsdMayaJobExportArgsTokens->materialCollectionsPath] = std::string();
d[UsdMayaJobExportArgsTokens->materialsScopeName]
Expand Down
28 changes: 15 additions & 13 deletions lib/mayaUsd/fileio/jobs/jobArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ TF_DECLARE_PUBLIC_TOKENS(
(exportSkin) \
(exportUVs) \
(exportVisibility) \
(fileName) \
(kind) \
(materialCollectionsPath) \
(materialsScopeName) \
Expand Down Expand Up @@ -141,19 +142,20 @@ struct UsdMayaJobExportArgs
/// material-collections are created and bindings are made to the
/// collections at \p materialCollectionsPath, instead of direct
/// per-gprim bindings.
const bool exportCollectionBasedBindings;
const bool exportColorSets;
const bool exportDefaultCameras;
const bool exportDisplayColor;
const bool exportInstances;
const bool exportMaterialCollections;
const bool exportMeshUVs;
const bool exportNurbsExplicitUV;
const bool exportReferenceObjects;
const bool exportRefsAsInstanceable;
const TfToken exportSkels;
const TfToken exportSkin;
const bool exportVisibility;
const bool exportCollectionBasedBindings;
const bool exportColorSets;
const bool exportDefaultCameras;
const bool exportDisplayColor;
const bool exportInstances;
const bool exportMaterialCollections;
const bool exportMeshUVs;
const bool exportNurbsExplicitUV;
const bool exportReferenceObjects;
const bool exportRefsAsInstanceable;
const TfToken exportSkels;
const TfToken exportSkin;
const bool exportVisibility;
const std::string fileName;

/// If this is not empty, then a set of collections are exported on the
/// prim pointed to by the path, each representing the collection of
Expand Down
5 changes: 4 additions & 1 deletion lib/usd/translators/shading/usdFileTextureWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,10 @@ void PxrUsdTranslators_FileTextureWriter::Write(const UsdTimeCode& usdTime)
// minimal interop. It will be replaced by proper use of Maya and
// USD asset resolvers. For package files, the exporter needs full
// paths.
const std::string& fileName = GetUsdStage()->GetRootLayer()->GetRealPath();

// We use the ExportArgs fileName here instead of the USD root layer path
// to make sure that we are basing logic of the final export location
const std::string& fileName = _GetExportArgs().fileName;
TfToken fileExt(TfGetExtension(fileName));
if (fileExt != UsdMayaTranslatorTokens->UsdFileExtensionPackage) {
boost::filesystem::path usdDir(fileName);
Expand Down
1 change: 1 addition & 0 deletions plugin/pxr/maya/lib/usdMaya/exportTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ MStatus UsdMayaExportTranslator::writer(
double frameStride = 1.0;
bool append = false;

userArgs["fileName"] = fileName;
MStringArray filteredTypes;
// Get the options
if (optionsString.length() > 0) {
Expand Down
1 change: 1 addition & 0 deletions test/lib/usd/translators/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ set(TEST_SCRIPT_FILES
testUsdExportNurbsCurve.py
testUsdExportOpenLayer.py
testUsdExportOverImport.py
testUsdExportPackage.py
testUsdExportParentScope.py
# To investigate: following test asserts in MFnParticleSystem, but passes.
# PPT, 17-Jun-20.
Expand Down
Loading

0 comments on commit ee4df76

Please sign in to comment.