Skip to content

Commit

Permalink
Merge pull request #1188 from dgovil/uvset-names-not-written
Browse files Browse the repository at this point in the history
Uvset names not written
  • Loading branch information
Krystian Ligenza authored Feb 24, 2021
2 parents 38aff08 + 0c06d85 commit 8ae436e
Showing 1 changed file with 34 additions and 2 deletions.
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

0 comments on commit 8ae436e

Please sign in to comment.