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

MAYA-105735 Clean up empty map1 texcoord #685

Merged
merged 3 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
44 changes: 39 additions & 5 deletions lib/mayaUsd/fileio/utils/meshReadUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ TF_DEFINE_PUBLIC_TOKENS(UsdMayaMeshColorSetTokens,
TF_DEFINE_PRIVATE_TOKENS(
_meshTokens,

// Default UV set name in Maya
(map1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be nice to have this token available publicly in a place that's accessible to both this file and meshWriteUtils.cpp so we can avoid hard-coding the string there also:

if (setName == "map1") {


// we capitalize this because it doesn't correspond to an actual attribute
(USD_EmitNormals)

Expand Down Expand Up @@ -181,7 +184,7 @@ namespace
}

bool
assignUVSetPrimvarToMesh(const UsdGeomPrimvar& primvar, MFnMesh& meshFn)
assignUVSetPrimvarToMesh(const UsdGeomPrimvar& primvar, MFnMesh& meshFn, bool hasDefaultUVSet)
{
const TfToken& primvarName = primvar.GetPrimvarName();

Expand Down Expand Up @@ -243,11 +246,24 @@ namespace

MStatus status{MS::kSuccess};
MString uvSetName(primvarName.GetText());
bool createUVSet = true;

if (primvarName == UsdUtilsGetPrimaryUVSetName()) {
// We assume that the primary USD UV set maps to Maya's default 'map1'
// set which always exists, so we shouldn't try to create it.
uvSetName = "map1";
} else {
uvSetName = _meshTokens->map1.GetText();
createUVSet = false;
} else if (!hasDefaultUVSet) {
// If map1 still exists, we rename and re-use it:
MStringArray uvSetNames;
meshFn.getUVSetNames(uvSetNames);
if (uvSetNames[0] == _meshTokens->map1.GetText()) {
meshFn.renameUVSet(_meshTokens->map1.GetText(), uvSetName);
createUVSet = false;
}
}

if (createUVSet) {
status = meshFn.createUVSet(uvSetName);
if (status != MS::kSuccess) {
TF_WARN("Unable to create UV set '%s' for mesh: %s",
Expand Down Expand Up @@ -608,7 +624,25 @@ UsdMayaMeshReadUtils::assignPrimvarsToMesh(const UsdGeomMesh& mesh,

// GETTING PRIMVARS
const std::vector<UsdGeomPrimvar> primvars = mesh.GetPrimvars();
TF_FOR_ALL(iter, primvars)

// Maya always has a map1 UV set. We need to find out if there is any stream in the file that
// will use that slot. If not, the first texcoord stream to load will replace the default map1
// stream.
bool hasDefaultUVSet = false;
TF_FOR_ALL(iter, primvars)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've been slowly yanking out usages of TF_FOR_ALL as we come across them, so these might be good ones to replace with regular range-based for loops:

for (const UsdGeomPrimvar& primvar : primvars) {

{
const UsdGeomPrimvar& primvar = *iter;
const SdfValueTypeName typeName = primvar.GetTypeName();
if (typeName == SdfValueTypeNames->TexCoord2fArray
|| (UsdMayaReadUtil::ReadFloat2AsUV() && typeName == SdfValueTypeNames->Float2Array)) {
const TfToken fullName = primvar.GetPrimvarName();
if (fullName == _meshTokens->map1 || fullName == UsdUtilsGetPrimaryUVSetName()) {
hasDefaultUVSet = true;
}
}
}

TF_FOR_ALL(iter, primvars)
{
const UsdGeomPrimvar& primvar = *iter;
const TfToken name = primvar.GetBaseName();
Expand Down Expand Up @@ -646,7 +680,7 @@ UsdMayaMeshReadUtils::assignPrimvarsToMesh(const UsdGeomMesh& mesh,
// Otherwise, if env variable for reading Float2
// as uv sets is turned on, we assume that Float2Array primvars
// are UV sets.
if (!assignUVSetPrimvarToMesh(primvar, meshFn)) {
if (!assignUVSetPrimvarToMesh(primvar, meshFn, hasDefaultUVSet)) {
TF_WARN("Unable to retrieve and assign data for UV set <%s> on "
"mesh <%s>",
name.GetText(),
Expand Down
3 changes: 3 additions & 0 deletions test/lib/usd/translators/testUsdImportUVSets.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ def testImportCompressibleUVSets(self):
"""
mayaCubeMesh = self._GetMayaMesh('CompressibleUVSetsCubeShape')

# We should not see the default "map1" UV set:
self.assertNotIn("map1", mayaCubeMesh.getUVSetNames())

# ALL face vertices should have the same value.
uvSetName = 'ConstantInterpSet'
expectedValues = {}
Expand Down