Skip to content

Commit efdc791

Browse files
committed
use vertex array length to check for valid normals
check for null and vertex array length, not triangle array length. Same for tangents and vertex colors. Binormals based on valid normals and tangents.
1 parent f7825d0 commit efdc791

File tree

1 file changed

+13
-29
lines changed

1 file changed

+13
-29
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ private bool ExportComponentAttributes (MeshInfo mesh, FbxMesh fbxMesh, int[] un
192192
// Set the normals on Layer 0.
193193
FbxLayer fbxLayer = GetOrCreateLayer(fbxMesh);
194194

195-
if (mesh.HasValidNormals(unmergedTriangles.Length)) {
195+
if (mesh.HasValidNormals()) {
196196
using (var fbxLayerElement = FbxLayerElementNormal.Create (fbxMesh, "Normals")) {
197197
fbxLayerElement.SetMappingMode (FbxLayerElement.EMappingMode.eByPolygonVertex);
198198
fbxLayerElement.SetReferenceMode (FbxLayerElement.EReferenceMode.eDirect);
@@ -211,7 +211,7 @@ private bool ExportComponentAttributes (MeshInfo mesh, FbxMesh fbxMesh, int[] un
211211
}
212212

213213
/// Set the binormals on Layer 0.
214-
if (mesh.HasValidBinormals(unmergedTriangles.Length)) {
214+
if (mesh.HasValidBinormals()) {
215215
using (var fbxLayerElement = FbxLayerElementBinormal.Create (fbxMesh, "Binormals")) {
216216
fbxLayerElement.SetMappingMode (FbxLayerElement.EMappingMode.eByPolygonVertex);
217217
fbxLayerElement.SetReferenceMode (FbxLayerElement.EReferenceMode.eDirect);
@@ -229,7 +229,7 @@ private bool ExportComponentAttributes (MeshInfo mesh, FbxMesh fbxMesh, int[] un
229229
}
230230

231231
/// Set the tangents on Layer 0.
232-
if (mesh.HasValidTangents(unmergedTriangles.Length)) {
232+
if (mesh.HasValidTangents()) {
233233
using (var fbxLayerElement = FbxLayerElementTangent.Create (fbxMesh, "Tangents")) {
234234
fbxLayerElement.SetMappingMode (FbxLayerElement.EMappingMode.eByPolygonVertex);
235235
fbxLayerElement.SetReferenceMode (FbxLayerElement.EReferenceMode.eDirect);
@@ -253,7 +253,7 @@ mesh.Tangents [unityTriangle] [2]
253253

254254
exportedAttribute |= ExportUVs (fbxMesh, mesh, unmergedTriangles);
255255

256-
if (mesh.HasValidVertexColors(unmergedTriangles.Length)) {
256+
if (mesh.HasValidVertexColors()) {
257257
using (var fbxLayerElement = FbxLayerElementVertexColor.Create (fbxMesh, "VertexColors")) {
258258
fbxLayerElement.SetMappingMode (FbxLayerElement.EMappingMode.eByPolygonVertex);
259259
fbxLayerElement.SetReferenceMode (FbxLayerElement.EReferenceMode.eIndexToDirect);
@@ -1430,9 +1430,7 @@ public Vector3 [] Binormals {
14301430
var normals = Normals;
14311431
var tangents = Tangents;
14321432

1433-
if (IsValidArray<Vector3>(normals) &&
1434-
IsValidArray<Vector4>(tangents, normals.Length)
1435-
) {
1433+
if (HasValidNormals() && HasValidTangents()) {
14361434
m_Binormals = new Vector3 [normals.Length];
14371435

14381436
for (int i = 0; i < normals.Length; i++)
@@ -1513,34 +1511,20 @@ public MeshInfo (Mesh mesh, Material[] materials)
15131511
}
15141512
}
15151513

1516-
/// <summary>
1517-
/// Determines whether this instance is a valid array with the specified length.
1518-
/// </summary>
1519-
/// <returns><c>true</c> if this instance is valid array; otherwise, <c>false</c>.</returns>
1520-
/// <param name="array">Array.</param>
1521-
/// <param name="expectedLength">Expected length.</param>
1522-
/// <typeparam name="T">The 1st type parameter.</typeparam>
1523-
public static bool IsValidArray<T>(T[] array, int expectedLength = -1)
1524-
{
1525-
return array != null &&
1526-
array.Length > 0 &&
1527-
(expectedLength >= 0 ? array.Length == expectedLength : true);
1528-
}
1529-
1530-
public bool HasValidNormals(int expectedLength){
1531-
return IsValidArray<Vector3> (Normals, expectedLength);
1514+
public bool HasValidNormals(){
1515+
return Normals != null && Normals.Length == Vertices.Length;
15321516
}
15331517

1534-
public bool HasValidBinormals(int expectedLength){
1535-
return IsValidArray<Vector3> (Binormals, expectedLength);
1518+
public bool HasValidBinormals(){
1519+
return HasValidNormals () && HasValidTangents () && Binormals != null;
15361520
}
15371521

1538-
public bool HasValidTangents(int expectedLength){
1539-
return IsValidArray<Vector4> (Tangents, expectedLength);
1522+
public bool HasValidTangents(){
1523+
return Tangents != null && Tangents.Length == Vertices.Length;
15401524
}
15411525

1542-
public bool HasValidVertexColors(int expectedLength){
1543-
return IsValidArray<Color32> (VertexColors, expectedLength);
1526+
public bool HasValidVertexColors(){
1527+
return VertexColors != null && VertexColors.Length == Vertices.Length;
15441528
}
15451529
}
15461530

0 commit comments

Comments
 (0)