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

Add check for invalid tangent data in Maya #1132

Merged
Changes from all 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
50 changes: 35 additions & 15 deletions Maya/Exporter/BabylonExporter.Mesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal partial class BabylonExporter
private MStringArray allMayaInfluenceNames; // the joint names that influence the mesh (joint with 0 weight included)
private MDoubleArray allMayaInfluenceWeights; // the joint weights for the vertex (0 weight included)
private Dictionary<string, int> indexByNodeName = new Dictionary<string, int>(); // contains the node (joint and parents of the current skin) fullPathName and its index

/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -919,15 +919,25 @@ private GlobalVertex ExtractVertex(MFnMesh mFnMesh, int polygonId, int vertexInd
{
MVector tangent = new MVector();
mFnMesh.getFaceVertexTangent(polygonId, vertexIndexGlobal, tangent);

if (tangent.isEquivalent(MVector.zero))
{
isTangentExportSuccess = false;
RaiseWarning($"Mesh has invalid tangent data. Exporter will not export tangets for the mesh {mFnMesh?.name ?? "Unknown"}");
}
else
{
tangent.normalize();

// Switch coordinate system at object level
tangent.z *= -1;
// Switch coordinate system at object level
tangent.z *= -1;

int tangentId = mFnMesh.getTangentId(polygonId, vertexIndexGlobal);
bool isRightHandedTangent = mFnMesh.isRightHandedTangent(tangentId);
int tangentId = mFnMesh.getTangentId(polygonId, vertexIndexGlobal);
bool isRightHandedTangent = mFnMesh.isRightHandedTangent(tangentId);

// Invert W to switch to left handed system
vertex.Tangent = new float[] { (float)tangent.x, (float)tangent.y, (float)tangent.z, isRightHandedTangent ? -1 : 1 };
// Invert W to switch to left handed system
vertex.Tangent = new float[] { (float)tangent.x, (float)tangent.y, (float)tangent.z, isRightHandedTangent ? -1 : 1 };
}
}
catch
{
Expand Down Expand Up @@ -1342,14 +1352,24 @@ private IList<BabylonMorphTarget> GetMorphTargets(BabylonMesh babylonMesh, MFnMe
MVector tangent = new MVector();
targetMesh.getFaceVertexTangent(vertexData.polygonId, vertexData.vertexIndexGlobal, tangent);

// Switch coordinate system at object level
tangent.z *= -1;

int tangentId = targetMesh.getTangentId(vertexData.polygonId, vertexData.vertexIndexGlobal);
bool isRightHandedTangent = targetMesh.isRightHandedTangent(tangentId);

// Invert W to switch to left handed system
vertex.Tangent = new float[] { (float)tangent.x, (float)tangent.y, (float)tangent.z, isRightHandedTangent ? -1 : 1 };
if (tangent.isEquivalent(MVector.zero))
{
isTangentExportSuccess = false;
RaiseWarning($"Mesh has invalid tangent data. Exporter will not export tangets for the mesh {mesh?.name ?? "Unknown"}");
}
else
{
tangent.normalize();

// Switch coordinate system at object level
tangent.z *= -1;

int tangentId = targetMesh.getTangentId(vertexData.polygonId, vertexData.vertexIndexGlobal);
bool isRightHandedTangent = targetMesh.isRightHandedTangent(tangentId);

// Invert W to switch to left handed system
vertex.Tangent = new float[] { (float)tangent.x, (float)tangent.y, (float)tangent.z, isRightHandedTangent ? -1 : 1 };
}
}
catch
{
Expand Down