@@ -184,8 +184,11 @@ public static string GetVersionFromReadme()
184
184
/// <summary>
185
185
/// Export the mesh's attributes using layer 0.
186
186
/// </summary>
187
- void ExportComponentAttributes ( MeshInfo mesh , FbxMesh fbxMesh , int [ ] unmergedTriangles )
187
+ private bool ExportComponentAttributes ( MeshInfo mesh , FbxMesh fbxMesh , int [ ] unmergedTriangles )
188
188
{
189
+ // return true if any attribute was exported
190
+ bool exportedAttribute = false ;
191
+
189
192
// Set the normals on Layer 0.
190
193
FbxLayer fbxLayer = GetOrCreateLayer ( fbxMesh ) ;
191
194
@@ -202,6 +205,7 @@ void ExportComponentAttributes (MeshInfo mesh, FbxMesh fbxMesh, int[] unmergedTr
202
205
}
203
206
204
207
fbxLayer . SetNormals ( fbxLayerElement ) ;
208
+ exportedAttribute = true ;
205
209
}
206
210
207
211
/// Set the binormals on Layer 0.
@@ -218,6 +222,7 @@ void ExportComponentAttributes (MeshInfo mesh, FbxMesh fbxMesh, int[] unmergedTr
218
222
fbxElementArray . Add ( ConvertNormalToRightHanded ( mesh . Binormals [ unityTriangle ] ) ) ;
219
223
}
220
224
fbxLayer . SetBinormals ( fbxLayerElement ) ;
225
+ exportedAttribute = true ;
221
226
}
222
227
223
228
/// Set the tangents on Layer 0.
@@ -239,9 +244,10 @@ void ExportComponentAttributes (MeshInfo mesh, FbxMesh fbxMesh, int[] unmergedTr
239
244
) ) ) ;
240
245
}
241
246
fbxLayer . SetTangents ( fbxLayerElement ) ;
247
+ exportedAttribute = true ;
242
248
}
243
249
244
- ExportUVs ( fbxMesh , mesh , unmergedTriangles ) ;
250
+ exportedAttribute = exportedAttribute || ExportUVs ( fbxMesh , mesh , unmergedTriangles ) ;
245
251
246
252
using ( var fbxLayerElement = FbxLayerElementVertexColor . Create ( fbxMesh , "VertexColors" ) )
247
253
{
@@ -271,7 +277,9 @@ void ExportComponentAttributes (MeshInfo mesh, FbxMesh fbxMesh, int[] unmergedTr
271
277
fbxIndexArray . SetAt ( i , unmergedTriangles [ i ] ) ;
272
278
}
273
279
fbxLayer . SetVertexColors ( fbxLayerElement ) ;
280
+ exportedAttribute = true ;
274
281
}
282
+ return exportedAttribute ;
275
283
}
276
284
277
285
/// <summary>
@@ -280,7 +288,7 @@ void ExportComponentAttributes (MeshInfo mesh, FbxMesh fbxMesh, int[] unmergedTr
280
288
/// <param name="fbxMesh">Fbx mesh.</param>
281
289
/// <param name="mesh">Mesh.</param>
282
290
/// <param name="unmergedTriangles">Unmerged triangles.</param>
283
- static void ExportUVs ( FbxMesh fbxMesh , MeshInfo mesh , int [ ] unmergedTriangles )
291
+ private static bool ExportUVs ( FbxMesh fbxMesh , MeshInfo mesh , int [ ] unmergedTriangles )
284
292
{
285
293
Vector2 [ ] [ ] uvs = new Vector2 [ ] [ ] {
286
294
mesh . UV ,
@@ -321,6 +329,9 @@ static void ExportUVs(FbxMesh fbxMesh, MeshInfo mesh, int[] unmergedTriangles)
321
329
}
322
330
k ++ ;
323
331
}
332
+
333
+ // if we incremented k, then at least on set of UV's were exported
334
+ return k > 0 ;
324
335
}
325
336
326
337
/// <summary>
@@ -366,26 +377,26 @@ public static FbxVector4 ConvertPositionToRightHanded(Vector3 leftHandedVector)
366
377
/// <param name="unityPropName">Unity property name, e.g. "_MainTex".</param>
367
378
/// <param name="fbxMaterial">Fbx material.</param>
368
379
/// <param name="fbxPropName">Fbx property name, e.g. <c>FbxSurfaceMaterial.sDiffuse</c>.</param>
369
- public void ExportTexture ( Material unityMaterial , string unityPropName ,
380
+ public bool ExportTexture ( Material unityMaterial , string unityPropName ,
370
381
FbxSurfaceMaterial fbxMaterial , string fbxPropName )
371
382
{
372
383
if ( ! unityMaterial ) {
373
- return ;
384
+ return false ;
374
385
}
375
386
376
387
// Get the texture on this property, if any.
377
388
if ( ! unityMaterial . HasProperty ( unityPropName ) ) {
378
- return ;
389
+ return false ;
379
390
}
380
391
var unityTexture = unityMaterial . GetTexture ( unityPropName ) ;
381
392
if ( ! unityTexture ) {
382
- return ;
393
+ return false ;
383
394
}
384
395
385
396
// Find its filename
386
397
var textureSourceFullPath = AssetDatabase . GetAssetPath ( unityTexture ) ;
387
398
if ( textureSourceFullPath == "" ) {
388
- return ;
399
+ return false ;
389
400
}
390
401
391
402
// get absolute filepath to texture
@@ -399,7 +410,7 @@ public void ExportTexture (Material unityMaterial, string unityPropName,
399
410
var fbxMaterialProperty = fbxMaterial . FindProperty ( fbxPropName ) ;
400
411
if ( fbxMaterialProperty == null || ! fbxMaterialProperty . IsValid ( ) ) {
401
412
Debug . Log ( "property not found" ) ;
402
- return ;
413
+ return false ;
403
414
}
404
415
405
416
// Find or create an fbx texture and link it up to the fbx material.
@@ -411,6 +422,8 @@ public void ExportTexture (Material unityMaterial, string unityPropName,
411
422
TextureMap . Add ( textureSourceFullPath , fbxTexture ) ;
412
423
}
413
424
TextureMap [ textureSourceFullPath ] . ConnectDstProperty ( fbxMaterialProperty ) ;
425
+
426
+ return true ;
414
427
}
415
428
416
429
/// <summary>
@@ -431,15 +444,16 @@ public FbxDouble3 GetMaterialColor (Material unityMaterial, string unityPropName
431
444
/// <summary>
432
445
/// Export (and map) a Unity PBS material to FBX classic material
433
446
/// </summary>
434
- public FbxSurfaceMaterial ExportMaterial ( Material unityMaterial , FbxScene fbxScene )
447
+ public bool ExportMaterial ( Material unityMaterial , FbxScene fbxScene , FbxNode fbxNode )
435
448
{
436
449
if ( ! unityMaterial ) {
437
450
unityMaterial = DefaultMaterial ;
438
451
}
439
452
440
453
var unityName = unityMaterial . name ;
441
454
if ( MaterialMap . ContainsKey ( unityName ) ) {
442
- return MaterialMap [ unityName ] ;
455
+ fbxNode . AddMaterial ( MaterialMap [ unityName ] ) ;
456
+ return true ;
443
457
}
444
458
445
459
var fbxName = ExportSettings . mayaCompatibleNames
@@ -482,7 +496,8 @@ public FbxSurfaceMaterial ExportMaterial (Material unityMaterial, FbxScene fbxSc
482
496
}
483
497
484
498
MaterialMap . Add ( unityName , fbxMaterial ) ;
485
- return fbxMaterial ;
499
+ fbxNode . AddMaterial ( fbxMaterial ) ;
500
+ return true ;
486
501
}
487
502
488
503
/// <summary>
@@ -558,10 +573,10 @@ private void AssignLayerElementMaterial(FbxMesh fbxMesh, Mesh mesh, int material
558
573
///
559
574
/// Use fbxNode.GetMesh() to access the exported mesh.
560
575
/// </summary>
561
- public void ExportMesh ( Mesh mesh , FbxNode fbxNode , Material [ ] materials = null )
576
+ public bool ExportMesh ( Mesh mesh , FbxNode fbxNode , Material [ ] materials = null )
562
577
{
563
578
var meshInfo = new MeshInfo ( mesh , materials ) ;
564
- ExportMesh ( meshInfo , fbxNode ) ;
579
+ return ExportMesh ( meshInfo , fbxNode ) ;
565
580
}
566
581
567
582
/// <summary>
@@ -649,8 +664,7 @@ bool ExportMesh (MeshInfo meshInfo, FbxNode fbxNode)
649
664
650
665
// Set up materials per submesh.
651
666
foreach ( var mat in meshInfo . Materials ) {
652
- var fbxMaterial = ExportMaterial ( mat , fbxScene ) ;
653
- fbxNode . AddMaterial ( fbxMaterial ) ;
667
+ ExportMaterial ( mat , fbxScene , fbxNode ) ;
654
668
}
655
669
AssignLayerElementMaterial ( fbxMesh , meshInfo . mesh , meshInfo . Materials . Length ) ;
656
670
@@ -687,7 +701,7 @@ public static FbxDouble3 ConvertQuaternionToXYZEuler(Quaternion q)
687
701
}
688
702
689
703
// get a fbxNode's global default position.
690
- protected void ExportTransform ( UnityEngine . Transform unityTransform , FbxNode fbxNode , Vector3 newCenter , TransformExportType exportType )
704
+ protected bool ExportTransform ( UnityEngine . Transform unityTransform , FbxNode fbxNode , Vector3 newCenter , TransformExportType exportType )
691
705
{
692
706
// Fbx rotation order is XYZ, but Unity rotation order is ZXY.
693
707
// This causes issues when converting euler to quaternion, causing the final
@@ -726,7 +740,7 @@ protected void ExportTransform (UnityEngine.Transform unityTransform, FbxNode fb
726
740
fbxNode . LclRotation . Set ( fbxRotate ) ;
727
741
fbxNode . LclScaling . Set ( fbxScale ) ;
728
742
729
- return ;
743
+ return true ;
730
744
}
731
745
732
746
/// <summary>
@@ -779,6 +793,7 @@ protected bool ExportCamera (GameObject unityGO, FbxScene fbxScene, FbxNode fbxN
779
793
780
794
float aspectRatio = unityCamera . aspect ;
781
795
796
+ #region Configure Film Camera from Game Camera
782
797
// Configure FilmBack settings: 35mm TV Projection (0.816 x 0.612)
783
798
float apertureHeightInInches = 0.612f ;
784
799
float apertureWidthInInches = aspectRatio * apertureHeightInInches ;
@@ -804,6 +819,7 @@ protected bool ExportCamera (GameObject unityGO, FbxScene fbxScene, FbxNode fbxN
804
819
805
820
// FarPlane
806
821
fbxCamera . SetFarPlane ( unityCamera . farClipPlane * UnitScaleFactor ) ;
822
+ #endregion
807
823
808
824
// Export backgroundColor as a custom property
809
825
// NOTE: export on fbxNode so that it will show up in Maya
@@ -839,7 +855,7 @@ protected void SetDefaultCamera (FbxScene fbxScene)
839
855
/// <summary>
840
856
/// Export Component's color property
841
857
/// </summary>
842
- FbxProperty ExportColorProperty ( FbxObject fbxObject , Color value , string name , string label )
858
+ bool ExportColorProperty ( FbxObject fbxObject , Color value , string name , string label )
843
859
{
844
860
// create a custom property for component value
845
861
var fbxProperty = FbxProperty . Create ( fbxObject , Globals . FbxColor4DT , name , label ) ;
@@ -855,13 +871,13 @@ FbxProperty ExportColorProperty (FbxObject fbxObject, Color value, string name,
855
871
fbxProperty . ModifyFlag ( FbxPropertyFlags . EFlags . eUserDefined , true ) ;
856
872
fbxProperty . ModifyFlag ( FbxPropertyFlags . EFlags . eAnimatable , true ) ;
857
873
858
- return fbxProperty ;
874
+ return true ;
859
875
}
860
876
861
877
/// <summary>
862
878
/// Export Component's int property
863
879
/// </summary>
864
- FbxProperty ExportIntProperty ( FbxObject fbxObject , int value , string name , string label )
880
+ bool ExportIntProperty ( FbxObject fbxObject , int value , string name , string label )
865
881
{
866
882
// create a custom property for component value
867
883
var fbxProperty = FbxProperty . Create ( fbxObject , Globals . FbxIntDT , name , label ) ;
@@ -874,7 +890,7 @@ FbxProperty ExportIntProperty (FbxObject fbxObject, int value, string name, stri
874
890
fbxProperty . ModifyFlag ( FbxPropertyFlags . EFlags . eUserDefined , true ) ;
875
891
fbxProperty . ModifyFlag ( FbxPropertyFlags . EFlags . eAnimatable , true ) ;
876
892
877
- return fbxProperty ;
893
+ return true ;
878
894
}
879
895
880
896
/// <summary>
0 commit comments