Skip to content

Commit

Permalink
Merge pull request #3071 from Autodesk/samuelliu-adsk/MAYA-128594/dis…
Browse files Browse the repository at this point in the history
…play-opacity-export

MAYA-128594 - Imported displayOpacity are not interpreted correctly
  • Loading branch information
seando-adsk authored May 15, 2023
2 parents 0916bdb + bcb480e commit f1ab078
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions lib/usd/translators/meshWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,8 @@ bool PxrUsdTranslators_MeshWriter::writeMeshAttrs(
VtArray<float> shadersAlphaData;
TfToken shadersInterpolation;
VtArray<int> shadersAssignmentIndices;
// check if its safe to export display opacity
bool exportDisplayOpacity = false;

// If we're exporting displayColor or we have color sets, gather colors and
// opacities from the shaders assigned to the mesh and/or its faces.
Expand Down Expand Up @@ -685,14 +687,18 @@ bool PxrUsdTranslators_MeshWriter::writeMeshAttrs(
}

if (colorSetName == UsdMayaMeshPrimvarTokens->DisplayOpacityColorSetName.GetString()) {
TF_WARN(
"Mesh \"%s\" has a color set named \"%s\", "
"which is a reserved Primvar name in USD. Skipping...",
finalMesh.fullPathName().asChar(),
UsdMayaMeshPrimvarTokens->DisplayOpacityColorSetName.GetText());
continue;
// We only export opacity when we are exporting display color
// and the color is float3
// if its float4 it will split to color and alpha
if (!exportDisplayOpacity) {
TF_WARN(
"Mesh \"%s\" has a color set named \"%s\", "
"which is a reserved Primvar name in USD. Skipping...",
finalMesh.fullPathName().asChar(),
UsdMayaMeshPrimvarTokens->DisplayOpacityColorSetName.GetText());
continue;
}
}

VtArray<GfVec3f> RGBData;
VtArray<float> AlphaData;
TfToken interpolation;
Expand Down Expand Up @@ -735,6 +741,12 @@ bool PxrUsdTranslators_MeshWriter::writeMeshAttrs(
clamped,
true,
_GetSparseValueWriter());

// We can only export display opacity separately if display color doesn't contain alpha
// data
if (colorSetRep == MFnMesh::kRGB) {
exportDisplayOpacity = true;
}
} else {
const std::string sanitizedName = UsdMayaUtil::SanitizeColorSetName(colorSetName);
// if our sanitized name is different than our current one and the
Expand Down

0 comments on commit f1ab078

Please sign in to comment.