@@ -507,14 +507,9 @@ private void CompareMeshComponentAttributes(Mesh mesh, Mesh fbxMesh)
507
507
Assert . AreEqual ( mesh . tangents , fbxMesh . tangents ) ;
508
508
}
509
509
510
- [ Test ]
511
- public void TestSkinnedMeshExport ( ) {
512
- // for now use this cowboy taken from the asset store as the test file
513
- // TODO: find a better/simpler test file
514
- var fbxPath = "FbxExporters/Editor/UnitTests/Models/Cowboy/cowboyMidPoly(riged).fbx" ;
515
-
510
+ private void ExportSkinnedMesh ( string fileToExport , out SkinnedMeshRenderer originalSkinnedMesh , out SkinnedMeshRenderer exportedSkinnedMesh ) {
516
511
// add fbx to scene
517
- GameObject originalFbxObj = AssetDatabase . LoadMainAssetAtPath ( "Assets/" + fbxPath ) as GameObject ;
512
+ GameObject originalFbxObj = AssetDatabase . LoadMainAssetAtPath ( "Assets/" + fileToExport ) as GameObject ;
518
513
Assert . IsNotNull ( originalFbxObj ) ;
519
514
GameObject originalGO = GameObject . Instantiate ( originalFbxObj ) ;
520
515
Assert . IsTrue ( originalGO ) ;
@@ -526,11 +521,36 @@ public void TestSkinnedMeshExport(){
526
521
GameObject fbxObj = AssetDatabase . LoadMainAssetAtPath ( filename ) as GameObject ;
527
522
Assert . IsTrue ( fbxObj ) ;
528
523
529
- var originalSkinnedMesh = originalGO . GetComponentInChildren < SkinnedMeshRenderer > ( ) ;
524
+ originalSkinnedMesh = originalGO . GetComponentInChildren < SkinnedMeshRenderer > ( ) ;
530
525
Assert . IsNotNull ( originalSkinnedMesh ) ;
531
526
532
- var exportedSkinnedMesh = fbxObj . GetComponentInChildren < SkinnedMeshRenderer > ( ) ;
527
+ exportedSkinnedMesh = fbxObj . GetComponentInChildren < SkinnedMeshRenderer > ( ) ;
533
528
Assert . IsNotNull ( exportedSkinnedMesh ) ;
529
+ }
530
+
531
+ public class SkinnedMeshTestDataClass
532
+ {
533
+ public static System . Collections . IEnumerable TestCases1 {
534
+ get {
535
+ // for now use this cowboy taken from the asset store as the test file
536
+ // TODO: find a better/simpler test file
537
+ yield return "Models/Cowboy/cowboyMidPoly(riged).fbx" ;
538
+ }
539
+ }
540
+ public static System . Collections . IEnumerable TestCases2 {
541
+ get {
542
+ yield return "Models/SimpleMan/SimpleMan.fbx" ;
543
+ }
544
+ }
545
+ }
546
+
547
+ [ Test , TestCaseSource ( typeof ( SkinnedMeshTestDataClass ) , "TestCases1" ) ]
548
+ public void TestSkinnedMeshExport ( string fbxPath ) {
549
+ fbxPath = FindPathInUnitTests ( fbxPath ) ;
550
+ Assert . That ( fbxPath , Is . Not . Null ) ;
551
+
552
+ SkinnedMeshRenderer originalSkinnedMesh , exportedSkinnedMesh ;
553
+ ExportSkinnedMesh ( fbxPath , out originalSkinnedMesh , out exportedSkinnedMesh ) ;
534
554
535
555
Assert . IsTrue ( originalSkinnedMesh . name == exportedSkinnedMesh . name ||
536
556
( originalSkinnedMesh . transform . parent == null && exportedSkinnedMesh . transform . parent == null ) ) ;
@@ -594,5 +614,68 @@ public void TestSkinnedMeshExport(){
594
614
var expWeights = exportedMesh . boneWeights ;
595
615
Assert . IsNotNull ( expWeights ) ;
596
616
}
617
+
618
+ [ Test , TestCaseSource ( typeof ( SkinnedMeshTestDataClass ) , "TestCases2" ) ]
619
+ public void TestBoneWeightExport ( string fbxPath ) {
620
+ fbxPath = FindPathInUnitTests ( fbxPath ) ;
621
+ Assert . That ( fbxPath , Is . Not . Null ) ;
622
+
623
+ SkinnedMeshRenderer originalSkinnedMesh , exportedSkinnedMesh ;
624
+ ExportSkinnedMesh ( fbxPath , out originalSkinnedMesh , out exportedSkinnedMesh ) ;
625
+
626
+ var origVerts = originalSkinnedMesh . sharedMesh . vertices ;
627
+ Assert . That ( origVerts , Is . Not . Null ) ;
628
+
629
+ var expVerts = exportedSkinnedMesh . sharedMesh . vertices ;
630
+ Assert . That ( expVerts , Is . Not . Null ) ;
631
+
632
+ var origBoneWeights = originalSkinnedMesh . sharedMesh . boneWeights ;
633
+ Assert . That ( origBoneWeights , Is . Not . Null ) ;
634
+ Assert . That ( origBoneWeights . Length , Is . GreaterThan ( 0 ) ) ;
635
+
636
+ var expBoneWeights = exportedSkinnedMesh . sharedMesh . boneWeights ;
637
+ Assert . That ( expBoneWeights , Is . Not . Null ) ;
638
+ Assert . That ( expBoneWeights . Length , Is . GreaterThan ( 0 ) ) ;
639
+
640
+ var origBones = originalSkinnedMesh . bones ;
641
+ var expBones = exportedSkinnedMesh . bones ;
642
+
643
+ int comparisonCount = 0 ;
644
+ int minVertCount = Mathf . Min ( origVerts . Length , expVerts . Length ) ;
645
+ for ( int i = 0 ; i < minVertCount ; i ++ ) {
646
+ for ( int j = 0 ; j < minVertCount ; j ++ ) {
647
+ if ( origVerts [ i ] == expVerts [ j ] ) {
648
+ // compare bone weights
649
+ var origBw = origBoneWeights [ i ] ;
650
+ var expBw = expBoneWeights [ j ] ;
651
+
652
+ var indexMsg = "Bone index {0} doesn't match" ;
653
+ var nameMsg = "bone names don't match" ;
654
+
655
+ Assert . That ( expBw . boneIndex0 , Is . EqualTo ( origBw . boneIndex0 ) , string . Format ( indexMsg , 0 ) ) ;
656
+ Assert . That ( expBones [ expBw . boneIndex0 ] . name , Is . EqualTo ( origBones [ origBw . boneIndex0 ] . name ) , nameMsg ) ;
657
+
658
+ Assert . That ( expBw . boneIndex1 , Is . EqualTo ( origBw . boneIndex1 ) , string . Format ( indexMsg , 1 ) ) ;
659
+ Assert . That ( expBones [ expBw . boneIndex1 ] . name , Is . EqualTo ( origBones [ origBw . boneIndex1 ] . name ) , nameMsg ) ;
660
+
661
+ Assert . That ( expBw . boneIndex2 , Is . EqualTo ( origBw . boneIndex2 ) , string . Format ( indexMsg , 2 ) ) ;
662
+ Assert . That ( expBones [ expBw . boneIndex2 ] . name , Is . EqualTo ( origBones [ origBw . boneIndex2 ] . name ) , nameMsg ) ;
663
+
664
+ Assert . That ( expBw . boneIndex3 , Is . EqualTo ( origBw . boneIndex3 ) , string . Format ( indexMsg , 3 ) ) ;
665
+ Assert . That ( expBones [ expBw . boneIndex3 ] . name , Is . EqualTo ( origBones [ origBw . boneIndex3 ] . name ) , nameMsg ) ;
666
+
667
+ var message = "Bone weight {0} doesn't match" ;
668
+ Assert . That ( expBw . weight0 , Is . EqualTo ( origBw . weight0 ) . Within ( 0.001f ) , string . Format ( message , 0 ) ) ;
669
+ Assert . That ( expBw . weight1 , Is . EqualTo ( origBw . weight1 ) . Within ( 0.001f ) , string . Format ( message , 1 ) ) ;
670
+ Assert . That ( expBw . weight2 , Is . EqualTo ( origBw . weight2 ) . Within ( 0.001f ) , string . Format ( message , 2 ) ) ;
671
+ Assert . That ( expBw . weight3 , Is . EqualTo ( origBw . weight3 ) . Within ( 0.001f ) , string . Format ( message , 3 ) ) ;
672
+
673
+ comparisonCount ++ ;
674
+ break ;
675
+ }
676
+ }
677
+ }
678
+ Debug . LogWarningFormat ( "Compared {0} out of a possible {1} bone weights" , comparisonCount , minVertCount ) ;
679
+ }
597
680
}
598
681
}
0 commit comments