Skip to content

Commit

Permalink
Merge pull request #860 from Autodesk/t_gamaj/MAYA-106690/merge_subsets
Browse files Browse the repository at this point in the history
MAYA-106690 - Merge subsets connected to same material
  • Loading branch information
Krystian Ligenza authored Oct 22, 2020
2 parents 2e807dd + cd4d4d6 commit dc910a9
Show file tree
Hide file tree
Showing 4 changed files with 502 additions and 2 deletions.
31 changes: 29 additions & 2 deletions lib/mayaUsd/fileio/shading/shadingModeExporterContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,35 @@ UsdMayaShadingModeExportContext::MakeStandardMaterialPrim(
UsdShadeMaterialBindingAPI bindingAPI =
UsdMayaTranslatorUtil::GetAPISchemaForAuthoring<
UsdShadeMaterialBindingAPI>(boundPrim);
UsdGeomSubset faceSubset = bindingAPI.CreateMaterialBindSubset(
/* subsetName */ TfToken(materialName),

UsdGeomSubset faceSubset;
TfToken materialNameToken = TfToken(materialName);

// Try to re-use existing subset if any:
for (auto subset : bindingAPI.GetMaterialBindSubsets()) {
TfToken elementType;
if (subset.GetPrim().GetName() == materialNameToken
&& subset.GetElementTypeAttr().Get(&elementType)
&& elementType == UsdGeomTokens->face) {
faceSubset = subset;
break;
}
}

if (faceSubset) {
// Update and continue:
VtIntArray mergedIndices;
UsdAttribute indicesAttribute = faceSubset.GetIndicesAttr();
indicesAttribute.Get(&mergedIndices);
std::set<int> uniqueIndices(mergedIndices.cbegin(), mergedIndices.cend());
uniqueIndices.insert(faceIndices.cbegin(), faceIndices.cend());
mergedIndices.assign(uniqueIndices.cbegin(), uniqueIndices.cend());
indicesAttribute.Set(mergedIndices);
continue;
}

faceSubset = bindingAPI.CreateMaterialBindSubset(
/* subsetName */ materialNameToken,
faceIndices,
/* elementType */ UsdGeomTokens->face);

Expand Down
1 change: 1 addition & 0 deletions test/lib/usd/translators/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set(TEST_SCRIPT_FILES
testUsdExportFileFormat.py
testUsdExportFilterTypes.py
testUsdExportFrameOffset.py
testUsdExportGeomSubset.py
testUsdExportInstances.py
testUsdExportLocator.py
testUsdExportMayaInstancer.py
Expand Down
Loading

0 comments on commit dc910a9

Please sign in to comment.