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

Uvset names not written #1188

Merged
merged 3 commits into from
Feb 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions lib/mayaUsd/fileio/shading/shadingModeExporterContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <pxr/usd/usdShade/shader.h>
#include <pxr/usd/usdUtils/pipeline.h>

#include <maya/MCommandResult.h>
#include <maya/MDGContext.h>
#include <maya/MDagPath.h>
#include <maya/MDagPathArray.h>
Expand Down Expand Up @@ -479,8 +480,39 @@ class _UVMappingManager
}
MString getAttrCmd;
getAttrCmd.format("getAttr \"^1s\";", uvSetRef.c_str());
TfToken getAttrResult(MGlobal::executeCommandStringResult(getAttrCmd).asChar());

MCommandResult mayaCmdResult;
TfToken getAttrResult;
MGlobal::executeCommand(getAttrCmd, mayaCmdResult, false, false);
// NOTE: (yliangsiew) We do this because if you have a mesh shape in Maya named the
// same as its parent transform, you get back the result `map1 map1` instead of just
// `map1`. Why? Refer to the issue here:
// https://github.com/Autodesk/maya-usd/issues/1079
switch (mayaCmdResult.resultType()) {
case MCommandResult::kStringArray: {
MStringArray cmdResult;
mayaCmdResult.getResult(cmdResult);
if (cmdResult.length() == 0) {
TF_RUNTIME_ERROR(
"No valid UV set names could be determined! The command run was: %s",
getAttrCmd.asChar());
continue;
}
getAttrResult = TfToken(cmdResult[0].asChar());
break;
}
case MCommandResult::kString: {
MString cmdResult;
mayaCmdResult.getResult(cmdResult);
getAttrResult = TfToken(cmdResult.asChar());
break;
}
default:
TF_RUNTIME_ERROR(
"The UV set name could not be determined; the result was of an "
"unrecognized type! The command run was: %s",
getAttrCmd.asChar());
continue;
}
// Check if map1 should export as st:
if (getAttrResult == _tokens->map1 && UsdMayaWriteUtil::WriteMap1AsST()) {
getAttrResult = UsdUtilsGetPrimaryUVSetName();
Expand Down