-
Notifications
You must be signed in to change notification settings - Fork 201
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
EMSUSD-280 import relative textures #3259
Changes from 3 commits
5f82786
0ea58bf
bb8a664
c7f1144
90150d3
985674a
2d0fd50
7527584
1046343
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -179,9 +179,9 @@ std::string UsdMayaUtilFileSystem::getPathRelativeToProject(const std::string& f | |||||||||
if (fileName.empty()) | ||||||||||
return {}; | ||||||||||
|
||||||||||
MString projectPath = MGlobal::executeCommandStringResult("workspace -q -rd"); | ||||||||||
// Note: don't use isEmpty() because it is not available in Maya 2022 and earlier. | ||||||||||
if (projectPath.length() == 0) | ||||||||||
const MString projectPath = UsdMayaUtil::GetCurrentMayaWorkspacePath(); | ||||||||||
if (projectPath.isEmpty()) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment right above says you cannot use MString::isEmpty(). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh my bad. I missed that comment.. |
||||||||||
return {}; | ||||||||||
|
||||||||||
// Note: we do *not* use filesystem function to attempt to make the | ||||||||||
|
@@ -191,7 +191,7 @@ std::string UsdMayaUtilFileSystem::getPathRelativeToProject(const std::string& f | |||||||||
// preserve paths entered manually with relative folder ("..") | ||||||||||
// by keping an absolute path with ".." embedded in them, | ||||||||||
// so this works even in this situation. | ||||||||||
const auto pos = fileName.find(projectPath.asChar()); | ||||||||||
const auto pos = fileName.rfind(projectPath.asChar(), 0); | ||||||||||
if (pos != 0) | ||||||||||
return {}; | ||||||||||
|
||||||||||
|
@@ -203,6 +203,24 @@ std::string UsdMayaUtilFileSystem::getPathRelativeToProject(const std::string& f | |||||||||
return relativePathAndSuccess.first; | ||||||||||
} | ||||||||||
|
||||||||||
std::string UsdMayaUtilFileSystem::makeProjectRelatedPath(const std::string& fileName) | ||||||||||
{ | ||||||||||
const MString projectPath = UsdMayaUtil::GetCurrentMayaWorkspacePath(); | ||||||||||
if (projectPath.isEmpty()) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, no isEmpty here. Since you need it as a char for both cases below I would just convert it to std::string here.
Suggested change
|
||||||||||
return {}; | ||||||||||
|
||||||||||
// Attempt to create a relative path relative to the project folder. | ||||||||||
// If that fails, we cannot create the project-relative path. | ||||||||||
const auto pathAndSuccess | ||||||||||
= UsdMayaUtilFileSystem::makePathRelativeTo(fileName, projectPath.asChar()); | ||||||||||
if (!pathAndSuccess.second) | ||||||||||
return {}; | ||||||||||
|
||||||||||
// Make the path absolute but relative to the project folder. That is an absolute | ||||||||||
// path that starts with the project path. | ||||||||||
return UsdMayaUtilFileSystem::appendPaths(projectPath.asChar(), pathAndSuccess.first); | ||||||||||
} | ||||||||||
|
||||||||||
std::string UsdMayaUtilFileSystem::getPathRelativeToDirectory( | ||||||||||
const std::string& fileName, | ||||||||||
const std::string& relativeToDir) | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
// limitations under the License. | ||
// | ||
#include "mtlxBaseReader.h" | ||
#include "shadingAsset.h" | ||
#include "shadingTokens.h" | ||
|
||
#include <mayaUsd/fileio/shaderReader.h> | ||
|
@@ -118,34 +119,8 @@ bool MtlxUsd_ImageReader::Read(UsdMayaPrimReaderContext& context) | |
} | ||
|
||
// File | ||
VtValue val; | ||
MPlug mayaAttr = depFn.findPlug(TrMayaTokens->fileTextureName.GetText(), true, &status); | ||
|
||
UsdShadeInput usdInput = shaderSchema.GetInput(TrMtlxTokens->file); | ||
if (status == MS::kSuccess && usdInput && usdInput.Get(&val) && val.IsHolding<SdfAssetPath>()) { | ||
std::string filePath = val.UncheckedGet<SdfAssetPath>().GetResolvedPath(); | ||
if (!filePath.empty() && !ArIsPackageRelativePath(filePath)) { | ||
// Maya has issues with relative paths, especially if deep inside a | ||
// nesting of referenced assets. Use absolute path instead if USD was | ||
// able to resolve. A better fix will require providing an asset | ||
// resolver to Maya that can resolve the file correctly using the | ||
// MPxFileResolver API. We also make sure the path is not expressed | ||
// as a relationship like texture paths inside USDZ assets. | ||
val = SdfAssetPath(filePath); | ||
} | ||
|
||
// NOTE: Will need UDIM support and potentially USDZ support. When that happens, consider | ||
// refactoring existing code from usdUVTextureReader.cpp as shared utilities. | ||
UsdMayaReadUtil::SetMayaAttr(mayaAttr, val); | ||
|
||
// colorSpace: | ||
if (usdInput.GetAttr().HasColorSpace()) { | ||
MString colorSpace = usdInput.GetAttr().GetColorSpace().GetText(); | ||
mayaAttr = depFn.findPlug(TrMayaTokens->colorSpace.GetText(), true, &status); | ||
if (status == MS::kSuccess) { | ||
mayaAttr.setString(colorSpace); | ||
} | ||
} | ||
if (!ResolveTextureAssetPath(prim, shaderSchema, depFn, _GetArgs().GetJobArguments())) { | ||
return false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That error is not fatal. Please continue loading the other USD attributes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IDK what is best here and the other place that uses that function. I'll do what you suggest, we can revisit the best practice in the future. Note that in the original usdUVTextureReader, many error were considered fatal, so I'm just keeping the existing behavior. |
||
} | ||
|
||
// Default color | ||
|
@@ -158,8 +133,9 @@ bool MtlxUsd_ImageReader::Read(UsdMayaPrimReaderContext& context) | |
} | ||
|
||
// Filter type: | ||
mayaAttr = depFn.findPlug(TrMayaTokens->filterType.GetText(), true, &status); | ||
usdInput = shaderSchema.GetInput(TrMtlxTokens->filtertype); | ||
MPlug mayaAttr = depFn.findPlug(TrMayaTokens->filterType.GetText(), true, &status); | ||
UsdShadeInput usdInput = shaderSchema.GetInput(TrMtlxTokens->filtertype); | ||
VtValue val; | ||
if (status == MS::kSuccess && usdInput && usdInput.Get(&val) && val.IsHolding<std::string>()) { | ||
std::string filterType = val.UncheckedGet<std::string>(); | ||
if (filterType == TrMtlxTokens->closest.GetString()) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would have been nice if you removed this comment as its not relevant anymore since we are using std::string instead of MString.