Skip to content
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

Merged
merged 9 commits into from
Aug 9, 2023

Conversation

pierrebai-adsk
Copy link
Collaborator

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.

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.
@pierrebai-adsk pierrebai-adsk added adsk Related to Autodesk plugin import-export Related to Import and/or Export labels Aug 3, 2023
return val.UncheckedGet<SdfAssetPath>();
}

static bool handleMissingResolvedPath(SdfAssetPath* resolvedAssetPath)
Copy link
Collaborator Author

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.

lib/mayaUsd/utils/utilFileSystem.cpp Outdated Show resolved Hide resolved
lib/usd/translators/shading/shadingAsset.cpp Outdated Show resolved Hide resolved
}
}
if (!ResolveTextureAssetPath(prim, shaderSchema, depFn, _GetArgs().GetJobArguments())) {
return false;
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

lib/usd/translators/shading/shadingAsset.cpp Show resolved Hide resolved
}
}
if (!ResolveTextureAssetPath(prim, shaderSchema, depFn, _GetArgs().GetJobArguments())) {
return false;
Copy link
Collaborator

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.

Copy link
Collaborator Author

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')
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

@pierrebai-adsk pierrebai-adsk removed the request for review from samuelliu-adsk August 4, 2023 15:51
- 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);
Copy link
Collaborator

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

Copy link
Collaborator Author

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see

@pierrebai-adsk pierrebai-adsk added the ready-for-merge Development process is finished, PR is ready for merge label Aug 4, 2023
@samuelliu-adsk
Copy link
Collaborator

LGTM

samuelliu-adsk
samuelliu-adsk previously approved these changes Aug 4, 2023
- Add a drop-down to select the relative textures mode in the import and edit-as-Maya dialogs.
- Make sure the mode is remembered.
Comment on lines 177 to 181
std::string UsdMayaUtilFileSystem::getProjectPath()
{
MString projectPath = MGlobal::executeCommandStringResult("workspace -q -rd");
return projectPath.asChar();
}
Copy link
Collaborator

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()

Copy link
Collaborator

@seando-adsk seando-adsk left a 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?

Copy link
Collaborator

@seando-adsk seando-adsk left a 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.

Comment on lines 182 to 184
// 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())
Copy link
Collaborator

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().

Copy link
Collaborator

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..

Comment on lines 208 to 209
const MString projectPath = UsdMayaUtil::GetCurrentMayaWorkspacePath();
if (projectPath.isEmpty())
Copy link
Collaborator

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.

Suggested change
const MString projectPath = UsdMayaUtil::GetCurrentMayaWorkspacePath();
if (projectPath.isEmpty())
const std::string projectPath(UsdMayaUtil::GetCurrentMayaWorkspacePath().asChar());
if (projectPath.empty())

@seando-adsk seando-adsk removed the ready-for-merge Development process is finished, PR is ready for merge label Aug 8, 2023
@@ -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.
Copy link
Collaborator

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.

seando-adsk
seando-adsk previously approved these changes Aug 8, 2023
@seando-adsk seando-adsk added the ready-for-merge Development process is finished, PR is ready for merge label Aug 9, 2023
…xtures-ui

EMSUSD-280 import relative texture UI
@seando-adsk seando-adsk removed the ready-for-merge Development process is finished, PR is ready for merge label Aug 9, 2023
@samuelliu-adsk samuelliu-adsk added the ready-for-merge Development process is finished, PR is ready for merge label Aug 9, 2023
@seando-adsk seando-adsk merged commit 89c5e0b into dev Aug 9, 2023
12 checks passed
@seando-adsk seando-adsk deleted the bailp/EMSUSD-280/import-relative-textures branch August 9, 2023 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adsk Related to Autodesk plugin import-export Related to Import and/or Export ready-for-merge Development process is finished, PR is ready for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants