-
Notifications
You must be signed in to change notification settings - Fork 203
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
kxl-adsk
merged 3 commits into
dev
from
t_gamaj/MAYA-105735/fix_empty_map1_on_mesh_import
Jul 28, 2020
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,9 @@ TF_DEFINE_PUBLIC_TOKENS(UsdMayaMeshColorSetTokens, | |
TF_DEFINE_PRIVATE_TOKENS( | ||
_meshTokens, | ||
|
||
// Default UV set name in Maya | ||
(map1) | ||
|
||
// we capitalize this because it doesn't correspond to an actual attribute | ||
(USD_EmitNormals) | ||
|
||
|
@@ -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(); | ||
|
||
|
@@ -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", | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We've been slowly yanking out usages of 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(); | ||
|
@@ -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(), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:maya-usd/lib/mayaUsd/fileio/utils/meshWriteUtils.cpp
Line 838 in e504341