-
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
Conversation
Refactor out the texture resolution code into a common reusable function: - Add a file system function to make a path absolute but relative to the project folder. - Add code to make the texture path relative to the project. - Use the common texture import code for materialX. - Split the texture handling into multiple helper functions to make each one clearer. - Warn if a USDZ archive is imported without the required corresponding flag to extract textures. - Properly detect absolute or relative path in automatic mode. Add import command flag: - Add the "importRelativeTextures" flag to the mayaUSDImport command. - Added a "none" relative textures mode for backward compatibility that leave all file names alone. - Made it the default for the command. - Add handling of the flag. - Add a "importRelativeTextures" option to the import job arguments class. - Add handling and validation of the option. - Wrap the option for Python. - Update the import command documentation. - Use the job args option in the import code. Add some unit tests.
return val.UncheckedGet<SdfAssetPath>(); | ||
} | ||
|
||
static bool handleMissingResolvedPath(SdfAssetPath* resolvedAssetPath) |
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.
This all code taken from usdUVTextureReader,cpp and refactored into multiple functions. You would need to diff with that file by hand to see what changed.
} | ||
} | ||
if (!ResolveTextureAssetPath(prim, shaderSchema, depFn, _GetArgs().GetJobArguments())) { | ||
return false; |
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.
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 comment
The 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.
} | ||
} | ||
if (!ResolveTextureAssetPath(prim, shaderSchema, depFn, _GetArgs().GetJobArguments())) { | ||
return false; |
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.
Non fatal, please continue with the import.
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.
The previous code had fatal error, this merely keep the old behavior.
""" | ||
Tests that the textures file paths mode is automatically detected. | ||
""" | ||
self.runImportRelativeTexturesTest('automatic') |
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.
Test an error case where paths can not be resolved?
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.
There are no new failure mode, the only existing failures are failing to extract from a USDZ archive, which I guess can only happen when the archive is corrupted or the disk is full. This makes it hard to test.
- Use rfind instead of find. - Make handleMissingResolvedPath() always succeeed. - Document that there are no current failure mode for relative path resolution.
if (pos != 0) | ||
return {}; | ||
|
||
auto relativePathAndSuccess = makePathRelativeTo(fileName, projectPath.asChar()); | ||
auto relativePathAndSuccess = makePathRelativeTo(fileName, projectPath); |
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.
Can we use the makeProjectRelatedPath
method? Seems like makeProjectRelatedPath
handles all the checkings and returns the related path
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.
No because this function wants to make a true relative path, but makeProjectRelativePath makes an absolute path, but relative to the absolute path of the project.
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.
Oh I see
LGTM |
- Add a drop-down to select the relative textures mode in the import and edit-as-Maya dialogs. - Make sure the mode is remembered.
lib/mayaUsd/utils/utilFileSystem.cpp
Outdated
std::string UsdMayaUtilFileSystem::getProjectPath() | ||
{ | ||
MString projectPath = MGlobal::executeCommandStringResult("workspace -q -rd"); | ||
return projectPath.asChar(); | ||
} |
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.
This function already exists as UsdMayaUtil::GetCurrentMayaWorkspacePath()
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.
Pierre added a new helper function that is identical (except return value std::string vs MString) to an existing helper. For code maintenance I don't think we should have two helper functions that do the same thing.
@samuelliu-adsk Since PierreB is on vacation can you checkout his branch and make the fix?
…urrentMayaWorkspacePath
c7f1144
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.
Thanks for the changes, but needs a couple of extra fixes.
lib/mayaUsd/utils/utilFileSystem.cpp
Outdated
// 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Oh my bad. I missed that comment..
lib/mayaUsd/utils/utilFileSystem.cpp
Outdated
const MString projectPath = UsdMayaUtil::GetCurrentMayaWorkspacePath(); | ||
if (projectPath.isEmpty()) |
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.
Again, no isEmpty here. Since you need it as a char for both cases below I would just convert it to std::string here.
const MString projectPath = UsdMayaUtil::GetCurrentMayaWorkspacePath(); | |
if (projectPath.isEmpty()) | |
const std::string projectPath(UsdMayaUtil::GetCurrentMayaWorkspacePath().asChar()); | |
if (projectPath.empty()) |
lib/mayaUsd/utils/utilFileSystem.cpp
Outdated
@@ -180,8 +180,8 @@ std::string UsdMayaUtilFileSystem::getPathRelativeToProject(const std::string& f | |||
return {}; | |||
|
|||
// Note: don't use isEmpty() because it is not available in Maya 2022 and earlier. |
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.
Remove extra "<b/>" tag on annotation.
…xtures-ui EMSUSD-280 import relative texture UI
Refactor out the texture resolution code into a common reusable function:
Add import command flag:
Add some unit tests.