Skip to content

Commit

Permalink
Merge pull request #1028 from dgovil/resolve_final_filename_issue972
Browse files Browse the repository at this point in the history
Fix texture writer path resolver to work relative to final export path
  • Loading branch information
Krystian Ligenza authored Jan 6, 2021
2 parents 4ab1eb7 + ab1aece commit d379bfc
Show file tree
Hide file tree
Showing 7 changed files with 396 additions and 15 deletions.
20 changes: 20 additions & 0 deletions lib/mayaUsd/fileio/jobs/jobArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <pxr/usdImaging/usdImaging/tokens.h>

#include <maya/MDagPath.h>
#include <maya/MFileObject.h>
#include <maya/MGlobal.h>
#include <maya/MNodeClass.h>
#include <maya/MTypeId.h>
Expand Down Expand Up @@ -321,6 +322,7 @@ UsdMayaJobExportArgs::UsdMayaJobExportArgs(
UsdMayaJobExportArgsTokens->none,
{ UsdMayaJobExportArgsTokens->auto_, UsdMayaJobExportArgsTokens->explicit_ }))
, exportVisibility(_Boolean(userArgs, UsdMayaJobExportArgsTokens->exportVisibility))
, file(_String(userArgs, UsdMayaJobExportArgsTokens->file))
, materialCollectionsPath(
_AbsolutePath(userArgs, UsdMayaJobExportArgsTokens->materialCollectionsPath))
, materialsScopeName(
Expand Down Expand Up @@ -387,6 +389,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
<< "file: " << exportArgs.file << std::endl
<< "materialCollectionsPath: " << exportArgs.materialCollectionsPath << std::endl
<< "materialsScopeName: " << exportArgs.materialsScopeName << std::endl
<< "mergeTransformAndShape: " << TfStringify(exportArgs.mergeTransformAndShape) << std::endl
Expand Down Expand Up @@ -470,6 +473,7 @@ const VtDictionary& UsdMayaJobExportArgs::GetDefaultDictionary()
d[UsdMayaJobExportArgsTokens->exportSkels] = UsdMayaJobExportArgsTokens->none.GetString();
d[UsdMayaJobExportArgsTokens->exportUVs] = true;
d[UsdMayaJobExportArgsTokens->exportVisibility] = true;
d[UsdMayaJobExportArgsTokens->file] = std::string();
d[UsdMayaJobExportArgsTokens->kind] = std::string();
d[UsdMayaJobExportArgsTokens->materialCollectionsPath] = std::string();
d[UsdMayaJobExportArgsTokens->materialsScopeName]
Expand Down Expand Up @@ -541,6 +545,22 @@ void UsdMayaJobExportArgs::AddFilteredTypeName(const MString& typeName)
}
}

std::string UsdMayaJobExportArgs::GetResolvedFileName() const
{
MFileObject fileObj;
fileObj.setRawFullName(file.c_str());

// Make sure it's an absolute path
fileObj.setRawFullName(fileObj.resolvedFullName());
const std::string resolvedFileName = fileObj.resolvedFullName().asChar();

if (!resolvedFileName.empty()) {
return resolvedFileName;
}

return file;
}

UsdMayaJobImportArgs::UsdMayaJobImportArgs(
const VtDictionary& userArgs,
const bool importWithProxyShapes,
Expand Down
32 changes: 19 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) \
(file) \
(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 file;

/// 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 Expand Up @@ -223,6 +225,10 @@ struct UsdMayaJobExportArgs
MAYAUSD_CORE_PUBLIC
void AddFilteredTypeName(const MString& typeName);

/// Returns the resolved file name of the final export location
MAYAUSD_CORE_PUBLIC
std::string GetResolvedFileName() const;

const std::set<unsigned int>& GetFilteredTypeIds() const { return _filteredTypeIds; }

void ClearFilteredTypeIds() { _filteredTypeIds.clear(); }
Expand Down
7 changes: 5 additions & 2 deletions lib/usd/translators/shading/usdFileTextureWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,11 @@ 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();
TfToken fileExt(TfGetExtension(fileName));

// 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().GetResolvedFileName();
TfToken fileExt(TfGetExtension(fileName));
if (fileExt != UsdMayaTranslatorTokens->UsdFileExtensionPackage) {
boost::filesystem::path usdDir(fileName);
usdDir = usdDir.parent_path();
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 d379bfc

Please sign in to comment.