@@ -174,7 +174,7 @@ void ExportComponentAttributes (MeshInfo mesh, FbxMesh fbxMesh, int[] unmergedTr
174
174
// Set the normals on Layer 0.
175
175
FbxLayer fbxLayer = GetOrCreateLayer ( fbxMesh ) ;
176
176
177
- if ( mesh . Normals != null && mesh . Normals . Length > 0 && mesh . Normals . Length == unmergedTriangles . Length ) {
177
+ if ( mesh . HasValidNormals ( unmergedTriangles . Length ) ) {
178
178
using ( var fbxLayerElement = FbxLayerElementNormal . Create ( fbxMesh , "Normals" ) ) {
179
179
fbxLayerElement . SetMappingMode ( FbxLayerElement . EMappingMode . eByPolygonVertex ) ;
180
180
fbxLayerElement . SetReferenceMode ( FbxLayerElement . EReferenceMode . eDirect ) ;
@@ -192,7 +192,7 @@ void ExportComponentAttributes (MeshInfo mesh, FbxMesh fbxMesh, int[] unmergedTr
192
192
}
193
193
194
194
/// Set the binormals on Layer 0.
195
- if ( mesh . Binormals != null && mesh . Binormals . Length > 0 && mesh . Binormals . Length == unmergedTriangles . Length ) {
195
+ if ( mesh . HasValidBinormals ( unmergedTriangles . Length ) ) {
196
196
using ( var fbxLayerElement = FbxLayerElementBinormal . Create ( fbxMesh , "Binormals" ) ) {
197
197
fbxLayerElement . SetMappingMode ( FbxLayerElement . EMappingMode . eByPolygonVertex ) ;
198
198
fbxLayerElement . SetReferenceMode ( FbxLayerElement . EReferenceMode . eDirect ) ;
@@ -209,7 +209,7 @@ void ExportComponentAttributes (MeshInfo mesh, FbxMesh fbxMesh, int[] unmergedTr
209
209
}
210
210
211
211
/// Set the tangents on Layer 0.
212
- if ( mesh . Tangents != null && mesh . Tangents . Length > 0 && mesh . Tangents . Length == unmergedTriangles . Length ) {
212
+ if ( mesh . HasValidTangents ( unmergedTriangles . Length ) ) {
213
213
using ( var fbxLayerElement = FbxLayerElementTangent . Create ( fbxMesh , "Tangents" ) ) {
214
214
fbxLayerElement . SetMappingMode ( FbxLayerElement . EMappingMode . eByPolygonVertex ) ;
215
215
fbxLayerElement . SetReferenceMode ( FbxLayerElement . EReferenceMode . eDirect ) ;
@@ -232,7 +232,7 @@ mesh.Tangents [unityTriangle] [2]
232
232
233
233
ExportUVs ( fbxMesh , mesh , unmergedTriangles ) ;
234
234
235
- if ( mesh . VertexColors != null && mesh . VertexColors . Length > 0 ) {
235
+ if ( mesh . HasValidVertexColors ( unmergedTriangles . Length ) ) {
236
236
using ( var fbxLayerElement = FbxLayerElementVertexColor . Create ( fbxMesh , "VertexColors" ) ) {
237
237
fbxLayerElement . SetMappingMode ( FbxLayerElement . EMappingMode . eByPolygonVertex ) ;
238
238
fbxLayerElement . SetReferenceMode ( FbxLayerElement . EReferenceMode . eIndexToDirect ) ;
@@ -1262,9 +1262,8 @@ public Vector3 [] Binormals {
1262
1262
var normals = Normals ;
1263
1263
var tangents = Tangents ;
1264
1264
1265
- if ( normals != null && normals . Length > 0 &&
1266
- tangents != null && tangents . Length > 0 &&
1267
- normals . Length == tangents . Length
1265
+ if ( IsValidArray < Vector3 > ( normals ) & &
1266
+ IsValidArray < Vector4 > ( tangents , normals . Length )
1268
1267
) {
1269
1268
m_Binormals = new Vector3 [ normals . Length ] ;
1270
1269
@@ -1345,6 +1344,36 @@ public MeshInfo (Mesh mesh, Material[] materials)
1345
1344
}
1346
1345
}
1347
1346
}
1347
+
1348
+ /// <summary>
1349
+ /// Determines whether this instance is a valid array with the specified length.
1350
+ /// </summary>
1351
+ /// <returns><c>true</c> if this instance is valid array; otherwise, <c>false</c>.</returns>
1352
+ /// <param name="array">Array.</param>
1353
+ /// <param name="expectedLength">Expected length.</param>
1354
+ /// <typeparam name="T">The 1st type parameter.</typeparam>
1355
+ public static bool IsValidArray < T > ( T [ ] array , int expectedLength = - 1 )
1356
+ {
1357
+ return array != null &&
1358
+ array . Length > 0 &&
1359
+ ( expectedLength >= 0 ? array . Length == expectedLength : true ) ;
1360
+ }
1361
+
1362
+ public bool HasValidNormals ( int expectedLength ) {
1363
+ return IsValidArray < Vector3 > ( Normals , expectedLength ) ;
1364
+ }
1365
+
1366
+ public bool HasValidBinormals ( int expectedLength ) {
1367
+ return IsValidArray < Vector3 > ( Binormals , expectedLength ) ;
1368
+ }
1369
+
1370
+ public bool HasValidTangents ( int expectedLength ) {
1371
+ return IsValidArray < Vector4 > ( Tangents , expectedLength ) ;
1372
+ }
1373
+
1374
+ public bool HasValidVertexColors ( int expectedLength ) {
1375
+ return IsValidArray < Color32 > ( VertexColors , expectedLength ) ;
1376
+ }
1348
1377
}
1349
1378
1350
1379
/// <summary>
0 commit comments