Skip to content

Commit

Permalink
MAYA-128503 - Error reporting rework
Browse files Browse the repository at this point in the history
  • Loading branch information
JGamache-autodesk committed Jun 5, 2023
1 parent 6a22de1 commit 9f83051
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 12 deletions.
27 changes: 22 additions & 5 deletions lib/mayaUsd/fileio/shading/shadingModeExporterContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,8 @@ class _UVMappingManager

switch (splitName.size()) {
case 3: _nodesWithUVInput.push_back(TfToken(splitName[1])); break;
default
: // NOTE: (yliangsiew) Means that we have a Maya node with a namespace/multiple
// namespaces.
default: // NOTE: (yliangsiew) Means that we have a Maya node with a namespace/multiple
// namespaces.
{
std::string mayaNodeName = splitName[1];
for (size_t i = 2; i < splitName.size() - 1; ++i) {
Expand Down Expand Up @@ -748,10 +747,28 @@ VtIntArray _AssignComponentTags(
const auto infoIt = subsetInfoDict.find(ssName);
if (infoIt != subsetInfoDict.cend()) {
// Check candidate:
if (!infoIt->second.IsObject()) {
TF_RUNTIME_ERROR(
"Invalid GeomSubset roundtrip info on node '%s': "
"info for subset '%s' is not a dictionary.",
UsdMayaUtil::GetMayaNodeName(geomHandle.object()).c_str(),
ssName.c_str());
continue;
}
const auto& geomSubsetInfo = infoIt->second.GetJsObject();
const auto uuidIt = geomSubsetInfo.find(UsdMayaGeomSubsetTokens->MaterialUuidKey);
if (uuidIt == geomSubsetInfo.cend()
|| uuidIt->second.GetString() != shadingGroupUUID) {
if (uuidIt == geomSubsetInfo.cend()) {
continue;
}
if (!uuidIt->second.IsString()) {
TF_RUNTIME_ERROR(
"Invalid GeomSubset roundtrip info on node '%s': "
"material info for subset '%s' is not a string.",
UsdMayaUtil::GetMayaNodeName(geomHandle.object()).c_str(),
ssName.c_str());
continue;
}
if (uuidIt->second.GetString() != shadingGroupUUID) {
continue;
}

Expand Down
22 changes: 19 additions & 3 deletions lib/mayaUsd/fileio/translators/translatorMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ _GetUVBindingsFromMaterial(const UsdShadeMaterial& material, UsdMayaPrimReaderCo
if (!val.IsHolding<TfToken>() && !val.IsHolding<std::string>()) {
continue;
}
SdfPath nodePath = isMergeable
? material.GetBaseMaterial().GetPath().AppendChild(TfToken(splitName[1]))
: material.GetPath().AppendChild(TfToken(splitName[1]));
SdfPath nodePath = isMergeable
? material.GetBaseMaterial().GetPath().AppendChild(TfToken(splitName[1]))
: material.GetPath().AppendChild(TfToken(splitName[1]));
MObject mayaNode = context->GetMayaNode(nodePath, false);
MStatus status;
MFnDependencyNode depFn(mayaNode, &status);
Expand Down Expand Up @@ -437,10 +437,26 @@ bool UsdMayaTranslatorMaterial::AssignMaterial(
JsObject updatedInfo;

for (auto&& ssInfoIt : meshRoundtrippingInfo) {
if (!ssInfoIt.second.IsObject()) {
TF_RUNTIME_ERROR(
"Invalid GeomSubset roundtrip info on node '%s': "
"info for subset '%s' is not a dictionary.",
UsdMayaUtil::GetMayaNodeName(shapeObj).c_str(),
ssInfoIt.first.c_str());
continue;
}
JsObject subsetRoundtrippingInfo = ssInfoIt.second.GetJsObject();
auto materialIt
= subsetRoundtrippingInfo.find(UsdMayaGeomSubsetTokens->MaterialPathKey);
if (materialIt != subsetRoundtrippingInfo.cend()) {
if (!materialIt->second.IsString()) {
TF_RUNTIME_ERROR(
"Invalid GeomSubset roundtrip info on node '%s': "
"material path for subset '%s' is not a string.",
UsdMayaUtil::GetMayaNodeName(shapeObj).c_str(),
ssInfoIt.first.c_str());
continue;
}
SdfPath materialPath(materialIt->second.GetString());
MObject materialObj = context->GetMayaNode(materialPath, false);
if (!materialObj.isNull()) {
Expand Down
16 changes: 16 additions & 0 deletions lib/mayaUsd/fileio/utils/meshReadUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -902,8 +902,24 @@ bool UsdMayaMeshReadUtils::getGeomSubsetInfo(const MObject& mesh, JsValue& meshR
JsParseError error;
JsValue value = JsParseString(plug.asString().asChar(), &error);
if (value) {
// That value must be a dictionary:
if (!value.IsObject()) {
TF_RUNTIME_ERROR(
"Invalid GeomSubset roundtrip info on node '%s': "
"does not parse to a dictionary.",
UsdMayaUtil::GetMayaNodeName(mesh).c_str());
return false;
}
meshRoundtripData = value;
return true;
} else {
TF_RUNTIME_ERROR(
"Failed to parse GeomSubset JSON roundtrip info on node '%s' "
"at line %d, column %d: %s",
UsdMayaUtil::GetMayaNodeName(mesh).c_str(),
error.line,
error.column,
error.reason.c_str());
}
}

Expand Down
24 changes: 20 additions & 4 deletions lib/mayaUsd/fileio/utils/meshWriteUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1442,10 +1442,26 @@ MStatus UsdMayaMeshWriteUtils::exportComponentTags(UsdGeomMesh& primSchema, MObj
TfToken familyName = UsdMayaGeomSubsetTokens->ComponentTagFamilyName;
const auto subsetIt = subsetInfoDict.find(keys[i].asChar());
if (subsetIt != subsetInfoDict.cend()) {
const auto& subsetInfo = subsetIt->second.GetJsObject();
const auto familyInfo = subsetInfo.find("familyName");
if (familyInfo != subsetInfo.cend()) {
familyName = TfToken(familyInfo->second.GetString());
if (subsetIt->second.IsObject()) {
const auto& subsetInfo = subsetIt->second.GetJsObject();
const auto familyInfo = subsetInfo.find("familyName");
if (familyInfo != subsetInfo.cend()) {
if (familyInfo->second.IsString()) {
familyName = TfToken(familyInfo->second.GetString());
} else {
TF_RUNTIME_ERROR(
"Invalid GeomSubset roundtrip info on node '%s': "
"familyName for subset '%s' is not a string.",
UsdMayaUtil::GetMayaNodeName(obj).c_str(),
keys[i].asChar());
}
}
} else {
TF_RUNTIME_ERROR(
"Invalid GeomSubset roundtrip info on node '%s': "
"info for subset '%s' is not a dictionary.",
UsdMayaUtil::GetMayaNodeName(obj).c_str(),
keys[i].asChar());
}
}
UsdGeomSubset ss = UsdGeomSubset::CreateGeomSubset(
Expand Down

0 comments on commit 9f83051

Please sign in to comment.