@@ -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,18 @@ 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
512
AnimTester . KeyValuesTest ( animCurveImported , animCurveOrig ,
507
- string . Format ( "path: {0}, property: {1}" , curveBinding . path , curveBinding . propertyName ) ) ;
513
+ string . Format ( "path: {0}, property: {1}" , curveBinding . path , curveBinding . propertyName ) ,
514
+ isRotation ) ;
508
515
}
509
516
}
510
517
}
@@ -545,7 +552,7 @@ public static void KeysTest (float [] expectedKeyTimes, float [] expectedKeyValu
545
552
return ;
546
553
}
547
554
548
- public static void KeyValuesTest ( float [ ] expectedKeyTimes , float [ ] expectedKeyValues , AnimationCurve actualAnimCurve , string message )
555
+ public static void KeyValuesTest ( float [ ] expectedKeyTimes , float [ ] expectedKeyValues , AnimationCurve actualAnimCurve , string message , bool isRotationCurve = false )
549
556
{
550
557
for ( var i = 0 ; i < expectedKeyTimes . Length ; ++ i )
551
558
{
@@ -554,23 +561,45 @@ public static void KeyValuesTest (float [] expectedKeyTimes, float [] expectedKe
554
561
555
562
float actualKeyValue = actualAnimCurve . Evaluate ( expectedKeyTime ) ;
556
563
557
- #if DEBUG_UNITTEST
564
+ #if DEBUG_UNITTEST
558
565
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.0001 ) , string . Format ( "{0} key ({1}) doesn't match" , message , expectedKeyTime ) ) ;
566
+ #endif
567
+ // also handles values that are equal but different signs (i.e. -90 == 270)
568
+ if ( isRotationCurve )
569
+ {
570
+ var expectedQuat = Quaternion . Euler ( new Vector3 ( expectedKeyValue , 0 , 0 ) ) ;
571
+ var actualQuat = Quaternion . Euler ( new Vector3 ( actualKeyValue , 0 , 0 ) ) ;
572
+ Assert . That ( Quaternion . Angle ( expectedQuat , actualQuat ) , Is . LessThan ( 0.1 ) , string . Format ( "{0} key ({1}) doesn't match" , message , expectedKeyTime ) ) ;
573
+ }
574
+ else
575
+ {
576
+ Assert . That ( expectedKeyValue , Is . EqualTo ( actualKeyValue ) . Within ( 0.0001 ) , string . Format ( "{0} key ({1}) doesn't match" , message , expectedKeyTime ) ) ;
577
+ }
561
578
}
562
579
}
563
580
564
- public static void KeyValuesTest ( AnimationCurve expectedAnimCurve , AnimationCurve actualAnimCurve , string message )
581
+ public static void KeyValuesTest ( AnimationCurve expectedAnimCurve , AnimationCurve actualAnimCurve , string message , bool isRotationCurve = false )
565
582
{
566
583
foreach ( var key in expectedAnimCurve . keys )
567
584
{
568
585
float actualKeyValue = actualAnimCurve . Evaluate ( key . time ) ;
569
586
570
- #if DEBUG_UNITTEST
587
+ #if DEBUG_UNITTEST
571
588
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 ) ) ;
589
+ #endif
590
+ var expectedKeyValue = key . value ;
591
+
592
+ // also handles values that are equal but different signs (i.e. -90 == 270)
593
+ if ( isRotationCurve )
594
+ {
595
+ var expectedQuat = Quaternion . Euler ( new Vector3 ( expectedKeyValue , 0 , 0 ) ) ;
596
+ var actualQuat = Quaternion . Euler ( new Vector3 ( actualKeyValue , 0 , 0 ) ) ;
597
+ Assert . That ( Quaternion . Angle ( expectedQuat , actualQuat ) , Is . LessThan ( 0.1 ) , string . Format ( "{0} key ({1}) doesn't match" , message , key . time ) ) ;
598
+ }
599
+ else
600
+ {
601
+ Assert . That ( expectedKeyValue , Is . EqualTo ( actualKeyValue ) . Within ( 0.1 ) , string . Format ( "{0} key ({1}) doesn't match" , message , key . time ) ) ;
602
+ }
574
603
}
575
604
}
576
605
0 commit comments