@@ -54,10 +54,10 @@ public class GltfShape : SharedShape
54
54
int SkeletonRootNode ;
55
55
public bool MsfsFlavoured ;
56
56
57
- internal ImmutableArray < Vector3 > Scales ;
58
- internal ImmutableArray < Quaternion > Rotations ;
59
- internal ImmutableArray < Vector3 > Translations ;
60
- internal ImmutableArray < float [ ] > Weights ;
57
+ internal Vector3 [ ] Scales ;
58
+ internal Quaternion [ ] Rotations ;
59
+ internal Vector3 [ ] Translations ;
60
+ internal float [ ] [ ] Weights ;
61
61
62
62
/// <summary>
63
63
/// glTF specification declares that the model's forward is +Z. However OpenRails uses -Z as forward,
@@ -338,7 +338,7 @@ public class GltfDistanceLevel : DistanceLevel
338
338
internal readonly GltfShape Shape ;
339
339
340
340
static readonly Stack < int > TempStack = new Stack < int > ( ) ; // (nodeNumber, parentIndex)
341
- static readonly string [ ] TestControls = new [ ] { "WIPER" , "ORTSBELL" , " ORTSITEM1CONTINUOUS", "ORTSITEM1CONTINUOUS " } ;
341
+ static readonly string [ ] TestControls = new [ ] { "WIPER" , "ORTSITEM1CONTINUOUS" , "ORTSITEM2CONTINUOUS " } ;
342
342
343
343
public GltfDistanceLevel ( GltfShape shape , int lodId , Gltf gltfFile , string gltfFileName )
344
344
{
@@ -455,10 +455,10 @@ public GltfDistanceLevel(GltfShape shape, int lodId, Gltf gltfFile, string gltfF
455
455
if ( lodId == 0 )
456
456
{
457
457
shape . Matrices = Matrices . ToArray ( ) ;
458
- shape . Scales = Scales ;
459
- shape . Rotations = Rotations ;
460
- shape . Translations = Translations ;
461
- shape . Weights = Weights ;
458
+ shape . Scales = Scales . ToArray ( ) ;
459
+ shape . Rotations = Rotations . ToArray ( ) ;
460
+ shape . Translations = Translations . ToArray ( ) ;
461
+ shape . Weights = Weights . ToArray ( ) ;
462
462
463
463
if ( SubObjects . FirstOrDefault ( ) is GltfSubObject gltfSubObject )
464
464
{
@@ -561,11 +561,10 @@ public GltfDistanceLevel(GltfShape shape, int lodId, Gltf gltfFile, string gltfF
561
561
562
562
if ( ConsistGenerator . GltfVisualTestRun )
563
563
{
564
- // Assign the first four animations to Wipers [V], Bell [Shift+B], Item1Continuous [Shift+,], Item2Continuous [Shift+.] respectively,
564
+ // Assign the first four animations to Wipers [V], Item1Continuous [Shift+,], Item2Continuous [Shift+.] respectively,
565
565
// because these are the ones capable of playing a loop.
566
566
for ( var i = 0 ; i < shape . GltfAnimations . Count ; i ++ )
567
- if ( i < TestControls . Length )
568
- shape . MatrixNames [ i ] = TestControls [ i ] ;
567
+ shape . MatrixNames [ i ] = TestControls [ i % TestControls . Length ] ;
569
568
}
570
569
}
571
570
}
@@ -1702,7 +1701,7 @@ public override int GetAnimationParent(int animationNumber)
1702
1701
public override Matrix GetMatrixProduct ( int iNode ) => base . GetMatrixProduct ( iNode ) * PlusZToForward ;
1703
1702
public override bool IsAnimationArticulation ( int number ) => GltfAnimations ? . ElementAtOrDefault ( number ) ? . Channels ? . FirstOrDefault ( ) ? . TimeArray == null ;
1704
1703
public override int GetAnimationTargetNode ( int animationId ) => GltfAnimations ? . ElementAtOrDefault ( animationId ) ? . Channels ? . FirstOrDefault ( ) ? . TargetNode ?? 0 ;
1705
- public override int GetAnimationNamesCount ( ) => EnableAnimations ? GltfAnimations ? . Count ?? 0 : 0 ;
1704
+ public override int GetAnimationNamesCount ( ) => EnableAnimations || ConsistGenerator . GltfVisualTestRun ? GltfAnimations ? . Count ?? 0 : 0 ;
1706
1705
1707
1706
public bool HasAnimation ( int number ) => GltfAnimations ? . ElementAtOrDefault ( number ) ? . Channels ? . FirstOrDefault ( ) != null ;
1708
1707
public float GetAnimationLength ( int number ) => GltfAnimations ? . ElementAtOrDefault ( number ) ? . Channels ? . Select ( c => c . TimeMax ) . Max ( ) ?? 0 ;
@@ -1714,7 +1713,7 @@ public override int GetAnimationParent(int animationNumber)
1714
1713
/// <param name="time">Actual time in the animation clip in seconds.</param>
1715
1714
public void Animate ( int animationNumber , float time , Matrix [ ] animatedMatrices )
1716
1715
{
1717
- if ( ! EnableAnimations )
1716
+ if ( ! EnableAnimations && ! ConsistGenerator . GltfVisualTestRun )
1718
1717
return ;
1719
1718
1720
1719
foreach ( var channel in GltfAnimations [ animationNumber ] . Channels )
@@ -1740,31 +1739,27 @@ public void Animate(int animationNumber, float time, Matrix[] animatedMatrices)
1740
1739
case AnimationSampler . InterpolationEnum . STEP : amount = 0 ; break ;
1741
1740
default : amount = 0 ; break ;
1742
1741
}
1743
- // Matrix.Decompose() gives wrong result, so must go with the individually stored transforms. It is guaranteed by the spec that the animation targeted nodes have these set.
1744
- var scale = Scales [ channel . TargetNode ] ;
1745
- var rotation = Rotations [ channel . TargetNode ] ;
1746
- var translation = Translations [ channel . TargetNode ] ;
1747
1742
switch ( channel . Path )
1748
1743
{
1749
1744
case AnimationChannelTarget . PathEnum . translation :
1750
- translation = channel . Interpolation == AnimationSampler . InterpolationEnum . CUBICSPLINE
1745
+ Translations [ channel . TargetNode ] = channel . Interpolation == AnimationSampler . InterpolationEnum . CUBICSPLINE
1751
1746
? Vector3 . Hermite ( channel . OutputVector3 [ Property ( frame1 ) ] , channel . OutputVector3 [ OutTangent ( frame2 ) ] , channel . OutputVector3 [ Property ( frame2 ) ] , channel . OutputVector3 [ InTangent ( frame2 ) ] , amount )
1752
1747
: Vector3 . Lerp ( channel . OutputVector3 [ frame1 ] , channel . OutputVector3 [ frame2 ] , amount ) ;
1753
1748
break ;
1754
1749
case AnimationChannelTarget . PathEnum . rotation :
1755
- rotation = channel . Interpolation == AnimationSampler . InterpolationEnum . CUBICSPLINE
1750
+ Rotations [ channel . TargetNode ] = channel . Interpolation == AnimationSampler . InterpolationEnum . CUBICSPLINE
1756
1751
? CsInterp ( channel . OutputQuaternion [ Property ( frame1 ) ] , channel . OutputQuaternion [ OutTangent ( frame2 ) ] , channel . OutputQuaternion [ Property ( frame2 ) ] , channel . OutputQuaternion [ InTangent ( frame2 ) ] , amount )
1757
1752
: Quaternion . Slerp ( channel . OutputQuaternion [ frame1 ] , channel . OutputQuaternion [ frame2 ] , amount ) ;
1758
1753
break ;
1759
1754
case AnimationChannelTarget . PathEnum . scale :
1760
- scale = channel . Interpolation == AnimationSampler . InterpolationEnum . CUBICSPLINE
1755
+ Scales [ channel . TargetNode ] = channel . Interpolation == AnimationSampler . InterpolationEnum . CUBICSPLINE
1761
1756
? Vector3 . Hermite ( channel . OutputVector3 [ Property ( frame1 ) ] , channel . OutputVector3 [ OutTangent ( frame2 ) ] , channel . OutputVector3 [ Property ( frame2 ) ] , channel . OutputVector3 [ InTangent ( frame2 ) ] , amount )
1762
1757
: Vector3 . Lerp ( channel . OutputVector3 [ frame1 ] , channel . OutputVector3 [ frame2 ] , amount ) ;
1763
1758
break ;
1764
1759
case AnimationChannelTarget . PathEnum . weights :
1765
1760
default : break ;
1766
1761
}
1767
- animatedMatrices [ channel . TargetNode ] = Matrix . CreateScale ( scale ) * Matrix . CreateFromQuaternion ( rotation ) * Matrix . CreateTranslation ( translation ) ;
1762
+ animatedMatrices [ channel . TargetNode ] = Matrix . CreateScale ( Scales [ channel . TargetNode ] ) * Matrix . CreateFromQuaternion ( Rotations [ channel . TargetNode ] ) * Matrix . CreateTranslation ( Translations [ channel . TargetNode ] ) ;
1768
1763
}
1769
1764
}
1770
1765
@@ -1840,13 +1835,13 @@ public void Animate(int animationNumber, float time, Matrix[] animatedMatrices)
1840
1835
{ "SheenChair" . ToLower ( ) , Matrix . CreateScale ( 2 ) } ,
1841
1836
{ "SheenCloth" . ToLower ( ) , Matrix . CreateScale ( 50 ) } ,
1842
1837
{ "SpecGlossVsMetalRough" . ToLower ( ) , Matrix . CreateScale ( 7 ) * Matrix . CreateTranslation ( 0 , 2 , 0 ) } ,
1843
- { "SpecularTest" . ToLower ( ) , Matrix . CreateScale ( 3 ) * Matrix . CreateTranslation ( 0 , 2 , 0 ) } ,
1838
+ { "SpecularTest" . ToLower ( ) , Matrix . CreateScale ( 5 ) * Matrix . CreateTranslation ( 0 , 2 , 0 ) } ,
1844
1839
{ "StainedGlassLamp" . ToLower ( ) , Matrix . CreateScale ( 3 ) } ,
1845
1840
{ "Suzanne" . ToLower ( ) , Matrix . CreateTranslation ( 0 , 2 , 0 ) } ,
1846
1841
{ "TextureCoordinateTest" . ToLower ( ) , Matrix . CreateTranslation ( 0 , 2 , 0 ) } ,
1847
1842
{ "TextureEncodingTest" . ToLower ( ) , Matrix . CreateScale ( 0.5f ) * Matrix . CreateTranslation ( 0 , 3 , 0 ) } ,
1848
1843
{ "TextureLinearInterpolationTest" . ToLower ( ) , Matrix . CreateTranslation ( 0 , 2 , 0 ) } ,
1849
- { "TextureSettingsTest" . ToLower ( ) , Matrix . CreateTranslation ( 0 , 6 , 0 ) } ,
1844
+ { "TextureSettingsTest" . ToLower ( ) , Matrix . CreateScale ( 0.5f ) * Matrix . CreateTranslation ( 0 , 4 , 0 ) } ,
1850
1845
{ "TextureTransformMultiTest" . ToLower ( ) , Matrix . CreateScale ( 2 ) * Matrix . CreateTranslation ( 0 , 4 , 0 ) } ,
1851
1846
{ "TextureTransformTest" . ToLower ( ) , Matrix . CreateTranslation ( 0 , 2 , 0 ) } ,
1852
1847
{ "ToyCar" . ToLower ( ) , Matrix . CreateScale ( 80 ) * Matrix . CreateTranslation ( 0 , 2 , 0 ) } ,
0 commit comments