@@ -416,6 +416,9 @@ public int Main (KeyData keyData, string testName, string path)
416
416
bool hasQuatBinding =
417
417
MapEulerToQuaternionPropertyName . TryGetValue ( propertyBinding , out propertyBinding ) ;
418
418
419
+ bool isRotation = AnimationTestDataClass . m_rotationEulerNames . Contains ( curveBinding . propertyName ) ||
420
+ AnimationTestDataClass . m_rotationQuaternionNames . Contains ( curveBinding . propertyName ) ;
421
+
419
422
if ( id == - 1 )
420
423
id = keyData . GetIndexOf ( propertyBinding ) ;
421
424
@@ -439,13 +442,13 @@ public int Main (KeyData keyData, string testName, string path)
439
442
else
440
443
{
441
444
// compare by sampled keyvalues against original keydata
442
- KeyValuesTest ( keyData . keyTimes , keyData . GetAltKeyValues ( id ) , animCurveImported , curveBinding . propertyName ) ;
445
+ KeyValuesTest ( keyData . keyTimes , keyData . GetAltKeyValues ( id ) , animCurveImported , curveBinding . propertyName , isRotation ) ;
443
446
}
444
447
}
445
448
else
446
449
{
447
450
// compare by sampled keyvalues against original animCurve
448
- KeyValuesTest ( animCurvesOriginal [ id ] , animCurveImported , curveBinding . propertyName ) ;
451
+ KeyValuesTest ( animCurvesOriginal [ id ] , animCurveImported , curveBinding . propertyName , isRotation ) ;
449
452
}
450
453
result ++ ;
451
454
}
@@ -497,14 +500,20 @@ public static void ClipTest(AnimationClip animClipOriginal, AnimationClip animCl
497
500
continue ;
498
501
}
499
502
503
+ bool isRotation = AnimationTestDataClass . m_rotationEulerNames . Contains ( curveBinding . propertyName ) ||
504
+ AnimationTestDataClass . m_rotationQuaternionNames . Contains ( curveBinding . propertyName ) ;
505
+
500
506
AnimationCurve animCurveOrig = AnimationUtility . GetEditorCurve ( animClipOriginal , curveBinding ) ;
501
507
Assert . That ( animCurveOrig , Is . Not . Null ) ;
502
508
503
509
AnimationCurve animCurveImported = AnimationUtility . GetEditorCurve ( animClipImported , impCurveBinding ) ;
504
510
Assert . That ( animCurveImported , Is . Not . Null ) ;
505
511
506
- AnimTester . KeyValuesTest ( animCurveImported , animCurveOrig ,
507
- string . Format ( "path: {0}, property: {1}" , curveBinding . path , curveBinding . propertyName ) ) ;
512
+ AnimTester . KeyValuesTest (
513
+ animCurveImported ,
514
+ animCurveOrig ,
515
+ string . Format ( "path: {0}, property: {1}" , curveBinding . path , curveBinding . propertyName ) ,
516
+ isRotation ) ;
508
517
}
509
518
}
510
519
}
@@ -545,7 +554,7 @@ public static void KeysTest (float [] expectedKeyTimes, float [] expectedKeyValu
545
554
return ;
546
555
}
547
556
548
- public static void KeyValuesTest ( float [ ] expectedKeyTimes , float [ ] expectedKeyValues , AnimationCurve actualAnimCurve , string message )
557
+ public static void KeyValuesTest ( float [ ] expectedKeyTimes , float [ ] expectedKeyValues , AnimationCurve actualAnimCurve , string message , bool isRotationCurve = false )
549
558
{
550
559
for ( var i = 0 ; i < expectedKeyTimes . Length ; ++ i )
551
560
{
@@ -554,23 +563,45 @@ public static void KeyValuesTest (float [] expectedKeyTimes, float [] expectedKe
554
563
555
564
float actualKeyValue = actualAnimCurve . Evaluate ( expectedKeyTime ) ;
556
565
557
- #if DEBUG_UNITTEST
566
+ #if DEBUG_UNITTEST
558
567
Debug . Log ( string . Format ( "key time={0} expected={1} actual={2} delta={3}" , expectedKeyTime . ToString ( ) , expectedKeyValue . ToString ( ) , actualKeyValue . ToString ( ) , Mathf . Abs ( expectedKeyValue - actualKeyValue ) . ToString ( ) ) ) ;
559
- #endif
560
- Assert . That ( expectedKeyValue , Is . EqualTo ( actualKeyValue ) . Within ( 0.000001 ) , string . Format ( "{0} key ({1}) doesn't match" , message , expectedKeyTime ) ) ;
568
+ #endif
569
+ // also handles values that are equal but different signs (i.e. -90 == 270)
570
+ if ( isRotationCurve )
571
+ {
572
+ var expectedQuat = Quaternion . Euler ( new Vector3 ( expectedKeyValue , 0 , 0 ) ) ;
573
+ var actualQuat = Quaternion . Euler ( new Vector3 ( actualKeyValue , 0 , 0 ) ) ;
574
+ Assert . That ( Quaternion . Angle ( expectedQuat , actualQuat ) , Is . LessThan ( 0.1 ) , string . Format ( "{0} key ({1}) doesn't match" , message , expectedKeyTime ) ) ;
575
+ }
576
+ else
577
+ {
578
+ Assert . That ( expectedKeyValue , Is . EqualTo ( actualKeyValue ) . Within ( 0.0001 ) , string . Format ( "{0} key ({1}) doesn't match" , message , expectedKeyTime ) ) ;
579
+ }
561
580
}
562
581
}
563
582
564
- public static void KeyValuesTest ( AnimationCurve expectedAnimCurve , AnimationCurve actualAnimCurve , string message )
583
+ public static void KeyValuesTest ( AnimationCurve expectedAnimCurve , AnimationCurve actualAnimCurve , string message , bool isRotationCurve = false )
565
584
{
566
585
foreach ( var key in expectedAnimCurve . keys )
567
586
{
568
587
float actualKeyValue = actualAnimCurve . Evaluate ( key . time ) ;
569
588
570
- #if DEBUG_UNITTEST
589
+ #if DEBUG_UNITTEST
571
590
Debug . Log ( string . Format ( "key time={0} actual={1} expected={2} delta={3}" , key . time . ToString ( ) , key . value . ToString ( ) , actualKeyValue . ToString ( ) , Mathf . Abs ( key . value - actualKeyValue ) . ToString ( ) ) ) ;
572
- #endif
573
- Assert . That ( key . value , Is . EqualTo ( actualKeyValue ) . Within ( 0.1 ) , string . Format ( "{0} key ({1}) doesn't match" , message , key . time ) ) ;
591
+ #endif
592
+ var expectedKeyValue = key . value ;
593
+
594
+ // also handles values that are equal but different signs (i.e. -90 == 270)
595
+ if ( isRotationCurve )
596
+ {
597
+ var expectedQuat = Quaternion . Euler ( new Vector3 ( expectedKeyValue , 0 , 0 ) ) ;
598
+ var actualQuat = Quaternion . Euler ( new Vector3 ( actualKeyValue , 0 , 0 ) ) ;
599
+ Assert . That ( Quaternion . Angle ( expectedQuat , actualQuat ) , Is . LessThan ( 0.1 ) , string . Format ( "{0} key ({1}) doesn't match" , message , key . time ) ) ;
600
+ }
601
+ else
602
+ {
603
+ Assert . That ( expectedKeyValue , Is . EqualTo ( actualKeyValue ) . Within ( 0.1 ) , string . Format ( "{0} key ({1}) doesn't match" , message , key . time ) ) ;
604
+ }
574
605
}
575
606
}
576
607
0 commit comments